Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_powerups.qc File Reference
#include "sv_powerups.qh"
Include dependency graph for sv_powerups.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 MUTATOR_HOOKFUNCTION (powerups, BotShouldAttack)
 MUTATOR_HOOKFUNCTION (powerups, BuildMutatorsPrettyString)
 MUTATOR_HOOKFUNCTION (powerups, BuildMutatorsString)
 MUTATOR_HOOKFUNCTION (powerups, CustomizeWaypoint)
 MUTATOR_HOOKFUNCTION (powerups, Damage_Calculate)
 MUTATOR_HOOKFUNCTION (powerups, ItemTouched)
 MUTATOR_HOOKFUNCTION (powerups, LogDeath_AppendItemCodes)
 MUTATOR_HOOKFUNCTION (powerups, MonsterValidTarget)
 MUTATOR_HOOKFUNCTION (powerups, PlayerDies)
 MUTATOR_HOOKFUNCTION (powerups, PlayerPhysics_UpdateStats)
 MUTATOR_HOOKFUNCTION (powerups, PlayerUseKey)
 MUTATOR_HOOKFUNCTION (powerups, W_PlayStrengthSound)
 MUTATOR_HOOKFUNCTION (powerups, WeaponRateFactor)
void powerups_DropItem (entity this, StatusEffect effect, bool freezeTimer)
void powerups_DropItem_Think (entity this)

Function Documentation

◆ MUTATOR_HOOKFUNCTION() [1/13]

MUTATOR_HOOKFUNCTION ( powerups ,
BotShouldAttack  )

Definition at line 204 of file sv_powerups.qc.

205{
206 entity targ = M_ARGV(1, entity);
207
208 if(StatusEffects_active(STATUSEFFECT_Invisibility, targ))
209 return true;
210}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define M_ARGV(x, type)
Definition events.qh:17
bool StatusEffects_active(StatusEffect this, entity actor)

References entity(), M_ARGV, and StatusEffects_active().

◆ MUTATOR_HOOKFUNCTION() [2/13]

MUTATOR_HOOKFUNCTION ( powerups ,
BuildMutatorsPrettyString  )

Definition at line 196 of file sv_powerups.qc.

197{
198 if(autocvar_g_powerups == 0)
199 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", No powerups");
200 if(autocvar_g_powerups > 0)
201 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Powerups");
202}
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
int autocvar_g_powerups
Definition sv_powerups.qh:7

References autocvar_g_powerups, M_ARGV, and strcat().

◆ MUTATOR_HOOKFUNCTION() [3/13]

MUTATOR_HOOKFUNCTION ( powerups ,
BuildMutatorsString  )

Definition at line 212 of file sv_powerups.qc.

213{
214 if(autocvar_g_powerups == 0)
215 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":no_powerups");
216 if(autocvar_g_powerups > 0)
217 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":powerups");
218}

References autocvar_g_powerups, M_ARGV, and strcat().

◆ MUTATOR_HOOKFUNCTION() [4/13]

MUTATOR_HOOKFUNCTION ( powerups ,
CustomizeWaypoint  )

Definition at line 61 of file sv_powerups.qc.

62{
63 entity wp = M_ARGV(0, entity);
64 entity player = M_ARGV(1, entity);
65
67
68 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
69 // but only apply this to real players, not to spectators
70 if(IS_CLIENT(wp.owner) && (e == player) && DIFF_TEAM(wp.owner, e) && StatusEffects_active(STATUSEFFECT_Invisibility, wp.owner))
71 return true;
72}
#define IS_CLIENT(s)
Definition player.qh:242
#define DIFF_TEAM(a, b)
Definition teams.qh:242
entity WaypointSprite_getviewentity(entity e)

References DIFF_TEAM, entity(), IS_CLIENT, M_ARGV, StatusEffects_active(), and WaypointSprite_getviewentity().

◆ MUTATOR_HOOKFUNCTION() [5/13]

MUTATOR_HOOKFUNCTION ( powerups ,
Damage_Calculate  )

Definition at line 30 of file sv_powerups.qc.

