From 6d6375349747e1870f9c74bc950bfd25b6bb2b51 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 19 Jan 2015 21:50:28 -0500 Subject: 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. --- src/hexen/g_game.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/hexen/g_game.c') 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; -- cgit v1.2.3