Skip to content

Commit

Permalink
- add RedirectCVAR directive for loading alternate maps based on a Bo…
Browse files Browse the repository at this point in the history
…ol CVAR setting
  • Loading branch information
madame-rachelle committed Feb 1, 2023
1 parent c8f3aa3 commit 04ea28d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/g_level.cpp
Expand Up @@ -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 ();
Expand Down
32 changes: 32 additions & 0 deletions src/gamedata/g_mapinfo.cpp
Expand Up @@ -274,6 +274,8 @@ void level_info_t::Reset()
Translator = "";
RedirectType = NAME_None;
RedirectMapName = "";
RedirectCVAR = NAME_None;
RedirectCVARMapName = "";
EnterPic = "";
ExitPic = "";
Intermission = NAME_None;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/gamedata/g_mapinfo.h
Expand Up @@ -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;
Expand Down

0 comments on commit 04ea28d

Please sign in to comment.