diff --git a/src/actor.h b/src/actor.h index ba1069042..7af666622 100644 --- a/src/actor.h +++ b/src/actor.h @@ -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); diff --git a/src/d_player.h b/src/d_player.h index 67c409ba3..59b25814a 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -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; diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index a9ff42c4a..02628d056 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -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 diff --git a/src/p_user.cpp b/src/p_user.cpp index 1a9ef4b1f..d5103b660 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -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 diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index d04f99ae0..20f050cd9 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -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" diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index adb5f679d..f3211ece9 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.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 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! diff --git a/wadsrc/static/zscript/actor_inventory.txt b/wadsrc/static/zscript/actor_inventory.txt new file mode 100644 index 000000000..052e1f21f --- /dev/null +++ b/wadsrc/static/zscript/actor_inventory.txt @@ -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++; + } + +} \ No newline at end of file diff --git a/wadsrc/static/zscript/shared/player_inventory.txt b/wadsrc/static/zscript/shared/player_inventory.txt new file mode 100644 index 000000000..c68c30814 --- /dev/null +++ b/wadsrc/static/zscript/shared/player_inventory.txt @@ -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; + } + } + +} \ No newline at end of file