-
Notifications
You must be signed in to change notification settings - Fork 19
/
NodeMachine.h
229 lines (155 loc) · 7.1 KB
/
NodeMachine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/**
* RealBot : Artificial Intelligence
* Version : Work In Progress
* Author : Stefan Hendriks
* Url : http://realbot.bots-united.com
**
* DISCLAIMER
*
* History, Information & Credits:
* RealBot is based partially upon the HPB-Bot Template #3 by Botman
* Thanks to Ditlew (NNBot), Pierre Marie Baty (RACCBOT), Tub (RB AI PR1/2/3)
* Greg Slocum & Shivan (RB V1.0), Botman (HPB-Bot) and Aspirin (JOEBOT). And
* everybody else who helped me with this project.
* Storage of Visibility Table using BITS by Cheesemonster.
*
* Some portions of code are from other bots, special thanks (and credits) go
* to (in no specific order):
*
* Pierre Marie Baty
* Count-Floyd
*
* !! BOTS-UNITED FOREVER !!
*
* This project is open-source, it is protected under the GPL license;
* By using this source-code you agree that you will ALWAYS release the
* source-code with your project.
*
**/
/**
* NODE MACHINE
* COPYRIGHTED BY STEFAN HENDRIKS (C)
**/
#ifndef NODEMACHINE_H
#define NODEMACHINE_H
#include "bot.h"
#include "NodeDataTypes.h"
// CLASS: NodeMachine
class cNodeMachine {
public:
// -----------------
int addNode(Vector vOrigin, edict_t *pEntity);
int Reachable(const int iStart, const int iEnd);
int add2(Vector vOrigin, int iType, edict_t *pEntity);
int getClosestNode(Vector vOrigin, float fDist, edict_t *pEdict); // returns a close node
int getFurthestNode(Vector vOrigin, float fDist, edict_t *pEdict); // returns a node within dist, but most far away
int getFreeNodeIndex();
// -----------------
bool add_neighbour_node(int iNode, int iToNode);
bool removeConnection(int iFrom, int iTo);
bool remove_neighbour_nodes(int iNode);
int freeNeighbourNodeIndex(tNode *Node);
int is_neighbour_node(tNode node, int iNode);
// -----------------
void init(); // Init (info)nodes
void save(); // Save nodes on disk
void load(); // Load nodes on disk
void save_important();
// -----------------
Vector node_vector(int iNode);
// -----------------
int GetTroubleIndexForConnection(int iFrom, int iTo);
int AddTroubledConnection(int iFrom, int iTo);
bool IncreaseAttemptsForTroubledConnectionOrRemoveIfExceeded(int iFrom, int iTo);
bool hasAttemptedConnectionTooManyTimes(int index);
void IncreaseAttemptsForTroubledConnection(int index);
bool ClearTroubledConnection(int iFrom, int iTo);
// -----------------
void setUpInitialGoals(); // find new goals and attach them to the nodes
void updateGoals(); // update moving goals (ie hostages)
int getGoalIndexFromNode(int iNode);
void resetCheckedValuesForGoals();
void ClearImportantGoals();
bool hasGoalWithEdict(edict_t *pEdict);
void addGoal(edict_t *pEdict, int goalType, Vector vVec);
tGoal * getRandomGoalByType(int goalType); // return a node close to a iType goal (random)
bool node_float(Vector vOrigin, edict_t *pEdict);
bool node_on_crate(Vector vOrigin, edict_t *pEdict);
int node_dangerous(int iTeam, Vector vOrigin, float fMaxDistance);
int node_look_camp(Vector vOrigin, int iTeam, edict_t *pEdict);
// -----------------
void danger(int iNode, int iTeam); // Make spot dangerous
void scale_danger();
// -----------------
void contact(int iNode, int iTeam); // Add contact area
void scale_contact();
// -----------------
void experience_save();
void experience_load();
// -----------------
int node_cover(int iFrom, int iTo, edict_t *pEdict);
int node_look_at_hear(int iFrom, int iTo, edict_t *pEdict);
int node_camp(Vector vOrigin, int iTeam);
void vis_calculate(int iFrom);
// -----------------
bool createPath(int nodeStartIndex, int nodeTargetIndex, int botIndex, cBot *pBot, int iFlags); // know the path
void path_draw(edict_t *pEntity); // draw the path
void path_walk(cBot *pBot, float distanceMoved); // walk the path
void path_think(cBot *pBot, float distanceMoved); // think about paths
void path_clear(int botIndex);
void ExecuteNearNodeLogic(cBot *pBot);
int getNodeIndexFromBotForPath(int botIndex, int pathNodeIndex);
// -----------------
void VectorToMeredian(Vector vOrigin, int *iX, int *iY); // Input: origin, output X and Y Meredians
void AddToMeredian(int iX, int iY, int iNode);
// -----------------
void draw(edict_t *pEntity); // Draw nodes
void connections(edict_t *pEntity); // Draw neighbours
// -----------------
void addNodesForPlayers(); // Players plot around!
void init_players(); // Initialize players (dll load)
void init_round(); // Initialize on round start
// -------------------
// From cheesemonster:
int GetVisibilityFromTo(int iFrom, int iTo); // BERKED
void ClearVisibilityTable(void);
void SetVisibilityFromTo(int iFrom, int iTo, bool bVisible);
void FreeVisibilityTable(void);
// Some debugging by EVY
void dump_goals(void);
void dump_path(int iBot, int ThisNode);
void Draw(void);
tNode *getNode(int index);
tGoal *getGoal(int index);
private:
tNode Nodes[MAX_NODES]; // Nodes
tInfoNode InfoNodes[MAX_NODES]; // Info for Nodes (metadata)
tPlayer Players[32]; // Players to keep track of, for node plotting
tGoal Goals[MAX_GOALS]; // Goals to pursue in the game
tMeredian Meredians[MAX_MEREDIANS][MAX_MEREDIANS]; // Meredian lookup search for Nodes, squared
int iPath[MAX_BOTS][MAX_PATH_NODES]; // 32 bots, with max waypoints paths (TODO: move to bot class?)
int iMaxUsedNodes;
byte iVisChecked[MAX_NODES];
unsigned char *cVisTable;
tTrouble Troubles[MAX_TROUBLE];
void FindMinMax(void);
void MarkAxis(void);
void MarkMeredians(void);
void PlotNodes(int NeighbourColor, int NodeColor);
void PlotPaths(int Tcolor, int CTcolor);
void PlotGoals(int GoalColor);
void makeAllWaypointsAvailable() const;
void closeNode(int nodeIndex, int parent, float cost);
void openNeighbourNodes(int startNodeIndex, int nodeToOpenNeighboursFrom, int destinationNodeIndex, int botTeam);
char *getGoalTypeAsText(const tGoal &goal) const;
int getFreeGoalIndex() const;
void initGoals();
void initGoal(int g);
bool isEntityDoor(const edict_t *pEntityHit) const;
bool isEntityHostage(const edict_t *pEntityHit) const;
bool isEntityWorldspawn(const edict_t *pEntityHit) const;
bool isDoorThatOpensWhenPressingUseButton(const edict_t *pEntityHit) const;
void ExecuteIsStuckLogic(cBot *pBot, int currentNodeToHeadFor, Vector &vector);
void ExecuteDoorInteractionLogic(cBot *pBot, edict_t *pS);
};
#endif // NODEMACHINE_H