Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AniruddhKSP authored Aug 23, 2020
1 parent 67eef30 commit 1f8e770
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 56 deletions.
26 changes: 14 additions & 12 deletions BeamedPowerReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ public class WirelessReceiver : PartModule
Vector3d source; Vector3d dest; double received_power; int frames; int initFrames;
readonly int EChash = PartResourceLibrary.Instance.GetDefinition("ElectricCharge").id;
VesselFinder vesselFinder = new VesselFinder(); ModuleCoreHeat coreHeat;
AnimationSync animation; //BPOcclusion occlusion = new BPOcclusion();
AnimationSync animation; OcclusionData occlusion = new OcclusionData();

List<Vessel> CorrectVesselList;
List<double> excessList;
List<double> constantList;
List<string> targetList;
List<string> wavelenghtList;

public void Start()
{
Expand All @@ -54,6 +55,7 @@ public void Start()
excessList = new List<double>();
constantList = new List<double>();
targetList = new List<string>();
wavelenghtList = new List<string>();
wavelength_ui = "Long";
animation = new AnimationSync();
SetHeatParams();
Expand Down Expand Up @@ -127,7 +129,7 @@ private void AddHeatToCore()
double heatModifier = (double)HighLogic.CurrentGame.Parameters.CustomParams<BPSettings>().PercentHeat / 100;
double heatExcess = (1 - recvEfficiency) * (received_power / recvEfficiency) * heatModifier;
wasteHeat = (float)Math.Round(heatExcess, 1);
coreHeat.AddEnergyToCore(heatExcess * 0.3 * 3 * Time.fixedDeltaTime); // first converted to kJ
coreHeat.AddEnergyToCore(heatExcess * 0.3 * 2 * Time.fixedDeltaTime); // first converted to kJ
this.part.AddSkinThermalFlux(heatExcess * 0.7); // some heat added to skin
}

Expand All @@ -137,7 +139,7 @@ public void FixedUpdate()
frames += 1;
if (frames == 150)
{
vesselFinder.SourceData(out CorrectVesselList, out excessList, out constantList, out targetList, out _);
vesselFinder.SourceData(out CorrectVesselList, out excessList, out constantList, out targetList, out wavelenghtList);
frames = 0;
}
if (initFrames < 60)
Expand Down Expand Up @@ -166,22 +168,22 @@ public void FixedUpdate()
source = CorrectVesselList[n].GetWorldPos3D();
double distance = Vector3d.Distance(source, dest);
double spotsize = constant2 * distance;
//occlusion.CheckIfOccluded(CorrectVesselList[n], this.vessel, out _, out bool occluded);
occlusion.IsOccluded(source, dest, wavelenghtList[n], out _, out bool occluded);

// adding EC that has been received
if (recvDiameter < spotsize)
{
//if (occluded == false)
//{
received_power += Math.Round(((recvDiameter / spotsize) * recvEfficiency * excess2 * (percentagePower / 100)), 1);
//}
if (occluded == false)
{
received_power += Math.Round(((recvDiameter / spotsize) * recvEfficiency * excess2 * (percentagePower / 100)), 1);
}
}
else
{
//if (occluded == false)
//{
received_power += Math.Round(((recvEfficiency * excess2) * (percentagePower / 100)), 1);
//}
if (occluded == false)
{
received_power += Math.Round(((recvEfficiency * excess2) * (percentagePower / 100)), 1);
}
}
}
}
Expand Down
36 changes: 9 additions & 27 deletions BeamedPowerReceiverDirectional.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using CommNet.Occluders;

