# HG changeset patch # User Adam Kaminski # Date 1632451221 14400 # Thu Sep 23 22:40:21 2021 -0400 # Node ID ea6a08fe1a29ef93e1153d6ffe15886c94279cf2 # Parent 9e12d0bb6e3d9d60c8d7183c3a5e86a0b3617266 Cleaned up the ACS function "SetCurrentGamemode" and changed it so the name of the new game mode has to match its corresponding GAMEMODE_e enum. diff -r 9e12d0bb6e3d -r ea6a08fe1a29 src/p_acs.cpp --- a/src/p_acs.cpp Wed Sep 22 13:06:59 2021 -0400 +++ b/src/p_acs.cpp Thu Sep 23 22:40:21 2021 -0400 @@ -7298,64 +7298,61 @@ case ACSF_SetCurrentGamemode: { - const char *name = FBehavior::StaticLookupString( args[0] ); + // [AK] Only the server should change the game mode, but not during the result sequence. + if (( NETWORK_InClientMode()) || ( GAMEMODE_GetState() == GAMESTATE_INRESULTSEQUENCE )) + return 0; + + FString name = "GAMEMODE_"; + name += FBehavior::StaticLookupString( args[0] ); + name.ToUpper( ); + const GAMEMODE_e oldmode = GAMEMODE_GetCurrentMode(); - GAMEMODE_e newmode; - - // [AK] Only the server should change the gamemode, but not during the result sequence. - if ( NETWORK_InClientMode() || GAMEMODE_GetState() == GAMESTATE_INRESULTSEQUENCE ) + GAMEMODE_e newmode = static_cast( GetValueGAMEMODE_e( name )); + + // [AK] No need to change the game mode if it's invalid or if we're already playing it. + if (( newmode == -1 ) || ( newmode == oldmode )) return 0; - // [AK] No need to change the gamemode if we're already playing it. - if ( stricmp( name, GAMEMODE_GetName( oldmode )) == 0 ) + // [AK] Don't change to any team game if there's no team starts on the map! + if (( GAMEMODE_GetFlags( newmode ) & GMF_TEAMGAME ) && ( TEAM_GetNumTeamsWithStarts() < 1 )) return 0; - - for ( int i = 0; i < NUM_GAMEMODES; i++ ) - { - newmode = static_cast ( i ); - if ( stricmp( name, GAMEMODE_GetName( newmode )) != 0 ) - continue; - - // [AK] Don't change to any team game if there's no team starts on the map! - if (( GAMEMODE_GetFlags( newmode ) & GMF_TEAMGAME ) && TEAM_GetNumTeamsWithStarts() < 1 ) + + // [AK] Don't change to deathmatch if there's no deathmatch starts on the map! + if ( GAMEMODE_GetFlags( newmode ) & GMF_DEATHMATCH ) + { + if ( deathmatchstarts.Size() < 1 ) + return 0; + + // [AK] If we're changing to duel, don't change if there's too many active players. + if (( newmode == GAMEMODE_DUEL ) && ( GAME_CountActivePlayers() > 2 )) return 0; - // [AK] Don't change to deathmatch if there's no deathmatch starts on the map! - if ( GAMEMODE_GetFlags( newmode ) & GMF_DEATHMATCH ) - { - if ( deathmatchstarts.Size() < 1 ) - return 0; - - // [AK] If we're changing to duel, don't change if there's too many active players. - if ( newmode == GAMEMODE_DUEL && GAME_CountActivePlayers() > 2 ) - return 0; - } - // [AK] Don't change to cooperative if there's no cooperative starts on the map! - else if ( GAMEMODE_GetFlags( newmode ) & GMF_COOPERATIVE ) - { - ULONG ulNumSpawns = 0; - for ( ULONG ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) + } + // [AK] Don't change to cooperative if there's no cooperative starts on the map! + else if ( GAMEMODE_GetFlags( newmode ) & GMF_COOPERATIVE ) + { + ULONG ulNumSpawns = 0; + for ( ULONG ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) + { + if ( playerstarts[ulIdx].type != 0 ) { - if ( playerstarts[ulIdx].type != 0 ) - { - ulNumSpawns++; - break; - } + ulNumSpawns++; + break; } - - if ( ulNumSpawns < 1 ) - return 0; - } - - // [AK] If everything's okay now, change the gamemode. - GAMEMODE_SetCurrentMode( newmode ); - - // [AK] We should also start a new game, so just execute the "map" CCMD to do this. - FString command; - command.Format( "map %s", level.mapname ); - C_DoCommand( command.GetChars()); - return 1; - } - return 0; + } + + if ( ulNumSpawns < 1 ) + return 0; + } + + // [AK] If everything's okay now, change the gamemode. + GAMEMODE_SetCurrentMode( newmode ); + + // [AK] We should also start a new game, so just execute the "map" CCMD to do this. + FString command; + command.Format( "map %s", level.mapname ); + C_DoCommand( command ); + + return 1; } case ACSF_GetCurrentGamemode: