Browse Source

Streamline class count function

I don't even use this.
nosoop 6 years ago
parent
commit
347394f7e3
1 changed files with 16 additions and 45 deletions
  1. 16 45
      scripting/botmanager.sp

+ 16 - 45
scripting/botmanager.sp

@@ -5,7 +5,7 @@
 #include <tf2>
 #include <tf2_stocks>
 
-#define PLUGIN_VERSION			"1.3.3"
+#define PLUGIN_VERSION			"1.3.4"
 
 public Plugin:myinfo = {
 	name		= "[TF2] Bot Manager",
@@ -164,41 +164,22 @@ AddBot() {
 	new TFClassType:class = TFClass_Unknown;
 	
 	if(!GetConVarBool(cvarGameLogic)) {
-		new scout, soldier, pyro, demoman, heavy, engineer, medic, sniper, spy;
-		GetClassCounts(team, scout, soldier, pyro, demoman, heavy, engineer, medic, sniper, spy);
-		if(medic == 0) {
+		int numClass[TFClassType];
+		GetClassCounts(team, numClass);
+		if(!numClass[TFClass_Medic]) {
 			class = TFClass_Medic;
 		} else {
-			new least = scout;
-			class = TFClass_Scout;
-			if(soldier < least) {
-				least = soldier;
-				class = TFClass_Soldier;
-			}
-			if(pyro < least) {
-				least = pyro;
-				class = TFClass_Pyro;
-			}
-			if(demoman < least) {
-				least = demoman;
-				class = TFClass_DemoMan;
-			}
-			if(heavy < least) {
-				least = heavy;
-				class = TFClass_Heavy;
-			}
-			if(engineer < least) {
-				least = engineer;
-				class = TFClass_Engineer;
-			}
-			if(sniper < least) {
-				least = sniper;
-				class = TFClass_Sniper;
-			}
-			if(spy < least) {
-				least = spy;
-				class = TFClass_Spy;
+			static TFClassType iter[] = { TFClass_Scout, TFClass_Soldier, TFClass_Pyro,
+					TFClass_DemoMan, TFClass_Heavy, TFClass_Engineer, TFClass_Sniper,
+					TFClass_Spy };
+			
+			TFClassType lowest = TFClass_Scout;
+			for (int i = 1; i < sizeof(iter); i++) {
+				if (numClass[ iter[i] ] < numClass[lowest]) {
+					lowest = iter[i];
+				}
 			}
+			class = lowest;
 		}
 	}
 	
@@ -251,22 +232,12 @@ AddBot() {
 	ServerCommand("tf_bot_add %s %s %s %s", strDifficulty, strTeam, strClass, quotedName); // count class team difficulty name (any order)
 }
 
-GetClassCounts(TFTeam:team, &scout, &soldier, &pyro, &demoman, &heavy, &engineer, &medic, &sniper, &spy) {
+GetClassCounts(TFTeam:team, int numClass[TFClassType]) {
 	for(new i = 1; i <= MaxClients; i++) {
 		if(!IsClientInGame(i) || TFTeam:GetClientTeam(i) != team) {
 			continue;
 		}
-		switch(TF2_GetPlayerClass(i)) {
-			case TFClass_Scout: scout++;
-			case TFClass_Soldier: soldier++;
-			case TFClass_Pyro: pyro++;
-			case TFClass_DemoMan: demoman++;
-			case TFClass_Heavy: heavy++;
-			case TFClass_Engineer: engineer++;
-			case TFClass_Medic: medic++;
-			case TFClass_Sniper: sniper++;
-			case TFClass_Spy: spy++;
-		}
+		numClass[ TF2_GetPlayerClass(i) ]++;
 	}
 }