namespace BeamedPowerStandalone
{
Expand Down Expand Up @@ -43,12 +44,13 @@ public class WirelessReceiverDirectional : PartModule
int frames; double received_power; int initFrames;
readonly int EChash = PartResourceLibrary.Instance.GetDefinition("ElectricCharge").id;
VesselFinder vesselFinder = new VesselFinder(); ModuleCoreHeat coreHeat;
AnimationSync animation;
AnimationSync animation; OcclusionData occlusion = new OcclusionData();

List <Vessel> CorrectVesselList;
List<double> excessList;
List<double> constantList;
List<string> targetList;
List<string> wavelengthList;

[KSPField(isPersistant = true)]
public int counter = 0;
Expand All @@ -61,6 +63,7 @@ public void Start()
excessList = new List<double>();
constantList = new List<double>();
targetList = new List<string>();
wavelengthList = new List<string>();
wavelength_ui = "Long";
animation = new AnimationSync();
SetEngineParams();
Expand Down Expand Up @@ -141,38 +144,17 @@ private void AddHeatToCore()
double heatModifier = (double)HighLogic.CurrentGame.Parameters.CustomParams<BPSettings>().PercentHeat / 100;
double heatExcess = (1 - recvEfficiency) * (received_power / recvEfficiency) * heatModifier;
wasteHeat = (float)Math.Round(heatExcess, 1);
coreHeat.AddEnergyToCore(heatExcess * 0.3 * 3 * Time.fixedDeltaTime); // first converted to kJ
coreHeat.AddEnergyToCore(heatExcess * 0.3 * 2 * Time.fixedDeltaTime); // first converted to kJ
this.part.AddSkinThermalFlux(heatExcess * 0.7); // some heat added to skin
}

// checks for occlusion by celestial body, uses derived class constructor BPOcclusion
private void IsOccluded(out CelestialBody celestialBody, out bool occluded)
{
Transform transform2; double radiusx2; double radiusy2; double radiusz2;
celestialBody = new CelestialBody(); occluded = false;
for (int x = 0; x < FlightGlobals.Bodies.Count; x++)
{
transform2 = FlightGlobals.Bodies[x].transform;
radiusx2 = FlightGlobals.Bodies[x].Radius;
radiusy2 = FlightGlobals.Bodies[x].Radius;
radiusz2 = FlightGlobals.Bodies[x].Radius;
celestialBody = FlightGlobals.Bodies[x];
BPOcclusion occlusion = new BPOcclusion(transform2, radiusx2, radiusy2, radiusz2, celestialBody);
occluded = occlusion.Raycast(source, dest);
if (occluded == true)
{
break;
}
}
}

// main block of code - runs every physics frame
public void FixedUpdate()
{
frames += 1;
if (frames == 150)
{
vesselFinder.SourceData(out CorrectVesselList, out excessList, out constantList, out targetList, out _);
vesselFinder.SourceData(out CorrectVesselList, out excessList, out constantList, out targetList, out wavelengthList);
frames = 0;
}
if (initFrames < 60)
Expand All @@ -196,7 +178,7 @@ public void FixedUpdate()
double distance = Vector3d.Distance(source, dest);
double spotsize = constant2 * distance;

IsOccluded(out CelestialBody celestial, out bool isOccluded);
occlusion.IsOccluded(source, dest, wavelengthList[counter], out CelestialBody celestial, out bool isOccluded);

// adding EC that has been received
if (recvDiameter < spotsize)
Expand All @@ -209,8 +191,8 @@ public void FixedUpdate()
}
if (isOccluded == true)
{
receivedPower = 0;
state = "Occluded by " + celestial.GetDisplayName();
received_power = 0;
state = "Occluded by " + celestial.GetDisplayName().TrimEnd(Convert.ToChar("N")).TrimEnd(Convert.ToChar("^"));
}

if (HighLogic.CurrentGame.Parameters.CustomParams<BPSettings>().BackgroundProcessing == false)
Expand Down
2 changes: 1 addition & 1 deletion BeamedPowerSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void AddHeatToCore()
double heatModifier = (double)HighLogic.CurrentGame.Parameters.CustomParams<BPSettings>().PercentHeat / 100;
double heatExcess = (1 - Efficiency) * (excess / Efficiency) * heatModifier;
wasteHeat = (float)Math.Round(heatExcess, 1);
coreHeat.AddEnergyToCore(heatExcess * 0.7 * 4 * Time.fixedDeltaTime); // first converted to kJ
coreHeat.AddEnergyToCore(heatExcess * 0.7 * 3 * Time.fixedDeltaTime); // first converted to kJ
part.AddSkinThermalFlux(heatExcess * 0.3); // some heat added to skin
}

