- add RedirectCVAR directive for loading alternate maps based on a Bool CVAR setting

This commit is contained in:
Rachael Alexanderson 2023-01-30 16:45:03 -05:00 committed by Rachael Alexanderson
parent c8f3aa3fd1
commit 04ea28defc
3 changed files with 43 additions and 0 deletions

View file

@ -557,6 +557,12 @@ void G_InitNew (const char *mapname, bool bTitleLevel)
// [RH] Mark all levels as not visited
for (unsigned int i = 0; i < wadlevelinfos.Size(); i++)
wadlevelinfos[i].flags = wadlevelinfos[i].flags & ~LEVEL_VISITED;
auto redirectmap = FindLevelInfo(mapname);
if (redirectmap->RedirectCVAR != NAME_None)
redirectmap = redirectmap->CheckLevelRedirect();
if (redirectmap)
mapname = redirectmap->MapName;
}
UnlatchCVars ();

View file

@ -274,6 +274,8 @@ void level_info_t::Reset()
Translator = "";
RedirectType = NAME_None;
RedirectMapName = "";
RedirectCVAR = NAME_None;
RedirectCVARMapName = "";
EnterPic = "";
ExitPic = "";
Intermission = NAME_None;
@ -388,6 +390,27 @@ level_info_t *level_info_t::CheckLevelRedirect ()
}
}
}
if (RedirectCVAR != NAME_None)
{
auto var = FindCVar(RedirectCVAR.GetChars(), NULL);
if ((var->GetRealType() == CVAR_Bool) && !(var->GetFlags() & CVAR_IGNORE)) // only check Bool cvars that are currently defined
{
if (var->GetFlags() & CVAR_USERINFO)
{
// user sync'd cvar, check for all players
for (int i = 0; i < MAXPLAYERS; ++i)
{
if (playeringame[i] && (var = GetCVar(i, RedirectCVAR.GetChars())))
{
if (var->ToInt())
return FindLevelInfo(RedirectCVARMapName);
}
}
}
else if (var->ToInt())
return FindLevelInfo(RedirectCVARMapName);
}
}
return NULL;
}
@ -1299,6 +1322,15 @@ DEFINE_MAP_OPTION(redirect, true)
parse.ParseNextMap(info->RedirectMapName);
}
DEFINE_MAP_OPTION(cvar_redirect, true)
{
parse.ParseAssign();
parse.sc.MustGetString();
info->RedirectCVAR = parse.sc.String;
parse.ParseComma();
parse.ParseNextMap(info->RedirectCVARMapName);
}
DEFINE_MAP_OPTION(sndseq, true)
{
parse.ParseAssign();

View file

@ -380,6 +380,11 @@ struct level_info_t
FName RedirectType;
FString RedirectMapName;
// CVAR Redirection: If the CVAR Bool returns true, then
// you go to the RedirectMap instead of this one.
FName RedirectCVAR;
FString RedirectCVARMapName;
FString EnterPic;
FString ExitPic;
FString InterMusic;