3 .float havocbot_role_timeout;
5 .void() havocbot_previous_role;
8 void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
12 float rating, d, discard, distance, friend_distance, enemy_distance;
14 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
15 head = findchainfloat(bot_pickup, TRUE);
19 o = (head.absmin + head.absmax) * 0.5;
20 distance = vlen(o - org);
21 friend_distance = 10000; enemy_distance = 10000;
24 if(!head.solid || distance > sradius || (head == self.ignoregoal && time < self.ignoregoaltime) )
30 // Check if the item can be picked up safely
31 if(head.classname == "droppedweapon")
33 traceline(o, o + '0 0 -1500', TRUE, world);
35 d = pointcontents(trace_endpos + '0 0 1');
36 if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
41 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
49 // Ignore items under water
50 traceline(head.origin + head.maxs, head.origin + head.maxs, MOVE_NORMAL, head);
51 if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
62 FOR_EACH_PLAYER(player)
65 if ( self == player || player.deadflag )
68 d = vlen(player.origin - o); // distance between player and item
70 if ( player.team == self.team )
72 if ( !IS_REAL_CLIENT(player) || discard )
75 if( d > friend_distance)
82 if( head.health && player.health > self.health )
85 if( head.armorvalue && player.armorvalue > self.armorvalue)
89 if( head.weapons & ~player.weapons )
92 if (head.ammo_shells && player.ammo_shells > self.ammo_shells)
95 if (head.ammo_nails && player.ammo_nails > self.ammo_nails)
98 if (head.ammo_rockets && player.ammo_rockets > self.ammo_rockets)
101 if (head.ammo_cells && player.ammo_cells > self.ammo_cells )
108 // If enemy only track distances
109 // TODO: track only if visible ?
110 if( d < enemy_distance )
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);
122 rating = head.bot_pickupevalfunc(self, head);
125 navigation_routerating(head, rating * ratingscale, 2000);
130 void havocbot_goalrating_controlpoints(float ratingscale, vector org, float sradius)
133 head = findchain(classname, "dom_controlpoint");
136 if (vlen(( ( head.absmin + head.absmax ) * 0.5 ) - org) < sradius)
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);
149 void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius)
152 float t, noteam, distance;
153 noteam = ((self.team == 0) || !teamplay); // fteqcc sucks
155 if (autocvar_bot_nofire)
158 // don't chase players if we're under water
159 if(self.waterlevel>WATERLEVEL_WETFEET)
162 FOR_EACH_PLAYER(head)
164 // TODO: Merge this logic with the bot_shouldattack function
165 if(bot_shouldattack(head))
167 distance = vlen(head.origin - org);
168 if (distance < 100 || distance > sradius)
171 // rate only visible enemies
173 traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
174 if (trace_fraction < 1 || trace_ent != head)
178 if((head.flags & FL_INWATER) || (head.flags & FL_PARTIALGROUND))
182 if((head.flags & FL_ONGROUND) == 0)
184 traceline(head.origin, head.origin + '0 0 -1500', TRUE, world);
185 t = pointcontents(trace_endpos + '0 0 1');
186 if( t != CONTENT_SOLID )
187 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
189 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
193 // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
194 // adding a player as a goal seems to be quite dangerous, especially on space maps
195 // remove hack in navigation_poptouchedgoals() after performing this change
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();
208 void havocbot_role_dm()
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_items(10000, self.origin, 10000);
218 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
219 //havocbot_goalrating_waypoints(1, self.origin, 1000);
220 navigation_goalrating_end();
225 //go to next checkpoint, and annoy enemies
226 .float race_checkpoint;
227 void havocbot_role_race()
229 if(self.deadflag != DEAD_NO)
233 if (self.bot_strategytime < time)
235 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
236 navigation_goalrating_start();
238 havocbot_goalrating_items(100, self.origin, 10000);
239 havocbot_goalrating_enemyplayers(500, self.origin, 20000);
242 for(e = world; (e = find(e, classname, "trigger_race_checkpoint")) != world; )
244 if(e.cnt == self.race_checkpoint)
246 navigation_routerating(e, 1000000, 5000);
248 else if(self.race_checkpoint == -1)
250 navigation_routerating(e, 1000000, 5000);
254 navigation_goalrating_end();
258 void havocbot_chooserole_dm()
260 self.havocbot_role = havocbot_role_dm;
263 void havocbot_chooserole_race()
265 self.havocbot_role = havocbot_role_race;
268 void havocbot_chooserole()
270 dprint("choosing a role...\n");
271 self.bot_strategytime = 0;
272 if (MUTATOR_CALLHOOK(HavocBot_ChooseRole))
275 havocbot_chooserole_kh();
276 else if (g_race || g_cts)
277 havocbot_chooserole_race();
278 else if (g_onslaught)
279 havocbot_chooserole_ons();
280 else // assume anything else is deathmatch
281 havocbot_chooserole_dm();