From 108ad7736a8af21ae2e0793303e1da408e38d5c6 Mon Sep 17 00:00:00 2001 From: jekyllgrim Date: Thu, 15 Aug 2024 17:02:17 +0300 Subject: [PATCH] Added itemcls to HasReceived CallTryPickup will cache the item's class and pass it to HasReceived, so the latter will know what item was received even if the item has been destroyed by the time it's called. --- wadsrc/static/zscript/actors/actor.zs | 6 ++++-- wadsrc/static/zscript/actors/inventory/inventory.zs | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index 2658a052f..7dd0cfc2b 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -534,7 +534,9 @@ class Actor : Thinker native // [AA] Called by inventory items at the end of CallTryPickup to let actors // do something with the items they've received. 'Item' might be null for // items that disappear on pickup. - virtual void HasReceived(Inventory item) {} + // 'itemcls' is passed unconditionally, so it can still be read even if + // 'item' is null due to being destroyed with GoAwayAndDie() on pickup. + virtual void HasReceived(Inventory item, class itemcls) {} // Called in TryMove if the mover ran into another Actor. This isn't called on players // if they're currently predicting. Guarantees collisions unlike CanCollideWith. @@ -705,7 +707,7 @@ class Actor : Thinker native native void SoundAlert(Actor target, bool splash = false, double maxdist = 0); native void ClearBounce(); native TerrainDef GetFloorTerrain(); - native bool CheckLocalView(int consoleplayer = -1 /* parameter is not used anymore but needed for backward compatibilityö. */); + native bool CheckLocalView(int consoleplayer = -1 /* parameter is not used anymore but needed for backward compatibility�. */); native bool CheckNoDelay(); native bool UpdateWaterLevel (bool splash = true); native bool IsZeroDamage(); diff --git a/wadsrc/static/zscript/actors/inventory/inventory.zs b/wadsrc/static/zscript/actors/inventory/inventory.zs index 0ca6faf3e..52009f2e1 100644 --- a/wadsrc/static/zscript/actors/inventory/inventory.zs +++ b/wadsrc/static/zscript/actors/inventory/inventory.zs @@ -647,9 +647,10 @@ class Inventory : Actor // unmorphed versions of a currently morphed actor cannot pick up anything. if (bUnmorphed) return false, null; - //[AA] starting with true, so that CanReceive can unset it, + // [AA] starting with true, so that CanReceive can unset it, // if necessary: bool res = true; + class cls = self.GetClass(); // [AA] CanReceive lets the actor receiving the item process it first. if (!toucher.CanReceive(self)) { @@ -696,7 +697,7 @@ class Inventory : Actor } } // [AA] Let the toucher do something with the item they've just received: - toucher.HasReceived(self); + toucher.HasReceived(self, cls); // If the item can be shared, make sure every player gets a copy. if (multiplayer && !deathmatch && !bDropped && ShouldShareItem(toucher))