Planeshift
waypoint.h
Go to the documentation of this file.
1 /*
2  * waypoint.h
3  *
4  * Copyright (C) 2004 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 #ifndef __WAYPOINT_H__
20 #define __WAYPOINT_H__
21 
22 #include <csutil/csstring.h>
23 #include <csgeom/vector3.h>
24 #include <iengine/sector.h>
25 
26 #include "util/psdatabase.h"
27 #include "util/location.h"
28 #include "util/pspath.h"
29 #include "util/edge.h"
30 
39 {
40 public:
43  WaypointAlias(Waypoint* wp, int id, const csString& alias, float rotationAngle);
44 
47  int GetID() const { return id; }
48 
51  const char* GetName() const { return alias.GetDataSafe(); }
52 
55  float GetRotationAngle() const { return rotationAngle; }
56 
59  bool CreateUpdate(iDataConnection* db);
60 
63  bool SetRotationAngle(iDataConnection* db, float rotationAngle);
64 
67  void SetRotationAngle(float rotationAngle) { this->rotationAngle = rotationAngle; }
68 
70  int id;
71  csString alias;
72  float rotationAngle;
73 };
74 
81 class Waypoint
82 {
83 public:
85  csString group;
86  csPDelArray<WaypointAlias> aliases;
87 
88  csArray<Waypoint*> links;
89  csArray<float> dists;
90  csPDelArray<Edge> edges;
91  csArray<psPath*> paths;
92 
93  bool allowReturn;
94  bool underground;
96  bool underwater;
97  bool priv;
98  bool pub;
99  bool city;
100  bool indoor;
101  bool path;
102  bool road;
103  bool ground;
104 
105  uint32_t effectID;
106 
107  Waypoint();
108  Waypoint(const char *name);
109  Waypoint(csString& name, csVector3& pos, csString& sectorName, float radius, csString& flags);
110 
111 
112  bool operator==(Waypoint& other) const
113  { return loc.name==other.loc.name; }
114  bool operator<(Waypoint& other) const
115  { return (strcmp(loc.name,other.loc.name)<0); }
116 
117  bool Load(iDocumentNode *node, iEngine *engine);
118  bool Import(iDocumentNode *node, iEngine *engine, iDataConnection *db);
119  bool Load(iResultRow& row, iEngine *engine);
120 
121  void AddLink(psPath * path, Waypoint * wp, psPath::Direction direction, float distance);
122  void RemoveLink(psPath * path);
123 
124  Edge* GetRandomEdge(const psPathNetwork::RouteFilter* routeFilter);
125 
126 
128  WaypointAlias* AddAlias(int id, csString aliasName, float rotationAngle);
129 
131  void RemoveAlias(csString aliasName);
132 
134  int GetID() const { return loc.id; }
135  void SetID(int id);
136 
138  const char * GetName() const { return loc.name.GetDataSafe(); }
139 
141  bool Rename(iDataConnection * db,const char* name);
143  void Rename(const char* name);
144 
146  const char* GetGroup(){ return group.GetDataSafe(); }
147 
149  csString GetAliases();
150 
153  const WaypointAlias* FindAlias(const csString& aliasName) const;
154 
157  WaypointAlias* FindAlias(const csString& aliasName);
158 
159 
162  bool SetRotationAngle(const csString& aliasName, float rotationAngle);
163 
164 
166  iSector* GetSector(iEngine * engine) { return loc.GetSector(engine); }
167  iSector* GetSector(iEngine * engine) const { return loc.GetSector(engine); }
168 
169  csString GetFlags() const;
170 
171  float GetRadius() const { return loc.radius; }
172  bool SetRadius(float radius);
173  bool SetRadius(iDataConnection * db, float radius);
174  void RecalculateEdges(psWorld * world, iEngine *engine);
175 
176  const csVector3& GetPosition() const { return loc.pos; }
177 
178  bool CheckWithin(iEngine * engine, const csVector3& pos, const iSector* sector);
179 
180  int Create(iDataConnection * db);
181  WaypointAlias* CreateAlias(iDataConnection * db, csString alias, float rotationAngle);
182  bool RemoveAlias(iDataConnection * db, csString alias);
183  bool Adjust(iDataConnection * db, csVector3 & pos, csString sector);
184  void Adjust(csVector3 & pos, csString sector);
185  void Adjust(csVector3 & pos, iSector* sector);
186 
188  void SetFlags(const csString& flagStr);
189 
200  bool SetFlag(iDataConnection * db, const csString &flagstr, bool enable);
201 
211  bool SetFlag(const csString &flagstr, bool enable);
212 
216  uint32_t GetEffectID(iEffectIDAllocator* allocator);
217 
219  float distance;
221  bool excluded;
222 
223 };
224 
227 #endif
psWorld is in charge of managing all regions (zone map files) and loading/unloading them as needed...
Definition: psworld.h:47
WaypointAlias(Waypoint *wp, int id, const csString &alias, float rotationAngle)
Constructor.
csString group
Hold group name for this waypoint if any.
Definition: waypoint.h:85
bool indoor
True if this waypoint is indoor.
Definition: waypoint.h:100
iSector * GetSector(iEngine *engine)
Return cached sector or find the sector and cache it from engine.
iSector * GetSector(iEngine *engine)
Get the sector from the location.
Definition: waypoint.h:166
const char * GetName() const
Get the name of this waypoint.
Definition: waypoint.h:138
Class to hold information regarding aliases for waypoints.
Definition: waypoint.h:38
csPDelArray< Edge > edges
Edges for each link.
Definition: waypoint.h:90
Location loc
Id and position.
Definition: waypoint.h:84
bool ground
True if this waypoint is ground.
Definition: waypoint.h:103
csPDelArray< WaypointAlias > aliases
Hold aliases for this waypoint.
Definition: waypoint.h:86
csArray< Waypoint * > links
Links to other waypoinst connected with paths from this node.
Definition: waypoint.h:88
float GetRadius() const
Definition: waypoint.h:171
bool underwater
True if this waypoint is underwater.
Definition: waypoint.h:96
Definition: pspath.h:152
csString alias
An alias for an waypoint.
Definition: waypoint.h:71
float GetRotationAngle() const
Get the Rotation Angle of this alias.
Definition: waypoint.h:55
const char * GetGroup()
Get the group name of this waypoint.
Definition: waypoint.h:146
void SetFlag(const char *name, bool flag, uint32 filter)
Direction
Definition: pspath.h:156
iSector * GetSector(iEngine *engine) const
Definition: waypoint.h:167
Represents the Edge in a PathNetwork.
Definition: edge.h:39
int GetID() const
Get the DB id for this alias.
Definition: waypoint.h:47
A waypoint is a specified circle on the map with a name, location, and a list of waypoints it is conn...
Definition: waypoint.h:81
float distance
Data used in the dijkstra&#39;s algorithm to find waypoint path.
Definition: waypoint.h:219
bool road
True if this waypoint is a road/street.
Definition: waypoint.h:102
bool excluded
Predecessor WP to track shortest way back to start.
Definition: waypoint.h:221
bool path
True if this waypoint is a path.
Definition: waypoint.h:101
csString name
The name of this location.
Definition: location.h:52
bool pub
True if this waypoint is public.
Definition: waypoint.h:98
csVector3 pos
The positon of this location.
Definition: location.h:53
bool operator==(Waypoint &other) const
Definition: waypoint.h:112
iDataConnection * db
Global connection to the Database. Set from the psDatabase class.
uint32_t effectID
When displayed in a client this is the effect id.
Definition: waypoint.h:105
Waypoint * pi
Hold current shortest distance to the start WP.
Definition: waypoint.h:220
bool SetRotationAngle(iDataConnection *db, float rotationAngle)
Set a new rotation angle for this waypoint.
int id
The ID of this location, from the DB.
Definition: location.h:51
int GetID() const
Get the id of this waypoint.
Definition: waypoint.h:134
bool priv
True if this waypoint is private.
Definition: waypoint.h:97
float radius
The radius of this locaiton.
Definition: location.h:55
csArray< float > dists
Distances of each link.
Definition: waypoint.h:89
bool operator<(Waypoint &other) const
Definition: waypoint.h:114
bool CreateUpdate(iDataConnection *db)
Crate or update a waypoint alias.
Helper interface to allocate effect IDs.
Definition: pspath.h:48
int id
The ID of this waypoint alias in DB.
Definition: waypoint.h:70
const csVector3 & GetPosition() const
Definition: waypoint.h:176
Waypoint * wp
The waypoint this alias is a part of.
Definition: waypoint.h:69
float rotationAngle
The direction the NPC should face when placed on this waypoint.
Definition: waypoint.h:72
csArray< psPath * > paths
Path object for each of the links.
Definition: waypoint.h:91
bool city
True if this waypoint is in a city.
Definition: waypoint.h:99
Template class for implementing waypoint filtering when calculating routes.
Definition: pspathnetwork.h:49
A Location is a named place on the map, located dynamically by NPCs as scripted.
Definition: location.h:48
void SetRotationAngle(float rotationAngle)
Set a new rotation angle for this waypoint.
Definition: waypoint.h:67
const char * GetName() const
Get the Name of this alias.
Definition: waypoint.h:51
bool allowReturn
This prevents the link back to the prior waypoint < from being chosen, if true.
Definition: waypoint.h:93