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_items(entity this, float ratingscale, vector org, float sradius)
18 float rating, d, discard, friend_distance, enemy_distance;
20 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
22 FOREACH_ENTITY_FLOAT(bot_pickup, true,
24 o = (it.absmin + it.absmax) * 0.5;
25 friend_distance = 10000; enemy_distance = 10000;
28 if(!it.solid || vdist(o - org, >, sradius) || (it == this.ignoregoal && time < this.ignoregoaltime) )
31 // Check if the item can be picked up safely
32 if(it.classname == "droppedweapon")
34 traceline(o, o + '0 0 -1500', true, NULL);
36 d = pointcontents(trace_endpos + '0 0 1');
37 if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
39 if(tracebox_hits_trigger_hurt(it.origin, it.mins, it.maxs, trace_endpos))
44 // Ignore items under water
45 traceline(it.origin + it.maxs, it.origin + it.maxs, MOVE_NORMAL, it);
46 if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
55 FOREACH_CLIENT(IS_PLAYER(it) && it != this && !IS_DEAD(it),
57 d = vlen(it.origin - o); // distance between player and item
59 if ( it.team == this.team )
61 if ( !IS_REAL_CLIENT(it) || discard )
64 if( d > friend_distance)
71 if( picker.health && it.health > this.health )
74 if( picker.armorvalue && it.armorvalue > this.armorvalue)
78 if( picker.weapons & ~it.weapons )
81 if (picker.ammo_shells && it.ammo_shells > this.ammo_shells)
84 if (picker.ammo_nails && it.ammo_nails > this.ammo_nails)
87 if (picker.ammo_rockets && it.ammo_rockets > this.ammo_rockets)
90 if (picker.ammo_cells && it.ammo_cells > this.ammo_cells)
93 if (picker.ammo_plasma && it.ammo_plasma > this.ammo_plasma)
100 // If enemy only track distances
101 // TODO: track only if visible ?
102 if( d < enemy_distance )
107 // Rate the item only if no one needs it, or if an enemy is closer to it
108 if ( (enemy_distance < friend_distance && vdist(o - org, <, enemy_distance)) ||
109 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
110 rating = it.bot_pickupevalfunc(this, it);
114 rating = it.bot_pickupevalfunc(this, it);
117 navigation_routerating(this, it, rating * ratingscale, 2000);
121 void havocbot_goalrating_controlpoints(entity this, float ratingscale, vector org, float sradius)
123 FOREACH_ENTITY_CLASS("dom_controlpoint", vdist((((it.absmin + it.absmax) * 0.5) - org), <, sradius),
125 if(it.cnt > -1) // this is just being fought
126 navigation_routerating(this, it, ratingscale, 5000);
127 else if(it.goalentity.cnt == 0) // unclaimed
128 navigation_routerating(this, it, ratingscale * 0.5, 5000);
129 else if(it.goalentity.team != this.team) // other team's point
130 navigation_routerating(this, it, ratingscale * 0.2, 5000);
134 void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius)
136 if (autocvar_bot_nofire)
139 // don't chase players if we're under water
140 if(this.waterlevel>WATERLEVEL_WETFEET)
145 FOREACH_CLIENT(IS_PLAYER(it) && bot_shouldattack(this, it), LAMBDA(
146 // TODO: Merge this logic with the bot_shouldattack function
147 if(vdist(it.origin - org, <, 100) || vdist(it.origin - org, >, sradius))
150 // rate only visible enemies
152 traceline(this.origin + this.view_ofs, it.origin, MOVE_NOMONSTERS, this);
153 if (trace_fraction < 1 || trace_ent != it)
157 if((it.flags & FL_INWATER) || (it.flags & FL_PARTIALGROUND))
161 if((IS_ONGROUND(it)) == 0)
163 traceline(it.origin, it.origin + '0 0 -1500', true, NULL);
164 t = pointcontents(trace_endpos + '0 0 1');
165 if(t != CONTENT_SOLID )
166 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
168 if(tracebox_hits_trigger_hurt(it.origin, it.mins, it.maxs, trace_endpos))
172 // TODO: rate waypoints near the targetted player at that moment, instead of the player itthis
173 // adding a player as a goal seems to be quite dangerous, especially on space maps
174 // remove hack in navigation_poptouchedgoals() after performing this change
176 t = (this.health + this.armorvalue ) / (it.health + it.armorvalue );
177 navigation_routerating(this, it, t * ratingscale, 2000);
181 // legacy bot role for standard gamemodes
183 void havocbot_role_generic(entity this)
188 if (this.bot_strategytime < time)
190 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
191 navigation_goalrating_start(this);
192 havocbot_goalrating_items(this, 10000, this.origin, 10000);
193 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
194 //havocbot_goalrating_waypoints(1, this.origin, 1000);
195 navigation_goalrating_end(this);
199 void havocbot_chooserole_generic(entity this)
201 this.havocbot_role = havocbot_role_generic;
204 void havocbot_chooserole(entity this)
206 LOG_TRACE("choosing a role...");
207 this.bot_strategytime = 0;
208 if(!MUTATOR_CALLHOOK(HavocBot_ChooseRole, this))
209 havocbot_chooserole_generic(this);