private void InitializePropellantMode()
        {
            // initialize propellant
            _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);

            if (propellantIsSaved || HighLogic.LoadedSceneIsEditor)
            {
                if (!string.IsNullOrEmpty(propellantName))
                {
                    CurrentPropellant = _propellants.FirstOrDefault(m => m.PropellantName == propellantName) ??
                                        _propellants.FirstOrDefault(m => m.PropellantGUIName == propellantName);
                }

                if (CurrentPropellant == null && !string.IsNullOrEmpty(propellantGUIName))
                {
                    CurrentPropellant = _propellants.FirstOrDefault(m => m.PropellantName == propellantGUIName);

                    if (CurrentPropellant == null)
                    {
                        CurrentPropellant = _propellants.FirstOrDefault(m => m.PropellantGUIName == propellantGUIName);
                    }
                }
            }
            if (_propellants == null)
            {
                Debug.LogWarning("[KSPI]: SetupPropellants _propellants is still null");
            }

            if (CurrentPropellant == null)
            {
                CurrentPropellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.First();
            }
        }
        public override string GetInfo()
        {
            List <ElectricEnginePropellant> props = ElectricEnginePropellant.GetPropellantsEngineForType(type);
            string return_str    = "Max Power Consumption: " + MaxPower.ToString("") + " MW\n";
            var    thrust_per_mw = (2e6 * powerThrustMultiplier) / _g0 / (baseISP * PluginHelper.ElectricEngineIspMult) / 1000.0;

            props.ForEach(prop =>
            {
                var ispPropellantModifier = (PluginHelper.IspElectroPropellantModifierBase + (this.type == (int)ElectricEngineType.VASIMR ? prop.DecomposedIspMult : prop.IspMultiplier)) / (1 + PluginHelper.IspNtrPropellantModifierBase);
                var ispProp = _modifiedEngineBaseISP * ispPropellantModifier;

                double efficiency;
                if (type == (int)ElectricEngineType.ARCJET)
                {
                    efficiency = 0.87 * prop.Efficiency;
                }
                else if (type == (int)ElectricEngineType.VASIMR)
                {
                    efficiency = baseEfficency + 0.5 * variableEfficency;
                }
                else
                {
                    efficiency = prop.Efficiency;
                }

                var thrustProp = thrust_per_mw / ispPropellantModifier * efficiency * (type == (int)ElectricEngineType.ARCJET ? prop.ThrustMultiplier : 1);
                return_str     = return_str + "---" + prop.PropellantGUIName + "---\nThrust: " + thrustProp.ToString("0.000") + " kN per MW\nEfficiency: " + (efficiency * 100.0).ToString("0.00") + "%\nISP: " + ispProp.ToString("0.00") + "s\n";
            });
            return(return_str);
        }
Ejemplo n.º 3
0
        public override string GetInfo()
        {
            var props       = ElectricEnginePropellant.GetPropellantsEngineForType(type);
            var returnStr   = Localizer.Format("#LOC_KSPIE_ElectricEngine_maxPowerConsumption") + " : " + MaxPower.ToString("F3") + " MW\n";
            var thrustPerMw = (2e6 * powerThrustMultiplier) / _g0 / (baseISP * PluginHelper.ElectricEngineIspMult) / 1000.0;

            props.ForEach(prop =>
            {
                var ispPropellantModifier = (PluginHelper.IspElectroPropellantModifierBase + (this.type == (int)ElectricEngineType.VASIMR ? prop.DecomposedIspMult : prop.IspMultiplier)) / (1 + PluginHelper.IspNtrPropellantModifierBase);
                var ispProp = _modifiedEngineBaseIsp * ispPropellantModifier;

                double efficiency;

                switch (type)
                {
                case (int)ElectricEngineType.ARCJET:
                    efficiency = 0.87 * prop.Efficiency;
                    break;

                case (int)ElectricEngineType.VASIMR:
                    efficiency = baseEfficency + 0.5 * variableEfficency;
                    break;

                default:
                    efficiency = prop.Efficiency;
                    break;
                }

                var thrustProp = thrustPerMw / ispPropellantModifier * efficiency * (type == (int)ElectricEngineType.ARCJET ? prop.ThrustMultiplier : 1);
                returnStr      = returnStr + "---" + prop.PropellantGUIName + "---\n" + Localizer.Format("#LOC_KSPIE_ElectricEngine_thrust")
                                 + ": " + thrustProp.ToString("0.000") + " " + Localizer.Format("#LOC_KSPIE_ElectricEngine_kiloNewtonPerMegaWatt") + "\n" + Localizer.Format("#LOC_KSPIE_ElectricEngine_efficiency")
                                 + " : " + (efficiency * 100.0).ToString("0.00") + "%\n" + Localizer.Format("#LOC_KSPIE_ElectricEngine_specificImpulse") + ": " + ispProp.ToString("0.00") + "s\n";
            });
            return(returnStr);
        }
