From b85add01c7890650153631fe82de302f225fcd72 Mon Sep 17 00:00:00 2001 From: Marisa the Magician Date: Fri, 23 Dec 2022 16:36:59 +0100 Subject: [PATCH] Additional lock-related ZScript functions. * Key.ValidLock: returns whether a lock number is valid (can be unlocked) or belongs to a "does not work" door. * Key.GetMapColorForLock: returns the automap color for a lock number (or -1 if the lock isn't valid). * Key.GetMapColorForKey: likewise, but for a specific key. --- src/gamedata/a_keys.cpp | 6 ++++++ src/gamedata/a_keys.h | 1 + src/scripting/vmthunks_actors.cpp | 21 +++++++++++++++++++ .../zscript/actors/inventory/inv_misc.zs | 3 +++ 4 files changed, 31 insertions(+) diff --git a/src/gamedata/a_keys.cpp b/src/gamedata/a_keys.cpp index 406b0fbb80..86b01306fb 100644 --- a/src/gamedata/a_keys.cpp +++ b/src/gamedata/a_keys.cpp @@ -516,6 +516,12 @@ int P_CheckKeys (AActor *owner, int keynum, bool remote, bool quiet) return false; } +// [MK] for ZScript, simply returns if a lock is defined or not +int P_ValidLock(int keynum) +{ + return !!Locks.CheckKey(keynum); +} + //========================================================================== // // These functions can be used to get color information for diff --git a/src/gamedata/a_keys.h b/src/gamedata/a_keys.h index 15c19c0171..40385a93fd 100644 --- a/src/gamedata/a_keys.h +++ b/src/gamedata/a_keys.h @@ -5,6 +5,7 @@ class AActor; class PClassActor; int P_CheckKeys (AActor *owner, int keynum, bool remote, bool quiet = false); +int P_ValidLock (int lock); void P_InitKeyMessages (); int P_GetMapColorForLock (int lock); int P_GetMapColorForKey (AActor *key); diff --git a/src/scripting/vmthunks_actors.cpp b/src/scripting/vmthunks_actors.cpp index 8b7edabc27..f91bb51b2e 100644 --- a/src/scripting/vmthunks_actors.cpp +++ b/src/scripting/vmthunks_actors.cpp @@ -1749,6 +1749,27 @@ DEFINE_ACTION_FUNCTION_NATIVE(AInventory, PrintPickupMessage, PrintPickupMessage // //===================================================================================== +DEFINE_ACTION_FUNCTION_NATIVE(AKey, ValidLock, P_ValidLock) +{ + PARAM_PROLOGUE; + PARAM_INT(locknum); + ACTION_RETURN_BOOL(P_ValidLock(locknum)); +} + +DEFINE_ACTION_FUNCTION_NATIVE(AKey, GetMapColorForLock, P_GetMapColorForLock) +{ + PARAM_PROLOGUE; + PARAM_INT(locknum); + ACTION_RETURN_INT(P_GetMapColorForLock(locknum)); +} + +DEFINE_ACTION_FUNCTION_NATIVE(AKey, GetMapColorForKey, P_GetMapColorForKey) +{ + PARAM_PROLOGUE; + PARAM_OBJECT(key, AActor); + ACTION_RETURN_INT(P_GetMapColorForKey(key)); +} + DEFINE_ACTION_FUNCTION_NATIVE(AKey, GetKeyTypeCount, P_GetKeyTypeCount) { PARAM_PROLOGUE; diff --git a/wadsrc/static/zscript/actors/inventory/inv_misc.zs b/wadsrc/static/zscript/actors/inventory/inv_misc.zs index a31efc5b18..09ce6436fe 100644 --- a/wadsrc/static/zscript/actors/inventory/inv_misc.zs +++ b/wadsrc/static/zscript/actors/inventory/inv_misc.zs @@ -37,6 +37,9 @@ class Key : Inventory Inventory.PickupSound "misc/k_pkup"; } + static native clearscope bool ValidLock(int locknum); + static native clearscope Color GetMapColorForLock(int locknum); + static native clearscope Color GetMapColorForKey(Key key); static native clearscope int GetKeyTypeCount(); static native clearscope class GetKeyType(int index);