]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Reset weapon alignment on respawn and when dual wielding status changes, default...
authorMario <mario.mario@y7mail.com>
Mon, 6 Jan 2020 10:27:07 +0000 (20:27 +1000)
committerMario <mario.mario@y7mail.com>
Mon, 6 Jan 2020 10:27:07 +0000 (20:27 +1000)
qcsrc/server/client.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/weapons/weaponsystem.qc
qcsrc/server/weapons/weaponsystem.qh

index 3b74ae30320479e52091c762ef8591dacccbae85..0276fbf63eacec7e78e4068e650390d7bceaed1f 100644 (file)
@@ -713,10 +713,7 @@ void PutPlayerInServer(entity this)
        for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
        {
                .entity weaponentity = weaponentities[slot];
        for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
        {
                .entity weaponentity = weaponentities[slot];
-               entity oldwep = this.(weaponentity);
                CL_SpawnWeaponentity(this, weaponentity);
                CL_SpawnWeaponentity(this, weaponentity);
-               if(oldwep && oldwep.owner == this)
-                       this.(weaponentity).m_gunalign = oldwep.m_gunalign;
        }
        this.alpha = default_player_alpha;
        this.colormod = '1 1 1' * autocvar_g_player_brightness;
        }
        this.alpha = default_player_alpha;
        this.colormod = '1 1 1' * autocvar_g_player_brightness;
@@ -778,6 +775,7 @@ void PutPlayerInServer(entity this)
 
        if (CS(this).impulse) ImpulseCommands(this);
 
 
        if (CS(this).impulse) ImpulseCommands(this);
 
+       W_ResetGunAlign(this, CS(this).cvar_cl_gunalign);
        for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
        {
                .entity weaponentity = weaponentities[slot];
        for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
        {
                .entity weaponentity = weaponentities[slot];
@@ -2085,6 +2083,7 @@ bool joinAllowed(entity this)
 
 .int items_added;
 .string shootfromfixedorigin;
 
 .int items_added;
 .string shootfromfixedorigin;
+.bool dualwielding_prev;
 bool PlayerThink(entity this)
 {
        if (game_stopped || intermission_running) {
 bool PlayerThink(entity this)
 {
        if (game_stopped || intermission_running) {
@@ -2187,6 +2186,15 @@ bool PlayerThink(entity this)
                stuffcmd(this, sprintf("\ncl_shootfromfixedorigin \"%s\"\n", autocvar_g_shootfromfixedorigin));
        }
 
                stuffcmd(this, sprintf("\ncl_shootfromfixedorigin \"%s\"\n", autocvar_g_shootfromfixedorigin));
        }
 
+       // reset gun alignment when dual wielding status changes
+       // to ensure guns are always aligned right and left
+       bool dualwielding = W_DualWielding(this);
+       if(this.dualwielding_prev != dualwielding)
+       {
+               W_ResetGunAlign(this, CS(this).cvar_cl_gunalign);
+               this.dualwielding_prev = dualwielding;
+       }
+
        // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
        //if(frametime)
        {
        // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
        //if(frametime)
        {
index 6082dbc9baf376b02ad6028a3b29036ba6096ac4..dd14a049e1bbb661464ab7bfb112c20ccf92c45f 100644 (file)
@@ -500,6 +500,8 @@ void GetCvars(entity this, entity store, int f)
                }
                if (s == "cl_allow_uidtracking")
                        PlayerStats_GameReport_AddPlayer(this);
                }
                if (s == "cl_allow_uidtracking")
                        PlayerStats_GameReport_AddPlayer(this);
+               //if (s == "cl_gunalign")
+                       //W_ResetGunAlign(this, store.cvar_cl_gunalign);
        }
 }
 
        }
 }
 
index 3191a763624cbd0287aa1e988f7a499422f925a6..0410c2f9ec45129c606efd30d0d7806fbbcc824d 100644 (file)
@@ -445,6 +445,28 @@ bool weaponLocked(entity player)
        return false;
 }
 
        return false;
 }
 
+void W_ResetGunAlign(entity player, int preferred_alignment)
+{
+       if(W_DualWielding(player))
+               preferred_alignment = 3; // right align, the second gun will default to left
+
+       // clear current weapon slots' alignments so we can redo the calculations!
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+       {
+               .entity weaponentity = weaponentities[slot];
+               if (player.(weaponentity))
+                       player.(weaponentity).m_gunalign = 0;
+       }
+
+       // now set the new values
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+       {
+               .entity weaponentity = weaponentities[slot];
+               if (player.(weaponentity))
+                       player.(weaponentity).m_gunalign = W_GunAlign(player.(weaponentity), preferred_alignment);
+       }
+}
+
 .bool hook_switchweapon;
 
 void W_WeaponFrame(Player actor, .entity weaponentity)
 .bool hook_switchweapon;
 
 void W_WeaponFrame(Player actor, .entity weaponentity)
index 91879feb2a9a95548eb6008c500498bc79a07a09..986756aa510344405c4f27e9db7f9b57effef938 100644 (file)
@@ -23,6 +23,8 @@ void W_DropEvent(.void(Weapon, entity actor, .entity) event, entity player, floa
 
 void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sent_sound);
 
 
 void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sent_sound);
 
+void W_ResetGunAlign(entity player, int preferred_alignment);
+
 void W_WeaponFrame(Player actor, .entity weaponentity);
 
 float W_WeaponRateFactor(entity this);
 void W_WeaponFrame(Player actor, .entity weaponentity);
 
 float W_WeaponRateFactor(entity this);