From 2cb0b2db87815a8d54fe2a04b3fd0fa749bff049 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 2 Dec 2018 14:56:10 +0100 Subject: [PATCH] - took the last methods aside from Tick and Serialize out of AInventory. --- src/g_game.cpp | 2 +- src/g_inventory/a_pickups.cpp | 48 ++------------------------- src/g_inventory/a_pickups.h | 6 +--- src/g_statusbar/sbarinfo_commands.cpp | 28 ++++++++++++++-- src/p_interaction.cpp | 2 +- src/p_mobj.cpp | 2 +- 6 files changed, 33 insertions(+), 55 deletions(-) diff --git a/src/g_game.cpp b/src/g_game.cpp index e2a8d1e255..8dba08cccb 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -1328,7 +1328,7 @@ void G_PlayerFinishLevel (int player, EFinishLevelType mode, int flags) { if (!(it->ObjectFlags & OF_EuthanizeMe)) { - it->DepleteOrDestroy(); + DepleteOrDestroy(item); } } } diff --git a/src/g_inventory/a_pickups.cpp b/src/g_inventory/a_pickups.cpp index 35fc071bf7..aee0b4df7a 100644 --- a/src/g_inventory/a_pickups.cpp +++ b/src/g_inventory/a_pickups.cpp @@ -174,57 +174,15 @@ DEFINE_ACTION_FUNCTION(AInventory, PrintPickupMessage) // //=========================================================================== -void AInventory::DepleteOrDestroy () +void DepleteOrDestroy (AInventory *item) { - IFVIRTUAL(AInventory, DepleteOrDestroy) + IFVIRTUALPTR(item, AInventory, DepleteOrDestroy) { - VMValue params[1] = { (DObject*)this }; + VMValue params[1] = { item }; VMCall(func, params, 1, nullptr, 0); } } -//=========================================================================== -// -// AInventory :: PrevInv -// -// Returns the previous item with IF_INVBAR set. -// -//=========================================================================== - -AInventory *AInventory::PrevInv () -{ - AInventory *lastgood = NULL; - AInventory *item = Owner->Inventory; - - while (item != NULL && item != this) - { - if (item->ItemFlags & IF_INVBAR) - { - lastgood = item; - } - item = item->Inventory; - } - return lastgood; -} -//=========================================================================== -// -// AInventory :: NextInv -// -// Returns the next item with IF_INVBAR set. -// -//=========================================================================== - -AInventory *AInventory::NextInv () -{ - AInventory *item = Inventory; - - while (item != NULL && !(item->ItemFlags & IF_INVBAR)) - { - item = item->Inventory; - } - return item; -} - //=========================================================================== // // AInventory :: CallTryPickup diff --git a/src/g_inventory/a_pickups.h b/src/g_inventory/a_pickups.h index 6b5b754861..a1f2fc8d9a 100644 --- a/src/g_inventory/a_pickups.h +++ b/src/g_inventory/a_pickups.h @@ -73,11 +73,6 @@ public: virtual void Serialize(FSerializer &arc) override; virtual void Tick() override; - void DepleteOrDestroy (); // virtual on the script side. - - AInventory *PrevInv(); // Returns the previous item with IF_INVBAR set. - AInventory *NextInv(); // Returns the next item with IF_INVBAR set. - TObjPtr Owner; // Who owns this item? NULL if it's still a pickup. int Amount; // Amount of item this instance has int MaxAmount; // Max amount of item this instance can have @@ -95,5 +90,6 @@ public: }; bool CallTryPickup(AInventory *item, AActor *toucher, AActor **toucher_return = nullptr); +void DepleteOrDestroy(AInventory *item); // virtual on the script side. #endif //__A_PICKUPS_H__ diff --git a/src/g_statusbar/sbarinfo_commands.cpp b/src/g_statusbar/sbarinfo_commands.cpp index 2eb527979d..0806ad6acb 100644 --- a/src/g_statusbar/sbarinfo_commands.cpp +++ b/src/g_statusbar/sbarinfo_commands.cpp @@ -2085,6 +2085,30 @@ class CommandDrawInventoryBar : public SBarInfoCommand } } + AInventory *PrevInv(AInventory *item) + { + AInventory *retval = nullptr; + IFVM(Inventory, PrevInv) + { + VMValue param = item; + VMReturn ret((void**)&retval); + VMCall(func, ¶m, 1, &ret, 1); + } + return retval; + } + + AInventory *NextInv(AInventory *item) + { + AInventory *retval = nullptr; + IFVM(Inventory, NextInv) + { + VMValue param = item; + VMReturn ret((void**)&retval); + VMCall(func, ¶m, 1, &ret, 1); + } + return retval; + } + void Draw(const SBarInfoMainBlock *block, const DSBarInfo *statusBar) { int spacing = GetCounterSpacing(statusBar); @@ -2099,7 +2123,7 @@ class CommandDrawInventoryBar : public SBarInfoCommand statusBar->CPlayer->mo->InvFirst = statusBar->wrapper->ValidateInvFirst(size); if(statusBar->CPlayer->mo->InvFirst != NULL || alwaysShow) { - for(item = statusBar->CPlayer->mo->InvFirst, i = 0; item != NULL && i < size; item = item->NextInv(), ++i) + for(item = statusBar->CPlayer->mo->InvFirst, i = 0; item != NULL && i < size; item = NextInv(item), ++i) { SBarInfoCoordinate rx = x + (!vertical ? i*spacing : 0); SBarInfoCoordinate ry = y + (vertical ? i*spacing : 0); @@ -2133,7 +2157,7 @@ class CommandDrawInventoryBar : public SBarInfoCommand statusBar->DrawGraphic(statusBar->Images[statusBar->invBarOffset + imgARTIBOX], x + (!vertical ? (i*spacing) : 0), y + (vertical ? (i*spacing) : 0), block->XOffset(), block->YOffset(), bgalpha, block->FullScreenOffsets()); // Is there something to the left? - if (!noArrows && statusBar->CPlayer->mo->InvFirst->PrevInv()) + if (!noArrows && PrevInv(statusBar->CPlayer->mo->InvFirst)) { int offset = (style != STYLE_Strife ? (style != STYLE_HexenStrict ? -12 : -10) : 14); int yOffset = style != STYLE_HexenStrict ? 0 : -1; diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index fd7f53fbe4..f36ccd5120 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -794,7 +794,7 @@ static int UseHealthItems(TArray &Items, int &saveHealth) saveHealth -= maxhealth; if (--Items[index]->Amount == 0) { - Items[index]->DepleteOrDestroy (); + DepleteOrDestroy (Items[index]); Items.Delete(index); break; } diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 0a937b8ba5..d803b3040f 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -950,7 +950,7 @@ void AActor::ClearInventory() AInventory *inv = *invp; if (!(inv->ItemFlags & IF_UNDROPPABLE)) { - inv->DepleteOrDestroy(); + DepleteOrDestroy(inv); if (!(inv->ObjectFlags & OF_EuthanizeMe)) invp = &inv->Inventory; // was only depleted so advance the pointer manually. } else