From 28dab3889bf5c5442a8c2fa03e4b9e214c60153f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 19 May 2021 17:59:44 +0200 Subject: [PATCH] - moved the handling of ending PowerWeaponLevel2 into PlayerPawn.Tick and restored the immediate weapon switch. This got changed because switching weapons in EndPowerup is not safe - this can be called from weapon states where the player can end up with a different weapon being active than the one running the state. The actual weapon switch has to be delayed until the state processing has ended. --- .../static/zscript/actors/inventory/powerups.zs | 14 ++------------ .../static/zscript/actors/inventory/weapons.zs | 10 ++++++---- wadsrc/static/zscript/actors/player/player.zs | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/wadsrc/static/zscript/actors/inventory/powerups.zs b/wadsrc/static/zscript/actors/inventory/powerups.zs index 48e146418..d257a9b20 100644 --- a/wadsrc/static/zscript/actors/inventory/powerups.zs +++ b/wadsrc/static/zscript/actors/inventory/powerups.zs @@ -1133,22 +1133,12 @@ class PowerWeaponLevel2 : Powerup Super.EndEffect(); if (Owner == null) return; let player = Owner.player; - if (player != NULL) + if (player != NULL && player.mo != null) { - if (player.ReadyWeapon != NULL && player.ReadyWeapon.bPowered_Up) - { - player.ReadyWeapon.EndPowerup (); - } - if (player.PendingWeapon != NULL && player.PendingWeapon != WP_NOCHANGE && - player.PendingWeapon.bPowered_Up && - player.PendingWeapon.SisterWeapon != NULL) - { - player.PendingWeapon = player.PendingWeapon.SisterWeapon; - } + player.mo.bWeaponLevel2Ended = true; } } - } //=========================================================================== diff --git a/wadsrc/static/zscript/actors/inventory/weapons.zs b/wadsrc/static/zscript/actors/inventory/weapons.zs index 3968d9722..8b822b5d1 100644 --- a/wadsrc/static/zscript/actors/inventory/weapons.zs +++ b/wadsrc/static/zscript/actors/inventory/weapons.zs @@ -848,9 +848,10 @@ class Weapon : StateProvider { if (player.PendingWeapon == NULL || player.PendingWeapon == WP_NOCHANGE) { - player.PendingWeapon = SisterWeapon; + player.refire = 0; + player.ReadyWeapon = SisterWeapon; + player.SetPsprite(PSP_WEAPON, SisterWeapon.GetReadyState()); } - player.WeaponState |= WF_REFIRESWITCHOK; } else { @@ -866,9 +867,10 @@ class Weapon : StateProvider if (player.PendingWeapon == NULL || player.PendingWeapon == WP_NOCHANGE) { // Something went wrong. Initiate a regular weapon change. - player.PendingWeapon = SisterWeapon; + player.refire = 0; + player.ReadyWeapon = SisterWeapon; + player.SetPsprite(PSP_WEAPON, SisterWeapon.GetReadyState()); } - player.WeaponState |= WF_REFIRESWITCHOK; } } } diff --git a/wadsrc/static/zscript/actors/player/player.zs b/wadsrc/static/zscript/actors/player/player.zs index 306c0ce84..fbf2c24ca 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -80,6 +80,7 @@ class PlayerPawn : Actor flagdef NoThrustWhenInvul: PlayerFlags, 0; flagdef CanSuperMorph: PlayerFlags, 1; flagdef CrouchableMorph: PlayerFlags, 2; + flagdef WeaponLevel2Ended: PlayerFlags, 3; Default { @@ -138,6 +139,21 @@ class PlayerPawn : Actor { if (health > 0) Height = FullHeight; } + + if (bWeaponLevel2Ended) + { + bWeaponLevel2Ended = false; + if (player.ReadyWeapon != NULL && player.ReadyWeapon.bPowered_Up) + { + player.ReadyWeapon.EndPowerup (); + } + if (player.PendingWeapon != NULL && player.PendingWeapon != WP_NOCHANGE && + player.PendingWeapon.bPowered_Up && + player.PendingWeapon.SisterWeapon != NULL) + { + player.PendingWeapon = player.PendingWeapon.SisterWeapon; + } + } Super.Tick(); }