diff options
-rw-r--r-- | ai/default/default.c | 521 | ||||
-rw-r--r-- | ai/trolly/build.c | 3 | ||||
-rw-r--r-- | ai/trolly/pathfinder.c | 2 | ||||
-rw-r--r-- | economy.c | 16 | ||||
-rw-r--r-- | graph_gui.c | 75 | ||||
-rw-r--r-- | misc.c | 6 | ||||
-rw-r--r-- | newgrf.c | 80 | ||||
-rw-r--r-- | oldloader.c | 11 | ||||
-rw-r--r-- | openttd.c | 7 | ||||
-rw-r--r-- | roadveh_cmd.c | 66 | ||||
-rw-r--r-- | station_cmd.c | 29 | ||||
-rw-r--r-- | strings.c | 9 | ||||
-rw-r--r-- | tunnelbridge_cmd.c | 2 |
13 files changed, 373 insertions, 454 deletions
diff --git a/ai/default/default.c b/ai/default/default.c index ef7f96812..edf0c7a2f 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -55,7 +55,8 @@ enum { #include "../../table/ai_rail.h" -static byte GetRailTrackStatus(TileIndex tile) { +static byte GetRailTrackStatus(TileIndex tile) +{ uint32 r = GetTileTrackStatus(tile, TRANSPORT_RAIL); return (byte) (r | r >> 8); } @@ -81,14 +82,12 @@ static void AiStateVehLoop(Player *p) index = (p->ai.cur_veh == NULL) ? 0 : p->ai.cur_veh->index + 1; FOR_ALL_VEHICLES_FROM(v, index) { - if (v->type == 0 || v->owner != _current_player) - continue; + if (v->type == 0 || v->owner != _current_player) continue; - if ((v->type == VEH_Train && v->subtype==0) || + if ((v->type == VEH_Train && v->subtype == 0) || v->type == VEH_Road || (v->type == VEH_Aircraft && v->subtype <= 2) || v->type == VEH_Ship) { - /* replace engine? */ if (v->type == VEH_Train && v->engine_type < 3 && (_price.build_railvehicle >> 3) < p->player_money) { @@ -99,8 +98,8 @@ static void AiStateVehLoop(Player *p) /* not profitable? */ if (v->age >= 730 && - v->profit_last_year < _price.station_value*5 && - v->profit_this_year < _price.station_value*5) { + v->profit_last_year < _price.station_value * 5 && + v->profit_this_year < _price.station_value * 5) { p->ai.state_counter = 0; p->ai.state = AIS_SELL_VEHICLE; p->ai.cur_veh = v; @@ -211,8 +210,10 @@ static int32 AiGetBasePrice(Player *p) int32 base = _price.station_value; // adjust base price when more expensive vehicles are available - if (p->ai.railtype_to_use == 1) base = (base * 3) >> 1; - else if (p->ai.railtype_to_use == 2) base *= 2; + switch (p->ai.railtype_to_use) { + case 1: base = (base * 3) >> 1; break; + case 2: base *= 2; break; + } return base; } @@ -381,7 +382,7 @@ static void AiHandleReplaceShip(Player *p) typedef EngineID CheckReplaceProc(Player* p, Vehicle* v); -static CheckReplaceProc * const _veh_check_replace_proc[] = { +static CheckReplaceProc* const _veh_check_replace_proc[] = { AiChooseTrainToReplaceWith, AiChooseRoadVehToReplaceWith, AiChooseShipToReplaceWith, @@ -389,7 +390,7 @@ static CheckReplaceProc * const _veh_check_replace_proc[] = { }; typedef void DoReplaceProc(Player *p); -static DoReplaceProc * const _veh_do_replace_proc[] = { +static DoReplaceProc* const _veh_do_replace_proc[] = { AiHandleReplaceTrain, AiHandleReplaceRoadVeh, AiHandleReplaceShip, @@ -413,11 +414,11 @@ static void AiStateCheckReplaceVehicle(Player *p) static void AiStateDoReplaceVehicle(Player *p) { - Vehicle *v = p->ai.cur_veh; + const Vehicle* v = p->ai.cur_veh; + p->ai.state = AIS_VEH_LOOP; // vehicle is not owned by the player anymore, something went very wrong. - if (v->type == 0 || v->owner != _current_player) - return; + if (v->type == 0 || v->owner != _current_player) return; _veh_do_replace_proc[v->type - VEH_Train](p); } @@ -454,8 +455,7 @@ static void AiFindSubsidyIndustryRoute(FoundRoute *fr) // Randomize subsidy index.. i = RandomRange(lengthof(_subsidies) * 3); - if (i >= lengthof(_subsidies)) - return; + if (i >= lengthof(_subsidies)) return; s = &_subsidies[i]; @@ -493,22 +493,19 @@ static void AiFindSubsidyPassengerRoute(FoundRoute *fr) // Randomize subsidy index.. i = RandomRange(lengthof(_subsidies) * 3); - if (i >= lengthof(_subsidies)) - return; + if (i >= lengthof(_subsidies)) return; s = &_subsidies[i]; // Only want passengers - if (s->cargo_type != CT_PASSENGERS || s->age > 7) - return; + if (s->cargo_type != CT_PASSENGERS || s->age > 7) return; fr->cargo = s->cargo_type; fr->from = from = GetTown(s->from); fr->to = to = GetTown(s->to); // They must be big enough - if (from->population < 400 || to->population < 400) - return; + if (from->population < 400 || to->population < 400) return; fr->distance = DistanceManhattan(from->xy, to->xy); } @@ -527,19 +524,16 @@ static void AiFindRandomIndustryRoute(FoundRoute *fr) // pick a source fr->from = i = AiFindRandomIndustry(); - if (i == NULL) - return; + if (i == NULL) return; // pick a random produced cargo cargo = i->produced_cargo[0]; - if (r&1 && i->produced_cargo[1] != 0xFF) - cargo = i->produced_cargo[1]; + if (r & 1 && i->produced_cargo[1] != 0xFF) cargo = i->produced_cargo[1]; fr->cargo = cargo; // don't allow passengers - if (cargo == 0xFF || cargo == CT_PASSENGERS) - return; + if (cargo == 0xFF || cargo == CT_PASSENGERS) return; if (cargo != CT_GOODS && cargo != CT_FOOD) { // pick a dest, and see if it can receive @@ -562,18 +556,17 @@ static void AiFindRandomIndustryRoute(FoundRoute *fr) static void AiFindRandomPassengerRoute(FoundRoute *fr) { - Town *source, *dest; + Town* source; + Town* dest; // initially error fr->distance = -1; fr->from = source = AiFindRandomTown(); - if (source == NULL || source->population < 400) - return; + if (source == NULL || source->population < 400) return; fr->to = dest = AiFindRandomTown(); - if (dest == NULL || source == dest || dest->population < 400) - return; + if (dest == NULL || source == dest || dest->population < 400) return; fr->distance = DistanceManhattan(source->xy, dest->xy); } @@ -598,20 +591,24 @@ static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask) if (cur < dist) dist = cur; cur = DistanceMax(to_tile, st->xy); if (cur < dist) dist = cur; - if (to_tile == from_tile && st->xy == to_tile) - same_station++; + if (to_tile == from_tile && st->xy == to_tile) same_station++; } // To prevent the AI from building ten busstations in the same town, do some calculations // For each road or airport station, we want 350 of population! - if ((bitmask == 2 || bitmask == 4) && same_station > 2 && ((Town *)(fr->from))->population < same_station * 350) - return false; - - if (dist != 0xFFFF && dist > 37) + if ((bitmask == 2 || bitmask == 4) && + same_station > 2 && + ((Town*)(fr->from))->population < same_station * 350) { return false; + } + + if (dist != 0xFFFF && dist > 37) return false; - if (p->ai.route_type_mask != 0 && !(p->ai.route_type_mask&bitmask) && !CHANCE16(1,5)) + if (p->ai.route_type_mask != 0 && + !(p->ai.route_type_mask & bitmask) && + !CHANCE16(1, 5)) { return false; + } if (fr->cargo == CT_PASSENGERS || fr->cargo == CT_MAIL) { if (((Town*)fr->from)->pct_pass_transported > 0x99 || @@ -619,11 +616,11 @@ static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask) return false; // Make sure it has a reasonably good rating - if ( ((Town*)fr->from)->ratings[_current_player] < -100 || + if (((Town*)fr->from)->ratings[_current_player] < -100 || ((Town*)fr->to)->ratings[_current_player] < -100) return false; } else { - Industry *i = (Industry*)fr->from; + const Industry* i = (const Industry*)fr->from; if (i->pct_transported[fr->cargo != i->produced_cargo[0]] > 0x99 || i->total_production[fr->cargo != i->produced_cargo[0]] == 0) @@ -658,17 +655,14 @@ static void AiWantLongIndustryRoute(Player *p) for (;;) { // look for one from the subsidy list AiFindSubsidyIndustryRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 60, 90+1)) - break; + if (IS_INT_INSIDE(fr.distance, 60, 90 + 1)) break; // try a random one AiFindRandomIndustryRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 60, 90+1)) - break; + if (IS_INT_INSIDE(fr.distance, 60, 90 + 1)) break; // only test 60 times - if (--i == 0) - return; + if (--i == 0) return; } if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; @@ -762,20 +756,16 @@ static void AiWantMediumIndustryRoute(Player *p) i = 60; for (;;) { - // look for one from the subsidy list AiFindSubsidyIndustryRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 40, 60+1)) - break; + if (IS_INT_INSIDE(fr.distance, 40, 60 + 1)) break; // try a random one AiFindRandomIndustryRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 40, 60+1)) - break; + if (IS_INT_INSIDE(fr.distance, 40, 60 + 1)) break; // only test 60 times - if (--i == 0) - return; + if (--i == 0) return; } if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; @@ -790,9 +780,9 @@ static void AiWantMediumIndustryRoute(Player *p) p->ai.src.buildcmd_a = 0x10; p->ai.src.buildcmd_b = 0xFF; p->ai.src.direction = AiGetDirectionBetweenTiles( - GET_TOWN_OR_INDUSTRY_TILE(fr.from), - GET_TOWN_OR_INDUSTRY_TILE(fr.to) - ); + GET_TOWN_OR_INDUSTRY_TILE(fr.from), + GET_TOWN_OR_INDUSTRY_TILE(fr.to) + ); p->ai.src.cargo = fr.cargo | 0x80; // Fill the dest field @@ -805,9 +795,9 @@ static void AiWantMediumIndustryRoute(Player *p) p->ai.dst.buildcmd_a = 0xFF; p->ai.dst.buildcmd_b = 0xFF; p->ai.dst.direction = AiGetDirectionBetweenTiles( - GET_TOWN_OR_INDUSTRY_TILE(fr.to), - GET_TOWN_OR_INDUSTRY_TILE(fr.from) - ); + GET_TOWN_OR_INDUSTRY_TILE(fr.to), + GET_TOWN_OR_INDUSTRY_TILE(fr.from) + ); p->ai.dst.cargo = fr.cargo; // Fill common fields @@ -834,20 +824,16 @@ static void AiWantShortIndustryRoute(Player *p) i = 60; for (;;) { - // look for one from the subsidy list AiFindSubsidyIndustryRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 15, 40+1)) - break; + if (IS_INT_INSIDE(fr.distance, 15, 40 + 1)) break; // try a random one AiFindRandomIndustryRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 15, 40+1)) - break; + if (IS_INT_INSIDE(fr.distance, 15, 40 + 1)) break; // only test 60 times - if (--i == 0) - return; + if (--i == 0) return; } if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; @@ -862,9 +848,9 @@ static void AiWantShortIndustryRoute(Player *p) p->ai.src.buildcmd_a = 0x10; p->ai.src.buildcmd_b = 0xFF; p->ai.src.direction = AiGetDirectionBetweenTiles( - GET_TOWN_OR_INDUSTRY_TILE(fr.from), - GET_TOWN_OR_INDUSTRY_TILE(fr.to) - ); + GET_TOWN_OR_INDUSTRY_TILE(fr.from), + GET_TOWN_OR_INDUSTRY_TILE(fr.to) + ); p->ai.src.cargo = fr.cargo | 0x80; // Fill the dest field @@ -877,9 +863,9 @@ static void AiWantShortIndustryRoute(Player *p) p->ai.dst.buildcmd_a = 0xFF; p->ai.dst.buildcmd_b = 0xFF; p->ai.dst.direction = AiGetDirectionBetweenTiles( - GET_TOWN_OR_INDUSTRY_TILE(fr.to), - GET_TOWN_OR_INDUSTRY_TILE(fr.from) - ); + GET_TOWN_OR_INDUSTRY_TILE(fr.to), + GET_TOWN_OR_INDUSTRY_TILE(fr.from) + ); p->ai.dst.cargo = fr.cargo; // Fill common fields @@ -906,20 +892,16 @@ static void AiWantMailRoute(Player *p) i = 60; for (;;) { - // look for one from the subsidy list AiFindSubsidyPassengerRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 60, 110+1)) - break; + if (IS_INT_INSIDE(fr.distance, 60, 110 + 1)) break; // try a random one AiFindRandomPassengerRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 60, 110+1)) - break; + if (IS_INT_INSIDE(fr.distance, 60, 110 + 1)) break; // only test 60 times - if (--i == 0) - return; + if (--i == 0) return; } fr.cargo = CT_MAIL; @@ -935,9 +917,9 @@ static void AiWantMailRoute(Player *p) p->ai.src.buildcmd_a = 0x24; p->ai.src.buildcmd_b = 0xFF; p->ai.src.direction = AiGetDirectionBetweenTiles( - GET_TOWN_OR_INDUSTRY_TILE(fr.from), - GET_TOWN_OR_INDUSTRY_TILE(fr.to) - ); + GET_TOWN_OR_INDUSTRY_TILE(fr.from), + GET_TOWN_OR_INDUSTRY_TILE(fr.to) + ); p->ai.src.cargo = fr.cargo; // Fill the dest field @@ -950,17 +932,17 @@ static void AiWantMailRoute(Player *p) p->ai.dst.buildcmd_a = 0x34; p->ai.dst.buildcmd_b = 0xFF; p->ai.dst.direction = AiGetDirectionBetweenTiles( - GET_TOWN_OR_INDUSTRY_TILE(fr.to), - GET_TOWN_OR_INDUSTRY_TILE(fr.from) - ); + GET_TOWN_OR_INDUSTRY_TILE(fr.to), + GET_TOWN_OR_INDUSTRY_TILE(fr.from) + ); p->ai.dst.cargo = fr.cargo; // Fill middle field 1 p->ai.mid1.spec_tile = AiGetPctTileBetween( - GET_TOWN_OR_INDUSTRY_TILE(fr.from), - GET_TOWN_OR_INDUSTRY_TILE(fr.to), - 0x55 - ); + GET_TOWN_OR_INDUSTRY_TILE(fr.from), + GET_TOWN_OR_INDUSTRY_TILE(fr.to), + 0x55 + ); p->ai.mid1.use_tile = 0; p->ai.mid1.rand_rng = 6; p->ai.mid1.cur_building_rule = 0xFF; @@ -973,10 +955,10 @@ static void AiWantMailRoute(Player *p) // Fill middle field 2 p->ai.mid2.spec_tile = AiGetPctTileBetween( - GET_TOWN_OR_INDUSTRY_TILE(fr.from), - GET_TOWN_OR_INDUSTRY_TILE(fr.to), - 0xAA - ); + GET_TOWN_OR_INDUSTRY_TILE(fr.from), + GET_TOWN_OR_INDUSTRY_TILE(fr.to), + 0xAA + ); p->ai.mid2.use_tile = 0; p->ai.mid2.rand_rng = 6; p->ai.mid2.cur_building_rule = 0xFF; @@ -1011,20 +993,16 @@ static void AiWantPassengerRoute(Player *p) i = 60; for (;;) { - // look for one from the subsidy list AiFindSubsidyPassengerRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 0, 55+1)) - break; + if (IS_INT_INSIDE(fr.distance, 0, 55 + 1)) break; // try a random one AiFindRandomPassengerRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 0, 55+1)) - break; + if (IS_INT_INSIDE(fr.distance, 0, 55 + 1)) break; // only test 60 times - if (--i == 0) - return; + if (--i == 0) return; } fr.cargo = CT_PASSENGERS; @@ -1103,20 +1081,16 @@ static void AiWantLongRoadIndustryRoute(Player *p) i = 60; for (;;) { - // look for one from the subsidy list AiFindSubsidyIndustryRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 35, 55+1)) - break; + if (IS_INT_INSIDE(fr.distance, 35, 55 + 1)) break; // try a random one AiFindRandomIndustryRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 35, 55+1)) - break; + if (IS_INT_INSIDE(fr.distance, 35, 55 + 1)) break; // only test 60 times - if (--i == 0) - return; + if (--i == 0) return; } if (!AiCheckIfRouteIsGood(p, &fr, 2)) return; @@ -1163,20 +1137,16 @@ static void AiWantMediumRoadIndustryRoute(Player *p) i = 60; for (;;) { - // look for one from the subsidy list AiFindSubsidyIndustryRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 15, 40+1)) - break; + if (IS_INT_INSIDE(fr.distance, 15, 40 + 1)) break; // try a random one AiFindRandomIndustryRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 15, 40+1)) - break; + if (IS_INT_INSIDE(fr.distance, 15, 40 + 1)) break; // only test 60 times - if (--i == 0) - return; + if (--i == 0) return; } if (!AiCheckIfRouteIsGood(p, &fr, 2)) return; @@ -1223,20 +1193,16 @@ static void AiWantLongRoadPassengerRoute(Player *p) i = 60; for (;;) { - // look for one from the subsidy list AiFindSubsidyPassengerRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 55, 180+1)) - break; + if (IS_INT_INSIDE(fr.distance, 55, 180 + 1)) break; // try a random one AiFindRandomPassengerRoute(&fr); - if (IS_INT_INSIDE(fr.distance, 55, 180+1)) - break; + if (IS_INT_INSIDE(fr.distance, 55, 180 + 1)) break; // only test 60 times - if (--i == 0) - return; + if (--i == 0) return; } fr.cargo = CT_PASSENGERS; @@ -1288,12 +1254,10 @@ static void AiWantPassengerRouteInsideTown(Player *p) for (;;) { // Find a town big enough t = AiFindRandomTown(); - if (t != NULL && t->population >= 700) - break; + if (t != NULL && t->population >= 700) break; // only test 60 times - if (--i == 0) - return; + if (--i == 0) return; } fr.cargo = CT_PASSENGERS; @@ -1358,25 +1322,20 @@ static void AiWantPassengerAircraftRoute(Player *p) i = 60; for (;;) { - // look for one from the subsidy list AiFindSubsidyPassengerRoute(&fr); - if (IS_INT_INSIDE(fr.distance,0,95+1)) - break; + if (IS_INT_INSIDE(fr.distance, 0, 95 + 1)) break; // try a random one AiFindRandomPassengerRoute(&fr); - if (IS_INT_INSIDE(fr.distance,0,95+1)) - break; + if (IS_INT_INSIDE(fr.distance, 0, 95 + 1)) break; // only test 60 times - if (--i == 0) - return; + if (--i == 0) return; } fr.cargo = CT_PASSENGERS; - if (!AiCheckIfRouteIsGood(p, &fr, 4)) - return; + if (!AiCheckIfRouteIsGood(p, &fr, 4)) return; // Fill the source field @@ -1429,15 +1388,13 @@ static void AiWantOilRigAircraftRoute(Player *p) } // only test 60 times - if (--i == 0) - return; + if (--i == 0) return; } fr.cargo = CT_PASSENGERS; fr.from = fr.to = t; - if (!AiCheckIfRouteIsGood(p, &fr, 4)) - return; + if (!AiCheckIfRouteIsGood(p, &fr, 4)) return; // Fill the source field p->ai.src.spec_tile = t->xy; @@ -1501,9 +1458,12 @@ static void AiStateWantNewRoute(Player *p) for (;;) { r = (uint16)Random(); - if (_patches.ai_disable_veh_train && _patches.ai_disable_veh_roadveh && - _patches.ai_disable_veh_aircraft && _patches.ai_disable_veh_ship) + if (_patches.ai_disable_veh_train && + _patches.ai_disable_veh_roadveh && + _patches.ai_disable_veh_aircraft && + _patches.ai_disable_veh_ship) { return; + } if (r < 0x7626) { if (_patches.ai_disable_veh_train) continue; @@ -1520,8 +1480,7 @@ static void AiStateWantNewRoute(Player *p) } // got a route? - if (p->ai.state != AIS_WANT_NEW_ROUTE) - break; + if (p->ai.state != AIS_WANT_NEW_ROUTE) break; // time out? if (--i == 0) { @@ -1619,7 +1578,7 @@ clear_town_stuff:; } /* signals too? */ - if (j&3) { + if (j & 3) { // Can't build signals on a road. if (IsTileType(c, MP_STREET)) return CMD_ERROR; @@ -1722,10 +1681,9 @@ static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode) tile = TILE_MASK(tile + TileOffsByDir(dir)); r >>= 2; - if (r&2) { + if (r & 2) { dir++; - if (r&1) - dir -= 2; + if (r & 1) dir -= 2; } dir &= 3; } while (--unk >= 0); @@ -1733,13 +1691,13 @@ static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode) slope = GetTileSlope(tile, &h); if (slope != 0) { - if (mode > 0 || (mode == 0 && !(r&0xC))) { + if (mode > 0 || (mode == 0 && !(r & 0xC))) { // Terraform up - DoCommandByTile(tile, _terraform_up_flags[slope-1], 1, + DoCommandByTile(tile, _terraform_up_flags[slope - 1], 1, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); } else if (h != 0) { // Terraform down - DoCommandByTile(tile, _terraform_down_flags[slope-1], 0, + DoCommandByTile(tile, _terraform_down_flags[slope - 1], 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); } } @@ -1768,8 +1726,7 @@ static void AiStateBuildDefaultRailBlocks(Player *p) j = p->ai.num_build_rec; do { // this item has already been built? - if (aib->cur_building_rule != 255) - continue; + if (aib->cur_building_rule != 255) continue; // adjust the coordinate randomly, // to make sure that we find a position. @@ -1779,7 +1736,8 @@ static void AiStateBuildDefaultRailBlocks(Player *p) rule = AiBuildDefaultRailTrack(aib->use_tile, p->ai.build_kind, p->ai.num_wagons, aib->unk6, aib->unk7, - aib->direction, aib->cargo, &cost); + aib->direction, aib->cargo, &cost + ); if (rule == -1) { // cannot build, terraform after a while @@ -2133,7 +2091,7 @@ static void AiBuildRailConstruct(Player *p) p->ai.cur_tile_a += TileOffsByDir(p->ai.cur_dir_a); - if (arf.best_ptr[0]&0x80) { + if (arf.best_ptr[0] & 0x80) { int i; int32 bridge_len = GetBridgeLength(arf.bridge_end_tile, p->ai.cur_tile_a); @@ -2169,8 +2127,9 @@ static void AiBuildRailConstruct(Player *p) } if (arf.best_tile != 0) { - for (i=0; i!=2; i++) + for (i = 0; i != 2; i++) { AiDoTerraformLand(arf.best_tile, arf.best_dir, 3, 0); + } } } @@ -2186,7 +2145,7 @@ static bool AiRemoveTileAndGoForward(Player *p) if (IsTileType(tile, MP_TUNNELBRIDGE)) { if (!(_m[tile].m5 & 0x80)) { // Clear the tunnel and continue at the other side of it. - if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)) ) + if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) return false; p->ai.cur_tile_a = TILE_MASK(_build_tunnel_endtile - TileOffsByDir(p->ai.cur_dir_a)); return true; @@ -2196,8 +2155,7 @@ static bool AiRemoveTileAndGoForward(Player *p) // Check if the bridge points in the right direction. // This is not really needed the first place AiRemoveTileAndGoForward is called. - if ((_m[tile].m5&1) != (p->ai.cur_dir_a&1)) - return false; + if ((_m[tile].m5 & 1) != (p->ai.cur_dir_a & 1)) return false; // Find other side of bridge. offs = TileOffsByDir(p->ai.cur_dir_a); @@ -2207,7 +2165,7 @@ static bool AiRemoveTileAndGoForward(Player *p) tilenew = TILE_MASK(tile - offs); // And clear the bridge. - if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)) ) + if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) return false; p->ai.cur_tile_a = tilenew; return true; @@ -2216,8 +2174,7 @@ static bool AiRemoveTileAndGoForward(Player *p) // Find the railtype at the position. Quit if no rail there. b = GetRailTrackStatus(tile) & _dir_table_3[p->ai.cur_dir_a]; - if (b == 0) - return false; + if (b == 0) return false; // Convert into a bit position that CMD_REMOVE_SINGLE_RAIL expects. bit = FindFirstBit(b); @@ -2229,12 +2186,12 @@ static bool AiRemoveTileAndGoForward(Player *p) } // And also remove the rail. - if (CmdFailed(DoCommandByTile(tile, 0, bit, DC_EXEC, CMD_REMOVE_SINGLE_RAIL)) ) + if (CmdFailed(DoCommandByTile(tile, 0, bit, DC_EXEC, CMD_REMOVE_SINGLE_RAIL))) return false; // Find the direction at the other edge of the rail. - ptr = _ai_table_15[p->ai.cur_dir_a^2]; - while (ptr[0] != bit) ptr+=2; + ptr = _ai_table_15[p->ai.cur_dir_a ^ 2]; + while (ptr[0] != bit) ptr += 2; p->ai.cur_dir_a = ptr[1] ^ 2; // And then also switch tile. @@ -2253,8 +2210,7 @@ static void AiBuildRailDestruct(Player *p) } // Don't do anything if the destination is already reached. - if (p->ai.cur_tile_a == p->ai.start_tile_a) - return; + if (p->ai.cur_tile_a == p->ai.start_tile_a) return; AiRemoveTileAndGoForward(p); } @@ -2262,19 +2218,17 @@ static void AiBuildRailDestruct(Player *p) static void AiBuildRail(Player *p) { - int i; - if (p->ai.state_mode < 1) { // Construct mode, build new rail. AiBuildRailConstruct(p); } else if (p->ai.state_mode == 1) { - // Destruct mode, destroy the rail currently built. AiBuildRailDestruct(p); } else if (p->ai.state_mode == 2) { + uint i; // Terraform some and then try building again. - for (i=0; i!=4; i++) + for (i = 0; i != 4; i++) AiDoTerraformLand(p->ai.cur_tile_a, p->ai.cur_dir_a, 3, 0); if (++p->ai.state_counter == 4) { @@ -2377,18 +2331,18 @@ static void AiStateBuildRailVeh(Player *p) uint loco_id; ptr = _default_rail_track_data[p->ai.src.cur_building_rule]->data; - while (ptr->mode != 0) { ptr++; } + while (ptr->mode != 0) ptr++; tile = TILE_ADD(p->ai.src.use_tile, ToTileIndexDiff(ptr->tileoffs)); cargo = p->ai.cargo_type; - for (i=0;;) { + for (i = 0;;) { if (p->ai.wagon_list[i] == INVALID_VEHICLE) { veh = _cargoc.ai_railwagon[p->ai.railtype_to_use][cargo]; cost = DoCommandByTile(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE); if (CmdFailed(cost)) goto handle_nocash; p->ai.wagon_list[i] = _new_wagon_id; - p->ai.wagon_list[i+1] = INVALID_VEHICLE; + p->ai.wagon_list[i + 1] = INVALID_VEHICLE; return; } if (cargo == CT_MAIL) @@ -2403,7 +2357,7 @@ static void AiStateBuildRailVeh(Player *p) handle_nocash: // after a while, if AI still doesn't have cash, get out of this block by selling the wagons. if (++p->ai.state_counter == 1000) { - for (i=0; p->ai.wagon_list[i] != INVALID_VEHICLE; i++) { + for (i = 0; p->ai.wagon_list[i] != INVALID_VEHICLE; i++) { cost = DoCommandByTile(tile, p->ai.wagon_list[i], 0, DC_EXEC, CMD_SELL_RAIL_WAGON); assert(!CmdFailed(cost)); } @@ -2420,21 +2374,23 @@ handle_nocash: // Sell a vehicle if the train is double headed. v = GetVehicle(loco_id); if (v->next != NULL) { - i = p->ai.wagon_list[p->ai.num_wagons*2-2]; - p->ai.wagon_list[p->ai.num_wagons*2-2] = INVALID_VEHICLE; + i = p->ai.wagon_list[p->ai.num_wagons * 2 - 2]; + p->ai.wagon_list[p->ai.num_wagons * 2 - 2] = INVALID_VEHICLE; DoCommandByTile(tile, i, 0, DC_EXEC, CMD_SELL_RAIL_WAGON); } // Move the wagons onto the train - for (i=0; p->ai.wagon_list[i] != INVALID_VEHICLE; i++) { + for (i = 0; p->ai.wagon_list[i] != INVALID_VEHICLE; i++) { DoCommandByTile(tile, p->ai.wagon_list[i] | (loco_id << 16), 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); } - for (i=0; p->ai.order_list_blocks[i] != 0xFF; i++) { + for (i = 0; p->ai.order_list_blocks[i] != 0xFF; i++) { AiBuildRec *aib = (&p->ai.src) + p->ai.order_list_blocks[i]; - bool is_pass = (p->ai.cargo_type == CT_PASSENGERS || - p->ai.cargo_type == CT_MAIL || - (_opt.landscape==LT_NORMAL && p->ai.cargo_type == CT_VALUABLES)); + bool is_pass = ( + p->ai.cargo_type == CT_PASSENGERS || + p->ai.cargo_type == CT_MAIL || + (_opt.landscape == LT_NORMAL && p->ai.cargo_type == CT_VALUABLES) + ); Order order; order.type = OT_GOTO_STATION; @@ -2452,8 +2408,7 @@ handle_nocash: DoCommandByTile(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT); - if (p->ai.num_want_fullload != 0) - p->ai.num_want_fullload--; + if (p->ai.num_want_fullload != 0) p->ai.num_want_fullload--; if (--p->ai.num_loco_to_build != 0) { // p->ai.loco_id = INVALID_VEHICLE; @@ -2495,7 +2450,7 @@ static bool AiCheckRoadResources(TileIndex tile, const AiDefaultBlockData *p, by rad = 4; } - for (;;p++) { + for (;; p++) { if (p->mode == 4) { return true; } else if (p->mode == 1) { @@ -2523,7 +2478,7 @@ static int AiFindBestDefaultRoadBlock(TileIndex tile, byte direction, byte cargo _want_road_truck_station = (cargo & 0x7F) != CT_PASSENGERS; - for (i=0; (p = _road_default_block_data[i]) != NULL; i++) { + for (i = 0; (p = _road_default_block_data[i]) != NULL; i++) { if (p->dir == direction) { *cost = AiDoBuildDefaultRoadBlock(tile, p->data, 0); if (!CmdFailed(*cost) && AiCheckRoadResources(tile, p->data, cargo)) @@ -2543,19 +2498,18 @@ static int32 AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData int roadflag = 0; for (;p->mode != 4;p++) { - uint c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs)); + TileIndex c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs)); _cleared_town = NULL; if (p->mode == 2) { if (IsTileType(c, MP_STREET) && - (_m[c].m5&0xF0)==0 && - (_m[c].m5&p->attr)!=0) { + (_m[c].m5 & 0xF0) == 0 && + (_m[c].m5 & p->attr) != 0) { roadflag |= 2; // all bits are already built? - if ((_m[c].m5&p->attr)==p->attr) - continue; + if ((_m[c].m5 & p->attr) == p->attr) continue; } ret = DoCommandByTile(c, p->attr, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD); @@ -2583,19 +2537,16 @@ clear_town_stuff:; total_cost += ret; if (_cleared_town != NULL) { - if (t != NULL && t != _cleared_town) - return CMD_ERROR; + if (t != NULL && t != _cleared_town) return CMD_ERROR; t = _cleared_town; rating += _cleared_town_rating; } } else if (p->mode == 3) { - if (flag & DC_EXEC) - continue; + if (flag & DC_EXEC) continue; - if (GetTileSlope(c, NULL) != 0) - return CMD_ERROR; + if (GetTileSlope(c, NULL) != 0) return CMD_ERROR; - if (!(IsTileType(c, MP_STREET) && (_m[c].m5 & 0xF0) == 0)) { + if (!IsTileType(c, MP_STREET) || (_m[c].m5 & 0xF0) != 0) { ret = DoCommandByTile(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR); if (CmdFailed(ret)) return CMD_ERROR; } @@ -2603,13 +2554,10 @@ clear_town_stuff:; } } - if (!_want_road_truck_station && !(roadflag&2)) - return CMD_ERROR; + if (!_want_road_truck_station && !(roadflag & 2)) return CMD_ERROR; if (!(flag & DC_EXEC)) { - if (t != NULL && rating > t->ratings[_current_player]) { - return CMD_ERROR; - } + if (t != NULL && rating > t->ratings[_current_player]) return CMD_ERROR; } return total_cost; } @@ -2625,8 +2573,7 @@ static bool AiCheckBlockDistances(Player *p, TileIndex tile) do { if (aib->cur_building_rule != 255) { - if (DistanceManhattan(aib->use_tile, tile) < 9) - return false; + if (DistanceManhattan(aib->use_tile, tile) < 9) return false; } } while (++aib, --num); @@ -2636,7 +2583,8 @@ static bool AiCheckBlockDistances(Player *p, TileIndex tile) static void AiStateBuildDefaultRoadBlocks(Player *p) { - int i, j; + uint i; + int j; AiBuildRec *aib; int rule; int32 cost; @@ -2648,23 +2596,22 @@ static void AiStateBuildDefaultRoadBlocks(Player *p) } // do the following 8 times - i = 8; - do { + for (i = 0; i != 8; i++) { // check if we can build the default track aib = &p->ai.src; j = p->ai.num_build_rec; do { // this item has already been built? - if (aib->cur_building_rule != 255) - continue; + if (aib->cur_building_rule != 255) continue; // adjust the coordinate randomly, // to make sure that we find a position. aib->use_tile = AdjustTileCoordRandomly(aib->spec_tile, aib->rand_rng); // check if the road can be built there. - rule = AiFindBestDefaultRoadBlock(aib->use_tile, - aib->direction, aib->cargo, &cost); + rule = AiFindBestDefaultRoadBlock( + aib->use_tile, aib->direction, aib->cargo, &cost + ); if (rule == -1) { // cannot build, terraform after a while @@ -2690,14 +2637,13 @@ static void AiStateBuildDefaultRoadBlocks(Player *p) assert(!CmdFailed(r)); } } while (++aib,--j); - } while (--i); + } // check if we're done with all of them aib = &p->ai.src; j = p->ai.num_build_rec; do { - if (aib->cur_building_rule == 255) - return; + if (aib->cur_building_rule == 255) return; } while (++aib,--j); // yep, all are done. switch state to the rail building state. @@ -2807,9 +2753,7 @@ static bool AiCheckRoadFinished(Player *p) tile = TILE_MASK(p->ai.cur_tile_a + TileOffsByDir(dir)); bits = GetTileTrackStatus(tile, TRANSPORT_ROAD) & _ai_road_table_and[dir]; - if (bits == 0) { - return false; - } + if (bits == 0) return false; are.best_dist = (uint)-1; @@ -2817,11 +2761,9 @@ static bool AiCheckRoadFinished(Player *p) FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _dir_by_track[i], (TPFEnumProc*)AiEnumFollowRoad, NULL, &are); } - if (DistanceManhattan(tile, are.dest) <= are.best_dist) - return false; + if (DistanceManhattan(tile, are.dest) <= are.best_dist) return false; - if (are.best_dist == 0) - return true; + if (are.best_dist == 0) return true; p->ai.cur_tile_a = are.best_tile; p->ai.cur_dir_a = _dir_by_track[are.best_track]; @@ -2876,8 +2818,7 @@ static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile, // At the bottom depth, check if the new path is better than the old one. if (arf->depth == 1) { - if (AiCheckRoadPathBetter(arf, p)) - arf->bridge_end_tile = tile_new; + if (AiCheckRoadPathBetter(arf, p)) arf->bridge_end_tile = tile_new; } } } @@ -2946,12 +2887,10 @@ static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, int dir) } // At the bottom depth? - if (arf->depth == 1) { - AiCheckRoadPathBetter(arf, p); - } + if (arf->depth == 1) AiCheckRoadPathBetter(arf, p); p += 2; - } while (!(p[0]&0x80)); + } while (!(p[0] & 0x80)); } AiCheckBuildRoadBridgeHere(arf, tile, p); @@ -2998,7 +2937,7 @@ static void AiBuildRoadConstruct(Player *p) if (arf.best_ptr == NULL) { // Terraform some do_some_terraform: - for (i=0; i!=5; i++) + for (i = 0; i != 5; i++) AiDoTerraformLand(p->ai.cur_tile_a, p->ai.cur_dir_a, 3, 0); if (++p->ai.state_counter == 21) { @@ -3027,8 +2966,7 @@ do_some_terraform: for (i = 10; i != 0; i--) { if (CheckBridge_Stuff(i, bridge_len)) { int32 cost = DoCommandByTile(tile, p->ai.cur_tile_a, i + (0x80 << 8), DC_AUTO, CMD_BUILD_BRIDGE); - if (!CmdFailed(cost) && cost < (p->player_money >> 5)) - break; + if (!CmdFailed(cost) && cost < (p->player_money >> 5)) break; } } @@ -3053,7 +2991,7 @@ do_some_terraform: } if (arf.best_tile != 0) { - for (i=0; i!=2; i++) + for (i = 0; i != 2; i++) AiDoTerraformLand(arf.best_tile, arf.best_dir, 3, 0); } } @@ -3061,8 +2999,6 @@ do_some_terraform: static void AiBuildRoad(Player *p) { - int i; - if (p->ai.state_mode < 1) { // Construct mode, build new road. AiBuildRoadConstruct(p); @@ -3071,9 +3007,10 @@ static void AiBuildRoad(Player *p) p->ai.state_mode = 2; p->ai.state_counter = 0; } else if (p->ai.state_mode == 2) { + uint i; // Terraform some and then try building again. - for (i=0; i!=4; i++) + for (i = 0; i != 4; i++) AiDoTerraformLand(p->ai.cur_tile_a, p->ai.cur_dir_a, 3, 0); if (++p->ai.state_counter == 4) { @@ -3169,10 +3106,10 @@ static void AiStateBuildRoadVehicles(Player *p) TileIndex tile; uint loco_id; EngineID veh; - int i; + uint i; ptr = _road_default_block_data[p->ai.src.cur_building_rule]->data; - for (;ptr->mode != 0;ptr++) {} + for (; ptr->mode != 0; ptr++) {} tile = TILE_ADD(p->ai.src.use_tile, ToTileIndexDiff(ptr->tileoffs)); veh = AiChooseRoadVehToBuild(p->ai.cargo_type, p->player_money, tile); @@ -3267,21 +3204,18 @@ static void AiStateAirportStuff(Player *p) FOR_ALL_STATIONS(st) { // Dismiss ghost stations. - if (st->xy == 0) - continue; + if (st->xy == 0) continue; // Is this an airport? - if (!(st->facilities & FACIL_AIRPORT)) - continue; + if (!(st->facilities & FACIL_AIRPORT)) continue; // Do we own the airport? (Oilrigs aren't owned, though.) - if (st->owner != OWNER_NONE && st->owner != _current_player) - continue; + if (st->owner != OWNER_NONE && st->owner != _current_player) continue; acc_planes = GetAirport(st->airport_type)->acc_planes; // Dismiss heliports, unless we are checking an oilrig. - if (acc_planes == HELICOPTERS_ONLY && !(p->ai.build_kind == 1 && i == 1)) + if (acc_planes == HELICOPTERS_ONLY && (p->ai.build_kind != 1 || i != 1)) continue; // Dismiss country airports if we are doing the other @@ -3335,9 +3269,8 @@ static int32 AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockDa { int32 total_cost = 0, ret; - for (;p->mode == 0;p++) { - if (!HASBIT(_avail_aircraft, p->attr)) - return CMD_ERROR; + for (; p->mode == 0; p++) { + if (!HASBIT(_avail_aircraft, p->attr)) return CMD_ERROR; ret = DoCommandByTile(TILE_MASK(tile + ToTileIndexDiff(p->tileoffs)), p->attr,0,flag | DC_AUTO | DC_NO_WATER,CMD_BUILD_AIRPORT); if (CmdFailed(ret)) return CMD_ERROR; total_cost += ret; @@ -3349,7 +3282,6 @@ static int32 AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockDa static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo) { uint values[NUM_CARGO]; - int w,h; int rad; if (_patches.modified_catchment) { @@ -3358,11 +3290,11 @@ static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p, rad = 4; } - for (;p->mode==0;p++) { + for (; p->mode == 0; p++) { TileIndex tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)); + uint w = _airport_size_x[p->attr]; + uint h = _airport_size_y[p->attr]; - w = _airport_size_x[p->attr]; - h = _airport_size_y[p->attr]; if (cargo & 0x80) { GetProductionAroundTiles(values, tile2, w, h, rad); return values[cargo & 0x7F] != 0; @@ -3376,13 +3308,13 @@ static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p, static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, int32 *cost) { - int i; const AiDefaultBlockData *p; - for (i=0; (p = _airport_default_block_data[i]) != NULL; i++) { + uint i; + + for (i = 0; (p = _airport_default_block_data[i]) != NULL; i++) { // If we are doing a helicopter service, avoid building // airports where they can't land. - if (heli && GetAirport(p->attr)->acc_planes == AIRCRAFT_ONLY) - continue; + if (heli && GetAirport(p->attr)->acc_planes == AIRCRAFT_ONLY) continue; *cost = AiDoBuildDefaultAirportBlock(tile, p, 0); if (!CmdFailed(*cost) && AiCheckAirportResources(tile, p, cargo)) @@ -3412,8 +3344,7 @@ static void AiStateBuildDefaultAirportBlocks(Player *p) j = p->ai.num_build_rec; do { // this item has already been built? - if (aib->cur_building_rule != 255) - continue; + if (aib->cur_building_rule != 255) continue; // adjust the coordinate randomly, // to make sure that we find a position. @@ -3465,8 +3396,7 @@ static void AiStateBuildDefaultAirportBlocks(Player *p) aib = &p->ai.src; j = p->ai.num_build_rec; do { - if (aib->cur_building_rule == 255) - return; + if (aib->cur_building_rule == 255) return; } while (++aib,--j); // yep, all are done. switch state. @@ -3522,12 +3452,9 @@ static void AiStateBuildAircraftVehicles(Player *p) DoCommandByTile(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT); - if (p->ai.num_want_fullload != 0) - p->ai.num_want_fullload--; + if (p->ai.num_want_fullload != 0) p->ai.num_want_fullload--; - if (--p->ai.num_loco_to_build == 0) { - p->ai.state = AIS_0; - } + if (--p->ai.num_loco_to_build == 0) p->ai.state = AIS_0; } static void AiStateCheckShipStuff(Player *p) @@ -3588,8 +3515,7 @@ static void AiStateSellVeh(Player *p) goto return_to_loop; going_to_depot:; - if (++p->ai.state_counter <= 832) - return; + if (++p->ai.state_counter <= 832) return; if (v->current_order.type == OT_GOTO_DEPOT) { v->current_order.type = OT_DUMMY; @@ -3616,8 +3542,7 @@ static void AiStateRemoveStation(Player *p) in_use = malloc(GetStationPoolSize()); memset(in_use, 0, GetStationPoolSize()); FOR_ALL_ORDERS(ord) { - if (ord->type == OT_GOTO_STATION) - in_use[ord->station] = 1; + if (ord->type == OT_GOTO_STATION) in_use[ord->station] = 1; } // Go through all stations and delete those that aren't in use @@ -3645,14 +3570,13 @@ static void AiRemovePlayerRailOrRoad(Player *p, TileIndex tile) if (!IsTileOwner(tile, _current_player)) return; m5 = _m[tile].m5; - if ((m5&~0x3) != 0xC0) { + if ((m5 & 0xFC) != 0xC0) { is_rail_crossing:; m5 = GetRailTrackStatus(tile); - if (m5 == 0xC || m5 == 0x30) - return; + if (m5 == 0xC || m5 == 0x30) return; - if (m5&0x25) { + if (m5 & 0x25) { pos_0: if (!(GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(1, 0))) & 0x19)) { p->ai.cur_dir_a = 0; @@ -3662,7 +3586,7 @@ pos_0: } } - if (m5&0x2A) { + if (m5 & 0x2A) { pos_1: if (!(GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(0, 1))) & 0x16)) { p->ai.cur_dir_a = 1; @@ -3672,7 +3596,7 @@ pos_1: } } - if (m5&0x19) { + if (m5 & 0x19) { pos_2: if (!(GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(1, 0))) & 0x25)) { p->ai.cur_dir_a = 2; @@ -3682,7 +3606,7 @@ pos_2: } } - if (m5&0x16) { + if (m5 & 0x16) { pos_3: if (!(GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(0, 1))) & 0x2A)) { p->ai.cur_dir_a = 3; @@ -3703,28 +3627,31 @@ pos_3: } else if (IsTileType(tile, MP_STREET)) { if (!IsTileOwner(tile, _current_player)) return; - if (IsLevelCrossing(tile)) - goto is_rail_crossing; + if (IsLevelCrossing(tile)) goto is_rail_crossing; - if ( (_m[tile].m5&0xF0) == 0x20) { - int dir; + if ((_m[tile].m5 & 0xF0) == 0x20) { // depot + uint dir; // Check if there are any stations around. if (IsTileType(tile + TileDiffXY(-1, 0), MP_STATION) && - IsTileOwner(tile + TileDiffXY(-1, 0), _current_player)) - return; + IsTileOwner(tile + TileDiffXY(-1, 0), _current_player)) { + return; + } if (IsTileType(tile + TileDiffXY(1, 0), MP_STATION) && - IsTileOwner(tile + TileDiffXY(1, 0), _current_player)) - return; + IsTileOwner(tile + TileDiffXY(1, 0), _current_player)) { + return; + } if (IsTileType(tile + TileDiffXY(0, -1), MP_STATION) && - IsTileOwner(tile + TileDiffXY(0, -1), _current_player)) - return; + IsTileOwner(tile + TileDiffXY(0, -1), _current_player)) { + return; + } if (IsTileType(tile + TileDiffXY(0, 1), MP_STATION) && - IsTileOwner(tile + TileDiffXY(0, 1), _current_player)) - return; + IsTileOwner(tile + TileDiffXY(0, 1), _current_player)) { + return; + } dir = _m[tile].m5 & 3; @@ -3768,17 +3695,14 @@ static void AiStateRemoveTrack(Player *p) // Remove player stuff in that tile AiRemovePlayerRailOrRoad(p, tile); - if (p->ai.state != AIS_REMOVE_TRACK) - return; + if (p->ai.state != AIS_REMOVE_TRACK) return; } while (--num); } static void AiStateRemoveSingleRailTile(Player *p) { // Remove until we can't remove more. - if (!AiRemoveTileAndGoForward(p)) { - p->ai.state = AIS_REMOVE_TRACK; - } + if (!AiRemoveTileAndGoForward(p)) p->ai.state = AIS_REMOVE_TRACK; } static AiStateAction * const _ai_actions[] = { @@ -3819,20 +3743,18 @@ extern void ShowBuyCompanyDialog(uint player); static void AiHandleTakeover(Player *p) { if (p->bankrupt_timeout != 0) { - if ((p->bankrupt_timeout-=8) > 0) - return; + p->bankrupt_timeout -= 8; + if (p->bankrupt_timeout > 0) return; p->bankrupt_timeout = 0; DeleteWindowById(WC_BUY_COMPANY, _current_player); if (IsLocalPlayer()) { AskExitToGameMenu(); return; } - if (IS_HUMAN_PLAYER(_current_player)) - return; + if (IS_HUMAN_PLAYER(_current_player)) return; } - if (p->bankrupt_asked == 255) - return; + if (p->bankrupt_asked == 255) return; { uint asked = p->bankrupt_asked; @@ -3865,8 +3787,7 @@ static void AiHandleTakeover(Player *p) ShowBuyCompanyDialog(_current_player); return; } - if (IS_HUMAN_PLAYER(best_pl->index)) - return; + if (IS_HUMAN_PLAYER(best_pl->index)) return; // Too little money for computer to buy it? if (best_pl->player_money >> 1 >= p->bankrupt_value) { diff --git a/ai/trolly/build.c b/ai/trolly/build.c index 1f56213e0..235166cab 100644 --- a/ai/trolly/build.c +++ b/ai/trolly/build.c @@ -239,8 +239,7 @@ int AiNew_PickVehicle(Player *p) if (!CmdFailed(ret)) break; } // We did not find a vehicle :( - if (CmdFailed(ret)) return -1; - return i; + return CmdFailed(ret) ? -1 : i; } } diff --git a/ai/trolly/pathfinder.c b/ai/trolly/pathfinder.c index 79d1dfc53..1ac4d49cb 100644 --- a/ai/trolly/pathfinder.c +++ b/ai/trolly/pathfinder.c @@ -485,7 +485,7 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, int dir1 = AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile); int dir2 = AiNew_GetRailDirection(parent->path.parent->parent->node.tile, parent->path.parent->node.tile, parent->path.node.tile); // First, see if we are on diagonal path, that is better than straight path - if (dir1 > 1) { res -= AI_PATHFINDER_DIAGONAL_BONUS; } + if (dir1 > 1) res -= AI_PATHFINDER_DIAGONAL_BONUS; // First see if they are different if (dir1 != dir2) { @@ -157,7 +157,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) /* Count stations */ { uint num = 0; - Station *st; + const Station* st; FOR_ALL_STATIONS(st) { if (st->xy != 0 && st->owner == owner) { @@ -170,7 +170,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) /* Generate statistics depending on recent income statistics */ { - PlayerEconomyEntry *pee; + const PlayerEconomyEntry* pee; int numec; int32 min_income; int32 max_income; @@ -194,7 +194,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) /* Generate score depending on amount of transported cargo */ { - PlayerEconomyEntry *pee; + const PlayerEconomyEntry* pee; int numec; uint32 total_delivered; @@ -216,8 +216,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) uint num = 0; do num += cargo&1; while (cargo>>=1); _score_part[owner][SCORE_CARGO] = num; - if (update) - p->cargo_types = 0; + if (update) p->cargo_types = 0; } /* Generate score for player money */ @@ -239,13 +238,13 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) int total_score = 0; int s; score = 0; - for (i=0;i<NUM_SCORE;i++) { + for (i = 0; i < NUM_SCORE; i++) { // Skip the total if (i == SCORE_TOTAL) continue; // Check the score s = (_score_part[owner][i] >= _score_info[i].needed) ? _score_info[i].score : - ((_score_part[owner][i] * _score_info[i].score) / _score_info[i].needed); + _score_part[owner][i] * _score_info[i].score / _score_info[i].needed; if (s < 0) s = 0; score += s; total_score += _score_info[i].score; @@ -254,8 +253,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) _score_part[owner][SCORE_TOTAL] = score; // We always want the score scaled to SCORE_MAX (1000) - if (total_score != SCORE_MAX) - score = score * SCORE_MAX / total_score; + if (total_score != SCORE_MAX) score = score * SCORE_MAX / total_score; } if (update) { diff --git a/graph_gui.c b/graph_gui.c index 14637dbf3..157726c9e 100644 --- a/graph_gui.c +++ b/graph_gui.c @@ -884,9 +884,9 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) { switch (e->event) { case WE_PAINT: { - int val, needed, score, i; + int i; byte owner, x; - uint16 y=14; + uint16 y = 14; int total_score = 0; int color_done, color_notdone; @@ -897,15 +897,14 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) owner = FindFirstBit(w->click_state) - 13; // Paint the player icons - for (i=0;i<MAX_PLAYERS;i++) { + for (i = 0; i < MAX_PLAYERS; i++) { if (!GetPlayer(i)->is_active) { // Check if we have the player as an active player - if (!(w->disabled_state & (1 << (i+13)))) { + if (!(w->disabled_state & (1 << (i + 13)))) { // Bah, player gone :( - w->disabled_state += 1 << (i+13); + w->disabled_state += 1 << (i + 13); // Is this player selected? If so, select first player (always save? :s) - if (w->click_state == 1U << (i + 13)) - w->click_state = 1 << 13; + if (w->click_state == 1U << (i + 13)) w->click_state = 1 << 13; // We need a repaint SetWindowDirty(w); } @@ -913,14 +912,14 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) } // Check if we have the player marked as inactive - if ((w->disabled_state & (1 << (i+13)))) { + if (w->disabled_state & (1 << (i + 13))) { // New player! Yippie :p - w->disabled_state -= 1 << (i+13); + w->disabled_state -= 1 << (i + 13); // We need a repaint SetWindowDirty(w); } - if (i == owner) x = 1; else x = 0; + x = (i == owner) ? 1 : 0; DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x); } @@ -929,11 +928,12 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) color_notdone = _color_list[4].window_color_1b; // Draw all the score parts - for (i=0;i<NUM_SCORE;i++) { + for (i = 0; i < NUM_SCORE; i++) { + int val = _score_part[owner][i]; + int needed = _score_info[i].needed; + int score = _score_info[i].score; + y += 20; - val = _score_part[owner][i]; - needed = _score_info[i].needed; - score = _score_info[i].score; // SCORE_TOTAL has his own rulez ;) if (i == SCORE_TOTAL) { needed = total_score; @@ -949,35 +949,33 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, 0); // Calculate the %-bar - if (val > needed) x = 50; - else if (val == 0) x = 0; - else x = ((val * 50) / needed); + if (val > needed) { + x = 50; + } else if (val == 0) { + x = 0; + } else { + x = val * 50 / needed; + } // SCORE_LOAN is inversed - if (val < 0 && i == SCORE_LOAN) - x = 0; + if (val < 0 && i == SCORE_LOAN) x = 0; // Draw the bar - if (x != 0) - GfxFillRect(112, y-2, x + 112, y+10, color_done); - if (x != 50) - GfxFillRect(x + 112, y-2, 50 + 112, y+10, color_notdone); + if (x != 0) GfxFillRect(112, y - 2, 112 + x, y + 10, color_done); + if (x != 50) GfxFillRect(112 + x, y - 2, 112 + 50, y + 10, color_notdone); // Calculate the % - if (val > needed) x = 100; - else x = ((val * 100) / needed); + x = (val <= needed) ? val * 100 / needed : 100; // SCORE_LOAN is inversed - if (val < 0 && i == SCORE_LOAN) - x = 0; + if (val < 0 && i == SCORE_LOAN) x = 0; // Draw it SetDParam(0, x); DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, 0); // SCORE_LOAN is inversed - if (i == SCORE_LOAN) - val = needed - val; + if (i == SCORE_LOAN) val = needed - val; // Draw the amount we have against what is needed // For some of them it is in currency format @@ -1017,16 +1015,14 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) w->disabled_state = 0; // Hide the player who are not active - for (i=0;i<MAX_PLAYERS;i++) { - if (!GetPlayer(i)->is_active) { - w->disabled_state += 1 << (i+13); - } + for (i = 0; i < MAX_PLAYERS; i++) { + if (!GetPlayer(i)->is_active) w->disabled_state += 1 << (i + 13); } // Update all player stats with the current data // (this is because _score_info is not saved to a savegame) - FOR_ALL_PLAYERS(p2) - if (p2->is_active) - UpdateCompanyRatingAndValue(p2, false); + FOR_ALL_PLAYERS(p2) { + if (p2->is_active) UpdateCompanyRatingAndValue(p2, false); + } w->custom[0] = DAY_TICKS; w->custom[1] = 5; @@ -1044,11 +1040,12 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) w->custom[0] = DAY_TICKS; if (--w->custom[1] == 0) { Player *p2; + w->custom[1] = 5; - FOR_ALL_PLAYERS(p2) + FOR_ALL_PLAYERS(p2) { // Skip if player is not active - if (p2->is_active) - UpdateCompanyRatingAndValue(p2, false); + if (p2->is_active) UpdateCompanyRatingAndValue(p2, false); + } SetWindowDirty(w); } } @@ -600,9 +600,9 @@ int FindFirstBit(uint32 value) // not more than 128. byte i = 0; if (value & 0xffff0000) { value >>= 16; i += 16; } - if (value & 0x0000ff00) { value >>= 8; i += 8; } - if (value & 0x000000f0) { value >>= 4; i += 4; } - if (value & 0x0000000c) { value >>= 2; i += 2; } + if (value & 0x0000ff00) { value >>= 8; i += 8; } + if (value & 0x000000f0) { value >>= 4; i += 4; } + if (value & 0x0000000c) { value >>= 2; i += 2; } if (value & 0x00000002) { i += 1; } return i; } @@ -239,8 +239,7 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf case 0x09: { /* Speed */ FOR_EACH_OBJECT { uint16 speed = grf_load_word(&buf); - if (speed == 0xFFFF) - speed = 0; + if (speed == 0xFFFF) speed = 0; rvi[i].max_speed = speed; } @@ -249,8 +248,7 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf FOR_EACH_OBJECT { uint16 power = grf_load_word(&buf); - if (rvi[i].flags & RVI_MULTIHEAD) - power /= 2; + if (rvi[i].flags & RVI_MULTIHEAD) power /= 2; rvi[i].power = power; dewagonize(power, engine + i); @@ -260,8 +258,7 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf FOR_EACH_OBJECT { uint8 runcostfact = grf_load_byte(&buf); - if (rvi[i].flags & RVI_MULTIHEAD) - runcostfact /= 2; + if (rvi[i].flags & RVI_MULTIHEAD) runcostfact /= 2; rvi[i].running_cost_base = runcostfact; } @@ -283,8 +280,7 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf /* TTD sprite IDs point to a location in a 16bit array, but we use it * as an array index, so we need it to be half the original value. */ - if (spriteid < 0xFD) - spriteid >>= 1; + if (spriteid < 0xFD) spriteid >>= 1; rvi[i].image_index = spriteid; } @@ -361,14 +357,15 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf uint8 traction = grf_load_byte(&buf); int engclass; - if (traction <= 0x07) + if (traction <= 0x07) { engclass = 0; - else if (traction <= 0x27) + } else if (traction <= 0x27) { engclass = 1; - else if (traction <= 0x41) + } else if (traction <= 0x41) { engclass = 2; - else + } else { break; + } rvi[i].engclass = engclass; } @@ -504,11 +501,10 @@ static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf FOR_EACH_OBJECT { uint8 spriteid = grf_load_byte(&buf); - if (spriteid == 0xFF) - spriteid = 0xFD; // cars have different custom id in the GRF file + // cars have different custom id in the GRF file + if (spriteid == 0xFF) spriteid = 0xFD; - if (spriteid < 0xFD) - spriteid >>= 1; + if (spriteid < 0xFD) spriteid >>= 1; rvi[i].image_index = spriteid; } @@ -614,11 +610,10 @@ static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf FOR_EACH_OBJECT { uint8 spriteid = grf_load_byte(&buf); - if (spriteid == 0xFF) - spriteid = 0xFD; // ships have different custom id in the GRF file + // ships have different custom id in the GRF file + if (spriteid == 0xFF) spriteid = 0xFD; - if (spriteid < 0xFD) - spriteid >>= 1; + if (spriteid < 0xFD) spriteid >>= 1; svi[i].image_index = spriteid; } @@ -740,11 +735,10 @@ static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte * FOR_EACH_OBJECT { uint8 spriteid = grf_load_byte(&buf); - if (spriteid == 0xFF) - spriteid = 0xFD; // ships have different custom id in the GRF file + // aircraft have different custom id in the GRF file + if (spriteid == 0xFF) spriteid = 0xFD; - if (spriteid < 0xFD) - spriteid >>= 1; + if (spriteid < 0xFD) spriteid >>= 1; avi[i].image_index = spriteid; } @@ -1034,9 +1028,11 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int p = 0; layout = malloc(length * number); - for (l = 0; l < length; l++) - for (p = 0; p < number; p++) + for (l = 0; l < length; l++) { + for (p = 0; p < number; p++) { layout[l * number + p] = grf_load_byte(&buf); + } + } l--; p--; @@ -1361,10 +1357,11 @@ static SpriteGroup* NewCallBackResultSpriteGroup(uint16 value) // Old style callback results have the highest byte 0xFF so signify it is a callback result // New style ones only have the highest bit set (allows 15-bit results, instead of just 8) - if ((value >> 8) == 0xFF) - value &= 0xFF; - else + if ((value >> 8) == 0xFF) { + value &= ~0xFF00; + } else { value &= ~0x8000; + } group->g.callback.result = value; @@ -2507,7 +2504,7 @@ static void ResetCustomStations(void) */ static void ResetNewGRFData(void) { - int i; + uint i; // Copy/reset original engine info data memcpy(&_engine_info, &orig_engine_info, sizeof(orig_engine_info)); @@ -2520,9 +2517,9 @@ static void ResetNewGRFData(void) // First, free sprite table data for (i = 0; i < MAX_BRIDGES; i++) { if (_bridge[i].sprite_table != NULL) { - byte j; - for (j = 0; j < 7; j++) - free(_bridge[i].sprite_table[j]); + uint j; + + for (j = 0; j < 7; j++) free(_bridge[i].sprite_table[j]); free(_bridge[i].sprite_table); } } @@ -2563,8 +2560,7 @@ static void InitNewGRFFile(const char* filename, int sprite_offset) newfile = calloc(1, sizeof(*newfile)); - if (newfile == NULL) - error ("Out of memory"); + if (newfile == NULL) error ("Out of memory"); newfile->filename = strdup(filename); newfile->sprite_offset = sprite_offset; @@ -2594,15 +2590,19 @@ static void CalculateRefitMasks(void) if (cargo_allowed[engine] != 0) { // Build up the list of cargo types from the set cargo classes. for (i = 0; i < lengthof(cargo_classes); i++) { - if (HASBIT(cargo_allowed[engine], i)) - mask |= cargo_classes[i]; - if (HASBIT(cargo_disallowed[engine], i)) - not_mask |= cargo_classes[i]; + if (HASBIT(cargo_allowed[engine], i)) mask |= cargo_classes[i]; + if (HASBIT(cargo_disallowed[engine], i)) not_mask |= cargo_classes[i]; } } else { // Don't apply default refit mask to wagons or engines with no capacity - if (xor_mask == 0 && !(GetEngine(engine)->type == VEH_Train && (RailVehInfo(engine)->capacity == 0 || RailVehInfo(engine)->flags & RVI_WAGON))) + if (xor_mask == 0 && ( + GetEngine(engine)->type != VEH_Train || ( + RailVehInfo(engine)->capacity != 0 && + !(RailVehInfo(engine)->flags & RVI_WAGON) + ) + )) { xor_mask = _default_refitmasks[GetEngine(engine)->type - VEH_Train]; + } } _engine_info[engine].refit_mask = ((mask & ~not_mask) ^ xor_mask) & _landscape_global_cargo_mask[_opt.landscape]; } diff --git a/oldloader.c b/oldloader.c index 653963a41..76fb79de9 100644 --- a/oldloader.c +++ b/oldloader.c @@ -472,17 +472,12 @@ static void ReadTTDPatchFlags(void) 1 vehicle == 128 bytes */ _bump_assert_value = (_old_vehicle_multipler - 1) * 850 * 128; - _new_ttdpatch_format = false; - /* Check if we have a modern TTDPatch savegame (has extra data all around) */ - if (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0) - _new_ttdpatch_format = true; + _new_ttdpatch_format = (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0); /* Clean the misused places */ - for (i = 0; i < 17; i++) - _old_map3[i] = 0; - for (i = 0x1FE00; i < 0x20000; i++) - _old_map3[i] = 0; + for (i = 0; i < 17; i++) _old_map3[i] = 0; + for (i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0; if (_new_ttdpatch_format) DEBUG(oldloader, 1)("[OldLoader] Found TTDPatch game"); @@ -282,12 +282,13 @@ static void LoadIntroGame(void) // Generate a world. sprintf(filename, "%sopntitle.dat", _path.data_dir); - if (SaveOrLoad(filename, SL_LOAD) != SL_OK) { #if defined SECOND_DATA_DIR + if (SaveOrLoad(filename, SL_LOAD) != SL_OK) { sprintf(filename, "%sopntitle.dat", _path.second_data_dir); - if (SaveOrLoad(filename, SL_LOAD) != SL_OK) + } #endif - GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world. + if (SaveOrLoad(filename, SL_LOAD) != SL_OK) { + GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world. } _pause = 0; diff --git a/roadveh_cmd.c b/roadveh_cmd.c index 7ef55f052..b81eee206 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -252,8 +252,11 @@ int32 CmdSellRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); - if (!IsTileDepotType(v->tile, TRANSPORT_ROAD) || v->u.road.state != 254 || !(v->vehstatus&VS_STOPPED)) + if (!IsTileDepotType(v->tile, TRANSPORT_ROAD) || + v->u.road.state != 254 || + !(v->vehstatus & VS_STOPPED)) { return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); + } if (flags & DC_EXEC) { // Invalidate depot @@ -296,7 +299,7 @@ static bool EnumRoadSignalFindDepot(TileIndex tile, RoadFindDepotData *rfdd, int return false; } -static Depot *FindClosestRoadDepot(Vehicle *v) +static const Depot* FindClosestRoadDepot(const Vehicle* v) { TileIndex tile = v->tile; int i; @@ -321,8 +324,9 @@ static Depot *FindClosestRoadDepot(Vehicle *v) rfdd.best_length = (uint)-1; /* search in all directions */ - for (i = 0; i != 4; i++) + for (i = 0; i != 4; i++) { FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadSignalFindDepot, NULL, &rfdd); + } if (rfdd.best_length == (uint)-1) return NULL; @@ -534,7 +538,8 @@ static void RoadVehCrash(Vehicle *v) STR_9031_ROAD_VEHICLE_CRASH_DRIVER : STR_9032_ROAD_VEHICLE_CRASH_DIE, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), v->index, - 0); + 0 + ); ModifyStationRatingAround(v->tile, v->owner, -160, 22); SndPlayVehicleFx(SND_12_EXPLOSION, v); @@ -744,8 +749,7 @@ static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, byte dir) return NULL; } - if (++v->u.road.blocked_ctr > 1480) - return NULL; + if (++v->u.road.blocked_ctr > 1480) return NULL; return u; } @@ -778,7 +782,8 @@ static void RoadVehArrivesAt(const Vehicle* v, Station* st) STR_9030_CITIZENS_CELEBRATE_FIRST, flags, v->index, - 0); + 0 + ); } } } @@ -857,7 +862,7 @@ static bool FindRoadVehToOvertake(OvertakeData *od) { uint32 bits; - bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD)&0x3F; + bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD) & 0x3F; if (!(od->tilebits & bits) || (bits&0x3C) || (bits & 0x3F3F0000)) return true; @@ -878,11 +883,9 @@ static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u) return; } - if (v->direction != u->direction || !(v->direction&1)) - return; + if (v->direction != u->direction || !(v->direction & 1)) return; - if (v->u.road.state >= 32 || (v->u.road.state&7) > 1 ) - return; + if (v->u.road.state >= 32 || (v->u.road.state & 7) > 1) return; tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F; if ((tt & 3) == 0) return; @@ -1049,7 +1052,7 @@ static int RoadFindPathToDest(Vehicle *v, TileIndex tile, int enterdir) } else { if (IsTileType(desttile, MP_STREET)) { m5 = _m[desttile].m5; - if ((m5&0xF0) == 0x20) + if ((m5 & 0xF0) == 0x20) /* We are heading for a Depot */ goto do_it; } else if (IsTileType(desttile, MP_STATION)) { @@ -1169,16 +1172,16 @@ static void RoadVehController(Vehicle *v) if (v->u.road.state == 254) { int dir; - const RoadDriveEntry*rdp; + const RoadDriveEntry* rdp; byte rd2; v->cur_speed = 0; dir = GB(_m[v->tile].m5, 0, 2); - v->direction = dir*2+1; + v->direction = dir * 2 + 1; rd2 = _roadveh_data_2[dir]; - rdp = _road_drive_data[(_opt.road_side<<4) + rd2]; + rdp = _road_drive_data[(_opt.road_side << 4) + rd2]; x = TileX(v->tile) * 16 + (rdp[6].x & 0xF); y = TileY(v->tile) * 16 + (rdp[6].y & 0xF); @@ -1213,8 +1216,9 @@ static void RoadVehController(Vehicle *v) if (v->u.road.state == 0 || v->u.road.state == 1 || v->u.road.state == 8 || v->u.road.state == 9 || v->u.road.state == 16 || v->u.road.state == 17 || - v->u.road.state == 24 || v->u.road.state == 25) + v->u.road.state == 24 || v->u.road.state == 25) { v->u.road.overtaking = 0; + } } BeginVehicleMove(v); @@ -1244,12 +1248,12 @@ static void RoadVehController(Vehicle *v) return; } - rd = _road_drive_data[(v->u.road.state + (_opt.road_side<<4)) ^ v->u.road.overtaking][v->u.road.frame+1]; + rd = _road_drive_data[(v->u.road.state + (_opt.road_side << 4)) ^ v->u.road.overtaking][v->u.road.frame + 1]; // switch to another tile if (rd.x & 0x80) { TileIndex tile = v->tile + TileOffsByDir(rd.x & 3); - int dir = RoadFindPathToDest(v, tile, rd.x&3); + int dir = RoadFindPathToDest(v, tile, rd.x & 3); uint32 r; byte newdir; const RoadDriveEntry *rdp; @@ -1284,7 +1288,10 @@ again: } if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) { - if ((dir & 7) >= 6) { v->cur_speed = 0; return; } + if ((dir & 7) >= 6) { + v->cur_speed = 0; + return; + } if (IS_BYTE_INSIDE(_m[v->tile].m5, 0x43, 0x4B)) { RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); byte *b = &rs->status; @@ -1312,7 +1319,7 @@ again: } if (rd.x & 0x40) { - int dir = RoadFindPathToDest(v, v->tile, rd.x&3); + int dir = RoadFindPathToDest(v, v->tile, rd.x & 3); uint32 r; int tmp; byte newdir; @@ -1323,7 +1330,7 @@ again: return; } - tmp = (_opt.road_side<<4) + dir; + tmp = (_opt.road_side << 4) + dir; rdp = _road_drive_data[tmp]; x = TileX(v->tile) * 16 + rdp[1].x; @@ -1352,12 +1359,13 @@ again: return; } - x = (v->x_pos&~15)+(rd.x&15); - y = (v->y_pos&~15)+(rd.y&15); + x = (v->x_pos & ~15) + (rd.x & 15); + y = (v->y_pos & ~15) + (rd.y & 15); 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 (!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); return; } @@ -1503,7 +1511,7 @@ void RoadVeh_Tick(Vehicle *v) static void CheckIfRoadVehNeedsService(Vehicle *v) { - Depot *depot; + const Depot* depot; if (_patches.servint_roadveh == 0) return; if (!VehicleNeedsService(v)) return; @@ -1532,8 +1540,9 @@ static void CheckIfRoadVehNeedsService(Vehicle *v) if (v->current_order.type == OT_GOTO_DEPOT && v->current_order.flags & OF_NON_STOP && - !CHANCE16(1,20)) + !CHANCE16(1, 20)) { return; + } v->current_order.type = OT_GOTO_DEPOT; v->current_order.flags = OF_NON_STOP; @@ -1578,8 +1587,9 @@ void OnNewDay_RoadVeh(Vehicle *v) DEBUG(ms, 2) ("Multistop: Attempting to obtain a slot for vehicle %d at station %d (0x%x)", v->unitnumber, st->index, st->xy); for (; rs != NULL; rs = rs->next) { // Only consider those with at least a free slot. - if (!(rs->slot[0] == INVALID_VEHICLE || rs->slot[1] == INVALID_VEHICLE)) + if (rs->slot[0] != INVALID_VEHICLE && rs->slot[1] != INVALID_VEHICLE) { continue; + } // Previously the NPF pathfinder was used here even if NPF is OFF.. WTF? assert(NUM_SLOTS == 2); diff --git a/station_cmd.c b/station_cmd.c index 9799878ba..025835f69 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -1623,12 +1623,12 @@ int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2) { const byte *b = _airport_map5_tiles[p1]; - BEGIN_TILE_LOOP(tile_cur,w,h,tile) { + BEGIN_TILE_LOOP(tile_cur, w, h, tile) { ModifyTile(tile_cur, MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5, st->index, *b++); - } END_TILE_LOOP(tile_cur,w,h,tile) + } END_TILE_LOOP(tile_cur, w, h, tile) } UpdateStationVirtCoordDirty(st); @@ -1655,24 +1655,24 @@ static int32 RemoveAirport(Station *st, uint32 flags) cost = w * h * _price.remove_airport; - { -BEGIN_TILE_LOOP(tile_cur,w,h,tile) - if (!EnsureNoVehicle(tile_cur)) - return CMD_ERROR; + BEGIN_TILE_LOOP(tile_cur, w, h, tile) { + if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; if (flags & DC_EXEC) { DeleteAnimatedTile(tile_cur); DoClearSquare(tile_cur); } -END_TILE_LOOP(tile_cur, w,h,tile) - } + } END_TILE_LOOP(tile_cur, w,h,tile) if (flags & DC_EXEC) { const AirportFTAClass *afc = GetAirport(st->airport_type); uint i; - for (i = 0; i < afc->nof_depots; ++i) - DeleteWindowById(WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i])); + for (i = 0; i < afc->nof_depots; ++i) { + DeleteWindowById( + WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i]) + ); + } st->airport_tile = 0; st->facilities &= ~FACIL_AIRPORT; @@ -2156,6 +2156,7 @@ static void AnimateTile_Station(TileIndex tile) } } + static void ClickTile_Station(TileIndex tile) { // 0x20 - hangar large airport (32) @@ -2297,7 +2298,7 @@ void DeleteAllPlayerStations(void) static void CheckOrphanedSlots(const Station *st, RoadStopType rst) { RoadStop *rs; - int k; + uint k; for (rs = GetPrimaryRoadStop(st, rst); rs != NULL; rs = rs->next) { for (k = 0; k < NUM_SLOTS; k++) { @@ -2934,10 +2935,10 @@ static void Load_STNS(void) // this means it's an oldstyle savegame without support for nonuniform stations if (st->train_tile != 0 && st->trainst_h == 0) { - int w = GB(st->trainst_w, 4, 4); - int h = GB(st->trainst_w, 0, 4); + uint w = GB(st->trainst_w, 4, 4); + uint h = GB(st->trainst_w, 0, 4); - if (_m[st->train_tile].m5 & 1) intswap(w, h); + if (_m[st->train_tile].m5 & 1) uintswap(w, h); st->trainst_w = w; st->trainst_h = h; } @@ -589,12 +589,11 @@ static char *FormatString(char *buff, const char *str, const int32 *argv, uint c } case 11: { /* {INDUSTRY} */ - Industry *i = GetIndustry(GetInt32(&argv)); + const Industry* i = GetIndustry(GetInt32(&argv)); int32 args[2]; // industry not valid anymore? - if (i->xy == 0) - break; + if (i->xy == 0) break; // First print the town name and the industry type name // The string STR_INDUSTRY_PATTERN controls the formatting @@ -1048,7 +1047,6 @@ bool ReadLanguagePack(int lang_index) ttd_strlcpy(_dynlang.curr_file, _dynlang.ent[lang_index].file, sizeof(_dynlang.curr_file)); - _dynlang.curr = lang_index; return true; } @@ -1117,8 +1115,7 @@ void InitializeLanguagePacks(void) error(n == 0 ? "No available language packs" : "Invalid version of language packs"); dl->num = m; - for (i = 0; i != dl->num; i++) - dl->dropdown[i] = SPECSTR_LANGUAGE_START + i; + for (i = 0; i != dl->num; i++) dl->dropdown[i] = SPECSTR_LANGUAGE_START + i; dl->dropdown[i] = INVALID_STRING_ID; for (i = 0; i != dl->num; i++) diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index 067778230..00276c84d 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -419,7 +419,7 @@ not_valid_below:; if (_current_player < MAX_PLAYERS && !_is_old_ai_player) bridge_len = CalcBridgeLenCostFactor(bridge_len); - cost += ((int64)bridge_len * _price.build_bridge * b->price) >> 8; + cost += (int64)bridge_len * _price.build_bridge * b->price >> 8; } return cost; |