This is a fork of Zandronum used on servers hosted by The Sentinels Playground (TSPG).
Revision | 005e26e8bfa2d4572b2f996d539ada8283234726 (tree) |
---|---|
Time | 2021-09-24 11:40:21 |
Author | Adam Kaminski <kaminskiadam9@gmai...> |
Commiter | Adam Kaminski |
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.
@@ -7298,64 +7298,66 @@ | ||
7298 | 7298 | |
7299 | 7299 | case ACSF_SetCurrentGamemode: |
7300 | 7300 | { |
7301 | - const char *name = FBehavior::StaticLookupString( args[0] ); | |
7302 | - const GAMEMODE_e oldmode = GAMEMODE_GetCurrentMode(); | |
7303 | - GAMEMODE_e newmode; | |
7304 | - | |
7305 | - // [AK] Only the server should change the gamemode, but not during the result sequence. | |
7306 | - if ( NETWORK_InClientMode() || GAMEMODE_GetState() == GAMESTATE_INRESULTSEQUENCE ) | |
7301 | + // [AK] Only the server should change the game mode, but not during the result sequence. | |
7302 | + if (( NETWORK_InClientMode()) || ( GAMEMODE_GetState() == GAMESTATE_INRESULTSEQUENCE )) | |
7307 | 7303 | return 0; |
7308 | 7304 | |
7309 | - // [AK] No need to change the gamemode if we're already playing it. | |
7310 | - if ( stricmp( name, GAMEMODE_GetName( oldmode )) == 0 ) | |
7305 | + FString name = "GAMEMODE_"; | |
7306 | + name += FBehavior::StaticLookupString( args[0] ); | |
7307 | + name.ToUpper( ); | |
7308 | + | |
7309 | + const GAMEMODE_e oldmode = GAMEMODE_GetCurrentMode(); | |
7310 | + | |
7311 | + // [AK] Don't accept invalid game mode names. | |
7312 | + int gamemode = GetValueGAMEMODE_e( name ); | |
7313 | + if ( gamemode == -1 ) | |
7311 | 7314 | return 0; |
7312 | 7315 | |
7313 | - for ( int i = 0; i < NUM_GAMEMODES; i++ ) | |
7314 | - { | |
7315 | - newmode = static_cast<GAMEMODE_e> ( i ); | |
7316 | - if ( stricmp( name, GAMEMODE_GetName( newmode )) != 0 ) | |
7317 | - continue; | |
7318 | - | |
7319 | - // [AK] Don't change to any team game if there's no team starts on the map! | |
7320 | - if (( GAMEMODE_GetFlags( newmode ) & GMF_TEAMGAME ) && TEAM_GetNumTeamsWithStarts() < 1 ) | |
7316 | + // [AK] No need to change the game mode if we're already playing it. | |
7317 | + GAMEMODE_e newmode = static_cast<GAMEMODE_e>( gamemode ); | |
7318 | + if ( newmode == oldmode ) | |
7319 | + return 0; | |
7320 | + | |
7321 | + // [AK] Don't change to any team game if there's no team starts on the map! | |
7322 | + if (( GAMEMODE_GetFlags( newmode ) & GMF_TEAMGAME ) && ( TEAM_GetNumTeamsWithStarts() < 1 )) | |
7323 | + return 0; | |
7324 | + | |
7325 | + // [AK] Don't change to deathmatch if there's no deathmatch starts on the map! | |
7326 | + if ( GAMEMODE_GetFlags( newmode ) & GMF_DEATHMATCH ) | |
7327 | + { | |
7328 | + if ( deathmatchstarts.Size() < 1 ) | |
7321 | 7329 | return 0; |
7322 | - // [AK] Don't change to deathmatch if there's no deathmatch starts on the map! | |
7323 | - if ( GAMEMODE_GetFlags( newmode ) & GMF_DEATHMATCH ) | |
7324 | - { | |
7325 | - if ( deathmatchstarts.Size() < 1 ) | |
7326 | - return 0; | |
7327 | - | |
7328 | - // [AK] If we're changing to duel, don't change if there's too many active players. | |
7329 | - if ( newmode == GAMEMODE_DUEL && GAME_CountActivePlayers() > 2 ) | |
7330 | - return 0; | |
7331 | - } | |
7332 | - // [AK] Don't change to cooperative if there's no cooperative starts on the map! | |
7333 | - else if ( GAMEMODE_GetFlags( newmode ) & GMF_COOPERATIVE ) | |
7334 | - { | |
7335 | - ULONG ulNumSpawns = 0; | |
7336 | - for ( ULONG ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) | |
7330 | + | |
7331 | + // [AK] If we're changing to duel, don't change if there's too many active players. | |
7332 | + if (( newmode == GAMEMODE_DUEL ) && ( GAME_CountActivePlayers() > 2 )) | |
7333 | + return 0; | |
7334 | + } | |
7335 | + // [AK] Don't change to cooperative if there's no cooperative starts on the map! | |
7336 | + else if ( GAMEMODE_GetFlags( newmode ) & GMF_COOPERATIVE ) | |
7337 | + { | |
7338 | + ULONG ulNumSpawns = 0; | |
7339 | + for ( ULONG ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) | |
7340 | + { | |
7341 | + if ( playerstarts[ulIdx].type != 0 ) | |
7337 | 7342 | { |
7338 | - if ( playerstarts[ulIdx].type != 0 ) | |
7339 | - { | |
7340 | - ulNumSpawns++; | |
7341 | - break; | |
7342 | - } | |
7343 | + ulNumSpawns++; | |
7344 | + break; | |
7343 | 7345 | } |
7344 | - | |
7345 | - if ( ulNumSpawns < 1 ) | |
7346 | - return 0; | |
7347 | - } | |
7348 | - | |
7349 | - // [AK] If everything's okay now, change the gamemode. | |
7350 | - GAMEMODE_SetCurrentMode( newmode ); | |
7351 | - | |
7352 | - // [AK] We should also start a new game, so just execute the "map" CCMD to do this. | |
7353 | - FString command; | |
7354 | - command.Format( "map %s", level.mapname ); | |
7355 | - C_DoCommand( command.GetChars()); | |
7356 | - return 1; | |
7357 | - } | |
7358 | - return 0; | |
7346 | + } | |
7347 | + | |
7348 | + if ( ulNumSpawns < 1 ) | |
7349 | + return 0; | |
7350 | + } | |
7351 | + | |
7352 | + // [AK] If everything's okay now, change the gamemode. | |
7353 | + GAMEMODE_SetCurrentMode( newmode ); | |
7354 | + | |
7355 | + // [AK] We should also start a new game, so just execute the "map" CCMD to do this. | |
7356 | + FString command; | |
7357 | + command.Format( "map %s", level.mapname ); | |
7358 | + C_DoCommand( command ); | |
7359 | + | |
7360 | + return 1; | |
7359 | 7361 | } |
7360 | 7362 | |
7361 | 7363 | case ACSF_GetCurrentGamemode: |