Merge branch 'more_cond_orders-sx' into jgrpp

# Conflicts:
#	config.lib
#	projects/openttd_vs100.vcxproj
#	projects/openttd_vs100.vcxproj.filters
#	projects/openttd_vs80.vcproj
#	projects/openttd_vs90.vcproj
#	src/order_gui.cpp
#	src/order_type.h
#	src/saveload/afterload.cpp
#	src/saveload/extended_ver_sl.cpp
pull/78/head
Jonathan G Rennison 5 years ago
commit 0e7519f33e

@ -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

@ -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

@ -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'

@ -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 <http://www.gnu.org/licenses/>.
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

@ -1343,8 +1343,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++11"
fi
if [ $cc_version -lt 140 ]; then
@ -1362,7 +1360,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"
@ -1412,7 +1411,7 @@ make_compiler_cflags() {
if [ "$cc_version" -ge "33" ]; then
# clang completed C++11 support in version 3.3
flags="$flags -std=c++11 -DCUSTOM_ALLOCATOR"
flags="$flags -DCUSTOM_ALLOCATOR"
else
log 1 "configure: error: clang version is too old: `$1 -v 2>&1 | head -n 1`, minumum: 3.3"
exit 1
@ -1476,12 +1475,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++11"
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
@ -1511,7 +1504,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
@ -1602,6 +1595,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_static" != "0" ]; then
STATIC_FLAGS="--static"
@ -3247,10 +3242,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 </dev/null 2>&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`

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -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

@ -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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -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%

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4712B013-437D-42CE-947F-DEBABA15261F}</ProjectGuid>
<RootNamespace>regression</RootNamespace>
<ProjectName>regression</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<NMakeBuildCommandLine>call regression.bat</NMakeBuildCommandLine>
<NMakeReBuildCommandLine>call regression.bat</NMakeReBuildCommandLine>
<NMakeCleanCommandLine>del ..\bin\tmp.regression</NMakeCleanCommandLine>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="openttd_vs140.vcxproj">
<Project>{668328a0-b40e-4cdb-bd72-d0064424414a}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4712B013-437D-42CE-947F-DEBABA15261F}</ProjectGuid>
<RootNamespace>regression</RootNamespace>
<ProjectName>regression</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<NMakeBuildCommandLine>call regression.bat</NMakeBuildCommandLine>
<NMakeReBuildCommandLine>call regression.bat</NMakeReBuildCommandLine>
<NMakeCleanCommandLine>del ..\bin\tmp.regression</NMakeCleanCommandLine>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="openttd_vs141.vcxproj">
<Project>{668328a0-b40e-4cdb-bd72-d0064424414a}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

@ -4580,6 +4580,7 @@ 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_CARGO_WAITING :Waiting cargo
STR_ORDER_CONDITIONAL_ACCEPTANCE_DROPDOWN :Accepted cargo
STR_ORDER_CONDITIONAL_FREE_PLATFORMS :Free platforms

@ -2708,6 +2708,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!!

@ -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;
}

@ -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 */

@ -16,11 +16,11 @@
#include "fluidsynth.h"
#include "midifile.hpp"
#include <fluidsynth.h>
#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);
}

@ -2411,6 +2411,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;

@ -598,6 +598,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,

@ -142,6 +142,7 @@ enum OrderConditionVariable {
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_CARGO_WAITING, ///< Skip if specified cargo is waiting at next station
OCV_CARGO_ACCEPTANCE, ///< Skip if specified cargo is accepted at next station
OCV_FREE_PLATFORMS, ///< Skip based on free platforms at next station

@ -303,7 +303,7 @@ void CreateConsole()
if (_has_console) return;
_has_console = true;
AllocConsole();
if (!AllocConsole()) return;
hand = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hand, &coninfo);

@ -432,8 +432,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));

@ -970,12 +970,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;
@ -1063,7 +1064,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;
@ -1075,7 +1076,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()
@ -1121,7 +1122,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, INVALID_TILE, INVALID_TRACKDIR, false, NULL, &user, 0, max_penalty);
if (ftd.best_bird_dist != 0) return FindDepotData();
@ -1176,7 +1177,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);
}
@ -1211,7 +1212,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 */

@ -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;

@ -35,6 +35,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()
{
@ -105,6 +109,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
@ -120,6 +129,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);
@ -128,6 +139,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 */
@ -172,7 +189,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;
}
@ -453,15 +469,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();

@ -3570,6 +3570,16 @@ bool AfterLoadGame()
FOR_ALL_COMPANIES(c) c->purchase_land_limit = _settings_game.construction.purchase_land_frame_burst << 16;
}
if (SlXvIsFeaturePresent(XSLFI_MORE_COND_ORDERS, 1, 1)) {
Order *order;
FOR_ALL_ORDERS(order) {
// Insertion of OCV_MAX_RELIABILITY between OCV_REMAINING_LIFETIME and OCV_CARGO_WAITING
if (order->IsType(OT_CONDITIONAL) && order->GetConditionVariable() > OCV_REMAINING_LIFETIME) {
order->SetConditionVariable(static_cast<OrderConditionVariable>((uint)order->GetConditionVariable() + 1));
}
}
}
/* Road stops is 'only' updating some caches */
AfterLoadRoadStops();
AfterLoadLabelMaps();

@ -49,7 +49,7 @@ static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version
const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_TRACE_RESTRICT, XSCF_NULL, 10, 10, "tracerestrict", NULL, NULL, "TRRM,TRRP,TRRS" },
{ XSLFI_TRACE_RESTRICT_OWNER, XSCF_NULL, 1, 1, "tracerestrict_owner", NULL, NULL, NULL },
{ XSLFI_TRACE_RESTRICT_ORDRCND, XSCF_NULL, 2, 2, "tracerestrict_order_cond", NULL, NULL, NULL },
{ XSLFI_TRACE_RESTRICT_ORDRCND, XSCF_NULL, 3, 3, "tracerestrict_order_cond", NULL, NULL, NULL },
{ XSLFI_TRACE_RESTRICT_STATUSCND,XSCF_NULL, 1, 1, "tracerestrict_status_cond", NULL, NULL, NULL },
{ XSLFI_TRACE_RESTRICT_REVERSE, XSCF_NULL, 1, 1, "tracerestrict_reverse", NULL, NULL, NULL },
{ XSLFI_PROG_SIGS, XSCF_NULL, 1, 1, "programmable_signals", NULL, NULL, "SPRG" },
@ -67,7 +67,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_INFRA_SHARING, XSCF_NULL, 2, 2, "infra_sharing", NULL, NULL, "CPDP" },
{ XSLFI_VARIABLE_DAY_LENGTH, XSCF_NULL, 2, 2, "variable_day_length", NULL, NULL, NULL },
{ XSLFI_ORDER_OCCUPANCY, XSCF_NULL, 2, 2, "order_occupancy", NULL, NULL, NULL },
{ XSLFI_MORE_COND_ORDERS, XSCF_NULL, 1, 1, "more_cond_orders", NULL, NULL, NULL },
{ XSLFI_MORE_COND_ORDERS, XSCF_NULL, 2, 2, "more_cond_orders", NULL, NULL, NULL },
{ XSLFI_EXTRA_LARGE_MAP, XSCF_NULL, 0, 1, "extra_large_map", NULL, NULL, NULL },
{ XSLFI_REVERSE_AT_WAYPOINT, XSCF_NULL, 1, 1, "reverse_at_waypoint", NULL, NULL, NULL },
{ XSLFI_VEH_LIFETIME_PROFIT, XSCF_NULL, 1, 1, "veh_lifetime_profit", NULL, NULL, NULL },

@ -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");

@ -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");

@ -215,6 +215,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:

@ -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.

@ -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");
}

@ -909,10 +909,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);
}

@ -1747,7 +1747,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);

Loading…
Cancel
Save