00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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