Skip to content

Commit

Permalink
Merge pull request #83 from Sigma88/Development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Sigma88 authored Jun 23, 2019
2 parents f62e121 + 56429d8 commit eb6d45a
Show file tree
Hide file tree
Showing 21 changed files with 461 additions and 404 deletions.
7 changes: 7 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
**v0.10.4**

- Added compatibility with custom 'Orbit/period'
- Fixed performance drop in flight scene
- Fixed PQSCity and PQSCity2 altitude calculation


**v0.10.3**

- Updated to KSP 1.7.1 and Kopernicus 1.7.1-4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
@Orbit
{
@semiMajorAxis *= #$../SigmaDimensions/Rescale$
@period != 0.666666666666666
@period *= #$../SigmaDimensions/Rescale$
@period != 1.5
@period /= #$../SigmaDimensions/Resize$
}
@PostSpawnOrbit
{
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.
12 changes: 0 additions & 12 deletions [Source]/SigmaDimensions/Configs.cs

This file was deleted.

2 changes: 1 addition & 1 deletion [Source]/SigmaDimensions/DebugLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal static void Log(string Method, string message)
}

[KSPAddon(KSPAddon.Startup.MainMenu, true)]
class DebugWarning : MonoBehaviour
internal class DebugWarning : MonoBehaviour
{
void Start()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace SigmaDimensionsPlugin
{
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
class AtmosphereTopLayer : MonoBehaviour
internal class AtmosphereTopLayer : MonoBehaviour
{
Ktype curve = Ktype.Exponential;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace SigmaDimensionsPlugin
{
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
class SigmaDimensions : MonoBehaviour
internal class SigmaDimensions : MonoBehaviour
{
double resize = 1;
double landscape = 1;
Expand Down Expand Up @@ -45,7 +45,6 @@ void Start()
}
}


// All PQSCity2 mods
PQSCity2[] cities2 = body.GetComponentsInChildren<PQSCity2>(true);

Expand All @@ -67,7 +66,6 @@ void CityFixer(PQSCity city)
// Resize the Building
city.transform.localScale *= (float)resizeBuildings;


// Fix PQSCity Groups
if (body.Has("PQSCityGroups"))
{
Expand All @@ -78,54 +76,60 @@ void CityFixer(PQSCity city)
}
}


// Add PQSCityFixer Component
PQSCityFixer fixer = city.GetComponent<PQSCityFixer>() ?? city.gameObject.AddComponent<PQSCityFixer>();

PQSCityFixer fixer = city.gameObject.AddOrGetComponent<PQSCityFixer>();

// Terrain
double groundLevel = body.pqsController.GetSurfaceHeight(city.repositionRadial) - body.Radius;
double oceanDepth = body.ocean && groundLevel < 0 ? -groundLevel : 0d;
Debug.Log("SigmaDimensions.CityFixer", " > Ground Level at Mod (GETSURFACE) = " + groundLevel);
double oceanOffset = body.ocean && groundLevel < 0 ? groundLevel : 0d;
Debug.Log("SigmaDimensions.CityFixer", " > Ocean Offset at Mod = " + oceanOffset);
groundLevel = body.ocean && groundLevel < 0 ? 0d : groundLevel;

Debug.Log("SigmaDimensions.CityFixer", " > Ground Level at Mod (WITH OCEAN) = " + groundLevel);

// Fix Altitude
if (city.repositionToSphere && !city.repositionToSphereSurface)
if (!city.repositionToSphere && !city.repositionToSphereSurface)
{
double builtInOffset = city.repositionRadiusOffset - groundLevel / (resize * landscape);
// Offset = Distance from the center of the planet
// THIS IS NOT POSSIBLE AS OF KSP 1.7.1

Debug.Log("SigmaDimensions.CityFixer", " > PQSCity Original Center Offset = " + city.repositionRadiusOffset);

double builtInOffset = city.repositionRadiusOffset - (groundLevel + oceanOffset) / (resize * landscape) - body.Radius / resize;

Debug.Log("SigmaDimensions.CityFixer", " > Builtin Offset = " + builtInOffset);

Debug.Log("SigmaDimensions.CityFixer", " > Builtuin Offset = " + builtInOffset);
city.repositionRadiusOffset = body.Radius + groundLevel + oceanOffset + builtInOffset * resizeBuildings;

Debug.Log("SigmaDimensions.CityFixer", " > PQSCity Fixed Center Offset = " + city.repositionRadiusOffset);
}
else if (city.repositionToSphere && !city.repositionToSphereSurface)
{
// Offset = Distance from the radius of the planet

Debug.Log("SigmaDimensions.CityFixer", " > PQSCity Original Radius Offset = " + city.repositionRadiusOffset);

double builtInOffset = city.repositionRadiusOffset - groundLevel / (resize * landscape);

Debug.Log("SigmaDimensions.CityFixer", " > Builtin Offset = " + builtInOffset);

city.repositionRadiusOffset = groundLevel + builtInOffset * resizeBuildings;

Debug.Log("SigmaDimensions.CityFixer", " > PQSCity Fixed Radius Offset = " + city.repositionRadiusOffset);
}
else
{
if (!city.repositionToSphereSurface)
{
city.repositionToSphereSurface = true;
city.repositionRadiusOffset = 0;
}
// Offset = Distance from the surface of the planet

if (!city.repositionToSphereSurfaceAddHeight)
{
city.repositionToSphereSurfaceAddHeight = true;
city.repositionRadiusOffset = 0;
}

double builtInOffset = city.repositionRadiusOffset - oceanDepth / (resize * landscape);

Debug.Log("SigmaDimensions.CityFixer", " > Builtuin Offset = " + builtInOffset);

// Offset = Distance from the surface of the planet

Debug.Log("SigmaDimensions.CityFixer", " > PQSCity Original Surface Offset = " + city.repositionRadiusOffset);

city.repositionRadiusOffset = oceanDepth + builtInOffset * resizeBuildings;
city.repositionRadiusOffset *= resizeBuildings;

Debug.Log("SigmaDimensions.CityFixer", " > PQSCity Fixed Surface Offset = " + city.repositionRadiusOffset);
}
Expand All @@ -138,7 +142,6 @@ void City2Fixer(PQSCity2 city)
// Resize the Building
city.transform.localScale *= (float)resizeBuildings;


// Fix PQSCity Groups
if (body.Has("PQSCityGroups"))
{
Expand All @@ -149,45 +152,41 @@ void City2Fixer(PQSCity2 city)
}
}


// Add PQSCity2Fixer Component
PQSCity2Fixer fixer = city.GetComponent<PQSCity2Fixer>() ?? city.gameObject.AddComponent<PQSCity2Fixer>();

PQSCity2Fixer fixer = city.gameObject.AddOrGetComponent<PQSCity2Fixer>();

// Terrain
double groundLevel = body.pqsController.GetSurfaceHeight(city.PlanetRelativePosition) - body.Radius;
double oceanDepth = body.ocean && groundLevel < 0 ? -groundLevel : 0d;
Debug.Log("SigmaDimensions.City2Fixer", " > Ground Level at Mod (GETSURFACE) = " + groundLevel);
double oceanOffset = body.ocean && groundLevel < 0 ? groundLevel : 0d;
Debug.Log("SigmaDimensions.City2Fixer", " > Ocean Offset at Mod = " + oceanOffset);
groundLevel = body.ocean && groundLevel < 0 ? 0d : groundLevel;

Debug.Log("SigmaDimensions.City2Fixer", " > Ground Level at Mod (WITH OCEAN) = " + groundLevel);

// Fix Altitude
if (!city.snapToSurface)
{
double builtInOffset = city.alt - groundLevel / (resize * landscape);

Debug.Log("SigmaDimensions.City2Fixer", " > Builtuin Offset = " + builtInOffset);

// Offset = Distance from the radius of the planet

Debug.Log("SigmaDimensions.City2Fixer", " > PQSCity Original Radius Offset = " + city.alt);

double builtInOffset = city.alt - groundLevel / (resize * landscape);

Debug.Log("SigmaDimensions.City2Fixer", " > Builtin Offset = " + builtInOffset);

city.alt = groundLevel + builtInOffset * resizeBuildings;

Debug.Log("SigmaDimensions.City2Fixer", " > PQSCity Fixed Radius Offset = " + city.alt);
}
else
{
double builtInOffset = city.snapHeightOffset - oceanDepth / (resize * landscape);

Debug.Log("SigmaDimensions.CityFixer", " > Builtuin Offset = " + builtInOffset);

// Offset = Distance from the surface of the planet

Debug.Log("SigmaDimensions.CityFixer", " > PQSCity Original Surface Offset = " + city.snapHeightOffset);
Debug.Log("SigmaDimensions.City2Fixer", " > PQSCity Original Surface Offset = " + city.snapHeightOffset);

city.snapHeightOffset = oceanDepth + builtInOffset * resizeBuildings;
city.snapHeightOffset *= resizeBuildings;

Debug.Log("SigmaDimensions.CityFixer", " > PQSCity Fixed Surface Offset = " + city.snapHeightOffset);
Debug.Log("SigmaDimensions.City2Fixer", " > PQSCity Fixed Surface Offset = " + city.snapHeightOffset);
}
}

