Logo
~Sockets~
~Examples~
~Contact~

Terrain.cpp

Go to the documentation of this file.
00001 // Terrain.cpp
00002 // released 2006-09-25
00003 /*
00004 Copyright (C) 2006  Anders Hedstrom (grymse@alhem.net)
00005 
00006 This program is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU General Public License
00008 as published by the Free Software Foundation; either version 2
00009 of the License, or (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 */
00020 //#include <stdio.h>
00021 #include <libfuture.h>
00022 
00023 #include "Terrain.h"
00024 #include "Area.h"
00025 
00026 
00027 // statics
00028 terrains_t Terrain::m_terrains;
00029 
00030 
00031 Terrain::Terrain(Database& db,Area& area,char tchar)
00032 :Object(db)
00033 ,m_area(area)
00034 {
00035         m_terrain = Terrain::GetTerrain(db, area, tchar);
00036         m_terrain -> area = area.GetNum();
00037         m_terrain -> tchar = tchar;
00038 }
00039 
00040 
00041 Terrain::~Terrain()
00042 {
00043 }
00044 
00045 
00046 db::Terrain *Terrain::GetTerrain(Database& db,Area& area,char tchar)
00047 {
00048         std::map<char,db::Terrain *>& ref = m_terrains[area.GetNum()];
00049         db::Terrain *p = ref[tchar];
00050         if (p != NULL)
00051                 return p;
00052         std::string tmp;
00053         tmp += tchar;
00054         p = new db::Terrain(db, area.GetNum(), tmp);
00055         p -> area = area.GetNum();
00056         p -> tchar = tchar;
00057         ref[tchar] = p;
00058         return p;
00059 }
00060 
00061 
00062 bool Terrain::Exists()
00063 {
00064         if (m_terrain && m_terrain -> num)
00065                 return true;
00066         return false;
00067 }
00068 
00069 
00070 const std::string& Terrain::GetColor()
00071 {
00072         return m_terrain -> tcolor;
00073 }
00074 
00075 
00076 char Terrain::GetChar()
00077 {
00078         return m_terrain -> tchar[0];
00079 }
00080 
00081 
00082 void Terrain::Save()
00083 {
00084         m_terrain -> save();
00085 }
00086 
00087 
00088 void Terrain::SetChar(char tchar)
00089 {
00090         m_terrain -> tchar = tchar;
00091 }
00092 
00093 
00094 void Terrain::SetColor(const std::string& x)
00095 {
00096         m_terrain -> tcolor = x;
00097 }
00098 
00099 
00100 const std::string& Terrain::GetName()
00101 {
00102         return m_terrain -> name;
00103 }
00104 
00105 
00106 void Terrain::SetName(const std::string& x)
00107 {
00108         m_terrain -> name = x;
00109 }
00110 
00111 
00112 bool Terrain::IsImpassable()
00113 {
00114         return m_terrain -> impassable ? true : false;
00115 }
00116 
00117 
00118 void Terrain::SetImpassable(bool x)
00119 {
00120         m_terrain -> impassable = x ? 1 : 0;
00121 }
00122 
00123 
00124 long Terrain::GetNum()
00125 {
00126         return m_terrain -> num;
00127 }
00128 
00129 
00130 double Terrain::GetDelay()
00131 {
00132         return m_terrain -> delay;
00133 }
00134 
00135 
00136 void Terrain::SetDelay(double d)
00137 {
00138         m_terrain -> delay = d;
00139 }
00140 
00141 
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4