Skip to content

Commit 62deafb

Browse files
committed
Change: More implementation work on pantographs
1 parent ba7cf2b commit 62deafb

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

source/OpenBVE/Parsers/Train/TrainDatParser.cs

+26-8
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ internal static void ParseTrainData(string FileName, System.Text.Encoding Encodi
6060
}
6161
}
6262
TrainDatFormats currentFormat = TrainDatFormats.openBVE;
63-
const int currentVersion = 15311;
63+
const int currentVersion = 18000;
6464
int myVersion = -1;
6565
for (int i = 0; i < Lines.Length; i++) {
6666
if (Lines[i].Length > 0) {
@@ -152,6 +152,8 @@ internal static void ParseTrainData(string FileName, System.Text.Encoding Encodi
152152
Train.Handles.EmergencyBrake = new TrainManager.EmergencyHandle();
153153
Train.Handles.HasLocoBrake = false;
154154
double[] powerDelayUp = { }, powerDelayDown = { }, brakeDelayUp = { }, brakeDelayDown = { }, locoBrakeDelayUp = { }, locoBrakeDelayDown = { };
155+
int numberOfPantographs = 1;
156+
double pantographLocation = -1;
155157
int powerNotches = 0, brakeNotches = 0, locoBrakeNotches = 0, powerReduceSteps = -1, locoBrakeType = 0, driverPowerNotches = 0, driverBrakeNotches = 0;
156158
TrainManager.MotorSoundTable[] Tables = new TrainManager.MotorSoundTable[4];
157159
for (int i = 0; i < 4; i++) {
@@ -675,6 +677,20 @@ internal static void ParseTrainData(string FileName, System.Text.Encoding Encodi
675677
} else {
676678
CarUnexposedFrontalArea = a;
677679
} break;
680+
case 11:
681+
if (a <= 0.0)
682+
{
683+
Interface.AddMessage(MessageType.Error, false, "NumberOfPantographs is expected to be positive at line " + (i + 1).ToString(Culture) + " in " + FileName);
684+
}
685+
else
686+
{
687+
numberOfPantographs = (int)a;
688+
}
689+
break;
690+
case 12:
691+
//Do no validation here, as we don't necessarily yet know the length of a car
692+
pantographLocation = a;
693+
break;
678694
}
679695
} i++; n++;
680696
} i--; break;
@@ -961,10 +977,18 @@ internal static void ParseTrainData(string FileName, System.Text.Encoding Encodi
961977
MaximumAcceleration = AccelerationCurves[i].StageOneAcceleration;
962978
}
963979
}
980+
981+
if (pantographLocation < 0 || pantographLocation > CarLength)
982+
{
983+
//Pantograph location is relative from the front of the car
984+
//Somone will probably want to add one outside the physical model, so just warn...
985+
Interface.AddMessage(MessageType.Warning, false, "A PantographLocation of " + pantographLocation.ToString(Culture) + " places it outside the bounds of the car in file " + FileName);
986+
}
964987
// assign motor cars
965988
if (MotorCars == 1) {
966989
if (FrontCarIsMotorCar | TrailerCars == 0) {
967990
Train.Cars[0].Specs.IsMotorCar = true;
991+
Train.Cars[0].Pantograph = new TrackFollower(Program.CurrentHost);
968992
} else {
969993
Train.Cars[Cars - 1].Specs.IsMotorCar = true;
970994
}
@@ -1184,15 +1208,9 @@ internal static void ParseTrainData(string FileName, System.Text.Encoding Encodi
11841208
{
11851209
Train.Cars[i].Coupler = new TrainManager.Coupler(0.9 * DistanceBetweenTheCars, 1.1 * DistanceBetweenTheCars, Train.Cars[i / 2], null, Train);
11861210
}
1187-
1188-
Train.Cars[i].CurrentCarSection = -1;
1189-
Train.Cars[i].ChangeCarSection(CarSectionType.NotVisible);
1190-
Train.Cars[i].FrontBogie.ChangeSection(-1);
1191-
Train.Cars[i].RearBogie.ChangeSection(-1);
1192-
Train.Cars[i].Coupler.ChangeSection(-1);
1211+
11931212
Train.Cars[i].FrontAxle.Follower.TriggerType = i == 0 ? EventTriggerType.FrontCarFrontAxle : EventTriggerType.OtherCarFrontAxle;
11941213
Train.Cars[i].RearAxle.Follower.TriggerType = i == Cars - 1 ? EventTriggerType.RearCarRearAxle : EventTriggerType.OtherCarRearAxle;
1195-
Train.Cars[i].BeaconReceiver.TriggerType = i == 0 ? EventTriggerType.TrainFront : EventTriggerType.None;
11961214
Train.Cars[i].BeaconReceiverPosition = 0.5 * CarLength;
11971215
Train.Cars[i].FrontAxle.Follower.Car = Train.Cars[i];
11981216
Train.Cars[i].RearAxle.Follower.Car = Train.Cars[i];

source/OpenBVE/Simulation/TrainManager/Car/Car.Bogie.cs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ internal Bogie(Train train, Car car)
4444
CarSections = new CarSection[] { };
4545
FrontAxle = new Axle(Program.CurrentHost, train, car);
4646
RearAxle = new Axle(Program.CurrentHost, train, car);
47+
ChangeSection(-1);
4748
}
4849

4950
internal void UpdateObjects(double TimeElapsed, bool ForceUpdate)

source/OpenBVE/Simulation/TrainManager/Car/Car.cs

+24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using LibRender2;
34
using LibRender2.Camera;
45
using LibRender2.Cameras;
@@ -52,7 +53,10 @@ internal partial class Car : AbstractCar
5253
internal Coupler Coupler;
5354

5455
internal double BeaconReceiverPosition;
56+
/// <summary>Recieves all safety system beacons</summary>
5557
internal TrackFollower BeaconReceiver;
58+
/// <summary>Provides current collection etc.</summary>
59+
internal TrackFollower Pantograph;
5660
/// <summary>Whether loading sway is enabled for this car</summary>
5761
internal bool EnableLoadingSway = true;
5862
/// <summary>A reference to the base train</summary>
@@ -66,6 +70,23 @@ internal partial class Car : AbstractCar
6670
internal CameraAlignment InteriorCamera;
6771

6872
internal bool HasInteriorView = false;
73+
74+
public override Dictionary<PowerSupplyTypes, PowerSupply> AvailablePowerSupplies
75+
{
76+
get
77+
{
78+
if (Pantograph != null)
79+
{
80+
return Pantograph.AvailablePowerSupplies;
81+
}
82+
else
83+
{
84+
//Not fitted, so return empty collection
85+
return new Dictionary<PowerSupplyTypes, PowerSupply>();
86+
}
87+
88+
}
89+
}
6990

7091
internal Car(Train train, int index, double CoefficientOfFriction, double CoefficientOfRollingResistance, double AerodynamicDragCoefficient)
7192
{
@@ -75,13 +96,16 @@ internal Car(Train train, int index, double CoefficientOfFriction, double Coeffi
7596
FrontAxle = new Axle(Program.CurrentHost, train, this, CoefficientOfFriction, CoefficientOfRollingResistance, AerodynamicDragCoefficient);
7697
RearAxle = new Axle(Program.CurrentHost, train, this, CoefficientOfFriction, CoefficientOfRollingResistance, AerodynamicDragCoefficient);
7798
BeaconReceiver = new TrackFollower(Program.CurrentHost, train);
99+
BeaconReceiver.TriggerType = index == 0 ? EventTriggerType.TrainFront : EventTriggerType.None;
78100
FrontBogie = new Bogie(train, this);
79101
RearBogie = new Bogie(train, this);
80102
Doors = new Door[2];
81103
Doors[0].Width = 1000.0;
82104
Doors[0].MaxTolerance = 0.0;
83105
Doors[1].Width = 1000.0;
84106
Doors[1].MaxTolerance = 0.0;
107+
CurrentCarSection = -1;
108+
ChangeCarSection(CarSectionType.NotVisible);
85109
}
86110

87111
internal Car(Train train, int index)

0 commit comments

Comments
 (0)