Logo
~Sockets~
~Examples~
~Contact~

Steps.cpp

Go to the documentation of this file.
00001 // Steps.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 <Parse.h>
00023 
00024 #include "Steps.h"
00025 #include "Player.h"
00026 #include "Area.h"
00027 
00028 
00029 // statics
00030 steps_t Steps::m_cache;
00031 
00032 Steps::Steps(Database& db,Player& pl,Area& area,long z,long y)
00033 :Object(db)
00034 ,m_player(pl)
00035 ,m_area(area)
00036 {
00037         m_steps = Steps::GetSteps(db, pl, area, z, y);
00038 }
00039 
00040 
00041 Steps::~Steps()
00042 {
00043 }
00044 
00045 
00046 db::Steps *Steps::GetSteps(Database& db,Player& pl,Area& area,long z,long y)
00047 {
00048         db::Steps *p = m_cache[pl.GetNum()][area.GetNum()][z][y];
00049         if (p)
00050                 return p;
00051         p = new db::Steps(db, pl.GetNum(), area.GetNum(), z, y);
00052         p -> player = pl.GetNum();
00053         p -> area = area.GetNum();
00054         p -> zcoord = z;
00055         p -> ycoord = y;
00056         m_cache[pl.GetNum()][area.GetNum()][z][y] = p;
00057         return p;
00058 }
00059 
00060 
00061 void Steps::AddCoord(long x)
00062 {
00063         Parse pa(m_steps -> xcoords, ":");
00064         std::string tmp = pa.getword();
00065         while (tmp.size())
00066         {
00067                 if (atol(tmp.c_str()) == x)
00068                         return;
00069                 //
00070                 tmp = pa.getword();
00071         }
00072         if (m_steps -> xcoords.size())
00073         {
00074                 m_steps -> xcoords += ":" + Utility::l2string(x);
00075         }
00076         else
00077         {
00078                 m_steps -> xcoords = Utility::l2string(x);
00079         }
00080         Save();
00081 }
00082 
00083 
00084 void Steps::Save()
00085 {
00086         m_steps -> save();
00087 }
00088 
00089 
00090 bool Steps::Exists()
00091 {
00092         if (m_steps && m_steps -> num)
00093                 return true;
00094         return false;
00095 }
00096 
00097 
00098 long Steps::GetNum()
00099 {
00100         return m_steps -> num;
00101 }
00102 
00103 
00104 db::Steps *Steps::GetStep(Player& pl,Area& area,long z,long y)
00105 {
00106         return m_cache[pl.GetNum()][area.GetNum()][z][y];
00107 }
00108 
00109 
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