From de4097cc7bb7c84b7a1d241a9dab67eaa224fd94 Mon Sep 17 00:00:00 2001 From: Edward Richardson Date: Thu, 5 Feb 2015 14:52:52 +1300 Subject: [PATCH] Added INVENTORY.TRANSFER - INVENTORY.TRANSFER allows transferring all owned inventory to a new owner on pickup. --- src/g_shared/a_pickups.h | 2 +- src/p_mobj.cpp | 26 ++++++++++++++++++++++++++ src/thingdef/thingdef_data.cpp | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/g_shared/a_pickups.h b/src/g_shared/a_pickups.h index 8616393e7..df0c94b46 100644 --- a/src/g_shared/a_pickups.h +++ b/src/g_shared/a_pickups.h @@ -136,7 +136,7 @@ enum IF_NOSCREENFLASH = 1<<21, // No pickup flash on the player's screen IF_TOSSED = 1<<22, // Was spawned by P_DropItem (i.e. as a monster drop) IF_ALWAYSRESPAWN = 1<<23, // Always respawn, regardless of dmflag - + IF_TRANSFER = 1<<24, // All inventory items that the inventory item contains is also transfered to the pickuper }; diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index ef23ca0ba..b8e45278e 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -551,12 +551,17 @@ void AActor::AddInventory (AInventory *item) { // Is it attached to us? if (item->Owner == this) + { + Printf("Crantech: AddInventory->%s->Owner was Owner\n", item->GetClass()->TypeName.GetChars()); return; + } // No, then remove it from the other actor first item->Owner->RemoveInventory (item); + Printf("Crantech: AddInventory->%s->Owner was nonNULL\n", item->GetClass()->TypeName.GetChars()); } + TObjPtr Invstack = item->Inventory; item->Owner = this; item->Inventory = Inventory; Inventory = item; @@ -567,6 +572,26 @@ void AActor::AddInventory (AInventory *item) // 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++; + + // If the flag exists, transfer all inventory accross that the old object had. + if ((item->ItemFlags & IF_TRANSFER)) + { + while (Invstack) + { + AInventory* titem = Invstack; + Invstack = titem->Inventory; + + Printf("Crantech: AddInventory->%s doing transfer of %s\n", item->GetClass()->TypeName.GetChars(), titem->GetClass()->TypeName.GetChars()); + bool success = titem->CallTryPickup(this); + if (!success) + { + Printf("Crantech: AddInventory->%s, %s is now being destroyed\n", item->GetClass()->TypeName.GetChars(), titem->GetClass()->TypeName.GetChars()); + titem->Destroy(); + } + //AddInventory(item->Inventory); // Adds current inventory item to present index + } + } + } //============================================================================ @@ -587,6 +612,7 @@ void AActor::RemoveInventory (AInventory *item) *invp = item->Inventory; item->DetachFromOwner (); item->Owner = NULL; + item->Inventory = NULL; break; } } diff --git a/src/thingdef/thingdef_data.cpp b/src/thingdef/thingdef_data.cpp index fbe28fb5b..e91c2ee65 100644 --- a/src/thingdef/thingdef_data.cpp +++ b/src/thingdef/thingdef_data.cpp @@ -324,6 +324,7 @@ static FFlagDef InventoryFlags[] = DEFINE_FLAG(IF, NOSCREENFLASH, AInventory, ItemFlags), DEFINE_FLAG(IF, TOSSED, AInventory, ItemFlags), DEFINE_FLAG(IF, ALWAYSRESPAWN, AInventory, ItemFlags), + DEFINE_FLAG(IF, TRANSFER, AInventory, ItemFlags), DEFINE_DEPRECATED_FLAG(PICKUPFLASH), DEFINE_DEPRECATED_FLAG(INTERHUBSTRIP),};