summaryrefslogtreecommitdiff
path: root/src/doom
diff options
context:
space:
mode:
authorSimon Howard2015-01-19 21:50:28 -0500
committerSimon Howard2015-01-19 21:50:28 -0500
commit6d6375349747e1870f9c74bc950bfd25b6bb2b51 (patch)
tree488386d78dfddef6384bb25f5a0a047746faaf4b /src/doom
parent10eb5ee80c7854d4ec5cce996af0c250347c0231 (diff)
downloadchocolate-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/doom')
-rw-r--r--src/doom/g_game.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/doom/g_game.c b/src/doom/g_game.c
index 0b9dda08..64f5b274 100644
--- a/src/doom/g_game.c
+++ b/src/doom/g_game.c
@@ -281,7 +281,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.
@@ -302,13 +302,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;
}
@@ -445,12 +445,11 @@ void G_BuildTiccmd (ticcmd_t* cmd, int maketic)
// next_weapon variable is set to change weapons when
// we generate a ticcmd. Choose a new weapon.
- if (next_weapon != 0)
+ if (gamestate == GS_LEVEL && next_weapon != 0)
{
i = G_NextWeapon(next_weapon);
cmd->buttons |= BT_CHANGE;
cmd->buttons |= i << BT_WEAPONSHIFT;
- next_weapon = 0;
}
else
{
@@ -469,6 +468,8 @@ void G_BuildTiccmd (ticcmd_t* cmd, int maketic)
}
}
+ next_weapon = 0;
+
// mouse
if (mousebuttons[mousebforward])
{