From f09a5f13438de624df5a62ae7b6ad49e29fac9d4 Mon Sep 17 00:00:00 2001
From: Ace Lite <47698279+Ace-Lite@users.noreply.github.com>
Date: Mon, 6 May 2024 01:34:44 +0200
Subject: [PATCH] Added 'LUA' condition and G_UnlockCondition

---
 src/deh_soc.c | 12 ++++++++++++
 src/m_cond.c  |  4 ++++
 src/m_cond.h  |  5 +++++
 3 files changed, 21 insertions(+)

diff --git a/src/deh_soc.c b/src/deh_soc.c
index 65db63ebb1..f2ae7f2244 100644
--- a/src/deh_soc.c
+++ b/src/deh_soc.c
@@ -3453,6 +3453,18 @@ static void readcondition(UINT8 set, UINT32 id, char *word2)
 			return;
 		}
 	}
+	else if (fastcmp(params[0], "LUA"))
+	{
+		PARAMCHECK(1);
+		ty = UC_LUA;
+		re = atoi(params[1]);
+
+		if (re <= 0 || re > MAXLUACONDITIONS)
+		{
+			deh_warning("Lua condition %d out of range (1 - %d)", re, MAXLUACONDITIONS);
+			return;
+		}
+	}
 	else if (fastcmp(params[0], "CONDITIONSET"))
 	{
 		PARAMCHECK(1);
diff --git a/src/m_cond.c b/src/m_cond.c
index 5a59132971..279eca8faf 100644
--- a/src/m_cond.c
+++ b/src/m_cond.c
@@ -155,6 +155,8 @@ void M_ClearSecrets(gamedata_t *data)
 		data->unlocked[i] = false;
 	for (i = 0; i < MAXCONDITIONSETS; ++i)
 		data->achieved[i] = false;
+	for (i = 0; i < MAXLUACONDITIONS; ++i)
+		data->lua[i] = false;
 
 	data->timesBeaten = data->timesBeatenWithEmeralds = data->timesBeatenUltimate = 0;
 
@@ -214,6 +216,8 @@ static UINT8 M_CheckCondition(condition_t *cn, gamedata_t *data)
 			return data->collected[cn->requirement-1];
 		case UC_EXTRAEMBLEM: // Requires extra emblem x to be obtained
 			return data->extraCollected[cn->requirement-1];
+		case UC_LUA:
+			return data->lua[cn->requirement-1];
 		case UC_CONDITIONSET: // requires condition set x to already be achieved
 			return M_Achieved(cn->requirement-1, data);
 	}
diff --git a/src/m_cond.h b/src/m_cond.h
index 2491a384c0..2e6606f560 100644
--- a/src/m_cond.h
+++ b/src/m_cond.h
@@ -47,6 +47,7 @@ typedef enum
 	UC_EMBLEM,          // EMBLEM [emblem number]
 	UC_EXTRAEMBLEM,     // EXTRAEMBLEM [extra emblem number]
 	UC_CONDITIONSET,    // CONDITIONSET [condition set number]
+	UC_LUA,				// LUA [condition set number]
 } conditiontype_t;
 
 // Condition Set information
@@ -141,6 +142,7 @@ typedef struct
 #define MAXEMBLEMS       512
 #define MAXEXTRAEMBLEMS   48
 #define MAXUNLOCKABLES    80
+#define MAXLUACONDITIONS 128
 
 /** Time attack information, currently a very small structure.
   */
@@ -202,6 +204,9 @@ typedef struct
 	// UNLOCKABLES UNLOCKED
 	boolean unlocked[MAXUNLOCKABLES];
 
+	// LUA DATA (NOT SAVED INTO GAMEDATA)
+	boolean lua[MAXLUACONDITIONS];
+
 	// TIME ATTACK DATA
 	recorddata_t *mainrecords[NUMMAPS];
 	nightsdata_t *nightsrecords[NUMMAPS];
-- 
GitLab