From: Mario Date: Mon, 6 Jan 2020 10:27:07 +0000 (+1000) Subject: Reset weapon alignment on respawn and when dual wielding status changes, default... X-Git-Tag: xonotic-v0.8.5~1105^2~50 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=f7b39f30ba70e25be35459c7d2c1f6f99efe135d Reset weapon alignment on respawn and when dual wielding status changes, default to right alignment when dual wielding --- diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 3b74ae3032..0276fbf63e 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -713,10 +713,7 @@ void PutPlayerInServer(entity this) for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { .entity weaponentity = weaponentities[slot]; - entity oldwep = 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; @@ -778,6 +775,7 @@ void PutPlayerInServer(entity 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]; @@ -2085,6 +2083,7 @@ bool joinAllowed(entity this) .int items_added; .string shootfromfixedorigin; +.bool dualwielding_prev; 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)); } + // 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) { diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 6082dbc9ba..dd14a049e1 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -500,6 +500,8 @@ void GetCvars(entity this, entity store, int f) } if (s == "cl_allow_uidtracking") PlayerStats_GameReport_AddPlayer(this); + //if (s == "cl_gunalign") + //W_ResetGunAlign(this, store.cvar_cl_gunalign); } } diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index 3191a76362..0410c2f9ec 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -445,6 +445,28 @@ bool weaponLocked(entity player) 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) diff --git a/qcsrc/server/weapons/weaponsystem.qh b/qcsrc/server/weapons/weaponsystem.qh index 91879feb2a..986756aa51 100644 --- a/qcsrc/server/weapons/weaponsystem.qh +++ b/qcsrc/server/weapons/weaponsystem.qh @@ -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_ResetGunAlign(entity player, int preferred_alignment); + void W_WeaponFrame(Player actor, .entity weaponentity); float W_WeaponRateFactor(entity this);