8 #include "../navigation.qh"
10 .float max_armorvalue;
11 .float havocbot_role_timeout;
13 .void(entity this) havocbot_previous_role;
14 .void(entity this) havocbot_role;
16 void havocbot_goalrating_waypoints(entity this, float ratingscale, vector org, float sradius)
18 // rate waypoints only if there's no alternative goal
19 if(navigation_bestgoal)
24 sradius = max(range, (0.5 + random() * 0.5) * sradius);
27 IL_EACH(g_waypoints, vdist(it.origin - org, <, sradius)
28 && vdist(it.origin - org, >, max(100, sradius - range)),
30 if(vdist(it.origin - this.wp_goal_prev0.origin, <, range * 1.5))
32 else if(vdist(it.origin - this.wp_goal_prev1.origin, <, range * 1.5))
35 f = 0.5 + random() * 0.5;
36 navigation_routerating(this, it, ratingscale * f, 2000);
38 if(navigation_bestgoal)
44 void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius)
46 float rating, d, discard, friend_distance, enemy_distance;
48 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
50 IL_EACH(g_items, it.bot_pickup,
56 if(!it.scheduledrespawntime)
58 if(it.respawntime < 30 || (it.respawntimejitter && !it.itemdef.instanceOfPowerup))
62 if(it.itemdef.instanceOfPowerup)
63 t = bound(0, skill / 10, 1) * 6;
67 if(time < it.scheduledrespawntime - t)
70 it.bot_pickup_respawning = true;
72 o = (it.absmin + it.absmax) * 0.5;
73 if(vdist(o - org, >, sradius) || (it == this.ignoregoal && time < this.ignoregoaltime) )
76 // Check if the item can be picked up safely
77 if(it.classname == "droppedweapon")
79 traceline(o, o + '0 0 -1500', true, NULL);
81 d = pointcontents(trace_endpos + '0 0 1');
82 if(d == CONTENT_WATER || d == CONTENT_SLIME || d == CONTENT_LAVA)
84 // this tracebox_hits_trigger_hurt call isn't needed:
85 // dropped weapons are removed as soon as they fall on a trigger_hurt
86 // and can't be rated while they are in the air
87 //if(tracebox_hits_trigger_hurt(it.origin, it.mins, it.maxs, trace_endpos))
92 // Ignore items under water
93 traceline(it.origin + it.maxs, it.origin + it.maxs, MOVE_NORMAL, it);
94 if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
100 friend_distance = 10000; enemy_distance = 10000;
104 FOREACH_CLIENT(IS_PLAYER(it) && it != this && !IS_DEAD(it),
106 d = vlen(it.origin - o); // distance between player and item
108 if ( it.team == this.team )
110 if ( !IS_REAL_CLIENT(it) || discard )
113 if( d > friend_distance)
119 if (picker.health && it.health > this.health) continue;
120 if (picker.armorvalue && it.armorvalue > this.armorvalue) continue;
122 if (picker.weapons && (picker.weapons & ~it.weapons)) continue;
124 if (picker.ammo_shells && it.ammo_shells > this.ammo_shells) continue;
125 if (picker.ammo_nails && it.ammo_nails > this.ammo_nails) continue;
126 if (picker.ammo_rockets && it.ammo_rockets > this.ammo_rockets) continue;
127 if (picker.ammo_cells && it.ammo_cells > this.ammo_cells) continue;
128 if (picker.ammo_plasma && it.ammo_plasma > this.ammo_plasma) continue;
134 // If enemy only track distances
135 // TODO: track only if visible ?
136 if( d < enemy_distance )
141 // Rate the item only if no one needs it, or if an enemy is closer to it
142 if ( (enemy_distance < friend_distance && vdist(o - org, <, enemy_distance)) ||
143 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
144 rating = it.bot_pickupevalfunc(this, it);
147 rating = it.bot_pickupevalfunc(this, it);
150 navigation_routerating(this, it, rating * ratingscale, 2000);
154 #define BOT_RATING_ENEMY 2500
155 void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius)
157 if (autocvar_bot_nofire)
160 // don't chase players if we're under water
161 if(this.waterlevel>WATERLEVEL_WETFEET)
164 ratingscale = ratingscale * 0.00005; // enemies are rated around 20000 already
167 FOREACH_CLIENT(IS_PLAYER(it) && bot_shouldattack(this, it), LAMBDA(
168 // TODO: Merge this logic with the bot_shouldattack function
169 if(vdist(it.origin - org, <, 100) || vdist(it.origin - org, >, sradius))
172 // rate only visible enemies
174 traceline(this.origin + this.view_ofs, it.origin, MOVE_NOMONSTERS, this);
175 if (trace_fraction < 1 || trace_ent != it)
179 t = ((this.health + this.armorvalue) - (it.health + it.armorvalue)) / 150;
180 t = bound(0, 1 + t, 3);
183 if (time < this.strength_finished - 1) t += 0.5;
184 if (time < it.strength_finished - 1) t -= 0.5;
186 t += max(0, 8 - skill) * 0.05; // less skilled bots attack more mindlessly
189 navigation_routerating(this, it, ratingscale * BOT_RATING_ENEMY, 2000);
193 // legacy bot role for standard gamemodes
195 void havocbot_role_generic(entity this)
200 if (this.bot_strategytime < time)
202 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
203 navigation_goalrating_start(this);
204 havocbot_goalrating_items(this, 10000, this.origin, 10000);
205 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
206 havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
207 navigation_goalrating_end(this);
211 void havocbot_chooserole_generic(entity this)
213 this.havocbot_role = havocbot_role_generic;
216 void havocbot_chooserole(entity this)
218 LOG_TRACE("choosing a role...");
219 this.bot_strategytime = 0;
220 if(!MUTATOR_CALLHOOK(HavocBot_ChooseRole, this))
221 havocbot_chooserole_generic(this);