From 6be7fc33f314de04fe7f613b5b5a714f41b4e3bc Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 24 Nov 2018 15:42:43 +0100 Subject: [PATCH] - scriptified 3 more functions in stateprovider. --- src/p_actionfunctions.cpp | 95 ------------------- .../zscript/inventory/stateprovider.txt | 73 +++++++++++++- 2 files changed, 70 insertions(+), 98 deletions(-) diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index e1b31a0ea..db72ad812 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -1602,30 +1602,6 @@ DEFINE_ACTION_FUNCTION(AActor, A_CustomComboAttack) return 0; } -//========================================================================== -// -// State jump function -// -//========================================================================== -DEFINE_ACTION_FUNCTION(AStateProvider, A_JumpIfNoAmmo) -{ - PARAM_ACTION_PROLOGUE(AStateProvider); - PARAM_STATE_ACTION(jump); - - if (!ACTION_CALL_FROM_PSPRITE() || self->player->ReadyWeapon == nullptr) - { - ACTION_RETURN_STATE(NULL); - } - - if (!self->player->ReadyWeapon->CheckAmmo(self->player->ReadyWeapon->bAltFire, false, true)) - { - ACTION_RETURN_STATE(jump); - } - ACTION_RETURN_STATE(NULL); -} - - - //========================================================================== // // also for monsters @@ -3830,77 +3806,6 @@ DEFINE_ACTION_FUNCTION(AActor, CheckIfInTargetLOS) ACTION_RETURN_BOOL(true); } -//=========================================================================== -// -// Modified code pointer from Skulltag -// -//=========================================================================== - -DEFINE_ACTION_FUNCTION(AStateProvider, A_CheckForReload) -{ - PARAM_ACTION_PROLOGUE(AStateProvider); - - if ( self->player == NULL || self->player->ReadyWeapon == NULL ) - { - ACTION_RETURN_STATE(NULL); - } - PARAM_INT (count); - PARAM_STATE_ACTION (jump); - PARAM_BOOL (dontincrement); - - if (numret > 0) - { - ret->SetPointer(NULL); - numret = 1; - } - - AWeapon *weapon = self->player->ReadyWeapon; - - int ReloadCounter = weapon->ReloadCounter; - if (!dontincrement || ReloadCounter != 0) - ReloadCounter = (weapon->ReloadCounter+1) % count; - else // 0 % 1 = 1? So how do we check if the weapon was never fired? We should only do this when we're not incrementing the counter though. - ReloadCounter = 1; - - // If we have not made our last shot... - if (ReloadCounter != 0) - { - // Go back to the refire frames, instead of continuing on to the reload frames. - if (numret != 0) - { - ret->SetPointer(jump); - } - } - else - { - // We need to reload. However, don't reload if we're out of ammo. - weapon->CheckAmmo(false, false); - } - if (!dontincrement) - { - weapon->ReloadCounter = ReloadCounter; - } - return numret; -} - -//=========================================================================== -// -// Resets the counter for the above function -// -//=========================================================================== - -DEFINE_ACTION_FUNCTION(AStateProvider, A_ResetReloadCounter) -{ - PARAM_ACTION_PROLOGUE(AStateProvider); - - if (self->player == NULL || self->player->ReadyWeapon == NULL) - return 0; - - AWeapon *weapon = self->player->ReadyWeapon; - weapon->ReloadCounter = 0; - return 0; -} - //=========================================================================== // // A_ChangeFlag diff --git a/wadsrc/static/zscript/inventory/stateprovider.txt b/wadsrc/static/zscript/inventory/stateprovider.txt index c9d74a27b..03cfd9b8d 100644 --- a/wadsrc/static/zscript/inventory/stateprovider.txt +++ b/wadsrc/static/zscript/inventory/stateprovider.txt @@ -1,11 +1,78 @@ class StateProvider : Inventory native { - action native state A_JumpIfNoAmmo(statelabel label); action native void A_WeaponReady(int flags = 0); - action native state A_CheckForReload(int counter, statelabel label, bool dontincrement = false); - action native void A_ResetReloadCounter(); + //========================================================================== + // + // State jump function + // + //========================================================================== + + action state A_JumpIfNoAmmo(statelabel label) + { + if (stateinfo == null || stateinfo.mStateType != STATE_Psprite || player == null || player.ReadyWeapon == null || + !player.ReadyWeapon.CheckAmmo(player.ReadyWeapon.bAltFire, false, true)) + { + return null; + } + else return ResolveState(label); + } + + //=========================================================================== + // + // Modified code pointer from Skulltag + // + //=========================================================================== + + action state A_CheckForReload(int count, statelabel jump, bool dontincrement = false) + { + if (stateinfo == null || stateinfo.mStateType != STATE_Psprite || player == null || player.ReadyWeapon == null) + { + return null; + } + + state ret = null; + + let weapon = player.ReadyWeapon; + + int ReloadCounter = weapon.ReloadCounter; + if (!dontincrement || ReloadCounter != 0) + ReloadCounter = (weapon.ReloadCounter+1) % count; + else // 0 % 1 = 1? So how do we check if the weapon was never fired? We should only do this when we're not incrementing the counter though. + ReloadCounter = 1; + + // If we have not made our last shot... + if (ReloadCounter != 0) + { + // Go back to the refire frames, instead of continuing on to the reload frames. + ret = ResolveState(jump); + } + else + { + // We need to reload. However, don't reload if we're out of ammo. + weapon.CheckAmmo(false, false); + } + if (!dontincrement) + { + weapon.ReloadCounter = ReloadCounter; + } + return ret; + } + + //=========================================================================== + // + // Resets the counter for the above function + // + //=========================================================================== + + action void A_ResetReloadCounter() + { + if (stateinfo != null && stateinfo.mStateType == STATE_Psprite && player != null && player.ReadyWeapon != null) + player.ReadyWeapon.ReloadCounter = 0; + } + + //--------------------------------------------------------------------------- // //