Skip to content

Commit bfe2acb

Browse files
Merge remote-tracking branch 'origin/1.7.0' into develop
# Conflicts: # src/RemoteTech/API/API.cs # src/RemoteTech/Modules/ModuleRTDataTransmitter.cs # src/RemoteTech/RTCore.cs # src/RemoteTech/RemoteTech.csproj
2 parents e3c1537 + baac6f6 commit bfe2acb

41 files changed

Lines changed: 1902 additions & 226 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
RemoteTechSettings
2+
{
3+
RemoteTechEnabled = True
4+
ConsumptionMultiplier = 1
5+
RangeMultiplier = 1
6+
ActiveVesselGuid = 35b89a0d664c43c6bec8d0840afc97b2
7+
NoTargetGuid = 00000000-0000-0000-0000-000000000000
8+
SpeedOfLight = 3E+08
9+
MapFilter = Omni, Dish, Path
10+
EnableSignalDelay = True
11+
RangeModelType = Standard
12+
MultipleAntennaMultiplier = 0
13+
ThrottleTimeWarp = True
14+
ThrottleZeroOnNoConnection = True
15+
HideGroundStationsBehindBody = True
16+
ControlAntennaWithoutConnection = False
17+
UpgradeableMissionControlAntennas = True
18+
HideGroundStationsOnDistance = True
19+
ShowMouseOverInfoGroundStations = True
20+
AutoInsertKaCAlerts = True
21+
DistanceToHideGroundStations = 3E+07
22+
DishConnectionColor = 0.9960784,0.7019608,0.03137255,1
23+
OmniConnectionColor = 0.5529412,0.5176471,0.4078431,1
24+
ActiveConnectionColor = 0.6588235,1,0.01568628,1
25+
RemoteStationColorDot = 0.996078,0,0,1
26+
GroundStations
27+
{
28+
STATION
29+
{
30+
Guid = 5105f5a9-d628-41c6-ad4b-21154e8fc488
31+
Name = Mission Control
32+
Latitude = -0.131331503391266
33+
Longitude = -74.594841003418
34+
Height = 75
35+
Body = 1
36+
MarkColor = 0.996078,0,0,1
37+
Antennas
38+
{
39+
ANTENNA
40+
{
41+
UpgradeableOmni = 4E+06;3.0E+07;7.5E+07
42+
Dish = 0
43+
CosAngle = 1
44+
}
45+
}
46+
}
47+
}
48+
}
49+

src/RemoteTech/API/API.cs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using RemoteTech.RangeModel;
2+
using RemoteTech.Modules;
23
using RemoteTech.SimpleTypes;
34
using System;
45
using System.Collections.Generic;
@@ -10,6 +11,12 @@ namespace RemoteTech.API
1011
{
1112
public static class API
1213
{
14+
public static bool IsRemoteTechEnabled()
15+
{
16+
if (RTCore.Instance == null) return true;
17+
return false;
18+
}
19+
1320
public static bool HasLocalControl(Guid id)
1421
{
1522
var vessel = RTUtil.GetVesselById(id);
@@ -83,6 +90,66 @@ public static bool HasConnectionToKSC(Guid id)
8390
return connectedToKerbin;
8491
}
8592

93+
public static bool AntennaHasConnection(Part part)
94+
{
95+
if (RTCore.Instance == null) return false;
96+
var antennaModules = part.Modules.OfType<IAntenna>();
97+
98+
return antennaModules.Any(m => m.Connected);
99+
}
100+
101+
public static Guid GetAntennaTarget(Part part) {
102+
ModuleRTAntenna module = part.Modules.OfType<ModuleRTAntenna>().First();
103+
104+
if (module == null)
105+
{
106+
throw new ArgumentException();
107+
}
108+
109+
return module.Target;
110+
}
111+
112+
public static void SetAntennaTarget(Part part, Guid id) {
113+
ModuleRTAntenna module = part.Modules.OfType<ModuleRTAntenna>().First();
114+
115+
if (module == null)
116+
{
117+
throw new ArgumentException();
118+
}
119+
120+
module.Target = id;
121+
}
122+
123+
public static IEnumerable<string> GetGroundStations()
124+
{
125+
return RTSettings.Instance.GroundStations.Select(s => ((ISatellite)s).Name);
126+
}
127+
128+
public static Guid GetGroundStationGuid(String name)
129+
{
130+
MissionControlSatellite groundStation = RTSettings.Instance.GroundStations.Where(station => station.GetName().Equals(name)).FirstOrDefault();
131+
132+
if (groundStation == null)
133+
{
134+
return Guid.Empty;
135+
}
136+
137+
return groundStation.mGuid;
138+
}
139+
140+
public static Guid GetCelestialBodyGuid(CelestialBody celestialBody)
141+
{
142+
return RTUtil.Guid(celestialBody);
143+
}
144+
145+
public static Guid GetNoTargetGuid() {
146+
return new Guid(RTSettings.Instance.NoTargetGuid);
147+
}
148+
149+
public static Guid GetActiveVesselGuid() {
150+
return new Guid(RTSettings.Instance.ActiveVesselGuid);
151+
}
152+
86153
public static double GetShortestSignalDelay(Guid id)
87154
{
88155
if (RTCore.Instance == null) return double.PositiveInfinity;
@@ -127,6 +194,7 @@ public static double GetSignalDelayToSatellite(Guid a, Guid b)
127194
//exposed method called by other mods, passing a ConfigNode to RemoteTech
128195
public static bool QueueCommandToFlightComputer(ConfigNode externalData)
129196
{
197+
if (RTCore.Instance == null) return false;
130198
//check we were actually passed a config node
131199
if (externalData == null) return false;
132200
// check our min values
@@ -176,6 +244,28 @@ public static void InvokeOriginalEvent(BaseEvent e)
176244
{
177245
e.Invoke();
178246
}
247+
}
248+
249+
public static Guid AddGroundStation(string name, double latitude, double longitude, double height, int body)
250+
{
251+
RTLog.Notify ("Trying to add groundstation {0}", RTLogLevel.API, name);
252+
Guid newStationId = RTSettings.Instance.AddGroundStation(name, latitude, longitude, height, body);
253+
254+
return newStationId;
255+
}
256+
257+
public static bool RemoveGroundStation(Guid stationid)
258+
{
259+
RTLog.Notify ("Trying to remove groundstation {0}", RTLogLevel.API, stationid);
260+
261+
// do not allow to remove the default mission control
262+
if (stationid.ToString ("N").Equals ("5105f5a9d62841c6ad4b21154e8fc488"))
263+
{
264+
RTLog.Notify ("Cannot remove KSC Mission Control!", RTLogLevel.API);
265+
return false;
266+
}
267+
268+
return RTSettings.Instance.RemoveGroundStation(stationid);
179269
}
180270
}
181271
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using RemoteTech.SimpleTypes;
2+
using System;
3+
using System.Reflection;
4+
5+
namespace RemoteTech.AddOns
6+
{
7+
/// <summary>
8+
/// This class connects to the KSP-Addon KerbalAlarmClock, created by triggerAU
9+
/// Topic: http://forum.kerbalspaceprogram.com/threads/24786
10+
/// </summary>
11+
public class KerbalAlarmClockAddon : AddOn
12+
{
13+
private bool KaCApiReady = false;
14+
15+
public enum AlarmTypeEnum
16+
{
17+
Raw,
18+
Maneuver,
19+
ManeuverAuto,
20+
Apoapsis,
21+
Periapsis,
22+
AscendingNode,
23+
DescendingNode,
24+
LaunchRendevous,
25+
Closest,
26+
SOIChange,
27+
SOIChangeAuto,
28+
Transfer,
29+
TransferModelled,
30+
Distance,
31+
Crew,
32+
EarthTime,
33+
Contract,
34+
ContractAuto
35+
}
36+
37+
public KerbalAlarmClockAddon()
38+
: base("KerbalAlarmClock", "KerbalAlarmClock.KerbalAlarmClock")
39+
{
40+
// change the bindings
41+
this.bFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod;
42+
if (this.assemblyLoaded)
43+
{
44+
this.loadInstance();
45+
}
46+
}
47+
48+
private void loadInstance()
49+
{
50+
/// load KaC instance
51+
try
52+
{
53+
this.instance = this.assemblyType.GetField("APIInstance", BindingFlags.Public | BindingFlags.Static).GetValue(null);
54+
this.KaCApiReady = (bool)this.assemblyType.GetField("APIReady", BindingFlags.Public | BindingFlags.Static).GetValue(null);
55+
}
56+
catch (Exception ex)
57+
{
58+
RTLog.Verbose("AddOn.loadInstance exception: {0}", RTLogLevel.Assembly, ex);
59+
}
60+
}
61+
62+
/// <summary>
63+
/// Returns the KaC API Status
64+
/// </summary>
65+
public bool APIReady()
66+
{
67+
return this.KaCApiReady;
68+
}
69+
70+
/// <summary>
71+
/// Create a new Alarm
72+
/// </summary>
73+
/// <param name="AlarmType">What type of alarm are we creating</param>
74+
/// <param name="Name">Name of the Alarm for the display</param>
75+
/// <param name="UT">Universal Time for the alarm</param>
76+
/// <returns>ID of the newly created alarm</returns>
77+
public String CreateAlarm(AlarmTypeEnum AlarmType, String Name, Double UT)
78+
{
79+
// Is KaC Ready?
80+
if (!this.APIReady()) return String.Empty;
81+
82+
var result = this.invoke(new System.Object[] { (Int32)AlarmType, Name, UT });
83+
84+
if (result != null) return (String)result;
85+
return String.Empty;
86+
}
87+
88+
/// <summary>
89+
/// Delete Alarm Method for calling via API
90+
/// </summary>
91+
/// <param name="AlarmID">Unique ID of the alarm</param>
92+
/// <returns>Success</returns>
93+
public Boolean DeleteAlarm(String AlarmID)
94+
{
95+
// Is KaC Ready?
96+
if (!this.APIReady()) return false;
97+
98+
var result = this.invoke(new System.Object[] { AlarmID });
99+
100+
if (result != null) return (Boolean)result;
101+
return false;
102+
}
103+
}
104+
}

src/RemoteTech/FlightComputer/Commands/AbstractCommand.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,17 @@ public static ICommand LoadCommand(ConfigNode n, FlightComputer fc)
133133

134134
return command;
135135
}
136+
137+
/// <summary>
138+
/// This method will be triggerd right after the command was enqueued to
139+
/// the flight computer list.
140+
/// </summary>
141+
/// <param name="computer">Current flightcomputer</param>
142+
public virtual void CommandEnqueued(FlightComputer computer) { }
143+
/// <summary>
144+
/// This method will be triggerd after deleting a command from the list.
145+
/// </summary>
146+
/// <param name="computer">Current flight computer</param>
147+
public virtual void CommandCanceled(FlightComputer computer) { }
136148
}
137149
}

src/RemoteTech/FlightComputer/Commands/AttitudeCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public static AttitudeCommand KillRot()
172172
};
173173
}
174174

175-
public static AttitudeCommand ManeuverNode()
175+
public static AttitudeCommand ManeuverNode(double timetoexec = 0)
176176
{
177177
return new AttitudeCommand()
178178
{
@@ -181,7 +181,7 @@ public static AttitudeCommand ManeuverNode()
181181
Frame = ReferenceFrame.Maneuver,
182182
Orientation = Quaternion.identity,
183183
Altitude = Single.NaN,
184-
TimeStamp = RTUtil.GameTime,
184+
TimeStamp = (timetoexec == 0) ? RTUtil.GameTime:timetoexec,
185185
};
186186
}
187187

src/RemoteTech/FlightComputer/Commands/BurnCommand.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class BurnCommand : AbstractCommand
77
[Persistent] public float Throttle;
88
[Persistent] public double Duration;
99
[Persistent] public double DeltaV;
10+
[Persistent] public string KaCItemId = String.Empty;
1011

1112
public override int Priority { get { return 2; } }
1213

@@ -106,5 +107,46 @@ public static BurnCommand WithDeltaV(float throttle, double delta)
106107
TimeStamp = RTUtil.GameTime,
107108
};
108109
}
110+
111+
/// <summary>
112+
/// This method will be triggerd right after the command was enqueued to
113+
/// the flight computer list.
114+
/// </summary>
115+
/// <param name="computer">Current flightcomputer</param>
116+
public override void CommandEnqueued(FlightComputer computer)
117+
{
118+
string KaCAddonLabel = String.Empty;
119+
double timetoexec = (this.TimeStamp + this.ExtraDelay) - 180;
120+
121+
// only insert if we've no negativ time and the option is set
122+
if (timetoexec - RTUtil.GameTime > 0 && RTSettings.Instance.AutoInsertKaCAlerts == true)
123+
{
124+
KaCAddonLabel = "Burn " + computer.Vessel.vesselName + " for ";
125+
126+
if (this.Duration > 0)
127+
KaCAddonLabel += RTUtil.FormatDuration(this.Duration);
128+
else
129+
KaCAddonLabel += this.DeltaV;
130+
131+
if (RTCore.Instance != null && RTCore.Instance.kacAddon != null)
132+
{
133+
this.KaCItemId = RTCore.Instance.kacAddon.CreateAlarm(AddOns.KerbalAlarmClockAddon.AlarmTypeEnum.Raw, KaCAddonLabel, timetoexec);
134+
}
135+
}
136+
}
137+
138+
/// <summary>
139+
/// This method will be triggerd after deleting a command from the list.
140+
/// </summary>
141+
/// <param name="computer">Current flight computer</param>
142+
public override void CommandCanceled(FlightComputer computer)
143+
{
144+
// Cancel also the kac entry
145+
if (this.KaCItemId != String.Empty && RTCore.Instance != null && RTCore.Instance.kacAddon != null)
146+
{
147+
RTCore.Instance.kacAddon.DeleteAlarm(this.KaCItemId);
148+
this.KaCItemId = String.Empty;
149+
}
150+
}
109151
}
110152
}

src/RemoteTech/FlightComputer/Commands/CancelCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ private bool cancelQueuedCommand(Guid cmdGuid, FlightComputer computer)
9999
ICommand searchCmd = computer.QueuedCommands.Where(cmd => cmd.CmdGuid == cmdGuid).FirstOrDefault();
100100
if (searchCmd != null)
101101
{
102+
searchCmd.CommandCanceled(computer);
102103
computer.Remove(searchCmd);
103104
return true;
104105
}

src/RemoteTech/FlightComputer/Commands/ICommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ public interface ICommand : IComparable<ICommand>
2020
///
2121
void Save(ConfigNode n, FlightComputer fc);
2222
bool Load(ConfigNode n, FlightComputer fc);
23+
///
24+
void CommandEnqueued(FlightComputer computer);
25+
void CommandCanceled(FlightComputer computer);
2326
}
2427
}

0 commit comments

Comments
 (0)