Skip to content

Commit

Permalink
fix broken/inconsistent weapon switching (#1902)
Browse files Browse the repository at this point in the history
* fix broken/inconsistent weapon switching

Fixes #1901

* get rid of doom_weapon_toggles

* switch weapons like PrBoom+

* Revert "get rid of doom_weapon_toggles"

This reverts commit 36f6408.

* fix stuck behavior

* select SSG with the "9" key again

* doom_weapon_toggles does not affect prev/next weapon again

* Revert "select SSG with the "9" key again"

This reverts commit e708a6f.

* Revert "doom_weapon_toggles does not affect prev/next weapon again"

This reverts commit 0ab51f5.

* cosmetics
  • Loading branch information
fabiangreffrath authored Sep 16, 2024
1 parent 58b7bdd commit e3ceb7f
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,20 @@ int bodyqueslot, bodyquesize, default_bodyquesize; // killough 2/8/98, 10/98

static int next_weapon = 0;

static const weapontype_t weapon_order_table[] = {
wp_fist,
wp_chainsaw,
wp_pistol,
wp_shotgun,
wp_supershotgun,
wp_chaingun,
wp_missile,
wp_plasma,
wp_bfg
static const struct
{
weapontype_t weapon;
weapontype_t weapon_num;
} weapon_order_table[] = {
{ wp_fist, wp_fist },
{ wp_chainsaw, wp_fist },
{ wp_pistol, wp_pistol },
{ wp_shotgun, wp_shotgun },
{ wp_supershotgun, wp_shotgun },
{ wp_chaingun, wp_chaingun },
{ wp_missile, wp_missile },
{ wp_plasma, wp_plasma },
{ wp_bfg, wp_bfg }
};

static boolean WeaponSelectable(weapontype_t weapon)
Expand Down Expand Up @@ -261,6 +265,7 @@ static boolean WeaponSelectable(weapontype_t weapon)
// we also have the berserk pack.

if (weapon == wp_fist
&& demo_compatibility
&& players[consoleplayer].weaponowned[wp_chainsaw]
&& !players[consoleplayer].powers[pw_strength])
{
Expand Down Expand Up @@ -288,7 +293,7 @@ static int G_NextWeapon(int direction)

for (i=0; i<arrlen(weapon_order_table); ++i)
{
if (weapon_order_table[i] == weapon)
if (weapon_order_table[i].weapon == weapon)
{
break;
}
Expand All @@ -305,9 +310,12 @@ static int G_NextWeapon(int direction)
{
i += direction;
i = (i + arrlen(weapon_order_table)) % arrlen(weapon_order_table);
} while (i != start_i && !WeaponSelectable(weapon_order_table[i]));
} while (i != start_i && !WeaponSelectable(weapon_order_table[i].weapon));

return weapon_order_table[i];
if (!demo_compatibility)
return weapon_order_table[i].weapon;
else
return weapon_order_table[i].weapon_num;
}

// [FG] toggle demo warp mode
Expand Down Expand Up @@ -772,7 +780,7 @@ void G_BuildTiccmd(ticcmd_t* cmd)
M_InputGameActive(input_weapon6) && gamemode != shareware ? wp_plasma :
M_InputGameActive(input_weapon7) && gamemode != shareware ? wp_bfg :
M_InputGameActive(input_weapon8) ? wp_chainsaw :
M_InputGameActive(input_weapon9) && have_ssg ? wp_supershotgun :
M_InputGameActive(input_weapon9) && !demo_compatibility && have_ssg ? wp_supershotgun :
wp_nochange;

// killough 3/22/98: For network and demo consistency with the
Expand All @@ -789,7 +797,7 @@ void G_BuildTiccmd(ticcmd_t* cmd)
// killough 10/98: make SG/SSG and Fist/Chainsaw
// weapon toggles optional

if (!demo_compatibility && doom_weapon_toggles && !next_weapon)
if (!demo_compatibility && doom_weapon_toggles)
{
const player_t *player = &players[consoleplayer];

Expand Down

0 comments on commit e3ceb7f

Please sign in to comment.