mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-31 21:50:48 +00:00
Bring back P_FindSpecialLineFromTag() for backwards compatibility reasons; emulate the old taglist behavior for this function.
This commit is contained in:
parent
729c8b2ec6
commit
c914ac99b4
3 changed files with 57 additions and 1 deletions
|
@ -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},
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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++)
|
||||
|
|
Loading…
Reference in a new issue