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/heretic | |
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/heretic')
-rw-r--r-- | src/heretic/g_game.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/heretic/g_game.c b/src/heretic/g_game.c index 389c0e1d..1154925a 100644 --- a/src/heretic/g_game.c +++ b/src/heretic/g_game.c @@ -228,7 +228,7 @@ static boolean WeaponSelectable(weapontype_t weapon) static int G_NextWeapon(int direction) { weapontype_t weapon; - int i; + int start_i, i; // Find index in the table. @@ -249,13 +249,13 @@ static int G_NextWeapon(int direction) } } - // Switch weapon. - + // Switch weapon. Don't loop forever. + start_i = i; do { i += direction; i = (i + arrlen(weapon_order_table)) % arrlen(weapon_order_table); - } while (!WeaponSelectable(weapon_order_table[i].weapon)); + } while (i != start_i && !WeaponSelectable(weapon_order_table[i].weapon)); return weapon_order_table[i].weapon_num; } @@ -466,7 +466,8 @@ void G_BuildTiccmd(ticcmd_t *cmd, int maketic) // we generate a ticcmd. Choose a new weapon. // (Can't weapon cycle when the player is a chicken) - if (players[consoleplayer].chickenTics == 0 && next_weapon != 0) + if (gamestate == GS_LEVEL + && players[consoleplayer].chickenTics == 0 && next_weapon != 0) { i = G_NextWeapon(next_weapon); cmd->buttons |= BT_CHANGE; |