diff --git a/src/d_player.h b/src/d_player.h index f23e2933..243ad402 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -223,6 +223,9 @@ typedef struct player_s int num_visitedlevels; level_t *visitedlevels; + // Last used weapon (last readyweapon). + weapontype_t lastweapon; + } player_t; diff --git a/src/g_game.c b/src/g_game.c index adb21b0b..9229e07e 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -318,6 +318,23 @@ static int G_NextWeapon(int direction) return weapon_order_table[i].weapon_num; } +static weapontype_t LastWeapon(void) +{ + const weapontype_t weapon = players[consoleplayer].lastweapon; + + if (weapon < wp_fist || weapon >= NUMWEAPONS || !WeaponSelectable(weapon)) + { + return wp_nochange; + } + + if (demo_compatibility && weapon == wp_supershotgun) + { + return wp_shotgun; + } + + return weapon; +} + static weapontype_t WeaponSSG(void) { const player_t *player = &players[consoleplayer]; @@ -788,6 +805,10 @@ void G_BuildTiccmd(ticcmd_t* cmd) boom_weapon_state_injection = false; newweapon = P_SwitchWeapon(&players[consoleplayer]); // phares } + else if (M_InputGameActive(input_lastweapon)) + { + newweapon = LastWeapon(); + } else { // phares 02/26/98: Added gamemode checks // [FG] prev/next weapon keys and buttons @@ -2937,6 +2958,7 @@ void G_PlayerReborn(int player) p->usedown = p->attackdown = true; // don't do anything immediately p->playerstate = PST_LIVE; p->health = initial_health; // Ty 03/12/98 - use dehacked values + p->lastweapon = wp_fist; p->readyweapon = p->pendingweapon = wp_pistol; p->weaponowned[wp_fist] = true; p->weaponowned[wp_pistol] = true; diff --git a/src/m_input.c b/src/m_input.c index b85b347b..7f009e08 100644 --- a/src/m_input.c +++ b/src/m_input.c @@ -699,6 +699,7 @@ void M_BindInputVariables(void) BIND_INPUT(input_weapon8, "Switch to weapon 8 (Chainsaw)"); BIND_INPUT(input_weapon9, "Switch to weapon 9 (Super Shotgun)"); BIND_INPUT(input_weapontoggle, "Switch between the two most-preferred weapons with ammo"); + BIND_INPUT(input_lastweapon, "Switch to last used weapon"); BIND_INPUT(input_menu_reloadlevel, "Restart current level/demo"); BIND_INPUT(input_menu_nextlevel, "Go to next level"); diff --git a/src/m_input.h b/src/m_input.h index f72fe732..c135ce1b 100644 --- a/src/m_input.h +++ b/src/m_input.h @@ -56,6 +56,7 @@ enum input_weapon8, input_weapon9, input_weapontoggle, + input_lastweapon, input_menu_up, input_menu_down, diff --git a/src/mn_setup.c b/src/mn_setup.c index 27142de9..174d3089 100644 --- a/src/mn_setup.c +++ b/src/mn_setup.c @@ -1361,6 +1361,7 @@ static setup_menu_t keys_settings2[] = { {"Chainsaw", S_INPUT, KB_X, M_SPC, {0}, m_scrn, input_weapon8}, {"SSG", S_INPUT, KB_X, M_SPC, {0}, m_scrn, input_weapon9}, {"Best", S_INPUT, KB_X, M_SPC, {0}, m_scrn, input_weapontoggle}, + {"Last", S_INPUT, KB_X, M_SPC, {0}, m_scrn, input_lastweapon}, MI_GAP, // [FG] prev/next weapon keys and buttons {"Prev", S_INPUT, KB_X, M_SPC, {0}, m_scrn, input_prevweapon}, diff --git a/src/p_pspr.c b/src/p_pspr.c index 67a1f2c6..65e8084e 100644 --- a/src/p_pspr.c +++ b/src/p_pspr.c @@ -588,6 +588,7 @@ void A_Lower(player_t *player, pspdef_t *psp) if (player->pendingweapon < NUMWEAPONS || !mbf21) { + player->lastweapon = player->readyweapon; player->readyweapon = player->pendingweapon; } diff --git a/src/p_saveg.c b/src/p_saveg.c index 04e37f02..febdd22d 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -989,11 +989,15 @@ static void saveg_read_player_t(player_t *str) level.map = saveg_read32(); array_push(str->visitedlevels, level); } + + // [Woof!]: weapontype_t lastweapon; + str->lastweapon = saveg_read_enum(); } else { str->num_visitedlevels = 0; array_clear(str->visitedlevels); + str->lastweapon = wp_nochange; } } @@ -1158,6 +1162,9 @@ static void saveg_write_player_t(player_t *str) saveg_write32(level->episode); saveg_write32(level->map); } + + // [Woof!]: weapontype_t lastweapon; + saveg_write_enum(str->lastweapon); }