Expand Down
6 changes: 3 additions & 3 deletions PhotonSail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PhotonSail : PartModule
Vector3d source; Vector3d dest;
List<Vessel> VesselsList; List<string> targetList;
List<double> excessList; List<double> constantList;
List<string> wavelengthList; int frames; ModuleEnginesFX engines;
List<string> wavelengthList; int frames; ModuleEngines engines;
VesselFinder vesselFinder = new VesselFinder(); AnimationSync animation;
RelativeOrientation rotation = new RelativeOrientation();

Expand All @@ -47,8 +47,8 @@ public void Start()

private void SetEngineParams()
{
this.part.AddModule("ModuleEnginesFX");
engines = this.part.Modules.GetModule<ModuleEnginesFX>();
this.part.AddModule("ModuleEngines");
engines = this.part.Modules.GetModule<ModuleEngines>();
engines.engineID = "BPPS";
engines.minThrust = 0;
engines.throttleLocked = true;
Expand Down
5 changes: 4 additions & 1 deletion Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public class BPSettings : GameParameters.CustomParameterNode
public override string Section { get { return "Beamed Power"; } }
public override string DisplaySection { get { return "Beamed Power"; } }
public override int SectionOrder { get { return 1; } }
public override bool HasPresets { get { return true; } }
public override bool HasPresets { get { return true; } }

[GameParameters.CustomParameterUI("Planetary Occlusion", unlockedDuringMission = false)]
public bool planetOcclusion = true;

[GameParameters.CustomIntParameterUI("Heat modifier %", unlockedDuringMission = false, minValue = 0, maxValue = 100, stepSize = 1)]
public int PercentHeat = 50;
Expand Down
38 changes: 26 additions & 12 deletions UsefulClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,33 @@ public double FractionalFlux(Vector3d source_pos, Vector3d dest_pos, Vessel rece
}
}

// get if receiver is occluded from source by a celestial body
public class BPOcclusion : OccluderHorizonCulling
public class OcclusionData
{
public BPOcclusion(Transform transform1, double radiusx1, double radiusy1, double radiusz1, CelestialBody body1)
: base(transform1, radiusx1, radiusy1, radiusz1)
// checks for occlusion by each celestial body
public void IsOccluded(Vector3d source, Vector3d dest, string wavelength, out CelestialBody celestialBody, out bool occluded)
{
transform = transform1;
radiusXRecip = radiusx1;
radiusYRecip = radiusy1;
radiusZRecip = radiusz1;
invRotation = transform1.rotation.Inverse();
body = body1;
useBody = true;
}
bool planetocclusion = HighLogic.CurrentGame.Parameters.CustomParams<BPSettings>().planetOcclusion;
Transform transform2; double radius2; celestialBody = new CelestialBody(); occluded = new bool();

for (int x = 0; x < FlightGlobals.Bodies.Count; x++)
{
transform2 = FlightGlobals.Bodies[x].transform;
radius2 = FlightGlobals.Bodies[x].Radius;
celestialBody = FlightGlobals.Bodies[x];
radius2 *= (wavelength == "Long") ? 0.7 : 0.9;

OccluderHorizonCulling occlusion = new OccluderHorizonCulling(transform2, radius2, radius2, radius2);
occlusion.Update();
occluded = occlusion.Raycast(source, dest);
if (occluded == true)
{
break;
}
}
if (planetocclusion == false)
{
occluded = false;
}
}
}
}

0 comments on commit 1f8e770

Please sign in to comment.