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)
16 float rating, d, discard, distance, friend_distance, enemy_distance;
18 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
19 head = findchainfloat(bot_pickup, true);
23 o = (head.absmin + head.absmax) * 0.5;
24 distance = vlen(o - org);
25 friend_distance = 10000; enemy_distance = 10000;
28 if(!head.solid || distance > sradius || (head == self.ignoregoal && time < self.ignoregoaltime) )
34 // Check if the item can be picked up safely
35 if(head.classname == "droppedweapon")
37 traceline(o, o + '0 0 -1500', true, world);
39 d = pointcontents(trace_endpos + '0 0 1');
40 if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
45 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
53 // Ignore items under water
54 traceline(head.origin + head.maxs, head.origin + head.maxs, MOVE_NORMAL, head);
55 if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
66 FOREACH_CLIENT(IS_PLAYER(it) && it != self && it.deadflag == DEAD_NO, LAMBDA(
67 d = vlen(it.origin - o); // distance between player and item
69 if ( it.team == self.team )
71 if ( !IS_REAL_CLIENT(it) || discard )
74 if( d > friend_distance)
81 if( head.health && it.health > self.health )
84 if( head.armorvalue && it.armorvalue > self.armorvalue)
88 if( head.weapons & ~it.weapons )
91 if (head.ammo_shells && it.ammo_shells > self.ammo_shells)
94 if (head.ammo_nails && it.ammo_nails > self.ammo_nails)
97 if (head.ammo_rockets && it.ammo_rockets > self.ammo_rockets)
100 if (head.ammo_cells && it.ammo_cells > self.ammo_cells)
103 if (head.ammo_plasma && it.ammo_plasma > self.ammo_plasma)
110 // If enemy only track distances
111 // TODO: track only if visible ?
112 if( d < enemy_distance )
117 // Rate the item only if no one needs it, or if an enemy is closer to it
118 if ( (enemy_distance < friend_distance && distance < enemy_distance) ||
119 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
120 rating = head.bot_pickupevalfunc(self, head);
124 rating = head.bot_pickupevalfunc(self, head);
127 navigation_routerating(head, rating * ratingscale, 2000);
132 void havocbot_goalrating_controlpoints(float ratingscale, vector org, float sradius)
135 head = findchain(classname, "dom_controlpoint");
138 if (vlen(( ( head.absmin + head.absmax ) * 0.5 ) - org) < sradius)
140 if(head.cnt > -1) // this is just being fought for
141 navigation_routerating(head, ratingscale, 5000);
142 else if(head.goalentity.cnt == 0) // unclaimed point
143 navigation_routerating(head, ratingscale * 0.5, 5000);
144 else if(head.goalentity.team != self.team) // other team's point
145 navigation_routerating(head, ratingscale * 0.2, 5000);
151 void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius)
153 if (autocvar_bot_nofire)
156 // don't chase players if we're under water
157 if(self.waterlevel>WATERLEVEL_WETFEET)
163 FOREACH_CLIENT(IS_PLAYER(it) && bot_shouldattack(it), LAMBDA(
164 // TODO: Merge this logic with the bot_shouldattack function
165 distance = vlen(it.origin - org);
166 if (distance < 100 || distance > sradius)
169 // rate only visible enemies
171 traceline(self.origin + self.view_ofs, it.origin, MOVE_NOMONSTERS, self);
172 if (trace_fraction < 1 || trace_ent != it)
176 if((it.flags & FL_INWATER) || (it.flags & FL_PARTIALGROUND))
180 if((it.flags & FL_ONGROUND) == 0)
182 traceline(it.origin, it.origin + '0 0 -1500', true, world);
183 t = pointcontents(trace_endpos + '0 0 1');
184 if(t != CONTENT_SOLID )
185 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
187 if(tracebox_hits_trigger_hurt(it.origin, it.mins, it.maxs, trace_endpos))
191 // TODO: rate waypoints near the targetted player at that moment, instead of the player itself
192 // adding a player as a goal seems to be quite dangerous, especially on space maps
193 // remove hack in navigation_poptouchedgoals() after performing this change
195 t = (self.health + self.armorvalue ) / (it.health + it.armorvalue );
196 navigation_routerating(it, t * ratingscale, 2000);
200 // legacy bot role for standard gamemodes
202 void havocbot_role_generic()
204 if(self.deadflag != DEAD_NO)
207 if (self.bot_strategytime < time)
209 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
210 navigation_goalrating_start();
211 havocbot_goalrating_items(10000, self.origin, 10000);
212 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
213 //havocbot_goalrating_waypoints(1, self.origin, 1000);
214 navigation_goalrating_end();
218 void havocbot_chooserole_generic()
220 self.havocbot_role = havocbot_role_generic;
223 void havocbot_chooserole()
225 LOG_TRACE("choosing a role...\n");
226 self.bot_strategytime = 0;
227 if(!MUTATOR_CALLHOOK(HavocBot_ChooseRole, self))
228 havocbot_chooserole_generic();