]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/buffs/sv_buffs.qc
remove unnecessary main.qh includes (also one server/player.qh include)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / buffs / sv_buffs.qc
index 83b471cd810e0c6ae992c9f115d70abc0cabff2a..07d6292bd9efc39f51800795ce777286104b3970 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <common/mapobjects/target/music.qh>
 #include <common/gamemodes/_mod.qh>
+#include <server/items/items.qh>
 
 void buffs_DelayedInit(entity this);
 
@@ -18,20 +19,16 @@ REGISTER_MUTATOR(buffs, autocvar_g_buffs)
 
 bool buffs_BuffModel_Customize(entity this, entity client)
 {
-       entity player, myowner;
-       bool same_team;
-
-       player = WaypointSprite_getviewentity(client);
-       myowner = this.owner;
-       same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner));
+       entity player = WaypointSprite_getviewentity(client);
+       entity myowner = this.owner;
 
-       if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0)
+       if(myowner.alpha <= 0.5 && DIFF_TEAM(player, myowner) && myowner.alpha != 0)
                return false;
 
        if(MUTATOR_CALLHOOK(BuffModel_Customize, this, player))
                return false;
 
-       if(player == myowner || (IS_SPEC(client) && client.enemy == myowner))
+       if(player == myowner)
        {
                // somewhat hide the model, but keep the glow
                this.effects = 0;
@@ -59,6 +56,13 @@ void buffs_BuffModel_Spawn(entity player)
        setcefc(player.buff_model, buffs_BuffModel_Customize);
 }
 
+void buffs_BuffModel_Remove(entity player)
+{
+       if(player.buff_model)
+               delete(player.buff_model);
+       player.buff_model = NULL;
+}
+
 vector buff_GlowColor(entity buff)
 {
        //if(buff.team) { return Team_ColorRGB(buff.team); }
@@ -92,6 +96,8 @@ bool buff_Waypoint_visible_for_player(entity this, entity player, entity view)
 
 void buff_Waypoint_Spawn(entity e)
 {
+       if(autocvar_g_buffs_waypoint_distance <= 0) return;
+
        entity buff = buff_FirstFromFlags(STAT(BUFFS, e));
        entity wp = WaypointSprite_Spawn(WP_Buff, 0, autocvar_g_buffs_waypoint_distance, e, '0 0 1' * e.maxs.z, NULL, e.team, e, buff_waypoint, true, RADARICON_Buff);
        wp.wp_extra = buff.m_id;
@@ -106,7 +112,9 @@ void buff_SetCooldown(entity this, float cd)
        if(!this.buff_waypoint)
                buff_Waypoint_Spawn(this);
 
-       WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd);
+       if(this.buff_waypoint)
+               WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd);
+
        this.buff_activetime = cd;
        this.buff_active = !cd;
 }
@@ -238,6 +246,9 @@ void buff_NewType(entity ent)
 
 void buff_Think(entity this)
 {
+       if(this.buff_waypoint && autocvar_g_buffs_waypoint_distance <= 0)
+               WaypointSprite_Kill(this.buff_waypoint);
+
        if(STAT(BUFFS, this) != this.oldbuffs)
        {
                entity buff = buff_FirstFromFlags(STAT(BUFFS, this));
@@ -261,7 +272,7 @@ void buff_Think(entity this)
        }
 
        if(!game_stopped)
-       if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
+       if((round_handler_IsActive() && round_handler_IsRoundStarted()) || time >= game_starttime)
        if(!this.buff_activetime_updated)
        {
                buff_SetCooldown(this, this.buff_activetime);
@@ -282,7 +293,7 @@ void buff_Think(entity this)
 
        if(this.buff_activetime)
        if(!game_stopped)
-       if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
+       if((round_handler_IsActive() && round_handler_IsRoundStarted()) || time >= game_starttime)
        {
                this.buff_activetime = max(0, this.buff_activetime - frametime);
 
@@ -299,8 +310,7 @@ void buff_Think(entity this)
                if(this.team && !this.buff_waypoint)
                        buff_Waypoint_Spawn(this);
 
-               if(this.lifetime)
-               if(time >= this.lifetime)
+               if(this.lifetime && time >= this.lifetime)
                        buff_Respawn(this);
        }
 
@@ -577,6 +587,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
 {
        entity player = M_ARGV(0, entity);
 
+       buffs_BuffModel_Remove(player);
        player.oldbuffs = 0;
        // reset timers here to prevent them continuing after re-spawn
        player.buff_disability_time = 0;
@@ -627,11 +638,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
                STAT(BUFFS, frag_target) = 0;
                STAT(BUFF_TIME, frag_target) = 0;
 
-               if(frag_target.buff_model)
-               {
-                       delete(frag_target.buff_model);
-                       frag_target.buff_model = NULL;
-               }
+               buffs_BuffModel_Remove(frag_target);
        }
 }
 
@@ -737,11 +744,7 @@ MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
 
 bool buffs_RemovePlayer(entity player)
 {
-       if(player.buff_model)
-       {
-               delete(player.buff_model);
-               player.buff_model = NULL;
-       }
+       buffs_BuffModel_Remove(player);
 
        // also reset timers here to prevent them continuing after spectating
        player.buff_disability_time = 0;
@@ -955,7 +958,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
 
                BUFF_ONADD(BUFF_INVISIBLE)
                {
-                       if(time < player.strength_finished && MUTATOR_IS_ENABLED(mutator_instagib))
+                       if(time < STAT(STRENGTH_FINISHED, player) && MUTATOR_IS_ENABLED(mutator_instagib))
                                player.buff_invisible_prev_alpha = default_player_alpha; // we don't want to save the powerup's alpha, as player may lose the powerup while holding the buff
                        else
                                player.buff_invisible_prev_alpha = player.alpha;
@@ -964,7 +967,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
 
                BUFF_ONREM(BUFF_INVISIBLE)
                {
-                       if(time < player.strength_finished && MUTATOR_IS_ENABLED(mutator_instagib))
+                       if(time < STAT(STRENGTH_FINISHED, player) && MUTATOR_IS_ENABLED(mutator_instagib))
                                player.alpha = autocvar_g_instagib_invis_alpha;
                        else
                                player.alpha = player.buff_invisible_prev_alpha;
@@ -994,9 +997,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
                }
                else
                {
-                       if(player.buff_model)
-                               delete(player.buff_model);
-                       player.buff_model = NULL;
+                       buffs_BuffModel_Remove(player);
 
                        player.effects &= ~(EF_NOSHADOW);
                }