- scriptified DropInventory.

This commit is contained in:
Christoph Oelckers 2018-12-01 17:18:26 +01:00
parent 09129e0113
commit 2c59172c42
4 changed files with 32 additions and 32 deletions

View file

@ -549,7 +549,7 @@ FString cht_Morph(player_t *player, PClassActor *morphclass, bool quickundo)
void cht_SetInv(player_t *player, const char *string, int amount, bool beyond) void cht_SetInv(player_t *player, const char *string, int amount, bool beyond)
{ {
IFVIRTUALPTR(player->mo, APlayerPawn, CheatSetInv) IFVIRTUALPTR(player->mo, APlayerPawn, CheatTakeInv)
{ {
FString message = string; FString message = string;
VMValue params[] = { player->mo, &message, amount, beyond }; VMValue params[] = { player->mo, &message, amount, beyond };

View file

@ -842,6 +842,7 @@ bool AActor::UseInventory (AInventory *item)
VMCall(func, params, 2, &ret, 1); VMCall(func, params, 2, &ret, 1);
return !!retval; return !!retval;
} }
return false;
} }
//=========================================================================== //===========================================================================
@ -854,38 +855,15 @@ bool AActor::UseInventory (AInventory *item)
AInventory *AActor::DropInventory (AInventory *item, int amt) AInventory *AActor::DropInventory (AInventory *item, int amt)
{ {
AInventory *drop = nullptr; IFVM(Actor, DropInventory)
IFVIRTUALPTR(item, AInventory, CreateTossable)
{ {
VMValue params[] = { (DObject*)item, amt }; VMValue params[] = { this, item, amt };
VMReturn ret((void**)&drop); AInventory *retval = 0;
VMCall(func, params, countof(params), &ret, 1); VMReturn ret((void**)&retval);
VMCall(func, params, 3, &ret, 1);
return retval;
} }
if (drop == nullptr) return NULL; return nullptr;
drop->SetOrigin(PosPlusZ(10.), false);
drop->Angles.Yaw = Angles.Yaw;
drop->VelFromAngle(5.);
drop->Vel.Z = 1.;
drop->Vel += Vel;
drop->flags &= ~MF_NOGRAVITY; // Don't float
drop->ClearCounters(); // do not count for statistics again
{
// [MK] call OnDrop so item can change its drop behaviour
IFVIRTUALPTR(drop, AInventory, OnDrop)
{
VMValue params[] = { drop, this };
VMCall(func, params, 2, nullptr, 0);
}
}
return drop;
}
DEFINE_ACTION_FUNCTION(AActor, DropInventory)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_OBJECT_NOT_NULL(item, AInventory);
PARAM_INT(amt);
ACTION_RETURN_OBJECT(self->DropInventory(item, amt));
} }
//============================================================================ //============================================================================

View file

@ -745,7 +745,6 @@ class Actor : Thinker native
protected native void DestroyAllInventory(); // This is not supposed to be called by user code! protected native void DestroyAllInventory(); // This is not supposed to be called by user code!
native clearscope Inventory FindInventory(class<Inventory> itemtype, bool subclass = false) const; native clearscope Inventory FindInventory(class<Inventory> itemtype, bool subclass = false) const;
native Inventory GiveInventoryType(class<Inventory> itemtype); native Inventory GiveInventoryType(class<Inventory> itemtype);
native Inventory DropInventory (Inventory item, int amt = -1);
native void ObtainInventory(Actor other); native void ObtainInventory(Actor other);
native bool GiveAmmo (Class<Ammo> type, int amount); native bool GiveAmmo (Class<Ammo> type, int amount);
native bool UsePuzzleItem(int PuzzleItemType); native bool UsePuzzleItem(int PuzzleItemType);

View file

@ -259,6 +259,29 @@ extend class Actor
return true; return true;
} }
//===========================================================================
//
// AActor :: DropInventory
//
// Removes a single copy of an item and throws it out in front of the actor.
//
//===========================================================================
Inventory DropInventory (Inventory item, int amt = 1)
{
Inventory drop = item.CreateTossable(amt);
if (drop == null) return NULL;
drop.SetOrigin(Pos + (0, 0, 10.), false);
drop.Angle = Angle;
drop.VelFromAngle(5.);
drop.Vel.Z = 1.;
drop.Vel += Vel;
drop.bNoGravity = false; // Don't float
drop.ClearCounters(); // do not count for statistics again
drop.OnDrop(self);
return drop;
}
//=========================================================================== //===========================================================================
// //