Xonotic
roles.qc File Reference
+ Include dependency graph for roles.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void havocbot_chooserole (entity this)
 
void havocbot_chooserole_generic (entity this)
 
void havocbot_goalrating_enemyplayers (entity this, float ratingscale, vector org, float sradius)
 
bool havocbot_goalrating_item_can_be_left_to_teammate (entity this, entity player, entity item)
 
bool havocbot_goalrating_item_pickable_check_players (entity this, vector org, entity item, vector item_org)
 
void havocbot_goalrating_items (entity this, float ratingscale, vector org, float sradius)
 
void havocbot_goalrating_waypoints (entity this, float ratingscale, vector org, float sradius)
 
void havocbot_role_generic (entity this)
 

Function Documentation

◆ havocbot_chooserole()

void havocbot_chooserole ( entity  this)

Definition at line 241 of file roles.qc.

References havocbot_chooserole_generic(), LOG_TRACE, MUTATOR_CALLHOOK, and navigation_goalrating_timeout_force().

Referenced by havocbot_setupbot().

242 {
243  LOG_TRACE("choosing a role...");
245  if(!MUTATOR_CALLHOOK(HavocBot_ChooseRole, this))
247 }
void navigation_goalrating_timeout_force(entity this)
Definition: navigation.qc:28
void havocbot_chooserole_generic(entity this)
Definition: roles.qc:236
#define LOG_TRACE(...)
Definition: log.qh:81
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ havocbot_chooserole_generic()

void havocbot_chooserole_generic ( entity  this)

Definition at line 236 of file roles.qc.

References havocbot_role_generic().

Referenced by havocbot_chooserole().

237 {
238  this.havocbot_role = havocbot_role_generic;
239 }
void havocbot_role_generic(entity this)
Definition: roles.qc:219
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ havocbot_goalrating_enemyplayers()

void havocbot_goalrating_enemyplayers ( entity  this,
float  ratingscale,
vector  org,
float  sradius 
)

Definition at line 176 of file roles.qc.

References autocvar_bot_nofire, BOT_RATING_ENEMY, bot_shouldattack(), bound(), FOREACH_CLIENT, GetResource(), IS_PLAYER, max(), navigation_routerating(), RES_HEALTH, skill, time, vdist, vec2, waterlevel, and WATERLEVEL_WETFEET.

Referenced by havocbot_role_ast_defense(), havocbot_role_ast_offense(), havocbot_role_ctf_defense(), havocbot_role_ctf_middle(), havocbot_role_ft_freeing(), havocbot_role_ft_offense(), havocbot_role_generic(), havocbot_role_ka_carrier(), havocbot_role_ka_collector(), and havocbot_role_ons_offense().

177 {
179  return;
180 
181  // don't chase players if we're under water
182  if(this.waterlevel > WATERLEVEL_WETFEET)
183  return;
184 
185  ratingscale = ratingscale * 0.0001;
186 
187  FOREACH_CLIENT(IS_PLAYER(it) && bot_shouldattack(this, it), {
188  // TODO: Merge this logic with the bot_shouldattack function
189  if(vdist(it.origin - org, <, 100) || vdist(it.origin - org, >, sradius))
190  continue;
191  if(vdist(vec2(it.velocity), >, autocvar_sv_maxspeed * 2))
192  continue;
193 
194  // rate only visible enemies
195  /*
196  traceline(this.origin + this.view_ofs, it.origin, MOVE_NOMONSTERS, this);
197  if (trace_fraction < 1 || trace_ent != it)
198  continue;
199  */
200 
201  float t = ((GetResource(this, RES_HEALTH) + GetResource(this, RES_ARMOR)) - (GetResource(it, RES_HEALTH) + GetResource(it, RES_ARMOR))) / 150;
202  t = bound(0, 1 + t, 3);
203  if (skill > 3)
204  {
205  if (time < StatusEffects_gettime(STATUSEFFECT_Strength, this) - 1) t += 0.5;
206  if (time < StatusEffects_gettime(STATUSEFFECT_Strength, it) - 1) t -= 0.5;
207  if (time < StatusEffects_gettime(STATUSEFFECT_Shield, this) - 1) t += 0.2;
208  if (time < StatusEffects_gettime(STATUSEFFECT_Shield, it) - 1) t -= 0.4;
209  }
210  t += max(0, 8 - skill) * 0.05; // less skilled bots attack more mindlessly
211  ratingscale *= t;
212  if (ratingscale > 0)
213  navigation_routerating(this, it, ratingscale * BOT_RATING_ENEMY, 2000);
214  });
215 }
float waterlevel
Definition: progsdefs.qc:181
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
float skill
Definition: api.qh:35
void navigation_routerating(entity this, entity e, float f, float rangebias)
Definition: navigation.qc:1220
RES_HEALTH
Definition: ent_cs.qc:126
const float BOT_RATING_ENEMY
Definition: roles.qh:3
const int WATERLEVEL_WETFEET
Definition: movetypes.qh:12
bool autocvar_bot_nofire
Definition: cvars.qh:54
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
#define vec2(...)
Definition: vector.qh:90
bool bot_shouldattack(entity this, entity e)
Definition: aim.qc:112
float time
Definition: csprogsdefs.qc:16
#define IS_PLAYER(v)
Definition: utils.qh:9
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ havocbot_goalrating_item_can_be_left_to_teammate()

