Example #1
0
        public override void OnStart(PartModule.StartState state)
        {
            enabled = true;

            // compensate for stock solar initialisation heating issies
            part.temperature = storedTemp;
            requiresPower    = powerReqKW > 0;

            isDisabledField          = Fields["isDisabled"];
            boiloffStrField          = Fields["boiloffStr"];
            powerStatusStrField      = Fields["powerStatusStr"];
            externalTemperatureField = Fields["externalTemperature"];

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

            part.temperature     = storedTemp;
            part.skinTemperature = storedTemp;

            // if electricCharge buffer is missing, add it.
            if (!part.Resources.Contains(InterstellarResourcesConfiguration.Instance.ElectricCharge))
            {
                ConfigNode node = new ConfigNode("RESOURCE");
                node.AddValue("name", InterstellarResourcesConfiguration.Instance.ElectricCharge);
                node.AddValue("maxAmount", powerReqKW > 0 ? powerReqKW / 50 : 1);
                node.AddValue("amount", powerReqKW > 0  ? powerReqKW / 50 : 1);
                part.AddResource(node);
            }

            resourceBuffers = new ResourceBuffers();
            resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(InterstellarResourcesConfiguration.Instance.ElectricCharge, 2));
            resourceBuffers.Init(this.part);
        }
Example #2
0
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                return;                             // don't do any of this stuff in editor
            }
            _moduleResourceIntake = this.part.FindModuleImplementing <ModuleResourceIntake>();

            if (_moduleResourceIntake == null)
            {
                return;
            }

            bool hasJetUpgradeTech0 = PluginHelper.HasTechRequirementOrEmpty(PluginHelper.JetUpgradeTech1);
            bool hasJetUpgradeTech1 = PluginHelper.HasTechRequirementOrEmpty(PluginHelper.JetUpgradeTech2);
            bool hasJetUpgradeTech2 = PluginHelper.HasTechRequirementOrEmpty(PluginHelper.JetUpgradeTech3);
            bool hasJetUpgradeTech3 = PluginHelper.HasTechRequirementOrEmpty(PluginHelper.JetUpgradeTech4);

            var jetTechBonus = Convert.ToInt32(hasJetUpgradeTech0) + 1.2f * Convert.ToInt32(hasJetUpgradeTech1) + 1.44f * Convert.ToInt32(hasJetUpgradeTech2) + 1.728f * Convert.ToInt32(hasJetUpgradeTech3);

            jetTechBonusPercentage = 10 * (1 + (jetTechBonus / 10.736f));

            area = _moduleResourceIntake.area;
            intakeTransformName = _moduleResourceIntake.intakeTransformName;
            unitScalar          = _moduleResourceIntake.unitScalar;

            resourceBuffers = new ResourceBuffers();
            resourceBuffers.AddConfiguration(
                new ResourceBuffers.TimeBasedConfig(InterstellarResourcesConfiguration.Instance.IntakeAtmosphere, 300, area * unitScalar * jetTechBonusPercentage * maxIntakeSpeed));
            resourceBuffers.Init(this.part);

            _resourceAtmosphere = PartResourceLibrary.Instance.GetDefinition(InterstellarResourcesConfiguration.Instance.IntakeAtmosphere);
            _intake_speed       = maxIntakeSpeed;
        }
Example #3
0
 public override void OnStart(PartModule.StartState state)
 {
     _resourceBuffers = new ResourceBuffers();
     _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_WASTEHEAT, wasteHeatMultiplier, baseResourceAmount * wasteHeatBufferMult, true));
     _resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_WASTEHEAT, this.part.mass);
     _resourceBuffers.Init(this.part);
 }
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            megaJouleSolarPowerSupplyField = Fields["megaJouleSolarPowerSupply"];
            solarMaxSupplyField            = Fields["solarMaxSupply"];

            // calculate Astronomical unit on homeworld semiMajorAxis when missing
            if (astronomicalUnit == 0)
            {
                astronomicalUnit = FlightGlobals.GetHomeBody().orbit.semiMajorAxis;
            }

            _microwavePowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();

            _solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>();
            if (_solarPanel == null)
            {
                return;
            }

            if (this.part.FindModuleImplementing <ModuleJettison>() == null)
            {
                UnityEngine.Debug.Log("[KSPI]: FNSolarPanelWasteHeatModule Force Activated  " + part.name);
                part.force_activate();
            }

            String[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES };
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);

            if (_solarPanel.resourceName == ResourceManager.FNRESOURCE_MEGAJOULES)
            {
                _outputType = ResourceType.megajoule;
            }
            else if (_solarPanel.resourceName == ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE)
            {
                _outputType = ResourceType.electricCharge;
            }
            else
            {
                _outputType = ResourceType.other;
            }

            // only manage power buffer when microwave receiver is not available
            if (_outputType != ResourceType.other && _microwavePowerReceiver == null)
            {
                _resourceBuffers = new ResourceBuffers();
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_MEGAJOULES));
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE));
                _resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_MEGAJOULES, (double)(decimal)(_outputType == ResourceType.electricCharge ? _solarPanel.chargeRate * 0.001f : _solarPanel.chargeRate));
                _resourceBuffers.UpdateVariable(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE, (double)(decimal)(_outputType == ResourceType.electricCharge ? _solarPanel.chargeRate : _solarPanel.chargeRate * 1000));
                _resourceBuffers.Init(part);
            }

            _stars = KopernicusHelper.Stars;
        }
 public override void OnStart(PartModule.StartState state)
 {
     _resourceBuffers = new ResourceBuffers();
     _resourceBuffers.AddConfiguration(new WasteHeatBufferConfig(wasteHeatMultiplier, baseResourceAmount * wasteHeatBufferMult, true));
     _resourceBuffers.UpdateVariable(ResourceSettings.Config.WasteHeatInMegawatt, this.part.mass);
     _resourceBuffers.Init(this.part);
 }
        public override void OnStart(PartModule.StartState state)
        {
            try
            {
                if (state == StartState.Editor)
                {
                    return;
                }

                microwavePowerReceiver = part.FindModuleImplementing <MicrowavePowerReceiver>();
                if (microwavePowerReceiver != null)
                {
                    Fields["megaJouleSolarPowerSupply"].guiActive = false;
                    return;
                }

                if (part.Modules.Contains("WarpFixer"))
                {
                    warpfixer = part.Modules["WarpFixer"];
                    _field_kerbalism_output = warpfixer.Fields["field_output"];
                }

                part.force_activate();

                String[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES };
                this.resources_to_supply = resources_to_supply;
                base.OnStart(state);

                solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>();

                if (solarPanel == null)
                {
                    return;
                }

                resourceBuffers = new ResourceBuffers();
                if (solarPanel.resourceName == ResourceManager.FNRESOURCE_MEGAJOULES)
                {
                    resourceBuffers.AddConfiguration(new ResourceBuffers.MaxAmountConfig(ResourceManager.FNRESOURCE_MEGAJOULES, 50));
                    outputType = resourceType.megajoule;
                }
                else if (solarPanel.resourceName == ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE)
                {
                    resourceBuffers.AddConfiguration(new ResourceBuffers.MaxAmountConfig(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE, 50));
                    outputType = resourceType.electricCharge;
                }
                else
                {
                    outputType = resourceType.other;
                }

                resourceBuffers.Init(this.part);
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI] - Exception in FNSolarPanelWasteHeatModule.OnStart " + e.Message);
                throw;
            }
        }
Example #7
0
        public override void OnStart(StartState state)
        {
            try
            {
                if (state == StartState.Editor)
                {
                    return;
                }

                moduleGenerator = part.FindModuleImplementing <ModuleGenerator>();

                if (moduleGenerator == null)
                {
                    return;
                }

                String[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES };
                this.resources_to_supply = resources_to_supply;
                base.OnStart(state);


                resourceBuffers = new ResourceBuffers();
                outputType      = resourceType.other;
                foreach (ModuleResource moduleResource in moduleGenerator.resHandler.outputResources)
                {
                    // assuming only one of those two is present
                    if (moduleResource.name == ResourceManager.FNRESOURCE_MEGAJOULES)
                    {
                        outputType = resourceType.megajoule;
                        resourceBuffers.AddConfiguration(new ResourceBuffers.MaxAmountConfig(ResourceManager.FNRESOURCE_MEGAJOULES, 50));

                        mockInputResource      = new ModuleResource();
                        mockInputResource.name = moduleResource.name;
                        mockInputResource.id   = moduleResource.name.GetHashCode();
                        moduleGenerator.resHandler.inputResources.Add(mockInputResource);
                        moduleOutputResource = moduleResource;
                        break;
                    }
                    if (moduleResource.name == ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE)
                    {
                        outputType = resourceType.electricCharge;
                        resourceBuffers.AddConfiguration(new ResourceBuffers.MaxAmountConfig(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE, 50));

                        mockInputResource      = new ModuleResource();
                        mockInputResource.name = moduleResource.name;
                        mockInputResource.id   = moduleResource.name.GetHashCode();
                        moduleGenerator.resHandler.inputResources.Add(mockInputResource);
                        moduleOutputResource = moduleResource;
                        break;
                    }
                }
                resourceBuffers.Init(this.part);
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI] - Exception in FNGeneratorAdapter.OnStart " + e.Message);
                throw;
            }
        }
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            // calculate Astronomical unit on homeworld semiMajorAxis when missing
            if (astronomicalUnit == 0)
            {
                astronomicalUnit = FlightGlobals.GetHomeBody().orbit.semiMajorAxis;
            }

            _microwavePowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();

            _solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>();
            if (_solarPanel == null)
            {
                return;
            }

            part.force_activate();

            String[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES };
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);

            if (_solarPanel.resourceName == ResourceManager.FNRESOURCE_MEGAJOULES)
            {
                outputType = ResourceType.megajoule;
            }
            else if (_solarPanel.resourceName == ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE)
            {
                outputType = ResourceType.electricCharge;
            }
            else
            {
                outputType = ResourceType.other;
            }

            mockInputResource      = new ModuleResource();
            mockInputResource.name = _solarPanel.resourceName;
            mockInputResource.id   = _solarPanel.resourceName.GetHashCode();
            _solarPanel.resHandler.inputResources.Add(mockInputResource);

            // only manager power buffer when microwave receiver is not available
            if (outputType != ResourceType.other && _microwavePowerReceiver == null)
            {
                _resourceBuffers = new ResourceBuffers();
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_MEGAJOULES));
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE));
                _resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_MEGAJOULES, (double)(decimal)(outputType == ResourceType.electricCharge ? _solarPanel.chargeRate * 0.001f : _solarPanel.chargeRate));
                _resourceBuffers.UpdateVariable(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE, (double)(decimal)(outputType == ResourceType.electricCharge ? _solarPanel.chargeRate : _solarPanel.chargeRate * 1000));
                _resourceBuffers.Init(this.part);
            }

            stars = KopernicusHelper.Stars;
        }
Example #9
0
        public override void OnStart(StartState state)
        {
            if (state.ToString().Contains(StartState.PreLaunch.ToString()))
            {
                Debug.Log("[KSPI]: PreLaunch uses InitialGearRatio:" + InitialGearRatio);
                SelectedIsp = ((MaxIsp - MinIsp) * Math.Max(0, Math.Min(1, InitialGearRatio))) + MinIsp;
            }

            Fields[nameof(selectedFuel)].guiName = fuelSwitchName;

            Fields[nameof(currentMaximumPowerRequirement)].guiActive = powerRequirement > 0;
            Fields[nameof(laserWasteheat)].guiActive    = powerRequirement > 0 && fusionWasteHeat > 0;
            Fields[nameof(absorbedWasteheat)].guiActive = powerRequirement > 0 && fusionWasteHeat > 0;
            Fields[nameof(fusionRatio)].guiActive       = powerRequirement > 0;

            Fields[nameof(powerRequirementMax)].guiActiveEditor = powerRequirement > 0;
            Fields[nameof(fusionWasteHeatMax)].guiActiveEditor  = fusionWasteHeat > 0;

            part.maxTemp             = maxTemp;
            part.thermalMass         = 1;
            part.thermalMassModifier = 1;

            curEngineT = part.FindModuleImplementing <ModuleEngines>();
            if (curEngineT == null)
            {
                Debug.LogError("[KSPI]: FusionEngine OnStart Engine not found");
                return;
            }
            BaseFloatCurve = curEngineT.atmosphereCurve;

            curveMaxISP = GetMaxKey(BaseFloatCurve);
            if (hasMultipleConfigurations)
            {
                FcSetup();
            }

            InitializeKerbalismEmitter();

            DetermineTechLevel();
            powerRequirementMax = PowerRequirementMaximum;
            fusionWasteHeatMax  = FusionWasteHeat;

            resourceBuffers = new ResourceBuffers();
            resourceBuffers.AddConfiguration(new WasteHeatBufferConfig(wasteHeatMultiplier, 1.0e+4, true));
            resourceBuffers.UpdateVariable(ResourceSettings.Config.WasteHeatInMegawatt, this.part.mass);
            resourceBuffers.Init(this.part);

            if (state != StartState.Editor)
            {
                part.emissiveConstant = maxTempatureRadiators > 0 ? 1 - coldBathTemp / maxTempatureRadiators : 0.01;
            }

            base.OnStart(state);

            Fields["localIsp"].guiActive       = selectableIsp;
            Fields["localIsp"].guiActiveEditor = selectableIsp;
        }
        public override void OnStart(PartModule.StartState state)
        {
            if (maintainsPropellantBuffer)
            {
                propellantBufferResourceDefinition = PartResourceLibrary.Instance.GetDefinition(propellantBufferResourceName);
            }

            resourceBuffers = new ResourceBuffers();
            resourceBuffers.AddConfiguration(new WasteHeatBufferConfig(wasteHeatMultiplier, 1.0e+6, true));
            resourceBuffers.UpdateVariable(ResourceSettings.Config.WasteHeatInMegawatt, this.part.mass);
            resourceBuffers.Init(this.part);

            _attached_warpable_engine = this.part.FindModuleImplementing <ModuleEnginesWarp>();
            _attached_engine          = _attached_warpable_engine;

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

            ConnectToReactor();

            UpdateEngineStats(true);

            max_power_multiplier = Math.Log10(maximum_isp / minimum_isp);

            throtleExponent = Math.Abs(Math.Log10(_attached_reactor.MinimumChargdIspMult / _attached_reactor.MaximumChargedIspMult));

            simulatedThrottleFloatRange = Fields["simulatedThrottle"].uiControlEditor as UI_FloatRange;
            simulatedThrottleFloatRange.onFieldChanged += UpdateFromGUI;

            if (_attached_reactor == null)
            {
                Debug.LogWarning("[KSPI]: InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!");
                return;
            }
            exchanger_thrust_divisor = radius >= _attached_reactor.Radius ? 1 : radius * radius / _attached_reactor.Radius / _attached_reactor.Radius;

            InitializesPropellantBuffer();

            if (_attached_engine != null && _attached_engine is ModuleEnginesFX)
            {
                if (!String.IsNullOrEmpty(runningEffectName))
                {
                    part.Effect(runningEffectName, 0, -1);
                }
                if (!String.IsNullOrEmpty(powerEffectName))
                {
                    part.Effect(powerEffectName, 0, -1);
                }
            }

            Fields["partMass"].guiActiveEditor = showPartMass;
            Fields["partMass"].guiActive       = showPartMass;
        }
Example #11
0
        public override void OnStart(PartModule.StartState state)
        {
            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);

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

            _attached_warpable_engine = this.part.FindModuleImplementing <ModuleEnginesWarp>();
            _attached_engine          = _attached_warpable_engine;

            if (_attached_engine != null)
            {
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";
            }
            else
            {
                Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no ModuleEnginesFX found for MagneticNozzle!");
            }

            // first try to look in part
            _attached_reactor = this.part.FindModuleImplementing <IChargedParticleSource>();

            // try to find nearest
            if (_attached_reactor == null)
            {
                _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1);
            }

            if (_attached_reactor == null)
            {
                Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!");
                return;
            }

            double joules_per_amu = _attached_reactor.CurrentMeVPerChargedProduct * 1e6 * GameConstants.ELECTRON_CHARGE / GameConstants.dilution_factor;

            calculatedIsp = Math.Sqrt(joules_per_amu * 2.0 / GameConstants.ATOMIC_MASS_UNIT) / PluginHelper.GravityConstant;

            minimum_isp          = calculatedIsp * _attached_reactor.MinimumChargdIspMult;
            maximum_isp          = calculatedIsp * _attached_reactor.MaximumChargedIspMult;
            max_power_multiplier = Math.Log10(maximum_isp / minimum_isp);

            throtleExponent = Math.Abs(Math.Log10(_attached_reactor.MinimumChargdIspMult / _attached_reactor.MaximumChargedIspMult));

            exchanger_thrust_divisor = radius > _attached_reactor.Radius
                ? _attached_reactor.Radius * _attached_reactor.Radius / radius / radius
                : radius * radius / _attached_reactor.Radius / _attached_reactor.Radius;
        }
        public override void OnStart(PartModule.StartState state)
        {
            enabled = true;

            // compensate for stock solar initialization heating issues
            part.temperature = storedTemp;
            requiresPower    = powerReqKW > 0;

            isDisabledField                   = Fields[nameof(isDisabled)];
            boiloffStrField                   = Fields[nameof(boiloffStr)];
            powerStatusStrField               = Fields[nameof(powerStatusStr)];
            externalTemperatureField          = Fields[nameof(externalTemperature)];
            maintainElectricChargeBufferField = Fields[nameof(maintainElectricChargeBuffer)];

            if (state == StartState.Editor)
            {
                if (!autoConfigElectricChargeBuffer)
                {
                    return;
                }

                var exitingElectricCharge = part.Resources[ResourceSettings.Config.ElectricPowerInKilowatt];

                bool hasHigherThanDefaultBuffer = exitingElectricCharge != null && exitingElectricCharge.maxAmount > powerReqKW / 50;

                //Debug.Log("[KSPI]: FNModuleCryostat: hasHigherThanDefaultBuffer: " + hasHigherThanDefaultBuffer);

                maintainElectricChargeBuffer   = hasHigherThanDefaultBuffer.IsFalse();
                autoConfigElectricChargeBuffer = false;
                return;
            }

            part.temperature     = storedTemp;
            part.skinTemperature = storedTemp;

            // if electricCharge buffer is missing, add it.
            if (!part.Resources.Contains(ResourceSettings.Config.ElectricPowerInKilowatt))
            {
                var node = new ConfigNode("RESOURCE");
                node.AddValue("name", ResourceSettings.Config.ElectricPowerInKilowatt);
                node.AddValue("maxAmount", requiresPower ? powerReqKW / 50 : 1);
                node.AddValue("amount", requiresPower ? powerReqKW / 50 : 1);
                part.AddResource(node);
            }

            if (maintainElectricChargeBuffer)
            {
                resourceBuffers = new ResourceBuffers();
                resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceSettings.Config.ElectricPowerInKilowatt, 2));
                resourceBuffers.Init(this.part);
            }
        }
Example #13
0
        public override void OnStart(PartModule.StartState state)
        {
            try
            {
                if (state.ToString().Contains(StartState.PreLaunch.ToString()))
                {
                    Debug.Log("[KSPI] - PreLaunch uses InitialGearRatio:" + InitialGearRatio);
                    SelectedIsp = ((MaxIsp - MinIsp) * Math.Max(0, Math.Min(1, InitialGearRatio))) + MinIsp;
                }

                Fields["selectedFuel"].guiName = "Fusion Type";

                part.maxTemp             = maxTemp;
                part.thermalMass         = 1;
                part.thermalMassModifier = 1;

                curEngineT = this.part.FindModuleImplementing <ModuleEngines>();
                if (curEngineT == null)
                {
                    Debug.LogError("[KSPI] - FusionEngine OnStart Engine not found");
                    return;
                }
                BaseFloatCurve = curEngineT.atmosphereCurve;

                curveMaxISP = GetMaxKey(BaseFloatCurve);
                if (hasMultipleConfigurations)
                {
                    FcSetup();
                }

                standard_deuterium_rate = GetRatio(InterstellarResourcesConfiguration.Instance.LqdDeuterium);
                standard_tritium_rate   = GetRatio(InterstellarResourcesConfiguration.Instance.LqdTritium);

                DetermineTechLevel();

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

                if (state != StartState.Editor)
                {
                    part.emissiveConstant = maxTempatureRadiators > 0 ? 1 - coldBathTemp / maxTempatureRadiators : 0.01;
                }

                base.OnStart(state);
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI] - FusionEngine OnStart eception: " + e.Message);
            }
        }
        public override void OnStart(PartModule.StartState state)
        {
            displayName = part.partInfo.title;

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

            resourceBuffers = new ResourceBuffers();
            resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig("Megajoules"));
            resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig("ElectricCharge", 1000));
            resourceBuffers.Init(this.part);

            this.part.force_activate();
        }
Example #15
0
        public override void OnStart(PartModule.StartState state)
        {
            ScaleParameters();

            _initializationCountdown = 10;
            Debug.Log("[KSPI] - Start Initializing ElectricEngineControllerFX");
            try
            {
                // initialise resources
                this.resources_to_supply = new [] { ResourceManager.FNRESOURCE_WASTEHEAT };
                base.OnStart(state);

                AttachToEngine();
                DetermineTechLevel();
                powerCapacityModifier = PowerCapacityModifier;

                _ispFloatCurve = new FloatCurve();
                _ispFloatCurve.Add(0, (float)baseISP);
                _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, (double)(decimal)this.part.mass);
                resourceBuffers.Init(this.part);

                InitializePropellantMode();

                SetupPropellants(true);

                _attachedEngine.maxThrust = (float)maxThrustInSpace;
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI] - Error OnStart ElectricEngineControllerFX " + e.Message);
            }
            Debug.Log("[KSPI] - End Initializing ElectricEngineControllerFX");
        }
        public override void OnStart(PartModule.StartState state)
        {
            part.maxTemp             = maxTemp;
            part.thermalMass         = 1;
            part.thermalMassModifier = 1;

            engineType = originalName;
            //curEngineT = (ModuleEnginesFX)this.part.Modules["ModuleEnginesFX"];
            curEngineT = this.part.FindModuleImplementing <ModuleEngines>();

            if (curEngineT == null)
            {
                return;
            }

            minISP = curEngineT.atmosphereCurve.Evaluate(0);
            //currentHeatProduction = curEngineT.heatProduction;

            standard_deuterium_rate = curEngineT.propellants.FirstOrDefault(pr => pr.name == InterstellarResourcesConfiguration.Instance.LqdDeuterium).ratio;
            standard_tritium_rate   = curEngineT.propellants.FirstOrDefault(pr => pr.name == InterstellarResourcesConfiguration.Instance.LqdTritium).ratio;

            // if we can upgrade, let's do so
            if (isupgraded)
            {
                upgradePartModule();
            }
            else if (this.HasTechsRequiredToUpgrade())
            {
                hasrequiredupgrade = true;
            }

            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);

            if (state == StartState.Editor && this.HasTechsRequiredToUpgrade())
            {
                isupgraded = true;
                upgradePartModule();
            }

            if (state != StartState.Editor)
            {
                part.emissiveConstant = maxTempatureRadiators > 0 ? 1 - coldBathTemp / maxTempatureRadiators : 0.01;
            }
        }
Example #17
0
        public override void OnStart(PartModule.StartState state)
        {
            displayName = part.partInfo.title;

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

            resourceBuffers = new ResourceBuffers();
            resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig("Megajoules"));
            resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig("ElectricCharge", 1000));
            resourceBuffers.Init(this.part);

            UnityEngine.Debug.Log("[KSPI]: GenericPowerSupply on " + part.name + " was Force Activated");
            this.part.force_activate();
        }
        public override void OnStart(PartModule.StartState state)
        {
            Debug.Log("[KSPI]: AtmosphericIntake OnStart Reading PluginHelper Upgrades");

            JetUpgradeTech1 = PluginHelper.JetUpgradeTech1;
            JetUpgradeTech2 = PluginHelper.JetUpgradeTech2;
            JetUpgradeTech3 = PluginHelper.JetUpgradeTech3;
            JetUpgradeTech4 = PluginHelper.JetUpgradeTech4;
            JetUpgradeTech5 = PluginHelper.JetUpgradeTech5;

            hasJetUpgradeTech1 = PluginHelper.HasTechRequirementOrEmpty(PluginHelper.JetUpgradeTech1);
            hasJetUpgradeTech2 = PluginHelper.HasTechRequirementOrEmpty(PluginHelper.JetUpgradeTech2);
            hasJetUpgradeTech3 = PluginHelper.HasTechRequirementOrEmpty(PluginHelper.JetUpgradeTech3);
            hasJetUpgradeTech4 = PluginHelper.HasTechRequirementOrEmpty(PluginHelper.JetUpgradeTech4);
            hasJetUpgradeTech5 = PluginHelper.HasTechRequirementOrEmpty(PluginHelper.JetUpgradeTech5);

            var jetTech = Convert.ToInt32(hasJetUpgradeTech1) * 1.2f + 1.44f * Convert.ToInt32(hasJetUpgradeTech2) + 1.728f * Convert.ToInt32(hasJetUpgradeTech3) + 2.0736f * Convert.ToInt32(hasJetUpgradeTech4) + 2.48832f * Convert.ToInt32(hasJetUpgradeTech5);

            jetTechBonus = 5 * (1 + (jetTech / 9.92992f));

            _moduleResourceIntake         = this.part.FindModulesImplementing <ModuleResourceIntake>().FirstOrDefault(m => m.resourceName == InterstellarResourcesConfiguration._INTAKE_AIR);
            _resourceAtmosphereDefinition = PartResourceLibrary.Instance.GetDefinition(InterstellarResourcesConfiguration.Instance.IntakeAtmosphere);

            if (_moduleResourceIntake == null)
            {
                Debug.LogWarning("[KSPI]: ModuleResourceIntake with IntakeAir is missing on " + part.partInfo.title);
            }

            var field        = Fields["intakeOpen"];
            var flightToggle = field.uiControlFlight as UI_Toggle;
            var editorToggle = field.uiControlEditor as UI_Toggle;

            flightToggle.onFieldChanged = IntakeOpenChanged;
            editorToggle.onFieldChanged = IntakeOpenChanged;

            UpdateResourceIntakeConfiguration();

            if (state == StartState.Editor)
            {
                return;                             // don't do any of this stuff in editor
            }
            resourceBuffers = new ResourceBuffers();
            resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(InterstellarResourcesConfiguration.Instance.IntakeAtmosphere, 300, area * unitScalar * 100));
            resourceBuffers.Init(this.part);
        }
