]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/bot/havocbot/roles.qc
Merge remote-tracking branch 'origin/terencehill/arena_stuff'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / havocbot / roles.qc
1
2 .float max_armorvalue;
3 .float havocbot_role_timeout;
4
5 .void() havocbot_previous_role;
6 .void() havocbot_role;
7
8 void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
9 {
10         local entity head;
11         local entity player;
12         local float rating, d, discard, distance, friend_distance, enemy_distance;
13         vector o;
14         ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
15         head = findchainfloat(bot_pickup, TRUE);
16
17         while (head)
18         {
19                 o = (head.absmin + head.absmax) * 0.5;
20                 distance = vlen(o - org);
21                 friend_distance = 10000; enemy_distance = 10000;
22                 rating = 0;
23
24                 if(!head.solid || distance > sradius || (head == self.ignoregoal && time < self.ignoregoaltime) )
25                 {
26                         head = head.chain;
27                         continue;
28                 }
29
30                 // Check if the item can be picked up safely
31                 if(head.classname == "droppedweapon")
32                 {
33                         traceline(o, o + '0 0 -1500', TRUE, world);
34
35                         d = pointcontents(trace_endpos + '0 0 1');
36                         if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
37                         {
38                                 head = head.chain;
39                                 continue;
40                         }
41                         if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
42                         {
43                                 head = head.chain;
44                                 continue;
45                         }
46                 }
47                 else
48                 {
49                         // Ignore items under water
50                         traceline(head.origin + head.maxs, head.origin + head.maxs, MOVE_NORMAL, head);
51                         if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
52                         {
53                                 head = head.chain;
54                                 continue;
55                         }
56                 }
57
58                 if(teamplay)
59                 {
60                         discard = FALSE;
61
62                         FOR_EACH_PLAYER(player)
63                         {
64
65                                 if ( self == player || player.deadflag )
66                                         continue;
67
68                                 d = vlen(player.origin - o); // distance between player and item
69
70                                 if ( player.team == self.team )
71                                 {
72                                         if ( clienttype(player) != CLIENTTYPE_REAL || discard )
73                                                 continue;
74
75                                         if( d > friend_distance)
76                                                 continue;
77
78                                         friend_distance = d;
79
80                                         discard = TRUE;
81
82                                         if( head.health && player.health > self.health )
83                                                 continue;
84
85                                         if( head.armorvalue && player.armorvalue > self.armorvalue)
86                                                 continue;
87
88                                         if( head.weapons )
89                                         if( (player.weapons & head.weapons) != head.weapons)
90                                                 continue;
91
92                                         if (head.ammo_shells && player.ammo_shells > self.ammo_shells)
93                                                 continue;
94
95                                         if (head.ammo_nails && player.ammo_nails > self.ammo_nails)
96                                                 continue;
97
98                                         if (head.ammo_rockets && player.ammo_rockets > self.ammo_rockets)
99                                                 continue;
100
101                                         if (head.ammo_cells && player.ammo_cells > self.ammo_cells )
102                                                 continue;
103
104                                         discard = FALSE;
105                                 }
106                                 else
107                                 {
108                                         // If enemy only track distances
109                                         // TODO: track only if visible ?
110                                         if( d < enemy_distance )
111                                                 enemy_distance = d;
112                                 }
113                         }
114
115                         // Rate the item only if no one needs it, or if an enemy is closer to it
116                         if ( (enemy_distance < friend_distance && distance < enemy_distance) ||
117                                 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
118                                 rating = head.bot_pickupevalfunc(self, head);
119
120                 }
121                 else
122                         rating = head.bot_pickupevalfunc(self, head);
123
124                 if(rating > 0)
125                         navigation_routerating(head, rating * ratingscale, 2000);
126                 head = head.chain;
127         }
128 };
129
130 void havocbot_goalrating_controlpoints(float ratingscale, vector org, float sradius)
131 {
132         local entity head;
133         head = findchain(classname, "dom_controlpoint");
134         while (head)
135         {
136                 if (vlen(( ( head.absmin + head.absmax ) * 0.5 ) - org) < sradius)
137                 {
138                         if(head.cnt > -1) // this is just being fought for
139                                 navigation_routerating(head, ratingscale, 5000);
140                         else if(head.goalentity.cnt == 0) // unclaimed point
141                                 navigation_routerating(head, ratingscale * 0.5, 5000);
142                         else if(head.goalentity.team != self.team) // other team's point
143                                 navigation_routerating(head, ratingscale * 0.2, 5000);
144                 }
145                 head = head.chain;
146         }
147 };
148
149 void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius)
150 {
151         local entity head;
152         local float t, noteam, distance;
153         noteam = ((self.team == 0) || !teamplay); // fteqcc sucks
154
155         if (autocvar_bot_nofire)
156                 return;
157
158         // don't chase players if we're under water
159         if(self.waterlevel>WATERLEVEL_WETFEET)
160                 return;
161
162         FOR_EACH_PLAYER(head)
163         {
164                 // TODO: Merge this logic with the bot_shouldattack function
165                 if (self != head)
166                 if (head.health > 0)
167                 if ((noteam && (!bot_ignore_bots || clienttype(head) == CLIENTTYPE_REAL)) || head.team != self.team)
168                 {
169                         distance = vlen(head.origin - org);
170                         if (distance < 100 || distance > sradius)
171                                 continue;
172
173                         if (head.freezetag_frozen)
174                                 continue;
175
176                         if(g_minstagib)
177                         if(head.items & IT_STRENGTH)
178                                 continue;
179
180                         // rate only visible enemies
181                         /*
182                         traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
183                         if (trace_fraction < 1 || trace_ent != head)
184                                 continue;
185                         */
186
187                         if(head.flags & FL_INWATER || head.flags & FL_PARTIALGROUND)
188                                 continue;
189
190                         // not falling
191                         if(head.flags & FL_ONGROUND == 0)
192                         {
193                                 traceline(head.origin, head.origin + '0 0 -1500', TRUE, world);
194                                 t = pointcontents(trace_endpos + '0 0 1');
195                                 if( t != CONTENT_SOLID )
196                                 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
197                                         continue;
198                                 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
199                                         continue;
200                         }
201
202                         // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
203                         //               adding a player as a goal seems to be quite dangerous, especially on space maps
204                         //               remove hack in navigation_poptouchedgoals() after performing this change
205
206                         t = (self.health + self.armorvalue ) / (head.health + head.armorvalue );
207                         navigation_routerating(head, t * ratingscale, 2000);
208                 }
209         }
210 };
211
212 // choose a role according to the situation
213 void() havocbot_role_dm;
214
215 //DOM:
216 //go to best items, or control points you don't own
217 void havocbot_role_dom()
218 {
219         if(self.deadflag != DEAD_NO)
220                 return;
221
222         if (self.bot_strategytime < time)
223         {
224                 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
225                 navigation_goalrating_start();
226                 havocbot_goalrating_controlpoints(10000, self.origin, 15000);
227                 havocbot_goalrating_items(8000, self.origin, 8000);
228                 //havocbot_goalrating_enemyplayers(3000, self.origin, 2000);
229                 //havocbot_goalrating_waypoints(1, self.origin, 1000);
230                 navigation_goalrating_end();
231         }
232 };
233
234 //DM:
235 //go to best items
236 void havocbot_role_dm()
237 {
238         if(self.deadflag != DEAD_NO)
239                 return;
240
241         if (self.bot_strategytime < time)
242         {
243                 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
244                 navigation_goalrating_start();
245                 havocbot_goalrating_items(10000, self.origin, 10000);
246                 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
247                 //havocbot_goalrating_waypoints(1, self.origin, 1000);
248                 navigation_goalrating_end();
249         }
250 };
251
252 //Race:
253 //go to next checkpoint, and annoy enemies
254 .float race_checkpoint;
255 void havocbot_role_race()
256 {
257         if(self.deadflag != DEAD_NO)
258                 return;
259
260         entity e;
261         if (self.bot_strategytime < time)
262         {
263                 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
264                 navigation_goalrating_start();
265                 /*
266                 havocbot_goalrating_items(100, self.origin, 10000);
267                 havocbot_goalrating_enemyplayers(500, self.origin, 20000);
268                 */
269
270                 for(e = world; (e = find(e, classname, "trigger_race_checkpoint")) != world; )
271                 {
272                         if(e.cnt == self.race_checkpoint)
273                         {
274                                 navigation_routerating(e, 1000000, 5000);
275                         }
276                         else if(self.race_checkpoint == -1)
277                         {
278                                 navigation_routerating(e, 1000000, 5000);
279                         }
280                 }
281
282                 navigation_goalrating_end();
283         }
284 };
285
286 void havocbot_chooserole_dm()
287 {
288         self.havocbot_role = havocbot_role_dm;
289 };
290
291 void havocbot_chooserole_race()
292 {
293         self.havocbot_role = havocbot_role_race;
294 };
295
296 void havocbot_chooserole_dom()
297 {
298         self.havocbot_role = havocbot_role_dom;
299 };
300
301 void havocbot_chooserole()
302 {
303         dprint("choosing a role...\n");
304         self.bot_strategytime = 0;
305         if (g_ctf)
306                 havocbot_chooserole_ctf();
307         else if (g_domination)
308                 havocbot_chooserole_dom();
309         else if (g_keyhunt)
310                 havocbot_chooserole_kh();
311         else if (g_race || g_cts)
312                 havocbot_chooserole_race();
313         else if (g_onslaught)
314                 havocbot_chooserole_ons();
315         else if (g_keepaway)
316                 havocbot_chooserole_ka();
317         else if (g_freezetag)
318                 havocbot_chooserole_ft();
319         else if (g_assault)
320                 havocbot_chooserole_ast();
321         else // assume anything else is deathmatch
322                 havocbot_chooserole_dm();
323 };