From c914ac99b4e39110bca1203b4d12e9078d406656 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Wed, 29 Jul 2020 17:26:43 +0200 Subject: [PATCH] Bring back P_FindSpecialLineFromTag() for backwards compatibility reasons; emulate the old taglist behavior for this function. --- src/lua_baselib.c | 13 +++++++++++++ src/taglist.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/taglist.h | 3 ++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index a8a45ba20..5d1db5641 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -32,6 +32,7 @@ #include "lua_script.h" #include "lua_libs.h" #include "lua_hud.h" // hud_running errors +#include "taglist.h" // P_FindSpecialLineFromTag #define NOHUD if (hud_running)\ return luaL_error(L, "HUD rendering code should not call this function!"); @@ -2094,6 +2095,17 @@ static int lib_pFindHighestCeilingSurrounding(lua_State *L) return 1; } +static int lib_pFindSpecialLineFromTag(lua_State *L) +{ + INT16 special = (INT16)luaL_checkinteger(L, 1); + INT16 line = (INT16)luaL_checkinteger(L, 2); + INT32 start = (INT32)luaL_optinteger(L, 3, -1); + NOHUD + INLEVEL + lua_pushinteger(L, P_FindSpecialLineFromTag(special, line, start)); + return 1; +} + static int lib_pSwitchWeather(lua_State *L) { INT32 weathernum = (INT32)luaL_checkinteger(L, 1); @@ -3581,6 +3593,7 @@ static luaL_Reg lib[] = { {"P_FindNextLowestFloor",lib_pFindNextLowestFloor}, {"P_FindLowestCeilingSurrounding",lib_pFindLowestCeilingSurrounding}, {"P_FindHighestCeilingSurrounding",lib_pFindHighestCeilingSurrounding}, + {"P_FindSpecialLineFromTag",lib_pFindSpecialLineFromTag}, {"P_SwitchWeather",lib_pSwitchWeather}, {"P_LinedefExecute",lib_pLinedefExecute}, {"P_SpawnLightningFlash",lib_pSpawnLightningFlash}, diff --git a/src/taglist.c b/src/taglist.c index 2c1ac85d7..7fd2601c7 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -284,6 +284,48 @@ INT32 Tag_FindLineSpecial(const INT16 special, const mtag_t tag) return -1; } +/// Backwards compatibility iteration function for Lua scripts. +INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start) +{ + if (tag == -1) + { + start++; + + if (start >= (INT32)numlines) + return -1; + + while (start < (INT32)numlines && lines[start].special != special) + start++; + + return start; + } + else + { + size_t p = 0; + INT32 id; + + // For backwards compatibility's sake, simulate the old linked taglist behavior: + // Iterate through the taglist and find the "start" line's position in the list, + // And start checking with the next one (if it exists). + if (start != -1) + { + for (; (id = Tag_Iterate_Lines(tag, p)) >= 0; p++) + if (id == start) + { + p++; + break; + } + } + + for (; (id = Tag_Iterate_Lines(tag, p)) >= 0; p++) + if (lines[id].special == special) + return id; + + return -1; + } +} + + // Ingame list manipulation. void Tag_SectorFSet (const size_t id, const mtag_t tag) diff --git a/src/taglist.h b/src/taglist.h index d1acff6cb..7c3b4ad52 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -44,7 +44,8 @@ INT32 Tag_Iterate_Sectors (const mtag_t tag, const size_t p); INT32 Tag_Iterate_Lines (const mtag_t tag, const size_t p); INT32 Tag_Iterate_Things (const mtag_t tag, const size_t p); -INT32 Tag_FindLineSpecial(const INT16 special, const INT16 tag); +INT32 Tag_FindLineSpecial(const INT16 special, const mtag_t tag); +INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start); #define TAG_ITER_C size_t kkkk; #define TAG_ITER(fn, tag, id) for(kkkk = 0; (id = fn(tag, kkkk)) >= 0; kkkk++)