Skip to content
Open
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
44 changes: 30 additions & 14 deletions FNPlugin/FNSolarPanelWasteHeatModule.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using KSP;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -10,34 +11,50 @@ class FNSolarPanelWasteHeatModule : FNResourceSuppliableModule {
[KSPField(isPersistant = false, guiActive = true, guiName = "Heat Production")]
public string heatProductionStr = ":";

[KSPField(isPersistant = false, guiActive = true, guiName = "Energy Flow", guiUnits = "KW", guiFormat = "F2")]
public float energyFlow;

[KSPField(isPersistant = false, guiActive = true, guiName = "Efficiency", guiFormat = "P0")]
public float panelEfficiency = 2f / 3f;

protected float chargeRate;

protected ModuleDeployableSolarPanel solarPanel;

public override void OnStart(PartModule.StartState state) {
String[] resources_to_supply = {FNResourceManager.FNRESOURCE_WASTEHEAT};
String[] resources_to_supply = {FNResourceManager.FNRESOURCE_WASTEHEAT, FNResourceManager.FNRESOURCE_MEGAJOULES};
this.resources_to_supply = resources_to_supply;

base.OnStart (state);

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

isEnabled = true;
solarPanel = (ModuleDeployableSolarPanel)this.part.Modules["ModuleDeployableSolarPanel"];
if (solarPanel != null)
{
ModuleDeployableSolarPanel panelPrefab = PartLoader.getPartInfoByName(this.part.partInfo.name).partPrefab.Modules["ModuleDeployableSolarPanel"] as ModuleDeployableSolarPanel;
solarPanel.Fields["flowRate"].guiActive = false;
this.chargeRate = panelPrefab.chargeRate * 1.5f;
solarPanel.chargeRate = 0f;
}
}

public override void OnUpdate() {
public void Update() {
heatProductionStr = wasteheat_production_f.ToString ("0.00") + " KW";
}

public override void OnFixedUpdate() {
base.OnFixedUpdate ();
if (solarPanel != null) {
float solar_rate = solarPanel.flowRate*TimeWarp.fixedDeltaTime;
float heat_rate = solar_rate * 0.5f/1000.0f;
public void FixedUpdate() {
if (HighLogic.LoadedSceneIsFlight && solarPanel != null) {
base.OnFixedUpdate();
double kerbinToKerbolSqr = (FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBIN].transform.position - FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position).sqrMagnitude;
double vesselToKerbolSqr = (vessel.transform.position - FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position).sqrMagnitude;
float inv_square_mult = (float)(kerbinToKerbolSqr / vesselToKerbolSqr);

double inv_square_mult = Math.Pow(Vector3d.Distance(FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBIN].transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2) / Math.Pow(Vector3d.Distance(vessel.transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2);
FloatCurve satcurve = new FloatCurve();
satcurve.Add(0.0f, (float)inv_square_mult);
solarPanel.powerCurve = satcurve;
float solar_rate = this.chargeRate * TimeWarp.fixedDeltaTime * solarPanel.sunAOA * inv_square_mult;
float heat_rate = solar_rate * (1f - panelEfficiency) / 1000.0f;
float power_rate = solar_rate * panelEfficiency / 1000.0f;
float max_rate = power_rate / solarPanel.sunAOA;

if (getResourceBarRatio (FNResourceManager.FNRESOURCE_WASTEHEAT) >= 0.98 && solarPanel.panelState == ModuleDeployableSolarPanel.panelStates.EXTENDED && solarPanel.sunTracking) {
solarPanel.Retract ();
Expand All @@ -48,9 +65,8 @@ public override void OnFixedUpdate() {
}

wasteheat_production_f = supplyFNResource(heat_rate,FNResourceManager.FNRESOURCE_WASTEHEAT)/TimeWarp.fixedDeltaTime*1000.0f;
energyFlow = supplyFNResourceFixedMax(power_rate, max_rate, FNResourceManager.FNRESOURCE_MEGAJOULES) / TimeWarp.fixedDeltaTime * 1000f;
}


}
}
}
Expand Down