(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters

This commit is contained in:
tron 2005-02-07 10:41:45 +00:00
parent ad837c2069
commit f8d97a5f61
10 changed files with 60 additions and 51 deletions

2
ai.c
View File

@ -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;

View File

@ -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, ...);

View File

@ -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;
}

View File

@ -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) {

View File

@ -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))

44
tile.c
View File

@ -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;
}

3
tile.h
View File

@ -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());

View File

@ -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?

View File

@ -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

View File

@ -253,7 +253,7 @@ void GenerateUnmovables(void)
uint tile;
uint32 r;
int dir;
int h;
uint h;
if (_opt.landscape == LT_CANDY)
return;