summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-02-07 10:41:45 +0000
committertron <tron@openttd.org>2005-02-07 10:41:45 +0000
commit7d56d1d84167e3bd1f9c8e0c6fff8412734adce9 (patch)
tree6fb9696d4610ea19244f194d0c47fa748af72fd4
parentc45312326a0ae8b7c64a67539b927d994b56681b (diff)
downloadopenttd-7d56d1d84167e3bd1f9c8e0c6fff8412734adce9.tar.xz
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
-rw-r--r--ai.c2
-rw-r--r--functions.h2
-rw-r--r--industry_cmd.c6
-rw-r--r--landscape.c41
-rw-r--r--station_cmd.c4
-rw-r--r--tile.c44
-rw-r--r--tile.h3
-rw-r--r--town_cmd.c2
-rw-r--r--tunnelbridge_cmd.c5
-rw-r--r--unmovable_cmd.c2
10 files changed, 60 insertions, 51 deletions
diff --git a/ai.c b/ai.c
index 2a1132993..1bbc88af2 100644
--- a/ai.c
+++ b/ai.c
@@ -1708,7 +1708,7 @@ static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode)
byte old_player;
uint32 r;
uint slope;
- int h;
+ uint h;
old_player = _current_player;
_current_player = OWNER_NONE;
diff --git a/functions.h b/functions.h
index 2b59c11a5..032c279c6 100644
--- a/functions.h
+++ b/functions.h
@@ -9,8 +9,6 @@
/* landscape.c */
void FindLandscapeHeight(TileInfo *ti, uint x, uint y);
void FindLandscapeHeightByTile(TileInfo *ti, uint tile);
-uint GetTileSlope(uint tile, int *h);
-int GetTileZ(uint tile);
void DoClearSquare(uint tile);
void CDECL ModifyTile(uint tile, uint flags, ...);
diff --git a/industry_cmd.c b/industry_cmd.c
index f0acc8310..961f44499 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -959,7 +959,7 @@ static void PlantFarmField(uint tile)
int type, type2;
if (_opt.landscape == LT_HILLY) {
- if (GetTileZ(tile) >= (_opt.snow_line - 16))
+ if (GetTileZ(tile) + 16 >= _opt.snow_line)
return;
}
@@ -1169,7 +1169,7 @@ static bool CheckNewIndustry_NULL(uint tile, int type)
static bool CheckNewIndustry_Forest(uint tile, int type)
{
if (_opt.landscape == LT_HILLY) {
- if (GetTileZ(tile) < (_opt.snow_line + 16) ) {
+ if (GetTileZ(tile) < _opt.snow_line + 16U) {
_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED;
return false;
}
@@ -1202,7 +1202,7 @@ static bool CheckNewIndustry_Oilwell(uint tile, int type)
static bool CheckNewIndustry_Farm(uint tile, int type)
{
if (_opt.landscape == LT_HILLY) {
- if (GetTileZ(tile) >= (_opt.snow_line - 16)) {
+ if (GetTileZ(tile) + 16 >= _opt.snow_line) {
_error_message = STR_0239_SITE_UNSUITABLE;
return false;
}
diff --git a/landscape.c b/landscape.c
index bdf596d70..462e669b1 100644
--- a/landscape.c
+++ b/landscape.c
@@ -41,45 +41,6 @@ const byte _tileh_to_sprite[32] = {
0,0,0,0,0,0,0,16,0,0,0,17,0,15,18,0,
};
-uint GetTileSlope(uint tile, int *h)
-{
- uint a,b,c,d,min;
- int r;
-
- assert(tile < MapSize());
-
- if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) {
- if (h)
- *h = 0;
- return 0;
- }
-
- min = a = TileHeight(tile);
- b = TileHeight(tile + TILE_XY(1,0));
- if (min >= b) min = b;
- c = TileHeight(tile + TILE_XY(0,1));
- if (min >= c) min = c;
- d = TileHeight(tile + TILE_XY(1,1));
- if (min >= d) min = d;
-
- r = 0;
- if ((a-=min)!=0) { r += (--a << 4) + 8; }
- if ((c-=min)!=0) { r += (--c << 4) + 4; }
- if ((d-=min)!=0) { r += (--d << 4) + 2; }
- if ((b-=min)!=0) { r += (--b << 4) + 1; }
-
- if (h != 0)
- *h = min * 8;
-
- return r;
-}
-
-int GetTileZ(uint tile)
-{
- int h;
- GetTileSlope(tile, &h);
- return h;
-}
void FindLandscapeHeightByTile(TileInfo *ti, TileIndex tile)
{
@@ -488,7 +449,7 @@ void InitializeLandscape(uint log_x, uint log_y)
void ConvertGroundTilesIntoWaterTiles(void)
{
TileIndex tile = 0;
- int h;
+ uint h;
for (tile = 0; tile < MapSize(); ++tile) {
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h == 0) {
diff --git a/station_cmd.c b/station_cmd.c
index f31634d78..c4d9854b2 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -757,7 +757,9 @@ int32 CheckFlatLandBelow(uint tile, uint w, uint h, uint flags, uint invalid_dir
int32 cost = 0, ret;
uint tileh;
- int z, allowed_z = -1, flat_z;
+ uint z;
+ int allowed_z = -1;
+ int flat_z;
BEGIN_TILE_LOOP(tile_cur, w, h, tile)
if (!EnsureNoVehicle(tile_cur))
diff --git a/tile.c b/tile.c
index d52cf460d..f7f79ea84 100644
--- a/tile.c
+++ b/tile.c
@@ -13,3 +13,47 @@ uint GetMapExtraBits(TileIndex tile)
assert(tile < MapSize());
return (_map_extra_bits[tile >> 2] >> (tile & 3) * 2) & 3;
}
+
+
+uint GetTileSlope(TileIndex tile, uint *h)
+{
+ uint a;
+ uint b;
+ uint c;
+ uint d;
+ uint min;
+ uint r;
+
+ assert(tile < MapSize());
+
+ if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) {
+ if (h != NULL) *h = 0;
+ return 0;
+ }
+
+ min = a = TileHeight(tile);
+ b = TileHeight(tile + TILE_XY(1,0));
+ if (min >= b) min = b;
+ c = TileHeight(tile + TILE_XY(0,1));
+ if (min >= c) min = c;
+ d = TileHeight(tile + TILE_XY(1,1));
+ if (min >= d) min = d;
+
+ r = 0;
+ if ((a -= min) != 0) { r += (--a << 4) + 8; }
+ if ((c -= min) != 0) { r += (--c << 4) + 4; }
+ if ((d -= min) != 0) { r += (--d << 4) + 2; }
+ if ((b -= min) != 0) { r += (--b << 4) + 1; }
+
+ if (h != NULL)
+ *h = min * 8;
+
+ return r;
+}
+
+uint GetTileZ(TileIndex tile)
+{
+ uint h;
+ GetTileSlope(tile, &h);
+ return h;
+}
diff --git a/tile.h b/tile.h
index 6943f4a0e..cb0fa1e03 100644
--- a/tile.h
+++ b/tile.h
@@ -20,6 +20,9 @@ typedef enum TileType {
void SetMapExtraBits(TileIndex tile, byte flags);
uint GetMapExtraBits(TileIndex tile);
+uint GetTileSlope(TileIndex tile, uint *h);
+uint GetTileZ(TileIndex tile);
+
static inline uint TileHeight(TileIndex tile)
{
assert(tile < MapSize());
diff --git a/town_cmd.c b/town_cmd.c
index b0c05b629..d0daaf146 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -1144,7 +1144,7 @@ static void DoBuildTownHouse(Town *t, uint tile)
uint bitmask;
int house;
uint slope;
- int z;
+ uint z;
uint oneof;
// Above snow?
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index a42640deb..95cc74dc7 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -586,7 +586,7 @@ static const byte _updsignals_tunnel_dir[4] = { 5, 7, 1, 3};
uint CheckTunnelBusy(uint tile, int *length)
{
- int z = GetTileZ(tile);
+ uint z = GetTileZ(tile);
byte m5 = _map5[tile];
int delta = TileOffsByDir(m5 & 3);
int len = 0;
@@ -1404,7 +1404,6 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, uint tile, int x, int y)
int z;
int dir, vdir;
byte fc;
- int h;
if ((_map5[tile] & 0xF0) == 0) {
z = GetSlopeZ(x, y) - v->z_pos;
@@ -1472,6 +1471,8 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, uint tile, int x, int y)
}
} else if (_map5[tile] & 0x80) {
if (v->type == VEH_Road || (v->type == VEH_Train && v->subtype == TS_Front_Engine)) {
+ uint h;
+
if (GetTileSlope(tile, &h) != 0)
h += 8; // Compensate for possible foundation
if (!(_map5[tile] & 0x40) || // start/end tile of bridge
diff --git a/unmovable_cmd.c b/unmovable_cmd.c
index ce5b46798..b84b73107 100644
--- a/unmovable_cmd.c
+++ b/unmovable_cmd.c
@@ -253,7 +253,7 @@ void GenerateUnmovables(void)
uint tile;
uint32 r;
int dir;
- int h;
+ uint h;
if (_opt.landscape == LT_CANDY)
return;