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 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
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 < 1 || by >= amount)
{
DepleteOrDestroy();
}
else
{
amount -= by;
}
}

//===========================================================================
//
// Inventory :: DepleteOrDestroy
Expand Down
16 changes: 5 additions & 11 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 @@ -169,11 +165,10 @@ extend class Actor
// 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 +266,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