(svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
authorbelugas
Sun, 26 Aug 2007 00:23:32 +0000
changeset 7473 3dfe8243a870
parent 7472 f6ec016b00f4
child 7474 1daa825ba893
(svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
Problem is that the upper limit of gfx tiles is currently at 175. So, of course the system will assert with 255 ;)
src/industry.h
src/industry_cmd.cpp
src/industry_map.h
--- a/src/industry.h	Sat Aug 25 20:32:18 2007 +0000
+++ b/src/industry.h	Sun Aug 26 00:23:32 2007 +0000
@@ -222,9 +222,18 @@
 
 static inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
 {
-	assert(gfx < INVALID_INDUSTRYTILE);
-	const IndustryTileSpec *it = &_industry_tile_specs[gfx];
-	return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override;
+	/* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
+	 * we'll simplify the writing.
+	 * Basically, the first test is required since the GFX_WATERTILE_SPECIALCHECK value
+	 * will never be assigned as a tile index and is only required in order to do some
+	 * tests while building the industry (as in WATER REQUIRED */
+	if (gfx != 0xFF) {
+		assert(gfx < INVALID_INDUSTRYTILE);
+		const IndustryTileSpec *it = &_industry_tile_specs[gfx];
+		return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override;
+	} else {
+		return gfx;
+	}
 }
 
 /* smallmap_gui.cpp */
--- a/src/industry_cmd.cpp	Sat Aug 25 20:32:18 2007 +0000
+++ b/src/industry_cmd.cpp	Sun Aug 26 00:23:32 2007 +0000
@@ -1183,11 +1183,11 @@
 		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
 
 		if (!IsValidTile(cur_tile)) {
-			if (gfx == 0xff) continue;
+			if (gfx == GFX_WATERTILE_SPECIALCHECK) continue;
 			return false;
 		}
 
-		if (gfx == 0xFF) {
+		if (gfx == GFX_WATERTILE_SPECIALCHECK) {
 			if (!IsTileType(cur_tile, MP_WATER) ||
 					GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) {
 				return false;
@@ -1452,7 +1452,7 @@
 	do {
 		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
 
-		if (it->gfx != 0xFF) {
+		if (it->gfx != GFX_WATERTILE_SPECIALCHECK) {
 			byte size;
 
 			size = it->ti.x;
--- a/src/industry_map.h	Sat Aug 25 20:32:18 2007 +0000
+++ b/src/industry_map.h	Sun Aug 26 00:23:32 2007 +0000
@@ -48,6 +48,7 @@
 	GFX_BUBBLE_CATCHER                 = 162,
 	GFX_TOFFEE_QUARY                   = 165,
 	GFX_SUGAR_MINE_SIEVE               = 174,
+	GFX_WATERTILE_SPECIALCHECK         = 255,  ///< not really a tile, but rather a very special check
 };
 
 /**