Xonotic
sv_powerups.qc File Reference
#include "sv_powerups.qh"
+ Include dependency graph for sv_powerups.qc:

Go to the source code of this file.

Functions

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

Function Documentation

◆ MUTATOR_HOOKFUNCTION() [1/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
W_PlayStrengthSound   
)

Definition at line 3 of file sv_powerups.qc.

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

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 autocvar_sv_strengthsound_antispam_time
Definition: common.qh:6
float autocvar_sv_strengthsound_antispam_refire_threshold
Definition: common.qh:5
entity() spawn
const int CH_TRIGGER
Definition: sound.qh:12
const float VOL_BASE
Definition: sound.qh:36
#define M_ARGV(x, type)
Definition: events.qh:17
const float ATTEN_NORM
Definition: sound.qh:30
#define sound(e, c, s, v, a)
Definition: sound.qh:52
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [2/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
LogDeath_AppendItemCodes   
)

Definition at line 17 of file sv_powerups.qc.

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

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 }
entity() spawn
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [3/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
Damage_Calculate   
)

Definition at line 30 of file sv_powerups.qc.

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

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  {
40  M_ARGV(4, float) = M_ARGV(4, float) * autocvar_g_balance_powerup_strength_selfdamage;
41  M_ARGV(6, vector) = M_ARGV(6, vector) * autocvar_g_balance_powerup_strength_selfforce;
42  }
43  else
44  {
45  M_ARGV(4, float) = M_ARGV(4, float) * autocvar_g_balance_powerup_strength_damage;
46  M_ARGV(6, vector) = M_ARGV(6, vector) * autocvar_g_balance_powerup_strength_force;
47  }
48  }
49 
50  // apply shield multiplier
51  if(StatusEffects_active(STATUSEFFECT_Shield, targ))
52  {
53  M_ARGV(4, float) = M_ARGV(4, float) * autocvar_g_balance_powerup_invincible_takedamage;
54  if (targ != attacker)
55  {
56  M_ARGV(6, vector) = M_ARGV(6, vector) * autocvar_g_balance_powerup_invincible_takeforce;
57  }
58  }
59 }
entity() spawn
#define M_ARGV(x, type)
Definition: events.qh:17
vector(float skel, float bonenum) _skel_get_boneabs_hidden
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [4/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
CustomizeWaypoint   
)

Definition at line 61 of file sv_powerups.qc.

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

