forked from Nivekk/KOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVesselTarget.cs
More file actions
59 lines (49 loc) · 1.5 KB
/
VesselTarget.cs
File metadata and controls
59 lines (49 loc) · 1.5 KB
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
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace kOS
{
public class VesselTarget : SpecialValue
{
public ExecutionContext context;
public Vessel target;
public VesselTarget(Vessel target, ExecutionContext context)
{
this.context = context;
this.target = target;
}
public bool IsInRange(double range)
{
if (GetDistance() <= range) return true;
return false;
}
public double GetDistance()
{
return Vector3d.Distance(context.Vessel.GetWorldPos3D(), target.GetWorldPos3D());
}
public override string ToString()
{
return "VESSEL(\"" + target.vesselName + "\")";
}
public override object GetSuffix(string suffixName)
{
if (suffixName == "DISTANCE") return (float)GetDistance();
if (suffixName == "DIRECTION")
{
var vector = (target.GetWorldPos3D() - context.Vessel.GetWorldPos3D());
return new Direction(vector, false);
}
if (suffixName == "BEARING")
{
return VesselUtils.GetTargetBearing(context.Vessel, target);
}
if (suffixName == "HEADING")
{
return VesselUtils.GetTargetHeading(context.Vessel, target);
}
return base.GetSuffix(suffixName);
}
}
}