Planeshift

waypoint.h

Go to the documentation of this file.
00001 /*
00002  * waypoint.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 __WAYPOINT_H__
00020 #define __WAYPOINT_H__
00021 
00022 #include <csutil/csstring.h>
00023 #include <csgeom/vector3.h>
00024 #include <iengine/sector.h>
00025 
00026 #include "util/psdatabase.h"
00027 #include "util/location.h"
00028 #include "util/pspath.h"
00029 #include "util/edge.h"
00030 
00038 class WaypointAlias
00039 {
00040 public:
00043     WaypointAlias(Waypoint* wp, int id, const csString& alias, float rotationAngle);
00044 
00047     int GetID() const { return id; }
00048     
00051     const char* GetName() const { return alias.GetDataSafe(); }
00052 
00055     float GetRotationAngle() const { return rotationAngle; }
00056 
00059     bool CreateUpdate(iDataConnection* db);
00060         
00063     bool SetRotationAngle(iDataConnection* db, float rotationAngle);
00064 
00067     void SetRotationAngle(float rotationAngle) { this->rotationAngle = rotationAngle; }
00068 
00069     Waypoint* wp;              
00070     int       id;              
00071     csString  alias;           
00072     float     rotationAngle;   
00073 };
00074 
00081 class Waypoint
00082 {
00083 public:
00084     Location                   loc;            
00085     csString                   group;          
00086     csPDelArray<WaypointAlias> aliases;        
00087 
00088     csArray<Waypoint*>         links;          
00089     csArray<float>             dists;          
00090     csPDelArray<Edge>          edges;          
00091     csArray<psPath*>           paths;          
00092     
00093     bool                       allowReturn;    
00094 
00095     bool                       underground;    
00096     bool                       underwater;     
00097     bool                       priv;           
00098     bool                       pub;            
00099     bool                       city;           
00100     bool                       indoor;         
00101     bool                       path;           
00102     bool                       road;           
00103     bool                       ground;         
00104 
00105     uint32_t                   effectID;       
00106 
00107     Waypoint();
00108     Waypoint(const char *name);
00109     Waypoint(csString& name, csVector3& pos, csString& sectorName, float radius, csString& flags);
00110     
00111     
00112     bool operator==(Waypoint& other) const
00113     { return loc.name==other.loc.name; }
00114     bool operator<(Waypoint& other) const
00115     { return (strcmp(loc.name,other.loc.name)<0); }
00116 
00117     bool Load(iDocumentNode *node, iEngine *engine);
00118     bool Import(iDocumentNode *node, iEngine *engine, iDataConnection *db);
00119     bool Load(iResultRow& row, iEngine *engine); 
00120 
00121     void AddLink(psPath * path, Waypoint * wp, psPath::Direction direction, float distance);
00122     void RemoveLink(psPath * path);
00123 
00124     Edge* GetRandomEdge(const psPathNetwork::RouteFilter* routeFilter);
00125 
00126 
00128     WaypointAlias* AddAlias(int id, csString aliasName, float rotationAngle);
00129     
00131     void RemoveAlias(csString aliasName);
00132 
00134     int          GetID() const { return loc.id; }
00135     void SetID(int id);
00136     
00138     const char * GetName() const { return loc.name.GetDataSafe(); }
00139 
00141     bool Rename(iDataConnection * db,const char* name);
00143     void Rename(const char* name);
00144 
00146     const char* GetGroup(){ return group.GetDataSafe(); }
00147     
00149     csString GetAliases();
00150 
00153     const WaypointAlias* FindAlias(const csString& aliasName) const;
00154 
00157     WaypointAlias* FindAlias(const csString& aliasName);
00158 
00159     
00162     bool SetRotationAngle(const csString& aliasName, float rotationAngle);
00163     
00164     
00166     iSector*     GetSector(iEngine * engine) { return loc.GetSector(engine); }
00167     iSector*     GetSector(iEngine * engine) const { return loc.GetSector(engine); }
00168     
00169     csString     GetFlags() const;
00170 
00171     float GetRadius() const  { return loc.radius; }
00172     bool SetRadius(float radius);
00173     bool SetRadius(iDataConnection * db, float radius);
00174     void RecalculateEdges(psWorld * world, iEngine *engine);
00175 
00176     const csVector3& GetPosition() const { return loc.pos; }
00177 
00178     bool CheckWithin(iEngine * engine, const csVector3& pos, const iSector* sector);
00179 
00180     int Create(iDataConnection * db);
00181     WaypointAlias* CreateAlias(iDataConnection * db, csString alias, float rotationAngle);
00182     bool RemoveAlias(iDataConnection * db, csString alias);
00183     bool Adjust(iDataConnection * db, csVector3 & pos, csString sector);
00184     void Adjust(csVector3 & pos, csString sector);
00185     void Adjust(csVector3 & pos, iSector* sector);
00186     
00188     void SetFlags(const csString& flagStr);
00189 
00200     bool SetFlag(iDataConnection * db, const csString &flagstr, bool enable);
00201 
00211     bool SetFlag(const csString &flagstr, bool enable);    
00212 
00216     uint32_t GetEffectID(iEffectIDAllocator* allocator);
00217 
00219     float distance; 
00220     Waypoint * pi;  
00221     bool excluded;  
00222 
00223 };
00224 
00227 #endif