Skip to content

Commit

Permalink
[survey] Add support for configurable ranges
Browse files Browse the repository at this point in the history
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
  • Loading branch information
taniwha committed Feb 10, 2022
1 parent d1b10df commit 0663eaa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Source/Survey/SurveySkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
31 changes: 29 additions & 2 deletions Source/Survey/SurveyStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 0663eaa

Please sign in to comment.