// Deploy Panels public void Deploy() { if (!Deployable) return; for (int i = 0; i < deployStates.Length ; i++) { deployStates[i].speed = 1; } State = ModuleDeployablePart.DeployState.EXTENDING; }
public void Update() { if (Deployable) { for (int i = 0; i < deployStates.Length ; i++) { deployStates[i].normalizedTime = Mathf.Clamp01(deployStates[i].normalizedTime); } if (State == ModuleDeployablePart.DeployState.RETRACTING) { if (EvalAnimationCompletionReversed(deployStates) == 0f) State = ModuleDeployablePart.DeployState.RETRACTED; } if (State == ModuleDeployablePart.DeployState.EXTENDING) { if (EvalAnimationCompletion(deployStates) == 1f) State = ModuleDeployablePart.DeployState.EXTENDED; } if ((State == ModuleDeployablePart.DeployState.EXTENDED && Events["DeployPanels"].active) || (State == ModuleDeployablePart.DeployState.RETRACTED && Events["RetractPanels"].active)) { Events["DeployPanels"].active = !Events["DeployPanels"].active; Events["RetractPanels"].active = !Events["RetractPanels"].active; } } }
public override void OnUpdate() // is called while in flight { update_count++; if (update_count < FRAME_DELAY) { return; } update_count = 0; if (_moduleDeployableRadiator != null && (_moduleDeployableRadiator.deployState == ModuleDeployablePart.DeployState.RETRACTED || _moduleDeployableRadiator.deployState == ModuleDeployablePart.DeployState.EXTENDED)) { if (radiatorState != _moduleDeployableRadiator.deployState) { part.SendMessage("GeometryPartModuleRebuildMeshData"); Debug.Log("[KSPI] - Updating geometry mesh due to radiator deployment."); } radiatorState = _moduleDeployableRadiator.deployState; } effectiveRadiatorArea = EffectiveRadiatorArea; stefanArea = PhysicsGlobals.StefanBoltzmanConstant * effectiveRadiatorArea * 1e-6; external_temperature = Math.Max(FlightGlobals.getExternalTemperature(vessel.altitude, vessel.mainBody), PhysicsGlobals.SpaceTemperature); normalizedAtmosphere = Math.Min(vessel.atmDensity, 1); maxCurrentTemperature = maxAtmosphereTemperature * Math.Max(normalizedAtmosphere, 0) + maxVacuumTemperature * Math.Max(Math.Min(1 - vessel.atmDensity, 1), 0); temperatureDifferenceCurrentWithExternal = maxCurrentTemperature - external_temperature; temperatureDifferenceMaximumWithExternal = maxRadiatorTemperature - external_temperature; thermalPowerConvStrField.guiActive = convectedThermalPower > 0; // synchronize states if (_moduleDeployableRadiator != null && pivotEnabled && showControls) { if (_moduleDeployableRadiator.deployState == ModuleDeployablePart.DeployState.EXTENDED) { radiatorIsEnabled = true; } else if (_moduleDeployableRadiator.deployState == ModuleDeployablePart.DeployState.RETRACTED) { radiatorIsEnabled = false; } } radiatorIsEnabledField.guiActive = showControls; radiatorIsEnabledField.guiActiveEditor = showControls; isAutomatedField.guiActive = showControls; isAutomatedField.guiActiveEditor = showControls; pivotEnabledField.guiActive = showControls; pivotEnabledField.guiActiveEditor = showControls; if (radiatorIsEnabled && canRadiateHeat) { thermalPowerDissipStr = PluginHelper.getFormattedPowerString(radiatedThermalPower, "0.0", "0.000"); thermalPowerConvStr = PluginHelper.getFormattedPowerString(convectedThermalPower, "0.0", "0.000"); } else { thermalPowerDissipStr = "disabled"; thermalPowerConvStr = "disabled"; } radiatorTempStr = CurrentRadiatorTemperature.ToString("0.0") + "K / " + maxCurrentTemperature.ToString("0.0") + "K"; partTempStr = part.temperature.ToString("0.0") + "K / " + part.maxTemp.ToString("0.0") + "K"; if (showColorHeat) { ColorHeat(); } }
// Retract Panels public void Retract() { if (!Deployable) return; for (int i = 0; i < deployStates.Length ; i++) { deployStates[i].speed = -1; } State = ModuleDeployablePart.DeployState.RETRACTING; }
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 * 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); }
public override void OnUpdate() // is called while in flight { radiator_deploy_delay++; if (_moduleDeployableRadiator != null && (_moduleDeployableRadiator.deployState == ModuleDeployablePart.DeployState.RETRACTED || _moduleDeployableRadiator.deployState == ModuleDeployablePart.DeployState.EXTENDED)) { if (radiatorState != _moduleDeployableRadiator.deployState) { part.SendMessage("GeometryPartModuleRebuildMeshData"); Debug.Log("[KSPI]: Updating geometry mesh due to radiator deployment."); } radiatorState = _moduleDeployableRadiator.deployState; } stefanArea = PhysicsGlobals.StefanBoltzmanConstant * effectiveRadiatorArea * 1e-6; external_temperature = Math.Max(FlightGlobals.getExternalTemperature(vessel.altitude, vessel.mainBody), PhysicsGlobals.SpaceTemperature); oxidationModifier = 0; UpdateMaxCurrentTemperature(); if (keepMaxPartTempEqualToMaxRadiatorTemp && double.IsNaN(maxCurrentRadiatorTemperature) == false) { part.skinMaxTemp = maxCurrentRadiatorTemperature; part.maxTemp = maxCurrentRadiatorTemperature; } currentTemperatureDifferenceWithExternal = maxCurrentRadiatorTemperature - external_temperature; maximumTemperatureDifferenceWithExternal = maxRadiatorTemperature - external_temperature; thermalPowerConvStrField.guiActive = convectedThermalPower > 0; // synchronize states if (_moduleDeployableRadiator != null && pivotEnabled && showControls) { if (_moduleDeployableRadiator.deployState == ModuleDeployablePart.DeployState.EXTENDED) { ActivateRadiator(); } else if (_moduleDeployableRadiator.deployState == ModuleDeployablePart.DeployState.RETRACTED) { DeactivateRadiator(); } } radiatorIsEnabledField.guiActive = !isPassive && showControls; radiatorIsEnabledField.guiActiveEditor = !isPassive && showControls; isAutomatedField.guiActive = showControls && isDeployable; isAutomatedField.guiActiveEditor = showControls && isDeployable; pivotEnabledField.guiActive = showControls && isDeployable; pivotEnabledField.guiActiveEditor = showControls && isDeployable; if (radiatorIsEnabled && canRadiateHeat) { thermalPowerDissipStr = PluginHelper.getFormattedPowerString(radiatedThermalPower, "0.0", "0.000"); thermalPowerConvStr = PluginHelper.getFormattedPowerString(convectedThermalPower, "0.0", "0.000"); } else { thermalPowerDissipStr = "disabled"; thermalPowerConvStr = "disabled"; } radiatorTempStr = CurrentRadiatorTemperature.ToString("0.0") + "K / " + maxCurrentRadiatorTemperature.ToString("0.0") + "K"; partTempStr = part.temperature.ToString("0.0") + "K / " + part.maxTemp.ToString("0.0") + "K"; if (showColorHeat) { ApplyColorHeat(); } }
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); } }
public override void OnUpdate() // is called while in flight { update_count++; if (update_count < FRAME_DELAY) { return; } update_count = 0; if (_moduleDeployableRadiator != null && (_moduleDeployableRadiator.deployState == ModuleDeployablePart.DeployState.RETRACTED || _moduleDeployableRadiator.deployState == ModuleDeployablePart.DeployState.EXTENDED)) { if (radiatorState != _moduleDeployableRadiator.deployState) { part.SendMessage("GeometryPartModuleRebuildMeshData"); Debug.Log("[KSPI] - Updating geometry mesh due to radiator deployment."); } radiatorState = _moduleDeployableRadiator.deployState; } thermalPowerConvStrField.guiActive = convectedThermalPower > 0; // synchronize states if (_moduleDeployableRadiator != null && pivotEnabled && showControls) { if (_moduleDeployableRadiator.deployState == ModuleDeployableRadiator.DeployState.EXTENDED) { radiatorIsEnabled = true; } else if (_moduleDeployableRadiator.deployState == ModuleDeployableRadiator.DeployState.RETRACTED) { radiatorIsEnabled = false; } } radiatorIsEnabledField.guiActive = showControls; radiatorIsEnabledField.guiActiveEditor = showControls; isAutomatedField.guiActive = showControls; isAutomatedField.guiActiveEditor = showControls; pivotEnabledField.guiActive = showControls; pivotEnabledField.guiActiveEditor = showControls; if (radiatorIsEnabled && canRadiateHeat) { thermalPowerDissipStr = PluginHelper.getFormattedPowerString(radiatedThermalPower, "0.0", "0.000"); thermalPowerConvStr = PluginHelper.getFormattedPowerString(convectedThermalPower, "0.0", "0.000"); } else { thermalPowerDissipStr = "disabled"; thermalPowerConvStr = "disabled"; } radiatorTempStr = CurrentRadiatorTemperature.ToString("0.0") + "K / " + maxCurrentTemperature.ToString("0.0") + "K"; partTempStr = part.temperature.ToString("0.0") + "K / " + part.maxTemp.ToString("0.0") + "K"; if (showColorHeat) { ColorHeat(); } }
protected override void DI_Disable() { this.antennaModule.enabled = false; lastDeployState = this.antennaModule.deployState; this.antennaModule.deployState = ModuleDeployablePart.DeployState.BROKEN; }