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

Definition at line 208 of file sv_powerups.qc.

209{
210 entity targ = M_ARGV(1, entity);
211
212 if(StatusEffects_active(STATUSEFFECT_Invisibility, targ))
213 return true;
214}
#define M_ARGV(idx, type)
Definition base.qh:153
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
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 198 of file sv_powerups.qc.

199{
200 if (autocvar_g_buffs == 1 && autocvar_g_buffs_replace_powerups)
201 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs replace Powerups");
202 else if (autocvar_g_powerups == 0)
203 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", No powerups");
204 else if (autocvar_g_powerups > 0)
205 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Powerups");
206}
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
bool autocvar_g_buffs_replace_powerups
Definition sv_buffs.qh:28
int autocvar_g_powerups
Definition sv_powerups.qh:7

References autocvar_g_buffs_replace_powerups, autocvar_g_powerups, M_ARGV, and strcat().

◆ MUTATOR_HOOKFUNCTION() [3/13]

MUTATOR_HOOKFUNCTION ( powerups ,
BuildMutatorsString  )

Definition at line 216 of file sv_powerups.qc.

217{
218 if (autocvar_g_buffs == 1 && autocvar_g_buffs_replace_powerups)
219 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":buffs_replace_powerups");
220 else if (autocvar_g_powerups == 0)
221 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":no_powerups");
222 else if (autocvar_g_powerups > 0)
223 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":powerups");
224}

References autocvar_g_buffs_replace_powerups, autocvar_g_powerups, M_ARGV, and strcat().

◆ MUTATOR_HOOKFUNCTION() [4/13]

MUTATOR_HOOKFUNCTION ( powerups ,
CustomizeWaypoint  )

Definition at line 63 of file sv_powerups.qc.

64{
65 entity wp = M_ARGV(0, entity);
66 entity player = M_ARGV(1, entity);
67
69
70 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
71 // but only apply this to real players, not to spectators
72 if(IS_CLIENT(wp.owner) && (e == player) && DIFF_TEAM(wp.owner, e) && StatusEffects_active(STATUSEFFECT_Invisibility, wp.owner))
73 return true;
74}
#define IS_CLIENT(s)
Definition player.qh:241
#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 32 of file sv_powerups.qc.

33{
34 entity attacker = M_ARGV(1, entity);
35 entity targ = M_ARGV(2, entity);
36
37 // apply strength multiplier
38 if(StatusEffects_active(STATUSEFFECT_Strength, attacker))
39 {
40 if(targ == attacker)
41 {
44 }
45 else
46 {
49 }
50 }
51
52 // apply shield multiplier
53 if(StatusEffects_active(STATUSEFFECT_Shield, targ))
54 {
56 if (targ != attacker)
57 {
59 }
60 }
61}
vector
Definition self.qh:96
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 144 of file sv_powerups.qc.

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

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

◆ MUTATOR_HOOKFUNCTION() [7/13]

MUTATOR_HOOKFUNCTION ( powerups ,
LogDeath_AppendItemCodes  )

Definition at line 19 of file sv_powerups.qc.

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

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

◆ MUTATOR_HOOKFUNCTION() [8/13]

MUTATOR_HOOKFUNCTION ( powerups ,
MonsterValidTarget  )

Definition at line 76 of file sv_powerups.qc.

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

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

◆ MUTATOR_HOOKFUNCTION() [9/13]

MUTATOR_HOOKFUNCTION ( powerups ,
PlayerDies  )

Definition at line 151 of file sv_powerups.qc.

152{
154 return;
155
157
158 FOREACH(StatusEffects, it.instanceOfPowerupStatusEffect,
159 {
160 if(StatusEffects_active(it, frag_target))
161 powerups_DropItem(frag_target, it, autocvar_g_powerups_drop_ondeath == 2);
162 });
163}
#define FOREACH(list, cond, body)
Definition iter.qh:19
entity frag_target
Definition sv_ctf.qc:2315
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 181 of file sv_powerups.qc.

182{
183 entity player = M_ARGV(0, entity);
184 // these automatically reset, no need to worry
185
186 if(StatusEffects_active(STATUSEFFECT_Speed, player))
187 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_balance_powerup_speed_highspeed;
188}
#define STAT(...)
Definition stats.qh:94
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 165 of file sv_powerups.qc.

