Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Auto Switch Weapon on Pickup" option #541

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions prboom2/src/dsda/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions prboom2/src/dsda/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions prboom2/src/m_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -3087,6 +3087,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 },
Expand Down
1 change: 1 addition & 0 deletions prboom2/src/m_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,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),
Expand Down
47 changes: 31 additions & 16 deletions prboom2/src/p_inter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put () around allow_incompatibility && !deathmatch && !netgame. I wouldnt think the ternary captures all those conditions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in my test, this does actually work correctly. (i.e. I tested putting allow_incompatiblity at the end) and it still worked as intended.

Lol I will admit it is probably better practice to put () around the conditions though, so I'll do it anyway. :P

//
// P_GiveAmmo
// Num is the number of clip loads,
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -187,7 +203,7 @@ static dboolean P_GiveAmmo(player_t *player, ammotype_t ammo, int num)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put if (!autoswitch) return true; before if (heretic) and remove these 2 conditions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah great catch! Also simplifies this section much more nicely :)

if (player->weaponowned[GetAmmoChange[ammo]])
{
player->pendingweapon = GetAmmoChange[ammo];
P_AutoSwitchWeapon(player, GetAmmoChange[ammo]);
}
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading