private ModuleDeployableRadiator ShieldControl()
        {
            ModuleDeployableRadiator shieldControl = null;

            shieldControl = part.FindModuleImplementing <ModuleDeployableRadiator>();

            return(shieldControl);
        }
Beispiel #2
0
 internal Radiator(Part part)
 {
     this.part = part;
     radiator  = part.InternalPart.Module <ModuleDeployableRadiator> ();
     if (radiator == null)
     {
         throw new ArgumentException("Part does not have a ModuleDeployableRadiator PartModule");
     }
 }
Beispiel #3
0
 internal Radiator(Part part)
 {
     this.part          = part;
     activeRadiator     = part.InternalPart.Module <ModuleActiveRadiator> ();
     deployableRadiator = part.InternalPart.Module <ModuleDeployableRadiator> ();
     if (activeRadiator == null && deployableRadiator == null)
     {
         throw new ArgumentException("Part is not a radiator");
     }
 }
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     if (HighLogic.LoadedSceneIsFlight)
     {
         shieldState = GetShieldState();
         shieldCheck = ShieldControl();
         hpTracker   = GetHP();
         CheckShieldState();
         calcSurfaceArea();
         hp      = hpTracker.Hitpoints;
         hpCheck = hp;
     }
 }
Beispiel #5
0
        public override void OnStart(StartState state)
        {
            radiatedThermalPower  = 0;
            convectedThermalPower = 0;
            current_rad_temp      = 0;
            directionrotate       = 1;
            //oldangle = 0;
            last_draw_update   = 0;
            update_count       = 0;
            hasrequiredupgrade = false;
            explode_counter    = 0;
            UpdateEnableAutomation();

            if (upgradedRadiatorArea == 1)
            {
                upgradedRadiatorArea = radiatorArea * 1.7f;
            }

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

            var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT);

            // calculate WasteHeat Capacity
            if (wasteheatPowerResource != null)
            {
                var ratio = Math.Min(1, Math.Max(0, wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount));
                wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;
                wasteheatPowerResource.amount    = wasteheatPowerResource.maxAmount * ratio;
            }

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

            if (myAttachedEngine == null)
            {
                Fields["partMass"].guiActiveEditor             = true;
                Fields["upgradeTechReq"].guiActiveEditor       = true;
                Fields["convectiveBonus"].guiActiveEditor      = true;
                Fields["upgradedRadiatorTemp"].guiActiveEditor = true;
            }

            if (state == StartState.Editor)
            {
                if (hasTechsRequiredToUpgrade())
                {
                    isupgraded         = true;
                    hasrequiredupgrade = true;
                }
                return;
            }

            list_of_thermal_sources = vessel.FindPartModulesImplementing <IThermalSource>();

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

            if (state == PartModule.StartState.Docked)
            {
                base.OnStart(state);
                return;
            }

            // add to static list of all radiators
            FNRadiator.list_of_all_radiators.Add(this);

            moduleDeployableRadiator = part.FindModuleImplementing <ModuleDeployableRadiator>();
            array = part.FindModelComponents <Renderer>();

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

                if (radiatorIsEnabled)
                {
                    deployAnim[animName].normalizedTime = 1.0f;
                    deployAnim[animName].enabled        = true;
                    deployAnim.Sample();
                }
            }

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

            if (isDeployable)
            {
                pivot           = part.FindModelTransform("suntransform");
                original_eulers = pivot.transform.localEulerAngles;
            }
            else
            {
                radiatorIsEnabled = true;
            }


            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                if (PluginHelper.hasTech(upgradeTechReq))
                {
                    hasrequiredupgrade = true;
                }
            }
            else
            {
                hasrequiredupgrade = true;
            }


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

            if (!isupgraded)
            {
                radiatorType = originalName;
            }
            else
            {
                radiatorType = upgradedName;
                radiatorTemp = upgradedRadiatorTemp;
            }

            radiatorTempStr = radiatorTemp + "K";
        }
Beispiel #6
0
        public override void OnStart(StartState state)
        {
            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT };
            this.resources_to_supply = resources_to_supply;

            base.OnStart(state);

            radiatedThermalPower       = 0;
            convectedThermalPower      = 0;
            CurrentRadiatorTemperature = 0;
            update_count    = 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"];

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

            // calculate WasteHeat Capacity
            partBaseWasteheat      = part.mass * 1e+6 * wasteHeatMultiplier;
            wasteheatPowerResource = part.Resources[FNResourceManager.FNRESOURCE_WASTEHEAT];

            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 = SetUpAnimation(thermalAnim, this.part);

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

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

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

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

            BaseField radiatorfield = Fields["radiatorIsEnabled"];

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

            BaseField automatedfield = Fields["isAutomated"];

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

            BaseField pivotfield = Fields["pivotEnabled"];

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

            _maxEnergyTransfer = radiatorArea * 1000 * Math.Pow(1 + ((int)CurrentGenerationType), 1.5);

            if (_moduleActiveRadiator != null)
            {
                _moduleActiveRadiator.maxEnergyTransfer = _maxEnergyTransfer;
            }

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

            int 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);
        }
Beispiel #7
0
        public override void OnStart(StartState state)
        {
            radiatedThermalPower = 0;
            convectedThermalPower = 0;
            current_rad_temp = 0;
            directionrotate = 1;
            //oldangle = 0;
            last_draw_update = 0;
            update_count = 0;
            hasrequiredupgrade = false;
            explode_counter = 0;
            UpdateEnableAutomation();

            if (upgradedRadiatorArea == 1)
                upgradedRadiatorArea = radiatorArea * 1.7f;

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

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

            var myAttachedEngine = this.part.FindModuleImplementing<ModuleEngines>();
            if (myAttachedEngine == null)
            {
                Fields["partMass"].guiActiveEditor = true;
                Fields["upgradeTechReq"].guiActiveEditor = true;
                Fields["convectiveBonus"].guiActiveEditor = true;
                Fields["upgradedRadiatorTemp"].guiActiveEditor = true;
            }

            if (state == StartState.Editor)
            {
                if (hasTechsRequiredToUpgrade())
                {
                    isupgraded = true;
                    hasrequiredupgrade = true;
                }
                return;
            }

            list_of_thermal_sources = vessel.FindPartModulesImplementing<IThermalSource>();

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

            if (state == PartModule.StartState.Docked)
            {
                base.OnStart(state);
                return;
            }

            // add to static list of all radiators
            FNRadiator.list_of_all_radiators.Add(this);

            moduleDeployableRadiator = part.FindModuleImplementing<ModuleDeployableRadiator>();
            array = part.FindModelComponents<Renderer>();

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

                if (radiatorIsEnabled)
                {
                    deployAnim[animName].normalizedTime = 1.0f;
                    deployAnim[animName].enabled = true;
                    deployAnim.Sample();
                }

            }

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

            if (isDeployable)
            {
                pivot = part.FindModelTransform ("suntransform");
                original_eulers = pivot.transform.localEulerAngles;
            }
            else
                radiatorIsEnabled = true;

            if(HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                if(PluginHelper.hasTech(upgradeTechReq))
                    hasrequiredupgrade = true;
            }
            else
                hasrequiredupgrade = true;

            if (radiatorInit == false)
                radiatorInit = true;

            if (!isupgraded)
                radiatorType = originalName;
            else
            {
                radiatorType = upgradedName;
                radiatorTemp = upgradedRadiatorTemp;
            }

            radiatorTempStr = radiatorTemp + "K";
        }
        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();

            kspShader = Shader.Find(kspShaderLocation);
            maxRadiatorTemperature = (float)MaxRadiatorTemperature;

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

            radiatorType = RadiatorType;

            effectiveRadiatorArea = EffectiveRadiatorArea;
            stefanArea            = PhysicsGlobals.StefanBoltzmanConstant * effectiveRadiatorArea * 1e-6;

            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 * 2500 * Math.Pow(generationValue, 1.5);
                _moduleActiveRadiator.maxEnergyTransfer = _maxEnergyTransfer;
                _moduleActiveRadiator.overcoolFactor    = 0.20 + ((int)CurrentGenerationType * 0.025);
            }

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

            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);
        }
        public override void OnStart(StartState state)
        {
            radiatedThermalPower       = 0;
            convectedThermalPower      = 0;
            CurrentRadiatorTemperature = 0;
            directionrotate            = 1;
            update_count    = 0;
            explode_counter = 0;

            DetermineGenerationType();

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

            radiatorType = RadiatorType;

            effectiveRadiatorArea = EffectiveRadiatorArea;

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

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

            doLegacyGraphics = (part.name.StartsWith("circradiator") || part.name.StartsWith("RadialRadiator") || (part.name.StartsWith("LargeFlatRadiator")));

            // calculate WasteHeat Capacity
            var wasteheatPowerResource = part.Resources.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT);

            if (wasteheatPowerResource != null)
            {
                var ratio = Math.Min(1.0, Math.Max(0.0, wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount));
                wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;
                wasteheatPowerResource.amount    = wasteheatPowerResource.maxAmount * ratio;
            }

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

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

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

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

                if (radiatorIsEnabled)
                {
                    deployAnim[animName].normalizedTime = 1;
                }
                else
                {
                    deployAnim[animName].normalizedTime = 0;
                }
            }

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

            BaseField radiatorfield = Fields["radiatorIsEnabled"];

            radiatorfield.OnValueModified += radiatorIsEnabled_OnValueModified;

            if (_moduleDeployableRadiator == null && _moduleActiveRadiator != null && state != StartState.Editor)
            {
                if (radiatorIsEnabled)
                {
                    Deploy();
                }
                else
                {
                    Retract();
                }
            }

            _maxEnergyTransfer = radiatorArea * 1000 * (1 + ((int)CurrentGenerationType * 2));

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

            int 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];
            }

            // find all thermal sources
            list_of_thermal_sources = vessel.FindPartModulesImplementing <IThermalSource>().Where(tc => tc.IsThermalSource).ToList();

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

            if (state == PartModule.StartState.Docked)
            {
                base.OnStart(state);
                return;
            }

            // add to static list of all radiators
            FNRadiator.list_of_all_radiators.Add(this);

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

            //if (isDeployable)
            //    UnityEngine.Debug.Log("[KSPI] - OnStart.Start isDeployable");
            //else
            //    radiatorIsEnabled = true;

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

            part.maxTemp = MaxRadiatorTemperature;

            radiatorTempStr = MaxRadiatorTemperature + "K";
        }
