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 mbf21 ammo autoswitch handling #26

Merged
merged 1 commit into from
Apr 16, 2021
Merged
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
16 changes: 8 additions & 8 deletions prboom2/src/d_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ weaponinfo_t doom_weaponinfo[NUMWEAPONS+2] =
S_NULL,
0,
0,
WPF_FLEEMELEE
WPF_FLEEMELEE | WPF_AUTOSWITCHFROM
},
{
// pistol
Expand All @@ -80,7 +80,7 @@ weaponinfo_t doom_weaponinfo[NUMWEAPONS+2] =
S_PISTOLFLASH,
1,
0,
WPF_NOFLAG
WPF_NOFLAG | WPF_AUTOSWITCHFROM | WPF_AUTOSWITCHTO
},
{
// shotgun
Expand All @@ -93,7 +93,7 @@ weaponinfo_t doom_weaponinfo[NUMWEAPONS+2] =
S_SGUNFLASH1,
1,
0,
WPF_NOFLAG
WPF_NOFLAG | WPF_AUTOSWITCHTO
},
{
// chaingun
Expand All @@ -106,7 +106,7 @@ weaponinfo_t doom_weaponinfo[NUMWEAPONS+2] =
S_CHAINFLASH1,
1,
0,
WPF_NOFLAG
WPF_NOFLAG | WPF_AUTOSWITCHTO
},
{
// missile launcher
Expand All @@ -119,7 +119,7 @@ weaponinfo_t doom_weaponinfo[NUMWEAPONS+2] =
S_MISSILEFLASH1,
1,
0,
WPF_NOAUTOFIRE
WPF_NOAUTOFIRE | WPF_AUTOSWITCHTO
},
{
// plasma rifle
Expand All @@ -132,7 +132,7 @@ weaponinfo_t doom_weaponinfo[NUMWEAPONS+2] =
S_PLASMAFLASH1,
1,
0,
WPF_NOFLAG
WPF_NOFLAG | WPF_AUTOSWITCHTO
},
{
// bfg 9000
Expand All @@ -145,7 +145,7 @@ weaponinfo_t doom_weaponinfo[NUMWEAPONS+2] =
S_BFGFLASH1,
40,
0,
WPF_NOAUTOFIRE
WPF_NOAUTOFIRE | WPF_AUTOSWITCHTO
},
{
// chainsaw
Expand All @@ -171,7 +171,7 @@ weaponinfo_t doom_weaponinfo[NUMWEAPONS+2] =
S_DSGUNFLASH1,
2,
0,
WPF_NOFLAG
WPF_NOFLAG | WPF_AUTOSWITCHTO
},

// dseg03:00082D90 weaponinfo_t <5, 46h, 45h, 43h, 47h, 0>
Expand Down
3 changes: 2 additions & 1 deletion prboom2/src/d_items.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
#define WPF_SILENT 0x00000002 // weapon is silent
#define WPF_NOAUTOFIRE 0x00000004 // weapon won't autofire in A_WeaponReady
#define WPF_FLEEMELEE 0x00000008 // monsters consider it a melee weapon
#define WPF_AUTOSWITCHFROM 0x00000010 // switches away if ammo for a better weapon is picked up
#define WPF_AUTOSWITCHFROM 0x00000010 // can be switched away from when ammo is picked up
#define WPF_AUTOSWITCHTO 0x00000020 // can be switched to when ammo is picked up

/* Weapon info: sprite frames, ammunition use. */
typedef struct
Expand Down
31 changes: 31 additions & 0 deletions prboom2/src/p_inter.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ static weapontype_t GetAmmoChange[] = {
// Returns false if the ammo can't be picked up at all
//

static dboolean P_GiveAmmoAutoSwitch(player_t *player, ammotype_t ammo, int oldammo)
{
int i;

if (
weaponinfo[player->readyweapon].flags & WPF_AUTOSWITCHFROM &&
weaponinfo[player->readyweapon].ammo != ammo
)
{
for (i = NUMWEAPONS - 1; i > player->readyweapon; --i)
{
if (
player->weaponowned[i] &&
weaponinfo[i].flags & WPF_AUTOSWITCHTO &&
weaponinfo[i].ammo == ammo &&
weaponinfo[i].ammopershot > oldammo &&
weaponinfo[i].ammopershot <= player->ammo[ammo]
)
{
player->pendingweapon = i;
break;
}
}
}

return true;
}

static dboolean P_GiveAmmo(player_t *player, ammotype_t ammo, int num)
{
int oldammo;
Expand Down Expand Up @@ -140,6 +168,9 @@ static dboolean P_GiveAmmo(player_t *player, ammotype_t ammo, int num)
if (player->ammo[ammo] > player->maxammo[ammo])
player->ammo[ammo] = player->maxammo[ammo];

if (mbf21)
return P_GiveAmmoAutoSwitch(player, ammo, oldammo);

// If non zero ammo, don't change up weapons, player was lower on purpose.
if (oldammo)
return true;
Expand Down