3 .float havocbot_role_timeout;
5 .void() havocbot_previous_role;
8 void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
12 local float rating, d, discard, distance, friend_distance, enemy_distance;
13 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
14 head = findchainfloat(bot_pickup, TRUE);
18 distance = vlen(head.origin - org);
19 friend_distance = 10000; enemy_distance = 10000;
22 if(!head.solid || distance > sradius || (head == self.ignoregoal && time < self.ignoregoaltime) )
28 // Check if the item can be picked up safely
29 if(head.classname == "droppedweapon")
31 traceline(head.origin, head.origin + '0 0 -1500', TRUE, world);
33 d = pointcontents(trace_endpos + '0 0 1');
34 if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
39 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
47 // Ignore items under water
48 traceline(head.origin + head.maxs, head.origin + head.maxs, MOVE_NORMAL, head);
49 if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
60 FOR_EACH_PLAYER(player)
63 if ( self == player || player.deadflag )
66 d = vlen(player.origin - head.origin); // distance between player and item
68 if ( player.team == self.team )
70 if ( clienttype(player) != CLIENTTYPE_REAL || discard )
73 if( d > friend_distance)
80 if( head.health && player.health > self.health )
83 if( head.armorvalue && player.armorvalue > self.armorvalue)
87 if( (player.weapons & head.weapons) != head.weapons)
90 if (head.ammo_shells && player.ammo_shells > self.ammo_shells)
93 if (head.ammo_nails && player.ammo_nails > self.ammo_nails)
96 if (head.ammo_rockets && player.ammo_rockets > self.ammo_rockets)
99 if (head.ammo_cells && player.ammo_cells > self.ammo_cells )
106 // If enemy only track distances
107 // TODO: track only if visible ?
108 if( d < enemy_distance )
113 // Rate the item only if no one needs it, or if an enemy is closer to it
114 if ( (enemy_distance < friend_distance && distance < enemy_distance) ||
115 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
116 rating = head.bot_pickupevalfunc(self, head);
120 rating = head.bot_pickupevalfunc(self, head);
123 navigation_routerating(head, rating * ratingscale, 2000);
128 void havocbot_goalrating_controlpoints(float ratingscale, vector org, float sradius)
131 head = findchain(classname, "dom_controlpoint");
134 if (vlen(head.origin - org) < sradius)
136 if(head.cnt > -1) // this is just being fought for
137 navigation_routerating(head, ratingscale, 5000);
138 else if(head.goalentity.cnt == 0) // unclaimed point
139 navigation_routerating(head, ratingscale * 0.5, 5000);
140 else if(head.goalentity.team != self.team) // other team's point
141 navigation_routerating(head, ratingscale * 0.2, 5000);
147 void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius)
150 local float t, noteam, distance;
151 noteam = ((self.team == 0) || !teams_matter); // fteqcc sucks
153 if (autocvar_bot_nofire)
156 // don't chase players if we're under water
157 if(self.waterlevel>WATERLEVEL_WETFEET)
160 FOR_EACH_PLAYER(head)
162 // TODO: Merge this logic with the bot_shouldattack function
165 if ((noteam && (!bot_ignore_bots || clienttype(head) == CLIENTTYPE_REAL)) || head.team != self.team)
167 distance = vlen(head.origin - org);
168 if (distance < 100 || distance > sradius)
172 if(head.items & IT_STRENGTH)
175 // rate only visible enemies
177 traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
178 if (trace_fraction < 1 || trace_ent != head)
182 if(head.flags & FL_INWATER || head.flags & FL_PARTIALGROUND)
186 if(head.flags & FL_ONGROUND == 0)
188 traceline(head.origin, head.origin + '0 0 -1500', TRUE, world);
189 t = pointcontents(trace_endpos + '0 0 1');
190 if( t != CONTENT_SOLID )
191 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
193 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
197 t = (self.health + self.armorvalue ) / (head.health + head.armorvalue );
198 navigation_routerating(head, t * ratingscale, 2000);
203 // choose a role according to the situation
204 void() havocbot_role_dm;
207 //go to best items, or control points you don't own
208 void havocbot_role_dom()
210 if(self.deadflag != DEAD_NO)
213 if (self.bot_strategytime < time)
215 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
216 navigation_goalrating_start();
217 havocbot_goalrating_controlpoints(10000, self.origin, 15000);
218 havocbot_goalrating_items(8000, self.origin, 8000);
219 //havocbot_goalrating_enemyplayers(3000, self.origin, 2000);
220 //havocbot_goalrating_waypoints(1, self.origin, 1000);
221 navigation_goalrating_end();
227 void havocbot_role_dm()
229 if(self.deadflag != DEAD_NO)
232 if (self.bot_strategytime < time)
234 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
235 navigation_goalrating_start();
236 havocbot_goalrating_items(10000, self.origin, 10000);
237 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
238 //havocbot_goalrating_waypoints(1, self.origin, 1000);
239 navigation_goalrating_end();
244 //go to next checkpoint, and annoy enemies
245 .float race_checkpoint;
246 void havocbot_role_race()
248 if(self.deadflag != DEAD_NO)
252 if (self.bot_strategytime < time)
254 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
255 navigation_goalrating_start();
257 havocbot_goalrating_items(100, self.origin, 10000);
258 havocbot_goalrating_enemyplayers(500, self.origin, 20000);
261 for(e = world; (e = find(e, classname, "trigger_race_checkpoint")) != world; )
263 if(e.cnt == self.race_checkpoint)
265 navigation_routerating(e, 1000000, 5000);
267 else if(self.race_checkpoint == -1)
269 navigation_routerating(e, 1000000, 5000);
273 navigation_goalrating_end();
278 // If you don't have the ball, get it; if you do, kill people.
279 void havocbot_role_ka()
281 if(self.deadflag != DEAD_NO)
284 if (self.bot_strategytime < time)
286 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
287 navigation_goalrating_start();
288 havocbot_goalrating_items(10000, self.origin, 10000);
289 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
290 //havocbot_goalrating_waypoints(1, self.origin, 1000);
291 navigation_goalrating_end();
295 void havocbot_chooserole_dm()
297 self.havocbot_role = havocbot_role_dm;
300 void havocbot_chooserole_race()
302 self.havocbot_role = havocbot_role_race;
305 void havocbot_chooserole_dom()
307 self.havocbot_role = havocbot_role_dom;
310 void havocbot_chooserole_ka()
312 self.havocbot_role = havocbot_role_ka;
315 void havocbot_chooserole()
317 dprint("choosing a role...\n");
318 self.bot_strategytime = 0;
320 havocbot_chooserole_ctf();
321 else if (g_domination)
322 havocbot_chooserole_dom();
324 havocbot_chooserole_kh();
325 else if (g_race || g_cts)
326 havocbot_chooserole_race();
327 else if (g_onslaught)
328 havocbot_chooserole_ons();
330 havocbot_chooserole_ka();
331 else // assume anything else is deathmatch
332 havocbot_chooserole_dm();