Example #19
0
        public override void OnStart(PartModule.StartState state)
        {
            displayName = part.partInfo.title;
            String[] resources_to_supply = { ResourceSettings.Config.ElectricPowerInMegawatt };
            this.resources_to_supply = resources_to_supply;

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

            resourceBuffers = new ResourceBuffers();
            resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceSettings.Config.ElectricPowerInMegawatt));
            resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceSettings.Config.ElectricPowerInKilowatt, 1000));
            resourceBuffers.Init(this.part);

            Debug.Log("[KSPI]: PowerSupply on " + part.name + " was Force Activated");
            this.part.force_activate();
        }
Example #20
0
        public override void OnStart(StartState state)
        {
            try
            {
                if (state == StartState.Editor)
                {
                    return;
                }

                if (part.Modules.Contains("FissionGenerator"))
                {
                    moduleGenerator     = part.Modules["FissionGenerator"];
                    _field_status       = moduleGenerator.Fields["Status"];
                    _field_generated    = moduleGenerator.Fields["CurrentGeneration"];
                    _field_addedToTanks = moduleGenerator.Fields["AddedToFuelTanks"];
                    _field_max          = moduleGenerator.Fields["PowerGeneration"];
                }

                if (moduleGenerator == null)
                {
                    return;
                }

                OverallEfficiency = "10%";

                String[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES, ResourceManager.FNRESOURCE_WASTEHEAT };
                this.resources_to_supply = resources_to_supply;
                base.OnStart(state);

                resourceBuffers = new ResourceBuffers();
                resourceBuffers.AddConfiguration(new ResourceBuffers.MaxAmountConfig(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE, 50));
                resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_WASTEHEAT, 1, 2.0e+5, true));
                resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_WASTEHEAT, this.part.mass);
                resourceBuffers.Init(this.part);
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI] - Exception in FNFissionGeneratorAdapter.OnStart " + e.Message);
                throw;
            }
        }
        public override void OnStart(PartModule.StartState state)
        {
            try
            {
                part.maxTemp             = maxTemp;
                part.thermalMass         = 1;
                part.thermalMassModifier = 1;
                EngineGenerationType     = GenerationType.Mk1;

                curEngineT = this.part.FindModuleImplementing <ModuleEngines>();

                if (curEngineT == null)
                {
                    Debug.LogWarning("[KSPI] - FusionEngine OnStart Engine not found");
                    return;
                }

                minISP = curEngineT.atmosphereCurve.Evaluate(0);

                standard_deuterium_rate = curEngineT.propellants.FirstOrDefault(pr => pr.name == InterstellarResourcesConfiguration.Instance.LqdDeuterium).ratio;
                standard_tritium_rate   = curEngineT.propellants.FirstOrDefault(pr => pr.name == InterstellarResourcesConfiguration.Instance.LqdTritium).ratio;

                DetermineTechLevel();

                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);

                if (state != StartState.Editor)
                {
                    part.emissiveConstant = maxTempatureRadiators > 0 ? 1 - coldBathTemp / maxTempatureRadiators : 0.01;
                }
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI] - FusionEngine OnStart eception: " + e.Message);
            }
        }
Example #22
0
        public override void OnStart(StartState state)
        {
            try
            {
                if (state == StartState.Editor)
                {
                    return;
                }

                if (part.Modules.Contains("FissionGenerator"))
                {
                    _moduleGenerator = part.Modules["FissionGenerator"];
                    _fieldStatus     = _moduleGenerator.Fields["Status"];
                    _fieldGenerated  = _moduleGenerator.Fields["CurrentGeneration"];
                    _fieldEfficiency = _moduleGenerator.Fields["Efficiency"];
                    _fieldMax        = _moduleGenerator.Fields["PowerGeneration"];
                }

                if (_moduleGenerator == null)
                {
                    return;
                }

                resources_to_supply = new string[] { ResourceSettings.Config.ElectricPowerInMegawatt, ResourceSettings.Config.WasteHeatInMegawatt };
                base.OnStart(state);

                _resourceBuffers = new ResourceBuffers();
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceSettings.Config.ElectricPowerInMegawatt));
                _resourceBuffers.AddConfiguration(new WasteHeatBufferConfig(wasteHeatMultiplier, 2.0e+5, true));
                _resourceBuffers.UpdateVariable(ResourceSettings.Config.WasteHeatInMegawatt, part.mass);
                _resourceBuffers.Init(part);
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI]: Exception in FNFissionGeneratorAdapter.OnStart " + e.Message);
                throw;
            }
        }
        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();

                _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();

                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");
        }
        public override void OnStart(PartModule.StartState state)
        {
            resourceBuffers = new ResourceBuffers();
            resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_WASTEHEAT, wasteHeatMultiplier, 1.0e+6, true));
            resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_WASTEHEAT, this.part.mass);
            resourceBuffers.Init(this.part);

            _attached_warpable_engine = this.part.FindModuleImplementing <ModuleEnginesWarp>();
            _attached_engine          = _attached_warpable_engine;

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

            ConnectToReactor();

            UpdateEngineStats(true);

            max_power_multiplier = Math.Log10(maximum_isp / minimum_isp);

            throtleExponent = Math.Abs(Math.Log10(_attached_reactor.MinimumChargdIspMult / _attached_reactor.MaximumChargedIspMult));

            simulatedThrottleFloatRange = Fields["simulatedThrottle"].uiControlEditor as UI_FloatRange;
            simulatedThrottleFloatRange.onFieldChanged += UpdateFromGUI;

            Fields["partMass"].guiActiveEditor = showPartMass;

            if (_attached_reactor == null)
            {
                Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!");
                return;
            }
            exchanger_thrust_divisor = radius > _attached_reactor.Radius
                ? _attached_reactor.Radius * _attached_reactor.Radius / radius / radius
                : radius * radius / _attached_reactor.Radius / _attached_reactor.Radius;
        }
        public override void OnStart(StartState state)
        {
            try
            {
                if (state.ToString().Contains(StartState.PreLaunch.ToString()))
                {
                    Debug.Log("[KSPI]: PreLaunch uses InitialGearRatio:" + InitialGearRatio);
                    SelectedIsp = ((MaxIsp - MinIsp) * Math.Max(0, Math.Min(1, InitialGearRatio))) + MinIsp;
                }

                Fields["selectedFuel"].guiName = fuelSwitchName;

                Fields["currentMaximumPowerRequirement"].guiActive = powerRequirement > 0;
                Fields["laserWasteheat"].guiActive    = powerRequirement > 0 && fusionWasteHeat > 0;
                Fields["absorbedWasteheat"].guiActive = powerRequirement > 0 && fusionWasteHeat > 0;
                Fields["fusionRatio"].guiActive       = powerRequirement > 0;

                Fields["powerRequirement"].guiActiveEditor          = powerRequirement > 0;
                Fields["powerRequirementUpgraded1"].guiActiveEditor = powerRequirementUpgraded1 > 0;
                Fields["powerRequirementUpgraded2"].guiActiveEditor = powerRequirementUpgraded2 > 0;
                Fields["powerRequirementUpgraded3"].guiActiveEditor = powerRequirementUpgraded3 > 0;
                Fields["powerRequirementUpgraded4"].guiActiveEditor = powerRequirementUpgraded4 > 0;

                Fields["fusionWasteHeat"].guiActiveEditor          = fusionWasteHeat > 0;
                Fields["fusionWasteHeatUpgraded1"].guiActiveEditor = !String.IsNullOrEmpty(upgradeTechReq1);
                Fields["fusionWasteHeatUpgraded2"].guiActiveEditor = !String.IsNullOrEmpty(upgradeTechReq2);
                Fields["fusionWasteHeatUpgraded3"].guiActiveEditor = !String.IsNullOrEmpty(upgradeTechReq3);
                Fields["fusionWasteHeatUpgraded4"].guiActiveEditor = !String.IsNullOrEmpty(upgradeTechReq4);

                part.maxTemp             = maxTemp;
                part.thermalMass         = 1;
                part.thermalMassModifier = 1;

                curEngineT = this.part.FindModuleImplementing <ModuleEngines>();
                if (curEngineT == null)
                {
                    Debug.LogError("[KSPI]: FusionEngine OnStart Engine not found");
                    return;
                }
                BaseFloatCurve = curEngineT.atmosphereCurve;

                curveMaxISP = GetMaxKey(BaseFloatCurve);
                if (hasMultipleConfigurations)
                {
                    FcSetup();
                }

                InitializeKerbalismEmitter();

                DetermineTechLevel();

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

                if (state != StartState.Editor)
                {
                    part.emissiveConstant = maxTempatureRadiators > 0 ? 1 - coldBathTemp / maxTempatureRadiators : 0.01;
                }

                base.OnStart(state);

                Fields["localIsp"].guiActive       = selectableIsp;
                Fields["localIsp"].guiActiveEditor = selectableIsp;
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI]: FusionEngine OnStart eception: " + e.Message);
            }
        }
