public void CloseVents() { ventState = BallastVentStates.Closed; updateGUI(); updateSymmetryVentState(); onBallastTankUpdated.Fire(this, tankType, ventState, isConverted); }
public void DumpBallast(bool updateSymmetryParts = true) { //Set the vent state ventState = BallastVentStates.Closed; //Clear the resource's ballast. if (resourceBallast != null) { resourceBallast.amount = 0.0f; } //Clear the ballast for all parts that have it else { this.part.RequestResource(ballastResourceName, double.MaxValue, ResourceFlowMode.ALL_VESSEL); } //Clear the ballast on symmetry parts if (!updateSymmetryParts) { return; } int count = this.part.symmetryCounterparts.Count; WBIBallastTank ballastTank; for (int index = 0; index < count; index++) { ballastTank = this.part.symmetryCounterparts[index].FindModuleImplementing <WBIBallastTank>(); if (ballastTank != null && ballastTank.resourceBallast != null) { ballastTank.resourceBallast.amount = 0.0f; } } }
public void VentBallast() { ventState = BallastVentStates.VentingBallast; updateGUI(); updateSymmetryVentState(); onBallastTankUpdated.Fire(this, tankType, ventState, isConverted); }
/// <summary> /// Dumps ballast /// </summary> /// <param name="updateSymmetryParts">A bool indicating whether or not to update symmetry parts</param> public void DumpBallast(bool updateSymmetryParts = true) { //Set the vent state ventState = BallastVentStates.Closed; updateSymmetryVentState(); //Clear the resource's ballast. if (ballastResource != null && ballastResource.flowState) { ballastResource.amount = 0.0f; } //Clear the ballast on symmetry parts if (!updateSymmetryParts) { return; } int count = part.symmetryCounterparts.Count; SWBallastTank ballastTank; for (int index = 0; index < count; index++) { ballastTank = part.symmetryCounterparts[index].FindModuleImplementing <SWBallastTank>(); if (ballastTank != null && ballastTank.ballastResource != null && ballastResource.flowState) { ballastTank.ballastResource.amount = 0.0f; } } }
public void ToggleSurface() { if (ballastTanks == null) { return; } if (ventState == BallastVentStates.VentingBallast) { ventState = BallastVentStates.Closed; } else { ventState = BallastVentStates.VentingBallast; } int count = ballastTanks.Count; for (int index = 0; index < count; index++) { ballastTanks[index].SetVentState(ventState); } updateGUI(); updateDiveComputers(); }
public void SetStandbyMode() { this.maintainDepth = false; this.wasMaintainingDepth = false; this.enableAutoTrim = false; this.wasAutoTrimming = false; this.ventState = BallastVentStates.Closed; updateGUI(); }
public void SetStandbyMode() { maintainDepth = false; wasMaintainingDepth = false; autoTrimEnabled = false; wasAutoTrimming = false; ventState = BallastVentStates.Closed; divingControlEnabled = false; standByMode = true; }
public void CloseVents() { if (ballastTanks == null) { return; } ventState = BallastVentStates.Closed; updateBallastTanksVentState(); updateDiveComputers(); }
public void VentBallastAction(KSPActionParam param) { if (ventState == BallastVentStates.VentingBallast) { ventState = BallastVentStates.Closed; } else { ventState = BallastVentStates.VentingBallast; } updateGUI(); }
void OnBallastTankUpdated(SWBallastTank ballastTank, BallastTankTypes ballastTankType, BallastVentStates ballastVentState, bool tankIsConverted) { // Stay in sync with other ballast tanks that are controlling the host part. if (ballastTank.hostPart != hostPart) { return; } tankType = ballastTankType; ventState = ballastVentState; isConverted = tankIsConverted; updatePAW = true; updateGUI(); }
public void VentBallast() { if (ballastTanks == null) { return; } ventState = BallastVentStates.VentingBallast; prevBallastFluidRate = ballastFluidRate; updateBallastTanksVentState(); updateDiveComputers(); maintainDepth = false; }
/// <summary> /// Sets the vent state /// </summary> /// <param name="state">The new BallastVentStates</param> /// <param name="fluidTransferRate">A float containing the new fluid transfer percentage</param> public void SetVentState(BallastVentStates state, float fluidTransferRate) { BallastVentStates prevState = ventState; // If we've finished venting or finished flooding then we're done. if ((state == BallastVentStates.VentingBallast && ballastResource.amount <= 0) || (state == BallastVentStates.FloodingBallast && ballastResource.amount >= ballastResource.maxAmount)) { return; } // Record vent state & transfer rate ventState = state; fluidTransferPercentage = fluidTransferRate; // Update UI if needed. if (ventState != prevState) { updateGUI(); } }
protected void updateBallastState() { //Check ballast states. We'll update our state once all the ballast tanks are closed. //Different ballast tanks fill/empty at different rates so the dive computer's state //needs to detect when all the ballast tanks have finished filling or emptying. int count = ballastTanks.Count; WBIBallastTank ballastTank; for (int index = 0; index < count; index++) { ballastTank = ballastTanks[index]; if (ballastTank.ventState != BallastVentStates.Closed && ballastTank.tankType == BallastTankTypes.Ballast) { return; } } //At this point all our ballast tanks are closed. ventState = BallastVentStates.Closed; updateGUI(); }
/// <summary> /// Controls buoyancy over a fixed unit of time. /// </summary> public void FixedUpdate() { if (!HighLogic.LoadedSceneIsFlight || kerbalEVA == null || !vessel.Splashed || !isActive) { return; } // Handle control inputs if (GameSettings.EVA_Pack_up.GetKey(false)) { ventState = BallastVentStates.VentingBallast; buoyancyControlStateDisplay = diveStateSurfacing; } else if (GameSettings.EVA_Pack_down.GetKey(false)) { ventState = BallastVentStates.FloodingBallast; buoyancyControlStateDisplay = diveStateDiving; } // Handle buoyancy control if we're maintaining depth. else if (maintainDepth) { buoyancyControlStateDisplay = ballastStateMaintainDisplay; if (vessel.verticalSpeed > kVerticalSpeedTrigger) { ventState = BallastVentStates.FloodingBallast; } else if (vessel.verticalSpeed <= kVerticalSpeedTrigger) { ventState = BallastVentStates.VentingBallast; } else { ventState = BallastVentStates.Closed; } } else { updateUI(); } // Reduce buoyancy if (ventState == BallastVentStates.FloodingBallast) { currentBuoyancy -= ((buoyancyControlRate / 100) * TimeWarp.fixedDeltaTime); if (currentBuoyancy <= 0f) { currentBuoyancy = 0f; ventState = BallastVentStates.Closed; if (!maintainDepth) { updateUI(); } } } // Increase buoyancy else if (ventState == BallastVentStates.VentingBallast) { currentBuoyancy += ((buoyancyControlRate / 100) * TimeWarp.fixedDeltaTime); if (currentBuoyancy > maxPositiveBuoyancy) { currentBuoyancy = maxPositiveBuoyancy; ventState = BallastVentStates.Closed; if (!maintainDepth) { updateUI(); } } } // Update part buoyancy. part.buoyancy = currentBuoyancy; }
public void Swim() { ventState = BallastVentStates.VentingBallast; maintainDepth = false; updateUI(); }
public void Sink() { ventState = BallastVentStates.FloodingBallast; maintainDepth = false; updateUI(); }
protected void updateBallastResource() { double maxAmount = 0f; double amount = 0; PartResourceDefinition resourceDef = null; PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; //Get the resource definition resourceDef = definitions[ballastResourceName]; //If we are filling ballast then increase the amount of ballast in the part. if (ventState == BallastVentStates.FloodingBallast) { //Make sure at least one of our intake transforms is underwater. if (intakeTransforms == null) { return; } if (!this.part.vessel.mainBody.ocean) { return; } bool intakeIsUnderwater = false; for (int index = 0; index < intakeTransforms.Length; index++) { if (FlightGlobals.getAltitudeAtPos((Vector3d)intakeTransforms[index].position, this.part.vessel.mainBody) <= 0.0f) { intakeIsUnderwater = true; break; } } if (!intakeIsUnderwater) { return; } //All good, fill the tank if (resourceBallast != null) { resourceBallast.amount += fillRate * TimeWarp.fixedDeltaTime; //Close the vents if we've filled the ballast. if (resourceBallast.amount >= resourceBallast.maxAmount) { resourceBallast.amount = resourceBallast.maxAmount; ventState = BallastVentStates.Closed; ventStateString = kClosed; } } //Fill the vessel else { this.part.RequestResource(ballastResourceName, -fillRate * TimeWarp.fixedDeltaTime, ResourceFlowMode.ALL_VESSEL); this.part.GetConnectedResourceTotals(resourceDef.id, out amount, out maxAmount, true); if (amount >= maxAmount) { ventState = BallastVentStates.Closed; ventStateString = kClosed; } } } //If we are venting ballast then reduce the amount of ballast in the part. else if (ventState == BallastVentStates.VentingBallast) { if (resourceBallast != null) { resourceBallast.amount -= ventRate * TimeWarp.fixedDeltaTime; //Close the vents if we've emptied the ballast. if (resourceBallast.amount <= 0.001f) { resourceBallast.amount = 0.0f; ventState = BallastVentStates.Closed; ventStateString = kClosed; } } //Empty the vessel else { this.part.RequestResource(ballastResourceName, fillRate * TimeWarp.fixedDeltaTime, ResourceFlowMode.ALL_VESSEL); this.part.GetConnectedResourceTotals(resourceDef.id, out amount, out maxAmount, true); if (amount <= 0.0f) { ventState = BallastVentStates.Closed; ventStateString = kClosed; } } } }
public void SetVentState(BallastVentStates state) { ventState = state; updateGUI(); }
void updateDepthState() { if (maintainDepth != wasMaintainingDepth) { wasMaintainingDepth = maintainDepth; updateDiveComputers(); } if (!maintainDepth || !divingControlEnabled || vesselIsManeuvering) { return; } //If we're rising up then flood the ballast int count = ballastTanks.Count; SWBallastTank ballastTank; if (part.vessel.verticalSpeed > verticalSpeedTrigger && ventState != BallastVentStates.FloodingBallast) { ventState = BallastVentStates.FloodingBallast; for (int index = 0; index < count; index++) { ballastTank = ballastTanks[index]; if (ballastTank.tankType == BallastTankTypes.Ballast) { ballastTank.SetVentState(BallastVentStates.FloodingBallast, ballastFluidRate); } } } //If we're sinking then empty the ballast else if (part.vessel.verticalSpeed < -verticalSpeedTrigger && ventState != BallastVentStates.VentingBallast) { ventState = BallastVentStates.VentingBallast; for (int index = 0; index < count; index++) { ballastTank = ballastTanks[index]; if (ballastTank.tankType == BallastTankTypes.Ballast) { ballastTank.SetVentState(BallastVentStates.VentingBallast, ballastFluidRate); } } } //All good else if ((part.vessel.verticalSpeed <= verticalSpeedTrigger || part.vessel.verticalSpeed >= -verticalSpeedTrigger) && ventState != BallastVentStates.Closed) { for (int index = 0; index < count; index++) { ballastTank = ballastTanks[index]; if (ballastTank.tankType == BallastTankTypes.Ballast) { if (ballastTank.ventState != BallastVentStates.Closed) { ballastTank.SetVentState(BallastVentStates.Closed, ballastFluidRate); } } } } }
public void CloseVents() { ventState = BallastVentStates.Closed; updateGUI(); updateSymmetryVentState(); }
public void VentBallast() { ventState = BallastVentStates.VentingBallast; updateGUI(); updateSymmetryVentState(); }
public void FloodBallast() { ventState = BallastVentStates.FloodingBallast; updateGUI(); updateSymmetryVentState(); }
void updateBallastResource() { //If we are filling ballast then increase the amount of ballast in the part. if (ventState == BallastVentStates.FloodingBallast) { // Make sure we're underwater. if (!part.vessel.mainBody.ocean) { return; } //Make sure at least one of our intake transforms is underwater. if (intakeTransforms == null) { return; } if (!this.part.vessel.mainBody.ocean) { return; } intakeIsUnderwater = false; for (int index = 0; index < intakeTransforms.Length; index++) { if (FlightGlobals.getAltitudeAtPos((Vector3d)intakeTransforms[index].position, this.part.vessel.mainBody) <= 0.0f) { intakeIsUnderwater = true; break; } } if (!intakeIsUnderwater) { return; } //All good, fill the tank if (ballastResource != null) { ballastResource.amount += fillRate * (fluidTransferPercentage / 100f) * TimeWarp.fixedDeltaTime; } //Close the vents if we've filled the ballast. if (ballastResource.amount >= ballastResource.maxAmount) { ballastResource.amount = ballastResource.maxAmount; ventState = BallastVentStates.Closed; updateGUI(); } } //If we are venting ballast then reduce the amount of ballast in the part. else if (ventState == BallastVentStates.VentingBallast) { ballastResource.amount -= ventRate * (fluidTransferPercentage / 100f) * TimeWarp.fixedDeltaTime; //Close the vents if we've emptied the ballast. if (ballastResource.amount <= 0.001f) { ballastResource.amount = 0.0f; ventState = BallastVentStates.Closed; updateGUI(); } } }
void updateBallastState() { // Check ballast states. We'll update our state once all the ballast tanks are closed. // Different ballast tanks fill/empty at different rates so the dive computer's state // needs to detect when all the ballast tanks have finished filling or emptying. int count = ballastTanks.Count; SWBallastTank ballastTank; bool ventsAreOpen = false; double amount = 0; double maxAmount = 0; for (int index = 0; index < count; index++) { ballastTank = ballastTanks[index]; // Get the current and max ballast. if (ballastTank.ballastResource != null && ballastTank.tankType == BallastTankTypes.Ballast) { amount += ballastTank.ballastResource.amount; maxAmount += ballastTank.ballastResource.maxAmount; // Check vent state if (ballastTank.ventState != BallastVentStates.Closed) { ventsAreOpen = true; } } } // Calculate buoyancy for the buoyancy controlled parts and update them. if (maxAmount > 0 && divingControlEnabled) { float buoyancy = 1 - ((float)(amount / maxAmount)); if (buoyancy < kMinBuoyancy) { buoyancy = kMinBuoyancy; } for (int index = 0; index < buoyancyPartCount; index++) { buoyancyControlledParts[index].buoyancy = buoyancy; } divingControlWasEnabled = true; } // If we're no longer controlling diving but it was enabled, then restore the buoyancy controlled parts' buoyancy. else if (!divingControlEnabled && divingControlWasEnabled) { divingControlWasEnabled = false; for (int index = 0; index < buoyancyPartCount; index++) { buoyancyControlledParts[index].buoyancy = 1f; } } // Check the flag. if (!ventsAreOpen) { ventState = BallastVentStates.Closed; } }
public void CloseVentsAction(KSPActionParam param) { ventState = BallastVentStates.Closed; updateGUI(); updateSymmetryVentState(); }