Ejemplo n.º 4
0
        public override void OnStart(PartModule.StartState state)
        {
            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT };
            _attached_engine         = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;
            this.resources_to_supply = resources_to_supply;
            _propellants             = getPropellants();
            base.OnStart(state);

            if (state == StartState.Editor)
            {
                if (this.HasTechsRequiredToUpgrade())
                {
                    upgradePartModule();
                }
                return;
            }

            if (this.HasTechsRequiredToUpgrade())
            {
                _hasrequiredupgrade = true;
            }

            if (_attached_engine != null)
            {
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";
            }

            fuel_gauge          = part.stackIcon.DisplayInfo();
            _current_propellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.FirstOrDefault();
            setupPropellants();
        }
        public override string GetInfo()
        {
            var props       = ElectricEnginePropellant.GetPropellantsEngineForType(type);
            var returnStr   = Localizer.Format("#LOC_KSPIE_ElectricEngine_maxPowerConsumption") + " : " + maxPower.ToString("F3") + " MW\n";
            var thrustPerMw = (2e6 * powerThrustMultiplier) / GameConstants.STANDARD_GRAVITY / (baseISP * PluginHelper.ElectricEngineIspMult) / 1000.0;

            //props.ForEach(prop =>
            //{
            //    var ispPropellantModifier = (this.type == (int)ElectricEngineType.VASIMR ? prop.DecomposedIspMult : prop.IspMultiplier);
            //    var ispProp = _modifiedEngineBaseIsp * ispPropellantModifier;

            //    double efficiency;

            //    switch (type)
            //    {
            //        case (int)ElectricEngineType.ARCJET:
            //            efficiency = 0.87 * prop.Efficiency;
            //            break;
            //        case (int)ElectricEngineType.VASIMR:
            //            efficiency = baseEfficency + 0.5 * variableEfficency;
            //            break;
            //        default:
            //            efficiency = prop.Efficiency;
            //            break;
            //    }

            //    var thrustProp = thrustPerMw / ispPropellantModifier * efficiency * (type == (int)ElectricEngineType.ARCJET ? prop.ThrustMultiplier : 1);
            //    returnStr = returnStr + "---" + prop.PropellantGUIName + "---\n" + Localizer.Format("#LOC_KSPIE_ElectricEngine_thrust")
            //        + ": " + thrustProp.ToString("0.000") + " " + Localizer.Format("#LOC_KSPIE_ElectricEngine_kiloNewtonPerMegaWatt") + "\n" + Localizer.Format("#LOC_KSPIE_ElectricEngine_efficiency")
            //        + " : " + (efficiency * 100.0).ToString("0.00") + "%\n" + Localizer.Format("#LOC_KSPIE_ElectricEngine_specificImpulse") + ": " + ispProp.ToString("0.00") + "s\n";
            //});
            return(returnStr);
        }
        public override void OnStart(PartModule.StartState state) 
        {
            // old legacy stuff
            if (baseThrust == 0 && maxThrust > 0)
                baseThrust = maxThrust;

            if (partMass == 0)
                partMass = part.mass;

            if (String.IsNullOrEmpty(displayName))
                displayName = part.partInfo.title;

            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT };
            this.resources_to_supply = resources_to_supply;

            attachedRCS = this.part.FindModuleImplementing<ModuleRCS>();
            oldThrustLimiter = thrustLimiter;
            oldPowerEnabled = powerEnabled;
            efficencyModifier = (float)g0 * 0.5f / 1000.0f / efficency;
            efficencyStr = (efficency * 100).ToString() + "%";

            if (!String.IsNullOrEmpty(AnimationName))
                rcsStates = SetUpAnimation(AnimationName, this.part);

            // initialize propellant
            _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);
            SetupPropellants(true, _propellants.Count);
            currentThrustMultiplier = hasSufficientPower ? Current_propellant.ThrustMultiplier : Current_propellant.ThrustMultiplierCold;

            base.OnStart(state);
         }
        private void SetupPropellants(bool moveNext = true, int maxSwitching = 0)
        {
            Current_propellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.FirstOrDefault();
            fuel_mode_name     = Current_propellant.PropellantName;

            if ((Current_propellant.SupportedEngines & type) != type)
            {
                SwitchPropellant(moveNext, --maxSwitching);
                return;
            }

            Propellant new_propellant = Current_propellant.Propellant;

            if (HighLogic.LoadedSceneIsFlight)
            {
                // you can have any fuel you want in the editor but not in flight
                List <PartResource> totalpartresources = part.GetConnectedResources(new_propellant.name).ToList();

                if (!totalpartresources.Any() && maxSwitching > 0)
                {
                    SwitchPropellant(moveNext, --maxSwitching);
                    return;
                }
            }

            if (PartResourceLibrary.Instance.GetDefinition(new_propellant.name) != null)
            {
                var effectiveIspMultiplier = type == 2 ? Current_propellant.DecomposedIspMult : Current_propellant.IspMultiplier;

                //var effectiveThrust = (thrustLimiter / 100) * Current_propellant.ThrustMultiplier * baseThrust / effectiveIspMultiplier;

                var moduleConfig = new ConfigNode("MODULE");
                moduleConfig.AddValue("name", "FNModuleRCSFX");
                moduleConfig.AddValue("thrusterPower", attachedRCS.thrusterPower.ToString("0.000"));
                moduleConfig.AddValue("resourceName", new_propellant.name);
                moduleConfig.AddValue("resourceFlowMode", "STAGE_PRIORITY_FLOW");

                currentThrustMultiplier = hasSufficientPower ? Current_propellant.ThrustMultiplier : Current_propellant.ThrustMultiplierCold;

                //var effectiveThrustModifier = currentThrustMultiplier * (currentThrustMultiplier / Current_propellant.ThrustMultiplier);

                var effectiveBaseIsp = hasSufficientPower ? maxIsp : minIsp;

                maxPropellantIsp = (float)(effectiveBaseIsp * effectiveIspMultiplier * currentThrustMultiplier);

                var atmosphereCurve = new ConfigNode("atmosphereCurve");
                atmosphereCurve.AddValue("key", "0 " + (maxPropellantIsp).ToString("0.000"));
                atmosphereCurve.AddValue("key", "1 " + (maxPropellantIsp * 0.5).ToString("0.000"));
                atmosphereCurve.AddValue("key", "4 " + (maxPropellantIsp * 0.00001).ToString("0.000"));
                moduleConfig.AddNode(atmosphereCurve);

                attachedRCS.Load(moduleConfig);
            }
            else if (maxSwitching > 0)
            {
                Debug.Log("ElectricRCSController SetupPropellants switching mode because no definition found for " + new_propellant.name);
                SwitchPropellant(moveNext, --maxSwitching);
                return;
            }
        }
        private void SetupPropellants(bool moveNext, int maxSwitching)
        {
            Current_propellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.FirstOrDefault();
            if ((Current_propellant.SupportedEngines & type) != type)
            {
                SwitchPropellant(moveNext, --maxSwitching);
                return;
            }
            Propellant new_propellant = Current_propellant.Propellant;

            if (HighLogic.LoadedSceneIsFlight)
            {
                // you can have any fuel you want in the editor but not in flight
                //List<PartResource> totalpartresources = part.GetConnectedResources(new_propellant.name).ToList();

                //if (!totalpartresources.Any() && maxSwitching > 0)
                //{
                //    SwitchPropellant(moveNext, --maxSwitching);
                //    return;
                //}

                var resourceDefinition = PartResourceLibrary.Instance.GetDefinition(new_propellant.name);
                
                double amount;
                double maxAmount;
                part.GetConnectedResourceTotals(resourceDefinition.id, out amount, out maxAmount);

                if (maxAmount > 0  && maxSwitching > 0)
                {
                    SwitchPropellant(moveNext, --maxSwitching);
                    return;
                }
            }

            if (PartResourceLibrary.Instance.GetDefinition(new_propellant.name) != null)
            {
                currentThrustMultiplier = hasSufficientPower ? Current_propellant.ThrustMultiplier : Current_propellant.ThrustMultiplierCold;

                var moduleConfig = new ConfigNode("MODULE");
                moduleConfig.AddValue("name", "ModuleRCSFX");
                moduleConfig.AddValue("thrusterPower", ((thrustLimiter / 100) * currentThrustMultiplier * baseThrust / Current_propellant.IspMultiplier).ToString("0.000"));
                moduleConfig.AddValue("resourceName", new_propellant.name);
                moduleConfig.AddValue("resourceFlowMode", "STAGE_PRIORITY_FLOW");

                maxPropellantIsp = (hasSufficientPower ? maxIsp : minIsp) * Current_propellant.IspMultiplier * currentThrustMultiplier;

                var atmosphereCurve = new ConfigNode("atmosphereCurve");
                atmosphereCurve.AddValue("key", "0 " + (maxPropellantIsp).ToString("0.000"));
                atmosphereCurve.AddValue("key", "1 " + (maxPropellantIsp * 0.5).ToString("0.000"));
                atmosphereCurve.AddValue("key", "4 " + (maxPropellantIsp * 0.00001).ToString("0.000"));
                moduleConfig.AddNode(atmosphereCurve);

                attachedRCS.Load(moduleConfig);
            }
            else if (maxSwitching > 0)
            {
                SwitchPropellant(moveNext, --maxSwitching);
                return;
            }
        }
