protected double GetSatPower(VesselMicrowavePersistence transmitter, double efficiency) { double availablePower = transmitter.getAvailablePower(); return availablePower * efficiency; }
protected double GetSatPower(VesselMicrowavePersistence transmitter, double efficiency) { double availablePower = transmitter.getAvailablePower(); return(availablePower * efficiency); }
public void calculateTransmitters() { unloaded_counter++; foreach (var vessel in FlightGlobals.Vessels) { // if vessek is offloaded to rails, parse file system if (vessel.state == Vessel.State.INACTIVE) { if (unloaded_counter % 100 != 1) // sometimes rebuild unloaded vessels as transmitters and relays continue; // parse transmitter var trans_pers = new VesselMicrowavePersistence(vessel); trans_pers.setNuclearPower(MicrowavePowerTransmitter.getEnumeratedNuclearPowerForVessel(vessel.protoVessel)); trans_pers.setSolarPower(MicrowavePowerTransmitter.getEnumeratedSolarPowerForVessel(vessel.protoVessel)); if (trans_pers.getAvailablePower() > 1.0) transmitters[vessel] = trans_pers; else transmitters.Remove(vessel); // parse relay var persistence = new VesselRelayPersistence(vessel); persistence.setActive(MicrowavePowerTransmitter.vesselIsRelay(vessel.protoVessel)); if (persistence.isActive()) relays[vessel] = persistence; else relays.Remove(vessel); continue; } // if vessel is dead if (vessel.state == Vessel.State.DEAD) { transmitters.Remove(vessel); relays.Remove(vessel); continue; } // if vessel is loaded var transes = vessel.FindPartModulesImplementing<MicrowavePowerTransmitter>(); if (transes.Count > 0) { var persistence = new VesselMicrowavePersistence(vessel); persistence.setNuclearPower(MicrowavePowerTransmitter.getEnumeratedNuclearPowerForVessel(vessel)); persistence.setSolarPower(MicrowavePowerTransmitter.getEnumeratedSolarPowerForVessel(vessel)); if (persistence.getAvailablePower() > 1.0) transmitters[vessel] = persistence; else transmitters.Remove(vessel); } if (MicrowavePowerTransmitter.vesselIsRelay(vessel)) { var persistence = new VesselRelayPersistence(vessel); persistence.setActive(true); if (persistence.isActive()) relays[vessel] = persistence; else relays.Remove(vessel); } } }
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 void calculateTransmitters() { unloaded_counter++; foreach (var vessel in FlightGlobals.Vessels) { // if vessek is offloaded to rails, parse file system if (vessel.state == Vessel.State.INACTIVE) { if (unloaded_counter % 100 != 1) // sometimes rebuild unloaded vessels as transmitters and relays { continue; } // parse transmitter var trans_pers = new VesselMicrowavePersistence(vessel); trans_pers.setNuclearPower(MicrowavePowerTransmitter.getEnumeratedNuclearPowerForVessel(vessel.protoVessel)); trans_pers.setSolarPower(MicrowavePowerTransmitter.getEnumeratedSolarPowerForVessel(vessel.protoVessel)); if (trans_pers.getAvailablePower() > 1.0) { transmitters[vessel] = trans_pers; } else { transmitters.Remove(vessel); } // parse relay var persistence = new VesselRelayPersistence(vessel); persistence.setActive(MicrowavePowerTransmitter.vesselIsRelay(vessel.protoVessel)); if (persistence.isActive()) { relays[vessel] = persistence; } else { relays.Remove(vessel); } continue; } // if vessel is dead if (vessel.state == Vessel.State.DEAD) { transmitters.Remove(vessel); relays.Remove(vessel); continue; } // if vessel is loaded var transes = vessel.FindPartModulesImplementing <MicrowavePowerTransmitter>(); if (transes.Count > 0) { var persistence = new VesselMicrowavePersistence(vessel); persistence.setNuclearPower(MicrowavePowerTransmitter.getEnumeratedNuclearPowerForVessel(vessel)); persistence.setSolarPower(MicrowavePowerTransmitter.getEnumeratedSolarPowerForVessel(vessel)); if (persistence.getAvailablePower() > 1.0) { transmitters[vessel] = persistence; } else { transmitters.Remove(vessel); } } if (MicrowavePowerTransmitter.vesselIsRelay(vessel)) { var persistence = new VesselRelayPersistence(vessel); persistence.setActive(true); if (persistence.isActive()) { relays[vessel] = persistence; } else { relays.Remove(vessel); } } } }