- scriptified a few parts of p_pspr.cpp.

- added a speed parameter to A_Lower and A_Raise in the process.
This commit is contained in:
Christoph Oelckers 2017-01-19 13:25:56 +01:00
parent 0376c8ba24
commit 42f3ccc602
7 changed files with 185 additions and 207 deletions

View file

@ -36,7 +36,6 @@
// MACROS ------------------------------------------------------------------
#define LOWERSPEED 6.
#define RAISESPEED 6.
// TYPES -------------------------------------------------------------------
@ -507,6 +506,13 @@ void P_BringUpWeapon (player_t *player)
}
}
DEFINE_ACTION_FUNCTION(_PlayerInfo, BringUpWeapon)
{
PARAM_SELF_STRUCT_PROLOGUE(player_t);
P_BringUpWeapon(self);
return 0;
}
//---------------------------------------------------------------------------
//
// PROC P_FireWeapon
@ -603,6 +609,12 @@ void P_DropWeapon (player_t *player)
}
}
DEFINE_ACTION_FUNCTION(_PlayerInfo, DropWeapon)
{
PARAM_SELF_STRUCT_PROLOGUE(player_t);
P_DropWeapon(self);
return 0;
}
//============================================================================
//
// P_BobWeapon
@ -999,40 +1011,6 @@ void A_ReFire(AActor *self, FState *state)
}
}
DEFINE_ACTION_FUNCTION(AStateProvider, A_ClearReFire)
{
PARAM_ACTION_PROLOGUE(AStateProvider);
player_t *player = self->player;
if (NULL != player)
{
player->refire = 0;
}
return 0;
}
//---------------------------------------------------------------------------
//
// PROC A_CheckReload
//
// Present in Doom, but unused. Also present in Strife, and actually used.
// This and what I call A_XBowReFire are actually the same thing in Strife,
// not two separate functions as I have them here.
//
//---------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AStateProvider, A_CheckReload)
{
PARAM_ACTION_PROLOGUE(AStateProvider);
if (self->player != NULL)
{
self->player->ReadyWeapon->CheckAmmo (
self->player->ReadyWeapon->bAltFire ? AWeapon::AltFire
: AWeapon::PrimaryFire, true);
}
return 0;
}
//---------------------------------------------------------------------------
//
@ -1206,95 +1184,6 @@ DEFINE_ACTION_FUNCTION(AActor, OverlayID)
//---------------------------------------------------------------------------
//
// PROC A_Lower
//
//---------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AStateProvider, A_Lower)
{
PARAM_ACTION_PROLOGUE(AStateProvider);
player_t *player = self->player;
DPSprite *psp;
if (nullptr == player)
{
return 0;
}
if (nullptr == player->ReadyWeapon)
{
P_BringUpWeapon(player);
return 0;
}
psp = player->GetPSprite(PSP_WEAPON);
if (player->morphTics || player->cheats & CF_INSTANTWEAPSWITCH)
{
psp->y = WEAPONBOTTOM;
}
else
{
psp->y += LOWERSPEED;
}
if (psp->y < WEAPONBOTTOM)
{ // Not lowered all the way yet
return 0;
}
if (player->playerstate == PST_DEAD)
{ // Player is dead, so don't bring up a pending weapon
// Player is dead, so keep the weapon off screen
P_SetPsprite(player, PSP_FLASH, nullptr);
psp->SetState(player->ReadyWeapon->FindState(NAME_DeadLowered));
return 0;
}
// [RH] Clear the flash state. Only needed for Strife.
P_SetPsprite(player, PSP_FLASH, nullptr);
P_BringUpWeapon (player);
return 0;
}
//---------------------------------------------------------------------------
//
// PROC A_Raise
//
//---------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AStateProvider, A_Raise)
{
PARAM_ACTION_PROLOGUE(AStateProvider);
if (self == nullptr)
{
return 0;
}
player_t *player = self->player;
DPSprite *psp;
if (nullptr == player)
{
return 0;
}
if (player->PendingWeapon != WP_NOCHANGE)
{
P_DropWeapon(player);
return 0;
}
if (player->ReadyWeapon == nullptr)
{
return 0;
}
psp = player->GetPSprite(PSP_WEAPON);
psp->y -= RAISESPEED;
if (psp->y > WEAPONTOP)
{ // Not raised all the way yet
return 0;
}
psp->y = WEAPONTOP;
psp->SetState(player->ReadyWeapon->GetReadyState());
return 0;
}
//---------------------------------------------------------------------------
//
// PROC A_Overlay
@ -1364,47 +1253,6 @@ DEFINE_ACTION_FUNCTION(AActor, A_ClearOverlays)
ACTION_RETURN_INT(count);
}
//
// A_GunFlash
//
enum GF_Flags
{
GFF_NOEXTCHANGE = 1,
};
DEFINE_ACTION_FUNCTION(AStateProvider, A_GunFlash)
{
PARAM_ACTION_PROLOGUE(AStateProvider);
PARAM_STATE_ACTION_DEF(flash);
PARAM_INT_DEF(flags);
player_t *player = self->player;
if (nullptr == player)
{
return 0;
}
if (!(flags & GFF_NOEXTCHANGE))
{
player->mo->PlayAttacking2 ();
}
if (flash == nullptr)
{
if (player->ReadyWeapon->bAltFire)
{
flash = player->ReadyWeapon->FindState(NAME_AltFlash);
}
if (flash == nullptr)
{
flash = player->ReadyWeapon->FindState(NAME_Flash);
}
}
P_SetPsprite(player, PSP_FLASH, flash);
return 0;
}
//
// WEAPON ATTACKS
//
@ -1450,20 +1298,6 @@ DEFINE_ACTION_FUNCTION(AActor, BulletSlope)
ACTION_RETURN_FLOAT(P_BulletSlope(self, t, aimflags).Degrees);
}
AActor *P_AimTarget(AActor *mo)
{
FTranslatedLineTarget t;
P_BulletSlope(mo, &t, ALF_PORTALRESTRICT);
return t.linetarget;
}
DEFINE_ACTION_FUNCTION(AActor, AimTarget)
{
PARAM_SELF_PROLOGUE(AActor);
ACTION_RETURN_OBJECT(P_AimTarget(self));
}
//------------------------------------------------------------------------
//
// PROC P_SetupPsprites

