Added co-op option to remember last used weapon when respawning

This commit is contained in:
Boondorl 2024-03-24 19:40:40 -04:00 committed by Rachael Alexanderson
parent 3e939b0ec1
commit 29a2ca0b13
5 changed files with 19 additions and 3 deletions

View file

@ -579,6 +579,7 @@ CVAR(Flag, sv_localitems, dmflags3, DF3_LOCAL_ITEMS);
CVAR(Flag, sv_nolocaldrops, dmflags3, DF3_NO_LOCAL_DROPS); CVAR(Flag, sv_nolocaldrops, dmflags3, DF3_NO_LOCAL_DROPS);
CVAR(Flag, sv_nocoopitems, dmflags3, DF3_NO_COOP_ONLY_ITEMS); CVAR(Flag, sv_nocoopitems, dmflags3, DF3_NO_COOP_ONLY_ITEMS);
CVAR(Flag, sv_nocoopthings, dmflags3, DF3_NO_COOP_ONLY_THINGS); CVAR(Flag, sv_nocoopthings, dmflags3, DF3_NO_COOP_ONLY_THINGS);
CVAR(Flag, sv_rememberlastweapon, dmflags3, DF3_REMEMBER_LAST_WEAP);
//========================================================================== //==========================================================================
// //

View file

@ -185,6 +185,7 @@ enum : unsigned
DF3_NO_LOCAL_DROPS = 1 << 3, // Drops from Actors aren't picked up locally DF3_NO_LOCAL_DROPS = 1 << 3, // Drops from Actors aren't picked up locally
DF3_NO_COOP_ONLY_ITEMS = 1 << 4, // Items that only appear in co-op are disabled DF3_NO_COOP_ONLY_ITEMS = 1 << 4, // Items that only appear in co-op are disabled
DF3_NO_COOP_ONLY_THINGS = 1 << 5, // Any Actor that only appears in co-op is disabled DF3_NO_COOP_ONLY_THINGS = 1 << 5, // Any Actor that only appears in co-op is disabled
DF3_REMEMBER_LAST_WEAP = 1 << 6, // When respawning in co-op, keep the last used weapon out instead of switching to the best new one.
}; };
// [RH] Compatibility flags. // [RH] Compatibility flags.

View file

@ -5508,6 +5508,7 @@ AActor *FLevelLocals::SpawnPlayer (FPlayerStart *mthing, int playernum, int flag
p->mo = mobj; p->mo = mobj;
mobj->player = p; mobj->player = p;
state = p->playerstate; state = p->playerstate;
const auto heldWeap = state == PST_REBORN && (dmflags3 & DF3_REMEMBER_LAST_WEAP) ? p->ReadyWeapon : nullptr;
if (state == PST_REBORN || state == PST_ENTER) if (state == PST_REBORN || state == PST_ENTER)
{ {
PlayerReborn (playernum); PlayerReborn (playernum);
@ -5608,7 +5609,7 @@ AActor *FLevelLocals::SpawnPlayer (FPlayerStart *mthing, int playernum, int flag
{ // Special inventory handling for respawning in coop { // Special inventory handling for respawning in coop
IFVM(PlayerPawn, FilterCoopRespawnInventory) IFVM(PlayerPawn, FilterCoopRespawnInventory)
{ {
VMValue params[] = { p->mo, oldactor }; VMValue params[] = { p->mo, oldactor, ((heldWeap == nullptr || (heldWeap->ObjectFlags & OF_EuthanizeMe)) ? nullptr : heldWeap) };
VMCall(func, params, 2, nullptr, 0); VMCall(func, params, 2, nullptr, 0);
} }
} }

View file

@ -1705,6 +1705,7 @@ OptionMenu CoopOptions protected
Option "$GMPLYMNU_SHAREKEYS", "sv_coopsharekeys", "YesNo" Option "$GMPLYMNU_SHAREKEYS", "sv_coopsharekeys", "YesNo"
Option "$GMPLYMNU_LOCALITEMS", "sv_localitems", "YesNo" Option "$GMPLYMNU_LOCALITEMS", "sv_localitems", "YesNo"
Option "$GMPLYMNU_NOLOCALDROP", "sv_nolocaldrops", "YesNo" Option "$GMPLYMNU_NOLOCALDROP", "sv_nolocaldrops", "YesNo"
Option "$GMPLYMNU_REMEMBERWEAP", "sv_rememberlastweapon", "YesNo"
Class "GameplayMenu" Class "GameplayMenu"
} }

View file

@ -867,7 +867,7 @@ class PlayerPawn : Actor
// //
//=========================================================================== //===========================================================================
void FilterCoopRespawnInventory (PlayerPawn oldplayer) void FilterCoopRespawnInventory (PlayerPawn oldplayer, Weapon curHeldWeapon = null)
{ {
// If we're losing everything, this is really simple. // If we're losing everything, this is really simple.
if (sv_cooploseinventory) if (sv_cooploseinventory)
@ -876,6 +876,10 @@ class PlayerPawn : Actor
return; return;
} }
// Make sure to get the real held weapon before messing with the inventory.
if (curHeldWeapon && curHeldWeapon.bPowered_Up)
curHeldWeapon = curHeldWeapon.SisterWeapon;
// Walk through the old player's inventory and destroy or modify // Walk through the old player's inventory and destroy or modify
// according to dmflags. // according to dmflags.
Inventory next; Inventory next;
@ -957,7 +961,15 @@ class PlayerPawn : Actor
ObtainInventory (oldplayer); ObtainInventory (oldplayer);
player.ReadyWeapon = NULL; player.ReadyWeapon = NULL;
PickNewWeapon (NULL); if (curHeldWeapon && curHeldWeapon.owner == self && curHeldWeapon.CheckAmmo(Weapon.EitherFire, false))
{
player.PendingWeapon = curHeldWeapon;
BringUpWeapon();
}
else
{
PickNewWeapon (NULL);
}
} }