changeset 18318:176f4e13618a draft

(svn r23154) -Change: [NewGRF v8] Use heightlevel units in nearby tile info variables. (rubidium)
author frosch <frosch@openttd.org>
date Tue, 08 Nov 2011 17:29:01 +0000
parents a04775eae135
children 12b6f3ecbd6c
files src/newgrf_airporttiles.cpp src/newgrf_commons.cpp src/newgrf_commons.h src/newgrf_house.cpp src/newgrf_industries.cpp src/newgrf_industries.h src/newgrf_industrytiles.cpp src/newgrf_object.cpp src/newgrf_station.cpp
diffstat 9 files changed, 31 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf_airporttiles.cpp
+++ b/src/newgrf_airporttiles.cpp
@@ -112,14 +112,15 @@
  * @param parameter from callback. It's in fact a pair of coordinates
  * @param tile TileIndex from which the callback was initiated
  * @param index of the industry been queried for
+ * @param grf_version8 True, if we are dealing with a new NewGRF which uses GRF version >= 8.
  * @return a construction of bits obeying the newgrf format
  */
-uint32 GetNearbyAirportTileInformation(byte parameter, TileIndex tile, StationID index)
+static uint32 GetNearbyAirportTileInformation(byte parameter, TileIndex tile, StationID index, bool grf_version8)
 {
 	if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
 	bool is_same_airport = (IsTileType(tile, MP_STATION) && IsAirport(tile) && GetStationIndex(tile) == index);
 
-	return GetNearbyTileInformation(tile) | (is_same_airport ? 1 : 0) << 8;
+	return GetNearbyTileInformation(tile, grf_version8) | (is_same_airport ? 1 : 0) << 8;
 }
 
 
@@ -194,7 +195,7 @@
 		case 0x44: return GetAnimationFrame(tile);
 
 		/* Land info of nearby tiles */
-		case 0x60: return GetNearbyAirportTileInformation(parameter, tile, st->index);
+		case 0x60: return GetNearbyAirportTileInformation(parameter, tile, st->index, object->grffile);
 
 		/* Animation stage of nearby tiles */
 		case 0x61:
--- a/src/newgrf_commons.cpp
+++ b/src/newgrf_commons.cpp
@@ -442,9 +442,10 @@
  * Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
  *
  * @param tile the tile of interest.
+ * @param grf_version8 True, if we are dealing with a new NewGRF which uses GRF version >= 8.
  * @return 0czzbbss: c = TileType; zz = TileZ; bb: 7-3 zero, 4-2 TerrainType, 1 water/shore, 0 zero; ss = TileSlope
  */
-uint32 GetNearbyTileInformation(TileIndex tile)
+uint32 GetNearbyTileInformation(TileIndex tile, bool grf_version8)
 {
 	TileType tile_type = GetTileType(tile);
 
@@ -455,7 +456,8 @@
 	Slope tileh = GetTilePixelSlope(tile, &z);
 	/* Return 0 if the tile is a land tile */
 	byte terrain_type = (HasTileWaterClass(tile) ? (GetWaterClass(tile) + 1) & 3 : 0) << 5 | GetTerrainType(tile) << 2 | (tile_type == MP_WATER ? 1 : 0) << 1;
-	return tile_type << 24 | z << 16 | terrain_type << 8 | tileh;
+	if (grf_version8) z /= TILE_HEIGHT;
+	return tile_type << 24 | Clamp(z, 0, 0xFF) << 16 | terrain_type << 8 | tileh;
 }
 
 /**
--- a/src/newgrf_commons.h
+++ b/src/newgrf_commons.h
@@ -296,7 +296,7 @@
 
 uint32 GetTerrainType(TileIndex tile, TileContext context = TCX_NORMAL);
 TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets = true, Axis axis = INVALID_AXIS);
-uint32 GetNearbyTileInformation(TileIndex tile);
+uint32 GetNearbyTileInformation(TileIndex tile, bool grf_version8);
 uint32 GetCompanyInfo(CompanyID owner, const struct Livery *l = NULL);
 CommandCost GetErrorMessageFromLocationCallbackResult(uint16 cb_res, uint32 grfid, StringID default_error);
 
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -132,10 +132,17 @@
 	return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
 }
 
-uint32 GetNearbyTileInformation(byte parameter, TileIndex tile)
+/**
+ * Get information about a nearby tile.
+ * @param parameter from callback. It's in fact a pair of coordinates
+ * @param tile TileIndex from which the callback was initiated
+ * @param grf_version8 True, if we are dealing with a new NewGRF which uses GRF version >= 8.
+ * @return a construction of bits obeying the newgrf format
+ */
+static uint32 GetNearbyTileInformation(byte parameter, TileIndex tile, bool grf_version8)
 {
 	tile = GetNearbyTile(parameter, tile);
-	return GetNearbyTileInformation(tile);
+	return GetNearbyTileInformation(tile, grf_version8);
 }
 
 /** Structure with user-data for SearchNearbyHouseXXX - functions */
