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;
}
// 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)
{
MakeBlackHole(newProxy, singularity.size);
}
else
{
MakeWhiteHole(newProxy, body.Config.Singularity.size);
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)
{

View File

@ -5,6 +5,9 @@ using System;
using NewHorizons.External.Modules.VariableSize;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
using System.Collections.Generic;
using System.Linq;
namespace NewHorizons.Builder.Body
{
public static class SingularityBuilder
@ -18,61 +21,73 @@ namespace NewHorizons.Builder.Body
private static readonly int DistortFadeDist = Shader.PropertyToID("_DistortFadeDist");
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;
var pairedSingularity = config.Singularity.pairedSingularity;
// If we've reloaded the first one will now be null so we have to refresh the list
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 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;
switch (polarity)
{
case SingularityModule.SingularityType.BlackHole:
newSingularity = MakeBlackHole(go, sector, localPosition, size, hasHazardVolume, config.Singularity.targetStarSystem);
newSingularity = MakeBlackHole(go, sector, localPosition, size, hasHazardVolume, singularity.targetStarSystem);
break;
case SingularityModule.SingularityType.WhiteHole:
newSingularity = MakeWhiteHole(go, sector, OWRB, localPosition, size, makeZeroGVolume);
break;
}
var uniqueID = string.IsNullOrEmpty(singularity.uniqueID) ? config.name : singularity.uniqueID;
_singularitiesByID.Add(uniqueID, newSingularity);
// Try to pair them
if (pairedSingularity != null && newSingularity != null)
if (!string.IsNullOrEmpty(pairedSingularity) && newSingularity != null)
{
var pairedSingularityAO = AstroObjectLocator.GetAstroObject(pairedSingularity);
if (pairedSingularityAO != null)
if (_singularitiesByID.TryGetValue(pairedSingularity, out var pairedSingularityGO))
{
switch (polarity)
{
case SingularityModule.SingularityType.BlackHole:
PairSingularities(newSingularity, pairedSingularityAO.gameObject);
PairSingularities(uniqueID, pairedSingularity, newSingularity, pairedSingularityGO);
break;
case SingularityModule.SingularityType.WhiteHole:
PairSingularities(pairedSingularityAO.gameObject, newSingularity);
PairSingularities(pairedSingularity, uniqueID, pairedSingularityGO, newSingularity);
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}");
try
if (blackHole == null || whiteHole == null) return;
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>();
}
catch (Exception)
{
Logger.LogError($"Couldn't pair singularities");
Logger.Log($"[{blackHoleID}] and [{whiteHoleID}] do not have compatible polarities");
return;
}
blackHoleVolume._whiteHole = whiteHoleVolume;
}
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;
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)
if (config.Star == null && config.Singularity == null) gravityRadius = Mathf.Min(gravityRadius, 4 * config.Base.surfaceSize);
// 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) gravityRadius = Mathf.Min(gravityRadius, 4 * config.Base.surfaceSize);
else gravityRadius = Mathf.Min(gravityRadius, 15 * config.Base.surfaceSize);
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();
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.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.Lava != null) color = new Color(1f, 0.5f, 0.5f);
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.External.Configs;
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
{
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;
if (starColor != null) return starColor.ToColor();
@ -555,6 +547,14 @@ namespace NewHorizons.Builder.ShipLog
var sandColor = body.Config.Sand?.tint;
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)
{

View File

@ -45,6 +45,9 @@ namespace NewHorizons.External.Configs
[Obsolete("ChildrenToDestroy is deprecated, please use RemoveChildren instead")]
public string[] childrenToDestroy;
[Obsolete("Singularity is deprecated, please use Props->singularities")]
public SingularityModule Singularity;
#endregion Obsolete
/// <summary>
@ -133,11 +136,6 @@ namespace NewHorizons.External.Configs
/// </summary>
public SignalModule Signal;
/// <summary>
/// Add a black or white hole to this planet
/// </summary>
public SingularityModule Singularity;
/// <summary>
/// Spawn the player at this planet
/// </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.Converters;
using System;
using NewHorizons.External.Modules.VariableSize;
namespace NewHorizons.External.Modules
{
@ -77,6 +78,11 @@ namespace NewHorizons.External.Modules
/// </summary>
public VolcanoInfo[] volcanoes;
/// <summary>
/// Add black/white-holes to this planet
/// </summary>
public SingularityModule[] singularities;
[JsonObject]
public class ScatterInfo
{

View File

@ -1,4 +1,4 @@
using System.ComponentModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using NewHorizons.Utility;
@ -24,11 +24,16 @@ namespace NewHorizons.External.Modules.VariableSize
[DefaultValue(true)] public bool makeZeroGVolume = true;
/// <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
/// </summary>
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>
/// Position of the singularity
/// </summary>

View File

@ -469,11 +469,6 @@ namespace NewHorizons.Handlers
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)
{
FunnelBuilder.Make(go, go.GetComponentInChildren<ConstantForceDetector>(), rb, body.Config.Funnel);