public EnginesStats(EnginesDB engines, VesselWrapper vsl) : base(vsl) { engines.SortByRole(); TorqueInfo = new TorqueInfo(VSL); for (int i = 0, count = engines.Count; i < count; i++) { var e = engines[i]; e.InitState(); e.InitTorque(VSL, EngineOptimizer.C.TorqueRatioFactor); e.UpdateCurrentTorque(1); } engines.OptimizeForZeroTorque(VSL.Physics.MoI); for (int i = 0, count = engines.Count; i < count; i++) { var e = engines[i]; var throttle = e.Role == TCARole.MANUAL ? e.limit : e.thrustLimit; if (throttle > 0) { if (e.Role != TCARole.MANEUVER) { var thrust = e.nominalCurrentThrust(throttle); MaxThrust += e.wThrustDir * thrust; MaxDefThrust += e.defThrustDir * thrust; MaxMassFlow += e.MaxFuelFlow * throttle; } if (e.isSteering) { TorqueLimits.Add(e.specificTorque * e.nominalCurrentThrust(throttle)); } } } TorqueInfo.Update(TorqueLimits.Max + VSL.Torque.NoEngines.Torque); }
private void AnalyzeReactionWheels() { torqueReactionWheel.Reset(); foreach (var pair in reactionWheels) { Part p = pair.Key; List <ModuleReactionWheel> mlist = p.Modules.GetModules <ModuleReactionWheel>(); for (int m = 0; m < mlist.Count; m++) { Vector3 pos; Vector3 neg; ModuleReactionWheel rw = mlist[m]; rw.GetPotentialTorque(out pos, out neg); torqueReactionWheel.Add(pos); torqueReactionWheel.Add(-neg); } } }
private void AnalyzeOtherTorque() { torqueOthers.Reset(); /* this is a special list of ITorqueProvider-containing Parts that are *NOT* Engines, RW, RCS, Control Surfaces */ foreach (var pair in otherTorque) { Part p = pair.Key; List <ITorqueProvider> mlist = p.Modules.GetModules <ITorqueProvider>(); for (int m = 0; m < mlist.Count; m++) { Vector3 pos; Vector3 neg; ITorqueProvider it = mlist[m]; it.GetPotentialTorque(out pos, out neg); torqueOthers.Add(pos); torqueOthers.Add(-neg); } } }
void update_RCS() { //init RCS wrappers and calculate MaxThrust taking torque imbalance into account MaxThrustRCS = new Vector6(); var RCSThrusImbalance = new Vector3[6]; for (int i = 0; i < NumActiveRCS; i++) { var t = ActiveRCS[i]; t.InitState(); for (int j = 0, tCount = t.rcs.thrusterTransforms.Count; j < tCount; j++) { var T = t.rcs.thrusterTransforms[j]; var thrust = refT.InverseTransformDirection((t.rcs.useZaxis ? T.forward : T.up) * t.maxThrust); MaxThrustRCS.Add(thrust); var pos = refT.InverseTransformDirection(T.position - VSL.Physics.wCoM); var athrust = Vector3.zero; for (int k = 0; k < 3; k++) { athrust[k] = thrust[k]; var p = pos; p[k] = 0; RCSThrusImbalance[thrust[k] > 0 ? k : k + 3] += Vector3.Cross(p, athrust); athrust[k] = 0; } } if (NoActiveRCS) { continue; } t.InitTorque(VSL, RCSOptimizer.C.TorqueRatioFactor); t.UpdateCurrentTorque(1); t.ApplyPreset(); } if (!MaxThrustRCS.IsZero()) { MaxThrustRCS.Scale(new Vector6( 1 / Utils.ClampL(RCSThrusImbalance[0].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[1].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[2].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[3].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[4].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[5].sqrMagnitude, 1))); } }
protected virtual void initRealDef(HeroData heroD) { realDef.Zero(); Vector6 temp = new Vector6(); float p = (heroD.lv-1)*heroD.defProportion; temp.Add(new Vector6(p,p,p,p,p,p)); temp.Add(heroD.itemMult.defense).Add(heroD.skillMult.defense).Div(100).Add(1); realDef.Add(heroD.defense).Add(heroD.itemAdd.defense).Add(heroD.skillAdd.defense).Multip(temp); }
//end protected virtual void initRealAtk(HeroData heroD) { realAtk.Zero(); Vector6 temp = new Vector6(); float p = (heroD.lv-1)*heroD.atkProportion; temp.Add(new Vector6(p,p,p,p,p,p)); temp.Add(heroD.itemMult.attack).Add(heroD.skillMult.attack).Div(100).Add(1); realAtk.Add(heroD.attack).Add(heroD.itemAdd.attack).Add(heroD.skillAdd.attack).Multip(temp).Multip(0.3f); }
public float getInitRealDef(HeroData heroD) { Vector6 initRealDef = new Vector6(); initRealDef.Zero(); Vector6 temp = new Vector6(); float p = (heroD.lv-1)*heroD.defProportion; temp.Add(new Vector6(p,p,p,p,p,p)); temp.Add(heroD.itemMult.defense).Add(heroD.skillMult.defense).Div(100).Add(1); initRealDef.Add(heroD.defense).Add(heroD.itemAdd.defense).Add(heroD.skillAdd.defense).Multip(temp); return initRealDef.PHY; }
private void AnalyzeEngines() { torqueGimbal.Reset(); double thrustOverVe = 0.0; foreach (var pair in engines) { Part p = pair.Key; List <ModuleGimbal> glist = p.Modules.GetModules <ModuleGimbal>(); for (int m = 0; m < glist.Count; m++) { Vector3 pos; Vector3 neg; ModuleGimbal g = glist[m]; g.GetPotentialTorque(out pos, out neg); torqueRcs.Add(pos); torqueRcs.Add(-neg); } List <ModuleEngines> elist = p.Modules.GetModules <ModuleEngines>(); for (int m = 0; m < elist.Count; m++) { ModuleEngines e = elist[m]; if ((!e.EngineIgnited) || (!e.isEnabled) || (!e.isOperational)) { continue; } float thrustLimiter = e.thrustPercentage / 100f; double Isp0 = e.atmosphereCurve.Evaluate((float)atmPressure); double Isp1 = e.atmosphereCurve.Evaluate((float)atmPressure1); double Isp = Math.Min(Isp0, Isp1); double Ve = Isp * e.g; double maxThrust = e.maxFuelFlow * e.flowMultiplier * Ve; double minThrust = e.minFuelFlow * e.flowMultiplier * Ve; /* handle RealFuels engines */ if (e.finalThrust == 0.0f && minThrust > 0.0f) { minThrust = maxThrust = 0.0; } double eMaxThrust = minThrust + (maxThrust - minThrust) * thrustLimiter; double eMinThrust = e.throttleLocked ? eMaxThrust : minThrust; double eCurrentThrust = e.finalThrust; thrustMaximum += eMaxThrust; thrustMinimum += eMinThrust; thrustCurrent += eCurrentThrust; thrustOverVe += eMaxThrust / Ve; /* FIXME: Cosine losses */ } } totalVe = thrustMaximum / thrustOverVe; }
public override void Update() { //init engine wrappers, thrust and torque information Thrust = Vector3.zero; MaxThrust = Vector3.zero; ManualThrust = Vector3.zero; ManualThrustLimits = Vector6.zero; MassFlow = 0f; MaxMassFlow = 0f; ManualMassFlow = 0f; ThrustDecelerationTime = 0f; SlowTorque = false; TorqueResponseTime = 0f; var total_torque = 0f; for (int i = 0; i < NumActive; i++) { var e = Active[i]; e.InitState(); e.InitTorque(VSL, GLB.ENG.TorqueRatioFactor); //do not include maneuver engines' thrust into the total to break the feedback loop with HSC if (e.Role != TCARole.MANEUVER) { Thrust += e.wThrustDir * e.finalThrust; } if (e.Role == TCARole.MANUAL) { ManualThrust += e.wThrustDir * e.finalThrust; ManualMassFlow += e.RealFuelFlow; ManualThrustLimits.Add(e.thrustDirection * e.nominalCurrentThrust(1)); } if (e.isVSC) { MaxThrust += e.wThrustDir * e.nominalCurrentThrust(1); MaxMassFlow += e.MaxFuelFlow; if (e.useEngineResponseTime && e.finalThrust > 0) { var decelT = 1f / e.engineDecelerationSpeed; if (decelT > ThrustDecelerationTime) { ThrustDecelerationTime = decelT; } } } if (e.useEngineResponseTime && (e.Role == TCARole.MAIN || e.Role == TCARole.MANEUVER)) { var torque = e.Torque(1).magnitude; total_torque += torque; TorqueResponseTime += torque * Mathf.Max(e.engineAccelerationSpeed, e.engineDecelerationSpeed); } MassFlow += e.RealFuelFlow; } if (MassFlow > MaxMassFlow) { MaxMassFlow = MassFlow; } if (TorqueResponseTime > 0) { TorqueResponseTime = total_torque / TorqueResponseTime; } SlowTorque = TorqueResponseTime > 0; MaxThrustM = MaxThrust.magnitude; MaxVe = MaxThrustM / MaxMassFlow; MaxAccel = MaxThrustM / VSL.Physics.M; //init RCS wrappers and calculate MaxThrust taking torque imbalance into account MaxThrustRCS = new Vector6(); var RCSThrusImbalance = new Vector3[6]; for (int i = 0; i < NumActiveRCS; i++) { var t = ActiveRCS[i]; t.InitState(); for (int j = 0, tCount = t.rcs.thrusterTransforms.Count; j < tCount; j++) { var T = t.rcs.thrusterTransforms[j]; var thrust = refT.InverseTransformDirection((t.rcs.useZaxis ? T.forward : T.up) * t.maxThrust); MaxThrustRCS.Add(thrust); var pos = refT.InverseTransformDirection(T.position - VSL.Physics.wCoM); var athrust = Vector3.zero; for (int k = 0; k < 3; k++) { athrust[k] = thrust[k]; var p = pos; p[k] = 0; RCSThrusImbalance[thrust[k] > 0 ? k : k + 3] += Vector3.Cross(p, athrust); athrust[k] = 0; } } if (NoActiveRCS) { continue; } t.InitTorque(VSL, GLB.RCS.TorqueRatioFactor); t.currentTorque = t.Torque(1); t.currentTorque_m = t.currentTorque.magnitude; } if (!MaxThrustRCS.IsZero()) { MaxThrustRCS.Scale(new Vector6( 1 / Utils.ClampL(RCSThrusImbalance[0].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[1].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[2].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[3].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[4].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[5].sqrMagnitude, 1))); } }