Logo
~Sockets~
~Examples~
~Contact~

Area.cpp

Go to the documentation of this file.
00001 // Area.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 <libfuture.h>
00021 #include <Utility.h>
00022 #include <sys/param.h>
00023 
00024 #include "Area.h"
00025 #include "Terrain.h"
00026 #include "Chunk.h"
00027 
00028 
00029 // statics
00030 areas_t Area::m_areas;
00031 
00032 
00033 Area::Area(Database& db,long num) : Object(db)
00034 {
00035         m_area = Area::GetArea(db, num);
00036         if (Exists())
00037         {
00038                 VerifyTerrain();
00039         }
00040 }
00041 
00042 
00043 Area::Area(Database& db,const std::string& name) : Object(db)
00044 {
00045         m_area = Area::GetArea(db, name);
00046         if (Exists())
00047         {
00048                 VerifyTerrain();
00049         }
00050 }
00051 
00052 
00053 Area::~Area()
00054 {
00055 }
00056 
00057 
00058 
00059 bool Area::Exists()
00060 {
00061         if (m_area && m_area -> num)
00062                 return true;
00063         return false;
00064 }
00065 
00066 
00067 void Area::Save()
00068 {
00069         m_area -> save();
00070         VerifyTerrain();
00071 }
00072 
00073 
00074 int Area::GetWidth()
00075 {
00076         return m_area -> width;
00077 }
00078 
00079 
00080 int Area::GetHeight()
00081 {
00082         return m_area -> height;
00083 }
00084 
00085 
00086 long Area::GetNum()
00087 {
00088         return m_area -> num;
00089 }
00090 
00091 
00092 void Area::SetWidth(int w)
00093 {
00094         m_area -> width = w;
00095 }
00096 
00097 
00098 void Area::SetHeight(int h)
00099 {
00100         m_area -> height = h;
00101 }
00102 
00103 
00104 void Area::SetName(const std::string& name)
00105 {
00106         m_area -> name = name;
00107 }
00108 
00109 
00110 const std::string& Area::GetName()
00111 {
00112         return m_area -> name;
00113 }
00114 
00115 
00116 void Area::VerifyTerrain()
00117 {
00118         {
00119                 Terrain t(m_db, *this, 'P');
00120                 if (!t.Exists())
00121                 {
00122                         t.SetColor("&m");
00123                         t.SetName("Portal");
00124                         t.Save();
00125                 }
00126         }
00127         {
00128                 Terrain t(m_db, *this, 'U');
00129                 if (!t.Exists())
00130                 {
00131                         t.SetColor("&m");
00132                         t.SetName("Stairs up");
00133                         t.Save();
00134                 }
00135         }
00136         {
00137                 Terrain t(m_db, *this, 'D');
00138                 if (!t.Exists())
00139                 {
00140                         t.SetColor("&m");
00141                         t.SetName("Stairs down");
00142                         t.Save();
00143                 }
00144         }
00145 }
00146 
00147 
00148 db::Area *Area::GetArea(Database& db,long num)
00149 {
00150         for (areas_t::iterator it = m_areas.begin(); it != m_areas.end(); it++)
00151         {
00152                 db::Area *p = *it;
00153                 if (p -> num == num)
00154                         return p;
00155         }
00156         db::Area *p = new db::Area(db, num);
00157         m_areas.push_back(p);
00158         return p;
00159 }
00160 
00161 
00162 db::Area *Area::GetArea(Database& db,const std::string& name)
00163 {
00164         for (areas_t::iterator it = m_areas.begin(); it != m_areas.end(); it++)
00165         {
00166                 db::Area *p = *it;
00167                 if (p -> name == name)
00168                         return p;
00169         }
00170         db::Area *p = new db::Area(db, name);
00171         p -> name = name;
00172         m_areas.push_back(p);
00173         return p;
00174 }
00175 
00176 
00177 void Area::GetAreaBorders(int ch_z,int& xmin,int& xmax,int &ymin,int &ymax)
00178 {
00179         xmin = ymin = 1000000;
00180         xmax = ymax = 0;
00181         Query q(m_db);
00182         q.get_result("select * from chunk where area=" + Utility::l2string(m_area -> num) +
00183                 " and z=" + Utility::l2string(ch_z) );
00184         while (q.fetch_row())
00185         {
00186                 db::Chunk chunk(&m_db, &q);
00187                 xmin = MIN(xmin, chunk.x);
00188                 xmax = MAX(xmax, chunk.x);
00189                 ymin = MIN(ymin, chunk.y);
00190                 ymax = MAX(ymax, chunk.y);
00191         }
00192         q.free_result();
00193 }
00194 
00195 
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