]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add a function to set the player's alpha, so mutators can adjust player visibility...
authorMario <mario@smbclan.net>
Sat, 29 Sep 2018 05:27:55 +0000 (15:27 +1000)
committerMario <mario@smbclan.net>
Sat, 29 Sep 2018 05:27:55 +0000 (15:27 +1000)
qcsrc/common/mutators/mutator/buffs/sv_buffs.qc
qcsrc/common/mutators/mutator/instagib/sv_instagib.qc
qcsrc/common/mutators/mutator/nades/nades.qc
qcsrc/server/client.qc
qcsrc/server/mutators/events.qh

index 9338c986c9d6ca3e3cd571c51895697a113e0543..86152e45858e25b52daf8b3710e8a193dd3a80f0 100644 (file)
@@ -784,6 +784,18 @@ MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
                M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
 }
 
+MUTATOR_HOOKFUNCTION(buffs, SetPlayerAlpha)
+{
+       entity player = M_ARGV(0, entity);
+
+       if(STAT(BUFFS, player) & BUFF_INVISIBLE.m_itemid)
+       {
+               float alph = ((autocvar_g_buffs_invisible_alpha) ? autocvar_g_buffs_invisible_alpha : -1);
+               M_ARGV(1, float) = alph; // player_alpha
+               M_ARGV(2, float) = alph; // weapon_alpha
+       }
+}
+
 .bool buff_flight_crouchheld;
 
 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
@@ -869,9 +881,6 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
                }
        }
 
-       if((STAT(BUFFS, player) & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid))
-               player.alpha = ((autocvar_g_buffs_invisible_alpha) ? autocvar_g_buffs_invisible_alpha : -1); // powerups reset alpha, so we must enforce this (TODO)
-
        if(STAT(BUFFS, player) & BUFF_MEDIC.m_itemid)
        if(time >= player.buff_medic_healtime)
        {
@@ -924,23 +933,6 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
                        }
                }
 
