1 #include "../../_all.qh"
4 #include "role_keyhunt.qh"
7 #include "../navigation.qh"
10 .float havocbot_role_timeout;
12 .void() havocbot_previous_role;
13 .void() havocbot_role;
15 void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
19 float rating, d, discard, distance, friend_distance, enemy_distance;
21 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
22 head = findchainfloat(bot_pickup, true);
26 o = (head.absmin + head.absmax) * 0.5;
27 distance = vlen(o - org);
28 friend_distance = 10000; enemy_distance = 10000;
31 if(!head.solid || distance > sradius || (head == self.ignoregoal && time < self.ignoregoaltime) )
37 // Check if the item can be picked up safely
38 if(head.classname == "droppedweapon")
40 traceline(o, o + '0 0 -1500', true, world);
42 d = pointcontents(trace_endpos + '0 0 1');
43 if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
48 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
56 // Ignore items under water
57 traceline(head.origin + head.maxs, head.origin + head.maxs, MOVE_NORMAL, head);
58 if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
69 FOR_EACH_PLAYER(player)
72 if ( self == player || player.deadflag )
75 d = vlen(player.origin - o); // distance between player and item
77 if ( player.team == self.team )
79 if ( !IS_REAL_CLIENT(player) || discard )
82 if( d > friend_distance)
89 if( head.health && player.health > self.health )
92 if( head.armorvalue && player.armorvalue > self.armorvalue)
96 if( head.weapons & ~player.weapons )
99 if (head.ammo_shells && player.ammo_shells > self.ammo_shells)
102 if (head.ammo_nails && player.ammo_nails > self.ammo_nails)
105 if (head.ammo_rockets && player.ammo_rockets > self.ammo_rockets)
108 if (head.ammo_cells && player.ammo_cells > self.ammo_cells)
111 if (head.ammo_plasma && player.ammo_plasma > self.ammo_plasma)
118 // If enemy only track distances
119 // TODO: track only if visible ?
120 if( d < enemy_distance )
125 // Rate the item only if no one needs it, or if an enemy is closer to it
126 if ( (enemy_distance < friend_distance && distance < enemy_distance) ||
127 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
128 rating = head.bot_pickupevalfunc(self, head);
132 rating = head.bot_pickupevalfunc(self, head);
135 navigation_routerating(head, rating * ratingscale, 2000);
140 void havocbot_goalrating_controlpoints(float ratingscale, vector org, float sradius)
143 head = findchain(classname, "dom_controlpoint");
146 if (vlen(( ( head.absmin + head.absmax ) * 0.5 ) - org) < sradius)
148 if(head.cnt > -1) // this is just being fought for
149 navigation_routerating(head, ratingscale, 5000);
150 else if(head.goalentity.cnt == 0) // unclaimed point
151 navigation_routerating(head, ratingscale * 0.5, 5000);
152 else if(head.goalentity.team != self.team) // other team's point
153 navigation_routerating(head, ratingscale * 0.2, 5000);
159 void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius)
164 noref bool noteam = ((self.team == 0) || !teamplay);
166 if (autocvar_bot_nofire)
169 // don't chase players if we're under water
170 if(self.waterlevel>WATERLEVEL_WETFEET)
173 FOR_EACH_PLAYER(head)
175 // TODO: Merge this logic with the bot_shouldattack function
176 if(bot_shouldattack(head))
178 distance = vlen(head.origin - org);
179 if (distance < 100 || distance > sradius)
182 // rate only visible enemies
184 traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
185 if (trace_fraction < 1 || trace_ent != head)
189 if((head.flags & FL_INWATER) || (head.flags & FL_PARTIALGROUND))
193 if((head.flags & FL_ONGROUND) == 0)
195 traceline(head.origin, head.origin + '0 0 -1500', true, world);
196 t = pointcontents(trace_endpos + '0 0 1');
197 if( t != CONTENT_SOLID )
198 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
200 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
204 // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
205 // adding a player as a goal seems to be quite dangerous, especially on space maps
206 // remove hack in navigation_poptouchedgoals() after performing this change
208 t = (self.health + self.armorvalue ) / (head.health + head.armorvalue );
209 navigation_routerating(head, t * ratingscale, 2000);
214 // legacy bot role for standard gamemodes
216 void havocbot_role_generic()
218 if(self.deadflag != DEAD_NO)
221 if (self.bot_strategytime < time)
223 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
224 navigation_goalrating_start();
225 havocbot_goalrating_items(10000, self.origin, 10000);
226 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
227 //havocbot_goalrating_waypoints(1, self.origin, 1000);
228 navigation_goalrating_end();
232 void havocbot_chooserole_generic()
234 self.havocbot_role = havocbot_role_generic;
237 void havocbot_chooserole()
239 LOG_TRACE("choosing a role...\n");
240 self.bot_strategytime = 0;
241 if (MUTATOR_CALLHOOK(HavocBot_ChooseRole, self))
244 havocbot_chooserole_kh();
246 havocbot_chooserole_generic();