Skip to content

Commit

Permalink
Merge pull request #70 from DMagic1/dev
Browse files Browse the repository at this point in the history
Version 1.3.8
  • Loading branch information
DMagic1 authored Jan 5, 2017
2 parents 7838674 + 4b4946f commit b4a1019
Showing 9 changed files with 142 additions and 25 deletions.
7 changes: 6 additions & 1 deletion GameData/DMagicOrbitalScience/Change Log.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
v1.3.7
v1.3.8
- Fix for magnetic field and reconnaissance contracts when using a vessel already in orbit
- Fix for Seismic impact hammer experiments when decoupling or undocking from another vessel
- Fix for X-Ray and Seismic impact hammer experiments when using Kopernicus and planet packs that replace Kerbin

v1.3.7
- Fix a bug with resetting experiments with an EVA Kerbal
- Add Module Data Transmitter to Soil Moisture instrument
- Add antenna upgrade package to turn all Orbital Science antenna parts into relays and boost signal strength
2 changes: 1 addition & 1 deletion GameData/DMagicOrbitalScience/DMagicOrbitalScience.version
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
"MAJOR":1,
"MINOR":3,
"PATCH":0,
"BUILD":7
"BUILD":8
},
"KSP_VERSION":{
"MAJOR":1,
32 changes: 31 additions & 1 deletion Source/DMSeismicHandler.cs
Original file line number Diff line number Diff line change
@@ -63,13 +63,16 @@ public static DMSeismicHandler Instance
private Dictionary<uint, DMSeismometerValues> seismometers = new Dictionary<uint, DMSeismometerValues>();
private Dictionary<uint, DMSeismometerValues> hammers = new Dictionary<uint, DMSeismometerValues>();

private bool loaded;

private static string bodyNameFixed = "Eeloo";

private void Start()
{
instance = this;

GameEvents.onPartDie.Add(onPartDestroyed);
GameEvents.onVesselSOIChanged.Add(SOIChange);

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

private void Update()
{
if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready)
if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready && loaded)
updatePositions();
}

private void SOIChange(GameEvents.HostedFromToAction<Vessel, CelestialBody> VB)
{
if (VB.host == null)
return;

if (VB.host != FlightGlobals.ActiveVessel)
return;

loaded = false;

seismometers.Clear();
hammers.Clear();

StartCoroutine(loadSensors());
}

private IEnumerator loadSensors()
{
while (!FlightGlobals.ready)
yield return null;

int timer = 0;

while (timer < 20)
{
timer++;
yield return null;
}

for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; i--)
{
Vessel v = FlightGlobals.Vessels[i];
@@ -142,6 +170,8 @@ private IEnumerator loadSensors()
}
}
}

loaded = true;
}

public void addLoadedSeismometer(uint id, IDMSeismometer sensor)
2 changes: 2 additions & 0 deletions Source/DMSeismometerValues.cs
Original file line number Diff line number Diff line change
@@ -60,6 +60,8 @@ public DMSeismometerValues(Vessel v, ProtoPartSnapshot pp, ProtoPartModuleSnapsh
bool.TryParse(pm.moduleValues.GetValue("IsDeployed"), out armed);
if (pm.moduleValues.HasValue("baseExperimentValue"))
float.TryParse(pm.moduleValues.GetValue("baseExperimentValue"), out baseScore);
else
baseScore = h ? 0.4f : 0.2f;

hammer = h;

57 changes: 41 additions & 16 deletions Source/Parameters/DMPartRequestParameter.cs
Original file line number Diff line number Diff line change
@@ -206,31 +206,56 @@ protected override void OnLoad(ConfigNode node)

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

if (!string.IsNullOrEmpty(vesselNames) && !HighLogic.LoadedSceneIsEditor && this.Root.ContractState == Contract.State.Active)
if (!HighLogic.LoadedSceneIsEditor && this.Root.ContractState == Contract.State.Active)
{
List<Guid> ids = node.parse("Vessels", new List<Guid>());
if (ids.Count > 0)
if (!string.IsNullOrEmpty(vesselNames))
{
foreach (Guid id in ids)
List<Guid> ids = node.parse("Vessels", new List<Guid>());
if (ids.Count > 0)
{
try
foreach (Guid id in ids)
{
Vessel V = FlightGlobals.Vessels.FirstOrDefault(v => v.id == id);
addVessel(V);
DMUtils.DebugLog("Vessel {0} Loaded", V.vesselName);
}
catch
{
DMUtils.Logging("Failed To Load Vessel; DM Part Request Parameter Reset");
if (HighLogic.LoadedSceneIsFlight)
try
{
Vessel V = FlightGlobals.Vessels.FirstOrDefault(v => v.id == id);
addVessel(V);
DMUtils.DebugLog("Vessel {0} Loaded", V.vesselName);
}
catch
{
DMUtils.Logging("Checking If Currently Loaded Vessel Is Appropriate");
if (vesselEquipped(FlightGlobals.ActiveVessel, FlightGlobals.currentMainBody))
addVessel(FlightGlobals.ActiveVessel);
DMUtils.Logging("Failed To Load Vessel; DM Part Request Parameter Reset");
if (HighLogic.LoadedSceneIsFlight)
{
DMUtils.Logging("Checking If Currently Loaded Vessel Is Appropriate");
if (vesselEquipped(FlightGlobals.ActiveVessel, FlightGlobals.currentMainBody))
addVessel(FlightGlobals.ActiveVessel);
}
}
}
}
}
else
{
for (int i = 0; i < FlightGlobals.Vessels.Count; i++)
{
Vessel V = FlightGlobals.Vessels[i];

if (V == null)
continue;

if (V.mainBody == null)
continue;

if (V.mainBody != TargetBody)
continue;

if (!vesselEquipped(V, V.mainBody))
continue;

if (!suitableVessels.Contains(V.id))
addVessel(V);
}
}
}

this.disableOnStateChange = false;
39 changes: 38 additions & 1 deletion Source/Part Modules/DMSeismicHammer.cs
Original file line number Diff line number Diff line change
@@ -95,6 +95,8 @@ public override void OnStart(PartModule.StartState state)

GameEvents.onVesselWasModified.Add(onVesselModified);
GameEvents.onPartCouple.Add(onCouple);
GameEvents.onVesselCreate.Add(onNewVessel);
GameEvents.onVesselSOIChanged.Add(SOIChange);

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

GameEvents.onVesselWasModified.Remove(onVesselModified);
GameEvents.onPartCouple.Remove(onCouple);
GameEvents.onVesselCreate.Remove(onNewVessel);
GameEvents.onVesselSOIChanged.Remove(SOIChange);
}

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

private void onNewVessel(Vessel v)
{
if (v == null)
return;

if (!v.loaded)
return;

if (v != vessel)
return;

if (values == null)
return;

values.VesselRef = v;
}

private void SOIChange(GameEvents.HostedFromToAction<Vessel, CelestialBody> VB)
{
if (VB.host == null)
return;

if (!VB.host.loaded)
return;

if (VB.host != vessel)
return;

values = null;
}

private void onVesselModified(Vessel v)
{
if (v == null)
@@ -695,7 +730,7 @@ private bool rayImpact(bool b, Transform t, float s, float max, out float d)
int i = 0; //Just to prevent this from getting stuck in a loop
while (hitT != null && i < 30)
{
if (hitT.name.Contains(vessel.mainBody.name))
if (hitT == vessel.mainBody.bodyTransform)
{
d = hit.distance;
return true;
@@ -710,6 +745,8 @@ private bool rayImpact(bool b, Transform t, float s, float max, out float d)

private void getScienceData(bool asteroid, bool silent, float score)
{
values.VesselRef = vessel;

ScienceData data = DMSeismicHandler.makeData(values, score, exp, experimentID, false, asteroid);

if (data == null)
20 changes: 19 additions & 1 deletion Source/Part Modules/DMSeismicSensor.cs
Original file line number Diff line number Diff line change
@@ -75,6 +75,7 @@ public override void OnStart(PartModule.StartState state)
GameEvents.onStageSeparation.Add(onDecouple);
GameEvents.onVesselCreate.Add(onNewVessel);
GameEvents.onPartCouple.Add(onCouple);
GameEvents.onVesselSOIChanged.Add(SOIChange);

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

private void OnDestroy()
protected override void OnDestroy()
{
base.OnDestroy();

GameEvents.onVesselWasModified.Remove(onVesselModified);
GameEvents.onStageSeparation.Remove(onDecouple);
GameEvents.onVesselCreate.Remove(onNewVessel);
GameEvents.onPartCouple.Remove(onCouple);
GameEvents.onVesselSOIChanged.Remove(SOIChange);
}

private void SOIChange(GameEvents.HostedFromToAction<Vessel, CelestialBody> VB)
{
if (VB.host == null)
return;

if (!VB.host.loaded)
return;

if (VB.host != vessel)
return;

values = null;
}

private void onDecouple(EventReport e)
2 changes: 1 addition & 1 deletion Source/Part Modules/DMXRayDiffract.cs
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ private bool drillImpact(bool b)
int i = 0; //Just to prevent this from getting stuck in a loop
while (hitT != null && i < 200)
{
if (hitT.name.Contains(vessel.mainBody.name))
if (hitT == vessel.mainBody.bodyTransform)
return true;
hitT = hitT.parent;
i++;
6 changes: 3 additions & 3 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5428988e-53a6-4d8e-8af4-014572513e22")]

[assembly: AssemblyVersion("1.3.0.7")]
[assembly: AssemblyFileVersion("1.3.0.7")]
[assembly: AssemblyInformationalVersion("v1.3.7")]
[assembly: AssemblyVersion("1.3.0.8")]
[assembly: AssemblyFileVersion("1.3.0.8")]
[assembly: AssemblyInformationalVersion("v1.3.8")]
[assembly: KSPAssembly("DMagic", 1, 4)]

0 comments on commit b4a1019

Please sign in to comment.