Skip to content

Commit

Permalink
Add inventory virtuals for weapon selection
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 committed Oct 21, 2024
1 parent d0e6bce commit 1bb560a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/g_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ CCMD (slot)
if (slot < NUM_WEAPON_SLOTS && mo)
{
// Needs to be redone
IFVIRTUALPTRNAME(mo, NAME_PlayerPawn, PickWeapon)
IFVIRTUALPTRNAME(mo, NAME_PlayerPawn, FindWeapon)
{
VMValue param[] = { mo, slot, !(dmflags2 & DF2_DONTCHECKAMMO) };
VMReturn ret((void**)&SendItemUse);
Expand Down Expand Up @@ -365,7 +365,7 @@ CCMD (weapnext)
if (mo)
{
// Needs to be redone
IFVIRTUALPTRNAME(mo, NAME_PlayerPawn, PickNextWeapon)
IFVIRTUALPTRNAME(mo, NAME_PlayerPawn, FindNextWeapon)
{
VMValue param[] = { mo };
VMReturn ret((void**)&SendItemUse);
Expand All @@ -392,7 +392,7 @@ CCMD (weapprev)
if (mo)
{
// Needs to be redone
IFVIRTUALPTRNAME(mo, NAME_PlayerPawn, PickPrevWeapon)
IFVIRTUALPTRNAME(mo, NAME_PlayerPawn, FindPrevWeapon)
{
VMValue param[] = { mo };
VMReturn ret((void**)&SendItemUse);
Expand Down
15 changes: 14 additions & 1 deletion wadsrc/static/zscript/actors/inventory/inventory.zs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,20 @@ class Inventory : Actor
}
}


virtual Weapon ModifyPickWeapon(int slot, bool checkammo, Weapon originalPick)
{
return originalPick;
}

virtual Weapon ModifyPickNextWeapon(Weapon originalPick)
{
return originalPick;
}

virtual Weapon ModifyPickPrevWeapon(Weapon originalPick)
{
return originalPick;
}

}

Expand Down
54 changes: 54 additions & 0 deletions wadsrc/static/zscript/actors/player/player.zs
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,24 @@ class PlayerPawn : Actor
return ReadyWeapon;
}

Weapon CallModifyPickWeapon(int slot, bool checkammo, Weapon pick)
{
let cur = inv;

if(cur) do
{
pick = cur.ModifyPickWeapon(slot, checkammo, pick);
}
while(cur = cur.inv)

return pick;
}

Weapon FindWeapon(int slot, bool checkammo)
{
return CallModifyPickWeapon(slot, checkammo, PickWeapon(slot, checkammo));
}

//===========================================================================
//
// FindMostRecentWeapon
Expand Down Expand Up @@ -2438,6 +2456,24 @@ class PlayerPawn : Actor
return ReadyWeapon;
}

Weapon CallModifyPickNextWeapon(Weapon pick)
{
let cur = inv;

if(cur) do
{
pick = cur.ModifyPickNextWeapon(pick);
}
while(cur = cur.inv)

return pick;
}

Weapon FindNextWeapon()
{
return CallModifyPickNextWeapon(PickNextWeapon());
}

//===========================================================================
//
// FWeaponSlots :: PickPrevWeapon
Expand Down Expand Up @@ -2491,6 +2527,24 @@ class PlayerPawn : Actor
return player.ReadyWeapon;
}

Weapon CallModifyPickPrevWeapon(Weapon pick)
{
let cur = inv;

if(cur) do
{
pick = cur.ModifyPickPrevWeapon(pick);
}
while(cur = cur.inv)

return pick;
}

Weapon FindPrevWeapon()
{
return CallModifyPickPrevWeapon(PickPrevWeapon());
}

//============================================================================
//
// P_BobWeapon
Expand Down

0 comments on commit 1bb560a

Please sign in to comment.