- scriptified A_RailAttack.

This commit is contained in:
Christoph Oelckers 2018-11-24 15:12:30 +01:00
parent 5c130737c4
commit 4c1b3f81ab
6 changed files with 107 additions and 74 deletions

View file

@ -1626,77 +1626,6 @@ DEFINE_ACTION_FUNCTION(AStateProvider, A_JumpIfNoAmmo)
//==========================================================================
//
// customizable railgun attack function
//
//==========================================================================
DEFINE_ACTION_FUNCTION(AStateProvider, A_RailAttack)
{
PARAM_ACTION_PROLOGUE(AStateProvider);
PARAM_INT (damage);
PARAM_INT (spawnofs_xy);
PARAM_BOOL (useammo);
PARAM_COLOR (color1);
PARAM_COLOR (color2);
PARAM_INT (flags);
PARAM_FLOAT (maxdiff);
PARAM_CLASS (pufftype, AActor);
PARAM_ANGLE (spread_xy);
PARAM_ANGLE (spread_z);
PARAM_FLOAT (range) ;
PARAM_INT (duration);
PARAM_FLOAT (sparsity);
PARAM_FLOAT (driftspeed);
PARAM_CLASS (spawnclass, AActor);
PARAM_FLOAT (spawnofs_z);
PARAM_INT (SpiralOffset);
PARAM_INT (limit);
if (range == 0) range = 8192;
if (sparsity == 0) sparsity=1.0;
if (self->player == NULL)
return 0;
AWeapon *weapon = self->player->ReadyWeapon;
// only use ammo when actually hitting something!
if (useammo && weapon != NULL && ACTION_CALL_FROM_PSPRITE())
{
if (!weapon->DepleteAmmo(weapon->bAltFire, true))
return 0; // out of ammo
}
if (!(flags & RAF_EXPLICITANGLE))
{
spread_xy = spread_xy * pr_crailgun.Random2() / 255;
spread_z = spread_z * pr_crailgun.Random2() / 255;
}
FRailParams p;
p.source = self;
p.damage = damage;
p.offset_xy = spawnofs_xy;
p.offset_z = spawnofs_z;
p.color1 = color1;
p.color2 = color2;
p.maxdiff = maxdiff;
p.flags = flags;
p.puff = pufftype;
p.angleoffset = spread_xy;
p.pitchoffset = spread_z;
p.distance = range;
p.duration = duration;
p.sparsity = sparsity;
p.drift = driftspeed;
p.spawnclass = spawnclass;
p.SpiralOffset = SpiralOffset;
p.limit = limit;
P_RailAttack(&p);
return 0;
}
//==========================================================================
//
// also for monsters

View file

@ -156,6 +156,25 @@ DEFINE_FIELD_X(FCheckPosition, FCheckPosition, portalstep);
DEFINE_FIELD_X(FCheckPosition, FCheckPosition, portalgroup);
DEFINE_FIELD_X(FCheckPosition, FCheckPosition, PushTime);
DEFINE_FIELD_X(FRailParams, FRailParams, source);
DEFINE_FIELD_X(FRailParams, FRailParams, damage);
DEFINE_FIELD_X(FRailParams, FRailParams, offset_xy);
DEFINE_FIELD_X(FRailParams, FRailParams, offset_z);
DEFINE_FIELD_X(FRailParams, FRailParams, color1);
DEFINE_FIELD_X(FRailParams, FRailParams, color2);
DEFINE_FIELD_X(FRailParams, FRailParams, maxdiff);
DEFINE_FIELD_X(FRailParams, FRailParams, flags);
DEFINE_FIELD_X(FRailParams, FRailParams, puff);
DEFINE_FIELD_X(FRailParams, FRailParams, angleoffset);
DEFINE_FIELD_X(FRailParams, FRailParams, pitchoffset);
DEFINE_FIELD_X(FRailParams, FRailParams, distance);
DEFINE_FIELD_X(FRailParams, FRailParams, duration);
DEFINE_FIELD_X(FRailParams, FRailParams, sparsity);
DEFINE_FIELD_X(FRailParams, FRailParams, drift);
DEFINE_FIELD_X(FRailParams, FRailParams, spawnclass);
DEFINE_FIELD_X(FRailParams, FRailParams, SpiralOffset);
DEFINE_FIELD_X(FRailParams, FRailParams, limit);
//==========================================================================
//
// CanCollideWith
@ -5603,6 +5622,15 @@ void P_RailAttack(FRailParams *p)
P_DrawRailTrail(source, rail_data.PortalHits, p->color1, p->color2, p->maxdiff, p->flags, p->spawnclass, angle, p->duration, p->sparsity, p->drift, p->SpiralOffset, pitch);
}
DEFINE_ACTION_FUNCTION(AActor, RailAttack)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_POINTER(p, FRailParams);
p->source = self;
P_RailAttack(p);
return 0;
}
//==========================================================================
//
// [RH] P_AimCamera

