public override void OnStart(PartModule.StartState state) { if (state == StartState.Editor) { return; } generators = vessel.FindPartModulesImplementing <FNGenerator>(); receivers = vessel.FindPartModulesImplementing <MicrowavePowerReceiver>(); panels = vessel.FindPartModulesImplementing <ModuleDeployableSolarPanel>(); if (part.FindModulesImplementing <MicrowavePowerReceiver>().Count == 1) { part_receiver = part.FindModulesImplementing <MicrowavePowerReceiver>().First(); has_receiver = true; } anim = part.FindModelAnimators(animName).FirstOrDefault(); if (anim != null) { anim[animName].layer = 1; if (!IsEnabled) { anim[animName].normalizedTime = 1f; anim[animName].speed = -1f; } else { anim[animName].normalizedTime = 0f; anim[animName].speed = 1f; } anim.Play(); } this.part.force_activate(); }
public override void OnStart(PartModule.StartState state) { onMoving = new EventData <float, float>("transmitterMoving"); onStop = new EventData <float>("transmitterStop"); power_capacity = maximumPower * powerMult; if (String.IsNullOrEmpty(partId)) { partId = Guid.NewGuid().ToString(); } // store aperture aperture = apertureDiameter; ConnectToBeamGenerator(); if (state == StartState.Editor) { part.OnEditorAttach += OnEditorAttach; return; } genericAnimation = part.FindModulesImplementing <ModuleAnimateGeneric>().FirstOrDefault(m => m.animationName == animName); panels = vessel.FindPartModulesImplementing <ModuleDeployableSolarPanel>(); vessel_recievers = this.vessel.FindPartModulesImplementing <MicrowavePowerReceiver>().Where(m => m.part != this.part).ToList(); part_receiver = part.FindModulesImplementing <MicrowavePowerReceiver>().FirstOrDefault(); UpdateRelayWavelength(); //ScreenMessages.PostScreenMessage("Microwave Transmitter Updated Wvelength", 10.0f, ScreenMessageStyle.UPPER_CENTER); anim = part.FindModelAnimators(animName).FirstOrDefault(); if (anim != null && part_receiver == null) { anim[animName].layer = 1; if (IsEnabled) { //ScreenMessages.PostScreenMessage("Microwave Transmitter Activates", 10.0f, ScreenMessageStyle.UPPER_CENTER); anim[animName].normalizedTime = 0f; anim[animName].speed = 1f; } else { //ScreenMessages.PostScreenMessage("Microwave Transmitter Deactivates", 10.0f, ScreenMessageStyle.UPPER_CENTER); anim[animName].normalizedTime = 1f; anim[animName].speed = -1f; } //anim.Play(); anim.Blend(animName, part.mass); } if (forceActivateAtStartup) { this.part.force_activate(); } //ScreenMessages.PostScreenMessage("Microwave Transmitter Force Activated", 5.0f, ScreenMessageStyle.UPPER_CENTER); }
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; } }
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 <MicrowavePowerReceiver>(); _solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>(); if (_solarPanel == null) { return; } _solarFlowRateResource = new ModuleResource(); _solarFlowRateResource.name = _solarPanel.resourceName; resHandler.inputResources.Add(_solarFlowRateResource); 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 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; }
public override void OnStart(PartModule.StartState state) { if (state == StartState.Editor) { return; } microwavePowerReceiver = part.FindModuleImplementing <MicrowavePowerReceiver>(); if (microwavePowerReceiver != null) { return; } String[] resources_to_supply = { FNResourceManager.FNRESOURCE_MEGAJOULES }; this.resources_to_supply = resources_to_supply; base.OnStart(state); previousDeltaTime = TimeWarp.fixedDeltaTime; solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>(); if (solarPanel == null) { return; } if (solarPanel.resourceName == FNResourceManager.FNRESOURCE_MEGAJOULES) { outputType = resourceType.megajoule; megajoulePartResource = part.Resources[FNResourceManager.FNRESOURCE_MEGAJOULES]; if (megajoulePartResource != null) { fixedMegajouleBufferSize = megajoulePartResource.maxAmount * 50; } } else if (solarPanel.resourceName == FNResourceManager.STOCK_RESOURCE_ELECTRICCHARGE) { outputType = resourceType.electricCharge; electricChargePartResource = part.Resources[FNResourceManager.STOCK_RESOURCE_ELECTRICCHARGE]; if (electricChargePartResource != null) { fixedElectricChargeBufferSize = electricChargePartResource.maxAmount * 50; } } else { outputType = resourceType.other; } outputDefinition = PartResourceLibrary.Instance.GetDefinition(solarPanel.resourceName); }
public override void OnStart(PartModule.StartState state) { if (state == StartState.Editor) { return; } generators = vessel.FindPartModulesImplementing <FNGenerator>(); receivers = vessel.FindPartModulesImplementing <MicrowavePowerReceiver>(); panels = vessel.FindPartModulesImplementing <ModuleDeployableSolarPanel>(); if (part.FindModulesImplementing <MicrowavePowerReceiver>().Count == 1) { part_receiver = part.FindModulesImplementing <MicrowavePowerReceiver>().First(); has_receiver = true; } anim = part.FindModelAnimators(animName).FirstOrDefault(); if (anim != null) { anim[animName].layer = 1; if (!IsEnabled) { anim[animName].normalizedTime = 1f; anim[animName].speed = -1f; } else { anim[animName].normalizedTime = 0f; anim[animName].speed = 1f; } anim.Play(); } this.part.force_activate(); // Debug.Log("[KSPI] - MicrowavePowerTransmitter - Looking for externalPowerSources"); // foreach (Part vesselpart in vessel.Parts) // { // if (vesselpart.partName == "reactor-25") // { // externalPowerSources.Add(new ExternalPowerSourePartModule() { Name = "reactor-25", Power = 2 }); // Debug.Log("[KSPI] - MicrowavePowerTransmitter - found " + vesselpart.partInfo.title); // } //} }
uint counter = 0; // OnFixedUpdate cycle counter public override void OnFixedUpdate() { base.OnFixedUpdate(); if (receiverIsEnabled) { if (getResourceBarRatio(FNResourceManager.FNRESOURCE_WASTEHEAT) >= 0.95 && !isThermalReceiver) { receiverIsEnabled = false; deactivate_timer++; if (FlightGlobals.ActiveVessel == vessel && deactivate_timer > 2) { ScreenMessages.PostScreenMessage("Warning Dangerous Overheating Detected: Emergency microwave power shutdown occuring NOW!", 5.0f, ScreenMessageStyle.UPPER_CENTER); } return; } if (++counter % 10 == 1) // recalculate input once per 10 physics cycles. Relay route algorythm is too expensive { double total_power = 0; int activeSatsIncr = 0; connectedsatsi = 0; connectedrelaysi = 0; networkDepth = 0; double atmosphericefficiency = Math.Exp(-FlightGlobals.getStaticPressure(vessel.transform.position) / 5); efficiency_d = GameConstants.microwave_dish_efficiency * atmosphericefficiency; deactivate_timer = 0; HashSet <VesselRelayPersistence> usedRelays = new HashSet <VesselRelayPersistence>(); //Transmitters power calculation foreach (var connectedTransmitterEntry in GetConnectedTransmitters()) { VesselMicrowavePersistence transmitter = connectedTransmitterEntry.Key; Vessel transmitterVessel = connectedTransmitterEntry.Key.getVessel(); double routeEfficiency = connectedTransmitterEntry.Value.Key; IEnumerable <VesselRelayPersistence> relays = connectedTransmitterEntry.Value.Value; received_power[transmitterVessel] = 0; // calculate maximum power receivable from satellite double satPowerCap = transmitter.getAvailablePower() * efficiency_d; double currentPowerFromSat = MicrowavePowerReceiver.getEnumeratedPowerFromSatelliteForAllVesssels(transmitter); double powerAvailableFromSat = (satPowerCap - currentPowerFromSat); double satPower = Math.Min(GetSatPower(transmitter, routeEfficiency), powerAvailableFromSat); // get sat power and make sure we conserve enegy received_power[transmitterVessel] = satPower * atmosphericefficiency; total_power += satPower; if (satPower > 0) { activeSatsIncr++; if (relays != null) { foreach (var relay in relays) { usedRelays.Add(relay); } networkDepth = Math.Max(networkDepth, relays.Count()); } } } connectedsatsi = activeSatsIncr; connectedrelaysi = usedRelays.Count; powerInputMegajoules = total_power / 1000.0 * GameConstants.microwave_dish_efficiency * atmosphericefficiency * receiptPower / 100.0f; powerInput = powerInputMegajoules * 1000.0f; } float animateTemp = (float)powerInputMegajoules / 3000; if (animateTemp > 1) { animateTemp = 1; } if (animT != null) { animT[animTName].normalizedTime = animateTemp; animT.Sample(); } if (!isThermalReceiver) { supplyFNResource(powerInputMegajoules * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES); double waste_heat_production = powerInputMegajoules / GameConstants.microwave_dish_efficiency * (1.0f - GameConstants.microwave_dish_efficiency); supplyFNResource(waste_heat_production * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_WASTEHEAT); } else { double cur_thermal_power = supplyFNResource(powerInputMegajoules * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_THERMALPOWER) / TimeWarp.fixedDeltaTime; if (ThermalPower <= 0) { ThermalPower = (float)(cur_thermal_power); } else { ThermalPower = (float)(cur_thermal_power * GameConstants.microwave_alpha + (1.0f - GameConstants.microwave_alpha) * ThermalPower); } } } else { connectedsatsi = 0; connectedrelaysi = 0; received_power.Clear(); } }
public override void OnStart(PartModule.StartState state) { if (state == StartState.Editor) { return; } generators = vessel.FindPartModulesImplementing<FNGenerator>(); receivers = vessel.FindPartModulesImplementing<MicrowavePowerReceiver>(); panels = vessel.FindPartModulesImplementing<ModuleDeployableSolarPanel>(); if (part.FindModulesImplementing<MicrowavePowerReceiver>().Count == 1) { part_receiver = part.FindModulesImplementing<MicrowavePowerReceiver>().First(); has_receiver = true; } anim = part.FindModelAnimators(animName).FirstOrDefault(); if (anim != null) { anim[animName].layer = 1; if (!IsEnabled) { anim[animName].normalizedTime = 1f; anim[animName].speed = -1f; } else { anim[animName].normalizedTime = 0f; anim[animName].speed = 1f; } anim.Play(); } this.part.force_activate(); }
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 = { FNResourceManager.FNRESOURCE_MEGAJOULES }; this.resources_to_supply = resources_to_supply; base.OnStart(state); previousDeltaTime = TimeWarp.fixedDeltaTime; solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>(); if (solarPanel == null) { return; } if (solarPanel.resourceName == FNResourceManager.FNRESOURCE_MEGAJOULES) { outputType = resourceType.megajoule; megajoulePartResource = part.Resources[FNResourceManager.FNRESOURCE_MEGAJOULES]; if (megajoulePartResource != null) { fixedMegajouleBufferSize = megajoulePartResource.maxAmount * 50; } } else if (solarPanel.resourceName == FNResourceManager.STOCK_RESOURCE_ELECTRICCHARGE) { outputType = resourceType.electricCharge; electricChargePartResource = part.Resources[FNResourceManager.STOCK_RESOURCE_ELECTRICCHARGE]; if (electricChargePartResource != null) { fixedElectricChargeBufferSize = electricChargePartResource.maxAmount * 50; } } else { outputType = resourceType.other; } outputDefinition = PartResourceLibrary.Instance.GetDefinition(solarPanel.resourceName); } catch (Exception e) { Debug.LogError("[KSPI] - Exception in FNSolarPanelWasteHeatModule.OnStart " + e.Message); throw; } }
public override void OnStart(PartModule.StartState state) { if (state == StartState.Editor) return; generators = vessel.FindPartModulesImplementing<FNGenerator>(); receivers = vessel.FindPartModulesImplementing<MicrowavePowerReceiver>(); panels = vessel.FindPartModulesImplementing<ModuleDeployableSolarPanel>(); if (part.FindModulesImplementing<MicrowavePowerReceiver>().Count == 1) { part_receiver = part.FindModulesImplementing<MicrowavePowerReceiver>().First(); has_receiver = true; } anim = part.FindModelAnimators(animName).FirstOrDefault(); if (anim != null) { anim[animName].layer = 1; if (!IsEnabled) { anim[animName].normalizedTime = 1f; anim[animName].speed = -1f; } else { anim[animName].normalizedTime = 0f; anim[animName].speed = 1f; } anim.Play(); } this.part.force_activate(); // Debug.Log("[KSPI] - MicrowavePowerTransmitter - Looking for externalPowerSources"); // foreach (Part vesselpart in vessel.Parts) // { // if (vesselpart.partName == "reactor-25") // { // externalPowerSources.Add(new ExternalPowerSourePartModule() { Name = "reactor-25", Power = 2 }); // Debug.Log("[KSPI] - MicrowavePowerTransmitter - found " + vesselpart.partInfo.title); // } //} }