-
Notifications
You must be signed in to change notification settings - Fork 87
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | |
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can put There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]); | ||
} | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
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 conditionsThere was a problem hiding this comment.
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