public override void OnFixedUpdate() { ES = "Deactivated"; if (part.Resources["GNparticle"].amount < part.Resources["GNparticle"].max) { } if (!HighLogic.LoadedSceneIsFlight || !vessel.isActiveVessel) { return; } float pitch = vessel.ctrlState.pitch; float roll = vessel.ctrlState.roll; float yaw = vessel.ctrlState.yaw; float throttle = vessel.ctrlState.mainThrottle * Overload; float y = -vessel.ctrlState.Y * Overload * 10; float x = -vessel.ctrlState.X * Overload * 10; float z = throttle * 10 - vessel.ctrlState.Z * Overload * 10; float enginecount = 0; float tefactor = 1; float ID = GetInstanceID(); if (Overload != overloadtemp) { modified = true; } foreach (Part p in this.vessel.Parts) { foreach (PartModule m in p.Modules) { GNdrive drive = null; if (m.moduleName == "Taudrive") { drive = (GNdrive)m; enginecount += 1; if (modified == true && drive.GetInstanceID() != GetInstanceID()) { if (drive.modified == true) { taactivated = drive.taactivated; agActivated = drive.agActivated; engineIgnited = drive.engineIgnited; Overload = drive.Overload; overloadtemp = drive.Overload; } else { drive.taactivated = taactivated; drive.agActivated = agActivated; drive.engineIgnited = engineIgnited; drive.Overload = Overload; drive.overloadtemp = Overload; } } } } } modified = false; if (engineIgnited == true) { ES = "Activated"; Events["Deactivate"].guiActive = true; Events["Activate"].guiActive = false; } else { Events["Deactivate"].guiActive = false; Events["Activate"].guiActive = true; } if (agActivated == true) { ES = "Activated"; Events["Deactivateag"].guiActive = true; Events["Activateag"].guiActive = false; } else { Events["Deactivateag"].guiActive = false; Events["Activateag"].guiActive = true; if (engineIgnited == false) { taactivated = false; Events["Activateta"].guiActive = true; } } if (taactivated == true) { ES = "Trans-AM"; } if (depleted == true) { ES = "GNpartical depleted"; } Vector3 srfVelocity = vessel.GetSrfVelocity(); float VerticalV; VerticalV = (float)vessel.verticalSpeed; Vector3 Airspeed = vessel.transform.InverseTransformDirection(srfVelocity); Vector3 gee = FlightGlobals.getGeeForceAtPosition(this.vessel.transform.position) / enginecount; Vector3 controlforce = vessel.ReferenceTransform.up * z + vessel.ReferenceTransform.forward * y + vessel.ReferenceTransform.right * x; if (enginecount > maxenginecount) { ES = "Unsynchronized"; controlforce = Vector3.zero; gee = Vector3.zero; } else { tefactor = (float)Math.Pow((double)particlegrate, (double)enginecount - 1); } if (engineIgnited == false) { controlforce = Vector3.zero; } if (agActivated == false) { gee = Vector3.zero; } float consumption = vessel.GetTotalMass() * Mathf.Abs((-gee + controlforce).magnitude) * fuelefficiency; float resourceDrawn = this.part.RequestResource("ElectricCharge", consumption); liftratio = resourceDrawn / consumption; float particlegen = particlegrate * tefactor; if (taactivated == true) { color = new Vector4(1F, 0F, 100F / 255F, 1F); controlforce *= 5; consumption = 4 * consumption - 3 * vessel.GetTotalMass() * Mathf.Abs(gee.magnitude) * fuelefficiency; Events["Activateta"].guiActive = false; consumption = Mathf.Max(particlegen, consumption) + 4; } else { color = new Vector4(0F, 1F, 170F / 255F, 1F); if (engineIgnited == true) { Events["Activateta"].guiActive = true; } } float reschange = (particlegen - consumption) * Time.deltaTime; if (part.Resources["GNparticle"].amount < -reschange) { depleted = false; controlforce = Vector3.zero; gee = Vector3.zero; taactivated = false; activated = false; engineIgnited = false; } else { if (part.Resources["GNparticle"].amount <= part.Resources["GNparticle"].maxAmount - reschange) { part.Resources["GNparticle"].amount += reschange; } else { part.Resources["GNparticle"].amount = part.Resources["GNparticle"].maxAmount; } } Debug.Log("Consumption " + consumption); Debug.Log("particlegen " + particlegen); Debug.Log("tefactor " + tefactor); Debug.Log("Time.deltaTime " + Time.deltaTime); mass = vessel.GetTotalMass().ToString("R"); if (engineIgnited == true) { foreach (Part p in this.vessel.parts) { if ((p.physicalSignificance == Part.PhysicalSignificance.FULL) && (p.rigidbody != null)) { p.rigidbody.AddForce(controlforce * p.rigidbody.mass); } } } if (agActivated == true) { foreach (Part p in this.vessel.parts) { if ((p.physicalSignificance == Part.PhysicalSignificance.FULL) && (p.rigidbody != null)) { p.rigidbody.AddForce(-gee * p.rigidbody.mass); } } } emt.minEmission = 2 * (Mathf.Abs(controlforce.magnitude) + 5); emt.maxEmission = emt.minEmission; rotor.renderer.material.SetColor("_EmissiveColor", color); stator.renderer.material.SetColor("_EmissiveColor", color); stator.light.color = color; rotor.transform.localEulerAngles = new Vector3(0, 0, rotation); rotation += 6 * (Mathf.Abs(controlforce.magnitude) + 1) * 120 * TimeWarp.deltaTime; while (rotation > 360) { rotation -= 360; } while (rotation < 0) { rotation += 360; } }
public override void OnFixedUpdate() { ES = "Deactivated"; if (!HighLogic.LoadedSceneIsFlight || !vessel.isActiveVessel) { return; } float pitch = vessel.ctrlState.pitch; float roll = vessel.ctrlState.roll; float yaw = vessel.ctrlState.yaw; float throttle = vessel.ctrlState.mainThrottle * Overload; float y = -vessel.ctrlState.Y * Overload * 10; float x = -vessel.ctrlState.X * Overload * 10; float z = throttle * 10 - vessel.ctrlState.Z * Overload * 10; float enginecount = 1; float agenginecount = 0; float tefactor = 1; float ID = GetInstanceID(); if (Overload != overloadtemp) { modified = true; } if (agActivated == true) { engineIgnited = true; } if (engineIgnited == true) { Emitter.emit = true; foreach (Part p in this.vessel.Parts) { foreach (PartModule m in p.Modules) { GNdrive drive = null; Taudrive tdrive = null; if (m.moduleName == "GNdrive") { drive = (GNdrive)m; if (drive.engineIgnited == true && drive.GetInstanceID() != GetInstanceID()) { enginecount += 1; if (modified == true) { if (drive.modified == true) { taactivated = drive.taactivated; agActivated = drive.agActivated; Overload = drive.Overload; overloadtemp = drive.Overload; hvActivated = drive.hvActivated; ICactivated = drive.ICactivated; ICIsActivaed = drive.ICIsActivaed; } else { drive.taactivated = taactivated; drive.agActivated = agActivated; drive.Overload = Overload; drive.overloadtemp = Overload; drive.hvActivated = hvActivated; drive.ICactivated = ICactivated; drive.ICIsActivaed = ICIsActivaed; } } } if (drive.agActivated == true) { agenginecount += 1; } } else if (m.moduleName == "Taudrive") { tdrive = (Taudrive)m; if (tdrive.agActivated == true) { agenginecount += 1; } } } } } else { Emitter.emit = false; } modified = false; if (engineIgnited == true) { ES = "Activated"; Events["Deactivate"].guiActive = true; Events["Activate"].guiActive = false; } else { Events["Deactivate"].guiActive = false; Events["Activate"].guiActive = true; } if (hvActivated == true && agActivated == true) { Events["Deactivatehv"].guiActive = true; Events["Activatehv"].guiActive = false; } else { Events["Deactivatehv"].guiActive = false; Events["Activatehv"].guiActive = true; } if (agActivated == true) { ES = "Activated"; Events["Deactivateag"].guiActive = true; Events["Activateag"].guiActive = false; } else { Events["Deactivateag"].guiActive = false; Events["Activateag"].guiActive = true; Events["Deactivatehv"].guiActive = false; Events["Activatehv"].guiActive = false; hvActivated = false; if (engineIgnited == false) { taactivated = false; Events["Activateta"].guiActive = true; } } if (taactivated == true) { ES = "Trans-AM"; } Vector3 srfVelocity = vessel.GetSrfVelocity(); float VerticalV; VerticalV = (float)vessel.verticalSpeed; //bool break = Vector3 Airspeed = vessel.transform.InverseTransformDirection(srfVelocity); Vector3 gee = FlightGlobals.getGeeForceAtPosition(this.vessel.transform.position) / agenginecount; float Vvelocity = Vector3.Dot(gee.normalized, part.rb.velocity); brakePid.Calibrateclamp(Overload); Vector3 VvCancel = hvActivated ? brakePid.Control(Vvelocity) * gee.normalized * 10 / agenginecount : Vector3.zero; Vector3 controlforce = vessel.ReferenceTransform.up * z + vessel.ReferenceTransform.forward * y + vessel.ReferenceTransform.right * x - VvCancel; if (enginecount > maxenginecount) { ES = "Unsynchronized"; controlforce = Vector3.zero; gee = Vector3.zero; } else { tefactor = (float)Math.Pow((double)particlegrate, (double)enginecount - 1); } if (engineIgnited == false) { controlforce = Vector3.zero; } if (agActivated == false) { gee = Vector3.zero; } float consumption = vessel.GetTotalMass() * Mathf.Abs((-gee + controlforce).magnitude) * fuelefficiency; float particlegen = particlegrate * tefactor; if (taactivated == true) { color = new Vector4(1F, 0F, 100F / 255F, 1F); controlforce *= 5; consumption = 4 * consumption - 3 * vessel.GetTotalMass() * Mathf.Abs(gee.magnitude) * fuelefficiency; Events["Activateta"].guiActive = false; consumption = Mathf.Max(particlegen, consumption) + 4; } else { color = new Vector4(0F, 1F, 170F / 255F, 1F); if (engineIgnited == true) { Events["Activateta"].guiActive = true; } } double reschange = (consumption - particlegen) * TimeWarp.fixedDeltaTime; double resourceDrawn = this.part.RequestResource("GNparticle", reschange); if (resourceDrawn == 0 && reschange > 0) { ES = "GNparticle depleted"; controlforce = Vector3.zero; gee = Vector3.zero; Deactivate(); Deactivateag(); taactivated = false; } // Debug.Log("Consumption " + consumption); // Debug.Log("particlegen " + particlegen); // Debug.Log("tefactor " + tefactor); // Debug.Log("resourceDrawn" + resourceDrawn); mass = vessel.GetTotalMass().ToString("R"); if (engineIgnited == true) { if (this.vessel.ActionGroups.groups[3]) { if (controlforce.magnitude > Overload) { controlforce = controlforce.normalized * Overload; } if (ICIsActivaed) { InertiaControl(); } Vector3 Breakforce = this.vessel.ActionGroups.groups[5] ? (-this.vessel.GetSrfVelocity()).normalized * Mathf.Min(this.vessel.GetSrfVelocity().magnitude / Time.fixedDeltaTime, Overload * 10f) - gee * 0.9f : Vector3.zero; controlforce += Breakforce; } foreach (Part p in this.vessel.parts) { if ((p.physicalSignificance == Part.PhysicalSignificance.FULL) && (p.rb != null)) { p.AddForce(controlforce * p.rb.mass); } } if (agActivated == true) { foreach (Part p in this.vessel.parts) { if ((p.physicalSignificance == Part.PhysicalSignificance.FULL) && (p.rb != null)) { p.AddForce(-gee * p.rb.mass); } } } rotor.GetComponent <Renderer>().material.SetColor("_EmissiveColor", color); stator.GetComponent <Renderer>().material.SetColor("_EmissiveColor", color); stator.GetComponent <Light>().color = color; rotor.transform.localEulerAngles = new Vector3(0, 0, rotation); rotation += 6 * (Mathf.Abs(controlforce.magnitude) + 1) * 120 * TimeWarp.deltaTime; while (rotation > 360) { rotation -= 360; } while (rotation < 0) { rotation += 360; } } void InertiaControl() { float DirFlag = 0; if (Airspeed.y < 0) { DirFlag = 2; } Vector3 InertiaForce = Vector3.zero; float ReD = 5000; Vessel target = null; if (this.vessel.targetObject != null) { target = this.vessel.targetObject.GetVessel(); ReD = Vector3.Distance(this.vessel.transform.position, target.transform.position); } if (target && ReD < 3000) { Vector3 RelVel = this.vessel.transform.InverseTransformDirection(this.vessel.rb_velocity - target.rb_velocity); Vector3 yawsForce = (x == 0 ? RelVel.x : -x) * -this.vessel.transform.right; Vector3 pitchsForce = (y == 0 ? RelVel.z : -y) * -this.vessel.transform.forward; Vector3 FrontForce = (RelVel.y - 10 * z < 0 && RelVel.y > 0 ? -z : RelVel.y) * -this.vessel.transform.up; InertiaForce = hvActivated ? Vector3.ProjectOnPlane(yawsForce + pitchsForce + FrontForce, gee.normalized) : yawsForce + pitchsForce + FrontForce; ICactivated = true; } else { if (target && ICactivated) { ICactivated = false; ICDeactivate(); } else { Vector3 yawsForce = (x == 0 ? Airspeed.x : -x) * -this.vessel.transform.right; Vector3 pitchsForce = (y == 0 ? Airspeed.z : -y) * -this.vessel.transform.forward; Vector3 FrontForce = Airspeed.y * -this.vessel.transform.up * DirFlag; InertiaForce = hvActivated ? Vector3.ProjectOnPlane(yawsForce + pitchsForce + FrontForce, gee.normalized) : yawsForce + pitchsForce + FrontForce; if (InertiaForce.magnitude > Overload) { InertiaForce = InertiaForce.normalized * Overload * 10; } } } controlforce += (InertiaForce) / Time.fixedDeltaTime / enginecount; } }