Ejemplo n.º 1
0
 public void CloseVents()
 {
     ventState = BallastVentStates.Closed;
     updateGUI();
     updateSymmetryVentState();
     onBallastTankUpdated.Fire(this, tankType, ventState, isConverted);
 }
Ejemplo n.º 2
0
        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;
                }
            }
        }
Ejemplo n.º 3
0
 public void VentBallast()
 {
     ventState = BallastVentStates.VentingBallast;
     updateGUI();
     updateSymmetryVentState();
     onBallastTankUpdated.Fire(this, tankType, ventState, isConverted);
 }
Ejemplo n.º 4
0
        /// <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;
                }
            }
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        public void SetStandbyMode()
        {
            this.maintainDepth       = false;
            this.wasMaintainingDepth = false;
            this.enableAutoTrim      = false;
            this.wasAutoTrimming     = false;
            this.ventState           = BallastVentStates.Closed;

            updateGUI();
        }
Ejemplo n.º 7
0
 public void SetStandbyMode()
 {
     maintainDepth        = false;
     wasMaintainingDepth  = false;
     autoTrimEnabled      = false;
     wasAutoTrimming      = false;
     ventState            = BallastVentStates.Closed;
     divingControlEnabled = false;
     standByMode          = true;
 }
Ejemplo n.º 8
0
        public void CloseVents()
        {
            if (ballastTanks == null)
            {
                return;
            }

            ventState = BallastVentStates.Closed;

            updateBallastTanksVentState();
            updateDiveComputers();
        }
Ejemplo n.º 9
0
        public void VentBallastAction(KSPActionParam param)
        {
            if (ventState == BallastVentStates.VentingBallast)
            {
                ventState = BallastVentStates.Closed;
            }
            else
            {
                ventState = BallastVentStates.VentingBallast;
            }

            updateGUI();
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        public void VentBallast()
        {
            if (ballastTanks == null)
            {
                return;
            }

            ventState = BallastVentStates.VentingBallast;

            prevBallastFluidRate = ballastFluidRate;
            updateBallastTanksVentState();
            updateDiveComputers();
            maintainDepth = false;
        }
Ejemplo n.º 12
0
        /// <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();
            }
        }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
0
        /// <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;
        }
Ejemplo n.º 15
0
 public void Swim()
 {
     ventState     = BallastVentStates.VentingBallast;
     maintainDepth = false;
     updateUI();
 }
Ejemplo n.º 16
0
 public void Sink()
 {
     ventState     = BallastVentStates.FloodingBallast;
     maintainDepth = false;
     updateUI();
 }
Ejemplo n.º 17
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 18
0
 public void SetVentState(BallastVentStates state)
 {
     ventState = state;
     updateGUI();
 }
Ejemplo n.º 19
0
        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 20
0
 public void CloseVents()
 {
     ventState = BallastVentStates.Closed;
     updateGUI();
     updateSymmetryVentState();
 }
Ejemplo n.º 21
0
 public void VentBallast()
 {
     ventState = BallastVentStates.VentingBallast;
     updateGUI();
     updateSymmetryVentState();
 }
Ejemplo n.º 22
0
 public void FloodBallast()
 {
     ventState = BallastVentStates.FloodingBallast;
     updateGUI();
     updateSymmetryVentState();
 }
Ejemplo n.º 23
0
        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();
                }
            }
        }
Ejemplo n.º 24
0
        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;
            }
        }
Ejemplo n.º 25
0
 public void CloseVentsAction(KSPActionParam param)
 {
     ventState = BallastVentStates.Closed;
     updateGUI();
     updateSymmetryVentState();
 }