Skip to content

Commit

Permalink
fix #68
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Sigma88 committed May 11, 2018
2 parents ddb5396 + a72f3c2 commit fee2538
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
5 changes: 5 additions & 0 deletions Changelog.txt
@@ -1,3 +1,8 @@
**v0.10.1**

- Fixed PQSCity2Fixer


**v0.10.0**

- Recompiled against KSP 1.4.3 and Kopernicus 1.4.3-1
Expand Down
Binary file modified GameData/Sigma/Dimensions/Plugins/SigmaDimensions.dll
Binary file not shown.
Binary file modified [Source]/Distribution/SigmaDimensions.dll
Binary file not shown.
51 changes: 24 additions & 27 deletions [Source]/SigmaDimensions/PQSCityFixer.cs
Expand Up @@ -7,12 +7,7 @@ namespace SigmaDimensionsPlugin
{
public class PQSCityFixer : MonoBehaviour
{
void Start()
{
TimingManager.UpdateAdd(TimingManager.TimingStage.Normal, FixAltitude);
}

void FixAltitude()
void Update()
{
CelestialBody body = FlightGlobals.currentMainBody;
if (body == null) return;
Expand Down Expand Up @@ -45,20 +40,18 @@ void FixAltitude()
{
if (hits[i].collider?.GetComponent<PQ>())
{
// Update only once
TimingManager.UpdateRemove(TimingManager.TimingStage.Normal, FixAltitude);
Debug.Log("PQSCityFixer", "> Planet: " + body.transform.name);
Debug.Log("PQSCityFixer", " > PQSCity: " + city);

// PQSCity parameters
double groundLevel = (hits[i].point - planet).magnitude - body.Radius;
Debug.Log("PQSCityFixer", " > Ground Level at Mod (RAYCAST) = " + groundLevel);
double error = pqs.GetSurfaceHeight(city.repositionRadial) - body.Radius - groundLevel;
Debug.Log("PQSCityFixer", " > Ground Level Error at Mod = " + error);
double oceanDepth = body.ocean && groundLevel < 0 ? -groundLevel : 0d;
Debug.Log("PQSCityFixer", " > Ocean Depth at Mod = " + oceanDepth);
groundLevel = body.ocean && groundLevel < 0 ? 0d : groundLevel;

Debug.Log("PQSCityFixer", " > Ground Level at Mod = " + groundLevel);
Debug.Log("PQSCityFixer", " > Ocean Depth at Mod = " + groundLevel);
Debug.Log("PQSCityFixer", " > Ground Level Error at Mod = " + groundLevel);
Debug.Log("PQSCityFixer", " > Ground Level at Mod (NEW) = " + groundLevel);

// Fix Altitude
if (city.repositionToSphere && !city.repositionToSphereSurface)
Expand Down Expand Up @@ -105,12 +98,7 @@ void FixAltitude()

public class PQSCity2Fixer : MonoBehaviour
{
void Start()
{
TimingManager.UpdateAdd(TimingManager.TimingStage.Normal, FixAltitude);
}

void FixAltitude()
void Update()
{
CelestialBody body = FlightGlobals.currentMainBody;
if (body == null) return;
Expand Down Expand Up @@ -143,26 +131,26 @@ void FixAltitude()
{
if (hits[i].collider?.GetComponent<PQ>())
{
// Update only once
TimingManager.UpdateRemove(TimingManager.TimingStage.Normal, FixAltitude);
Debug.Log("PQSCity2Fixer", "> Planet: " + body.transform.name);
Debug.Log("PQSCity2Fixer", " > PQSCity2: " + city);


// PQSCity2 parameters
double groundLevel = (hits[i].point - planet).magnitude - body.Radius;
Debug.Log("PQSCity2Fixer", " > Ground Level at Mod (RAYCAST) = " + groundLevel);
double error = pqs.GetSurfaceHeight(city.PlanetRelativePosition) - body.Radius - groundLevel;
Debug.Log("PQSCity2Fixer", " > Ground Level Error at Mod = " + error);
double oceanDepth = body.ocean && groundLevel < 0 ? -groundLevel : 0d;
Debug.Log("PQSCity2Fixer", " > Ocean Depth at Mod = " + oceanDepth);
groundLevel = body.ocean && groundLevel < 0 ? 0d : groundLevel;
Debug.Log("PQSCity2Fixer", " > Ground Level at Mod (NEW) = " + groundLevel);

Debug.Log("PQSCity2Fixer", " > Ground Level at Mod = " + groundLevel);
Debug.Log("PQSCity2Fixer", " > Ocean Depth at Mod = " + groundLevel);
Debug.Log("PQSCity2Fixer", " > Ground Level Error at Mod = " + groundLevel);
// Because, SQUAD
city.PositioningPoint.localPosition /= (float)(body.Radius + city.alt);

// Fix Altitude
if (!city.snapToSurface)
{
// Offset = Distance from the radius of the planet
// Alt = Distance from the radius of the planet

Debug.Log("PQSCity2Fixer", " > PQSCity2 Original Radius Offset = " + city.alt);

Expand All @@ -176,13 +164,22 @@ void FixAltitude()
}
else
{
// Offset = Distance from the surface of the planet

Debug.Log("PQSCity2Fixer", " > PQSCity2 Original Surface Offset = " + city.snapHeightOffset);

city.snapHeightOffset = oceanDepth + error / (resize * landscape) - (oceanDepth + error - city.snapHeightOffset) / resizeBuildings;
double newOffset = oceanDepth + error / (resize * landscape) - (oceanDepth + error - city.snapHeightOffset) / resizeBuildings;

city.alt += newOffset - city.snapHeightOffset;
city.snapHeightOffset = newOffset;

Debug.Log("PQSCity2Fixer", " > PQSCity2 Fixed Surface Offset = " + city.snapHeightOffset);
Debug.Log("PQSCity2Fixer", " > PQSCity2 New Surface Offset = " + city.snapHeightOffset);
}

// Because, SQUAD
city.PositioningPoint.localPosition *= (float)(body.Radius + city.alt);

// Apply Changes and Destroy
city.Orientate();
DestroyImmediate(this);
}
Expand Down
2 changes: 1 addition & 1 deletion [Source]/SigmaDimensions/Version.cs
Expand Up @@ -6,7 +6,7 @@ namespace SigmaDimensionsPlugin
[KSPAddon(KSPAddon.Startup.Instantly, true)]
public class Version : MonoBehaviour
{
public static readonly System.Version number = new System.Version("0.10.0");
public static readonly System.Version number = new System.Version("0.10.1");

void Awake()
{
Expand Down

0 comments on commit fee2538

Please sign in to comment.