]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/buffs/sv_buffs.qc
Merge branch 'master' into Mario/cts_respawn_clear
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / buffs / sv_buffs.qc
index a65d57d729b615fde18d66c6d62fc61cac0baa82..70217365d40e0156259dff72b2f5ec3e11dc2b09 100644 (file)
@@ -214,15 +214,17 @@ float buff_Available(entity buff)
 
 .int buff_seencount;
 
-void buff_NewType(entity ent, float cb)
+void buff_NewType(entity ent)
 {
        RandomSelection_Init();
-       FOREACH(Buffs, buff_Available(it), LAMBDA(
-               it.buff_seencount += 1;
+       FOREACH(Buffs, buff_Available(it),
+       {
                // if it's already been chosen, give it a lower priority
-               RandomSelection_AddFloat(it.m_itemid, 1, max(0.2, 1 / it.buff_seencount));
-       ));
-       ent.buffs = RandomSelection_chosen_float;
+               RandomSelection_AddEnt(it, max(0.2, 1 / it.buff_seencount), 1);
+       });
+       entity newbuff = RandomSelection_chosen_ent;
+       newbuff.buff_seencount += 1; // lower chances of seeing this buff again soon
+       ent.buffs = newbuff.m_itemid;
 }
 
 void buff_Think(entity this)
@@ -263,7 +265,7 @@ void buff_Think(entity this)
                buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
                this.owner = NULL;
                if(autocvar_g_buffs_randomize)
-                       buff_NewType(this, this.buffs);
+                       buff_NewType(this);
 
                if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
                        buff_Respawn(this);
@@ -307,7 +309,7 @@ void buff_Waypoint_Reset(entity this)
 void buff_Reset(entity this)
 {
        if(autocvar_g_buffs_randomize)
-               buff_NewType(this, this.buffs);
+               buff_NewType(this);
        this.owner = NULL;
        buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate);
        buff_Waypoint_Reset(this);
@@ -345,7 +347,7 @@ void buff_Init(entity this)
        entity buff = buff_FirstFromFlags(this.buffs);
 
        if(!this.buffs || !buff_Available(buff))
-               buff_NewType(this, 0);
+               buff_NewType(this);
 
        this.classname = "item_buff";
        this.solid = SOLID_TRIGGER;
@@ -368,7 +370,7 @@ void buff_Init(entity this)
        //this.gravity = 100;
        this.color = buff.m_color;
        this.glowmod = buff_GlowColor(this);
-       buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + game_starttime);
+       buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + max(0, game_starttime - time));
        this.buff_active = !this.buff_activetime;
        this.pflags = PFLAGS_FULLDYNAMIC;
 
@@ -564,39 +566,25 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
        player.buff_disability_effect_time = 0;
 }
 
-.float stat_sv_maxspeed;
-.float stat_sv_airspeedlimit_nonqw;
-.float stat_sv_jumpvelocity;
-
-MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
+MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics_UpdateStats)
 {
        entity player = M_ARGV(0, entity);
+       // these automatically reset, no need to worry
 
        if(player.buffs & BUFF_SPEED.m_itemid)
-       {
-               player.stat_sv_maxspeed *= autocvar_g_buffs_speed_speed;
-               player.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_speed_speed;
-       }
+               STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_speed_speed;
 
        if(time < player.buff_disability_time)
-       {
-               player.stat_sv_maxspeed *= autocvar_g_buffs_disability_speed;
-               player.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_disability_speed;
-       }
-
-       if(player.buffs & BUFF_JUMP.m_itemid)
-       {
-               // automatically reset, no need to worry
-               player.stat_sv_jumpvelocity = autocvar_g_buffs_jump_height;
-       }
+               STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_disability_speed;
 }
 
-MUTATOR_HOOKFUNCTION(buffs, PlayerJump)
+MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
 {
        entity player = M_ARGV(0, entity);
+       // these automatically reset, no need to worry
 
        if(player.buffs & BUFF_JUMP.m_itemid)
-               M_ARGV(1, float) = autocvar_g_buffs_jump_height;
+               STAT(MOVEVARS_JUMPVELOCITY, player) = autocvar_g_buffs_jump_height;
 }
 
 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)