Skip to content

Commit 3270171

Browse files
committed
New: Implement permissive sections
Route command .SectionP
1 parent 77b3eee commit 3270171

File tree

9 files changed

+83
-7
lines changed

9 files changed

+83
-7
lines changed

assets/Languages/en-US.xlf

+9
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,15 @@
14661466
<trans-unit id="delimiter">
14671467
<source>\x20</source>
14681468
</trans-unit>
1469+
<trans-unit id="signal_access_invalid">
1470+
<source>The next section is not a permissive section.</source>
1471+
</trans-unit>
1472+
<trans-unit id="signal_access_denied">
1473+
<source>The next section is a permissive section, but access is not currently possible. Please wait and retry.</source>
1474+
</trans-unit>
1475+
<trans-unit id="signal_access_granted">
1476+
<source>Access to the next section has been granted.</source>
1477+
</trans-unit>
14691478
<trans-unit id="signal_proceed">
14701479
<source>You may proceed at [speed] [unit] with extreme caution.</source>
14711480
</trans-unit>

source/OpenBVE/System/Input/ProcessControls.Digital.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,9 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro
13801380
break;
13811381
}
13821382
break;
1383+
case Translations.Command.AccessPermissiveSection:
1384+
TrainManager.PlayerTrain.ContactSignaller();
1385+
break;
13831386
}
13841387
}
13851388
else if (Control.DigitalState == DigitalControlState.Released)

source/OpenBveApi/Interface/Input/Commands.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,10 @@ public enum Command
315315
/// <summary>Uncouples the rear coupling of a car</summary>
316316
UncoupleRear,
317317
/// <summary>Controls the DSD</summary>
318-
DriverSupervisionDevice
318+
DriverSupervisionDevice,
319+
// Added in 1.11.2.0
320+
/// <summary>Press to request permission from the signaller to access a permissive section</summary>
321+
AccessPermissiveSection
319322
}
320323

321324
/// <summary>Defines the possible command types</summary>

source/Plugins/Route.CsvRw/Namespaces/Track/Track.Commands.cs

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ internal enum TrackCommand
2929
Section,
3030
/// <summary>Adds a signalling section</summary>
3131
SectionS,
32+
/// <summary>Adds a permissive signalling section</summary>
33+
/// <remarks>Must be value based</remarks>
34+
SectionP,
3235
/// <summary>Adds a signal object</summary>
3336
SigF,
3437
/// <summary>Adds a signal object</summary>

