diff --git a/ai.c b/ai.c index 2a11329936..1bbc88af2a 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 2b59c11a50..032c279c65 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 f0acc83106..961f44499f 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 bdf596d70d..462e669b12 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 f31634d780..c4d9854b28 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 d52cf460df..f7f79ea845 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 6943f4a0e4..cb0fa1e039 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 b0c05b6292..d0daaf146e 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 a42640deb4..95cc74dc78 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 ce5b467982..b84b73107b 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;