Skip to content

Commit

Permalink
support for KerbNet only installs and future reflection.
Browse files Browse the repository at this point in the history
  • Loading branch information
GER-Space committed Oct 27, 2016
1 parent 7c4df64 commit 19ec59f
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 33 deletions.
81 changes: 48 additions & 33 deletions KOS-Scansat/Addon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using kOS.Suffixed;
using UnityEngine;
using SCANsat;
//using SCANsat;
using System.Reflection;

using kOS.Safe.Encapsulation;
Expand All @@ -25,8 +25,6 @@ public override BooleanValue Available()
private void InitializeSuffixes()
{

if (IsModInstalled("scansat"))
{
AddSuffix("CURRENTBIOME", new kOS.Safe.Encapsulation.Suffixes.NoArgsSuffix<StringValue>(GetCurrentBiome, "Get Name of current Biome"));
AddSuffix(new[] { "GETBIOME", "BIOMEAT" }, new kOS.Safe.Encapsulation.Suffixes.TwoArgsSuffix<StringValue, BodyTarget, GeoCoordinates>(GetBiomeAt, "Get Name of Biome of Body,GeoCoordinates"));
AddSuffix("ELEVATION", new kOS.Safe.Encapsulation.Suffixes.TwoArgsSuffix<ScalarDoubleValue, BodyTarget, GeoCoordinates>(GetAltAtSuffix, "Get scanned altitude of Body,GeoCoordinates"));
Expand All @@ -36,24 +34,31 @@ private void InitializeSuffixes()
AddSuffix("RESOURCEAT", new kOS.Safe.Encapsulation.Suffixes.VarArgsSuffix<ScalarDoubleValue, Structure>(GetResourceByName, "Returns the amount of a resource by its scan type: Body,GeoCoordinates,scantype"));
AddSuffix("SLOPE", new kOS.Safe.Encapsulation.Suffixes.TwoArgsSuffix<ScalarDoubleValue, BodyTarget, GeoCoordinates>(GetSlope, "Returns the most accurate slope of the location"));
AddSuffix("GETCOVERAGE", new kOS.Safe.Encapsulation.Suffixes.TwoArgsSuffix<ScalarDoubleValue, BodyTarget, StringValue>(GetCoverage, "Returns completen percatage of a body,scantype"));
}


SCANWrapper = new SCANWrapper();
if (IsModInstalled("scansat"))
{
SCANWrapper.InitReflection();
}
}

internal SCANWrapper SCANWrapper;