Ejemplo n.º 9
0
 protected void togglePropellants()
 {
     fuel_mode++;
     if (fuel_mode >= _propellants.Count)
     {
         fuel_mode = 0;
     }
     _current_propellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.FirstOrDefault();
     setupPropellants();
 }
        public void upgradePartModule()
        {
            isupgraded    = true;
            type          = upgradedtype;
            _propellants  = ElectricEnginePropellant.GetPropellantsEngineForType(type);
            engineTypeStr = upgradedName;

            if (!vacplasmaadded && type == (int)ElectricEngineType.VACUUMTHRUSTER)
            {
                vacplasmaadded = true;
                ConfigNode node = new ConfigNode("RESOURCE");
                node.AddValue("name", InterstellarResourcesConfiguration.Instance.VacuumPlasma);
                node.AddValue("maxAmount", maxPower * 0.0000001);
                node.AddValue("amount", maxPower * 0.0000001);
                this.part.AddResource(node);
            }
        }
Ejemplo n.º 11
0
        public override void OnStart(PartModule.StartState state)
        {
            UnityEngine.Debug.Log("[KSPI] - Start Initializing ElectricEngineControllerFX");
            try
            {
                // initialise resources
                this.resources_to_supply = new string[] { FNResourceManager.FNRESOURCE_WASTEHEAT };
                base.OnStart(state);
                AttachToEngine();

                _g0 = PluginHelper.GravityConstant;
                _hasGearTechnology     = String.IsNullOrEmpty(gearsTechReq) || PluginHelper.upgradeAvailable(gearsTechReq);
                _modifiedEngineBaseISP = baseISP * PluginHelper.ElectricEngineIspMult;
                _hasrequiredupgrade    = this.HasTechsRequiredToUpgrade();

                if (_hasrequiredupgrade && (isupgraded || state == StartState.Editor))
                {
                    upgradePartModule();
                }
                UpdateEngineTypeString();

                // calculate WasteHeat Capacity
                var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT);
                if (wasteheatPowerResource != null)
                {
                    var ratio = wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount;
                    wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;
                    wasteheatPowerResource.amount    = wasteheatPowerResource.maxAmount * ratio;
                }

                if (HighLogic.LoadedSceneIsFlight)
                {
                    fuel_gauge = part.stackIcon.DisplayInfo();
                }

                // initialize propellant
                _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);
                SetupPropellants(true);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError("[KSPI] - Error OnStart ElectricEngineControllerFX " + e.Message);
            }
            UnityEngine.Debug.Log("[KSPI] - End Initializing ElectricEngineControllerFX");
        }
        public override void OnStart(PartModule.StartState state)
        {
            initializationCountdown = 10;
            UnityEngine.Debug.Log("[KSPI] - Start Initializing ElectricEngineControllerFX");
            try
            {
                // initialise resources
                this.resources_to_supply = new string[] { ResourceManager.FNRESOURCE_WASTEHEAT };
                base.OnStart(state);
                AttachToEngine();

                _g0 = PluginHelper.GravityConstant;
                _hasGearTechnology     = String.IsNullOrEmpty(gearsTechReq) || PluginHelper.upgradeAvailable(gearsTechReq);
                _modifiedEngineBaseISP = baseISP * PluginHelper.ElectricEngineIspMult;
                _hasrequiredupgrade    = this.HasTechsRequiredToUpgrade();

                if (_hasrequiredupgrade && (isupgraded || state == StartState.Editor))
                {
                    upgradePartModule();
                }

                vacuumPlasmaResource = part.Resources[InterstellarResourcesConfiguration.Instance.VacuumPlasma];
                UpdateEngineTypeString();

                // calculate WasteHeat Capacity
                var wasteheatPowerResource = part.Resources.FirstOrDefault(r => r.resourceName == ResourceManager.FNRESOURCE_WASTEHEAT);
                if (wasteheatPowerResource != null)
                {
                    var wasteheat_ratio = Math.Min(wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount, 0.95);
                    wasteheatPowerResource.maxAmount = part.mass * 2.0e+4 * wasteHeatMultiplier;
                    wasteheatPowerResource.amount    = wasteheatPowerResource.maxAmount * wasteheat_ratio;
                }

                // initialize propellant
                _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);
                SetupPropellants(true);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError("[KSPI] - Error OnStart ElectricEngineControllerFX " + e.Message);
            }
            UnityEngine.Debug.Log("[KSPI] - End Initializing ElectricEngineControllerFX");
        }
