4 .float havocbot_role_timeout;
6 .void() havocbot_previous_role;
9 void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
13 float rating, d, discard, distance, friend_distance, enemy_distance;
15 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
16 head = findchainfloat(bot_pickup, true);
20 o = (head.absmin + head.absmax) * 0.5;
21 distance = vlen(o - org);
22 friend_distance = 10000; enemy_distance = 10000;
25 if(!head.solid || distance > sradius || (head == self.ignoregoal && time < self.ignoregoaltime) )
31 // Check if the item can be picked up safely
32 if(head.classname == "droppedweapon")
34 traceline(o, o + '0 0 -1500', true, world);
36 d = pointcontents(trace_endpos + '0 0 1');
37 if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
42 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
50 // Ignore items under water
51 traceline(head.origin + head.maxs, head.origin + head.maxs, MOVE_NORMAL, head);
52 if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
63 FOR_EACH_PLAYER(player)
66 if ( self == player || player.deadflag )
69 d = vlen(player.origin - o); // distance between player and item
71 if ( player.team == self.team )
73 if ( !IS_REAL_CLIENT(player) || discard )
76 if( d > friend_distance)
83 if( head.health && player.health > self.health )
86 if( head.armorvalue && player.armorvalue > self.armorvalue)
90 if( head.weapons & ~player.weapons )
93 if (head.ammo_shells && player.ammo_shells > self.ammo_shells)
96 if (head.ammo_nails && player.ammo_nails > self.ammo_nails)
99 if (head.ammo_rockets && player.ammo_rockets > self.ammo_rockets)
102 if (head.ammo_cells && player.ammo_cells > self.ammo_cells)
105 if (head.ammo_plasma && player.ammo_plasma > self.ammo_plasma)
112 // If enemy only track distances
113 // TODO: track only if visible ?
114 if( d < enemy_distance )
119 // Rate the item only if no one needs it, or if an enemy is closer to it
120 if ( (enemy_distance < friend_distance && distance < enemy_distance) ||
121 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
122 rating = head.bot_pickupevalfunc(self, head);
126 rating = head.bot_pickupevalfunc(self, head);
129 navigation_routerating(head, rating * ratingscale, 2000);
134 void havocbot_goalrating_controlpoints(float ratingscale, vector org, float sradius)
137 head = findchain(classname, "dom_controlpoint");
140 if (vlen(( ( head.absmin + head.absmax ) * 0.5 ) - org) < sradius)
142 if(head.cnt > -1) // this is just being fought for
143 navigation_routerating(head, ratingscale, 5000);
144 else if(head.goalentity.cnt == 0) // unclaimed point
145 navigation_routerating(head, ratingscale * 0.5, 5000);
146 else if(head.goalentity.team != self.team) // other team's point
147 navigation_routerating(head, ratingscale * 0.2, 5000);
153 void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius)
158 noref bool noteam = ((self.team == 0) || !teamplay);
160 if (autocvar_bot_nofire)
163 // don't chase players if we're under water
164 if(self.waterlevel>WATERLEVEL_WETFEET)
167 FOR_EACH_PLAYER(head)
169 // TODO: Merge this logic with the bot_shouldattack function
170 if(bot_shouldattack(head))
172 distance = vlen(head.origin - org);
173 if (distance < 100 || distance > sradius)
176 // rate only visible enemies
178 traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
179 if (trace_fraction < 1 || trace_ent != head)
183 if((head.flags & FL_INWATER) || (head.flags & FL_PARTIALGROUND))
187 if((head.flags & FL_ONGROUND) == 0)
189 traceline(head.origin, head.origin + '0 0 -1500', true, world);
190 t = pointcontents(trace_endpos + '0 0 1');
191 if( t != CONTENT_SOLID )
192 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
194 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
198 // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
199 // adding a player as a goal seems to be quite dangerous, especially on space maps
200 // remove hack in navigation_poptouchedgoals() after performing this change
202 t = (self.health + self.armorvalue ) / (head.health + head.armorvalue );
203 navigation_routerating(head, t * ratingscale, 2000);
208 // legacy bot role for standard gamemodes
210 void havocbot_role_generic()
212 if(self.deadflag != DEAD_NO)
215 if (self.bot_strategytime < time)
217 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
218 navigation_goalrating_start();
219 havocbot_goalrating_items(10000, self.origin, 10000);
220 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
221 //havocbot_goalrating_waypoints(1, self.origin, 1000);
222 navigation_goalrating_end();
226 void havocbot_chooserole_generic()
228 self.havocbot_role = havocbot_role_generic;
231 void havocbot_chooserole()
233 LOG_TRACE("choosing a role...\n");
234 self.bot_strategytime = 0;
235 if (MUTATOR_CALLHOOK(HavocBot_ChooseRole, self))
238 havocbot_chooserole_kh();
240 havocbot_chooserole_generic();