3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
10 #include "../navigation.qh"
12 .float max_armorvalue;
13 .float havocbot_role_timeout;
15 .void(entity this) havocbot_previous_role;
16 .void(entity this) havocbot_role;
18 void havocbot_goalrating_waypoints(entity this, float ratingscale, vector org, float sradius)
20 // rate waypoints only if there's no alternative goal
21 if(navigation_bestgoal)
26 sradius = max(range, (0.5 + random() * 0.5) * sradius);
29 IL_EACH(g_waypoints, vdist(it.origin - org, <, sradius)
30 && vdist(it.origin - org, >, max(100, sradius - range))
31 && !(it.wpflags & WAYPOINTFLAG_TELEPORT),
33 if(vdist(it.origin - this.wp_goal_prev0.origin, <, range * 1.5))
35 else if(vdist(it.origin - this.wp_goal_prev1.origin, <, range * 1.5))
38 f = 0.5 + random() * 0.5;
39 navigation_routerating(this, it, ratingscale * f, 2000);
41 if(navigation_bestgoal)
47 void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius)
49 float rating, discard, friend_distance, enemy_distance;
51 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
53 IL_EACH(g_items, it.bot_pickup,
59 if(!autocvar_bot_ai_timeitems)
61 if(!it.scheduledrespawntime)
63 if(it.respawntime < max(11, autocvar_bot_ai_timeitems_minrespawndelay))
65 if(it.respawntimejitter && !it.itemdef.instanceOfPowerup)
69 if(it.itemdef.instanceOfPowerup)
70 t = bound(0, skill / 10, 1) * 6;
74 if(time < it.scheduledrespawntime - t)
77 it.bot_pickup_respawning = true;
79 o = (it.absmin + it.absmax) * 0.5;
80 if(vdist(o - org, >, sradius) || (it == this.ignoregoal && time < this.ignoregoaltime) )
83 // Check if the item can be picked up safely
84 if(it.classname == "droppedweapon")
88 traceline(o, o + '0 0 -1500', true, NULL);
90 if(IN_LAVA(trace_endpos + '0 0 1'))
93 // this tracebox_hits_trigger_hurt call isn't needed:
94 // dropped weapons are removed as soon as they fall on a trigger_hurt
95 // and can't be rated while they are in the air
96 //if(tracebox_hits_trigger_hurt(it.origin, it.mins, it.maxs, trace_endpos))
101 if(IN_LAVA(it.origin + (it.mins + it.maxs) * 0.5))
107 friend_distance = 10000; enemy_distance = 10000;
111 FOREACH_CLIENT(IS_PLAYER(it) && it != this && !IS_DEAD(it),
113 if ( it.team == this.team )
115 if ( !IS_REAL_CLIENT(it) || discard )
118 if( vdist(it.origin - o, >, friend_distance) )
121 friend_distance = vlen(it.origin - o); // distance between player and item
124 if (picker.health && it.health > this.health) continue;
125 if (picker.armorvalue && it.armorvalue > this.armorvalue) continue;
127 if (picker.weapons && (picker.weapons & ~it.weapons)) continue;
129 if (picker.ammo_shells && it.ammo_shells > this.ammo_shells) continue;
130 if (picker.ammo_nails && it.ammo_nails > this.ammo_nails) continue;
131 if (picker.ammo_rockets && it.ammo_rockets > this.ammo_rockets) continue;
132 if (picker.ammo_cells && it.ammo_cells > this.ammo_cells) continue;
133 if (picker.ammo_plasma && it.ammo_plasma > this.ammo_plasma) continue;
139 // If enemy only track distances
140 // TODO: track only if visible ?
141 if( vdist(it.origin - o, <, enemy_distance) )
142 enemy_distance = vlen(it.origin - o); // distance between player and item
146 // Rate the item only if no one needs it, or if an enemy is closer to it
147 if ( (enemy_distance < friend_distance && vdist(o - org, <, enemy_distance)) ||
148 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
149 rating = it.bot_pickupevalfunc(this, it);
152 rating = it.bot_pickupevalfunc(this, it);
155 navigation_routerating(this, it, rating * ratingscale, 2000);
159 #define BOT_RATING_ENEMY 2500
160 void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius)
162 if (autocvar_bot_nofire)
165 // don't chase players if we're under water
166 if(this.waterlevel>WATERLEVEL_WETFEET)
169 ratingscale = ratingscale * 0.00005; // enemies are rated around 20000 already
172 FOREACH_CLIENT(IS_PLAYER(it) && bot_shouldattack(this, it), {
173 // TODO: Merge this logic with the bot_shouldattack function
174 if(vdist(it.origin - org, <, 100) || vdist(it.origin - org, >, sradius))
177 // rate only visible enemies
179 traceline(this.origin + this.view_ofs, it.origin, MOVE_NOMONSTERS, this);
180 if (trace_fraction < 1 || trace_ent != it)
184 t = ((this.health + this.armorvalue) - (it.health + it.armorvalue)) / 150;
185 t = bound(0, 1 + t, 3);
188 if (time < this.strength_finished - 1) t += 0.5;
189 if (time < it.strength_finished - 1) t -= 0.5;
191 t += max(0, 8 - skill) * 0.05; // less skilled bots attack more mindlessly
194 navigation_routerating(this, it, ratingscale * BOT_RATING_ENEMY, 2000);
198 // legacy bot role for standard gamemodes
200 void havocbot_role_generic(entity this)
205 if (this.bot_strategytime < time)
207 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
208 navigation_goalrating_start(this);
209 havocbot_goalrating_items(this, 10000, this.origin, 10000);
210 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
211 havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
212 navigation_goalrating_end(this);
214 if(IS_PLAYER(this.goalentity))
215 this.bot_strategytime = time + min(2, autocvar_bot_ai_strategyinterval);
219 void havocbot_chooserole_generic(entity this)
221 this.havocbot_role = havocbot_role_generic;
224 void havocbot_chooserole(entity this)
226 LOG_TRACE("choosing a role...");
227 this.bot_strategytime = 0;
228 if(!MUTATOR_CALLHOOK(HavocBot_ChooseRole, this))
229 havocbot_chooserole_generic(this);