- scriptified GiveAmmo and the one remaining piece of native code still using it.

This commit is contained in:
Christoph Oelckers 2018-12-01 17:20:23 +01:00
parent 2c59172c42
commit 7301bbc58e
6 changed files with 55 additions and 64 deletions

View file

@ -772,9 +772,6 @@ public:
// Returns the first item held with IF_INVBAR set.
AInventory *FirstInv ();
// Tries to give the actor some ammo.
bool GiveAmmo (PClassActor *type, int amount);
// Destroys all the inventory the actor is holding.
void DestroyAllInventory ();

View file

@ -2485,30 +2485,11 @@ void FParser::SF_PlayerKeys(void)
void FParser::SF_PlayerAmmo(void)
{
int playernum, amount;
PClassActor * ammotype;
if (CheckArgs(2))
{
playernum=T_GetPlayerNum(t_argv[0]);
if (playernum==-1) return;
ammotype=T_GetAmmo(t_argv[1]);
if (!ammotype) return;
if(t_argc >= 3)
{
AInventory * iammo = players[playernum].mo->FindInventory(ammotype);
amount = intvalue(t_argv[2]);
if(amount < 0) amount = 0;
if (iammo) iammo->Amount = amount;
else players[playernum].mo->GiveAmmo(ammotype, amount);
}
t_return.type = svt_int;
AInventory * iammo = players[playernum].mo->FindInventory(ammotype);
if (iammo) t_return.value.i = iammo->Amount;
else t_return.value.i = 0;
t_return.value.i = ScriptUtil::Exec("PlayerAmmo", ScriptUtil::Pointer, T_GetPlayerActor(t_argv[0]), ScriptUtil::Class, T_GetAmmo(t_argv[1]),
ScriptUtil::Int, t_argc >= 3 ? intvalue(t_argv[2]) : INT_MIN, ScriptUtil::End);
}
}
@ -2524,7 +2505,7 @@ void FParser::SF_MaxPlayerAmmo()
if (CheckArgs(2))
{
t_return.type = svt_int;
t_return.value.i = ScriptUtil::Exec("MaxPlayerAmmo", ScriptUtil::Pointer, T_GetPlayerActor(t_argv[0]), ScriptUtil::Class, T_ClassType(t_argv[1]),
t_return.value.i = ScriptUtil::Exec("MaxPlayerAmmo", ScriptUtil::Pointer, T_GetPlayerActor(t_argv[0]), ScriptUtil::Class, T_GetAmmo(t_argv[1]),
ScriptUtil::Int, t_argc >= 3? intvalue(t_argv[2]) : INT_MIN, ScriptUtil::Int, t_argc >= 4 ? intvalue(t_argv[3]) : INT_MIN, ScriptUtil::End);
}
}

View file

@ -942,44 +942,6 @@ DEFINE_ACTION_FUNCTION(AActor, GiveInventoryType)
ACTION_RETURN_OBJECT(self->GiveInventoryType(type));
}
//============================================================================
//
// AActor :: GiveAmmo
//
// Returns true if the ammo was added, false if not.
//
//============================================================================
bool AActor::GiveAmmo (PClassActor *type, int amount)
{
if (type != NULL)
{
if (!type->IsDescendantOf(RUNTIME_CLASS(AInventory))) return false;
AInventory *item = static_cast<AInventory *>(Spawn (type));
if (item)
{
item->Amount = amount;
item->flags |= MF_DROPPED;
if (!item->CallTryPickup (this))
{
item->Destroy ();
return false;
}
return true;
}
}
return false;
}
DEFINE_ACTION_FUNCTION(AActor, GiveAmmo)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_CLASS(type, AInventory);
PARAM_INT(amount);
ACTION_RETURN_BOOL(self->GiveAmmo(type, amount));
}
//============================================================================
//
// AActor :: ClearInventory

View file

@ -746,7 +746,6 @@ class Actor : Thinker native
native clearscope Inventory FindInventory(class<Inventory> itemtype, bool subclass = false) const;
native Inventory GiveInventoryType(class<Inventory> itemtype);
native void ObtainInventory(Actor other);
native bool GiveAmmo (Class<Ammo> type, int amount);
native bool UsePuzzleItem(int PuzzleItemType);
native float AccuracyFactor();

View file

@ -283,6 +283,35 @@ extend class Actor
}
//============================================================================
//
// AActor :: GiveAmmo
//
// Returns true if the ammo was added, false if not.
//
//============================================================================
bool GiveAmmo (Class<Ammo> type, int amount)
{
if (type != NULL && type is 'Ammo')
{
let item = Inventory(Spawn (type));
if (item)
{
item.Amount = amount;
item.bDropped = true;
if (!item.CallTryPickup (self))
{
item.Destroy ();
return false;
}
return true;
}
}
return false;
}
//===========================================================================
//
// DoGiveInventory

View file

@ -229,5 +229,28 @@ class ScriptUtil play
else return GetDefaultByType(ammotype).MaxAmount;
}
//==========================================================================
//
//
//
//==========================================================================
int PlayerAmmo(Actor activator, class<Inventory> type, int newamount = int.min)
{
if (activator == null) return 0;
let ammotype = (class<Ammo>)(type);
if (ammotype == null) return 0;
if (newamount != int.min)
{
let iammo = activator.FindInventory(ammotype);
newamount = max(newamount, 0);
if (iammo) iammo.Amount = newamount;
else activator.GiveAmmo(ammotype, newamount);
}
let iammo = activator.FindInventory(ammotype);
if (iammo) return iammo.Amount;
else return 0;
}
}