source/Plugins/Route.CsvRw/Namespaces/Track/Track.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ private void ParseTrackCommand(TrackCommand Command, string[] Arguments, string
461461
break;
462462
case TrackCommand.Section:
463463
case TrackCommand.SectionS:
464+
case TrackCommand.SectionP:
464465
{
465466
if (!PreviewOnly)
466467
{
@@ -531,7 +532,16 @@ private void ParseTrackCommand(TrackCommand Command, string[] Arguments, string
531532
}
532533
}
533534

534-
Data.Blocks[BlockIndex].Sections[n] = new Section(Data.TrackPosition, aspects, departureStationIndex, valueBased ? SectionType.ValueBased : SectionType.IndexBased);
535+
SectionType type;
536+
if (valueBased)
537+
{
538+
type = Command == TrackCommand.SectionP ? SectionType.PermissiveValueBased : SectionType.ValueBased;
539+
}
540+
else
541+
{
542+
type = Command == TrackCommand.SectionP ? SectionType.PermissiveIndexBased : SectionType.IndexBased;
543+
}
544+
Data.Blocks[BlockIndex].Sections[n] = new Section(Data.TrackPosition, aspects, departureStationIndex, type);
535545

536546

537547
CurrentSection++;

source/RouteManager2/CurrentRoute.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void UpdateSection(Section Section, out Section PreviousSection)
170170
int zeroAspect = 0;
171171
bool setToRed = false;
172172

173-
if (Section.Type == SectionType.ValueBased)
173+
if (Section.Type == SectionType.ValueBased || Section.Type == SectionType.PermissiveValueBased)
174174
{
175175
// value-based
176176
zeroAspect = 0;
@@ -312,6 +312,19 @@ public void UpdateSection(Section Section, out Section PreviousSection)
312312
setToRed = true;
313313
}
314314

315+
if ((Section.Type == SectionType.PermissiveValueBased || Section.Type == SectionType.PermissiveIndexBased) && Section.SignallerPermission == false)
316+
{
317+
// with a permissive section, check to see if the *previous* section holds the player train
318+
// ignore for AI trains (we'll assume they can contact the signaller silently)
319+
for (int i = 0; i < Section.PreviousSection.Trains.Length; i++)
320+
{
321+
if (Section.PreviousSection.Trains[i].Type == TrainType.LocalPlayerTrain || Section.PreviousSection.Trains[i].Type == TrainType.RemotePlayerTrain)
322+
{
323+
setToRed = true;
324+
}
325+
}
326+
}
327+
315328
// free sections
316329
int newAspect = -1;
317330

@@ -344,7 +357,7 @@ public void UpdateSection(Section Section, out Section PreviousSection)
344357
// change aspect
345358
if (newAspect == -1)
346359
{
347-
if (Section.Type == SectionType.ValueBased)
360+
if (Section.Type == SectionType.ValueBased || Section.Type == SectionType.PermissiveValueBased)
348361
{
349362
// value-based
350363
Section n = Section.NextSection;

source/RouteManager2/SignalManager/Section.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Runtime.CompilerServices;
34
using OpenBveApi.Runtime;
45
using OpenBveApi.Trains;
56

@@ -46,6 +47,8 @@ public class Section
4647

4748
internal double RedTimer;
4849

50+
public bool SignallerPermission;
51+
4952
/// <summary>Whether this section has been announced with accessibility in use</summary>
5053
public bool AccessibilityAnnounced;
5154

source/RouteManager2/SignalManager/SectionTypes.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
public enum SectionType
55
{
66
/// <summary>A section aspect may have any value</summary>
7-
ValueBased,
8-
7+
ValueBased,
8+
/// <summary>A section aspect may have any value</summary>
9+
/// <remarks>The section is held at red until the permissive key is pressed</remarks>
10+
PermissiveValueBased,
11+
/// <summary>Section aspect count upwards from zero (0,1,2,3....)</summary>
12+
IndexBased,
913
/// <summary>Section aspect count upwards from zero (0,1,2,3....)</summary>
10-
IndexBased
14+
/// <remarks>The section is held at red until the permissive key is pressed</remarks>
15+
PermissiveIndexBased
16+
1117
}
1218
}

source/TrainManager/Train/TrainBase.cs

+26
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using OpenBveApi.Routes;
1111
using OpenBveApi.Runtime;
1212
using OpenBveApi.Trains;
13+
using RouteManager2;
1314
using RouteManager2.MessageManager;
1415
using RouteManager2.SignalManager;
1516
using RouteManager2.Stations;
@@ -1162,5 +1163,30 @@ public override void Couple(AbstractTrain Train, bool Front)
11621163
string message = Translations.GetInterfaceString(HostApplication.OpenBve, Front ? new[] { "notification", "couple_front" } : new[] { "notification", "couple_rear" }).Replace("[number]", trainBase.Cars.Length.ToString());
11631164
TrainManagerBase.currentHost.AddMessage(message, MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 5.0, null);
11641165
}
1166+
1167+
public void ContactSignaller()
1168+
{
1169+
Section sct = TrainManagerBase.CurrentRoute.Sections[CurrentSectionIndex].NextSection;
1170+
if (sct.Type != SectionType.PermissiveValueBased && sct.Type != SectionType.PermissiveIndexBased)
1171+
{
1172+
// not a valid section to access
1173+
string s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "message", "signal_access_invalid" });
1174+
}
1175+
else
1176+
{
1177+
if (sct.IsFree())
1178+
{
1179+
// section is free of trains, so can be permissively accessed
1180+
string s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "message", "signal_access_granted" });
1181+
sct.SignallerPermission = true;
1182+
}
1183+
else
1184+
{
1185+
// not free, access denied
1186+
string s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "message", "signal_access_denied" });
1187+
sct.SignallerPermission = false;
1188+
}
1189+
}
1190+
}
11651191
}
11661192
}

0 commit comments

Comments
 (0)