From 5af4e716647e8b54207089a58be67436605e5a1e Mon Sep 17 00:00:00 2001 From: Arsinikk <61759217+andrikpowell@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:51:01 -0600 Subject: [PATCH] Add "Auto Switch Weapon on Pickup" option (#541) --- prboom2/src/dsda/configuration.c | 4 +++ prboom2/src/dsda/configuration.h | 1 + prboom2/src/m_menu.c | 1 + prboom2/src/m_misc.c | 1 + prboom2/src/p_inter.c | 47 +++++++++++++++++++++----------- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/prboom2/src/dsda/configuration.c b/prboom2/src/dsda/configuration.c index 228651325..c55ebc032 100644 --- a/prboom2/src/dsda/configuration.c +++ b/prboom2/src/dsda/configuration.c @@ -996,6 +996,10 @@ dsda_config_t dsda_config[dsda_config_count] = { "dsda_switch_when_ammo_runs_out", dsda_config_switch_when_ammo_runs_out, CONF_BOOL(1) }, + [dsda_config_switch_weapon_on_pickup] = { + "dsda_switch_weapon_on_pickup", dsda_config_switch_weapon_on_pickup, + CONF_BOOL(1), NULL, STRICT_INT(1) + }, [dsda_config_viewbob] = { "dsda_viewbob", dsda_config_viewbob, CONF_BOOL(1) diff --git a/prboom2/src/dsda/configuration.h b/prboom2/src/dsda/configuration.h index 529e39518..c04e50447 100644 --- a/prboom2/src/dsda/configuration.h +++ b/prboom2/src/dsda/configuration.h @@ -220,6 +220,7 @@ typedef enum { dsda_config_parallel_sfx_window, dsda_config_movement_toggle_sfx, dsda_config_switch_when_ammo_runs_out, + dsda_config_switch_weapon_on_pickup, dsda_config_viewbob, dsda_config_weaponbob, dsda_config_quake_intensity, diff --git a/prboom2/src/m_menu.c b/prboom2/src/m_menu.c index 15005acbb..db4f76e0c 100644 --- a/prboom2/src/m_menu.c +++ b/prboom2/src/m_menu.c @@ -3088,6 +3088,7 @@ setup_menu_t misc_settings[] = { { "Skip Quit Prompt", S_YESNO, m_conf, G_X, dsda_config_skip_quit_prompt }, { "Death Use Action", S_CHOICE, m_conf, G_X, dsda_config_death_use_action, 0, death_use_strings }, { "Boom Weapon Auto Switch", S_YESNO, m_conf, G_X, dsda_config_switch_when_ammo_runs_out }, + { "Auto Switch Weapon on Pickup", S_YESNO, m_conf, G_X, dsda_config_switch_weapon_on_pickup }, { "Parallel Same-Sound Limit", S_NUM, m_conf, G_X, dsda_config_parallel_sfx_limit }, { "Parallel Same-Sound Window", S_NUM, m_conf, G_X, dsda_config_parallel_sfx_window }, { "Play SFX For Movement Toggles", S_YESNO, m_conf, G_X, dsda_config_movement_toggle_sfx }, diff --git a/prboom2/src/m_misc.c b/prboom2/src/m_misc.c index 66f5efb01..eaffef510 100644 --- a/prboom2/src/m_misc.c +++ b/prboom2/src/m_misc.c @@ -312,6 +312,7 @@ cfg_def_t cfg_defs[] = MIGRATED_SETTING(dsda_config_parallel_sfx_window), MIGRATED_SETTING(dsda_config_movement_toggle_sfx), MIGRATED_SETTING(dsda_config_switch_when_ammo_runs_out), + MIGRATED_SETTING(dsda_config_switch_weapon_on_pickup), MIGRATED_SETTING(dsda_config_viewbob), MIGRATED_SETTING(dsda_config_weaponbob), MIGRATED_SETTING(dsda_config_quake_intensity), diff --git a/prboom2/src/p_inter.c b/prboom2/src/p_inter.c index 5f1ab40bd..c4a1f08ba 100644 --- a/prboom2/src/p_inter.c +++ b/prboom2/src/p_inter.c @@ -108,6 +108,22 @@ static weapontype_t GetAmmoChange[] = { wp_mace }; +// +// P_AutoSwitchWeapon +// Autoswitches player to a weapon, +// Based on config and other conditions. +// + +static void P_AutoSwitchWeapon(player_t *player, weapontype_t weapon) +{ + int autoswitch_config = dsda_IntConfig(dsda_config_switch_weapon_on_pickup); + int autoswitch = ((allow_incompatibility && !deathmatch && !netgame) ? autoswitch_config : true); + + if (!autoswitch) return; + + player->pendingweapon = weapon; +} + // // P_GiveAmmo // Num is the number of clip loads, @@ -134,7 +150,7 @@ static dboolean P_GiveAmmoAutoSwitch(player_t *player, ammotype_t ammo, int olda weaponinfo[i].ammopershot <= player->ammo[ammo] ) { - player->pendingweapon = i; + P_AutoSwitchWeapon(player, i); break; } } @@ -187,7 +203,7 @@ static dboolean P_GiveAmmo(player_t *player, ammotype_t ammo, int num) { if (player->weaponowned[GetAmmoChange[ammo]]) { - player->pendingweapon = GetAmmoChange[ammo]; + P_AutoSwitchWeapon(player, GetAmmoChange[ammo]); } } @@ -199,28 +215,28 @@ static dboolean P_GiveAmmo(player_t *player, ammotype_t ammo, int num) case am_clip: if (player->readyweapon == wp_fist) { if (player->weaponowned[wp_chaingun]) - player->pendingweapon = wp_chaingun; + P_AutoSwitchWeapon(player, wp_chaingun); else - player->pendingweapon = wp_pistol; + P_AutoSwitchWeapon(player, wp_pistol); } break; case am_shell: if (player->readyweapon == wp_fist || player->readyweapon == wp_pistol) if (player->weaponowned[wp_shotgun]) - player->pendingweapon = wp_shotgun; + P_AutoSwitchWeapon(player, wp_shotgun); break; case am_cell: if (player->readyweapon == wp_fist || player->readyweapon == wp_pistol) if (player->weaponowned[wp_plasma]) - player->pendingweapon = wp_plasma; + P_AutoSwitchWeapon(player, wp_plasma); break; case am_misl: if (player->readyweapon == wp_fist) if (player->weaponowned[wp_missile]) - player->pendingweapon = wp_missile; + P_AutoSwitchWeapon(player, wp_missile); default: break; } @@ -249,8 +265,7 @@ dboolean P_GiveWeapon(player_t *player, weapontype_t weapon, dboolean dropped) player->weaponowned[weapon] = true; P_GiveAmmo(player, weaponinfo[weapon].ammo, deathmatch ? 5 : 2); - - player->pendingweapon = weapon; + P_AutoSwitchWeapon(player, weapon); /* cph 20028/10 - for old-school DM addicts, allow old behavior * where only consoleplayer's pickup sounds are heard */ // displayplayer, not consoleplayer, for viewing multiplayer demos @@ -276,7 +291,7 @@ dboolean P_GiveWeapon(player_t *player, weapontype_t weapon, dboolean dropped) { gaveweapon = true; player->weaponowned[weapon] = true; - player->pendingweapon = weapon; + P_AutoSwitchWeapon(player, weapon); } return gaveweapon || gaveammo; } @@ -628,7 +643,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher) return; dsda_AddPlayerMessage(s_GOTBERSERK, player); if (player->readyweapon != wp_fist) - player->pendingweapon = wp_fist; + P_AutoSwitchWeapon(player, wp_fist); sound = sfx_getpow; break; @@ -2298,7 +2313,7 @@ dboolean Heretic_P_GiveWeapon(player_t * player, weapontype_t weapon) player->bonuscount += BONUSADD; player->weaponowned[weapon] = true; P_GiveAmmo(player, wpnlev1info[weapon].ammo, GetWeaponAmmo[weapon]); - player->pendingweapon = weapon; + P_AutoSwitchWeapon(player, weapon); if (player == &players[consoleplayer]) { S_StartVoidSound(heretic_sfx_wpnup); @@ -2317,7 +2332,7 @@ dboolean Heretic_P_GiveWeapon(player_t * player, weapontype_t weapon) player->weaponowned[weapon] = true; if (WeaponValue[weapon] > WeaponValue[player->readyweapon]) { // Only switch to more powerful weapons - player->pendingweapon = weapon; + P_AutoSwitchWeapon(player, weapon); } } return (gaveWeapon || gaveAmmo); @@ -2843,7 +2858,7 @@ void TryPickupWeapon(player_t * player, pclass_t weaponClass, { P_GiveMana(player, MANA_2, 25); } - player->pendingweapon = weaponType; + P_AutoSwitchWeapon(player, weaponType); remove = false; } else @@ -2866,7 +2881,7 @@ void TryPickupWeapon(player_t * player, pclass_t weaponClass, player->weaponowned[weaponType] = true; if (weaponType > player->readyweapon) { // Only switch to more powerful weapons - player->pendingweapon = weaponType; + P_AutoSwitchWeapon(player, weaponType); } } if (!(gaveWeapon || gaveMana)) @@ -3002,7 +3017,7 @@ static void TryPickupWeaponPiece(player_t * player, pclass_t matchClass, { gaveWeapon = true; player->weaponowned[wp_fourth] = true; - player->pendingweapon = wp_fourth; + P_AutoSwitchWeapon(player, wp_fourth); } }