Y'know what? Just make these functions one-based, sheesh

This commit is contained in:
GenericHeroGuy 2025-03-03 21:16:21 +01:00
parent 037a75df08
commit 8a51847fb1
6 changed files with 19 additions and 28 deletions

View file

@ -1132,19 +1132,14 @@ void readlevelheader(MYFILE *f, char * name)
// compatmode map number system:
// 0-1034 correspond to MAP01-MAPZZ,
// longname maps are appended starting at NUMMAPS
if (exnum)
if (!exnum)
{
exnum--;
kartmap2native[exnum] = num;
nativemap2kart[num] = exnum;
}
else
{
kartmap2native[nextexnum] = num;
nativemap2kart[num] = nextexnum;
if (++nextexnum >= NEXTMAP_SPECIAL)
exnum = ++nextexnum;
if (exnum >= NEXTMAP_SPECIAL)
I_Error("Ran out of compatibility map slots");
}
kartmap2native[exnum-1] = num;
nativemap2kart[num] = exnum-1;
if (mapheaderinfo[num]->lumpname == NULL)
{

View file

@ -340,7 +340,6 @@ boolean precache = true; // if true, load all graphics at start
INT16 prevmap, nextmap;
// initialized to -1 in G_LoadGameSettings
INT16 kartmap2native[NEXTMAP_SPECIAL] = {0}, nativemap2kart[NEXTMAP_SPECIAL] = {0};
INT16 nextexnum = NUMMAPS;
@ -796,17 +795,17 @@ INT32 G_MapNumber(const char * name)
// convert kart map number to native map number
INT16 G_KartMapToNative(INT16 mapnum)
{
if (mapnum >= 0 && mapnum < NEXTMAP_SPECIAL)
return kartmap2native[mapnum];
return -1;
if (mapnum > 0 && mapnum < NEXTMAP_SPECIAL)
return kartmap2native[mapnum-1]+1;
return 0;
}
// convert native map number to kart
INT16 G_NativeMapToKart(INT16 mapnum)
{
if (mapnum >= 0 && mapnum < NEXTMAP_SPECIAL)
return nativemap2kart[mapnum];
return -1;
if (mapnum > 0 && mapnum < NEXTMAP_SPECIAL)
return nativemap2kart[mapnum-1]+1;
return 0;
}
/** Clips the console player's mouse aiming to the current view.
@ -4359,9 +4358,6 @@ void G_LoadGameSettings(void)
{
// initialize free sfx slots for skin sounds
S_InitRuntimeSounds();
for (size_t i = 0; i < NEXTMAP_SPECIAL; i++)
kartmap2native[i] = nativemap2kart[i] = -1;
}
#define GD_VERSIONCHECK 0xBA5ED444

View file

@ -3164,7 +3164,7 @@ static int lib_gAddGametype(lua_State *L)
static int Lcheckmapnumber (lua_State *L, int idx, const char *fun)
{
if (ISINLEVEL)
return luaL_optinteger(L, idx, lua_compatmode ? G_NativeMapToKart(gamemap-1)+1 : gamemap);
return luaL_optinteger(L, idx, lua_compatmode ? G_NativeMapToKart(gamemap) : gamemap);
else
{
if (lua_isnoneornil(L, idx))
@ -3183,7 +3183,7 @@ static int lib_gBuildMapName(lua_State *L)
{
INT32 map = Lcheckmapnumber(L, 1, "G_BuildMapName");
//HUDSAFE
lua_pushstring(L, G_BuildMapName(lua_compatmode ? G_KartMapToNative(map-1)+1 : map));
lua_pushstring(L, G_BuildMapName(lua_compatmode ? G_KartMapToNative(map) : map));
return 1;
}
@ -3350,7 +3350,7 @@ static int lib_gSetCustomExitVars(lua_State *L)
nextmapoverride = (INT16)luaL_optinteger(L, 1, 0);
skipstats = (INT16)luaL_optinteger(L, 2, 0);
if (lua_compatmode && nextmapoverride)
nextmapoverride = G_KartMapToNative(nextmapoverride-1)+1;
nextmapoverride = G_KartMapToNative(nextmapoverride);
}
return 0;
@ -3373,7 +3373,7 @@ static int lib_gIsSpecialStage(lua_State *L)
INT32 mapnum = Lcheckmapnumber(L, 1, "G_IsSpecialStage");
//HUDSAFE
INLEVEL
lua_pushboolean(L, G_IsSpecialStage(lua_compatmode ? G_KartMapToNative(mapnum-1)+1 : mapnum));
lua_pushboolean(L, G_IsSpecialStage(lua_compatmode ? G_KartMapToNative(mapnum) : mapnum));
return 1;
}

View file

@ -647,7 +647,7 @@ void LUA_HookGamemap(int hook_type)
if (prepare_hook(&hook, 0, hook_type))
{
lua_pushinteger(gL, gamemap);
lua_pushinteger(gL, G_NativeMapToKart(gamemap-1)+1);
lua_pushinteger(gL, G_NativeMapToKart(gamemap));
init_hook_call(&hook, 0, res_none);
hook.values = 1;
call_mapped_gamemap(&hook, &hookIds[hook.hook_type]);

View file

@ -2521,10 +2521,10 @@ static int lib_getMapheaderinfo(lua_State *L)
lua_remove(L, 1); // dummy userdata table is unused.
if (lua_isnumber(L, 1))
{
INT32 i = lua_tointeger(L, 1)-1;
INT32 i = lua_tointeger(L, 1);
if (lua_compatmode)
i = G_KartMapToNative(i);
if (i < 0 || i >= nummapheaders)
if (--i < 0 || i >= nummapheaders)
return 0;
LUA_PushUserdata(L, mapheaderinfo[i], META_MAPHEADER);
//CONS_Printf(mapheaderinfo[i]->lvlttl);

View file

@ -157,7 +157,7 @@ boolean lua_compatmode = false;
int LUA_PushGlobals(lua_State *L, const char *word)
{
if (fastcmp(word,"gamemap")) {
lua_pushinteger(L, lua_compatmode ? G_NativeMapToKart(gamemap-1)+1 : gamemap);
lua_pushinteger(L, lua_compatmode ? G_NativeMapToKart(gamemap) : gamemap);
return 1;
} else if (fastcmp(word,"udmf")) {
lua_pushboolean(L, udmf);