Singularities now go under props, can have multiple per planet

This commit is contained in:
Nick 2022-06-29 17:41:54 -04:00
parent 10f4f477e6
commit 1e3f941286
10 changed files with 89 additions and 53 deletions

View File

@ -93,18 +93,21 @@ namespace NewHorizons.Builder.Body
if (realSize < body.Config.Sand.size) realSize = body.Config.Sand.size; if (realSize < body.Config.Sand.size) realSize = body.Config.Sand.size;
} }
// Could improve this to actually use the proper renders and materials // Could improve this to actually use the proper renders and materials
if (body.Config.Singularity != null) if (body.Config.Props?.singularities != null)
{ {
if (body.Config.Singularity.type == SingularityModule.SingularityType.BlackHole) foreach(var singularity in body.Config.Props.singularities)
{ {
MakeBlackHole(newProxy, body.Config.Singularity.size); if (singularity.type == SingularityModule.SingularityType.BlackHole)
} {
else MakeBlackHole(newProxy, singularity.size);
{ }
MakeWhiteHole(newProxy, body.Config.Singularity.size); else
} {
MakeWhiteHole(newProxy, singularity.size);
}
if (realSize < body.Config.Singularity.size) realSize = body.Config.Singularity.size; if (realSize < singularity.size) realSize = singularity.size;
}
} }
if (body.Config.Base.hasCometTail) if (body.Config.Base.hasCometTail)
{ {

View File

@ -5,6 +5,9 @@ using System;
using NewHorizons.External.Modules.VariableSize; using NewHorizons.External.Modules.VariableSize;
using UnityEngine; using UnityEngine;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
using System.Collections.Generic;
using System.Linq;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {
public static class SingularityBuilder public static class SingularityBuilder
@ -18,61 +21,73 @@ namespace NewHorizons.Builder.Body
private static readonly int DistortFadeDist = Shader.PropertyToID("_DistortFadeDist"); private static readonly int DistortFadeDist = Shader.PropertyToID("_DistortFadeDist");
private static readonly int Color1 = Shader.PropertyToID("_Color"); private static readonly int Color1 = Shader.PropertyToID("_Color");
public static void Make(GameObject go, Sector sector, OWRigidbody OWRB, PlanetConfig config) private static Dictionary<string, GameObject> _singularitiesByID;
public static void Make(GameObject go, Sector sector, OWRigidbody OWRB, PlanetConfig config, SingularityModule singularity)
{ {
var size = config.Singularity.size; // If we've reloaded the first one will now be null so we have to refresh the list
var pairedSingularity = config.Singularity.pairedSingularity; if (_singularitiesByID?.Values?.FirstOrDefault() == null) _singularitiesByID = new Dictionary<string, GameObject>();
var polarity = config.Singularity.type; var size = singularity.size;
var pairedSingularity = singularity.pairedSingularity;
bool isWormHole = config.Singularity?.targetStarSystem != null; var polarity = singularity.type;
bool isWormHole = singularity?.targetStarSystem != null;
bool hasHazardVolume = !isWormHole && (pairedSingularity == null); bool hasHazardVolume = !isWormHole && (pairedSingularity == null);
bool makeZeroGVolume = config.Singularity == null ? true : config.Singularity.makeZeroGVolume; bool makeZeroGVolume = singularity == null ? true : singularity.makeZeroGVolume;
Vector3 localPosition = config.Singularity?.position == null ? Vector3.zero : (Vector3)config.Singularity.position; Vector3 localPosition = singularity?.position == null ? Vector3.zero : singularity.position;
GameObject newSingularity = null; GameObject newSingularity = null;
switch (polarity) switch (polarity)
{ {
case SingularityModule.SingularityType.BlackHole: case SingularityModule.SingularityType.BlackHole:
newSingularity = MakeBlackHole(go, sector, localPosition, size, hasHazardVolume, config.Singularity.targetStarSystem); newSingularity = MakeBlackHole(go, sector, localPosition, size, hasHazardVolume, singularity.targetStarSystem);
break; break;
case SingularityModule.SingularityType.WhiteHole: case SingularityModule.SingularityType.WhiteHole:
newSingularity = MakeWhiteHole(go, sector, OWRB, localPosition, size, makeZeroGVolume); newSingularity = MakeWhiteHole(go, sector, OWRB, localPosition, size, makeZeroGVolume);
break; break;
} }
var uniqueID = string.IsNullOrEmpty(singularity.uniqueID) ? config.name : singularity.uniqueID;
_singularitiesByID.Add(uniqueID, newSingularity);
// Try to pair them // Try to pair them
if (pairedSingularity != null && newSingularity != null) if (!string.IsNullOrEmpty(pairedSingularity) && newSingularity != null)
{ {
var pairedSingularityAO = AstroObjectLocator.GetAstroObject(pairedSingularity); if (_singularitiesByID.TryGetValue(pairedSingularity, out var pairedSingularityGO))
if (pairedSingularityAO != null)
{ {
switch (polarity) switch (polarity)
{ {
case SingularityModule.SingularityType.BlackHole: case SingularityModule.SingularityType.BlackHole:
PairSingularities(newSingularity, pairedSingularityAO.gameObject); PairSingularities(uniqueID, pairedSingularity, newSingularity, pairedSingularityGO);
break; break;
case SingularityModule.SingularityType.WhiteHole: case SingularityModule.SingularityType.WhiteHole:
PairSingularities(pairedSingularityAO.gameObject, newSingularity); PairSingularities(pairedSingularity, uniqueID, pairedSingularityGO, newSingularity);
break; break;
} }
} }
} }
} }
public static void PairSingularities(GameObject blackHole, GameObject whiteHole) public static void PairSingularities(string blackHoleID, string whiteHoleID, GameObject blackHole, GameObject whiteHole)
{ {
Logger.Log($"Pairing singularities {blackHole?.name}, {whiteHole?.name}"); if (blackHole == null || whiteHole == null) return;
try
Logger.Log($"Pairing singularities [{blackHoleID}], [{whiteHoleID}]");
var whiteHoleVolume = whiteHole.GetComponentInChildren<WhiteHoleVolume>();
var blackHoleVolume = blackHole.GetComponentInChildren<BlackHoleVolume>();
if (whiteHoleVolume == null || blackHoleVolume == null)
{ {
blackHole.GetComponentInChildren<BlackHoleVolume>()._whiteHole = whiteHole.GetComponentInChildren<WhiteHoleVolume>(); Logger.Log($"[{blackHoleID}] and [{whiteHoleID}] do not have compatible polarities");
} return;
catch (Exception)
{
Logger.LogError($"Couldn't pair singularities");
} }
blackHoleVolume._whiteHole = whiteHoleVolume;
} }
public static GameObject MakeBlackHole(GameObject planetGO, Sector sector, Vector3 localPosition, float size, bool hasDestructionVolume, string targetSolarSystem, bool makeAudio = true) public static GameObject MakeBlackHole(GameObject planetGO, Sector sector, Vector3 localPosition, float size, bool hasDestructionVolume, string targetSolarSystem, bool makeAudio = true)

View File

@ -15,8 +15,8 @@ namespace NewHorizons.Builder.General
var gravityRadius = GM / 0.1f; var gravityRadius = GM / 0.1f;
if (exponent == 2f) gravityRadius = Mathf.Sqrt(gravityRadius); if (exponent == 2f) gravityRadius = Mathf.Sqrt(gravityRadius);
// To let you actually orbit things the way you would expect we cap this at 4x the diameter if its not a star or black hole (this is what giants deep has) // To let you actually orbit things the way you would expect we cap this at 4x the diameter if its not a star (this is what giants deep has)
if (config.Star == null && config.Singularity == null) gravityRadius = Mathf.Min(gravityRadius, 4 * config.Base.surfaceSize); if (config.Star == null) gravityRadius = Mathf.Min(gravityRadius, 4 * config.Base.surfaceSize);
else gravityRadius = Mathf.Min(gravityRadius, 15 * config.Base.surfaceSize); else gravityRadius = Mathf.Min(gravityRadius, 15 * config.Base.surfaceSize);
if (config.Base.soiOverride != 0f) gravityRadius = config.Base.soiOverride; if (config.Base.soiOverride != 0f) gravityRadius = config.Base.soiOverride;

View File

@ -52,7 +52,6 @@ namespace NewHorizons.Builder.Orbital
if (config.Orbit.tint != null) color = config.Orbit.tint.ToColor(); if (config.Orbit.tint != null) color = config.Orbit.tint.ToColor();
else if (config.Star?.tint != null) color = config.Star.tint.ToColor(); else if (config.Star?.tint != null) color = config.Star.tint.ToColor();
else if (config.Atmosphere?.clouds?.tint != null) color = config.Atmosphere.clouds.tint.ToColor(); else if (config.Atmosphere?.clouds?.tint != null) color = config.Atmosphere.clouds.tint.ToColor();
else if (config.Singularity != null) color = new Color(1f, 0.5f, 1f);
else if (config.Water != null) color = new Color(0.5f, 0.5f, 1f); else if (config.Water != null) color = new Color(0.5f, 0.5f, 1f);
else if (config.Lava != null) color = new Color(1f, 0.5f, 0.5f); else if (config.Lava != null) color = new Color(1f, 0.5f, 0.5f);
else if (config.Atmosphere != null && config.Atmosphere.fogTint != null) color = config.Atmosphere.fogTint.ToColor(); else if (config.Atmosphere != null && config.Atmosphere.fogTint != null) color = config.Atmosphere.fogTint.ToColor();

View File

@ -1,3 +1,4 @@
using NewHorizons.Builder.Body;
using NewHorizons.Builder.ShipLog; using NewHorizons.Builder.ShipLog;
using NewHorizons.External.Configs; using NewHorizons.External.Configs;
using OWML.Common; using OWML.Common;
@ -191,6 +192,13 @@ namespace NewHorizons.Builder.Props
} }
} }
} }
if (config.Props.singularities != null)
{
foreach (var singularity in config.Props.singularities)
{
SingularityBuilder.Make(go, sector, go.GetComponent<OWRigidbody>(), config, singularity);
}
}
} }
} }
} }

View File

@ -522,14 +522,6 @@ namespace NewHorizons.Builder.ShipLog
{ {
try try
{ {
switch (body.Config?.Singularity?.type)
{
case SingularityModule.SingularityType.BlackHole:
return Color.black;
case SingularityModule.SingularityType.WhiteHole:
return Color.white;
}
var starColor = body.Config?.Star?.tint; var starColor = body.Config?.Star?.tint;
if (starColor != null) return starColor.ToColor(); if (starColor != null) return starColor.ToColor();
@ -555,6 +547,14 @@ namespace NewHorizons.Builder.ShipLog
var sandColor = body.Config.Sand?.tint; var sandColor = body.Config.Sand?.tint;
if (sandColor != null) return sandColor.ToColor(); if (sandColor != null) return sandColor.ToColor();
switch (body.Config?.Props?.singularities?.FirstOrDefault()?.type)
{
case SingularityModule.SingularityType.BlackHole:
return Color.black;
case SingularityModule.SingularityType.WhiteHole:
return Color.white;
}
} }
catch (Exception) catch (Exception)
{ {

View File

@ -45,6 +45,9 @@ namespace NewHorizons.External.Configs
[Obsolete("ChildrenToDestroy is deprecated, please use RemoveChildren instead")] [Obsolete("ChildrenToDestroy is deprecated, please use RemoveChildren instead")]
public string[] childrenToDestroy; public string[] childrenToDestroy;
[Obsolete("Singularity is deprecated, please use Props->singularities")]
public SingularityModule Singularity;
#endregion Obsolete #endregion Obsolete
/// <summary> /// <summary>
@ -133,11 +136,6 @@ namespace NewHorizons.External.Configs
/// </summary> /// </summary>
public SignalModule Signal; public SignalModule Signal;
/// <summary>
/// Add a black or white hole to this planet
/// </summary>
public SingularityModule Singularity;
/// <summary> /// <summary>
/// Spawn the player at this planet /// Spawn the player at this planet
/// </summary> /// </summary>
@ -323,6 +321,13 @@ namespace NewHorizons.External.Configs
} }
} }
// Singularity is now a list in props so you can have many per planet
if (Singularity != null)
{
if (Props == null) Props = new PropModule();
if (Props.singularities == null) Props.singularities = new SingularityModule[0];
Props.singularities = Props.singularities.Append(Singularity).ToArray();
}
} }
} }
} }

View File

@ -6,6 +6,7 @@ using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
using System; using System;
using NewHorizons.External.Modules.VariableSize;
namespace NewHorizons.External.Modules namespace NewHorizons.External.Modules
{ {
@ -77,6 +78,11 @@ namespace NewHorizons.External.Modules
/// </summary> /// </summary>
public VolcanoInfo[] volcanoes; public VolcanoInfo[] volcanoes;
/// <summary>
/// Add black/white-holes to this planet
/// </summary>
public SingularityModule[] singularities;
[JsonObject] [JsonObject]
public class ScatterInfo public class ScatterInfo
{ {

View File

@ -1,4 +1,4 @@
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using NewHorizons.Utility; using NewHorizons.Utility;
@ -24,11 +24,16 @@ namespace NewHorizons.External.Modules.VariableSize
[DefaultValue(true)] public bool makeZeroGVolume = true; [DefaultValue(true)] public bool makeZeroGVolume = true;
/// <summary> /// <summary>
/// The name of the white hole or black hole that is paired to this one. If you don't set a value, entering will kill /// The uniqueID of the white hole or black hole that is paired to this one. If you don't set a value, entering will kill
/// the player /// the player
/// </summary> /// </summary>
public string pairedSingularity; public string pairedSingularity;
/// <summary>
/// The uniqueID of this white hole or black hole. If not set it will default to the name of the planet
/// </summary>
public string uniqueID;
/// <summary> /// <summary>
/// Position of the singularity /// Position of the singularity
/// </summary> /// </summary>

View File

@ -469,11 +469,6 @@ namespace NewHorizons.Handlers
SignalBuilder.Make(go, sector, body.Config.Signal, body.Mod); SignalBuilder.Make(go, sector, body.Config.Signal, body.Mod);
} }
if (body.Config.Singularity != null)
{
SingularityBuilder.Make(go, sector, rb, body.Config);
}
if (body.Config.Funnel != null) if (body.Config.Funnel != null)
{ {
FunnelBuilder.Make(go, go.GetComponentInChildren<ConstantForceDetector>(), rb, body.Config.Funnel); FunnelBuilder.Make(go, go.GetComponentInChildren<ConstantForceDetector>(), rb, body.Config.Funnel);