Merge branch 'conditionslua' into 'next'

Add Lua conditions for custom unlockable systems and expose 'info panel' at escape (pause) menu.

See merge request STJr/SRB2!2439
This commit is contained in:
Skydusk 2025-03-20 07:39:45 +00:00
commit 781a3900d9
9 changed files with 117 additions and 3 deletions

View file

@ -3490,6 +3490,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);

View file

@ -3880,6 +3880,34 @@ static int lib_gAddGametype(lua_State *L)
return 0;
}
// Lua exclusive function to unlock Lua Conditions
// Up to Lua scripter
static int lib_gUnlockCondition(lua_State* L)
{
int id = luaL_checkinteger(L, 1) - 1;
boolean global = luaL_checkboolean(L, 2);
if (id <= 0 || id > MAXLUACONDITIONS)
{
luaL_error(L, "Lua condition %d out of range (1 - %d)", id + 1, MAXLUACONDITIONS);
return 0;
}
if (global)
{
serverGamedata->lua[id] = true;
M_SilentUpdateUnlockablesAndEmblems(serverGamedata);
}
clientGamedata->lua[id] = true;
if (M_UpdateUnlockablesAndExtraEmblems(clientGamedata))
{
S_StartSound(NULL, sfx_s3k68);
}
return 0;
}
// Bot adding function!
// Partly lifted from Got_AddPlayer
static int lib_gAddPlayer(lua_State *L)
@ -4628,6 +4656,7 @@ static luaL_Reg lib[] = {
{"G_AddGametype", lib_gAddGametype},
{"G_AddPlayer", lib_gAddPlayer},
{"G_RemovePlayer", lib_gRemovePlayer},
{"G_UnlockCondition", lib_gUnlockCondition},
{"G_SetUsedCheats", lib_gSetUsedCheats},
{"G_BuildMapName",lib_gBuildMapName},
{"G_BuildMapTitle",lib_gBuildMapTitle},

View file

@ -86,6 +86,7 @@ automatically.
X (scores),/* emblems/multiplayer list */\
X (title),/* titlescreen */\
X (titlecard),\
X (escpanel) /* rings/time/score/emblem panel in pause menu */,\
X (intermission),\
X (continue),\
X (playersetup),\
@ -127,6 +128,10 @@ int LUA_HookCharacterHUD
INT32 skinIndex, UINT8 sprite2, UINT8 frame, UINT8 rotation, skincolornum_t color,
INT32 ticker, boolean mode
);
int LUA_HookEscapePanel(
int hook, huddrawlist_h drawlist,
int x, int y, int width, int height
);
int LUA_HookMobj(mobj_t *, int hook);
int LUA_Hook2Mobj(mobj_t *, mobj_t *, int hook);

View file

@ -727,6 +727,22 @@ int LUA_HookCharacterHUD
return hook.status;
}
int LUA_HookEscapePanel(int hook, huddrawlist_h drawlist, int x, int y, int width, int height)
{
Hook_State hookstate;
if (prepare_hud_hook(&hookstate, false, hook))
{
LUA_SetHudHook(hook, drawlist);
lua_pushinteger(gL, x);
lua_pushinteger(gL, y);
lua_pushinteger(gL, width);
lua_pushinteger(gL, height);
call_hud_hooks(&hookstate, 1, res_true);
}
return hookstate.status;
}
/* =========================================================================
SPECIALIZED HOOKS
========================================================================= */

View file

@ -412,6 +412,15 @@ int LUA_PushGlobals(lua_State *L, const char *word)
} else if (fastcmp(word, "token")) {
lua_pushinteger(L, token);
return 1;
} else if (fastcmp(word, "emblems")) {
lua_pushinteger(L, M_CountEmblems(clientGamedata));
return 1;
} else if (fastcmp(word, "numemblems")) {
lua_pushinteger(L, numemblems);
return 1;
} else if (fastcmp(word, "numextraemblems")) {
lua_pushinteger(L, numextraemblems);
return 1;
} else if (fastcmp(word, "gamestate")) {
lua_pushinteger(L, gamestate);
return 1;

View file

@ -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);
}

View file

@ -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];

View file

@ -186,6 +186,7 @@ static tic_t keydown = 0;
// Lua
static huddrawlist_h luahuddrawlist_playersetup;
static huddrawlist_h luahuddrawlist_infoscreen;
//
// PROTOTYPES
@ -393,6 +394,7 @@ static void M_DrawColorRamp(INT32 x, INT32 y, INT32 w, INT32 h, skincolor_t colo
// Handling functions
static boolean M_ExitPandorasBox(void);
static boolean M_QuitMultiPlayerMenu(void);
static boolean M_QuitPauseMenu(void);
static void M_HandleAddons(INT32 choice);
static void M_HandleLevelPlatter(INT32 choice);
static void M_HandleSoundTest(INT32 choice);
@ -3767,6 +3769,14 @@ void M_StartControlPanel(void)
CON_ToggleOff(); // move away console
}
static boolean M_QuitPauseMenu(void)
{
LUA_HUD_DestroyDrawList(luahuddrawlist_infoscreen);
luahuddrawlist_infoscreen = NULL;
return true;
}
void M_EndModeAttackRun(void)
{
G_ClearModeAttackRetryFlag();
@ -4719,8 +4729,29 @@ static void M_DrawPauseMenu(void)
emblem_t *emblem_detail[3] = {NULL, NULL, NULL};
char emblem_text[3][20];
INT32 i;
INT16 xbox = 27;
INT16 ybox = 16;
INT16 widthbox = 32;
INT16 heightbox = 6;
M_DrawTextBox(27, 16, 32, 6);
M_DrawTextBox(xbox, ybox, widthbox, heightbox);
if (!LUA_HUD_IsDrawListValid(luahuddrawlist_infoscreen))
{
LUA_HUD_DestroyDrawList(luahuddrawlist_infoscreen);
luahuddrawlist_infoscreen = LUA_HUD_CreateDrawList();
}
LUA_HUD_ClearDrawList(luahuddrawlist_infoscreen);
boolean esc_override = LUA_HookEscapePanel(
HUD_HOOK(escpanel),
luahuddrawlist_infoscreen,
xbox+5, ybox+5, widthbox*8+6, heightbox*8+6);
LUA_HUD_DrawList(luahuddrawlist_infoscreen);
if (esc_override)
goto draw_rest;
// Draw any and all emblems at the top.
M_DrawMapEmblems(gamemap, 272, 28, true);
@ -4853,7 +4884,10 @@ static void M_DrawPauseMenu(void)
}
}
M_DrawGenericMenu();
draw_rest:
{
M_DrawGenericMenu();
}
}
static void M_DrawCenteredMenu(void)

View file

@ -524,7 +524,7 @@ void M_FreePlayerSetupColors(void);
M_DrawPauseMenu,\
x, y,\
0,\
NULL\
M_QuitPauseMenu\
}
#define CENTERMENUSTYLE(id, header, source, prev, y)\