Beispiel #10
0
        public override void OnStart(StartState state)
        {
            radiatedThermalPower  = 0;
            convectedThermalPower = 0;
            current_rad_temp      = 0;
            directionrotate       = 1;
            last_draw_update      = 0;
            update_count          = 0;
            hasrequiredupgrade    = false;
            explode_counter       = 0;

            DetermineGenerationType();

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

            radiatorType = RadiatorType;

            UpdateEnableAutomation();

            effectiveRadiatorArea = EffectiveRadiatorArea;

            //attachedParts = part.attachNodes.Where(a => a.attachedPart != null).Select(m => m.attachedPart).ToList();

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

            var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT);

            // calculate WasteHeat Capacity
            if (wasteheatPowerResource != null)
            {
                var ratio = Math.Min(1, Math.Max(0, wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount));
                wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;
                wasteheatPowerResource.amount    = wasteheatPowerResource.maxAmount * ratio;
            }

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

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

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

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

                if (radiatorIsEnabled)
                {
                    deployAnim[animName].normalizedTime = 1;
                }
                else
                {
                    deployAnim[animName].normalizedTime = 0;
                }
            }

            _moduleDeployableRadiator = part.FindModuleImplementing <ModuleDeployableRadiator>();
            _moduleActiveRadiator     = part.FindModuleImplementing <ModuleActiveRadiator>();

            _maxEnergyTransfer = radiatorArea * 1000 * (1 + ((int)CurrentGenerationType * 2));

            if (state == StartState.Editor)
            {
                if (hasTechsRequiredToUpgrade())
                {
                    isupgraded         = true;
                    hasrequiredupgrade = true;
                }
                return;
            }

            // find all thermal sources
            list_of_thermal_sources = vessel.FindPartModulesImplementing <IThermalSource>().Where(tc => tc.IsThermalSource).ToList();

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

            if (state == PartModule.StartState.Docked)
            {
                base.OnStart(state);
                return;
            }

            // add to static list of all radiators
            FNRadiator.list_of_all_radiators.Add(this);



            array = part.FindModelComponents <Renderer>();

            if (isDeployable)
            {
                UnityEngine.Debug.Log("[KSPI] - OnStart.Start isDeployable");

                pivot = part.FindModelTransform("suntransform");

                if (pivot != null)
                {
                    original_eulers = pivot.transform.localEulerAngles;
                }
            }
            else
            {
                radiatorIsEnabled = true;
            }

            UnityEngine.Debug.Log("[KSPI] - OnStart.Start I");

            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                //if(PluginHelper.hasTech(upgradeTechReq))
                //	hasrequiredupgrade = true;
            }
            else
            {
                hasrequiredupgrade = true;
            }

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

            part.maxTemp = RadiatorTemperature;

            radiatorTempStr = RadiatorTemperature + "K";

            UnityEngine.Debug.Log("[KSPI] - OnStart.Start J");
        }
