Skip to content

Commit e0e47f2

Browse files
committed
Automatic merge of T1.5.1-866-gbae4730e2 and 17 pull requests
- Pull request #570 at 3539862: Experimental glTF 2.0 support with PBR lighting - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #882 at 9c456aa: Blueprint/train car operations UI window - Pull request #885 at 8f94333: feat: Add notifications to Menu - Pull request #886 at 6c0785b: Scene viewer extension to TrackViewer - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #896 at 5866028: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains - Pull request #897 at 42f1dd9: feat: Improved system information collection - Pull request #903 at 0d6d045: Downloading route content (Github, zip) - Pull request #907 at 9b0b04f: Bug fix for https://bugs.launchpad.net/or/+bug/2047300 Dynamic tracks disappear after long tunnel - Pull request #908 at ad3362c: feat: supports switching adhesion precisions - Pull request #911 at 6834af0: docs: Add refactoring as a special type of PR - Pull request #912 at 659396e: New Triple Valve Features Vol. 2 - Pull request #914 at 9ee1da3: Adjustments to Duplex steam - Pull request #915 at 6d911d7: Correct calculation error with curve friction - Pull request #916 at 11ac52c: Distributed Power Air Brake Synchronization
19 parents cd7a526 + bae4730 + 3539862 + d00beb9 + f92de76 + 9c456aa + 8f94333 + 6c0785b + 1f5ba4c + 5866028 + 42f1dd9 + 0d6d045 + 9b0b04f + ad3362c + 6834af0 + 659396e + 9ee1da3 + 6d911d7 + 11ac52c commit e0e47f2

File tree

1 file changed

+84
-9
lines changed
  • Source/Orts.Simulation/Simulation/Physics

1 file changed

+84
-9
lines changed

Source/Orts.Simulation/Simulation/Physics/Train.cs

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ public TrainCar LeadLocomotive
513513
//if (lead.EngineBrakeController != null)
514514
// lead.EngineBrakeController.UpdateEngineBrakePressure(ref BrakeLine3PressurePSI, 1000);
515515
}
516+
517+
// If lead locomotive changes, distributed power needs to be updated
518+
SetDPUnitIDs(true);
516519
}
517520
}
518521

