From ebea1395d477f7ce2ea01b7e72b69a9b03a37b80 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Mon, 3 Mar 2025 01:28:21 +0100 Subject: [PATCH] Map number compatmode --- src/deh_soc.c | 33 +++++++++++++++++++++++++++++++++ src/dehacked.c | 7 +------ src/doomdata.h | 2 ++ src/g_game.c | 23 +++++++++++++++++++++++ src/g_game.h | 5 +++++ src/lua_baselib.c | 6 ++++-- src/lua_maplib.c | 5 ++++- src/lua_script.c | 2 +- 8 files changed, 73 insertions(+), 10 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 73fd6cc9b..8e4a8082f 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -1101,6 +1101,22 @@ void readlevelheader(MYFILE *f, char * name) char *tmp; INT32 i; + // convert old map names to MAPxx + INT32 exnum = atoi(name); + if (exnum > 0 && exnum <= NUMMAPS) + { + if (exnum < 100) + name = va("MAP%02d", exnum); + else + // one liner extended names :^) + name = va("MAP%c%c", 'A' + (exnum - 100)/36, ((exnum - 100) % 36 < 10 ? '0' : 'A'-10) + (exnum - 100) % 36); + } + else if (strlen(name) == 2 && isalpha(name[0]) && isalnum(name[1])) + { + exnum = (name[0] - 'A')*36 + (isalpha(name[1]) ? name[1] - 'A'+10 : name[1] - '0') + 100; + name = va("MAP%s", name); + } + INT32 num = G_MapNumber(name); if (num >= nummapheaders) @@ -1113,6 +1129,23 @@ void readlevelheader(MYFILE *f, char * name) G_SetGameModified(multiplayer, true); } + // compatmode map number system: + // 0-1034 correspond to MAP01-MAPZZ, + // longname maps are appended starting at NUMMAPS + if (exnum) + { + exnum--; + kartmap2native[exnum] = num; + nativemap2kart[num] = exnum; + } + else + { + kartmap2native[nextexnum] = num; + nativemap2kart[num] = nextexnum; + if (++nextexnum >= NEXTMAP_SPECIAL) + I_Error("Ran out of compatibility map slots"); + } + if (mapheaderinfo[num]->lumpname == NULL) { mapheaderinfo[num]->lumpname = Z_StrDup(name); diff --git a/src/dehacked.c b/src/dehacked.c index 9ce541cb4..2afd3b8f7 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -371,12 +371,7 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile) size_t len = strlen(word2); if (len <= MAXMAPLUMPNAME-1) { - if (len == 1) - readlevelheader(f, va("MAP0%s",word2)); - else if (len == 2) - readlevelheader(f, va("MAP%s",word2)); - else - readlevelheader(f, word2); + readlevelheader(f, word2); } else { diff --git a/src/doomdata.h b/src/doomdata.h index 03686a537..5655a93d8 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -296,6 +296,8 @@ enum CEILING_SLOPE_THING = 778, }; +#define NUMMAPS 1035 // only for compatmode + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/g_game.c b/src/g_game.c index 867db0b1c..10bc93010 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -340,6 +340,10 @@ 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; + static CV_PossibleValue_t joyaxis_cons_t[] = {{0, "None"}, {1, "Left X"}, {2, "Left Y"}, {-1, "Left X-"}, {-2, "Left Y-"}, #if JOYAXISSET > 1 @@ -789,6 +793,22 @@ INT32 G_MapNumber(const char * name) #endif } +// convert kart map number to native map number +INT16 G_KartMapToNative(INT16 mapnum) +{ + if (mapnum >= 0 && mapnum < NEXTMAP_SPECIAL) + return kartmap2native[mapnum]; + return -1; +} + +// convert native map number to kart +INT16 G_NativeMapToKart(INT16 mapnum) +{ + if (mapnum >= 0 && mapnum < NEXTMAP_SPECIAL) + return nativemap2kart[mapnum]; + return -1; +} + /** Clips the console player's mouse aiming to the current view. * Used whenever the player view is changed manually. * @@ -4335,6 +4355,9 @@ 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 diff --git a/src/g_game.h b/src/g_game.h index 51c27fb84..e39b006a1 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -52,6 +52,9 @@ typedef enum NEXTMAP_SPECIAL = NEXTMAP_INVALID } nextmapspecial_t; +extern INT16 kartmap2native[NEXTMAP_SPECIAL], nativemap2kart[NEXTMAP_SPECIAL]; +extern INT16 nextexnum; + extern INT32 gameovertics; extern UINT8 ammoremovaltics; extern tic_t timeinmap; // Ticker for time spent in level (used for levelcard display) @@ -109,6 +112,8 @@ void weaponPrefChange4(void); const char *G_BuildMapName(INT32 map); INT32 G_MapNumber(const char *mapname); +INT16 G_KartMapToNative(INT16 mapnum); +INT16 G_NativeMapToKart(INT16 mapnum); void G_ResetAnglePrediction(player_t *player); void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 4d6010ba2..474fe9b32 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3183,7 +3183,7 @@ static int lib_gBuildMapName(lua_State *L) { INT32 map = Lcheckmapnumber(L, 1, "G_BuildMapName"); //HUDSAFE - lua_pushstring(L, G_BuildMapName(map)); + lua_pushstring(L, G_BuildMapName(lua_compatmode ? G_KartMapToNative(map-1)+1 : map)); return 1; } @@ -3349,6 +3349,8 @@ 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; } return 0; @@ -3371,7 +3373,7 @@ static int lib_gIsSpecialStage(lua_State *L) INT32 mapnum = luaL_optinteger(L, 1, gamemap); //HUDSAFE INLEVEL - lua_pushboolean(L, G_IsSpecialStage(mapnum)); + lua_pushboolean(L, G_IsSpecialStage(lua_compatmode ? G_KartMapToNative(mapnum-1)+1 : mapnum)); return 1; } diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 841141a26..86f182222 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -18,6 +18,7 @@ #include "p_slopes.h" #include "p_polyobj.h" #include "r_main.h" +#include "g_game.h" // G_KartMapToNative #include "lua_script.h" #include "lua_libs.h" @@ -2521,6 +2522,8 @@ static int lib_getMapheaderinfo(lua_State *L) if (lua_isnumber(L, 1)) { INT32 i = lua_tointeger(L, 1)-1; + if (lua_compatmode) + i = G_KartMapToNative(i); if (i < 0 || i >= nummapheaders) return 0; LUA_PushUserdata(L, mapheaderinfo[i], META_MAPHEADER); @@ -2539,7 +2542,7 @@ static int lib_getMapheaderinfo(lua_State *L) static int lib_nummapheaders(lua_State *L) { - lua_pushinteger(L, nummapheaders); + lua_pushinteger(L, lua_compatmode ? NUMMAPS : nummapheaders); return 1; } diff --git a/src/lua_script.c b/src/lua_script.c index 57d62c8e4..53ec8c185 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -157,7 +157,7 @@ boolean lua_compatmode = false; int LUA_PushGlobals(lua_State *L, const char *word) { if (fastcmp(word,"gamemap")) { - lua_pushinteger(L, gamemap); + lua_pushinteger(L, lua_compatmode ? G_NativeMapToKart(gamemap-1)+1 : gamemap); return 1; } else if (fastcmp(word,"udmf")) { lua_pushboolean(L, udmf);