View file

@ -8,6 +8,7 @@
#include "zscript/inventory/inventory.txt"
#include "zscript/inventory/inv_misc.txt"
#include "zscript/inventory/stateprovider.txt"
#include "zscript/inventory/weapons.txt"
#include "zscript/inventory/weaponpiece.txt"
#include "zscript/inventory/armor.txt"

View file

@ -373,7 +373,7 @@ class Actor : Thinker native
native void SetXYZ(vector3 newpos);
native Actor GetPointer(int aaptr);
native double BulletSlope(out FTranslatedLineTarget pLineTarget = null, int aimflags = 0);
native Actor AimTarget();
native bool CheckMissileSpawn(double maxdist);
native bool CheckPosition(Vector2 pos, bool actorsonly = false, FCheckPosition tm = null);
native bool TestMobjLocation();
@ -692,6 +692,12 @@ class Actor : Thinker native
return true;
}
Actor AimTarget()
{
FTranslatedLineTarget t;
BulletSlope(t, ALF_PORTALRESTRICT);
return t.linetarget;
}
native void A_Face(Actor faceto, double max_turn = 0, double max_pitch = 270, double ang_offset = 0, double pitch_offset = 0, int flags = 0, double z_ofs = 0);

View file

@ -194,25 +194,6 @@ class Inventory : Actor native
}
class StateProvider : Inventory native
{
action native state A_JumpIfNoAmmo(statelabel label);
action native void A_CustomPunch(int damage, bool norandom = false, int flags = CPF_USEAMMO, class<Actor> pufftype = "BulletPuff", double range = 0, double lifesteal = 0, int lifestealmax = 0, class<BasicArmorBonus> armorbonustype = "ArmorBonus", sound MeleeSound = 0, sound MissSound = "");
action native void A_FireBullets(double spread_xy, double spread_z, int numbullets, int damageperbullet, class<Actor> pufftype = "BulletPuff", int flags = 1, double range = 0, class<Actor> missile = null, double Spawnheight = 32, double Spawnofs_xy = 0);
action native void A_FireProjectile(class<Actor> missiletype, double angle = 0, bool useammo = true, double spawnofs_xy = 0, double spawnheight = 0, int flags = 0, double pitch = 0);
action native void A_RailAttack(int damage, int spawnofs_xy = 0, bool useammo = true, color color1 = 0, color color2 = 0, int flags = 0, double maxdiff = 0, class<Actor> pufftype = "BulletPuff", double spread_xy = 0, double spread_z = 0, double range = 0, int duration = 0, double sparsity = 1.0, double driftspeed = 1.0, class<Actor> spawnclass = "none", double spawnofs_z = 0, int spiraloffset = 270, int limit = 0);
action native void A_WeaponReady(int flags = 0);
action native void A_Lower();
action native void A_Raise();
action native void A_ReFire(statelabel flash = null);
action native void A_ClearReFire();
action native void A_CheckReload();
action native void A_GunFlash(statelabel flash = null, int flags = 0);
action native state A_CheckForReload(int counter, statelabel label, bool dontincrement = false);
action native void A_ResetReloadCounter();
}
class DehackedPickup : Inventory native
{
}
@ -221,11 +202,3 @@ class FakeInventory : Inventory native
{
native bool Respawnable;
}
class CustomInventory : StateProvider native
{
Default
{
DefaultStateUsage SUF_ACTOR|SUF_OVERLAY|SUF_ITEM;
}
}

View file