bool havocbot_goalrating_item_can_be_left_to_teammate ( entity  this,
entity  player,
entity  item 
)

Definition at line 45 of file roles.qc.

References GetResource(), and RES_HEALTH.

46 {
47  if (GetResource(item, RES_HEALTH) && GetResource(player, RES_HEALTH) <= GetResource(this, RES_HEALTH)) {return true;}
48  if (GetResource(item, RES_ARMOR) && GetResource(player, RES_ARMOR) <= GetResource(this, RES_ARMOR)) {return true;}
49  if (STAT(WEAPONS, item) && !(STAT(WEAPONS, player) & STAT(WEAPONS, item))) {return true;}
50  if (GetResource(item, RES_SHELLS) && GetResource(player, RES_SHELLS) <= GetResource(this, RES_SHELLS)) {return true;}
51  if (GetResource(item, RES_BULLETS) && GetResource(player, RES_BULLETS) <= GetResource(this, RES_BULLETS)) {return true;}
52  if (GetResource(item, RES_ROCKETS) && GetResource(player, RES_ROCKETS) <= GetResource(this, RES_ROCKETS)) {return true;}
53  if (GetResource(item, RES_CELLS) && GetResource(player, RES_CELLS) <= GetResource(this, RES_CELLS)) {return true;}
54  if (GetResource(item, RES_PLASMA) && GetResource(player, RES_PLASMA) <= GetResource(this, RES_PLASMA)) {return true;}
55  if (item.itemdef.instanceOfPowerup) {return true;}
56 
57  return false;
58 };
RES_HEALTH
Definition: ent_cs.qc:126
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
+ Here is the call graph for this function:

◆ havocbot_goalrating_item_pickable_check_players()

bool havocbot_goalrating_item_pickable_check_players ( entity  this,
vector  org,
entity  item,
vector  item_org 
)

Definition at line 60 of file roles.qc.

References autocvar_bot_ai_friends_aware_pickup_radius, FLOAT_MAX, FOREACH_CLIENT, IS_DEAD, IS_PLAYER, teamplay, and vlen2.

Referenced by havocbot_goalrating_items(), and navigation_goalrating_timeout_can_be_anticipated().

