]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/powerups/sv_powerups.qc
63e64c1a37b2a591a0dd9f722168721e9ab96454
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / powerups / sv_powerups.qc
1 #include "sv_powerups.qh"
2
3 MUTATOR_HOOKFUNCTION(powerups, W_PlayStrengthSound)
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 }
16
17 MUTATOR_HOOKFUNCTION(powerups, LogDeath_AppendItemCodes)
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 }
29
30 MUTATOR_HOOKFUNCTION(powerups, Damage_Calculate)
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 }
60
61 MUTATOR_HOOKFUNCTION(powerups, CustomizeWaypoint)
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 }
73
74 MUTATOR_HOOKFUNCTION(powerups, MonsterValidTarget)
75 {
76         entity targ = M_ARGV(1, entity);
77         return StatusEffects_active(STATUSEFFECT_Invisibility, targ);
78 }
79
80 void powerups_DropItem(entity this, StatusEffects effect)
81 {
82         entity item = Item_DefinitionFromInternalName(effect.netname);
83         float t = StatusEffects_gettime(effect, this);
84         float timeleft = t - time;
85
86         if(timeleft <= 1 || !item)
87                 return;
88         entity e = spawn();
89
90         // If we want the timer to keep running, we enable expiring then use the exact time the powerup will finish at.
91         // If we want the timer to freeze, we disable expiring and we just use the time left of the powerup.
92         // See Item_SetExpiring() below.
93         float finished = (autocvar_g_powerups_dropondeath == 2 ? timeleft : t);
94
95         // If the timer is frozen, the item will stay on the floor for 20 secs (same as weapons),
96         // otherwise it'll disappear after the timer runs out.
97         float time_to_live = (autocvar_g_powerups_dropondeath == 2 ? autocvar_g_powerups_dropondeath_ttl : timeleft);
98
99         // TODO: items cannot hold their "item field" yet, so we need to list all the powerups here!
100         switch(item)
101         {
102                 case ITEM_Strength: e.strength_finished = finished; break;
103                 case ITEM_Shield: e.invincible_finished = finished; break;
104                 case ITEM_Invisibility: e.invisibility_finished = finished; break;
105                 case ITEM_Speed: e.speed_finished = finished; break;
106         }
107         Item_InitializeLoot(e, item.m_canonical_spawnfunc, this.origin + '0 0 32', randomvec() * 175 + '0 0 175', time_to_live);
108
109         if(autocvar_g_powerups_dropondeath != 2)
110                 Item_SetExpiring(e, true);
111
112         // Create expiring waypoint
113         entity wp = WaypointSprite_Spawn(WP_Item, time_to_live * -1, 0, e, '0 0 1' * e.maxs.z, NULL, 0, e, waypointsprite_attached, true, RADARICON_Item);
114         wp.wp_extra = item.m_id;
115         wp.wp_reverse = 1;
116         WaypointSprite_UpdateBuildFinished(e.waypointsprite_attached, time + time_to_live);
117 }
118
119 MUTATOR_HOOKFUNCTION(powerups, ItemTouched)
120 {
121         entity e = M_ARGV(0, entity);
122         if(e.waypointsprite_attached)
123                 WaypointSprite_Kill(e.waypointsprite_attached);
124 }
125
126 MUTATOR_HOOKFUNCTION(powerups, PlayerDies)
127 {
128         if(!autocvar_g_powerups_dropondeath)
129                 return;
130
131         entity frag_target = M_ARGV(2, entity);
132
133         FOREACH(StatusEffect, it.instanceOfPowerups,
134         {
135                 if(StatusEffects_active(it, frag_target))
136                         powerups_DropItem(frag_target, it);
137         });
138 }
139
140 MUTATOR_HOOKFUNCTION(powerups, PlayerPhysics_UpdateStats)
141 {
142         entity player = M_ARGV(0, entity);
143         // these automatically reset, no need to worry
144
145         if(StatusEffects_active(STATUSEFFECT_Speed, player))
146                 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_balance_powerup_speed_highspeed;
147 }
148
149 MUTATOR_HOOKFUNCTION(powerups, WeaponRateFactor)
150 {
151         entity player = M_ARGV(1, entity);
152
153         if(StatusEffects_active(STATUSEFFECT_Speed, player))
154                 M_ARGV(0, float) *= autocvar_g_balance_powerup_speed_attackrate;
155 }
156
157 MUTATOR_HOOKFUNCTION(powerups, BuildMutatorsPrettyString)
158 {
159         if(autocvar_g_powerups == 0)
160                 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", No powerups");
161         if(autocvar_g_powerups > 0)
162                 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Powerups");
163 }
164
165 MUTATOR_HOOKFUNCTION(powerups, BotShouldAttack)
166 {
167         entity targ = M_ARGV(1, entity);
168
169         if(StatusEffects_active(STATUSEFFECT_Invisibility, targ))
170                 return true;
171 }
172
173 MUTATOR_HOOKFUNCTION(powerups, BuildMutatorsString)
174 {
175         if(autocvar_g_powerups == 0)
176                 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":no_powerups");
177         if(autocvar_g_powerups > 0)
178                 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":powerups");
179 }