private Tuple<PriorityInformation, float> CanDrive( PriorityInformation[] privilagesCar ) { var min = privilagesCar[ 0 ]; var minTime = MyMathHelper.GetTimeToDriveThrough( min.CarDistanceToJunction, min.CarWihtPriority.Velocity, min.CarWihtPriority.MaxSpeed, min.CarWihtPriority.AccelerateForce ); foreach ( var info in privilagesCar.Skip( 1 ) ) { var time = MyMathHelper.GetTimeToDriveThrough( info.CarDistanceToJunction, info.CarWihtPriority.Velocity, info.CarWihtPriority.MaxSpeed, info.CarWihtPriority.AccelerateForce ); if ( time < minTime ) { min = info; } } return Tuple.Create( min, minTime ); }
private void ProcesPrivilagesCarInformation( PriorityInformation[] privilagesCarInformation, float distance ) { if ( privilagesCarInformation.Length > 1 ) { // Debugger.Break(); } if ( privilagesCarInformation.Length != 0 ) { var privilagesCar = this.CanDrive( privilagesCarInformation ); var myTime = MyMathHelper.GetTimeToDriveThrough( distance, this._car.Velocity, this._car.MaxSpeed, this._car.AccelerateForce ); if ( myTime + UnitConverter.FromSecond( 5 ) > privilagesCar.Item2 ) { if ( privilagesCar.Item1.CarDistanceToJunction > privilagesCar.Item1.CarWihtPriority.StateMachine.DestinationDistance && privilagesCar.Item1.CarWihtPriority.StateMachine.DestinationSpeed < UnitConverter.FromKmPerHour( 1 ) ) { return; } this.SetDestinationPositionAndSpeed( distance - this._car.Lenght / 2, 0.0f ); this._canDriver = false; this._freeWay = false; } } }