diff options
author | Simon Howard | 2015-01-19 21:50:28 -0500 |
---|---|---|
committer | Simon Howard | 2015-01-19 21:50:28 -0500 |
commit | 6d6375349747e1870f9c74bc950bfd25b6bb2b51 (patch) | |
tree | 488386d78dfddef6384bb25f5a0a047746faaf4b /src/hexen | |
parent | 10eb5ee80c7854d4ec5cce996af0c250347c0231 (diff) | |
download | chocolate-doom-6d6375349747e1870f9c74bc950bfd25b6bb2b51.tar.gz chocolate-doom-6d6375349747e1870f9c74bc950bfd25b6bb2b51.tar.bz2 chocolate-doom-6d6375349747e1870f9c74bc950bfd25b6bb2b51.zip |
Add extra checks to weapon cycling loops.
Ensure that the loops to find the next weapon always terminate -
even if there are somehow no weapons equipped. Also, only ever do
weapon cycling when in the GS_LEVEL gamestate. This fixes #503 -
thanks to Fabian and raithe on Doomworld.
Diffstat (limited to 'src/hexen')
-rw-r--r-- | src/hexen/g_game.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/hexen/g_game.c b/src/hexen/g_game.c index 6d10dcfd..3593ffe2 100644 --- a/src/hexen/g_game.c +++ b/src/hexen/g_game.c @@ -451,9 +451,11 @@ void G_BuildTiccmd(ticcmd_t *cmd, int maketic) // Weapon cycling. Switch to previous or next weapon. // (Disabled when player is a pig). - - if (players[consoleplayer].morphTics == 0 && next_weapon != 0) + if (gamestate == GS_LEVEL + && players[consoleplayer].morphTics == 0 && next_weapon != 0) { + int start_i; + if (players[consoleplayer].pendingweapon == WP_NOCHANGE) { i = players[consoleplayer].readyweapon; @@ -463,9 +465,11 @@ void G_BuildTiccmd(ticcmd_t *cmd, int maketic) i = players[consoleplayer].pendingweapon; } + // Don't loop forever. + start_i = i; do { - i = (i + next_weapon) % NUMWEAPONS; - } while (!players[consoleplayer].weaponowned[i]); + i = (i + next_weapon + NUMWEAPONS) % NUMWEAPONS; + } while (i != start_i && !players[consoleplayer].weaponowned[i]); cmd->buttons |= BT_CHANGE; cmd->buttons |= i << BT_WEAPONSHIFT; |