summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2008-01-31 17:46:08 +0000
committerfrosch <frosch@openttd.org>2008-01-31 17:46:08 +0000
commitfe9891c8ec0376a3a79195ee2bd76bba317865a5 (patch)
tree938c7be67dc7eb597b5484394eaaf2db1f9b663a
parentef35cefddc94539174c490e4e0bbe04a5a9d3dc8 (diff)
downloadopenttd-fe9891c8ec0376a3a79195ee2bd76bba317865a5.tar.xz
(svn r12028) -Codechange: Split common part of station var 0x67, house var 0x62, indtile var 0x60 and industry var 0x62 to 'newgrf_commons.cpp'.
-rw-r--r--src/newgrf_commons.cpp16
-rw-r--r--src/newgrf_commons.h1
-rw-r--r--src/newgrf_house.cpp8
-rw-r--r--src/newgrf_industrytiles.cpp10
-rw-r--r--src/newgrf_station.cpp9
5 files changed, 24 insertions, 20 deletions
diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp
index 944161a0a..d10b45138 100644
--- a/src/newgrf_commons.cpp
+++ b/src/newgrf_commons.cpp
@@ -285,3 +285,19 @@ TileIndex GetNearbyTile(byte parameter, TileIndex tile)
/* Make sure we never roam outside of the map */
return TILE_MASK(tile + TileDiffXY(x, y));
}
+
+/**
+ * Common part of station var 0x67 , house var 0x62, indtile var 0x60, industry var 0x62.
+ *
+ * @param tile the tile of interest.
+ * @return 0czzbbss: c = TileType; zz = TileZ; bb: 7-3 zero, 4-2 TerrainType, 1 water/shore, 0 zero; ss = TileSlope
+ */
+uint32 GetNearbyTileInformation(TileIndex tile)
+{
+ TileType tile_type = GetTileType(tile);
+
+ uint z;
+ Slope tileh = GetTileSlope(tile, &z);
+ byte terrain_type = GetTerrainType(tile) << 2 | (tile_type == MP_WATER ? 1 : 0) << 1;
+ return tile_type << 24 | z << 16 | terrain_type << 8 | tileh;
+}
diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h
index c4526a89c..5b9dea9e7 100644
--- a/src/newgrf_commons.h
+++ b/src/newgrf_commons.h
@@ -93,5 +93,6 @@ extern IndustryTileOverrideManager _industile_mngr;
uint32 GetTerrainType(TileIndex tile);
TileIndex GetNearbyTile(byte parameter, TileIndex tile);
+uint32 GetNearbyTileInformation(TileIndex tile);
#endif /* NEWGRF_COMMONS_H */
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index 31aa4e972..44b615f2b 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -170,14 +170,8 @@ static uint32 GetGRFParameter(HouseID house_id, byte parameter)
uint32 GetNearbyTileInformation(byte parameter, TileIndex tile)
{
- uint32 tile_type;
-
tile = GetNearbyTile(parameter, tile);
- tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1;
-
- uint z;
- Slope tileh = GetTileSlope(tile, &z);
- return GetTileType(tile) << 24 | z << 16 | tile_type << 8 | tileh;
+ return GetNearbyTileInformation(tile);
}
/**
diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp
index fcf4105bc..0a964d115 100644
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -45,16 +45,10 @@ static uint32 GetGRFParameter(IndustryGfx indtile_id, byte parameter)
*/
uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index)
{
- byte tile_type;
- bool is_same_industry;
-
if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
- is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index);
- tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1 | (is_same_industry ? 1 : 0);
+ bool is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index);
- uint z;
- Slope tileh = GetTileSlope(tile, &z);
- return GetTileType(tile) << 24 | z << 16 | tile_type << 8 | tileh;
+ return GetNearbyTileInformation(tile) | (is_same_industry ? 1 : 0) << 8;
}
/** This is the position of the tile relative to the northernmost tile of the industry.
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index 7eaf6164b..626e50821 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -426,12 +426,11 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, by
Axis axis = GetRailStationAxis(tile);
if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
- byte tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1;
- uint z;
- Slope tileh = GetTileSlope(tile, &z);
- bool swap = (axis == AXIS_Y && HasBit(tileh, 0) != HasBit(tileh, 2));
- return GetTileType(tile) << 24 | z << 16 | tile_type << 8 | (tileh ^ (swap ? 5 : 0));
+ Slope tileh = GetTileSlope(tile, NULL);
+ bool swap = (axis == AXIS_Y && HasBit(tileh, SLOPE_W) != HasBit(tileh, SLOPE_E));
+
+ return GetNearbyTileInformation(tile) ^ (swap ? SLOPE_EW : 0);
}
case 0x68: { // Station info of nearby tiles