@@ -7129,20 +7129,46 @@ void CTFPlayer::HandleCommand_JoinClass( const char *pClassName, bool bAllowSpaw
71297129 }
71307130 else
71317131 {
7132+ #ifdef BDSBASE
7133+ int iChoices = 0;
7134+ int iClasses[TF_LAST_NORMAL_CLASS - 1] = {}; // -1 to remove the civilian from the randomness
7135+ int iCurrentClass = GetPlayerClass()->GetClassIndex();
7136+
7137+ for (iClass = TF_FIRST_NORMAL_CLASS; iClass < TF_LAST_NORMAL_CLASS; iClass++)
7138+ {
7139+ if (iClass != iCurrentClass && TFGameRules()->CanPlayerChooseClass(this, iClass))
7140+ {
7141+ iClasses[iChoices++] = iClass;
7142+ }
7143+ }
7144+
7145+ if (!iChoices)
7146+ {
7147+ if (TFGameRules()->CanPlayerChooseClass(this, iCurrentClass))
7148+ return;
7149+
7150+ // We failed to find a random class. Bring up the class menu again.
7151+ ShowViewPortPanel((GetTeamNumber() == TF_TEAM_RED) ? PANEL_CLASS_RED : PANEL_CLASS_BLUE);
7152+ return;
7153+ }
7154+
7155+ iClass = iClasses[random->RandomInt(0, iChoices - 1)];
7156+ #else
71327157 int iTries = 20;
71337158 // The player has selected Random class...so let's pick one for them.
7134- do{
7159+ do {
71357160 // Don't let them be the same class twice in a row
7136- iClass = random->RandomInt( TF_FIRST_NORMAL_CLASS, TF_LAST_NORMAL_CLASS - 1 ); // -1 to remove the civilian from the randomness
7161+ iClass = random->RandomInt(TF_FIRST_NORMAL_CLASS, TF_LAST_NORMAL_CLASS - 1); // -1 to remove the civilian from the randomness
71377162 iTries--;
7138- } while( iClass == GetPlayerClass()->GetClassIndex() || (iTries > 0 && !TFGameRules()->CanPlayerChooseClass(this,iClass)) );
7163+ } while ( iClass == GetPlayerClass()->GetClassIndex() || (iTries > 0 && !TFGameRules()->CanPlayerChooseClass(this, iClass)));
71397164
7140- if ( iTries <= 0 )
7165+ if (iTries <= 0)
71417166 {
71427167 // We failed to find a random class. Bring up the class menu again.
7143- ShowViewPortPanel( ( GetTeamNumber() == TF_TEAM_RED ) ? PANEL_CLASS_RED : PANEL_CLASS_BLUE );
7168+ ShowViewPortPanel(( GetTeamNumber() == TF_TEAM_RED) ? PANEL_CLASS_RED : PANEL_CLASS_BLUE);
71447169 return;
71457170 }
7171+ #endif
71467172 }
71477173
71487174 if ( TFGameRules() && TFGameRules()->State_Get() == GR_STATE_RND_RUNNING )
0 commit comments