Skip to content

Commit 2dc7e29

Browse files
committed
Merge pull request #1 from RemoteTechnologiesGroup/master
Merging 1.6.2 in
2 parents 1c9b0df + cadfe12 commit 2dc7e29

16 files changed

+301
-64
lines changed

CHANGES.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1+
Version 1.6.1
2+
========================================
3+
Released January 19, 2015
4+
5+
Bug Fixes:
6+
--------------------
7+
* Fix for the calculation of the manual delay after switching to the vessel with saved commands
8+
* The disappeared satellite switcher on the map view (middle right) will now displayed correctly
9+
* The attitude action-buttons now shows you the current flight mode
10+
* Fix for the stopped timer of commands after a maneuver command
11+
12+
113
Version 1.6.0
214
========================================
3-
Released January 11, 2014
15+
Released January 11, 2015
416

517
Features:
618
--------------------

GameData/RemoteTech/RemoteTech.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"VERSION":{
1212
"MAJOR":1,
1313
"MINOR":6,
14-
"PATCH":0,
14+
"PATCH":1,
1515
"BUILD":0
1616
},
1717
"KSP_VERSION":{

src/RemoteTech/FlightComputer/Commands/AbstractCommand.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public virtual void Save(ConfigNode n, FlightComputer fc)
5151
}
5252
catch (Exception) {}
5353

54+
if (Delay == 0) {
55+
// only save the current gametime if we have no signal delay.
56+
// We need this to calculate the correct delta time for the
57+
// ExtraDelay if we come back to this satellite.
58+
TimeStamp = RTUtil.GameTime;
59+
}
60+
5461
save.AddValue("TimeStamp", TimeStamp);
5562
save.AddValue("ExtraDelay", ExtraDelay);
5663
n.AddNode(save);

src/RemoteTech/FlightComputer/Commands/AttitudeCommand.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,16 @@ public static AttitudeCommand WithSurface(double pitch, double yaw, double roll)
226226
TimeStamp = RTUtil.GameTime,
227227
};
228228
}
229+
230+
/// <summary>
231+
/// Convert this AttitudeCommand values to a ComputerMode
232+
/// </summary>
233+
public SimpleTypes.ComputerModeMapper mapFlightMode()
234+
{
235+
SimpleTypes.ComputerModeMapper computerMode = new SimpleTypes.ComputerModeMapper();
236+
computerMode.mapFlightMode(Mode,Attitude,Frame);
237+
238+
return computerMode;
239+
}
229240
}
230241
}

src/RemoteTech/FlightComputer/Commands/ManeuverCommand.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public override bool Execute(FlightComputer f, FlightCtrlState fcs)
7777
RemainingDelta -= thrustToMass * TimeWarp.deltaTime;
7878
return false;
7979
}
80-
f.Enqueue(AttitudeCommand.Off(), true, true, true);
80+
f.Enqueue(AttitudeCommand.KillRot(), true, true, true);
8181
return true;
8282
}
8383

@@ -106,7 +106,6 @@ public static ManeuverCommand WithNode(int nodeIndex, FlightComputer f)
106106
var newNode = new ManeuverCommand()
107107
{
108108
Node = node,
109-
NodeIndex = nodeIndex,
110109
TimeStamp = node.UT - advance,
111110
};
112111
return newNode;
@@ -122,11 +121,29 @@ public override void Load(ConfigNode n, FlightComputer fc)
122121
base.Load(n,fc);
123122
if(n.HasValue("NodeIndex"))
124123
{
125-
int nodeIndex = int.Parse(n.GetValue("NodeIndex"));
126-
RTLog.Notify("Trying to get Maneuver {0}",nodeIndex);
127-
// Set the ManeuverNode into this command
128-
Node = fc.Vessel.patchedConicSolver.maneuverNodes[nodeIndex];
129-
RTLog.Notify("Found Maneuver {0} with {1} dV", nodeIndex, Node.DeltaV);
124+
this.NodeIndex = int.Parse(n.GetValue("NodeIndex"));
125+
RTLog.Notify("Trying to get Maneuver {0}", this.NodeIndex);
126+
if (this.NodeIndex >= 0)
127+
{
128+
// Set the ManeuverNode into this command
129+
this.Node = fc.Vessel.patchedConicSolver.maneuverNodes[this.NodeIndex];
130+
RTLog.Notify("Found Maneuver {0} with {1} dV", this.NodeIndex, this.Node.DeltaV);
131+
}
132+
}
133+
}
134+
135+
/// <summary>
136+
/// Save the index of the maneuver node to the persistent
137+
/// </summary>
138+
public override void Save(ConfigNode n, FlightComputer fc)
139+
{
140+
// search the node on the List
141+
this.NodeIndex = fc.Vessel.patchedConicSolver.maneuverNodes.IndexOf(this.Node);
142+
143+
// only save this command if we are on the maneuverNode list
144+
if (this.NodeIndex >= 0)
145+
{
146+
base.Save(n, fc);
130147
}
131148
}
132149
}

src/RemoteTech/FlightComputer/Commands/TargetCommand.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ public override bool Pop(FlightComputer f)
2727
{
2828
f.DelayedTarget = Target;
2929
f.lastTarget = this;
30-
// Switch the vessels target
31-
FlightGlobals.fetch.SetVesselTarget(Target);
30+
31+
if (Target != null && Target != FlightGlobals.fetch.VesselTarget)
32+
{
33+
// Switch the vessels target
34+
FlightGlobals.fetch.SetVesselTarget(Target);
35+
}
3236

3337
return true;
3438
}
@@ -87,26 +91,29 @@ public override void Load(ConfigNode n, FlightComputer fc)
8791
public override void Save(ConfigNode n, FlightComputer fc)
8892
{
8993
if (Target != null)
94+
{
9095
TargetType = Target.GetType().ToString();
9196

92-
switch (TargetType)
93-
{
94-
case "Vessel":
95-
{
96-
TargetId = ((Vessel)Target).id.ToString();
97-
break;
98-
}
99-
case "CelestialBody":
100-
{
101-
TargetId = FlightGlobals.Bodies.ToList().IndexOf(((CelestialBody)Target)).ToString();
102-
break;
103-
}
104-
default:
105-
{
106-
TargetId = null;
107-
break;
108-
}
97+
switch (TargetType)
98+
{
99+
case "Vessel":
100+
{
101+
TargetId = ((Vessel)Target).id.ToString();
102+
break;
103+
}
104+
case "CelestialBody":
105+
{
106+
TargetId = FlightGlobals.Bodies.ToList().IndexOf(((CelestialBody)Target)).ToString();
107+
break;
108+
}
109+
default:
110+
{
111+
TargetId = null;
112+
break;
113+
}
114+
}
109115
}
116+
110117
base.Save(n, fc);
111118
}
112119
}

src/RemoteTech/FlightComputer/EventCommand.cs

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,35 @@ namespace RemoteTech.FlightComputer
77
{
88
public class EventCommand : AbstractCommand
99
{
10+
// Guiname of the BaseEvent
1011
[Persistent] public string GUIName;
11-
[Persistent] public int PartId;
12+
// flight id of the part by this BaseEvent
13+
[Persistent] public uint flightID;
14+
// PartModule of the part by this BaseEvent
1215
[Persistent] public string Module;
13-
16+
// BaseEvent to invoke
1417
public BaseEvent BaseEvent = null;
1518

1619
public override String Description
1720
{
1821
get
1922
{
20-
return BaseEvent.listParent.part.partInfo.title + ": " + BaseEvent.GUIName +
23+
return ((this.BaseEvent != null) ? this.BaseEvent.listParent.part.partInfo.title + ": " + this.BaseEvent.GUIName : "none") +
2124
Environment.NewLine + base.Description;
2225
}
2326
}
2427
public override string ShortName
2528
{
2629
get
2730
{
28-
return BaseEvent.GUIName;
31+
return (this.BaseEvent != null) ? this.BaseEvent.GUIName : "none";
2932
}
3033
}
3134

3235
public override bool Pop(FlightComputer f)
3336
{
34-
BaseEvent.Invoke();
37+
if (this.BaseEvent != null)
38+
this.BaseEvent.Invoke();
3539

3640
return false;
3741
}
@@ -41,9 +45,6 @@ public static EventCommand Event(BaseEvent ev)
4145
return new EventCommand()
4246
{
4347
BaseEvent = ev,
44-
GUIName = ev.GUIName,
45-
PartId = FlightGlobals.ActiveVessel.parts.ToList().IndexOf(ev.listParent.part),
46-
Module = ev.listParent.module.ClassName.ToString(),
4748
TimeStamp = RTUtil.GameTime,
4849
};
4950
}
@@ -55,17 +56,59 @@ public override void Load(ConfigNode n, FlightComputer fc)
5556
{
5657
base.Load(n, fc);
5758

58-
PartId = int.Parse(n.GetValue("PartId"));
59+
// deprecated since 1.6.2, we need this for upgrading from 1.6.x => 1.6.2
60+
int PartId = 0;
61+
{
62+
if (n.HasValue("PartId"))
63+
PartId = int.Parse(n.GetValue("PartId"));
64+
}
65+
66+
if (n.HasValue("flightID"))
67+
this.flightID = uint.Parse(n.GetValue("flightID"));
68+
5969
Module = n.GetValue("Module");
6070
GUIName = n.GetValue("GUIName");
6171

62-
Part part = FlightGlobals.ActiveVessel.parts[PartId];
63-
PartModule partmodule = part.Modules[Module];
64-
BaseEventList eventlist = new BaseEventList(part, partmodule);
65-
if (eventlist.Count > 0)
72+
RTLog.Notify("Try to load an EventCommand from persistent with {0},{1},{2},{3}", PartId, flightID, Module, GUIName);
73+
74+
Part part = null;
75+
var partlist = FlightGlobals.ActiveVessel.parts;
76+
77+
if (this.flightID == 0)
78+
{
79+
// only look with the partid if we've enough parts
80+
if (PartId < partlist.Count)
81+
part = partlist.ElementAt(PartId);
82+
}
83+
else
84+
{
85+
part = partlist.Where(p => p.flightID == this.flightID).FirstOrDefault();
86+
}
87+
88+
if (part != null)
6689
{
67-
BaseEvent = eventlist.Where(ba => ba.GUIName == GUIName).FirstOrDefault();
90+
PartModule partmodule = part.Modules[Module];
91+
if (partmodule != null)
92+
{
93+
BaseEventList eventlist = new BaseEventList(part, partmodule);
94+
if (eventlist.Count > 0)
95+
{
96+
this.BaseEvent = eventlist.Where(ba => ba.GUIName == this.GUIName).FirstOrDefault();
97+
}
98+
}
6899
}
69100
}
101+
102+
/// <summary>
103+
/// Save the BaseEvent to the persistent
104+
/// </summary>
105+
public override void Save(ConfigNode n, FlightComputer fc)
106+
{
107+
GUIName = this.BaseEvent.GUIName;
108+
flightID = this.BaseEvent.listParent.module.part.flightID;
109+
Module = this.BaseEvent.listParent.module.ClassName.ToString();
110+
111+
base.Save(n, fc);
112+
}
70113
}
71114
}

src/RemoteTech/FlightComputer/FlightComputer.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ public State Status
6666
public IEnumerable<ICommand> ActiveCommands { get { return mActiveCommands.Values; } }
6767
public IEnumerable<ICommand> QueuedCommands { get { return mCommandQueue; } }
6868

69+
/// Will be triggered if the active command is aborted
70+
public Action onActiveCommandAbort;
71+
/// Will be triggered if a new command popped to an active command
72+
public Action onNewCommandPop;
73+
/// Get the active Flightmode
74+
public AttitudeCommand currentFlightMode { get { return (mActiveCommands[0] is AttitudeCommand) ? (AttitudeCommand)mActiveCommands[0] : null; } }
75+
6976
// Flight controller parameters from MechJeb, copied from master on June 27, 2014
7077
public PIDControllerV2 pid { get; private set; }
7178
public Vector3d lastAct { get; set; }
@@ -129,6 +136,8 @@ public void Reset()
129136
{
130137
cmd.Abort();
131138
}
139+
140+
onActiveCommandAbort.Invoke();
132141
}
133142

134143
public void Enqueue(ICommand cmd, bool ignore_control = false, bool ignore_delay = false, bool ignore_extra = false)
@@ -233,7 +242,8 @@ private void PopCommand()
233242
}
234243
}
235244

236-
foreach (var dc in mCommandQueue.TakeWhile(c => c.TimeStamp <= RTUtil.GameTime).ToList())
245+
// Proceed the extraDelay for every command where the normal delay is over
246+
foreach (var dc in mCommandQueue.Where(s=>s.Delay==0).ToList())
237247
{
238248
// Use time decrement instead of comparing scheduled time, in case we later want to
239249
// reinstate event clocks stopping under certain conditions
@@ -245,7 +255,12 @@ private void PopCommand()
245255
{
246256
if (SignalProcessor.Powered) {
247257
// Note: depending on implementation, dc.Pop() may execute the event
248-
if (dc.Pop(this)) mActiveCommands [dc.Priority] = dc;
258+
if (dc.Pop(this)) {
259+
mActiveCommands[dc.Priority] = dc;
260+
if (onNewCommandPop != null) {
261+
onNewCommandPop.Invoke();
262+
}
263+
}
249264
} else {
250265
string message = String.Format ("[Flight Computer]: Out of power, cannot run \"{0}\" on schedule.", dc.ShortName);
251266
ScreenMessages.PostScreenMessage(new ScreenMessage(
@@ -353,7 +368,7 @@ public void orderCommandList()
353368
/// <param name="n">Node with the informations for the flightcomputer</param>
354369
public void load(ConfigNode n)
355370
{
356-
RTLog.Notify("Loading Flightcomputer from persistant!");
371+
RTLog.Notify("Loading Flightcomputer from persistent!");
357372

358373
if (!n.HasNode("FlightComputer"))
359374
return;
@@ -402,7 +417,7 @@ public void load(ConfigNode n)
402417
if (mCommandQueue.Count > 0)
403418
mCommandQueue.Clear();
404419

405-
RTLog.Notify("Loading queued commands from persistant ...");
420+
RTLog.Notify("Loading queued commands from persistent ...");
406421
foreach (ConfigNode cmdNode in Commands.nodes)
407422
{
408423
ICommand cmd = AbstractCommand.LoadCommand(cmdNode, this);
@@ -424,7 +439,6 @@ public void load(ConfigNode n)
424439
if (cmd.ExtraDelay > 0)
425440
{
426441
cmd.ExtraDelay = cmd.TimeStamp + cmd.ExtraDelay - RTUtil.GameTime;
427-
cmd.TimeStamp = RTUtil.GameTime;
428442

429443
// Are we ready to handle the command ?
430444
if (cmd.ExtraDelay <= 0)

src/RemoteTech/NetworkPathfinder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public static NetworkRoute<T> Solve<T>(T start, T goal,
4040
foreach (var link in neighborsFunction.Invoke(current.Item.Target))
4141
{
4242
double new_cost = current.Cost + costFunction.Invoke(current.Item.Target, link);
43+
44+
// Todo: Dennis: i use the fix from Taste83 #139 and i'll look closer if i'm more related to the Pathfinder
45+
if (new_cost == current.Cost)
46+
{
47+
continue;
48+
}
49+
4350
// If the item has a node, it will either be in the closedSet, or the openSet
4451
if (nodeMap.ContainsKey(link.Target))
4552
{

src/RemoteTech/Properties/AssemblyInfo.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44

@@ -32,8 +32,12 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.6.0")]
36-
[assembly: AssemblyFileVersion("1.6.0")]
35+
36+
// Don't include the patch revision in the AssemblyVersion - as this will break any dependent
37+
// DLLs any time it changes. Breaking on a minor revision is probably acceptable - it's
38+
// unlikely that there wouldn't be other breaking changes on a minor version change.
39+
[assembly: AssemblyVersion("1.6")]
40+
[assembly: AssemblyFileVersion("1.6.1")]
3741

3842
// Use KSPAssembly to allow other DLLs to make this DLL a dependency in a
3943
// non-hacky way in KSP. Format is (AssemblyProduct, major, minor), and it

0 commit comments

Comments
 (0)