166{
168
169 entity player = M_ARGV(0, entity);
170
171 FOREACH(StatusEffects, it.instanceOfPowerupStatusEffect,
172 {
173 if(StatusEffects_active(it, player)) {
174 powerups_DropItem(player, it, autocvar_g_powerups_drop == 2);
175 StatusEffects_remove(it, player, STATUSEFFECT_REMOVE_NORMAL);
176 return true;
177 }
178 });
179}
#define MUTATOR_RETURNVALUE
Definition base.qh:384
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 5 of file sv_powerups.qc.

6{
7 entity player = M_ARGV(0, entity);
8
9 if(StatusEffects_active(STATUSEFFECT_Strength, player)
10 && ((time > player.prevstrengthsound + autocvar_sv_strengthsound_antispam_time) // prevent insane sound spam
11 || (time > player.prevstrengthsoundattempt + autocvar_sv_strengthsound_antispam_refire_threshold)))
12 {
13 sound(player, CH_TRIGGER, SND_STRENGTH_FIRE, VOL_BASE, ATTEN_NORM);
14 player.prevstrengthsound = time;
15 }
16 player.prevstrengthsoundattempt = time;
17}
float time
float autocvar_sv_strengthsound_antispam_refire_threshold
Definition common.qh:8
float autocvar_sv_strengthsound_antispam_time
Definition common.qh:9
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 190 of file sv_powerups.qc.

191{
192 entity player = M_ARGV(1, entity);
193
194 if(StatusEffects_active(STATUSEFFECT_Speed, player))
196}
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 95 of file sv_powerups.qc.

96{
97 float t = StatusEffects_gettime(effect, this);
98 float timeleft = t - time;
99 float maxtime = 0;
100
101 if(timeleft <= 1)
102 return;
103 entity e = spawn();
104
105 // If we want the timer to keep running, we enable expiring then use the exact time the powerup will finish at.
106 // If we want the timer to freeze, we disable expiring and we just use the time left of the powerup.
107 // See ITEM_SET_EXPIRING() below.
108 float finished = (freezeTimer ? timeleft : t);
109
110 // If the timer is frozen, the item will stay on the floor for 20 secs (same as weapons),
111 // otherwise it'll disappear after the timer runs out.
112 e.lifetime = (freezeTimer ? autocvar_g_items_dropped_lifetime : timeleft);
113
114 // TODO: items cannot hold their "item field" yet, so we need to list all the powerups here!
115 switch (effect)
116 {
117 case STATUSEFFECT_Strength: e.itemdef = ITEM_Strength; e.strength_finished = finished; maxtime = autocvar_g_balance_powerup_strength_time; break;
118 case STATUSEFFECT_Shield: e.itemdef = ITEM_Shield; e.invincible_finished = finished; maxtime = autocvar_g_balance_powerup_invincible_time; break;
119 case STATUSEFFECT_Invisibility: e.itemdef = ITEM_Invisibility; e.invisibility_finished = finished; maxtime = autocvar_g_balance_powerup_invisibility_time; break;
120 case STATUSEFFECT_Speed: e.itemdef = ITEM_Speed; e.speed_finished = finished; maxtime = autocvar_g_balance_powerup_speed_time; break;
121 default: delete(e); return;
122 }
123
124 e.origin = this.origin;
125 e.velocity = W_CalculateProjectileVelocity(this, this.velocity, v_forward * 750, false);
126 if (!Item_Initialise(e))
127 return;
128
129 if(!freezeTimer)
130 ITEM_SET_EXPIRING(e, true);
131
132 // Use armor as timer freezer
133 if(freezeTimer)
135
136 // Create waypoint displaying time left of the powerup
137 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, e, '0 0 1' * e.maxs.z, NULL, 0, e, waypointsprite_attached, true, RADARICON_Item);
138 wp.wp_extra = e.itemdef.m_id;
139 WaypointSprite_UpdateMaxHealth(e.waypointsprite_attached, maxtime);
140 WaypointSprite_UpdateHealth(e.waypointsprite_attached, timeleft);
141 // Item_Think() will call powerups_DropItem_Think() to update the waypoint
142}
vector velocity
vector v_forward
vector origin
#define spawn
RES_ARMOR
Definition ent_cs.qc:155
SetResourceExplicit(ent, RES_ARMOR, ReadByte() *DEC_FACTOR)) ENTCS_PROP(NAME
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:10
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:177
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 82 of file sv_powerups.qc.

83{
84 // if there is no armor it means the timer of the powerup is running
86 {
87 float timeleft = floor(this.wait - time);
88 if (timeleft)
90 else
92 }
93}
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().