- added a mapinfo dumper and used it to verify correctness of the data generated from game-native definitions.

Also simplified the levelnumber setup a bit.
This commit is contained in:
Christoph Oelckers 2021-05-03 23:00:24 +02:00
parent 020a636c2f
commit a303da37a9
5 changed files with 99 additions and 64 deletions

View File

@ -651,6 +651,94 @@ MapFlagHandlers[] =
{ NULL, MITYPE_IGNORE, 0, 0}
};
void PrintCutscene(const char* name, CutsceneDef& cut)
{
if (cut.function.IsEmpty() && cut.video.IsEmpty()) return;
Printf("\t%s\n\t{\n", name);
if (cut.function.IsNotEmpty())
{
Printf("\t\tfunction = %s\n", cut.function.GetChars());
}
if (cut.video.IsNotEmpty())
{
Printf("\t\tvideo = \"%s\"\n", cut.video.GetChars());
}
if (cut.soundName.IsNotEmpty())
{
Printf("\t\tsound = \"%s\"\n", cut.soundName.GetChars());
}
Printf("\t}\n");
}
CCMD(mapinfo)
{
for (auto& vol : volumes)
{
Printf("episode %s\n{\n", vol.startmap.GetChars());
if (vol.name.IsNotEmpty()) Printf("\tname = \"%s\"\n", vol.name.GetChars());
if (vol.subtitle.IsNotEmpty()) Printf("\tsubtitle = \"%s\"\n{\n", vol.subtitle.GetChars());
Printf("}\n");
}
for (auto& clust : clusters)
{
Printf("cluster %d\n{\n", clust.index);
if (clust.name.IsNotEmpty()) Printf("\tname = \"%s\"\n", clust.name.GetChars());
if (clust.InterBackground.IsNotEmpty()) Printf("\tInterBackground = %s\n", clust.InterBackground.GetChars());
PrintCutscene("intro", clust.intro);
PrintCutscene("outro", clust.outro);
PrintCutscene("gameover", clust.gameover);
Printf("}\n");
}
for (auto& map : mapList)
{
int lump = fileSystem.FindFile(map->fileName);
if (lump >= 0)
{
int rfnum = fileSystem.GetFileContainer(lump);
Printf("map %s \"%s\"\n{\n", map->labelName.GetChars(), map->DisplayName());
Printf("\tlevelnum = %d\n\tCluster = %d\n", map->levelNumber, map->cluster);
if (map->Author.IsNotEmpty())
{
FString auth = map->Author;
auth.Substitute("\"", "\\\"");
Printf("\tAuthor = \"%s\"\n", auth.GetChars());
}
if (map->NextMap.IsNotEmpty()) Printf("\tNext = %s\n", map->NextMap.GetChars());
if (map->NextSecret.IsNotEmpty()) Printf("\tSecretNext = %s\n", map->NextSecret.GetChars());
if (map->InterBackground.IsNotEmpty()) Printf("\tInterBackground = %s\n", map->InterBackground.GetChars());
if (map->music.IsNotEmpty()) Printf("\tMusic = \"%s\"\n", map->music.GetChars());
if (map->musicorder > 0) Printf("\tMusicorder = %d\n", map->musicorder);
if (map->cdSongId > 0) Printf("\tCDtrack = %d\n", map->cdSongId);
if (map->parTime) Printf("\tParTime = %d\n", map->parTime);
if (map->designerTime) Printf("\tDesignerTime = %d\n", map->designerTime);
for (int i = 0; i < MAX_MESSAGES; i++)
{
if (map->messages[i].IsNotEmpty()) Printf("\tMessage = %d, \"%s\"\n", i + 1, map->messages[i]);
}
for (auto& flagh : MapFlagHandlers)
{
if (flagh.type == MITYPE_SETFLAG)
{
if (map->flags & flagh.data1) Printf("\t%s\n", flagh.name);
}
if (flagh.type == MITYPE_SETFLAGG)
{
if (map->gameflags & flagh.data1) Printf("\t%s\n", flagh.name);
}
}
PrintCutscene("intro", map->intro);
PrintCutscene("outro", map->outro);
Printf("}\n");
}
else
{
//Printf("%s - %s (defined but does not exist)\n", map->fileName.GetChars(), map->DisplayName());
}
}
}
//==========================================================================
//
// ParseMapDefinition
@ -786,7 +874,7 @@ static int GetDefaultLevelNum(const char *mapname)
(mapname[2] == 'M' || mapname[2] == 'L') &&
mapname[3] >= '0' && mapname[3] <= '9')
{
int epinum = mapname[1] - '1';
int epinum = mapname[1] - '0';
int mapnum = mapname[3] - '0';
return makelevelnum(epinum, mapnum);
}
@ -837,7 +925,7 @@ MapRecord *FMapInfoParser::ParseMapHeader(MapRecord &defaultinfo)
if (map != &sink && map->name.IsEmpty()) sc.ScriptError("Missing level name");
sc.UnGet();
}
map->levelNumber = GetDefaultLevelNum(map->labelName);
if (!map->levelNumber) map->levelNumber = GetDefaultLevelNum(map->labelName);
return map;
}
@ -1218,6 +1306,7 @@ void G_ParseMapInfo ()
}
// Parse any extra RMAPINFOs.
lastlump = 0;
while ((lump = fileSystem.FindLump ("RMAPINFO", &lastlump, false)) != -1)
{
FMapInfoParser parse;

View File

@ -68,59 +68,6 @@ CCMD(listmaps)
}
}
CCMD(mapinfo)
{
const char* mapname = nullptr;
if (argv.argc() > 1) mapname = argv[1];
if (!mapname)
{
for (auto& vol : volumes)
{
Printf("Volume %d\n\tName = '%s'\n\tstartmap = '%s'\n}\n", vol.index, vol.name.GetChars(), vol.startmap.GetChars());
}
for (auto& clus : clusters)
{
if (clus.intro.isdefined() || clus.outro.isdefined())
{
Printf("Cluster %d\n\tName = '%s'\n", clus.index, clus.name.GetChars());
if (clus.intro.function.IsNotEmpty()) Printf("\tIntro function = %s\n", clus.intro.function.GetChars());
if (clus.intro.video.IsNotEmpty()) Printf("\tIntro video = %s\n", clus.intro.video.GetChars());
if (clus.outro.function.IsNotEmpty()) Printf("\tOutro function = %s\n", clus.outro.function.GetChars());
if (clus.outro.video.IsNotEmpty()) Printf("\tOutro video = %s\n", clus.outro.video.GetChars());
Printf("}\n");
}
}
}
for (auto& map : mapList)
{
if (mapname && map->labelName.CompareNoCase(mapname)) continue;
int lump = fileSystem.FindFile(map->fileName);
if (lump >= 0)
{
int rfnum = fileSystem.GetFileContainer(lump);
Printf("%s - %s (%s)\n{\n", map->fileName.GetChars(), map->DisplayName(), fileSystem.GetResourceFileName(rfnum));
Printf("\tlevel number = %d\n\tCluster = %d\n\tIndex = %d\n", map->levelNumber, map->cluster, map->mapindex);
if (map->Author.IsNotEmpty()) Printf("\tAuthor = '%s'\n", map->Author.GetChars());
if (map->NextMap.IsNotEmpty()) Printf("\tNext map = '%s'\n", map->NextMap.GetChars());
if (map->NextSecret.IsNotEmpty()) Printf("\tNext secret map = '%s'\n", map->NextSecret.GetChars());
if (map->music.IsNotEmpty()) Printf("\tMusic = '%s:%d'", map->music.GetChars(), map->musicorder);
if (map->cdSongId > 0) Printf("\tCD track = %d\n", map->cdSongId);
if (map->parTime) Printf("\tPar Time = %d\n", map->parTime);
if (map->designerTime) Printf("\tPar Time = %d\n", map->designerTime);
if (map->intro.function.IsNotEmpty()) Printf("\tIntro function = %s\n", map->intro.function.GetChars());
if (map->intro.video.IsNotEmpty()) Printf("\tIntro video = %s\n", map->intro.video.GetChars());
if (map->outro.function.IsNotEmpty()) Printf("\tOutro function = %s\n", map->outro.function.GetChars());
if (map->outro.video.IsNotEmpty()) Printf("\tOutro video = %s\n", map->outro.video.GetChars());
Printf("}\n");
}
else
{
Printf("%s - %s (defined but does not exist)\n", map->fileName.GetChars(), map->DisplayName());
}
}
}
int CutsceneDef::GetSound()
{
int id;
@ -185,9 +132,10 @@ VolumeRecord* AllocateVolume()
MapRecord* FindMapByIndexOnly(int cluster, int num)
{
int levelnum = makelevelnum(cluster, num);
for (auto& map : mapList)
{
if (map->mapindex == num && map->cluster == cluster) return map.Data();
if (map->levelNumber == levelnum) return map.Data();
}
return nullptr;
}
@ -195,7 +143,7 @@ MapRecord* FindMapByIndexOnly(int cluster, int num)
MapRecord* FindMapByIndex(int cluster, int num)
{
auto map = FindMapByLevelNum(num);
if (!map) map = FindMapByIndexOnly(cluster, num); // modern definitions take precedence.
if (!map && num < 1000) map = FindMapByLevelNum(makelevelnum(cluster, num));
return map;
}

View File

@ -115,7 +115,6 @@ struct ClusterDef
FString InterBackground;
int index = -1;
int flags = 0; // engine and common flags
int gameflags = 0; // game specific flags.
};
struct VolumeRecord // episodes
@ -147,7 +146,6 @@ struct MapRecord
int flags = 0;
int gameflags = 0;
int levelNumber = -1;
int mapindex = -1; // index in the episode. This only for finding the next map in the progression when nothing explicit is defined.
int cluster = -1;
PalEntry fadeto = 0;

