public override void OnUpdate() { opFloor = findAcceptableAltitude(vessel.mainBody); // Keep updating tooltip display. if (FlightGlobals.getGeeForceAtPosition(vessel.GetWorldPos3D()).magnitude <= gLimit) { Fields["neededEC"].guiActive = !activated; } Fields["constantEC"].guiActive = activated; ModuleAnimateGeneric MAG = part.FindModuleImplementing <ModuleAnimateGeneric>(); MAG.Events["Toggle"].guiActive = false; if (activated && MAG.Progress == 0 && !MAG.IsMoving()) { MAG.Toggle(); } else if (!activated && MAG.Progress == 1 && !MAG.IsMoving()) { MAG.Toggle(); } double vfuel = 0; foreach (Part vpart in vessel.Parts) { foreach (PartResource vpr in vpart.Resources) { if (vpr.resourceName == "Karborundum") { vfuel += vpr.amount; } } } fuelOnBoard = vfuel; }
private void FixedUpdate() { if (!animationModule.IsMoving() && isMoving) { foreach (Part p in this.part.children) { /*p.attachJoint.Joint.xMotion = ConfigurableJointMotion.Locked; * p.attachJoint.Joint.yMotion = ConfigurableJointMotion.Locked; * p.attachJoint.Joint.zMotion = ConfigurableJointMotion.Locked; * p.attachJoint.Joint.angularXMotion = ConfigurableJointMotion.Locked; * p.attachJoint.Joint.angularYMotion = ConfigurableJointMotion.Locked; * p.attachJoint.Joint.angularZMotion = ConfigurableJointMotion.Locked; */ p.transform.SetParent(null, true); //p.transform.position = moveNode.nodeTransform.position; //p.attachJoint.Joint.targetPosition = p.transform.position; p.attachJoint.Joint.connectedBody = this.part.rb; p.attachJoint.Joint.autoConfigureConnectedAnchor = true; p.rb.isKinematic = false; //part.rb.WakeUp(); } vessel.CycleAllAutoStrut(); isMoving = false; } }
public override void OnUpdate() { ModuleAnimateGeneric MAG = part.FindModuleImplementing <ModuleAnimateGeneric>(); MAG.Events["Toggle"].guiActive = false; if (activated && MAG.Progress == 0 && !MAG.IsMoving()) { MAG.Toggle(); } else if (!activated && MAG.Progress == 1 && !MAG.IsMoving()) { MAG.Toggle(); } }
private void FixedUpdate() { if (!animationModule.IsMoving() && isMoving) { /*foreach (Part p in this.part.children) * { * p.transform.SetParent(null, true); * p.attachJoint.Joint.connectedBody = this.part.rb; * p.rb.isKinematic = false; * }*/ Stack <Part> stack = new Stack <Part>(); stack.Push(this.part); while (stack.Count > 0) { Part item = stack.Pop(); if (item == this.part) { Part child = moveNode.attachedPart; ConfigurableJoint partJoint = child.attachJoint.Joint; child.transform.SetParent(null, true); partJoint.connectedBody = this.part.rb; partJoint.autoConfigureConnectedAnchor = true; child.rb.isKinematic = false; //partJoint.autoConfigureConnectedAnchor = false; stack.Push(child); } else { foreach (Part child in item.children) { if (child.PhysicsSignificance == 1) { continue; } ConfigurableJoint partJoint = child.attachJoint.Joint; child.transform.SetParent(null, true); partJoint.connectedBody = item.rb; //partJoint.autoConfigureConnectedAnchor = true; child.rb.isKinematic = false; stack.Push(child); } } } isMoving = false; } }
void OnCollisionStay(Collision collisionInfo) { //if (collisionInfo.rigidbody != part.Rigidbody || !moduleAnimateGeneric) if (!moduleAnimateGeneric || !animationStopper) { return; } if (!moduleAnimateGeneric.IsMoving()) { return; } foreach (ContactPoint contact in collisionInfo.contacts) { ColliderInfo thisColliderInfo = GetColliderInfo(contact.thisCollider); // Check if this is an internal collider moving in respect to the part, // or if it is a child part moving due to being animated by AnimatedAttachment if (thisColliderInfo.part == part) { PosRot currentPosRot = PosRot.GetPosRot(thisColliderInfo.collider.transform, part); Vector3 movement = currentPosRot.position - thisColliderInfo.posRot.position; double angle = Quaternion.Angle(currentPosRot.rotation, thisColliderInfo.posRot.rotation); thisColliderInfo.posRot = currentPosRot; // Set a minimum level if (movement.IsSmallerThan(0.1f) && angle < 0.1) { continue; } printf("Animation stopped by a collision between %s and %s (movement %s, angle %s)", thisColliderInfo.collider.name, collisionInfo.collider.name, movement, angle); } else { printf("Animation stopped by a collision between %s.%s and %s", thisColliderInfo.part.name, thisColliderInfo.collider.name, collisionInfo.collider.name); } float time = moduleAnimateGeneric.animTime; if (moduleAnimateGeneric.revClampPercent) { time = 1 - time; } moduleAnimateGeneric.deployPercent = 100.0f * time; moduleAnimateGeneric.allowDeployLimit = true; break; } }
/// <summary> /// Helper function to determine the state of a ModuleAnimateGeneric. /// </summary> /// <param name="mag"></param> /// <returns></returns> internal static bool Extended(this ModuleAnimateGeneric mag) { Animation animation = mag.GetAnimation(); AnimationState animationState = animation[mag.animationName]; if (animationState != null && mag.IsMoving()) { return(animationState.normalizedSpeed > 0.0f); } else if (mag.Progress > 0.5f) { return(true); } else { return(false); } }
private bool Extended() { if (animationState == null) { Animation animation = animationModule.GetAnimation(); animationState = animation[animationModule.animationName]; } if (animationState != null && animationModule.IsMoving()) { return(animationState.normalizedSpeed > 0.0f); } else if (animationModule.Progress > 0.5f) { return(true); } else { return(false); } }
public void FixedUpdate() { if (!isActive) { return; } if (_loopingAnimation != null && !_loopingAnimation.IsMoving()) { _loopingAnimation.Toggle(); } // first check available hydrogen part.GetConnectedResourceTotals(_liquidHydrogenDefinition.id, out double amount, out double maxAmount); if (amount <= 0) { return; } var availablePower = GetAvailableStableSupply(ResourceSettings.Config.ElectricPowerInMegawatt); var resourceBarRatio = GetResourceBarRatio(ResourceSettings.Config.ElectricPowerInMegawatt); var effectiveResourceThrottling = resourceBarRatio > 1d / 3d ? 1 : resourceBarRatio * 3; var requestedPower = powerPercentage * 0.01 * Math.Min(powerCapacity * powerRequirementMultiplier, effectiveResourceThrottling * availablePower); var receivedPower = CheatOptions.InfiniteElectricity ? requestedPower : ConsumeFnResourcePerSecond(requestedPower, ResourceSettings.Config.ElectricPowerInMegawatt); megajoulesPerSecond = receivedPower * efficiency; // produce wasteheat SupplyFnResourcePerSecond(receivedPower * (1 - efficiency), ResourceSettings.Config.WasteHeatInMegawatt); Produce(megajoulesPerSecond, TimeWarp.fixedDeltaTime); }
/// <summary> /// Do stuff, or not, depending on whether we're supposed to. /// </summary> public void FixedUpdate() { if (HighLogic.LoadedSceneIsEditor || !vessel.isActiveVessel) { return; } if (radarEnabled) { bool radarDeployed = true; bool radarBroken = false; if (deployPart != null) { radarDeployed = deployPart.useAnimation && deployPart.deployState == ModuleDeployablePart.DeployState.EXTENDED; radarBroken = deployPart.deployState == ModuleDeployablePart.DeployState.BROKEN; } else if (deployAnimator != null) { radarDeployed = deployAnimator.IsMoving() == false && deployAnimator.animTime == 1.0f; } if (!radarDeployed) { // If the radar's not deployed, we're done. status = (radarBroken) ? RadarStatus.BROKEN : RadarStatus.NOT_DEPLOYED; UpdateRadarStatus(); return; } status = RadarStatus.SCANNING; // Resources check if (resourceAmount > 0.0f) { double requested = resourceAmount * TimeWarp.fixedDeltaTime; double supplied = part.RequestResource(resourceId, requested); if (supplied < requested * 0.5f) { status = RadarStatus.NO_POWER; UpdateRadarStatus(); return; } } FlightGlobals fg = FlightGlobals.fetch; ITargetable target = fg.VesselTarget; if (target == null) { // Scan ScanForTarget(fg); } else if (targetDockingPorts && dock != null && (target is Vessel)) { Vessel targetVessel = target as Vessel; if (!targetVessel.packed && targetVessel.loaded) { // Attempt to refine our target. ModuleDockingNode closestNode = null; float closestDistance = float.MaxValue; List <ModuleDockingNode> docks = targetVessel.FindPartModulesImplementing <ModuleDockingNode>(); if (docks != null) { for (int i = docks.Count - 1; i >= 0; --i) { ModuleDockingNode otherDock = docks[i]; // Only lock on to an available dock of the same type that is either ungendered or the opposite gender. if (otherDock.state == "Ready" && (string.IsNullOrEmpty(nodeType) || nodeType == otherDock.nodeType) && (dock.gendered == false || dock.genderFemale != otherDock.genderFemale)) { Vector3 vectorToTarget = (otherDock.part.transform.position - scanTransform.position); if (vectorToTarget.sqrMagnitude < closestDistance) { closestDistance = vectorToTarget.sqrMagnitude; closestNode = otherDock; } } } } if (closestNode != null) { fg.SetVesselTarget(closestNode); status = RadarStatus.TRACKING; } } } else { status = RadarStatus.TRACKING; } } else { status = RadarStatus.STANDBY; } UpdateRadarStatus(); }