diff --git a/Source/Orts.Simulation/Simulation/Physics/Train.cs b/Source/Orts.Simulation/Simulation/Physics/Train.cs index 2407b05b33..6eaa3bf2dd 100644 --- a/Source/Orts.Simulation/Simulation/Physics/Train.cs +++ b/Source/Orts.Simulation/Simulation/Physics/Train.cs @@ -439,7 +439,6 @@ public enum END_AUTHORITY public Simulator Simulator { get; protected set; } // reference to the simulator - // For AI control of the train public float AITrainBrakePercent { @@ -552,7 +551,6 @@ public virtual bool GetWagonsAttachedIndication() // // Constructor // - void Init(Simulator simulator) { Simulator = simulator; @@ -582,7 +580,6 @@ public Train(Simulator simulator) // Constructor for Dummy entries used on restore // Signals is restored before Trains, links are restored by Simulator // - public Train(Simulator simulator, int number) { Init(simulator); @@ -597,7 +594,6 @@ public Train(Simulator simulator, int number) // Constructor for uncoupled trains // copy path info etc. from original train // - public Train(Simulator simulator, Train orgTrain) { Init(simulator); @@ -657,7 +653,6 @@ public Train(Simulator simulator, Train orgTrain) { StationStops = null; } - } /// @@ -729,7 +724,6 @@ public Train(Simulator simulator, BinaryReader inf) } CheckFreight(); - SignalObjectItems = new List(); signalRef = simulator.Signals; @@ -1264,7 +1258,6 @@ private void SaveAuxContainer(BinaryWriter outf) AuxActionsContain.Save(outf, Convert.ToInt32(Math.Floor(Simulator.ClockTime))); } - //================================================================================================// /// /// Changes the Lead locomotive (i.e. the loco which the player controls) to the next in the consist. @@ -1429,7 +1422,6 @@ private bool SkipOtherUsersCar(int i) /// /// Flips the train if necessary so that the train orientation matches the lead locomotive cab direction /// - // public void Orient() // { // TrainCar lead = LeadLocomotive; @@ -1467,7 +1459,6 @@ private bool SkipOtherUsersCar(int i) /// Only performed when train activates a reversal point /// NOTE : this routine handles the physical train orientation only, all related route settings etc. must be handled separately /// - public void ReverseFormation(bool setMUParameters) { if (MPManager.IsMultiPlayer()) MPManager.BroadCast((new MSGFlip(this, setMUParameters, Number)).ToString()); // message contains data before flip @@ -1730,7 +1721,6 @@ protected void DistributedPowerUpdate() DPIdle(); } - //================================================================================================// /// /// Someone is sending an event notification to all cars on this train. @@ -1765,7 +1755,6 @@ public void SignalEvent(PowerSupplyEvent evt, int id) /// /// Set starting conditions when speed > 0 /// <\summary> - public virtual void InitializeMoving() { ColdStart = false; @@ -1809,7 +1798,6 @@ public virtual void InitializeMoving() /// /// Set starting conditions for TrainCars when speed > 0 /// <\summary> - public void TraincarsInitializeMoving() { for (int i = 0; i < Cars.Count; ++i) @@ -1823,7 +1811,6 @@ public void TraincarsInitializeMoving() /// /// Update train /// <\summary> - public virtual void Update(float elapsedClockSeconds, bool auxiliaryUpdate = true) { if (!auxiliaryUpdate) @@ -1836,14 +1823,12 @@ public virtual void Update(float elapsedClockSeconds, bool auxiliaryUpdate = tru CheckStationTask(); } - if (IsActualPlayerTrain && Simulator.Settings.ActRandomizationLevel > 0 && Simulator.ActivityRun != null) // defects might occur { CheckFailures(elapsedClockSeconds); } // Update train physics, position and movement - physicsUpdate(elapsedClockSeconds); // Update the UiD of First Wagon @@ -1869,17 +1854,14 @@ public virtual void Update(float elapsedClockSeconds, bool auxiliaryUpdate = tru { UpdateTurntable(elapsedClockSeconds); } - else if (ControlMode == TRAIN_CONTROL.MANUAL) // manual mode { UpdateManual(elapsedClockSeconds); } - else if (ControlMode == TRAIN_CONTROL.EXPLORER) // explorer mode { UpdateExplorer(elapsedClockSeconds); } - else if (ValidRoute[0] != null && GetAIMovementState() != AITrain.AI_MOVEMENT_STATE.AI_STATIC) // no actions required for static objects // { if (ControlMode != TRAIN_CONTROL.OUT_OF_CONTROL) movedBackward = CheckBackwardClearance(); // check clearance at rear if not out of control // @@ -1914,19 +1896,16 @@ public virtual void Update(float elapsedClockSeconds, bool auxiliaryUpdate = tru DistributedPowerUpdate(); // log train details - if (DatalogTrainSpeed) { LogTrainSpeed(Simulator.ClockTime); } - } // end Update //================================================================================================// /// /// Update train physics /// <\summary> - public virtual void physicsUpdate(float elapsedClockSeconds) { //if out of track, will set it to stop @@ -2001,7 +1980,6 @@ public virtual void physicsUpdate(float elapsedClockSeconds) { car.HUDBrakeSkid = false; } - } if (car.CouplerExceedBreakLimit) @@ -2044,7 +2022,6 @@ public virtual void physicsUpdate(float elapsedClockSeconds) else numOfCouplerBreaksNoted = false; - UpdateCarSteamHeat(elapsedClockSeconds); UpdateCarElectricHeatingAndAirConditioning(elapsedClockSeconds); UpdateAuxTender(); @@ -2109,7 +2086,6 @@ public virtual void physicsUpdate(float elapsedClockSeconds) /// /// Update Wind components for the train /// <\summary> - public void UpdateWindComponents() { // Gets wind direction and speed, and determines HUD display values for the train as a whole. @@ -2150,15 +2126,12 @@ public void UpdateWindComponents() WindResultantSpeedMpS = (float)Math.Sqrt(TrainSpeedMpS * TrainSpeedMpS + PhysicsWindSpeedMpS * PhysicsWindSpeedMpS + 2.0f * TrainSpeedMpS * PhysicsWindSpeedMpS * (float)Math.Cos(WindAngleRad)); } - //================================================================================================// /// /// Update Auxiliary Tenders added to train /// <\summary> - public void UpdateAuxTender() { - var mstsSteamLocomotive = Cars[0] as MSTSSteamLocomotive; // Don't process if locomotive is not steam locomotive if (mstsSteamLocomotive != null) { @@ -2166,7 +2139,6 @@ public void UpdateAuxTender() // Calculate when an auxiliary tender is coupled to train for (int i = 0; i < Cars.Count; i++) { - if (Cars[i].AuxWagonType == "AuxiliaryTender" && i > LeadLocomotiveIndex && IsPlayerDriven) // If value has been entered for auxiliary tender & AuxTender car value is greater then the lead locomotive & and it is player driven { PrevWagonType = Cars[i - 1].AuxWagonType; @@ -2180,7 +2152,6 @@ public void UpdateAuxTender() mstsSteamLocomotive.CurrentAuxTenderWaterMassKG = Cars[i].AuxTenderWaterMassKG * (Simulator.Activity.Tr_Activity.Tr_Activity_Header.FuelWater / 100.0f); // IsAuxTenderCoupled = true; // Flag to advise MSTSSteamLovcomotive that tender is set. AuxTenderFound = true; // Auxililary tender found in consist. - } else // Otherwise assume aux tender not connected at start of activity and therefore full value of water mass available when connected. { @@ -2196,17 +2167,13 @@ public void UpdateAuxTender() mstsSteamLocomotive.CurrentAuxTenderWaterMassKG = Cars[i].AuxTenderWaterMassKG; IsAuxTenderCoupled = true; AuxTenderFound = true; // Auxililary tender found in consist. - } - - } else // Aux tender not found in consist { MaxAuxTenderWaterMassKG = 0.0f; IsAuxTenderCoupled = false; } - } #if DEBUG_AUXTENDER @@ -2215,7 +2182,6 @@ public void UpdateAuxTender() Trace.TraceInformation("CarID {0} AuxWagonType {1} LeadLocomotive {2} Max WaterMass {3} Current Water Mass {4}", i, Cars[i].AuxWagonType, LeadLocomotiveIndex, MaxAuxTenderWaterMassKG, mstsSteamLocomotive.CurrentAuxTenderWaterMassKG); Trace.TraceInformation("Prev {0} Coupled {1}", PrevWagonType, IsAuxTenderCoupled); #endif - } if (AuxTenderFound == false && IsAuxTenderCoupled == true) // If an auxiliary tender is not found in the consist, then assume that it has been uncoupled @@ -2224,10 +2190,8 @@ public void UpdateAuxTender() IsAuxTenderCoupled = false; } } - } - //================================================================================================// /// /// Update Steam Heating - this model calculates the total train heat losses and gains for all the cars @@ -2247,13 +2211,11 @@ public void UpdateAuxTender() // subtracted from this value. Heat gain from the radiation heat exchange area are added to this value. If all is ok then a balance should be achieved. // Leaks in system, loss of heat (and pressure) as steam moves along train - public void UpdateCarSteamHeat(float elapsedClockSeconds) { var mstsLocomotive = Simulator.PlayerLocomotive as MSTSLocomotive; if (mstsLocomotive != null) { - if (IsFirstTimeBoilerCarAttached) { foreach (TrainCar car in Cars) @@ -2417,11 +2379,9 @@ public void UpdateCarSteamHeat(float elapsedClockSeconds) Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetStringFmt("Car {0} temperature is too cold for the freight.", car.CarID)); } } - } else if (car.CarInsideTempC > C.FromF(65.0f)) { - IsSteamHeatLow = false; // Reset temperature warning } } @@ -2521,7 +2481,6 @@ public void UpdateCarElectricHeatingAndAirConditioning(float elapsedClockSeconds /// /// ProcessTunnels : check position of each car in train wrt tunnel /// <\summary> - public void ProcessTunnels() { // start at front of train @@ -2645,7 +2604,6 @@ public void ProcessTunnels() /// /// Train speed evaluation logging - open file /// <\summary> - public void CreateLogFile() { //Time, Train Speed, Max Speed, Signal Aspect, Elevation, Direction, Control Mode, Distance Travelled, Throttle, Brake, Dyn Brake, Gear @@ -2746,7 +2704,6 @@ public void CreateLogFile() /// /// Train speed evaluation logging /// <\summary> - public void LogTrainSpeed(double clockTime) { int clockInt = Convert.ToInt32(clockTime); @@ -2876,7 +2833,6 @@ public void LogTrainSpeed(double clockTime) /// /// Update in manual mode /// <\summary> - public void UpdateManual(float elapsedClockSeconds) { UpdateTrainPosition(); // position update // @@ -2905,7 +2861,6 @@ public void UpdateManual(float elapsedClockSeconds) /// /// Update in explorer mode /// <\summary> - public void UpdateExplorer(float elapsedClockSeconds) { UpdateTrainPosition(); // position update // @@ -2934,7 +2889,6 @@ public void UpdateExplorer(float elapsedClockSeconds) /// /// Update in turntable mode /// <\summary> - public void UpdateTurntable(float elapsedClockSeconds) { if (LeadLocomotive is MSTSLocomotive locomotive && (LeadLocomotive.ThrottlePercent >= 1 || Math.Abs(LeadLocomotive.SpeedMpS) > 0.05 || !(LeadLocomotive.Direction == Direction.N @@ -2949,12 +2903,9 @@ public void UpdateTurntable(float elapsedClockSeconds) /// /// Post Init : perform all actions required to start /// - public virtual bool PostInit() { - // if train has no valid route, build route over trainlength (from back to front) - bool validPosition = InitialTrainPlacement(); if (validPosition) @@ -2967,14 +2918,11 @@ public virtual bool PostInit() AuxActionsContain.SetAuxAction(this); } - // set train speed logging flag (valid per activity, so will be restored after save) - if (IsActualPlayerTrain) { SetTrainSpeedLoggingFlag(); - // if debug, print out all passing paths #if DEBUG_DEADLOCK @@ -2989,7 +2937,6 @@ public virtual bool PostInit() /// /// set train speed logging flag (valid per activity, so will be restored after save) /// - protected void SetTrainSpeedLoggingFlag() { DatalogTrainSpeed = Simulator.Settings.DataLogTrainSpeed; @@ -3017,7 +2964,6 @@ protected void SetTrainSpeedLoggingFlag() /// /// get aspect of next signal ahead /// - public MstsSignalAspect GetNextSignalAspect(int direction) { MstsSignalAspect thisAspect = MstsSignalAspect.STOP; @@ -3033,7 +2979,6 @@ public MstsSignalAspect GetNextSignalAspect(int direction) /// /// initialize signal array /// - public void InitializeSignals(bool existingSpeedLimits) { Debug.Assert(signalRef != null, "Cannot InitializeSignals() without Simulator.Signals."); @@ -3046,7 +2991,6 @@ public void InitializeSignals(bool existingSpeedLimits) IndexNextSpeedlimit = -1; // set overall speed limits if these do not yet exist - if (!existingSpeedLimits) { if ((TrainMaxSpeedMpS <= 0f) && (this.LeadLocomotive != null)) @@ -3219,11 +3163,8 @@ public void InitializeSignals(bool existingSpeedLimits) } } - // // get first signal and first speedlimit // also initiate nextSignal variable - // - bool signalFound = false; bool speedlimFound = false; @@ -3250,11 +3191,8 @@ public void InitializeSignals(bool existingSpeedLimits) } } - // // If signal in list, set signal reference, // else try to get first signal if in signal mode - // - NextSignalObject[0] = null; if (IndexNextSignal >= 0) { @@ -3275,10 +3213,7 @@ public void InitializeSignals(bool existingSpeedLimits) } } - // // determine actual speed limits depending on overall speed and type of train - // - UpdateSpeedInfo(); } @@ -3351,7 +3286,6 @@ public void UpdateSignalState(int backward) tempMaxSpeedMps = AllowedMaxSpeedMpS; } - if (firstObject.ObjectDetails.Type == SignalObjectType.Signal) { allowedMaxSpeedSignalMpS = tempMaxSpeedMps; @@ -3429,7 +3363,6 @@ public void UpdateSignalState(int backward) // if moving backward, check signals have been passed if (backward > backwardThreshold) { - int newSignalIndex = -1; bool noMoreNewSignals = false; @@ -3756,7 +3689,6 @@ public void UpdateSignalState(int backward) /// /// set actual speed limit for all objects depending on state and type of train /// - public void UpdateSpeedInfo() { float validSpeedMpS = AllowedMaxSpeedMpS; @@ -3765,7 +3697,6 @@ public void UpdateSpeedInfo() float validTempSpeedLimitMpS = allowedMaxTempSpeedLimitMpS; // update valid speed with pending actions - foreach (var thisAction in requiredActions) { if (thisAction is ActivateSpeedLimit) @@ -3789,13 +3720,9 @@ public void UpdateSpeedInfo() } // loop through objects - foreach (ObjectItemInfo thisObject in SignalObjectItems) { - // // select speed on type of train - // - float actualSpeedMpS = IsFreight ? thisObject.speed_freight : thisObject.speed_passenger; if (thisObject.ObjectDetails.Type == SignalObjectType.Signal) @@ -3862,7 +3789,6 @@ public void UpdateSpeedInfo() thisObject.actual_speed = Math.Min(actualSpeedMpS, TrainMaxSpeedMpS); } } - else if (!thisObject.speed_isWarning) // Enhanced Compatibility on & SpeedLimit { if (actualSpeedMpS > 998f) @@ -3935,7 +3861,6 @@ public void UpdateSpeedInfo() /// /// Initialize brakes /// <\summary> - public virtual void InitializeBrakes() { if (Math.Abs(SpeedMpS) > 0.1) @@ -4052,7 +3977,6 @@ public void UnconditionalInitializeBrakes() /// /// Set handbrakes /// <\summary> - public void SetHandbrakePercent(float percent) { if (SpeedMpS < -.1 || SpeedMpS > .1) @@ -4065,7 +3989,6 @@ public void SetHandbrakePercent(float percent) /// /// Connect brake hoses when train is initialised /// <\summary> - public void ConnectBrakeHoses() { for (var i = 0; i < Cars.Count; i++) @@ -4090,7 +4013,6 @@ public void ConnectBrakeHoses() /// /// Disconnect brakes /// <\summary> - public void DisconnectBrakes() { if (SpeedMpS < -.1 || SpeedMpS > .1) @@ -4108,7 +4030,6 @@ public void DisconnectBrakes() /// /// Set retainers /// <\summary> - public void SetRetainers(bool increase) { if (SpeedMpS < -.1 || SpeedMpS > .1) @@ -4158,7 +4079,6 @@ public void SetRetainers(bool increase) // engine brake pipe pressure will be propagated. It only identifies multiple units when coupled directly together, // for example a double headed steam locomotive will most often have a tender separating the two locomotives, // so the second locomotive will not be identified, nor will a locomotive added at the rear of the train. - public void FindLeadLocomotives(out int first, out int last) { first = last = -1; @@ -4171,13 +4091,10 @@ public void FindLeadLocomotives(out int first, out int last) } // If first (lead) locomotive is a steam locomotive check to see if the engine brake needs to be extended to cover the tender - if (first != -1) // if lead locomotive is set at initialised value, then don't attempt to process engine brake extension { - if (Cars[first] is MSTSSteamLocomotive) { - // If double headed tank steam locomotive (no tender is attached) then only apply engine brake to first locomotive for consistency if (last != first && Cars[first] is MSTSSteamLocomotive && Cars[last] is MSTSSteamLocomotive) { @@ -4221,7 +4138,6 @@ public TrainCar FindLeadLocomotive() /// /// Propagate brake pressure /// <\summary> - public void PropagateBrakePressure(float elapsedClockSeconds) { if (LeadLocomotive is MSTSLocomotive lead) @@ -4267,7 +4183,6 @@ private void AISetUniformBrakePressures() /// /// Cars have been added to the rear of the train, recalc the rearTDBtraveller /// - public void RepositionRearTraveller() { var traveller = new Traveller(FrontTDBTraveller, Traveller.TravellerDirection.Backward); @@ -4345,12 +4260,10 @@ public void RepositionRearTraveller() Length = length; } // RepositionRearTraveller - //================================================================================================// /// /// Check if train is passenger or freight train /// - public void CheckFreight() { IsFreight = false; @@ -4377,7 +4290,6 @@ public void CalculatePositionOfCars() /// Distance is the signed distance the cars are moving. /// /// - public void CalculatePositionOfCars(float elapsedTime, float distance) { if (float.IsNaN(distance)) distance = 0;//sanity check @@ -4441,7 +4353,6 @@ public void CalculatePositionOfCars(float elapsedTime, float distance) ++tileZ; } - // note the railcar sits 0.275meters above the track database path TODO - is this always consistent? car.WorldPosition.XNAMatrix = Matrix.Identity; if (car.Flipped) @@ -4473,7 +4384,6 @@ public void CalculatePositionOfCars(float elapsedTime, float distance) /// /// /// - public void CalculatePositionOfEOT() { var traveller = new Traveller(RearTDBTraveller, Traveller.TravellerDirection.Backward); @@ -4525,7 +4435,6 @@ public void CalculatePositionOfEOT() ++tileZ; } - // note the railcar sits 0.275meters above the track database path TODO - is this always consistent? car.WorldPosition.XNAMatrix = Matrix.Identity; if (car.Flipped) @@ -4554,7 +4463,6 @@ public void CalculatePositionOfEOT() /// Recalculate rear traveller when removing EOT /// /// - public void RecalculateRearTDBTraveller() { var traveller = new Traveller(RearTDBTraveller); @@ -4588,7 +4496,6 @@ public void RecalculateRearTDBTraveller() /// /// Sets this train's speed so that momentum is conserved when otherTrain is coupled to it /// <\summary> - public void SetCoupleSpeed(Train otherTrain, float otherMult) { float kg1 = 0; @@ -4611,12 +4518,10 @@ public void SetCoupleSpeed(Train otherTrain, float otherMult) car2.SpeedMpS = car2.Flipped ^ (car2.IsDriveable && car2.Train.IsActualPlayerTrain && ((MSTSLocomotive)car2).UsingRearCab) ? -SpeedMpS : SpeedMpS; } - //================================================================================================// /// /// setups of the left hand side of the coupler force solving equations /// <\summary> - void SetupCouplerForceEquations() { for (int i = 0; i < Cars.Count - 1; i++) @@ -4629,18 +4534,15 @@ void SetupCouplerForceEquations() } } - //================================================================================================// /// /// solves coupler force equations /// <\summary> - void SolveCouplerForceEquations() { float b = Cars[0].CouplerForceB; Cars[0].CouplerForceU = Cars[0].CouplerForceR / b; - for (int i = 1; i < Cars.Count - 1; i++) { Cars[i].CouplerForceG = Cars[i - 1].CouplerForceC / b; @@ -4652,16 +4554,13 @@ void SolveCouplerForceEquations() { Cars[i].CouplerForceU -= Cars[i + 1].CouplerForceG * Cars[i + 1].CouplerForceU; } - } - //================================================================================================// /// /// removes equations if forces don't match faces in contact /// returns true if a change is made /// <\summary> - bool FixCouplerForceEquations() { // This section zeroes coupler forces if either of the simple or advanced coupler are in Zone 1, ie coupler faces not touching yet. @@ -4721,7 +4620,6 @@ bool FixCouplerForceEquations() } else // "Simple coupler" - only operates on two extension zones, coupler faces not in contact, so set coupler forces to zero { - float maxs1 = car.GetMaximumSimpleCouplerSlack1M(); // In Zone 1 set coupler forces to zero, as coupler faces not touching, or if coupler force is in the opposite direction, ie in tension ( -ve CouplerForceU ) if (car.CouplerSlackM > -maxs1 || car.CouplerForceU < 0) @@ -4734,12 +4632,10 @@ bool FixCouplerForceEquations() return false; } - //================================================================================================// /// /// changes the coupler force equation for car to make the corresponding force equal to forceN /// <\summary> - static void SetCouplerForce(TrainCar car, float forceN) { car.CouplerForceA = car.CouplerForceC = 0; @@ -4752,7 +4648,6 @@ static void SetCouplerForce(TrainCar car, float forceN) /// removes equations if forces don't match faces in contact /// returns true if a change is made /// <\summary> - bool FixCouplerImpulseForceEquations() { // This section zeroes impulse coupler forces where there is a force mismatch, ie where coupler is in compression, and a tension force is applied, or vicer versa @@ -4816,12 +4711,10 @@ bool FixCouplerImpulseForceEquations() return false; } - //================================================================================================// /// /// computes and applies coupler impulse forces which force speeds to match when no relative movement is possible /// <\summary> - public void AddCouplerImpulseForces(float elapsedTime) { if (Cars.Count < 2) @@ -4845,7 +4738,6 @@ public void AddCouplerImpulseForces(float elapsedTime) else car.CouplerForceR = Cars[i + 1].SpeedMpS - car.SpeedMpS; } - else // Simple coupler - set impulse force to zero if coupler slack has not exceeded zone 2 limit { float max = car.CouplerSlack2M; @@ -4890,8 +4782,6 @@ public void AddCouplerImpulseForces(float elapsedTime) // Trace.TraceInformation("Last Car Zero Speed Set - CarID {0} - +ve set -ve", car.CarID); } } - - } else // Simple Coupler { @@ -4932,10 +4822,8 @@ public void AddCouplerImpulseForces(float elapsedTime) /// Coupler Force (CouplerForceU) : Fwd = -ve, Rev = +ve, Total Force (TotalForceN): Fwd = -ve, Rev = +ve /// /// <\summary> - public void ComputeCouplerForces(float elapsedTime) { - // TODO: this loop could be extracted and become a separate method, that could be called also by TTTrain.physicsPreUpdate for (int i = 0; i < Cars.Count; i++) { @@ -4954,13 +4842,11 @@ public void ComputeCouplerForces(float elapsedTime) // Calculate RH side coupler force // Whilever coupler faces not in contact, then "zero coupler force" by setting A = C = R = 0 // otherwise R is calculated based on difference in acceleration between cars, or stiffness and damping value - for (int i = 0; i < Cars.Count - 1; i++) { TrainCar car = Cars[i]; if (car.IsPlayerTrain && !Simulator.Settings.SimpleControlPhysics && car.IsAdvancedCoupler) // "Advanced coupler" - operates in three extension zones { - //Force on coupler is set so that no force is applied until coupler faces come into contact with each other float MaxZ1TensionM = car.GetMaximumCouplerTensionSlack1M(); float MaxZ1CompressionM = -car.GetMaximumCouplerCompressionSlack1M(); @@ -4976,7 +4862,6 @@ public void ComputeCouplerForces(float elapsedTime) { car.CouplerForceR = Cars[i + 1].TotalForceN / Cars[i + 1].MassKG - car.TotalForceN / car.MassKG; } - } else // "Simple coupler" - only operates on two extension zones, coupler faces not in contact, so set coupler forces to zero { @@ -4996,8 +4881,6 @@ public void ComputeCouplerForces(float elapsedTime) SolveCouplerForceEquations(); while (FixCouplerForceEquations()); - - for (int i = 0; i < Cars.Count - 1; i++) { // Calculate total forces on cars @@ -5035,7 +4918,6 @@ public void ComputeCouplerForces(float elapsedTime) if (car.IsPlayerTrain && !Simulator.Settings.SimpleControlPhysics && car.IsAdvancedCoupler) // "Advanced coupler" - operates in three extension zones { - // Note different slack lengths can be used depending upon whether the coupler is in tension or compression // Rigid couplers use a fixed limit, and there is no variation. float MaxZ1TensionM = car.GetMaximumCouplerTensionSlack1M(); @@ -5078,7 +4960,6 @@ public void ComputeCouplerForces(float elapsedTime) { if (!IsRigidCoupler) { - if (IndividualCouplerSlackM < 0 && FirstCar.SpeedMpS > 0 && LastCar.SpeedMpS >= LastCarZeroSpeedMpS && LastCar.SpeedMpS < LastCarTensionMoveSpeedMpS && LeadLocomotive.Direction == Direction.Forward) { // Whilst train is starting in forward direction, don't allow negative coupler slack. @@ -5105,7 +4986,6 @@ public void ComputeCouplerForces(float elapsedTime) car.AdvancedCouplerDynamicCompressionSlackLimitM = car.CouplerSlackM; } } - else if (IndividualCouplerSlackM > MaxZ1TensionM && IndividualCouplerSlackM <= MaxZ3TensionM) { // A linear curve is assumed for coupler stiffness - this curve is then used to calculate the amount of slack that the coupler should have. @@ -5229,7 +5109,6 @@ public void ComputeCouplerForces(float elapsedTime) } } } - else if (car.SmoothedCouplerForceUN == 0) // In this instance the coupler slack must be greater then the Z1 limit, as no coupler force is generated, and train will not move. { if (car.SpeedMpS == 0) @@ -5434,7 +5313,6 @@ public void ComputeCouplerForces(float elapsedTime) /// /// Update Car speeds /// <\summary> - public void UpdateCarSpeeds(float elapsedTime) { // The train speed is calculated by averaging all the car speeds. The individual car speeds are calculated from the TotalForce acting on each car. @@ -5502,9 +5380,7 @@ public void UpdateCarSpeeds(float elapsedTime) if (n == 0) return; - // // start a car moving forward when it is stationary, once it is moving this whole section is skipped - // for (int i = 0; i < Cars.Count; i++) { TrainCar car = Cars[i]; @@ -5539,8 +5415,6 @@ public void UpdateCarSpeeds(float elapsedTime) { for (int k = i; k <= j; k++) { - - if ((Cars[k].CarBrakeSystemType == "air_piped" || Cars[k].CarBrakeSystemType == "vacuum_piped" || car.CarBrakeSystemType == "manual_braking") && FirstCar.SpeedMpS > 0 && Cars[k-1].SpeedMpS == 0.0) { // If is manual braked, air_piped car or vacuum_piped, and preceeding car is at stop, then set speed to zero. These type of cars do not have any brake force to hold them still @@ -5551,7 +5425,6 @@ public void UpdateCarSpeeds(float elapsedTime) // Start this stationary car Cars[k].SpeedMpS = f / m * elapsedTime; } - } n -= j - i + 1; } @@ -5559,9 +5432,7 @@ public void UpdateCarSpeeds(float elapsedTime) if (n == 0) return; - // // start cars moving backward when it is stationary, once it is moving it skips this whole section - // for (int i = Cars.Count - 1; i >= 0; i--) { TrainCar car = Cars[i]; @@ -5596,7 +5467,6 @@ public void UpdateCarSpeeds(float elapsedTime) { for (int k = j; k <= i; k++) { - if ((Cars[k].CarBrakeSystemType == "air_piped" || Cars[k].CarBrakeSystemType == "vacuum_piped" || car.CarBrakeSystemType == "manual_braking") && FirstCar.SpeedMpS > 0 && Cars[k - 1].SpeedMpS == 0.0) { // If is manual braked, air_piped car or vacuum_piped, and preceeding car is at stop, then set speed to zero. These type of cars do not have any brake force to hold them still @@ -5616,7 +5486,6 @@ public void UpdateCarSpeeds(float elapsedTime) /// /// Update coupler slack - ensures that coupler slack doesn't exceed the maximum permissible value, and provides indication to HUD /// <\summary> - public void UpdateCouplerSlack(float elapsedTime) { TotalCouplerSlackM = 0; @@ -5630,7 +5499,6 @@ public void UpdateCouplerSlack(float elapsedTime) car.CouplerSlackM += (car.SpeedMpS - Cars[i + 1].SpeedMpS) * elapsedTime; // Make sure that coupler slack does not exceed the maximum (dynamic) coupler slack - if (car.IsPlayerTrain && !Simulator.Settings.SimpleControlPhysics && car.IsAdvancedCoupler) // "Advanced coupler" - operates in three extension zones { float AdvancedCouplerCompressionLimitM = car.AdvancedCouplerDynamicCompressionSlackLimitM; @@ -5638,7 +5506,6 @@ public void UpdateCouplerSlack(float elapsedTime) if (car.CouplerSlackM < AdvancedCouplerCompressionLimitM) // Compression car.CouplerSlackM = AdvancedCouplerCompressionLimitM; - else if (car.CouplerSlackM > AdvancedCouplerTensionLimitM) // Tension car.CouplerSlackM = AdvancedCouplerTensionLimitM; } @@ -5685,7 +5552,6 @@ public void UpdateCouplerSlack(float elapsedTime) if (!car.GetCouplerRigidIndication()) // Flexible coupling - pulling and pushing value will be equal to slack when couplers faces touch { - if (car.CouplerSlackM >= 0.001) // Coupler pulling { NPull++; @@ -5717,9 +5583,7 @@ public void UpdateCouplerSlack(float elapsedTime) { car.HUDCouplerForceIndication = 0; // Coupler neutral } - } - } int j = 0; @@ -5757,7 +5621,6 @@ public void UpdateCouplerSlack(float elapsedTime) { Cars[j].CarAhead = Cars[j - 1]; Cars[j].CarBehind = Cars[j + 1]; - } j = j + 1; @@ -5769,12 +5632,9 @@ public void UpdateCouplerSlack(float elapsedTime) /// /// Calculate initial position /// - public virtual TCSubpathRoute CalculateInitialTrainPosition(ref bool trackClear) { - // calculate train length - float trainLength = 0f; for (var i = Cars.Count - 1; i >= 0; --i) @@ -5788,7 +5648,6 @@ public virtual TCSubpathRoute CalculateInitialTrainPosition(ref bool trackClear) } // get starting position and route - TrackNode tn = RearTDBTraveller.TN; float offset = RearTDBTraveller.TrackNodeOffset; int direction = (int)RearTDBTraveller.Direction; @@ -5808,7 +5667,6 @@ public virtual TCSubpathRoute CalculateInitialTrainPosition(ref bool trackClear) } // create route if train has none - if (ValidRoute[0] == null) { ValidRoute[0] = signalRef.BuildTempRoute(this, thisSection.Index, PresentPosition[1].TCOffset, @@ -5816,7 +5674,6 @@ public virtual TCSubpathRoute CalculateInitialTrainPosition(ref bool trackClear) } // find sections - bool sectionAvailable = true; float remLength = trainLength; int routeIndex = ValidRoute[0].GetRouteIndex(PresentPosition[1].TCSectionIndex, 0); @@ -5859,7 +5716,6 @@ public virtual TCSubpathRoute CalculateInitialTrainPosition(ref bool trackClear) sectionAvailable = false; } } - } trackClear = true; @@ -5878,12 +5734,9 @@ public virtual TCSubpathRoute CalculateInitialTrainPosition(ref bool trackClear) // // Set initial train route // - public void SetInitialTrainRoute(TCSubpathRoute tempRoute) { - // reserve sections, use direction 0 only - foreach (TCRouteElement thisElement in tempRoute) { TrackCircuitSection thisSection = signalRef.TrackCircuitList[thisElement.TCSectionIndex]; @@ -5895,12 +5748,9 @@ public void SetInitialTrainRoute(TCSubpathRoute tempRoute) // // Reset initial train route // - public void ResetInitialTrainRoute(TCSubpathRoute tempRoute) { - // unreserve sections - foreach (TCRouteElement thisElement in tempRoute) { TrackCircuitSection thisSection = signalRef.TrackCircuitList[thisElement.TCSectionIndex]; @@ -5912,7 +5762,6 @@ public void ResetInitialTrainRoute(TCSubpathRoute tempRoute) // // Initial train placement // - public virtual bool InitialTrainPlacement() { // for initial placement, use direction 0 only @@ -5934,7 +5783,6 @@ public virtual bool InitialTrainPlacement() PresentPosition[1].SetTCPosition(tn.TCCrossReference, offset, direction); // check if train has route, if not create dummy - if (ValidRoute[0] == null) { ValidRoute[0] = signalRef.BuildTempRoute(this, PresentPosition[1].TCSectionIndex, PresentPosition[1].TCOffset, @@ -5942,7 +5790,6 @@ public virtual bool InitialTrainPlacement() } // get index of first section in route - int rearIndex = ValidRoute[0].GetRouteIndex(PresentPosition[1].TCSectionIndex, 0); if (rearIndex < 0) { @@ -5956,7 +5803,6 @@ public virtual bool InitialTrainPlacement() PresentPosition[1].RouteListIndex = rearIndex; // get index of front of train - int frontIndex = ValidRoute[0].GetRouteIndex(PresentPosition[0].TCSectionIndex, 0); if (frontIndex < 0) { @@ -5967,13 +5813,11 @@ public virtual bool InitialTrainPlacement() PresentPosition[0].RouteListIndex = frontIndex; // check if train can be placed - // get index of section in train route // - + // get index of section in train route int routeIndex = rearIndex; List placementSections = new List(); // check if route is available - offset = PresentPosition[1].TCOffset; float remLength = Length; bool sectionAvailable = true; @@ -6001,7 +5845,6 @@ public virtual bool InitialTrainPlacement() sectionAvailable = false; } } - } else { @@ -6010,14 +5853,12 @@ public virtual bool InitialTrainPlacement() } // if not available - return - if (!sectionAvailable || placementSections.Count <= 0) { return (false); } // set any deadlocks for sections ahead of start with end beyond start - for (int iIndex = 0; iIndex < rearIndex; iIndex++) { int rearSectionIndex = ValidRoute[0][iIndex].TCSectionIndex; @@ -6039,7 +5880,6 @@ public virtual bool InitialTrainPlacement() } // set track occupied (if not done yet) - foreach (TrackCircuitSection thisSection in placementSections) { if (!thisSection.IsSet(routedForward, false)) @@ -6056,19 +5896,15 @@ public virtual bool InitialTrainPlacement() /// Set Formed Occupied /// Set track occupied for train formed out of other train /// - public void SetFormedOccupied() { - int rearIndex = PresentPosition[1].RouteListIndex; int frontIndex = PresentPosition[0].RouteListIndex; - int routeIndex = rearIndex; List placementSections = new List(); // route is always available as previous train was there - float offset = PresentPosition[1].TCOffset; float remLength = Length; @@ -6095,7 +5931,6 @@ public void SetFormedOccupied() } // set track occupied (if not done yet) - foreach (TrackCircuitSection thisSection in placementSections) { if (!thisSection.IsSet(routedForward, false)) @@ -6160,16 +5995,13 @@ public virtual bool CheckStationPosition(PlatformDetails thisPlatform, int stati return atStation; } - //================================================================================================// /// /// Update train position /// - public void UpdateTrainPosition() { // update positions - PresentPosition[0].CopyTo(ref PreviousPosition[0]); TrackNode tn = FrontTDBTraveller.TN; @@ -6210,12 +6042,9 @@ public void UpdateTrainPosition() /// Update Position linked information /// Switches train to Out_Of_Control if it runs out of path /// <\summary> - public void UpdateTrainPositionInformation() { - // check if train still on route - set train to OUT_OF_CONTROL - PresentPosition[0].DistanceTravelledM = DistanceTravelledM; PresentPosition[1].DistanceTravelledM = DistanceTravelledM - Length; @@ -6235,7 +6064,6 @@ public void UpdateTrainPositionInformation() /// compute boarding time for activity mode /// also check validity of depart time value /// <\summary> - public virtual bool ComputeTrainBoardingTime(StationStop thisStop, ref int stopTime) { stopTime = thisStop.ComputeStationBoardingTime(this); @@ -6276,9 +6104,7 @@ public float ComputeDistanceToNextStation(StationStop thisStation) int tempSectionTCSectionIndex; if (distanceToTrainM >= 0) { - // compute length of intermediate subpaths, if any, from reversal or section at beginning to reversal or section at end - for (int iSubpath = TCRoute.activeSubpath + 1; iSubpath < thisStation.SubrouteIndex; iSubpath++) { if (TCRoute.ReversalInfo[iSubpath - 1].Valid) @@ -6377,7 +6203,6 @@ public float ComputeDistanceToNextStation(StationStop thisStation) else distanceToTrainM += distanceFromStartOfsubPath; } } - else { // No enhanced compatibility, simple computation @@ -6390,12 +6215,10 @@ public float ComputeDistanceToNextStation(StationStop thisStation) return distanceToTrainM; } - //================================================================================================// /// /// Compute distance to reversal point /// <\summary> - public float ComputeDistanceToReversalPoint() { float lengthToGoM = -PresentPosition[0].TCOffset; @@ -6451,7 +6274,6 @@ public float ComputeDistanceToReversalPoint() /// /// Compute path length /// <\summary> - public float ComputePathLength() { float pathLength = 0; @@ -6494,12 +6316,10 @@ public float ComputePathLength() return pathLength; } - //================================================================================================// /// /// get list of required actions (only if not moving backward) /// - public void ObtainRequiredActions(int backward) { if (this is AITrain && (this as AITrain).MovementState == AITrain.AI_MOVEMENT_STATE.SUSPENDED) return; @@ -6527,10 +6347,8 @@ public void ObtainRequiredActions(int backward) /// Update section occupy states /// Input is backward movement counter /// - public void UpdateSectionState(int backward) { - sectionList.Clear(); int lastIndex = PreviousPosition[0].RouteListIndex; @@ -6543,14 +6361,12 @@ public void UpdateSectionState(int backward) int presentDTM = Convert.ToInt32(DistanceTravelledM); // don't bother with update if train out of control - all will be reset when train is stopped - if (ControlMode == TRAIN_CONTROL.OUT_OF_CONTROL) { return; } // don't bother with update if train off route - set train to out of control - if (presentIndex < 0) { SetTrainOutOfControl(OUTOFCONTROL.OUT_OF_PATH); @@ -6558,7 +6374,6 @@ public void UpdateSectionState(int backward) } // train moved backward - if (backward > backwardThreshold) { if (presentIndex < lastIndex) @@ -6578,9 +6393,7 @@ public void UpdateSectionState(int backward) sectionList.Add(new int[2] { presentIndex, presentDTM }); } } - // train moves forward - else { if (presentIndex > lastIndex) @@ -6606,7 +6419,6 @@ public void UpdateSectionState(int backward) } // set section states, for AUTOMODE use direction 0 only - foreach (int[] routeListIndex in sectionList) { int sectionIndex = ValidRoute[0][routeListIndex[0]].TCSectionIndex; @@ -6630,7 +6442,6 @@ public void UpdateSectionState(int backward) /// /// Change control mode of other trains in same section if needed /// - public void ChangeControlModeOtherTrains(TrackCircuitSection thisSection) { int otherdirection = -1; @@ -6658,13 +6469,11 @@ public void ChangeControlModeOtherTrains(TrackCircuitSection thisSection) /// Check if train went passed signal /// if so, and signal was at danger, set train Out_Of_Control /// - public int CheckSignalPassed(int direction, TCPosition trainPosition, TCPosition trainPreviousPos) { int passedSignalIndex = -1; if (NextSignalObject[direction] != null) { - while (NextSignalObject[direction] != null && !ValidRoute[direction].SignalIsAheadOfTrain(NextSignalObject[direction], trainPosition)) // signal not in front // { // correct route index if necessary @@ -6722,7 +6531,6 @@ public int CheckSignalPassed(int direction, TCPosition trainPosition, TCPosition SetTrainOutOfControl(OUTOFCONTROL.SPAD); break; } - else if (ControlMode == TRAIN_CONTROL.AUTO_SIGNAL && NextSignalObject[direction].sigfound[SignalFunction.NORMAL] < 0) // no next signal { SwitchToNodeControl(LastReservedSection[direction]); @@ -6797,7 +6605,6 @@ public int CheckSignalPassed(int direction, TCPosition trainPosition, TCPosition /// Check if train moves backward and if so, check clearance behindtrain /// If no save clearance left, set train to Out_Of_Control /// - public int CheckBackwardClearance() { bool outOfControl = false; @@ -6813,7 +6620,6 @@ public int CheckBackwardClearance() } // backward - if (presentIndex < lastIndex || (presentIndex == lastIndex && presentOffset < lastOffset)) { movedBackward = movedBackward < 2 * backwardThreshold ? ++movedBackward : movedBackward; @@ -6870,9 +6676,7 @@ public int CheckBackwardClearance() if (RearSignalObject != null) { - // create new position some 25 m. behind train as allowed overlap - TCPosition overlapPosition = new TCPosition(); PresentPosition[1].CopyTo(ref overlapPosition); TrackCircuitSection thisSection = signalRef.TrackCircuitList[overlapPosition.TCSectionIndex]; @@ -6925,7 +6729,6 @@ public int CheckBackwardClearance() outOfControl = true; // stop train in path - List trainsInSection = nextSection.CircuitState.TrainsOccupying(); foreach (TrainRouted nextTrain in trainsInSection) { @@ -6970,7 +6773,6 @@ public int CheckBackwardClearance() } return (movedBackward); - } //================================================================================================// @@ -6981,7 +6783,6 @@ public int CheckBackwardClearance() // Return parameter : true if train still exists (only used in timetable mode) /// // - public virtual bool CheckRouteActions(float elapsedClockSeconds) { int directionNow = PresentPosition[0].TCDirection; @@ -6997,7 +6798,6 @@ public virtual bool CheckRouteActions(float elapsedClockSeconds) if (!nextRoute[0]) return (true); // not at end of route // check if train reversed - if (nextRoute[1]) { if (positionNowBack == PresentPosition[0].TCSectionIndex && directionNowBack != PresentPosition[0].TCDirection) @@ -7013,7 +6813,6 @@ public virtual bool CheckRouteActions(float elapsedClockSeconds) } // check if next station was on previous subpath - if so, move to this subpath - if (nextRoute[1] && StationStops.Count > 0) { StationStop thisStation = StationStops[0]; @@ -7026,7 +6825,6 @@ public virtual bool CheckRouteActions(float elapsedClockSeconds) return (true); // always return true for activity player train } - //================================================================================================// /// /// Check for end of route actions @@ -7035,7 +6833,6 @@ public virtual bool CheckRouteActions(float elapsedClockSeconds) /// bool[0] "false" end of route not reached /// bool[1] "false" if no further route available /// - public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = true) { bool endOfRoute = false; @@ -7043,7 +6840,6 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru nextRouteReady = false; // obtain reversal section index - int reversalSectionIndex = -1; if (TCRoute != null && (ControlMode == TRAIN_CONTROL.AUTO_NODE || ControlMode == TRAIN_CONTROL.AUTO_SIGNAL)) { @@ -7073,7 +6869,6 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru PresentPosition[1].RouteListIndex = ValidRoute[0].GetRouteIndex(rearSection, 0); // Invalidate preceding section indexes to avoid wrong indexing when building route forward (in Reserve()) - for (int routeListIndex = 0; routeListIndex < PresentPosition[1].RouteListIndex; routeListIndex++) { ValidRoute[0][routeListIndex].TCSectionIndex = -1; @@ -7082,7 +6877,6 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru returnState[1] = true; return (returnState); } - // if loopend no longer on this valid route, remove loopend indication else if (loopSectionIndex < 0) { @@ -7092,22 +6886,17 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru } // check position in relation to present end of path - endOfRoute = CheckEndOfRoutePosition(); // not end of route - no action - if (!endOfRoute) { return (returnState); } // TODO: check if holding signals correctly released in case of reversal point between WP and signal - // if next subpath available : check if it can be activated - bool nextRouteAvailable = false; - TCSubpathRoute nextRoute = null; if (endOfRoute && TCRoute.activeSubpath < (TCRoute.TCRouteSubpaths.Count - 1)) @@ -7118,11 +6907,9 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru int firstSectionIndex = PresentPosition[1].TCSectionIndex; // find index of present rear position - int firstRouteIndex = nextRoute.GetRouteIndex(firstSectionIndex, 0); // if not found try index of present front position - if (firstRouteIndex >= 0) { nextRouteReady = true; @@ -7133,7 +6920,6 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru firstRouteIndex = nextRoute.GetRouteIndex(firstSectionIndex, 0); // cant find next part of route - check if really at end of this route, if so, error, else just wait and see (train stopped for other reason) - if (PresentPosition[0].RouteListIndex == ValidRoute[0].Count - 1) { if (firstRouteIndex < 0) @@ -7144,7 +6930,6 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru PresentPosition[0].TCSectionIndex.ToString()); } // search for junction and check if it is not clear - else { bool junctionFound = false; @@ -7230,12 +7015,9 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru } // if next route available : reverse train, reset and reinitiate signals - if (endOfRoute && nextRouteAvailable && nextRouteReady) { - // check if reverse is required - int newIndex = nextRoute.GetRouteIndex(PresentPosition[0].TCSectionIndex, 0); var oldDirection = ValidRoute[0][PresentPosition[0].RouteListIndex].Direction; if (newIndex < 0) @@ -7246,9 +7028,7 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru if (oldDirection != nextRoute[newIndex].Direction) { - // set new train positions and reset distance travelled - TCPosition tempPosition = new TCPosition(); PresentPosition[0].CopyTo(ref tempPosition); PresentPosition[1].CopyTo(ref PresentPosition[0]); @@ -7302,7 +7082,6 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru TCRoute.activeSubpath++; ValidRoute[0] = TCRoute.TCRouteSubpaths[TCRoute.activeSubpath]; - TCRoute.SetReversalOffset(Length, Simulator.TimetableMode); // clear existing list of occupied track, and build new list @@ -7310,7 +7089,6 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru { TrackCircuitSection thisSection = OccupiedTrack[iSection]; thisSection.ResetOccupied(this); - } int rearIndex = PresentPosition[1].RouteListIndex; @@ -7338,17 +7116,14 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru CheckDeadlock(ValidRoute[0], Number); // reset signal information - SignalObjectItems.Clear(); NextSignalObject[0] = null; - InitializeSignals(true); LastReservedSection[0] = PresentPosition[0].TCSectionIndex; // clear claims of any trains which have claimed present occupied sections upto common point - this avoids deadlocks // trains may have claimed while train was reversing - TrackCircuitSection presentSection = signalRef.TrackCircuitList[LastReservedSection[0]]; presentSection.ClearReversalClaims(routedForward); @@ -7369,13 +7144,11 @@ public bool[] UpdateRouteActions(float elapsedClockSeconds, bool checkLoop = tru /// /// Check End of Route Position /// - public virtual bool CheckEndOfRoutePosition() { bool endOfRoute = false; // obtain reversal section index - int reversalSectionIndex = -1; if (TCRoute != null && (ControlMode == TRAIN_CONTROL.AUTO_NODE || ControlMode == TRAIN_CONTROL.AUTO_SIGNAL)) { @@ -7390,7 +7163,6 @@ public virtual bool CheckEndOfRoutePosition() if (TCRoute.ReversalInfo[TCRoute.activeSubpath].Valid || TCRoute.activeSubpath == TCRoute.TCRouteSubpaths.Count - 1) { // can only be performed if train is stationary - if (Math.Abs(SpeedMpS) > 0.03) return (endOfRoute); @@ -7452,7 +7224,6 @@ public virtual bool CheckEndOfRoutePosition() } } } - // MSTS double reversal point: can be recognized and passed at speed > 0 else { @@ -7468,7 +7239,6 @@ public virtual bool CheckEndOfRoutePosition() /// Update route clearance ahead of train /// Called every update, actions depend on present control state /// - public void UpdateRouteClearanceAhead(int signalObjectIndex, int backward, float elapsedClockSeconds) { switch (ControlMode) @@ -7502,7 +7272,6 @@ public void UpdateRouteClearanceAhead(int signalObjectIndex, int backward, float } // reset signal which we've just passed - if (signalObjectIndex >= 0) { var signalObject = signalRef.SignalObjects[signalObjectIndex]; @@ -7521,12 +7290,10 @@ public void UpdateRouteClearanceAhead(int signalObjectIndex, int backward, float /// /// Perform auto signal mode update /// - public void UpdateSignalMode(int signalObjectIndex, int backward, float elapsedClockSeconds) { // in AUTO mode, use forward route only // if moving backward, check if slipped passed signal, if so, re-enable signal - if (backward > backwardThreshold) { if (NextSignalObject[0] != null && NextSignalObject[0].enabledTrain != routedForward) @@ -7541,7 +7308,6 @@ public void UpdateSignalMode(int signalObjectIndex, int backward, float elapsedC // if signal passed, send request to clear to next signal // if next signal not enabled, also send request (can happen after choosing passing path) - if (signalObjectIndex >= 0) { var thisSignal = signalRef.SignalObjects[signalObjectIndex]; @@ -7552,17 +7318,12 @@ public void UpdateSignalMode(int signalObjectIndex, int backward, float elapsedC nextSignal.requestClearSignal(ValidRoute[0], routedForward, 0, false, null); } } - // if next signal not enabled or enabled for other train, also send request (can happen after choosing passing path or after detach) - else if (NextSignalObject[0] != null && (!NextSignalObject[0].enabled || NextSignalObject[0].enabledTrain != routedForward)) { NextSignalObject[0].requestClearSignal(ValidRoute[0], routedForward, 0, false, null); } - - // check if waiting for signal - else if (SpeedMpS < Math.Abs(0.1) && NextSignalObject[0] != null && GetNextSignalAspect(0) == MstsSignalAspect.STOP && @@ -7629,7 +7390,6 @@ public void UpdateSignalMode(int signalObjectIndex, int backward, float elapsedC // // Check if train is waiting for a stationary (stopped) train or a train in manual mode // - public bool CheckStoppedTrains(TCSubpathRoute thisRoute) { foreach (TCRouteElement thisElement in thisRoute) @@ -7661,7 +7421,6 @@ public bool CheckStoppedTrains(TCSubpathRoute thisRoute) /// /// /// - public virtual bool TestCallOn(SignalObject thisSignal, bool allowOnNonePlatform, TCSubpathRoute thisRoute, string dumpfile) { bool intoPlatform = false; @@ -7671,7 +7430,6 @@ public virtual bool TestCallOn(SignalObject thisSignal, bool allowOnNonePlatform TrackCircuitSection routeSection = signalRef.TrackCircuitList[routeElement.TCSectionIndex]; // check if route leads into platform - if (routeSection.PlatformIndex.Count > 0) { intoPlatform = true; @@ -7706,7 +7464,6 @@ public virtual bool TestCallOn(SignalObject thisSignal, bool allowOnNonePlatform /// /// Check if train is waiting for signal /// - public bool CheckTrainWaitingForSignal(SignalObject thisSignal, int direction) { TrainRouted thisRouted = direction == 0 ? routedForward : routedBackward; @@ -7714,14 +7471,12 @@ public bool CheckTrainWaitingForSignal(SignalObject thisSignal, int direction) int signalRouteIndex = ValidRoute[direction].GetRouteIndex(thisSignal.TCReference, trainRouteIndex); // signal section is not in train route, so train can't be waiting for signal - if (signalRouteIndex < 0) { return false; } // check if any other trains in section ahead of this train - int thisSectionIndex = ValidRoute[0][trainRouteIndex].TCSectionIndex; TrackCircuitSection thisSection = signalRef.TrackCircuitList[thisSectionIndex]; @@ -7739,7 +7494,6 @@ public bool CheckTrainWaitingForSignal(SignalObject thisSignal, int direction) } // check if any other sections inbetween train and signal - if (trainRouteIndex != signalRouteIndex) { for (int iIndex = trainRouteIndex + 1; iIndex <= signalRouteIndex; iIndex++) @@ -7751,8 +7505,7 @@ public bool CheckTrainWaitingForSignal(SignalObject thisSignal, int direction) { return false; } - else if (!nextSection.IsAvailable(this)) // is section really available to us? // - + else if (!nextSection.IsAvailable(this)) // is section really available to us? // something is wrong - section upto signal is not available - give warning and switch to node control // also reset signal if it was enabled to us { @@ -7819,7 +7572,6 @@ public bool CheckTrainWaitingForSignal(SignalObject thisSignal, int direction) /// /// Breakdown claimed route when signal set to hold /// - public void BreakdownClaim(TrackCircuitSection thisSection, int routeDirectionIndex, TrainRouted thisTrainRouted) { TrackCircuitSection nextSection = thisSection; @@ -7833,17 +7585,13 @@ public void BreakdownClaim(TrackCircuitSection thisSection, int routeDirectionIn } } - //================================================================================================// /// /// Perform auto node mode update /// - public virtual void UpdateNodeMode() { - // update distance to end of authority - int lastRouteIndex = ValidRoute[0].GetRouteIndex(LastReservedSection[0], PresentPosition[0].RouteListIndex); TrackCircuitSection thisSection = signalRef.TrackCircuitList[PresentPosition[0].TCSectionIndex]; @@ -7855,7 +7603,6 @@ public virtual void UpdateNodeMode() DistanceToEndNodeAuthorityM[0] += thisSection.Length; } - // run out of authority : train is out of control // TODO : check end of (sub)path @@ -7883,7 +7630,6 @@ public virtual void UpdateNodeMode() /// /// Switches switch after dispatcher window command, when in auto mode /// - public bool ProcessRequestAutoSetSwitch(int reqSwitchIndex) { TrackCircuitSection reqSwitch = signalRef.TrackCircuitList[reqSwitchIndex]; @@ -7906,7 +7652,6 @@ public bool ProcessRequestAutoSetSwitch(int reqSwitchIndex) /// Update section occupy states for manual mode /// Note : manual mode has no distance actions so sections must be cleared immediately /// - public void UpdateSectionStateManual() { // occupation is set in forward mode only @@ -7922,7 +7667,6 @@ public void UpdateSectionStateManual() } // set track occupied - OccupiedTrack.Clear(); foreach (TCRouteElement thisElement in TrainRoute) @@ -7949,7 +7693,6 @@ public void UpdateSectionStateManual() /// /// Update Manual Mode /// - public void UpdateManualMode(int signalObjectIndex) { // check present forward @@ -7968,9 +7711,7 @@ public void UpdateManualMode(int signalObjectIndex) ref DistanceToEndNodeAuthorityM[1]); ValidRoute[1] = newRouteR; - // select valid route - if (MUDirection == Direction.Forward) { // use position from other end of section @@ -7991,7 +7732,6 @@ public void UpdateManualMode(int signalObjectIndex) } // reset signal - if (signalObjectIndex >= 0) { var thisSignal = signalRef.SignalObjects[signalObjectIndex]; @@ -8006,7 +7746,6 @@ public void UpdateManualMode(int signalObjectIndex) } // get next signal - // forward NextSignalObject[0] = null; for (int iindex = 0; iindex < ValidRoute[0].Count && NextSignalObject[0] == null; iindex++) @@ -8029,19 +7768,16 @@ public void UpdateManualMode(int signalObjectIndex) requiredActions.RemovePendingAIActionItems(true); } - //================================================================================================// /// /// Check Manual Path /// <\summary> - public TCSubpathRoute CheckManualPath(int direction, TCPosition requiredPosition, TCSubpathRoute requiredRoute, bool forward, ref END_AUTHORITY endAuthority, ref float endAuthorityDistanceM) { TrainRouted thisRouted = direction == 0 ? routedForward : routedBackward; // create new route or set to existing route - TCSubpathRoute newRoute = null; TCRouteElement thisElement = null; @@ -8060,12 +7796,10 @@ public void UpdateManualMode(int signalObjectIndex) } // check if train on valid position in route - int thisRouteIndex = newRoute.GetRouteIndex(requiredPosition.TCSectionIndex, 0); if (thisRouteIndex < 0) // no valid point in route { // check if run out of route on misaligned switch - if (newRoute.Count > 0) { // get last section, and get next expected section @@ -8080,7 +7814,6 @@ public void UpdateManualMode(int signalObjectIndex) if (nextSectionIndex == MisalignedSwitch[direction, 0] && lastSection.Index == MisalignedSwitch[direction, 1] && nextSection.ActivePins[0, 0].Link == requiredPosition.TCSectionIndex) { - // misaligned switch // reset indication @@ -8097,22 +7830,18 @@ public void UpdateManualMode(int signalObjectIndex) UpdateSectionStateManual(); // exit - return (newRoute); } } } - if (requiredRoute != null && requiredRoute.Count > 0) // if route defined, then breakdown route { signalRef.BreakDownRouteList(requiredRoute, 0, thisRouted); requiredRoute.Clear(); } - // build new route - MisalignedSwitch[direction, 0] = -1; MisalignedSwitch[direction, 1] = -1; @@ -8122,9 +7851,7 @@ public void UpdateManualMode(int signalObjectIndex) if (tempSections.Count > 0) { - // create subpath route - int prevSection = -2; // preset to invalid foreach (int sectionIndex in tempSections) @@ -8147,7 +7874,6 @@ public void UpdateManualMode(int signalObjectIndex) } // check if route ends at signal, determine length - totalLengthM = 0; thisSection = signalRef.TrackCircuitList[requiredPosition.TCSectionIndex]; offsetM = direction == 0 ? requiredPosition.TCOffset : thisSection.Length - requiredPosition.TCOffset; @@ -8189,7 +7915,6 @@ public void UpdateManualMode(int signalObjectIndex) // check if signal is in last section // if not, probably moved forward beyond a signal, so remove all beyond first signal - if (endWithSignal && sectionWithSignalIndex < newRoute.Count - 1) { for (int iindex = newRoute.Count - 1; iindex >= sectionWithSignalIndex + 1; iindex--) @@ -8201,10 +7926,8 @@ public void UpdateManualMode(int signalObjectIndex) } // if route does not end with signal and is too short, extend - if (!endWithSignal && totalLengthM < minCheckDistanceManualM) { - float extendedDistanceM = minCheckDistanceManualM - totalLengthM; TCRouteElement lastElement = newRoute[newRoute.Count - 1]; @@ -8215,7 +7938,6 @@ public void UpdateManualMode(int signalObjectIndex) int nextSectionDirection = lastSection.Pins[lastElement.OutPin[0], lastElement.OutPin[1]].Direction; // check if last item is non-aligned switch - MisalignedSwitch[direction, 0] = -1; MisalignedSwitch[direction, 1] = -1; @@ -8244,7 +7966,6 @@ public void UpdateManualMode(int signalObjectIndex) if (tempSections.Count > 0) { // add new sections - int prevSection = lastElement.TCSectionIndex; foreach (int sectionIndex in tempSections) @@ -8256,9 +7977,7 @@ public void UpdateManualMode(int signalObjectIndex) } } } - // if route is too long, remove sections at end - else if (totalLengthM > minCheckDistanceManualM) { float remainingLengthM = totalLengthM - signalRef.TrackCircuitList[newRoute[0].TCSectionIndex].Length; // do not count first section @@ -8283,7 +8002,6 @@ public void UpdateManualMode(int signalObjectIndex) // route created to signal or max length, now check availability // check if other train in first section - if (newRoute.Count > 0) { thisElement = newRoute[0]; @@ -8303,10 +8021,8 @@ public void UpdateManualMode(int signalObjectIndex) } RemoveSignalEnablings(0, newRoute); } - // check route availability // reserve sections which are available - else { int lastValidSectionIndex = 0; @@ -8347,12 +8063,9 @@ public void UpdateManualMode(int signalObjectIndex) endAuthority = END_AUTHORITY.SIGNAL; endAuthorityDistanceM = totalLengthM; } - // sections not clear - check if end has signal - else { - TrackCircuitSection nextSection = null; TCRouteElement nextElement = null; @@ -8369,7 +8082,6 @@ public void UpdateManualMode(int signalObjectIndex) endAuthority = END_AUTHORITY.END_OF_TRACK; endAuthorityDistanceM = totalLengthM; } - // first non-available section is switch or crossover else if (nextSection != null && (nextSection.CircuitType == TrackCircuitSection.TrackCircuitType.Junction || nextSection.CircuitType == TrackCircuitSection.TrackCircuitType.Crossover)) @@ -8377,7 +8089,6 @@ public void UpdateManualMode(int signalObjectIndex) endAuthority = END_AUTHORITY.RESERVED_SWITCH; endAuthorityDistanceM = totalLengthM; } - // set authority is end of path unless train ahead else { @@ -8385,7 +8096,6 @@ public void UpdateManualMode(int signalObjectIndex) endAuthorityDistanceM = totalLengthM; // check if train ahead not moving in opposite direction, in first non-available section - if (nextSection != null) { int oppositeDirection = forward ? (nextElement.Direction == 0 ? 1 : 0) : (nextElement.Direction == 0 ? 0 : 1); @@ -8422,7 +8132,6 @@ public void UpdateManualMode(int signalObjectIndex) } } } - // no valid route could be found else { @@ -8438,7 +8147,6 @@ public void UpdateManualMode(int signalObjectIndex) /// Remove signal enablings for subsequent route sections. /// They were set before testing whether there is an occupying train /// - private void RemoveSignalEnablings(int firstSection, TCSubpathRoute newRoute) { for (int iSection = firstSection; iSection <= newRoute.Count - 1; iSection++) @@ -8458,11 +8166,9 @@ private void RemoveSignalEnablings(int firstSection, TCSubpathRoute newRoute) /// /// Restore Manual Mode /// - public void RestoreManualMode() { // get next signal - // forward NextSignalObject[0] = null; for (int iindex = 0; iindex < ValidRoute[0].Count && NextSignalObject[0] == null; iindex++) @@ -8482,22 +8188,17 @@ public void RestoreManualMode() } } - //================================================================================================// // // Request signal permission in manual mode // - public void RequestManualSignalPermission(ref TCSubpathRoute selectedRoute, int routeIndex) { - // check if route ends with signal at danger - TCRouteElement lastElement = selectedRoute[selectedRoute.Count - 1]; TrackCircuitSection lastSection = signalRef.TrackCircuitList[lastElement.TCSectionIndex]; // no signal in required direction at end of path - if (lastSection.EndSignals[lastElement.Direction] == null) { if (Simulator.Confirmer != null) // As Confirmer may not be created until after a restore. @@ -8520,9 +8221,7 @@ public void RequestManualSignalPermission(ref TCSubpathRoute selectedRoute, int requestedSignal.hasPermission = SignalObject.Permission.Requested; // get route from next signal - extend to next signal or maximum length - // first, get present length (except first section) - float totalLengthM = 0; for (int iindex = 1; iindex < selectedRoute.Count; iindex++) { @@ -8534,14 +8233,12 @@ public void RequestManualSignalPermission(ref TCSubpathRoute selectedRoute, int Math.Min(minCheckDistanceManualM, Math.Max((minCheckDistanceManualM - totalLengthM), (minCheckDistanceManualM * 0.25f))); // get section behind signal - int nextSectionIndex = lastSection.Pins[lastElement.OutPin[0], lastElement.OutPin[1]].Link; int nextSectionDirection = lastSection.Pins[lastElement.OutPin[0], lastElement.OutPin[1]].Direction; bool requestValid = false; // get route from signal - set remaining length or upto next signal - if (nextSectionIndex > 0) { List tempSections = signalRef.ScanRoute(this, nextSectionIndex, 0, @@ -8549,7 +8246,6 @@ public void RequestManualSignalPermission(ref TCSubpathRoute selectedRoute, int true, false, true, false, false, false, false, IsFreight); // set as signal route - if (tempSections.Count > 0) { int prevSection = -1; @@ -8584,7 +8280,6 @@ public void RequestManualSignalPermission(ref TCSubpathRoute selectedRoute, int public bool ProcessRequestManualSetSwitch(Direction direction) { // find first switch in required direction - TrackCircuitSection reqSwitch = null; int routeDirectionIndex = direction == Direction.Forward ? 0 : 1; bool switchSet = false; @@ -8601,7 +8296,6 @@ public bool ProcessRequestManualSetSwitch(Direction direction) if (reqSwitch == null) { // search beyond last section for switch using default pins (continue through normal sections only) - TCRouteElement thisElement = ValidRoute[routeDirectionIndex][ValidRoute[routeDirectionIndex].Count - 1]; TrackCircuitSection lastSection = signalRef.TrackCircuitList[thisElement.TCSectionIndex]; int curDirection = thisElement.Direction; @@ -8687,7 +8381,6 @@ public bool ProcessRequestManualSetSwitch(Direction direction) public bool ProcessRequestManualSetSwitch(int reqSwitchIndex) { // find switch in route - forward first - int routeDirectionIndex = -1; bool switchFound = false; Direction direction = Direction.N; @@ -8726,7 +8419,6 @@ public bool ProcessRequestManualSetSwitch(int reqSwitchIndex) /// /// Process switching of manual switch /// - public void ProcessManualSwitch(int routeDirectionIndex, TrackCircuitSection switchSection, Direction direction) { TrainRouted thisRouted = direction == Direction.Reverse ? routedForward : routedBackward; @@ -8754,14 +8446,12 @@ public void ProcessManualSwitch(int routeDirectionIndex, TrackCircuitSection swi } // if any signals found : reset signals - foreach (SignalObject thisSignal in signalsFound) { thisSignal.ResetSignal(false); } // breakdown and clear route - signalRef.BreakDownRouteList(selectedRoute, 0, thisRouted); selectedRoute.Clear(); @@ -8777,7 +8467,6 @@ public void ProcessManualSwitch(int routeDirectionIndex, TrackCircuitSection swi MisalignedSwitch[routeDirectionIndex, 1] = -1; // build new route - int routeIndex = -1; if (direction == Direction.Forward) @@ -8785,7 +8474,6 @@ public void ProcessManualSwitch(int routeDirectionIndex, TrackCircuitSection swi selectedRoute = CheckManualPath(0, PresentPosition[0], null, true, ref EndAuthorityType[0], ref DistanceToEndNodeAuthorityM[0]); routeIndex = 0; - } else { @@ -8798,7 +8486,6 @@ public void ProcessManualSwitch(int routeDirectionIndex, TrackCircuitSection swi } // if route ends at previously cleared signal, request clear signal again - TCRouteElement lastElement = selectedRoute[selectedRoute.Count - 1]; TrackCircuitSection lastSection = signalRef.TrackCircuitList[lastElement.TCSectionIndex]; int lastDirection = lastElement.Direction == 0 ? 0 : 1; @@ -8823,12 +8510,10 @@ public void ProcessManualSwitch(int routeDirectionIndex, TrackCircuitSection swi /// /// Update speed limit in manual mode /// - public void CheckSpeedLimitManual(TCSubpathRoute routeBehind, TCSubpathRoute routeUnderTrain, float offsetStart, float reverseOffset, int passedSignalIndex, int routeDirection) { // check backward for last speedlimit in direction of train - raise speed if passed - TCRouteElement thisElement = routeBehind[0]; List foundSpeedLimit = new List(); @@ -8858,7 +8543,6 @@ public void ProcessManualSwitch(int routeDirectionIndex, TrackCircuitSection swi // check backward for last signal in direction of train - check with list of pending signal speeds // search also checks for speedlimit to see which is nearest train - foundSpeedLimit.Clear(); foundSpeedLimit = signalRef.ScanRoute(this, thisElement.TCSectionIndex, offsetStart, thisElement.Direction, true, -1, false, true, false, false, false, false, true, false, true, IsFreight, true); @@ -8906,7 +8590,6 @@ public void ProcessManualSwitch(int routeDirectionIndex, TrackCircuitSection swi // check forward along train for speedlimit and signal in direction of train - limit speed if passed // loop as there might be more than one - thisElement = routeUnderTrain[0]; foundSpeedLimit.Clear(); float remLength = Length; @@ -8998,7 +8681,6 @@ public void ProcessManualSwitch(int routeDirectionIndex, TrackCircuitSection swi } // check if signal passed posed a speed limit lower than present limit - if (passedSignalIndex >= 0) { var passedSignal = signalRef.SignalObjects[passedSignalIndex]; @@ -9023,7 +8705,6 @@ public void ProcessManualSwitch(int routeDirectionIndex, TrackCircuitSection swi /// Update section occupy states fore explorer mode /// Note : explorer mode has no distance actions so sections must be cleared immediately /// - public void UpdateSectionStateExplorer() { // occupation is set in forward mode only @@ -9032,7 +8713,6 @@ public void UpdateSectionStateExplorer() PresentPosition[1].TCDirection, Length, false, true, false); // save present occupation list - List clearedSections = new List(); for (int iindex = OccupiedTrack.Count - 1; iindex >= 0; iindex--) { @@ -9040,7 +8720,6 @@ public void UpdateSectionStateExplorer() } // first check for misaligned switch - int reqDirection = MUDirection == Direction.Forward ? 0 : 1; foreach (TCRouteElement thisElement in TrainRoute) { @@ -9066,7 +8745,6 @@ public void UpdateSectionStateExplorer() } // if all is well, set tracks to occupied - OccupiedTrack.Clear(); foreach (TCRouteElement thisElement in TrainRoute) @@ -9093,7 +8771,6 @@ public void UpdateSectionStateExplorer() /// /// Update Explorer Mode /// - public void UpdateExplorerMode(int signalObjectIndex) { if (MPManager.IsMultiPlayer()) @@ -9141,7 +8818,6 @@ public void UpdateExplorerMode(int signalObjectIndex) ValidRoute[1] = newRouteR; // select valid route - if (MUDirection == Direction.Forward) { // use position from other end of section @@ -9162,7 +8838,6 @@ public void UpdateExplorerMode(int signalObjectIndex) } // reset signal permission - if (signalObjectIndex >= 0) { var thisSignal = signalRef.SignalObjects[signalObjectIndex]; @@ -9172,7 +8847,6 @@ public void UpdateExplorerMode(int signalObjectIndex) } // get next signal - // forward float distanceToSignalForward = 0; float lengthOffset = PresentPosition[0].TCOffset; @@ -9223,14 +8897,12 @@ public void UpdateExplorerMode(int signalObjectIndex) /// /// Check Explorer Path /// <\summary> - public TCSubpathRoute CheckExplorerPath(int direction, TCPosition requiredPosition, TCSubpathRoute requiredRoute, bool forward, ref END_AUTHORITY endAuthority, ref float endAuthorityDistanceM) { TrainRouted thisRouted = direction == 0 ? routedForward : routedBackward; // create new route or set to existing route - TCSubpathRoute newRoute = null; TCRouteElement thisElement = null; @@ -9249,7 +8921,6 @@ public void UpdateExplorerMode(int signalObjectIndex) } // check if train on valid position in route - int thisRouteIndex = newRoute.GetRouteIndex(requiredPosition.TCSectionIndex, 0); if (thisRouteIndex < 0) // no valid point in route { @@ -9260,16 +8931,13 @@ public void UpdateExplorerMode(int signalObjectIndex) } // build new route - List tempSections = signalRef.ScanRoute(this, requiredPosition.TCSectionIndex, requiredPosition.TCOffset, requiredPosition.TCDirection, forward, MinCheckDistanceExplorerM, true, false, true, false, true, false, false, false, false, IsFreight); if (tempSections.Count > 0) { - // create subpath route - int prevSection = -2; // preset to invalid foreach (int sectionIndex in tempSections) @@ -9292,7 +8960,6 @@ public void UpdateExplorerMode(int signalObjectIndex) } // check if route ends at signal, determine length - totalLengthM = 0; thisSection = signalRef.TrackCircuitList[requiredPosition.TCSectionIndex]; offsetM = direction == 0 ? requiredPosition.TCOffset : thisSection.Length - requiredPosition.TCOffset; @@ -9310,7 +8977,6 @@ public void UpdateExplorerMode(int signalObjectIndex) // check on state of signals // also check if signal properly enabled - reqDirection = thisElement.Direction; if (thisSection.EndSignals[reqDirection] != null) { @@ -9329,13 +8995,11 @@ public void UpdateExplorerMode(int signalObjectIndex) if (iindex + 1 == newRoute.Count) newRoute = extendedRoute; } - } } // check if signal is in last section // if not, probably moved forward beyond a signal, so remove all beyond first signal - if (endWithSignal && sectionWithSignalIndex < newRoute.Count - 1) { for (int iindex = newRoute.Count - 1; iindex >= sectionWithSignalIndex + 1; iindex--) @@ -9347,10 +9011,8 @@ public void UpdateExplorerMode(int signalObjectIndex) } // if route does not end with signal and is too short, extend - if (!endWithSignal && totalLengthM < MinCheckDistanceExplorerM) { - float extendedDistanceM = MinCheckDistanceExplorerM - totalLengthM; TCRouteElement lastElement = newRoute[newRoute.Count - 1]; @@ -9361,7 +9023,6 @@ public void UpdateExplorerMode(int signalObjectIndex) int nextSectionDirection = lastSection.Pins[lastElement.OutPin[0], lastElement.OutPin[1]].Direction; // check if last item is non-aligned switch - MisalignedSwitch[direction, 0] = -1; MisalignedSwitch[direction, 1] = -1; @@ -9389,7 +9050,6 @@ public void UpdateExplorerMode(int signalObjectIndex) if (tempSections != null && tempSections.Count > 0) { // add new sections - int prevSection = lastElement.TCSectionIndex; foreach (int sectionIndex in tempSections) @@ -9403,7 +9063,6 @@ public void UpdateExplorerMode(int signalObjectIndex) } // check for any uncleared signals in route - if first found, request clear signal - bool unclearedSignal = false; int signalIndex = newRoute.Count - 1; int nextUnclearSignalIndex = -1; @@ -9426,7 +9085,6 @@ public void UpdateExplorerMode(int signalObjectIndex) // route created to signal or max length, now check availability - but only up to first unclear signal // check if other train in first section - if (newRoute.Count > 0) { thisElement = newRoute[0]; @@ -9444,10 +9102,8 @@ public void UpdateExplorerMode(int signalObjectIndex) if (!thisSection.CircuitState.ThisTrainOccupying(this)) thisSection.PreReserve(thisRouted); } } - // check route availability // reserve sections which are available - else { int lastValidSectionIndex = 0; @@ -9488,12 +9144,9 @@ public void UpdateExplorerMode(int signalObjectIndex) endAuthority = END_AUTHORITY.SIGNAL; endAuthorityDistanceM = totalLengthM; } - // sections not clear - check if end has signal - else { - TrackCircuitSection nextSection = null; TCRouteElement nextElement = null; @@ -9510,7 +9163,6 @@ public void UpdateExplorerMode(int signalObjectIndex) endAuthority = END_AUTHORITY.END_OF_TRACK; endAuthorityDistanceM = totalLengthM; } - // first non-available section is switch or crossover else if (nextSection != null && (nextSection.CircuitType == TrackCircuitSection.TrackCircuitType.Junction || nextSection.CircuitType == TrackCircuitSection.TrackCircuitType.Crossover)) @@ -9518,7 +9170,6 @@ public void UpdateExplorerMode(int signalObjectIndex) endAuthority = END_AUTHORITY.RESERVED_SWITCH; endAuthorityDistanceM = totalLengthM; } - // set authority is end of path unless train ahead else { @@ -9526,7 +9177,6 @@ public void UpdateExplorerMode(int signalObjectIndex) endAuthorityDistanceM = totalLengthM; // check if train ahead not moving in opposite direction, in first non-available section - if (nextSection != null) { int oppositeDirection = forward ? (nextElement.Direction == 0 ? 1 : 0) : (nextElement.Direction == 0 ? 0 : 1); @@ -9562,7 +9212,6 @@ public void UpdateExplorerMode(int signalObjectIndex) // check if route ends at signal and this is first unclear signal // if so, request clear signal - if (endAuthority == END_AUTHORITY.SIGNAL) { // The logic here is to keep the value of SNCA of first signal found in path, and reduce this value as cleared signals are passed. @@ -9625,7 +9274,6 @@ public void UpdateExplorerMode(int signalObjectIndex) } } } - // no valid route could be found else { @@ -9640,11 +9288,9 @@ public void UpdateExplorerMode(int signalObjectIndex) /// /// Restore Explorer Mode /// - public void RestoreExplorerMode() { // get next signal - // forward NextSignalObject[0] = null; for (int iindex = 0; iindex < ValidRoute[0].Count && NextSignalObject[0] == null; iindex++) @@ -9664,16 +9310,13 @@ public void RestoreExplorerMode() } } - //================================================================================================// // // Request signal permission in explorer mode // - public void RequestExplorerSignalPermission(ref TCSubpathRoute selectedRoute, int routeIndex) { // check route for first signal at danger, from present position - SignalObject reqSignal = null; bool signalFound = false; @@ -9729,7 +9372,6 @@ public void RequestExplorerSignalPermission(ref TCSubpathRoute selectedRoute, in /// Process request to set switch in explorer mode /// Request may contain direction or actual node /// - public bool ProcessRequestExplorerSetSwitch(Direction direction) { // find first switch in required direction @@ -9750,7 +9392,6 @@ public bool ProcessRequestExplorerSetSwitch(Direction direction) if (reqSwitch == null) { // search beyond last section for switch using default pins (continue through normal sections only) - TCRouteElement thisElement = ValidRoute[routeDirectionIndex][ValidRoute[routeDirectionIndex].Count - 1]; TrackCircuitSection lastSection = signalRef.TrackCircuitList[thisElement.TCSectionIndex]; int curDirection = thisElement.Direction; @@ -9825,7 +9466,6 @@ public bool ProcessRequestExplorerSetSwitch(Direction direction) public bool ProcessRequestExplorerSetSwitch(int reqSwitchIndex) { // find switch in route - forward first - int routeDirectionIndex = -1; bool switchFound = false; Direction direction = Direction.N; @@ -9867,7 +9507,6 @@ public bool ProcessRequestExplorerSetSwitch(int reqSwitchIndex) /// /// Process switching of explorer switch /// - public void ProcessExplorerSwitch(int routeDirectionIndex, TrackCircuitSection switchSection, Direction direction) { TrainRouted thisRouted = direction == Direction.Reverse ? routedBackward : routedForward; @@ -9902,20 +9541,16 @@ public void ProcessExplorerSwitch(int routeDirectionIndex, TrackCircuitSection s } // if last first is found : reset signal and further signals, clear route as from signal and request clear signal - if (firstSignal != null) { firstSignal.ResetSignal(true); // breakdown and clear route - // checke whether trailing or leading // Probably also in singleplayer the logic of multiplayer should be used, but it's unwise to modify it just before a release if (switchSection.Pins[0, 0].Link == selectedRoute[lastIndex].TCSectionIndex || !MPManager.IsMultiPlayer()) // leading, train may still own switch - { - signalRef.BreakDownRouteList(selectedRoute, lastIndex + 1, thisRouted); selectedRoute.RemoveRange(lastIndex + 1, selectedRoute.Count - lastIndex - 1); @@ -9944,7 +9579,6 @@ public void ProcessExplorerSwitch(int routeDirectionIndex, TrackCircuitSection s signalRef.setSwitch(switchSection.OriginalIndex, switchSection.JunctionSetManual, switchSection); } } - // no signal is found - build route using full update process else { @@ -9960,7 +9594,6 @@ public void ProcessExplorerSwitch(int routeDirectionIndex, TrackCircuitSection s // // Switch to explorer mode // - public void ToggleToExplorerMode() { if (ControlMode == TRAIN_CONTROL.OUT_OF_CONTROL && LeadLocomotive is MSTSLocomotive locomotive) @@ -9972,7 +9605,6 @@ public void ToggleToExplorerMode() UpdateSectionStateExplorer(); // breakdown present route - both directions if set - if (ValidRoute[0] != null) { int listIndex = PresentPosition[0].RouteListIndex; @@ -9992,25 +9624,19 @@ public void ToggleToExplorerMode() LastReservedSection[1] = -1; // clear all outstanding actions - ClearActiveSectionItems(); requiredActions.RemovePendingAIActionItems(true); // clear signal info - NextSignalObject[0] = null; NextSignalObject[1] = null; - SignalObjectItems.Clear(); - PassedSignalSpeeds.Clear(); // set explorer mode - ControlMode = TRAIN_CONTROL.EXPLORER; // reset routes and check sections either end of train - PresentPosition[0].RouteListIndex = -1; PresentPosition[1].RouteListIndex = -1; PreviousPosition[0].RouteListIndex = -1; @@ -10023,7 +9649,6 @@ public void ToggleToExplorerMode() /// public void UpdateOutOfControl() { - // train is at a stand : // clear all occupied blocks // clear signal/speedpost list @@ -10040,7 +9665,6 @@ public void UpdateOutOfControl() public virtual void SwitchToSignalControl(SignalObject thisSignal) { // in auto mode, use forward direction only - ControlMode = TRAIN_CONTROL.AUTO_SIGNAL; thisSignal.requestClearSignal(ValidRoute[0], routedForward, 0, false, null); @@ -10119,13 +9743,11 @@ public virtual void SwitchToNodeControl(int thisSectionIndex) IndexNextSignal = -1; // no next signal in Node Control // if section is set, check if it is on route and ahead of train - if (activeSectionIndex > 0) { endListIndex = ValidRoute[0].GetRouteIndex(thisSectionIndex, PresentPosition[0].RouteListIndex); // section is not on route - give warning and break down route, following active links and resetting reservation - if (endListIndex < 0) { signalRef.BreakDownRoute(thisSectionIndex, routedForward); @@ -10133,7 +9755,6 @@ public virtual void SwitchToNodeControl(int thisSectionIndex) } // if section is (still) set, check if this is at maximum distance - if (activeSectionIndex > 0) { TrackCircuitSection thisSection = signalRef.TrackCircuitList[activeSectionIndex]; @@ -10153,7 +9774,6 @@ public virtual void SwitchToNodeControl(int thisSectionIndex) } // new request or not beyond max distance - if (activeSectionIndex < 0 || EndAuthorityType[0] != END_AUTHORITY.MAX_DISTANCE) { signalRef.requestClearNode(routedForward, ValidRoute[0]); @@ -10164,7 +9784,6 @@ public virtual void SwitchToNodeControl(int thisSectionIndex) // // Request to switch to or from manual mode // - public void RequestToggleManualMode() { if (TrainType == TRAINTYPE.AI_PLAYERHOSTING) @@ -10180,7 +9799,6 @@ public void RequestToggleManualMode() else if (ControlMode == TRAIN_CONTROL.MANUAL) { // check if train is back on path - TCSubpathRoute lastRoute = TCRoute.TCRouteSubpaths[TCRoute.activeSubpath]; int routeIndex = lastRoute.GetRouteIndex(PresentPosition[0].TCSectionIndex, 0); @@ -10204,7 +9822,6 @@ public void RequestToggleManualMode() Simulator.Confirmer.Confirm(CabControl.SignalMode, CabSetting.On); } } - } else if (ControlMode == TRAIN_CONTROL.EXPLORER) { @@ -10227,7 +9844,6 @@ public void RequestToggleManualMode() // // Switch to manual mode // - public void ToggleToManualMode() { if (LeadLocomotive is MSTSLocomotive locomotive) @@ -10239,7 +9855,6 @@ public void ToggleToManualMode() UpdateSectionStateManual(); // breakdown present route - both directions if set - if (ValidRoute[0] != null) { int listIndex = PresentPosition[0].RouteListIndex; @@ -10259,25 +9874,19 @@ public void ToggleToManualMode() LastReservedSection[1] = -1; // clear all outstanding actions - ClearActiveSectionItems(); requiredActions.RemovePendingAIActionItems(true); // clear signal info - NextSignalObject[0] = null; NextSignalObject[1] = null; - SignalObjectItems.Clear(); - PassedSignalSpeeds.Clear(); // set manual mode - ControlMode = TRAIN_CONTROL.MANUAL; // reset routes and check sections either end of train - PresentPosition[0].RouteListIndex = -1; PresentPosition[1].RouteListIndex = -1; PreviousPosition[0].RouteListIndex = -1; @@ -10289,16 +9898,13 @@ public void ToggleToManualMode() // // Switch back from manual mode // - public void ToggleFromManualMode(int routeIndex) { // extract route at present front position - TCSubpathRoute newRoute = new TCSubpathRoute(); TCSubpathRoute oldRoute = TCRoute.TCRouteSubpaths[TCRoute.activeSubpath]; // test on reversal, if so check rear of train - bool reversal = false; if (!CheckReversal(oldRoute, ref reversal)) { @@ -10311,9 +9917,7 @@ public void ToggleFromManualMode(int routeIndex) signalRef.BreakDownRouteList(ValidRoute[0], 0, routedForward); signalRef.BreakDownRouteList(ValidRoute[1], 0, routedBackward); - // clear occupied sections - for (int iSection = OccupiedTrack.Count - 1; iSection >= 0; iSection--) { TrackCircuitSection thisSection = OccupiedTrack[iSection]; @@ -10339,7 +9943,6 @@ public void ToggleFromManualMode(int routeIndex) InitializeSignals(true); // restore deadlock information - CheckDeadlock(ValidRoute[0], Number); // Check deadlock against all other trains // switch to AutoNode mode @@ -10356,7 +9959,6 @@ public void ToggleFromManualMode(int routeIndex) // // ResetExplorerMode // - public void ResetExplorerMode() { if (ControlMode == TRAIN_CONTROL.OUT_OF_CONTROL && LeadLocomotive is MSTSLocomotive locomotive) @@ -10368,7 +9970,6 @@ public void ResetExplorerMode() UpdateSectionStateExplorer(); // breakdown present route - both directions if set - if (ValidRoute[0] != null) { int listIndex = PresentPosition[0].RouteListIndex; @@ -10388,25 +9989,19 @@ public void ResetExplorerMode() LastReservedSection[1] = -1; // clear all outstanding actions - ClearActiveSectionItems(); requiredActions.RemovePendingAIActionItems(true); // clear signal info - NextSignalObject[0] = null; NextSignalObject[1] = null; - SignalObjectItems.Clear(); - PassedSignalSpeeds.Clear(); // set explorer mode - ControlMode = TRAIN_CONTROL.EXPLORER; // reset routes and check sections either end of train - PresentPosition[0].RouteListIndex = -1; PresentPosition[1].RouteListIndex = -1; PreviousPosition[0].RouteListIndex = -1; @@ -10418,7 +10013,6 @@ public void ResetExplorerMode() // // Check if reversal is required // - public bool CheckReversal(TCSubpathRoute reqRoute, ref bool reversal) { bool valid = true; @@ -10455,11 +10049,9 @@ public bool CheckReversal(TCSubpathRoute reqRoute, ref bool reversal) // // Restore train placement // - public void RestoreTrainPlacement(ref TCSubpathRoute newRoute, TCSubpathRoute oldRoute, int frontIndex, bool reversal) { // reverse train if required - if (reversal) { ReverseFormation(true); @@ -10468,12 +10060,10 @@ public void RestoreTrainPlacement(ref TCSubpathRoute newRoute, TCSubpathRoute ol } // reset distance travelled - DistanceTravelledM = 0.0f; // check if end of train on original route // copy sections from earliest start point (front or rear) - int rearIndex = oldRoute.GetRouteIndex(PresentPosition[1].TCSectionIndex, 0); int startIndex = rearIndex >= 0 ? Math.Min(rearIndex, frontIndex) : frontIndex; @@ -10483,10 +10073,8 @@ public void RestoreTrainPlacement(ref TCSubpathRoute newRoute, TCSubpathRoute ol } // if rear not on route, build route under train and add sections - if (rearIndex < 0) { - TCSubpathRoute tempRoute = signalRef.BuildTempRoute(this, PresentPosition[1].TCSectionIndex, PresentPosition[1].TCOffset, PresentPosition[1].TCDirection, Length, true, true, false); @@ -10501,7 +10089,6 @@ public void RestoreTrainPlacement(ref TCSubpathRoute newRoute, TCSubpathRoute ol } // set route as valid route - ValidRoute[0] = newRoute; // Reindexes ReversalInfo items @@ -10510,22 +10097,16 @@ public void RestoreTrainPlacement(ref TCSubpathRoute newRoute, TCSubpathRoute ol if (TCRoute.ReversalInfo[TCRoute.activeSubpath].LastSignalIndex >= 0) TCRoute.ReversalInfo[TCRoute.activeSubpath].LastSignalIndex = ValidRoute[0].GetRouteIndex(TCRoute.ReversalInfo[TCRoute.activeSubpath].SignalSectorIndex, 0); - - // get index of first section in route - rearIndex = ValidRoute[0].GetRouteIndex(PresentPosition[1].TCSectionIndex, 0); PresentPosition[1].RouteListIndex = rearIndex; // get index of front of train - frontIndex = ValidRoute[0].GetRouteIndex(PresentPosition[0].TCSectionIndex, 0); PresentPosition[0].RouteListIndex = frontIndex; - PresentPosition[0].CopyTo(ref PreviousPosition[0]); // set track occupied - forward only - foreach (TrackCircuitSection thisSection in OccupiedTrack) { if (!thisSection.CircuitState.ThisTrainOccupying(this)) @@ -10534,15 +10115,12 @@ public void RestoreTrainPlacement(ref TCSubpathRoute newRoute, TCSubpathRoute ol thisSection.SetOccupied(routedForward); } } - } - //================================================================================================// // // Request permission to pass signal // - public void RequestSignalPermission(Direction direction) { if (MPManager.IsClient()) @@ -10580,7 +10158,6 @@ public void RequestSignalPermission(Direction direction) Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetString("Cannot clear signal behind train while in AUTO mode")); Simulator.SoundNotify = Event.PermissionDenied; } - else if (NextSignalObject[0] != null) { NextSignalObject[0].hasPermission = SignalObject.Permission.Requested; @@ -10592,7 +10169,6 @@ public void RequestSignalPermission(Direction direction) // // Request reset signal // - public void RequestResetSignal(Direction direction) { if (!MPManager.IsMultiPlayer()) @@ -10618,12 +10194,9 @@ public void RequestResetSignal(Direction direction) /// /// Get distance from train to object position using route list /// - public float GetObjectDistanceToTrain(ObjectItemInfo thisObject) { - // follow active links to get to object - int reqSectionIndex = thisObject.ObjectDetails.TCReference; float endOffset = thisObject.ObjectDetails.TCOffset; @@ -10643,11 +10216,9 @@ public float GetObjectDistanceToTrain(ObjectItemInfo thisObject) /// TODO : rewrite to use active links, and if fails use traveller /// location must have same direction as train /// - public float GetDistanceToTrain(int sectionIndex, float endOffset) { // use start of list to see if passed position - int endListIndex = ValidRoute[0].GetRouteIndex(sectionIndex, PresentPosition[0].RouteListIndex); if (endListIndex < 0) endListIndex = ValidRoute[0].GetRouteIndex(sectionIndex, 0); @@ -10663,7 +10234,6 @@ public float GetDistanceToTrain(int sectionIndex, float endOffset) } // section is not on route - if (endListIndex < 0) { return (-1.0f); @@ -10682,10 +10252,8 @@ public float GetDistanceToTrain(int sectionIndex, float endOffset) /// Switch train to Out-of-Control /// Set mode and apply emergency brake /// - public void SetTrainOutOfControl(OUTOFCONTROL reason) { - if (ControlMode == TRAIN_CONTROL.OUT_OF_CONTROL) // allready out of control, so exit { return; @@ -10714,13 +10282,10 @@ public void SetTrainOutOfControl(OUTOFCONTROL reason) // TODO : clear routes for MANUAL if (!MPManager.IsMultiPlayer() || Simulator.TimetableMode || reason != OUTOFCONTROL.OUT_OF_PATH || IsActualPlayerTrain) { - // set control state and issue warning - ControlMode = TRAIN_CONTROL.OUT_OF_CONTROL; var report = string.Format("Train {0} is out of control and will be stopped. Reason : ", Number.ToString()); - OutOfControlReason = reason; switch (reason) @@ -10825,7 +10390,6 @@ public void ManualResetOutOfControlMode() /// /// Re-routes a train in auto mode after a switch moved manually /// - public void ReRouteTrain(int forcedRouteSectionIndex, int forcedTCSectionIndex) { // check for any stations in abandoned path @@ -10847,7 +10411,6 @@ public void ReRouteTrain(int forcedRouteSectionIndex, int forcedTCSectionIndex) /// /// Resets ValidRoute after some event like a switch moved /// - public void ResetValidRoute() { // clear all reserved sections etc. - both directions @@ -10871,12 +10434,10 @@ public void ResetValidRoute() } } - //================================================================================================// /// /// Generates a new ValidRoute after some event like a switch moved /// - public void GenerateValidRoute(int forcedRouteSectionIndex, int forcedTCSectionIndex) { // We don't kill the AI train and build a new route for it @@ -10958,7 +10519,6 @@ public void GenerateValidRoute(int forcedRouteSectionIndex, int forcedTCSectionI TCRoute.ReversalInfo[TCRoute.activeSubpath].LastSignalIndex = TCRoute.ReversalInfo[TCRoute.activeSubpath].LastSignalIndex + countDifference; TCRoute.TCRouteSubpaths[TCRoute.activeSubpath] = newRoute; - } else { @@ -10983,7 +10543,6 @@ public void GenerateValidRoute(int forcedRouteSectionIndex, int forcedTCSectionI PresentPosition[0].RouteListIndex = ValidRoute[0].GetRouteIndex(PresentPosition[0].TCSectionIndex, PreviousPosition[0].RouteListIndex); // reset signal information - SignalObjectItems.Clear(); NextSignalObject[0] = null; // create new list @@ -10996,7 +10555,6 @@ public void GenerateValidRoute(int forcedRouteSectionIndex, int forcedTCSectionI /// /// Perform actions linked to distance travelled /// - public virtual void PerformActions(List nowActions) { foreach (var thisAction in nowActions) @@ -11021,7 +10579,6 @@ public virtual void PerformActions(List nowActions) /// /// Clear section /// - public void ClearOccupiedSection(ClearSectionItem sectionInfo) { int thisSectionIndex = sectionInfo.TrackSectionIndex; @@ -11034,7 +10591,6 @@ public void ClearOccupiedSection(ClearSectionItem sectionInfo) /// /// Set pending speed limits /// - public void SetPendingSpeedLimit(ActivateSpeedLimit speedInfo) { float prevMaxSpeedMpS = AllowedMaxSpeedMpS; @@ -11074,7 +10630,6 @@ public void SetPendingSpeedLimit(ActivateSpeedLimit speedInfo) /// /// Clear all active items on occupied track /// <\summary> - public void ClearActiveSectionItems() { ClearSectionItem dummyItem = new ClearSectionItem(0.0f, 0); @@ -11099,7 +10654,6 @@ public void ClearActiveSectionItems() /// /// Forced stop due to problems with other train /// <\summary> - public void ForcedStop(String reason, string otherTrainName, int otherTrainNumber) { Trace.TraceInformation("Train {0} ({1}) stopped for train {2} ({3}) : {4}", @@ -11119,7 +10673,6 @@ public void ForcedStop(String reason, string otherTrainName, int otherTrainNumbe { File.AppendAllText(@"C:\temp\checktrain.txt", report + "\n"); } - } if (LeadLocomotive is MSTSLocomotive locomotive) @@ -11132,7 +10685,6 @@ public void ForcedStop(String reason, string otherTrainName, int otherTrainNumbe /// /// Remove train /// <\summary> - public virtual void RemoveTrain() { RemoveFromTrack(); @@ -11144,11 +10696,9 @@ public virtual void RemoveTrain() // // Remove train from not-occupied sections only (for reset after uncoupling) // - public void RemoveFromTrackNotOccupied(TCSubpathRoute newSections) { // clear occupied track - List clearedSectionIndices = new List(); TrackCircuitSection[] tempSectionArray = new TrackCircuitSection[OccupiedTrack.Count]; // copy sections as list is cleared by ClearOccupied method OccupiedTrack.CopyTo(tempSectionArray); @@ -11165,7 +10715,6 @@ public void RemoveFromTrackNotOccupied(TCSubpathRoute newSections) } // clear outstanding clear sections for sections no longer occupied - foreach (DistanceTravelledItem thisAction in requiredActions) { if (thisAction is ClearSectionItem) @@ -11184,11 +10733,9 @@ public void RemoveFromTrackNotOccupied(TCSubpathRoute newSections) // // Remove train (after coupling or when train disappeared in multiplayer) // - public void RemoveFromTrack() { // check if no reserved sections remain - int presentIndex = PresentPosition[1].RouteListIndex; if (presentIndex >= 0) @@ -11202,7 +10749,6 @@ public void RemoveFromTrack() } // for explorer (e.g. in Multiplayer) and manual mode check also backward route - if (ValidRoute[1] != null && ValidRoute[1].Count > 0) { for (int iIndex = 0; iIndex < ValidRoute[1].Count; iIndex++) @@ -11214,7 +10760,6 @@ public void RemoveFromTrack() } // clear occupied track - TrackCircuitSection[] tempSectionArray = new TrackCircuitSection[OccupiedTrack.Count]; // copy sections as list is cleared by ClearOccupied method OccupiedTrack.CopyTo(tempSectionArray); @@ -11229,7 +10774,6 @@ public void RemoveFromTrack() LastReservedSection[1] = -1; // clear outstanding clear sections and remove them from queue as they are no longer required - List activeActions = requiredActions.GetActions(99999999f, typeof(ClearSectionItem)); foreach (DistanceTravelledItem thisAction in activeActions) { @@ -11238,12 +10782,11 @@ public void RemoveFromTrack() thisSection.ClearOccupied(this, true); } } - + //================================================================================================// // // Update track actions after coupling // - public void UpdateTrackActionsCoupling(bool couple_to_front) { @@ -11262,24 +10805,20 @@ public void UpdateTrackActionsCoupling(bool couple_to_front) } // remove train from track - clear all reservations etc. - RemoveFromTrack(); ClearDeadlocks(); // check if new train is freight or not - CheckFreight(); SetDPUnitIDs(); ReinitializeEOT(); // clear all track occupation actions - ClearSectionItem dummyItem = new ClearSectionItem(0.0f, 0); List activeActions = requiredActions.GetActions(99999999f, dummyItem.GetType()); activeActions.Clear(); // save existing TCPositions - TCPosition oldPresentPosition = new TCPosition(); PresentPosition[0].CopyTo(ref oldPresentPosition); TCPosition oldRearPosition = new TCPosition(); @@ -11289,7 +10828,6 @@ public void UpdateTrackActionsCoupling(bool couple_to_front) PresentPosition[1] = new TCPosition(); // create new TCPositions - TrackNode tn = FrontTDBTraveller.TN; float offset = FrontTDBTraveller.TrackNodeOffset; int direction = (int)FrontTDBTraveller.Direction; @@ -11307,7 +10845,6 @@ public void UpdateTrackActionsCoupling(bool couple_to_front) PresentPosition[1].DistanceTravelledM = oldRearPosition.DistanceTravelledM; // use difference in position to update existing DistanceTravelled - float deltaoffset = 0.0f; if (couple_to_front) @@ -11363,7 +10900,6 @@ public void UpdateTrackActionsCoupling(bool couple_to_front) UpdateOccupancies(); // add sections to required actions list - foreach (TrackCircuitSection thisSection in OccupiedTrack) { float distanceToClear = DistanceTravelledM + thisSection.Length + standardOverlapM; @@ -11389,7 +10925,6 @@ public void UpdateTrackActionsCoupling(bool couple_to_front) } // rebuild list of station stops - if (StationStops.Count > 0) { int presentStop = StationStops[0].PlatformReference; @@ -11418,11 +10953,9 @@ public void UpdateTrackActionsCoupling(bool couple_to_front) } // add present occupied sections to train route to avoid out-of-path detection - AddTrackSections(); // reset signals etc. - SignalObjectItems.Clear(); NextSignalObject[0] = null; NextSignalObject[1] = null; @@ -11443,11 +10976,9 @@ public void UpdateTrackActionsCoupling(bool couple_to_front) else if (ControlMode == TRAIN_CONTROL.MANUAL) { // set track occupation - UpdateSectionStateManual(); // reset routes and check sections either end of train - PresentPosition[0].RouteListIndex = -1; PresentPosition[1].RouteListIndex = -1; PreviousPosition[0].RouteListIndex = -1; @@ -11457,11 +10988,9 @@ public void UpdateTrackActionsCoupling(bool couple_to_front) else if (ControlMode == TRAIN_CONTROL.EXPLORER) { // set track occupation - UpdateSectionStateExplorer(); // reset routes and check sections either end of train - PresentPosition[0].RouteListIndex = -1; PresentPosition[1].RouteListIndex = -1; PreviousPosition[0].RouteListIndex = -1; @@ -11511,11 +11040,9 @@ public void UpdateOccupancies() // AddTrackSections // Add track sections not present in path to avoid out-of-path detection // - public void AddTrackSections() { // check if first section in route - if (ValidRoute[0].GetRouteIndex(OccupiedTrack[0].Index, 0) > 0) { int lastSectionIndex = OccupiedTrack[0].Index; @@ -11610,7 +11137,6 @@ public void AddTrackSections() // // Update track details after uncoupling // - public bool UpdateTrackActionsUncoupling(bool originalTrain) { bool inPath = true; @@ -11640,7 +11166,6 @@ public bool UpdateTrackActionsUncoupling(bool originalTrain) } // create new TCPositions - TrackNode tn = FrontTDBTraveller.TN; float offset = FrontTDBTraveller.TrackNodeOffset; int direction = (int)FrontTDBTraveller.Direction; @@ -11658,7 +11183,6 @@ public bool UpdateTrackActionsUncoupling(bool originalTrain) PresentPosition[1].DistanceTravelledM = DistanceTravelledM - Length; // Set track sections to occupied - OccupiedTrack.Clear(); // build route of sections now occupied @@ -11669,14 +11193,10 @@ public bool UpdateTrackActionsUncoupling(bool originalTrain) TrackCircuitSection thisSection; - // static train - if (TrainType == TRAINTYPE.STATIC) { - // clear routes, required actions, traffic details - ControlMode = TRAIN_CONTROL.UNDEFINED; if (TCRoute != null) { @@ -11700,7 +11220,6 @@ public bool UpdateTrackActionsUncoupling(bool originalTrain) TrafficService.TrafficDetails.Clear(); // build dummy route - thisSection = signalRef.TrackCircuitList[PresentPosition[1].TCSectionIndex]; offset = PresentPosition[1].TCOffset; @@ -11712,14 +11231,10 @@ public bool UpdateTrackActionsUncoupling(bool originalTrain) thisSection = signalRef.TrackCircuitList[thisElement.TCSectionIndex]; thisSection.SetOccupied(routedForward); } - } - // player train or AI train - else { - // InitializeSignals needs this info sometimes, so I repeat lines below here if (!IsActualPlayerTrain && (ControlMode == TRAIN_CONTROL.AUTO_SIGNAL || ControlMode == TRAIN_CONTROL.AUTO_NODE)) { @@ -11762,8 +11277,8 @@ public bool UpdateTrackActionsUncoupling(bool originalTrain) thisSection = signalRef.TrackCircuitList[thisElement.TCSectionIndex]; thisSection.SetOccupied(routedForward); } - // rebuild list of station stops + // rebuild list of station stops if (StationStops.Count > 0) { int presentStop = StationStops[0].PlatformReference; @@ -11812,18 +11327,15 @@ public bool UpdateTrackActionsUncoupling(bool originalTrain) // // Perform various reinitializations // - public void Reinitialize() { // reset signals etc. - SignalObjectItems.Clear(); NextSignalObject[0] = null; NextSignalObject[1] = null; LastReservedSection[0] = PresentPosition[0].TCSectionIndex; LastReservedSection[1] = PresentPosition[1].TCSectionIndex; - InitializeSignals(true); if (ControlMode == TRAIN_CONTROL.AUTO_SIGNAL || ControlMode == TRAIN_CONTROL.AUTO_NODE) @@ -11838,11 +11350,9 @@ public void Reinitialize() else if (ControlMode == TRAIN_CONTROL.MANUAL) { // set track occupation - UpdateSectionStateManual(); // reset routes and check sections either end of train - PresentPosition[0].RouteListIndex = -1; PresentPosition[1].RouteListIndex = -1; PreviousPosition[0].RouteListIndex = -1; @@ -11852,11 +11362,9 @@ public void Reinitialize() else if (ControlMode == TRAIN_CONTROL.EXPLORER) { // set track occupation - UpdateSectionStateExplorer(); // reset routes and check sections either end of train - PresentPosition[0].RouteListIndex = -1; PresentPosition[1].RouteListIndex = -1; PreviousPosition[0].RouteListIndex = -1; @@ -11874,7 +11382,6 @@ public void Reinitialize() // // Temporarily remove from track to allow decoupled train to set occupied sections // - public void TemporarilyRemoveFromTrack() { RemoveFromTrack(); @@ -11914,12 +11421,10 @@ public void IncrementSubpath(Train thisTrain) } } - //================================================================================================// // // Check on deadlock // - internal void CheckDeadlock(TCSubpathRoute thisRoute, int thisNumber) { if (signalRef.UseLocationPassingPaths) @@ -11936,15 +11441,12 @@ internal void CheckDeadlock(TCSubpathRoute thisRoute, int thisNumber) // // Check on deadlock - old style path based logic // - internal void CheckDeadlock_pathBased(TCSubpathRoute thisRoute, int thisNumber) { // clear existing deadlock info - ClearDeadlocks(); // build new deadlock info - foreach (Train otherTrain in Simulator.Trains) { if (otherTrain.Number != thisNumber && otherTrain.TrainType != TRAINTYPE.STATIC) @@ -12005,7 +11507,6 @@ internal void CheckDeadlock_pathBased(TCSubpathRoute thisRoute, int thisNumber) // // Obtain deadlock details - old style path based logic // - private int[] SetDeadlock_pathBased(int thisIndex, TCSubpathRoute thisRoute, TCSubpathRoute otherRoute, Train otherTrain) { int[] returnValue = new int[2]; @@ -12086,7 +11587,6 @@ private int[] SetDeadlock_pathBased(int thisIndex, TCSubpathRoute thisRoute, TCS endSectionFound = lastSection.CircuitType == TrackCircuitSection.TrackCircuitType.Junction; } } - else if (otherTrainIndex > 0) { for (int iIndex = otherTrainIndex - 1; iIndex >= 0 && !endSectionFound; iIndex--) @@ -12103,7 +11603,6 @@ private int[] SetDeadlock_pathBased(int thisIndex, TCSubpathRoute thisRoute, TCS } // set deadlock info for both trains - SetDeadlockInfo(firstSectionIndex, lastSectionIndex, otherTrain.Number); otherTrain.SetDeadlockInfo(lastSectionIndex, firstSectionIndex, Number); @@ -12123,21 +11622,17 @@ private int[] SetDeadlock_pathBased(int thisIndex, TCSubpathRoute thisRoute, TCS // // Check on deadlock - new style location based logic // - internal void CheckDeadlock_locationBased(TCSubpathRoute thisRoute, int thisNumber) { // clear existing deadlock info - ClearDeadlocks(); // build new deadlock info - foreach (Train otherTrain in Simulator.Trains) { bool validTrain = true; // check if not AI_Static - if (otherTrain.GetAIMovementState() == AITrain.AI_MOVEMENT_STATE.AI_STATIC) { validTrain = false; @@ -12188,7 +11683,6 @@ internal void CheckDeadlock_locationBased(TCSubpathRoute thisRoute, int thisNumb // // Obtain deadlock details - new style location based logic // - private int[] SetDeadlock_locationBased(int thisIndex, TCSubpathRoute thisRoute, TCSubpathRoute otherRoute, Train otherTrain) { int[] returnValue = new int[2]; @@ -12250,7 +11744,6 @@ private int[] SetDeadlock_locationBased(int thisIndex, TCSubpathRoute thisRoute, endOfPassLoop = true; endOfLoop = true; } - // get next section else if (nextThisRouteIndex < ValidRoute[0].Count - 2) { @@ -12270,7 +11763,6 @@ private int[] SetDeadlock_locationBased(int thisIndex, TCSubpathRoute thisRoute, passLength += passLoopSection.Length; } } - // end of route else { @@ -12279,12 +11771,9 @@ private int[] SetDeadlock_locationBased(int thisIndex, TCSubpathRoute thisRoute, } } } - // if section is a deadlock boundary, check available paths for both trains - else { - List thisTrainAllocatedPaths = new List(); List otherTrainAllocatedPaths = new List(); @@ -12386,7 +11875,6 @@ private int[] SetDeadlock_locationBased(int thisIndex, TCSubpathRoute thisRoute, } // if both trains have only one route, make sure it's not the same (inverse) route - if (thisTrainAllocatedPaths.Count == 1 && otherTrainAllocatedPaths.Count == 1) { if (thisDeadlockInfo.InverseInfo.ContainsKey(thisTrainAllocatedPaths[0]) && thisDeadlockInfo.InverseInfo[thisTrainAllocatedPaths[0]] == otherTrainAllocatedPaths[0]) @@ -12417,7 +11905,6 @@ private int[] SetDeadlock_locationBased(int thisIndex, TCSubpathRoute thisRoute, } // if loop not yet ended - not a valid pass location, move to next section (if available) - if (gotoNextSection) { // if this section is occupied by other train, break loop - further checks are of no use @@ -12441,7 +11928,6 @@ private int[] SetDeadlock_locationBased(int thisIndex, TCSubpathRoute thisRoute, } // if valid pass location : set return index - if (validPassLocation && endSectionRouteIndex >= 0) { returnValue[1] = endSectionRouteIndex; @@ -12473,7 +11959,6 @@ private int[] SetDeadlock_locationBased(int thisIndex, TCSubpathRoute thisRoute, endSectionFound = lastSection.CircuitType == TrackCircuitSection.TrackCircuitType.Junction; } } - else if (otherTrainIndex > 0) { for (int iIndex = otherTrainIndex; iIndex >= 0 && !endSectionFound; iIndex--) @@ -12502,7 +11987,6 @@ private int[] SetDeadlock_locationBased(int thisIndex, TCSubpathRoute thisRoute, } // set deadlock info for both trains - SetDeadlockInfo(firstSectionIndex, lastSectionIndex, otherTrain.Number); otherTrain.SetDeadlockInfo(lastSectionIndex, firstSectionIndex, Number); @@ -12513,7 +11997,6 @@ private int[] SetDeadlock_locationBased(int thisIndex, TCSubpathRoute thisRoute, } // if any section occupied by own train, reverse deadlock is active - TrackCircuitSection firstSection = signalRef.TrackCircuitList[firstSectionIndex]; int firstRouteIndex = ValidRoute[0].GetRouteIndex(firstSectionIndex, 0); @@ -12544,7 +12027,6 @@ private int[] SetDeadlock_locationBased(int thisIndex, TCSubpathRoute thisRoute, // Return value : boolean to indicate it is a deadlock or not // If not a deadlock, the REF int elementIndex is set to index of the last common section (will be increased in the loop) // - internal bool CheckRealDeadlock_locationBased(TCSubpathRoute thisRoute, TCSubpathRoute otherRoute, ref int elementIndex) { bool isValidDeadlock = false; @@ -12558,7 +12040,6 @@ internal bool CheckRealDeadlock_locationBased(TCSubpathRoute thisRoute, TCSubpat } // loop through common section - if signal is found, it is a deadlock - bool validLoop = true; int otherRouteIndex = otherRoute.GetRouteIndex(thisSection.Index, 0); @@ -12589,7 +12070,6 @@ internal bool CheckRealDeadlock_locationBased(TCSubpathRoute thisRoute, TCSubpat // if no signals along section, check if section is protected by signals - if so, it is not a deadlock // check only as far as maximum signal check distance - if (!isValidDeadlock) { // this route backward first @@ -12652,7 +12132,6 @@ internal bool CheckRealDeadlock_locationBased(TCSubpathRoute thisRoute, TCSubpat } // if not a valid deadlock, find end of common section - if (!isValidDeadlock) { int newElementIndex = EndCommonSection(elementIndex, thisRoute, otherRoute); @@ -12666,7 +12145,6 @@ internal bool CheckRealDeadlock_locationBased(TCSubpathRoute thisRoute, TCSubpat // // Set deadlock information // - private void SetDeadlockInfo(int firstSection, int lastSection, int otherTrainNumber) { List> DeadlockList = null; @@ -12689,7 +12167,6 @@ private void SetDeadlockInfo(int firstSection, int lastSection, int otherTrainNu // // Get end of common section // - static int EndCommonSection(int thisIndex, TCSubpathRoute thisRoute, TCSubpathRoute otherRoute) { int firstSection = thisRoute[thisIndex].TCSectionIndex; @@ -12715,14 +12192,11 @@ static int EndCommonSection(int thisIndex, TCSubpathRoute thisRoute, TCSubpathRo // // Check if waiting for deadlock // - public bool CheckDeadlockWait(SignalObject nextSignal) { - bool deadlockWait = false; // check section list of signal for any deadlock traps - foreach (TCRouteElement thisElement in nextSignal.signalRoute) { TrackCircuitSection thisSection = signalRef.TrackCircuitList[thisElement.TCSectionIndex]; @@ -12794,14 +12268,12 @@ public bool CheckDeadlockWait(SignalObject nextSignal) /// /// Create station stop list /// <\summary> - public void BuildStationList(float clearingDistanceM) { if (TrafficService == null) return; // no traffic definition // loop through traffic points - int beginActiveSubroute = 0; int activeSubrouteNodeIndex = 0; @@ -12835,7 +12307,6 @@ public void BuildStationList(float clearingDistanceM) /// /// Create station stop list /// <\summary> - public bool CreateStationStop(int platformStartID, int arrivalTime, int departTime, DateTime arrivalDT, DateTime departureDT, float clearingDistanceM, ref int beginActiveSubroute, ref int activeSubrouteNodeIndex) { @@ -12847,7 +12318,6 @@ public void BuildStationList(float clearingDistanceM) TCSubpathRoute thisRoute = TCRoute.TCRouteSubpaths[activeSubroute]; // get platform details - if (signalRef.PlatformXRefList.TryGetValue(platformStartID, out platformIndex)) { PlatformDetails thisPlatform = signalRef.PlatformDetailsList[platformIndex]; @@ -12882,9 +12352,7 @@ public void BuildStationList(float clearingDistanceM) routeIndex = -1; } - // if first section not found in route, try last - if (routeIndex < 0) { sectionIndex = thisPlatform.TCSectionIndex[thisPlatform.TCSectionIndex.Count - 1]; @@ -12904,7 +12372,6 @@ public void BuildStationList(float clearingDistanceM) } // if neither section found - try next subroute - keep trying till found or out of subroutes - while (routeIndex < 0 && activeSubroute < (TCRoute.TCRouteSubpaths.Count - 1)) { activeSubroute++; @@ -12940,7 +12407,6 @@ public void BuildStationList(float clearingDistanceM) } // if neither section found - platform is not on route - skip - if (routeIndex < 0) { Trace.TraceWarning("Train {0} Service {1} : platform {2} is not on route", @@ -12954,7 +12420,6 @@ public void BuildStationList(float clearingDistanceM) } // determine end stop position depending on direction - TCRouteElement thisElement = thisRoute[routeIndex]; int endSectionIndex = thisElement.Direction == 0 ? @@ -12971,7 +12436,6 @@ public void BuildStationList(float clearingDistanceM) TrackCircuitSection endSection = signalRef.TrackCircuitList[endSectionIndex]; - int firstRouteIndex = thisRoute.GetRouteIndex(beginSectionIndex, 0); if (firstRouteIndex < 0) firstRouteIndex = routeIndex; @@ -12980,7 +12444,6 @@ public void BuildStationList(float clearingDistanceM) lastRouteIndex = routeIndex; // if train too long : search back for platform with same name - float fullLength = thisPlatform.Length; if (deltaLength < 0) @@ -12990,7 +12453,6 @@ public void BuildStationList(float clearingDistanceM) TrackCircuitSection thisSection = signalRef.TrackCircuitList[beginSectionIndex]; // Other platforms in same section - if (thisSection.PlatformIndex.Count > 1) { foreach (int nextIndex in thisSection.PlatformIndex) @@ -13035,7 +12497,6 @@ public void BuildStationList(float clearingDistanceM) } // search back along route - if (deltaLength < 0) { float distance = fullLength + beginOffset; @@ -13084,14 +12545,12 @@ public void BuildStationList(float clearingDistanceM) } } - // determine stop position float stopOffset = endOffset - (0.5f * deltaLength); if (terminalStation && deltaLength > 0 && !Simulator.TimetableMode) stopOffset = endOffset - 1; // beyond section : check for route validity (may not exceed route) - if (stopOffset > endSection.Length) { float addOffset = stopOffset - endSection.Length; @@ -13108,7 +12567,6 @@ public void BuildStationList(float clearingDistanceM) } // check if stop offset beyond end signal - do not hold at signal - int EndSignal = -1; bool HoldSignal = false; bool NoWaitSignal = false; @@ -13116,7 +12574,6 @@ public void BuildStationList(float clearingDistanceM) // check if train is to reverse in platform // if so, set signal at other end as hold signal - int useDirection = thisElement.Direction; bool inDirection = true; @@ -13134,7 +12591,6 @@ public void BuildStationList(float clearingDistanceM) } // check for end signal - if (thisPlatform.EndSignals[useDirection] >= 0) { EndSignal = thisPlatform.EndSignals[useDirection]; @@ -13227,9 +12683,7 @@ public void BuildStationList(float clearingDistanceM) } // build and add station stop - TCRouteElement lastElement = thisRoute[lastRouteIndex]; - StationStop thisStation = new StationStop( platformStartID, thisPlatform, @@ -13255,14 +12709,11 @@ public void BuildStationList(float clearingDistanceM) false, false, StationStop.STOPTYPE.STATION_STOP); - thisStation.arrivalDT = arrivalDT; thisStation.departureDT = departureDT; - StationStops.Add(thisStation); // should this be reused? - // // // // if station has hold signal and this signal is the same as the exit signal for previous station, remove the exit signal from the previous station @@ -13280,9 +12731,7 @@ public void BuildStationList(float clearingDistanceM) // } // } - // add signal to list of hold signals - if (HoldSignal) { HoldingSignals.Add(EndSignal); @@ -13336,7 +12785,6 @@ public void BuildStationList(float clearingDistanceM) /// Check whether train is at Platform /// returns true if yes /// - public bool IsAtPlatform() { // build list of occupied section @@ -13382,11 +12830,9 @@ public bool IsAtPlatform() /// Check whether train has missed platform /// returns true if yes /// - public bool IsMissedPlatform(float thresholdDistance) { // check if station missed - int stationRouteIndex = ValidRoute[0].GetRouteIndex(StationStops[0].TCSectionIndex, 0); if (StationStops[0].SubrouteIndex == TCRoute.activeSubpath) @@ -13410,7 +12856,6 @@ public bool IsMissedPlatform(float thresholdDistance) /// Check vicinity of reversal point to Platform /// returns false if distance greater than preset value /// - public bool CheckVicinityOfPlatformToReversalPoint(float tcOffset, int routeListIndex, int activeSubpath) { float Threshold = 100.0f; @@ -13458,7 +12903,6 @@ public bool CheckVicinityOfPlatformToReversalPoint(float tcOffset, int routeList /// Parameters: /// maxDelay maximum added random delay (may be seconds or minutes) /// Ac - public int RandomizedDelayWithThreshold(int maxAddedDelay) { if (DateTime.Now.Millisecond % 10 < 6 - Simulator.Settings.ActRandomizationLevel) return 0; @@ -13472,7 +12916,6 @@ public int RandomizedDelayWithThreshold(int maxAddedDelay) /// Parameters: /// maxDelay maximum added random delay (may be seconds or minutes) /// - public int RandomizedDelay(int maxAddedDelay) { return (int)(Simulator.Random.Next(0, (int)(Simulator.Resolution * Simulator.Random.NextDouble()) + 1) / Simulator.Resolution * maxAddedDelay); @@ -13482,7 +12925,6 @@ public int RandomizedDelay(int maxAddedDelay) /// /// Computes a randomized delay for the various types of waiting points. /// - public int RandomizedWPDelay(ref int randomizedDelay) { if (randomizedDelay < 30000) // standard WP @@ -13511,10 +12953,8 @@ public int RandomizedWPDelay(ref int randomizedDelay) /// /// Convert player traffic list to station list /// <\summary> - public void ConvertPlayerTraffic(List playerList) { - if (playerList == null || playerList.Count == 0) { return; // no traffic details @@ -13538,7 +12978,6 @@ public void ConvertPlayerTraffic(List playerList) /// /// Clear station from list, clear exit signal if required /// <\summary> - public virtual void ClearStation(uint id1, uint id2, bool removeStation) { int foundStation = -1; @@ -13584,7 +13023,6 @@ public virtual void ClearStation(uint id1, uint id2, bool removeStation) /// /// Create pathless player train out of static train /// - public void CreatePathlessPlayerTrain() { TrainType = Train.TRAINTYPE.PLAYER; @@ -13601,7 +13039,6 @@ public void CreatePathlessPlayerTrain() /// Initializes speeds for pathless player train /// /// - public void InitializeSpeeds() { allowedMaxSpeedSignalMpS = allowedAbsoluteMaxSpeedSignalMpS; @@ -13614,7 +13051,6 @@ public void InitializeSpeeds() /// Gets the train name from one CarID; used for remote trains /// /// - public string GetTrainName(string ID) { int location = ID.LastIndexOf('-'); @@ -13623,7 +13059,6 @@ public string GetTrainName(string ID) } //================================================================================================// - /// /// Create status line /// <\summary> @@ -13764,7 +13199,6 @@ public string GetTrainName(string ID) /// <\remarks> public String[] GetStatus(bool metric) { - int iColumn = 0; string[] statusString = new string[13]; @@ -13887,7 +13321,6 @@ public String[] GetStatus(bool metric) // 8, "Distance" statusString[iColumn] = " "; } - else if (ControlMode == TRAIN_CONTROL.AUTO_NODE) { switch (EndAuthorityType[0]) @@ -14141,7 +13574,6 @@ public String[] GetStatus(bool metric) TrackCircuitSection thisSection = signalRef.TrackCircuitList[thisElement.TCSectionIndex]; circuitString = BuildSectionString(circuitString, thisSection, 0); - } } @@ -14191,7 +13623,6 @@ public String[] GetStatus(bool metric) circuitString = String.Concat(circuitString, "}="); // forward path - string forwardstring = String.Empty; for (int iindex = 0; iindex < ValidRoute[0].Count; iindex++) { @@ -14207,8 +13638,6 @@ public String[] GetStatus(bool metric) } //================================================================================================// - - /// /// Build string for section information /// returnString + @@ -14236,7 +13665,6 @@ public String[] GetStatus(bool metric) /// public string BuildSectionString(string thisString, TrackCircuitSection thisSection, int direction) { - string returnString = String.Copy(thisString); switch (thisSection.CircuitType) @@ -14310,7 +13738,6 @@ public string BuildSectionString(string thisString, TrackCircuitSection thisSect /// Create Path information line /// "Train", "Path" /// <\summary> - public String[] GetPathStatus(bool metric) { int iColumn = 0; @@ -14329,12 +13756,10 @@ public String[] GetPathStatus(bool metric) string circuitString = String.Empty; circuitString = string.Concat(circuitString, "Path: "); - statusString[iColumn] = String.Copy(circuitString); iColumn++; return (statusString); - } #endif @@ -14344,7 +13769,6 @@ public String[] GetPathStatus(bool metric) /// Update the string for 'TextPageDispatcherInfo'. /// Modifiy fields 4 and 5 /// <\summary> - public String[] AddRestartTime(String[] stateString) { String[] retString = new String[stateString.Length]; @@ -14404,12 +13828,10 @@ public String[] AddRestartTime(String[] stateString) return (retString); } - //================================================================================================// /// /// Generation of Train data useful for TCS and TrackMonitor; player train only /// <\summary> - // Contains data about all types of signals public Dictionary>[] PlayerTrainSignals; // first index 0 forward, 1 backward; second index signal type (NORMAL etc.) @@ -14792,7 +14214,6 @@ public TrainInfo GetTrainInfo() } // sort items on increasing distance - thisInfo.ObjectInfoForward.Sort(); thisInfo.ObjectInfoBackward.Sort(); @@ -14911,7 +14332,6 @@ public void GetTrainInfoAuto(ref TrainInfo thisInfo) } } - /// /// Add reversal info to TrackMonitorInfo /// @@ -14959,7 +14379,6 @@ public void AddWaitingPointInfo(ref TrainInfo thisInfo) float leftInSectionM = thisSection.Length - PresentPosition[0].TCOffset; // get action route index - if not found, return distances < 0 - int actionIndex0 = PresentPosition[0].RouteListIndex; int actionRouteIndex = ValidRoute[0].GetRouteIndex((AuxActionsContain.SpecAuxActions[0] as AIActionWPRef).TCSectionIndex, actionIndex0); var wpDistance = ValidRoute[0].GetDistanceAlongRoute(actionIndex0, leftInSectionM, actionRouteIndex, (AuxActionsContain.SpecAuxActions[0] as AIActionWPRef).RequiredDistance, AITrainDirectionForward, signalRef); @@ -15009,13 +14428,11 @@ public void GetTrainInfoManual(ref TrainInfo thisInfo) } // set forward information - // set authority TrainObjectItem thisItem = new TrainObjectItem(EndAuthorityType[0], DistanceToEndNodeAuthorityM[0]); thisInfo.ObjectInfoForward.Add(thisItem); // run along forward path to catch all speedposts, signals mileposts and diverging switches - const float maxDistanceM = 7000.0f; if (ValidRoute[0] != null) @@ -15058,13 +14475,11 @@ public void GetTrainInfoManual(ref TrainInfo thisInfo) } // set backward information - // set authority thisItem = new TrainObjectItem(EndAuthorityType[1], DistanceToEndNodeAuthorityM[1]); thisInfo.ObjectInfoBackward.Add(thisItem); // run along backward path to catch all speedposts and signals - if (ValidRoute[1] != null) { // Add all normal signals @@ -15169,7 +14584,6 @@ public void PresetExplorerPath(AIPath aiPath, Signals orgSignals) TCRoute = new TCRoutePath(aiPath, orgDirection, 0, orgSignals, Number, Simulator.Settings); // loop through all sections in first subroute except first and last (neither can be junction) - for (int iElement = 1; iElement <= TCRoute.TCRouteSubpaths[0].Count - 2; iElement++) { TrackCircuitSection thisSection = orgSignals.TrackCircuitList[TCRoute.TCRouteSubpaths[0][iElement].TCSectionIndex]; @@ -15177,7 +14591,6 @@ public void PresetExplorerPath(AIPath aiPath, Signals orgSignals) int prevSectionIndex = TCRoute.TCRouteSubpaths[0][iElement - 1].TCSectionIndex; // process Junction - if (thisSection.CircuitType == TrackCircuitSection.TrackCircuitType.Junction) { if (thisSection.Pins[0, 0].Link == nextSectionIndex && !MPManager.NoAutoSwitch()) @@ -15250,7 +14663,6 @@ public TCSubpathRoute ExtractAlternativeRoute_pathBased(int altRouteIndex) TCSubpathRoute returnRoute = new TCSubpathRoute(); // extract entries of alternative route upto first signal - foreach (TCRouteElement thisElement in TCRoute.TCAlternativePaths[altRouteIndex]) { returnRoute.Add(thisElement); @@ -15272,7 +14684,6 @@ public TCSubpathRoute ExtractAlternativeRoute_locationBased(TCSubpathRoute altRo TCSubpathRoute returnRoute = new TCSubpathRoute(); // extract entries of alternative route upto first signal - foreach (TCRouteElement thisElement in altRoute) { returnRoute.Add(thisElement); @@ -15308,7 +14719,6 @@ public virtual void SetAlternativeRoute_pathBased(int startElementIndex, int alt } // set new train route - TCSubpathRoute thisRoute = ValidRoute[0]; TCSubpathRoute newRoute = new TCSubpathRoute(); int actSubpath = TCRoute.activeSubpath; @@ -15317,14 +14727,12 @@ public virtual void SetAlternativeRoute_pathBased(int startElementIndex, int alt TCRoute.activeAltpath = altRouteIndex; // part upto split - for (int iElement = 0; iElement < startElementIndex; iElement++) { newRoute.Add(thisRoute[iElement]); } // alternative path - for (int iElement = 0; iElement < altRoute.Count; iElement++) { newRoute.Add(altRoute[iElement]); @@ -15336,7 +14744,6 @@ public virtual void SetAlternativeRoute_pathBased(int startElementIndex, int alt CheckAbandonedStations(startElementIndex, lastAlternativeSectionIndex, actSubpath, abdStations); // continued path - for (int iElement = lastAlternativeSectionIndex + 1; iElement < thisRoute.Count; iElement++) { newRoute.Add(thisRoute[iElement]); @@ -15349,7 +14756,6 @@ public virtual void SetAlternativeRoute_pathBased(int startElementIndex, int alt TCRoute.ReversalInfo[TCRoute.activeSubpath].LastSignalIndex = TCRoute.ReversalInfo[TCRoute.activeSubpath].LastSignalIndex + countDifference; // set new route - ValidRoute[0] = newRoute; TCRoute.TCRouteSubpaths[TCRoute.activeSubpath] = newRoute; @@ -15358,7 +14764,6 @@ public virtual void SetAlternativeRoute_pathBased(int startElementIndex, int alt // set signal route // part upto split - TCSubpathRoute newSignalRoute = new TCSubpathRoute(); int splitSignalIndex = nextSignal.signalRoute.GetRouteIndex(thisRoute[startElementIndex].TCSectionIndex, 0); @@ -15368,7 +14773,6 @@ public virtual void SetAlternativeRoute_pathBased(int startElementIndex, int alt } // extract new route upto next signal - TCSubpathRoute nextPart = ExtractAlternativeRoute_pathBased(altRouteIndex); foreach (TCRouteElement thisElement in nextPart) { @@ -15441,15 +14845,12 @@ public virtual void SetAlternativeRoute_locationBased(int startSectionIndex, Dea } // set new train route - TCSubpathRoute thisRoute = ValidRoute[0]; TCSubpathRoute newRoute = new TCSubpathRoute(); - TCSubpathRoute altRoute = sectionDeadlockInfo.AvailablePathList[usedPath].Path; int actSubpath = TCRoute.activeSubpath; // part upto split - int startElementIndex = thisRoute.GetRouteIndex(startSectionIndex, PresentPosition[0].RouteListIndex); for (int iElement = 0; iElement < startElementIndex; iElement++) { @@ -15457,14 +14858,12 @@ public virtual void SetAlternativeRoute_locationBased(int startSectionIndex, Dea } // alternative path - for (int iElement = 0; iElement < altRoute.Count; iElement++) { newRoute.Add(altRoute[iElement]); } // check for any deadlocks on abandoned path - but only if not on new path - int lastAlternativeSectionIndex = thisRoute.GetRouteIndex(altRoute[altRoute.Count - 1].TCSectionIndex, startElementIndex); for (int iElement = startElementIndex; iElement <= lastAlternativeSectionIndex; iElement++) { @@ -15498,12 +14897,10 @@ public virtual void SetAlternativeRoute_locationBased(int startSectionIndex, Dea File.AppendAllText(@"C:\temp\deadlock.txt", "\n"); #endif // check for any stations in abandoned path - Dictionary abdStations = new Dictionary(); CheckAbandonedStations(startElementIndex, lastAlternativeSectionIndex, actSubpath, abdStations); // continued path - for (int iElement = lastAlternativeSectionIndex + 1; iElement < thisRoute.Count; iElement++) { newRoute.Add(thisRoute[iElement]); @@ -15517,7 +14914,6 @@ public virtual void SetAlternativeRoute_locationBased(int startSectionIndex, Dea TCRoute.ReversalInfo[TCRoute.activeSubpath].LastSignalIndex = TCRoute.ReversalInfo[TCRoute.activeSubpath].LastSignalIndex + countDifference; // set new route - ValidRoute[0] = newRoute; TCRoute.TCRouteSubpaths[TCRoute.activeSubpath] = newRoute; @@ -15526,7 +14922,6 @@ public virtual void SetAlternativeRoute_locationBased(int startSectionIndex, Dea // set signal route // part upto split - if (nextSignal != null) { TCSubpathRoute newSignalRoute = new TCSubpathRoute(); @@ -15538,7 +14933,6 @@ public virtual void SetAlternativeRoute_locationBased(int startSectionIndex, Dea } // extract new route upto next signal - TCSubpathRoute nextPart = ExtractAlternativeRoute_locationBased(altRoute); foreach (TCRouteElement thisElement in nextPart) { @@ -15548,7 +14942,6 @@ public virtual void SetAlternativeRoute_locationBased(int startSectionIndex, Dea // set new signal route // reset signal // if train in signal mode, request clear signal - nextSignal.ResetSignal(true); nextSignal.signalRoute = newSignalRoute; @@ -15603,7 +14996,6 @@ private void CheckAbandonedStations(int startElementIndex, int lastAlternativeSe { int nextStationIndex = 0; - if (StationStops != null && StationStops.Count > 0) { int stationRouteIndex = StationStops[nextStationIndex].RouteIndex; @@ -15639,7 +15031,6 @@ private void CheckAbandonedStations(int startElementIndex, int lastAlternativeSe // private void LookForReplacementStations(Dictionary abdStations, TCSubpathRoute newRoute, TCSubpathRoute altRoute) { - if (StationStops != null) { List newStops = new List(); @@ -15755,7 +15146,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in TCSubpathRoute thisRoute = TCRoute.TCRouteSubpaths[activeSubroute]; // get platform details - if (!signalRef.PlatformXRefList.TryGetValue(platformStartID, out platformIndex)) { return (null); // station not found @@ -15767,7 +15157,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in int routeIndex = thisRoute.GetRouteIndex(sectionIndex, 0); // if first section not found in route, try last - if (routeIndex < 0) { sectionIndex = thisPlatform.TCSectionIndex[thisPlatform.TCSectionIndex.Count - 1]; @@ -15775,7 +15164,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in } // if neither section found - try next subroute - keep trying till found or out of subroutes - while (routeIndex < 0 && activeSubroute < (TCRoute.TCRouteSubpaths.Count - 1)) { activeSubroute++; @@ -15783,7 +15171,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in routeIndex = thisRoute.GetRouteIndex(sectionIndex, 0); // if first section not found in route, try last - if (routeIndex < 0) { sectionIndex = thisPlatform.TCSectionIndex[thisPlatform.TCSectionIndex.Count - 1]; @@ -15792,7 +15179,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in } // if neither section found - platform is not on route - skip - if (routeIndex < 0) { Trace.TraceWarning("Train {0} Service {1} : platform {2} is not on route", @@ -15801,7 +15187,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in } // determine end stop position depending on direction - TCRouteElement thisElement = thisRoute[routeIndex]; int endSectionIndex = thisElement.Direction == 0 ? @@ -15818,7 +15203,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in TrackCircuitSection endSection = signalRef.TrackCircuitList[endSectionIndex]; - int firstRouteIndex = thisRoute.GetRouteIndex(beginSectionIndex, 0); if (firstRouteIndex < 0) firstRouteIndex = routeIndex; @@ -15829,7 +15213,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in float stopOffset = 0; float fullLength = thisPlatform.Length; - // if train too long : search back for platform with same name if (deltaLength < 0) { @@ -15838,7 +15221,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in TrackCircuitSection thisSection = signalRef.TrackCircuitList[beginSectionIndex]; // Other platforms in same section - if (thisSection.PlatformIndex.Count > 1) { foreach (int nextIndex in thisSection.PlatformIndex) @@ -15864,7 +15246,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in int addRouteIndex = thisRoute.GetRouteIndex(otherSectionIndex, 0); float addOffset = otherPlatform.TCOffset[1, thisElement.Direction == 0 ? 1 : 0]; // offset of begin in other direction is length of available track - if (lastRouteIndex > 0) { float thisLength = @@ -15883,7 +15264,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in } // search back along route - if (deltaLength < 0) { float distance = fullLength + beginOffset; @@ -15912,13 +15292,10 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in deltaLength = fullLength - Length; } - // determine stop position - stopOffset = endOffset - (0.5f * deltaLength); // beyond section : check for route validity (may not exceed route) - if (stopOffset > endSection.Length) { float addOffset = stopOffset - endSection.Length; @@ -15935,7 +15312,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in } // check if stop offset beyond end signal - do not hold at signal - int EndSignal = -1; bool HoldSignal = false; bool NoWaitSignal = false; @@ -15943,7 +15319,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in // check if train is to reverse in platform // if so, set signal at other end as hold signal - int useDirection = thisElement.Direction; bool inDirection = true; @@ -15959,7 +15334,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in } // check for end signal - if (thisPlatform.EndSignals[useDirection] >= 0) { EndSignal = thisPlatform.EndSignals[useDirection]; @@ -16037,9 +15411,7 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in } // build and add station stop - TCRouteElement lastElement = thisRoute[lastRouteIndex]; - StationStop thisStation = new StationStop( platformStartID, thisPlatform, @@ -16065,7 +15437,6 @@ public StationStop CalculateStationStop(int platformStartID, int arrivalTime, in false, false, StationStop.STOPTYPE.STATION_STOP); - thisStation.arrivalDT = arrivalDT; thisStation.departureDT = departureDT; @@ -16472,7 +15843,6 @@ public void CheckLocoPower(float elapsedClockSeconds) iLocoUnpoweredCar = jLocoUnpoweredCar; locoUnpowered = SearchFrontOfTrain(ref iLocoUnpoweredCar); } - } else { @@ -16527,7 +15897,6 @@ private bool SearchBackOfTrain(ref int iLocoUnpoweredCar) /// private bool SearchFrontOfTrain(ref int iLocoUnpoweredCar) { - var locoUnpowered = false; while (iLocoUnpoweredCar >= 0 && !((Cars[iLocoUnpoweredCar] is MSTSElectricLocomotive || Cars[iLocoUnpoweredCar] is MSTSDieselLocomotive) && Cars[iLocoUnpoweredCar].Parts.Count >= 2)) iLocoUnpoweredCar--; @@ -16543,7 +15912,6 @@ private bool SearchFrontOfTrain(ref int iLocoUnpoweredCar) /// Routed train class : train class plus valid route direction indication /// Used throughout in the signalling process in order to derive correct route in Manual and Explorer modes /// - public class TrainRouted { public Train Train; @@ -16553,7 +15921,6 @@ public class TrainRouted /// /// Constructor /// - public TrainRouted(Train thisTrain, int thisIndex) { Train = thisTrain; @@ -16565,7 +15932,6 @@ public TrainRouted(Train thisTrain, int thisIndex) /// /// Track Circuit Route Path /// - public class TCRoutePath { public List TCRouteSubpaths = new List(); @@ -16586,18 +15952,14 @@ public class TCRoutePath /// /// Constructor (from AIPath) /// - public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals orgSignals, int trainNumber, UserSettings settings) { activeSubpath = 0; activeAltpath = -1; float offset = 0; - // // collect all TC Elements - // // get tracknode from first path node - // int sublist = 0; Dictionary AlternativeRoutes = new Dictionary(); @@ -16613,10 +15975,7 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org List reversalOffset = new List(); List reversalIndex = new List(); - // // if original direction not set, determine it through first switch - // - if (orgDir < -1) { bool firstSwitch = false; @@ -16648,10 +16007,7 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org currentDir = jnDir; } - // // loop through path nodes - // - AIPathNode thisPathNode = aiPath.Nodes[0]; AIPathNode nextPathNode = null; AIPathNode lastPathNode = null; @@ -16667,7 +16023,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org lastPathNode = thisPathNode; // process siding items - if (thisPathNode.Type == AIPathNodeType.SidingStart) { TrackNode sidingNode = aiPath.TrackDB.TrackNodes[thisPathNode.JunctionIndex]; @@ -16693,10 +16048,7 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org thisPathNode.Type = AIPathNodeType.Other; } - // // process last non-junction section - // - if (thisPathNode.Type == AIPathNodeType.Other) { thisNode = aiPath.TrackDB.TrackNodes[trackNodeIndex]; @@ -16712,7 +16064,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org SetStationReference(TCRouteSubpaths, thisElement.TCSectionIndex, orgSignals); } newDir = thisNode.TrPins[currentDir].Direction; - } else { @@ -16781,10 +16132,7 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // SPA: WP: New forms - // // process junction section - // - if (thisPathNode.JunctionIndex > 0) { TrackNode junctionNode = aiPath.TrackDB.TrackNodes[thisPathNode.JunctionIndex]; @@ -16822,7 +16170,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org // if we were on last main node, direction was already set if (nextPathNode != null) currentDir = newDir; - } else { @@ -16856,7 +16203,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org { reverseOffset += reversalNode.TCCrossReference[i].Length; sectionIndex = reversalNode.TCCrossReference[i].Index; - } } else @@ -16885,7 +16231,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org int[] waitingPoint = new int[6]; waitingPoint[0] = sublist + reversal; waitingPoint[1] = ConvertWaitingPoint(nextPathNode, aiPath.TrackDB, aiPath.TSectionDat, currentDir); - waitingPoint[2] = nextPathNode.WaitTimeS; waitingPoint[3] = nextPathNode.WaitUntil; waitingPoint[4] = -1; // hold signal set later @@ -16894,7 +16239,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // other type of path need not be processed - // go to next node nextPathNode = nextPathNode.NextMainNode; } @@ -16922,7 +16266,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } } newDir = thisNode.TrPins[currentDir].Direction; - } else { @@ -16946,10 +16289,8 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org reversal--; // reset reverse point } } - // - // add last section - // + // add last section thisNode = aiPath.TrackDB.TrackNodes[trackNodeIndex]; TrVectorSection endFirstSection = thisNode.TrVectorNode.TrVectorSections[0]; Traveller TDBEndTrav = new Traveller(aiPath.TSectionDat, aiPath.TrackDB.TrackNodes, thisNode, @@ -16971,7 +16312,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org { reverseEndOffset += thisNode.TCCrossReference[i].Length; endNodeSectionIndex = thisNode.TCCrossReference[i].Index; - } } else @@ -17029,7 +16369,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // check if section extends to end of track - TCRouteElement lastElement = thisSubpath[thisSubpath.Count - 1]; TrackCircuitSection lastEndSection = orgSignals.TrackCircuitList[lastElement.TCSectionIndex]; int lastDirection = lastElement.Direction; @@ -17061,7 +16400,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // remove sections beyond reversal points - for (int iSub = 0; iSub < reversalOffset.Count; iSub++) // no reversal for final path { TCSubpathRoute revSubPath = TCRouteSubpaths[reversalIndex[iSub]]; @@ -17076,7 +16414,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org int lastSectionIndex = revSubPath.Count - 1; // create list of sections beyond reversal point - if (direction == 0) { for (int iSection = revSubPath.Count - 1; iSection > 0 && withinOffset; iSection--) @@ -17129,7 +16466,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // extend route to first signal or first node - bool signalFound = false; for (int iSection = lastSectionIndex; iSection < revSubPath.Count - 1 && !signalFound; iSection++) @@ -17143,7 +16479,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // remove sections beyond first signal or first node from reversal point - for (int iSection = 0; iSection < removeSections.Count; iSection++) { revSubPath.RemoveAt(removeSections[iSection]); @@ -17151,7 +16486,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // remove dummy subpaths (from double reversion) - List subRemoved = new List(); int orgCount = TCRouteSubpaths.Count; int removed = 0; @@ -17204,7 +16538,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // if remove, update indices in station xref - Dictionary copyXRef = StationXRef; StationXRef.Clear(); @@ -17217,10 +16550,8 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // find if last stretch is dummy track - // first, find last signal - there may not be a junction between last signal and end // last end must be end-of-track - foreach (TCSubpathRoute endSubPath in TCRouteSubpaths) { int lastIndex = endSubPath.Count - 1; @@ -17228,7 +16559,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org TrackCircuitSection lastSection = orgSignals.TrackCircuitList[thisElement.TCSectionIndex]; // build additional route from end of last section but not further than train length - int nextSectionIndex = lastSection.ActivePins[thisElement.OutPin[0], thisElement.OutPin[1]].Link; int nextDirection = lastSection.ActivePins[thisElement.OutPin[0], thisElement.OutPin[1]].Direction; int lastUseIndex = lastIndex - 1; // do not use final element if this is end of track @@ -17249,9 +16579,7 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org if (lastSection.CircuitType == TrackCircuitSection.TrackCircuitType.EndOfTrack) { - // first length of added sections - float totalLength = 0.0f; bool juncfound = false; @@ -17267,7 +16595,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org // next length of sections back to last signal // stop loop : when junction found, when signal found, when length exceeds train length - int sigIndex = -1; for (int iSection = lastUseIndex; @@ -17292,7 +16619,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // remove dummy ends - if (sigIndex > 0 && totalLength < 0.5f * thisTrainLength) { for (int iSection = endSubPath.Count - 1; iSection > sigIndex; iSection--) @@ -17311,7 +16637,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // for reversals, find actual diverging section - int prevDivergeSectorIndex = -1; int iReversalLists = 0; TCReversalInfo reversalInfo; @@ -17342,12 +16667,9 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org ReversalInfo[ReversalInfo.Count - 1].ReverseReversalOffset = RoughReversalInfos[RoughReversalInfos.Count - 1].ReverseReversalOffset; ReversalInfo[ReversalInfo.Count - 1].ReversalIndex = RoughReversalInfos[RoughReversalInfos.Count - 1].SubPathIndex; ReversalInfo[ReversalInfo.Count - 1].ReversalSectionIndex = RoughReversalInfos[RoughReversalInfos.Count - 1].ReversalSectionIndex; - RoughReversalInfos.Clear(); // no more used - // process alternative paths - MSTS style - if (orgSignals.UseLocationPassingPaths) { ProcessAlternativePath_LocationDef(AlternativeRoutes, aiPath, orgSignals, trainNumber); @@ -17359,7 +16681,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org } // search for loops - LoopSearch(orgSignals); #if DEBUG_TEST @@ -17441,7 +16762,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org for (int iWP = 0; iWP < WaitingPoints.Count; iWP++) { - File.AppendAllText(@"C:\temp\TCSections.txt", "--------------------------------------------------\n"); File.AppendAllText(@"C:\temp\TCSections.txt", "\n-- Waiting Point Info : " + iWP.ToString() + " --\n\n"); int[] thisWaitingPoint = WaitingPoints[iWP]; @@ -17459,7 +16779,6 @@ public TCRoutePath(AIPath aiPath, int orgDir, float thisTrainLength, Signals org // SPA: Used with enhanced MSTS Mode, please don't change float GetOffsetToPathNode(AIPath aiPath, int direction, AIPathNode pathNode) { - float offset = 0; TrackNode WPNode; TrVectorSection firstSection; @@ -17579,13 +16898,11 @@ public String[] GetTCRouteInfo(String[] stateString, TCPosition position) retString[3] = "..."; retString[4] = TCSidxString; return (retString); - } //================================================================================================// // // process alternative paths - MSTS style Path definition // - public void ProcessAlternativePath_PathDef(Dictionary AlternativeRoutes, AIPath aiPath, Signals orgSignals) { int altlist = 0; @@ -17632,16 +16949,12 @@ public void ProcessAlternativePath_PathDef(Dictionary AlternativeRou int currentDir = startElement.Direction; int newDir = currentDir; - // // loop through path nodes - // - AIPathNode thisPathNode = aiPath.Nodes[pathDetails[1]]; AIPathNode nextPathNode = null; AIPathNode lastPathNode = null; // process junction node - TrackNode firstJunctionNode = aiPath.TrackDB.TrackNodes[thisPathNode.JunctionIndex]; TCRouteElement thisJunctionElement = new TCRouteElement(firstJunctionNode, 0, currentDir, orgSignals); @@ -17663,17 +16976,12 @@ public void ProcessAlternativePath_PathDef(Dictionary AlternativeRou } // process alternative path - TrackNode thisNode = null; thisPathNode = thisPathNode.NextSidingNode; while (thisPathNode != null) { - - // // process last non-junction section - // - if (thisPathNode.Type == AIPathNodeType.Other) { if (trackNodeIndex > 0) @@ -17689,7 +16997,6 @@ public void ProcessAlternativePath_PathDef(Dictionary AlternativeRou thisAltpath.Add(thisElement); } newDir = thisNode.TrPins[currentDir].Direction; - } else { @@ -17704,10 +17011,7 @@ public void ProcessAlternativePath_PathDef(Dictionary AlternativeRou trackNodeIndex = -1; } - // // process junction section - // - if (thisPathNode.JunctionIndex > 0) { TrackNode junctionNode = aiPath.TrackDB.TrackNodes[thisPathNode.JunctionIndex]; @@ -17741,10 +17045,7 @@ public void ProcessAlternativePath_PathDef(Dictionary AlternativeRou currentDir = newDir; - // // find next junction path node - // - nextPathNode = thisPathNode.NextSidingNode; } else @@ -17760,10 +17061,8 @@ public void ProcessAlternativePath_PathDef(Dictionary AlternativeRou lastPathNode = thisPathNode; thisPathNode = nextPathNode; } - // - // add last section - // + // add last section if (trackNodeIndex > 0) { thisNode = aiPath.TrackDB.TrackNodes[trackNodeIndex]; @@ -17798,7 +17097,6 @@ public void ProcessAlternativePath_PathDef(Dictionary AlternativeRou // // process alternative paths - location definition // - public void ProcessAlternativePath_LocationDef(Dictionary AlternativeRoutes, AIPath aiPath, Signals orgSignals, int trainNumber) { foreach (KeyValuePair thisAltPathIndex in AlternativeRoutes) @@ -17834,16 +17132,12 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ int currentDir = startElement.Direction; int newDir = currentDir; - // // loop through path nodes - // - AIPathNode thisPathNode = aiPath.Nodes[pathDetails[1]]; AIPathNode nextPathNode = null; AIPathNode lastPathNode = null; // process junction node - TrackNode firstJunctionNode = aiPath.TrackDB.TrackNodes[thisPathNode.JunctionIndex]; TCRouteElement thisJunctionElement = new TCRouteElement(firstJunctionNode, 0, currentDir, orgSignals); @@ -17865,17 +17159,12 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ } // process alternative path - TrackNode thisNode = null; thisPathNode = thisPathNode.NextSidingNode; while (thisPathNode != null) { - - // // process last non-junction section - // - if (thisPathNode.Type == AIPathNodeType.Other) { if (trackNodeIndex > 0) @@ -17891,7 +17180,6 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ thisAltpath.Add(thisElement); } newDir = thisNode.TrPins[currentDir].Direction; - } else { @@ -17906,10 +17194,7 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ trackNodeIndex = -1; } - // // process junction section - // - if (thisPathNode.JunctionIndex > 0) { TrackNode junctionNode = aiPath.TrackDB.TrackNodes[thisPathNode.JunctionIndex]; @@ -17943,10 +17228,7 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ currentDir = newDir; - // // find next junction path node - // - nextPathNode = thisPathNode.NextSidingNode; } else @@ -17962,10 +17244,8 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ lastPathNode = thisPathNode; thisPathNode = nextPathNode; } - // - // add last section - // + // add last section if (trackNodeIndex > 0) { thisNode = aiPath.TrackDB.TrackNodes[trackNodeIndex]; @@ -18001,12 +17281,10 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ // process alternative paths - location definition // main path may be NULL if private path is to be set for fixed deadlocks // - public void InsertPassingPath(TCSubpathRoute mainPath, TCSubpathRoute passPath, int startSectionIndex, int endSectionIndex, Signals orgSignals, int trainNumber, int sublistRef) { // if main set, check if path is valid diverge path - otherwise assume it is indeed - if (mainPath != null) { int[,] validPassingPath = mainPath.FindActualDivergePath(passPath, 0, mainPath.Count - 1); @@ -18020,7 +17298,6 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ } // find related deadlock definition - note that path may be extended to match other deadlock paths - DeadlockInfo thisDeadlock = new DeadlockInfo(orgSignals); thisDeadlock = thisDeadlock.FindDeadlockInfo(ref passPath, mainPath, startSectionIndex, endSectionIndex); @@ -18031,7 +17308,6 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ } // insert main path - int usedStartSectionIndex = passPath[0].TCSectionIndex; int usedEndSectionIndex = passPath[passPath.Count - 1].TCSectionIndex; int usedStartSectionRouteIndex = mainPath.GetRouteIndex(usedStartSectionIndex, 0); @@ -18064,7 +17340,6 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ } // if name is main insert inverse path also as MAIN to ensure reverse path is available - if (String.Compare(thisDeadlockPathInfo.Name, "MAIN") == 0 && !orgSignals.Simulator.TimetableMode) { TCSubpathRoute inverseMainPath = mainPathPart.ReversePath(orgSignals); @@ -18092,7 +17367,6 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ } // add passing path - int[] passIndex = thisDeadlock.AddPath(passPath, startSectionIndex); if (passIndex[1] < 0) @@ -18116,7 +17390,6 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ } // insert inverse path only if public - if (trainNumber < 0) { TCSubpathRoute inversePassPath = passPath.ReversePath(orgSignals); @@ -18149,7 +17422,6 @@ public void ProcessAlternativePath_LocationDef(Dictionary Alternativ // search for valid passing paths // includes public paths // - public void SearchPassingPaths(int trainNumber, float trainLength, Signals orgSignals) { for (int iSubpath = 0; iSubpath <= TCRouteSubpaths.Count - 1; iSubpath++) @@ -18184,7 +17456,6 @@ public void SearchPassingPaths(int trainNumber, float trainLength, Signals orgSi // // search for loops // - public void LoopSearch(Signals orgSignals) { List> loopList = new List>(); @@ -18215,7 +17486,6 @@ public void LoopSearch(Signals orgSignals) // check if loop reverses or continues loopreverse = thisElement.Direction != thisRoute[loopindex].Direction; - } else if (sections.ContainsKey(thisElement.TCSectionIndex) && loopset) { @@ -18249,7 +17519,6 @@ public void LoopSearch(Signals orgSignals) // check for inner loops within outer loops // if found, remove outer loops - for (int iRoute = 0; iRoute <= TCRouteSubpaths.Count - 1; iRoute++) { List invalids = new List(); @@ -18267,14 +17536,12 @@ public void LoopSearch(Signals orgSignals) } // preset loop ends to invalid - for (int iRoute = 0; iRoute <= TCRouteSubpaths.Count - 1; iRoute++) { LoopEnd.Add(-1); } // split loops with overlap - search backward as subroutes may be added - int orgTotalRoutes = TCRouteSubpaths.Count; for (int iRoute = orgTotalRoutes - 1; iRoute >= 0; iRoute--) { @@ -18322,7 +17589,6 @@ public void LoopSearch(Signals orgSignals) // // Constructor from existing path // - public TCRoutePath(TCRoutePath otherPath) { activeSubpath = otherPath.activeSubpath; @@ -18376,7 +17642,6 @@ public TCRoutePath(TCRoutePath otherPath) // // Constructor from single subpath // - public TCRoutePath(TCSubpathRoute subPath) { activeSubpath = 0; @@ -18389,7 +17654,6 @@ public TCRoutePath(TCSubpathRoute subPath) // // Restore // - public TCRoutePath(BinaryReader inf) { activeSubpath = inf.ReadInt32(); @@ -18444,7 +17708,6 @@ public TCRoutePath(BinaryReader inf) // // Save // - public void Save(BinaryWriter outf) { outf.Write(activeSubpath); @@ -18493,7 +17756,6 @@ public void Save(BinaryWriter outf) // // Convert waiting point to section no. // - static int ConvertWaitingPoint(AIPathNode stopPathNode, TrackDB TrackDB, TrackSectionsFile TSectionDat, int direction) { TrackNode waitingNode = TrackDB.TrackNodes[stopPathNode.NextMainTVNIndex]; @@ -18530,7 +17792,6 @@ static int ConvertWaitingPoint(AIPathNode stopPathNode, TrackDB TrackDB, TrackSe // // Check for reversal offset margin // - public void SetReversalOffset(float trainLength, bool timetableMode = true) { TCReversalInfo thisReversal = ReversalInfo[activeSubpath]; @@ -18541,7 +17802,6 @@ public void SetReversalOffset(float trainLength, bool timetableMode = true) // // build station xref list // - public void SetStationReference(List subpaths, int sectionIndex, Signals orgSignals) { TrackCircuitSection actSection = orgSignals.TrackCircuitList[sectionIndex]; @@ -18565,7 +17825,6 @@ public void SetStationReference(List subpaths, int sectionIndex, // To the end will be added to the new subpath. // The WaitingPoint list will be aligned with. // - public void CloneSubPath(int WPIdx, int position) { int subpathIdx = WaitingPoints[WPIdx][0]; @@ -18597,14 +17856,12 @@ public void CloneSubPath(int WPIdx, int position) // // add sections from other path at front // - public void AddSectionsAtStart(TCSubpathRoute otherRoute, Train train, bool reverse) { int addedSections = 0; // add sections from other path at front // as sections are inserted at index 0, insertion must take place in reverse sequence to preserve original sequence - // add in reverse sequence - also reverse direction if (reverse) { @@ -18683,7 +17940,6 @@ public void AddSectionsAtStart(TCSubpathRoute otherRoute, Train train, bool reve // // Add subroute from other path at front // - public void AddSubrouteAtStart(TCSubpathRoute otherRoute, Train train) { TCRouteSubpaths.Insert(0, new TCSubpathRoute(otherRoute)); @@ -18712,14 +17968,12 @@ public void AddSubrouteAtStart(TCSubpathRoute otherRoute, Train train) thisStop.SubrouteIndex++; } } - } //================================================================================================// // // Add sections from other path at end // - public void AddSectionsAtEnd(TCSubpathRoute otherRoute, bool reverse) { int addedSections = 0; @@ -18779,7 +18033,6 @@ public void AddSectionsAtEnd(TCSubpathRoute otherRoute, bool reverse) // // Add subroute from other path at end // - public void AddSubrouteAtEnd(TCSubpathRoute otherRoute) { TCRouteSubpaths.Add(new TCSubpathRoute(otherRoute)); @@ -18792,7 +18045,6 @@ public void AddSubrouteAtEnd(TCSubpathRoute otherRoute) // add additional loop end info LoopEnd.Add(-1); - } } @@ -18800,7 +18052,6 @@ public void AddSubrouteAtEnd(TCSubpathRoute otherRoute) /// /// Track Circuit Route Element /// - public class TCRouteElement { public int TCSectionIndex; @@ -18822,7 +18073,6 @@ public class TCRouteElement /// /// Constructor from tracknode /// - public TCRouteElement(TrackNode thisNode, int TCIndex, int direction, Signals mySignals) { TCSectionIndex = thisNode.TCCrossReference[TCIndex].Index; @@ -18859,7 +18109,6 @@ public TCRouteElement(TrackNode thisNode, int TCIndex, int direction, Signals my /// /// Constructor from CircuitSection /// - public TCRouteElement(TrackCircuitSection thisSection, int direction, Signals mySignals, int lastSectionIndex) { TCSectionIndex = thisSection.Index; @@ -18890,7 +18139,6 @@ public TCRouteElement(TrackCircuitSection thisSection, int direction, Signals my /// /// Constructor for additional items for route checking (not part of train route, NORMAL items only) /// - public TCRouteElement(int TCIndex, int direction) { TCSectionIndex = TCIndex; @@ -18905,7 +18153,6 @@ public TCRouteElement(int TCIndex, int direction) // // Constructor from other route element // - public TCRouteElement(TCRouteElement otherElement) { TCSectionIndex = otherElement.TCSectionIndex; @@ -18935,7 +18182,6 @@ public TCRouteElement(TCRouteElement otherElement) // // Restore // - public TCRouteElement(BinaryReader inf) { TCSectionIndex = inf.ReadInt32(); @@ -18968,7 +18214,6 @@ public TCRouteElement(BinaryReader inf) // // Save // - public void Save(BinaryWriter outf) { outf.Write(TCSectionIndex); @@ -18986,7 +18231,6 @@ public void Save(BinaryWriter outf) outf.Write(-1); } - if (EndAlternativePath != null) { outf.Write(EndAlternativePath[0]); @@ -19007,25 +18251,20 @@ public void Save(BinaryWriter outf) /// /// Subpath list : list of TCRouteElements building a subpath /// - public class TCSubpathRoute : List { - //================================================================================================// // // Base contstructor // - public TCSubpathRoute() { } - //================================================================================================// // // Constructor from existing subpath // - public TCSubpathRoute(TCSubpathRoute otherSubpathRoute) { if (otherSubpathRoute != null) @@ -19042,7 +18281,6 @@ public TCSubpathRoute(TCSubpathRoute otherSubpathRoute) // Constructor from part of existing subpath // if either value is < 0, start from start or stop at end // - public TCSubpathRoute(TCSubpathRoute otherSubpathRoute, int startIndex, int endIndex) { int lstartIndex = startIndex >= 0 ? startIndex : 0; @@ -19062,7 +18300,6 @@ public TCSubpathRoute(TCSubpathRoute otherSubpathRoute, int startIndex, int endI // // Restore // - public TCSubpathRoute(BinaryReader inf) { int totalElements = inf.ReadInt32(); @@ -19078,7 +18315,6 @@ public TCSubpathRoute(BinaryReader inf) // // Save // - public void Save(BinaryWriter outf) { outf.Write(this.Count); @@ -19092,7 +18328,6 @@ public void Save(BinaryWriter outf) /// /// Get sectionindex in subpath /// <\summary> - public int GetRouteIndex(int thisSectionIndex, int startIndex) { for (int iNode = startIndex; iNode >= 0 && iNode < this.Count; iNode++) @@ -19111,7 +18346,6 @@ public int GetRouteIndex(int thisSectionIndex, int startIndex) /// /// Get sectionindex in subpath /// <\summary> - public int GetRouteIndexBackward(int thisSectionIndex, int startIndex) { for (int iNode = startIndex - 1; iNode >= 0 && iNode < this.Count; iNode--) @@ -19130,7 +18364,6 @@ public int GetRouteIndexBackward(int thisSectionIndex, int startIndex) /// /// returns if signal is ahead of train /// <\summary> - public bool SignalIsAheadOfTrain(SignalObject thisSignal, TCPosition trainPosition) { int signalSection = thisSignal.TCReference; @@ -19172,7 +18405,6 @@ public bool SignalIsAheadOfTrain(SignalObject thisSignal, TCPosition trainPositi /// /// returns distance along route /// <\summary> - public float GetDistanceAlongRoute(int startSectionIndex, float startOffset, int endSectionIndex, float endOffset, bool forward, Signals signals) @@ -19221,7 +18453,6 @@ public bool SignalIsAheadOfTrain(SignalObject thisSignal, TCPosition trainPositi /// /// returns if position is ahead of train /// <\summary> - // without offset public static bool IsAheadOfTrain(TrackCircuitSection thisSection, TCPosition trainPosition) { @@ -19244,7 +18475,6 @@ public static bool IsAheadOfTrain(TrackCircuitSection thisSection, float offset, // // Converts list of elements to dictionary // - public Dictionary ConvertRoute() { Dictionary thisDict = new Dictionary(); @@ -19264,22 +18494,18 @@ public static bool IsAheadOfTrain(TrackCircuitSection thisSection, float offset, /// /// check if subroute contains section /// <\summary> - public bool ContainsSection(TCRouteElement thisElement) { // convert route to dictionary - Dictionary thisRoute = ConvertRoute(); return (thisRoute.ContainsKey(thisElement.TCSectionIndex)); } - //================================================================================================// /// /// Find actual diverging path from alternative path definition /// Returns : [0,*] = Main Route, [1,*] = Alt Route, [*,0] = Start Index, [*,1] = End Index /// <\summary> - public int[,] FindActualDivergePath(TCSubpathRoute altRoute, int startIndex, int endIndex) { int[,] returnValue = new int[2, 2] { { -1, -1 }, { -1, -1 } }; @@ -19333,7 +18559,6 @@ public bool ContainsSection(TCRouteElement thisElement) /// key is last section to be used in path (before signal or node) /// value is usefull length /// <\summary> - public Dictionary GetUsefullLength(float defaultSignalClearingDistance, Signals signals, int startIndex, int endIndex) { float actLength = 0.0f; @@ -19358,7 +18583,6 @@ public bool ContainsSection(TCRouteElement thisElement) useLength = actLength; // intermediate sections - for (int iSection = usedStartIndex + 1; iSection < usedEndIndex - 1; iSection++) { TCRouteElement thisElement = this[iSection]; @@ -19375,7 +18599,6 @@ public bool ContainsSection(TCRouteElement thisElement) } // last section if no signal found - if (!endSignal) { TrackCircuitSection lastSection = signals.TrackCircuitList[this[usedEndIndex].TCSectionIndex]; @@ -19401,11 +18624,9 @@ public bool ContainsSection(TCRouteElement thisElement) /// compares if equal to other path /// paths must be exactly equal (no part check) /// <\summary> - public bool EqualsPath(TCSubpathRoute otherRoute) { // check common route parts - if (Count != otherRoute.Count) return (false); // if path lengths are unequal they cannot be the same bool equalPath = true; @@ -19427,11 +18648,9 @@ public bool EqualsPath(TCSubpathRoute otherRoute) /// compares if equal to other path in reverse /// paths must be exactly equal (no part check) /// <\summary> - public bool EqualsReversePath(TCSubpathRoute otherRoute) { // check common route parts - if (Count != otherRoute.Count) return (false); // if path lengths are unequal they cannot be the same bool equalPath = true; @@ -19452,7 +18671,6 @@ public bool EqualsReversePath(TCSubpathRoute otherRoute) /// /// reverses existing path /// <\summary> - public TCSubpathRoute ReversePath(Signals orgSignals) { TCSubpathRoute reversePath = new TCSubpathRoute(); @@ -19469,7 +18687,6 @@ public TCSubpathRoute ReversePath(Signals orgSignals) // reset outpin for JUNCTION // if trailing, pin[0] = 0, pin[1] = 0 // if facing, pin[0] = 1, check next element for pin[1] - if (thisSection.CircuitType == TrackCircuitSection.TrackCircuitType.Junction) { if (newElement.FacingPoint) @@ -19499,7 +18716,6 @@ public TCSubpathRoute ReversePath(Signals orgSignals) /// /// TrackCircuit position class /// - public class TCPosition { public int TCSectionIndex; @@ -19513,7 +18729,6 @@ public class TCPosition /// /// constructor - creates empty item /// - public TCPosition() { TCSectionIndex = -1; @@ -19528,7 +18743,6 @@ public TCPosition() // // Restore // - public void RestorePresentPosition(BinaryReader inf, Train train) { TrackNode tn = train.FrontTDBTraveller.TN; @@ -19555,7 +18769,6 @@ public void RestorePresentPosition(BinaryReader inf, Train train) } } - public void RestorePresentRear(BinaryReader inf, Train train) { TrackNode tn = train.RearTDBTraveller.TN; @@ -19582,7 +18795,6 @@ public void RestorePresentRear(BinaryReader inf, Train train) } } - public void RestorePreviousPosition(BinaryReader inf) { TCSectionIndex = inf.ReadInt32(); @@ -19593,12 +18805,10 @@ public void RestorePreviousPosition(BinaryReader inf) DistanceTravelledM = inf.ReadSingle(); } - //================================================================================================// // // Restore dummies for trains not yet started // - public void RestorePresentPositionDummy(BinaryReader inf, Train train) { TCSectionIndex = inf.ReadInt32(); @@ -19609,7 +18819,6 @@ public void RestorePresentPositionDummy(BinaryReader inf, Train train) DistanceTravelledM = inf.ReadSingle(); } - public void RestorePresentRearDummy(BinaryReader inf, Train train) { TCSectionIndex = inf.ReadInt32(); @@ -19620,7 +18829,6 @@ public void RestorePresentRearDummy(BinaryReader inf, Train train) DistanceTravelledM = inf.ReadSingle(); } - public void RestorePreviousPositionDummy(BinaryReader inf) { TCSectionIndex = inf.ReadInt32(); @@ -19635,7 +18843,6 @@ public void RestorePreviousPositionDummy(BinaryReader inf) // // Save // - public void Save(BinaryWriter outf) { outf.Write(TCSectionIndex); @@ -19650,7 +18857,6 @@ public void Save(BinaryWriter outf) /// /// Copy TCPosition /// <\summary> - public void CopyTo(ref TCPosition thisPosition) { thisPosition.TCSectionIndex = this.TCSectionIndex; @@ -19665,7 +18871,6 @@ public void CopyTo(ref TCPosition thisPosition) /// /// Reverse (or continue in same direction) /// <\summary> - public void Reverse(int oldDirection, TCSubpathRoute thisRoute, float offset, Signals orgSignals) { RouteListIndex = thisRoute.GetRouteIndex(TCSectionIndex, 0); @@ -19708,7 +18913,6 @@ public void SetTCPosition(TrackCircuitXRefList trackCircuitXRefList, float offse /// /// Reversal information class /// - public class TCReversalInfo { public bool Valid; @@ -19731,7 +18935,6 @@ public class TCReversalInfo /// /// Constructor (from route path details) /// <\summary> - public TCReversalInfo(TCSubpathRoute lastRoute, int prevReversalIndex, TCSubpathRoute firstRoute, Signals orgSignals, float reverseReversalOffset, int reversalIndex, int reversalSectionIndex) { // preset values @@ -19748,7 +18951,6 @@ public TCReversalInfo(TCSubpathRoute lastRoute, int prevReversalIndex, TCSubpath ReversalActionInserted = false; // search for first common section in last and first - int lastIndex = lastRoute.Count - 1; int firstIndex = 0; @@ -19819,7 +19021,6 @@ public TCReversalInfo(TCSubpathRoute lastRoute, int prevReversalIndex, TCSubpath } // determine offset - if (validDivPoint) { DivergeOffset = 0.0f; @@ -19830,7 +19031,6 @@ public TCReversalInfo(TCSubpathRoute lastRoute, int prevReversalIndex, TCSubpath } // find last signal furthest away from diverging point - bool signalFound = false; int startSection = 0; @@ -19900,7 +19100,6 @@ public TCReversalInfo(TCSubpathRoute lastRoute, int prevReversalIndex, TCSubpath /// /// Constructor (from copy) /// <\summary> - public TCReversalInfo(TCReversalInfo otherInfo) { Valid = otherInfo.Valid; @@ -19926,7 +19125,6 @@ public TCReversalInfo(TCReversalInfo otherInfo) /// /// Constructor (for invalid item) /// <\summary> - public TCReversalInfo() { // preset values @@ -19954,7 +19152,6 @@ public TCReversalInfo() /// /// Constructor for Restore /// <\summary> - public TCReversalInfo(BinaryReader inf) { Valid = inf.ReadBoolean(); @@ -19979,7 +19176,6 @@ public TCReversalInfo(BinaryReader inf) /// /// Save /// <\summary> - public void Save(BinaryWriter outf) { outf.Write(Valid); @@ -20005,7 +19201,6 @@ public void Save(BinaryWriter outf) /// /// Rough Reversal information class, used only during route building. /// - public class RoughReversalInfo { public int SubPathIndex; @@ -20016,23 +19211,18 @@ public class RoughReversalInfo /// /// Constructor (from route path details) /// <\summary> - public RoughReversalInfo(int subPathIndex, float reverseReversalOffset, int reversalSectionIndex) { - - SubPathIndex = subPathIndex; ReverseReversalOffset = reverseReversalOffset; ReversalSectionIndex = reversalSectionIndex; } } - //================================================================================================// /// /// Distance Travelled action item list /// - public class DistanceTravelledActions : LinkedList { readonly List itemList = new List(); @@ -20041,7 +19231,6 @@ public class DistanceTravelledActions : LinkedList // // Copy list // - public DistanceTravelledActions Copy() { DistanceTravelledActions newList = new DistanceTravelledActions(); @@ -20065,15 +19254,12 @@ public DistanceTravelledActions Copy() return (newList); } - //================================================================================================// /// /// Insert item on correct distance /// <\summary> - public void InsertAction(DistanceTravelledItem thisItem) { - if (this.Count == 0) { this.AddFirst(thisItem); @@ -20119,7 +19305,6 @@ public void InsertClearSection(float distance, int sectionIndex) /// /// Get list of items to be processed /// <\summary> - public List GetActions(float distance) { itemList.Clear(); @@ -20167,7 +19352,6 @@ public List GetAuxActions(Train thisTrain, float distance /// /// Get list of items to be processed of particular type /// <\summary> - public List GetActions(float distance, Type reqType) { itemList.Clear(); @@ -20205,7 +19389,6 @@ public List GetActions(float distance, Type reqType) /// /// Get distance of last track clearance item /// <\summary> - public float? GetLastClearingDistance() { float? lastDistance = null; @@ -20230,7 +19413,6 @@ public List GetActions(float distance, Type reqType) /// /// update any pending speed limits to new limit /// <\summary> - public void UpdatePendingSpeedlimits(float reqSpeedMpS) { foreach (var thisAction in this) @@ -20259,7 +19441,6 @@ public void UpdatePendingSpeedlimits(float reqSpeedMpS) /// /// remove any pending AIActionItems /// <\summary> - public void RemovePendingAIActionItems(bool removeAll) { List itemsToRemove = new List(); @@ -20277,15 +19458,12 @@ public void RemovePendingAIActionItems(bool removeAll) { this.Remove(thisAction); } - } - //================================================================================================// /// /// Modifies required distance of actions after a train coupling /// <\summary> - public void ModifyRequiredDistance(float Length) { foreach (var thisAction in this) @@ -20302,7 +19480,6 @@ public void ModifyRequiredDistance(float Length) /// /// Distance Travelled action item - base class for all possible actions /// - public class DistanceTravelledItem { public float RequiredDistance; @@ -20311,7 +19488,6 @@ public class DistanceTravelledItem // // Base contructor // - public DistanceTravelledItem() { } @@ -20320,7 +19496,6 @@ public DistanceTravelledItem() // // Restore // - public DistanceTravelledItem(BinaryReader inf) { RequiredDistance = inf.ReadSingle(); @@ -20330,7 +19505,6 @@ public DistanceTravelledItem(BinaryReader inf) // // Save // - public void Save(BinaryWriter outf) { if (this is ActivateSpeedLimit) @@ -20372,7 +19546,6 @@ public void Save(BinaryWriter outf) { outf.Write(-1); } - } } @@ -20380,7 +19553,6 @@ public void Save(BinaryWriter outf) /// /// Distance Travelled Clear Section action item /// - public class ClearSectionItem : DistanceTravelledItem { public int TrackSectionIndex; // in case of CLEAR_SECTION // @@ -20389,7 +19561,6 @@ public class ClearSectionItem : DistanceTravelledItem /// /// constructor for clear section /// - public ClearSectionItem(float distance, int sectionIndex) { RequiredDistance = distance; @@ -20400,7 +19571,6 @@ public ClearSectionItem(float distance, int sectionIndex) // // Restore // - public ClearSectionItem(BinaryReader inf) : base(inf) { @@ -20411,20 +19581,16 @@ public ClearSectionItem(BinaryReader inf) // // Save // - public void SaveItem(BinaryWriter outf) { outf.Write(TrackSectionIndex); } - - } //================================================================================================// /// /// Distance Travelled Speed Limit Item /// - public class ActivateSpeedLimit : DistanceTravelledItem { public float MaxSpeedMpSLimit = -1; @@ -20435,7 +19601,6 @@ public class ActivateSpeedLimit : DistanceTravelledItem /// /// constructor for speedlimit value /// - public ActivateSpeedLimit(float reqDistance, float maxSpeedMpSLimit, float maxSpeedMpSSignal, float maxTempSpeedMpSLimit = -1) { RequiredDistance = reqDistance; @@ -20448,7 +19613,6 @@ public ActivateSpeedLimit(float reqDistance, float maxSpeedMpSLimit, float maxSp // // Restore // - public ActivateSpeedLimit(BinaryReader inf) : base(inf) { @@ -20461,7 +19625,6 @@ public ActivateSpeedLimit(BinaryReader inf) // // Save // - public void SaveItem(BinaryWriter outf) { outf.Write(MaxSpeedMpSLimit); @@ -20478,7 +19641,6 @@ public class ClearMovingTableAction : DistanceTravelledItem /// /// constructor for speedlimit value /// - public ClearMovingTableAction(float reqDistance, float maxSpeedMpSLimit) { RequiredDistance = reqDistance; @@ -20489,7 +19651,6 @@ public ClearMovingTableAction(float reqDistance, float maxSpeedMpSLimit) // // Restore // - public ClearMovingTableAction(BinaryReader inf) : base(inf) { @@ -20500,12 +19661,10 @@ public ClearMovingTableAction(BinaryReader inf) // // Save // - public void SaveItem(BinaryWriter outf) { outf.Write(OriginalMaxTrainSpeedMpS); } - } //================================================================================================// @@ -20513,10 +19672,8 @@ public void SaveItem(BinaryWriter outf) /// StationStop class /// Class to hold information on station stops /// <\summary> - public class StationStop : IComparable { - public enum STOPTYPE { STATION_STOP, @@ -20572,7 +19729,6 @@ public enum STOPTYPE // // Constructor // - public StationStop(int platformReference, PlatformDetails platformItem, int subrouteIndex, int routeIndex, int tcSectionIndex, int direction, int exitSignal, bool holdSignal, bool noWaitSignal, bool noClaimAllowed, float stopOffset, int arrivalTime, int departTime, bool terminal, int? actualMinStopTime, float? keepClearFront, float? keepClearRear, @@ -20625,7 +19781,6 @@ public enum STOPTYPE // // Constructor to create empty item (used for passing variables only) // - public StationStop() { } @@ -20634,7 +19789,6 @@ public StationStop() // // Restore // - public StationStop(BinaryReader inf, Signals signalRef) { ActualStopType = (STOPTYPE)inf.ReadInt32(); @@ -20737,7 +19891,6 @@ public StationStop(BinaryReader inf, Signals signalRef) // // Compare To (to allow sort) // - public int CompareTo(StationStop otherStop) { if (this.SubrouteIndex < otherStop.SubrouteIndex) @@ -20774,7 +19927,6 @@ public int CompareTo(StationStop otherStop) // // Save // - public void Save(BinaryWriter outf) { outf.Write((int)ActualStopType); @@ -20870,7 +20022,6 @@ public StationStop CreateCopy() /// Make special checks for stops arount midnight /// /// - public int CalculateDepartTime(int presentTime, Train stoppedTrain) { int eightHundredHours = 8 * 3600; @@ -20919,8 +20070,8 @@ public int CalculateDepartTime(int presentTime, Train stoppedTrain) stopTime += ActualDepart - correctedTime; if (stopTime > 24 * 3600) stopTime -= 24 * 3600; else if (stopTime < 0) stopTime += 24 * 3600; - } + return stopTime; } @@ -20987,7 +20138,6 @@ public int ComputeStationBoardingTime(Train stopTrain) } else { - passengerCarsWithinPlatform = stopTrain.Length - trainPartOutsidePlatformForward - trainPartOutsidePlatformBackward > 0 ? stopTrain.PassengerCarsNumber : (int)Math.Min((stopTrain.Length - trainPartOutsidePlatformForward - trainPartOutsidePlatformBackward) / stopTrain.Cars.Count() + 0.33, stopTrain.PassengerCarsNumber); @@ -21021,7 +20171,6 @@ public bool CheckScheduleValidity(Train stopTrain) /// Randomizes number of passengers waiting for train, and therefore boarding time /// Randomization can be upwards or downwards /// - private void RandomizePassengersWaiting(ref int actualNumPassengersWaiting, Train stopTrain) { if (stopTrain.Simulator.Settings.ActRandomizationLevel > 0) @@ -21043,14 +20192,12 @@ private void RandomizePassengersWaiting(ref int actualNumPassengersWaiting, Trai } } } - } //================================================================================================// /// /// Class for info to TrackMonitor display /// - public class TrainInfo { public TRAIN_CONTROL ControlMode; // present control mode @@ -21068,7 +20215,6 @@ public class TrainInfo /// /// Constructor - creates empty objects, data is filled by GetInfo routine from Train /// <\summary> - public TrainInfo() { ObjectInfoForward = new List(); @@ -21090,7 +20236,6 @@ public void Clear() } /// no need for Restore or Save items as info is not kept in permanent variables - } /// @@ -21174,7 +20319,6 @@ public enum SpeedItemType // DistanceToTrainM // SignalObject - //================================================================================================// /// /// Constructors @@ -21309,14 +20453,12 @@ public TrainObjectItem(float thisDistanceM, int thisTunnelLength, TRAINOBJECTTYP StationPlatformLength = thisTunnelLength; } - /// no need for Restore or Save items as info is not kept in permanent variables //================================================================================================// // // Compare To (to allow sort) // - public int CompareTo(TrainObjectItem otherItem) { if (this.DistanceToTrainM < otherItem.DistanceToTrainM) @@ -21370,8 +20512,8 @@ private void UpdateCarSlack(float expectedLength) { car.CouplerSlackM = staticLength - car.GetCouplerZeroLengthM(); } - } + public void UpdateRemoteTrainPos(float elapsedClockSeconds) { float newDistanceTravelledM = DistanceTravelledM; @@ -21421,7 +20563,6 @@ public void UpdateRemoteTrainPos(float elapsedClockSeconds) this.travelled = expectedTravelled; this.RearTDBTraveller = t; CalculatePositionOfCars(); - } } else//if the predicted location and reported location are similar, will try to increase/decrease the speed to bridge the gap in 1 second @@ -21442,7 +20583,6 @@ public void UpdateRemoteTrainPos(float elapsedClockSeconds) } /*if (Math.Abs(requestedSpeed) < 0.00001 && Math.Abs(SpeedMpS) > 0.01) updateMSGReceived = true; //if requested is stop, but the current speed is still moving else*/ - } else//no message received, will move at the previous speed { @@ -21500,7 +20640,6 @@ public void UpdateRemoteTrainPos(float elapsedClockSeconds) //Orient(); return; - } /// @@ -21508,7 +20647,6 @@ public void UpdateRemoteTrainPos(float elapsedClockSeconds) /// public void ClearValidRoutes() { - if (ValidRoute[0] != null) { int listIndex = PresentPosition[0].RouteListIndex; @@ -21533,22 +20671,18 @@ public void ClearValidRoutes() /// public void ClearReservedSections() { - if (ValidRoute[0] != null) { int listIndex = PresentPosition[0].RouteListIndex; signalRef.BreakDownRouteList(ValidRoute[0], listIndex, routedForward); ClearDeadlocks(); } - } - /// /// After turntable rotation, must find where it is /// /// - public void ReenterTrackSections(int trackNodeIndex, int trVectorSectionIndex, Vector3 finalFrontTravellerXNALocation, Vector3 finalRearTravellerXNALocation, Traveller.TravellerDirection direction) { FrontTDBTraveller = new Traveller(Simulator.TSectionDat, Simulator.TDB.TrackDB.TrackNodes, Simulator.TDB.TrackDB.TrackNodes[trackNodeIndex], @@ -21616,6 +20750,5 @@ public void ReinitializeEOT() EOT = (EOT)Cars.First(); } } - }// class Train }