61 {
62  if(!teamplay)
63  return true;
64 
65  // these variables hold squared distances in order to optimize code
66  float friend_dist2 = FLOAT_MAX;
67  float enemy_dist2 = FLOAT_MAX;
68  float dist2;
69 
70  FOREACH_CLIENT(IS_PLAYER(it) && it != this && !(IS_DEAD(it) || STAT(FROZEN, it)),
71  {
72  if (it.team == this.team)
73  {
74  if (!IS_REAL_CLIENT(it))
75  continue;
76 
77  dist2 = vlen2(it.origin - item_org);
78  if (dist2 > friend_dist2)
79  continue;
80 
81  if(havocbot_goalrating_item_can_be_left_to_teammate(this, it, item))
82  {
83  friend_dist2 = dist2;
84  continue;
85  }
86  }
87  else
88  {
89  // If enemy only track distances
90  // TODO: track only if visible ?
91  dist2 = vlen2(it.origin - item_org);
92  if (dist2 < enemy_dist2)
93  enemy_dist2 = dist2;
94  }
95  });
96 
97  // Rate the item only if no one needs it, or if an enemy is closer to it
98  dist2 = vlen2(item_org - org);
99  if ((enemy_dist2 < friend_dist2 && dist2 < enemy_dist2)
100  || (friend_dist2 > autocvar_bot_ai_friends_aware_pickup_radius ** 2)
101  || (dist2 < friend_dist2 && dist2 < 200 ** 2))
102  return true;
103  return false;
104 };
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
#define vlen2(v)
Definition: vector.qh:4
float teamplay
Definition: progsdefs.qc:31
#define IS_DEAD(s)
Definition: utils.qh:26
float autocvar_bot_ai_friends_aware_pickup_radius
Definition: cvars.qh:38
#define IS_PLAYER(v)
Definition: utils.qh:9
const float FLOAT_MAX
Definition: float.qh:3
+ Here is the caller graph for this function:

◆ havocbot_goalrating_items()

void havocbot_goalrating_items ( entity  this,
float  ratingscale,
vector  org,
float  sradius 
)

Definition at line 106 of file roles.qc.

References g_items, havocbot_goalrating_item_pickable_check_players(), ignoregoal, ignoregoaltime, IL_EACH, IN_LAVA, IS_ONGROUND, Item_IsLoot(), navigation_routerating(), NULL, time, trace_endpos, vdist, and vector().

Referenced by havocbot_goalrating_kh(), havocbot_role_ast_defense(), havocbot_role_ast_offense(), havocbot_role_ctf_carrier(), havocbot_role_ctf_defense(), havocbot_role_ctf_escort(), havocbot_role_ctf_middle(), havocbot_role_ctf_offense(), havocbot_role_ctf_retriever(), havocbot_role_dom(), havocbot_role_ft_freeing(), havocbot_role_ft_offense(), havocbot_role_generic(), havocbot_role_ka_carrier(), havocbot_role_ka_collector(), and havocbot_role_ons_offense().

107 {
108  ratingscale = ratingscale * 0.0001;
109 
110  IL_EACH(g_items, it.bot_pickup,
111  {
112  // ignore if bot already rated this item with a higher ratingscale
113  // NOTE: this code assumes each bot rates items in a different frame
114  if(it.bot_ratingscale_time == time && ratingscale < it.bot_ratingscale)
115  continue;
116 
117  if(!it.solid)
118  {
119  if(!autocvar_bot_ai_timeitems)
120  continue;
121  if(!it.scheduledrespawntime)
122  continue;
123  if(it.respawntime < max(11, autocvar_bot_ai_timeitems_minrespawndelay))
124  continue;
125  if(it.respawntimejitter && !it.itemdef.instanceOfPowerup)
126  continue;
127 
128  float t = 0;
129  if(it.itemdef.instanceOfPowerup)
130  t = bound(0, skill / 10, 1) * 6;
131  else if(skill >= 9)
132  t = 4;
133 
134  if(time < it.scheduledrespawntime - t)
135  continue;
136 
137  it.bot_pickup_respawning = true;
138  }
139  vector o = (it.absmin + it.absmax) * 0.5;
140  if(vdist(o - org, >, sradius) || (it == this.ignoregoal && time < this.ignoregoaltime) )
141  continue;
142 
143  // Check if the item can be picked up safely
144  if(Item_IsLoot(it))
145  {
146  if(!IS_ONGROUND(it))
147  continue;
148  traceline(o, o + '0 0 -1500', true, NULL);
149 
150  if(IN_LAVA(trace_endpos + '0 0 1'))
151  continue;
152 
153  // this tracebox_hits_trigger_hurt call isn't needed:
154  // dropped weapons are removed as soon as they fall on a trigger_hurt
155  // and can't be rated while they are in the air
156  //if(tracebox_hits_trigger_hurt(it.origin, it.mins, it.maxs, trace_endpos))
157  // continue;
158  }
159  else
160  {
161  if(IN_LAVA(it.origin + (it.mins + it.maxs) * 0.5))
162  continue;
163  }
164 
166  continue;
167 
168  it.bot_ratingscale_time = time;
169  it.bot_ratingscale = ratingscale;
170  float rating = it.bot_pickupevalfunc(this, it);
171  if(rating > 0)
172  navigation_routerating(this, it, rating * ratingscale, 2000);
173  });
174 }
#define IL_EACH(this, cond, body)
float ignoregoaltime
Definition: api.qh:98
entity ignoregoal
Definition: api.qh:99
#define IN_LAVA(pos)
Definition: bot.qh:83
#define IS_ONGROUND(s)
Definition: movetypes.qh:16
void navigation_routerating(entity this, entity e, float f, float rangebias)
Definition: navigation.qc:1220
IntrusiveList g_items
Definition: items.qh:126
#define NULL
Definition: post.qh:17
vector trace_endpos
Definition: csprogsdefs.qc:37
vector(float skel, float bonenum) _skel_get_boneabs_hidden
bool havocbot_goalrating_item_pickable_check_players(entity this, vector org, entity item, vector item_org)
Definition: roles.qc:60
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
bool Item_IsLoot(entity item)
Returns whether the item is loot.
Definition: spawning.qc:121
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ havocbot_goalrating_waypoints()

