From f8efab4653b195de2a16c331a90d56c0d8ccaa03 Mon Sep 17 00:00:00 2001 From: translators Date: Fri, 12 Nov 2021 18:46:13 +0000 Subject: [PATCH 01/10] Update: Translations from eints japanese: 1 change by akaregi dutch: 3 changes by Afoklala --- src/lang/dutch.txt | 4 +++- src/lang/japanese.txt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lang/dutch.txt b/src/lang/dutch.txt index 5b11449440..ff15afbf64 100644 --- a/src/lang/dutch.txt +++ b/src/lang/dutch.txt @@ -1741,8 +1741,10 @@ STR_CONFIG_SETTING_NEWS_ARRIVAL_FIRST_VEHICLE_OTHER :Eerste voertuig STR_CONFIG_SETTING_NEWS_ARRIVAL_FIRST_VEHICLE_OTHER_HELPTEXT :Nieuwsbericht weergeven als het eerste voertuig arriveert op een nieuw station van een concurrent STR_CONFIG_SETTING_NEWS_ACCIDENTS_DISASTERS :Ongelukken / rampen: {STRING} -STR_CONFIG_SETTING_NEWS_ACCIDENTS_DISASTERS_HELPTEXT :Nieuwsbericht weergeven bij ongevallen of rampen +STR_CONFIG_SETTING_NEWS_ACCIDENTS_DISASTERS_HELPTEXT :Nieuwsbericht weergeven bij ongelukken of rampen +STR_CONFIG_SETTING_NEWS_ACCIDENT_OTHER :Ongelukken met voertuigen van concurrenten: {STRING} +STR_CONFIG_SETTING_NEWS_ACCIDENT_OTHER_HELPTEXT :Nieuwsbericht weergeven over ongelukken met voertuigen van concurrenten STR_CONFIG_SETTING_NEWS_COMPANY_INFORMATION :Bedrijfsinformatie: {STRING} STR_CONFIG_SETTING_NEWS_COMPANY_INFORMATION_HELPTEXT :Nieuwsbericht weergeven als een nieuw bedrijf start en wanneer een bedrijf bijna falliet gaat diff --git a/src/lang/japanese.txt b/src/lang/japanese.txt index cbf78cf54a..3946ef3895 100644 --- a/src/lang/japanese.txt +++ b/src/lang/japanese.txt @@ -4102,7 +4102,7 @@ STR_VEHICLE_VIEW_CLONE_AIRCRAFT_INFO :{BLACK}航空 STR_VEHICLE_VIEW_TRAIN_IGNORE_SIGNAL_TOOLTIP :{BLACK}赤信号を無視して進行させます STR_VEHICLE_VIEW_TRAIN_REVERSE_TOOLTIP :{BLACK}運転方向を反転させます STR_VEHICLE_VIEW_ROAD_VEHICLE_REVERSE_TOOLTIP :{BLACK}車両を反転します -STR_VEHICLE_VIEW_ORDER_LOCATION_TOOLTIP :{BLACK}注文先の中央のメインビュー。Ctrlキーを押しながらクリックすると、注文先の場所に新しいビューポートが開きます +STR_VEHICLE_VIEW_ORDER_LOCATION_TOOLTIP :{BLACK}移動先の中央のメインビュー。Ctrlキーを押しながらクリックすると移動先の新しいビューポートが開きます ###length VEHICLE_TYPES STR_VEHICLE_VIEW_TRAIN_REFIT_TOOLTIP :{BLACK}現在とは異なる種類の貨物を運送するように列車を改造します From 5f6303f985928d8fe2a9f75b80a32c9564b88fd6 Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 13 Nov 2021 21:01:16 +0100 Subject: [PATCH 02/10] Fix: don't complain when the sprite font is missing glyphs. (#9692) Silently auto-pick a suitable font. --- src/strings.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/strings.cpp b/src/strings.cpp index 7ff1cee315..bfbde9b0dc 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -2116,6 +2116,7 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher) if (bad_font) { /* We found an unprintable character... lets try whether we can find * a fallback font that can print the characters in the current language. */ + bool any_font_configured = !_freetype.medium.font.empty(); FreeTypeSettings backup = _freetype; _freetype.mono.os_handle = nullptr; @@ -2125,10 +2126,10 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher) _freetype = backup; - if (!bad_font) { - /* Show that we loaded fallback font. To do this properly we have - * to set the colour of the string, otherwise we end up with a lot - * of artifacts.* The colour 'character' might change in the + if (!bad_font && any_font_configured) { + /* If the user configured a bad font, and we found a better one, + * show that we loaded the better font instead of the configured one. + * The colour 'character' might change in the * future, so for safety we just Utf8 Encode it into the string, * which takes exactly three characters, so it replaces the "XXX" * with the colour marker. */ From 0cbe94256e4f600ceb397ddf8c0e3dca60676e5b Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sun, 14 Nov 2021 16:59:49 +0100 Subject: [PATCH 03/10] Change: [Emscripten] update to 2.0.34 and use Release over RelWithDebInfo (#9696) It turns out that having "-g" in the compile-statement causes Emscripten to pick -g3, which makes for very big binaries. This is very likely not your intention when building Emscripten, as smaller really is better. For comparison, with RelWithDebInfo the binary is ~80MB. With Release it is ~7.4MB. --- .github/workflows/preview_build.yml | 2 +- os/emscripten/Dockerfile | 2 +- os/emscripten/README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/preview_build.yml b/.github/workflows/preview_build.yml index 345a2152db..2a280a6fcd 100644 --- a/.github/workflows/preview_build.yml +++ b/.github/workflows/preview_build.yml @@ -76,7 +76,7 @@ jobs: echo "::group::CMake" emcmake cmake .. \ -DHOST_BINARY_DIR=../build-host \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_BUILD_TYPE=Release \ # EOF echo "::endgroup::" diff --git a/os/emscripten/Dockerfile b/os/emscripten/Dockerfile index cbbff38c15..5d54b54114 100644 --- a/os/emscripten/Dockerfile +++ b/os/emscripten/Dockerfile @@ -1,4 +1,4 @@ -FROM emscripten/emsdk:2.0.31 +FROM emscripten/emsdk:2.0.34 COPY emsdk-liblzma.patch / RUN cd /emsdk/upstream/emscripten && patch -p1 < /emsdk-liblzma.patch diff --git a/os/emscripten/README.md b/os/emscripten/README.md index 59f17c6269..c78dc6727b 100644 --- a/os/emscripten/README.md +++ b/os/emscripten/README.md @@ -24,7 +24,7 @@ Next, build the game with emscripten: ``` mkdir build - docker run -it --rm -v $(pwd):$(pwd) -u $(id -u):$(id -g) --workdir $(pwd)/build emsdk-lzma emcmake cmake .. -DHOST_BINARY_DIR=$(pwd)/build-host -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPTION_USE_ASSERTS=OFF + docker run -it --rm -v $(pwd):$(pwd) -u $(id -u):$(id -g) --workdir $(pwd)/build emsdk-lzma emcmake cmake .. -DHOST_BINARY_DIR=../build-host -DCMAKE_BUILD_TYPE=Release -DOPTION_USE_ASSERTS=OFF docker run -it --rm -v $(pwd):$(pwd) -u $(id -u):$(id -g) --workdir $(pwd)/build emsdk-lzma emmake make -j5 ``` From cf16f452da6d1cc8d4777ea4021d0c29b5679835 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 15 Nov 2021 13:39:41 +0000 Subject: [PATCH 04/10] Fix #9680: Recalculating aircraft positions before map array updates caused crashes (#9699) --- src/saveload/afterload.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index d3194cd4e2..bc8ffd2474 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -957,10 +957,6 @@ bool AfterLoadGame() } } - /* In version 2.2 of the savegame, we have new airports, so status of all aircraft is reset. - * This has to be called after the oilrig airport_type update above ^^^ ! */ - if (IsSavegameVersionBefore(SLV_2, 2)) UpdateOldAircraft(); - /* In version 6.1 we put the town index in the map-array. To do this, we need * to use m2 (16bit big), so we need to clean m2, and that is where this is * all about ;) */ @@ -2899,6 +2895,10 @@ bool AfterLoadGame() } } + /* In version 2.2 of the savegame, we have new airports, so status of all aircraft is reset. + * This has to be called after all map array updates */ + if (IsSavegameVersionBefore(SLV_2, 2)) UpdateOldAircraft(); + if (IsSavegameVersionBefore(SLV_188)) { /* Fix articulated road vehicles. * Some curves were shorter than other curves. From fc58ed9987a24785213a24c8c5d27f3b39c156ae Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 16 Nov 2021 22:48:21 +0000 Subject: [PATCH 05/10] Codechange: Remove CargoSpec::multipliertowngrowth which is unused (#9701) This is set by cargo property 19. This property is only implemented in TTDPatch. --- src/cargotype.h | 1 - src/newgrf.cpp | 2 +- src/table/cargo_const.h | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cargotype.h b/src/cargotype.h index 5ed9ac90e2..22c1bf7f54 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -66,7 +66,6 @@ struct CargoSpec { bool is_freight; ///< Cargo type is considered to be freight (affects train freight multiplier). TownEffect town_effect; ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies. - uint16 multipliertowngrowth; ///< Size of the effect. uint8 callback_mask; ///< Bitmask of cargo callbacks that have to be called StringID name; ///< Name of this type of cargo. diff --git a/src/newgrf.cpp b/src/newgrf.cpp index d1352d02e7..ef13e5545d 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3019,7 +3019,7 @@ static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, ByteRea } case 0x19: // Town growth coefficient - cs->multipliertowngrowth = buf->ReadWord(); + buf->ReadWord(); break; case 0x1A: // Bitmask of callbacks to use diff --git a/src/table/cargo_const.h b/src/table/cargo_const.h index bb6f811a92..8fffc8e804 100644 --- a/src/table/cargo_const.h +++ b/src/table/cargo_const.h @@ -44,7 +44,7 @@ * @param classes Classes of this cargo type. @see CargoClass */ #define MK(bt, label, colour, weight, mult, ip, td1, td2, freight, te, str_plural, str_singular, str_volume, classes) \ - {bt, label, colour, colour, weight, mult, ip, {td1, td2}, freight, te, 0, 0, \ + {bt, label, colour, colour, weight, mult, ip, {td1, td2}, freight, te, 0, \ MK_STR_CARGO_PLURAL(str_plural), MK_STR_CARGO_SINGULAR(str_singular), str_volume, MK_STR_QUANTITY(str_plural), MK_STR_ABBREV(str_plural), \ MK_SPRITE(str_plural), classes, nullptr, nullptr, 0} From f6886754ff99420dd4e02b541b94c213ad6f2052 Mon Sep 17 00:00:00 2001 From: translators Date: Thu, 18 Nov 2021 18:47:13 +0000 Subject: [PATCH 06/10] Update: Translations from eints greek: 2 changes by dionisis84 german: 2 changes by danidoedel --- src/lang/german.txt | 2 ++ src/lang/greek.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/lang/german.txt b/src/lang/german.txt index 3c18b22b23..8b1d81dba1 100644 --- a/src/lang/german.txt +++ b/src/lang/german.txt @@ -1744,6 +1744,8 @@ STR_CONFIG_SETTING_NEWS_ARRIVAL_FIRST_VEHICLE_OTHER_HELPTEXT :Zeitung anzeige STR_CONFIG_SETTING_NEWS_ACCIDENTS_DISASTERS :Unfälle und Katastrophen: {STRING} STR_CONFIG_SETTING_NEWS_ACCIDENTS_DISASTERS_HELPTEXT :Zeitung anzeigen, wenn Unfälle oder Katastrophen auftreten +STR_CONFIG_SETTING_NEWS_ACCIDENT_OTHER :Unfälle von Mitbewerberfahrzeugen: {STRING} +STR_CONFIG_SETTING_NEWS_ACCIDENT_OTHER_HELPTEXT :Zeitung anzeigen, wenn Fahrzeuge eines Mitbewerbers Unfälle haben STR_CONFIG_SETTING_NEWS_COMPANY_INFORMATION :Firmenmitteilungen: {STRING} STR_CONFIG_SETTING_NEWS_COMPANY_INFORMATION_HELPTEXT :Zeitung anzeigen, wenn neue Firmen gegründet werden oder kurz vor dem Bankrott stehen diff --git a/src/lang/greek.txt b/src/lang/greek.txt index 962ae84eb7..ca18521d53 100644 --- a/src/lang/greek.txt +++ b/src/lang/greek.txt @@ -1850,6 +1850,8 @@ STR_CONFIG_SETTING_NEWS_ARRIVAL_FIRST_VEHICLE_OTHER_HELPTEXT :Παρουσί STR_CONFIG_SETTING_NEWS_ACCIDENTS_DISASTERS :Ατυχήματα / καταστροφές: {STRING} STR_CONFIG_SETTING_NEWS_ACCIDENTS_DISASTERS_HELPTEXT :Προβάλλει εφημερίδα όταν συμβαίνουν ατυχήματα ή καταστροφές +STR_CONFIG_SETTING_NEWS_ACCIDENT_OTHER :Ατυχήματα των ανταγωνιστικών οχημάτων: {STRING} +STR_CONFIG_SETTING_NEWS_ACCIDENT_OTHER_HELPTEXT :Εμφάνιση εφημερίδας για τα διαλυμένα οχήματα για τους ανταγωνιστές STR_CONFIG_SETTING_NEWS_COMPANY_INFORMATION :Πληροφορίες εταιρίας: {STRING} STR_CONFIG_SETTING_NEWS_COMPANY_INFORMATION_HELPTEXT :Προβάλλει εφημερίδα όταν αρχίζει νέα εταιρεία ή όταν οι εταιρίες ρισκάρουν χρεωκοπία From 0533b666b7036750ed0b004f22f933625391dd8e Mon Sep 17 00:00:00 2001 From: Bernard Teo Date: Fri, 19 Nov 2021 08:03:52 +0800 Subject: [PATCH 07/10] Fix #9702: Display order window for vehicle group on ctrl-click only when using shared orders (#9704) --- src/group_gui.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/group_gui.cpp b/src/group_gui.cpp index bc6a9aaf2e..374ed5700d 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -746,17 +746,23 @@ public: NOT_REACHED(); } if (v) { - if (_ctrl_pressed) { - if (this->grouping == GB_NONE) { - this->SelectGroup(v->group_id); - } else { - ShowOrdersWindow(v); - } + if (_ctrl_pressed && this->grouping == GB_SHARED_ORDERS) { + ShowOrdersWindow(v); } else { this->vehicle_sel = v->index; + + if (_ctrl_pressed && this->grouping == GB_NONE) { + /* + * It only makes sense to select a group if not using shared orders + * since two vehicles sharing orders can be from different groups. + */ + this->SelectGroup(v->group_id); + } + SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this); SetMouseCursorVehicle(v, EIT_IN_LIST); _cursor.vehchain = true; + this->SetDirty(); } } From 2cb6351af596178ac3169baeffbc5a827f9aad5f Mon Sep 17 00:00:00 2001 From: nchappe <74881848+nchappe@users.noreply.github.com> Date: Fri, 19 Nov 2021 00:04:22 +0000 Subject: [PATCH 08/10] Fix: Update last servicing dates when using the date cheat (#9694) --- src/cheat_gui.cpp | 2 ++ src/date.cpp | 2 +- src/vehicle.cpp | 10 ++++++++++ src/vehicle_base.h | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 4821edbcc9..a0ac5fab8f 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -14,6 +14,7 @@ #include "company_func.h" #include "date_func.h" #include "saveload/saveload.h" +#include "vehicle_base.h" #include "textbuf_gui.h" #include "window_gui.h" #include "string_func.h" @@ -106,6 +107,7 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2) if (p1 == _cur_year) return _cur_year; Date new_date = ConvertYMDToDate(p1, ymd.month, ymd.day); + for (auto v : Vehicle::Iterate()) v->ShiftDates(new_date - _date); LinkGraphSchedule::instance.ShiftDates(new_date - _date); SetDate(new_date, _date_fract); EnginesMonthlyLoop(); diff --git a/src/date.cpp b/src/date.cpp index 0fd98c42b9..eac0c5f0ba 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -211,7 +211,7 @@ static void OnNewYear() _cur_year--; days_this_year = IsLeapYear(_cur_year) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR; _date -= days_this_year; - for (Vehicle *v : Vehicle::Iterate()) v->date_of_last_service -= days_this_year; + for (Vehicle *v : Vehicle::Iterate()) v->ShiftDates(-days_this_year); for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(-days_this_year); /* Because the _date wraps here, and text-messages expire by game-days, we have to clean out diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 9e22927512..30e1c477cb 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -763,6 +763,16 @@ uint32 Vehicle::GetGRFID() const return this->GetEngine()->GetGRFID(); } +/** + * Shift all dates by given interval. + * This is useful if the date has been modified with the cheat menu. + * @param interval Number of days to be added or substracted. + */ +void Vehicle::ShiftDates(int interval) +{ + this->date_of_last_service += interval; +} + /** * Handle the pathfinding result, especially the lost status. * If the vehicle is now lost and wasn't previously fire an diff --git a/src/vehicle_base.h b/src/vehicle_base.h index a5549b4441..12acaa8edf 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -545,6 +545,8 @@ public: */ virtual void OnNewDay() {}; + void ShiftDates(int interval); + /** * Crash the (whole) vehicle chain. * @param flooded whether the cause of the crash is flooding or not. From 54951e39a1f0395438180ba920aad88eea928f50 Mon Sep 17 00:00:00 2001 From: dP Date: Fri, 19 Nov 2021 03:07:22 +0300 Subject: [PATCH 09/10] Fix #8797: Use logical rail length when placing signals (#9652) --- src/rail_cmd.cpp | 188 ++++++++++++++++++++++++++------------------- src/vehicle_base.h | 5 +- 2 files changed, 113 insertions(+), 80 deletions(-) diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 59c1d27ab0..4c34f1ca86 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1209,8 +1209,11 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, return cost; } -static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal_ctr, bool remove) +static bool AdvanceSignalAutoFill(TileIndex &tile, Trackdir &trackdir, bool remove) { + /* We only process starting tiles of tunnels or bridges so jump to the other end before moving further. */ + if (IsTileType(tile, MP_TUNNELBRIDGE)) tile = GetOtherTunnelBridgeEnd(tile); + tile = AddTileIndexDiffCWrap(tile, _trackdelta[trackdir]); if (tile == INVALID_TILE) return false; @@ -1233,35 +1236,21 @@ static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal case MP_RAILWAY: if (IsRailDepot(tile)) return false; if (!remove && HasSignalOnTrack(tile, TrackdirToTrack(trackdir))) return false; - signal_ctr++; - if (IsDiagonalTrackdir(trackdir)) { - signal_ctr++; - /* Ensure signal_ctr even so X and Y pieces get signals */ - ClrBit(signal_ctr, 0); - } - return true; + break; case MP_ROAD: if (!IsLevelCrossing(tile)) return false; - signal_ctr += 2; - return true; + break; case MP_TUNNELBRIDGE: { - TileIndex orig_tile = tile; // backup old value - if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) return false; if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(trackdir)) return false; - - /* Skip to end of tunnel or bridge - * note that tile is a parameter by reference, so it must be updated */ - tile = GetOtherTunnelBridgeEnd(tile); - - signal_ctr += (GetTunnelBridgeLength(orig_tile, tile) + 2) * 2; - return true; + break; } default: return false; } + return true; } /** @@ -1292,7 +1281,7 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin bool remove = HasBit(p2, 5); bool autofill = HasBit(p2, 6); bool minimise_gaps = HasBit(p2, 10); - byte signal_density = GB(p2, 24, 8); + int signal_density = GB(p2, 24, 8); if (p1 >= MapSize() || !ValParamTrackOrientation(track)) return CMD_ERROR; TileIndex end_tile = p1; @@ -1300,9 +1289,8 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin if (!IsPlainRailTile(tile)) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK); - /* for vertical/horizontal tracks, double the given signals density - * since the original amount will be too dense (shorter tracks) */ - signal_density *= 2; + /* Interpret signal_density as the logical length of said amount of tiles in X/Y direction. */ + signal_density *= TILE_AXIAL_DISTANCE; Trackdir trackdir = TrackToTrackdir(track); CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile); @@ -1350,86 +1338,128 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin * and convert all others to semaphore/signal * remove - 1 remove signals, 0 build signals */ int signal_ctr = 0; - int last_used_ctr = INT_MIN; // initially INT_MIN to force building/removing at the first tile + int last_used_ctr = -signal_density; // to force signal at first tile int last_suitable_ctr = 0; TileIndex last_suitable_tile = INVALID_TILE; Trackdir last_suitable_trackdir = INVALID_TRACKDIR; CommandCost last_error = CMD_ERROR; bool had_success = false; - for (;;) { - /* only build/remove signals with the specified density */ - if (remove || minimise_gaps || signal_ctr % signal_density == 0) { - uint32 param1 = GB(TrackdirToTrack(trackdir), 0, 3); - SB(param1, 3, 1, mode); - SB(param1, 4, 1, semaphores); - SB(param1, 5, 3, sigtype); - if (!remove && signal_ctr == 0) SetBit(param1, 17); - - /* Pick the correct orientation for the track direction */ - signals = 0; - if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir); - if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir); - - /* Test tiles in between for suitability as well if minimising gaps. */ - bool test_only = !remove && minimise_gaps && signal_ctr < (last_used_ctr + signal_density); - CommandCost ret = DoCommand(tile, param1, signals, test_only ? flags & ~DC_EXEC : flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS); - - if (ret.Succeeded()) { - /* Remember last track piece where we can place a signal. */ - last_suitable_ctr = signal_ctr; - last_suitable_tile = tile; - last_suitable_trackdir = trackdir; - } else if (!test_only && last_suitable_tile != INVALID_TILE) { - /* If a signal can't be placed, place it at the last possible position. */ - SB(param1, 0, 3, TrackdirToTrack(last_suitable_trackdir)); - ClrBit(param1, 17); - - /* Pick the correct orientation for the track direction. */ - signals = 0; - if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(last_suitable_trackdir); - if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(last_suitable_trackdir); - - ret = DoCommand(last_suitable_tile, param1, signals, flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS); + uint32 param1 = 0; + SB(param1, 3, 1, mode); + SB(param1, 4, 1, semaphores); + SB(param1, 5, 3, sigtype); + + auto build_signal = [&](TileIndex tile, Trackdir trackdir, bool test_only) { + SB(param1, 0, 3, TrackdirToTrack(trackdir)); + SB(param1, 17, 1, (!remove && signal_ctr == 0 ? 1 : 0)); + + /* Pick the correct orientation for the track direction */ + byte signals = 0; + if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir); + if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir); + + CommandCost ret = DoCommand(tile, param1, signals, test_only ? flags & ~DC_EXEC : flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS); + + if (test_only) return ret.Succeeded(); + + if (ret.Succeeded()) { + had_success = true; + total_cost.AddCost(ret); + } else { + /* The "No railway" error is the least important one. */ + if (ret.GetErrorMessage() != STR_ERROR_THERE_IS_NO_RAILROAD_TRACK || + last_error.GetErrorMessage() == INVALID_STRING_ID) { + last_error = ret; } + } + return ret.Succeeded(); + }; - /* Collect cost. */ - if (!test_only) { - /* Be user-friendly and try placing signals as much as possible */ - if (ret.Succeeded()) { - had_success = true; - total_cost.AddCost(ret); + for (;;) { + if (remove) { + /* In remove mode last_* stuff doesn't matter, we simply try to clear every tile. */ + build_signal(tile, trackdir, false); + } else if (minimise_gaps) { + /* We're trying to minimize gaps wherever possible, so keep track of last suitable + * position and use it if current gap exceeds required signal density. */ + + if (signal_ctr > last_used_ctr + signal_density && last_suitable_tile != INVALID_TILE) { + /* We overshot so build a signal in last good location. */ + if (build_signal(last_suitable_tile, last_suitable_trackdir, false)) { + last_suitable_tile = INVALID_TILE; last_used_ctr = last_suitable_ctr; + } + } + + if (signal_ctr == last_used_ctr + signal_density) { + /* Current gap matches the required density, build a signal. */ + if (build_signal(tile, trackdir, false)) { + last_used_ctr = signal_ctr; last_suitable_tile = INVALID_TILE; - } else { - /* The "No railway" error is the least important one. */ - if (ret.GetErrorMessage() != STR_ERROR_THERE_IS_NO_RAILROAD_TRACK || - last_error.GetErrorMessage() == INVALID_STRING_ID) { - last_error = ret; - } + } + } else { + /* Test tile for a potential signal spot. */ + if (build_signal(tile, trackdir, true)) { + last_suitable_tile = tile; + last_suitable_ctr = signal_ctr; + last_suitable_trackdir = trackdir; } } + } else if(signal_ctr >= last_used_ctr + signal_density) { + /* We're always keeping regular interval between signals so doesn't matter whether we succeed or not. */ + build_signal(tile, trackdir, false); + last_used_ctr = signal_ctr; } if (autofill) { - if (!CheckSignalAutoFill(tile, trackdir, signal_ctr, remove)) break; + switch (GetTileType(tile)) { + case MP_RAILWAY: + signal_ctr += (IsDiagonalTrackdir(trackdir) ? TILE_AXIAL_DISTANCE : TILE_CORNER_DISTANCE); + break; + + case MP_ROAD: + signal_ctr += TILE_AXIAL_DISTANCE; + break; + + case MP_TUNNELBRIDGE: { + uint len = (GetTunnelBridgeLength(tile, GetOtherTunnelBridgeEnd(tile)) + 2) * TILE_AXIAL_DISTANCE; + if (remove || minimise_gaps) { + signal_ctr += len; + } else { + /* To keep regular interval we need to emulate placing signals on a bridge. + * We start with TILE_AXIAL_DISTANCE as one bridge tile gets processed in the main loop. */ + signal_ctr += TILE_AXIAL_DISTANCE; + for(uint i = TILE_AXIAL_DISTANCE; i < len; i += TILE_AXIAL_DISTANCE) { + if (signal_ctr >= last_used_ctr + signal_density) last_used_ctr = signal_ctr; + signal_ctr += TILE_AXIAL_DISTANCE; + } + } + break; + } + + default: break; + } + + if (!AdvanceSignalAutoFill(tile, trackdir, remove)) break; /* Prevent possible loops */ if (tile == start_tile && trackdir == start_trackdir) break; } else { if (tile == end_tile) break; - tile += ToTileIndexDiff(_trackdelta[trackdir]); - signal_ctr++; - + signal_ctr += (IsDiagonalTrackdir(trackdir) ? TILE_AXIAL_DISTANCE : TILE_CORNER_DISTANCE); /* toggle railbit for the non-diagonal tracks (|, -- tracks) */ - if (IsDiagonalTrackdir(trackdir)) { - signal_ctr++; - } else { - ToggleBit(trackdir, 0); - } + + tile += ToTileIndexDiff(_trackdelta[trackdir]); + if (!IsDiagonalTrackdir(trackdir)) ToggleBit(trackdir, 0); } } + /* We may end up with the current gap exceeding the signal density so fix that if needed. */ + if (!remove && minimise_gaps && signal_ctr > last_used_ctr + signal_density && last_suitable_tile != INVALID_TILE) { + build_signal(last_suitable_tile, last_suitable_trackdir, false); + } + return had_success ? total_cost : last_error; } diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 12acaa8edf..a5ab42989c 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -26,6 +26,9 @@ #include #include +const uint TILE_AXIAL_DISTANCE = 192; // Logical length of the tile in any DiagDirection used in vehicle movement. +const uint TILE_CORNER_DISTANCE = 128; // Logical length of the tile corner crossing in any non-diagonal direction used in vehicle movement. + /** Vehicle status bits in #Vehicle::vehstatus. */ enum VehStatus { VS_HIDDEN = 0x01, ///< Vehicle is not visible. @@ -426,7 +429,7 @@ public: */ inline uint GetAdvanceDistance() { - return (this->direction & 1) ? 192 : 256; + return (this->direction & 1) ? TILE_AXIAL_DISTANCE : TILE_CORNER_DISTANCE * 2; } /** From ad90e88ebdfcacead53c9af40e75cb0ab37e3b00 Mon Sep 17 00:00:00 2001 From: dP Date: Fri, 19 Nov 2021 03:08:06 +0300 Subject: [PATCH 10/10] Change: Make pf.yapf.rail_firstred_twoway_eol on by default (#9544) --- src/table/settings/pathfinding_settings.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/table/settings/pathfinding_settings.ini b/src/table/settings/pathfinding_settings.ini index 322090001a..ac0a428371 100644 --- a/src/table/settings/pathfinding_settings.ini +++ b/src/table/settings/pathfinding_settings.ini @@ -334,7 +334,7 @@ cat = SC_EXPERT [SDT_BOOL] var = pf.yapf.rail_firstred_twoway_eol from = SLV_28 -def = false +def = true cat = SC_EXPERT [SDT_VAR]