#region suffix_functions
///<summary>
///returns the amount of a given resource for a body and place
/// takes the args <body> <geocoordinates> and <resource-string> in any order
///</summary>
public ScalarDoubleValue GetResourceByName(params Structure[] args )
///<summary>
///returns the amount of a given resource for a body and place
/// takes the args <body> <geocoordinates> and <resource-string> in any order
///</summary>
public ScalarDoubleValue GetResourceByName(params Structure[] args )
{
if (args.Length != 3 ) { return null; }
BodyTarget body = args.Where(s => s.GetType() == typeof(BodyTarget)).Cast<BodyTarget>().First();
// BodyTarget body = args[0] as BodyTarget;
GeoCoordinates coordinate = args.Where(s => s.GetType() == typeof(GeoCoordinates)).Cast<GeoCoordinates>().First();
StringValue s_type = args.Where(s => s.GetType() == typeof(StringValue)).Cast<StringValue>().First();

if ( (SCANUtil.isCovered(coordinate.Longitude, coordinate.Latitude, body.Body, SCANUtil.GetSCANtype(s_type))) || ((HasKerbNet("Resource") && (IsInKerbNetFoV(body.Body, coordinate.Longitude, coordinate.Latitude)))) )
if ( (SCANWrapper.IsCovered(coordinate.Longitude, coordinate.Latitude, body.Body, s_type)) || ((HasKerbNet("Resource") && (IsInKerbNetFoV(body.Body, coordinate.Longitude, coordinate.Latitude)))) )

{
float amount = 0f;
Expand All @@ -65,7 +70,7 @@ public ScalarDoubleValue GetResourceByName(params Structure[] args )
ResourceName = s_type,
ResourceType = HarvestTypes.Planetary,
Altitude = 0,
CheckForLock = SCANcontroller.controller.resourceBiomeLock,
CheckForLock = SCANWrapper.GetResourceBiomeLock(),
BiomeName = ScienceUtil.GetExperimentBiome(body.Body, coordinate.Latitude, coordinate.Longitude),
ExcludeVariance = false,
};
Expand All @@ -86,14 +91,17 @@ public ScalarDoubleValue GetResourceByName(params Structure[] args )
public ListValue GetScans(BodyTarget body, GeoCoordinates coordinate)
{
ListValue scans = new ListValue();
foreach (string s_type in Enum.GetNames(typeof(SCANtype)))
{
if (CheckScanBlacklisted(s_type)) { continue; }
if (SCANUtil.isCovered(coordinate.Longitude, coordinate.Latitude, body.Body, SCANUtil.GetSCANtype(s_type)))
{
scans.Add(new StringValue(s_type));
}
}
if (IsModInstalled("scansat"))
{
foreach (string s_type in Enum.GetNames(typeof(SCANtype)))
{
if (CheckScanBlacklisted(s_type)) { continue; }
if (SCANWrapper.IsCovered(coordinate.Longitude, coordinate.Latitude, body.Body, s_type))
{
scans.Add(new StringValue(s_type));
}
}
}
return scans;
}

Expand All @@ -104,9 +112,13 @@ public ListValue GetScans(BodyTarget body, GeoCoordinates coordinate)
public ListValue GetResourceNames()
{
ListValue resources = new ListValue();
foreach (SCANresourceGlobal res in SCANcontroller.setLoadedResourceList() ) {
resources.Add(new StringValue(res.Name));
}
if (IsModInstalled("scansat"))
{
foreach (SCANresourceGlobal res in SCANWrapper.GetLoadedResourceList())
{
resources.Add(new StringValue(res.Name));
}
}
return resources;
}

Expand All @@ -116,11 +128,14 @@ public ListValue GetResourceNames()
public ListValue GetScanNames()
{
ListValue allscans = new ListValue();
foreach (string s_type in Enum.GetNames(typeof(SCANtype)))
{
if (CheckScanBlacklisted(s_type)) { continue; }
allscans.Add(new StringValue(s_type));
}
if (IsModInstalled("scansat"))
{
foreach (string s_type in Enum.GetNames(typeof(SCANtype)))
{
if (CheckScanBlacklisted(s_type)) { continue; }
allscans.Add(new StringValue(s_type));
}
}
return allscans;
}

Expand All @@ -135,7 +150,7 @@ public StringValue GetCurrentBiome()
var Biome = "";

// check if we have crew onboard, which can look outside of a window, to determinate where we are or have we kerbnet access
if ( (HasKerbNet("Biome")) || (vessel.GetCrewCount() > 0) )
if ( (HasKerbNet("Biome")) || (vessel.GetCrewCount() > 0) || (SCANWrapper.IsCovered(vessel.longitude, vessel.latitude, body, "Biome")) )
{
Biome = string.IsNullOrEmpty(vessel.landedAt)
? ScienceUtil.GetExperimentBiome(body, vessel.latitude, vessel.longitude)
Expand Down Expand Up @@ -172,7 +187,7 @@ public ScalarDoubleValue GetAltAtSuffix(BodyTarget body, GeoCoordinates coordina
///</summary>
public ScalarDoubleValue GetCoverage(BodyTarget body, StringValue scantype)
{
return SCANUtil.GetCoverage(SCANUtil.GetSCANtype(scantype),body.Body);
return SCANWrapper.GetCoverage(scantype,body.Body);
}

///<summary>
Expand All @@ -187,7 +202,7 @@ public ScalarDoubleValue GetSlope(BodyTarget bodytgt, GeoCoordinates coordinate)
double lat = coordinate.Latitude;
CelestialBody body = bodytgt.Body;

if ( (SCANUtil.isCovered(lon, lat, body, SCANUtil.GetSCANtype("AltimetryHiRes"))) || ( (HasKerbNet("Terrain") && (IsInKerbNetFoV(body,lon,lat))) ) )
if ( (SCANWrapper.IsCovered(lon, lat, body, "AltimetryHiRes")) || ( (HasKerbNet("Terrain") && (IsInKerbNetFoV(body,lon,lat))) ) )
{
offsetm = 5;
}
Expand Down Expand Up @@ -315,7 +330,7 @@ internal bool IsInKerbNetFoV(CelestialBody body,double lng, double lat)
///</summary>
internal string GetScannedBiomeName(CelestialBody body,double lng, double lat)
{
if ( (SCANUtil.isCovered(lng,lat,body, SCANUtil.GetSCANtype("Biome"))) || ( (HasKerbNet("Biome")) && (IsInKerbNetFoV(body,lng,lat)) ) )
if ( (SCANWrapper.IsCovered(lng,lat,body, "Biome")) || ( (HasKerbNet("Biome")) && (IsInKerbNetFoV(body,lng,lat)) ) )
{
return ScienceUtil.GetExperimentBiome(body, lat, lng);
} else
Expand All @@ -333,12 +348,12 @@ internal double GetAltAt(CelestialBody body, double lon, double lat)
{
double altitude = -1;

if ( (SCANUtil.isCovered(lon, lat, body, SCANUtil.GetSCANtype("AltimetryHiRes"))) || ( (HasKerbNet("Terrain")) && (IsInKerbNetFoV(body,lon,lat)) ) )
if ( (SCANWrapper.IsCovered(lon, lat, body, "AltimetryHiRes")) || ( (HasKerbNet("Terrain")) && (IsInKerbNetFoV(body,lon,lat)) ) )
{
altitude = GetElevation(body, lon, lat);
return altitude;
}
if (SCANUtil.isCovered(lon, lat, body, SCANUtil.GetSCANtype("AltimetryLoRes")))
if (SCANWrapper.IsCovered(lon, lat, body, "AltimetryLoRes"))
{
double alt = GetElevation(body, lon, lat);
altitude = (Math.Round(alt / 500)) * 500;
Expand Down
1 change: 1 addition & 0 deletions KOS-Scansat/KOS-Scansat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<ItemGroup>
<Compile Include="Addon.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SCANWrapper.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
67 changes: 67 additions & 0 deletions KOS-Scansat/SCANWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCANsat;
using SCANsat.SCAN_Data;

namespace kOS.AddOns.kOSSCANsat
{


public class SCANWrapper
{
public SCANWrapper instance;

internal bool scansatinstalled;
public SCANWrapper()
{
instance = this;
scansatinstalled = Addon.IsModInstalled("scansat");
}
public void InitReflection()
{
//for future use
}

public int GetSCANtype(string s_type)
{
return SCANUtil.GetSCANtype(s_type);
}

public bool GetResourceBiomeLock()
{
bool resourcelock = true;
if (scansatinstalled)
{
resourcelock = SCANUtil.resourceBiomeLockEnabled();
}
return resourcelock;
}

public bool IsCovered(double lon, double lat, CelestialBody body, string scan_type) {
bool iscovered = false;
if (scansatinstalled) {
iscovered = SCANUtil.isCovered(lon, lat, body, SCANUtil.GetSCANtype(scan_type));
}
return iscovered;
}

public double GetCoverage(string scantype, CelestialBody body)
{
double completed = 0d;
if (scansatinstalled)
{
completed = SCANUtil.GetCoverage(SCANUtil.GetSCANtype(scantype), body);
}
return completed;
}

public List<SCANresourceGlobal> GetLoadedResourceList()
{
return SCANcontroller.setLoadedResourceList();
}


}
}

0 comments on commit 19ec59f

Please sign in to comment.