5 #include "../navigation.qh"
8 .float havocbot_role_timeout;
10 .void() havocbot_previous_role;
11 .void() havocbot_role;
13 void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
17 float rating, d, discard, distance, friend_distance, enemy_distance;
19 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
20 head = findchainfloat(bot_pickup, true);
24 o = (head.absmin + head.absmax) * 0.5;
25 distance = vlen(o - org);
26 friend_distance = 10000; enemy_distance = 10000;
29 if(!head.solid || distance > sradius || (head == self.ignoregoal && time < self.ignoregoaltime) )
35 // Check if the item can be picked up safely
36 if(head.classname == "droppedweapon")
38 traceline(o, o + '0 0 -1500', true, world);
40 d = pointcontents(trace_endpos + '0 0 1');
41 if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
46 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
54 // Ignore items under water
55 traceline(head.origin + head.maxs, head.origin + head.maxs, MOVE_NORMAL, head);
56 if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
67 FOR_EACH_PLAYER(player)
70 if ( self == player || player.deadflag )
73 d = vlen(player.origin - o); // distance between player and item
75 if ( player.team == self.team )
77 if ( !IS_REAL_CLIENT(player) || discard )
80 if( d > friend_distance)
87 if( head.health && player.health > self.health )
90 if( head.armorvalue && player.armorvalue > self.armorvalue)
94 if( head.weapons & ~player.weapons )
97 if (head.ammo_shells && player.ammo_shells > self.ammo_shells)
100 if (head.ammo_nails && player.ammo_nails > self.ammo_nails)
103 if (head.ammo_rockets && player.ammo_rockets > self.ammo_rockets)
106 if (head.ammo_cells && player.ammo_cells > self.ammo_cells)
109 if (head.ammo_plasma && player.ammo_plasma > self.ammo_plasma)
116 // If enemy only track distances
117 // TODO: track only if visible ?
118 if( d < enemy_distance )
123 // Rate the item only if no one needs it, or if an enemy is closer to it
124 if ( (enemy_distance < friend_distance && distance < enemy_distance) ||
125 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
126 rating = head.bot_pickupevalfunc(self, head);
130 rating = head.bot_pickupevalfunc(self, head);
133 navigation_routerating(head, rating * ratingscale, 2000);
138 void havocbot_goalrating_controlpoints(float ratingscale, vector org, float sradius)
141 head = findchain(classname, "dom_controlpoint");
144 if (vlen(( ( head.absmin + head.absmax ) * 0.5 ) - org) < sradius)
146 if(head.cnt > -1) // this is just being fought for
147 navigation_routerating(head, ratingscale, 5000);
148 else if(head.goalentity.cnt == 0) // unclaimed point
149 navigation_routerating(head, ratingscale * 0.5, 5000);
150 else if(head.goalentity.team != self.team) // other team's point
151 navigation_routerating(head, ratingscale * 0.2, 5000);
157 void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius)
162 noref bool noteam = ((self.team == 0) || !teamplay);
164 if (autocvar_bot_nofire)
167 // don't chase players if we're under water
168 if(self.waterlevel>WATERLEVEL_WETFEET)
171 FOR_EACH_PLAYER(head)
173 // TODO: Merge this logic with the bot_shouldattack function
174 if(bot_shouldattack(head))
176 distance = vlen(head.origin - org);
177 if (distance < 100 || distance > sradius)
180 // rate only visible enemies
182 traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
183 if (trace_fraction < 1 || trace_ent != head)
187 if((head.flags & FL_INWATER) || (head.flags & FL_PARTIALGROUND))
191 if((head.flags & FL_ONGROUND) == 0)
193 traceline(head.origin, head.origin + '0 0 -1500', true, world);
194 t = pointcontents(trace_endpos + '0 0 1');
195 if( t != CONTENT_SOLID )
196 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
198 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
202 // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
203 // adding a player as a goal seems to be quite dangerous, especially on space maps
204 // remove hack in navigation_poptouchedgoals() after performing this change
206 t = (self.health + self.armorvalue ) / (head.health + head.armorvalue );
207 navigation_routerating(head, t * ratingscale, 2000);
212 // legacy bot role for standard gamemodes
214 void havocbot_role_generic()
216 if(self.deadflag != DEAD_NO)
219 if (self.bot_strategytime < time)
221 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
222 navigation_goalrating_start();
223 havocbot_goalrating_items(10000, self.origin, 10000);
224 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
225 //havocbot_goalrating_waypoints(1, self.origin, 1000);
226 navigation_goalrating_end();
230 void havocbot_chooserole_generic()
232 self.havocbot_role = havocbot_role_generic;
235 void havocbot_chooserole()
237 LOG_TRACE("choosing a role...\n");
238 self.bot_strategytime = 0;
239 if(!MUTATOR_CALLHOOK(HavocBot_ChooseRole, self))
240 havocbot_chooserole_generic();