31{
32 entity attacker = M_ARGV(1, entity);
33 entity targ = M_ARGV(2, entity);
34
35 // apply strength multiplier
36 if(StatusEffects_active(STATUSEFFECT_Strength, attacker))
37 {
38 if(targ == attacker)
39 {
42 }
43 else
44 {
47 }
48 }
49
50 // apply shield multiplier
51 if(StatusEffects_active(STATUSEFFECT_Shield, targ))
52 {
54 if (targ != attacker)
55 {
57 }
58 }
59}
vector
Definition self.qh:92
float autocvar_g_balance_powerup_invincible_takeforce
Definition shield.qh:19
float autocvar_g_balance_powerup_invincible_takedamage
Definition shield.qh:18
float autocvar_g_balance_powerup_strength_force
Definition strength.qh:19
float autocvar_g_balance_powerup_strength_selfforce
Definition strength.qh:21
float autocvar_g_balance_powerup_strength_selfdamage
Definition strength.qh:20
float autocvar_g_balance_powerup_strength_damage
Definition strength.qh:18

References autocvar_g_balance_powerup_invincible_takedamage, autocvar_g_balance_powerup_invincible_takeforce, autocvar_g_balance_powerup_strength_damage, autocvar_g_balance_powerup_strength_force, autocvar_g_balance_powerup_strength_selfdamage, autocvar_g_balance_powerup_strength_selfforce, entity(), M_ARGV, StatusEffects_active(), and vector.

◆ MUTATOR_HOOKFUNCTION() [6/13]

MUTATOR_HOOKFUNCTION ( powerups ,
ItemTouched  )

Definition at line 142 of file sv_powerups.qc.

143{
144 entity e = M_ARGV(0, entity);
145 if(e.waypointsprite_attached)
146 WaypointSprite_Kill(e.waypointsprite_attached);
147}
void WaypointSprite_Kill(entity wp)

References entity(), M_ARGV, and WaypointSprite_Kill().

◆ MUTATOR_HOOKFUNCTION() [7/13]

MUTATOR_HOOKFUNCTION ( powerups ,
LogDeath_AppendItemCodes  )

Definition at line 17 of file sv_powerups.qc.

18{
19 entity player = M_ARGV(0, entity);
20
21 if(StatusEffects_active(STATUSEFFECT_Strength, player))
22 M_ARGV(1, string) = strcat(M_ARGV(1, string), "S");
23
24 if(StatusEffects_active(STATUSEFFECT_Shield, player))
25 M_ARGV(1, string) = strcat(M_ARGV(1, string), "I");
26
27 // TODO: item codes for other powerups?
28}

References entity(), M_ARGV, StatusEffects_active(), and strcat().

◆ MUTATOR_HOOKFUNCTION() [8/13]

MUTATOR_HOOKFUNCTION ( powerups ,
MonsterValidTarget  )

Definition at line 74 of file sv_powerups.qc.

75{
76 entity targ = M_ARGV(1, entity);
77 return StatusEffects_active(STATUSEFFECT_Invisibility, targ);
78}

References entity(), M_ARGV, and StatusEffects_active().

◆ MUTATOR_HOOKFUNCTION() [9/13]

MUTATOR_HOOKFUNCTION ( powerups ,
PlayerDies  )

Definition at line 149 of file sv_powerups.qc.

150{
152 return;
153
155
156 FOREACH(StatusEffects, it.instanceOfPowerupStatusEffect,
157 {
158 if(StatusEffects_active(it, frag_target))
159 powerups_DropItem(frag_target, it, autocvar_g_powerups_drop_ondeath == 2);
160 });
161}
#define FOREACH(list, cond, body)
Definition iter.qh:19
entity frag_target
Definition sv_ctf.qc:2321
int autocvar_g_powerups_drop_ondeath
Definition sv_powerups.qh:9

References autocvar_g_powerups_drop_ondeath, entity(), FOREACH, frag_target, and M_ARGV.

◆ MUTATOR_HOOKFUNCTION() [10/13]

MUTATOR_HOOKFUNCTION ( powerups ,
PlayerPhysics_UpdateStats  )

Definition at line 179 of file sv_powerups.qc.

180{
181 entity player = M_ARGV(0, entity);
182 // these automatically reset, no need to worry
183
184 if(StatusEffects_active(STATUSEFFECT_Speed, player))
185 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_balance_powerup_speed_highspeed;
186}
#define STAT(...)
Definition stats.qh:82
float autocvar_g_balance_powerup_speed_highspeed
Definition speed.qh:21