@@ -302,7 +309,7 @@
 		}
 
 		/* Land info for nearby tiles. */
-		case 0x62: return GetNearbyTileInformation(parameter, tile);
+		case 0x62: return GetNearbyTileInformation(parameter, tile, object->grffile->grf_version >= 8);
 
 		/* Current animation frame of nearby house tiles */
 		case 0x63: {
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -251,7 +251,7 @@
 			return (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0;
 
 		/* Land info of nearby tiles */
-		case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY, false);
+		case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY, false, object->grffile->grf_version >= 8);
 
 		/* Animation stage of nearby tiles */
 		case 0x63:
--- a/src/newgrf_industries.h
+++ b/src/newgrf_industries.h
@@ -46,6 +46,6 @@
 IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id);
 
 /* in newgrf_industrytiles.cpp*/
-uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index, bool signed_offsets = true);
+uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8);
 
 #endif /* NEWGRF_INDUSTRIES_H */
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -32,14 +32,15 @@
  * @param tile TileIndex from which the callback was initiated
  * @param index of the industry been queried for
  * @param signed_offsets Are the x and y offset encoded in parameter signed?
+ * @param grf_version8 True, if we are dealing with a new NewGRF which uses GRF version >= 8.
  * @return a construction of bits obeying the newgrf format
  */
-uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index, bool signed_offsets)
+uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
 {
 	if (parameter != 0) tile = GetNearbyTile(parameter, tile, signed_offsets); // only perform if it is required
 	bool is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index);
 
-	return GetNearbyTileInformation(tile) | (is_same_industry ? 1 : 0) << 8;
+	return GetNearbyTileInformation(tile, grf_version8) | (is_same_industry ? 1 : 0) << 8;
 }
 
 /**
@@ -87,7 +88,7 @@
 		case 0x44: return (IsTileType(tile, MP_INDUSTRY)) ? GetAnimationFrame(tile) : 0;
 
 		/* Land info of nearby tiles */
-		case 0x60: return GetNearbyIndustryTileInformation(parameter, tile, inds == NULL ? (IndustryID)INVALID_INDUSTRY : inds->index);
+		case 0x60: return GetNearbyIndustryTileInformation(parameter, tile, inds == NULL ? (IndustryID)INVALID_INDUSTRY : inds->index, true, object->grffile->grf_version >= 8);
 
 		/* Animation stage of nearby tiles */
 		case 0x61:
--- a/src/newgrf_object.cpp
+++ b/src/newgrf_object.cpp
@@ -157,14 +157,15 @@
  * @param parameter from callback.  It's in fact a pair of coordinates
  * @param tile TileIndex from which the callback was initiated
  * @param index of the object been queried for
+ * @param grf_version8 True, if we are dealing with a new NewGRF which uses GRF version >= 8.
  * @return a construction of bits obeying the newgrf format
  */
-static uint32 GetNearbyObjectTileInformation(byte parameter, TileIndex tile, ObjectID index)
+static uint32 GetNearbyObjectTileInformation(byte parameter, TileIndex tile, ObjectID index, bool grf_version8)
 {
 	if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
 	bool is_same_object = (IsTileType(tile, MP_OBJECT) && GetObjectIndex(tile) == index);
 
-	return GetNearbyTileInformation(tile) | (is_same_object ? 1 : 0) << 8;
+	return GetNearbyTileInformation(tile, grf_version8) | (is_same_object ? 1 : 0) << 8;
 }
 
 /**
@@ -321,7 +322,7 @@
 			return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == o) ? GetObjectRandomBits(tile) : 0;
 
 		/* Land info of nearby tiles */
-		case 0x62: return GetNearbyObjectTileInformation(parameter, tile, o == NULL ? INVALID_OBJECT : o->index);
+		case 0x62: return GetNearbyObjectTileInformation(parameter, tile, o == NULL ? INVALID_OBJECT : o->index, object->grffile->grf_version >= 8);
 
 		/* Animation counter of nearby tile */
 		case 0x63:
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -296,7 +296,7 @@
 					Slope tileh = GetTileSlope(tile);
 					bool swap = (object->u.station.axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E));
 
-					return GetNearbyTileInformation(tile) ^ (swap ? SLOPE_EW : 0);
+					return GetNearbyTileInformation(tile, object->grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
 				}
 				break;
 
@@ -353,7 +353,7 @@
 			Slope tileh = GetTileSlope(tile);
 			bool swap = (axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E));
 
-			return GetNearbyTileInformation(tile) ^ (swap ? SLOPE_EW : 0);
+			return GetNearbyTileInformation(tile, object->grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
 		}
 
 		case 0x68: { // Station info of nearby tiles