private int GetGear(ISensorModel model) { int gear = model.GetGear(); double rpm = model.GetRPM(); // if gear is 0 (N) or -1 (R) just return 1 if (gear < 1) { return 1; } // check if the RPM value of car is greater than the one suggested // to shift up the gear from the current one if (gear < 6 && rpm >= GearUp[gear - 1]) { return gear + 1; } else { // check if the RPM value of car is lower than the one suggested // to shift down the gear from the current one if (gear > 1 && rpm <= GearDown[gear - 1]) { return gear - 1; } else // otherwhise keep current gear { return gear; } } }
private float Clutching(ISensorModel model, float clutch) { float maxClutch = ClutchMax; // Check if the current situation is the race start if (model.GetCurrentLapTime() < ClutchDeltaTime && Stage_ == Stage.RACE && model.GetDistanceRaced() < ClutchDeltaRaced) { clutch = maxClutch; } // Adjust the current value of the clutch if (clutch > 0) { double delta = ClutchDelta; if(model.GetGear() < 2) { // Apply a stronger clutch output when the gear is one and the race is just started delta /= 2; maxClutch *= ClutchMaxModifier; if(model.GetCurrentLapTime() < ClutchMaxTime) { clutch = maxClutch; } } // Check clutch is not bigger than maximum values clutch = Math.Min(maxClutch, clutch); // If clutch is not at max value decrease it quite quickly if (clutch != maxClutch) { clutch -= (float)delta; clutch = Math.Max(0.0f, clutch); } // if clutch is at max value decrease it very slowly else { clutch -= ClutchDec; } } return clutch; }