1 // 2 // C++ Implementation: bot_waypoint.h 3 // 4 // Description: Containts all defintions for bot waypoint code 5 // 6 // 7 // Author: Rick Helmus <rickhelmus@gmail.com> 8 // 9 10 // Enable this for flood support 11 #define WP_FLOOD 12 13 #ifndef BOT_WAYPOINT_H 14 #define BOT_WAYPOINT_H 15 16 #define WAYPOINT_VERSION 2 17 #define EXP_WP_VERSION 1 18 #define REACHABLE_RANGE 15.0f 19 #define MAX_MAP_GRIDS 64 20 #define SECTOR_SIZE 18 21 22 #define W_FL_TELEPORT (1<<1) // used if waypoint is at a teleporter 23 #define W_FL_TELEPORTDEST (1<<2) // used if waypoint is at a teleporter destination 24 #define W_FL_FLOOD (1<<3) // used if this waypoint is made by flooding the map 25 #define W_FL_JUMP (1<<4) // if set, bot jumps when reached this waypoint 26 #define W_FL_TRIGGER (1<<5) // used if this waypoint is at a trigger 27 #define W_FL_INTAG (1<<6) // used if this waypoint is in a tagged cube 28 29 #define MAX_FLOODWPCONNECTDIST 2 30 #define MAX_FLOODWPDIST 4.0f 31 32 struct waypoint_header_s 33 { 34 char szFileType[10]; 35 int iFileVersion; 36 int iFileFlags; // not currently used 37 int iWPCount; 38 char szMapName[32]; // name of map for these waypoints 39 }; 40 41 // Old waypoint structure, used for waypoint version 1 42 struct waypoint_version_1_s 43 { 44 int iFlags; 45 vec v_origin; 46 TLinkedList<waypoint_version_1_s *> ConnectedWPs; 47 48 // A* stuff 49 float f, g; 50 waypoint_version_1_s *pParent; 51 52 // Construction waypoint_version_1_swaypoint_version_1_s53 waypoint_version_1_s(void) : iFlags(0), f(0.0f), g(0.0f), pParent(NULL) { }; 54 }; 55 56 struct node_s 57 { 58 vec v_origin; 59 int iFlags; 60 short sTriggerNr; 61 short sYaw; 62 short sCost; // Base and static cost 63 TLinkedList<node_s *> ConnectedWPs; 64 TLinkedList<node_s *> ConnectedWPsWithMe; 65 66 TLinkedList<node_s *> FailedGoalList; 67 68 // Construction node_snode_s69 node_s(void) : iFlags(0), sTriggerNr(0), sYaw(-1), sCost(10) { }; v_originnode_s70 node_s(const vec &o, const int &f, const short t=0, const short y=-1) : v_origin(o), 71 iFlags(f), 72 sTriggerNr(t), 73 sYaw(y), 74 sCost(0) { }; 75 }; 76 77 struct waypoint_s 78 { 79 node_s *pNode; 80 short g[2]; 81 waypoint_s *pParent[2]; 82 bool bIsOpen[2], bIsClosed[2]; 83 84 // Construction waypoint_swaypoint_s85 waypoint_s(void) : pNode(NULL) { bIsOpen[0] = bIsOpen[1] = bIsClosed[0] = 86 bIsClosed[1] = false; pParent[0] = pParent[1] = NULL; 87 g[0] = g[1] = 0; }; 88 }; 89 90 class CWaypointClass 91 { 92 protected: 93 bool m_bDrawWaypoints; 94 bool m_bDrawWPPaths; 95 bool m_bAutoWaypoint; 96 bool m_bAutoPlacePaths; 97 bool m_bDrawWPText; 98 vec m_vLastCreatedWP; 99 float m_fPathDrawTime; 100 char m_szMapName[32]; 101 102 #ifdef WP_FLOOD 103 bool m_bFlooding; // True if flooding map with waypoints 104 bool m_bFilteringNodes; 105 int m_iFloodStartTime; 106 int m_iCurFloodX, m_iCurFloodY; 107 int m_iFloodSize; 108 int m_iFilteredNodes; 109 #endif 110 friend class CBot; 111 112 public: 113 TLinkedList<node_s *> m_Waypoints[MAX_MAP_GRIDS][MAX_MAP_GRIDS]; 114 int m_iWaypointCount; // number of waypoints currently in use 115 116 CWaypointClass(void); ~CWaypointClass(void)117 virtual ~CWaypointClass(void) { Clear(); }; 118 119 void Think(void); 120 void Init(void); 121 void Clear(void); 122 bool LoadWaypoints(void); 123 void SaveWaypoints(void); 124 bool LoadWPExpFile(void); 125 void SaveWPExpFile(void); SetMapName(const char * map)126 void SetMapName(const char *map) { strcpy(m_szMapName, map); }; 127 SetWaypointsVisible(bool Visible)128 void SetWaypointsVisible(bool Visible) { m_bDrawWaypoints = Visible; }; SetPathsVisible(bool Visible)129 void SetPathsVisible(bool Visible) { m_bDrawWPPaths = Visible; }; SetAutoWaypoint(bool On)130 void SetAutoWaypoint(bool On) { m_bAutoWaypoint = On; }; SetWPInfo(bool on)131 void SetWPInfo(bool on) { m_bDrawWPText = on; }; SetWPFlags(node_s * wp,int iFlags)132 void SetWPFlags(node_s *wp, int iFlags) { wp->iFlags |= iFlags; }; UnsetWPFlags(node_s * wp,int iFlags)133 void UnsetWPFlags(node_s *wp, int iFlags) { wp->iFlags &= ~iFlags; }; SetWPTriggerNr(node_s * wp,short sTriggerNr)134 void SetWPTriggerNr(node_s *wp, short sTriggerNr) { wp->sTriggerNr = sTriggerNr; }; SetWPYaw(node_s * wp,short sYaw)135 void SetWPYaw(node_s *wp, short sYaw) { wp->sYaw = sYaw; }; WaypointsAreVisible(void)136 bool WaypointsAreVisible(void) { return m_bDrawWaypoints; }; 137 node_s *AddWaypoint(vec o, bool connectwp); 138 void DeleteWaypoint(vec v_src); 139 void AddPath(node_s *pWP1, node_s *pWP2); 140 void DeletePath(node_s *pWP); 141 void DeletePath(node_s *pWP1, node_s *pWP2); 142 void ManuallyCreatePath(vec v_src, int iCmd, bool TwoWay); 143 void ManuallyDeletePath(vec v_src, int iCmd, bool TwoWay); 144 145 bool WPIsReachable(vec from, vec to); 146 //node_s *GetNearestWaypoint(vec v_src, float flRange, bool CheckVisible = true, bool SkipFloodWPs = true); 147 node_s *GetNearestWaypoint(vec v_src, float flRange); GetNearestWaypoint(dynent * d,float flRange)148 node_s *GetNearestWaypoint(dynent *d, float flRange) { return GetNearestWaypoint(d->o, flRange); }; 149 node_s *GetNearestTriggerWaypoint(vec v_src, float flRange); 150 node_s *GetWaypointFromVec(const vec &v_src); 151 void DrawNearWaypoints(); 152 void GetNodeIndexes(const vec &v_origin, short *i, short *j); 153 void CalcCost(node_s *pNode); 154 void ReCalcCosts(void); 155 156 157 #ifdef WP_FLOOD 158 // Flood functions 159 virtual void StartFlood(void); 160 void StopFlood(void); 161 void FloodThink(void); 162 bool CanPlaceNodeHere(const vec &from); 163 void ConnectFloodWP(node_s *pWP); 164 node_s *GetNearestFloodWP(vec v_origin, float flRange, node_s *pIgnore, bool SkipTags=false); GetNearestFloodWP(dynent * d,float flRange)165 node_s *GetNearestFloodWP(dynent *d, float flRange) { return GetNearestFloodWP(d->o, flRange, NULL); }; 166 node_s *GetNearestTriggerFloodWP(vec v_origin, float flRange); 167 #endif 168 }; 169 170 class CACWaypointClass: public CWaypointClass 171 { 172 public: 173 #ifdef WP_FLOOD 174 // Flood functions 175 virtual void StartFlood(void); 176 #endif 177 }; 178 179 class CCubeWaypointClass: public CWaypointClass 180 { 181 public: 182 void CreateWPsAtTeleporters(void); 183 void CreateWPsAtTriggers(void); 184 185 #ifdef WP_FLOOD 186 // Flood functions 187 virtual void StartFlood(void); 188 #endif 189 }; 190 191 #endif // BOT_WAYPOINT_H 192