Example #26
0
        public override void OnStart(StartState state)
        {
            try
            {
                if (state == StartState.Editor)
                {
                    return;
                }

                var beamedPowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();
                if (beamedPowerReceiver != null)
                {
                    Debug.LogWarning("[KSPI]: disabling FNGeneratorAdapter, found BeamedPowerReceiver");
                    return;
                }

                var generator = part.FindModuleImplementing <FNGenerator>();
                if (generator != null)
                {
                    Debug.LogWarning("[KSPI]: disabling FNGeneratorAdapter, found FNGenerator");
                    return;
                }

                var modules = part.FindModulesImplementing <ModuleGenerator>();

                moduleGenerator = modules.Count > index ? modules[index] : null;

                if (moduleGenerator == null)
                {
                    Debug.LogWarning("[KSPI]: disabling FNGeneratorAdapter, failed to find ModuleGenerator");
                    return;
                }

                string[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES };
                this.resources_to_supply = resources_to_supply;
                base.OnStart(state);

                if (maintainsBuffer)
                {
                    resourceBuffers = new ResourceBuffers();
                }

                outputType = ResourceType.other;
                foreach (ModuleResource moduleResource in moduleGenerator.resHandler.outputResources)
                {
                    if (moduleResource.name != ResourceManager.FNRESOURCE_MEGAJOULES && (moduleResource.name != ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE))
                    {
                        continue;
                    }

                    // assuming only one of those two is present
                    if (moduleResource.name == ResourceManager.FNRESOURCE_MEGAJOULES)
                    {
                        outputType = ResourceType.megajoule;
                    }
                    else
                    {
                        outputType = ResourceType.electricCharge;
                    }

                    if (maintainsBuffer)
                    {
                        resourceBuffers.AddConfiguration(new ResourceBuffers.MaxAmountConfig(moduleResource.name, 50));
                    }

                    mockInputResource      = new ModuleResource();
                    mockInputResource.name = moduleResource.name;
                    mockInputResource.id   = moduleResource.name.GetHashCode();
                    moduleGenerator.resHandler.inputResources.Add(mockInputResource);
                    moduleOutputResource = moduleResource;
                    break;
                }

                if (maintainsBuffer)
                {
                    resourceBuffers.Init(this.part);
                }

                efficiencyField    = moduleGenerator.Fields["efficiency"];
                displayStatusField = moduleGenerator.Fields["displayStatus"];

                efficiencyField.guiActive    = showEfficiency;
                displayStatusField.guiActive = showDisplayStatus;
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI]: Exception in FNGeneratorAdapter.OnStart " + e.Message);
                throw;
            }
        }
