Skip to content

Commit

Permalink
1.12.5 (#646)
Browse files Browse the repository at this point in the history
## Minor features
- Added `solarFlareSettings` to star where you can change the size, life
length, and time between spawns of solar flares. Fixes #368, fixes #369.
- Added `initialRotation` to orbit module. Fixes #360.
- NH will no longer free the map view angle by default. If you want it
in your star system, set `freeMapAngle` in the system config.
- "Returning to system" autopilot behaviour now works in other star
systems. Enable it using `returnToSolarSystemWhenTooFar` in the star
system config. Off by default.
- Add support for custom `fogColorRampTexture` (resolves #530)

## Improvements
- Bramble dimensions now support having gravity. Fixes #632.
- Warp-drive system images can go in the `systems` folder now instead of
in `planets`. Fixes #637.
- Added `offset` to player and ship spawn positions. By default it moves
them up by 4m to prevent clipping into the ground but this can be non
ideal in cramped spawn locations.

## Bug fixes
- Will no longer show 2 debug prompts in certain mods. Fixes #643.
- Stability between loops should be improved as coroutines are now
cancelled when the scene unloads. If you were for some reason using the
`Delay` class from inside NH for your mod and relying on it doing things
between scenes, then what the hell is wrong with you.
- Warp drive lock-on now overrides the "returning to system" autopilot.
Fixes #649.
- Fixed the map pan, zoom, and view distance to make sense for each
system. Fixes #290.
- Fixed scout/ship HUD markers being hidden if there were no cloaking
fields in the system. Fixes #647.
  • Loading branch information
xen-42 committed Jul 19, 2023
2 parents 6557286 + a0dfc6d commit 05aa557
Show file tree
Hide file tree
Showing 28 changed files with 353 additions and 78 deletions.
15 changes: 11 additions & 4 deletions NewHorizons/Builder/Atmosphere/FogBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NewHorizons.External.Modules;
using NewHorizons.Utility;
using NewHorizons.Utility.Files;
using OWML.Common;
using UnityEngine;
namespace NewHorizons.Builder.Atmosphere
{
Expand Down Expand Up @@ -35,7 +36,7 @@ internal static void InitPrefabs()
if (_dbImpostorMaterials == null) _dbImpostorMaterials = SearchUtilities.Find("DarkBramble_Body/Atmosphere_DB/FogLOD").GetComponent<MeshRenderer>().sharedMaterials.MakePrefabMaterials();
}

public static PlanetaryFogController Make(GameObject planetGO, Sector sector, AtmosphereModule atmo)
public static PlanetaryFogController Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod)
{
InitPrefabs();

Expand All @@ -58,7 +59,10 @@ public static PlanetaryFogController Make(GameObject planetGO, Sector sector, At
PFC.lodFadeDistance = PFC.fogRadius * 0.5f;
PFC.fogDensity = atmo.fogDensity;
PFC.fogExponent = 1f;
var colorRampTexture = atmo.fogTint == null ? _ramp : ImageUtilities.TintImage(_ramp, atmo.fogTint.ToColor());
var colorRampTexture =
atmo.fogRampPath != null ? ImageUtilities.GetTexture(mod, atmo.fogRampPath) :
atmo.fogTint != null ? ImageUtilities.TintImage(_ramp, atmo.fogTint.ToColor()) :
_ramp;
PFC.fogColorRampTexture = colorRampTexture;
PFC.fogColorRampIntensity = 1f;
if (atmo.fogTint != null)
Expand All @@ -78,7 +82,7 @@ public static PlanetaryFogController Make(GameObject planetGO, Sector sector, At
return PFC;
}

public static Renderer MakeProxy(GameObject proxyGO, AtmosphereModule atmo)
public static Renderer MakeProxy(GameObject proxyGO, AtmosphereModule atmo, IModBehaviour mod)
{
InitPrefabs();

Expand All @@ -94,7 +98,10 @@ public static Renderer MakeProxy(GameObject proxyGO, AtmosphereModule atmo)
MR.materials = _dbImpostorMaterials;
MR.allowOcclusionWhenDynamic = true;

var colorRampTexture = atmo.fogTint == null ? _ramp : ImageUtilities.TintImage(_ramp, atmo.fogTint.ToColor());
var colorRampTexture =
atmo.fogRampPath != null ? ImageUtilities.GetTexture(mod, atmo.fogRampPath) :
atmo.fogTint != null ? ImageUtilities.TintImage(_ramp, atmo.fogTint.ToColor()) :
_ramp;
if (atmo.fogTint != null)
{
MR.material.SetColor(Tint, atmo.fogTint.ToColor());
Expand Down
2 changes: 1 addition & 1 deletion NewHorizons/Builder/Body/ProxyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private static bool SharedMake(GameObject planetGO, GameObject proxy, NHProxy pr

if (body.Config.Atmosphere.fogSize != 0)
{
fog = FogBuilder.MakeProxy(proxy, body.Config.Atmosphere);
fog = FogBuilder.MakeProxy(proxy, body.Config.Atmosphere, body.Mod);
fogCurveMaxVal = body.Config.Atmosphere.fogDensity;
}

Expand Down
35 changes: 25 additions & 10 deletions NewHorizons/Builder/Body/StarBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NewHorizons.Components.Stars;
using NewHorizons.Utility.OuterWilds;
using NewHorizons.Utility.Files;
using NewHorizons.Utility.OWML;

namespace NewHorizons.Builder.Body
{
Expand Down Expand Up @@ -348,28 +349,42 @@ public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector,
solarFlareEmitter.name = "SolarFlareEmitter";
solarFlareEmitter.SetActive(true);

var emitter = solarFlareEmitter.GetComponent<SolarFlareEmitter>();

if (starModule.solarFlareSettings != null)
{
emitter._minTimeBetweenFlares = starModule.solarFlareSettings.minTimeBetweenFlares;
emitter._maxTimeBetweenFlares = starModule.solarFlareSettings.maxTimeBetweenFlares;
emitter._lifeLength = starModule.solarFlareSettings.lifeLength;
}

if (starModule.tint != null)
{
var flareTint = starModule.tint.ToColor();
var emitter = solarFlareEmitter.GetComponent<SolarFlareEmitter>();
emitter.tint = flareTint;
emitter.tint = starModule.tint.ToColor();
}

var material = new Material(_flareMaterial);
// Since the star isn't awake yet the controllers haven't been made
foreach (var prefab in new GameObject[] { emitter.domePrefab, emitter.loopPrefab, emitter.streamerPrefab })
var material = new Material(_flareMaterial);
// Since the star isn't awake yet the controllers haven't been made
foreach (var prefab in new GameObject[] { emitter.domePrefab, emitter.loopPrefab, emitter.streamerPrefab })
{
var controller = prefab.GetComponent<SolarFlareController>();
// controller._meshRenderer doesn't exist yet since Awake hasn't been called
if (starModule.tint != null)
{
var controller = prefab.GetComponent<SolarFlareController>();
// controller._meshRenderer doesn't exist yet since Awake hasn't been called
controller.GetComponent<MeshRenderer>().sharedMaterial = material;
controller._color = Color.white;
controller._tint = flareTint;
controller._tint = starModule.tint.ToColor();
}
if (starModule.solarFlareSettings != null)
{
controller._scaleFactor = Vector3.one * starModule.solarFlareSettings.scaleFactor;
}
}

starGO.transform.position = rootObject.transform.position;
starGO.transform.localScale = starModule.size * Vector3.one;

TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>();
var surface = sunSurface.GetComponent<TessellatedSphereRenderer>();

if (starModule.tint != null)
{
Expand Down
15 changes: 8 additions & 7 deletions NewHorizons/Builder/General/AstroObjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@ public static NHAstroObject Make(GameObject body, AstroObject primaryBody, Plane
var alignmentAxis = config.Orbit.alignmentAxis ?? new Vector3(0, -1, 0);

// Start it off facing the right way
var facing = body.transform.TransformDirection(alignmentAxis);
body.transform.rotation = Quaternion.FromToRotation(facing, alignmentAxis) * body.transform.rotation;

var alignment = body.AddComponent<AlignWithTargetBody>();
alignment.SetTargetBody(primaryBody?.GetAttachedOWRigidbody());
alignment._usePhysicsToRotate = false;
alignment._localAlignmentAxis = alignmentAxis;
alignment._owRigidbody = body.GetComponent<OWRigidbody>();

// Have it face the right way
var currentDirection = alignment.transform.TransformDirection(alignment._localAlignmentAxis);
var targetDirection = alignment.GetAlignmentDirection();
alignment.transform.rotation = Quaternion.FromToRotation(currentDirection, targetDirection) * alignment.transform.rotation;
alignment._owRigidbody.SetAngularVelocity(Vector3.zero);

// Static bodies won't update rotation with physics for some reason
// Have to set it in 2 ticks else it flings the player into deep space on spawn (#171)
// Pushed to 3 frames after system is ready, bc spawning takes 2 frames, this is hurting my brain too much to try to improve the numbers idc
if (!config.Orbit.isStatic) Delay.RunWhen(() => Main.IsSystemReady, () => Delay.FireInNUpdates(() => alignment._usePhysicsToRotate = true, 3));
alignment._usePhysicsToRotate = !config.Orbit.isStatic;
}

if (config.Base.centerOfSolarSystem)
Expand Down
10 changes: 6 additions & 4 deletions NewHorizons/Builder/General/SpawnPointBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbo
if (module.playerSpawn != null)
{
GameObject spawnGO = GeneralPropBuilder.MakeNew("PlayerSpawnPoint", planetGO, null, module.playerSpawn);
spawnGO.SetActive(false);
spawnGO.layer = Layer.PlayerSafetyCollider;

playerSpawn = spawnGO.AddComponent<SpawnPoint>();
Expand All @@ -31,8 +30,7 @@ public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbo
playerSpawn._triggerVolumes = new OWTriggerVolume[0];

// This was a stupid hack to stop players getting stuck in the ground and now we have to keep it forever
spawnGO.transform.position += 4f * spawnGO.transform.up;
spawnGO.SetActive(true);
spawnGO.transform.position += spawnGO.transform.TransformDirection(module.playerSpawn.offset ?? Vector3.up * 4f);
}

if (module.shipSpawn != null)
Expand All @@ -57,7 +55,11 @@ public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbo
ship.transform.rotation = spawnGO.transform.rotation;

// Move it up a bit more when aligning to surface
if (module.shipSpawn.alignRadial.GetValueOrDefault())
if (module.shipSpawn.offset != null)
{
ship.transform.position += spawnGO.transform.TransformDirection(module.shipSpawn.offset);
}
else if (module.shipSpawn.alignRadial.GetValueOrDefault())
{
ship.transform.position += ship.transform.up * 4f;
}
Expand Down
4 changes: 3 additions & 1 deletion NewHorizons/Builder/Orbital/InitialMotionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public static InitialMotion SetInitialMotionFromConfig(InitialMotion initialMoti
initialMotion._initAngularSpeed = orbit.siderealPeriod == 0 ? 0f : 2f * Mathf.PI / (orbit.siderealPeriod * 60f);
var rotationAxis = Quaternion.AngleAxis(orbit.axialTilt, Vector3.right) * Vector3.up;

// For things with children this is broken
// For stock planets with unsuspended rigidbody children this is broken
// For planets with rafts this is broken
if (AstroObjectLocator.GetChildren(secondaryBody).Length == 0)
{
secondaryBody.transform.rotation = Quaternion.FromToRotation(Vector3.up, rotationAxis);
secondaryBody.transform.Rotate(rotationAxis, orbit.initialRotation);
}

if (!orbit.isStatic && primaryBody != null)
Expand Down
13 changes: 11 additions & 2 deletions NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,18 @@ public GameObject CreateCard(string uniqueID, Transform parent, Vector2 position
}
else
{
var path = Path.Combine("planets", uniqueID + ".png");
var mod = Main.SystemDict[uniqueID].Mod;

var path = Path.Combine("systems", uniqueID + ".png");

// Else check the old location
if (!File.Exists(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, path)))
{
path = Path.Combine("planets", uniqueID + ".png");
}

NHLogger.LogVerbose($"ShipLogStarChartManager - Trying to load {path}");
texture = ImageUtilities.GetTexture(Main.SystemDict[uniqueID].Mod, path);
texture = ImageUtilities.GetTexture(mod, path);
}
}
catch (Exception) { }
Expand Down
3 changes: 2 additions & 1 deletion NewHorizons/Components/Volumes/LoadCreditsVolume.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NewHorizons.External.SerializableEnums;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using NewHorizons.Utility.OWML;
using System.Collections;
using UnityEngine;
Expand Down Expand Up @@ -28,7 +29,7 @@ public override void OnTriggerVolumeEntry(GameObject hitObj)
if (hitObj.CompareTag("PlayerDetector") && enabled)
{
// Have to run it off the mod behaviour since the game over controller disables everything
Main.Instance.StartCoroutine(GameOver());
Delay.StartCoroutine(GameOver());
}
}

Expand Down
10 changes: 10 additions & 0 deletions NewHorizons/External/Configs/StarSystemConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ namespace NewHorizons.External.Configs
[JsonObject]
public class StarSystemConfig
{
/// <summary>
/// In this system should the player be able to rotate their map camera freely or be stuck above the plane of the solar system?
/// </summary>
public bool freeMapAngle;

/// <summary>
/// When well past the furthest orbit, should the player be summoned back to the star?
/// </summary>
public bool returnToSolarSystemWhenTooFar;

/// <summary>
/// An override value for the far clip plane. Allows you to see farther.
/// </summary>
Expand Down
8 changes: 7 additions & 1 deletion NewHorizons/External/Modules/AtmosphereModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class AtmosphereModule
/// <summary>
/// How dense the fog is, if you put fog.
/// </summary>
[Range(0f, 1f)] public float fogDensity;
[Range(0f, double.MaxValue)] public float fogDensity;

/// <summary>
/// Radius of fog sphere, independent of the atmosphere. This has to be set for there to be fog.
Expand All @@ -57,6 +57,12 @@ public class AtmosphereModule
/// Colour of fog on the planet, if you put fog.
/// </summary>
public MColor fogTint;

/// <summary>
/// Relative filepath to the fog color ramp texture, if you put fog.
/// x axis is angle to sun (left at midnight, right at noon), y axis is distance to camera (close at bottom, far at top).
/// </summary>
public string fogRampPath;

/// <summary>
/// Lets you survive on the planet without a suit.
Expand Down
6 changes: 6 additions & 0 deletions NewHorizons/External/Modules/OrbitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public class OrbitModule : IOrbitalParameters
/// </summary>
public float siderealPeriod;

/// <summary>
/// Offsets the planet's starting sidereal rotation. In degrees.
/// </summary>
[Range(0f, 360f)]
public float initialRotation;

/// <summary>
/// Should the body always have one side facing its primary?
/// </summary>
Expand Down
17 changes: 15 additions & 2 deletions NewHorizons/External/Modules/SpawnModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ public class SpawnModule
[Obsolete("startWithSuit is deprecated. Use playerSpawn.startWithSuit instead")] public bool startWithSuit;

[JsonObject]
public class PlayerSpawnPoint : GeneralPropInfo {
public class SpawnPoint : GeneralPropInfo
{
/// <summary>
/// Offsets the player/ship by this local vector when spawning. Used to prevent spawning in the floor. Optional: defaults to (0, 4, 0).
/// </summary>
public MVector3 offset;
}

[JsonObject]
public class PlayerSpawnPoint : SpawnPoint
{
/// <summary>
/// If you spawn on a planet with no oxygen, you probably want to set this to true ;;)
/// </summary>
Expand All @@ -33,10 +43,13 @@ public class PlayerSpawnPoint : GeneralPropInfo {
/// Whether this planet's spawn point is the one the player will initially spawn at, if multiple spawn points exist.
/// </summary>
public bool isDefault;


}

[JsonObject]
public class ShipSpawnPoint : GeneralPropInfo {
public class ShipSpawnPoint : SpawnPoint
{

}
}
Expand Down
33 changes: 33 additions & 0 deletions NewHorizons/External/Modules/VariableSize/StarModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,39 @@ public class StarModule : VariableSizeModule
/// The type of stellar remnant your star will leave behind.
/// </summary>
[DefaultValue("default")] public StellarRemnantType stellarRemnantType = StellarRemnantType.Default;

/// <summary>
/// Allows overriding solar flare graphical settings.
/// </summary>
public SolarFlareModule solarFlareSettings;

[JsonObject]
public class SolarFlareModule
{
/// <summary>
/// Size multiuplier for solar flares. Defaults to 1.
/// </summary>
[DefaultValue(1)]
public float scaleFactor = 1f;

/// <summary>
/// How long a solar flare is visible for. Defaults to 15.
/// </summary>
[DefaultValue(15f)]
public float lifeLength = 15f;

/// <summary>
/// Solar flares are emitted randomly. This is the minimum ammount of time between solar flares.
/// </summary>
[DefaultValue(5f)]
public float minTimeBetweenFlares = 5f;

/// <summary>
/// Solar flares are emitted randomly. This is the maximum ammount of time between solar flares.
/// </summary>
[DefaultValue(30f)]
public float maxTimeBetweenFlares = 30f;
}
}

[JsonConverter(typeof(StringEnumConverter))]
Expand Down
4 changes: 3 additions & 1 deletion NewHorizons/Handlers/CloakHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NewHorizons.Components.EOTE;
using NewHorizons.OtherMods.VoiceActing;
using NewHorizons.Utility;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand Down Expand Up @@ -81,7 +82,8 @@ private static void Refresh()

if (!_cloaks.Any())
{
Locator.RegisterCloakFieldController(null);
// For some reason ship/scout HUD markers break if this isn't set to the Stranger when it is disabled #647
Locator.RegisterCloakFieldController(GameObject.FindObjectOfType<CloakFieldController>());
Shader.DisableKeyword("_CLOAKINGFIELDENABLED");
_cloakLocator.SetCurrentCloak(null);
_cloakLocator.enabled = false;
Expand Down
5 changes: 3 additions & 2 deletions NewHorizons/Handlers/FadeHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using NewHorizons.Utility.OWML;
using System;
using System.Collections;
using UnityEngine;
Expand All @@ -6,7 +7,7 @@ namespace NewHorizons.Handlers
{
public static class FadeHandler
{
public static void FadeOut(float length) => Main.Instance.StartCoroutine(FadeOutCoroutine(length));
public static void FadeOut(float length) => Delay.StartCoroutine(FadeOutCoroutine(length));

private static IEnumerator FadeOutCoroutine(float length)
{
Expand All @@ -24,7 +25,7 @@ private static IEnumerator FadeOutCoroutine(float length)
yield return new WaitForEndOfFrame();
}

public static void FadeThen(float length, Action action) => Main.Instance.StartCoroutine(FadeThenCoroutine(length, action));
public static void FadeThen(float length, Action action) => Delay.StartCoroutine(FadeThenCoroutine(length, action));

private static IEnumerator FadeThenCoroutine(float length, Action action)
{
Expand Down

0 comments on commit 05aa557

Please sign in to comment.