- scriptified UseInventory and several functions using the already scriptified ones,
This commit is contained in:
parent
588ddd185b
commit
09129e0113
14 changed files with 384 additions and 436 deletions
|
|
@ -1588,238 +1588,6 @@ DEFINE_ACTION_FUNCTION(AActor, A_CustomRailgun)
|
|||
return 0;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// DoGiveInventory
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
static bool DoGiveInventory(AActor *receiver, bool orresult, VM_ARGS)
|
||||
{
|
||||
int paramnum = 0;
|
||||
PARAM_CLASS (mi, AInventory);
|
||||
PARAM_INT (amount)
|
||||
|
||||
if (!orresult)
|
||||
{
|
||||
PARAM_INT(setreceiver)
|
||||
receiver = COPY_AAPTR(receiver, setreceiver);
|
||||
}
|
||||
if (receiver == NULL)
|
||||
{ // If there's nothing to receive it, it's obviously a fail, right?
|
||||
return false;
|
||||
}
|
||||
// Owned inventory items cannot own anything because their Inventory pointer is repurposed for the owner's linked list.
|
||||
if (receiver->IsKindOf(RUNTIME_CLASS(AInventory)) && static_cast<AInventory*>(receiver)->Owner != nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (amount <= 0)
|
||||
{
|
||||
amount = 1;
|
||||
}
|
||||
if (mi)
|
||||
{
|
||||
AInventory *item = static_cast<AInventory *>(Spawn(mi));
|
||||
if (item == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (item->IsKindOf(NAME_Health))
|
||||
{
|
||||
item->Amount *= amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
item->Amount = amount;
|
||||
}
|
||||
item->flags |= MF_DROPPED;
|
||||
item->ClearCounters();
|
||||
if (!item->CallTryPickup(receiver))
|
||||
{
|
||||
item->Destroy();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AActor, A_GiveInventory)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
ACTION_RETURN_BOOL(DoGiveInventory(self, false, VM_ARGS_NAMES));
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AActor, A_GiveToTarget)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
ACTION_RETURN_BOOL(DoGiveInventory(self->target, false, VM_ARGS_NAMES));
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AActor, A_GiveToChildren)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
|
||||
TThinkerIterator<AActor> it;
|
||||
AActor *mo;
|
||||
int count = 0;
|
||||
|
||||
while ((mo = it.Next()))
|
||||
{
|
||||
if (mo->master == self)
|
||||
{
|
||||
count += DoGiveInventory(mo, true, VM_ARGS_NAMES);
|
||||
}
|
||||
}
|
||||
ACTION_RETURN_INT(count);
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AActor, A_GiveToSiblings)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
|
||||
TThinkerIterator<AActor> it;
|
||||
AActor *mo;
|
||||
int count = 0;
|
||||
|
||||
if (self->master != NULL)
|
||||
{
|
||||
while ((mo = it.Next()))
|
||||
{
|
||||
if (mo->master == self->master && mo != self)
|
||||
{
|
||||
count += DoGiveInventory(mo, true, VM_ARGS_NAMES);
|
||||
}
|
||||
}
|
||||
}
|
||||
ACTION_RETURN_INT(count);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// A_SetInventory
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AActor, A_SetInventory)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
PARAM_CLASS(itemtype, AInventory);
|
||||
PARAM_INT(amount);
|
||||
PARAM_INT(ptr);
|
||||
PARAM_BOOL(beyondMax);
|
||||
|
||||
bool res = false;
|
||||
|
||||
if (itemtype == nullptr)
|
||||
{
|
||||
ACTION_RETURN_BOOL(false);
|
||||
}
|
||||
|
||||
AActor *mobj = COPY_AAPTR(self, ptr);
|
||||
|
||||
if (mobj == nullptr)
|
||||
{
|
||||
ACTION_RETURN_BOOL(false);
|
||||
}
|
||||
|
||||
// Do not run this function on voodoo dolls because the way they transfer the inventory to the player will not work with the code below.
|
||||
if (mobj->player != nullptr)
|
||||
{
|
||||
mobj = mobj->player->mo;
|
||||
}
|
||||
ACTION_RETURN_BOOL(mobj->SetInventory(itemtype, amount, beyondMax));
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// A_TakeInventory
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
enum
|
||||
{
|
||||
TIF_NOTAKEINFINITE = 1,
|
||||
};
|
||||
|
||||
bool DoTakeInventory(AActor *receiver, bool orresult, VM_ARGS)
|
||||
{
|
||||
int paramnum = 0;
|
||||
PARAM_CLASS (itemtype, AInventory);
|
||||
PARAM_INT (amount);
|
||||
PARAM_INT (flags);
|
||||
|
||||
if (itemtype == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!orresult)
|
||||
{
|
||||
PARAM_INT(setreceiver);
|
||||
receiver = COPY_AAPTR(receiver, setreceiver);
|
||||
}
|
||||
if (receiver == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return receiver->TakeInventory(itemtype, amount, true, (flags & TIF_NOTAKEINFINITE) != 0);
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AActor, A_TakeInventory)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
ACTION_RETURN_BOOL(DoTakeInventory(self, false, VM_ARGS_NAMES));
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AActor, A_TakeFromTarget)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
ACTION_RETURN_BOOL(DoTakeInventory(self->target, false, VM_ARGS_NAMES));
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AActor, A_TakeFromChildren)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
TThinkerIterator<AActor> it;
|
||||
AActor *mo;
|
||||
int count = 0;
|
||||
|
||||
while ((mo = it.Next()))
|
||||
{
|
||||
if (mo->master == self)
|
||||
{
|
||||
count += DoTakeInventory(mo, true, VM_ARGS_NAMES);
|
||||
}
|
||||
}
|
||||
ACTION_RETURN_INT(count);
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AActor, A_TakeFromSiblings)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
TThinkerIterator<AActor> it;
|
||||
AActor *mo;
|
||||
int count = 0;
|
||||
|
||||
if (self->master != NULL)
|
||||
{
|
||||
while ((mo = it.Next()))
|
||||
{
|
||||
if (mo->master == self->master && mo != self)
|
||||
{
|
||||
count += DoTakeInventory(mo, true, VM_ARGS_NAMES);
|
||||
}
|
||||
}
|
||||
}
|
||||
ACTION_RETURN_INT(count);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// A_Recoil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue