From dea7f078f453fd80a8c399cde9ad998f59d5ace8 Mon Sep 17 00:00:00 2001 From: Gabda Date: Tue, 12 Mar 2019 20:12:34 +0100 Subject: [PATCH 1/8] Codechange: Update town sign on population change only when population is shown (#7368) --- src/town_cmd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index ee2f49d930..0ae79367cc 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -423,7 +423,7 @@ static void ChangePopulation(Town *t, int mod) { t->cache.population += mod; InvalidateWindowData(WC_TOWN_VIEW, t->index); // Cargo requirements may appear/vanish for small populations - t->UpdateVirtCoord(); + if (_settings_client.gui.population_in_label) t->UpdateVirtCoord(); InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1); } From ba3d7122dfcbbee750dad6559b8c354bec873505 Mon Sep 17 00:00:00 2001 From: "Johannes E. Krause" Date: Tue, 12 Mar 2019 13:09:33 +0100 Subject: [PATCH 2/8] Cleanup: Remove questionable syntax in station rating calculation --- src/station_cmd.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index f7eb353a09..ec4f6739e8 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3375,27 +3375,25 @@ static void UpdateStationRating(Station *st) byte waittime = ge->time_since_pickup; if (st->last_vehicle_type == VEH_SHIP) waittime >>= 2; - (waittime > 21) || - (rating += 25, waittime > 12) || - (rating += 25, waittime > 6) || - (rating += 45, waittime > 3) || - (rating += 35, true); + if (waittime <= 21) rating += 25; + if (waittime <= 12) rating += 25; + if (waittime <= 6) rating += 45; + if (waittime <= 3) rating += 35; - (rating -= 90, ge->max_waiting_cargo > 1500) || - (rating += 55, ge->max_waiting_cargo > 1000) || - (rating += 35, ge->max_waiting_cargo > 600) || - (rating += 10, ge->max_waiting_cargo > 300) || - (rating += 20, ge->max_waiting_cargo > 100) || - (rating += 10, true); + rating -= 90; + if (ge->max_waiting_cargo <= 1500) rating += 55; + if (ge->max_waiting_cargo <= 1000) rating += 35; + if (ge->max_waiting_cargo <= 600) rating += 10; + if (ge->max_waiting_cargo <= 300) rating += 20; + if (ge->max_waiting_cargo <= 100) rating += 10; } if (Company::IsValidID(st->owner) && HasBit(st->town->statues, st->owner)) rating += 26; byte age = ge->last_age; - (age >= 3) || - (rating += 10, age >= 2) || - (rating += 10, age >= 1) || - (rating += 13, true); + if (age < 3) rating += 10; + if (age < 2) rating += 10; + if (age < 1) rating += 13; { int or_ = ge->rating; // old rating From 234f1007f7a6e81f38ddd1de06c6e1727cb9da76 Mon Sep 17 00:00:00 2001 From: "Johannes E. Krause" Date: Tue, 12 Mar 2019 14:55:56 +0100 Subject: [PATCH 3/8] Cleanup: Remove questionable syntax in HQ size calculation --- src/object_cmd.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index 9f03813dfb..0b18dd4b14 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -158,12 +158,11 @@ void UpdateCompanyHQ(TileIndex tile, uint score) { if (tile == INVALID_TILE) return; - byte val; - (val = 0, score < 170) || - (val++, score < 350) || - (val++, score < 520) || - (val++, score < 720) || - (val++, true); + byte val = 0; + if (score >= 170) val++; + if (score >= 350) val++; + if (score >= 520) val++; + if (score >= 720) val++; while (GetCompanyHQSize(tile) < val) { IncreaseCompanyHQSize(tile); From 21ec3e55314505153c363ed52857306d595f55d3 Mon Sep 17 00:00:00 2001 From: "Johannes E. Krause" Date: Tue, 12 Mar 2019 15:05:00 +0100 Subject: [PATCH 4/8] Cleanup: Remove questionable syntax in GetOrderCmdFromTile --- src/order_gui.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 81350deb74..e50247e275 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -395,11 +395,13 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile) if (st->owner == _local_company || st->owner == OWNER_NONE) { byte facil; - (facil = FACIL_DOCK, v->type == VEH_SHIP) || - (facil = FACIL_TRAIN, v->type == VEH_TRAIN) || - (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) || - (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) || - (facil = FACIL_TRUCK_STOP, 1); + switch (v->type) { + case VEH_SHIP: facil = FACIL_DOCK; break; + case VEH_TRAIN: facil = FACIL_TRAIN; break; + case VEH_AIRCRAFT: facil = FACIL_AIRPORT; break; + case VEH_ROAD: facil = RoadVehicle::From(v)->IsBus() ? FACIL_BUS_STOP : FACIL_TRUCK_STOP; break; + default: NOT_REACHED(); + } if (st->facilities & facil) { order.MakeGoToStation(st_index); if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY); From e6798ffdca7d374ad23e35f56017a6777cf527ce Mon Sep 17 00:00:00 2001 From: "Johannes E. Krause" Date: Tue, 12 Mar 2019 18:08:13 +0100 Subject: [PATCH 5/8] Cleanup: Remove questionable syntax in town rating display --- src/town_gui.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 17449854d6..bc322b08f2 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -154,15 +154,14 @@ public: SetDParam(1, c->index); int r = this->town->ratings[c->index]; - StringID str; - (str = STR_CARGO_RATING_APPALLING, r <= RATING_APPALLING) || // Apalling - (str++, r <= RATING_VERYPOOR) || // Very Poor - (str++, r <= RATING_POOR) || // Poor - (str++, r <= RATING_MEDIOCRE) || // Mediocore - (str++, r <= RATING_GOOD) || // Good - (str++, r <= RATING_VERYGOOD) || // Very Good - (str++, r <= RATING_EXCELLENT) || // Excellent - (str++, true); // Outstanding + StringID str = STR_CARGO_RATING_APPALLING; + if (r > RATING_APPALLING) str++; + if (r > RATING_VERYPOOR) str++; + if (r > RATING_POOR) str++; + if (r > RATING_MEDIOCRE) str++; + if (r > RATING_GOOD) str++; + if (r > RATING_VERYGOOD) str++; + if (r > RATING_EXCELLENT) str++; SetDParam(2, str); if (this->town->exclusivity == c->index) { From 43ced57794ca5546e5f5a18eb82990d20845967c Mon Sep 17 00:00:00 2001 From: "Johannes E. Krause" Date: Tue, 12 Mar 2019 20:41:37 +0100 Subject: [PATCH 6/8] Cleanup: Remove questionable syntax in track drawing --- src/rail_cmd.cpp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index aa4e7ab551..1c07932cd3 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -2285,23 +2285,30 @@ static void DrawTrackBits(TileInfo *ti, TrackBits track) image = _track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.track_y; } else { /* track on flat ground */ - (image = rti->base_sprites.track_y, track == TRACK_BIT_Y) || - (image++, track == TRACK_BIT_X) || - (image++, track == TRACK_BIT_UPPER) || - (image++, track == TRACK_BIT_LOWER) || - (image++, track == TRACK_BIT_RIGHT) || - (image++, track == TRACK_BIT_LEFT) || - (image++, track == TRACK_BIT_CROSS) || + switch (track) { + /* single track, select combined track + ground sprite*/ + case TRACK_BIT_Y: image = rti->base_sprites.track_y; break; + case TRACK_BIT_X: image = rti->base_sprites.track_y + 1; break; + case TRACK_BIT_UPPER: image = rti->base_sprites.track_y + 2; break; + case TRACK_BIT_LOWER: image = rti->base_sprites.track_y + 3; break; + case TRACK_BIT_RIGHT: image = rti->base_sprites.track_y + 4; break; + case TRACK_BIT_LEFT: image = rti->base_sprites.track_y + 5; break; + case TRACK_BIT_CROSS: image = rti->base_sprites.track_y + 6; break; - (image = rti->base_sprites.track_ns, track == TRACK_BIT_HORZ) || - (image++, track == TRACK_BIT_VERT) || + /* double diagonal track, select combined track + ground sprite*/ + case TRACK_BIT_HORZ: image = rti->base_sprites.track_ns; break; + case TRACK_BIT_VERT: image = rti->base_sprites.track_ns + 1; break; - (junction = true, false) || - (image = rti->base_sprites.ground, (track & TRACK_BIT_3WAY_NE) == 0) || - (image++, (track & TRACK_BIT_3WAY_SW) == 0) || - (image++, (track & TRACK_BIT_3WAY_NW) == 0) || - (image++, (track & TRACK_BIT_3WAY_SE) == 0) || - (image++, true); + /* junction, select only ground sprite, handle track sprite later */ + default: + junction = true; + if ((track & TRACK_BIT_3WAY_NE) == 0) { image = rti->base_sprites.ground; break; } + if ((track & TRACK_BIT_3WAY_SW) == 0) { image = rti->base_sprites.ground + 1; break; } + if ((track & TRACK_BIT_3WAY_NW) == 0) { image = rti->base_sprites.ground + 2; break; } + if ((track & TRACK_BIT_3WAY_SE) == 0) { image = rti->base_sprites.ground + 3; break; } + image = rti->base_sprites.ground + 4; + break; + } } switch (rgt) { From 6b92b83128d92e5b064649922780eadeee9c31ba Mon Sep 17 00:00:00 2001 From: peter1138 Date: Wed, 13 Mar 2019 07:29:11 +0000 Subject: [PATCH 7/8] Fix #7372: FindStationsAroundTiles() with caching returns no result for industry tiles. Currently this can only be triggered by NewGRF house tiles querying for cargo acceptance history of nearby stations (var 0x64) with a tile offset, and providing an offset that happens to point to an industry tile. This serves no useful purpose. --- src/station_cmd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index ec4f6739e8..df71da127c 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3829,7 +3829,7 @@ void FindStationsAroundTiles(const TileArea &location, StationList *stations, bo /* Industries and towns maintain a list of nearby stations */ if (IsTileType(location.tile, MP_INDUSTRY)) { /* Industry nearby stations are already filtered by catchment. */ - stations = &Industry::GetByTile(location.tile)->stations_near; + *stations = Industry::GetByTile(location.tile)->stations_near; return; } else if (IsTileType(location.tile, MP_HOUSE)) { /* Town nearby stations need to be filtered per tile. */ From b00a861467b9c7ea62bae2df140975f0838e0ea7 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Wed, 13 Mar 2019 08:14:15 +0000 Subject: [PATCH 8/8] Codechange: Make FindStationsAroundTile() out-parameter stations const to prevent incorrect modification. --- src/station_cmd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index df71da127c..72c70456f7 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3820,10 +3820,10 @@ static void AddNearbyStationsByCatchment(TileIndex tile, StationList *stations, * Find all stations around a rectangular producer (industry, house, headquarter, ...) * * @param location The location/area of the producer - * @param stations The list to store the stations in + * @param[out] stations The list to store the stations in * @param use_nearby Use nearby station list of industry/town associated with location.tile */ -void FindStationsAroundTiles(const TileArea &location, StationList *stations, bool use_nearby) +void FindStationsAroundTiles(const TileArea &location, StationList * const stations, bool use_nearby) { if (use_nearby) { /* Industries and towns maintain a list of nearby stations */