Classes:DehackedPickup

From ZDoom Wiki
Jump to navigation Jump to search
Note: Wait! Stop! You do not need to copy this actor's code into your project! Here's why:
  1. This actor is already defined in GZDoom, there's no reason to define it again.
  2. In fact, trying to define an actor with the same name will cause an error (because it already exists).
  3. If you want to make your own version of this actor, use inheritance.
  4. Definitions for existing actors are put on the wiki for reference purpose only.
DeHackEd pickup
Actor type Internal Game MiniZDoomLogoIcon.png (ZDoom)
DoomEd Number None Class Name DehackedPickup


Classes: InventoryDehackedPickup

DehackedPickup is a class used to emulate Doom's original behavior of determining a pickup's type by its sprite. This class is never used by mods directly; GZDoom makes use of it automatically when detecting an Inventory item modified by DEHACKED.

The real item that should be given is determined with a special private function, DetermineType(), which is invoked in DehackedPickup's TryPickup override.

ZScript definition

Note: The ZScript definition below is for reference and may be different in the current version of GZDoom.The most up-to-date version of this code can be found on GZDoom GitHub.
class DehackedPickup : Inventory
{
	Inventory RealPickup;
	bool droppedbymonster;
	
	private native class<Inventory> DetermineType();
	
	override bool TryPickup (in out Actor toucher)
	{
		let type = DetermineType ();
		if (type == NULL)
		{
			return false;
		}
		RealPickup = Inventory(Spawn (type, Pos, NO_REPLACE));
		if (RealPickup != NULL)
		{
			// The internally spawned item should never count towards statistics.
			RealPickup.ClearCounters();
			if (!bDropped)
			{
				RealPickup.bDropped = false;
			}
			// If this item has been dropped by a monster the
			// amount of ammo this gives must be adjusted.
			if (droppedbymonster)
			{
				RealPickup.ModifyDropAmount(0);
			}
			if (!RealPickup.CallTryPickup (toucher))
			{
				RealPickup.Destroy ();
				RealPickup = NULL;
				return false;
			}
			GoAwayAndDie ();
			return true;
		}
		return false;
	}

	override String PickupMessage ()
	{
		if (RealPickup != null)
			return RealPickup.PickupMessage ();
		else return "";
	}

	override bool ShouldStay ()
	{
		if (RealPickup != null)
			return RealPickup.ShouldStay ();
		else return true;
	}

	override bool ShouldRespawn ()
	{
		if (RealPickup != null)
			return RealPickup.ShouldRespawn ();
		else return false;
	}

	override void PlayPickupSound (Actor toucher)
	{
		if (RealPickup != null)
			RealPickup.PlayPickupSound (toucher);
	}

	override void DoPickupSpecial (Actor toucher)
	{
		Super.DoPickupSpecial (toucher);
		// If the real pickup hasn't joined the toucher's inventory, make sure it
		// doesn't stick around.
		if (RealPickup != null && RealPickup.Owner != toucher)
		{
			RealPickup.Destroy ();
		}
		RealPickup = null;
	}

	override void OnDestroy ()
	{
		if (RealPickup != null)
		{
			RealPickup.Destroy ();
			RealPickup = null;
		}
		Super.OnDestroy();
	}
	
	override void ModifyDropAmount(int dropamount)
	{
		// Must forward the adjustment to the real item.
		// dropamount is not relevant here because Dehacked cannot change it.
		droppedbymonster = true;
	}

}

DECORATE definition

Note: This is legacy code, kept for archival purposes only. DECORATE is deprecated in GZDoom and is completely superseded by ZScript. GZDoom internally uses the ZScript definition above.
ACTOR DehackedPickup : Inventory native {}