diff --git a/BeamedPowerReceiver.cs b/BeamedPowerReceiver.cs index cb46876..14c7cd6 100644 --- a/BeamedPowerReceiver.cs +++ b/BeamedPowerReceiver.cs @@ -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 CorrectVesselList; List excessList; List constantList; List targetList; + List wavelenghtList; public void Start() { @@ -54,6 +55,7 @@ public void Start() excessList = new List(); constantList = new List(); targetList = new List(); + wavelenghtList = new List(); wavelength_ui = "Long"; animation = new AnimationSync(); SetHeatParams(); @@ -127,7 +129,7 @@ private void AddHeatToCore() double heatModifier = (double)HighLogic.CurrentGame.Parameters.CustomParams().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 } @@ -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) @@ -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); + } } } } diff --git a/BeamedPowerReceiverDirectional.cs b/BeamedPowerReceiverDirectional.cs index 99200f5..338d630 100644 --- a/BeamedPowerReceiverDirectional.cs +++ b/BeamedPowerReceiverDirectional.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using UnityEngine; +using CommNet.Occluders; namespace BeamedPowerStandalone { @@ -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 CorrectVesselList; List excessList; List constantList; List targetList; + List wavelengthList; [KSPField(isPersistant = true)] public int counter = 0; @@ -61,6 +63,7 @@ public void Start() excessList = new List(); constantList = new List(); targetList = new List(); + wavelengthList = new List(); wavelength_ui = "Long"; animation = new AnimationSync(); SetEngineParams(); @@ -141,38 +144,17 @@ private void AddHeatToCore() double heatModifier = (double)HighLogic.CurrentGame.Parameters.CustomParams().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) @@ -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) @@ -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().BackgroundProcessing == false) diff --git a/BeamedPowerSource.cs b/BeamedPowerSource.cs index df76579..90055d4 100644 --- a/BeamedPowerSource.cs +++ b/BeamedPowerSource.cs @@ -136,7 +136,7 @@ private void AddHeatToCore() double heatModifier = (double)HighLogic.CurrentGame.Parameters.CustomParams().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 } diff --git a/PhotonSail.cs b/PhotonSail.cs index 156e377..d9f35db 100644 --- a/PhotonSail.cs +++ b/PhotonSail.cs @@ -29,7 +29,7 @@ public class PhotonSail : PartModule Vector3d source; Vector3d dest; List VesselsList; List targetList; List excessList; List constantList; - List wavelengthList; int frames; ModuleEnginesFX engines; + List wavelengthList; int frames; ModuleEngines engines; VesselFinder vesselFinder = new VesselFinder(); AnimationSync animation; RelativeOrientation rotation = new RelativeOrientation(); @@ -47,8 +47,8 @@ public void Start() private void SetEngineParams() { - this.part.AddModule("ModuleEnginesFX"); - engines = this.part.Modules.GetModule(); + this.part.AddModule("ModuleEngines"); + engines = this.part.Modules.GetModule(); engines.engineID = "BPPS"; engines.minThrust = 0; engines.throttleLocked = true; diff --git a/Settings.cs b/Settings.cs index 8a954e4..6565b7b 100644 --- a/Settings.cs +++ b/Settings.cs @@ -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; diff --git a/UsefulClasses.cs b/UsefulClasses.cs index e49121a..5bdfb4a 100644 --- a/UsefulClasses.cs +++ b/UsefulClasses.cs @@ -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().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; + } + } } }