6 #include "../navigation.qh"
9 .float havocbot_role_timeout;
11 .void(entity this) havocbot_previous_role;
12 .void(entity this) havocbot_role;
14 void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius)
17 float rating, d, discard, distance, friend_distance, enemy_distance;
19 ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
20 head = findchainfloat(bot_pickup, true);
24 o = (head.absmin + head.absmax) * 0.5;
25 distance = vlen(o - org);
26 friend_distance = 10000; enemy_distance = 10000;
29 if(!head.solid || distance > sradius || (head == this.ignoregoal && time < this.ignoregoaltime) )
35 // Check if the item can be picked up safely
36 if(head.classname == "droppedweapon")
38 traceline(o, o + '0 0 -1500', true, NULL);
40 d = pointcontents(trace_endpos + '0 0 1');
41 if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
46 if(tracebox_hits_trigger_hurt(head.origin, head.mins, head.maxs, trace_endpos))
54 // Ignore items under water
55 traceline(head.origin + head.maxs, head.origin + head.maxs, MOVE_NORMAL, head);
56 if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
67 FOREACH_CLIENT(IS_PLAYER(it) && it != this && !IS_DEAD(it), LAMBDA(
68 d = vlen(it.origin - o); // distance between player and item
70 if ( it.team == this.team )
72 if ( !IS_REAL_CLIENT(it) || discard )
75 if( d > friend_distance)
82 if( head.health && it.health > this.health )
85 if( head.armorvalue && it.armorvalue > this.armorvalue)
89 if( head.weapons & ~it.weapons )
92 if (head.ammo_shells && it.ammo_shells > this.ammo_shells)
95 if (head.ammo_nails && it.ammo_nails > this.ammo_nails)
98 if (head.ammo_rockets && it.ammo_rockets > this.ammo_rockets)
101 if (head.ammo_cells && it.ammo_cells > this.ammo_cells)
104 if (head.ammo_plasma && it.ammo_plasma > this.ammo_plasma)
111 // If enemy only track distances
112 // TODO: track only if visible ?
113 if( d < enemy_distance )
118 // Rate the item only if no one needs it, or if an enemy is closer to it
119 if ( (enemy_distance < friend_distance && distance < enemy_distance) ||
120 (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
121 rating = head.bot_pickupevalfunc(this, head);
125 rating = head.bot_pickupevalfunc(this, head);
128 navigation_routerating(this, head, rating * ratingscale, 2000);
133 void havocbot_goalrating_controlpoints(entity this, float ratingscale, vector org, float sradius)
136 head = findchain(classname, "dom_controlpoint");
139 if(vdist((((head.absmin + head.absmax) * 0.5) - org), <, sradius))
141 if(head.cnt > -1) // this is just being fought for
142 navigation_routerating(this, head, ratingscale, 5000);
143 else if(head.goalentity.cnt == 0) // unclaimed point
144 navigation_routerating(this, head, ratingscale * 0.5, 5000);
145 else if(head.goalentity.team != this.team) // other team's point
146 navigation_routerating(this, head, ratingscale * 0.2, 5000);
152 void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius)
154 if (autocvar_bot_nofire)
157 // don't chase players if we're under water
158 if(this.waterlevel>WATERLEVEL_WETFEET)
163 FOREACH_CLIENT(IS_PLAYER(it) && bot_shouldattack(this, it), LAMBDA(
164 // TODO: Merge this logic with the bot_shouldattack function
165 if(vdist(it.origin - org, <, 100) || vdist(it.origin - org, >, sradius))
168 // rate only visible enemies
170 traceline(this.origin + this.view_ofs, it.origin, MOVE_NOMONSTERS, this);
171 if (trace_fraction < 1 || trace_ent != it)
175 if((it.flags & FL_INWATER) || (it.flags & FL_PARTIALGROUND))
179 if((IS_ONGROUND(it)) == 0)
181 traceline(it.origin, it.origin + '0 0 -1500', true, NULL);
182 t = pointcontents(trace_endpos + '0 0 1');
183 if(t != CONTENT_SOLID )
184 if(t & CONTENT_WATER || t & CONTENT_SLIME || t & CONTENT_LAVA)
186 if(tracebox_hits_trigger_hurt(it.origin, it.mins, it.maxs, trace_endpos))
190 // TODO: rate waypoints near the targetted player at that moment, instead of the player itthis
191 // adding a player as a goal seems to be quite dangerous, especially on space maps
192 // remove hack in navigation_poptouchedgoals() after performing this change
194 t = (this.health + this.armorvalue ) / (it.health + it.armorvalue );
195 navigation_routerating(this, it, t * ratingscale, 2000);
199 // legacy bot role for standard gamemodes
201 void havocbot_role_generic(entity this)
206 if (this.bot_strategytime < time)
208 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
209 navigation_goalrating_start(this);
210 havocbot_goalrating_items(this, 10000, this.origin, 10000);
211 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
212 //havocbot_goalrating_waypoints(1, this.origin, 1000);
213 navigation_goalrating_end(this);
217 void havocbot_chooserole_generic(entity this)
219 this.havocbot_role = havocbot_role_generic;
222 void havocbot_chooserole(entity this)
224 LOG_TRACE("choosing a role...\n");
225 this.bot_strategytime = 0;
226 if(!MUTATOR_CALLHOOK(HavocBot_ChooseRole, this))
227 havocbot_chooserole_generic(this);