-               BUFF_ONADD(BUFF_INVISIBLE)
-               {
-                       if(time < player.strength_finished && 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;
-                       player.alpha = autocvar_g_buffs_invisible_alpha;
-               }
-
-               BUFF_ONREM(BUFF_INVISIBLE)
-               {
-                       if(time < player.strength_finished && MUTATOR_IS_ENABLED(mutator_instagib))
-                               player.alpha = autocvar_g_instagib_invis_alpha;
-                       else
-                               player.alpha = player.buff_invisible_prev_alpha;
-               }
-
                BUFF_ONADD(BUFF_FLIGHT)
                {
                        player.buff_flight_oldgravity = player.gravity;
index 3cda4485f1a3efde2bcb324335fbc2da635ea11b..0ce5d84d3c59a812e0850da14dc06692fe00e1aa 100644 (file)
@@ -224,6 +224,17 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
        return true;
 }
 
+MUTATOR_HOOKFUNCTION(mutator_instagib, SetPlayerAlpha)
+{
+       entity player = M_ARGV(0, entity);
+
+       if(time < player.strength_finished)
+       {
+               M_ARGV(1, float) = autocvar_g_instagib_invis_alpha; // player_alpha
+               M_ARGV(2, float) = autocvar_g_instagib_invis_alpha; // weapon_alpha
+       }
+}
+
 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
 {
        entity player = M_ARGV(0, entity);
@@ -236,8 +247,6 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
                play_countdown(player, player.strength_finished, SND_POWEROFF);
                if (time > player.strength_finished)
                {
-                       player.alpha = default_player_alpha;
-                       player.exteriorweaponentity.alpha = default_weapon_alpha;
                        player.items &= ~ITEM_Invisibility.m_itemid;
                        Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
                }
@@ -246,8 +255,6 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
        {
                if (time < player.strength_finished)
                {
-                       player.alpha = autocvar_g_instagib_invis_alpha;
-                       player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
                        player.items |= ITEM_Invisibility.m_itemid;
                        Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
                        Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
index b4a3066fb04a17621faa46e165db9160320e9308..eaaa81f4d83510c6fd900db71d51c7899f35307c 100644 (file)
@@ -676,20 +676,14 @@ void nade_monster_boom(entity this)
 
 void nade_veil_touch(entity this, entity toucher)
 {
-       if ( IS_REAL_CLIENT(toucher) || IS_VEHICLE(toucher) || IS_MONSTER(toucher) )
+       if ( IS_PLAYER(toucher) || (IS_VEHICLE(toucher) && toucher.owner) )
        {
                entity show_tint = (IS_VEHICLE(toucher)) ? toucher.owner : toucher;
 
                float tint_alpha = 0.75;
-               if(SAME_TEAM(toucher, this.realowner))
-               {
+               if(SAME_TEAM(show_tint, this.realowner))
                        tint_alpha = 0.45;
-                       if(!STAT(VEIL_ORB, show_tint))
-                       {
-                               toucher.nade_veil_prevalpha = toucher.alpha;
-                               toucher.alpha = -1;
-                       }
-               }
+
                STAT(VEIL_ORB, show_tint) = time + 0.1;
                STAT(VEIL_ORB_ALPHA, show_tint) = tint_alpha * (this.ltime - time) / this.orb_lifetime;
        }
@@ -1267,6 +1261,17 @@ MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
        (it != player && !STAT(FROZEN, it) && !IS_DEAD(it) && SAME_TEAM(it, player) \
        && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
 
+MUTATOR_HOOKFUNCTION(nades, SetPlayerAlpha)
+{
+       entity player = M_ARGV(0, entity);
+
+       if(STAT(VEIL_ORB, player) > time)
+       {
+               M_ARGV(1, float) = -1; // player_alpha
+               M_ARGV(2, float) = -1; // weapon_alpha
+       }
+}
+
 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
 {
        entity player = M_ARGV(0, entity);
@@ -1330,10 +1335,6 @@ MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
                if(STAT(VEIL_ORB, player) && STAT(VEIL_ORB, player) <= time)
                {
                        STAT(VEIL_ORB, player) = 0;
-                       if(player.vehicle)
-                               player.vehicle.alpha = player.vehicle.nade_veil_prevalpha;
-                       else
-                               player.alpha = player.nade_veil_prevalpha;
                }
        }
 
@@ -1395,12 +1396,6 @@ MUTATOR_HOOKFUNCTION(nades, MonsterMove)
                M_ARGV(1, float) *= autocvar_g_nades_entrap_speed; // run speed
                M_ARGV(2, float) *= autocvar_g_nades_entrap_speed; // walk speed
        }
-
-       if (STAT(VEIL_ORB, mon) && STAT(VEIL_ORB, mon) <= time)
-       {
-               mon.alpha = mon.nade_veil_prevalpha;
-               STAT(VEIL_ORB, mon) = 0;
-       }
 }
 
 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
index 3e457df14e740a9c2b24e8f3938f8bf8e2e706ed..45def4dadafc09e6befd26713182b56b474c827c 100644 (file)
@@ -1369,8 +1369,24 @@ void play_countdown(entity this, float finished, Sound samp)
                                sound (this, CH_INFO, samp, VOL_BASE, ATTEN_NORM);
 }
 
+void SetPlayerAlpha(entity this)
+{
+       if(IS_DEAD(this) || this.vehicle)
+               return;
+
+       float player_alpha = default_player_alpha;
+       float weapon_alpha = default_weapon_alpha;
+       MUTATOR_CALLHOOK(SetPlayerAlpha, this, player_alpha, weapon_alpha);
+       player_alpha = M_ARGV(1, float);
+       weapon_alpha = M_ARGV(2, float);
+       this.alpha = player_alpha;
+       this.exteriorweaponentity.alpha = weapon_alpha;
+}
+
 void player_powerups(entity this)
 {
+       SetPlayerAlpha(this);
+
        // add a way to see what the items were BEFORE all of these checks for the mutator hook
        int items_prev = this.items;
 
index 58e9ca127dabb4fb3183616f7815885fcfafa861..6d79b20804c9b7cb6905374a48cd8f71dd922d19 100644 (file)
@@ -1203,3 +1203,13 @@ MUTATOR_HOOKABLE(Freeze, EV_Freeze);
     /** targ */             i(entity, MUTATOR_ARGV_0_entity) \
     /**/
 MUTATOR_HOOKABLE(Unfreeze, EV_Unfreeze);
+
+/** Called when setting the player's alpha, useful for powerups */
+#define EV_SetPlayerAlpha(i, o) \
+    /** player */       i(entity, MUTATOR_ARGV_0_entity) \
+    /** player alpha */ i(float, MUTATOR_ARGV_1_float) \
+    /**/                o(float, MUTATOR_ARGV_1_float) \
+    /** weapon alpha */ i(float, MUTATOR_ARGV_2_float) \
+    /**/                o(float, MUTATOR_ARGV_2_float) \
+    /**/
+MUTATOR_HOOKABLE(SetPlayerAlpha, EV_SetPlayerAlpha);