Skip to content

Commit b4a1019

Browse files
authored
Merge pull request #70 from DMagic1/dev
Version 1.3.8
2 parents 7838674 + 4b4946f commit b4a1019

9 files changed

Lines changed: 142 additions & 25 deletions

File tree

GameData/DMagicOrbitalScience/Change Log.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
v1.3.7
1+
v1.3.8
2+
- Fix for magnetic field and reconnaissance contracts when using a vessel already in orbit
3+
- Fix for Seismic impact hammer experiments when decoupling or undocking from another vessel
4+
- Fix for X-Ray and Seismic impact hammer experiments when using Kopernicus and planet packs that replace Kerbin
5+
6+
v1.3.7
27
- Fix a bug with resetting experiments with an EVA Kerbal
38
- Add Module Data Transmitter to Soil Moisture instrument
49
- Add antenna upgrade package to turn all Orbital Science antenna parts into relays and boost signal strength

GameData/DMagicOrbitalScience/DMagicOrbitalScience.version

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

Source/DMSeismicHandler.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ public static DMSeismicHandler Instance
6363
private Dictionary<uint, DMSeismometerValues> seismometers = new Dictionary<uint, DMSeismometerValues>();
6464
private Dictionary<uint, DMSeismometerValues> hammers = new Dictionary<uint, DMSeismometerValues>();
6565

66+
private bool loaded;
67+
6668
private static string bodyNameFixed = "Eeloo";
6769

6870
private void Start()
6971
{
7072
instance = this;
7173

7274
GameEvents.onPartDie.Add(onPartDestroyed);
75+
GameEvents.onVesselSOIChanged.Add(SOIChange);
7376

7477
if (FlightGlobals.Bodies.Count >= 17)
7578
bodyNameFixed = FlightGlobals.Bodies[16].bodyName;
@@ -80,19 +83,44 @@ private void Start()
8083
private void OnDestroy()
8184
{
8285
GameEvents.onPartDie.Remove(onPartDestroyed);
86+
GameEvents.onVesselSOIChanged.Remove(SOIChange);
8387
}
8488

8589
private void Update()
8690
{
87-
if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready)
91+
if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready && loaded)
8892
updatePositions();
8993
}
9094

95+
private void SOIChange(GameEvents.HostedFromToAction<Vessel, CelestialBody> VB)
96+
{
97+
if (VB.host == null)
98+
return;
99+
100+
if (VB.host != FlightGlobals.ActiveVessel)
101+
return;
102+
103+
loaded = false;
104+
105+
seismometers.Clear();
106+
hammers.Clear();
107+
108+
StartCoroutine(loadSensors());
109+
}
110+
91111
private IEnumerator loadSensors()
92112
{
93113
while (!FlightGlobals.ready)
94114
yield return null;
95115

116+
int timer = 0;
117+
118+
while (timer < 20)
119+
{
120+
timer++;
121+
yield return null;
122+
}
123+
96124
for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; i--)
97125
{
98126
Vessel v = FlightGlobals.Vessels[i];
@@ -142,6 +170,8 @@ private IEnumerator loadSensors()
142170
}
143171
}
144172
}
173+
174+
loaded = true;
145175
}
146176

147177
public void addLoadedSeismometer(uint id, IDMSeismometer sensor)

Source/DMSeismometerValues.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public DMSeismometerValues(Vessel v, ProtoPartSnapshot pp, ProtoPartModuleSnapsh
6060
bool.TryParse(pm.moduleValues.GetValue("IsDeployed"), out armed);
6161
if (pm.moduleValues.HasValue("baseExperimentValue"))
6262
float.TryParse(pm.moduleValues.GetValue("baseExperimentValue"), out baseScore);
63+
else
64+
baseScore = h ? 0.4f : 0.2f;
6365

6466
hammer = h;
6567

Source/Parameters/DMPartRequestParameter.cs

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -206,31 +206,56 @@ protected override void OnLoad(ConfigNode node)
206206

207207
vesselNames = node.parse("Vessels", "");
208208

209-
if (!string.IsNullOrEmpty(vesselNames) && !HighLogic.LoadedSceneIsEditor && this.Root.ContractState == Contract.State.Active)
209+
if (!HighLogic.LoadedSceneIsEditor && this.Root.ContractState == Contract.State.Active)
210210
{
211-
List<Guid> ids = node.parse("Vessels", new List<Guid>());
212-
if (ids.Count > 0)
211+
if (!string.IsNullOrEmpty(vesselNames))
213212
{
214-
foreach (Guid id in ids)
213+
List<Guid> ids = node.parse("Vessels", new List<Guid>());
214+
if (ids.Count > 0)
215215
{
216-
try
216+
foreach (Guid id in ids)
217217
{
218-
Vessel V = FlightGlobals.Vessels.FirstOrDefault(v => v.id == id);
219-
addVessel(V);
220-
DMUtils.DebugLog("Vessel {0} Loaded", V.vesselName);
221-
}
222-
catch
223-
{
224-
DMUtils.Logging("Failed To Load Vessel; DM Part Request Parameter Reset");
225-
if (HighLogic.LoadedSceneIsFlight)
218+
try
219+
{
220+
Vessel V = FlightGlobals.Vessels.FirstOrDefault(v => v.id == id);
221+
addVessel(V);
222+
DMUtils.DebugLog("Vessel {0} Loaded", V.vesselName);
223+
}
224+
catch
226225
{
227-
DMUtils.Logging("Checking If Currently Loaded Vessel Is Appropriate");
228-
if (vesselEquipped(FlightGlobals.ActiveVessel, FlightGlobals.currentMainBody))
229-
addVessel(FlightGlobals.ActiveVessel);
226+
DMUtils.Logging("Failed To Load Vessel; DM Part Request Parameter Reset");
227+
if (HighLogic.LoadedSceneIsFlight)
228+
{
229+
DMUtils.Logging("Checking If Currently Loaded Vessel Is Appropriate");
230+
if (vesselEquipped(FlightGlobals.ActiveVessel, FlightGlobals.currentMainBody))
231+
addVessel(FlightGlobals.ActiveVessel);
232+
}
230233
}
231234
}
232235
}
233236
}
237+
else
238+
{
239+
for (int i = 0; i < FlightGlobals.Vessels.Count; i++)
240+
{
241+
Vessel V = FlightGlobals.Vessels[i];
242+
243+
if (V == null)
244+
continue;
245+
246+
if (V.mainBody == null)
247+
continue;
248+
249+
if (V.mainBody != TargetBody)
250+
continue;
251+
252+
if (!vesselEquipped(V, V.mainBody))
253+
continue;
254+
255+
if (!suitableVessels.Contains(V.id))
256+
addVessel(V);
257+
}
258+
}
234259
}
235260

236261
this.disableOnStateChange = false;

Source/Part Modules/DMSeismicHammer.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public override void OnStart(PartModule.StartState state)
9595

9696
GameEvents.onVesselWasModified.Add(onVesselModified);
9797
GameEvents.onPartCouple.Add(onCouple);
98+
GameEvents.onVesselCreate.Add(onNewVessel);
99+
GameEvents.onVesselSOIChanged.Add(SOIChange);
98100

99101
Transform l1 = part.FindModelTransform("SignalLight.004");
100102
Transform l2 = part.FindModelTransform("SignalLight.003");
@@ -155,6 +157,8 @@ protected override void OnDestroy()
155157

156158
GameEvents.onVesselWasModified.Remove(onVesselModified);
157159
GameEvents.onPartCouple.Remove(onCouple);
160+
GameEvents.onVesselCreate.Remove(onNewVessel);
161+
GameEvents.onVesselSOIChanged.Remove(SOIChange);
158162
}
159163

160164
private void onCouple(GameEvents.FromToAction<Part, Part> p)
@@ -186,6 +190,37 @@ private IEnumerator waitOnVessel()
186190
DMSeismicHandler.Instance.addLoadedSeismometer(part.flightID, this);
187191
}
188192

193+
private void onNewVessel(Vessel v)
194+
{
195+
if (v == null)
196+
return;
197+
198+
if (!v.loaded)
199+
return;
200+
201+
if (v != vessel)
202+
return;
203+
204+
if (values == null)
205+
return;
206+
207+
values.VesselRef = v;
208+
}
209+
210+
private void SOIChange(GameEvents.HostedFromToAction<Vessel, CelestialBody> VB)
211+
{
212+
if (VB.host == null)
213+
return;
214+
215+
if (!VB.host.loaded)
216+
return;
217+
218+
if (VB.host != vessel)
219+
return;
220+
221+
values = null;
222+
}
223+
189224
private void onVesselModified(Vessel v)
190225
{
191226
if (v == null)
@@ -695,7 +730,7 @@ private bool rayImpact(bool b, Transform t, float s, float max, out float d)
695730
int i = 0; //Just to prevent this from getting stuck in a loop
696731
while (hitT != null && i < 30)
697732
{
698-
if (hitT.name.Contains(vessel.mainBody.name))
733+
if (hitT == vessel.mainBody.bodyTransform)
699734
{
700735
d = hit.distance;
701736
return true;
@@ -710,6 +745,8 @@ private bool rayImpact(bool b, Transform t, float s, float max, out float d)
710745

711746
private void getScienceData(bool asteroid, bool silent, float score)
712747
{
748+
values.VesselRef = vessel;
749+
713750
ScienceData data = DMSeismicHandler.makeData(values, score, exp, experimentID, false, asteroid);
714751

715752
if (data == null)

Source/Part Modules/DMSeismicSensor.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public override void OnStart(PartModule.StartState state)
7575
GameEvents.onStageSeparation.Add(onDecouple);
7676
GameEvents.onVesselCreate.Add(onNewVessel);
7777
GameEvents.onPartCouple.Add(onCouple);
78+
GameEvents.onVesselSOIChanged.Add(SOIChange);
7879

7980
Transform l1 = part.FindModelTransform("SignalLight.004");
8081
Transform l2 = part.FindModelTransform("SignalLight.003");
@@ -125,12 +126,29 @@ public override void OnSave(ConfigNode node)
125126
base.OnSave(node);
126127
}
127128

128-
private void OnDestroy()
129+
protected override void OnDestroy()
129130
{
131+
base.OnDestroy();
132+
130133
GameEvents.onVesselWasModified.Remove(onVesselModified);
131134
GameEvents.onStageSeparation.Remove(onDecouple);
132135
GameEvents.onVesselCreate.Remove(onNewVessel);
133136
GameEvents.onPartCouple.Remove(onCouple);
137+
GameEvents.onVesselSOIChanged.Remove(SOIChange);
138+
}
139+
140+
private void SOIChange(GameEvents.HostedFromToAction<Vessel, CelestialBody> VB)
141+
{
142+
if (VB.host == null)
143+
return;
144+
145+
if (!VB.host.loaded)
146+
return;
147+
148+
if (VB.host != vessel)
149+
return;
150+
151+
values = null;
134152
}
135153

136154
private void onDecouple(EventReport e)

Source/Part Modules/DMXRayDiffract.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private bool drillImpact(bool b)
9090
int i = 0; //Just to prevent this from getting stuck in a loop
9191
while (hitT != null && i < 200)
9292
{
93-
if (hitT.name.Contains(vessel.mainBody.name))
93+
if (hitT == vessel.mainBody.bodyTransform)
9494
return true;
9595
hitT = hitT.parent;
9696
i++;

Source/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// The following GUID is for the ID of the typelib if this project is exposed to COM
2020
[assembly: Guid("5428988e-53a6-4d8e-8af4-014572513e22")]
2121

22-
[assembly: AssemblyVersion("1.3.0.7")]
23-
[assembly: AssemblyFileVersion("1.3.0.7")]
24-
[assembly: AssemblyInformationalVersion("v1.3.7")]
22+
[assembly: AssemblyVersion("1.3.0.8")]
23+
[assembly: AssemblyFileVersion("1.3.0.8")]
24+
[assembly: AssemblyInformationalVersion("v1.3.8")]
2525
[assembly: KSPAssembly("DMagic", 1, 4)]

0 commit comments

Comments
 (0)