Ejemplo n.º 13
0
        public override void OnStart(PartModule.StartState state)
        {
            _initializationCountdown = 10;
            Debug.Log("[KSPI] - Start Initializing ElectricEngineControllerFX");
            try
            {
                // initialise resources
                this.resources_to_supply = new [] { ResourceManager.FNRESOURCE_WASTEHEAT };
                base.OnStart(state);
                AttachToEngine();

                _ispFloatCurve = new FloatCurve();
                _ispFloatCurve.Add(0, baseISP);
                _g0                    = PluginHelper.GravityConstant;
                _speedOfLight          = GameConstants.speedOfLight * PluginHelper.SpeedOfLightMult;
                _hasGearTechnology     = String.IsNullOrEmpty(gearsTechReq) || PluginHelper.UpgradeAvailable(gearsTechReq);
                _modifiedEngineBaseIsp = baseISP * PluginHelper.ElectricEngineIspMult;
                _hasrequiredupgrade    = this.HasTechsRequiredToUpgrade();

                if (_hasrequiredupgrade && (isupgraded || state == StartState.Editor))
                {
                    upgradePartModule();
                }

                UpdateEngineTypeString();

                resourceBuffers = new ResourceBuffers();
                resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_WASTEHEAT, wasteHeatMultiplier, 2.0e+4, true));
                resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_WASTEHEAT, this.part.mass);
                resourceBuffers.Init(this.part);

                // initialize propellant
                _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);
                SetupPropellants(true);
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI] - Error OnStart ElectricEngineControllerFX " + e.Message);
            }
            Debug.Log("[KSPI] - End Initializing ElectricEngineControllerFX");
        }