View File

@ -97,7 +97,7 @@ void levelLoadMapInfo(IniFile* pIni, MapRecord* pLevelInfo, const char* pzSectio
char buffer[16];
pLevelInfo->SetName(pIni->GetKeyString(pzSection, "Title", pLevelInfo->labelName));
pLevelInfo->Author = pIni->GetKeyString(pzSection, "Author", "");
pLevelInfo->music = pIni->GetKeyString(pzSection, "Song", ""); DefaultExtension(pLevelInfo->music, ".mid");
pLevelInfo->music = pIni->GetKeyString(pzSection, "Song", ""); if (pLevelInfo->music.IsNotEmpty()) DefaultExtension(pLevelInfo->music, ".mid");
pLevelInfo->cdSongId = pIni->GetKeyInt(pzSection, "Track", -1);
*nextmap = pIni->GetKeyInt(pzSection, "EndingA", 0);
*nextsecret = pIni->GetKeyInt(pzSection, "EndingB", 0);
@ -193,7 +193,6 @@ void levelLoadDefaults(void)
CheckSectionAbend(pMap);
SetLevelNum(pLevelInfo, makelevelnum(i, j));
pLevelInfo->cluster = i;
pLevelInfo->mapindex = j;
pLevelInfo->labelName = pMap;
if (j == 1) volume->startmap = pLevelInfo->labelName;
pLevelInfo->fileName.Format("%s.map", pMap);
@ -219,12 +218,14 @@ void levelLoadDefaults(void)
if (nmap) map->NextMap = nmap->labelName;
else map->NextMap = "-";
}
else map->NextMap = "-";
if (nextsecrets[j - 1] > 0)
{
auto nmap = FindMapByIndexOnly(i, nextsecrets[j - 1]);
if (nmap) map->NextSecret = nmap->labelName;
else map->NextSecret = "-";
}
else map->NextSecret = "-";
}
}
}
@ -246,7 +247,7 @@ void levelTryPlayMusic()
{
buffer = currentLevel->music;
if (Mus_Play(currentLevel->labelName, buffer, true)) return;
DefaultExtension(buffer, ".mid");
if (buffer.IsNotEmpty()) DefaultExtension(buffer, ".mid");
}
if (!Mus_Play(currentLevel->labelName, buffer, true))
{

View File

@ -1728,7 +1728,6 @@ int ConCompiler::parsecommand()
SetLevelNum(map, makelevelnum(j + 1, k + 1));
map->mapindex = k + 1;
map->cluster = j + 1;
textptr += 5;
@ -3236,7 +3235,7 @@ void loadcons()
{
if (map->cluster == 1)
{
if (!FindMapByIndexOnly(map->cluster, map->mapindex + 1))
if (!FindMapByLevelNum(map->levelNumber + 1))
{
auto nextmap = FindMapByIndexOnly(map->cluster + 1, 1);
if (nextmap)