Example #27
0
        public override void OnStart(StartState state)
        {
            String[] resourcesToSupply = { ResourceManager.FNRESOURCE_WASTEHEAT };
            this.resources_to_supply = resourcesToSupply;

            base.OnStart(state);

            radiatedThermalPower       = 0;
            convectedThermalPower      = 0;
            CurrentRadiatorTemperature = 0;
            update_count          = 0;
            radiator_deploy_delay = 0;
            explode_counter       = 0;

            DetermineGenerationType();

            maxRadiatorTemperature = (float)MaxRadiatorTemperature;

            if (hasSurfaceAreaUpgradeTechReq)
            {
                part.emissiveConstant = 1.6;
            }

            radiatorType = RadiatorType;

            effectiveRadiatorArea = EffectiveRadiatorArea;

            deployRadiatorEvent  = Events["DeployRadiator"];
            retractRadiatorEvent = Events["RetractRadiator"];

            thermalPowerConvStrField = Fields["thermalPowerConvStr"];
            radiatorIsEnabledField   = Fields["radiatorIsEnabled"];
            isAutomatedField         = Fields["isAutomated"];
            pivotEnabledField        = Fields["pivotEnabled"];

            var preventDeplyField = Fields["preventShieldedDeploy"];

            preventDeplyField.guiActive       = isDeployable;
            preventDeplyField.guiActiveEditor = isDeployable;

            Actions["DeployRadiatorAction"].guiName = Events["DeployRadiator"].guiName = "Deploy Radiator";
            Actions["ToggleRadiatorAction"].guiName = String.Format("Toggle Radiator");

            Actions["RetractRadiatorAction"].guiName = "Retract Radiator";
            Events["RetractRadiator"].guiName        = "Retract Radiator";

            var myAttachedEngine = part.FindModuleImplementing <ModuleEngines>();

            if (myAttachedEngine == null)
            {
                partMass = part.mass;
                Fields["partMass"].guiActiveEditor        = true;
                Fields["partMass"].guiActive              = true;
                Fields["convectiveBonus"].guiActiveEditor = true;
            }

            if (!String.IsNullOrEmpty(thermalAnim))
            {
                heatStates = PluginHelper.SetUpAnimation(thermalAnim, this.part);

                if (heatStates != null)
                {
                    SetHeatAnimationRatio(0);
                }
            }

            deployAnimation = part.FindModelAnimators(animName).FirstOrDefault();
            if (deployAnimation != null)
            {
                deployAnimation[animName].layer = 1;
                deployAnimation[animName].speed = 0;

                deployAnimation[animName].normalizedTime = radiatorIsEnabled ? 1 : 0;
            }

            _moduleActiveRadiator = part.FindModuleImplementing <ModuleActiveRadiator>();
            if (_moduleActiveRadiator != null)
            {
                _moduleActiveRadiator.Events["Activate"].guiActive = false;
                _moduleActiveRadiator.Events["Shutdown"].guiActive = false;
            }
            _moduleDeployableRadiator = part.FindModuleImplementing <ModuleDeployableRadiator>();
            if (_moduleDeployableRadiator != null)
            {
                radiatorState = _moduleDeployableRadiator.deployState;
            }

            var radiatorfield = Fields["radiatorIsEnabled"];

            radiatorfield.guiActive        = showControls;
            radiatorfield.guiActiveEditor  = showControls;
            radiatorfield.OnValueModified += radiatorIsEnabled_OnValueModified;

            var automatedfield = Fields["isAutomated"];

            automatedfield.guiActive       = showControls;
            automatedfield.guiActiveEditor = showControls;

            var pivotfield = Fields["pivotEnabled"];

            pivotfield.guiActive       = showControls;
            pivotfield.guiActiveEditor = showControls;

            if (_moduleActiveRadiator != null)
            {
                var generationValue = 1 + ((int)CurrentGenerationType);
                _maxEnergyTransfer = radiatorArea * 1000 * generationValue * generationValue;
                _moduleActiveRadiator.maxEnergyTransfer = _maxEnergyTransfer;
                _moduleActiveRadiator.overcoolFactor    = 0.20 + ((int)CurrentGenerationType * 0.025);
            }

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

            var depth = 0;

            star = FlightGlobals.currentMainBody;
            while (depth < 10 && star != null && star.GetTemperature(0) < 2000)
            {
                star = star.referenceBody;
                depth++;
            }
            if (star == null)
            {
                star = FlightGlobals.Bodies[0];
            }

            if (ResearchAndDevelopment.Instance != null)
            {
                upgradeCostStr = ResearchAndDevelopment.Instance.Science + "/" + upgradeCost.ToString("0") + " Science";
            }

            renderArray = part.FindModelComponents <Renderer>().ToArray();

            if (radiatorInit == false)
            {
                radiatorInit = true;
            }

            part.maxTemp = maxRadiatorTemperature;

            radiatorTempStr = maxRadiatorTemperature + "K";

            maxVacuumTemperature     = String.IsNullOrEmpty(surfaceAreaUpgradeTechReq) ? Math.Min((float)PluginHelper.RadiatorTemperatureMk3, maxRadiatorTemperature) :  Math.Min(maxVacuumTemperature, maxRadiatorTemperature);
            maxAtmosphereTemperature = String.IsNullOrEmpty(surfaceAreaUpgradeTechReq) ? Math.Min((float)PluginHelper.RadiatorTemperatureMk3, maxRadiatorTemperature) : Math.Min(maxAtmosphereTemperature, maxRadiatorTemperature);

            resourceBuffers = new ResourceBuffers();
            resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_WASTEHEAT, wasteHeatMultiplier, 2.0e+6));
            resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_WASTEHEAT, this.part.mass);
            resourceBuffers.Init(this.part);
        }
Example #28
0
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            _mjSolarSupplyField = Fields[nameof(mjSolarSupply)];
            _mjMaxSupplyField   = Fields[nameof(mjMaxSupply)];

            if (part.Modules.Contains("SolarPanelFixer"))
            {
                _solarPanelFixer = part.Modules["SolarPanelFixer"];

                _fieldKerbalismNominalRate = _solarPanelFixer.Fields["nominalRate"];
                _fieldKerbalismPanelStatus = _solarPanelFixer.Fields["panelStatus"];
            }

            // calculate Astronomical unit on homeworld semiMajorAxis when missing
            if (astronomicalUnit <= 0)
            {
                astronomicalUnit = FlightGlobals.GetHomeBody().orbit.semiMajorAxis;
            }

            _microwavePowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();

            _solarPanel = part.FindModuleImplementing <ModuleDeployableSolarPanel>();
            if (_solarPanel == null || _solarPanel.chargeRate <= 0)
            {
                return;
            }

            if (part.FindModuleImplementing <ModuleJettison>() == null)
            {
                Debug.Log("[KSPI]: FNSolarPanelWasteHeatModule Force Activated  " + part.name);
                part.force_activate();
            }

            string[] resourcesToSupply = { ResourceSettings.Config.ElectricPowerInMegawatt };
            this.resourcesToSupply = resourcesToSupply;
            base.OnStart(state);

            _outputResource = _solarPanel.resHandler.outputResources.FirstOrDefault();

            resourceName = _solarPanel.resourceName;

            if (resourceName == ResourceSettings.Config.ElectricPowerInMegawatt)
            {
                _outputType = ResourceType.megajoule;
            }
            else if (resourceName == ResourceSettings.Config.ElectricPowerInKilowatt)
            {
                _outputType = ResourceType.electricCharge;
            }
            else
            {
                _outputType = ResourceType.other;
            }

            // only manage power buffer when microwave receiver is not available
            if (_outputType != ResourceType.other && _microwavePowerReceiver == null)
            {
                _resourceBuffers = new ResourceBuffers();
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceSettings.Config.ElectricPowerInMegawatt));

                _resourceBuffers.UpdateVariable(ResourceSettings.Config.ElectricPowerInMegawatt, _outputType == ResourceType.electricCharge ? _solarPanel.chargeRate / GameConstants.ecPerMJ : _solarPanel.chargeRate);
                if (!Kerbalism.IsLoaded)
                {
                    _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceSettings.Config.ElectricPowerInKilowatt));
                    _resourceBuffers.UpdateVariable(ResourceSettings.Config.ElectricPowerInKilowatt, _outputType == ResourceType.electricCharge ? _solarPanel.chargeRate : _solarPanel.chargeRate * GameConstants.ecPerMJ);
                }

                _resourceBuffers.Init(part);
            }

            _stars = KopernicusHelper.Stars;
        }
