]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/buffs/buffs.qc
Use STAT(FROZEN, e) instead of e.frozen
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / buffs / buffs.qc
index 9eb113a96ff86355b809b690b43ceaff159cc79e..889b0db2f28149beb01ec0717c03ee9647fad852 100644 (file)
@@ -73,19 +73,16 @@ const vector BUFF_MAX = ('16 16 20');
 
 #ifdef IMPLEMENTATION
 
-#include "../../../triggers/target/music.qh"
-#include "../../../gamemodes/all.qh"
+#include <common/triggers/target/music.qh>
+#include <common/gamemodes/all.qh>
 
-.float buff_time;
+.float buff_time = _STAT(BUFF_TIME);
 void buffs_DelayedInit();
 
 REGISTER_MUTATOR(buffs, cvar("g_buffs"))
 {
        MUTATOR_ONADD
        {
-               addstat(STAT_BUFFS, AS_INT, buffs);
-               addstat(STAT_BUFF_TIME, AS_FLOAT, buff_time);
-
                InitializeEntity(world, buffs_DelayedInit, INITPRIO_FINDTARGET);
        }
 }
@@ -194,37 +191,39 @@ void buff_SetCooldown(float cd)
        self.buff_active = !cd;
 }
 
-void buff_Respawn(entity ent)
-{SELFPARAM();
+void buff_Respawn(entity this)
+{
        if(gameover) { return; }
 
-       vector oldbufforigin = ent.origin;
+       vector oldbufforigin = this.origin;
+       this.velocity = '0 0 200';
 
-       if(!MoveToRandomMapLocation(ent, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
+       if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
+               ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
        {
                entity spot = SelectSpawnPoint(true);
-               setorigin(ent, spot.origin + '0 0 200');
-               ent.angles = spot.angles;
+               setorigin(this, spot.origin);
+               this.velocity = ((randomvec() * 100) + '0 0 200');
+               this.angles = spot.angles;
        }
 
-       tracebox(ent.origin, ent.mins * 1.5, self.maxs * 1.5, ent.origin, MOVE_NOMONSTERS, ent);
+       tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
 
-       setorigin(ent, trace_endpos); // attempt to unstick
+       setorigin(this, trace_endpos); // attempt to unstick
 
-       ent.movetype = MOVETYPE_TOSS;
+       this.movetype = MOVETYPE_TOSS;
 
-       makevectors(ent.angles);
-       ent.velocity = '0 0 200';
-       ent.angles = '0 0 0';
+       makevectors(this.angles);
+       this.angles = '0 0 0';
        if(autocvar_g_buffs_random_lifetime > 0)
-               ent.lifetime = time + autocvar_g_buffs_random_lifetime;
+               this.lifetime = time + autocvar_g_buffs_random_lifetime;
 
-       Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((ent.mins + ent.maxs) * 0.5), '0 0 0', 1);
-       Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(ent), '0 0 0', 1);
+       Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
+       Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
 
-       WaypointSprite_Ping(ent.buff_waypoint);
+       WaypointSprite_Ping(this.buff_waypoint);
 
-       sound(ent, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
+       sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
 }
 
 void buff_Touch()
@@ -238,7 +237,7 @@ void buff_Touch()
        }
 
        if((self.team && DIFF_TEAM(other, self))
-       || (other.frozen)
+       || (STAT(FROZEN, other))
        || (other.vehicle)
        || (!self.buff_active)
        )
@@ -335,7 +334,7 @@ void buff_Think()
        }
 
        if(!self.buff_active && !self.buff_activetime)
-       if(!self.owner || self.owner.frozen || self.owner.deadflag != DEAD_NO || !self.owner.iscreature || !(self.owner.buffs & self.buffs))
+       if(!self.owner || STAT(FROZEN, self.owner) || IS_DEAD(self.owner) || !self.owner.iscreature || !(self.owner.buffs & self.buffs))
        {
                buff_SetCooldown(autocvar_g_buffs_cooldown_respawn + frametime);
                self.owner = world;
@@ -587,10 +586,10 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_Calculate)
        if(!frag_target.vehicle)
        if(DEATH_WEAPONOF(frag_deathtype) != WEP_ARC)
        if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
-       if(frag_target.deadflag == DEAD_NO)
+       if(!IS_DEAD(frag_target))
        if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
        if(frag_attacker != frag_target)
-       if(!frag_target.frozen)
+       if(!STAT(FROZEN, frag_target))
        if(frag_target.takedamage)
        if(DIFF_TEAM(frag_attacker, frag_target))
        {
@@ -698,15 +697,15 @@ MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
        {
                float best_distance = autocvar_g_buffs_swapper_range;
                entity closest = world;
-               entity player;
-               FOR_EACH_PLAYER(player)
-               if(DIFF_TEAM(self, player))
-               if(player.deadflag == DEAD_NO && !player.frozen && !player.vehicle)
-               if(vlen(self.origin - player.origin) <= best_distance)
-               {
-                       best_distance = vlen(self.origin - player.origin);
-                       closest = player;
-               }
+               FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+                       if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
+                       if(DIFF_TEAM(it, self))
+                       if(vlen(self.origin - it.origin) <= best_distance)
+                       {
+                               best_distance = vlen(self.origin - it.origin);
+                               closest = it;
+                       }
+               ));
 
                if(closest)
                {
@@ -831,7 +830,7 @@ MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
 
 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
 {SELFPARAM();
-       if(gameover || self.deadflag != DEAD_NO) { return false; }
+       if(gameover || IS_DEAD(self)) { return false; }
 
        if(time < self.buff_disability_time)
        if(time >= self.buff_disability_effect_time)
@@ -849,7 +848,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
        if(time >= self.buff_time)
                buff_lost = 2;
 
-       if(self.frozen) { buff_lost = 1; }
+       if(STAT(FROZEN, self)) { buff_lost = 1; }
 
        if(buff_lost)
        {
@@ -883,7 +882,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
 
        if(self.buffs & BUFF_AMMO.m_itemid)
        if(self.clip_size)
-               self.clip_load = self.(weapon_load[self.switchweapon]) = self.clip_size;
+               self.clip_load = self.(weapon_load[PS(self).m_switchweapon.m_id]) = self.clip_size;
 
        if((self.buffs & BUFF_INVISIBLE.m_itemid) && (self.oldbuffs & BUFF_INVISIBLE.m_itemid))
        if(self.alpha != autocvar_g_buffs_invisible_alpha)
@@ -905,7 +904,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
 
                        if(self.clip_load)
                                self.buff_ammo_prev_clipload = self.clip_load;
-                       self.clip_load = self.(weapon_load[self.switchweapon]) = self.clip_size;
+                       self.clip_load = self.(weapon_load[PS(self).m_switchweapon.m_id]) = self.clip_size;
                }
 
                BUFF_ONREM(BUFF_AMMO)
@@ -985,7 +984,7 @@ MUTATOR_HOOKFUNCTION(buffs, VehicleEnter)
 {
        vh_vehicle.buffs = vh_player.buffs;
        vh_player.buffs = 0;
-       vh_vehicle.buff_time = vh_player.buff_time - time;
+       vh_vehicle.buff_time = max(0, time - vh_player.buff_time);
        vh_player.buff_time = 0;
        return false;
 }