References autocvar_g_balance_powerup_speed_highspeed, entity(), M_ARGV, STAT, and StatusEffects_active().

◆ MUTATOR_HOOKFUNCTION() [11/13]

MUTATOR_HOOKFUNCTION ( powerups ,
PlayerUseKey  )

Definition at line 163 of file sv_powerups.qc.

164{
166
167 entity player = M_ARGV(0, entity);
168
169 FOREACH(StatusEffects, it.instanceOfPowerupStatusEffect,
170 {
171 if(StatusEffects_active(it, player)) {
172 powerups_DropItem(player, it, autocvar_g_powerups_drop == 2);
173 StatusEffects_remove(it, player, STATUSEFFECT_REMOVE_NORMAL);
174 return true;
175 }
176 });
177}
#define MUTATOR_RETURNVALUE
Definition base.qh:328
float game_stopped
Definition stats.qh:81
int autocvar_g_powerups_drop
Definition sv_powerups.qh:8

References autocvar_g_powerups_drop, entity(), FOREACH, game_stopped, M_ARGV, MUTATOR_RETURNVALUE, and PlayerUseKey().

◆ MUTATOR_HOOKFUNCTION() [12/13]

MUTATOR_HOOKFUNCTION ( powerups ,
W_PlayStrengthSound  )

Definition at line 3 of file sv_powerups.qc.

4{
5 entity player = M_ARGV(0, entity);
6
7 if(StatusEffects_active(STATUSEFFECT_Strength, player)
8 && ((time > player.prevstrengthsound + autocvar_sv_strengthsound_antispam_time) // prevent insane sound spam
9 || (time > player.prevstrengthsoundattempt + autocvar_sv_strengthsound_antispam_refire_threshold)))
10 {
11 sound(player, CH_TRIGGER, SND_STRENGTH_FIRE, VOL_BASE, ATTEN_NORM);
12 player.prevstrengthsound = time;
13 }
14 player.prevstrengthsoundattempt = time;
15}
float time
float autocvar_sv_strengthsound_antispam_refire_threshold
Definition common.qh:6
float autocvar_sv_strengthsound_antispam_time
Definition common.qh:7
const int CH_TRIGGER
Definition sound.qh:12
const float VOL_BASE
Definition sound.qh:36
const float ATTEN_NORM
Definition sound.qh:30
#define sound(e, c, s, v, a)
Definition sound.qh:52

References ATTEN_NORM, autocvar_sv_strengthsound_antispam_refire_threshold, autocvar_sv_strengthsound_antispam_time, CH_TRIGGER, entity(), M_ARGV, sound, StatusEffects_active(), time, VOL_BASE, and W_PlayStrengthSound().

◆ MUTATOR_HOOKFUNCTION() [13/13]

MUTATOR_HOOKFUNCTION ( powerups ,
WeaponRateFactor  )

Definition at line 188 of file sv_powerups.qc.

189{
190 entity player = M_ARGV(1, entity);
191
192 if(StatusEffects_active(STATUSEFFECT_Speed, player))
194}
float autocvar_g_balance_powerup_speed_attack_time_multiplier
Definition speed.qh:20

References autocvar_g_balance_powerup_speed_attack_time_multiplier, entity(), M_ARGV, and StatusEffects_active().

◆ powerups_DropItem()

void powerups_DropItem ( entity this,
StatusEffect effect,
bool freezeTimer )

Definition at line 93 of file sv_powerups.qc.

