diff --git a/src/g_inventory/a_weapons.cpp b/src/g_inventory/a_weapons.cpp index 37611c8b04..0cd0583bec 100644 --- a/src/g_inventory/a_weapons.cpp +++ b/src/g_inventory/a_weapons.cpp @@ -267,27 +267,6 @@ FState *AWeapon::GetDownState () return nullptr; } -//=========================================================================== -// -// AWeapon :: GetReadyState -// -//=========================================================================== - -FState *AWeapon::GetReadyState () -{ - IFVIRTUAL(AWeapon, GetReadyState) - { - VMValue params[1] = { (DObject*)this }; - VMReturn ret; - FState *retval; - ret.PointerAt((void**)&retval); - VMCall(func, params, 1, &ret, 1); - return retval; - } - return nullptr; -} - - /* Weapon slots ***********************************************************/ //=========================================================================== diff --git a/src/g_inventory/a_weapons.h b/src/g_inventory/a_weapons.h index f1ab58fd48..ea2460b081 100644 --- a/src/g_inventory/a_weapons.h +++ b/src/g_inventory/a_weapons.h @@ -131,7 +131,6 @@ public: // scripted virtuals. FState *GetUpState (); FState *GetDownState (); - FState *GetReadyState (); enum { diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 76587f6cbd..2eaa4dee1f 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -556,56 +556,11 @@ DEFINE_ACTION_FUNCTION(DPSprite, SetState) void P_BringUpWeapon (player_t *player) { - AWeapon *weapon; - - if (player->PendingWeapon == WP_NOCHANGE) + IFVM(PlayerPawn, BringUpWeapon) { - if (player->ReadyWeapon != nullptr) - { - player->GetPSprite(PSP_WEAPON)->y = WEAPONTOP; - P_SetPsprite(player, PSP_WEAPON, player->ReadyWeapon->GetReadyState()); - } - return; + VMValue param = player->mo; + VMCall(func, ¶m, 1, nullptr, 0); } - - weapon = player->PendingWeapon; - - // If the player has a tome of power, use this weapon's powered up - // version, if one is available. - if (weapon != nullptr && - weapon->SisterWeapon && - weapon->SisterWeapon->WeaponFlags & WIF_POWERED_UP && - player->mo->FindInventory (PClass::FindActor(NAME_PowerWeaponLevel2), true)) - { - weapon = weapon->SisterWeapon; - } - - player->PendingWeapon = WP_NOCHANGE; - player->ReadyWeapon = weapon; - player->mo->weaponspecial = 0; - - if (weapon != nullptr) - { - if (weapon->UpSound) - { - S_Sound (player->mo, CHAN_WEAPON, weapon->UpSound, 1, ATTN_NORM); - } - player->refire = 0; - - player->GetPSprite(PSP_WEAPON)->y = player->cheats & CF_INSTANTWEAPSWITCH - ? WEAPONTOP : WEAPONBOTTOM; - // make sure that the previous weapon's flash state is terminated. - // When coming here from a weapon drop it may still be active. - P_SetPsprite(player, PSP_FLASH, nullptr); - P_SetPsprite(player, PSP_WEAPON, weapon->GetUpState()); - } -} - -DEFINE_ACTION_FUNCTION(_PlayerInfo, BringUpWeapon) -{ - PARAM_SELF_STRUCT_PROLOGUE(player_t); - P_BringUpWeapon(self); - return 0; } //--------------------------------------------------------------------------- diff --git a/src/scripting/vm/vm.h b/src/scripting/vm/vm.h index d52dc0f6f9..030388efde 100644 --- a/src/scripting/vm/vm.h +++ b/src/scripting/vm/vm.h @@ -678,15 +678,7 @@ FString FStringFormat(VM_ARGS, int offset = 0); #define IFVM(cls, funcname) \ static VMFunction * func = nullptr; \ if (func == nullptr) { \ - func = dyn_cast(RUNTIME_CLASS(cls)->FindSymbol(#funcname, false)); \ - assert(func); \ - } \ - if (func != nullptr) - -#define IFVMNAME(cls, funcname) \ - static VMFunction * func = nullptr; \ - if (func == nullptr) { \ - func = dyn_cast(PClass::FindClass(cls)->FindSymbol(#funcname, false)); \ + PClass::FindFunction(&func, #cls, #funcname); \ assert(func); \ } \ if (func != nullptr) diff --git a/wadsrc/static/zscript/inventory/weapons.txt b/wadsrc/static/zscript/inventory/weapons.txt index 80a892883d..3c4353f9a2 100644 --- a/wadsrc/static/zscript/inventory/weapons.txt +++ b/wadsrc/static/zscript/inventory/weapons.txt @@ -109,6 +109,14 @@ class Weapon : StateProvider native return s; } + virtual void PlayUpSound(Actor origin) + { + if (UpSound) + { + origin.A_PlaySound(UpSound, CHAN_WEAPON); + } + } + override String GetObituary(Actor victim, Actor inflictor, Name mod, bool playerattack) { // Weapons may never return HitObituary by default. Override this if it is needed. @@ -165,7 +173,7 @@ class Weapon : StateProvider native } if (null == player.ReadyWeapon) { - player.BringUpWeapon(); + player.mo.BringUpWeapon(); return; } let psp = player.GetPSprite(PSP_WEAPON); @@ -190,7 +198,7 @@ class Weapon : StateProvider native } // [RH] Clear the flash state. Only needed for Strife. player.SetPsprite(PSP_FLASH, null); - player.BringUpWeapon (); + player.mo.BringUpWeapon (); return; } diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index 25f025d29d..046d9cfa70 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -421,7 +421,7 @@ class PlayerPawn : Actor native if (player.ReadyWeapon == null) { if (player.PendingWeapon != WP_NOCHANGE) - player.BringUpWeapon(); + player.mo.BringUpWeapon(); } else { @@ -1262,6 +1262,56 @@ class PlayerPawn : Actor native } } + //--------------------------------------------------------------------------- + // + // PROC P_BringUpWeapon + // + // Starts bringing the pending weapon up from the bottom of the screen. + // This is only called to start the rising, not throughout it. + // + //--------------------------------------------------------------------------- + + void BringUpWeapon () + { + if (player.PendingWeapon == WP_NOCHANGE) + { + if (player.ReadyWeapon != null) + { + player.GetPSprite(PSP_WEAPON).y = WEAPONTOP; + player.SetPsprite(PSP_WEAPON, player.ReadyWeapon.GetReadyState()); + } + return; + } + + let weapon = player.PendingWeapon; + + // If the player has a tome of power, use this weapon's powered up + // version, if one is available. + if (weapon != null && + weapon.SisterWeapon && + weapon.SisterWeapon.bPowered_Up && + player.mo.FindInventory ('PowerWeaponLevel2', true)) + { + weapon = weapon.SisterWeapon; + } + + player.PendingWeapon = WP_NOCHANGE; + player.ReadyWeapon = weapon; + player.mo.weaponspecial = 0; + + if (weapon != null) + { + weapon.PlayUpSound(self); + player.refire = 0; + + player.GetPSprite(PSP_WEAPON).y = player.cheats & CF_INSTANTWEAPSWITCH? WEAPONTOP : WEAPONBOTTOM; + // make sure that the previous weapon's flash state is terminated. + // When coming here from a weapon drop it may still be active. + player.SetPsprite(PSP_FLASH, null); + player.SetPsprite(PSP_WEAPON, weapon.GetUpState()); + } + } + //---------------------------------------------------------------------------- // @@ -1503,7 +1553,6 @@ struct PlayerInfo native play // this is what internally is known as player_t native void SetLogNumber (int text); native void SetLogText (String text); native void DropWeapon(); - native void BringUpWeapon(); native bool Resurrect(); native String GetUserName() const; @@ -1567,7 +1616,6 @@ struct PlayerInfo native play // this is what internally is known as player_t { return (mo.ViewHeight + crouchviewdelta - viewheight) / 8; } - }