Beispiel #11
0
		public override void OnStart(PartModule.StartState state) 
        {
            _moduleDeployableRadiator = part.FindModuleImplementing<ModuleDeployableRadiator>();

            radiatedThermalPower = 0;
		    convectedThermalPower = 0;
		    current_rad_temp = 0;
		    directionrotate = 1;
		    oldangle = 0;
		    last_draw_update = 0;
            update_count = 0;
		    hasrequiredupgrade = false;
		    explode_counter = 0;

            if (upgradedRadiatorArea == 1)
                upgradedRadiatorArea = radiatorArea * 1.7f;

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

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

            if (state == StartState.Editor) 
            {
                if (hasTechsRequiredToUpgrade()) 
                {
                    isupgraded = true;
                    hasrequiredupgrade = true;
                }
                return;
            }

			FNRadiator.list_of_radiators.Add (this);

			anim = part.FindModelAnimators (animName).FirstOrDefault ();
			//orig_emissive_colour = part.renderer.material.GetTexture (emissive_property_name);
			if (anim != null) 
            {
				anim [animName].layer = 1;

				if (radiatorIsEnabled) 
                {
					anim[animName].normalizedTime = 1.0f;
					anim[animName].enabled = true;
					anim.Sample();
				} 
                else 
                {
					//anim.Blend (animName, 0, 0);
				}
				//anim.Play ();
			}

			if (isDeployable) 
            {
				pivot = part.FindModelTransform ("suntransform");
				original_eulers = pivot.transform.localEulerAngles;
			} 
            else 
				radiatorIsEnabled = true;
			

			if(HighLogic.CurrentGame.Mode == Game.Modes.CAREER) 
            {
				if(PluginHelper.hasTech(upgradeTechReq)) 
					hasrequiredupgrade = true;
			}
            else
				hasrequiredupgrade = true;
			

			if (radiatorInit == false) 
				radiatorInit = true;
			

			if (!isupgraded) 
				radiatorType = originalName;
			else 
            {
				radiatorType = upgradedName;
				radiatorTemp = upgradedRadiatorTemp;
			}


			radiatorTempStr = radiatorTemp + "K";
            this.part.force_activate();
		}
        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;
            radiator_deploy_delay      = 0;

            DetermineGenerationType();

            isGraphene = !String.IsNullOrEmpty(surfaceAreaUpgradeTechReq);
            maximumRadiatorTempInSpace = (float)RadiatorProperties.RadiatorTemperatureMk6;
            maxSpaceTempBonus          = maximumRadiatorTempInSpace - maximumRadiatorTempAtOneAtmosphere;
            temperatureRange           = maximumRadiatorTempInSpace - drapperPoint;

            kspShader = Shader.Find(kspShaderLocation);
            maxRadiatorTemperature = (float)MaxRadiatorTemperature;

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

            radiatorType = RadiatorType;

            effectiveRadiatorArea = EffectiveRadiatorArea;
            stefanArea            = PhysicsGlobals.StefanBoltzmanConstant * effectiveRadiatorArea * 1e-6;

            startWithCircradiator      = part.name.StartsWith("circradiator");
            startWithRadialRadiator    = part.name.StartsWith("RadialRadiator");
            startWithLargeFlatRadiator = part.name.StartsWith("LargeFlatRadiator");

            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)
            {
                _maxEnergyTransfer = radiatorArea * PhysicsGlobals.StefanBoltzmanConstant * Math.Pow(MaxRadiatorTemperature, 4) * 0.001;

                _moduleActiveRadiator.maxEnergyTransfer = _maxEnergyTransfer;
                _moduleActiveRadiator.overcoolFactor    = 0.20 + ((int)CurrentGenerationType * 0.025);

                if (radiatorIsEnabled)
                {
                    _moduleActiveRadiator.Activate();
                }
                else
                {
                    _moduleActiveRadiator.Shutdown();
                }
            }

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

            if (isAutomated && !isDeployable)
            {
                ActivateRadiator();
            }

            for (var i = 0; i < 20; i++)
            {
                radTempQueue.Enqueue(currentRadTemp);
            }

            InitializeTemperatureColorChannels();

            ApplyColorHeat();

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

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

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

            radiatorTempStr = maxRadiatorTemperature + "K";

            maxVacuumTemperature     = isGraphene ? Math.Min(maxVacuumTemperature, maxRadiatorTemperature) : Math.Min(RadiatorProperties.RadiatorTemperatureMk4, maxRadiatorTemperature);
            maxAtmosphereTemperature = isGraphene ? Math.Min(maxAtmosphereTemperature, maxRadiatorTemperature) : Math.Min(RadiatorProperties.RadiatorTemperatureMk3, maxRadiatorTemperature);

            UpdateMaxCurrentTemperature();

            if (keepMaxPartTempEqualToMaxRadiatorTemp)
            {
                var partSkinTemperature = Math.Min(part.skinTemperature, maxCurrentRadiatorTemperature * 0.99);
                if (double.IsNaN(partSkinTemperature) == false)
                {
                    part.skinTemperature = partSkinTemperature;
                }

                var partTemperature = Math.Min(part.temperature, maxCurrentRadiatorTemperature * 0.99);
                if (double.IsNaN(partTemperature) == false)
                {
                    part.temperature = partTemperature;
                }

                if (double.IsNaN(maxCurrentRadiatorTemperature) == false)
                {
                    part.skinMaxTemp = maxCurrentRadiatorTemperature;
                    part.maxTemp     = maxCurrentRadiatorTemperature;
                }
            }

            if (maintainResourceBuffers)
            {
                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);
            }
        }
