Beispiel #1
0
        /// <summary>Is called once a frame, to update the door states of the specified train</summary>
        /// <param name="Train">The train</param>
        /// <param name="TimeElapsed">The frame time elapsed</param>
        private static void UpdateTrainDoors(Train Train, double TimeElapsed)
        {
            OpenBveApi.Runtime.DoorStates oldState = OpenBveApi.Runtime.DoorStates.None;
            OpenBveApi.Runtime.DoorStates newState = OpenBveApi.Runtime.DoorStates.None;
            for (int i = 0; i < Train.Cars.Length; i++)
            {
                bool   ld = Train.Cars[i].Doors[0].AnticipatedOpen;
                bool   rd = Train.Cars[i].Doors[1].AnticipatedOpen;
                double os = Train.Cars[i].Specs.DoorOpenFrequency;
                double cs = Train.Cars[i].Specs.DoorCloseFrequency;

                for (int j = 0; j < Train.Cars[i].Doors.Length; j++)
                {
                    if (Train.Cars[i].Doors[j].Direction == -1 | Train.Cars[i].Doors[j].Direction == 1)
                    {
                        bool shouldBeOpen = Train.Cars[i].Doors[j].Direction == -1 ? ld : rd;
                        if (Train.Cars[i].Doors[j].State > 0.0)
                        {
                            if (Train.Cars[i].Doors[j].Direction == -1)
                            {
                                oldState |= OpenBveApi.Runtime.DoorStates.Left;
                            }
                            else
                            {
                                oldState |= OpenBveApi.Runtime.DoorStates.Right;
                            }
                        }
                        if (shouldBeOpen)
                        {
                            // open
                            Train.Cars[i].Doors[j].State += os * TimeElapsed;
                            if (Train.Cars[i].Doors[j].State > 1.0)
                            {
                                Train.Cars[i].Doors[j].State = 1.0;
                            }
                        }
                        else
                        {
                            // close
                            if (Train.Cars[i].Doors[j].DoorLockDuration > 0.0)
                            {
                                if (Train.Cars[i].Doors[j].State > Train.Cars[i].Doors[j].DoorLockState)
                                {
                                    Train.Cars[i].Doors[j].State -= cs * TimeElapsed;
                                }
                                if (Train.Cars[i].Doors[j].State < Train.Cars[i].Doors[j].DoorLockState)
                                {
                                    Train.Cars[i].Doors[j].State = Train.Cars[i].Doors[j].DoorLockState;
                                }
                                Train.Cars[i].Doors[j].DoorLockDuration -= TimeElapsed;
                                if (Train.Cars[i].Doors[j].DoorLockDuration < 0.0)
                                {
                                    Train.Cars[i].Doors[j].DoorLockDuration = 0.0;
                                }
                            }
                            else
                            {
                                Train.Cars[i].Doors[j].State -= cs * TimeElapsed;
                            }
                            if (Train.Cars[i].Doors[j].AnticipatedReopen && Train.Cars[i].Doors[j].State < Train.Cars[i].Doors[j].InterferingObjectRate)
                            {
                                Train.Cars[i].Doors[j].State = Train.Cars[i].Doors[j].InterferingObjectRate;
                            }
                            if (Train.Cars[i].Doors[j].State < 0.0)
                            {
                                Train.Cars[i].Doors[j].State = 0.0;
                            }
                        }
                        if (Train.Cars[i].Doors[j].State > 0.0)
                        {
                            if (Train.Cars[i].Doors[j].Direction == -1)
                            {
                                newState |= OpenBveApi.Runtime.DoorStates.Left;
                            }
                            else
                            {
                                newState |= OpenBveApi.Runtime.DoorStates.Right;
                            }
                        }
                    }
                }
            }

            if (oldState != OpenBveApi.Runtime.DoorStates.None & newState == OpenBveApi.Runtime.DoorStates.None)
            {
                Sounds.SoundBuffer buffer = Train.Cars[Train.DriverCar].Sounds.PilotLampOn.Buffer;
                if (buffer != null)
                {
                    OpenBveApi.Math.Vector3 pos = Train.Cars[Train.DriverCar].Sounds.PilotLampOn.Position;
                    Sounds.PlaySound(buffer, 1.0, 1.0, pos, Train, Train.DriverCar, false);
                }
            }
            else if (oldState == OpenBveApi.Runtime.DoorStates.None & newState != OpenBveApi.Runtime.DoorStates.None)
            {
                Sounds.SoundBuffer buffer = Train.Cars[Train.DriverCar].Sounds.PilotLampOff.Buffer;
                if (buffer != null)
                {
                    OpenBveApi.Math.Vector3 pos = Train.Cars[Train.DriverCar].Sounds.PilotLampOff.Position;
                    Sounds.PlaySound(buffer, 1.0, 1.0, pos, Train, Train.DriverCar, false);
                }
            }
            if (oldState != newState)
            {
                if (Train.Plugin != null)
                {
                    Train.Plugin.DoorChange(oldState, newState);
                }
            }
        }
