- 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.
This commit is contained in:
Christoph Oelckers 2021-05-19 17:59:44 +02:00
parent af137dbb35
commit 28dab3889b
3 changed files with 24 additions and 16 deletions

View file

@ -1133,21 +1133,11 @@ 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;
}
}
}
}

View file

@ -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;
}
}
}

View file

@ -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();
}