View file

@ -948,6 +948,11 @@ void InitThingdef()
fcp->Size = sizeof(FCheckPosition);
fcp->Align = alignof(FCheckPosition);
//This must also have its size set.
auto frp = NewStruct("FRailParams", nullptr);
frp->Size = sizeof(FRailParams);
frp->Align = alignof(FRailParams);
FieldTable.Clear();
if (FieldTable.Size() == 0)

View file

@ -592,6 +592,7 @@ class Actor : Thinker native
native bool IsZeroDamage();
native void ClearInterpolation();
native clearscope Vector3 PosRelative(sector sec) const;
native void RailAttack(FRailParams p);
native void HandleSpawnFlags();
native void ExplodeMissile(line lin = null, Actor target = null, bool onsky = false);

View file

@ -958,3 +958,24 @@ struct Shader native
native clearscope static void SetUniform3f(PlayerInfo player, string shaderName, string uniformName, vector3 value);
native clearscope static void SetUniform1i(PlayerInfo player, string shaderName, string uniformName, int value);
}
struct FRailParams
{
native int damage;
native double offset_xy;
native double offset_z;
native int color1, color2;
native double maxdiff;
native int flags;
native Class<Actor> puff;
native double angleoffset;
native double pitchoffset;
native double distance;
native int duration;
native double sparsity;
native double drift;
native Class<Actor> spawnclass;
native int SpiralOffset;
native int limit;
}; // [RH] Shoot a railgun

View file

@ -2,8 +2,9 @@
class StateProvider : Inventory native
{
action native state A_JumpIfNoAmmo(statelabel label);
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 state A_CheckForReload(int counter, statelabel label, bool dontincrement = false);
action native void A_ResetReloadCounter();
//---------------------------------------------------------------------------
//
@ -265,6 +266,55 @@ class StateProvider : Inventory native
}
}
//==========================================================================
//
// customizable railgun attack function
//
//==========================================================================
action 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)
{
if (range == 0) range = 8192;
if (sparsity == 0) sparsity=1.0;
let player = self.player;
if (!player) return;
let weapon = player.ReadyWeapon;
if (useammo && weapon != NULL && stateinfo != null && stateinfo.mStateType == STATE_Psprite)
{
if (!weapon.DepleteAmmo(weapon.bAltFire, true))
return; // out of ammo
}
if (!(flags & RGF_EXPLICITANGLE))
{
spread_xy = spread_xy * Random2[crailgun]() / 255.;
spread_z = spread_z * Random2[crailgun]() / 255.;
}
FRailParams p;
p.damage = damage;
p.offset_xy = spawnofs_xy;
p.offset_z = spawnofs_z;
p.color1 = color1;
p.color2 = color2;
p.maxdiff = maxdiff;
p.flags = flags;
p.puff = pufftype;
p.angleoffset = spread_xy;
p.pitchoffset = spread_z;
p.distance = range;
p.duration = duration;
p.sparsity = sparsity;
p.drift = driftspeed;
p.spawnclass = spawnclass;
p.SpiralOffset = SpiralOffset;
p.limit = limit;
self.RailAttack(p);
}
//---------------------------------------------------------------------------
@ -304,8 +354,7 @@ class StateProvider : Inventory native
}
}
action native state A_CheckForReload(int counter, statelabel label, bool dontincrement = false);
action native void A_ResetReloadCounter();
action void A_ClearReFire()
{