From 64bdc8c4956774b42d024ac7b8c0f4b3a8be0508 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Mar 2017 01:39:59 +0100 Subject: [PATCH] - fixed some incomplete checks for static arrays. - made AActor::OkaytoSwitchTarget scripted virtual. --- src/actor.h | 1 + src/p_interaction.cpp | 28 +++++++++++++++++++++++++++- src/scripting/backend/codegen.cpp | 4 ++-- wadsrc/static/zscript/actor.txt | 2 +- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/actor.h b/src/actor.h index 066e15411..c1d5696b3 100644 --- a/src/actor.h +++ b/src/actor.h @@ -692,6 +692,7 @@ public: int SpecialMissileHit (AActor *victim); // Returns true if it's okay to switch target to "other" after being attacked by it. + bool CallOkayToSwitchTarget(AActor *other); bool OkayToSwitchTarget (AActor *other); // Note: Although some of the inventory functions are virtual, this diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index 708b022e5..e54d4a688 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -1682,8 +1682,13 @@ DEFINE_ACTION_FUNCTION(AActor, PoisonMobj) return 0; } +//========================================================================== +// +// OkayToSwitchTarget +// +//========================================================================== -bool AActor::OkayToSwitchTarget (AActor *other) +bool AActor::OkayToSwitchTarget(AActor *other) { if (other == this) return false; // [RH] Don't hate self (can happen when shooting barrels) @@ -1743,6 +1748,27 @@ bool AActor::OkayToSwitchTarget (AActor *other) return true; } +DEFINE_ACTION_FUNCTION(AActor, OkayToSwitchTarget) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT(other, AActor); + ACTION_RETURN_BOOL(self->OkayToSwitchTarget(other)); +} + +bool AActor::CallOkayToSwitchTarget(AActor *other) +{ + IFVIRTUAL(AActor, OkayToSwitchTarget) + { + VMValue params[] = { (DObject*)this, other }; + int retv; + VMReturn ret(&retv); + GlobalVMStack.Call(func, params, 2, &ret, 1); + return !!retv; + } + return false; +} + + //========================================================================== // // P_PoisonPlayer - Sets up all data concerning poisoning diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index ae752b062..9c32e9f0f 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -6293,7 +6293,7 @@ FxExpression *FxMemberIdentifier::Resolve(FCompileContext& ctx) else { auto f = dyn_cast(sym); - if (f != nullptr && (f->Flags & VARF_Static | VARF_ReadOnly) == (VARF_Static | VARF_ReadOnly)) + if (f != nullptr && (f->Flags & (VARF_Static | VARF_ReadOnly | VARF_Meta)) == (VARF_Static | VARF_ReadOnly)) { auto x = new FxGlobalVariable(f, ScriptPosition); delete this; @@ -6944,7 +6944,7 @@ FxExpression *FxStructMember::Resolve(FCompileContext &ctx) } // Even though this is global, static and readonly, we still need to do the scope checks for consistency. - if ((membervar->Flags & (VARF_Static | VARF_ReadOnly)) == (VARF_Static | VARF_ReadOnly)) + if ((membervar->Flags & (VARF_Static | VARF_ReadOnly | VARF_Meta)) == (VARF_Static | VARF_ReadOnly)) { // This is a static constant array, which is stored at a constant address, like a global variable. auto x = new FxGlobalVariable(membervar, ScriptPosition); diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 7733d2ec3..db0a804b9 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -438,7 +438,7 @@ class Actor : Thinker native return Obituary; } - + native virtual bool OkayToSwitchTarget(Actor other); native static class GetReplacement(class cls); native static class GetReplacee(class cls); native static int GetSpriteIndex(name sprt);