Index: lib/ivis_common/imd.h
===================================================================
--- lib/ivis_common/imd.h	(revision 8059)
+++ lib/ivis_common/imd.h	(working copy)
@@ -35,6 +35,8 @@
 
 //*************************************************************************
 
+#define iV_IMD_TCMASK 0x00010000
+
 // polygon flags	b0..b7: col, b24..b31: anim index
 
 
Index: lib/ivis_common/imdload.c
===================================================================
--- lib/ivis_common/imdload.c	(revision 8059)
+++ lib/ivis_common/imdload.c	(working copy)
@@ -568,6 +568,7 @@
 		return NULL;
 	}
 
+	s->flags = 0;
 	s->nconnectors = 0; // Default number of connectors must be 0
 	s->npoints = 0;
 	s->npolys = 0;
@@ -580,6 +581,7 @@
 	s->shadowEdgeList = NULL;
 	s->nShadowEdges = 0;
 	s->texpage = iV_TEX_INVALID;
+	s->tcmaskpage = iV_TEX_INVALID;
 
 
 	if (sscanf(pFileData, "%s %d%n", buffer, &s->npoints, &cnt) != 2)
@@ -806,6 +808,26 @@
 		{
 			psShape->texpage = texpage;
 		}
+
+		// check if model should use team color mask
+		if (imd_flags & iV_IMD_TCMASK)
+		{
+			pie_MakeTexPageTCMaskName(texfile);
+			texpage = iV_GetTexture(texfile);
+
+			if (texpage < 0)
+			{
+				ASSERT(false, "iV_ProcessIMD %s could not load tcmask %s", pFileName, texfile);
+			}
+			else
+			{
+				shape->flags |= iV_IMD_TCMASK;
+				for (psShape = shape; psShape != NULL; psShape = psShape->next)
+				{
+					psShape->tcmaskpage = texpage;
+				}
+			}			
+		}
 	}
 
 	*ppFileData = pFileData;
Index: lib/ivis_common/ivisdef.h
===================================================================
--- lib/ivis_common/ivisdef.h	(revision 8059)
+++ lib/ivis_common/ivisdef.h	(working copy)
@@ -86,7 +86,9 @@
 } iIMDPoly;
 
 typedef struct _iIMDShape {
+	unsigned int flags;	
 	int texpage;
+	int tcmaskpage;
 	int sradius, radius;
 	Vector3f min, max;
 
Index: lib/ivis_common/tex.h
===================================================================
--- lib/ivis_common/tex.h	(revision 8059)
+++ lib/ivis_common/tex.h	(working copy)
@@ -28,6 +28,9 @@
 #define iV_TEX_INVALID -1
 #define iV_TEXNAME_MAX 64
 
+#define iV_TEXNAME_TCSUFFIX "_tcmask"
+
+
 //*************************************************************************
 
 #define iV_TEXNAME(i)	((char *) (&_TEX_PAGE[(i)].name))
@@ -58,6 +61,7 @@
 extern void pie_InitSkybox(SDWORD pageNum);
 
 extern void pie_MakeTexPageName(char * filename);
+extern void pie_MakeTexPageTCMaskName(char * filename);
 
 //*************************************************************************
 
Index: lib/ivis_opengl/tex.c
===================================================================
--- lib/ivis_opengl/tex.c	(revision 8059)
+++ lib/ivis_opengl/tex.c	(working copy)
@@ -181,6 +181,20 @@
 	}
 }
 
+/*!
+ * Turns page filename into a pagename + tc mask if possible
+ * \param[in,out] filename Filename to pagify
+ */
+void pie_MakeTexPageTCMaskName(char * filename)
+{
+	if (strncmp(filename, "page-", 5) == 0)
+	{
+		int i;
+		for( i = 5; i < iV_TEXNAME_MAX-1 && isdigit(filename[i]); i++);
+		filename[i] = '\0';
+		strcat(filename, iV_TEXNAME_TCSUFFIX);
+	}
+}
 
 /*!
  * Print the names of all loaded textures to LOG_ERROR
Index: src/data.c
===================================================================
--- src/data.c	(revision 8059)
+++ src/data.c	(working copy)
@@ -68,6 +68,10 @@
 #include "multiplay.h"
 #include "lib/netplay/netplay.h"
 
+
+#define DT_TEXPAGE "TEXPAGE"
+#define DT_TCMASK "TCMASK"
+
 /**********************************************************
  *
  * Local Variables
@@ -778,7 +782,7 @@
 	}
 
 	// see if this texture page has already been loaded
-	if (resPresent("TEXPAGE", texpage))
+	if (resPresent(DT_TEXPAGE, texpage))
 	{
 		// replace the old texture page with the new one
 		debug(LOG_TEXTURE, "replacing %s with new texture %s", texpage, fileName);
@@ -794,6 +798,42 @@
 	return true;
 }
 
+/* Load a texturepage team color mask into memory */
+static BOOL dataTexPageTCMaskLoad(const char *fileName, void **ppData)
+{
+	char texpage[PATH_MAX] = {'\0'};
+
+	// This hackery is needed, because fileName will include the directory name, whilst the LastResourceFilename will not, and we need a short name to identify the texpage
+	sstrcpy(texpage, GetLastResourceFilename());
+
+	// Check if a corresponding texpage exists, exit if no
+	pie_MakeTexPageName(texpage);
+	ASSERT_OR_RETURN(false, resPresent(DT_TEXPAGE, texpage), "Corresponding texpage %s doesn't exists!", texpage);
+
+	pie_MakeTexPageTCMaskName(texpage);
+		
+	if (!dataImageLoad(fileName, ppData))
+	{
+		return false;
+	}
+
+	// see if this texture page has already been loaded
+	if (resPresent(DT_TCMASK, texpage))
+	{
+		// replace the old texture page with the new one
+		debug(LOG_TEXTURE, "replacing %s with new tc mask %s", texpage, fileName);
+		(void) pie_ReplaceTexPage(*ppData, texpage, getTextureSize());
+	}
+	else
+	{
+		debug(LOG_TEXTURE, "adding page %s with tc mask %s", texpage, fileName);
+		SetLastResourceFilename(texpage);
+		(void) pie_AddTexPage(*ppData, texpage, 0, getTextureSize());
+	}
+
+	return true;
+}
+
 /*!
  * Release an Image
  */
@@ -1067,11 +1107,12 @@
 	{"IMGPAGE", dataImageLoad, dataImageRelease},
 	{"TERTILES", dataTERTILESLoad, dataTERTILESRelease},
 	{"IMG", dataIMGLoad, dataIMGRelease},
-	{"TEXPAGE", dataTexPageLoad, dataImageRelease},
+	{DT_TEXPAGE, dataTexPageLoad, dataImageRelease},
+	{DT_TCMASK, dataTexPageTCMaskLoad, dataImageRelease},
 	{"SCRIPT", dataScriptLoad, dataScriptRelease},
 	{"SCRIPTVAL", dataScriptLoadVals, NULL},
 	{"STR_RES", dataStrResLoad, dataStrResRelease},
-	{ "RESEARCHMSG", dataResearchMsgLoad, dataSMSGRelease },
+	{"RESEARCHMSG", dataResearchMsgLoad, dataSMSGRelease },
 };
 
 typedef struct

