From a5f9eb5be1f885346d1fa00a8edb1b6d0489b4b6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 11 Nov 2016 22:14:29 +0100 Subject: [PATCH] - Scriptified Heretic's knight. --- src/CMakeLists.txt | 1 - src/g_heretic/a_hereticmisc.cpp | 1 - src/g_heretic/a_knight.cpp | 70 ------------------------ src/p_mobj.cpp | 9 +++ src/scripting/codegeneration/codegen.cpp | 2 +- wadsrc/static/zscript/actor.txt | 1 + wadsrc/static/zscript/heretic/knight.txt | 49 +++++++++++++++-- 7 files changed, 55 insertions(+), 78 deletions(-) delete mode 100644 src/g_heretic/a_knight.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8b75d7b62a..9f5b0346c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -857,7 +857,6 @@ set( NOT_COMPILED_SOURCE_FILES g_heretic/a_hereticartifacts.cpp g_heretic/a_hereticweaps.cpp g_heretic/a_ironlich.cpp - g_heretic/a_knight.cpp g_heretic/a_wizard.cpp g_hexen/a_bats.cpp g_hexen/a_bishop.cpp diff --git a/src/g_heretic/a_hereticmisc.cpp b/src/g_heretic/a_hereticmisc.cpp index 2ea39a4bcb..c6192b8e23 100644 --- a/src/g_heretic/a_hereticmisc.cpp +++ b/src/g_heretic/a_hereticmisc.cpp @@ -26,7 +26,6 @@ #include "a_hereticartifacts.cpp" #include "a_hereticweaps.cpp" #include "a_ironlich.cpp" -#include "a_knight.cpp" #include "a_wizard.cpp" diff --git a/src/g_heretic/a_knight.cpp b/src/g_heretic/a_knight.cpp deleted file mode 100644 index a3125f77d4..0000000000 --- a/src/g_heretic/a_knight.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* -#include "actor.h" -#include "info.h" -#include "m_random.h" -#include "s_sound.h" -#include "p_local.h" -#include "a_action.h" -#include "a_sharedglobal.h" -#include "gstrings.h" -#include "vm.h" -*/ - -static FRandom pr_dripblood ("DripBlood"); -static FRandom pr_knightatk ("KnightAttack"); - -//---------------------------------------------------------------------------- -// -// PROC A_DripBlood -// -//---------------------------------------------------------------------------- - -DEFINE_ACTION_FUNCTION(AActor, A_DripBlood) -{ - PARAM_SELF_PROLOGUE(AActor); - - AActor *mo; - - double xo = pr_dripblood.Random2() / 32.; - double yo = pr_dripblood.Random2() / 32.; - mo = Spawn ("Blood", self->Vec3Offset(xo, yo, 0.), ALLOW_REPLACE); - mo->Vel.X = pr_dripblood.Random2 () / 64.; - mo->Vel.Y = pr_dripblood.Random2() / 64.; - mo->Gravity = 1./8; - return 0; -} - -//---------------------------------------------------------------------------- -// -// PROC A_KnightAttack -// -//---------------------------------------------------------------------------- - -DEFINE_ACTION_FUNCTION(AActor, A_KnightAttack) -{ - PARAM_SELF_PROLOGUE(AActor); - - if (!self->target) - { - return 0; - } - if (self->CheckMeleeRange ()) - { - int damage = pr_knightatk.HitDice (3); - int newdam = P_DamageMobj (self->target, self, self, damage, NAME_Melee); - P_TraceBleed (newdam > 0 ? newdam : damage, self->target, self); - S_Sound (self, CHAN_BODY, "hknight/melee", 1, ATTN_NORM); - return 0; - } - // Throw axe - S_Sound (self, CHAN_BODY, self->AttackSound, 1, ATTN_NORM); - if (self->flags & MF_SHADOW || pr_knightatk () < 40) - { // Red axe - P_SpawnMissileZ (self, self->Z() + 36, self->target, PClass::FindActor("RedAxe")); - return 0; - } - // Green axe - P_SpawnMissileZ (self, self->Z() + 36, self->target, PClass::FindActor("KnightAxe")); - return 0; -} - diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 3205067b83..400fe8c746 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -6077,6 +6077,15 @@ AActor *P_SpawnMissileZ (AActor *source, double z, AActor *dest, PClassActor *ty return P_SpawnMissileXYZ (source->PosAtZ(z), source, dest, type); } +DEFINE_ACTION_FUNCTION(AActor, SpawnMissileZ) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT(z); + PARAM_OBJECT(dest, AActor); + PARAM_CLASS(type, AActor); + ACTION_RETURN_OBJECT(P_SpawnMissileZ(self, z, dest, type)); +} + AActor *P_SpawnMissileXYZ (DVector3 pos, AActor *source, AActor *dest, PClassActor *type, bool checkspawn, AActor *owner) { if (source == NULL) diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index dfe02404b5..5e212dfe3c 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -7000,7 +7000,7 @@ FxExpression *FxSequence::Resolve(FCompileContext &ctx) { fail = true; } - if (Expressions[i]->ValueType == TypeError) + else if (Expressions[i]->ValueType == TypeError) { ScriptPosition.Message(MSG_ERROR, "Invalid statement"); fail = true; diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index c70ab28a19..0baac6bf0a 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -63,6 +63,7 @@ class Actor : Thinker native native Actor GetPointer(int aaptr); native static Actor Spawn(class type, vector3 pos = (0,0,0), int replace = NO_REPLACE); native Actor SpawnMissile(Actor dest, class type, Actor owner = null); + native Actor SpawnMissileZ (double z, Actor dest, class type); native Actor OldSpawnMissile(Actor dest, class type, Actor owner = null); native Actor SpawnPuff(class pufftype, vector3 pos, float hitdir, float particledir, int updown, int flags = 0, Actor vict = null); diff --git a/wadsrc/static/zscript/heretic/knight.txt b/wadsrc/static/zscript/heretic/knight.txt index 1eb341859b..01b7252c60 100644 --- a/wadsrc/static/zscript/heretic/knight.txt +++ b/wadsrc/static/zscript/heretic/knight.txt @@ -22,8 +22,6 @@ class Knight : Actor HitObituary "$OB_BONEKNIGHTHIT"; DropItem "CrossbowAmmo", 84, 5; } - - native void A_KnightAttack (); States { @@ -56,6 +54,34 @@ class Knight : Actor Stop; } + //---------------------------------------------------------------------------- + // + // PROC A_KnightAttack + // + //---------------------------------------------------------------------------- + + void A_KnightAttack () + { + if (!target) return; + if (CheckMeleeRange ()) + { + int damage = random[KnightAttack](1, 8) * 3; + int newdam = target.DamageMobj (self, self, damage, 'Melee'); + target.TraceBleed (newdam > 0 ? newdam : damage, self); + A_PlaySound ("hknight/melee", CHAN_BODY); + return; + } + // Throw axe + A_PlaySound (AttackSound, CHAN_BODY); + if (self.bShadow || random[KnightAttack]() < 40) + { // Red axe + SpawnMissileZ (pos.Z + 36, target, "RedAxe"); + } + else + { // Green axe + SpawnMissileZ (pos.Z + 36, target, "KnightAxe"); + } + } } @@ -116,8 +142,6 @@ class RedAxe : KnightAxe Damage 7; } - native void A_DripBlood (); - States { Spawn: @@ -127,5 +151,20 @@ class RedAxe : KnightAxe RAXE CDE 6 BRIGHT; Stop; } + + //---------------------------------------------------------------------------- + // + // PROC A_DripBlood + // + //---------------------------------------------------------------------------- + + void A_DripBlood () + { + double xo = random2[DripBlood]() / 32.0; + double yo = random2[DripBlood]() / 32.0; + Actor mo = Spawn ("Blood", Vec3Offset(xo, yo, 0.), ALLOW_REPLACE); + mo.Vel.X = random2[DripBlood]() / 64.0; + mo.Vel.Y = random2[DripBlood]() / 64.0; + mo.Gravity = 1./8; + } } -