Beispiel #13
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            skinCapTemp = part.skinMaxTemp * radiatorMaxTempCap;
            capTemp     = part.maxTemp * radiatorMaxTempCap;

            GameEvents.onVesselWasModified.Add(OnVesselWasModified);

            if ((object)moduleDeployableRadiator == null)
            {
                Events ["Shutdown"].active = isActive;
                Events ["Activate"].active = !isActive;
            }
            else
            {
                Events ["Shutdown"].active       = false;
                Events ["Activate"].active       = false;
                Actions["ToggleAction"].active   = false;
                Actions["ActivateAction"].active = false;
                Actions["ShutdownAction"].active = false;
            }
            if (inputResources.Count == 0 && part.partInfo != null)
            {
                inputResources = ((ModuleHeatPump)part.partInfo.partPrefab.Modules["ModuleHeatPump"]).inputResources;
            }
            if (outputResources.Count == 0 && part.partInfo != null)
            {
                outputResources = ((ModuleHeatPump)part.partInfo.partPrefab.Modules ["ModuleHeatPump"]).outputResources;
            }
            if (attachNodes.Count == 0)
            {
                foreach (string nodeName in attachNodeNames)
                {
                    AttachNode node = part.FindAttachNode(nodeName);
                    if ((object)node != null)
                    {
                        print("Found AttachNode: " + nodeName);
                        attachNodes.Add(node);
                        if ((object)node.attachedPart != null)
                        {
                            print("Found attached part: " + node.attachedPart.name);
                            node.attachedPart.heatConductivity           = Math.Min(heatConductivity, node.attachedPart.heatConductivity);
                            node.attachedPart.skinInternalConductionMult = Math.Min(skinInternalConductionMult, node.attachedPart.skinInternalConductionMult);
                        }
                    }
                }
            }
            if ((object)part.srfAttachNode.attachedPart != null)
            {
                part.srfAttachNode.attachedPart.heatConductivity           = Math.Min(heatConductivity, part.srfAttachNode.attachedPart.heatConductivity);
                part.srfAttachNode.attachedPart.skinInternalConductionMult = Math.Min(skinInternalConductionMult, part.srfAttachNode.attachedPart.skinInternalConductionMult);
            }

            if (HighLogic.LoadedSceneIsFlight)
            {
                for (int i = 0; i < vessel.vesselModules.Count; i++)
                {
                    if (vessel.vesselModules[i] is FlightIntegrator)
                    {
                        _flightIntegrator = vessel.vesselModules[i] as FlightIntegrator;
                    }
                }

                moduleDeployableRadiator = part.FindModuleImplementing <ModuleDeployableRadiator>();
                radiatorCount            = part.symmetryCounterparts.Count + 1;
            }
        }