Planeshift
|
00001 /* 00002 * location.h 00003 * 00004 * Copyright (C) 2004 Atomic Blue ([email protected], http://www.atomicblue.org) 00005 * 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation (version 2 of the License) 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * 00018 */ 00019 #ifndef __LOCATION_H__ 00020 #define __LOCATION_H__ 00021 00022 #include <csutil/csstring.h> 00023 #include <csgeom/vector3.h> 00024 #include <csgeom/box.h> 00025 #include <csutil/parray.h> 00026 #include <csutil/list.h> 00027 #include <iengine/sector.h> 00028 #include <csutil/weakref.h> 00029 00030 #include "util/psconst.h" 00031 #include "util/psdatabase.h" 00032 00033 struct iEngine; 00034 class LocationType; 00035 class psWorld; 00036 class iEffectIDAllocator; 00037 00048 class Location 00049 { 00050 public: 00051 int id; 00052 csString name; 00053 csVector3 pos; 00054 float rot_angle; 00055 float radius; 00056 csArray<Location*> locs; 00057 int id_prev_loc_in_region; 00058 csString sectorName; 00059 00060 csBox2 boundingBox; 00061 csWeakRef<iSector> sector; 00062 LocationType* type; 00063 uint32_t effectID; 00064 Location* region; 00065 00068 Location(); 00069 00072 Location(LocationType* locationType, const char* locationName, const csVector3 &pos, iSector* sector, float radius, float rot_angle, const csString &flags); 00073 00076 ~Location(); 00077 00080 int GetID() const 00081 { 00082 return id; 00083 } 00084 00087 void SetID(int id) 00088 { 00089 this->id = id; 00090 } 00091 00094 const csVector3 &GetPosition() const 00095 { 00096 return pos; 00097 } 00098 00102 csString GetFlags() const 00103 { 00104 return csString(); 00105 } 00106 00110 bool SetFlags(const csString &flags) 00111 { 00112 return false; 00113 } 00114 00118 bool SetFlag(const csString &flag, bool enable) 00119 { 00120 return false; 00121 } 00122 00125 float GetRadius() const 00126 { 00127 return radius; 00128 } 00129 00132 bool SetRadius(iDataConnection* db, float radius); 00133 00136 void SetRadius(float radius); 00137 00140 float GetRotationAngle() const 00141 { 00142 return rot_angle; 00143 } 00144 00147 const char* GetTypeName() const; 00148 00151 bool Load(iResultRow &row, iEngine* engine, iDataConnection* db); 00152 00156 bool CreateUpdate(iDataConnection* db); 00157 00160 bool Import(iDocumentNode* node, iDataConnection* db, int typeID); 00161 00167 bool IsRegion() 00168 { 00169 return locs.GetSize() != 0; 00170 } 00171 00174 bool IsCircle() 00175 { 00176 return locs.GetSize() == 0; 00177 } 00178 00181 iSector* GetSector(iEngine* engine); 00182 00185 iSector* GetSector(iEngine* engine) const; 00186 00191 const csBox2 &GetBoundingBox() const; 00192 00198 void CalculateBoundingBox(); 00199 00202 bool CheckWithinBounds(iEngine* engine,const csVector3 &pos,const iSector* sector); 00203 00215 bool GetRandomPosition(iEngine* engine,csVector3 &pos,iSector* §or); 00216 00219 static int GetSectorID(iDataConnection* db, const char* name); 00220 00223 const char* GetName() const 00224 { 00225 return name.GetDataSafe(); 00226 } 00227 00230 void SetName(const csString &name) 00231 { 00232 this->name = name; 00233 } 00234 00238 uint32_t GetEffectID(iEffectIDAllocator* allocator); 00239 00242 bool Adjust(iDataConnection* db, const csVector3 &pos, iSector* sector); 00243 00246 bool Adjust(iDataConnection* db, const csVector3 &pos, iSector* sector, float rot_angle); 00247 00250 bool Adjust(const csVector3 &pos, iSector* sector); 00251 00254 bool Adjust(const csVector3 &pos, iSector* sector, float rot_angle); 00255 00258 Location* Insert(iDataConnection* db, csVector3 &pos, iSector* sector); 00259 00262 Location* Insert(int id, csVector3 &pos, iSector* sector); 00263 00266 csString ToString() const; 00267 }; 00268 00275 class LocationType 00276 { 00277 public: 00278 int id; 00279 csString name; 00280 csArray<Location*> locs; 00281 00284 LocationType(); 00285 00288 LocationType(int id, const csString &name); 00289 00292 ~LocationType(); 00293 00297 bool CreateUpdate(iDataConnection* db); 00298 00301 bool Load(iDocumentNode* node); 00302 bool Import(iDocumentNode* node, iDataConnection* db); 00303 bool ImportLocations(iDocumentNode* node, iDataConnection* db); 00304 00307 bool Load(iResultRow &row, iEngine* engine, iDataConnection* db); 00308 00311 void AddLocation(Location* location); 00312 00315 void RemoveLocation(Location* location); 00316 00319 bool CheckWithinBounds(iEngine* engine,const csVector3 &pos,const iSector* sector); 00320 00333 bool GetRandomPosition(iEngine* engine,csVector3 &pos,iSector* §or, const iSector* inSector); 00334 00337 int GetID() const 00338 { 00339 return id; 00340 } 00341 00344 const char* GetName() const 00345 { 00346 return name.GetDataSafe(); 00347 } 00348 }; 00349 00353 class LocationManager 00354 { 00355 public: 00358 LocationManager(); 00359 00362 virtual ~LocationManager(); 00363 00366 bool Load(iEngine* engine, iDataConnection* db); 00367 00370 int GetNumberOfLocations() const; 00371 00374 Location* GetLocation(int index); 00375 00378 LocationType* FindRegion(const char* regname); 00379 00382 LocationType* FindLocation(const char* typeName); 00383 00386 Location* FindLocation(const char* typeName, const char* name); 00387 00390 Location* FindLocation(LocationType* type, const char* name); 00391 00394 Location* FindLocation(int id); 00395 00398 size_t FindLocationsInSector(iEngine* engine, iSector* sector, csList<Location*> &list); 00399 00402 Location* FindNearestLocation(psWorld* world, csVector3 &pos, iSector* sector, float range, float* found_range); 00403 00406 Location* FindNearestLocation(psWorld* world, const char* typeName, csVector3 &pos, iSector* sector, float range, float* found_range); 00407 00410 Location* FindRandomLocation(psWorld* world, const char* typeName, csVector3 &pos, iSector* sector, float range, float* found_range); 00411 00414 csHash<LocationType*, csString>::GlobalIterator GetIterator(); 00415 00418 Location* CreateLocation(iDataConnection* db, LocationType* locationType, const char* locationName, 00419 const csVector3 &pos, iSector* sector, float radius, float rot_angle, 00420 const csString &flags); 00421 00424 Location* CreateLocation(const char* locationTypeName, const char* locationName, 00425 const csVector3 &pos, iSector* sector, float radius, float rot_angle, 00426 const csString &flags); 00427 00430 Location* CreateLocation(LocationType* locationType, const char* locationName, 00431 const csVector3 &pos, iSector* sector, float radius, float rot_angle, 00432 const csString &flags); 00433 00436 LocationType* CreateLocationType(iDataConnection* db, const csString &locationName); 00437 00440 LocationType* CreateLocationType(const csString &locationName); 00441 00444 LocationType* CreateLocationType(int id, const csString &locationName); 00445 00448 bool RemoveLocationType(iDataConnection* db, const csString &locationName); 00449 00452 bool RemoveLocationType(const csString &locationName); 00453 00454 private: 00455 csHash<LocationType*, csString> loctypes; 00456 csArray<Location*> all_locations; 00457 }; 00458 00461 #endif 00462