Пример #1
0
        public void OnEngineActive(string engineID, bool isRunning)
        {
            if (reactorIsOn == false && isRunning)
            {
                if (currentElectricCharge >= ecNeededToStart)
                {
                    reactorState = EReactorStates.Off;
                    ToggleReactor();
                    return;
                }

                primaryEngine.Events["Shutdown"].Invoke();
                primaryEngine.currentThrottle   = 0;
                primaryEngine.requestedThrottle = 0;

                secondaryEngine.Events["Shutdown"].Invoke();
                secondaryEngine.currentThrottle   = 0;
                secondaryEngine.requestedThrottle = 0;

                //If the reactor is off, then then start charging the capacitor.
                if (reactorState != EReactorStates.Charging)
                {
                    ScreenMessages.PostScreenMessage(kChargingCapacitor, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                    Events["ToggleReactor"].guiName = kStartEngine;
                    ToggleReactor();
                }
            }
        }
Пример #2
0
        public void ShutdownReactorAndEngine()
        {
            primaryEngine.Events["Shutdown"].Invoke();
            primaryEngine.currentThrottle   = 0;
            primaryEngine.requestedThrottle = 0;

            secondaryEngine.Events["Shutdown"].Invoke();
            secondaryEngine.currentThrottle   = 0;
            secondaryEngine.requestedThrottle = 0;

            Events["ToggleReactor"].guiName = kStartEngine;

            if (reactorState != EReactorStates.Charging)
            {
                currentElectricCharge = 0f;
            }
            reactorState = EReactorStates.Off;
            if (currentElectricCharge == 0f)
            {
                reactorStatus = EReactorStates.Off + string.Format(" Needs {0:F2} EC", ecNeededToStart);
            }
            else
            {
                reactorStatus = EReactorStates.Off + string.Format(" Needs {0:F2} EC", ecNeededToStart - currentElectricCharge);
            }
            reactorIsOn = false;
        }
Пример #3
0
        public void OnUpdateFixed()
        {
            //The logic below doesn't apply unless we're flying
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            if (reactorState == EReactorStates.None || reactorState == EReactorStates.Off)
            {
                return;
            }

            //If we are charging up, request electric charge and then exit.
            if (ReactorNeedsCharge())
            {
                return;
            }

            //Set status
            if (primaryEngine.currentThrottle > 0f || secondaryEngine.currentThrottle > 0f)
            {
                reactorState = EReactorStates.Running;
            }
            else
            {
                reactorState = EReactorStates.Idling;
            }
            reactorStatus = reactorState.ToString();

            //Consume a small amount of fusion pellets to represent the fusion reactor's operation in NTR mode.
            ConsumeFuel();
        }
Пример #4
0
        public void StartEngine()
        {
            reactorState                      = EReactorStates.Charged;
            currentElectricCharge             = 0f;
            Events["ChargeCapacitor"].guiName = kShutdownEngine;

            getCurrentEngine();
            engine.Activate();
            engine.part.force_activate();
        }
Пример #5
0
        public void ToggleReactor()
        {
            //If we got this far then it means we have the potential to start.
            //First check to see if we have enough electric charge.
            if (reactorState == EReactorStates.Off)
            {
                //If we need ec to start, then set our state to charging
                if ((currentElectricCharge < ecNeededToStart) && requiresECToStart)
                {
                    reactorState = EReactorStates.Charging;
                    reactorIsOn  = false;
                    Events["ToggleReactor"].guiName = kStopCharging;
                    ScreenMessages.PostScreenMessage(kChargingCapacitor, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                }

                //Capacitor is fully charged, activate the engine and star idling the reactor
                else
                {
                    reactorState = EReactorStates.Idling;
                    reactorIsOn  = true;
                    Events["ToggleReactor"].guiName = kShutdownEngine;

                    //Start your engine
                    StartEngine();
                }

                //Ok, we're done
                return;
            }

            else if (reactorState == EReactorStates.Charging)
            {
                reactorState  = EReactorStates.Off;
                reactorStatus = EReactorStates.Off + string.Format(" Needs {0:#.#} EC", ecNeededToStart - currentElectricCharge);
                reactorIsOn   = false;
            }

            else if (reactorState == EReactorStates.Running || reactorState == EReactorStates.Idling)
            {
                ShutdownReactorAndEngine();
                reactorIsOn           = false;
                reactorState          = EReactorStates.Off;
                currentElectricCharge = 0f;
                reactorStatus         = EReactorStates.Off + string.Format(" Needs {0:F2} EC", ecNeededToStart);
            }
        }
Пример #6
0
        public void SetEngineStateOnStart()
        {
            if (reactorIsOn)
            {
                reactorState  = EReactorStates.Idling;
                reactorStatus = reactorState.ToString();
                Events["ToggleReactor"].guiName = kShutdownEngine;

                //Start your engine
                StartEngine();
            }

            else if (reactorState == EReactorStates.None)
            {
                currentElectricCharge = 0f;
                reactorState          = EReactorStates.Off;
                reactorStatus         = EReactorStates.Off + string.Format(" Needs {0:F2} EC", ecNeededToStart);
            }
        }
Пример #7
0
        public void ConsumeFuel()
        {
            float fuelPerTimeTick = fuelConsumption * TimeWarp.fixedDeltaTime;

            //Adjust fuel consuption for idling
            if (primaryEngine.thrustPercentage == 0f && secondaryEngine.thrustPercentage == 0f)
            {
                fuelPerTimeTick = fuelPerTimeTick / 10.0f;
            }

            if (multiModeEngine.runningPrimary == true)
            {
                //Make sure we reach the minimum threshold
                fuelRequest += fuelPerTimeTick;
                if (fuelRequest >= 0.01f)
                {
                    //Consume fusion pellets
                    float fuelObtained = this.part.vessel.rootPart.RequestResource(reactorFuel, fuelRequest);

                    //If we haven't consumed enough pellets then the reactor cannot be sustained
                    //and the engine flames out.
                    if (fuelObtained < fuelRequest)
                    {
                        ScreenMessages.PostScreenMessage(kOutOfFuel, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                        primaryEngine.Events["Shutdown"].Invoke();
                        primaryEngine.currentThrottle   = 0;
                        primaryEngine.requestedThrottle = 0;
                        primaryEngine.flameout          = true;
                        reactorIsOn = false;
                        Events["ToggleReactor"].guiName = kStartEngine;
                        reactorState  = EReactorStates.Off;
                        reactorStatus = EReactorStates.Off + string.Format(" Needs {0:F2} EC", ecNeededToStart);
                    }

                    //Reset the fuel request
                    fuelRequest = 0f;
                }
            }
        }
Пример #8
0
        public void ShutdownEngine()
        {
            getCurrentEngine();
            engine.Events["Shutdown"].Invoke();
            engine.currentThrottle   = 0;
            engine.requestedThrottle = 0;

            Events["ChargeCapacitor"].guiName = kStartEngine;

            if (reactorState != EReactorStates.Charging)
            {
                currentElectricCharge = 0f;
            }
            reactorState = EReactorStates.Off;
            if (currentElectricCharge == 0f)
            {
                capacitorStatus = EReactorStates.Off + string.Format(" Needs {0:F2} EC", ecNeededToStart);
            }
            else
            {
                capacitorStatus = EReactorStates.Off + string.Format(" Needs {0:F2} EC", ecNeededToStart - currentElectricCharge);
            }
        }
Пример #9
0
        protected void setupEngines()
        {
            //See if we have multiple engines that we need to support
            engineSwitcher = this.part.FindModuleImplementing <MultiModeEngine>();
            List <ModuleEngines> engines      = this.part.FindModulesImplementing <ModuleEngines>();
            ModuleEngines        moduleEngine = null;

            //Hide GUI on the switcher
            engineSwitcher.autoSwitch = false;
            engineSwitcher.Events["DisableAutoSwitch"].guiActive       = false;
            engineSwitcher.Events["DisableAutoSwitch"].guiActiveEditor = false;
            engineSwitcher.Events["EnableAutoSwitch"].guiActive        = false;
            engineSwitcher.Events["EnableAutoSwitch"].guiActiveEditor  = false;

            //Find all the engines in the part and record their properties.
            for (int index = 0; index < engines.Count; index++)
            {
                moduleEngine = engines[index];
                multiModeEngines.Add(moduleEngine.engineID, moduleEngine);

                //Hide the GUI
                moduleEngine.Events["Activate"].guiActive       = false;
                moduleEngine.Events["Shutdown"].guiActive       = false;
                moduleEngine.Events["Activate"].guiActiveEditor = false;
                moduleEngine.Events["Shutdown"].guiActiveEditor = false;
            }

            //Get whichever multimode engine is the active one.
            if (engineSwitcher != null)
            {
                if (engineSwitcher.runningPrimary)
                {
                    engine = multiModeEngines[engineSwitcher.primaryEngineID];
                }
                else
                {
                    engine = multiModeEngines[engineSwitcher.secondaryEngineID];
                }
            }

            //Just get the first engine in the list.
            else if (engines.Count > 0)
            {
                engine = multiModeEngines.Values.ToArray()[0];
            }

            //Setup engine state
            if (reactorState == EReactorStates.Charged)
            {
                capacitorStatus = reactorState.ToString();
                Events["ChargeCapacitor"].guiName = kShutdownEngine;

                //Start your engine
                StartEngine();
            }

            else if (reactorState == EReactorStates.None)
            {
                currentElectricCharge = 0f;
                reactorState          = EReactorStates.Off;
                capacitorStatus       = EReactorStates.Off + string.Format(" Needs {0:F2} EC", ecNeededToStart);
            }
        }