Skip to content

Commit

Permalink
Additional lock-related ZScript functions.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Marisa the Magician authored and coelckers committed Dec 23, 2022
1 parent 6072260 commit b85add0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/gamedata/a_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/gamedata/a_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions src/scripting/vmthunks_actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions wadsrc/static/zscript/actors/inventory/inv_misc.zs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Key> GetKeyType(int index);

Expand Down

0 comments on commit b85add0

Please sign in to comment.