From 9f8a5dae214b03e73aa51c80c59760c202c293be Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 23 Oct 2016 17:15:24 +0200 Subject: [PATCH] - scriptified A_BruisAttack. - removed 'self' as a dedicated token. Internally this gets handled as a normal but implicitly named variable so the token just gets in the way of proper processing. - removed P_ prefix from SpawnMissile export. - fixed a crash with misnamed function exports. --- src/g_doom/a_bruiser.cpp | 23 ------------------ src/g_doom/a_doommisc.cpp | 1 - src/p_enemy.cpp | 6 +++++ src/p_interaction.cpp | 12 ++++++++++ src/p_map.cpp | 10 ++++++++ src/p_mobj.cpp | 2 +- src/sc_man_scanner.re | 1 - src/sc_man_tokens.h | 1 - src/scripting/zscript/zcc-parse.lemon | 15 +----------- src/scripting/zscript/zcc_compile.cpp | 5 +++- src/scripting/zscript/zcc_exprlist.h | 1 - src/scripting/zscript/zcc_parser.cpp | 1 - src/scripting/zscript/zcc_parser.h | 1 - wadsrc/static/zscript/actor.txt | 8 +++---- wadsrc/static/zscript/doom/arachnotron.txt | 2 +- wadsrc/static/zscript/doom/bruiser.txt | 27 ++++++++++++++++++++++ 16 files changed, 66 insertions(+), 50 deletions(-) delete mode 100644 src/g_doom/a_bruiser.cpp diff --git a/src/g_doom/a_bruiser.cpp b/src/g_doom/a_bruiser.cpp deleted file mode 100644 index 1d2be64f03..0000000000 --- a/src/g_doom/a_bruiser.cpp +++ /dev/null @@ -1,23 +0,0 @@ -static FRandom pr_bruisattack ("BruisAttack"); - - -DEFINE_ACTION_FUNCTION(AActor, A_BruisAttack) -{ - PARAM_SELF_PROLOGUE(AActor); - - if (!self->target) - return 0; - - if (self->CheckMeleeRange ()) - { - int damage = (pr_bruisattack()%8+1)*10; - S_Sound (self, CHAN_WEAPON, "baron/melee", 1, ATTN_NORM); - int newdam = P_DamageMobj (self->target, self, self, damage, NAME_Melee); - P_TraceBleed (newdam > 0 ? newdam : damage, self->target, self); - return 0; - } - - // launch a missile - P_SpawnMissile (self, self->target, PClass::FindActor("BaronBall")); - return 0; -} diff --git a/src/g_doom/a_doommisc.cpp b/src/g_doom/a_doommisc.cpp index 81e5a253aa..2115e70e1a 100644 --- a/src/g_doom/a_doommisc.cpp +++ b/src/g_doom/a_doommisc.cpp @@ -24,7 +24,6 @@ // Include all the other Doom stuff here to reduce compile time #include "a_archvile.cpp" #include "a_bossbrain.cpp" -#include "a_bruiser.cpp" #include "a_cacodemon.cpp" #include "a_cyberdemon.cpp" #include "a_demon.cpp" diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index 14ea2b7c1e..0c2cb8e28b 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -310,6 +310,12 @@ bool AActor::CheckMeleeRange () return true; } +DEFINE_ACTION_FUNCTION(AActor, CheckMeleeRange) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_INT(self->CheckMeleeRange()); +} + //---------------------------------------------------------------------------- // // FUNC P_CheckMeleeRange2 diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index 261cfb8f3d..f3d02428d1 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -1555,6 +1555,18 @@ dopain: return damage; } +DEFINE_ACTION_FUNCTION(AActor, DamageMobj) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT(inflictor, AActor); + PARAM_OBJECT(source, AActor); + PARAM_INT(damage); + PARAM_NAME(mod); + PARAM_INT_OPT(flags) { flags = 0; } + PARAM_FLOAT_OPT(angle) { angle = 0; } + ACTION_RETURN_INT(P_DamageMobj(self, inflictor, source, damage, mod, flags, angle)); +} + void P_PoisonMobj (AActor *target, AActor *inflictor, AActor *source, int damage, int duration, int period, FName type) { // Check for invulnerability. diff --git a/src/p_map.cpp b/src/p_map.cpp index 5cc9bdf72c..849f8dd241 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -4574,6 +4574,16 @@ void P_TraceBleed(int damage, AActor *target, AActor *missile) P_TraceBleed(damage, target->PosPlusZ(target->Height/2), target, missile->AngleTo(target), pitch); } +DEFINE_ACTION_FUNCTION(AActor, TraceBleed) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_INT(damage); + PARAM_OBJECT(missile, AActor); + + P_TraceBleed(damage, self, missile); + return 0; +} + //========================================================================== // // diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index d89a89576c..8e630b77a5 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -5824,7 +5824,7 @@ AActor *P_SpawnMissile (AActor *source, AActor *dest, PClassActor *type, AActor return P_SpawnMissileXYZ (source->PosPlusZ(32 + source->GetBobOffset()), source, dest, type, true, owner); } -DEFINE_ACTION_FUNCTION(AActor, P_SpawnMissile) +DEFINE_ACTION_FUNCTION(AActor, SpawnMissile) { PARAM_SELF_PROLOGUE(AActor); PARAM_OBJECT(dest, AActor); diff --git a/src/sc_man_scanner.re b/src/sc_man_scanner.re index cc9968ae3f..8fbb28ef55 100644 --- a/src/sc_man_scanner.re +++ b/src/sc_man_scanner.re @@ -169,7 +169,6 @@ std2: 'virtual' { RET(TK_Virtual); } 'super' { RET(TK_Super); } 'global' { RET(TK_Global); } - 'self' { RET(TK_Self); } 'stop' { RET(TK_Stop); } 'null' { RET(TK_Null); } diff --git a/src/sc_man_tokens.h b/src/sc_man_tokens.h index 19d3313019..7d9f81e9b9 100644 --- a/src/sc_man_tokens.h +++ b/src/sc_man_tokens.h @@ -108,7 +108,6 @@ xx(TK_Virtual, "'virtual'") xx(TK_Super, "'super'") xx(TK_Null, "'null'") xx(TK_Global, "'global'") -xx(TK_Self, "'self'") xx(TK_Stop, "'stop'") xx(TK_Include, "'include'") diff --git a/src/scripting/zscript/zcc-parse.lemon b/src/scripting/zscript/zcc-parse.lemon index fc34fd2d76..0cf061bef0 100644 --- a/src/scripting/zscript/zcc-parse.lemon +++ b/src/scripting/zscript/zcc-parse.lemon @@ -977,13 +977,6 @@ primary(X) ::= IDENTIFIER(A). expr->Type = NULL; X = expr; } -primary(X) ::= NULL(T). -{ - NEW_AST_NODE(Expression, expr, T); - expr->Operation = PEX_Null; - expr->Type = NULL; - X = expr; -} primary(X) ::= SUPER(T). { NEW_AST_NODE(Expression, expr, T); @@ -992,13 +985,7 @@ primary(X) ::= SUPER(T). X = expr; } primary(X) ::= constant(A). { X = A; /*X-overwrites-A*/ } -primary(X) ::= SELF(T). -{ - NEW_AST_NODE(Expression, expr, T); - expr->Operation = PEX_Self; - expr->Type = NULL; - X = expr; -} + primary(X) ::= LPAREN expr(A) RPAREN. { X = A; /*X-overwrites-A*/ diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 723e82c8d5..274778dfee 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2001,7 +2001,10 @@ void ZCCCompiler::InitFunctions() { Error(f, "The function '%s' has not been exported from the executable.", FName(f->Name).GetChars()); } - (*afd->VMPointer)->ImplicitArgs = BYTE(implicitargs); + else + { + (*afd->VMPointer)->ImplicitArgs = BYTE(implicitargs); + } } SetImplicitArgs(&args, &argflags, &argnames, c->Type(), varflags); auto p = f->Params; diff --git a/src/scripting/zscript/zcc_exprlist.h b/src/scripting/zscript/zcc_exprlist.h index 4770a08a47..bbf99189c3 100644 --- a/src/scripting/zscript/zcc_exprlist.h +++ b/src/scripting/zscript/zcc_exprlist.h @@ -4,7 +4,6 @@ xx(Nil, TK_None) xx(ID, TK_Identifier) xx(Super, TK_Super) xx(Null, TK_Null) -xx(Self, TK_Self) xx(ConstValue, TK_Const) xx(FuncCall, '(') xx(ArrayAccess, TK_Array) diff --git a/src/scripting/zscript/zcc_parser.cpp b/src/scripting/zscript/zcc_parser.cpp index bc78576306..18d683c4cc 100644 --- a/src/scripting/zscript/zcc_parser.cpp +++ b/src/scripting/zscript/zcc_parser.cpp @@ -155,7 +155,6 @@ static void InitTokenMap() TOKENDEF (TK_Optional, ZCC_OPTIONAL); TOKENDEF (TK_Super, ZCC_SUPER); TOKENDEF (TK_Null, ZCC_NULLPTR); - TOKENDEF (TK_Self, ZCC_SELF); TOKENDEF ('~', ZCC_TILDE); TOKENDEF ('!', ZCC_BANG); TOKENDEF (TK_SizeOf, ZCC_SIZEOF); diff --git a/src/scripting/zscript/zcc_parser.h b/src/scripting/zscript/zcc_parser.h index ca8c3f3cbf..7ba48d711c 100644 --- a/src/scripting/zscript/zcc_parser.h +++ b/src/scripting/zscript/zcc_parser.h @@ -44,7 +44,6 @@ enum }; - // Syntax tree structures. enum EZCCTreeNodeType { diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 502b8d0cfa..caea22aaec 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -47,7 +47,10 @@ class Actor : Thinker native } // Functions - native Actor P_SpawnMissile(Actor dest, class type, Actor owner = null); + native Actor SpawnMissile(Actor dest, class type, Actor owner = null); + native void TraceBleed(int damage, Actor missile); + native bool CheckMeleeRange(); + native int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags = 0, double angle = 0); // DECORATE compatible functions native bool CheckClass(class checkclass, int ptr_select = AAPTR_DEFAULT, bool match_superclass = false); @@ -110,13 +113,10 @@ class Actor : Thinker native native void A_TroopAttack(); native void A_SargAttack(); native void A_HeadAttack(); - native void A_BruisAttack(); native void A_SkullAttack(float speed = 20); native void A_BetaSkullAttack(); native void A_Metal(); native void A_SpidRefire(); - //native void A_BabyMetal(); - //native void A_BspiAttack(); native void A_Hoof(); native void A_CyberAttack(); native void A_PainAttack(class spawntype = "LostSoul", float angle = 0, int flags = 0, int limit = -1); diff --git a/wadsrc/static/zscript/doom/arachnotron.txt b/wadsrc/static/zscript/doom/arachnotron.txt index 0e093323b2..c7e11ab146 100644 --- a/wadsrc/static/zscript/doom/arachnotron.txt +++ b/wadsrc/static/zscript/doom/arachnotron.txt @@ -101,7 +101,7 @@ extend class Actor if (target) { A_FaceTarget(); - P_SpawnMissile(target, "ArachnotronPlasma"); + SpawnMissile(target, "ArachnotronPlasma"); } } diff --git a/wadsrc/static/zscript/doom/bruiser.txt b/wadsrc/static/zscript/doom/bruiser.txt index bbeb319f61..c1faa23c19 100644 --- a/wadsrc/static/zscript/doom/bruiser.txt +++ b/wadsrc/static/zscript/doom/bruiser.txt @@ -138,3 +138,30 @@ class BaronBall : Actor } } +//=========================================================================== +// +// Code (must be attached to Actor) +// +//=========================================================================== + +extend class Actor +{ + void A_BruisAttack() + { + if (target) + { + if (CheckMeleeRange()) + { + int damage = random[pr_bruisattack](1, 8) * 10; + A_PlaySound ("baron/melee", CHAN_WEAPON); + int newdam = target.DamageMobj (self, self, damage, "Melee"); + target.TraceBleed (newdam > 0 ? newdam : damage, self); + } + else + { + // launch a missile + SpawnMissile (target, "BaronBall"); + } + } + } +}