- scriptified 3 more functions in stateprovider.

This commit is contained in:
Christoph Oelckers 2018-11-24 15:42:43 +01:00
parent 4c1b3f81ab
commit 6be7fc33f3
2 changed files with 70 additions and 98 deletions

View file

@ -1602,30 +1602,6 @@ DEFINE_ACTION_FUNCTION(AActor, A_CustomComboAttack)
return 0; 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 // also for monsters
@ -3830,77 +3806,6 @@ DEFINE_ACTION_FUNCTION(AActor, CheckIfInTargetLOS)
ACTION_RETURN_BOOL(true); 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 // A_ChangeFlag

View file

@ -1,10 +1,77 @@
class StateProvider : Inventory native class StateProvider : Inventory native
{ {
action native state A_JumpIfNoAmmo(statelabel label);
action native void A_WeaponReady(int flags = 0); 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;
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //