public void DefaultByPowerEconomy() { var maxPwr = Drivetrain.CalculateMaxPower() * 0.75; maxPwr = 500; tableGear = new Dictionary <int, Dictionary <double, int> >(); tableThrottle = new Dictionary <int, Dictionary <double, double> >(); // Make sure there are 20 rpm steps, and 10 load steps for (int speed = 0; speed <= MaximumSpeed; speed += 1) { tableGear.Add(speed, new Dictionary <double, int>()); tableThrottle.Add(speed, new Dictionary <double, double>()); for (var load = 0.0; load <= 1.0; load += 0.1) { tableThrottle[speed].Add(load, 1); var gearSet = false; double req = Math.Max(25, load * maxPwr); var bestFuelEfficiency = double.MaxValue; var bestFuelGear = 0; var highestValidGear = 11; for (int gear = 0; gear < Drivetrain.Gears; gear++) { var calculatedRpm = Drivetrain.GearRatios[gear] * speed; if (calculatedRpm <= Drivetrain.StallRpm * 1.033333) { highestValidGear = 0; continue; } if (calculatedRpm >= Drivetrain.MaximumRpm) { continue; } var thr = Drivetrain.CalculateThrottleByPower(calculatedRpm, req); if (thr > 1) { continue; } if (thr < 0) { continue; } if (double.IsNaN(thr) || double.IsInfinity(thr)) { continue; } var fuel = Drivetrain.CalculateFuelConsumption(calculatedRpm, thr); if (bestFuelEfficiency >= fuel) { bestFuelEfficiency = fuel; bestFuelGear = gear; gearSet = true; } } if (!gearSet) { if (Drivetrain is Ets2Drivetrain) { highestValidGear = Math.Max(2, highestValidGear); } tableGear[speed].Add(load, 1 + highestValidGear); } else { bestFuelGear = Math.Max(2, bestFuelGear); if (Drivetrain is Ets2Drivetrain) { highestValidGear = Math.Max(2, bestFuelGear); } tableGear[speed].Add(load, bestFuelGear + 1); } } } }