- took the last methods aside from Tick and Serialize out of AInventory.

This commit is contained in:
Christoph Oelckers 2018-12-02 14:56:10 +01:00
parent db814dc333
commit 2cb0b2db87
6 changed files with 33 additions and 55 deletions

View file

@ -1328,7 +1328,7 @@ void G_PlayerFinishLevel (int player, EFinishLevelType mode, int flags)
{
if (!(it->ObjectFlags & OF_EuthanizeMe))
{
it->DepleteOrDestroy();
DepleteOrDestroy(item);
}
}
}

View file

@ -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

View file

@ -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<AActor*> 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__

View file

@ -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, &param, 1, &ret, 1);
}
return retval;
}
AInventory *NextInv(AInventory *item)
{
AInventory *retval = nullptr;
IFVM(Inventory, NextInv)
{
VMValue param = item;
VMReturn ret((void**)&retval);
VMCall(func, &param, 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;

View file

@ -794,7 +794,7 @@ static int UseHealthItems(TArray<AInventory *> &Items, int &saveHealth)
saveHealth -= maxhealth;
if (--Items[index]->Amount == 0)
{
Items[index]->DepleteOrDestroy ();
DepleteOrDestroy (Items[index]);
Items.Delete(index);
break;
}

View file

@ -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