# HG changeset patch # User Adam Kaminski # Date 1632671991 14400 # Sun Sep 26 11:59:51 2021 -0400 # Node ID 949c88c5c08ad17c09b530ad26b28878d606b3c6 # Parent 81f94e9cac8f4e9d2aca957a0117bf1e827b6ce0 Added "DefaultGameSettings" and "DefaultLockedGameSettings" blocks to GAMEMODE so that gameplay/compatibility flags can be enabled or disabled across all game modes. diff -r 81f94e9cac8f -r 949c88c5c08a src/gamemode.cpp --- a/src/gamemode.cpp Sun Sep 26 10:46:39 2021 -0400 +++ b/src/gamemode.cpp Sun Sep 26 11:59:51 2021 -0400 @@ -210,38 +210,7 @@ } else if ((0 == stricmp (sc.String, "gamesettings")) || (0 == stricmp (sc.String, "lockedgamesettings"))) { - bool bLockFlags = !stricmp( sc.String, "lockedgamesettings" ); - - sc.MustGetStringName( "{" ); - while ( !sc.CheckString( "}" )) - { - FFlagCVar *flag = GAMEMODE_ParserMustGetFlagset( sc, GameMode, flagset ); - ULONG ulBit = flag->GetBitVal(); - bool bEnableFlag; - - // [AK] There must be an equal sign following the name of the flag. - sc.MustGetStringName( "=" ); - sc.GetString(); - - if ( stricmp( sc.String, "true" ) == 0 ) - bEnableFlag = true; - else if ( stricmp( sc.String, "false" ) == 0 ) - bEnableFlag = false; - else - bEnableFlag = !!atoi( sc.String ); - - // [AK] Enable or disable the flag as desired. - if ( bEnableFlag ) - g_GameModes[GameMode].lFlagsets[flagset][FLAGSET_VALUE] |= ulBit; - else - g_GameModes[GameMode].lFlagsets[flagset][FLAGSET_VALUE] &= ~ulBit; - - g_GameModes[GameMode].lFlagsets[flagset][FLAGSET_MASK] |= ulBit; - - // [AK] Lock this flag so it can't be manually changed. - if ( bLockFlags ) - g_GameModes[GameMode].lFlagsets[flagset][FLAGSET_LOCKEDMASK] |= ulBit; - } + GAMEMODE_ParseGameSettingBlock( sc, GameMode, !stricmp( sc.String, "lockedgamesettings" )); } else if (0 == stricmp (sc.String, "removegamesetting")) { @@ -273,28 +242,117 @@ //***************************************************************************** // +void GAMEMODE_ParseGameSettingBlock ( FScanner &sc, const GAMEMODE_e GameMode, bool bLockFlags, bool bResetFlags ) +{ + FLAGSET_e flagset; + sc.MustGetStringName( "{" ); + + // [AK] If this is the start of a "defaultgamesettings" or "defaultlockedgamesettings" block, reset the + // flagsets of all game modes to zero. We don't want to do this more than once in a single GAMEMODE lump, + // in case both blocks are declared in the same lump. + if (( GameMode == NUM_GAMEMODES ) && ( bResetFlags )) + { + for ( unsigned int mode = GAMEMODE_COOPERATIVE; mode < NUM_GAMEMODES; mode++ ) + { + for ( unsigned int set = FLAGSET_DMFLAGS; set < NUM_FLAGSETS; set++ ) + { + g_GameModes[mode].lFlagsets[set][FLAGSET_VALUE] = 0; + g_GameModes[mode].lFlagsets[set][FLAGSET_MASK] = 0; + g_GameModes[mode].lFlagsets[set][FLAGSET_LOCKEDMASK] = 0; + } + } + } + + while ( !sc.CheckString( "}" )) + { + FFlagCVar *flag = GAMEMODE_ParserMustGetFlagset( sc, GameMode, flagset ); + ULONG ulBit = flag->GetBitVal(); + bool bEnableFlag; + + // [AK] There must be an equal sign following the name of the flag. + sc.MustGetStringName( "=" ); + sc.GetString(); + + if ( stricmp( sc.String, "true" ) == 0 ) + bEnableFlag = true; + else if ( stricmp( sc.String, "false" ) == 0 ) + bEnableFlag = false; + else + bEnableFlag = !!atoi( sc.String ); + + // [AK] If this flag was added inside a "defaultgamesettings" or "defaultlockedgamesettings" block, apply + // it to all the game modes. Otherwise, just apply it to the one we specified. + if ( GameMode == NUM_GAMEMODES ) + { + for ( unsigned int mode = GAMEMODE_COOPERATIVE; mode < NUM_GAMEMODES; mode++ ) + { + // [AK] Enable or disable the flag as desired. + if ( bEnableFlag ) + g_GameModes[mode].lFlagsets[flagset][FLAGSET_VALUE] |= ulBit; + else + g_GameModes[mode].lFlagsets[flagset][FLAGSET_VALUE] &= ~ulBit; + + g_GameModes[mode].lFlagsets[flagset][FLAGSET_MASK] |= ulBit; + + // [AK] Lock this flag so it can't be manually changed. + if ( bLockFlags ) + g_GameModes[mode].lFlagsets[flagset][FLAGSET_LOCKEDMASK] |= ulBit; + } + } + else + { + // [AK] Enable or disable the flag as desired. + if ( bEnableFlag ) + g_GameModes[GameMode].lFlagsets[flagset][FLAGSET_VALUE] |= ulBit; + else + g_GameModes[GameMode].lFlagsets[flagset][FLAGSET_VALUE] &= ~ulBit; + + g_GameModes[GameMode].lFlagsets[flagset][FLAGSET_MASK] |= ulBit; + + // [AK] Lock this flag so it can't be manually changed. + if ( bLockFlags ) + g_GameModes[GameMode].lFlagsets[flagset][FLAGSET_LOCKEDMASK] |= ulBit; + } + } +} + +//***************************************************************************** +// void GAMEMODE_ParseGamemodeInfo( void ) { int lastlump = 0, lump; - // [AK] Before we start parsing any GAMEMODE lumps, initialize the flagset values used by all game modes to zero. - for ( unsigned int gamemode = GAMEMODE_COOPERATIVE; gamemode < NUM_GAMEMODES; gamemode++ ) - { - for ( unsigned int flagset = FLAGSET_DMFLAGS; flagset < NUM_FLAGSETS; flagset++ ) - { - g_GameModes[gamemode].lFlagsets[flagset][FLAGSET_VALUE] = 0; - g_GameModes[gamemode].lFlagsets[flagset][FLAGSET_MASK] = 0; - g_GameModes[gamemode].lFlagsets[flagset][FLAGSET_LOCKEDMASK] = 0; - } - } - while ((lump = Wads.FindLump ("GAMEMODE", &lastlump)) != -1) { FScanner sc(lump); + bool bParsedDefGameSettings = false; + bool bParsedDefLockedSettings = false; + while (sc.GetString ()) { - GAMEMODE_e GameMode = static_cast( GAMEMODE_ParserMustGetEnumName( sc, "gamemode", "GAMEMODE_", GetValueGAMEMODE_e, true ) ); - GAMEMODE_ParseGamemodeInfoLump ( sc, GameMode ); + if (stricmp(sc.String, "defaultgamesettings") == 0) + { + // [AK] Don't allow more than one "defaultgamesettings" block in the same lump. + if ( bParsedDefGameSettings ) + sc.ScriptError( "There is already a \"DefaultGameSettings\" block defined in this lump." ); + + GAMEMODE_ParseGameSettingBlock( sc, NUM_GAMEMODES, false, !( bParsedDefGameSettings || bParsedDefLockedSettings ) ); + bParsedDefGameSettings = true; + } + else if (stricmp(sc.String, "defaultlockedgamesettings") == 0) + { + // [AK] Don't allow more than one "defaultlockedgamesettings" block in the same lump. + if ( bParsedDefLockedSettings ) + sc.ScriptError( "There is already a \"DefaultLockedGameSettings\" block defined in this lump." ); + + GAMEMODE_ParseGameSettingBlock( sc, NUM_GAMEMODES, true, !( bParsedDefGameSettings || bParsedDefLockedSettings ) ); + bParsedDefLockedSettings = true; + } + else + { + GAMEMODE_e GameMode = static_cast( GAMEMODE_ParserMustGetEnumName( sc, "gamemode", "GAMEMODE_", GetValueGAMEMODE_e, true ) ); + GAMEMODE_ParseGamemodeInfoLump ( sc, GameMode ); + } } } diff -r 81f94e9cac8f -r 949c88c5c08a src/gamemode.h --- a/src/gamemode.h Sun Sep 26 10:46:39 2021 -0400 +++ b/src/gamemode.h Sun Sep 26 11:59:51 2021 -0400 @@ -174,6 +174,7 @@ void GAMEMODE_Tick( void ); void GAMEMODE_ParseGamemodeInfoLump ( FScanner &sc, const GAMEMODE_e GameMode ); +void GAMEMODE_ParseGameSettingBlock ( FScanner &sc, const GAMEMODE_e GameMode, bool bLockFlags, bool bResetFlags = false ); void GAMEMODE_ParseGamemodeInfo( void ); ULONG GAMEMODE_GetFlags( GAMEMODE_e GameMode ); ULONG GAMEMODE_GetCurrentFlags( void ); diff -r 81f94e9cac8f -r 949c88c5c08a wadsrc/static/gamemode.txt --- a/wadsrc/static/gamemode.txt Sun Sep 26 10:46:39 2021 -0400 +++ b/wadsrc/static/gamemode.txt Sun Sep 26 11:59:51 2021 -0400 @@ -1,3 +1,8 @@ +// [AK] This is just to initialize the flagsets of all game modes to zero. +DefaultGameSettings +{ +} + // Regular co-op Cooperative {