From 0663eaab38094957b0f07f969a964085969a0479 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 10 Feb 2022 10:43:29 +0900 Subject: [PATCH] [survey] Add support for configurable ranges The ranges for the survey station can be configured on a per-part basis using the SiteRanges field in the module node. This is just a list of comma-separated ranges in meters. 0 or negative ranges use the default range, missing elements (ie, too few in the list) use the default value for those ranges, excess ranges are ignored, and any parsing error aborts the list leaving unprocessed ranges at their default value. Closes #179 --- Source/Survey/SurveySkill.cs | 2 +- Source/Survey/SurveyStation.cs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Source/Survey/SurveySkill.cs b/Source/Survey/SurveySkill.cs index 607da973..e911f6df 100644 --- a/Source/Survey/SurveySkill.cs +++ b/Source/Survey/SurveySkill.cs @@ -46,7 +46,7 @@ protected override string GetDescription () int exp = Parent.CrewMemberExperienceLevel (6); return String.Format ("{0} can use survey sites out to {1}m.", pronoun, - ELSurveyStation.site_ranges[exp + 2]); + ELSurveyStation.default_site_ranges[exp + 2]); } public int GetValue () diff --git a/Source/Survey/SurveyStation.cs b/Source/Survey/SurveyStation.cs index 478d2591..9293fcfc 100644 --- a/Source/Survey/SurveyStation.cs +++ b/Source/Survey/SurveyStation.cs @@ -43,9 +43,12 @@ public class ELSurveyStation : PartModule, IModuleInfo, IPartMassModifier, ELBui double craft_mass; [KSPField (guiName = "Range", guiActive = true)] float range = 20; - public static float[] site_ranges = { + + public static float[] default_site_ranges = { 20, 50, 100, 200, 400, 800, 1600, 2000 }; + [KSPField] public string SiteRanges; + public float[] site_ranges; public override string GetInfo () { @@ -239,7 +242,7 @@ public Transform PlaceShip (Transform shipTransform, Box vessel_bounds) xform.transform.rotation = points.GetOrientation (); Debug.Log ($"[EL SurveyStation] launchPos {xform.position} {xform.rotation}"); - Vector3 shift = shipTransform.position; + Vector3 shift = shipTransform.position + new Vector3(0, 5, 0); shift += points.ShiftBounds (xform, shift, vessel_bounds); relativeRotaion = shipTransform.rotation; @@ -293,6 +296,9 @@ public override void OnLoad (ConfigNode node) public override void OnAwake () { control = new ELBuildControl (this); + + site_ranges = new float[default_site_ranges.Length]; + Array.Copy (default_site_ranges, site_ranges, site_ranges.Length); } public override void OnStart (PartModule.StartState state) @@ -301,6 +307,27 @@ public override void OnStart (PartModule.StartState state) || state == PartModule.StartState.Editor) { return; } + + if (!String.IsNullOrEmpty (SiteRanges)) { + string[] ranges = ParseExtensions.ParseArray (SiteRanges); + if (ranges != null) { + for (int i = 0; i < ranges.Length && i < site_ranges.Length; i++) { + float v; + if (!float.TryParse (ranges[i], out v)) { + Debug.Log ($"[EL SurveyStation] error parsing site ranges: {ranges[i]}"); + break; + } + if (v <= 0) { + // treat as default + continue; + } + site_ranges[i] = v; + } + } + } + //for (int i = 0; i < site_ranges.Length; i++) { + // Debug.Log ($"[EL SurveyStation] site_ranges[{i}]: {site_ranges[i]}"); + //} control.OnStart (); if (EVARange > 0) { EL_Utils.SetupEVAEvent (Events["ShowRenameUI"], EVARange);