Example #1
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            turbineState = (ETurbineStates)turbineStateID;
            GameEvents.onStageActivate.Add(OnStageActivate);
            GameEvents.onVesselWasModified.Add(OnVesselModified);
            GameEvents.onVesselChange.Add(OnVesselChange);

            setupGUI();

            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            //Optional turbine transform
            if (!string.IsNullOrEmpty(turbineTransformName) && !string.IsNullOrEmpty(turbineAxis))
            {
                turbineTransform = this.part.FindModelTransform(turbineTransformName);

                string[] axisValues = turbineAxis.Split(',');
                float    value;
                if (axisValues.Length == 3)
                {
                    if (float.TryParse(axisValues[0], out value))
                    {
                        turbineRotationAxis.x = value;
                    }
                    if (float.TryParse(axisValues[1], out value))
                    {
                        turbineRotationAxis.y = value;
                    }
                    if (float.TryParse(axisValues[2], out value))
                    {
                        turbineRotationAxis.z = value;
                    }
                }
            }

            //Output percent
            lastOutputPercent = outputPercent;

            //Power output display
            ResourceRatio[] outputs = outputList.ToArray();
            ResourceRatio   output;

            for (int index = 0; index < outputs.Length; index++)
            {
                output = outputs[index];
                if (output.ResourceName == "ElectricCharge")
                {
                    ecBaseOutput = output.Ratio;
                    break;
                }
            }

            //Info box
            setupInfoBox();
        }
Example #2
0
        public void TurnOffGenerator()
        {
            turbineState   = ETurbineStates.SpoolingDown;
            turbineStateID = (int)turbineState;
            if (!string.IsNullOrEmpty(stopEffect))
            {
                this.part.Effect(stopEffect, 1.0f);
            }

            //Clear info box
            if (infoBox != null)
            {
                infoBox.Collapse();
            }

            setupGUI();
        }
Example #3
0
        public void TurnOnGenerator()
        {
            lastThrottleSetting = FlightInputHandler.state.mainThrottle;

            turbineState   = ETurbineStates.SpoolingUp;
            turbineStateID = (int)turbineState;
            if (!string.IsNullOrEmpty(startEffect))
            {
                this.part.Effect(startEffect, 1.0f);
            }

            //Setup info box
            if (infoBox != null)
            {
                infoBox.Expand();
            }

            setupGUI();
        }
Example #4
0
        protected override void PreProcessing()
        {
            base.PreProcessing();
            float bonusEfficiency = 0f;
            float outputLimit     = outputPercent / 100.0f;

            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            if (turbineState == ETurbineStates.Off)
            {
                if (EfficiencyBonus > 0f)
                {
                    SetEfficiencyBonus(0f);
                    updatePowerDisplay();
                    updateFuelGauge();
                }
                return;
            }

            switch (turbineState)
            {
            case ETurbineStates.SpoolingUp:
                if (powerLevel < kBaseSpoolPowerLevel)
                {
                    powerLevel        = Mathf.MoveTowards(powerLevel, kBaseSpoolPowerLevel, TimeWarp.fixedDeltaTime / spoolTime);
                    turbineSpinFactor = Mathf.MoveTowards(turbineSpinFactor, turbineMinRPS, TimeWarp.fixedDeltaTime);
                }

                if (powerLevel >= kBaseSpoolPowerLevel)
                {
                    turbineSpinFactor = 1.0f;
                    turbineState      = ETurbineStates.ThrottleControlled;
                    turbineStateID    = (int)turbineState;
                    StartResourceConverter();
                }

                bonusEfficiency = kBaseEfficiencyBonus * powerLevel;
                break;

            case ETurbineStates.SpoolingDown:
                if (powerLevel > kBaseSpoolPowerLevel)
                {
                    powerLevel        = Mathf.MoveTowards(powerLevel, kBaseSpoolPowerLevel, TimeWarp.fixedDeltaTime / spoolTime);
                    turbineSpinFactor = Mathf.MoveTowards(turbineSpinFactor, turbineMinRPS, TimeWarp.fixedDeltaTime);
                    bonusEfficiency   = kBaseEfficiencyBonus * powerLevel;
                }

                //power down completely
                else
                {
                    StopResourceConverter();

                    powerLevel = Mathf.MoveTowards(powerLevel, 0, TimeWarp.fixedDeltaTime / spoolTime);
                    if (powerLevel <= 0.0001f)
                    {
                        powerLevel        = 0f;
                        turbineSpinFactor = 0f;
                        turbineState      = ETurbineStates.Off;
                        turbineStateID    = (int)turbineState;
                        if (!string.IsNullOrEmpty(turbineEffect))
                        {
                            this.part.Effect(turbineEffect, 0f);
                        }
                        if (!string.IsNullOrEmpty(smokeEffect))
                        {
                            this.part.Effect(smokeEffect, 0f);
                        }
                    }
                }
                break;

            case ETurbineStates.ThrottleControlled:
                //If we're missing inputs then flameout.
                if (!string.IsNullOrEmpty(status) && status.ToLower().Contains("missing"))
                {
                    StopResourceConverter();
                    turbineState   = ETurbineStates.SpoolingDown;
                    turbineStateID = (int)turbineState;
                    if (!string.IsNullOrEmpty(flameoutEffect))
                    {
                        this.part.Effect(flameoutEffect, 1.0f);
                    }
                }

                //Set production efficiency bonus and power level based on throttle
                if (FlightGlobals.ActiveVessel == this.part.vessel)
                {
                    lastThrottleSetting = FlightInputHandler.state.mainThrottle;
                }
                if (lastThrottleSetting > 0)
                {
                    powerLevel      = Mathf.MoveTowards(powerLevel, lastThrottleSetting * outputLimit, TimeWarp.fixedDeltaTime / spoolTime);
                    bonusEfficiency = powerLevel;
                }

                else
                {
                    powerLevel      = Mathf.MoveTowards(powerLevel, kBaseSpoolPowerLevel, TimeWarp.fixedDeltaTime / spoolTime);
                    bonusEfficiency = powerLevel;
                }

                //Make sure we achieve minimum power levels.
                if (powerLevel <= kBaseSpoolPowerLevel)
                {
                    powerLevel      = kBaseSpoolPowerLevel;
                    bonusEfficiency = kBaseEfficiencyBonus;
                }
                break;

            default:
                break;
            }

            //Set efficiency bonus
            SetEfficiencyBonus(bonusEfficiency);
            updatePowerDisplay();
            updateFuelGauge();

            //Spin the turbine (optional)
            if (turbineTransform != null && turbineRotationAxis != null)
            {
                if (powerLevel > kBaseSpoolPowerLevel)
                {
                    turbineTransform.Rotate(turbineRotationAxis * (turbineMaxRPS * powerLevel));
                }
                else
                {
                    turbineTransform.Rotate(turbineRotationAxis * turbineMinRPS * turbineSpinFactor);
                }
            }
        }