Example #29
0
        public override void OnStart(StartState state)
        {
            try
            {
                if (state == StartState.Editor)
                {
                    return;
                }

                //InitializePartModule();

                var modules = part.FindModulesImplementing <ModuleGenerator>();

                moduleGenerator = modules.Count > index ? modules[index] : null;

                if (moduleGenerator == null)
                {
                    return;
                }

                string[] resourcesToSupply = { ResourceSettings.Config.ElectricPowerInMegawatt };
                this.resourcesToSupply = resourcesToSupply;
                base.OnStart(state);

                if (maintainsBuffer)
                {
                    resourceBuffers = new ResourceBuffers();
                }

                outputType = ResourceType.other;
                inputType  = ResourceType.other;

                foreach (ModuleResource moduleResource in moduleGenerator.resHandler.inputResources)
                {
                    if (moduleResource.name == ResourceSettings.Config.ElectricPowerInMegawatt)
                    {
                        inputType = ResourceType.megajoule;
                    }
                    else if (moduleResource.name == ResourceSettings.Config.ElectricPowerInKilowatt)
                    {
                        inputType = ResourceType.electricCharge;
                    }

                    if (inputType != ResourceType.other)
                    {
                        moduleInputResource = moduleResource;

                        if (inputRate != 0)
                        {
                            moduleInputResource.rate = inputRate;
                        }

                        initialInputAmount = moduleInputResource.rate;

                        break;
                    }
                }

                if (offlineProcessing && moduleInputResource != null && last_active_time > 0 && powerGeneratorPowerInput > 0)
                {
                    var timePassedSinceLastProcessing = Planetarium.GetUniversalTime() - last_active_time;

                    var consumption = timePassedSinceLastProcessing * powerGeneratorPowerInput;

                    part.RequestResource(moduleInputResource.name, consumption);

                    var message = Localizer.Format("#LOC_KSPIE_FNGeneratorAdapter_msg", timePassedSinceLastProcessing, consumption, moduleInputResource.name);// <<1>> seconds passed durring which <<2>> <<3>> was consumed "

                    Debug.Log("[KSPI]: " + message);
                }

                foreach (ModuleResource moduleResource in moduleGenerator.resHandler.outputResources)
                {
                    // assuming only one of those two is present
                    if (moduleResource.name == ResourceSettings.Config.ElectricPowerInMegawatt)
                    {
                        outputType = ResourceType.megajoule;
                    }
                    else if (moduleResource.name == ResourceSettings.Config.ElectricPowerInKilowatt)
                    {
                        outputType = ResourceType.electricCharge;
                    }

                    if (outputType != ResourceType.other)
                    {
                        if (maintainsBuffer)
                        {
                            var bufferResource = part.Resources[moduleResource.name];
                            if (bufferResource != null)
                            {
                                if (initialMaxBufferSize == 0)
                                {
                                    initialMaxBufferSize = bufferResource.maxAmount;
                                }
                                else
                                {
                                    bufferResource.maxAmount = initialMaxBufferSize;
                                }
                            }

                            resourceBuffers.AddConfiguration(new ResourceBuffers.MaxAmountConfig(moduleResource.name, 50));
                        }

                        mockInputResource      = new ModuleResource();
                        mockInputResource.name = moduleResource.name;
                        mockInputResource.id   = moduleResource.name.GetHashCode();
                        moduleGenerator.resHandler.inputResources.Add(mockInputResource);

                        moduleOutputResource = moduleResource;

                        if (outputRate != 0)
                        {
                            moduleOutputResource.rate = outputRate;
                        }

                        initialOutputAmount = moduleOutputResource.rate;

                        moduleGeneratorEfficienctBaseField = moduleGenerator.Fields["efficiency"];
                        if (moduleGeneratorEfficienctBaseField != null)
                        {
                            moduleGeneratorEfficienctBaseField.guiActive       = false;
                            moduleGeneratorEfficienctBaseField.guiActiveEditor = false;
                        }

                        break;
                    }
                }

                if (maintainsBuffer)
                {
                    resourceBuffers.Init(part);
                }

                efficiencyField    = moduleGenerator.Fields["efficiency"];
                displayStatusField = moduleGenerator.Fields["displayStatus"];

                efficiencyField.guiActive    = showEfficiency;
                displayStatusField.guiActive = showDisplayStatus;

                powerGeneratorPowerInputField  = Fields["powerGeneratorPowerInput"];
                powerGeneratorPowerOutputField = Fields["powerGeneratorPowerOutput"];

                if (index > 0)
                {
                    powerGeneratorPowerInputField.guiName  = powerGeneratorPowerInputField.guiName + " " + (index + 1);
                    powerGeneratorPowerOutputField.guiName = powerGeneratorPowerOutputField.guiName + " " + (index + 1);
                }
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI]: Exception in FNGeneratorAdapter.OnStart " + e.ToString());
                throw;
            }
        }
        public override void OnStart(StartState state)
        {
            try
            {
                if (state == StartState.Editor)
                {
                    return;
                }

                var beamedPowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();
                if (beamedPowerReceiver != null)
                {
                    Debug.LogWarning("[KSPI]: disabling FNGeneratorAdapter, found BeamedPowerReceiver");
                    return;
                }

                var generator = part.FindModuleImplementing <FNGenerator>();
                if (generator != null)
                {
                    Debug.LogWarning("[KSPI]: disabling FNGeneratorAdapter, found FNGenerator");
                    return;
                }

                var modules = part.FindModulesImplementing <ModuleGenerator>();

                _moduleGenerator = modules.Count > index ? modules[index] : null;

                if (_moduleGenerator == null)
                {
                    Debug.LogWarning("[KSPI]: disabling FNGeneratorAdapter, failed to find ModuleGenerator");
                    return;
                }

                string[] resourcesToSupply = { ResourceSettings.Config.ElectricPowerInMegawatt };
                this.resources_to_supply = resourcesToSupply;
                base.OnStart(state);

                if (maintainsBuffer)
                {
                    _resourceBuffers = new ResourceBuffers();
                }

                _outputType = ResourceType.other;
                foreach (ModuleResource moduleResource in _moduleGenerator.resHandler.outputResources)
                {
                    if (moduleResource.name != ResourceSettings.Config.ElectricPowerInMegawatt && (moduleResource.name != ResourceSettings.Config.ElectricPowerInKilowatt))
                    {
                        continue;
                    }

                    // assuming only one of those two is present
                    _outputType = moduleResource.name == ResourceSettings.Config.ElectricPowerInMegawatt ? ResourceType.megajoule : ResourceType.electricCharge;

                    if (maintainsBuffer)
                    {
                        _resourceBuffers.AddConfiguration(new ResourceBuffers.MaxAmountConfig(moduleResource.name, 50));
                    }

                    _mockInputResource = new ModuleResource
                    {
                        name = moduleResource.name,
                        id   = moduleResource.name.GetHashCode()
                    };

                    _moduleGenerator.resHandler.inputResources.Add(_mockInputResource);
                    _moduleOutputResource = moduleResource;
                    break;
                }

                if (maintainsBuffer)
                {
                    _resourceBuffers.Init(part);
                }

                _efficiencyField    = _moduleGenerator.Fields[nameof(ModuleGenerator.efficiency)];
                _displayStatusField = _moduleGenerator.Fields[nameof(ModuleGenerator.displayStatus)];

                _efficiencyField.guiActive    = showEfficiency;
                _displayStatusField.guiActive = showDisplayStatus;
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI]: Exception in FNGeneratorAdapter.OnStart " + e.ToString());
                throw;
            }
        }