From 49ab02c084c0f69efdf4bbe286ce3662d1eafe86 Mon Sep 17 00:00:00 2001 From: translators Date: Fri, 4 Jan 2019 19:45:45 +0100 Subject: [PATCH 01/22] Update: Translations from eints spanish: 4 changes by SilverSurferZzZ --- src/lang/spanish.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lang/spanish.txt b/src/lang/spanish.txt index fb702b0fba..43f9d57b19 100644 --- a/src/lang/spanish.txt +++ b/src/lang/spanish.txt @@ -2710,6 +2710,10 @@ STR_FRAMERATE_FPS_BAD :{RED}{DECIMAL} STR_FRAMERATE_GRAPH_MILLISECONDS :{TINY_FONT}{COMMA} ms STR_FRAMERATE_GRAPH_SECONDS :{TINY_FONT}{COMMA} s ############ Leave those lines in this order!! +STR_FRAMERATE_GL_TRAINS :{BLACK} Ticks de trenes: +STR_FRAMERATE_GL_ROADVEHS :{BLACK} Ticks de vehículos de carretera: +STR_FRAMERATE_GL_SHIPS :{BLACK} Ticks de barcos: +STR_FRAMERATE_GL_AIRCRAFT :{BLACK} Ticks de aeronaves: STR_FRAMERATE_DRAWING :{BLACK}Renderizado gráfico: ############ End of leave-in-this-order ############ Leave those lines in this order!! From 16a91130a791de4b219c387c7aeccd15f14ea26f Mon Sep 17 00:00:00 2001 From: J0an Josep Date: Wed, 25 Jul 2018 18:53:58 +0200 Subject: [PATCH 02/22] Codechange: Use INVALID_TRACKDIR instead of 0xFF. --- src/pathfinder/npf/npf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index 3218d8314f..bc4d8b3099 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -1169,7 +1169,7 @@ Track NPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, * we did not find our target, but ftd.best_trackdir contains the direction leading * to the tile closest to our target. */ path_found = (ftd.best_bird_dist == 0); - if (ftd.best_trackdir == 0xff) return INVALID_TRACK; + if (ftd.best_trackdir == INVALID_TRACKDIR) return INVALID_TRACK; return TrackdirToTrack(ftd.best_trackdir); } From 9e30054de9de1b826137279d333648ca09217ef7 Mon Sep 17 00:00:00 2001 From: Juanjo Date: Fri, 18 Oct 2013 18:52:01 +0000 Subject: [PATCH 03/22] Codechange: Use window class as expected. --- src/window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.cpp b/src/window.cpp index 5b9dad6777..22084c200e 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1741,7 +1741,7 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int int16 default_width = max(desc->GetDefaultWidth(), sm_width); int16 default_height = max(desc->GetDefaultHeight(), sm_height); - if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ && (w = FindWindowById(desc->parent_cls, window_number)) != NULL) { + if (desc->parent_cls != WC_NONE && (w = FindWindowById(desc->parent_cls, window_number)) != NULL) { bool rtl = _current_text_dir == TD_RTL; if (desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) { pt.x = w->left + (rtl ? w->width - default_width : 0); From 0aa69693c69849498ac70b14b8bfc9c5ab1ee449 Mon Sep 17 00:00:00 2001 From: glx Date: Thu, 27 Dec 2018 22:34:00 +0100 Subject: [PATCH 04/22] Fix 59e42ea17, 1f083c3ac: 'make clean' was not fully cleaning --- Makefile.lang.in | 2 +- Makefile.setting.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.lang.in b/Makefile.lang.in index 7ce331913d..2853ae3898 100644 --- a/Makefile.lang.in +++ b/Makefile.lang.in @@ -78,7 +78,7 @@ depend: clean: $(E) '$(STAGE) Cleaning up language files' - $(Q)rm -f strgen.o string.o alloc_func.o getoptdata.o table/strings.h $(STRGEN) $(LANGS) $(LANGS:%=$(BIN_DIR)/lang/%) lang/english.* + $(Q)rm -f strgen_base.o strgen.o string.o alloc_func.o getoptdata.o table/strings.h $(STRGEN) $(LANGS) $(LANGS:%=$(BIN_DIR)/lang/%) lang/english.* mrproper: clean $(Q)rm -rf $(BIN_DIR)/lang diff --git a/Makefile.setting.in b/Makefile.setting.in index 656de05723..1e2dc992f8 100644 --- a/Makefile.setting.in +++ b/Makefile.setting.in @@ -58,7 +58,7 @@ depend: clean: $(E) '$(STAGE) Cleaning up settings files' - $(Q)rm -f settingsgen.o alloc_func.o getoptdata.o ini_load.o $(SETTINGSGEN) table/settings.h + $(Q)rm -f settingsgen.o alloc_func.o getoptdata.o string.o ini_load.o $(SETTINGSGEN) table/settings.h mrproper: clean From 12ba56c5a3173054ac25899bef481f4801d5b6e8 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sat, 5 Jan 2019 14:13:38 +0100 Subject: [PATCH 05/22] Fix 6accbf9: Silence warnings about unused fread() result --- src/script/squirrel.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index d11e85bee8..23163f6b34 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -449,7 +449,8 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printer } unsigned short bom = 0; if (size >= 2) { - fread(&bom, 1, sizeof(bom), file); // Inside tar, no point checking return value of fread + size_t sr = fread(&bom, 1, sizeof(bom), file); + (void)sr; // Inside tar, no point checking return value of fread } SQLEXREADFUNC func; @@ -487,8 +488,7 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printer return sq_throwerror(vm, "I/O error"); } unsigned char uc; - fread(&uc, 1, sizeof(uc), file); - if (uc != 0xBF) { + if (fread(&uc, 1, sizeof(uc), file) != sizeof(uc) || uc != 0xBF) { FioFCloseFile(file); return sq_throwerror(vm, "Unrecognized encoding"); } From d6c06de5ad8f36c74eacba46e48a482c5c5c69b7 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 4 Nov 2018 12:58:42 +0100 Subject: [PATCH 06/22] Add: Mixer feature for streaming sampled music --- src/mixer.cpp | 17 +++++++++++++++++ src/mixer.h | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/mixer.cpp b/src/mixer.cpp index 6aaa8204d4..6014f6082e 100644 --- a/src/mixer.cpp +++ b/src/mixer.cpp @@ -15,6 +15,7 @@ #include "framerate_type.h" #include "safeguards.h" +#include "mixer.h" struct MixerChannel { bool active; @@ -38,6 +39,7 @@ struct MixerChannel { static MixerChannel _channels[8]; static uint32 _play_rate = 11025; static uint32 _max_size = UINT_MAX; +static MxStreamCallback _music_stream = NULL; /** * The theoretical maximum volume for a single sound sample. Multiple sound @@ -151,6 +153,9 @@ void MxMixSamples(void *buffer, uint samples) /* Clear the buffer */ memset(buffer, 0, sizeof(int16) * 2 * samples); + /* Fetch music if a sampled stream is available */ + if (_music_stream) _music_stream((int16*)buffer, samples); + /* Mix each channel */ for (mc = _channels; mc != endof(_channels); mc++) { if (mc->active) { @@ -215,6 +220,17 @@ void MxSetChannelVolume(MixerChannel *mc, uint volume, float pan) void MxActivateChannel(MixerChannel *mc) { mc->active = true; +} + +/** + * Set source of PCM music + * @param music_callback Function that will be called to fill sample buffers with music data. + * @return Sample rate of mixer, which the buffers supplied to the callback must be rendered at. + */ +uint32 MxSetMusicSource(MxStreamCallback music_callback) +{ + _music_stream = music_callback; + return _play_rate; } @@ -222,5 +238,6 @@ bool MxInitialize(uint rate) { _play_rate = rate; _max_size = UINT_MAX / _play_rate; + _music_stream = NULL; /* rate may have changed, any music source is now invalid */ return true; } diff --git a/src/mixer.h b/src/mixer.h index 0ccee61092..9766682d6b 100644 --- a/src/mixer.h +++ b/src/mixer.h @@ -14,6 +14,14 @@ struct MixerChannel; +/** + * Type of callback functions for supplying PCM music. + * A music decoder/renderer implements this function and installs it with MxSetMusicSource, which also returns the sample rate used. + * @param buffer Pointer to interleaved 2-channel signed 16 bit PCM data buffer, guaranteed to be 0-initialized. + * @param samples number of samples that must be filled into \c buffer. + */ +typedef void(*MxStreamCallback)(int16 *buffer, size_t samples); + bool MxInitialize(uint rate); void MxMixSamples(void *buffer, uint samples); @@ -22,4 +30,6 @@ void MxSetChannelRawSrc(MixerChannel *mc, int8 *mem, size_t size, uint rate, boo void MxSetChannelVolume(MixerChannel *mc, uint volume, float pan); void MxActivateChannel(MixerChannel*); +uint32 MxSetMusicSource(MxStreamCallback music_callback); + #endif /* MIXER_H */ From cb60a5e57fb7013b330041d428c53ba7f97e4f92 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sat, 5 Jan 2019 12:33:13 +0100 Subject: [PATCH 07/22] Change: Fluidsynth music driver plays through mixer instead of own audio driver --- src/music/fluidsynth.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/music/fluidsynth.cpp b/src/music/fluidsynth.cpp index 63be1dd99c..d1088f4bc4 100644 --- a/src/music/fluidsynth.cpp +++ b/src/music/fluidsynth.cpp @@ -16,11 +16,11 @@ #include "fluidsynth.h" #include "midifile.hpp" #include +#include "../mixer.h" static struct { fluid_settings_t* settings; ///< FluidSynth settings handle fluid_synth_t* synth; ///< FluidSynth synthesizer handle - fluid_audio_driver_t* adriver; ///< FluidSynth audio driver handle fluid_player_t* player; ///< FluidSynth MIDI player handle } _midi; ///< Metadata about the midi we're playing. @@ -42,33 +42,27 @@ static const char *default_sf[] = { NULL }; +static void RenderMusicStream(int16 *buffer, size_t samples) +{ + if (!_midi.synth || !_midi.player) return; + fluid_synth_write_s16(_midi.synth, samples, buffer, 0, 2, buffer, 1, 2); +} + const char *MusicDriver_FluidSynth::Start(const char * const *param) { - const char *driver_name = GetDriverParam(param, "driver"); const char *sfont_name = GetDriverParam(param, "soundfont"); int sfont_id; - if (!driver_name) driver_name = "alsa"; - - DEBUG(driver, 1, "Fluidsynth: driver %s, sf %s", driver_name, sfont_name); + DEBUG(driver, 1, "Fluidsynth: sf %s", sfont_name); /* Create the settings. */ _midi.settings = new_fluid_settings(); if (!_midi.settings) return "Could not create midi settings"; - if (fluid_settings_setstr(_midi.settings, "audio.driver", driver_name) != 1) { - return "Could not set audio driver name"; - } - /* Create the synthesizer. */ _midi.synth = new_fluid_synth(_midi.settings); if (!_midi.synth) return "Could not open synth"; - /* Create the audio driver. The synthesizer starts playing as soon - as the driver is created. */ - _midi.adriver = new_fluid_audio_driver(_midi.settings, _midi.synth); - if (!_midi.adriver) return "Could not open audio driver"; - /* Load a SoundFont and reset presets (so that new instruments * get used from the SoundFont) */ if (!sfont_name) { @@ -87,13 +81,17 @@ const char *MusicDriver_FluidSynth::Start(const char * const *param) _midi.player = NULL; + uint32 samplerate = MxSetMusicSource(RenderMusicStream); + fluid_synth_set_sample_rate(_midi.synth, samplerate); + DEBUG(driver, 1, "Fluidsynth: samplerate %.0f", (float)samplerate); + return NULL; } void MusicDriver_FluidSynth::Stop() { + MxSetMusicSource(NULL); this->StopSong(); - delete_fluid_audio_driver(_midi.adriver); delete_fluid_synth(_midi.synth); delete_fluid_settings(_midi.settings); } From b8b6954fb58aac07d05dabe63918f0392c5672d1 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sat, 5 Jan 2019 14:30:59 +0100 Subject: [PATCH 08/22] Fix 6a3d411: Silence truncation warning --- src/tunnelbridge_cmd.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 297a01d30a..06dc24e84f 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -701,10 +701,11 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, */ assert(coa >= _cleared_object_areas.Begin() && coa < _cleared_object_areas.End()); size_t coa_index = coa - _cleared_object_areas.Begin(); + assert(coa_index < UINT_MAX); // more than 2**32 cleared areas would be a bug in itself coa = NULL; ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND); - _cleared_object_areas[coa_index].first_tile = old_first_tile; + _cleared_object_areas[(uint)coa_index].first_tile = old_first_tile; if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND); cost.AddCost(ret); } From 0e7af55ef704757dfee40c1799359df01b937ebb Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 24 Sep 2018 22:17:55 +0100 Subject: [PATCH 09/22] Fix: [OSX] Check all search paths for iconv.h --- config.lib | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/config.lib b/config.lib index 894a22c176..2d2f864d76 100644 --- a/config.lib +++ b/config.lib @@ -2927,10 +2927,16 @@ detect_iconv() { # Try to find iconv.h, seems to only thing to detect iconv with if [ "$with_iconv" = "1" ] || [ "$with_iconv" = "" ] || [ "$with_iconv" = "2" ]; then - iconv=`ls -1 /usr/include 2>/dev/null | grep "iconv.h"` - if [ -z "$iconv" ]; then - iconv=`ls -1 /usr/local/include 2>/dev/null | grep "iconv.h"` - fi + # Iterate over search paths + iconv="" + search_paths=`LC_ALL=C $cxx_host $OSX_SYSROOT $CFLAGS -E - -v &1 | \ + $awk '/#include <...> search starts here:/{flag=1;next}/End of search list./{flag=0}flag'` + for path in $search_paths; do + iconv=`ls -1 $path 2>/dev/null | grep "iconv.h"` + if [ -n "$iconv" ]; then + break + fi + done else # Make sure it exists iconv=`ls $with_iconv/include/iconv.h 2>/dev/null` From 175829b8b5a24efaa46e18d2a0d0b1f59d14e72d Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 24 Sep 2018 22:18:58 +0100 Subject: [PATCH 10/22] Fix #6880: [OSX] Clang version detection --- config.lib | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.lib b/config.lib index 2d2f864d76..c5b7ee09c4 100644 --- a/config.lib +++ b/config.lib @@ -1331,7 +1331,8 @@ make_compiler_cflags() { fi elif echo "$version_line" | grep -q "clang"; then # Enable some things only for certain clang versions - cc_version="`$1 -v 2>&1 | head -n 1 | sed s@[^0-9]@@g | cut -c 1-2`" + # Need to try really hard to get the version line, because OSX clang likes to hide its true version + cc_version="`$1 -v 2>&1 | grep -i version | head -n 1 | sed s@[^0-9]@@g | cut -c 1-2`" # aliasing rules are not held in openttd code flags="$flags -fno-strict-aliasing" From 4fbfe34e3697b4275212d9e569d05af398552fda Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 25 Nov 2018 11:27:08 +0000 Subject: [PATCH 11/22] Codechange: Always compile with C++11 --- config.lib | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/config.lib b/config.lib index c5b7ee09c4..1af354e163 100644 --- a/config.lib +++ b/config.lib @@ -1317,8 +1317,6 @@ make_compiler_cflags() { if [ $cc_version -ge 110 ]; then # remark #2259: non-pointer conversion from ... to ... may lose significant bits flags="$flags -wd2259" - # Use c++0x mode so static_assert() is available - cxxflags="$cxxflags -std=c++0x" fi if [ "$enable_lto" != "0" ]; then @@ -1380,11 +1378,6 @@ make_compiler_cflags() { flags="$flags -Wno-unused-variable" fi - if [ "$cc_version" -ge "33" ]; then - # clang completed C++11 support in version 3.3 - flags="$flags -std=c++11" - fi - # rdynamic is used to get useful stack traces from crash reports. ldflags="$ldflags -rdynamic" @@ -1443,12 +1436,6 @@ make_compiler_cflags() { flags="$flags -Wnon-virtual-dtor" fi - if [ $cc_version -ge 403 ] && [ $cc_version -lt 600 ]; then - # Use gnu++0x mode so static_assert() is available. - # Don't use c++0x, it breaks mingw (with gcc 4.4.0). - cxxflags="$cxxflags -std=gnu++0x" - fi - if [ $cc_version -eq 405 ]; then # Prevent optimisation supposing enums are in a range specified by the standard # For details, see http://gcc.gnu.org/PR43680 @@ -1470,7 +1457,7 @@ make_compiler_cflags() { if [ $cc_version -ge 600 ]; then # -flifetime-dse=2 (default since GCC 6) doesn't play # well with our custom pool item allocator - cxxflags="$cxxflags -flifetime-dse=1 -std=gnu++14" + cxxflags="$cxxflags -flifetime-dse=1" fi if [ "$enable_lto" != "0" ]; then @@ -1533,6 +1520,8 @@ make_cflags_and_ldflags() { CFLAGS="$CFLAGS -D$os" CFLAGS_BUILD="$CFLAGS_BUILD -D$os" + CXXFLAGS="$CXXFLAGS -std=c++11" + CXXFLAGS_BUILD="$CXXFLAGS_BUILD -std=c++11" if [ "$enable_debug" = "0" ]; then # No debug, add default stuff From 92d3358db551ac9d98064219ec64404a74764ce2 Mon Sep 17 00:00:00 2001 From: glx Date: Mon, 31 Dec 2018 00:00:29 +0100 Subject: [PATCH 12/22] Fix: [Win32] don't mess with std[out|err|in] if we can't allocate a console --- src/os/windows/win32.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index d2540ac345..bb1a0a4209 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -300,7 +300,7 @@ void CreateConsole() if (_has_console) return; _has_console = true; - AllocConsole(); + if (!AllocConsole()) return; hand = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hand, &coninfo); From 7b5e7aa14fa250b93c603abd03dab6e4023b2045 Mon Sep 17 00:00:00 2001 From: glx Date: Mon, 31 Dec 2018 01:05:19 +0100 Subject: [PATCH 13/22] Add: [Win32] regression test script --- bin/ai/regression/run.vbs | 154 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 bin/ai/regression/run.vbs diff --git a/bin/ai/regression/run.vbs b/bin/ai/regression/run.vbs new file mode 100644 index 0000000000..88cea5c4eb --- /dev/null +++ b/bin/ai/regression/run.vbs @@ -0,0 +1,154 @@ +Option Explicit + +' $Id$ +' +' This file is part of OpenTTD. +' OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. +' OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +' See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + +Dim FSO +Set FSO = CreateObject("Scripting.FileSystemObject") + +Function GetTestList() + Dim retests, i, tests, dir + Set retests = New RegExp + Set GetTestList = CreateObject("Scripting.Dictionary") + + retests.Pattern = "ai/regression/tst_*" + retests.Global = True + For i = 0 To WScript.Arguments.Count - 1 + Dim test + test = "ai/regression/tst_" & WScript.Arguments.Item(i) + If FSO.FolderExists(test) Then + retests.Pattern = test + Exit For + End If + Next + + For Each dir In FSO.GetFolder("ai/regression/").SubFolders + Dim name + name = "ai/regression/" & dir.Name + If retests.Test(name) Then + GetTestList.Add name, name + End If + Next +End Function + +Function GetParams() + GetParams = "-snull -mnull -vnull:ticks=30000" + If WScript.Arguments.Count = 0 Then Exit Function + If WScript.Arguments.Item(0) <> "-r" Then Exit Function + GetParams = "" +End Function + +Sub FilterFile(filename) + Dim lines, filter, file + + Set file = FSO.OpenTextFile(filename, 1) + If Not file.AtEndOfStream Then + lines = file.ReadAll + End If + file.Close + + Set filter = New RegExp + filter.Global = True + filter.Multiline = True + filter.Pattern = "0x(\(nil\)|0+)(x0)?" + lines = filter.Replace(lines, "0x00000000") + filter.Pattern = "^dbg: \[script\]" + lines = filter.Replace(lines, "") + filter.Pattern = "^ " + lines = filter.Replace(lines, "ERROR: ") + filter.Pattern = "ERROR: \[1\] \[P\] " + lines = filter.Replace(lines, "") + filter.Pattern = "^dbg: .*\r\n" + lines = filter.Replace(lines, "") + + Set file = FSO.OpenTextFile(filename, 2) + file.Write lines + file.Close +End Sub + +Function CompareFiles(filename1, filename2) + Dim file, lines1, lines2 + Set file = FSO.OpenTextFile(filename1, 1) + If Not file.AtEndOfStream Then + lines1 = file.ReadAll + End IF + file.Close + Set file = FSO.OpenTextFile(filename2, 1) + If Not file.AtEndOfStream Then + lines2 = file.ReadAll + End IF + file.Close + CompareFiles = (lines1 = lines2) +End Function + +Function RunTest(test, params, ret) + Dim WshShell, oExec, sav, command + Set WshShell = CreateObject("WScript.Shell") + + ' Make sure that only one info.nut is present for each test run. Otherwise openttd gets confused. + FSO.CopyFile "ai/regression/regression_info.nut", test & "/info.nut" + + sav = test & "/test.sav" + If Not FSO.FileExists(sav) Then + sav = "ai/regression/empty.sav" + End If + + command = ".\openttd -x -c ai/regression/regression.cfg " & params & " -g " & sav & " -d script=2 -d misc=9" + ' 2>&1 must be after >tmp.regression, else stderr is not redirected to the file + WshShell.Run "cmd /c " & command & " >tmp.regression 2>&1", 0, True + + FilterFile "tmp.regression" + + If CompareFiles(test & "/result.txt", "tmp.regression") Then + RunTest = "passed!" + Else + RunTest = "failed!" + ret = 1 + End If + + FSO.DeleteFile test & "/info.nut" +End Function + +On Error Resume Next +WScript.StdOut.WriteLine "" +If Err.Number <> 0 Then + WScript.Echo "This script must be started with cscript." + WScript.Quit 1 +End If +On Error Goto 0 + +If Not FSO.FileExists("ai/regression/run.vbs") Then + WScript.Echo "Make sure you are in the root of OpenTTD before starting this script." + WScript.Quit 1 +End If + +If FSO.FileExists("scripts/game_start.scr") Then + FSO.MoveFile "scripts/game_start.scr", "scripts/game_start.scr.regression" +End If + +Dim params, test, ret +params = GetParams() +ret = 0 + +For Each test in GetTestList() + WScript.StdOut.Write "Running " & test & "... " + WScript.StdOut.WriteLine RunTest(test, params, ret) +Next + +If FSO.FileExists("scripts/game_start.scr.regression") Then + FSO.MoveFile "scripts/game_start.scr.regression", "scripts/game_start.scr" +End If + +If WScript.Arguments.Count > 0 Then + If WScripts.Arguments.Items(0) = "-k" Then + WScript.Quit ret + End If +End If + +FSO.DeleteFile "tmp.regression" + +WScript.Quit ret From c0a655225d29d96d355e94b34512da5bffcf12f9 Mon Sep 17 00:00:00 2001 From: glx Date: Mon, 31 Dec 2018 01:06:28 +0100 Subject: [PATCH 14/22] Add: [Win32] regression project files --- projects/openttd_vs140.sln | 6 +++++ projects/openttd_vs141.sln | 6 +++++ projects/regression.bat | 6 +++++ projects/regression_vs140.vcxproj | 41 +++++++++++++++++++++++++++++++ projects/regression_vs141.vcxproj | 41 +++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 projects/regression.bat create mode 100644 projects/regression_vs140.vcxproj create mode 100644 projects/regression_vs141.vcxproj diff --git a/projects/openttd_vs140.sln b/projects/openttd_vs140.sln index d256cfa495..32f3033fb2 100644 --- a/projects/openttd_vs140.sln +++ b/projects/openttd_vs140.sln @@ -24,6 +24,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "settings", "settings_vs140. EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "settingsgen", "settingsgen_vs140.vcxproj", "{E9548DE9-F089-49B7-93A6-30BE2CC311C7}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "regression", "regression_vs140.vcxproj", "{4712B013-437D-42CE-947F-DEBABA15261F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -84,6 +86,10 @@ Global {E9548DE9-F089-49B7-93A6-30BE2CC311C7}.Release|Win32.Build.0 = Debug|Win32 {E9548DE9-F089-49B7-93A6-30BE2CC311C7}.Release|x64.ActiveCfg = Debug|Win32 {E9548DE9-F089-49B7-93A6-30BE2CC311C7}.Release|x64.Build.0 = Debug|Win32 + {4712B013-437D-42CE-947F-DEBABA15261F}.Debug|Win32.ActiveCfg = Debug|Win32 + {4712B013-437D-42CE-947F-DEBABA15261F}.Debug|x64.ActiveCfg = Debug|Win32 + {4712B013-437D-42CE-947F-DEBABA15261F}.Release|Win32.ActiveCfg = Debug|Win32 + {4712B013-437D-42CE-947F-DEBABA15261F}.Release|x64.ActiveCfg = Debug|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/projects/openttd_vs141.sln b/projects/openttd_vs141.sln index e314c628a7..86f2685cd9 100644 --- a/projects/openttd_vs141.sln +++ b/projects/openttd_vs141.sln @@ -24,6 +24,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "settings", "settings_vs141. EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "settingsgen", "settingsgen_vs141.vcxproj", "{E9548DE9-F089-49B7-93A6-30BE2CC311C7}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "regression", "regression_vs141.vcxproj", "{4712B013-437D-42CE-947F-DEBABA15261F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -84,6 +86,10 @@ Global {E9548DE9-F089-49B7-93A6-30BE2CC311C7}.Release|Win32.Build.0 = Debug|Win32 {E9548DE9-F089-49B7-93A6-30BE2CC311C7}.Release|x64.ActiveCfg = Debug|Win32 {E9548DE9-F089-49B7-93A6-30BE2CC311C7}.Release|x64.Build.0 = Debug|Win32 + {4712B013-437D-42CE-947F-DEBABA15261F}.Debug|Win32.ActiveCfg = Debug|Win32 + {4712B013-437D-42CE-947F-DEBABA15261F}.Debug|x64.ActiveCfg = Debug|Win32 + {4712B013-437D-42CE-947F-DEBABA15261F}.Release|Win32.ActiveCfg = Debug|Win32 + {4712B013-437D-42CE-947F-DEBABA15261F}.Release|x64.ActiveCfg = Debug|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/projects/regression.bat b/projects/regression.bat new file mode 100644 index 0000000000..db373c371b --- /dev/null +++ b/projects/regression.bat @@ -0,0 +1,6 @@ +cd ..\bin +editbin /nologo /subsystem:console openttd.exe +cscript /nologo ai\regression\run.vbs +set RESULT=%ERRORLEVEL% +editbin /nologo /subsystem:windows openttd.exe +exit %RESULT% diff --git a/projects/regression_vs140.vcxproj b/projects/regression_vs140.vcxproj new file mode 100644 index 0000000000..b1c9f4930a --- /dev/null +++ b/projects/regression_vs140.vcxproj @@ -0,0 +1,41 @@ + + + + + Debug + Win32 + + + + {4712B013-437D-42CE-947F-DEBABA15261F} + regression + regression + + + + Makefile + v140 + + + + + + + + + + + + call regression.bat + call regression.bat + del ..\bin\tmp.regression + + + + {668328a0-b40e-4cdb-bd72-d0064424414a} + + + + + + diff --git a/projects/regression_vs141.vcxproj b/projects/regression_vs141.vcxproj new file mode 100644 index 0000000000..fda3f3312d --- /dev/null +++ b/projects/regression_vs141.vcxproj @@ -0,0 +1,41 @@ + + + + + Debug + Win32 + + + + {4712B013-437D-42CE-947F-DEBABA15261F} + regression + regression + + + + Makefile + v141 + + + + + + + + + + + + call regression.bat + call regression.bat + del ..\bin\tmp.regression + + + + {668328a0-b40e-4cdb-bd72-d0064424414a} + + + + + + From 96b961c69a7be052b9104994b73801b32b5e1c41 Mon Sep 17 00:00:00 2001 From: glx Date: Mon, 31 Dec 2018 17:25:08 +0100 Subject: [PATCH 15/22] Add: [AzurePipelines] run regression with MSVC --- azure-pipelines-ci.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/azure-pipelines-ci.yml b/azure-pipelines-ci.yml index ea7f355141..e71ab60ea4 100644 --- a/azure-pipelines-ci.yml +++ b/azure-pipelines-ci.yml @@ -34,6 +34,13 @@ jobs: workingDirectory: $(Build.ArtifactStagingDirectory) - script: $(Build.ArtifactStagingDirectory)\windows-dependencies\vcpkg.exe integrate install displayName: 'Install dependencies' + - bash: | + set -ex + cd bin/baseset + curl -L https://binaries.openttd.org/extra/opengfx/0.5.2/opengfx-0.5.2-all.zip > opengfx-0.5.2-all.zip + unzip opengfx-0.5.2-all.zip + rm -f opengfx-0.5.2-all.zip + displayName: 'Install OpenGFX' - task: VSBuild@1 displayName: 'Build' inputs: @@ -41,7 +48,11 @@ jobs: platform: $(BuildPlatform) configuration: Release maximumCpuCount: true - # Running the regression is currently not possibe via MSVC (console is not redirected) + - script: | + call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86 + cd projects + call regression.bat + displayName: 'Test' - job: linux displayName: 'Linux' From 13056aedbc0a6c22704a525c1395980d887e0ad2 Mon Sep 17 00:00:00 2001 From: Eddi-z <43699911+Eddi-z@users.noreply.github.com> Date: Sat, 5 Jan 2019 22:10:37 +0100 Subject: [PATCH 16/22] Add: Conditional order for max. reliability (patch by Cirdan, #6360) (#7017) --- src/lang/english.txt | 1 + src/order_cmd.cpp | 1 + src/order_gui.cpp | 1 + src/order_type.h | 1 + src/script/api/ai/ai_order.hpp.sq | 1 + src/script/api/game/game_order.hpp.sq | 1 + src/script/api/script_order.cpp | 1 + src/script/api/script_order.hpp | 1 + 8 files changed, 8 insertions(+) diff --git a/src/lang/english.txt b/src/lang/english.txt index 1cfe149219..20608a2787 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3854,6 +3854,7 @@ STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP :{BLACK}Vehicle # Conditional order variables, must follow order of OrderConditionVariable enum STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE :Load percentage STR_ORDER_CONDITIONAL_RELIABILITY :Reliability +STR_ORDER_CONDITIONAL_MAX_RELIABILITY :Maximum reliability STR_ORDER_CONDITIONAL_MAX_SPEED :Maximum speed STR_ORDER_CONDITIONAL_AGE :Age (years) STR_ORDER_CONDITIONAL_REQUIRES_SERVICE :Requires service diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 12a5eec31a..ba8a1a060d 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -2017,6 +2017,7 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v) switch (order->GetConditionVariable()) { case OCV_LOAD_PERCENTAGE: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, NULL), value); break; case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->reliability), value); break; + case OCV_MAX_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->GetEngine()->reliability), value); break; case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break; case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break; case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break; diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 9045fac6b5..81350deb74 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -152,6 +152,7 @@ static const StringID _order_goto_dropdown_aircraft[] = { static const OrderConditionVariable _order_conditional_variable[] = { OCV_LOAD_PERCENTAGE, OCV_RELIABILITY, + OCV_MAX_RELIABILITY, OCV_MAX_SPEED, OCV_AGE, OCV_REMAINING_LIFETIME, diff --git a/src/order_type.h b/src/order_type.h index d3a771ce8b..ade0992961 100644 --- a/src/order_type.h +++ b/src/order_type.h @@ -118,6 +118,7 @@ DECLARE_ENUM_AS_BIT_SET(OrderDepotActionFlags) enum OrderConditionVariable { OCV_LOAD_PERCENTAGE, ///< Skip based on the amount of load OCV_RELIABILITY, ///< Skip based on the reliability + OCV_MAX_RELIABILITY, ///< Skip based on the maximum reliability OCV_MAX_SPEED, ///< Skip based on the maximum speed OCV_AGE, ///< Skip based on the age OCV_REQUIRES_SERVICE, ///< Skip when the vehicle requires service diff --git a/src/script/api/ai/ai_order.hpp.sq b/src/script/api/ai/ai_order.hpp.sq index 71cc8cfe90..ab25e4810d 100644 --- a/src/script/api/ai/ai_order.hpp.sq +++ b/src/script/api/ai/ai_order.hpp.sq @@ -44,6 +44,7 @@ void SQAIOrder_Register(Squirrel *engine) SQAIOrder.DefSQConst(engine, ScriptOrder::OF_INVALID, "OF_INVALID"); SQAIOrder.DefSQConst(engine, ScriptOrder::OC_LOAD_PERCENTAGE, "OC_LOAD_PERCENTAGE"); SQAIOrder.DefSQConst(engine, ScriptOrder::OC_RELIABILITY, "OC_RELIABILITY"); + SQAIOrder.DefSQConst(engine, ScriptOrder::OC_MAX_RELIABILITY, "OC_MAX_RELIABILITY"); SQAIOrder.DefSQConst(engine, ScriptOrder::OC_MAX_SPEED, "OC_MAX_SPEED"); SQAIOrder.DefSQConst(engine, ScriptOrder::OC_AGE, "OC_AGE"); SQAIOrder.DefSQConst(engine, ScriptOrder::OC_REQUIRES_SERVICE, "OC_REQUIRES_SERVICE"); diff --git a/src/script/api/game/game_order.hpp.sq b/src/script/api/game/game_order.hpp.sq index f95dce925a..e2126c603d 100644 --- a/src/script/api/game/game_order.hpp.sq +++ b/src/script/api/game/game_order.hpp.sq @@ -44,6 +44,7 @@ void SQGSOrder_Register(Squirrel *engine) SQGSOrder.DefSQConst(engine, ScriptOrder::OF_INVALID, "OF_INVALID"); SQGSOrder.DefSQConst(engine, ScriptOrder::OC_LOAD_PERCENTAGE, "OC_LOAD_PERCENTAGE"); SQGSOrder.DefSQConst(engine, ScriptOrder::OC_RELIABILITY, "OC_RELIABILITY"); + SQGSOrder.DefSQConst(engine, ScriptOrder::OC_MAX_RELIABILITY, "OC_MAX_RELIABILITY"); SQGSOrder.DefSQConst(engine, ScriptOrder::OC_MAX_SPEED, "OC_MAX_SPEED"); SQGSOrder.DefSQConst(engine, ScriptOrder::OC_AGE, "OC_AGE"); SQGSOrder.DefSQConst(engine, ScriptOrder::OC_REQUIRES_SERVICE, "OC_REQUIRES_SERVICE"); diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp index 676262dc77..a1390bf8f5 100644 --- a/src/script/api/script_order.cpp +++ b/src/script/api/script_order.cpp @@ -214,6 +214,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr switch (condition) { case OC_LOAD_PERCENTAGE: case OC_RELIABILITY: + case OC_MAX_RELIABILITY: case OC_MAX_SPEED: case OC_AGE: case OC_REMAINING_LIFETIME: diff --git a/src/script/api/script_order.hpp b/src/script/api/script_order.hpp index 63089a2bd4..a4f945511e 100644 --- a/src/script/api/script_order.hpp +++ b/src/script/api/script_order.hpp @@ -91,6 +91,7 @@ public: /* Note: these values represent part of the in-game OrderConditionVariable enum */ OC_LOAD_PERCENTAGE = ::OCV_LOAD_PERCENTAGE, ///< Skip based on the amount of load, value is in tons. OC_RELIABILITY = ::OCV_RELIABILITY, ///< Skip based on the reliability, value is percent (0..100). + OC_MAX_RELIABILITY = ::OCV_MAX_RELIABILITY, ///< Skip based on the maximum reliability. Value in percent OC_MAX_SPEED = ::OCV_MAX_SPEED, ///< Skip based on the maximum speed, value is in OpenTTD's internal speed unit, see ScriptEngine::GetMaxSpeed. OC_AGE = ::OCV_AGE, ///< Skip based on the age, value is in years. OC_REQUIRES_SERVICE = ::OCV_REQUIRES_SERVICE, ///< Skip when the vehicle requires service, no value. From 15a7f9da9d12a40bb65dda7cef4f4b3ec5342087 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 6 Jan 2019 10:31:56 +0100 Subject: [PATCH 17/22] Fix 13056ae: PR #7017 added new enum value in bad position, move it --- src/lang/english.txt | 2 +- src/order_type.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 20608a2787..cb4e685c46 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3854,12 +3854,12 @@ STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP :{BLACK}Vehicle # Conditional order variables, must follow order of OrderConditionVariable enum STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE :Load percentage STR_ORDER_CONDITIONAL_RELIABILITY :Reliability -STR_ORDER_CONDITIONAL_MAX_RELIABILITY :Maximum reliability STR_ORDER_CONDITIONAL_MAX_SPEED :Maximum speed STR_ORDER_CONDITIONAL_AGE :Age (years) STR_ORDER_CONDITIONAL_REQUIRES_SERVICE :Requires service STR_ORDER_CONDITIONAL_UNCONDITIONALLY :Always STR_ORDER_CONDITIONAL_REMAINING_LIFETIME :Remaining lifetime (years) +STR_ORDER_CONDITIONAL_MAX_RELIABILITY :Maximum reliability STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP :{BLACK}How to compare the vehicle data to the given value STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS :is equal to diff --git a/src/order_type.h b/src/order_type.h index ade0992961..ac66bfa38f 100644 --- a/src/order_type.h +++ b/src/order_type.h @@ -118,12 +118,12 @@ DECLARE_ENUM_AS_BIT_SET(OrderDepotActionFlags) enum OrderConditionVariable { OCV_LOAD_PERCENTAGE, ///< Skip based on the amount of load OCV_RELIABILITY, ///< Skip based on the reliability - OCV_MAX_RELIABILITY, ///< Skip based on the maximum reliability OCV_MAX_SPEED, ///< Skip based on the maximum speed OCV_AGE, ///< Skip based on the age OCV_REQUIRES_SERVICE, ///< Skip when the vehicle requires service OCV_UNCONDITIONALLY, ///< Always skip OCV_REMAINING_LIFETIME, ///< Skip based on the remaining lifetime + OCV_MAX_RELIABILITY, ///< Skip based on the maximum reliability OCV_END }; From 19a2f8494389a3c8fba2c17d90fbc5723c7b842c Mon Sep 17 00:00:00 2001 From: J0an Josep Date: Thu, 3 Jan 2019 14:49:37 +0100 Subject: [PATCH 18/22] Fix #7001: Pathfinders should see standard road stations as tiles where to reverse. --- src/pathfinder/follow_track.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pathfinder/follow_track.hpp b/src/pathfinder/follow_track.hpp index 0aec3951ed..9b4377248e 100644 --- a/src/pathfinder/follow_track.hpp +++ b/src/pathfinder/follow_track.hpp @@ -410,8 +410,9 @@ protected: } } - /* single tram bits cause reversing */ - if (IsTram() && GetSingleTramBit(m_old_tile) == ReverseDiagDir(m_exitdir)) { + /* Single tram bits and standard road stops cause reversing. */ + if (IsRoadTT() && ((IsTram() && GetSingleTramBit(m_old_tile) == ReverseDiagDir(m_exitdir)) || + (IsStandardRoadStopTile(m_old_tile) && GetRoadStopDir(m_old_tile) == ReverseDiagDir(m_exitdir)))) { /* reverse */ m_new_tile = m_old_tile; m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td)); From edb7adf183d11c452ab5f60ef7176cd34bab3f54 Mon Sep 17 00:00:00 2001 From: Juanjo! Date: Sat, 4 Jun 2016 19:01:36 +0200 Subject: [PATCH 19/22] Codechange: [NPF] Stop looking for an automatic servicing (rail/road) depot when the cost of a path exceeds max. penalty. --- src/pathfinder/npf/npf.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index bc4d8b3099..71ecf89128 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -959,12 +959,13 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current) * multiple targets that are spread around, we should perform a breadth first * search by specifiying CalcZero as our heuristic. */ -static NPFFoundTargetData NPFRouteInternal(AyStarNode *start1, bool ignore_start_tile1, AyStarNode *start2, bool ignore_start_tile2, NPFFindStationOrTileData *target, AyStar_EndNodeCheck target_proc, AyStar_CalculateH heuristic_proc, AyStarUserData *user, uint reverse_penalty, bool ignore_reserved = false) +static NPFFoundTargetData NPFRouteInternal(AyStarNode *start1, bool ignore_start_tile1, AyStarNode *start2, bool ignore_start_tile2, NPFFindStationOrTileData *target, AyStar_EndNodeCheck target_proc, AyStar_CalculateH heuristic_proc, AyStarUserData *user, uint reverse_penalty, bool ignore_reserved = false, int max_penalty = 0) { int r; NPFFoundTargetData result; /* Initialize procs */ + _npf_aystar.max_path_cost = max_penalty; _npf_aystar.CalculateH = heuristic_proc; _npf_aystar.EndNodeCheck = target_proc; _npf_aystar.FoundEndNode = NPFSaveTargetData; @@ -1052,7 +1053,7 @@ static NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, Trackdir track * reverse_penalty applied (NPF_TILE_LENGTH is the equivalent of one full * tile). */ -static NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Trackdir trackdir1, bool ignore_start_tile1, TileIndex tile2, Trackdir trackdir2, bool ignore_start_tile2, NPFFindStationOrTileData *target, AyStarUserData *user, uint reverse_penalty) +static NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Trackdir trackdir1, bool ignore_start_tile1, TileIndex tile2, Trackdir trackdir2, bool ignore_start_tile2, NPFFindStationOrTileData *target, AyStarUserData *user, uint reverse_penalty, int max_penalty) { AyStarNode start1; AyStarNode start2; @@ -1064,7 +1065,7 @@ static NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Tra /* perform a breadth first search. Target is NULL, * since we are just looking for any depot...*/ - return NPFRouteInternal(&start1, ignore_start_tile1, (IsValidTile(tile2) ? &start2 : NULL), ignore_start_tile2, target, NPFFindDepot, NPFCalcZero, user, reverse_penalty); + return NPFRouteInternal(&start1, ignore_start_tile1, (IsValidTile(tile2) ? &start2 : NULL), ignore_start_tile2, target, NPFFindDepot, NPFCalcZero, user, reverse_penalty, false, max_penalty); } void InitializeNPF() @@ -1114,7 +1115,7 @@ FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penal Trackdir trackdir = v->GetVehicleTrackdir(); AyStarUserData user = { v->owner, TRANSPORT_ROAD, INVALID_RAILTYPES, v->compatible_roadtypes }; - NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, v->tile, ReverseTrackdir(trackdir), false, NULL, &user, 0); + NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, v->tile, ReverseTrackdir(trackdir), false, NULL, &user, 0, max_penalty); if (ftd.best_bird_dist != 0) return FindDepotData(); @@ -1204,7 +1205,7 @@ FindDepotData NPFTrainFindNearestDepot(const Train *v, int max_penalty) assert(trackdir != INVALID_TRACKDIR); AyStarUserData user = { v->owner, TRANSPORT_RAIL, v->compatible_railtypes, ROADTYPES_NONE }; - NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, last->tile, trackdir_rev, false, &fstd, &user, NPF_INFINITE_PENALTY); + NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, last->tile, trackdir_rev, false, &fstd, &user, NPF_INFINITE_PENALTY, max_penalty); if (ftd.best_bird_dist != 0) return FindDepotData(); /* Found target */ From 1db66a285e9e887d86dad60e73b00c5a3efc0219 Mon Sep 17 00:00:00 2001 From: Juanjo! Date: Sat, 4 Jun 2016 20:45:09 +0200 Subject: [PATCH 20/22] Codechange: [YAPF] Stop looking for an automatic servicing road depot when the cost of a path exceeds max. penalty. --- src/pathfinder/yapf/yapf_road.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index edc8d2a3a3..0240eb9366 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -27,6 +27,10 @@ public: typedef typename Node::Key Key; ///< key to hash tables protected: + int m_max_cost; + + CYapfCostRoadT() : m_max_cost(0) {}; + /** to access inherited path finder */ Tpf& Yapf() { @@ -97,6 +101,11 @@ protected: } public: + inline void SetMaxCost(int max_cost) + { + m_max_cost = max_cost; + } + /** * Called by YAPF to calculate the cost from the origin to the given node. * Calculates only the cost of given node, adds it to the parent node cost @@ -109,6 +118,8 @@ public: /* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */ TileIndex tile = n.m_key.m_tile; Trackdir trackdir = n.m_key.m_td; + int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0; + for (;;) { /* base tile cost depending on distance between edges */ segment_cost += Yapf().OneTileCost(tile, trackdir); @@ -117,6 +128,12 @@ public: /* we have reached the vehicle's destination - segment should end here to avoid target skipping */ if (Yapf().PfDetectDestinationTile(tile, trackdir)) break; + /* Finish if we already exceeded the maximum path cost (i.e. when + * searching for the nearest depot). */ + if (m_max_cost > 0 && (parent_cost + segment_cost) > m_max_cost) { + return false; + } + /* stop if we have just entered the depot */ if (IsRoadDepotTile(tile) && trackdir == DiagDirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) { /* next time we will reverse and leave the depot */ @@ -160,7 +177,6 @@ public: n.m_segment_last_td = trackdir; /* save also tile cost */ - int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0; n.m_cost = parent_cost + segment_cost; return true; } @@ -441,15 +457,12 @@ public: * @param tile Tile of the vehicle. * @param td Trackdir of the vehicle. * @param max_distance max length (penalty) for paths. - * @todo max_distance not used by YAPF for road vehicles. - * It can be removed or copy the SetMaxCost() strategy - * applied in YAPF for rail. The best depot can be at - * a distance greater than max_distance. */ inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance) { /* Set origin. */ Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td)); + Yapf().SetMaxCost(max_distance); /* Find the best path and return if no depot is found. */ if (!Yapf().FindPath(v)) return FindDepotData(); From c304aa50e9f3fb67a0f661edcf9bc69b426ea7b7 Mon Sep 17 00:00:00 2001 From: J0an Josep Date: Fri, 4 Jan 2019 01:41:22 +0100 Subject: [PATCH 21/22] Fix: [NPF] Don't look two-way for road vehicles when looking for a depot. Road vehicles shouldn't reverse all of a sudden. --- src/pathfinder/npf/npf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index 71ecf89128..9535ac0636 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -1115,7 +1115,7 @@ FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penal Trackdir trackdir = v->GetVehicleTrackdir(); AyStarUserData user = { v->owner, TRANSPORT_ROAD, INVALID_RAILTYPES, v->compatible_roadtypes }; - NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, v->tile, ReverseTrackdir(trackdir), false, NULL, &user, 0, max_penalty); + NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, INVALID_TILE, INVALID_TRACKDIR, false, NULL, &user, 0, max_penalty); if (ftd.best_bird_dist != 0) return FindDepotData(); From effb7da5b478fea198b342690d0f5aac8f562ee6 Mon Sep 17 00:00:00 2001 From: J0an Josep Date: Fri, 4 Jan 2019 02:14:40 +0100 Subject: [PATCH 22/22] Doc: Fix spelling in comments. --- src/pathfinder/pathfinder_type.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pathfinder/pathfinder_type.h b/src/pathfinder/pathfinder_type.h index 9f5a42d76d..73031d5c81 100644 --- a/src/pathfinder/pathfinder_type.h +++ b/src/pathfinder/pathfinder_type.h @@ -20,8 +20,8 @@ static const int NPF_TILE_LENGTH = 100; /** * This penalty is the equivalent of "infinite", which means that paths that * get this penalty will be chosen, but only if there is no other route - * without it. Be careful with not applying this penalty to often, or the - * total path cost might overflow.. + * without it. Be careful with not applying this penalty too often, or the + * total path cost might overflow. */ static const int NPF_INFINITE_PENALTY = 1000 * NPF_TILE_LENGTH; @@ -35,8 +35,8 @@ static const int YAPF_TILE_CORNER_LENGTH = 71; /** * This penalty is the equivalent of "infinite", which means that paths that * get this penalty will be chosen, but only if there is no other route - * without it. Be careful with not applying this penalty to often, or the - * total path cost might overflow.. + * without it. Be careful with not applying this penalty too often, or the + * total path cost might overflow. */ static const int YAPF_INFINITE_PENALTY = 1000 * YAPF_TILE_LENGTH;