Beispiel #2
0
        /// <summary>Is called once a frame, to update the door states of the specified train</summary>
        /// <param name="Train">The train</param>
        /// <param name="TimeElapsed">The frame time elapsed</param>
        private static void UpdateTrainDoors(Train Train, double TimeElapsed)
        {
            OpenBveApi.Runtime.DoorStates oldState = OpenBveApi.Runtime.DoorStates.None;
            OpenBveApi.Runtime.DoorStates newState = OpenBveApi.Runtime.DoorStates.None;
            for (int i = 0; i < Train.Cars.Length; i++)
            {
                bool   ld = Train.Cars[i].Doors[0].AnticipatedOpen;
                bool   rd = Train.Cars[i].Doors[1].AnticipatedOpen;
                double os = Train.Cars[i].Specs.DoorOpenFrequency;
                double cs = Train.Cars[i].Specs.DoorCloseFrequency;

                for (int j = 0; j < Train.Cars[i].Doors.Length; j++)
                {
                    if (Train.Cars[i].Doors[j].Direction == -1 | Train.Cars[i].Doors[j].Direction == 1)
                    {
                        bool shouldBeOpen = Train.Cars[i].Doors[j].Direction == -1 ? ld : rd;
                        if (Train.Cars[i].Doors[j].State > 0.0)
                        {
                            if (Train.Cars[i].Doors[j].Direction == -1)
                            {
                                oldState |= OpenBveApi.Runtime.DoorStates.Left;
                            }
                            else
                            {
                                oldState |= OpenBveApi.Runtime.DoorStates.Right;
                            }
                        }
                        if (shouldBeOpen)
                        {
                            // open
                            Train.Cars[i].Doors[j].State += os * TimeElapsed;
                            if (Train.Cars[i].Doors[j].State > 1.0)
                            {
                                Train.Cars[i].Doors[j].State = 1.0;
                            }
                        }
                        else
                        {
                            // close
                            if (Train.Cars[i].Doors[j].DoorLockDuration > 0.0)
                            {
                                if (Train.Cars[i].Doors[j].State > Train.Cars[i].Doors[j].DoorLockState)
                                {
                                    Train.Cars[i].Doors[j].State -= cs * TimeElapsed;
                                }
                                if (Train.Cars[i].Doors[j].State < Train.Cars[i].Doors[j].DoorLockState)
                                {
                                    Train.Cars[i].Doors[j].State = Train.Cars[i].Doors[j].DoorLockState;
                                }
                                Train.Cars[i].Doors[j].DoorLockDuration -= TimeElapsed;
                                if (Train.Cars[i].Doors[j].DoorLockDuration < 0.0)
                                {
                                    Train.Cars[i].Doors[j].DoorLockDuration = 0.0;
                                }
                            }
                            else
                            {
                                Train.Cars[i].Doors[j].State -= cs * TimeElapsed;
                            }
                            if (Train.Cars[i].Doors[j].AnticipatedReopen && Train.Cars[i].Doors[j].State < Train.Cars[i].Doors[j].InterferingObjectRate)
                            {
                                Train.Cars[i].Doors[j].State = Train.Cars[i].Doors[j].InterferingObjectRate;
                            }
                            if (Train.Cars[i].Doors[j].State < 0.0)
                            {
                                Train.Cars[i].Doors[j].State = 0.0;
                            }
                        }
                        if (Train.Cars[i].Doors[j].State > 0.0)
                        {
                            if (Train.Cars[i].Doors[j].Direction == -1)
                            {
                                newState |= OpenBveApi.Runtime.DoorStates.Left;
                            }
                            else
                            {
                                newState |= OpenBveApi.Runtime.DoorStates.Right;
                            }
                        }
                    }
                }
            }

            if (Train.SafetySystems.PilotLamp != null)
            {
                Train.SafetySystems.PilotLamp.Update(newState);
            }

            if (oldState != newState)
            {
                if (Train.Plugin != null)
                {
                    Train.Plugin.DoorChange(oldState, newState);
                }
            }
        }