summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-11-08 17:29:01 +0000
committerfrosch <frosch@openttd.org>2011-11-08 17:29:01 +0000
commit8f4c6d42f90dc6bda68c803bebec48a9382eb675 (patch)
treeb2c9b3e4e53cfcb2433ea5acb4553c7516ae2d0a /src
parent5aaecae6e2ea2c2236375274439645e669081328 (diff)
downloadopenttd-8f4c6d42f90dc6bda68c803bebec48a9382eb675.tar.xz
(svn r23154) -Change: [NewGRF v8] Use heightlevel units in nearby tile info variables. (rubidium)
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_airporttiles.cpp7
-rw-r--r--src/newgrf_commons.cpp6
-rw-r--r--src/newgrf_commons.h2
-rw-r--r--src/newgrf_house.cpp13
-rw-r--r--src/newgrf_industries.cpp2
-rw-r--r--src/newgrf_industries.h2
-rw-r--r--src/newgrf_industrytiles.cpp7
-rw-r--r--src/newgrf_object.cpp7
-rw-r--r--src/newgrf_station.cpp4
9 files changed, 31 insertions, 19 deletions
diff --git a/src/newgrf_airporttiles.cpp b/src/newgrf_airporttiles.cpp
index cf61d024d..7d90bd0dd 100644
--- a/src/newgrf_airporttiles.cpp
+++ b/src/newgrf_airporttiles.cpp
@@ -112,14 +112,15 @@ static const SpriteGroup *AirportTileResolveReal(const ResolverObject *object, c
* @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 @@ static uint32 AirportTileGetVariable(const ResolverObject *object, byte variable
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:
diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp
index 5f2ada887..0e28ce768 100644
--- a/src/newgrf_commons.cpp
+++ b/src/newgrf_commons.cpp
@@ -442,9 +442,10 @@ TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axi
* 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 @@ uint32 GetNearbyTileInformation(TileIndex tile)
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;
}
/**
diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h
index 99a124caa..fd0dd699d 100644
--- a/src/newgrf_commons.h
+++ b/src/newgrf_commons.h
@@ -296,7 +296,7 @@ extern ObjectOverrideManager _object_mngr;
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);
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index 5e841b7d1..0ce9c8855 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -132,10 +132,17 @@ static uint32 GetNumHouses(HouseID house_id, const Town *town)
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 @@ static uint32 HouseGetVariable(const ResolverObject *object, byte variable, uint
}
/* 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: {
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 4d61dd4bf..eedb5c17b 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -251,7 +251,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, uint32 p
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:
diff --git a/src/newgrf_industries.h b/src/newgrf_industries.h
index 4132e51e9..7f04a48a8 100644
--- a/src/newgrf_industries.h
+++ b/src/newgrf_industries.h
@@ -46,6 +46,6 @@ bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type);
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 */
diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp
index 0014a0bd8..bf5859864 100644
--- 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 @@ static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variabl
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:
diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp
index 285570c1b..991580acd 100644
--- a/src/newgrf_object.cpp
+++ b/src/newgrf_object.cpp
@@ -157,14 +157,15 @@ static uint32 GetObjectIDAtOffset(TileIndex tile, uint32 cur_grfid)
* @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 @@ static uint32 ObjectGetVariable(const ResolverObject *object, byte variable, uin
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:
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index 8ef375c4c..240f66436 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -296,7 +296,7 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, ui
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 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, ui
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