Skip to content

Commit

Permalink
Development (#35)
Browse files Browse the repository at this point in the history
* small improvements and contractWeight

* not required anymore

* contractWeight

* fix logspam and contracts

* not needed

* avoid infinites

* recompile

* added version.cs

* recompile

* changelog and version

* remove contracts crap from the plugin

* now it's not my problem anymore

* recompile

* new version log and recompile
  • Loading branch information
Sigma88 committed Sep 3, 2017
1 parent dd9dffb commit bb9d3b6
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 46 deletions.
6 changes: 6 additions & 0 deletions Changelog.txt
@@ -1,3 +1,9 @@
**v1.6.5**

- Fixed log spam on binary system flybys
- Blocked generation of undesired contracts


**v1.6.4**

- Updated to Kopernicus 1.3.0-4
Expand Down
1 change: 1 addition & 0 deletions GameData/Sigma/Binary/Configs/addOrbits.cfg
Expand Up @@ -39,6 +39,7 @@
{
name = #$/Body[SigmaOrbit]/SigmaBinary/name$Orbit
barycenter = True
contractWeight = 0
Template
{
name = Jool
Expand Down
14 changes: 7 additions & 7 deletions GameData/Sigma/Binary/Configs/generateBarycenters.cfg
@@ -1,22 +1,22 @@
@Kopernicus:FOR[SigmaBinary]
{
@Body,*
{
!SigmaBarycenter,* = DEL
}
+Body:HAS[@SigmaBinary]
{
@name = SigmaBarycenter
}
}

@Contracts:FOR[SigmaBinary]
{
#@Kopernicus {}
}

@Kopernicus:HAS[@Body[SigmaBarycenter]]:FOR[SigmaBinary]
{
Body
{
name = #$/Body[SigmaBarycenter]/SigmaBinary/name$
SigmaBarycenter = True
contractWeight = 0
Template
{
name = Jool
Expand Down Expand Up @@ -49,9 +49,9 @@
exportMesh = false
}
}
@Body:HAS[#SigmaBarycenter[True]]
@Body,*
{
!SigmaBarycenter = DEL
!SigmaBarycenter,* = DEL
}
!Body[SigmaBarycenter] {}
MM_PATCH_LOOP {}
Expand Down
31 changes: 0 additions & 31 deletions GameData/Sigma/Binary/Configs/removeContracts.cfg

This file was deleted.

Binary file modified GameData/Sigma/Binary/Plugins/SigmaBinary.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion GameData/Sigma/Binary/Sigma-Binary.version
Expand Up @@ -13,7 +13,7 @@
{
"MAJOR": 1,
"MINOR": 6,
"PATCH": 4,
"PATCH": 5,
"BUILD": 0
},
"KSP_VERSION":
Expand Down
Binary file modified [Source]/Distribution/SigmaBinary.dll
Binary file not shown.
135 changes: 135 additions & 0 deletions [Source]/SigmaBinary/EncounterMathFixer.cs
@@ -0,0 +1,135 @@
using System;
using UnityEngine;


namespace SigmaBinaryPlugin
{
public class EncounterMathFixer
{
public static int FindClosestPointsRevertedCauseNewOneSucks(Orbit p, Orbit s, ref double CD, ref double CCD, ref double FFp, ref double FFs, ref double SFp, ref double SFs, double epsilon, int maxIterations, ref int iterationCount)
{
Orbit.FindClosestPoints_old(p, s, ref CD, ref CCD, ref FFp, ref FFs, ref SFp, ref SFs, epsilon, maxIterations, ref iterationCount);
return 2;
}

public static bool CheckEncounterButDontBitchAboutIt(Orbit p, Orbit nextPatch, double startEpoch, OrbitDriver sec, CelestialBody targetBody, PatchedConics.SolverParameters pars)
{
Orbit orbit = sec.orbit;
double num = 1.1;
if (GameSettings.ALWAYS_SHOW_TARGET_APPROACH_MARKERS && sec.celestialBody == targetBody)
{
num = Math.Sqrt(orbit.semiMajorAxis / sec.celestialBody.sphereOfInfluence);
}
if (!Orbit.PeApIntersects(p, orbit, sec.celestialBody.sphereOfInfluence * num))
{
return false;
}
if (p.closestEncounterLevel < Orbit.EncounterSolutionLevel.ORBIT_INTERSECT)
{
p.closestEncounterLevel = Orbit.EncounterSolutionLevel.ORBIT_INTERSECT;
p.closestEncounterBody = sec.celestialBody;
}
double clEctr = p.ClEctr1;
double clEctr2 = p.ClEctr2;
double fEVp = p.FEVp;
double fEVs = p.FEVs;
double sEVp = p.SEVp;
double sEVs = p.SEVs;
int num2 = Orbit.FindClosestPoints(p, orbit, ref clEctr, ref clEctr2, ref fEVp, ref fEVs, ref sEVp, ref sEVs, 0.0001, pars.maxGeometrySolverIterations, ref pars.GeoSolverIterations);
if (num2 < 1)
{
return false;
}
double dTforTrueAnomaly = p.GetDTforTrueAnomaly(fEVp, 0.0);
double dTforTrueAnomaly2 = p.GetDTforTrueAnomaly(sEVp, 0.0);
double num3 = dTforTrueAnomaly + startEpoch;
double num4 = dTforTrueAnomaly2 + startEpoch;

// avoid bad numbers
if (double.IsInfinity(num3) && !double.IsInfinity(num4))
num3 = num4;
if (double.IsInfinity(num4) && !double.IsInfinity(num3))
num4 = num3;

if (double.IsInfinity(num3) && double.IsInfinity(num4))
{
Debug.Log("CheckEncounter: both intercept UTs are infinite");
return false;
}
if ((num3 < p.StartUT || num3 > p.EndUT) && (num4 < p.StartUT || num4 > p.EndUT))
{
return false;
}
if (num4 < num3 || num3 < p.StartUT || num3 > p.EndUT)
{
UtilMath.SwapValues(ref fEVp, ref sEVp);
UtilMath.SwapValues(ref fEVs, ref sEVs);
UtilMath.SwapValues(ref clEctr, ref clEctr2);
UtilMath.SwapValues(ref dTforTrueAnomaly, ref dTforTrueAnomaly2);
UtilMath.SwapValues(ref num3, ref num4);
}
if (num4 < p.StartUT || num4 > p.EndUT || double.IsInfinity(num4))
{
num2 = 1;
}
p.numClosePoints = num2;
p.FEVp = fEVp;
p.FEVs = fEVs;
p.SEVp = sEVp;
p.SEVs = sEVs;
p.ClEctr1 = clEctr;
p.ClEctr2 = clEctr2;
if (Math.Min(p.ClEctr1, p.ClEctr2) > sec.celestialBody.sphereOfInfluence)
{
if (GameSettings.ALWAYS_SHOW_TARGET_APPROACH_MARKERS && sec.celestialBody == targetBody)
{
p.UTappr = startEpoch;
p.ClAppr = PatchedConics.GetClosestApproach(p, orbit, startEpoch, p.nearestTT * 0.5, pars);
p.closestTgtApprUT = p.UTappr;
}
return false;
}
if (p.closestEncounterLevel < Orbit.EncounterSolutionLevel.SOI_INTERSECT_1)
{
p.closestEncounterLevel = Orbit.EncounterSolutionLevel.SOI_INTERSECT_1;
p.closestEncounterBody = sec.celestialBody;
}
p.timeToTransition1 = dTforTrueAnomaly;
p.secondaryPosAtTransition1 = orbit.getPositionAtUT(num3);
Debug.DrawLine(ScaledSpace.LocalToScaledSpace(p.referenceBody.position), ScaledSpace.LocalToScaledSpace(p.secondaryPosAtTransition1), Color.yellow);
p.timeToTransition2 = dTforTrueAnomaly2;
p.secondaryPosAtTransition2 = orbit.getPositionAtUT(num4);
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))
{
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);
if (PatchedConics.EncountersBody(p, orbit, nextPatch, sec, startEpoch, pars))
{
return true;
}
if (num2 > 1)
{
p.closestEncounterLevel = Orbit.EncounterSolutionLevel.SOI_INTERSECT_2;
p.closestEncounterBody = sec.celestialBody;
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;
}
Debug.DrawLine(ScaledSpace.LocalToScaledSpace(p.getPositionAtUT(p.UTappr)), ScaledSpace.LocalToScaledSpace(orbit.getPositionAtUT(p.UTappr)), XKCDColors.Orange);
}
if (sec.celestialBody == targetBody)
{
p.closestTgtApprUT = p.UTappr;
}
return false;
}
}
}
7 changes: 1 addition & 6 deletions [Source]/SigmaBinary/SigmaBinary.cs
Expand Up @@ -5,6 +5,7 @@
using Kopernicus.Components;
using Kopernicus.Configuration;
using Kopernicus;
using Contracts;


namespace SigmaBinaryPlugin
Expand Down Expand Up @@ -272,12 +273,6 @@ void IParserEventSubscriber.PostApply(ConfigNode node)
}
}

public static int FindClosestPointsReverted(Orbit p, Orbit s, ref double CD, ref double CCD, ref double FFp, ref double FFs, ref double SFp, ref double SFs, double epsilon, int maxIterations, ref int iterationCount)
{
Orbit.FindClosestPoints_old(p, s, ref CD, ref CCD, ref FFp, ref FFs, ref SFp, ref SFs, epsilon, maxIterations, ref iterationCount);
return 2;
}

public string OrbitPatcher(Body body)
{
// This if is here to make sure stars don't give us trouble
Expand Down
2 changes: 2 additions & 0 deletions [Source]/SigmaBinary/SigmaBinary.csproj
Expand Up @@ -31,6 +31,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="EncounterMathFixer.cs" />
<Compile Include="MapViewFixer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SigmaBinaryLoader.cs" />
Expand All @@ -39,6 +40,7 @@
<Compile Include="KerbinFixer.cs" />
<Compile Include="PeriodFixer.cs" />
<Compile Include="LateFixes.cs" />
<Compile Include="Version.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down
3 changes: 2 additions & 1 deletion [Source]/SigmaBinary/SigmaBinaryLoader.cs
Expand Up @@ -58,7 +58,8 @@ public NumericParser<bool> redrawOrbit

void IParserEventSubscriber.Apply(ConfigNode node)
{
Orbit.FindClosestPoints = SigmaBinary.FindClosestPointsReverted;
Orbit.FindClosestPoints = new Orbit.FindClosestPointsDelegate(EncounterMathFixer.FindClosestPointsRevertedCauseNewOneSucks);
PatchedConics.CheckEncounter = new PatchedConics.CheckEncounterDelegate(EncounterMathFixer.CheckEncounterButDontBitchAboutIt);
periodFixer = generatedBody.celestialBody.gameObject.AddComponent<PeriodFixer>();
kerbinFixer = generatedBody.celestialBody.gameObject.AddComponent<KerbinFixer>();
}
Expand Down
14 changes: 14 additions & 0 deletions [Source]/SigmaBinary/Version.cs
@@ -0,0 +1,14 @@
using UnityEngine;


namespace SigmaBinaryPlugin
{
[KSPAddon(KSPAddon.Startup.Instantly, true)]
class Version : MonoBehaviour
{
void Awake()
{
Debug.Log("[SigmaLog] Version Check: Sigma Binary v1.6.5");
}
}
}

0 comments on commit bb9d3b6

Please sign in to comment.