示例#1
0
 public PassAlarm(PassAlarmType type, AbstractCar Car)
 {
     this.baseCar = Car;
     this.Type    = type;
     this.Sound   = new CarSound();
     this.Lit     = false;
 }
示例#2
0
 public PilotLamp(AbstractCar car)
 {
     baseCar  = car;
     oldState = DoorStates.None;
     OnSound  = new CarSound();
     OffSound = new CarSound();
 }
示例#3
0
 public void BuildTestContext(CarFactory cf)
 {
     AbstractCar c1 = cf.CreateCar();
     AbstractCar c2 = cf.CreateCar();
     AbstractCar c3 = cf.CreateCar();
     AbstractCar c4 = cf.CreateCar();
 }
        public AbstractCar next()
        {
            AbstractCar abstractCar = _volkswagenCatalogue[_arrayPosition];

            _arrayPosition++;
            return(abstractCar);
        }
示例#5
0
    public void AddCar(AbstractCar car)
    {
        Debug.Assert(!cars.Contains(car));

        cars.Add(car);
        roadControlForRoad(car.position.referenceRoad).AddCar(car);
    }
示例#6
0
 /// <summary>Creates a new breaker</summary>
 /// <param name="car">The car</param>
 public Breaker(AbstractCar car)
 {
     Resumed           = false;
     Car               = car;
     Resume            = new CarSound();
     ResumeOrInterrupt = new CarSound();
 }
示例#7
0
        /// <summary>Triggers a change in run and flange sounds</summary>
        /// <param name="direction">The direction of travel- 1 for forwards, and -1 for backwards</param>
        /// <param name="trackFollower">The TrackFollower</param>
        public override void Trigger(int direction, TrackFollower trackFollower)
        {
            AbstractCar car = trackFollower.Car;

            switch (trackFollower.TriggerType)
            {
            case EventTriggerType.FrontCarFrontAxle:
            case EventTriggerType.OtherCarFrontAxle:
                if (direction < 0)
                {
                    car.FrontAxle.RunIndex    = PreviousRunIndex;
                    car.FrontAxle.FlangeIndex = PreviousFlangeIndex;
                }
                else if (direction > 0)
                {
                    car.FrontAxle.RunIndex    = NextRunIndex;
                    car.FrontAxle.FlangeIndex = NextFlangeIndex;
                }
                break;

            case EventTriggerType.RearCarRearAxle:
            case EventTriggerType.OtherCarRearAxle:
                if (direction < 0)
                {
                    car.RearAxle.RunIndex    = PreviousRunIndex;
                    car.RearAxle.FlangeIndex = PreviousFlangeIndex;
                }
                else if (direction > 0)
                {
                    car.RearAxle.RunIndex    = NextRunIndex;
                    car.RearAxle.FlangeIndex = NextFlangeIndex;
                }
                break;
            }
        }
