mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-24 13:01:47 +00:00
- scriptified AddInventory.
This commit is contained in:
parent
d812b94d57
commit
a426655d61
8 changed files with 64 additions and 68 deletions
|
@ -746,9 +746,6 @@ public:
|
|||
// APlayerPawn for some specific handling for players. None of this
|
||||
// should ever be overridden by custom classes.
|
||||
|
||||
// Adds the item to this actor's inventory and sets its Owner.
|
||||
virtual void AddInventory (AInventory *item);
|
||||
|
||||
// Give an item to the actor and pick it up.
|
||||
// Returns true if the item pickup succeeded.
|
||||
bool GiveInventory (PClassActor *type, int amount, bool givecheat = false);
|
||||
|
|
|
@ -89,7 +89,6 @@ public:
|
|||
|
||||
virtual void PostBeginPlay() override;
|
||||
virtual void Tick() override;
|
||||
virtual void AddInventory (AInventory *item) override;
|
||||
virtual void RemoveInventory (AInventory *item) override;
|
||||
virtual bool UseInventory (AInventory *item) override;
|
||||
virtual void BeginPlay () override;
|
||||
|
|
|
@ -350,6 +350,7 @@ DEFINE_FIELD(AActor, RenderHidden)
|
|||
DEFINE_FIELD(AActor, RenderRequired)
|
||||
DEFINE_FIELD(AActor, friendlyseeblocks)
|
||||
DEFINE_FIELD(AActor, SpawnTime)
|
||||
DEFINE_FIELD(AActor, InventoryID)
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
|
@ -752,46 +753,6 @@ DEFINE_ACTION_FUNCTION(AActor, SetState)
|
|||
ACTION_RETURN_BOOL(self->SetState(state, nofunction));
|
||||
};
|
||||
|
||||
//============================================================================
|
||||
//
|
||||
// AActor :: AddInventory
|
||||
//
|
||||
//============================================================================
|
||||
|
||||
void AActor::AddInventory (AInventory *item)
|
||||
{
|
||||
// Check if it's already attached to an actor
|
||||
if (item->Owner != NULL)
|
||||
{
|
||||
// Is it attached to us?
|
||||
if (item->Owner == this)
|
||||
return;
|
||||
|
||||
// No, then remove it from the other actor first
|
||||
item->Owner->RemoveInventory (item);
|
||||
}
|
||||
|
||||
item->Owner = this;
|
||||
item->Inventory = Inventory;
|
||||
Inventory = item;
|
||||
|
||||
// Each item receives an unique ID when added to an actor's inventory.
|
||||
// This is used by the DEM_INVUSE command to identify the item. Simply
|
||||
// using the item's position in the list won't work, because ticcmds get
|
||||
// run sometime in the future, so by the time it runs, the inventory
|
||||
// might not be in the same state as it was when DEM_INVUSE was sent.
|
||||
Inventory->InventoryID = InventoryID++;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(AActor, AddInventory)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(AActor);
|
||||
PARAM_OBJECT_NOT_NULL(item, AInventory);
|
||||
self->AddInventory(item);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
//
|
||||
// AActor :: GiveInventory
|
||||
|
|
|
@ -938,29 +938,6 @@ void APlayerPawn::PostBeginPlay()
|
|||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// APlayerPawn :: AddInventory
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void APlayerPawn::AddInventory (AInventory *item)
|
||||
{
|
||||
// Adding inventory to a voodoo doll should add it to the real player instead.
|
||||
if (player != NULL && player->mo != this && player->mo != NULL)
|
||||
{
|
||||
player->mo->AddInventory (item);
|
||||
return;
|
||||
}
|
||||
Super::AddInventory (item);
|
||||
|
||||
// If nothing is selected, select this item.
|
||||
if (InvSel == NULL && (item->ItemFlags & IF_INVBAR))
|
||||
{
|
||||
InvSel = item;
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// APlayerPawn :: RemoveInventory
|
||||
|
|
|
@ -8,6 +8,7 @@ version "3.7"
|
|||
#include "zscript/actor_attacks.txt"
|
||||
#include "zscript/actor_checks.txt"
|
||||
#include "zscript/actor_interaction.txt"
|
||||
#include "zscript/actor_inventory.txt"
|
||||
#include "zscript/events.txt"
|
||||
#include "zscript/destructible.txt"
|
||||
#include "zscript/level_compatibility.txt"
|
||||
|
@ -56,6 +57,7 @@ version "3.7"
|
|||
|
||||
#include "zscript/shared/player.txt"
|
||||
#include "zscript/shared/player_cheat.txt"
|
||||
#include "zscript/shared/player_inventory.txt"
|
||||
#include "zscript/shared/morph.txt"
|
||||
#include "zscript/shared/botstuff.txt"
|
||||
#include "zscript/shared/sharedmisc.txt"
|
||||
|
|
|
@ -241,6 +241,7 @@ class Actor : Thinker native
|
|||
native int RenderRequired;
|
||||
native readonly int FriendlySeeBlocks;
|
||||
native readonly int SpawnTime;
|
||||
private native int InventoryID; // internal counter.
|
||||
|
||||
meta String Obituary; // Player was killed by this actor
|
||||
meta String HitObituary; // Player was killed by this actor in melee
|
||||
|
@ -740,7 +741,6 @@ class Actor : Thinker native
|
|||
native clearscope int GetAge() const;
|
||||
|
||||
native bool CheckClass(class<Actor> checkclass, int ptr_select = AAPTR_DEFAULT, bool match_superclass = false);
|
||||
native void AddInventory(Inventory inv);
|
||||
native void RemoveInventory(Inventory inv);
|
||||
native void ClearInventory();
|
||||
protected native void DestroyAllInventory(); // This is not supposed to be called by user code!
|
||||
|
|
34
wadsrc/static/zscript/actor_inventory.txt
Normal file
34
wadsrc/static/zscript/actor_inventory.txt
Normal file
|
@ -0,0 +1,34 @@
|
|||
extend class Actor
|
||||
{
|
||||
//============================================================================
|
||||
//
|
||||
// AActor :: AddInventory
|
||||
//
|
||||
//============================================================================
|
||||
|
||||
virtual void AddInventory (Inventory item)
|
||||
{
|
||||
// Check if it's already attached to an actor
|
||||
if (item.Owner != NULL)
|
||||
{
|
||||
// Is it attached to us?
|
||||
if (item.Owner == self)
|
||||
return;
|
||||
|
||||
// No, then remove it from the other actor first
|
||||
item.Owner.RemoveInventory (item);
|
||||
}
|
||||
|
||||
item.Owner = self;
|
||||
item.Inv = Inv;
|
||||
Inv = item;
|
||||
|
||||
// Each item receives an unique ID when added to an actor's inventory.
|
||||
// This is used by the DEM_INVUSE command to identify the item. Simply
|
||||
// using the item's position in the list won't work, because ticcmds get
|
||||
// run sometime in the future, so by the time it runs, the inventory
|
||||
// might not be in the same state as it was when DEM_INVUSE was sent.
|
||||
Inv.InventoryID = InventoryID++;
|
||||
}
|
||||
|
||||
}
|
26
wadsrc/static/zscript/shared/player_inventory.txt
Normal file
26
wadsrc/static/zscript/shared/player_inventory.txt
Normal file
|
@ -0,0 +1,26 @@
|
|||
extend class PlayerPawn
|
||||
{
|
||||
//===========================================================================
|
||||
//
|
||||
// APlayerPawn :: AddInventory
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
override void AddInventory (Inventory item)
|
||||
{
|
||||
// Adding inventory to a voodoo doll should add it to the real player instead.
|
||||
if (player != NULL && player.mo != self && player.mo != NULL)
|
||||
{
|
||||
player.mo.AddInventory (item);
|
||||
return;
|
||||
}
|
||||
Super.AddInventory (item);
|
||||
|
||||
// If nothing is selected, select this item.
|
||||
if (InvSel == NULL && item.bInvBar)
|
||||
{
|
||||
InvSel = item;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue