- undid hardcoded coupling of Mapinfo slots with episode/level pairs in Blood.

This both lifts the imposed limit of 16 levels and will allow dynamic management of global mapinfo data.
This commit is contained in:
Christoph Oelckers 2020-08-03 20:11:30 +02:00
parent d87f0dc0b0
commit 35a5c4e23c
5 changed files with 43 additions and 36 deletions

View file

@ -366,6 +366,8 @@ void StartLevel(GAMEOPTIONS *gameOptions)
gStartNewGame = 0; gStartNewGame = 0;
ready2send = 0; ready2send = 0;
netWaitForEveryone(0); netWaitForEveryone(0);
currentLevel = FindMapByLevelNum(levelnum(gGameOptions.nEpisode, gGameOptions.nLevel));
if (gGameOptions.nGameType == 0) if (gGameOptions.nGameType == 0)
{ {
if (!(gGameOptions.uGameFlags&1)) if (!(gGameOptions.uGameFlags&1))
@ -415,14 +417,13 @@ void StartLevel(GAMEOPTIONS *gameOptions)
memset(xsprite,0,sizeof(xsprite)); memset(xsprite,0,sizeof(xsprite));
memset(sprite,0,kMaxSprites*sizeof(spritetype)); memset(sprite,0,kMaxSprites*sizeof(spritetype));
//drawLoadingScreen(); //drawLoadingScreen();
if (dbLoadMap(gameOptions->zLevelName,(int*)&startpos.x,(int*)&startpos.y,(int*)&startpos.z,&startang,&startsectnum,(unsigned int*)&gameOptions->uMapCRC)) if (dbLoadMap(currentLevel->fileName,(int*)&startpos.x,(int*)&startpos.y,(int*)&startpos.z,&startang,&startsectnum,(unsigned int*)&gameOptions->uMapCRC))
{ {
I_Error("Unable to load map"); I_Error("Unable to load map");
} }
currentLevel = &mapList[gGameOptions.nEpisode * kMaxLevels + gGameOptions.nLevel];
SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name); SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name);
STAT_NewLevel(currentLevel->fileName); STAT_NewLevel(currentLevel->fileName);
G_LoadMapHack(gameOptions->zLevelName); G_LoadMapHack(currentLevel->fileName);
wsrand(gameOptions->uMapCRC); wsrand(gameOptions->uMapCRC);
gKillMgr.Clear(); gKillMgr.Clear();
gSecretMgr.Clear(); gSecretMgr.Clear();

View file

