forked from Nivekk/KOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBodyTarget.cs
56 lines (45 loc) · 1.81 KB
/
BodyTarget.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace kOS
{
public class BodyTarget : SpecialValue
{
public ExecutionContext context;
public CelestialBody target;
public BodyTarget(String name, ExecutionContext context) : this(VesselUtils.GetBodyByName(name), context) { }
public BodyTarget(CelestialBody target, ExecutionContext context)
{
this.context = context;
this.target = target;
}
public double GetDistance()
{
return Vector3d.Distance(context.Vessel.GetWorldPos3D(), target.position) - target.Radius;
}
public override object GetSuffix(string suffixName)
{
if (target == null) throw new kOSException("BODY structure appears to be empty!");
if (suffixName == "NAME") return target.name;
if (suffixName == "DESCRIPTION") return target.bodyDescription;
if (suffixName == "MASS") return target.Mass;
if (suffixName == "POSITION") return new Vector(target.position);
if (suffixName == "ALTITUDE") return target.orbit.altitude;
if (suffixName == "APOAPSIS") return target.orbit.ApA;
if (suffixName == "PERIAPSIS") return target.orbit.PeA;
if (suffixName == "VELOCITY") return new Vector(target.orbit.GetVel());
if (suffixName == "DISTANCE") return (float)GetDistance();
if (suffixName == "BODY") return new BodyTarget(target.orbit.referenceBody, context);
return base.GetSuffix(suffixName);
}
public override string ToString()
{
if (target != null)
{
return "BODY(\"" + target.name + "\")";
}
return base.ToString();
}
}
}