94{
95 float t = StatusEffects_gettime(effect, this);
96 float timeleft = t - time;
97 float maxtime = 0;
98
99 if(timeleft <= 1)
100 return;
101 entity e = spawn();
102
103 // If we want the timer to keep running, we enable expiring then use the exact time the powerup will finish at.
104 // If we want the timer to freeze, we disable expiring and we just use the time left of the powerup.
105 // See ITEM_SET_EXPIRING() below.
106 float finished = (freezeTimer ? timeleft : t);
107
108 // If the timer is frozen, the item will stay on the floor for 20 secs (same as weapons),
109 // otherwise it'll disappear after the timer runs out.
110 e.lifetime = (freezeTimer ? autocvar_g_items_dropped_lifetime : timeleft);
111
112 // TODO: items cannot hold their "item field" yet, so we need to list all the powerups here!
113 switch (effect)
114 {
115 case STATUSEFFECT_Strength: e.itemdef = ITEM_Strength; e.strength_finished = finished; maxtime = autocvar_g_balance_powerup_strength_time; break;
116 case STATUSEFFECT_Shield: e.itemdef = ITEM_Shield; e.invincible_finished = finished; maxtime = autocvar_g_balance_powerup_invincible_time; break;
117 case STATUSEFFECT_Invisibility: e.itemdef = ITEM_Invisibility; e.invisibility_finished = finished; maxtime = autocvar_g_balance_powerup_invisibility_time; break;
118 case STATUSEFFECT_Speed: e.itemdef = ITEM_Speed; e.speed_finished = finished; maxtime = autocvar_g_balance_powerup_speed_time; break;
119 default: delete(e); return;
120 }
121
122 e.origin = this.origin;
123 e.velocity = W_CalculateProjectileVelocity(this, this.velocity, v_forward * 750, false);
124 if (!Item_Initialise(e))
125 return;
126
127 if(!freezeTimer)
128 ITEM_SET_EXPIRING(e, true);
129
130 // Use armor as timer freezer
131 if(freezeTimer)
133
134 // Create waypoint displaying time left of the powerup
135 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, e, '0 0 1' * e.maxs.z, NULL, 0, e, waypointsprite_attached, true, RADARICON_Item);
136 wp.wp_extra = e.itemdef.m_id;
137 WaypointSprite_UpdateMaxHealth(e.waypointsprite_attached, maxtime);
138 WaypointSprite_UpdateHealth(e.waypointsprite_attached, timeleft);
139 // Item_Think() will call powerups_DropItem_Think() to update the waypoint
140}
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
vector velocity
vector v_forward
vector origin
#define spawn
RES_ARMOR
Definition ent_cs.qc:130
float autocvar_g_balance_powerup_invisibility_time
bool Item_Initialise(entity item)
An optimised and generic way to initialise items (loot or permanent)
Definition spawning.qc:27
#define ITEM_SET_EXPIRING(item, expiring)
Sets the item expiring status (i.e.
Definition spawning.qh:65
float autocvar_g_balance_powerup_speed_time
Definition speed.qh:22
#define NULL
Definition post.qh:14
float autocvar_g_items_dropped_lifetime
Definition items.qh:9
float autocvar_g_balance_powerup_invincible_time
Definition shield.qh:20
float StatusEffects_gettime(StatusEffect this, entity actor)
float autocvar_g_balance_powerup_strength_time
Definition strength.qh:22
vector W_CalculateProjectileVelocity(entity actor, vector pvelocity, vector mvelocity, float forceAbsolute)
Definition tracing.qc:176
void WaypointSprite_UpdateMaxHealth(entity e, float f)
entity WaypointSprite_Spawn(entity spr, float _lifetime, float maxdistance, entity ref, vector ofs, entity showto, float t, entity own,.entity ownfield, float hideable, entity icon)
void WaypointSprite_UpdateHealth(entity e, float f)
entity waypointsprite_attached

References autocvar_g_balance_powerup_invincible_time, autocvar_g_balance_powerup_invisibility_time, autocvar_g_balance_powerup_speed_time, autocvar_g_balance_powerup_strength_time, autocvar_g_items_dropped_lifetime, entity(), Item_Initialise(), ITEM_SET_EXPIRING, NULL, origin, RES_ARMOR, SetResourceExplicit(), spawn, StatusEffects_gettime(), time, v_forward, velocity, W_CalculateProjectileVelocity(), waypointsprite_attached, WaypointSprite_Spawn(), WaypointSprite_UpdateHealth(), and WaypointSprite_UpdateMaxHealth().

◆ powerups_DropItem_Think()

void powerups_DropItem_Think ( entity this)

Definition at line 80 of file sv_powerups.qc.

81{
82 // if there is no armor it means the timer of the powerup is running
84 {
85 float timeleft = floor(this.wait - time);
86 if (timeleft)
88 else
90 }
91}
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
float wait
Definition items.qc:17
float floor(float f)

References entity(), floor(), GetResource(), RES_ARMOR, time, wait, waypointsprite_attached, WaypointSprite_Kill(), and WaypointSprite_UpdateHealth().

Referenced by Item_Think().