void havocbot_goalrating_waypoints ( entity  this,
float  ratingscale,
vector  org,
float  sradius 
)

Definition at line 16 of file roles.qc.

References g_waypoints, IL_EACH, max(), navigation_bestgoal, random(), vdist, and WAYPOINTFLAG_TELEPORT.

Referenced by havocbot_role_dom(), havocbot_role_ft_freeing(), havocbot_role_ft_offense(), havocbot_role_generic(), and havocbot_role_ka_carrier().

17 {
18  // rate waypoints only if there's no alternative goal
20  return;
21 
22  float f;
23  float range = 500;
24  sradius = max(range, (0.5 + random() * 0.5) * sradius);
25  while(sradius > 100)
26  {
27  IL_EACH(g_waypoints, vdist(it.origin - org, <, sradius)
28  && vdist(it.origin - org, >, max(100, sradius - range))
29  && !(it.wpflags & WAYPOINTFLAG_TELEPORT),
30  {
31  if(vdist(it.origin - this.wp_goal_prev0.origin, <, range * 1.5))
32  f = 0.1;
33  else if(vdist(it.origin - this.wp_goal_prev1.origin, <, range * 1.5))
34  f = 0.1;
35  else
36  f = 0.5 + random() * 0.5;
37  navigation_routerating(this, it, ratingscale * f, 2000);
38  });
40  break;
41  sradius -= range;
42  }
43 };
#define IL_EACH(this, cond, body)
const int WAYPOINTFLAG_TELEPORT
Definition: api.qh:13
IntrusiveList g_waypoints
Definition: api.qh:148
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ havocbot_role_generic()

void havocbot_role_generic ( entity  this)

Definition at line 219 of file roles.qc.

References havocbot_goalrating_enemyplayers(), havocbot_goalrating_items(), havocbot_goalrating_waypoints(), IS_DEAD, navigation_goalrating_end(), navigation_goalrating_start(), navigation_goalrating_timeout(), navigation_goalrating_timeout_set(), and origin.

Referenced by havocbot_chooserole_generic().

220 {
221  if(IS_DEAD(this))
222  return;
223 
225  {
227  havocbot_goalrating_items(this, 10000, this.origin, 10000);
228  havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
229  havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
231 
233  }
234 }
void navigation_goalrating_start(entity this)
Definition: navigation.qc:1830
void navigation_goalrating_end(entity this)
Definition: navigation.qc:1845
void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius)
Definition: roles.qc:176
origin
Definition: ent_cs.qc:114
void havocbot_goalrating_waypoints(entity this, float ratingscale, vector org, float sradius)
Definition: roles.qc:16
void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius)
Definition: roles.qc:106
bool navigation_goalrating_timeout(entity this)
Definition: navigation.qc:43
#define IS_DEAD(s)
Definition: utils.qh:26
void navigation_goalrating_timeout_set(entity this)
Definition: navigation.qc:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function: