Skip to content

Commit

Permalink
Allow to add multiple HazardousBody configs, also, add heat control
Browse files Browse the repository at this point in the history
through a greyscale map
StollD committed Nov 17, 2018
1 parent abf47e0 commit 97b999a
Showing 4 changed files with 63 additions and 9 deletions.
11 changes: 10 additions & 1 deletion src/Kopernicus.Components/HazardousBody.cs
Original file line number Diff line number Diff line change
@@ -61,6 +61,11 @@ public class HazardousBody : MonoBehaviour
/// </summary>
public FloatCurve AltitudeCurve;

/// <summary>
/// Controls the amount of heat that is applied on each spot of the planet
/// </summary>
public MapSO HeatMap;

private CelestialBody _body;

/// <summary>
@@ -102,8 +107,12 @@ private IEnumerator<WaitForSeconds> Worker()
AltitudeCurve.Evaluate((Single)Vector3d.Distance(vessel.transform.position, _body.transform.position));
Double latitude = LatitudeCurve.Evaluate((Single)vessel.latitude);
Double longitude = LongitudeCurve.Evaluate((Single)vessel.longitude);

Double heat = altitude * latitude * longitude * HeatRate;
if (HeatMap != null)
{
heat *= HeatMap.GetPixelFloat((longitude + 180) / 360f, (latitude + 90) / 180f);
}
foreach (Part part in vessel.Parts)
part.temperature += heat;
}
9 changes: 7 additions & 2 deletions src/Kopernicus/Configuration/Body.cs
Original file line number Diff line number Diff line change
@@ -199,8 +199,8 @@ public NumericParser<Int32> contractWeight
[ParserTargetCollection("Particles", AllowMerge = true)]
public List<ParticleLoader> particles { get; set; }

[ParserTarget("HazardousBody")]
public HazardousBodyLoader hazardousBody { get; set; }
[ParserTargetCollection("HazardousBody", AllowMerge = true)]
public List<HazardousBodyLoader> hazardousBody { get; set; }

// Wrapper around the settings for the SpaceCenter
[ParserTarget("SpaceCenter", AllowMerge = true)]
@@ -409,6 +409,11 @@ public Body(CelestialBody celestialBody)
{
particles.Add(new ParticleLoader(particle));
}
hazardousBody = new List<HazardousBodyLoader>();
foreach (HazardousBody body in celestialBody.GetComponents<HazardousBody>())
{
hazardousBody.Add(new HazardousBodyLoader(body));
}
if (celestialBody.isHomeWorld)
{
spaceCenter = new SpaceCenterLoader(celestialBody);
50 changes: 45 additions & 5 deletions src/Kopernicus/Configuration/HazardousBodyLoader.cs
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
using Kopernicus.Components;
using System;
using Kopernicus.UI;
using UnityEngine;

namespace Kopernicus
{
@@ -81,6 +82,16 @@ public FloatCurveParser longitudeCurve
get { return Value.LongitudeCurve; }
set { Value.LongitudeCurve = value; }
}

// Controls the how much of the average heat gets applied at a certain longitude
[ParserTarget("HeatMap")]
[KittopiaDescription("Greyscale map for fine control of the heat on a planet. black = 0, white = 1")]
public MapSOParser_GreyScale<MapSO> heatMap
{
get { return Value.HeatMap; }
set { Value.HeatMap = value; }
}


[KittopiaDestructor]
public void Destroy()
@@ -89,7 +100,7 @@ public void Destroy()
}

/// <summary>
/// Creates a new Particle Loader from the Injector context.
/// Creates a new HazardousBody Loader from the Injector context.
/// </summary>
public HazardousBodyLoader()
{
@@ -98,13 +109,16 @@ public HazardousBodyLoader()
{
throw new InvalidOperationException("Must be executed in Injector context.");
}

// Store values
Value = generatedBody.celestialBody.gameObject.AddOrGetComponent<HazardousBody>();
Value = generatedBody.celestialBody.gameObject.AddComponent<HazardousBody>();
Value.AltitudeCurve = new FloatCurve(new[] {new Keyframe(0, 1)});
Value.LatitudeCurve = new FloatCurve(new[] {new Keyframe(0, 1)});
Value.LongitudeCurve = new FloatCurve(new[] {new Keyframe(0, 1)});
}

/// <summary>
/// Creates a new Particle Loader on a spawned CelestialBody.
/// Creates a new HazardousBody Loader on a spawned CelestialBody.
/// </summary>
[KittopiaConstructor(KittopiaConstructor.Parameter.CelestialBody)]
public HazardousBodyLoader(CelestialBody body)
@@ -116,7 +130,33 @@ public HazardousBodyLoader(CelestialBody body)
}

// Store values
Value = body.gameObject.AddOrGetComponent<HazardousBody>();
Value = body.gameObject.AddComponent<HazardousBody>();
Value.AltitudeCurve = new FloatCurve(new[] {new Keyframe(0, 1)});
Value.LatitudeCurve = new FloatCurve(new[] {new Keyframe(0, 1)});
Value.LongitudeCurve = new FloatCurve(new[] {new Keyframe(0, 1)});
}

/// <summary>
/// Creates a new HazardousBody Loader from an already existing component
/// </summary>
public HazardousBodyLoader(HazardousBody value)
{
// Store values
Value = value;

// Null safe
if (Value.AltitudeCurve == null)
{
Value.AltitudeCurve = new FloatCurve(new[] {new Keyframe(0, 1)});
}
if (Value.LatitudeCurve == null)
{
Value.LatitudeCurve = new FloatCurve(new[] {new Keyframe(0, 1)});
}
if (Value.LongitudeCurve == null)
{
Value.LongitudeCurve = new FloatCurve(new[] {new Keyframe(0, 1)});
}
}
}
}
2 changes: 1 addition & 1 deletion src/Kopernicus/RuntimeUtility/RuntimeUtility.cs
Original file line number Diff line number Diff line change
@@ -350,7 +350,7 @@ void LateUpdate()
ApplyOrbitVisibility();
RDFixer();
ApplyOrbitIconCustomization();

// Prevent the orbit lines from flickering
PlanetariumCamera.Camera.farClipPlane = 1e14f;

0 comments on commit 97b999a

Please sign in to comment.