@@ -1539,27 +1542,43 @@ public void SetDPUnitIDs(bool keepRemoteGroups = false)
15391542
{
15401543
// List to keep track of new 'lead' DP units
15411544
// 'Lead' DP units follow the air brake commands of the master loco, 'trail' DP units do not
1542-
List<TrainCar> tempDPLead = new List<TrainCar>();
1545+
List<TrainCar> tempDPLeads = new List<TrainCar>();
1546+
TrainCar tempDPLead = null;
1547+
// Value judging how compatible this locomotive is to the lead locomotive for DP purposes
1548+
float dpRating = 0;
15431549

15441550
// List of each DP group's locomotives
15451551
List<List<TrainCar>> tempLocoGroups = new List<List<TrainCar>>();
15461552

15471553
var prevId = -1;
1548-
15491554
var id = 0;
1555+
15501556
foreach (var car in Cars)
15511557
{
1552-
//Console.WriteLine("___{0} {1}", car.CarID, id);
15531558
if (car is MSTSLocomotive loco)
15541559
{
1560+
float thisDPRating = DetermineDPCompatibility(LeadLocomotive, car);
1561+
15551562
loco.DPUnitID = id;
15561563

1557-
if (id != prevId && !tempDPLead.Contains(car)) // If this is a new ID, that means we found a 'lead' unit
1564+
if (id != prevId) // New locomotive group
15581565
{
1559-
tempDPLead.Add(car);
1566+
// Add the most suitable unit from the previous group as a DP lead unit
1567+
if (tempDPLead != null && !tempDPLeads.Contains(tempDPLead))
1568+
tempDPLeads.Add(tempDPLead);
1569+
1570+
dpRating = thisDPRating;
1571+
tempDPLead = car;
15601572

15611573
prevId = id;
15621574
}
1575+
else // Same locomotive group
1576+
// Check to see if this locomotive is more compatible than previous ones
1577+
if (thisDPRating > dpRating)
1578+
{
1579+
dpRating = thisDPRating;
1580+
tempDPLead = car;
1581+
}
15631582

15641583
if (car.RemoteControlGroup == 1 && !keepRemoteGroups)
15651584
car.RemoteControlGroup = 0;
@@ -1568,20 +1587,24 @@ public void SetDPUnitIDs(bool keepRemoteGroups = false)
15681587
id++;
15691588
}
15701589

1571-
foreach (TrainCar locoCar in tempDPLead)
1590+
// Add final DP lead unit
1591+
if (tempDPLead != null && !tempDPLeads.Contains(tempDPLead))
1592+
tempDPLeads.Add(tempDPLead);
1593+
1594+
foreach (TrainCar locoCar in tempDPLeads)
15721595
{
15731596
// The train's lead unit should always be a DP lead unit, even if not at the front
15741597
// If a different locomotive in the lead loco's group has been declared DP lead, replace that loco with the lead loco
15751598
if (LeadLocomotive is MSTSLocomotive lead && locoCar is MSTSLocomotive loco)
15761599
if (loco.DPUnitID == lead.DPUnitID && locoCar != LeadLocomotive)
15771600
{
1578-
tempDPLead.Insert(tempDPLead.IndexOf(locoCar), LeadLocomotive);
1579-
tempDPLead.Remove(locoCar);
1601+
tempDPLeads.Insert(tempDPLeads.IndexOf(locoCar), LeadLocomotive);
1602+
tempDPLeads.Remove(locoCar);
15801603
break; // foreach doesn't like it when the collection is modified during the loop, break to mitigate error
15811604
}
15821605
}
15831606

1584-
DPLeadUnits = tempDPLead;
1607+
DPLeadUnits = tempDPLeads;
15851608

15861609
foreach (TrainCar loco in DPLeadUnits)
15871610
{
@@ -4352,6 +4375,58 @@ public TrainCar DetermineDPLeadLocomotive(TrainCar locoCar)
43524375
return null;
43534376
}
43544377

4378+
//================================================================================================//
4379+
/// <summary>
4380+
/// Find compatibility of DP connection between two locomotives
4381+
/// <\summary>
4382+
4383+
// Returns a score judging the compatibility of a lead locomotive (first input as a TrainCar)
4384+
// and remote locomotive (second input as a TrainCar). The more capabilities the two locomotives
4385+
// share, the higher the number returned. There is an additional slight bias for remote
4386+
// locomotives having higher capabilities than the lead locomotive.
4387+
// Returns -1 if one of the input TrainCars isn't a locomotive
4388+
4389+
public float DetermineDPCompatibility(TrainCar leadCar, TrainCar remoteCar)
4390+
{
4391+
float score = 0;
4392+
4393+
if (leadCar is MSTSLocomotive lead && remoteCar is MSTSLocomotive remote)
4394+
{
4395+
if (remote.DPSyncTrainApplication)
4396+
{
4397+
if (lead.DPSyncTrainApplication)
4398+
score++;
4399+
else
4400+
score += 0.1f;
4401+
}
4402+
if (remote.DPSyncTrainRelease)
4403+
{
4404+
if (lead.DPSyncTrainRelease)
4405+
score++;
4406+
else
4407+
score += 0.1f;
4408+
}
4409+
if (remote.DPSyncEmergency)
4410+
{
4411+
if (lead.DPSyncEmergency)
4412+
score++;
4413+
else
4414+
score += 0.1f;
4415+
}
4416+
if (remote.DPSyncIndependent)
4417+
{
4418+
if (lead.DPSyncIndependent)
4419+
score++;
4420+
else
4421+
score += 0.1f;
4422+
}
4423+
4424+
return score;
4425+
}
4426+
else
4427+
return -1;
4428+
}
4429+
43554430
//================================================================================================//
43564431
/// <summary>
43574432
/// Propagate brake pressure

0 commit comments

Comments
 (0)