summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--disaster_cmd.c32
-rw-r--r--industry_cmd.c40
-rw-r--r--train_cmd.c51
-rw-r--r--water_cmd.c30
4 files changed, 87 insertions, 66 deletions
diff --git a/disaster_cmd.c b/disaster_cmd.c
index 0c28ddc0a..16c0a523d 100644
--- a/disaster_cmd.c
+++ b/disaster_cmd.c
@@ -13,25 +13,31 @@
#include "airport_movement.h"
#include "sound.h"
-static void DisasterClearSquare(uint tile)
+static void DisasterClearSquare(TileIndex tile)
{
- int type;
-
if (!EnsureNoVehicle(tile))
return;
- type = TileType(tile);
+ switch (TileType(tile)) {
+ case MP_RAILWAY:
+ if (IS_HUMAN_PLAYER(_map_owner[tile])) DoClearSquare(tile);
+ break;
+
+ case MP_HOUSE: {
+ byte p = _current_player;
+ _current_player = OWNER_NONE;
+ DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
+ _current_player = p;
+ break;
+ }
- if (type == MP_RAILWAY) {
- if (IS_HUMAN_PLAYER(_map_owner[tile]))
+ case MP_TREES:
+ case MP_CLEAR:
DoClearSquare(tile);
- } else if (type == MP_HOUSE) {
- byte p = _current_player;
- _current_player = OWNER_NONE;
- DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
- _current_player = p;
- } else if (type == MP_TREES || type == MP_CLEAR) {
- DoClearSquare(tile);
+ break;
+
+ default:
+ break;
}
}
diff --git a/industry_cmd.c b/industry_cmd.c
index 8fb2c03fc..de8bdffa9 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -854,31 +854,35 @@ void DeleteIndustry(Industry *i)
static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
-static bool IsBadFarmFieldTile(uint tile)
+static bool IsBadFarmFieldTile(TileIndex tile)
{
- if (IsTileType(tile, MP_CLEAR)) {
- byte m5 = _map5[tile] & 0x1C;
- if (m5 == 0xC || m5 == 0x10)
+ switch (TileType(tile)) {
+ case MP_CLEAR: {
+ byte m5 = _map5[tile] & 0x1C;
+ return m5 == 0xC || m5 == 0x10;
+ }
+
+ case MP_TREES:
+ return false;
+
+ default:
return true;
- return false;
- } else if (IsTileType(tile, MP_TREES)) {
- return false;
- } else {
- return true;
}
}
-static bool IsBadFarmFieldTile2(uint tile)
+static bool IsBadFarmFieldTile2(TileIndex tile)
{
- if (IsTileType(tile, MP_CLEAR)) {
- byte m5 = _map5[tile] & 0x1C;
- if (m5 == 0x10)
+ switch (TileType(tile)) {
+ case MP_CLEAR: {
+ byte m5 = _map5[tile] & 0x1C;
+ return m5 == 0x10;
+ }
+
+ case MP_TREES:
+ return false;
+
+ default:
return true;
- return false;
- } else if (IsTileType(tile, MP_TREES)) {
- return false;
- } else {
- return true;
}
}
diff --git a/train_cmd.c b/train_cmd.c
index e96bc5866..fccded322 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -1893,36 +1893,39 @@ static int GetDirectionToVehicle(Vehicle *v, int x, int y)
}
/* Check if the vehicle is compatible with the specified tile */
-static bool CheckCompatibleRail(Vehicle *v, uint tile)
+static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
{
- if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION)) {
- // normal tracks, jump to owner check
- } else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
- if ((_map5[tile] & 0xC0) == 0xC0) {// is bridge middle part?
- TileInfo ti;
- FindLandscapeHeightByTile(&ti, tile);
+ switch (TileType(tile)) {
+ case MP_RAILWAY:
+ case MP_STATION:
+ // normal tracks, jump to owner check
+ break;
- // correct Z position of a train going under a bridge on slopes
- if (CORRECT_Z(ti.tileh))
- ti.z += 8;
+ case MP_TUNNELBRIDGE:
+ if ((_map5[tile] & 0xC0) == 0xC0) { // is bridge middle part?
+ TileInfo ti;
+ FindLandscapeHeightByTile(&ti, tile);
- if(v->z_pos != ti.z) // train is going over bridge
- return true;
- }
- } else if (IsTileType(tile, MP_STREET)) { // train is going over a road-crossing
- // tracks over roads, do owner check of tracks (_map_owner[tile])
- if (_map_owner[tile] != v->owner || (v->subtype == 0 && (_map3_hi[tile] & 0xF) != v->u.rail.railtype))
- return false;
+ // correct Z position of a train going under a bridge on slopes
+ if (CORRECT_Z(ti.tileh)) ti.z += 8;
- return true;
- } else
- return true;
+ if (v->z_pos != ti.z) return true; // train is going over bridge
+ }
+ break;
- if (_map_owner[tile] != v->owner ||
- (v->subtype == 0 && (_map3_lo[tile] & 0xF) != v->u.rail.railtype))
- return false;
+ case MP_STREET:
+ // tracks over roads, do owner check of tracks (_map_owner[tile])
+ return
+ _map_owner[tile] == v->owner &&
+ (v->subtype != 0 || (_map3_hi[tile] & 0xF) == v->u.rail.railtype);
- return true;
+ default:
+ return true;
+ }
+
+ return
+ _map_owner[tile] == v->owner &&
+ (v->subtype != 0 || (_map3_lo[tile] & 0xF) == v->u.rail.railtype);
}
typedef struct {
diff --git a/water_cmd.c b/water_cmd.c
index e11cc50b9..f3ac23e3a 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -315,19 +315,27 @@ static int32 ClearTile_Water(uint tile, byte flags) {
}
// return true if a tile is a water tile.
-static bool IsWateredTile(uint tile)
+static bool IsWateredTile(TileIndex tile)
{
byte m5 = _map5[tile];
- if (IsTileType(tile, MP_WATER)) {
- return m5 != 1;
- } else if (IsTileType(tile, MP_STATION)) {
- // returns true if it is a dock-station (m5 inside values is m5<75 all stations,
- // 83<=m5<=114 new airports
- return !(m5 < 75 || (m5 >= 83 && m5 <= 114));
- } else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
- return (m5 & 0xF8) == 0xC8;
- } else
- return false;
+
+ switch (TileType(tile)) {
+ case MP_WATER:
+ // true, if not coast/riverbank
+ return m5 != 1;
+
+ case MP_STATION:
+ // returns true if it is a dock-station
+ // m5 inside values is m5 < 75 all stations, 83 <= m5 <= 114 new airports
+ return !(m5 < 75 || (m5 >= 83 && m5 <= 114));
+
+ case MP_TUNNELBRIDGE:
+ // true, if tile is middle part of bridge with water underneath
+ return (m5 & 0xF8) == 0xC8;
+
+ default:
+ return false;
+ }
}
// draw a canal styled water tile with dikes around