Added A_SetInventory.
- Sets the absolute amount of an inventory actor. - Limits itself to the range [0, MaxAmount]. Setting beyondMax to true disregards the MaxAmount. Default is false.
This commit is contained in:
parent
bdbc7c3fb7
commit
5dc94a10c3
3 changed files with 89 additions and 0 deletions
|
|
@ -2622,6 +2622,92 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveToSiblings)
|
|||
ACTION_RETURN_INT(count);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// A_SetInventory
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetInventory)
|
||||
{
|
||||
PARAM_ACTION_PROLOGUE;
|
||||
PARAM_CLASS(itemtype, AInventory);
|
||||
PARAM_INT(amount);
|
||||
PARAM_INT_OPT(ptr) { ptr = AAPTR_DEFAULT; }
|
||||
PARAM_BOOL_OPT(beyondMax) { beyondMax = false; }
|
||||
|
||||
bool res = false;
|
||||
|
||||
if (itemtype == nullptr)
|
||||
{
|
||||
ACTION_RETURN_BOOL(false);
|
||||
}
|
||||
|
||||
AActor *mobj = COPY_AAPTR(self, ptr);
|
||||
|
||||
if (mobj == nullptr)
|
||||
{
|
||||
ACTION_RETURN_BOOL(false);
|
||||
}
|
||||
|
||||
AInventory *item = mobj->FindInventory(itemtype);
|
||||
|
||||
if (item != nullptr)
|
||||
{
|
||||
// A_SetInventory sets the absolute amount.
|
||||
// Subtract or set the appropriate amount as necessary.
|
||||
|
||||
if (amount == item->Amount)
|
||||
{
|
||||
// Nothing was changed.
|
||||
ACTION_RETURN_BOOL(false);
|
||||
}
|
||||
else if (amount <= 0)
|
||||
{
|
||||
//Remove it all.
|
||||
res = (mobj->TakeInventory(itemtype, item->Amount, true, false));
|
||||
ACTION_RETURN_BOOL(res);
|
||||
}
|
||||
else if (amount < item->Amount)
|
||||
{
|
||||
int amt = abs(item->Amount - amount);
|
||||
res = (mobj->TakeInventory(itemtype, amt, true, false));
|
||||
ACTION_RETURN_BOOL(res);
|
||||
}
|
||||
else
|
||||
{
|
||||
item->Amount = (beyondMax ? amount : clamp(amount, 0, item->MaxAmount));
|
||||
ACTION_RETURN_BOOL(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (amount <= 0)
|
||||
{
|
||||
ACTION_RETURN_BOOL(false);
|
||||
}
|
||||
item = static_cast<AInventory *>(Spawn(itemtype));
|
||||
if (item == nullptr)
|
||||
{
|
||||
ACTION_RETURN_BOOL(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
item->Amount = amount;
|
||||
item->flags |= MF_DROPPED;
|
||||
item->ItemFlags |= IF_IGNORESKILL;
|
||||
item->ClearCounters();
|
||||
if (!item->CallTryPickup(mobj))
|
||||
{
|
||||
item->Destroy();
|
||||
ACTION_RETURN_BOOL(false);
|
||||
}
|
||||
ACTION_RETURN_BOOL(true);
|
||||
}
|
||||
}
|
||||
ACTION_RETURN_BOOL(false);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// A_TakeInventory
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue