(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
--- a/ai.c Mon Feb 07 10:37:12 2005 +0000
+++ b/ai.c Mon Feb 07 10:41:45 2005 +0000
@@ -1708,7 +1708,7 @@
byte old_player;
uint32 r;
uint slope;
- int h;
+ uint h;
old_player = _current_player;
_current_player = OWNER_NONE;
--- a/functions.h Mon Feb 07 10:37:12 2005 +0000
+++ b/functions.h Mon Feb 07 10:41:45 2005 +0000
@@ -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, ...);
--- a/industry_cmd.c Mon Feb 07 10:37:12 2005 +0000
+++ b/industry_cmd.c Mon Feb 07 10:41:45 2005 +0000
@@ -959,7 +959,7 @@
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_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_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;
}
--- a/landscape.c Mon Feb 07 10:37:12 2005 +0000
+++ b/landscape.c Mon Feb 07 10:41:45 2005 +0000
@@ -41,45 +41,6 @@
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 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) {
--- a/station_cmd.c Mon Feb 07 10:37:12 2005 +0000
+++ b/station_cmd.c Mon Feb 07 10:41:45 2005 +0000
@@ -757,7 +757,9 @@
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))
--- a/tile.c Mon Feb 07 10:37:12 2005 +0000
+++ b/tile.c Mon Feb 07 10:41:45 2005 +0000
@@ -13,3 +13,47 @@
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;
+}
--- a/tile.h Mon Feb 07 10:37:12 2005 +0000
+++ b/tile.h Mon Feb 07 10:41:45 2005 +0000
@@ -20,6 +20,9 @@
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());
--- a/town_cmd.c Mon Feb 07 10:37:12 2005 +0000
+++ b/town_cmd.c Mon Feb 07 10:41:45 2005 +0000
@@ -1144,7 +1144,7 @@
uint bitmask;
int house;
uint slope;
- int z;
+ uint z;
uint oneof;
// Above snow?
--- a/tunnelbridge_cmd.c Mon Feb 07 10:37:12 2005 +0000
+++ b/tunnelbridge_cmd.c Mon Feb 07 10:41:45 2005 +0000
@@ -586,7 +586,7 @@
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 @@
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 @@
}
} 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
--- a/unmovable_cmd.c Mon Feb 07 10:37:12 2005 +0000
+++ b/unmovable_cmd.c Mon Feb 07 10:41:45 2005 +0000
@@ -253,7 +253,7 @@
uint tile;
uint32 r;
int dir;
- int h;
+ uint h;
if (_opt.landscape == LT_CANDY)
return;