reverted Urre's changes (avoid loading navnodes when bots are disabled)
[divverent/nexuiz.git] / data / qcsrc / server / gamec / bots.c
1 float BOT_TYPE_AUTOURRE = 0;
2 float BOT_TYPE_AUTOMAUVE = 1;
3 float BOT_TYPE_URREBOT = 2;
4 float BOT_TYPE_MAUVEBOT = 3;
5 .float bot_type;
6 float bot_number;
7
8 /*
9 MauveBot v1.0 for Nexuiz
10 */
11
12 float intermission_running;
13
14 .float skill_level;
15
16 .float ai_time;
17 .float threat;
18 .entity dodgeent;
19
20 float THREAT_UNFLAGGED = 0;
21 float THREAT_IGNORE = -1;
22
23 float DODGE_DIST = 500;
24 float SEARCH_DIST = 1000;
25
26 .float search_time;
27
28 float mauvebots;
29
30 entity(float bottype) add_MauveBot;
31 void() remove_MauveBot;
32
33 /*
34 UrreBot 1.5 for Nexuiz
35 */
36
37 entity navnode_chain, urrebot_chain;
38 float navnodes, loadstep;
39 .entity list, link0, link1, link2, link3, link4, link5, link6, link7, link8, link9;
40 .entity link10, link11, link12, link13, link14, link15, link16, link17, link18, link19;
41 .float sflags;
42 .float lflags0, lflags1, lflags2, lflags3, lflags4, lflags5, lflags6, lflags7, lflags8, lflags9;
43 .float lflags10, lflags11, lflags12, lflags13, lflags14, lflags15, lflags16, lflags17, lflags18, lflags19;
44 .vector pointl;
45 .float costl;
46 .float lmark;
47 float search_distance;
48 float minisearch_distance;
49 float stratsearch_distance;
50 .entity goalcurrent;
51 .entity goallist;
52 .float strat_me;
53 .float(entity c_item) evalfunc;
54
55 vector nullvector;
56 .vector movepoint;
57 .float camptime;
58 .vector campcheck;
59
60 .vector aimpoint;
61 .float aimtime;
62 .float evaltime;
63 .float lead;
64
65 float skill;
66
67 float S_TELEPORT = 1;
68 float S_DOOR = 2;
69 float S_TOUCH = 4;
70
71 float LF_NOLINK = 1;
72 float LF_NOWALK = 2;
73 float LF_BAD = 4;
74 float LF_BIGDROP = 8;
75 float LF_REMOTE = 16;
76
77 .entity optp_chain;
78
79 .entity plane_chain;
80
81 float urrebots, urrebots_strategytime, urrebots_combattime, urrebots_navopt;
82
83 entity strategytoken;
84 float strategytime;
85 .float combattime;
86
87 entity(vector org, vector minss, vector maxss) FindCurrentNavNode;
88 void(float distance) UrreBotPath;
89 void() UrreBotSetup;
90 void() UrreBotThink;
91 void() LoadNavNodes;
92 void() LinkNavNodes;
93 void() ItemEvals;
94 void() OptimiseNavigation;
95 entity(float bottype) UrreBotAdd;
96 void() UrreBotRemove;
97 vector(vector point, entity current_space, entity goal_space) ClampPointToSpace;
98
99 float(vector m1, vector m2, vector m3, vector m4) boxesoverlap = {return m2_x >= m3_x && m1_x <= m4_x && m2_y >= m3_y && m1_y <= m4_y && m2_z >= m3_z && m1_z <= m4_z;};
100 float(vector smins, vector smaxs, vector bmins, vector bmaxs) boxenclosed = {return smins_x >= bmins_x && smaxs_x <= bmaxs_x && smins_y >= bmins_y && smaxs_y <= bmaxs_y && smins_z >= bmins_z && smaxs_z <= bmaxs_z;};
101
102 entity newmis;
103 void() SUB_Remove;
104 float JoinBestTeam(entity pl, float only_return_best);
105 float sv_maxspeed;
106
107 void() AutoBotRemove =
108 {
109         local entity ent, t;
110
111         ent = findchain(classname, "player");
112         while (ent)
113         {
114                 if (clienttype(ent) == CLIENTTYPE_BOT)
115                 {
116                         if (ent.bot_type != BOT_TYPE_URREBOT && ent.bot_type != BOT_TYPE_MAUVEBOT)
117                         {
118                                 if (self.list)
119                                 {
120                                         if (urrebot_chain == self)
121                                                 urrebot_chain = self.list;
122                                         else
123                                         {
124                                                 t = find(world, classname, "player");
125                                                 while(t)
126                                                 {
127                                                         if (t.list == ent)
128                                                                 t.list = ent.list;
129                                                         t = find(t, classname, "player");
130                                                 }
131                                         }
132                                 }
133                                 if (bot_number > 0)
134                                         bot_number -= 1;
135                                 self = ent;
136                                 ClientDisconnect();
137                                 dropclient(ent);
138                         }
139                 }
140                 ent = ent.chain;
141         }
142 };
143
144 void() Bots_Shared =
145 {
146         local entity bot;
147         local float f;
148
149         if (time >= 3)
150         {
151                 // UrreBots
152                 urrebots_strategytime = cvar("urrebots_strategytime");
153                 urrebots_combattime = cvar("urrebots_combattime");
154                 stratsearch_distance = cvar("urrebots_stratsearch_dist");
155                 minisearch_distance = cvar("urrebots_minisearch_dist");
156                 if (loadstep == 0)
157                 {
158                         LoadNavNodes();
159                         loadstep = 1;
160                         return;
161                 }
162                 else if (loadstep == 1)
163                 {
164                         LinkNavNodes();
165                         loadstep = 2;
166                         return;
167                 }
168                 else if (loadstep == 2)
169                 {
170                         if (navnodes)
171                         if (urrebots_navopt)
172                                 OptimiseNavigation();
173                         loadstep = 3;
174                         return;
175                 }
176                 else if (loadstep == 3)
177                 {
178                         if (navnodes)
179                                 ItemEvals();
180                         loadstep = 4;
181                         return;
182                 }
183                 f = cvar("urrebots");
184                 if (urrebots < f)
185                 {
186                         bot = UrreBotAdd(BOT_TYPE_URREBOT);
187                         bot.bot_type = BOT_TYPE_URREBOT;
188                         urrebots += 1;
189                 }
190                 if (urrebots > f)
191                         UrreBotRemove();
192
193                 // MauveBots
194                 f = cvar("mauvebots");
195                 if (f > mauvebots)
196                 {
197                         bot = add_MauveBot(BOT_TYPE_MAUVEBOT);
198                         bot.bot_type = BOT_TYPE_MAUVEBOT;
199                         mauvebots += 1;
200                 }
201                 else if (f < mauvebots)
202                         remove_MauveBot();
203
204                 // AutoBots
205                 f = cvar("bot_number");
206                 if (f > bot_number)
207                 {
208                         bot = world;
209                         if (navnodes)
210                         {
211                                 bot = UrreBotAdd(BOT_TYPE_AUTOURRE);
212                                 if (bot)
213                                 {
214                                         bot.bot_type = BOT_TYPE_AUTOURRE;
215                                         bot_number += 1;
216                                 }
217                         }
218                         else
219                         {
220                                 bot = add_MauveBot(BOT_TYPE_AUTOMAUVE);
221                                 if (bot)
222                                 {
223                                         bot.bot_type = BOT_TYPE_AUTOMAUVE;
224                                         bot_number += 1;
225                                 }
226                         }
227                 }
228                 else if (f < bot_number)
229                         AutoBotRemove();
230         }
231         else
232         {
233                 AutoBotRemove();
234                 remove_MauveBot();
235                 UrreBotRemove();
236         }
237 };