@ -0,0 +1,39 @@
class StateProvider : Inventory native
{
action native state A_JumpIfNoAmmo(statelabel label);
action native void A_CustomPunch(int damage, bool norandom = false, int flags = CPF_USEAMMO, class<Actor> pufftype = "BulletPuff", double range = 0, double lifesteal = 0, int lifestealmax = 0, class<BasicArmorBonus> armorbonustype = "ArmorBonus", sound MeleeSound = 0, sound MissSound = "");
action native void A_FireBullets(double spread_xy, double spread_z, int numbullets, int damageperbullet, class<Actor> pufftype = "BulletPuff", int flags = 1, double range = 0, class<Actor> missile = null, double Spawnheight = 32, double Spawnofs_xy = 0);
action native void A_FireProjectile(class<Actor> missiletype, double angle = 0, bool useammo = true, double spawnofs_xy = 0, double spawnheight = 0, int flags = 0, double pitch = 0);
action native void A_RailAttack(int damage, int spawnofs_xy = 0, bool useammo = true, color color1 = 0, color color2 = 0, int flags = 0, double maxdiff = 0, class<Actor> pufftype = "BulletPuff", double spread_xy = 0, double spread_z = 0, double range = 0, int duration = 0, double sparsity = 1.0, double driftspeed = 1.0, class<Actor> spawnclass = "none", double spawnofs_z = 0, int spiraloffset = 270, int limit = 0);
action native void A_WeaponReady(int flags = 0);
action native void A_ReFire(statelabel flash = null);
action native state A_CheckForReload(int counter, statelabel label, bool dontincrement = false);
action native void A_ResetReloadCounter();
}
class CustomInventory : StateProvider native
{
Default
{
DefaultStateUsage SUF_ACTOR|SUF_OVERLAY|SUF_ITEM;
}
//---------------------------------------------------------------------------
//
//
//---------------------------------------------------------------------------
action void A_ClearReFire()
{
if (NULL != player) player.refire = 0;
}
// This is only here, because these functions were originally exported on Inventory, despite only working for weapons, so this is here to satisfy some potential old mods having called it through CustomInventory.
deprecated action void A_GunFlash(statelabel flash = null, int flags = 0) {}
deprecated action void A_Lower() {}
deprecated action void A_Raise() {}
deprecated action void A_CheckReload() {}
}

View file

@ -85,6 +85,129 @@ class Weapon : StateProvider native
return s;
}
action void A_GunFlash(statelabel flashlabel = null, int flags = 0)
{
let player = player;
if (null == player || player.ReadyWeapon == null)
{
return;
}
if (!(flags & GFF_NOEXTCHANGE))
{
player.mo.PlayAttacking2 ();
}
if (flashlabel == null)
{
if (player.ReadyWeapon.bAltFire)
{
flashlabel = 'AltFlash';
}
if (flashlabel == null)
{
flashlabel = 'Flash';
}
}
player.SetPsprite(PSP_FLASH, player.ReadyWeapon.FindState(flashlabel));
}
//---------------------------------------------------------------------------
//
// PROC A_Lower
//
//---------------------------------------------------------------------------
action void A_Lower(int lowerspeed = 6)
{
let player = player;
if (null == player)
{
return;
}
if (null == player.ReadyWeapon)
{
player.BringUpWeapon();
return;
}
let psp = player.GetPSprite(PSP_WEAPON);
if (player.morphTics || player.cheats & CF_INSTANTWEAPSWITCH)
{
psp.y = WEAPONBOTTOM;
}
else
{
psp.y += lowerspeed;
}
if (psp.y < WEAPONBOTTOM)
{ // Not lowered all the way yet
return;
}
if (player.playerstate == PST_DEAD)
{ // Player is dead, so don't bring up a pending weapon
// Player is dead, so keep the weapon off screen
player.SetPsprite(PSP_FLASH, null);
psp.SetState(player.ReadyWeapon.FindState('DeadLowered'));
return;
}
// [RH] Clear the flash state. Only needed for Strife.
player.SetPsprite(PSP_FLASH, null);
player.BringUpWeapon ();
return;
}
//---------------------------------------------------------------------------
//
// PROC A_Raise
//
//---------------------------------------------------------------------------
action void A_Raise(int raisespeed = 6)
{
let player = player;
if (null == player)
{
return;
}
if (player.PendingWeapon != WP_NOCHANGE)
{
player.DropWeapon();
return;
}
if (player.ReadyWeapon == null)
{
return;
}
let psp = player.GetPSprite(PSP_WEAPON);
psp.y -= raisespeed;
if (psp.y > WEAPONTOP)
{ // Not raised all the way yet
return;
}
psp.y = WEAPONTOP;
psp.SetState(player.ReadyWeapon.GetReadyState());
return;
}
//---------------------------------------------------------------------------
//
// PROC A_CheckReload
//
// Present in Doom, but unused. Also present in Strife, and actually used.
//
//---------------------------------------------------------------------------
action void A_CheckReload()
{
let player = self.player;
if (player != NULL)
{
player.ReadyWeapon.CheckAmmo (player.ReadyWeapon.bAltFire ? Weapon.AltFire : Weapon.PrimaryFire, true);
}
}
native action void A_ZoomFactor(double scale = 1, int flags = 0);
native action void A_SetCrosshair(int xhair);
const ZOOM_INSTANT = 1;

View file

@ -308,5 +308,7 @@ userinfo_t userinfo;
native void SetLogNumber (int text);
native void SetLogText (String text);
native String GetUserName();
native void DropWeapon();
native void BringUpWeapon();
}