Exemplo n.º 1
0
 public void Update(List <IDriver> otherDrivers)
 {
     _vehicle.ThrottlePedalInput = VehicleController.Acceleration;
     _vehicle.BrakePedalInput    = VehicleController.Brake;
     _vehicle.SteeringInput      = VehicleController.Turn;
     _vehicle.GearDownInput      = VehicleController.GearDown;
     _vehicle.GearUpInput        = VehicleController.GearUp;
     _vehicle.HandbrakeInput     = VehicleController.Handbrake;
     _vehicle.Update();
 }
Exemplo n.º 2
0
        public override void Update(List <IDriver> otherDrivers)
        {
            _vehicle.ThrottlePedalInput = 0.9f;
            _vehicle.BrakePedalInput    = 0;

            var node = _vehicle.CurrentNode;
            var pos  = _vehicle.Position;

            if (node.Next == null || node.Next.Next == null)
            {
                _vehicle.ThrottlePedalInput = 0;
                _vehicle.BrakePedalInput    = 1;
                AtEndOfTrack = true;
                return;
            }

            FollowTrack();

            foreach (var otherDriver in otherDrivers)
            {
                if (otherDriver == this)
                {
                    continue;
                }
                //if (!(otherDriver is AIDriver)) continue;
                // if I am not in the same lane, ignore
                if (otherDriver is AIDriver && ((AIDriver)otherDriver).VirtualLane != VirtualLane)
                {
                    continue;
                }
                if (otherDriver is PlayerDriver)
                {
                    continue;                                               //ignore player for now
                }
                // if I am going slower than the other driver, ignore
                if (Vehicle.Speed < otherDriver.Vehicle.Speed)
                {
                    continue;
                }

                var progressDist = otherDriver.Vehicle.TrackPosition - _vehicle.TrackPosition;
                // if we are only slightly behind another driver (less than 2 nodes back) then consider them a possible danger
                if (progressDist > 0 && progressDist < 2f)
                {
                    // pick a new lane if we're far enough from the start of the race.
                    if (Vehicle.CurrentNode.Number > _firstLaneChangeAllowed)
                    {
                        if (Engine.Instance.Random.Next() % 2 == 0)
                        {
                            VirtualLane = Math.Max(0, VirtualLane - 1);
                        }
                        else
                        {
                            VirtualLane = Math.Min(MaxVirtualLanes, VirtualLane + 1);
                        }
                    }
                    else
                    {
                        Vehicle.Speed = Math.Max(0, otherDriver.Vehicle.Speed * 0.8f);
                    }
                }
            }

            _vehicle.Update();
        }