public string Scan(Vessel ves, CelestialBody targetBody, double objectiveDiam, double FOV, float timeStep) { string results = ""; double angRes = 1.22d * Wavelength / objectiveDiam; double targetAngularSize = 2d * Math.Atan((targetBody.Radius * 2d) / (2d * Vector3d.Distance(ves.GetWorldPos3D(), targetBody.position))); double clampedTargetSize = MathExtensions.Clamp(targetAngularSize, 0d, FOV); double pxSize = clampedTargetSize / angRes; if (targetAngularSize < angRes) { results = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustTelescope_Field_Instrument_OutOfRange", targetBody.bodyDisplayName); } else { float atmosphereScale = 0f; if (ves.atmDensity > 0.00001) { atmosphereScale = (float)(Utils.CalculateAirMass(ves, targetBody) * ves.mainBody.atmosphereDepth * ves.mainBody.atmDensityASL); } float toDiscover = (float)(pxSize * Settings.BaseTelescopeDiscoverRate * Sensitivity / 100f * AtmosphereEffect.Evaluate((float)atmosphereScale)); if (Discovers) { SpaceDustScenario.Instance.AddDiscoveryAtBody(ResourceName, targetBody, toDiscover * timeStep); } if (Identifies) { SpaceDustScenario.Instance.AddIdentifyAtBody(ResourceName, targetBody, toDiscover * timeStep); } results = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustTelescope_Field_Instrument_Scanning", (toDiscover).ToString("F3")); } return(results); }
void DoFocusedHarvesting(double scale) { if (HarvestType == HarvesterType.Atmosphere && part.vessel.atmDensity > 0d) { if (part.vessel.atmDensity <= 0d) { ScoopUI = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_NeedsAtmo"); Fields["ThermalUI"].guiActive = false; Fields["IntakeSpeed"].guiActive = false; return; } Vector3d worldVelocity = part.vessel.srf_velocity; double mach = part.vessel.mach; Vector3 intakeVector; Transform intakeTransform; if (HarvestIntakeTransform == null) { intakeTransform = this.transform; } else { intakeTransform = HarvestIntakeTransform; } if (CheckOcclusion && Physics.Raycast(intakeTransform.position, intakeTransform.forward, RaycastDistance)) { ScoopUI = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_Blocked"); Fields["ThermalUI"].guiActive = false; Fields["IntakeSpeed"].guiActive = false; return; } intakeVector = intakeTransform.forward; double dot = Vector3d.Dot(worldVelocity, intakeVector); float intakeVolume = (float)(worldVelocity.magnitude * MathExtensions.Clamp(dot, 0d, 1d) * IntakeVelocityScale.Evaluate((float)mach) + IntakeSpeedStatic) * IntakeArea; IntakeSpeed = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_IntakeSpeed_Normal", Utils.ToSI(intakeVolume, "G2")); ScoopUI = ""; for (int i = 0; i < resources.Count; i++) { double resourceSample = SpaceDustResourceMap.Instance.SampleResource(resources[i].Name, part.vessel.mainBody, vessel.altitude + part.vessel.mainBody.Radius, vessel.latitude, vessel.longitude); if (resourceSample > resources[i].MinHarvestValue) { double resAmt = resourceSample * intakeVolume * 1d / resources[i].density * resources[i].BaseEfficiency * scale; if (ScoopUI != "") { ScoopUI += "\n"; } ScoopUI += Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_Resource", resources[i].Name, resAmt.ToString("G5")); part.RequestResource(resources[i].Name, -resAmt * TimeWarp.fixedDeltaTime, ResourceFlowMode.ALL_VESSEL, false); } } if (ScoopUI == "") { ScoopUI = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_Resource_None"); } } if (HarvestType == HarvesterType.Exosphere && part.vessel.atmDensity == 0d) { if (part.vessel.atmDensity > 0d) { ScoopUI = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_NeedsVacuum"); Fields["ThermalUI"].guiActive = false; Fields["IntakeSpeed"].guiActive = false; return; } double orbitSpeedAtAlt = Math.Sqrt(part.vessel.mainBody.gravParameter / (part.vessel.altitude + part.vessel.mainBody.Radius)); Vector3d worldVelocity = part.vessel.obt_velocity; Vector3 intakeVector; if (HarvestIntakeTransform == null) { intakeVector = this.transform.forward; } else { intakeVector = HarvestIntakeTransform.forward; } double dot = Vector3d.Dot(worldVelocity.normalized, intakeVector.normalized); float intakeVolume = (float)(worldVelocity.magnitude * MathExtensions.Clamp(dot, 0d, 1d) + IntakeSpeedStatic) * IntakeArea; IntakeSpeed = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_IntakeSpeed_Normal", intakeVolume.ToString("G2")); ScoopUI = ""; for (int i = 0; i < resources.Count; i++) { double resourceSample = SpaceDustResourceMap.Instance.SampleResource(resources[i].Name, part.vessel.mainBody, vessel.altitude + part.vessel.mainBody.Radius, vessel.latitude, vessel.longitude); if (resourceSample * intakeVolume * resources[i].BaseEfficiency > resources[i].MinHarvestValue) { double resAmt = resourceSample * intakeVolume * 1d / resources[i].density * resources[i].BaseEfficiency * scale; if (ScoopUI != "") { ScoopUI += "\n"; } ScoopUI += Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_Resource", resources[i].Name, resAmt.ToString("G3")); part.RequestResource(resources[i].Name, -resAmt * TimeWarp.fixedDeltaTime, ResourceFlowMode.ALL_VESSEL, false); } } if (ScoopUI == "") { ScoopUI = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_Resource_None"); } } }
public void Process(float timeStep) { // Utils.Log($"[SpaceDustHarvesterBackground]: tring to harvest {harvester.resources.Count} resources"); //Utils.Log($"[SpaceDustHarvesterBackground]: type {harvester.HarvestType}, density {ves.mainBody.GetPressureAtm(ves.altitude)}, Vsrf {ves.srf_velocity}"); if (bool.Parse(protoMiner.moduleValues.GetValue("Enabled"))) { if (harvester.HarvestType == HarvesterType.Atmosphere && ves.mainBody.GetPressureAtm(ves.altitude) > 0.0001d) { Vector3d worldVelocity = ves.srf_velocity; double mach = ves.mach; double dot = 1.0d; float intakeVolume = (float)(worldVelocity.magnitude * MathExtensions.Clamp(dot, 0d, 1d) * harvester.IntakeVelocityScale.Evaluate((float)mach) + harvester.IntakeSpeedStatic) * harvester.IntakeArea; for (int i = 0; i < harvester.resources.Count; i++) { double resourceSample = SpaceDustResourceMap.Instance.SampleResource(harvester.resources[i].Name, ves.mainBody, ves.altitude + ves.mainBody.Radius, ves.latitude, ves.longitude); if (resourceSample > harvester.resources[i].MinHarvestValue) { double resAmt = resourceSample * intakeVolume * harvester.resources[i].BaseEfficiency * timeStep; foreach (ProtoPartSnapshot p in ves.protoVessel.protoPartSnapshots) { foreach (ProtoPartResourceSnapshot r in p.resources) { if (r.amount < r.maxAmount + resAmt) { r.amount = r.amount + resAmt; resAmt = 0d; } else if (r.amount < r.maxAmount) { resAmt = resAmt - (r.maxAmount - r.amount); r.amount = r.maxAmount; } } } } } } if (harvester.HarvestType == HarvesterType.Exosphere && ves.mainBody.GetPressureAtm(ves.altitude) < 0.0001d) { Vector3d worldVelocity = ves.obt_velocity; double mach = ves.mach; double dot = 1d; float intakeVolume = (float)(worldVelocity.magnitude * MathExtensions.Clamp(dot, 0d, 1d) + harvester.IntakeSpeedStatic) * harvester.IntakeArea; for (int i = 0; i < harvester.resources.Count; i++) { double resourceSample = SpaceDustResourceMap.Instance.SampleResource(harvester.resources[i].Name, ves.mainBody, ves.altitude + ves.mainBody.Radius, ves.latitude, ves.longitude); if (resourceSample > harvester.resources[i].MinHarvestValue) { double resAmt = resourceSample * intakeVolume * harvester.resources[i].BaseEfficiency * timeStep; foreach (ProtoPartSnapshot p in ves.protoVessel.protoPartSnapshots) { foreach (ProtoPartResourceSnapshot r in p.resources) { if (r.amount < r.maxAmount + resAmt) { r.amount = r.amount + resAmt; resAmt = 0d; } else if (r.amount < r.maxAmount) { resAmt = resAmt - (r.maxAmount - r.amount); r.amount = r.maxAmount; } } } } } } } }
public void Process(float timeStep) { // Utils.Log($"[SpaceDustHarvesterBackground]: tring to harvest {harvester.resources.Count} resources"); //Utils.Log($"[SpaceDustHarvesterBackground]: type {harvester.HarvestType}, density {ves.mainBody.GetPressureAtm(ves.altitude)}, Vsrf {ves.srf_velocity}"); if (bool.Parse(protoMiner.moduleValues.GetValue("Enabled"))) { if (harvester.HarvestType == HarvesterType.Atmosphere && ves.mainBody.GetPressureAtm(ves.altitude) > 0.000d) { Vector3d worldVelocity = ves.srf_velocity; double mach = ves.mach; double dot = 1.0d; float intakeVolume = (float)(worldVelocity.magnitude * MathExtensions.Clamp(dot, 0d, 1d) * harvester.IntakeVelocityScale.Evaluate((float)mach) + harvester.IntakeSpeedStatic) * harvester.IntakeArea; for (int i = 0; i < harvester.resources.Count; i++) { double resourceSample = SpaceDustResourceMap.Instance.SampleResource(harvester.resources[i].Name, ves.mainBody, ves.altitude + ves.mainBody.Radius, ves.latitude, ves.longitude); if (resourceSample > harvester.resources[i].MinHarvestValue) { double amountToAdd = resourceSample * intakeVolume * harvester.resources[i].BaseEfficiency * timeStep; AddBackgroundResources(ves.protoVessel, harvester.resources[i].Name, amountToAdd); } } } if (harvester.HarvestType == HarvesterType.Exosphere && ves.mainBody.GetPressureAtm(ves.altitude) == 0d) { Vector3d worldVelocity = ves.orbitDriver.vel; double dot = 1d; float intakeVolume = (float)(worldVelocity.magnitude * MathExtensions.Clamp(dot, 0d, 1d) + harvester.IntakeSpeedStatic) * harvester.IntakeArea; for (int i = 0; i < harvester.resources.Count; i++) { double resourceSample = SpaceDustResourceMap.Instance.SampleResource(harvester.resources[i].Name, ves.mainBody, ves.altitude + ves.mainBody.Radius, ves.latitude, ves.longitude); if (resourceSample >= harvester.resources[i].MinHarvestValue) { double amountToAdd = resourceSample * intakeVolume * 1d / harvester.resources[i].density * harvester.resources[i].BaseEfficiency * timeStep; //Utils.Log($"[SpaceDustHarvesterBackground] sampled {harvester.resources[i].Name} @ {resourceSample}, " + //$"minH {harvester.resources[i].MinHarvestValue}," + //$"effic {harvester.resources[i].BaseEfficiency}," + //$"volume {intakeVolume}," + //$"area {harvester.IntakeArea}," + //$"speedstatic {harvester.IntakeSpeedStatic}," + //$"worldvel {worldVelocity.magnitude}"); //Utils.Log($"[SpaceDustHarvesterBackground] sampled {harvester.resources[i].Name} @ {resourceSample}. Harvesting {amountToAdd} at step {timeStep}"); AddBackgroundResources(ves.protoVessel, harvester.resources[i].Name, amountToAdd); } } } } }