1 #include "../../_all.qh"
4 #include "role_keyhunt.qh"
5 #include "role_onslaught.qh"
8 #include "../navigation.qh"
10 .float max_armorvalue;
11 .float havocbot_role_timeout;
13 .void() havocbot_previous_role;
14 .void() havocbot_role;
16 void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
20 float rating, d, discard, distance, friend_distance, enemy_distance;
22 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
23 head = findchainfloat(bot_pickup, true);
27 o = (head.absmin + head.absmax) * 0.5;
28 distance = vlen(o - org);
29 friend_distance = 10000; enemy_distance = 10000;
32 if(!head.solid || distance > sradius || (head == self.ignoregoal && time < self.ignoregoaltime) )
38 // Check if the item can be picked up safely
39 if(head.classname == "droppedweapon")
41 traceline(o, o + '0 0 -1500', true, world);
43 d = pointcontents(trace_endpos + '0 0 1');
44 if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
49 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
57 // Ignore items under water
58 traceline(head.origin + head.maxs, head.origin + head.maxs, MOVE_NORMAL, head);
59 if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
70 FOR_EACH_PLAYER(player)
73 if ( self == player || player.deadflag )
76 d = vlen(player.origin - o); // distance between player and item
78 if ( player.team == self.team )
80 if ( !IS_REAL_CLIENT(player) || discard )
83 if( d > friend_distance)
90 if( head.health && player.health > self.health )
93 if( head.armorvalue && player.armorvalue > self.armorvalue)
97 if( head.weapons & ~player.weapons )
100 if (head.ammo_shells && player.ammo_shells > self.ammo_shells)
103 if (head.ammo_nails && player.ammo_nails > self.ammo_nails)
106 if (head.ammo_rockets && player.ammo_rockets > self.ammo_rockets)
109 if (head.ammo_cells && player.ammo_cells > self.ammo_cells)
112 if (head.ammo_plasma && player.ammo_plasma > self.ammo_plasma)
119 // If enemy only track distances
120 // TODO: track only if visible ?
121 if( d < enemy_distance )
126 // Rate the item only if no one needs it, or if an enemy is closer to it
127 if ( (enemy_distance < friend_distance && distance < enemy_distance) ||
128 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
129 rating = head.bot_pickupevalfunc(self, head);
133 rating = head.bot_pickupevalfunc(self, head);
136 navigation_routerating(head, rating * ratingscale, 2000);
141 void havocbot_goalrating_controlpoints(float ratingscale, vector org, float sradius)
144 head = findchain(classname, "dom_controlpoint");
147 if (vlen(( ( head.absmin + head.absmax ) * 0.5 ) - org) < sradius)
149 if(head.cnt > -1) // this is just being fought for
150 navigation_routerating(head, ratingscale, 5000);
151 else if(head.goalentity.cnt == 0) // unclaimed point
152 navigation_routerating(head, ratingscale * 0.5, 5000);
153 else if(head.goalentity.team != self.team) // other team's point
154 navigation_routerating(head, ratingscale * 0.2, 5000);
160 void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius)
165 noref bool noteam = ((self.team == 0) || !teamplay);
167 if (autocvar_bot_nofire)
170 // don't chase players if we're under water
171 if(self.waterlevel>WATERLEVEL_WETFEET)
174 FOR_EACH_PLAYER(head)
176 // TODO: Merge this logic with the bot_shouldattack function
177 if(bot_shouldattack(head))
179 distance = vlen(head.origin - org);
180 if (distance < 100 || distance > sradius)
183 // rate only visible enemies
185 traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
186 if (trace_fraction < 1 || trace_ent != head)
190 if((head.flags & FL_INWATER) || (head.flags & FL_PARTIALGROUND))
194 if((head.flags & FL_ONGROUND) == 0)
196 traceline(head.origin, head.origin + '0 0 -1500', true, world);
197 t = pointcontents(trace_endpos + '0 0 1');
198 if( t != CONTENT_SOLID )
199 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
201 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
205 // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
206 // adding a player as a goal seems to be quite dangerous, especially on space maps
207 // remove hack in navigation_poptouchedgoals() after performing this change
209 t = (self.health + self.armorvalue ) / (head.health + head.armorvalue );
210 navigation_routerating(head, t * ratingscale, 2000);
215 // choose a role according to the situation
216 void havocbot_role_dm();
220 void havocbot_role_dm()
222 if(self.deadflag != DEAD_NO)
225 if (self.bot_strategytime < time)
227 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
228 navigation_goalrating_start();
229 havocbot_goalrating_items(10000, self.origin, 10000);
230 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
231 //havocbot_goalrating_waypoints(1, self.origin, 1000);
232 navigation_goalrating_end();
236 void havocbot_chooserole_dm()
238 self.havocbot_role = havocbot_role_dm;
241 void havocbot_chooserole()
243 dprint("choosing a role...\n");
244 self.bot_strategytime = 0;
245 if (MUTATOR_CALLHOOK(HavocBot_ChooseRole))
248 havocbot_chooserole_kh();
249 else if (g_onslaught)
250 havocbot_chooserole_ons();
251 else // assume anything else is deathmatch
252 havocbot_chooserole_dm();