- scriptified GiveInventory and made the interface a bit more configurable by mods.
Now a child type can decide for itself how to treat 'amount'. The scripting interfaces to this function in ACS and FraggleScript have been consolidated and also scriptified.
This commit is contained in:
parent
a426655d61
commit
eb47fb9adc
10 changed files with 156 additions and 171 deletions
|
|
@ -753,81 +753,6 @@ DEFINE_ACTION_FUNCTION(AActor, SetState)
|
|||
ACTION_RETURN_BOOL(self->SetState(state, nofunction));
|
||||
};
|
||||
|
||||
//============================================================================
|
||||
//
|
||||
// AActor :: GiveInventory
|
||||
//
|
||||
//============================================================================
|
||||
|
||||
bool AActor::GiveInventory(PClassActor *type, int amount, bool givecheat)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (type == nullptr || !type->IsDescendantOf(RUNTIME_CLASS(AInventory))) return false;
|
||||
|
||||
auto savedPendingWeap = player != NULL ? player->PendingWeapon : NULL;
|
||||
bool hadweap = player != NULL ? player->ReadyWeapon != NULL : true;
|
||||
|
||||
AInventory *item;
|
||||
if (!givecheat)
|
||||
{
|
||||
item = static_cast<AInventory *>(Spawn (type));
|
||||
}
|
||||
else
|
||||
{
|
||||
item = static_cast<AInventory *>(Spawn (type, Pos(), NO_REPLACE));
|
||||
if (item == NULL) return false;
|
||||
}
|
||||
|
||||
// This shouldn't count for the item statistics!
|
||||
item->ClearCounters();
|
||||
if (!givecheat || amount > 0)
|
||||
{
|
||||
if (type->IsDescendantOf(NAME_BasicArmorPickup) || type->IsDescendantOf(NAME_BasicArmorBonus))
|
||||
{
|
||||
item->IntVar(NAME_SaveAmount) *= amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (givecheat)
|
||||
{
|
||||
const AInventory *const haveitem = FindInventory(type);
|
||||
|
||||
item->Amount = MIN(amount, nullptr == haveitem
|
||||
? static_cast<AInventory*>(GetDefaultByType(type))->MaxAmount
|
||||
: haveitem->MaxAmount);
|
||||
}
|
||||
else
|
||||
{
|
||||
item->Amount = amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!item->CallTryPickup (this))
|
||||
{
|
||||
item->Destroy ();
|
||||
result = false;
|
||||
}
|
||||
// If the item was a weapon, don't bring it up automatically
|
||||
// unless the player was not already using a weapon.
|
||||
// Don't bring it up automatically if this is called by the give cheat.
|
||||
if (!givecheat && player != NULL && savedPendingWeap != NULL && hadweap)
|
||||
{
|
||||
player->PendingWeapon = savedPendingWeap;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AActor, GiveInventory)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
PARAM_CLASS(type, AInventory);
|
||||
PARAM_INT(amount);
|
||||
PARAM_BOOL(givecheat);
|
||||
ACTION_RETURN_BOOL(self->GiveInventory(type, amount, givecheat));
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
//
|
||||
// AActor :: RemoveInventory
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue