Skip to content

Commit

Permalink
Revert "test successful (#37)"
Browse files Browse the repository at this point in the history
This reverts commit e498ccc.
  • Loading branch information
Sigma88 committed Sep 24, 2017
1 parent e498ccc commit 9049fe5
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 415 deletions.
Binary file modified [Source]/Distribution/SigmaBinary.dll
Binary file not shown.
54 changes: 11 additions & 43 deletions [Source]/SigmaBinary/ArchivesFixer.cs
Expand Up @@ -24,62 +24,30 @@ public class ArchivesFixer : MonoBehaviour
{
void Start()
{
for (int i = 0; i < SigmaBinary.archivesFixerList?.Count; i++)
PSystemBody sun = PSystemManager.Instance.systemPrefab.GetComponentsInChildren<PSystemBody>(true).First(b => b.name == "Sun");
foreach (string P in SigmaBinary.archivesFixerList.Keys)
{
KeyValuePair<PSystemBody, PSystemBody> pair = SigmaBinary.archivesFixerList.ElementAt(i);
PSystemBody primary = pair.Key;
PSystemBody barycenter = pair.Value;
PSystemBody oldParent = ParentOf(primary);
PSystemBody primary = PSystemManager.Instance.systemPrefab.GetComponentsInChildren<PSystemBody>(true).First(b => b.name == P);
PSystemBody barycenter = PSystemManager.Instance.systemPrefab.GetComponentsInChildren<PSystemBody>(true).First(b => b.name == SigmaBinary.archivesFixerList[P][0]);
PSystemBody reference = PSystemManager.Instance.systemPrefab.GetComponentsInChildren<PSystemBody>(true).First(b => b.name == SigmaBinary.archivesFixerList[P][1]);

if (oldParent != null && oldParent.children.Contains(primary))
{
oldParent.children.Remove(primary);
Debug.Log("ArchivesFixer", "Removed primary " + primary.name + " from the children list of oldParent " + oldParent.name);
}
else
{
Debug.Log("ArchivesFixer", "Failed to remove primary " + primary.name + " from the children list of oldParent " + (string.IsNullOrEmpty(oldParent?.name) ? "(null)" : oldParent.name) + ".");
continue;
}

if (primary.name == "Kerbin")
sun.children.Remove(primary);

PSystemBody newParent = ParentOf(barycenter);
int index = reference.children.IndexOf(barycenter);

if (newParent != null && newParent.children.Contains(barycenter))
{
newParent.children.Insert(newParent.children.IndexOf(barycenter), primary);
Debug.Log("ArchivesFixer", "Inserted primary " + primary.name + " in the children list of parent " + newParent.name + " at index = " + newParent?.children?.IndexOf(primary));

newParent.children.Remove(barycenter);
Debug.Log("ArchivesFixer", "Removed barycenter " + barycenter.name + " from the children list of parent " + newParent.name);
}
else
{
Debug.Log("ArchivesFixer", "Failed to remove body " + primary.name + " from the children list of parent " + (string.IsNullOrEmpty(newParent?.name) ? "(null)" : newParent.name) + ".");
continue;
}
reference.children.Remove(barycenter);
reference.children.Insert(index, primary);
}

FieldInfo list = typeof(RDArchivesController).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).Skip(7).First();
Debug.Log("ArchivesFixer", "FieldInfo 'list' should be 'searchFilter_planets', FieldInfo name is: " + list.Name);

MethodInfo add = typeof(RDArchivesController).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).Skip(26).First();
Debug.Log("ArchivesFixer", "MethodInfo 'add' should be 'AddPlanets', MethodInfo name is: " + add.Name);

MethodInfo add = typeof(RDArchivesController).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).Skip(27).First();

var archivesFixer = Resources.FindObjectsOfTypeAll<RDArchivesController>().First();


list.SetValue(archivesFixer, new Dictionary<string, List<RDArchivesController.Filter>>());
Debug.Log("ArchivesFixer", "Cleared list 'searchFilter_planets' as the 'AddPlanets' method requires it to be empty.");

add.Invoke(archivesFixer, null);
Debug.Log("ArchivesFixer", "Invoked method 'AddPlanets' to make sure the science archives show the planets in the correct order.");
}

PSystemBody ParentOf(PSystemBody child)
{
return PSystemManager.Instance?.systemPrefab?.GetComponentsInChildren<PSystemBody>(true)?.FirstOrDefault(b => b.children.Contains(child));
}
}
}
12 changes: 6 additions & 6 deletions [Source]/SigmaBinary/EncounterMathFixer.cs
Expand Up @@ -53,7 +53,7 @@ public static bool CheckEncounterButDontBitchAboutIt(Orbit p, Orbit nextPatch, d

if (double.IsInfinity(num3) && double.IsInfinity(num4))
{
UnityEngine.Debug.Log("CheckEncounter: both intercept UTs are infinite");
Debug.Log("CheckEncounter: both intercept UTs are infinite");
return false;
}
if ((num3 < p.StartUT || num3 > p.EndUT) && (num4 < p.StartUT || num4 > p.EndUT))
Expand Down Expand Up @@ -96,15 +96,15 @@ public static bool CheckEncounterButDontBitchAboutIt(Orbit p, Orbit nextPatch, d
}
p.timeToTransition1 = dTforTrueAnomaly;
p.secondaryPosAtTransition1 = orbit.getPositionAtUT(num3);
UnityEngine.Debug.DrawLine(ScaledSpace.LocalToScaledSpace(p.referenceBody.position), ScaledSpace.LocalToScaledSpace(p.secondaryPosAtTransition1), Color.yellow);
Debug.DrawLine(ScaledSpace.LocalToScaledSpace(p.referenceBody.position), ScaledSpace.LocalToScaledSpace(p.secondaryPosAtTransition1), Color.yellow);
p.timeToTransition2 = dTforTrueAnomaly2;
p.secondaryPosAtTransition2 = orbit.getPositionAtUT(num4);
UnityEngine.Debug.DrawLine(ScaledSpace.LocalToScaledSpace(p.referenceBody.position), ScaledSpace.LocalToScaledSpace(p.secondaryPosAtTransition2), Color.red);
Debug.DrawLine(ScaledSpace.LocalToScaledSpace(p.referenceBody.position), ScaledSpace.LocalToScaledSpace(p.secondaryPosAtTransition2), Color.red);
p.nearestTT = p.timeToTransition1;
p.nextTT = p.timeToTransition2;
if (double.IsNaN(p.nearestTT))
{
UnityEngine.Debug.Log(string.Concat(new object[] { "nearestTT is NaN! t1: ", p.timeToTransition1, ", t2: ", p.timeToTransition2, ", FEVp: ", p.FEVp, ", SEVp: ", p.SEVp }));
Debug.Log(string.Concat(new object[] { "nearestTT is NaN! t1: ", p.timeToTransition1, ", t2: ", p.timeToTransition2, ", FEVp: ", p.FEVp, ", SEVp: ", p.SEVp }));
}
p.UTappr = startEpoch;
p.ClAppr = PatchedConics.GetClosestApproach(p, orbit, startEpoch, p.nearestTT * 0.5, pars);
Expand All @@ -116,14 +116,14 @@ public static bool CheckEncounterButDontBitchAboutIt(Orbit p, Orbit nextPatch, d
{
p.closestEncounterLevel = Orbit.EncounterSolutionLevel.SOI_INTERSECT_2;
p.closestEncounterBody = sec.celestialBody;
UnityEngine.Debug.DrawLine(ScaledSpace.LocalToScaledSpace(p.getPositionAtUT(p.UTappr)), ScaledSpace.LocalToScaledSpace(orbit.getPositionAtUT(p.UTappr)), XKCDColors.Orange * 0.5f);
Debug.DrawLine(ScaledSpace.LocalToScaledSpace(p.getPositionAtUT(p.UTappr)), ScaledSpace.LocalToScaledSpace(orbit.getPositionAtUT(p.UTappr)), XKCDColors.Orange * 0.5f);
p.UTappr = startEpoch + p.nearestTT;
p.ClAppr = PatchedConics.GetClosestApproach(p, orbit, startEpoch, (p.nextTT - p.nearestTT) * 0.5, pars);
if (PatchedConics.EncountersBody(p, orbit, nextPatch, sec, startEpoch, pars))
{
return true;
}
UnityEngine.Debug.DrawLine(ScaledSpace.LocalToScaledSpace(p.getPositionAtUT(p.UTappr)), ScaledSpace.LocalToScaledSpace(orbit.getPositionAtUT(p.UTappr)), XKCDColors.Orange);
Debug.DrawLine(ScaledSpace.LocalToScaledSpace(p.getPositionAtUT(p.UTappr)), ScaledSpace.LocalToScaledSpace(orbit.getPositionAtUT(p.UTappr)), XKCDColors.Orange);
}
if (sec.celestialBody == targetBody)
{
Expand Down
83 changes: 24 additions & 59 deletions [Source]/SigmaBinary/KerbinFixer.cs
@@ -1,33 +1,15 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;


namespace SigmaBinaryPlugin
{
[KSPAddon(KSPAddon.Startup.Instantly, true)]
public class KerbinxFixer : MonoBehaviour
public class KerbinFixer : MonoBehaviour
{
public void Start()
void Start()
{
Kopernicus.Events.OnPostFixing.Add(FixKerbins);
}

public void FixKerbins()
{
Debug.Log("KerbinFixer", "'kerbinFixer' contains " + (SigmaBinary.kerbinFixer?.Count > 0 ? SigmaBinary.kerbinFixer.Count.ToString() : "no") + " bodies.");

for (int i = 0; i < SigmaBinary.kerbinFixer?.Count; i++)
{
KeyValuePair<string, string> pair = SigmaBinary.kerbinFixer.ElementAt(i);
CelestialBody body = FlightGlobals.Bodies.FirstOrDefault(cb => cb.transform.name == pair.Key);
CelestialBody parent = FlightGlobals.Bodies.FirstOrDefault(cb => cb.transform.name == pair.Value);
Debug.Log("KerbinFixer", "Body #" + (i + 1) + " = " + body + ", old parent = " + body.referenceBody + ", new parent = " + parent);

body.orbit.referenceBody = parent;
body.orbitDriver.orbit.referenceBody = parent;
Debug.Log("KerbinFixer", "Changed 'referenceBody' of body " + body + " to " + body.referenceBody);
}
if (SigmaBinary.kerbinFixer != null)
FlightGlobals.Bodies.Find(k => k.transform.name == "Kerbin").orbitDriver.orbit.referenceBody = FlightGlobals.Bodies.Find(rb => rb.transform.name == SigmaBinary.kerbinFixer);
}
}

Expand All @@ -36,58 +18,41 @@ public class TrackingStationFixer : MonoBehaviour
{
void Start()
{
var targets = PlanetariumCamera.fetch.targets;

for (int i = 0; i < SigmaBinary.kerbinFixer?.Count; i++)
if (SigmaBinary.kerbinFixer != null)
{
KeyValuePair<string, string> pair = SigmaBinary.kerbinFixer.ElementAt(i);
MapObject body = targets.FirstOrDefault(obj => obj.celestialBody.transform.name == pair.Key);
MapObject parent = targets.FirstOrDefault(obj => obj.celestialBody.transform.name == pair.Value);

List<MapObject> trackingstation = new List<MapObject>();
List<MapObject> children = new List<MapObject>();
children.Add(body);
Debug.Log("TrackingStationFixer", "Body MapObject " + body + " added to 'children'.");
List<string> children = new List<string>();

for (int j = 0; j < targets?.Count; j++)
{
MapObject target = targets[j];
children.Add("Kerbin");

// If the MapObject is not null
if (target != null)
for (int count = 1; count > 0;)
{
foreach (CelestialBody b in FlightGlobals.Bodies)
{
// And the MapObject has not already been added to the list
if (!children.Any(obj => obj.celestialBody == target.celestialBody))
count = 0;
if (children.Contains(b.referenceBody.transform.name))
{
// And the MapObject is a child of any MapObject already in the list
if (children.Any(obj => obj.celestialBody == target.celestialBody.referenceBody))
{
children.Add(target);
Debug.Log("TrackingStationFixer", "Child MapObject " + target.celestialBody + " added to 'children'.");
}
children.Add(b.transform.name);
count++;
}
}
}

// Reorder the tracking station targets
Debug.Log("TrackingStationFixer", "Count of elements in 'trackingstation' = " + trackingstation.Count);
for (int j = 0; j < targets.Count; j++)
foreach (MapObject m in PlanetariumCamera.fetch.targets)
{
MapObject target = targets[j];

if (target != null)
if (m != null)
{
if (!children.Contains(target))
if (!children.Contains(m.celestialBody.transform.name))
{
trackingstation.Add(target);
Debug.Log("TrackingStationFixer", "Target MapObject " + target.celestialBody + " added to 'trackingstation'.");
Debug.Log("TrackingStationFixer", "New count of elements in 'trackingstation' = " + trackingstation.Count);
trackingstation.Add(m);
}
if (target == parent)

if (m.celestialBody.transform.name == SigmaBinary.kerbinFixer)
{
trackingstation.AddRange(children);
Debug.Log(children.Count + " child MapObjects added to 'trackingstation'.");
Debug.Log("TrackingStationFixer", "New count of elements in 'trackingstation' = " + trackingstation.Count);
foreach (string c in children)
{
trackingstation.Add(PlanetariumCamera.fetch.targets.Find(t => t.celestialBody.transform.name == c));
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion [Source]/SigmaBinary/LateFixes.cs
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using KSP.UI.Screens;
using Kopernicus;
using Kopernicus.Components;
using Kopernicus.Configuration;
using Kopernicus.OnDemand;

Expand Down
6 changes: 3 additions & 3 deletions [Source]/SigmaBinary/MapViewFixer.cs
@@ -1,5 +1,5 @@
using System.Linq;
using System.Reflection;
using System.Linq;
using UnityEngine;
using KSP.UI.Screens.Mapview;
using KSP.UI.Screens.Mapview.MapContextMenuOptions;
Expand Down Expand Up @@ -40,9 +40,9 @@ void LateUpdate()

CelestialBody body = PSystemManager.Instance.localBodies.Find(b => b.name == cast.or.discoveryInfo.name.Value);

if (SigmaBinary.mapViewFixerList.ContainsKey(body))
if (SigmaBinary.mapViewFixerList.ContainsKey(body.transform.name))
{
CelestialBody body2 = SigmaBinary.mapViewFixerList[body];
CelestialBody body2 = PSystemManager.Instance.localBodies.Find(b => b.transform.name == SigmaBinary.mapViewFixerList[body.transform.name]);

((MapContextMenu)fields[1].GetValue(targeter)).Dismiss();

Expand Down
28 changes: 6 additions & 22 deletions [Source]/SigmaBinary/PeriodFixer.cs
Expand Up @@ -4,38 +4,22 @@

namespace SigmaBinaryPlugin
{
[KSPAddon(KSPAddon.Startup.Instantly, true)]
public class PeriodFxixer : MonoBehaviour
public class PeriodFixer : MonoBehaviour
{
public void Start()
void Start()
{
Kopernicus.Events.OnPostFixing.Add(FixPeriods);
}

public void FixPeriods()
{
var bodies = FlightGlobals.Bodies;

for (int i = 0; i < bodies?.Count; i++)
foreach (CelestialBody cb in FlightGlobals.Bodies)
{
CelestialBody cb = bodies[i];

if (SigmaBinary.periodFixerList.ContainsKey(cb.transform.name))
{
Debug.Log("PeriodFixer", "Fixing orbital period of body " + cb + ", old orbital period = " + cb.orbit.period);

cb.orbit.orbitalSpeed *= cb.orbit.period;
cb.orbit.period = SigmaBinary.periodFixerList[cb.transform.name];
cb.orbit.meanMotion = 2 * Math.PI / cb.orbit.period;
cb.orbit.ObTAtEpoch = cb.orbit.meanAnomalyAtEpoch / 2 / Math.PI * cb.orbit.period;
cb.orbit.orbitalSpeed /= cb.orbit.period;
Debug.Log("PeriodFixer", "Fixed orbital period of body " + cb + ", new orbital period = " + cb.orbit.period);

if (cb.tidallyLocked)
{
cb.rotationPeriod = cb.orbit.period;
Debug.Log("PeriodFixer", "Fixed rotation period of tidallyLocked body " + cb + ", new rotation period = " + cb.rotationPeriod);
}


SigmaBinary.periodFixerList.Remove(cb.transform.name);
}
}
}
Expand Down

0 comments on commit 9049fe5

Please sign in to comment.