62 {
63  entity wp = M_ARGV(0, entity);
64  entity player = M_ARGV(1, entity);
65 
66  entity e = WaypointSprite_getviewentity(player);
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(v)
Definition: utils.qh:13
entity() spawn
#define DIFF_TEAM(a, b)
Definition: teams.qh:240
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [5/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
MonsterValidTarget   
)

Definition at line 74 of file sv_powerups.qc.

References entity(), and M_ARGV.

75 {
76  entity targ = M_ARGV(1, entity);
77  return StatusEffects_active(STATUSEFFECT_Invisibility, targ);
78 }
entity() spawn
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [6/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
ItemTouched   
)

Definition at line 144 of file sv_powerups.qc.

References entity(), and M_ARGV.

145 {
146  entity e = M_ARGV(0, entity);
147  if(e.waypointsprite_attached)
148  WaypointSprite_Kill(e.waypointsprite_attached);
149 }
entity() spawn
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [7/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
PlayerDies   
)

Definition at line 151 of file sv_powerups.qc.

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

152 {
154  return;
155 
156  entity frag_target = M_ARGV(2, entity);
157 
158  FOREACH(StatusEffect, it.instanceOfPowerups,
159  {
160  if(StatusEffects_active(it, frag_target))
161  powerups_DropItem(frag_target, it);
162  });
163 }
entity() spawn
int autocvar_g_powerups_drop_ondeath
Definition: sv_powerups.qh:8
#define M_ARGV(x, type)
Definition: events.qh:17
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [8/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
PlayerPhysics_UpdateStats   
)

Definition at line 165 of file sv_powerups.qc.

References entity(), and M_ARGV.

166 {
167  entity player = M_ARGV(0, entity);
168  // these automatically reset, no need to worry
169 
170  if(StatusEffects_active(STATUSEFFECT_Speed, player))
171  STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_balance_powerup_speed_highspeed;
172 }
entity() spawn
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [9/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
WeaponRateFactor   
)

Definition at line 174 of file sv_powerups.qc.

References entity(), and M_ARGV.

175 {
176  entity player = M_ARGV(1, entity);
177 
178  if(StatusEffects_active(STATUSEFFECT_Speed, player))
179  M_ARGV(0, float) *= autocvar_g_balance_powerup_speed_attackrate;
180 }
entity() spawn
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [10/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
BuildMutatorsPrettyString   
)

Definition at line 182 of file sv_powerups.qc.

References autocvar_g_powerups, M_ARGV, and strcat().

183 {
184  if(autocvar_g_powerups == 0)
185  M_ARGV(0, string) = strcat(M_ARGV(0, string), ", No powerups");
186  if(autocvar_g_powerups > 0)
187  M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Powerups");
188 }
int autocvar_g_powerups
Definition: sv_powerups.qh:7
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [11/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
BotShouldAttack   
)

Definition at line 190 of file sv_powerups.qc.

References entity(), and M_ARGV.

191 {
192  entity targ = M_ARGV(1, entity);
193 
194  if(StatusEffects_active(STATUSEFFECT_Invisibility, targ))
195  return true;
196 }
entity() spawn
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [12/12]

MUTATOR_HOOKFUNCTION ( powerups  ,
BuildMutatorsString   
)

Definition at line 198 of file sv_powerups.qc.

References autocvar_g_powerups, M_ARGV, and strcat().

199 {
200  if(autocvar_g_powerups == 0)
201  M_ARGV(0, string) = strcat(M_ARGV(0, string), ":no_powerups");
202  if(autocvar_g_powerups > 0)
203  M_ARGV(0, string) = strcat(M_ARGV(0, string), ":powerups");
204 }
int autocvar_g_powerups
Definition: sv_powerups.qh:7
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ powerups_DropItem()

void powerups_DropItem ( entity  this,
StatusEffects  effect 
)

Definition at line 97 of file sv_powerups.qc.

References autocvar_g_items_dropped_lifetime, autocvar_g_powerups_drop_ondeath, entity(), Item_DefinitionFromInternalName(), Item_InitializeLoot(), Item_SetExpiring(), NULL, powerups_DropItem_Think(), randomvec(), RES_HEALTH, SetResourceExplicit(), setthink, spawn(), and time.

98 {
99  entity item = Item_DefinitionFromInternalName(effect.netname);
100  float t = StatusEffects_gettime(effect, this);
101  float timeleft = t - time;
102  float maxtime = 0;
103 
104  if(timeleft <= 1 || !item)
105  return;
106  entity e = spawn();
107 
108  // If we want the timer to keep running, we enable expiring then use the exact time the powerup will finish at.
109  // If we want the timer to freeze, we disable expiring and we just use the time left of the powerup.
110  // See Item_SetExpiring() below.
111  float finished = (autocvar_g_powerups_drop_ondeath == 2 ? timeleft : t);
112 
113  // If the timer is frozen, the item will stay on the floor for 20 secs (same as weapons),
114  // otherwise it'll disappear after the timer runs out.
115  float time_to_live = (autocvar_g_powerups_drop_ondeath == 2 ? autocvar_g_items_dropped_lifetime : timeleft);
116 
117  // TODO: items cannot hold their "item field" yet, so we need to list all the powerups here!
118  switch(item)
119  {
120  case ITEM_Strength: e.strength_finished = finished; maxtime = autocvar_g_balance_powerup_strength_time; break;
121  case ITEM_Shield: e.invincible_finished = finished; maxtime = autocvar_g_balance_powerup_invincible_time; break;
122  case ITEM_Invisibility: e.invisibility_finished = finished; maxtime = autocvar_g_balance_powerup_invincible_time; break;
123  case ITEM_Speed: e.speed_finished = finished; maxtime = autocvar_g_balance_powerup_speed_time; break;
124  }
125  Item_InitializeLoot(e, item.m_canonical_spawnfunc, this.origin + '0 0 32', randomvec() * 175 + '0 0 175', time_to_live);
126 
128  Item_SetExpiring(e, true);
129 
130  // Use health as time left to live
131  SetResourceExplicit(e, RES_HEALTH, time_to_live);
132 
133  // Create waypoint displaying time left of the powerup
134  entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, e, '0 0 1' * e.maxs.z, NULL, 0, e, waypointsprite_attached, true, RADARICON_Item);
135  wp.wp_extra = item.m_id;
136  WaypointSprite_UpdateMaxHealth(e.waypointsprite_attached, maxtime);
137  WaypointSprite_UpdateHealth(e.waypointsprite_attached, timeleft);
138 
139  // Start dropping its time to live
141  e.nextthink = time + 1;
142 }
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
Definition: cl_resources.qc:15
entity Item_DefinitionFromInternalName(string item_name)
Returns the item definition corresponding to the given internal name.
Definition: spawning.qc:32
bool Item_InitializeLoot(entity item, string class_name, vector position, vector vel, float time_to_live)
Initializes the loot item.
Definition: spawning.qc:101
entity() spawn
int autocvar_g_powerups_drop_ondeath
Definition: sv_powerups.qh:8
RES_HEALTH
Definition: ent_cs.qc:126
#define NULL
Definition: post.qh:17
void powerups_DropItem_Think(entity this)
Definition: sv_powerups.qc:80
float autocvar_g_items_dropped_lifetime
Definition: items.qh:10
#define setthink(e, f)
float time
Definition: csprogsdefs.qc:16
void Item_SetExpiring(entity item, bool expiring)
Sets the item expiring status (i.e.
Definition: spawning.qc:141
+ Here is the call graph for this function:

◆ powerups_DropItem_Think()

void powerups_DropItem_Think ( entity  this)

Definition at line 80 of file sv_powerups.qc.

References autocvar_g_powerups_drop_ondeath, GetResource(), nextthink, RES_HEALTH, TakeResource(), and time.

Referenced by powerups_DropItem().

81 {
82  TakeResource(this, RES_HEALTH, 1);
83 
84  if(GetResource(this, RES_HEALTH) < 1) {
85  WaypointSprite_Kill(this.waypointsprite_attached);
86  delete(this);
87  return;
88  }
89 
90  // Only needed to update if the timer of the powerup is running
92  WaypointSprite_UpdateHealth(this.waypointsprite_attached, GetResource(this, RES_HEALTH));
93 
94  this.nextthink = time + 1;
95 }
int autocvar_g_powerups_drop_ondeath
Definition: sv_powerups.qh:8
void TakeResource(entity receiver, Resource res_type, float amount)
Takes an entity some resource.
Definition: cl_resources.qc:31
RES_HEALTH
Definition: ent_cs.qc:126
float nextthink
Definition: csprogsdefs.qc:121
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function: