forked from theSpeare/RoverScience-Revisit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rover.cs
141 lines (104 loc) · 4.24 KB
/
Rover.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections.Generic;
namespace RoverScience
{
public class Rover
{
public System.Random rand = new System.Random();
public ScienceSpot scienceSpot;
public LandingSpot landingSpot;
public Coords location = new Coords ();
public double distanceTraveled = 0;
public double distanceCheck = 20;
public double distanceTraveledTotal = 0;
public int minRadius = 40;
public int maxRadius = 100;
public List<string> anomaliesAnalyzed = new List<string>();
public Anomalies.Anomaly closestAnomaly = new Anomalies.Anomaly();
public double DistanceFromLandingSpot
=> GeomLib.GetDistanceBetweenTwoPoints (Vessel.mainBody, location, landingSpot.location);
public double DistanceFromScienceSpot
=> GeomLib.GetDistanceBetweenTwoPoints(Vessel.mainBody, location, scienceSpot.location);
public double BearingToScienceSpot
=> GeomLib.GetBearingFromCoords(scienceSpot.location, location);
Vessel Vessel => FlightGlobals.ActiveVessel;
public double Heading => GeomLib.GetRoverHeading (Vessel);
public bool ScienceSpotReached
=> (scienceSpot.established && DistanceFromScienceSpot <= scienceSpot.minDistance);
public bool AnomalySpotReached
=> (scienceSpot.established && DistanceToClosestAnomaly <= scienceSpot.minDistance);
public bool AnomalyPresent
=> ((DistanceToClosestAnomaly <= 100) && !Anomalies.Instance.HasCurrentAnomalyBeenAnalyzed());
public int NumberWheelsLanded => GetWheelsLanded();
public int NumberWheels => GetWheelCount();
public bool ValidStatus => CheckRoverValidStatus();
public double DistanceToClosestAnomaly
{
get
{
if (location == null)
Utilities.LogVerbose("location == null in DistanceToClosestAnomaly");
if (closestAnomaly == null)
Utilities.LogVerbose("closestAnomaly == null in DistanceToClosestAnomaly");
if (Vessel == null)
Utilities.LogVerbose("Vessel == null in DistanceToClosestAnomaly");
return GeomLib.GetDistanceBetweenTwoPoints(Vessel.mainBody, location, closestAnomaly.location);
}
}
public void CalculateDistanceTraveled(double deltaTime)
{
distanceTraveled += (RoverScience.Instance.vessel.srfSpeed) * deltaTime;
if (!scienceSpot.established) distanceTraveledTotal += (RoverScience.Instance.vessel.srfSpeed) * deltaTime;
}
public void SetRoverLocation()
{
location.latitude = Vessel.latitude;
location.longitude = Vessel.longitude;
}
public void ResetDistanceTraveled()
{
distanceTraveled = 0;
}
private bool CheckRoverValidStatus()
{
// Checks if rover is landed with at least one wheel on with no time-warp.
return ((TimeWarp.CurrentRate == 1) && (Vessel.horizontalSrfSpeed > (double)0.01) && (NumberWheelsLanded > 0));
}
private int GetWheelCount()
{
int wheelCount = 0;
List<Part> vesselParts = FlightGlobals.ActiveVessel.Parts;
foreach (Part part in vesselParts) {
foreach (PartModule module in part.Modules) {
if (module.moduleName == "ModuleWheelBase") {
wheelCount++;
}
}
}
return wheelCount;
}
private int GetWheelsLanded()
{
int count = 0;
List<Part> vesselParts = FlightGlobals.ActiveVessel.Parts;
foreach (Part part in vesselParts) {
foreach (PartModule module in part.Modules) {
if ((module.moduleName.IndexOf("wheel", StringComparison.OrdinalIgnoreCase) >= 0)) {
if (part.GroundContact)
{
count++;
}
}
}
}
return count;
}
//List<Anomalies.Anomaly> anomaliesList = new List<Anomalies.Anomaly>();
public void SetClosestAnomaly()
{
// this is run on establishing landing spot (to avoid expensive constant foreach loops
SetRoverLocation(); // (update rover location)
closestAnomaly = Anomalies.Instance.ClosestAnomaly(Vessel, Vessel.mainBody.bodyName);
}
}
}