3 #include "role_keyhunt.qh"
6 #include "../navigation.qh"
9 .float havocbot_role_timeout;
11 .void() havocbot_previous_role;
12 .void() havocbot_role;
14 void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
18 float rating, d, discard, distance, friend_distance, enemy_distance;
20 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
21 head = findchainfloat(bot_pickup, true);
25 o = (head.absmin + head.absmax) * 0.5;
26 distance = vlen(o - org);
27 friend_distance = 10000; enemy_distance = 10000;
30 if(!head.solid || distance > sradius || (head == self.ignoregoal && time < self.ignoregoaltime) )
36 // Check if the item can be picked up safely
37 if(head.classname == "droppedweapon")
39 traceline(o, o + '0 0 -1500', true, world);
41 d = pointcontents(trace_endpos + '0 0 1');
42 if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
47 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
55 // Ignore items under water
56 traceline(head.origin + head.maxs, head.origin + head.maxs, MOVE_NORMAL, head);
57 if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
68 FOR_EACH_PLAYER(player)
71 if ( self == player || player.deadflag )
74 d = vlen(player.origin - o); // distance between player and item
76 if ( player.team == self.team )
78 if ( !IS_REAL_CLIENT(player) || discard )
81 if( d > friend_distance)
88 if( head.health && player.health > self.health )
91 if( head.armorvalue && player.armorvalue > self.armorvalue)
95 if( head.weapons & ~player.weapons )
98 if (head.ammo_shells && player.ammo_shells > self.ammo_shells)
101 if (head.ammo_nails && player.ammo_nails > self.ammo_nails)
104 if (head.ammo_rockets && player.ammo_rockets > self.ammo_rockets)
107 if (head.ammo_cells && player.ammo_cells > self.ammo_cells)
110 if (head.ammo_plasma && player.ammo_plasma > self.ammo_plasma)
117 // If enemy only track distances
118 // TODO: track only if visible ?
119 if( d < enemy_distance )
124 // Rate the item only if no one needs it, or if an enemy is closer to it
125 if ( (enemy_distance < friend_distance && distance < enemy_distance) ||
126 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
127 rating = head.bot_pickupevalfunc(self, head);
131 rating = head.bot_pickupevalfunc(self, head);
134 navigation_routerating(head, rating * ratingscale, 2000);
139 void havocbot_goalrating_controlpoints(float ratingscale, vector org, float sradius)
142 head = findchain(classname, "dom_controlpoint");
145 if (vlen(( ( head.absmin + head.absmax ) * 0.5 ) - org) < sradius)
147 if(head.cnt > -1) // this is just being fought for
148 navigation_routerating(head, ratingscale, 5000);
149 else if(head.goalentity.cnt == 0) // unclaimed point
150 navigation_routerating(head, ratingscale * 0.5, 5000);
151 else if(head.goalentity.team != self.team) // other team's point
152 navigation_routerating(head, ratingscale * 0.2, 5000);
158 void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius)
163 noref bool noteam = ((self.team == 0) || !teamplay);
165 if (autocvar_bot_nofire)
168 // don't chase players if we're under water
169 if(self.waterlevel>WATERLEVEL_WETFEET)
172 FOR_EACH_PLAYER(head)
174 // TODO: Merge this logic with the bot_shouldattack function
175 if(bot_shouldattack(head))
177 distance = vlen(head.origin - org);
178 if (distance < 100 || distance > sradius)
181 // rate only visible enemies
183 traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
184 if (trace_fraction < 1 || trace_ent != head)
188 if((head.flags & FL_INWATER) || (head.flags & FL_PARTIALGROUND))
192 if((head.flags & FL_ONGROUND) == 0)
194 traceline(head.origin, head.origin + '0 0 -1500', true, world);
195 t = pointcontents(trace_endpos + '0 0 1');
196 if( t != CONTENT_SOLID )
197 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
199 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
203 // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
204 // adding a player as a goal seems to be quite dangerous, especially on space maps
205 // remove hack in navigation_poptouchedgoals() after performing this change
207 t = (self.health + self.armorvalue ) / (head.health + head.armorvalue );
208 navigation_routerating(head, t * ratingscale, 2000);
213 // legacy bot role for standard gamemodes
215 void havocbot_role_generic()
217 if(self.deadflag != DEAD_NO)
220 if (self.bot_strategytime < time)
222 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
223 navigation_goalrating_start();
224 havocbot_goalrating_items(10000, self.origin, 10000);
225 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
226 //havocbot_goalrating_waypoints(1, self.origin, 1000);
227 navigation_goalrating_end();
231 void havocbot_chooserole_generic()
233 self.havocbot_role = havocbot_role_generic;
236 void havocbot_chooserole()
238 LOG_TRACE("choosing a role...\n");
239 self.bot_strategytime = 0;
240 if (MUTATOR_CALLHOOK(HavocBot_ChooseRole, self))
243 havocbot_chooserole_kh();
245 havocbot_chooserole_generic();