Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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.

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:29
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
#define LOG_TRACE(...)
Definition log.qh:76
void havocbot_chooserole_generic(entity this)
Definition roles.qc:236

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

Referenced by havocbot_setupbot().

◆ havocbot_chooserole_generic()

void havocbot_chooserole_generic ( entity this)

Definition at line 236 of file roles.qc.

237{
238 this.havocbot_role = havocbot_role_generic;
239}
void havocbot_role_generic(entity this)
Definition roles.qc:219

References entity(), and havocbot_role_generic().

Referenced by havocbot_chooserole().

◆ havocbot_goalrating_enemyplayers()

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

Definition at line 176 of file roles.qc.

177{
179 return;
180
181 // don't chase players if we're under water
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 skill
Definition api.qh:35
void navigation_routerating(entity this, entity e, float f, float rangebias)
bool bot_shouldattack(entity this, entity e)
Definition aim.qc:97
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
float autocvar_sv_maxspeed
Definition player.qh:53
float waterlevel
Definition player.qh:226
#define IS_PLAYER(s)
Definition player.qh:243
float time
bool autocvar_bot_nofire
Definition cvars.qh:51
RES_ARMOR
Definition ent_cs.qc:130
float bound(float min, float value, float max)
float max(float f,...)
const int WATERLEVEL_WETFEET
Definition movetypes.qh:12
const float BOT_RATING_ENEMY
Definition roles.qh:3
vector org
Definition self.qh:92
float StatusEffects_gettime(StatusEffect this, entity actor)
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:50
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8
#define vec2(...)
Definition vector.qh:90

References autocvar_bot_nofire, autocvar_sv_maxspeed, BOT_RATING_ENEMY, bot_shouldattack(), bound(), entity(), FOREACH_CLIENT, GetResource(), IS_PLAYER, max(), navigation_routerating(), org, RES_ARMOR, skill, StatusEffects_gettime(), time, vdist, vec2, vector, 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(), havocbot_role_ons_offense(), havocbot_role_tka_carrier(), havocbot_role_tka_collector(), and void().

◆ 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.

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 (item.itemdef.instanceOfPowerup) {return true;}
51 if (this.items & IT_UNLIMITED_AMMO) {return true;}
52 if (GetResource(item, RES_SHELLS) && GetResource(player, RES_SHELLS) <= GetResource(this, RES_SHELLS)) {return true;}
53 if (GetResource(item, RES_BULLETS) && GetResource(player, RES_BULLETS) <= GetResource(this, RES_BULLETS)) {return true;}
54 if (GetResource(item, RES_ROCKETS) && GetResource(player, RES_ROCKETS) <= GetResource(this, RES_ROCKETS)) {return true;}
55 if (GetResource(item, RES_CELLS) && GetResource(player, RES_CELLS) <= GetResource(this, RES_CELLS)) {return true;}
56
57 return false;
58};
const int IT_UNLIMITED_AMMO
Definition item.qh:23
int items
Definition player.qh:227
#define STAT(...)
Definition stats.qh:82

References entity(), GetResource(), IT_UNLIMITED_AMMO, items, RES_ARMOR, and STAT.

Referenced by havocbot_goalrating_item_pickable_check_players().

◆ 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.

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
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 IS_DEAD(s)
Definition player.qh:245
float autocvar_bot_ai_friends_aware_pickup_radius
Definition cvars.qh:35
const float FLOAT_MAX
Definition float.qh:3
bool havocbot_goalrating_item_can_be_left_to_teammate(entity this, entity player, entity item)
Definition roles.qc:45
bool teamplay
Definition teams.qh:59
#define IS_REAL_CLIENT(v)
Definition utils.qh:17
#define vlen2(v)
Definition vector.qh:4

References autocvar_bot_ai_friends_aware_pickup_radius, entity(), FLOAT_MAX, FOREACH_CLIENT, havocbot_goalrating_item_can_be_left_to_teammate(), IS_DEAD, IS_PLAYER, IS_REAL_CLIENT, org, STAT, teamplay, vector, and vlen2.

Referenced by havocbot_goalrating_items(), and navigation_goalrating_timeout_can_be_anticipated().

◆ havocbot_goalrating_items()

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

Definition at line 106 of file roles.qc.

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_IS_LOOT(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}
entity ignoregoal
Definition api.qh:99
float ignoregoaltime
Definition api.qh:98
#define IN_LAVA(pos)
Definition bot.qh:84
vector trace_endpos
#define IL_EACH(this, cond, body)
#define ITEM_IS_LOOT(item)
Returns whether the item is loot.
Definition spawning.qh:39
#define IS_ONGROUND(s)
Definition movetypes.qh:16
#define NULL
Definition post.qh:14
bool havocbot_goalrating_item_pickable_check_players(entity this, vector org, entity item, vector item_org)
Definition roles.qc:60
vector
Definition self.qh:92
IntrusiveList g_items
Definition items.qh:125

References entity(), g_items, havocbot_goalrating_item_pickable_check_players(), ignoregoal, ignoregoaltime, IL_EACH, IN_LAVA, IS_ONGROUND, ITEM_IS_LOOT, navigation_routerating(), NULL, org, 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(), havocbot_role_ons_offense(), havocbot_role_tka_carrier(), havocbot_role_tka_collector(), and void().

◆ havocbot_goalrating_waypoints()

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

Definition at line 16 of file roles.qc.

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};
const int WAYPOINTFLAG_TELEPORT
Definition api.qh:13
IntrusiveList g_waypoints
Definition api.qh:148
float random(void)
entity navigation_bestgoal
Definition navigation.qh:15

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

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

◆ havocbot_role_generic()

void havocbot_role_generic ( entity this)

Definition at line 219 of file roles.qc.

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)
void navigation_goalrating_timeout_set(entity this)
Definition navigation.qc:20
bool navigation_goalrating_timeout(entity this)
Definition navigation.qc:44
void navigation_goalrating_end(entity this)
vector origin
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
void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius)
Definition roles.qc:176

References entity(), 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().