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

Conversation

XLightningStormL
Copy link

ExtraDepletionBehavior is a dynamic way of expanding upon TakeInventory and UseInventory* with additional behaviour, whilst also preventing code bloat from custom inventory use and take functions.

Extremely useful for weight systems, requires at least 1 item in reserve to function (use DetachFromOwner for when the final item is dropped)

*SetInventory should also be theoretically supported, at least on the takeinventory side

Added ExtraDepletionBehavior() functionality to TakeInventory and UseInventory
Added ExtraDepletionBehavior (int takeAmount) function
ExtraDepletionBehavior now requires at least 1 item in reserve to work
@RicardoLuis0
Copy link
Collaborator

RicardoLuis0 commented Jul 6, 2024

hmm, what about renaming it to DepleteBy and moving the whole depletion logic to it?
ex.:

virtual void DepleteBy(int by)
{
    if (!amount || by >= amount)
    {
        DepleteOrDestroy();
    }
    else
    {
        amount -= by;
    }
}

@XLightningStormL
Copy link
Author

hmm, what about renaming it to DepleteBy and moving the whole depletion logic to it? ex.:

virtual void DepleteBy(int by)
{
    if (!amount || by >= amount)
    {
        DepleteOrDestroy();
    }
    else
    {
        amount -= by;
    }
}

Moving the depletion logic to it was the original concept (see here: https://forum.zdoom.org/viewtopic.php?t=79266 and combining the two would definitely be the way to go. My idea was more a functioning proof of concept. Hmm.

@XLightningStormL
Copy link
Author

Alright I've just changed HandleDecrement to DepleteBy behavior as per @RicardoLuis0 's suggestion. Also tested it privately and it works perfectly.

Though I am not sure if usedItem is necessary or not, I only threw it in because it was present in UsedInventory, and I want to try an avoid any inadvertent effects from not including it.

@RicardoLuis0
Copy link
Collaborator

wouldn't this --Amount <= 0 && usedItem make it decrese by one extra with every single call of DepleteBy?

@RicardoLuis0
Copy link
Collaborator

item.DepleteBy(1) just by itself without --Amount <= 0 && usedItem will have the same result as the if(--item.Amount <= 0) item.DepleteOrDestroy(); in UseInventory

@MajorCooke
Copy link
Contributor

MajorCooke commented Jul 7, 2024

Don't forget there's infinite ammo powerups, and the "infinite ammo/items" gameplay options.

added sv_infiniteinventory checks for takeinventory for custominventory items, restored support for sv_infiniteinventory useinventory items
cleaned up DepleteBy - removing unnecessary "--Amount <= 0 && usedItem" check and usedItem bool
@XLightningStormL
Copy link
Author

Alright, both are done. Additionally threw in a sv_infiniteinventory check for custominventory items when they are taken with the cvar active. Tested, and all good, so that should be it at the moment.

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.

//===========================================================================
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.

removed unnecessary sv_infiniteinventory check
amount is integer, depleteordestroy should occur when amount is less than 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants