From 34fc6323a471c2f46bd47bffdab39ed27fe997c8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 12 Nov 2016 09:33:43 +0100 Subject: [PATCH] - scriptified Hexen's bats. - removed AMinotaurFriend::IsOkayToAttack. The condition it checks (i.e. friendliness with player) is already covered by the base version of this function so this is quite redundant. - removed a few 'virtual' qualifiers from functions that never get overridden. --- src/actor.h | 8 +-- src/g_hexen/a_bats.cpp | 98 ---------------------------- src/g_hexen/a_hexenmisc.cpp | 1 - src/g_raven/a_minotaur.cpp | 6 -- src/g_raven/ravenshared.h | 1 - src/p_mobj.cpp | 8 +++ src/virtual.h | 10 +-- wadsrc/static/zscript/actor.txt | 7 ++ wadsrc/static/zscript/hexen/bats.txt | 82 +++++++++++++++++++++-- 9 files changed, 98 insertions(+), 123 deletions(-) delete mode 100644 src/g_hexen/a_bats.cpp diff --git a/src/actor.h b/src/actor.h index 833cd2c0a..122839850 100644 --- a/src/actor.h +++ b/src/actor.h @@ -614,7 +614,7 @@ public: virtual void BeginPlay(); // Called immediately after the actor is created virtual void PostBeginPlay(); // Called immediately before the actor's first tick - virtual void LevelSpawned(); // Called after BeginPlay if this actor was spawned by the world + void LevelSpawned(); // Called after BeginPlay if this actor was spawned by the world virtual void HandleSpawnFlags(); // Translates SpawnFlags into in-game flags. virtual void MarkPrecacheSounds() const; // Marks sounds used by this actor for precaching. @@ -733,7 +733,7 @@ public: void ObtainInventory (AActor *other); // Die. Now. - virtual bool Massacre (); + bool Massacre (); // Transforms the actor into a finely-ground paste virtual bool Grind(bool items); @@ -958,7 +958,7 @@ public: { SetOrigin(Pos() + vel, true); } - virtual void SetOrigin(double x, double y, double z, bool moving); + void SetOrigin(double x, double y, double z, bool moving); void SetOrigin(const DVector3 & npos, bool moving) { SetOrigin(npos.X, npos.Y, npos.Z, moving); @@ -970,7 +970,7 @@ public: bool IsInsideVisibleAngles() const; // Calculate amount of missile damage - virtual int GetMissileDamage(int mask, int add); + int GetMissileDamage(int mask, int add); bool CanSeek(AActor *target) const; diff --git a/src/g_hexen/a_bats.cpp b/src/g_hexen/a_bats.cpp deleted file mode 100644 index 02fc6111e..000000000 --- a/src/g_hexen/a_bats.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* -#include "actor.h" -#include "info.h" -#include "m_random.h" -#include "p_local.h" -#include "s_sound.h" -#include "vm.h" -*/ - -static FRandom pr_batspawn ("BatSpawn"); -static FRandom pr_batmove ("BatMove"); - -//=========================================================================== -// Bat Spawner Variables -// special1 frequency counter -// special2 -// args[0] frequency of spawn (1=fastest, 10=slowest) -// args[1] spread angle (0..255) -// args[2] -// args[3] duration of bats (in octics) -// args[4] turn amount per move (in degrees) -// -// Bat Variables -// special2 lifetime counter -// args[4] turn amount per move (in degrees) -//=========================================================================== - -DEFINE_ACTION_FUNCTION(AActor, A_BatSpawnInit) -{ - PARAM_SELF_PROLOGUE(AActor); - - self->special1 = 0; // Frequency count - return 0; -} - -DEFINE_ACTION_FUNCTION(AActor, A_BatSpawn) -{ - PARAM_SELF_PROLOGUE(AActor); - - AActor *mo; - int delta; - DAngle angle; - - // Countdown until next spawn - if (self->special1-- > 0) return 0; - self->special1 = self->args[0]; // Reset frequency count - - delta = self->args[1]; - if (delta==0) delta=1; - - angle = self->Angles.Yaw + (((pr_batspawn() % delta) - (delta >> 1)) * (360 / 256.)); - - mo = P_SpawnMissileAngle (self, PClass::FindActor("Bat"), angle, 0); - if (mo) - { - mo->args[0] = pr_batspawn()&63; // floatbob index - mo->args[4] = self->args[4]; // turn degrees - mo->special2 = self->args[3]<<3; // Set lifetime - mo->target = self; - } - return 0; -} - - -DEFINE_ACTION_FUNCTION(AActor, A_BatMove) -{ - PARAM_SELF_PROLOGUE(AActor); - - DAngle newangle; - - if (self->special2 < 0) - { - self->SetState (self->FindState(NAME_Death)); - } - self->special2 -= 2; // Called every 2 tics - - if (pr_batmove()<128) - { - newangle = self->Angles.Yaw + self->args[4]; - } - else - { - newangle = self->Angles.Yaw - self->args[4]; - } - - // Adjust velocity vector to new direction - self->VelFromAngle(self->Speed, newangle); - - if (pr_batmove()<15) - { - S_Sound (self, CHAN_VOICE, "BatScream", 1, ATTN_IDLE); - } - - // Handle Z movement - self->SetZ(self->target->Z() + 2 * BobSin(self->args[0])); - self->args[0] = (self->args[0]+3)&63; - return 0; -} diff --git a/src/g_hexen/a_hexenmisc.cpp b/src/g_hexen/a_hexenmisc.cpp index 2c91f37b2..da17d37be 100644 --- a/src/g_hexen/a_hexenmisc.cpp +++ b/src/g_hexen/a_hexenmisc.cpp @@ -27,7 +27,6 @@ #include "vm.h" // Include all the Hexen stuff here to reduce compile time -#include "a_bats.cpp" #include "a_bishop.cpp" #include "a_blastradius.cpp" #include "a_boostarmor.cpp" diff --git a/src/g_raven/a_minotaur.cpp b/src/g_raven/a_minotaur.cpp index 36946ba87..dd4e4a8b8 100644 --- a/src/g_raven/a_minotaur.cpp +++ b/src/g_raven/a_minotaur.cpp @@ -117,12 +117,6 @@ void AMinotaurFriend::Die (AActor *source, AActor *inflictor, int dmgflags) } } -bool AMinotaurFriend::OkayToSwitchTarget (AActor *other) -{ - if (other == tracer) return false; // Do not target the master - return Super::OkayToSwitchTarget (other); -} - // Action functions for the minotaur ---------------------------------------- //---------------------------------------------------------------------------- diff --git a/src/g_raven/ravenshared.h b/src/g_raven/ravenshared.h index 81824a957..3c6019ae7 100644 --- a/src/g_raven/ravenshared.h +++ b/src/g_raven/ravenshared.h @@ -21,7 +21,6 @@ public: int StartTime; void Die (AActor *source, AActor *inflictor, int dmgflags); - bool OkayToSwitchTarget (AActor *other); void BeginPlay (); void Serialize(FSerializer &arc); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 65fd1ad34..83e4d0282 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -6885,6 +6885,14 @@ DEFINE_ACTION_FUNCTION(AActor, AddZ) return 0; } +DEFINE_ACTION_FUNCTION(AActor, SetZ) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(z); + self->SetZ(z); + return 0; +} + DEFINE_ACTION_FUNCTION(AActor, SetDamage) { PARAM_SELF_PROLOGUE(AActor); diff --git a/src/virtual.h b/src/virtual.h index 188519f71..d3a2bfa3a 100644 --- a/src/virtual.h +++ b/src/virtual.h @@ -35,7 +35,6 @@ VMEXPORTED_NATIVES_START VMEXPORTED_NATIVES_FUNC(Destroy) VMEXPORTED_NATIVES_FUNC(Tick) VMEXPORTED_NATIVES_FUNC(PostBeginPlay) - VMEXPORTED_NATIVES_FUNC(DropInventory) VMEXPORTED_NATIVES_END template @@ -103,11 +102,6 @@ public: { ExportedNatives::Get()->template PostBeginPlay(this); } - - AInventory *DropInventory(AInventory *item) - { - return ExportedNatives::Get()->template DropInventory(this, item); - } }; template @@ -134,7 +128,7 @@ VMEXPORT_NATIVES_START(DThinker, DObject) VMEXPORT_NATIVES_FUNC(PostBeginPlay) VMEXPORT_NATIVES_END(DThinker) +/* VMEXPORT_NATIVES_START(AActor, DThinker) - VMEXPORT_NATIVES_FUNC(DropInventory) VMEXPORT_NATIVES_END(AActor) - +*/ \ No newline at end of file diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index d9fd23a46..2fd6c4e03 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -53,6 +53,12 @@ class Actor : Thinker native { return GetPointer(ptr_select1) == GetPointer(ptr_select2); } + + static double BobSin(double fb) + { + return sin(fb * (180./32)) * 8; + } + native static readonly GetDefaultByType(class cls); native static float deltaangle(float ang1, float ang2); @@ -84,6 +90,7 @@ class Actor : Thinker native native bool CanSeek(Actor target); native double AngleTo(Actor target, bool absolute = false); native void AddZ(float zadd); + native void SetZ(float z); native vector3 Vec3Offset(float x, float y, float z, bool absolute = false); native vector3 Vec3Angle(float length, float angle, float z = 0, bool absolute = false); native vector3 Vec2OffsetZ(float x, float y, float atz, bool absolute = false); diff --git a/wadsrc/static/zscript/hexen/bats.txt b/wadsrc/static/zscript/hexen/bats.txt index 1e6ee459f..a530da176 100644 --- a/wadsrc/static/zscript/hexen/bats.txt +++ b/wadsrc/static/zscript/hexen/bats.txt @@ -9,9 +9,6 @@ class BatSpawner : SwitchableDecoration RenderStyle "None"; } - native void A_BatSpawnInit(); - native void A_BatSpawn(); - States { Spawn: @@ -24,6 +21,48 @@ class BatSpawner : SwitchableDecoration TNT1 A -1; Stop; } + + //=========================================================================== + // Bat Spawner Variables + // special1 frequency counter + // special2 + // args[0] frequency of spawn (1=fastest, 10=slowest) + // args[1] spread angle (0..255) + // args[2] + // args[3] duration of bats (in octics) + // args[4] turn amount per move (in degrees) + // + // Bat Variables + // special2 lifetime counter + // args[4] turn amount per move (in degrees) + //=========================================================================== + + void A_BatSpawnInit() + { + special1 = 0; // Frequency count + } + + void A_BatSpawn() + { + // Countdown until next spawn + if (special1-- > 0) return; + special1 = args[0]; // Reset frequency count + + int delta = args[1]; + if (delta == 0) delta = 1; + + double ang = Angle + (((random[BatSpawn]() % delta) - (delta >> 1)) * (360 / 256.)); + + Actor mo = SpawnMissileAngle ("Bat", ang, 0); + if (mo) + { + mo.args[0] = random[BatSpawn]() & 63; // floatbob index + mo.args[4] = args[4]; // turn degrees + mo.special2 = args[3] << 3; // Set lifetime + mo.target = self; + } + } + } // Bat ---------------------------------------------------------------------- @@ -39,8 +78,6 @@ class Bat : Actor +NOTELEPORT +CANPASS } - native void A_BatMove(); - States { Spawn: @@ -50,4 +87,39 @@ class Bat : Actor ABAT A 2; Stop; } + + void A_BatMove() + { + if (special2 < 0) + { + SetState ("Death"); + } + special2 -= 2; // Called every 2 tics + + double newangle; + if (random[BatMove]() < 128) + { + newangle = Angle + args[4]; + } + else + { + newangle = Angle - args[4]; + } + + // Adjust velocity vector to new direction + VelFromAngle(Speed, newangle); + + if (random[BatMove]() < 15) + { + A_PlaySound ("BatScream", CHAN_VOICE, 1, false, ATTN_IDLE); + } + + // Handle Z movement + SetZ(target.pos.Z + 2 * BobSin(args[0])); + args[0] = (args[0] + 3) & 63; + } } + + + +