Ejemplo n.º 14
0
        public override void OnStart(PartModule.StartState state)
        {
            definitionMegajoule = PartResourceLibrary.Instance.GetDefinition(ResourceManager.FNRESOURCE_MEGAJOULES);

            try
            {
                attachedRCS = this.part.FindModuleImplementing <ModuleRCSFX>();

                // old legacy stuff
                if (baseThrust == 0 && maxThrust > 0)
                {
                    baseThrust = maxThrust;
                }

                if (partMass == 0)
                {
                    partMass = part.mass;
                }

                if (String.IsNullOrEmpty(displayName))
                {
                    displayName = part.partInfo.title;
                }

                String[] resources_to_supply = { ResourceManager.FNRESOURCE_WASTEHEAT };
                this.resources_to_supply = resources_to_supply;

                oldPowerEnabled = powerEnabled;
                efficiencyStr   = (efficiency * 100).ToString() + "%";

                if (!String.IsNullOrEmpty(AnimationName))
                {
                    rcsStates = PluginHelper.SetUpAnimation(AnimationName, this.part);
                }

                // initialize propellant
                _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);

                delayedVerificationPropellant = true;
                // find correct fuel mode index
                if (!String.IsNullOrEmpty(fuel_mode_name))
                {
                    Debug.Log("[KSPI]: ElectricRCSController OnStart loaded fuelmode " + fuel_mode_name);
                    Current_propellant = _propellants.FirstOrDefault(p => p.PropellantName == fuel_mode_name);
                }
                if (Current_propellant != null && _propellants.Contains(Current_propellant))
                {
                    fuel_mode = _propellants.IndexOf(Current_propellant);
                    Debug.Log("[KSPI]: ElectricRCSController OnStart index of fuelmode " + Current_propellant.PropellantGUIName + " = " + fuel_mode);
                }

                base.OnStart(state);

                Fields["electricalPowerConsumptionStr"].guiActive = showConsumption;

                maxStoredPower = bufferMult * maxThrust * maxIsp * 9.81 / efficiency / 1000;
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI]: ElectricRCSController OnStart Error: " + e.Message);
                throw;
            }
        }
        public override void OnStart(PartModule.StartState state)
        {
            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT };
            _attached_engine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;
            this.resources_to_supply = resources_to_supply;
            _propellants = getPropellants();
            base.OnStart(state);

            if (state == StartState.Editor)
            {
                if (this.HasTechsRequiredToUpgrade())
                {
                    upgradePartModule();
                }
                return;
            }

            if (this.HasTechsRequiredToUpgrade())
            {
                _hasrequiredupgrade = true;
            }

            if (_attached_engine != null)
            {
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";
            }

            fuel_gauge = part.stackIcon.DisplayInfo();
            _current_propellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.FirstOrDefault();
            setupPropellants();
        }
 protected void togglePropellants()
 {
     fuel_mode++;
     if (fuel_mode >= _propellants.Count)
     {
         fuel_mode = 0;
     }
     _current_propellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.FirstOrDefault();
     setupPropellants();
 }
        public override void OnStart(PartModule.StartState state)
        {
            try
            {
                attachedRCS = this.part.FindModuleImplementing<ModuleRCS>();
                attachedModuleRCSFX = attachedRCS as FNModuleRCSFX;

                if (!isInitialised)
                {
                    if (attachedModuleRCSFX != null)
                    {
                        useLeverEnabled = attachedModuleRCSFX.useLever;
                        precisionFactorLimiter = attachedModuleRCSFX.precisionFactor * 100;
                        fullThrustMinLimiter = attachedModuleRCSFX.fullThrustMin * 100;
                        fullThrustEnabled = attachedModuleRCSFX.fullThrust;
                        useThrotleEnabled = attachedModuleRCSFX.useThrottle;
                    }
                }

                if (attachedModuleRCSFX != null)
                {
                    attachedModuleRCSFX.Fields["RCS"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableYaw"].guiActive = true;
                    attachedModuleRCSFX.Fields["enablePitch"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableRoll"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableX"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableY"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableZ"].guiActive = true;
                    attachedModuleRCSFX.fullThrust = fullThrustEnabled;
                    attachedModuleRCSFX.fullThrustMin = fullThrustMinLimiter / 100;
                    attachedModuleRCSFX.useLever = useLeverEnabled;
                    attachedModuleRCSFX.precisionFactor = precisionFactorLimiter / 100;
                }

                // old legacy stuff
                if (baseThrust == 0 && maxThrust > 0)
                    baseThrust = maxThrust;

                if (partMass == 0)
                    partMass = part.mass;

                if (String.IsNullOrEmpty(displayName))
                    displayName = part.partInfo.title;

                String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT };
                this.resources_to_supply = resources_to_supply;

                oldThrustLimiter = thrustLimiter;
                oldPowerEnabled = powerEnabled;
                efficencyModifier = (float)g0 * 0.5f / 1000.0f / efficency;
                efficencyStr = (efficency * 100).ToString() + "%";

                if (!String.IsNullOrEmpty(AnimationName))
                    rcsStates = SetUpAnimation(AnimationName, this.part);

                // initialize propellant
                _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);

                delayedVerificationPropellant = true;
                // find correct fuel mode index
                if (!String.IsNullOrEmpty(fuel_mode_name))
                {
                    Debug.Log("ElectricRCSController OnStart loaded fuelmode " + fuel_mode_name);
                    Current_propellant = _propellants.FirstOrDefault(p => p.PropellantName == fuel_mode_name);
                }
                if (Current_propellant != null && _propellants.Contains(Current_propellant))
                {
                    fuel_mode = _propellants.IndexOf(Current_propellant);
                    Debug.Log("ElectricRCSController OnStart index of fuelmode " + Current_propellant.PropellantGUIName + " = " + fuel_mode);
                }

                base.OnStart(state);

                Fields["electricalPowerConsumptionStr"].guiActive = showConsumption;
            }
            catch (Exception e)
            {
                Debug.LogError("ElectricRCSController OnStart Error: " + e.Message);
                throw;
            }
        }
        public override void OnStart(PartModule.StartState state)
        {
            definitionMegajoule = PartResourceLibrary.Instance.GetDefinition(ResourceManager.FNRESOURCE_MEGAJOULES);

            try
            {
                attachedRCS         = this.part.FindModuleImplementing <ModuleRCS>();
                attachedModuleRCSFX = attachedRCS as FNModuleRCSFX;

                if (!isInitialised)
                {
                    precisionFactorLimiter = attachedRCS.precisionFactor * 100;
                    fullThrustMinLimiter   = attachedRCS.fullThrustMin * 100;
                    useThrotleEnabled      = attachedRCS.useThrottle;
                    fullThrustEnabled      = attachedRCS.fullThrust;
                    useLeverEnabled        = attachedRCS.useLever;
                }

                if (attachedModuleRCSFX != null)
                {
                    attachedModuleRCSFX.Fields["RCS"].guiActive         = true;
                    attachedModuleRCSFX.Fields["enableYaw"].guiActive   = true;
                    attachedModuleRCSFX.Fields["enablePitch"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableRoll"].guiActive  = true;
                    attachedModuleRCSFX.Fields["enableX"].guiActive     = true;
                    attachedModuleRCSFX.Fields["enableY"].guiActive     = true;
                    attachedModuleRCSFX.Fields["enableZ"].guiActive     = true;
                }

                attachedRCS.precisionFactor = precisionFactorLimiter / 100;
                attachedRCS.fullThrustMin   = fullThrustMinLimiter / 100;
                attachedRCS.useThrottle     = useThrotleEnabled;
                attachedRCS.fullThrust      = fullThrustEnabled;
                attachedRCS.useLever        = useLeverEnabled;

                // old legacy stuff
                if (baseThrust == 0 && maxThrust > 0)
                {
                    baseThrust = maxThrust;
                }

                if (partMass == 0)
                {
                    partMass = part.mass;
                }

                if (String.IsNullOrEmpty(displayName))
                {
                    displayName = part.partInfo.title;
                }

                String[] resources_to_supply = { ResourceManager.FNRESOURCE_WASTEHEAT };
                this.resources_to_supply = resources_to_supply;

                oldThrustLimiter = thrustLimiter;
                oldPowerEnabled  = powerEnabled;
                //efficiencyModifier = g0 * 0.5 / 1000 / efficiency;
                efficiencyStr = (efficiency * 100).ToString() + "%";

                if (!String.IsNullOrEmpty(AnimationName))
                {
                    rcsStates = SetUpAnimation(AnimationName, this.part);
                }

                // initialize propellant
                _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);

                delayedVerificationPropellant = true;
                // find correct fuel mode index
                if (!String.IsNullOrEmpty(fuel_mode_name))
                {
                    Debug.Log("[KSPI] - ElectricRCSController OnStart loaded fuelmode " + fuel_mode_name);
                    Current_propellant = _propellants.FirstOrDefault(p => p.PropellantName == fuel_mode_name);
                }
                if (Current_propellant != null && _propellants.Contains(Current_propellant))
                {
                    fuel_mode = _propellants.IndexOf(Current_propellant);
                    Debug.Log("[KSPI] - ElectricRCSController OnStart index of fuelmode " + Current_propellant.PropellantGUIName + " = " + fuel_mode);
                }

                base.OnStart(state);

                Fields["electricalPowerConsumptionStr"].guiActive = showConsumption;
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI] - ElectricRCSController OnStart Error: " + e.Message);
                throw;
            }
        }
        private void SetupPropellants(bool moveNext, int maxSwitching)
        {
            Current_propellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.FirstOrDefault();
            if ((Current_propellant.SupportedEngines & type) != type)
            {
                SwitchPropellant(moveNext, --maxSwitching);
                return;
            }
            Propellant new_propellant = Current_propellant.Propellant;

            if (HighLogic.LoadedSceneIsFlight)
            {
                // you can have any fuel you want in the editor but not in flight
                List<PartResource> totalpartresources = part.GetConnectedResources(new_propellant.name).ToList();

                if (!totalpartresources.Any() && maxSwitching > 0)
                {
                    SwitchPropellant(moveNext, --maxSwitching);
                    return;
                }
            }

            if (PartResourceLibrary.Instance.GetDefinition(new_propellant.name) != null)
            {
                currentThrustMultiplier = hasSufficientPower ? Current_propellant.ThrustMultiplier : Current_propellant.ThrustMultiplierCold;

                var moduleConfig = new ConfigNode("MODULE");
                moduleConfig.AddValue("name", "ModuleRCSFX");
                moduleConfig.AddValue("thrusterPower", ((thrustLimiter / 100) * currentThrustMultiplier * baseThrust / Current_propellant.IspMultiplier).ToString("0.000"));
                moduleConfig.AddValue("resourceName", new_propellant.name);
                moduleConfig.AddValue("resourceFlowMode", "STAGE_PRIORITY_FLOW");

                maxPropellantIsp = (hasSufficientPower ? maxIsp : minIsp) * Current_propellant.IspMultiplier * currentThrustMultiplier;

                var atmosphereCurve = new ConfigNode("atmosphereCurve");
                atmosphereCurve.AddValue("key", "0 " + (maxPropellantIsp).ToString("0.000"));
                atmosphereCurve.AddValue("key", "1 " + (maxPropellantIsp * 0.5).ToString("0.000"));
                atmosphereCurve.AddValue("key", "4 " + (maxPropellantIsp * 0.00001).ToString("0.000"));
                moduleConfig.AddNode(atmosphereCurve);

                attachedRCS.Load(moduleConfig);
            }
            else if (maxSwitching > 0)
            {
                SwitchPropellant(moveNext, --maxSwitching);
                return;
            }
        }