Skip to content

Commit 401b689

Browse files
committed
Automatic merge of T1.5.1-1288-g58b2418aa6 and 16 pull requests
- Pull request #980 at 86bcd3a: Downloading route content (Github, zip) second part - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #891 at 9a1d6b2: Auto save - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #952 at 8347095: Investigation - Pulsing graphics - Pull request #953 at a519452: Fix Lights Crash on Corrupt Shapes - Pull request #954 at e4ba0d7: Multiple Track Profiles & Superelevation Rewrite - Pull request #972 at e90a2aa: On Map window color changed switch or signal is not changed - Pull request #981 at 10d297f: Multiple type trainset lightglows - Pull request #982 at efcf19c: WEB based Switch Panel enhancement: Alerter - Pull request #984 at 0f8122e: Player train switching for timetable mode - Pull request #986 at 5d7e692: Fix: The TrainCarOperations window does not resize correctly. - Pull request #987 at 232e8fb: fix: Temporary workaround for building with NET 5+ - Pull request #900 at c27f32d: DMI updates - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #988 at a0ebdf9: Conditional sound, blueprint https://blueprints.launchpad.net/or/+spec/conditional-sound
18 parents 707974f + 58b2418 + 86bcd3a + d00beb9 + 9a1d6b2 + 1f5ba4c + 8347095 + a519452 + e4ba0d7 + e90a2aa + 10d297f + efcf19c + 0f8122e + 5d7e692 + 232e8fb + c27f32d + f92de76 + a0ebdf9 commit 401b689

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

Source/Orts.Formats.Msts/SoundManagmentFile.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ public class SMSStream
176176
public float Volume = 1.0f;
177177
public List<VolumeCurve> VolumeCurves = new List<VolumeCurve>();
178178
public FrequencyCurve FrequencyCurve;
179+
public bool[] Season;
180+
public bool[] Weather;
181+
public int[] TimeInterval;
182+
public List<int[]> TimeIntervals;
183+
184+
179185

180186
public SMSStream(STFReader stf)
181187
{
@@ -186,6 +192,42 @@ public SMSStream(STFReader stf)
186192
new STFReader.TokenProcessor("volumecurve", ()=>{ VolumeCurves.Add(new VolumeCurve(stf)); }),
187193
new STFReader.TokenProcessor("frequencycurve", ()=>{ FrequencyCurve = new FrequencyCurve(stf); }),
188194
new STFReader.TokenProcessor("volume", ()=>{ Volume = stf.ReadFloatBlock(STFReader.UNITS.None, Volume); }),
195+
new STFReader.TokenProcessor("ortstimeofday", ()=>{
196+
if (TimeIntervals == null)
197+
TimeIntervals = new List<int[]>();
198+
var timeInterval = new int[2];
199+
stf.MustMatch("(");
200+
timeInterval[0] = stf.ReadInt(null);
201+
timeInterval[1] = stf.ReadInt(null);
202+
TimeIntervals.Add(timeInterval);
203+
stf.SkipRestOfBlock();
204+
}),
205+
new STFReader.TokenProcessor("ortsseason", ()=>{
206+
Season = new bool[4];
207+
stf.MustMatch("(");
208+
stf.ParseBlock(new STFReader.TokenProcessor[] {
209+
new STFReader.TokenProcessor("spring", ()=>{ if(stf.ReadBoolBlock(true))
210+
Season[(int)SeasonType.Spring] = true; }),
211+
new STFReader.TokenProcessor("summer", ()=>{ if(stf.ReadBoolBlock(true))
212+
Season[(int)SeasonType.Summer] = true; }),
213+
new STFReader.TokenProcessor("autumn", ()=>{ if(stf.ReadBoolBlock(true))
214+
Season[(int)SeasonType.Autumn] = true; }),
215+
new STFReader.TokenProcessor("winter", ()=>{ if(stf.ReadBoolBlock(true))
216+
Season[(int)SeasonType.Winter] = true; }),
217+
});
218+
}),
219+
new STFReader.TokenProcessor("ortsweather", ()=>{
220+
Weather = new bool[3];
221+
stf.MustMatch("(");
222+
stf.ParseBlock(new STFReader.TokenProcessor[] {
223+
new STFReader.TokenProcessor("clear", ()=>{ if(stf.ReadBoolBlock(true))
224+
Weather[(int)WeatherType.Clear] = true; }),
225+
new STFReader.TokenProcessor("snow", ()=>{ if(stf.ReadBoolBlock(true))
226+
Weather[(int)WeatherType.Snow] = true; }),
227+
new STFReader.TokenProcessor("rain", ()=>{ if(stf.ReadBoolBlock(true))
228+
Weather[(int)WeatherType.Rain] = true; }),
229+
});
230+
}),
189231
});
190232
//if (Volume > 1) Volume /= 100f;
191233
}

Source/RunActivity/Viewer3D/Sound.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,32 @@ private void SetFreqAndVolume()
14441444
volume *= ((MSTSWagon)SoundSource.Viewer.Camera.AttachedCar).TrackSoundPassThruPercent * 0.01f;
14451445
}
14461446

1447+
// check if time of day, season and weather enable the sound; if not, set volume to zero
1448+
if (MSTSStream?.TimeIntervals != null)
1449+
{
1450+
var outOfInterval = true;
1451+
foreach (var timeInterval in MSTSStream.TimeIntervals)
1452+
{
1453+
int hourOfDay = (int)SoundSource.Viewer.Simulator.ClockTime / 3600;
1454+
if (hourOfDay >= timeInterval[0] && hourOfDay < timeInterval[1])
1455+
{
1456+
outOfInterval = false;
1457+
break;
1458+
}
1459+
}
1460+
if (outOfInterval)
1461+
volume = 0;
1462+
}
1463+
if (MSTSStream?.Season != null )
1464+
{
1465+
if (!MSTSStream.Season[(int)(SoundSource.Viewer.Simulator.Season)])
1466+
volume = 0;
1467+
}
1468+
if (MSTSStream?.Weather != null )
1469+
{
1470+
if (!MSTSStream.Weather[(int)(SoundSource.Viewer.Simulator.WeatherType)])
1471+
volume = 0;
1472+
}
14471473
ALSoundSource.Volume = volume;
14481474
}
14491475

0 commit comments

Comments
 (0)