From 4c1b3f81abc5690a2e30c8b288a89f134f0eab2e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 24 Nov 2018 15:12:30 +0100 Subject: [PATCH] - scriptified A_RailAttack. --- src/p_actionfunctions.cpp | 71 ------------------- src/p_map.cpp | 28 ++++++++ src/scripting/thingdef_data.cpp | 5 ++ wadsrc/static/zscript/actor.txt | 1 + wadsrc/static/zscript/base.txt | 21 ++++++ .../zscript/inventory/stateprovider.txt | 55 +++++++++++++- 6 files changed, 107 insertions(+), 74 deletions(-) diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index c7cd2a199..e1b31a0ea 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -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 diff --git a/src/p_map.cpp b/src/p_map.cpp index d1670dc37..33916fdb2 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -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 diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 019c10b3a..f5d10a417 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -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) diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 89ee2ed50..e4eff57aa 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -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); diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index fff6f9ecc..0bf5cc175 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -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 puff; + native double angleoffset; + native double pitchoffset; + native double distance; + native int duration; + native double sparsity; + native double drift; + native Class spawnclass; + native int SpiralOffset; + native int limit; +}; // [RH] Shoot a railgun + diff --git a/wadsrc/static/zscript/inventory/stateprovider.txt b/wadsrc/static/zscript/inventory/stateprovider.txt index 25c3ad1f3..c9d74a27b 100644 --- a/wadsrc/static/zscript/inventory/stateprovider.txt +++ b/wadsrc/static/zscript/inventory/stateprovider.txt @@ -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 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 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 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 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() {