示例#8
0
    // finds which direction to head to at the intersection
    // note that car.referenceIntersection is different from the parameter intersection
    // car's referenceRoad connects the above two intersection
    // car is at the parameter intersection
    public Road targetWayForAbstractCarAtIntersection(AbstractCar car, Intersection intersection)
    {
        switch (intersection.GetGraphicsType())
        {
        case Intersection.IntersectionGraphicsType.NONE:
            return(null);

        case Intersection.IntersectionGraphicsType.ONE_WAY_WRAP:
            return(intersection.getConnectedRoads()[0]);

        case Intersection.IntersectionGraphicsType.TWO_WAY_SKEW:
        case Intersection.IntersectionGraphicsType.TWO_WAY_TRANSITION:
        case Intersection.IntersectionGraphicsType.TWO_WAY_SMOOTH:
            // for two way, we always return the other way
            return(intersection.getConnectedRoads()[0] == car.position.referenceRoad
                    ? intersection.getConnectedRoads()[1]
                    : intersection.getConnectedRoads()[0]);

        case Intersection.IntersectionGraphicsType.MULTI_WAY:
            // we return random for now
            int pickedIndex = 0;
            do
            {
                pickedIndex = Random.Range(0, intersection.getConnectedRoads().Length);
            } while (intersection.getConnectedRoads()[pickedIndex] == car.position.referenceRoad);

            return(intersection.getConnectedRoads()[pickedIndex]);

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
示例#9
0
 public void StartServiceProcess(AbstractCar car)
 {
     _listOfServiceHandlers[0].Service(car);
     if (car.IsServiceComplete())
     {
         Console.WriteLine("Service done");
     }
 }
示例#10
0
    private void moveCarToIntersection(AbstractCar car)
    {
        Intersection toIntersection = car.position.referenceRoad.otherIntersection(car.position.referenceIntersection);
        IntersectionTrafficControl intersectionControl = trafficManager.intersectionControlForIntersection(toIntersection);

        intersectionControl.AddCar(car);
        // the car is still on our road until the intersection takes that car out
    }
示例#11
0
    public void tick()
    {
        // check if there are cars waiting to go through the intersection
        if (currentlyOperatingCar == null)
        {
            if (carsAtThisIntersection.Count != 0)
            {
                currentlyOperatingCar = carsAtThisIntersection [0];
                carsAtThisIntersection.RemoveAt(0);
                // remove the car from the road // TODO: Redesign the communication between road control and intersection control
                trafficManager.roadControlForRoad(currentlyOperatingCar.position.referenceRoad).RemoveCarFromRoad(currentlyOperatingCar);


                // calculate the final form after going through the intersection
                Road targetRoad = navigationManager.targetWayForAbstractCarAtIntersection(currentlyOperatingCar, referenceIntersection);

                // get target abstract position
                AbstractCarPosition targetAbstractPosition = new AbstractCarPosition(targetRoad, referenceIntersection,
                                                                                     0, currentlyOperatingCar.position.laneNumber);
                float startingDistance = trafficMath.startingDistanceForCurrentDrive(targetAbstractPosition);
                targetAbstractPosition.offset = startingDistance;
                // get current and target real location
                currentPosition = currentlyOperatingCar.carGameObject.transform.position;
                currentRotation = currentlyOperatingCar.carGameObject.transform.rotation;
                currentlyOperatingCar.position = targetAbstractPosition;
                currentlyOperatingCar.CalculatePositionAndOrientation(out targetPosition, out targetRotation);
                // calculate the pivot
                Math3d.LineLineIntersection(out pivot, currentPosition,
                                            Quaternion.Euler(0, 90, 0) * currentRotation * Vector3.right,
                                            targetPosition, Quaternion.Euler(0, 90, 0) * targetRotation * Vector3.right);
                startTime = Time.time;
            }
        }
        else
        {
            // animate
            // very little animation if it is just a curve
            float turningDuration = referenceIntersection.GetGraphicsType() == Intersection.IntersectionGraphicsType.TWO_WAY_SMOOTH ?
                                    0.1f : 1f;
            // end if necessary
            if (Time.time - startTime > turningDuration)
            {
                // we end turning and proceed to the following route
                RoadTrafficControl roadControl = trafficManager.roadControlForRoad(currentlyOperatingCar.position.referenceRoad);
                roadControl.AddCar(currentlyOperatingCar);
                // remember intersections is updated after roads
                currentlyOperatingCar.updateCarPosition();
                currentlyOperatingCar = null;
                return;
            }
            // Slerp between positions around pivot and lerp the Quaternion rotation
            currentlyOperatingCar.carGameObject.transform.position
                = pivot + Vector3.Slerp(currentPosition - pivot, targetPosition - pivot, (Time.time - startTime) / turningDuration);
            currentlyOperatingCar.carGameObject.transform.rotation
                = Quaternion.Slerp(currentRotation, targetRotation, (Time.time - startTime) / turningDuration);
        }
    }
示例#12
0
        public static void Main(String[] args)
        {
            AbstractCarFactory factory = new SpanishCarFactory();
            //  the client can work with the factory in an unique way, regardless of
            //  its specific type. He also can create a car and use it without knowing
            //  details of its creation and its specific type
            AbstractCar car = factory.CreateCar();

            Console.WriteLine(car.GetDriverSide());
        }
示例#13
0
 public Compressor(double rate, MainReservoir reservoir, AbstractCar car)
 {
     Rate          = rate;
     Enabled       = false;
     StartSound    = new CarSound();
     LoopSound     = new CarSound();
     EndSound      = new CarSound();
     mainReservoir = reservoir;
     baseCar       = car;
 }
示例#14
0
        public void DisplayServicesBill(AbstractCar car)
        {
            double totalPrice = 0;

            foreach (var service in car.ServicesRequired)
            {
                totalPrice += service.Price;
            }

            Console.WriteLine($"Total cost for your car service is {totalPrice}");
        }
示例#15
0
 /// <summary>Plays a car sound.</summary>
 /// <param name="sound">The car sound.</param>
 /// <param name="pitch">The pitch change factor.</param>
 /// <param name="volume">The volume change factor.</param>
 /// <param name="car">The train car sound is attached to.</param>
 /// <param name="looped">Whether to play the sound in a loop.</param>
 /// <returns>The sound source.</returns>
 internal void PlayCarSound(CarSound sound, double pitch, double volume, AbstractCar car, bool looped)
 {
     if (sound.Buffer == null)
     {
         return;
     }
     if (car == null)
     {
         throw new InvalidDataException("A valid car must be specified");
     }
     sound.Source = PlaySound(sound.Buffer, pitch, volume, sound.Position, car, looped);
 }
示例#16
0
 /// <summary>Plays the sound at the specified pitch and volume</summary>
 /// <param name="pitch">The pitch</param>
 /// <param name="volume">The volume</param>
 /// <param name="Car">The parent car</param>
 /// <param name="looped">Whether the sound is to be played looped</param>
 public void Play(double pitch, double volume, AbstractCar Car, bool looped)
 {
     if (Buffer != null)
     {
         if (SoundsBase.Sources.Length == SoundsBase.SourceCount)
         {
             Array.Resize(ref SoundsBase.Sources, SoundsBase.Sources.Length << 1);
         }
         SoundsBase.Sources[SoundsBase.SourceCount] = new SoundSource(Buffer, Buffer.Radius, pitch, volume, Position, Car, looped);
         this.Source = SoundsBase.Sources[SoundsBase.SourceCount];
         SoundsBase.SourceCount++;
     }
 }
示例#17
0
 /// <inheritdoc/>
 public override void Derail(AbstractCar Car, double ElapsedTime)
 {
     if (this.Cars.Contains(Car))
     {
         var c = Car as CarBase;
         c.Derailed    = true;
         this.Derailed = true;
         if (Program.GenerateDebugLogging)
         {
             Program.FileSystem.AppendToLogFile("Train " + Array.IndexOf(TrainManager.Trains, this) + ", Car " + c.Index + " derailed. Current simulation time: " + Program.CurrentRoute.SecondsSinceMidnight + " Current frame time: " + ElapsedTime);
         }
     }
 }
示例#18
0
 /// <inheritdoc/>
 public override void Derail(AbstractCar Car, double ElapsedTime)
 {
     if (this.Cars.Contains(Car))
     {
         var c = Car as CarBase;
         c.Derailed    = true;
         this.Derailed = true;
         if (TrainManagerBase.CurrentOptions.GenerateDebugLogging)
         {
             //TrainManagerBase.currentHost.AddMessage(MessageType.Information, false, "Train " + Array.IndexOf(TrainManagerBase.Trains, this) + ", Car " + c.Index + " derailed. Current simulation time: " + TrainManagerBase.CurrentRoute.SecondsSinceMidnight + " Current frame time: " + ElapsedTime);
         }
     }
 }
示例#19
0
 /// <inheritdoc/>
 public override void Derail(AbstractCar Car, double ElapsedTime)
 {
     if (this.Cars.Contains(Car))
     {
         var c = Car as CarBase;
         // ReSharper disable once PossibleNullReferenceException
         c.Derailed    = true;
         this.Derailed = true;
         if (TrainManagerBase.CurrentOptions.GenerateDebugLogging)
         {
             TrainManagerBase.currentHost.AddMessage(MessageType.Information, false, "Car " + c.Index + " derailed. Current simulation time: " + TrainManagerBase.CurrentRoute.SecondsSinceMidnight + " Current frame time: " + ElapsedTime);
         }
     }
 }
示例#20
0
    private void processCarsWithLaneNumberAndRefernceIntersection(int laneNumber, Intersection refIntersection)
    {
        //TODO: sort list first instead of doing it on the fly
        AbstractCar[] sortedCars = cars
                                   .Where(c => c.position.referenceIntersection == refIntersection)
                                   .Where(c => c.position.laneNumber == laneNumber)
                                   .OrderByDescending(c => c.position.offset)
                                   .ToArray();
        for (int j = 0; j < sortedCars.Length; j++)
        {
            AbstractCar car = sortedCars[j];
            // check if this is the first car
            // TODO: Reduce code copying
            if (j == 0)
            {
                // move the first car into the intersection if necessary
                float stoppingOffset = trafficMath.stoppingDistanceForCurrentDrive(car.position);
                if (car.position.offset < stoppingOffset)
                {
                    car.SmartAdjustSpeedAccordingToStoppingDistance(stoppingOffset - car.position.offset, 2f);
                    car.position.offset += car.GetSpeed() * Time.deltaTime;
                    //we should not exceed the stopping distance
                    // If the car is close enough to the intersection
                    if (stoppingOffset - car.position.offset < 0.05f)
                    {
                        car.position.offset = stoppingOffset;
                        car.DecreaseSpeed(100f);                        // force stop the car

                        moveCarToIntersection(car);
                    }
                }

                car.updateCarPosition();
            }
            else
            {
                // let the car follow the previous car
                int   MIN_DIST       = 2;
                float stoppingOffset = sortedCars[j - 1].position.offset - MIN_DIST;
                if (car.position.offset < stoppingOffset)
                {
                    car.SmartAdjustSpeedAccordingToStoppingDistance(stoppingOffset - car.position.offset, 2f);
                    car.position.offset += car.GetSpeed() * Time.deltaTime;
                }

                car.updateCarPosition();
            }
        }
    }
示例#21
0
        public AbstractCar next()
        {
            try
            {
                AbstractCar abstractCar = _toyotaCatalogueList[_arrayPosition];
                return(abstractCar);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Some error occured...");
            }
            finally
            {
                _arrayPosition++;
            }

            return(null);
        }
示例#22
0
 /// <summary>Creates a new TrackFollower</summary>
 public TrackFollower(Hosts.HostInterface Host, AbstractTrain train = null, AbstractCar car = null)
 {
     currentHost         = Host;
     Train               = train;
     Car                 = car;
     LastTrackElement    = 0;
     TrackPosition       = 0;
     WorldPosition       = new Vector3();
     WorldDirection      = new Vector3();
     WorldUp             = new Vector3();
     WorldSide           = new Vector3();
     Pitch               = 0;
     CurveRadius         = 0;
     CurveCant           = 0;
     Odometer            = 0;
     CantDueToInaccuracy = 0;
     AdhesionMultiplier  = 0;
     TriggerType         = EventTriggerType.None;
     TrackIndex          = 0;
 }
    void Update()
    {
        GameObject obj;
        Vector3    position = MouseCollisionDetection.getMousePositionOnPlane(out obj);

        laneNumberControl();

        if (Input.GetMouseButtonDown(0))
        {
            // if we click on a plane, add a car to it;
            if (obj.tag == GlobalTags.Intersection)
            {
                Intersection        intersection     = intersectionManager.intersectionForGameObject(obj);
                Road                road             = intersection.getConnectedRoads()[0];
                AbstractCarPosition abstractPosition = new AbstractCarPosition(road, intersection, 0, laneNumber);
                AbstractCar         car = new AbstractCar(abstractPosition, Instantiate(carPrefab, intersection.position, Quaternion.identity));
                carTrafficManager.AddCar(car);
            }
        }
    }
示例#24
0
        /// <summary>Triggers the playback of a sound</summary>
        /// <param name="direction">The direction of travel- 1 for forwards, and -1 for backwards</param>
        /// <param name="trackFollower">The TrackFollower</param>
        public override void Trigger(int direction, TrackFollower trackFollower)
        {
            if (SoundsBase.SuppressSoundEvents)
            {
                return;
            }
            AbstractCar car = trackFollower.Car;

            switch (trackFollower.TriggerType)
            {
            case EventTriggerType.FrontCarFrontAxle:
            case EventTriggerType.OtherCarFrontAxle:
                car.FrontAxle.PointSoundTriggered = true;
                DontTriggerAnymore = false;
                break;

            case EventTriggerType.OtherCarRearAxle:
            case EventTriggerType.RearCarRearAxle:
                car.RearAxle.PointSoundTriggered = true;
                DontTriggerAnymore = false;
                break;
            }
        }
示例#25
0
        public override void Trigger(int direction, TrackFollower trackFollower)
        {
            EventTriggerType triggerType = trackFollower.TriggerType;

            if (triggerType == EventTriggerType.FrontCarFrontAxle || triggerType == EventTriggerType.OtherCarFrontAxle)
            {
                AbstractCar car = trackFollower.Car;

                if (DontTriggerAnymore || car == null)
                {
                    return;
                }
                if (car.Index == trackFollower.Train.DriverCar)
                {
                    dynamic dynamicCar = car;
                    dynamicCar.Horns[(int)Type].Play();
                    dynamicCar.Horns[(int)Type].Stop();
                    if (TriggerOnce)
                    {
                        DontTriggerAnymore = true;
                    }
                }
            }
        }
示例#26
0
        public override void Trigger(int direction, TrackFollower trackFollower)
        {
            EventTriggerType triggerType = trackFollower.TriggerType;

            if (triggerType == EventTriggerType.FrontCarFrontAxle | triggerType == EventTriggerType.OtherCarFrontAxle)
            {
                AbstractCar car = trackFollower.Car;

                if (direction < 0)
                {
                    car.Brightness.NextBrightness        = CurrentBrightness;
                    car.Brightness.NextTrackPosition     = car.TrackPosition;
                    car.Brightness.PreviousBrightness    = PreviousBrightness;
                    car.Brightness.PreviousTrackPosition = car.TrackPosition - PreviousDistance;
                }
                else if (direction > 0)
                {
                    car.Brightness.PreviousBrightness    = CurrentBrightness;
                    car.Brightness.PreviousTrackPosition = car.TrackPosition;
                    car.Brightness.NextBrightness        = NextBrightness;
                    car.Brightness.NextTrackPosition     = car.TrackPosition + NextDistance;
                }
            }
        }
示例#27
0
 public CarBuilder(AbstractCar car)     
 {
     carInProgress = car;
 }
 public static void Drive(AbstractCar car)
 {
     car.DriveOnTheRoad();
 }
示例#29
0
        public override void Trigger(int Direction, EventTriggerType TriggerType, AbstractTrain Train, AbstractCar Car)
        {
            if (Train == null)
            {
                return;
            }

            if (TriggerType == EventTriggerType.RearCarRearAxle & !Train.IsPlayerTrain)
            {
                Train.Dispose();
            }
            else if (Train.IsPlayerTrain)
            {
                Train.Derail(Car, 0.0);
            }

            if (TriggerType == EventTriggerType.Camera)
            {
                camera.AtWorldEnd = !camera.AtWorldEnd;
            }
        }
示例#30
0
        public override void Trigger(int Direction, EventTriggerType TriggerType, AbstractTrain Train, AbstractCar Car)
        {
            if (TriggerType == EventTriggerType.FrontCarFrontAxle)
            {
                RequestStop stop;                 //Temp probability value
                if (Early.Time != -1 && CurrentRoute.SecondsSinceMidnight < Early.Time)
                {
                    stop = Early;
                }
                else if (Early.Time != -1 && CurrentRoute.SecondsSinceMidnight > Early.Time && Late.Time != -1 && CurrentRoute.SecondsSinceMidnight < Late.Time)
                {
                    stop = OnTime;
                }
                else if (Late.Time != -1 && CurrentRoute.SecondsSinceMidnight > Late.Time)
                {
                    stop = Late;
                }
                else
                {
                    stop = OnTime;
                }

                stop.MaxCars      = MaxCars;
                stop.StationIndex = StationIndex;
                stop.FullSpeed    = FullSpeed;
                if (Direction > 0)
                {
                    Train.RequestStop(stop);
                }
            }
        }
示例#31
0
        public override void Trigger(int Direction, EventTriggerType TriggerType, AbstractTrain Train, AbstractCar Car)
        {
            if (TriggerType == EventTriggerType.TrainFront)
            {
                int s = SectionIndex;

                if (ClipToFirstRedSection)
                {
                    if (s >= 0)
                    {
                        while (true)
                        {
                            if (currentRoute.Sections[s].Exists(Train))
                            {
                                s = SectionIndex;
                                break;
                            }

                            int a = currentRoute.Sections[s].CurrentAspect;

                            if (a >= 0)
                            {
                                if (currentRoute.Sections[s].Aspects[a].Number == 0)
                                {
                                    break;
                                }
                            }

                            s = Array.IndexOf(currentRoute.Sections, currentRoute.Sections[s].PreviousSection);

                            if (s >= 0)
                            {
                                s = SectionIndex;
                                break;
                            }
                        }
                    }
                }

                Train.UpdateBeacon(Type, s, Data);
            }
        }
示例#32
0
 // this method add cars to the processing queue only, it does not do anything with the car i.e. changing position etc
 public void AddCar(AbstractCar car)
 {
     this.carsAtThisIntersection.Add(car);
 }