From 5ec3dff93e879c2ab37f8563b790359ba69d2d10 Mon Sep 17 00:00:00 2001
From: Adam Olsen <rhamph@gmail.com>
Date: Sun, 7 Oct 2001 22:15:22 +0000
Subject: [PATCH] - totally disable TeamFortress_ChecKTeamCheats - fix
 GetNoPlayers (didn't init num_players) - overhaul the map cycler   -
 automatically restart if a cyclenumber doesn't work   - fix minp/maxp   -
 exec mapcfg.cfg each map change  (affects minp/maxp)   - exec mapcfg/MAP.cfg
 each map change.  (affects minp/maxp) - fix a "rockets explode on observers"
 bug - make it so colors aren't reset every time you respawn

---
 BUGS       |  1 +
 client.qc  | 93 +++++++++++++++++++++++++++++++-----------------------
 often.qc   |  2 +-
 tforttm.qc | 15 ++++++---
 weapons.qc |  3 ++
 5 files changed, 69 insertions(+), 45 deletions(-)

diff --git a/BUGS b/BUGS
index 74626f9..a35c81b 100644
--- a/BUGS
+++ b/BUGS
@@ -17,3 +17,4 @@
 - prematch shouldn't force autoteam when it's done
 - sometimes ID doesn't work.  this may be because impulses are unreliable though :/
 - minp/maxp are broken.  possibly compiler !string bug
+- rockets explode on observers
diff --git a/client.qc b/client.qc
index fa4c239..c7b2adf 100644
--- a/client.qc
+++ b/client.qc
@@ -76,6 +76,8 @@ string(entity themonster) GetMonsterName;
 void(entity attacker) MonsterKill;
 void() DetonateAllGunsForced;
 
+void(float mapnum) SetNextMapNum;
+
 /*
 =============================================================================
 
@@ -84,6 +86,11 @@ void() DetonateAllGunsForced;
 =============================================================================
 */
 
+#define MAP_NO 0
+#define MAP_YES 1
+#define MAP_LOADCYCLE 2
+#define MAP_LOADCONFIG 3
+
 string nextmap;
 
 float	intermission_running;
@@ -443,7 +450,7 @@ void() DecodeLevelParms =
 	self.armortype = parm9 * 0.01;
 
 	SetTeamName (self);
-	SetPlayerColor (self, TeamGetNiceColor (self.team_no), TeamGetColor (self.team_no) - 1);
+//	SetPlayerColor (self, TeamGetNiceColor (self.team_no), TeamGetColor (self.team_no) - 1);
 
 	// TeamFortress Parameters
 	// Detect whether this is the first entrance into a map
@@ -879,10 +886,9 @@ float() DoExtraCycle =
 {
     //-------------------------------------------------//
     //- OfN - I tried to make this work like in tf2.8 -//
-    local string nfmap, temp;
-    nfmap = infokey(world, "nmap");
-    if (nfmap)
-    {
+    local string nmap, temp;
+    nmap = infokey(world, "nmap");
+    if (nmap) {
         local float minplayers, maxplayers, itsok, currentpl;
         
         if (infokey(world,"minp")!="")
@@ -901,11 +907,10 @@ float() DoExtraCycle =
 
         //check conditions
         
-        if (minplayers > currentpl)
-        {
+        if (minplayers > currentpl) {
             bprint(PRINT_HIGH,"Map ");
-            nfmap = infokey(world, "nmap");
-            bprint(PRINT_HIGH, nfmap);
+            nmap = infokey(world, "nmap");
+            bprint(PRINT_HIGH, nmap);
             bprint(PRINT_HIGH," skipped - minimum players ");
             temp = ftos(minplayers);
             bprint(PRINT_HIGH, temp);
@@ -914,14 +919,11 @@ float() DoExtraCycle =
             bprint(PRINT_HIGH, temp);
             bprint(PRINT_HIGH,")\n");
             itsok = FALSE;
-        }
-        else 
-        {
-            if (maxplayers < currentpl)
-            {
+        } else {
+            if (maxplayers < currentpl) {
                 bprint(PRINT_HIGH,"Map ");
-                nfmap = infokey(world, "nmap");
-                bprint(PRINT_HIGH, nfmap);
+                nmap = infokey(world, "nmap");
+                bprint(PRINT_HIGH, nmap);
                 bprint(PRINT_HIGH," skipped - maximum players ");
                 temp = ftos(maxplayers);
                 bprint(PRINT_HIGH,temp);
@@ -939,28 +941,31 @@ float() DoExtraCycle =
         //locals clean
 
         //execute map conditions ok
-        if (itsok)
-        {
-            nfmap = infokey(world, "nmap");
+        if (itsok) {
+            nmap = infokey(world, "nmap");
             
             bprint(PRINT_HIGH,"\nLoading ");
-            bprint(PRINT_HIGH,nfmap);
+            bprint(PRINT_HIGH,nmap);
             bprint(PRINT_HIGH," map file...\n");
 
             localcmd("localinfo nmap \"\"\n");
 
             localcmd("map ");
-            localcmd(nfmap);
+            localcmd(nmap);
             localcmd("\n");
             
             return TRUE;
-        }
-        else //conditions not passed...
-        {
-            localcmd("localinfo nmap \"\"\n");
-            return FALSE;
-        }
-    }
+		} else { //conditions not passed...
+			localcmd("localinfo nmap \"\"\n");
+			return FALSE;
+		}
+    } else if (already_chosen_map == MAP_LOADCYCLE) {
+		local string st = infokey (world, "loopcycle");
+		if (st != "0" && st != "off") {
+			dprint ("No map loaded, restarting map cycle\n");
+			SetNextMapNum (0);
+		}
+	}
 
     return FALSE;
 };
@@ -1007,7 +1012,7 @@ float() GetNextMapNum =
 
 	if (!maxmapnum)
 		return num;
-	else if (num > stof (maxmapnum))
+	if (num > stof (maxmapnum))
 		return 0;
 	else
 		return num;
@@ -1035,6 +1040,7 @@ void(float mapnum) SetNextMapNum =
 	localcmd("localinfo n ");
 	localcmd(mapstring);
 	localcmd("\n");
+	setinfokey (world, "n", mapstring);
 };
 
 void() LoadNextMap =
@@ -1092,41 +1098,48 @@ void() LoadNextMap =
 		localcmd(ftos(nextlevel));
 		localcmd(".cfg\n");
 
-		already_chosen_map = CYCLED;
+		already_chosen_map = MAP_LOADCYCLE;
 	}
 };
 
 void() GotoNextMap =
 {
-
 	if (nextmap != mapname)
 	{
 		changelevel(nextmap);
-		already_chosen_map = TRUE;
+		already_chosen_map = MAP_YES;
 	}
 
-    if (already_chosen_map == FALSE || already_chosen_map == CYCLED)
+    if (already_chosen_map != MAP_YES)
     {
-        if (DoExtraCycle())
-      		already_chosen_map = TRUE;
+		local string nmap = infokey (world, "nmap");
+		if (already_chosen_map == MAP_LOADCYCLE && nmap) {
+			// load up the map config
+			localcmd ("exec \"mapcfg.cfg\"\n");
+			localcmd ("exec \"mapcfg/" + nmap + ".cfg\"\n");
+			already_chosen_map = MAP_LOADCONFIG;
+		} else if (DoExtraCycle())
+      		already_chosen_map = MAP_LOADCYCLE;
         else
-            already_chosen_map = FALSE;
+            already_chosen_map = MAP_NO;
     }
 
 	//- OfN - super new map cycling code :)
-	if (already_chosen_map == FALSE)
+	if (already_chosen_map == MAP_NO)
 		LoadNextMap();
 
 	if (GetNextMapNum() == 0)
-        already_chosen_map = FALSE;
+        already_chosen_map = MAP_NO;
 
-    if (already_chosen_map == FALSE) // nothing was done yet, so set the damn timer..
+    if (already_chosen_map == MAP_NO) // nothing was done yet, so set the damn timer..
     {
         SetCycleTimer();
         return;
     }
     
-    if (already_chosen_map == CYCLED) // if we executed a mapx.cfg
+	// if we executed a mapx.cfg
+    if (already_chosen_map == MAP_LOADCYCLE ||
+		already_chosen_map == MAP_LOADCONFIG)
         SetCycleTimer(); // set the timer to check the real map afte 0.1 seconds
 };
 
diff --git a/often.qc b/often.qc
index 4d57b67..5bff6a5 100644
--- a/often.qc
+++ b/often.qc
@@ -887,7 +887,7 @@ float (vector spot1, vector spot2) vis2orig =
 // Return the number of players in game
 float() GetNoPlayers =
 {
-	local float num_players;
+	local float num_players = 0;
 	local entity search;
 
 	search = find (world, classname, "player");
diff --git a/tforttm.qc b/tforttm.qc
index 0ced12f..896c624 100644
--- a/tforttm.qc
+++ b/tforttm.qc
@@ -364,6 +364,7 @@ float(float tno) TeamFortress_TeamSet =
 // Make sure no-one is changing their colors
 void() TeamFortress_CheckTeamCheats =
 {
+/*
 	local string st, sk;
 	local float tc, tc2;
 	local float rate;
@@ -536,6 +537,7 @@ void() TeamFortress_CheckTeamCheats =
 		}
 		}
 	}
+*/
 };
 
 void (entity pl, float topcolor, float bottomcolor) SetPlayerColor =
@@ -564,10 +566,15 @@ void (string key, string value) UserInfoCallback =
 	}
 //	dprint ("[[" + self.netname + "](" + key + ")(" + value + ")(" + oldval + ")]\n");
 
-/*	else if (key == "topcolor") { // FIXME: some topcolors may be allowed
-		setinfokey(self, "topcolor", oldval);
-		stuffcmd(self, "color \"" + oldval + "\"\n");
-	}*/	else if (key == "bottomcolor") {
+	else if (key == "topcolor") { // FIXME: some topcolors may be allowed
+		dprint ("items: " + ftos (self.cutf_items & CUTF_SPY_KIT) + "  ");
+		dprint ("skin: " + ftos (self.is_undercover) + "\n");
+		if ((self.cutf_items & CUTF_SPY_KIT) && self.is_undercover) {
+			setinfokey(self, "topcolor", oldval);
+			stuffcmd(self, "color \"" + oldval + "\"\n");
+		} else
+			setinfokey (self, key, value);
+	}	else if (key == "bottomcolor") {
 		setinfokey (self, "bottomcolor", oldval);
 		stuffcmd (self, "bottomcolor \"" + oldval + "\"\n");
 	} else if (key == "skin") { // FIXME: some other skins may be allowed
diff --git a/weapons.qc b/weapons.qc
index 2c06b97..515407a 100644
--- a/weapons.qc
+++ b/weapons.qc
@@ -1577,6 +1577,9 @@ void() T_MissileTouch =
 	local float	damg;
 	local float	bonus;
 
+	if (other.classname == "player" && other.playerclass == PC_UNDEFINED)
+		return;
+
 	if (pointcontents(self.origin) == CONTENTS_SKY)
 	{
 		dremove(self);