From d1a68421bdc29f3913475ba93c4121ba3fadd02f Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 5 Aug 2020 20:04:14 +1000 Subject: [PATCH] - fix `cl_weaponsway` for Duke. --- source/games/duke/src/funct.h | 1 + source/games/duke/src/player.cpp | 24 ++++++++++++++++++++++++ source/games/duke/src/player_d.cpp | 18 +----------------- source/games/duke/src/player_r.cpp | 18 +----------------- 4 files changed, 27 insertions(+), 34 deletions(-) diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 21f0740d9..a613fc52d 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -250,6 +250,7 @@ void backupview(player_struct* p); void backupweapon(player_struct* p); void resetinputhelpers(player_struct* p); void checkhardlanding(player_struct* p); +void playerweaponsway(player_struct* p, spritetype* s); void playerAddAngle(player_struct* p, int ang); void playerSetAngle(player_struct* p, int ang); diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index cf38285f3..ce3eaaa5a 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -927,6 +927,30 @@ void checkhardlanding(player_struct* p) } } +void playerweaponsway(player_struct* p, spritetype* s) +{ + if (cl_weaponsway) + { + if (s->xvel < 32 || p->on_ground == 0 || p->bobcounter == 1024) + { + if ((p->weapon_sway & 2047) > (1024 + 96)) + p->weapon_sway -= 96; + else if ((p->weapon_sway & 2047) < (1024 - 96)) + p->weapon_sway += 96; + else p->oweapon_sway = p->weapon_sway = 1024; + } + else + { + p->weapon_sway = p->bobcounter; + + if ((p->bobcounter - p->oweapon_sway) > 256) + { + p->oweapon_sway = p->weapon_sway; + } + } + } +} + //--------------------------------------------------------------------------- // // diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 18fdbf677..ca87a2dde 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2731,23 +2731,7 @@ void processinput_d(int snum) if (p->on_crane >= 0) goto HORIZONLY; - if (s->xvel < 32 || p->on_ground == 0 || p->bobcounter == 1024) - { - if ((p->weapon_sway & 2047) > (1024 + 96)) - p->weapon_sway -= 96; - else if ((p->weapon_sway & 2047) < (1024 - 96)) - p->weapon_sway += 96; - else p->oweapon_sway = p->weapon_sway = 1024; - } - else - { - p->weapon_sway = p->bobcounter; - - if ((p->bobcounter - p->oweapon_sway) > 256) - { - p->oweapon_sway = p->weapon_sway; - } - } + playerweaponsway(p, s); s->xvel = ksqrt((p->posx - p->bobposx) * (p->posx - p->bobposx) + (p->posy - p->bobposy) * (p->posy - p->bobposy)); diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 82d5578e4..b542147ae 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3637,23 +3637,7 @@ void processinput_r(int snum) if (p->on_crane >= 0) goto HORIZONLY; - if (s->xvel < 32 || p->on_ground == 0 || p->bobcounter == 1024) - { - if ((p->weapon_sway & 2047) > (1024 + 96)) - p->weapon_sway -= 96; - else if ((p->weapon_sway & 2047) < (1024 - 96)) - p->weapon_sway += 96; - else p->oweapon_sway = p->weapon_sway = 1024; - } - else - { - p->weapon_sway = p->bobcounter; - - if ((p->bobcounter - p->oweapon_sway) > 256) - { - p->oweapon_sway = p->weapon_sway; - } - } + playerweaponsway(p, s); s->xvel = ksqrt((p->posx - p->bobposx) * (p->posx - p->bobposx) + (p->posy - p->bobposy) * (p->posy - p->bobposy));