@ -46,7 +46,7 @@ BEGIN_BLD_NS
GAMEOPTIONS gGameOptions; GAMEOPTIONS gGameOptions;
GAMEOPTIONS gSingleGameOptions = { GAMEOPTIONS gSingleGameOptions = {
0, 2, 0, 0, "", 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 3600, 1800, 1800, 7200 0, 2, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 3600, 1800, 1800, 7200
}; };
EPISODEINFO gEpisodeInfo[kMaxEpisodes+1]; EPISODEINFO gEpisodeInfo[kMaxEpisodes+1];
@ -114,9 +114,10 @@ void levelSetupOptions(int nEpisode, int nLevel)
{ {
gGameOptions.nEpisode = nEpisode; gGameOptions.nEpisode = nEpisode;
gGameOptions.nLevel = nLevel; gGameOptions.nLevel = nLevel;
strcpy(gGameOptions.zLevelName, gEpisodeInfo[nEpisode].levels[nLevel].labelName); auto level = FindMapByLevelNum(levelnum(nEpisode, nLevel));
gGameOptions.uMapCRC = dbReadMapCRC(gGameOptions.zLevelName); if (!level) return;
gGameOptions.nTrackNumber = gEpisodeInfo[nEpisode].levels[nLevel].cdSongId; gGameOptions.uMapCRC = dbReadMapCRC(level->LabelName());
gGameOptions.nTrackNumber = level->cdSongId;
} }
void levelLoadMapInfo(IniFile *pIni, MapRecord *pLevelInfo, const char *pzSection, int epinum, int mapnum) void levelLoadMapInfo(IniFile *pIni, MapRecord *pLevelInfo, const char *pzSection, int epinum, int mapnum)
@ -177,16 +178,16 @@ void levelLoadDefaults(void)
pEpisodeInfo->cutALevel = BloodINI->GetKeyInt(buffer, "CutSceneALevel", 0); pEpisodeInfo->cutALevel = BloodINI->GetKeyInt(buffer, "CutSceneALevel", 0);
if (pEpisodeInfo->cutALevel > 0) if (pEpisodeInfo->cutALevel > 0)
pEpisodeInfo->cutALevel--; pEpisodeInfo->cutALevel--;
pEpisodeInfo->levels = mapList + i * kMaxLevels;
int j; int j;
for (j = 0; j < kMaxLevels; j++) for (j = 0; j < kMaxLevels; j++)
{ {
auto pLevelInfo = &pEpisodeInfo->levels[j];
sprintf(buffer2, "Map%d", j+1); sprintf(buffer2, "Map%d", j+1);
if (!BloodINI->KeyExists(buffer, buffer2)) if (!BloodINI->KeyExists(buffer, buffer2))
break; break;
auto pLevelInfo = AllocateMap();
const char *pMap = BloodINI->GetKeyString(buffer, buffer2, NULL); const char *pMap = BloodINI->GetKeyString(buffer, buffer2, NULL);
CheckSectionAbend(pMap); CheckSectionAbend(pMap);
pLevelInfo->levelNumber = levelnum(i, j);
pLevelInfo->labelName = pMap; pLevelInfo->labelName = pMap;
pLevelInfo->fileName.Format("%s.map", pMap); pLevelInfo->fileName.Format("%s.map", pMap);
levelLoadMapInfo(BloodINI, pLevelInfo, pMap, i, j); levelLoadMapInfo(BloodINI, pLevelInfo, pMap, i, j);
@ -199,6 +200,7 @@ void levelLoadDefaults(void)
void levelAddUserMap(const char *pzMap) void levelAddUserMap(const char *pzMap)
{ {
// FIXME: Make this work with the reworked map system // FIXME: Make this work with the reworked map system
#if 0
char buffer[BMAX_PATH]; char buffer[BMAX_PATH];
strncpy(buffer, pzMap, BMAX_PATH); strncpy(buffer, pzMap, BMAX_PATH);
ChangeExtension(buffer, ".DEF"); ChangeExtension(buffer, ".DEF");
@ -223,13 +225,15 @@ void levelAddUserMap(const char *pzMap)
gGameOptions.nEpisode = nEpisode; gGameOptions.nEpisode = nEpisode;
gGameOptions.nLevel = nLevel; gGameOptions.nLevel = nLevel;
gGameOptions.uMapCRC = dbReadMapCRC(pLevelInfo->name); gGameOptions.uMapCRC = dbReadMapCRC(pLevelInfo->name);
strcpy(gGameOptions.zLevelName, pLevelInfo->name); #else
auto map = SetupUserMap(pzMap);
#endif
} }
void levelGetNextLevels(int nEpisode, int nLevel, int *pnEndingA, int *pnEndingB) void levelGetNextLevels(int nEpisode, int nLevel, int *pnEndingA, int *pnEndingB)
{ {
dassert(pnEndingA != NULL && pnEndingB != NULL); dassert(pnEndingA != NULL && pnEndingB != NULL);
auto pLevelInfo = &gEpisodeInfo[nEpisode].levels[nLevel]; auto pLevelInfo = FindMapByLevelNum(levelnum(nEpisode, nLevel));
int nEndingA = pLevelInfo->nextLevel; int nEndingA = pLevelInfo->nextLevel;
if (nEndingA >= 0) if (nEndingA >= 0)
nEndingA--; nEndingA--;
@ -305,15 +309,18 @@ int levelGetMusicIdx(const char *str)
bool levelTryPlayMusic(int nEpisode, int nLevel, bool bSetLevelSong) bool levelTryPlayMusic(int nEpisode, int nLevel, bool bSetLevelSong)
{ {
auto level = FindMapByLevelNum(levelnum(nEpisode, nLevel));
if (!level) return false;
FString buffer; FString buffer;
if (mus_redbook && gEpisodeInfo[nEpisode].levels[nLevel].cdSongId > 0) if (mus_redbook && level->cdSongId > 0)
buffer.Format("blood%02i.ogg", gEpisodeInfo[nEpisode].levels[nLevel].cdSongId); buffer.Format("blood%02i.ogg", level->cdSongId);
else else
{ {
buffer = gEpisodeInfo[nEpisode].levels[nLevel].music; buffer = level->music;
if (Mus_Play(level->labelName, buffer, true)) return true;
DefaultExtension(buffer, ".mid"); DefaultExtension(buffer, ".mid");
} }
return !!Mus_Play(gEpisodeInfo[nEpisode].levels[nLevel].labelName, buffer, true); return !!Mus_Play(level->labelName, buffer, true);
} }
void levelTryPlayMusicOrNothing(int nEpisode, int nLevel) void levelTryPlayMusicOrNothing(int nEpisode, int nLevel)

View file

@ -40,7 +40,6 @@ struct GAMEOPTIONS {
unsigned char nDifficulty; unsigned char nDifficulty;
int nEpisode; int nEpisode;
int nLevel; int nLevel;
char zLevelName[BMAX_PATH];
int nTrackNumber; //at12a; int nTrackNumber; //at12a;
short nSaveGameSlot; short nSaveGameSlot;
int picEntry; int picEntry;
@ -75,7 +74,6 @@ struct EPISODEINFO
int nLevels; int nLevels;
unsigned int bloodbath : 1; unsigned int bloodbath : 1;
unsigned int cutALevel : 4; unsigned int cutALevel : 4;
MapRecord* levels; // points into the global table.
char cutsceneAName[BMAX_PATH]; char cutsceneAName[BMAX_PATH];
char cutsceneBName[BMAX_PATH]; char cutsceneBName[BMAX_PATH];
int at9028; int at9028;

View file

@ -80,6 +80,23 @@ MapRecord *FindNextMap(MapRecord *thismap);
MapRecord* SetupUserMap(const char* boardfilename, const char *defaultmusic = nullptr); MapRecord* SetupUserMap(const char* boardfilename, const char *defaultmusic = nullptr);
MapRecord* AllocateMap(); MapRecord* AllocateMap();
// These should be the only places converting between level numbers and volume/map pairs
constexpr inline int levelnum(int vol, int map)
{
return vol * 1000 + map;
}
constexpr inline int volfromlevelnum(int num)
{
return num > 0 ? num / 1000 : 0;
}
constexpr inline int mapfromlevelnum(int num)
{
return num > 0 ? num % 1000 : -1;
}
enum enum
{ {
RRENDSLOT = 127 RRENDSLOT = 127

View file

@ -198,22 +198,6 @@ inline double get16thOfHoriz(int snum, bool interpolate, double smoothratio)
} }
// These should be the only places converting between level numbers and volume/map pairs
constexpr inline int levelnum(int vol, int map)
{
return vol * 1000 + map;
}
constexpr inline int volfromlevelnum(int num)
{
return num > 0 ? num / 1000 : 0;
}
constexpr inline int mapfromlevelnum(int num)
{
return num > 0 ? num % 1000 : -1;
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// //