Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another take on MicrowavePowerTransmitter #18

Merged
merged 1 commit into from
Aug 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions InterstellarPlugin/MicrowavePowerTransmitter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
extern alias ORSv1_1;
using ORSv1_1::OpenResourceSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -39,6 +41,12 @@ class MicrowavePowerTransmitter : FNResourceSuppliableModule {
[KSPEvent(guiActive = true, guiName = "Activate Transmitter", active = true)]
public void ActivateTransmitter() {
if (relay) { return; }
// Disallow activating more than one MicrowavePowerTransmitter in transmitter mode
if (vessel.FindPartModulesImplementing<MicrowavePowerTransmitter>().Exists(pm => pm.isActive() && !pm.getIsRelay()))
{
ScreenMessages.PostScreenMessage("Warning: Only one Microwave Transmitter can be active at any given time.", 10.0f, ScreenMessageStyle.UPPER_CENTER);
return;
}
if (anim != null) {
anim[animName].speed = 1f;
anim[animName].normalizedTime = 0f;
Expand Down Expand Up @@ -178,23 +186,25 @@ public override void OnFixedUpdate() {
solar_power = 0;
displayed_solar_power = 0;
if (IsEnabled && !relay) {
float fusionReactorsRequirements = 0.0f;

double powerDraw = 0.0;
try
{
fusionReactorsRequirements = vessel.FindPartModulesImplementing<FNFusionReactor>().Where(r => r.isActive()).Sum(r => r.powerRequirements);
ORSResourceManager manager = getOvermanagerForResource(FNResourceManager.FNRESOURCE_MEGAJOULES).getManagerForVessel(vessel);
if (manager != null)
powerDraw = manager.PowerDraws.Where(pm => !(pm.Key is MicrowavePowerTransmitter && (pm.Key as MicrowavePowerTransmitter) == this)).Sum(pm => pm.Value);
}
catch (ArgumentNullException)
{
fusionReactorsRequirements = 0.0f;
powerDraw = 0.0;
}

foreach (FNGenerator generator in generators) {
if (generator.isActive()) {
FNThermalSource thermal_source = generator.getThermalSource();
if (thermal_source != null && !thermal_source.isVolatileSource()) {
double output = -generator.getCurrentPower();
output -= fusionReactorsRequirements / (double)generators.Count(g => g.isActive());
if (thermal_source != null && !thermal_source.isVolatileSource() && thermal_source.isActive()) {
double output = generator.getMaxPowerOutput();
output -= powerDraw / (double)generators.Count(g => g.isActive() && g.getThermalSource().isActive());
output = output * transmitPower / 100.0;
double gpower = consumeFNResource(output * TimeWarp.fixedDeltaTime, FNResourceManager.FNRESOURCE_MEGAJOULES);
nuclear_power += gpower * 1000 / TimeWarp.fixedDeltaTime;
Expand Down
2 changes: 2 additions & 0 deletions OpenResourceSystem/ORSResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace OpenResourceSystem
{
public class ORSResourceManager
{
public List<KeyValuePair<ORSResourceSuppliable, double>> PowerDraws
{ get { return power_draw_list_archive; } }
public const string FNRESOURCE_MEGAJOULES = "Megajoules";
public const string FNRESOURCE_CHARGED_PARTICLES = "ChargedParticles";
public const string FNRESOURCE_THERMALPOWER = "ThermalPower";
Expand Down