summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--console.c4
-rw-r--r--economy.c33
-rw-r--r--industry_gui.c16
-rw-r--r--landscape.c59
-rw-r--r--npf.c41
-rw-r--r--openttd.h2
-rw-r--r--pathfind.c12
-rw-r--r--rail_cmd.c47
-rw-r--r--road_cmd.c126
-rw-r--r--roadveh_cmd.c135
-rw-r--r--terraform_gui.c2
-rw-r--r--tile.c3
-rw-r--r--town_cmd.c2
-rw-r--r--train_cmd.c255
-rw-r--r--tree_cmd.c2
-rw-r--r--tunnelbridge_cmd.c81
-rw-r--r--unmovable_cmd.c8
-rw-r--r--water_cmd.c20
18 files changed, 404 insertions, 444 deletions
diff --git a/console.c b/console.c
index 7a52e172f..1cabd2923 100644
--- a/console.c
+++ b/console.c
@@ -695,7 +695,7 @@ static void IConsoleAliasExec(const IConsoleAlias* alias, byte tokencount, char*
{
const char *cmdptr;
char *aliases[ICON_MAX_ALIAS_LINES], aliasstream[ICON_MAX_STREAMSIZE];
- int i;
+ uint i;
uint a_index, astream_i;
memset(&aliases, 0, sizeof(aliases));
@@ -758,7 +758,7 @@ static void IConsoleAliasExec(const IConsoleAlias* alias, byte tokencount, char*
}
}
- for (i = 0; i <= (int)a_index; i++) IConsoleCmdExec(aliases[i]); // execute each alias in turn
+ for (i = 0; i <= a_index; i++) IConsoleCmdExec(aliases[i]); // execute each alias in turn
}
/**
diff --git a/economy.c b/economy.c
index 311bc0d7e..b4b38e985 100644
--- a/economy.c
+++ b/economy.c
@@ -1121,10 +1121,11 @@ int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, b
if (transit_days > _cargoc.transit_days_2[cargo]) {
transit_days -= _cargoc.transit_days_2[cargo];
- if (f < transit_days)
+ if (f < transit_days) {
f = 0;
- else
+ } else {
f -= transit_days;
+ }
}
}
if (f < 31) f = 31;
@@ -1134,19 +1135,23 @@ int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, b
static void DeliverGoodsToIndustry(TileIndex xy, byte cargo_type, int num_pieces)
{
- Industry *ind, *best;
- int t, u;
+ Industry* best = NULL;
+ Industry* ind;
+ uint u;
- /* Check if there's an industry close to the station that accepts
- * the cargo */
- best = NULL;
+ // Check if there's an industry close to the station that accepts the cargo
u = _patches.station_spread + 8;
FOR_ALL_INDUSTRIES(ind) {
- if (ind->xy != 0 && (cargo_type == ind->accepts_cargo[0] || cargo_type
- == ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]) &&
- ind->produced_cargo[0] != CT_INVALID &&
- ind->produced_cargo[0] != cargo_type &&
- (t = DistanceManhattan(ind->xy, xy)) < 2 * u) {
+ uint t;
+
+ if (ind->xy != 0 && (
+ cargo_type == ind->accepts_cargo[0] ||
+ cargo_type == ind->accepts_cargo[1] ||
+ cargo_type == ind->accepts_cargo[2]
+ ) &&
+ ind->produced_cargo[0] != CT_INVALID &&
+ ind->produced_cargo[0] != cargo_type &&
+ (t = DistanceManhattan(ind->xy, xy)) < 2 * u) {
u = t;
best = ind;
}
@@ -1595,7 +1600,7 @@ int32 CmdBuyShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
break;
}
}
- InvalidateWindow(WC_COMPANY, (int)p1);
+ InvalidateWindow(WC_COMPANY, p1);
}
return cost;
}
@@ -1627,7 +1632,7 @@ int32 CmdSellShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
PlayerID* b = p->share_owners;
while (*b != _current_player) b++; /* share owners is guaranteed to contain player */
*b = OWNER_SPECTATOR;
- InvalidateWindow(WC_COMPANY, (int)p1);
+ InvalidateWindow(WC_COMPANY, p1);
}
return cost;
}
diff --git a/industry_gui.c b/industry_gui.c
index 6449aa880..08c743f29 100644
--- a/industry_gui.c
+++ b/industry_gui.c
@@ -392,19 +392,11 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
break;
case WE_ON_EDIT_TEXT:
- if (*e->edittext.str) {
- Industry *i;
- int val;
- int line;
+ if (e->edittext.str[0] != '\0') {
+ Industry* i = GetIndustry(w->window_number);
+ int line = WP(w,vp2_d).data_1;
- i = GetIndustry(w->window_number);
- line = WP(w,vp2_d).data_1;
- val = atoi(e->edittext.str);
- if (!IS_INT_INSIDE(val, 32, 2040)) {
- if (val < 32) val = 32;
- else val = 2040;
- }
- i->production_rate[line] = (byte)(val / 8);
+ i->production_rate[line] = clamp(atoi(e->edittext.str), 32, 2040) / 8;
UpdateIndustryProduction(i);
SetWindowDirty(w);
}
diff --git a/landscape.c b/landscape.c
index 4cffefe65..af0b8cb9b 100644
--- a/landscape.c
+++ b/landscape.c
@@ -461,8 +461,8 @@ void ConvertGroundTilesIntoWaterTiles(void)
for (tile = 0; tile < MapSize(); ++tile) {
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h == 0) {
SetTileType(tile, MP_WATER);
- _m[tile].m5 = 0;
SetTileOwner(tile, OWNER_WATER);
+ _m[tile].m5 = 0;
}
}
}
@@ -630,37 +630,48 @@ void GenerateLandscape(void)
uint flag;
uint32 r;
- if (_opt.landscape == LT_HILLY) {
- for (i = ScaleByMapSize((Random() & 0x7F) + 950); i != 0; --i)
- GenerateTerrain(2, 0);
+ switch (_opt.landscape) {
+ case LT_HILLY:
+ for (i = ScaleByMapSize((Random() & 0x7F) + 950); i != 0; --i) {
+ GenerateTerrain(2, 0);
+ }
+
+ r = Random();
+ flag = GB(r, 0, 2) | 4;
+ for (i = ScaleByMapSize(GB(r, 16, 7) + 450); i != 0; --i) {
+ GenerateTerrain(4, flag);
+ }
+ break;
+
+ case LT_DESERT:
+ for (i = ScaleByMapSize((Random() & 0x7F) + 170); i != 0; --i) {
+ GenerateTerrain(0, 0);
+ }
- r = Random();
- flag = GB(r, 0, 2) | 4;
- for (i = ScaleByMapSize(GB(r, 16, 7) + 450); i != 0; --i)
- GenerateTerrain(4, flag);
- } else if (_opt.landscape == LT_DESERT) {
- for (i = ScaleByMapSize((Random()&0x7F) + 170); i != 0; --i)
- GenerateTerrain(0, 0);
+ r = Random();
+ flag = GB(r, 0, 2) | 4;
+ for (i = ScaleByMapSize(GB(r, 16, 8) + 1700); i != 0; --i) {
+ GenerateTerrain(0, flag);
+ }
- r = Random();
- flag = GB(r, 0, 2) | 4;
- for (i = ScaleByMapSize(GB(r, 16, 8) + 1700); i != 0; --i)
- GenerateTerrain(0, flag);
+ flag ^= 2;
- flag ^= 2;
+ for (i = ScaleByMapSize((Random() & 0x7F) + 410); i != 0; --i) {
+ GenerateTerrain(3, flag);
+ }
+ break;
- for (i = ScaleByMapSize((Random() & 0x7F) + 410); i != 0; --i)
- GenerateTerrain(3, flag);
- } else {
- i = ScaleByMapSize((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes) * 256 + 100);
- for (; i != 0; --i)
- GenerateTerrain(_opt.diff.terrain_type, 0);
+ default:
+ i = ScaleByMapSize((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes) * 256 + 100);
+ for (; i != 0; --i) {
+ GenerateTerrain(_opt.diff.terrain_type, 0);
+ }
+ break;
}
ConvertGroundTilesIntoWaterTiles();
- if (_opt.landscape == LT_DESERT)
- CreateDesertOrRainForest();
+ if (_opt.landscape == LT_DESERT) CreateDesertOrRainForest();
}
void OnTick_Town(void);
diff --git a/npf.c b/npf.c
index ad0fbccbd..2285af1c4 100644
--- a/npf.c
+++ b/npf.c
@@ -208,25 +208,26 @@ static void NPFMarkTile(TileIndex tile)
#ifdef NO_DEBUG_MESSAGES
return;
#else
- if (_debug_npf_level >= 1)
- switch (GetTileType(tile)) {
- case MP_RAILWAY:
- /* DEBUG: mark visited tiles by mowing the grass under them
- * ;-) */
- if (!IsTileDepotType(tile, TRANSPORT_RAIL)) {
- SB(_m[tile].m2, 0, 4, 0);
- MarkTileDirtyByTile(tile);
- }
- break;
- case MP_STREET:
- if (!IsTileDepotType(tile, TRANSPORT_ROAD)) {
- SB(_m[tile].m4, 4, 3, 0);
- MarkTileDirtyByTile(tile);
- }
- break;
- default:
- break;
- }
+ if (_debug_npf_level < 1) return;
+ switch (GetTileType(tile)) {
+ case MP_RAILWAY:
+ /* DEBUG: mark visited tiles by mowing the grass under them ;-) */
+ if (!IsTileDepotType(tile, TRANSPORT_RAIL)) {
+ SB(_m[tile].m2, 0, 4, 0);
+ MarkTileDirtyByTile(tile);
+ }
+ break;
+
+ case MP_STREET:
+ if (!IsTileDepotType(tile, TRANSPORT_ROAD)) {
+ SB(_m[tile].m4, 4, 3, 0);
+ MarkTileDirtyByTile(tile);
+ }
+ break;
+
+ default:
+ break;
+ }
#endif
}
@@ -298,7 +299,7 @@ static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
TileIndex tile = current->tile;
Trackdir trackdir = (Trackdir)current->direction;
int32 cost = 0;
- /* HACK: We create a OpenListNode manualy, so we can call EndNodeCheck */
+ /* HACK: We create a OpenListNode manually, so we can call EndNodeCheck */
OpenListNode new_node;
/* Determine base length */
diff --git a/openttd.h b/openttd.h
index f2ae7684e..8fb3d9f4c 100644
--- a/openttd.h
+++ b/openttd.h
@@ -116,7 +116,7 @@ typedef enum TransportTypes {
* bridges. For now, you should just not change the values for road
* and rail.
*/
- TRANSPORT_RAIL = 0,
+ TRANSPORT_RAIL = 0,
TRANSPORT_ROAD = 1,
TRANSPORT_WATER, // = 2
TRANSPORT_END,
diff --git a/pathfind.c b/pathfind.c
index 8107fc5ed..10961c5ec 100644
--- a/pathfind.c
+++ b/pathfind.c
@@ -558,12 +558,12 @@ static bool NtpVisit(NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint len
uint offs = tpf->hash_tile[hash];
do {
link = NTP_GET_LINK_PTR(tpf, offs);
- if (tile == link->tile && (uint)(link->typelength & 0x3) == dir) {
- if (length >= (uint)(link->typelength >> 2)) return false;
+ if (tile == link->tile && (link->typelength & 0x3U) == dir) {
+ if (length >= link->typelength >> 2) return false;
link->typelength = dir | (length << 2);
return true;
}
- } while ((offs=link->next) != 0xFFFF);
+ } while ((offs = link->next) != 0xFFFF);
}
/* get here if we need to add a new link to link,
@@ -611,9 +611,9 @@ static bool NtpCheck(NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint len
offs = tpf->hash_tile[hash];
for (;;) {
link = NTP_GET_LINK_PTR(tpf, offs);
- if (tile == link->tile && (uint)(link->typelength & 0x3) == dir) {
- assert( (uint)(link->typelength >> 2) <= length);
- return length == (uint)(link->typelength >> 2);
+ if (tile == link->tile && (link->typelength & 0x3U) == dir) {
+ assert(link->typelength >> 2 <= length);
+ return length == link->typelength >> 2;
}
offs = link->next;
assert(offs != 0xffff);
diff --git a/rail_cmd.c b/rail_cmd.c
index 60c49e332..6db554fdb 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -1577,33 +1577,34 @@ typedef struct SetSignalsData {
static bool SetSignalsEnumProc(TileIndex tile, SetSignalsData *ssd, int track, uint length, byte *state)
{
- // the tile has signals?
- if (IsTileType(tile, MP_RAILWAY)) {
- if (HasSignalOnTrack(tile, TrackdirToTrack(track))) {
- if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) {
- // yes, add the signal to the list of signals
- if (ssd->cur != NUM_SSD_ENTRY) {
- ssd->tile[ssd->cur] = tile; // remember the tile index
- ssd->bit[ssd->cur] = track; // and the controlling bit number
- ssd->cur++;
- }
+ if (!IsTileType(tile, MP_RAILWAY)) return false;
- // remember if this block has a presignal.
- ssd->has_presignal |= (_m[tile].m4&1);
+ // the tile has signals?
+ if (HasSignalOnTrack(tile, TrackdirToTrack(track))) {
+ if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) {
+ // yes, add the signal to the list of signals
+ if (ssd->cur != NUM_SSD_ENTRY) {
+ ssd->tile[ssd->cur] = tile; // remember the tile index
+ ssd->bit[ssd->cur] = track; // and the controlling bit number
+ ssd->cur++;
}
- if (HasSignalOnTrackdir(tile, track) && (_m[tile].m4 & 2)) {
- // this is an exit signal that points out from the segment
- ssd->presignal_exits++;
- if (GetSignalState(tile, track) != SIGNAL_STATE_RED)
- ssd->presignal_exits_free++;
- }
+ // remember if this block has a presignal.
+ ssd->has_presignal |= (_m[tile].m4&1);
+ }
- return true;
- } else if (IsTileDepotType(tile, TRANSPORT_RAIL)) {
- return true; // don't look further if the tile is a depot
+ if (HasSignalOnTrackdir(tile, track) && _m[tile].m4 & 2) {
+ // this is an exit signal that points out from the segment
+ ssd->presignal_exits++;
+ if (GetSignalState(tile, track) != SIGNAL_STATE_RED)
+ ssd->presignal_exits_free++;
}
+
+ return true;
+ } else if (IsTileDepotType(tile, TRANSPORT_RAIL)) {
+ return true; // don't look further if the tile is a depot
}
+
return false;
}
@@ -1806,7 +1807,7 @@ bool UpdateSignalsOnSegment(TileIndex tile, byte direction)
direction = ssd.next_dir[ssd.cur_stack];
}
- return (bool)result;
+ return result != 0;
}
void SetSignalsOnBothDir(TileIndex tile, byte track)
@@ -1836,7 +1837,7 @@ static uint GetSlopeZ_Track(const TileInfo* ti)
// inclined foundation
th = _inclined_tileh[f - 15];
}
- } else if ((ti->map5 & 0xC0) == 0xC0) {
+ } else if ((ti->map5 & RAIL_TILE_TYPE_MASK) == RAIL_TYPE_DEPOT_WAYPOINT) {
// depot or waypoint
return z + 8;
}
diff --git a/road_cmd.c b/road_cmd.c
index 1c8952cd3..e45574a69 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -69,16 +69,13 @@ static bool CheckAllowRemoveRoad(TileIndex tile, uint br, bool *edge_road)
uint n;
*edge_road = true;
- if (_game_mode == GM_EDITOR)
- return true;
+ if (_game_mode == GM_EDITOR) return true;
blocks = GetRoadBitsByTile(tile);
- if (blocks == 0)
- return true;
+ if (blocks == 0) return true;
// Only do the special processing for actual players.
- if (_current_player >= MAX_PLAYERS)
- return true;
+ if (_current_player >= MAX_PLAYERS) return true;
// A railway crossing has the road owner in the map3_lo byte.
if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile)) {
@@ -92,8 +89,7 @@ static bool CheckAllowRemoveRoad(TileIndex tile, uint br, bool *edge_road)
return owner == OWNER_NONE || CheckOwnership(owner);
}
- if (_cheats.magic_bulldozer.value)
- return true;
+ if (_cheats.magic_bulldozer.value) return true;
// Get a bitmask of which neighbouring roads has a tile
n = 0;
@@ -108,8 +104,7 @@ static bool CheckAllowRemoveRoad(TileIndex tile, uint br, bool *edge_road)
Town *t;
*edge_road = false;
// you can remove all kind of roads with extra dynamite
- if (_patches.extra_dynamite)
- return true;
+ if (_patches.extra_dynamite) return true;
t = ClosestTownFromTile(tile, _patches.dist_local_authority);
@@ -164,14 +159,15 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (owner == OWNER_TOWN && _game_mode != GM_EDITOR) {
if (IsTileType(tile, MP_TUNNELBRIDGE)) { // index of town is not saved for bridge (no space)
t = ClosestTownFromTile(tile, _patches.dist_local_authority);
- } else
+ } else {
t = GetTown(_m[tile].m2);
- } else
+ }
+ } else {
t = NULL;
+ }
// allow deleting road under bridge
- if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile))
- return CMD_ERROR;
+ if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) return CMD_ERROR;
{
bool b;
@@ -336,7 +332,7 @@ static uint32 CheckRoadSlope(int tileh, byte *pieces, byte existing)
}
// partly leveled up tile, only if there's no road on that tile
- if ( !existing && (tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8) ) {
+ if (!existing && (tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8)) {
// force full pieces.
*pieces |= (*pieces & 0xC) >> 2;
*pieces |= (*pieces & 0x3) << 2;
@@ -383,11 +379,13 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} else if (ti.type == MP_RAILWAY) {
byte m5;
- if (IsSteepTileh(ti.tileh)) // very steep tile
- return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
+ if (IsSteepTileh(ti.tileh)) { // very steep tile
+ return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
+ }
- if (!_valid_tileh_slopes_road[2][ti.tileh]) // prevent certain slopes
- return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
+ if (!_valid_tileh_slopes_road[2][ti.tileh]) { // prevent certain slopes
+ return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
+ }
if (ti.map5 == 2) {
if (pieces & 5) goto do_clear;
@@ -395,8 +393,9 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} else if (ti.map5 == 1) {
if (pieces & 10) goto do_clear;
m5 = 0x18;
- } else
+ } else {
goto do_clear;
+ }
if (flags & DC_EXEC) {
ModifyTile(tile,
@@ -410,26 +409,25 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
return _price.build_road * 2;
} else if (ti.type == MP_TUNNELBRIDGE) {
-
/* check for flat land */
- if (IsSteepTileh(ti.tileh)) // very steep tile
- return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
+ if (IsSteepTileh(ti.tileh)) { // very steep tile
+ return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
+ }
/* is this middle part of a bridge? */
- if ((ti.map5 & 0xC0) != 0xC0)
- goto do_clear;
+ if ((ti.map5 & 0xC0) != 0xC0) goto do_clear;
/* only allow roads pertendicular to bridge */
- if (((pieces & 5U) != 0) == ((ti.map5 & 0x01U) != 0))
- goto do_clear;
+ if (((pieces & 5U) != 0) == ((ti.map5 & 0x01U) != 0)) goto do_clear;
/* check if clear land under bridge */
- if ((ti.map5 & 0xF8) == 0xE8) /* road under bridge */
- return_cmd_error(STR_1007_ALREADY_BUILT);
- else if ((ti.map5 & 0xE0) == 0xE0) /* other transport route under bridge */
- return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
- else if ((ti.map5 & 0xF8) == 0xC8) /* water under bridge */
- return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
+ if ((ti.map5 & 0xF8) == 0xE8) { /* road under bridge */
+ return_cmd_error(STR_1007_ALREADY_BUILT);
+ } else if ((ti.map5 & 0xE0) == 0xE0) { /* other transport route under bridge */
+ return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
+ } else if ((ti.map5 & 0xF8) == 0xC8) { /* water under bridge */
+ return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
+ }
/* all checked, can build road now! */
cost = _price.build_road * 2;
@@ -587,7 +585,7 @@ int32 CmdRemoveLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
TileIndex t = start_tile;
start_tile = end_tile;
end_tile = t;
- p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0;
+ p2 ^= IS_INT_INSIDE(p2 & 3, 1, 3) ? 3 : 0;
}
cost = 0;
@@ -735,17 +733,23 @@ uint GetRoadFoundation(uint tileh, uint bits)
{
int i;
// normal level sloped building
- if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0)
- return tileh;
+ if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) return tileh;
// inclined sloped building
- if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) &&
- ((bits == (ROAD_SW | ROAD_NE)) || (i++, bits == (ROAD_NW | ROAD_SE))))
+ if ((
+ (i = 0, tileh == 1) ||
+ (i += 2, tileh == 2) ||
+ (i += 2, tileh == 4) ||
+ (i += 2, tileh == 8)
+ ) && (
+ ( bits == (ROAD_SW | ROAD_NE)) ||
+ (i++, bits == (ROAD_NW | ROAD_SE))
+ )) {
return i + 15;
+ }
// rail crossing
- if ((bits & 0x10) && _valid_tileh_slopes_road[2][tileh])
- return tileh;
+ if ((bits & 0x10) && _valid_tileh_slopes_road[2][tileh]) return tileh;
return 0;
}
@@ -808,14 +812,12 @@ static void DrawRoadBits(TileInfo *ti, byte road, byte ground_type, bool snow, b
}
// Draw extra details.
- drts = _road_display_table[ground_type][road];
- while ((image = drts->image) != 0) {
+ for (drts = _road_display_table[ground_type][road]; drts->image != 0; drts++) {
int x = ti->x | drts->subcoord_x;
int y = ti->y | drts->subcoord_y;
byte z = ti->z;
if (ti->tileh != 0) z = GetSlopeZ(x, y);
- AddSortableSpriteToDraw(image, x, y, 2, 2, 0x10, z);
- drts++;
+ AddSortableSpriteToDraw(drts->image, x, y, 2, 2, 0x10, z);
}
}
@@ -980,22 +982,23 @@ static void TileLoop_Road(TileIndex tile)
Town *t;
int grp;
- if (_opt.landscape == LT_HILLY) {
- // Fix snow style if the road is above the snowline
- if ((_m[tile].m4 & 0x80) != ((GetTileZ(tile) > _opt.snow_line) ? 0x80 : 0x00)) {
- _m[tile].m4 ^= 0x80;
- MarkTileDirtyByTile(tile);
- }
- } else if (_opt.landscape == LT_DESERT) {
- // Fix desert style
- if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) {
- _m[tile].m4 |= 0x80;
- MarkTileDirtyByTile(tile);
- }
+ switch (_opt.landscape) {
+ case LT_HILLY:
+ if ((_m[tile].m4 & 0x80) != (GetTileZ(tile) > _opt.snow_line ? 0x80 : 0x00)) {
+ _m[tile].m4 ^= 0x80;
+ MarkTileDirtyByTile(tile);
+ }
+ break;
+
+ case LT_DESERT:
+ if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) {
+ _m[tile].m4 |= 0x80;
+ MarkTileDirtyByTile(tile);
+ }
+ break;
}
- if (_m[tile].m5 & 0xE0)
- return;
+ if (_m[tile].m5 & 0xE0) return;
if (GB(_m[tile].m4, 4, 3) < 6) {
t = ClosestTownFromTile(tile, (uint)-1);
@@ -1007,8 +1010,8 @@ static void TileLoop_Road(TileIndex tile)
// Show an animation to indicate road work
if (t->road_build_months != 0 &&
!(DistanceManhattan(t->xy, tile) >= 8 && grp == 0) &&
- (_m[tile].m5==5 || _m[tile].m5==10)) {
- if (GetTileSlope(tile, NULL) == 0 && EnsureNoVehicle(tile) && CHANCE16(1,20)) {
+ (_m[tile].m5 == 5 || _m[tile].m5 == 10)) {
+ if (GetTileSlope(tile, NULL) == 0 && EnsureNoVehicle(tile) && CHANCE16(1, 20)) {
_m[tile].m4 |= (GB(_m[tile].m4, 4, 3) <= 2 ? 7 : 6) << 4;
SndPlayTileFx(SND_21_JACKHAMMER, tile);
@@ -1027,8 +1030,7 @@ static void TileLoop_Road(TileIndex tile)
const byte *p = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp];
byte b = GB(_m[tile].m4, 4, 3);
- if (b == p[0])
- return;
+ if (b == p[0]) return;
if (b == p[1]) {
b = p[0];
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index 0964aaf39..7bf29103f 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -82,7 +82,7 @@ void DrawRoadVehEngine(int x, int y, EngineID engine, uint32 image_ormod)
if (is_custom_sprite(spritenum)) {
int sprite = GetCustomVehicleIcon(engine, 6);
- if (sprite) {
+ if (sprite != 0) {
DrawSprite(sprite | image_ormod, x, y);
return;
}
@@ -263,8 +263,7 @@ int32 CmdSellRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
ClearSlot(v, v->u.road.slot);
DeleteVehicle(v);
- if (IsLocalPlayer())
- InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window
+ if (IsLocalPlayer()) InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road);
}
return -(int32)v->value;
@@ -310,10 +309,11 @@ static Depot *FindClosestRoadDepot(Vehicle *v)
Trackdir trackdir = GetVehicleTrackdir(v);
ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE);
- if (ftd.best_bird_dist == 0)
+ if (ftd.best_bird_dist == 0) {
return GetDepotByTile(ftd.node.tile); /* Target found */
- else
+ } else {
return NULL; /* Target not found */
+ }
/* We do not search in two directions here, why should we? We can't reverse right now can we? */
} else {
RoadFindDepotData rfdd;
@@ -324,8 +324,7 @@ static Depot *FindClosestRoadDepot(Vehicle *v)
for (i = 0; i != 4; i++)
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadSignalFindDepot, NULL, &rfdd);
- if (rfdd.best_length == (uint)-1)
- return NULL;
+ if (rfdd.best_length == (uint)-1) return NULL;
return GetDepotByTile(rfdd.tile);
}
@@ -455,8 +454,7 @@ static void RoadVehDelete(Vehicle *v)
RebuildVehicleLists();
InvalidateWindow(WC_COMPANY, v->owner);
- if (IsTileType(v->tile, MP_STATION))
- ClearCrashedStation(v);
+ if (IsTileType(v->tile, MP_STATION)) ClearCrashedStation(v);
BeginVehicleMove(v);
EndVehicleMove(v);
@@ -471,7 +469,9 @@ static byte SetRoadVehPosition(Vehicle *v, int x, int y)
// need this hint so it returns the right z coordinate on bridges.
_get_z_hint = v->z_pos;
- new_z = GetSlopeZ(v->x_pos=x, v->y_pos=y);
+ v->x_pos = x;
+ v->y_pos = y;
+ new_z = GetSlopeZ(x, y);
_get_z_hint = 0;
old_z = v->z_pos;
@@ -486,7 +486,7 @@ static void RoadVehSetRandomDirection(Vehicle *v)
{
static const int8 _turn_prob[4] = { -1, 0, 0, 1 };
uint32 r = Random();
- v->direction = (v->direction+_turn_prob[r&3])&7;
+ v->direction = (v->direction + _turn_prob[r & 3]) & 7;
BeginVehicleMove(v);
UpdateRoadVehDeltaXY(v);
v->cur_image = GetRoadVehImage(v, v->direction);
@@ -499,8 +499,7 @@ static void RoadVehIsCrashed(Vehicle *v)
if (v->u.road.crashed_ctr == 2) {
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
} else if (v->u.road.crashed_ctr <= 45) {
- if ((v->tick_counter & 7) == 0)
- RoadVehSetRandomDirection(v);
+ if ((v->tick_counter & 7) == 0) RoadVehSetRandomDirection(v);
} else if (v->u.road.crashed_ctr >= 2220) {
RoadVehDelete(v);
}
@@ -684,7 +683,7 @@ static void HandleRoadVehLoading(Vehicle *v)
InvalidateVehicleOrder(v);
}
-static void StartRoadVehSound(Vehicle *v)
+static void StartRoadVehSound(const Vehicle* v)
{
SoundFx s = RoadVehInfo(v->engine_type)->sfx;
if (s == SND_19_BUS_START_PULL_AWAY && (v->tick_counter & 3) == 0)
@@ -693,8 +692,9 @@ static void StartRoadVehSound(Vehicle *v)
}
typedef struct RoadVehFindData {
- int x,y;
- Vehicle *veh;
+ int x;
+ int y;
+ const Vehicle* veh;
byte dir;
} RoadVehFindData;
@@ -727,8 +727,7 @@ static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, byte dir)
RoadVehFindData rvf;
Vehicle *u;
- if (v->u.road.reverse_ctr != 0)
- return NULL;
+ if (v->u.road.reverse_ctr != 0) return NULL;
rvf.x = x;
rvf.y = y;
@@ -823,23 +822,22 @@ static byte RoadVehGetNewDirection(Vehicle *v, int x, int y)
x = x - v->x_pos + 1;
y = y - v->y_pos + 1;
- if ((uint)x > 2 || (uint)y > 2)
- return v->direction;
- return _roadveh_new_dir[y*4+x];
+ if ((uint)x > 2 || (uint)y > 2) return v->direction;
+ return _roadveh_new_dir[y * 4 + x];
}
static byte RoadVehGetSlidingDirection(Vehicle *v, int x, int y)
{
- byte b = RoadVehGetNewDirection(v,x,y);
+ byte b = RoadVehGetNewDirection(v, x, y);
byte d = v->direction;
if (b == d) return d;
- d = (d+1)&7;
- if (b==d) return d;
- d = (d-2)&7;
- if (b==d) return d;
- if (b==((d-1)&7)) return d;
- if (b==((d-2)&7)) return d;
- return (d+2)&7;
+ d = (d + 1) & 7;
+ if (b == d) return d;
+ d = (d - 2) & 7;
+ if (b == d) return d;
+ if (b == ((d - 1) & 7)) return d;
+ if (b == ((d - 2) & 7)) return d;
+ return (d + 2) & 7;
}
typedef struct OvertakeData {
@@ -850,9 +848,9 @@ typedef struct OvertakeData {
static void *EnumFindVehToOvertake(Vehicle *v, OvertakeData *od)
{
- if (v->tile != od->tile || v->type != VEH_Road || v == od->u || v == od->v)
- return NULL;
- return v;
+ return
+ v->tile == od->tile && v->type == VEH_Road && v == od->u && v == od->v ?
+ v : NULL;
}
static bool FindRoadVehToOvertake(OvertakeData *od)
@@ -911,15 +909,13 @@ static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
static void RoadZPosAffectSpeed(Vehicle *v, byte old_z)
{
- if (old_z == v->z_pos)
- return;
+ if (old_z == v->z_pos) return;
if (old_z < v->z_pos) {
- v->cur_speed = v->cur_speed * 232 >> 8;
+ v->cur_speed = v->cur_speed * 232 / 256; // slow down by ~10%
} else {
uint16 spd = v->cur_speed + 2;
- if (spd <= v->max_speed)
- v->cur_speed = spd;
+ if (spd <= v->max_speed) v->cur_speed = spd;
}
}
@@ -935,7 +931,7 @@ static int PickRandomBit(uint bits)
num = RandomRange(num);
- for (i = 0; !((bits & 1) && ((int)--num) < 0); bits >>= 1, i++);
+ for (i = 0; !(bits & 1) || (int)--num >= 0; bits >>= 1, i++) {}
return i;
}
@@ -973,8 +969,7 @@ static int RoadFindPathToDest(Vehicle *v, TileIndex tile, int enterdir)
byte m5;
{
- uint32 r;
- r = GetTileTrackStatus(tile, TRANSPORT_ROAD);
+ uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD);
signal = GB(r, 16, 16);
bitmask = GB(r, 0, 16);
}
@@ -1100,8 +1095,7 @@ do_it:;
found_best_track:;
- if (HASBIT(signal, best_track))
- return -1;
+ if (HASBIT(signal, best_track)) return -1;
return best_track;
}
@@ -1147,8 +1141,7 @@ static void RoadVehController(Vehicle *v)
// decrease counters
v->tick_counter++;
- if (v->u.road.reverse_ctr != 0)
- v->u.road.reverse_ctr--;
+ if (v->u.road.reverse_ctr != 0) v->u.road.reverse_ctr--;
// handle crashed
if (v->u.road.crashed_ctr != 0) {
@@ -1277,8 +1270,8 @@ again:
x = TileX(tile) * 16 + rdp[0].x;
y = TileY(tile) * 16 + rdp[0].y;
- if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y)))
- return;
+ newdir = RoadVehGetSlidingDirection(v, x, y);
+ if (RoadVehFindCloseTo(v, x, y, newdir)) return;
r = VehicleEnterTile(v, tile, x, y);
if (r & 8) {
@@ -1336,8 +1329,8 @@ again:
x = TileX(v->tile) * 16 + rdp[1].x;
y = TileY(v->tile) * 16 + rdp[1].y;
- if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y)))
- return;
+ newdir = RoadVehGetSlidingDirection(v, x, y);
+ if (RoadVehFindCloseTo(v, x, y, newdir)) return;
r = VehicleEnterTile(v, v->tile, x, y);
if (r & 8) {
@@ -1365,8 +1358,7 @@ again:
new_dir = RoadVehGetSlidingDirection(v, x, y);
if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && (u=RoadVehFindCloseTo(v, x, y, new_dir)) != NULL) {
- if (v->u.road.overtaking == 0)
- RoadVehCheckOvertake(v, u);
+ if (v->u.road.overtaking == 0) RoadVehCheckOvertake(v, u);
return;
}
@@ -1449,9 +1441,7 @@ again:
return;
}
- if ((r & 4) == 0) {
- v->u.road.frame++;
- }
+ if ((r & 4) == 0) v->u.road.frame++;
v->cur_image = GetRoadVehImage(v, v->direction);
UpdateRoadVehDeltaXY(v);
@@ -1489,7 +1479,8 @@ void RoadVehEnterDepot(Vehicle *v)
STR_9016_ROAD_VEHICLE_IS_WAITING,
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0),
v->index,
- 0);
+ 0
+ );
}
}
}
@@ -1500,10 +1491,8 @@ void RoadVehEnterDepot(Vehicle *v)
static void AgeRoadVehCargo(Vehicle *v)
{
- if (_age_cargo_skip_counter != 0)
- return;
- if (v->cargo_days != 255)
- v->cargo_days++;
+ if (_age_cargo_skip_counter != 0) return;
+ if (v->cargo_days != 255) v->cargo_days++;
}
void RoadVeh_Tick(Vehicle *v)
@@ -1516,17 +1505,10 @@ static void CheckIfRoadVehNeedsService(Vehicle *v)
{
Depot *depot;
- if (_patches.servint_roadveh == 0)
- return;
-
- if (!VehicleNeedsService(v))
- return;
-
- if (v->vehstatus & VS_STOPPED)
- return;
-
- if (_patches.gotodepot && VehicleHasDepotOrders(v))
- return;
+ if (_patches.servint_roadveh == 0) return;
+ if (!VehicleNeedsService(v)) return;
+ if (v->vehstatus & VS_STOPPED) return;
+ if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
// Don't interfere with a depot visit scheduled by the user, or a
// depot visit by the order list.
@@ -1534,9 +1516,8 @@ static void CheckIfRoadVehNeedsService(Vehicle *v)
(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0)
return;
- //If we already got a slot at a stop, use that FIRST, and go to a depot later
- if (v->u.road.slot != NULL)
- return;
+ // If we already got a slot at a stop, use that FIRST, and go to a depot later
+ if (v->u.road.slot != NULL) return;
depot = FindClosestRoadDepot(v);
@@ -1567,11 +1548,8 @@ void OnNewDay_RoadVeh(Vehicle *v)
int32 cost;
Station *st;
- if ((++v->day_counter & 7) == 0)
- DecreaseVehicleValue(v);
-
- if (v->u.road.blocked_ctr == 0)
- CheckVehicleBreakdown(v);
+ if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v);
+ if (v->u.road.blocked_ctr == 0) CheckVehicleBreakdown(v);
AgeVehicle(v);
CheckIfRoadVehNeedsService(v);
@@ -1653,8 +1631,7 @@ void OnNewDay_RoadVeh(Vehicle *v)
}
}
- if (v->vehstatus & VS_STOPPED)
- return;
+ if (v->vehstatus & VS_STOPPED) return;
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364;
diff --git a/terraform_gui.c b/terraform_gui.c
index 1834d8161..02d6f9490 100644
--- a/terraform_gui.c
+++ b/terraform_gui.c
@@ -63,7 +63,7 @@ static void GenerateDesertArea(TileIndex end, TileIndex start)
_generating_world = false;
}
-/** Scenario editor command that generates desert areas */
+/** Scenario editor command that generates rocky areas */
static void GenerateRockyArea(TileIndex end, TileIndex start)
{
int size_x, size_y;
diff --git a/tile.c b/tile.c
index 9fe175766..7d2f680b8 100644
--- a/tile.c
+++ b/tile.c
@@ -46,8 +46,7 @@ uint GetTileSlope(TileIndex tile, uint *h)
if ((d -= min) != 0) r += (--d << 4) + 2;
if ((b -= min) != 0) r += (--b << 4) + 1;
- if (h != NULL)
- *h = min * 8;
+ if (h != NULL) *h = min * 8;
return r;
}
diff --git a/town_cmd.c b/town_cmd.c
index 8d2f43de4..492cb07a2 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -570,7 +570,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1)
int a,b,rcmd;
TileIndex tmptile;
TileInfo ti;
- int i;
+ uint i;
int j;
TileIndex tile = *tile_ptr;
diff --git a/train_cmd.c b/train_cmd.c
index bb6b97e3d..6bc48e883 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -305,8 +305,7 @@ static int GetTrainAcceleration(Vehicle *v, bool mode)
num++;
drag_coeff += 3;
- if (u->u.rail.track == 0x80)
- max_speed = min(61, max_speed);
+ if (u->u.rail.track == 0x80) max_speed = min(max_speed, 61);
if (HASBIT(u->u.rail.flags, VRF_GOINGUP)) {
incl += u->u.rail.cached_veh_weight * 60; //3% slope, quite a bit actually
@@ -322,8 +321,9 @@ static int GetTrainAcceleration(Vehicle *v, bool mode)
resistance += 60 * num;
resistance += friction * mass * speed / 1000;
resistance += (area * drag_coeff * speed * speed) / 10000;
- } else
+ } else {
resistance = (area * (drag_coeff / 2) * speed * speed) / 10000;
+ }
resistance += incl;
resistance *= 4; //[N]
@@ -452,13 +452,11 @@ static void AddArticulatedParts(const RailVehicleInfo *rvi, Vehicle **vl)
bool flip_image;
uint i;
- if (!HASBIT(rvi->callbackmask, CBM_ARTIC_ENGINE))
- return;
+ if (!HASBIT(rvi->callbackmask, CBM_ARTIC_ENGINE)) return;
for (i = 1; i < 10; i++) {
callback = GetCallBackResult(CBID_TRAIN_ARTIC_ENGINE + (i << 8), v->engine_type, NULL);
- if (callback == CALLBACK_FAILED || callback == 0xFF)
- return;
+ if (callback == CALLBACK_FAILED || callback == 0xFF) return;
u->next = vl[i];
u = u->next;
@@ -632,7 +630,7 @@ static const byte _railveh_score[] = {
static int32 EstimateTrainCost(const RailVehicleInfo* rvi)
{
- return (rvi->base_cost * (_price.build_railvehicle >> 3)) >> 5;
+ return rvi->base_cost * (_price.build_railvehicle >> 3) >> 5;
}
static void AddRearEngineToMultiheadedTrain(Vehicle* v, Vehicle* u, bool building)
@@ -858,8 +856,7 @@ static Vehicle *FindGoodVehiclePos(const Vehicle *src)
TileIndex tile = src->tile;
FOR_ALL_VEHICLES(dst) {
- if (dst->type == VEH_Train && IsFreeWagon(dst) &&
- dst->tile == tile) {
+ if (dst->type == VEH_Train && IsFreeWagon(dst) && dst->tile == tile) {
// check so all vehicles in the line have the same engine.
Vehicle *v = dst;
@@ -908,7 +905,6 @@ static void NormaliseTrainConsist(Vehicle *v)
if (u == v->u.rail.other_multiheaded_part) continue;
AddWagonToConsist(v->u.rail.other_multiheaded_part, u);
-
}
}
@@ -988,9 +984,7 @@ int32 CmdMoveRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
engine = NULL;
}
if (u == dst) {
- if (engine != NULL) {
- dst = engine->u.rail.other_multiheaded_part;
- }
+ if (engine != NULL) dst = engine->u.rail.other_multiheaded_part;
break;
}
@@ -1052,8 +1046,7 @@ int32 CmdMoveRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (unit_num > _patches.max_trains)
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
- if (flags & DC_EXEC)
- src->unitnumber = unit_num;
+ if (flags & DC_EXEC) src->unitnumber = unit_num;
}
@@ -1365,11 +1358,10 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
/* 3. If it is still a valid train after selling, update its acceleration and cached values */
- if ((flags & DC_EXEC) && first != NULL) {
+ if (flags & DC_EXEC && first != NULL) {
NormaliseTrainConsist(first);
TrainConsistChanged(first);
- if (IsFrontEngine(first))
- UpdateTrainAcceleration(first);
+ if (IsFrontEngine(first)) UpdateTrainAcceleration(first);
InvalidateWindow(WC_VEHICLE_DETAILS, first->index);
InvalidateWindow(WC_VEHICLE_REFIT, first->index);
}
@@ -1415,7 +1407,7 @@ static void SetLastSpeed(Vehicle* v, int spd)
int old = v->u.rail.last_speed;
if (spd != old) {
v->u.rail.last_speed = spd;
- if (_patches.vehicle_speed || !old != !spd)
+ if (_patches.vehicle_speed || (old == 0) != (spd == 0))
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
}
}
@@ -1702,16 +1694,23 @@ int32 CmdRefitRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (amount == CALLBACK_FAILED) { // callback failed or not used, use default
CargoID old_cid = rvi->cargo_type;
- /* normally, the capacity depends on the cargo type, a rail vehicle
- * can carry twice as much mail/goods as normal cargo,
- * and four times as much passengers */
+ /* normally, the capacity depends on the cargo type, a rail vehicle can
+ * carry twice as much mail/goods as normal cargo, and four times as
+ * many passengers
+ */
amount = rvi->capacity;
- (old_cid == CT_PASSENGERS) ||
- (amount <<= 1, old_cid == CT_MAIL || old_cid == CT_GOODS) ||
- (amount <<= 1, true);
- (new_cid == CT_PASSENGERS) ||
- (amount >>= 1, new_cid == CT_MAIL || new_cid == CT_GOODS) ||
- (amount >>= 1, true);
+ switch (old_cid) {
+ case CT_PASSENGERS: break;
+ case CT_MAIL:
+ case CT_GOODS: amount *= 2; break;
+ default: amount *= 4; break;
+ }
+ switch (new_cid) {
+ case CT_PASSENGERS: break;
+ case CT_MAIL:
+ case CT_GOODS: amount /= 2; break;
+ default: amount /= 4; break;
+ }
};
if (amount != 0) {
@@ -1726,7 +1725,7 @@ int32 CmdRefitRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
}
}
- } while ( (v=v->next) != NULL );
+ } while ((v = v->next) != NULL);
_returned_refit_capacity = num;
@@ -1747,7 +1746,7 @@ typedef struct TrainFindDepotData {
static bool NtpCallbFindDepot(TileIndex tile, TrainFindDepotData *tfdd, int track, uint length)
{
if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, tfdd->owner)) {
- if ((_m[tile].m5 & ~0x3) == 0xC0) {
+ if ((_m[tile].m5 & 0xFC) == 0xC0) {
tfdd->best_length = length;
tfdd->tile = tile;
return true;
@@ -1795,8 +1794,7 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v)
* work for now :-) We can possibly change this when the old pathfinder
* is removed. */
tfdd.best_length = ftd.best_path_dist / NPF_TILE_LENGTH;
- if (NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE))
- tfdd.reverse = true;
+ if (NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE)) tfdd.reverse = true;
}
} else {
// search in the forward direction first.
@@ -1954,13 +1952,8 @@ static void TrainPlayLeaveStationSound(const Vehicle* v)
SndPlayVehicleFx(sfx[RailVehInfo(engtype)->engclass], v);
break;
- case RAILTYPE_MONO:
- SndPlayVehicleFx(SND_47_MAGLEV_2, v);
- break;
-
- case RAILTYPE_MAGLEV:
- SndPlayVehicleFx(SND_41_MAGLEV, v);
- break;
+ case RAILTYPE_MONO: SndPlayVehicleFx(SND_47_MAGLEV_2, v); break;
+ case RAILTYPE_MAGLEV: SndPlayVehicleFx(SND_41_MAGLEV, v); break;
}
}
@@ -2113,11 +2106,10 @@ static byte ChooseTrainTrack(Vehicle *v, TileIndex tile, int enterdir, TrackdirB
static float f;
#endif
- assert( (trackdirbits & ~0x3F) == 0);
+ assert((trackdirbits & ~0x3F) == 0);
/* quick return in case only one possible track is available */
- if (KILL_FIRST_BIT(trackdirbits) == 0)
- return FIND_FIRST_BIT(trackdirbits);
+ if (KILL_FIRST_BIT(trackdirbits) == 0) return FIND_FIRST_BIT(trackdirbits);
if (_patches.new_pathfinding_all) { /* Use a new pathfinding for everything */
NPFFindStationOrTileData fstd;
@@ -2214,10 +2206,11 @@ static bool CheckReverseTrain(Vehicle *v)
/* We didn't find anything, just keep on going straight ahead */
reverse_best = false;
} else {
- if (NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE))
+ if (NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE)) {
reverse_best = true;
- else
+ } else {
reverse_best = false;
+ }
}
} else {
for (;;) {
@@ -2260,8 +2253,7 @@ good:;
best_track_dist = fd.best_track_dist;
reverse_best = reverse;
bad:;
- if (reverse != 0)
- break;
+ if (reverse != 0) break;
reverse = 2;
}
}
@@ -2455,7 +2447,8 @@ static void TrainEnterStation(Vehicle *v, StationID station)
STR_8801_CITIZENS_CELEBRATE_FIRST,
flags,
v->index,
- 0);
+ 0
+ );
}
// Did we reach the final destination?
@@ -2678,8 +2671,7 @@ static void SetVehicleCrashed(Vehicle *v)
{
Vehicle *u;
- if (v->u.rail.crash_anim_pos != 0)
- return;
+ if (v->u.rail.crash_anim_pos != 0) return;
v->u.rail.crash_anim_pos++;
@@ -2765,8 +2757,7 @@ static void *CheckVehicleAtSignal(Vehicle *v, void *data)
v->tile == vasd->tile) {
byte diff = (v->direction - vasd->direction + 2) & 7;
- if (diff == 2 || (v->cur_speed <= 5 && diff <= 4))
- return v;
+ if (diff == 2 || (v->cur_speed <= 5 && diff <= 4)) return v;
}
return NULL;
}
@@ -2796,8 +2787,7 @@ static void TrainController(Vehicle *v)
} else {
/* is not inside depot */
- if (!TrainCheckIfLineEnds(v))
- return;
+ if (!TrainCheckIfLineEnds(v)) return;
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
if (r & 0x8) {
@@ -2831,14 +2821,15 @@ static void TrainController(Vehicle *v)
/* Combine the from & to directions.
* Now, the lower byte contains the track status, and the byte at bit 16 contains
* the signal status. */
- tracks = ts|(ts >> 8);
+ tracks = ts | (ts >> 8);
bits = tracks & 0xFF;
- if (_patches.new_pathfinding_all && _patches.forbid_90_deg && prev == NULL)
+ if (_patches.new_pathfinding_all && _patches.forbid_90_deg && prev == NULL) {
/* We allow wagons to make 90 deg turns, because forbid_90_deg
* can be switched on halfway a turn */
bits &= ~TrackCrossesTracks(FIND_FIRST_BIT(v->u.rail.track));
+ }
- if ( bits == 0) {
+ if (bits == 0) {
//debug("%x == 0", bits);
goto invalid_rail;
}
@@ -2878,7 +2869,7 @@ static void TrainController(Vehicle *v)
/* Call the landscape function and tell it that the vehicle entered the tile */
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
- if (r&0x8){
+ if (r & 0x8) {
//debug("%x & 0x8", r);
goto invalid_rail;
}
@@ -2891,17 +2882,14 @@ static void TrainController(Vehicle *v)
assert(v->u.rail.track);
}
- if (IsFrontEngine(v))
- TrainMovedChangeSignals(gp.new_tile, enterdir);
+ if (IsFrontEngine(v)) TrainMovedChangeSignals(gp.new_tile, enterdir);
/* Signals can only change when the first
* (above) or the last vehicle moves. */
if (v->next == NULL)
TrainMovedChangeSignals(gp.old_tile, (enterdir) ^ 2);
- if (prev == NULL) {
- AffectSpeedByDirChange(v, chosen_dir);
- }
+ if (prev == NULL) AffectSpeedByDirChange(v, chosen_dir);
v->direction = chosen_dir;
}
@@ -2951,9 +2939,8 @@ red_light: {
if (!(_m[gp.new_tile].m3 & SignalAgainstTrackdir(i))) {
v->cur_speed = 0;
v->subspeed = 0;
- v->progress = 255-100;
- if (++v->load_unload_time_rem < _patches.wait_oneway_signal * 20)
- return;
+ v->progress = 255 - 100;
+ if (++v->load_unload_time_rem < _patches.wait_oneway_signal * 20) return;
} else if (_m[gp.new_tile].m3 & SignalAlongTrackdir(i)){
v->cur_speed = 0;
v->subspeed = 0;
@@ -2965,8 +2952,7 @@ red_light: {
vasd.direction = dir ^ 4;
/* check if a train is waiting on the other side */
- if (VehicleFromPos(o_tile, &vasd, CheckVehicleAtSignal) == NULL)
- return;
+ if (VehicleFromPos(o_tile, &vasd, CheckVehicleAtSignal) == NULL) return;
}
}
}
@@ -3016,8 +3002,7 @@ static void DeleteLastWagon(Vehicle *v)
if (v->u.rail.track == 0x40) { // inside a tunnel
TileIndex endtile = CheckTunnelBusy(v->tile, NULL);
- if (endtile == INVALID_TILE) // tunnel is busy (error returned)
- return;
+ if (endtile == INVALID_TILE) return; // tunnel is busy (error returned)
switch (v->direction) {
case 1:
@@ -3040,7 +3025,7 @@ static void DeleteLastWagon(Vehicle *v)
static void ChangeTrainDirRandomly(Vehicle *v)
{
- static int8 _random_dir_change[4] = { -1, 0, 0, 1};
+ static const int8 _random_dir_change[4] = { -1, 0, 0, 1 };
do {
//I need to buffer the train direction
@@ -3052,12 +3037,12 @@ static void ChangeTrainDirRandomly(Vehicle *v)
v->cur_image = GetTrainImage(v, v->direction);
AfterSetTrainPos(v, false);
}
- } while ( (v=v->next) != NULL);
+ } while ((v = v->next) != NULL);
}
static void HandleCrashedTrain(Vehicle *v)
{
- int state = ++v->u.rail.crash_anim_pos, index;
+ int state = ++v->u.rail.crash_anim_pos;
uint32 r;
Vehicle *u;
@@ -3066,7 +3051,7 @@ static void HandleCrashedTrain(Vehicle *v)
}
if (state <= 200 && CHANCE16R(1, 7, r)) {
- index = (r * 10 >> 16);
+ int index = (r * 10 >> 16);
u = v;
do {
@@ -3080,12 +3065,10 @@ static void HandleCrashedTrain(Vehicle *v)
EV_EXPLOSION_SMALL);
break;
}
- } while ( (u=u->next) != NULL);
+ } while ((u = u->next) != NULL);
}
- if (state <= 240 && !(v->tick_counter&3)) {
- ChangeTrainDirRandomly(v);
- }
+ if (state <= 240 && !(v->tick_counter & 3)) ChangeTrainDirRandomly(v);
if (state >= 4440 && !(v->tick_counter&0x1F)) {
DeleteLastWagon(v);
@@ -3174,27 +3157,13 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
y = v->y_pos & 0xF;
switch (v->direction) {
- case 0:
- x = (~x) + (~y) + 24;
- break;
- case 7:
- x = y;
- /* fall through */
- case 1:
- x = (~x) + 16;
- break;
- case 2:
- x = (~x) + y + 8;
- break;
- case 3:
- x = y;
- break;
- case 4:
- x = x + y - 8;
- break;
- case 6:
- x = (~y) + x + 8;
- break;
+ case 0: x = ~x + ~y + 24; break;
+ case 7: x = y; /* FALLTHROUGH */
+ case 1: x = ~x + 16; break;
+ case 2: x = ~x + y + 8; break;
+ case 3: x = y; break;
+ case 4: x = x + y - 8; break;
+ case 6: x = ~y + x + 8; break;
}
if (GB(ts, 0, 16) != 0) {
@@ -3227,7 +3196,7 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
// slow down
v->vehstatus |= VS_TRAIN_SLOWING;
break_speed = _breakdown_speeds[x & 0xF];
- if (!(v->direction&1)) break_speed >>= 1;
+ if (!(v->direction & 1)) break_speed >>= 1;
if (break_speed < v->cur_speed) v->cur_speed = break_speed;
return true;
@@ -3243,8 +3212,7 @@ static void TrainLocoHandler(Vehicle *v, bool mode)
return;
}
- if (v->u.rail.force_proceed != 0)
- v->u.rail.force_proceed--;
+ if (v->u.rail.force_proceed != 0) v->u.rail.force_proceed--;
/* train is broken down? */
if (v->breakdown_ctr != 0) {
@@ -3260,9 +3228,7 @@ static void TrainLocoHandler(Vehicle *v, bool mode)
}
/* exit if train is stopped */
- if (v->vehstatus & VS_STOPPED && v->cur_speed == 0)
- return;
-
+ if (v->vehstatus & VS_STOPPED && v->cur_speed == 0) return;
if (ProcessTrainOrder(v)) {
v->load_unload_time_rem = 0;
@@ -3274,19 +3240,16 @@ static void TrainLocoHandler(Vehicle *v, bool mode)
HandleTrainLoading(v, mode);
- if (v->current_order.type == OT_LOADING)
- return;
+ if (v->current_order.type == OT_LOADING) return;
- if (CheckTrainStayInDepot(v))
- return;
+ if (CheckTrainStayInDepot(v)) return;
if (!mode) HandleLocomotiveSmokeCloud(v);
j = UpdateTrainSpeed(v);
if (j == 0) {
// if the vehicle has speed 0, update the last_speed field.
- if (v->cur_speed != 0)
- return;
+ if (v->cur_speed != 0) return;
} else {
TrainCheckIfLineEnds(v);
@@ -3409,8 +3372,9 @@ static void CheckIfTrainNeedsService(Vehicle *v)
if (v->current_order.type == OT_GOTO_DEPOT &&
v->current_order.station != depot->index &&
- !CHANCE16(3,16))
+ !CHANCE16(3, 16)) {
return;
+ }
v->current_order.type = OT_GOTO_DEPOT;
v->current_order.flags = OF_NON_STOP;
@@ -3436,8 +3400,7 @@ void OnNewDay_Train(Vehicle *v)
{
TileIndex tile;
- if ((++v->day_counter & 7) == 0)
- DecreaseVehicleValue(v);
+ if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v);
if (IsFrontEngine(v)) {
CheckVehicleBreakdown(v);
@@ -3582,46 +3545,46 @@ void ConvertOldMultiheadToNew(void)
if (HASBIT(v->subtype, 7) && ((v->subtype & ~0x80) == 0 || (v->subtype & ~0x80) == 4)) {
Vehicle *u = v;
- BEGIN_ENUM_WAGONS(u)
+ BEGIN_ENUM_WAGONS(u) {
const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
- CLRBIT(u->subtype, 7);
- switch (u->subtype) {
- case 0: /* TS_Front_Engine */
- if (rvi->flags & RVI_MULTIHEAD) {
- SetMultiheaded(u);
- }
- SetFrontEngine(u);
- SetTrainEngine(u);
- break;
- case 1: /* TS_Artic_Part */
- u->subtype = 0;
- SetArticulatedPart(u);
- break;
- case 2: /* TS_Not_First */
- u->subtype = 0;
- if (rvi->flags & RVI_WAGON) {
- // normal wagon
- SetTrainWagon(u);
+
+ CLRBIT(u->subtype, 7);
+ switch (u->subtype) {
+ case 0: /* TS_Front_Engine */
+ if (rvi->flags & RVI_MULTIHEAD) SetMultiheaded(u);
+ SetFrontEngine(u);
+ SetTrainEngine(u);
break;
- }
+
+ case 1: /* TS_Artic_Part */
+ u->subtype = 0;
+ SetArticulatedPart(u);
+ break;
+
+ case 2: /* TS_Not_First */
+ u->subtype = 0;
+ if (rvi->flags & RVI_WAGON) {
+ // normal wagon
+ SetTrainWagon(u);
+ break;
+ }
if (rvi->flags & RVI_MULTIHEAD && rvi->image_index == u->spritenum - 1) {
// rear end of a multiheaded engine
SetMultiheaded(u);
break;
}
- if (rvi->flags & RVI_MULTIHEAD) {
- SetMultiheaded(u);
- }
+ if (rvi->flags & RVI_MULTIHEAD) SetMultiheaded(u);
SetTrainEngine(u);
- break;
- case 4: /* TS_Free_Car */
- u->subtype = 0;
- SetTrainWagon(u);
- SetFreeWagon(u);
- break;
- default: NOT_REACHED(); break;
- }
- END_ENUM_WAGONS(u)
+ break;
+
+ case 4: /* TS_Free_Car */
+ u->subtype = 0;
+ SetTrainWagon(u);
+ SetFreeWagon(u);
+ break;
+ default: NOT_REACHED(); break;
+ }
+ } END_ENUM_WAGONS(u)
}
}
}
diff --git a/tree_cmd.c b/tree_cmd.c
index 31c010f72..076e1efdb 100644
--- a/tree_cmd.c
+++ b/tree_cmd.c
@@ -538,7 +538,7 @@ void OnTick_Trees(void)
uint32 r;
TileIndex tile;
ClearGround ct;
- int tree;
+ TreeType tree;
/* place a tree at a random rainforest spot */
if (_opt.landscape == LT_DESERT &&
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 8178d162a..067778230 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -471,22 +471,22 @@ static int32 DoBuildTunnel(int x, int y, int x2, int y2, uint32 flags, uint exc_
/* check if valid, and make sure that (x,y) is smaller than (x2,y2) */
direction = 0;
if (x == x2) {
- if (y == y2)
- return_cmd_error(STR_5008_CANNOT_START_AND_END_ON);
+ if (y == y2) return_cmd_error(STR_5008_CANNOT_START_AND_END_ON);
direction++;
if (y > y2) {
intswap(y,y2);
intswap(x,x2);
- exc_tile|=2;
+ exc_tile |= 2;
}
} else if (y == y2) {
if (x > x2) {
intswap(y,y2);
intswap(x,x2);
- exc_tile|=2;
+ exc_tile |= 2;
}
- } else
+ } else {
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN);
+ }
cost = 0;
@@ -829,7 +829,6 @@ clear_it:;
SetSignalsOnBothDir(tile, direction);
SetSignalsOnBothDir(endtile, direction);
-
}
if (direction) {
@@ -845,11 +844,9 @@ static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags)
if ((m5 & 0xF0) == 0) {
if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
-
return DoClearTunnel(tile, flags);
} else if (m5 & 0x80) {
if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
-
return DoClearBridge(tile, flags);
}
@@ -1023,13 +1020,20 @@ uint GetBridgeFoundation(uint tileh, byte direction)
{
int i;
// normal level sloped building (7, 11, 13, 14)
- if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh))
- return tileh;
+ if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh)) return tileh;
// inclined sloped building
- if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) &&
- ( direction == 0 || (i++, direction == 1)) )
+ if ((
+ (i = 0, tileh == 1) ||
+ (i += 2, tileh == 2) ||
+ (i += 2, tileh == 4) ||
+ (i += 2, tileh == 8)
+ ) && (
+ direction == 0 ||
+ (i++, direction == 1)
+ )) {
return i + 15;
+ }
return 0;
}
@@ -1132,10 +1136,11 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
// draw land under bridge
if (ice) image += 2;
- if (image != 1 || ti->tileh == 0)
+ if (image != 1 || ti->tileh == 0) {
DrawGroundSprite(_bridge_land_below[image] + _tileh_to_sprite[ti->tileh]);
- else
+ } else {
DrawGroundSprite(_water_shore_sprites[ti->tileh]);
+ }
// draw canal water?
if (ti->map5 & 8 && ti->z != 0) DrawCanalWater(ti->tile);
@@ -1185,7 +1190,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
// draw roof, the component of the bridge which is logically between the vehicle and the camera
- if (ti->map5&1) {
+ if (ti->map5 & 1) {
x += 12;
if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x,y, 1, 16, 0x28, z);
} else {
@@ -1193,10 +1198,10 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x,y, 16, 1, 0x28, z);
}
- if (ti->z + 5 == z ) {
+ if (ti->z + 5 == z) {
// draw poles below for small bridges
image = b[2];
- if (image) {
+ if (image != 0) {
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
DrawGroundSpriteAt(image, x, y, z);
}
@@ -1235,10 +1240,10 @@ static uint GetSlopeZ_TunnelBridge(const TileInfo* ti)
return z + 8;
} else if (!(ti->map5 & 0x20)) { // northern / southern ending
// ramp
- return (z + (x>>1) + 1);
+ return z + (x >> 1) + 1;
} else {
// ramp in opposite dir
- return (z + ((x^0xF)>>1));
+ return z + ((x ^ 0xF) >> 1);
}
// bridge middle part
@@ -1351,23 +1356,27 @@ static void AnimateTile_TunnelBridge(TileIndex tile)
static void TileLoop_TunnelBridge(TileIndex tile)
{
- if (_opt.landscape == LT_HILLY) {
- if (GetTileZ(tile) > _opt.snow_line) {
- if (!(_m[tile].m4 & 0x80)) {
- _m[tile].m4 |= 0x80;
- MarkTileDirtyByTile(tile);
+ switch (_opt.landscape) {
+ case LT_HILLY:
+ if (GetTileZ(tile) > _opt.snow_line) {
+ if (!(_m[tile].m4 & 0x80)) {
+ _m[tile].m4 |= 0x80;
+ MarkTileDirtyByTile(tile);
+ }
+ } else {
+ if (_m[tile].m4 & 0x80) {
+ _m[tile].m4 &= ~0x80;
+ MarkTileDirtyByTile(tile);
+ }
}
- } else {
- if (_m[tile].m4 & 0x80) {
- _m[tile].m4 &= ~0x80;
+ break;
+
+ case LT_DESERT:
+ if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) {
+ _m[tile].m4 |= 0x80;
MarkTileDirtyByTile(tile);
}
- }
- } else if (_opt.landscape == LT_DESERT) {
- if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4&0x80)) {
- _m[tile].m4 |= 0x80;
- MarkTileDirtyByTile(tile);
- }
+ break;
}
// if it's a bridge with water below, call tileloop_water on it.
@@ -1537,14 +1546,14 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
if (v->type == VEH_Road || (v->type == VEH_Train && IsFrontEngine(v))) {
uint h;
- if (GetTileSlope(tile, &h) != 0)
- h += 8; // Compensate for possible foundation
+ // Compensate for possible foundation
+ if (GetTileSlope(tile, &h) != 0) h += 8;
if (!(_m[tile].m5 & 0x40) || // start/end tile of bridge
myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge
/* modify speed of vehicle */
uint16 spd = _bridge[GetBridgeType(tile)].speed;
if (v->type == VEH_Road) spd *= 2;
- if (spd < v->cur_speed) v->cur_speed = spd;
+ if (v->cur_speed > spd) v->cur_speed = spd;
}
}
}
diff --git a/unmovable_cmd.c b/unmovable_cmd.c
index 4c9a33c5e..07389b414 100644
--- a/unmovable_cmd.c
+++ b/unmovable_cmd.c
@@ -51,7 +51,7 @@ static int32 DestroyCompanyHQ(TileIndex tile, uint32 flags)
DoClearSquare(p->location_of_house + TileDiffXY(1, 0));
DoClearSquare(p->location_of_house + TileDiffXY(1, 1));
p->location_of_house = 0; // reset HQ position
- InvalidateWindow(WC_COMPANY, (int)p->index);
+ InvalidateWindow(WC_COMPANY, p->index);
}
// cost of relocating company is 1% of company value
@@ -91,7 +91,7 @@ int32 CmdBuildCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2)
ModifyTile(tile + TileDiffXY(1, 0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x82);
ModifyTile(tile + TileDiffXY(1, 1), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x83);
UpdatePlayerHouse(p, score);
- InvalidateWindow(WC_COMPANY, (int)p->index);
+ InvalidateWindow(WC_COMPANY, p->index);
}
return cost;
@@ -346,8 +346,8 @@ void GenerateUnmovables(void)
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) {
if (!checkRadioTowerNearby(tile)) continue;
SetTileType(tile, MP_UNMOVABLE);
- _m[tile].m5 = 0;
SetTileOwner(tile, OWNER_NONE);
+ _m[tile].m5 = 0;
if (--j == 0) break;
}
} while (--i);
@@ -375,8 +375,8 @@ restart:
assert(tile == TILE_MASK(tile));
SetTileType(tile, MP_UNMOVABLE);
- _m[tile].m5 = 1;
SetTileOwner(tile, OWNER_NONE);
+ _m[tile].m5 = 1;
} while (--i);
}
diff --git a/water_cmd.c b/water_cmd.c
index 2187f917d..9ad7cbf65 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -274,7 +274,6 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
static int32 ClearTile_Water(TileIndex tile, byte flags)
{
byte m5 = _m[tile].m5;
- uint slope;
if (m5 <= 1) { // water and shore
// Allow building on water? It's ok to build on shores.
@@ -285,25 +284,26 @@ static int32 ClearTile_Water(TileIndex tile, byte flags)
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
// Make sure it's not an edge tile.
- if (!(IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) &&
- IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)))
+ if (!IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) ||
+ !IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)) {
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
+ }
if (m5 == 0) {
if (flags & DC_EXEC) DoClearSquare(tile);
return _price.clear_water;
} else if (m5 == 1) {
- slope = GetTileSlope(tile,NULL);
+ uint slope = GetTileSlope(tile,NULL);
+
+ if (flags & DC_EXEC) DoClearSquare(tile);
if (slope == 8 || slope == 4 || slope == 2 || slope == 1) {
- if (flags & DC_EXEC)
- DoClearSquare(tile);
return _price.clear_water;
+ } else {
+ return _price.purchase_land;
}
- if (flags & DC_EXEC)
- DoClearSquare(tile);
- return _price.purchase_land;
- } else
+ } else {
return CMD_ERROR;
+ }
} else if ((m5 & 0x10) == 0x10) {
// shiplift