Expand Down
29 changes: 29 additions & 0 deletions [Source]/SigmaDimensions/PQSCity/LightsFixer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using UnityEngine;
using Kopernicus;


namespace SigmaDimensionsPlugin
{
[KSPAddon(KSPAddon.Startup.SpaceCentre, true)]
internal class LightsFixer : MonoBehaviour
{
void Start()
{
foreach (CelestialBody cb in FlightGlobals.Bodies)
{
if (cb?.pqsController != null)
{
if (cb.Has("resizeBuildings"))
{
float resizeBuildings = (float)cb.Get<double>("resizeBuildings");

foreach (Light light in cb.pqsController.GetComponentsInChildren<Light>(true))
{
light.range *= resizeBuildings;
}
}
}
}
}
}
}
117 changes: 117 additions & 0 deletions [Source]/SigmaDimensions/PQSCity/PQSCity2Fixer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using UnityEngine;
using Kopernicus;


namespace SigmaDimensionsPlugin
{
public class PQSCity2Fixer : MonoBehaviour
{
double time = 0;

void Update()
{
if (time < 0.2)
{
time += Time.deltaTime;
}
else
{
time = 0;

CelestialBody body = FlightGlobals.currentMainBody;
if (body == null) return;

PQS pqs = body.pqsController;
if (pqs == null) return;

PQSCity2 city = GetComponent<PQSCity2>();
if (city == null) return;

// Location
Vector3 planet = body.transform.position;
Vector3 building = city.transform.position; // From body to city
Vector3 location = (building - planet).normalized;

// Sigma Dimensions Settings
double resize = body.Has("resize") ? body.Get<double>("resize") : 1;
double landscape = body.Has("landscape") ? body.Get<double>("landscape") : 1;
double resizeBuildings = body.Has("resizeBuildings") ? body.Get<double>("resizeBuildings") : 1;

// Max distance
double maxDistance = Math.Abs(2 * pqs.mapMaxHeight);
maxDistance *= resize * landscape > 1 ? resize * landscape : 1;
maxDistance += body.Radius;

RaycastHit[] hits = Physics.RaycastAll(planet + location * (float)maxDistance, -location, (float)maxDistance, LayerMask.GetMask("Local Scenery"));

for (int i = 0; i < hits?.Length; i++)
{
if (hits[i].collider?.GetComponent<PQ>())
{
Debug.Log("PQSCity2Fixer", "> Planet: " + body.transform.name);
Debug.Log("PQSCity2Fixer", " > PQSCity2: " + city);

// PQSCity2 parameters
double oldGroundLevel = pqs.GetSurfaceHeight(city.PlanetRelativePosition) - body.Radius;
Debug.Log("PQSCity2Fixer", " > Old Ground Level at Mod (GETSURFACE) = " + oldGroundLevel);
double oldOceanOffset = body.ocean && oldGroundLevel < 0 ? oldGroundLevel : 0d;
Debug.Log("PQSCity2Fixer", " > Old Ocean Offset at Mod = " + oldOceanOffset);
oldGroundLevel = body.ocean && oldGroundLevel < 0 ? 0d : oldGroundLevel;
Debug.Log("PQSCity2Fixer", " > Old Ground Level at Mod (WITH OCEAN) = " + oldGroundLevel);

double groundLevel = (hits[i].point - planet).magnitude - body.Radius;
Debug.Log("PQSCity2Fixer", " > Ground Level at Mod (RAYCAST) = " + groundLevel);
double oceanOffset = body.ocean && groundLevel < 0 ? groundLevel : 0d;
Debug.Log("PQSCity2Fixer", " > Ocean Offset at Mod = " + oceanOffset);
groundLevel = body.ocean && groundLevel < 0 ? 0d : groundLevel;
Debug.Log("PQSCity2Fixer", " > Ground Level at Mod (NEW) = " + groundLevel);

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

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

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

double builtInOffset = (city.alt - oldGroundLevel) / resizeBuildings - (groundLevel - oldGroundLevel) / (resize * landscape);

Debug.Log("PQSCity2Fixer", " > Builtin Offset = " + builtInOffset);

city.alt = groundLevel + builtInOffset * resizeBuildings;

Debug.Log("PQSCity2Fixer", " > PQSCity2 Fixed Radius Offset = " + city.alt);
}
else
{
// Offset = Distance from the surface of the planet

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

double builtInOffset = city.snapHeightOffset / resizeBuildings - (groundLevel + oceanOffset - oldGroundLevel - oldOceanOffset) / (resize * landscape);

Debug.Log("PQSCity2Fixer", " > Builtin Offset = " + builtInOffset);

double newOffset = builtInOffset * resizeBuildings + groundLevel + oceanOffset - oldGroundLevel - oldOceanOffset;

Debug.Log("PQSCity2Fixer", " > PQSCity2 Fixed Surface Offset = " + newOffset);

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

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

// Apply Changes and Destroy
city.Orientate();
DestroyImmediate(this);
}
}
}
}
}
}
Loading

0 comments on commit eb6d45a

Please sign in to comment.