Index: lib/ivis_common/bitimage.c
===================================================================
--- lib/ivis_common/bitimage.c	(revision 9745)
+++ lib/ivis_common/bitimage.c	(working copy)
@@ -48,7 +48,7 @@
 	}
 
 	debug(LOG_TEXTURE, "LoadTextureFile: had to upload texture!");
-	return pie_AddTexPage(pSprite, FileName, 0, 0);
+	return pie_AddTexPage(pSprite, FileName, 0, 0, true);
 }
 
 IMAGEFILE *iV_LoadImageFile(const char *fileName)
Index: lib/ivis_common/imd.h
===================================================================
--- lib/ivis_common/imd.h	(revision 9745)
+++ lib/ivis_common/imd.h	(working copy)
@@ -35,9 +35,12 @@
 
 //*************************************************************************
 
+// PIE model flags
+#define iV_IMD_TCMASK 0x00010000
+
 // polygon flags	b0..b7: col, b24..b31: anim index
 
-
+// Polygon flags
 #define iV_IMD_TEX 0x00000200
 #define iV_IMD_TEXANIM 0x00004000 // iV_IMD_TEX must be set also
 
Index: lib/ivis_common/imdload.c
===================================================================
--- lib/ivis_common/imdload.c	(revision 9745)
+++ lib/ivis_common/imdload.c	(working copy)
@@ -557,6 +557,7 @@
 		return NULL;
 	}
 
+	s->flags = 0;
 	s->nconnectors = 0; // Default number of connectors must be 0
 	s->npoints = 0;
 	s->npolys = 0;
@@ -569,6 +570,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)
@@ -662,7 +664,7 @@
 	iIMDShape *shape, *psShape;
 	UDWORD level;
 	int32_t imd_version;
-	uint32_t imd_flags; // FIXME UNUSED
+	uint32_t imd_flags;
 	BOOL bTextured = false;
 
 	if (sscanf(pFileData, "%s %d%n", buffer, &imd_version, &cnt) != 2)
@@ -795,6 +797,27 @@
 		{
 			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);
+				debug(LOG_ERROR, "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 9745)
+++ lib/ivis_common/ivisdef.h	(working copy)
@@ -84,7 +84,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 9745)
+++ lib/ivis_common/tex.h	(working copy)
@@ -33,6 +33,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))
@@ -56,13 +59,14 @@
 extern void iV_unloadImage(iV_Image *image);
 extern unsigned int iV_getPixelFormat(const iV_Image *image);
 
-extern int pie_ReplaceTexPage(iV_Image *s, const char *texPage, int maxTextureSize);
-extern int pie_AddTexPage(iV_Image *s, const char *filename, int slot, int maxTextureSize);
+extern int pie_ReplaceTexPage(iV_Image *s, const char *texPage, int maxTextureSize, bool useMipmaping);
+extern int pie_AddTexPage(iV_Image *s, const char *filename, int slot, int maxTextureSize, bool useMipmaping);
 extern void pie_TexInit(void);
 
 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 9745)
+++ lib/ivis_opengl/tex.c	(working copy)
@@ -57,12 +57,13 @@
 
 	Returns the texture number of the image.
 **************************************************************************/
-int pie_AddTexPage(iV_Image *s, const char* filename, int slot, int maxTextureSize)
+int pie_AddTexPage(iV_Image *s, const char* filename, int slot, int maxTextureSize, bool useMipmaping)
 {
 	unsigned int i = 0;
 	int width, height;
 	void *bmp;
 	bool scaleDown = false;
+	GLint minfilter = GL_LINEAR;
 
 	/* Have we already loaded this one? Should not happen here. */
 	while (i < _TEX_INDEX)
@@ -130,14 +131,28 @@
 			// this is an interface texture, do not use compression
 			gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height, iV_getPixelFormat(s), GL_UNSIGNED_BYTE, bmp);
 		}
-	} else {
+	}
+	else
+	{
 		debug(LOG_ERROR, "pie_AddTexPage: non POT texture %s", filename);
 	}
-	free(bmp); // it is uploaded, we do not need it anymore
+	
+	// it is uploaded, we do not need it anymore
+	free(bmp); 
 	s->bmp = NULL;
 
+	if (useMipmaping)
+	{
+		minfilter = GL_LINEAR_MIPMAP_LINEAR;
+	}
+	else
+	{
+		minfilter = GL_LINEAR;
+	}
+
 	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minfilter);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
 	// Use anisotropic filtering, if available, but only max 4.0 to reduce processor burden
@@ -181,6 +196,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
@@ -236,7 +265,7 @@
 	replaceing the texture page with the same name if another file
 	with this prefix is loaded.
 **************************************************************************/
-int pie_ReplaceTexPage(iV_Image *s, const char *texPage, int maxTextureSize)
+int pie_ReplaceTexPage(iV_Image *s, const char *texPage, int maxTextureSize, bool useMipmaping)
 {
 	int i = iV_GetTexture(texPage);
 
@@ -249,7 +278,7 @@
 	glDeleteTextures(1, &_TEX_PAGE[i].id);
 	debug(LOG_TEXTURE, "Reloading texture %s from index %d", texPage, i);
 	_TEX_PAGE[i].name[0] = '\0';
-	pie_AddTexPage(s, texPage, i, maxTextureSize);
+	pie_AddTexPage(s, texPage, i, maxTextureSize, useMipmaping);
 
 	return i;
 }
Index: src/data.c
===================================================================
--- src/data.c	(revision 9745)
+++ src/data.c	(working copy)
@@ -67,6 +67,10 @@
 #include "multiplay.h"
 #include "lib/netplay/netplay.h"
 #include <SDL.h>
+
+#define DT_TEXPAGE "TEXPAGE"
+#define DT_TCMASK "TCMASK"
+
 /**********************************************************
  *
  * Local Variables
@@ -854,22 +858,58 @@
 	}
 
 	// 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);
-		(void) pie_ReplaceTexPage(*ppData, texpage, getTextureSize());
+		(void) pie_ReplaceTexPage(*ppData, texpage, getTextureSize(), true);
 	}
 	else
 	{
 		debug(LOG_TEXTURE, "adding page %s with texture %s", texpage, fileName);
 		SetLastResourceFilename(texpage);
-		(void) pie_AddTexPage(*ppData, texpage, 0, getTextureSize());
+		(void) pie_AddTexPage(*ppData, texpage, 0, getTextureSize(), true);
 	}
 
 	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(), false);
+	}
+	else
+	{
+		debug(LOG_TEXTURE, "adding page %s with tc mask %s", texpage, fileName);
+		SetLastResourceFilename(texpage);
+		(void) pie_AddTexPage(*ppData, texpage, 0, getTextureSize(), false);
+	}
+
+	return true;
+}
+
 /*!
  * Release an Image
  */
@@ -1182,11 +1222,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 },
 };
 
 /* Pass all the data loading functions to the framework library */

