Map number compatmode

This commit is contained in:
GenericHeroGuy 2025-03-03 01:28:21 +01:00
parent 14b758f84a
commit ebea1395d4
8 changed files with 73 additions and 10 deletions

View file

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

View file

@ -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
{

View file

@ -296,6 +296,8 @@ enum
CEILING_SLOPE_THING = 778,
};
#define NUMMAPS 1035 // only for compatmode
#ifdef __cplusplus
} // extern "C"
#endif

View file

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

View file

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

View file

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

View file

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

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, gamemap);
lua_pushinteger(L, lua_compatmode ? G_NativeMapToKart(gamemap-1)+1 : gamemap);
return 1;
} else if (fastcmp(word,"udmf")) {
lua_pushboolean(L, udmf);