![]() |
Chunk Class ReferenceDatabase table Chunk.
More...
|
Public Member Functions | |
Chunk (Database &, Area &, long num) | |
Chunk (Database &, Area &, int x, int y, int z=0) | |
~Chunk () | |
void | Init (InSocket *, int x, int y, int z, char tchar) |
void | Set (int x, int y, char tchar) |
char | Get (int x, int y) |
void | Fill (int x, int y, char fromchar, char tochar) |
void | Edge (Terrain &t, int width) |
bool | Exists () |
Check if the object already exists in database. | |
int | GetX () |
int | GetY () |
int | GetZ () |
void | Save () |
Save the object in database. | |
long | GetNum () |
Get integer primary key from object. | |
void | AddPortal (int x, int y, Area &to_area, Chunk &to_chunk, int to_x, int to_y) |
void | Show (InSocket *) |
Static Public Member Functions | |
static void | RemoveObject (Area &, int x, int y, int z) |
Private Member Functions | |
void | GetInfo () |
Static Private Member Functions | |
static db::Chunk * | GetChunk (Database &, Area &, int x, int y, int z=0) |
static db::Chunk * | GetChunk (Database &, Area &, long num) |
Private Attributes | |
Area & | m_area |
db::Chunk * | m_chunk |
Static Private Attributes | |
static chunks_t | m_chunks |
Definition at line 38 of file Chunk.h.
Chunk::Chunk | ( | Database & | , | |
Area & | , | |||
long | num | |||
) |
Chunk::Chunk | ( | Database & | , | |
Area & | , | |||
int | x, | |||
int | y, | |||
int | z = 0 | |||
) |
void Chunk::Init | ( | InSocket * | , | |
int | x, | |||
int | y, | |||
int | z, | |||
char | tchar | |||
) |
Definition at line 56 of file Chunk.cpp.
References db::Chunk::area, db::Chunk::created_by, db::Chunk::created_date, Exists(), Get(), GetChunk(), Area::GetHeight(), Player::GetNum(), Area::GetNum(), Area::GetWidth(), m_area, m_chunk, Object::m_db, RemoveObject(), db::Chunk::save(), Set(), db::Chunk::terrain, db::Chunk::x, db::Chunk::y, and db::Chunk::z.
Referenced by FutureHandler::FutureHandler(), and Create::OnLine().
00057 { 00058 { 00059 db::Chunk chunk(&m_db); 00060 chunk.area = m_area.GetNum(); 00061 chunk.x = x; 00062 chunk.y = y; 00063 chunk.z = z; 00064 if (from) 00065 { 00066 Database& db = from -> GetDatabase(); 00067 Player pl(db, from -> GetAccountName()); 00068 chunk.created_by = pl.GetNum(); 00069 } 00070 else 00071 { 00072 chunk.created_by = 0; 00073 } 00074 // next line will crash when initing a new world 00075 chunk.created_date = static_cast<FutureHandler&>(from -> Handler()).GetDateTime(); 00076 while (chunk.terrain.size() < (size_t)m_area.GetWidth() * m_area.GetHeight()) 00077 chunk.terrain += tchar; 00078 chunk.save(); 00079 } 00080 Chunk::RemoveObject(m_area, x, y, z); 00081 m_chunk = Chunk::GetChunk(m_db, m_area, x, y, z); 00082 00083 Chunk cnorth(m_db, m_area, x, y + 1, z); 00084 if (cnorth.Exists()) 00085 { 00086 for (int x = 0; x < m_area.GetWidth(); x++) 00087 Set(x, 0, cnorth.Get(x, m_area.GetHeight() - 1)); 00088 } 00089 00090 Chunk csouth(m_db, m_area, x, y - 1, z); 00091 if (csouth.Exists()) 00092 { 00093 for (int x = 0; x < m_area.GetWidth(); x++) 00094 Set(x, m_area.GetHeight() - 1, csouth.Get(x, 0)); 00095 } 00096 00097 Chunk ceast(m_db, m_area, x + 1, y, z); 00098 if (ceast.Exists()) 00099 { 00100 for (int y = 0; y < m_area.GetHeight(); y++) 00101 Set(m_area.GetWidth() - 1, y, ceast.Get(0, y)); 00102 } 00103 00104 Chunk cwest(m_db, m_area, x - 1, y, z); 00105 if (cwest.Exists()) 00106 { 00107 for (int y = 0; y < m_area.GetHeight(); y++) 00108 Set(0, y, cwest.Get(m_area.GetWidth() - 1, y)); 00109 } 00110 }
void Chunk::Set | ( | int | x, | |
int | y, | |||
char | tchar | |||
) |
char Chunk::Get | ( | int | x, | |
int | y | |||
) |
Definition at line 120 of file Chunk.cpp.
References Area::GetWidth(), m_area, and m_chunk.
Referenced by Fill(), Look::getmap(), Init(), and Move::move_to().
00121 { 00122 if (m_chunk) 00123 return m_chunk -> terrain[x + y * m_area.GetWidth()]; 00124 return ' '; 00125 }
void Chunk::Fill | ( | int | x, | |
int | y, | |||
char | fromchar, | |||
char | tochar | |||
) |
Definition at line 151 of file Chunk.cpp.
References Get(), Area::GetHeight(), Area::GetWidth(), m_area, and Set().
00152 { 00153 Set(x,y,tochar); 00154 if (y > 0 && Get(x,y - 1) == fromchar) 00155 Fill(x, y - 1, fromchar, tochar); 00156 if (y < m_area.GetHeight() - 1 && Get(x,y + 1) == fromchar) 00157 Fill(x, y + 1, fromchar, tochar); 00158 if (x < m_area.GetWidth() - 1 && Get(x + 1,y) == fromchar) 00159 Fill(x + 1, y, fromchar, tochar); 00160 if (x > 0 && Get(x - 1,y) == fromchar) 00161 Fill(x - 1, y, fromchar, tochar); 00162 }
void Chunk::Edge | ( | Terrain & | t, | |
int | width | |||
) |
Definition at line 238 of file Chunk.cpp.
References Terrain::GetChar(), Area::GetHeight(), Area::GetWidth(), m_area, and Set().
00239 { 00240 if (width < m_area.GetWidth() && width < m_area.GetHeight()) 00241 { 00242 for (int w = 0; w < width; w++) 00243 { 00244 for (int x = 0; x < m_area.GetWidth(); x++) 00245 { 00246 Set(x, w, t.GetChar()); 00247 Set(x, m_area.GetHeight() - w - 1, t.GetChar()); 00248 } 00249 for (int y = 0; y < m_area.GetHeight(); y++) 00250 { 00251 Set(w, y, t.GetChar()); 00252 Set(m_area.GetWidth() - w - 1, y, t.GetChar()); 00253 } 00254 } 00255 } 00256 }
bool Chunk::Exists | ( | ) | [virtual] |
int Chunk::GetX | ( | ) |
Definition at line 220 of file Chunk.cpp.
References m_chunk.
Referenced by Player::GetCoordX(), and Look::getmap().
00221 { 00222 return m_chunk -> x; 00223 }
int Chunk::GetY | ( | ) |
Definition at line 226 of file Chunk.cpp.
References m_chunk.
Referenced by Player::GetCoordY(), and Look::getmap().
00227 { 00228 return m_chunk -> y; 00229 }
int Chunk::GetZ | ( | ) |
Definition at line 232 of file Chunk.cpp.
References m_chunk.
Referenced by Look::getmap().
00233 { 00234 return m_chunk -> z; 00235 }
void Chunk::Save | ( | ) | [virtual] |
Save the object in database.
Implements Object.
Definition at line 136 of file Chunk.cpp.
References m_chunk.
Referenced by AddPortal(), FutureHandler::FutureHandler(), and Create::OnLine().
long Chunk::GetNum | ( | ) | [virtual] |
Get integer primary key from object.
Implements Object.
Definition at line 143 of file Chunk.cpp.
References m_chunk.
Referenced by AddPortal(), Chunkinfo::GetChunkinfo(), GetInfo(), Move::move_to(), and Player::VerifyPos().
void Chunk::RemoveObject | ( | Area & | , | |
int | x, | |||
int | y, | |||
int | z | |||
) | [static] |
Definition at line 204 of file Chunk.cpp.
References Area::GetNum(), and m_chunks.
Referenced by Init().
00205 { 00206 std::list<db::Chunk *>& ref = m_chunks[area.GetNum()]; 00207 for (std::list<db::Chunk *>::iterator it = ref.begin(); it != ref.end(); it++) 00208 { 00209 db::Chunk *p = *it; 00210 if (p -> x == x && p -> y == y && p -> z == z) 00211 { 00212 delete p; 00213 ref.erase(it); 00214 return; 00215 } 00216 } 00217 }
Definition at line 274 of file Chunk.cpp.
References GetNum(), Area::GetNum(), Object::m_db, Save(), Chunkinfo::Save(), Set(), Portal::SetToArea(), Portal::SetToChunk(), Portal::SetToX(), Portal::SetToY(), Chunkinfo::SetType(), Chunkinfo::SetX(), Chunkinfo::SetY(), and Chunkinfo::TYPE_PORTAL.
00275 { 00276 Portal info(m_db, *this); 00277 info.SetX(x); 00278 info.SetY(y); 00279 info.SetType(Chunkinfo::TYPE_PORTAL); 00280 info.SetToArea(to_area.GetNum()); 00281 info.SetToChunk(to_chunk.GetNum()); 00282 info.SetToX(to_x); 00283 info.SetToY(to_y); 00284 info.Save(); 00285 Set(x, y, 'P'); 00286 Save(); 00287 }
void Chunk::Show | ( | InSocket * | ) |
Definition at line 290 of file Chunk.cpp.
References Chunkinfo::GetChunkinfo(), Player::GetChunkX(), Player::GetChunkY(), and Chunkinfo::GetInstance().
00291 { 00292 Database& db = from -> GetDatabase(); 00293 Player pl(db, from -> GetAccountName()); 00294 std::list<db::Chunkinfo *>& ref = Chunkinfo::GetChunkinfo(*this); 00295 for (std::list<db::Chunkinfo *>::iterator it = ref.begin(); it != ref.end(); it++) 00296 { 00297 db::Chunkinfo *p = *it; 00298 if (p -> x == pl.GetChunkX() && p -> y == pl.GetChunkY()) 00299 { 00300 Chunkinfo *info = Chunkinfo::GetInstance(db, *this, p -> x, p -> y, (Chunkinfo::infotype_t)p -> type); 00301 info -> Display(from); 00302 delete info; 00303 } 00304 } 00305 }
Definition at line 165 of file Chunk.cpp.
References Area::GetNum(), and m_chunks.
Referenced by Init().
00166 { 00167 std::list<db::Chunk *>& ref = m_chunks[area.GetNum()]; 00168 for (std::list<db::Chunk *>::iterator it = ref.begin(); it != ref.end(); it++) 00169 { 00170 db::Chunk *p = *it; 00171 if (p -> x == x && p -> y == y && p -> z == z) 00172 { 00173 return p; 00174 } 00175 } 00176 db::Chunk *p = new db::Chunk(db, area.GetNum(), x, y, z); 00177 p -> area = area.GetNum(); 00178 p -> x = x; 00179 p -> y = y; 00180 p -> z = z; 00181 ref.push_back(p); 00182 return p; 00183 }
Definition at line 186 of file Chunk.cpp.
References Area::GetNum(), and m_chunks.
00187 { 00188 std::list<db::Chunk *>& ref = m_chunks[area.GetNum()]; 00189 for (std::list<db::Chunk *>::iterator it = ref.begin(); it != ref.end(); it++) 00190 { 00191 db::Chunk *p = *it; 00192 if (p -> num == num) 00193 { 00194 return p; 00195 } 00196 } 00197 db::Chunk *p = new db::Chunk(db, num); 00198 p -> area = area.GetNum(); 00199 ref.push_back(p); 00200 return p; 00201 }
void Chunk::GetInfo | ( | ) | [private] |
Definition at line 259 of file Chunk.cpp.
References Exists(), GetNum(), and Object::m_db.
Referenced by Chunk().
00260 { 00261 if (!Exists()) 00262 return; 00263 Query q(m_db); 00264 q.get_result("select * from chunkinfo where chunk=" + Utility::l2string(GetNum())); 00265 while (q.fetch_row()) 00266 { 00267 db::Chunkinfo info(&m_db, &q); 00268 Chunkinfo x(m_db, *this, info.x, info.y, (Chunkinfo::infotype_t)info.type); 00269 } 00270 q.free_result(); 00271 }
Area& Chunk::m_area [private] |
db::Chunk* Chunk::m_chunk [private] |
chunks_t Chunk::m_chunks [static, private] |