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

ExtraDepletionBehavior #2615

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
19 changes: 19 additions & 0 deletions wadsrc/static/zscript/actors/inventory/inventory.zs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,25 @@ class Inventory : Actor
}
}

//===========================================================================
//
// Inventory :: DepleteBy
//
// Handles item depletion when using or taking items
//
//===========================================================================
virtual void DepleteBy(int by)
{
if (!amount || by >= amount)
Copy link
Contributor

@MajorCooke MajorCooke Jul 8, 2024

Choose a reason for hiding this comment

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

The check here should be amount < 1, not !amount.

amount is an integer and it can be negative.

Copy link
Author

Choose a reason for hiding this comment

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

Both changes pushed now.

{
DepleteOrDestroy();
}
else
{
amount -= by;
}
}

//===========================================================================
//
// Inventory :: DepleteOrDestroy
Expand Down
20 changes: 8 additions & 12 deletions wadsrc/static/zscript/actors/inventory_util.zs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ extend class Actor

if (!fromdecorate)
{
item.Amount -= amount;
if (item.Amount <= 0)
{
item.DepleteOrDestroy();
}
item.DepleteBy(amount);
// It won't be used in non-decorate context, so return false here
return false;
}
Expand All @@ -163,17 +159,18 @@ extend class Actor

// Do not take ammo if the "no take infinite/take as ammo depletion" flag is set
// and infinite ammo is on
// Alternatively do not take customInventory items if sv_infiniteinventory is true
if (notakeinfinite &&
(sv_infiniteammo || (player && FindInventory('PowerInfiniteAmmo', true))) && (item is 'Ammo'))
(sv_infiniteammo || (player && FindInventory('PowerInfiniteAmmo', true))) && (item is 'Ammo')
|| sv_infiniteinventory && item is 'CustomInventory')
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wrong. TakeInventory is never called if sv_infiniteinventory is true, so this part alone should be reverted. Otherwise this could cause some problems.

Sorry about that.

{
// Nothing to do here, except maybe res = false;? Would it make sense?
result = false;
}
else if (!amount || amount >= item.Amount)
else
{
item.DepleteOrDestroy();
item.DepleteBy(amount);
}
else item.Amount -= amount;

return result;
}
Expand Down Expand Up @@ -271,10 +268,9 @@ extend class Actor
{
return true;
}

if (--item.Amount <= 0)
else
{
item.DepleteOrDestroy ();
item.DepleteBy(1); //useinventory can only really use one item at a time
}
return true;
}
Expand Down
Loading