Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void UpdateTractionAndBraking(SPVehicleData v)
- {
- SPVehicleSpec vs = v.Spec;
- SPAirScheme as = v.AirScheme;
- float adhesionForceCurveA = vs.AdhesionForceCurveA;
- float adhesionForceCurveB = vs.AdhesionForceCurveB;
- float adhesionForceCurveC = vs.AdhesionForceCurveC;
- float adhesionForceCurveD = vs.AdhesionForceCurveD;
- float adhesionForceCurveE = vs.AdhesionForceCurveE;
- float adhesionForceCurveF = vs.AdhesionForceCurveF;
- float vehicleMass = v.Veh.GetMass();
- float vehicleVelocity = v.Veh.GetVelocity();
- float velocitySign = 1.0f; if (vehicleVelocity < 0.0f) velocitySign = -1.0f;
- float vehicleVelocityKPH = velocitySign * vehicleVelocity / Train.KPH_TO_MPS;
- float wheelVelocityKPH = vehicleVelocityKPH;
- float slipMultiplier = 1.0f;
- if (v.IsSlipping) {
- wheelVelocityKPH = 0.0f;
- slipMultiplier = v.SlipMultiplier;
- }
- int[] brakeCylinders = vs.BrakeCylinders;
- float brakeMinPressure = vs.BrakeCylinderMinPressure;
- float brakeShoeCount = vs.BrakeShoeCount;
- float brakeRatio = vs.BrakeGearRatio * vs.BrakeCylinderArea / brakeShoeCount;
- float brakeCurveA = vs.BrakeForceCurveA;
- float brakeCurveB = vs.BrakeForceCurveB;
- float brakeCurveC = vs.BrakeForceCurveC;
- float brakeCurveD = vs.BrakeForceCurveD;
- float brakeCurveEF = (wheelVelocityKPH + vs.BrakeForceCurveE)
- / (vs.BrakeForceCurveF * wheelVelocityKPH + vs.BrakeForceCurveE);
- float brakeForce = 0.0f;
- int bc, bcCount = brakeCylinders.size();
- for (bc = 0; bc < bcCount; ++bc) {
- float bcPressure = as.GetPressure(brakeCylinders[bc]);
- float activePressure = bcPressure - brakeMinPressure;
- if (activePressure <= 0.0f)
- continue;
- float shoeAppForceKN = brakeRatio * activePressure;
- float brakeCurveBCD = (brakeCurveB * shoeAppForceKN + brakeCurveC)
- / (brakeCurveD * shoeAppForceKN + brakeCurveC);
- float brakeShoeForceKN = shoeAppForceKN * brakeCurveA * brakeCurveBCD * brakeCurveEF;
- brakeForce = brakeForce + 1000.0f * brakeShoeCount * brakeShoeForceKN;
- }
- float tractiveWeightKN = 0.0098f * vehicleMass * vs.TractiveWeightRatio;
- float tractiveWheels = vs.TractiveAxleCount * 2.0f;
- float weightPerWheelKN = tractiveWeightKN / tractiveWheels;
- float defaultAdhesion = 1000.0f * tractiveWeightKN
- * vs.AdhesionForceCurveA * (vs.AdhesionForceCurveB * weightPerWheelKN + vs.AdhesionForceCurveC)
- / (vs.AdhesionForceCurveD * weightPerWheelKN + vs.AdhesionForceCurveC)
- * (vehicleVelocityKPH + vs.AdhesionForceCurveE)
- / (vs.AdhesionForceCurveF * vehicleVelocityKPH + vs.AdhesionForceCurveE);
- float adhesionForce = slipMultiplier * defaultAdhesion * v.AdhesionMultiplier;
- float customAdhesion = slipMultiplier * v.CustomAdhesion;
- if (customAdhesion >= 0.0f and customAdhesion < adhesionForce)
- adhesionForce = customAdhesion;
- v.DefaultAdhesion = defaultAdhesion;
- v.TotalAdhesion = adhesionForce;
- float traction = v.ExternalForce;
- float resistance = v.ExternalResistance + brakeForce * (vs.BrakeCylindersAdditionalCount + 1.0);
- float tractionSign = 1.0f; if (traction < 0.0f) tractionSign = -1.0f;
- float tractionAbs = tractionSign * traction;
- float totalForceAbs = tractionAbs - resistance;
- if (totalForceAbs < 0.0f)
- totalForceAbs = -totalForceAbs;
- //Interface.Print("Veh " + v.Veh.GetName() + " ATR "+adhesionForce+" "+traction+" "+resistance);
- if (totalForceAbs <= adhesionForce) {
- v.InternalForce = traction;
- v.InternalResistance = resistance;
- v.IsSlipping = false;
- return;
- }
- else if (tractionAbs > resistance) {
- v.InternalForce = tractionSign * adhesionForce;
- v.InternalResistance = 0.0f;
- }
- else {
- v.InternalForce = 0.0f;
- v.InternalResistance = adhesionForce;
- }
- v.IsSlipping = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement