# HG changeset patch # User Adam Kaminski # Date 1636993582 18000 # Mon Nov 15 11:26:22 2021 -0500 # Node ID 19e84da7d04ddaa2a272f8128ca62d012d765b68 # Parent 852a9121d66b23bc207299ccddf8d3b23068c625 SetPlayerClass can now assign random classes to players. diff -r 852a9121d66b -r 19e84da7d04d src/p_acs.cpp --- a/src/p_acs.cpp Mon Nov 15 08:50:50 2021 -0500 +++ b/src/p_acs.cpp Mon Nov 15 11:26:22 2021 -0500 @@ -168,6 +168,9 @@ extern FILE *Logfile; +// [AK] We need this for SetPlayerClass. +extern FRandom pr_classchoice; + FRandom pr_acs ("ACS"); // I imagine this much stack space is probably overkill, but it could @@ -7401,21 +7404,34 @@ return 0; const char *classname = FBehavior::StaticLookupString( args[1] ); - const PClass *playerclass = PClass::FindClass( classname ); - - // [AK] Stop if the class provided doesn't exist or isn't a descendant of PlayerPawn. - // Also check if the player isn't already playing as the same class. - if ( playerclass == NULL || !playerclass->IsDescendantOf( RUNTIME_CLASS( APlayerPawn )) || player->cls == playerclass ) - return 0; - - // [AK] Don't change the player's class if it's not allowed. - if ( !TEAM_IsActorAllowedForPlayer( GetDefaultByType( playerclass ), player ) ) - return 0; - - player->userinfo.PlayerClassChanged( playerclass->Meta.GetMetaString( APMETA_DisplayName )); - // [AK] In a singleplayer game, we must also change the class the player would start as. - if ( NETWORK_GetState() != NETSTATE_SERVER ) - SinglePlayerClass[args[0]] = player->userinfo.GetPlayerClassNum(); + + if ( stricmp( classname, "random" ) == 0 ) + { + player->userinfo.PlayerClassNumChanged( -1 ); + + // [AK] In a singleplayer game, we must also change the class the player would start as. + if ( NETWORK_GetState() != NETSTATE_SERVER ) + SinglePlayerClass[args[0]] = ( pr_classchoice() ) % PlayerClasses.Size(); + } + else + { + const PClass *playerclass = PClass::FindClass( classname ); + + // [AK] Stop if the class provided doesn't exist or isn't a descendant of PlayerPawn. + // Also check if the player isn't already playing as the same class. + if ( playerclass == NULL || !playerclass->IsDescendantOf( RUNTIME_CLASS( APlayerPawn )) || player->cls == playerclass ) + return 0; + + // [AK] Don't change the player's class if it's not allowed. + if ( !TEAM_IsActorAllowedForPlayer( GetDefaultByType( playerclass ), player ) ) + return 0; + + player->userinfo.PlayerClassChanged( playerclass->Meta.GetMetaString( APMETA_DisplayName )); + + // [AK] In a singleplayer game, we must also change the class the player would start as. + if ( NETWORK_GetState() != NETSTATE_SERVER ) + SinglePlayerClass[args[0]] = player->userinfo.GetPlayerClassNum(); + } if ( bRespawn && PLAYER_IsValidPlayerWithMo( args[0] ) ) {