From ba9e127e9f1e851d69d4ff3843f1f883188b45f7 Mon Sep 17 00:00:00 2001 From: jekyllgrim Date: Thu, 14 Aug 2025 14:37:36 +0300 Subject: [PATCH] Added to CreateTossable and PowerWeaponLevel2 --- .../zscript/actors/inventory/powerups.zs | 3 +++ .../zscript/actors/inventory/weapons.zs | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/wadsrc/static/zscript/actors/inventory/powerups.zs b/wadsrc/static/zscript/actors/inventory/powerups.zs index 5d0f0d7da..f12540cfc 100644 --- a/wadsrc/static/zscript/actors/inventory/powerups.zs +++ b/wadsrc/static/zscript/actors/inventory/powerups.zs @@ -1104,6 +1104,7 @@ class PowerWeaponLevel2 : Powerup if (weap.GetReadyState() != ready) { player.ReadyWeapon = sister; + player.ReadyWeapon.OnSelect(fromPowerup: true); player.SetPsprite(PSP_WEAPON, ready); } else @@ -1114,11 +1115,13 @@ class PowerWeaponLevel2 : Powerup // If the weapon changes but the state does not, we have to manually change the PSprite's caller here. psp.Caller = sister; player.ReadyWeapon = sister; + player.ReadyWeapon.OnSelect(fromPowerup: true); } else { // Something went wrong. Initiate a regular weapon change. player.PendingWeapon = sister; + player.PendingWeapon.OnSelect(fromPowerup: true); } } } diff --git a/wadsrc/static/zscript/actors/inventory/weapons.zs b/wadsrc/static/zscript/actors/inventory/weapons.zs index ba9fda8e7..19a7d093c 100644 --- a/wadsrc/static/zscript/actors/inventory/weapons.zs +++ b/wadsrc/static/zscript/actors/inventory/weapons.zs @@ -144,9 +144,14 @@ class Weapon : StateProvider return -1, 0; } - virtual void OnSelect() {} - virtual void OnDeselect() {} + // [AA] Called when the weapon is selected, including + // PowerWeaponLevel2 activation: + virtual void OnSelect(bool fromPowerup = false) {} + + // [AA] Called when the weapon is deselected, including + // PowerWeaponLevel2 running out or being tossed: + virtual void OnDeselect(bool fromPowerup = false, bool onToss = false) {} virtual State GetReadyState () { @@ -694,6 +699,13 @@ class Weapon : StateProvider { return SisterWeapon.CreateTossable (amt); } + + // [AA] This weapon was selected and its amount is about to become 0: + if (Amount == 1 && Owner != NULL && Owner.Player != NULL && Owner.Player.ReadyWeapon == self) + { + OnDeselect(onToss: true); + } + let copy = Weapon(Super.CreateTossable (-1)); if (copy != NULL) @@ -872,6 +884,7 @@ class Weapon : StateProvider if (player.PendingWeapon == NULL || player.PendingWeapon == WP_NOCHANGE) { player.refire = 0; + OnDeselect(fromPowerup: true); player.ReadyWeapon = SisterWeapon; player.SetPsprite(PSP_WEAPON, SisterWeapon.GetReadyState()); } @@ -882,6 +895,7 @@ class Weapon : StateProvider if (psp != null && psp.Caller == player.ReadyWeapon && psp.CurState.InStateSequence(ready)) { // If the weapon changes but the state does not, we have to manually change the PSprite's caller here. + OnDeselect(fromPowerup: true); psp.Caller = SisterWeapon; player.ReadyWeapon = SisterWeapon; } @@ -890,6 +904,7 @@ class Weapon : StateProvider if (player.PendingWeapon == NULL || player.PendingWeapon == WP_NOCHANGE) { // Something went wrong. Initiate a regular weapon change. + OnDeselect(fromPowerup: true); player.refire = 0; player.ReadyWeapon = SisterWeapon; player.SetPsprite(PSP_WEAPON, SisterWeapon.GetReadyState());