Merge pull request #29 from xen-42/dev

Dev
This commit is contained in:
Nick 2022-02-13 21:43:04 -05:00 committed by GitHub
commit 535468835f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 258 additions and 94 deletions

View File

@ -7,7 +7,7 @@ namespace NewHorizons.Atmosphere
{
static class VolumesBuilder
{
public static void Make(GameObject body, float innerRadius, float outerRadius)
public static void Make(GameObject body, float innerRadius, float outerRadius, IPlanetConfig config)
{
GameObject volumesGO = new GameObject("Volumes");
volumesGO.SetActive(false);
@ -24,17 +24,18 @@ namespace NewHorizons.Atmosphere
SS.pointChecksOnly = true;
SS.radius = outerRadius;
/*OWTriggerVolume trigvol = */
rulesetGO.AddComponent<OWTriggerVolume>();
PlanetoidRuleset PR = rulesetGO.AddComponent<PlanetoidRuleset>();
PR.SetValue("_altitudeFloor", innerRadius);
PR.SetValue("_altitudeCeiling", outerRadius);
PR._altitudeFloor = innerRadius;
PR._altitudeCeiling = outerRadius;
PR._useMinimap = !config.Base.IsSatellite;
PR._useAltimeter = !config.Base.IsSatellite;
EffectRuleset ER = rulesetGO.AddComponent<EffectRuleset>();
ER.SetValue("_type", EffectRuleset.BubbleType.Underwater);
ER.SetValue("_material", GameObject.Find("RulesetVolumes_GD").GetComponent<RulesetVolume>().GetValue<Material>("_material"));
ER.SetValue("_cloudMaterial", GameObject.Find("RulesetVolumes_GD").GetComponent<RulesetVolume>().GetValue<Material>("_cloudMaterial"));
ER._type = EffectRuleset.BubbleType.Underwater;
ER._material = GameObject.Find("RulesetVolumes_GD").GetComponent<RulesetVolume>().GetValue<Material>("_material");
ER._cloudMaterial = GameObject.Find("RulesetVolumes_GD").GetComponent<RulesetVolume>().GetValue<Material>("_cloudMaterial");
volumesGO.transform.localPosition = Vector3.zero;
rulesetGO.SetActive(true);

View File

@ -22,22 +22,22 @@ namespace NewHorizons.Builder.General
ReferenceFrameVolume RFV = rfGO.AddComponent<ReferenceFrameVolume>();
ReferenceFrame RV = new ReferenceFrame(rigidbody);
RV.SetValue("_minSuitTargetDistance", sphereOfInfluence);
RV.SetValue("_maxTargetDistance", 0);
RV.SetValue("_autopilotArrivalDistance", sphereOfInfluence * 2f);
RV.SetValue("_autoAlignmentDistance", sphereOfInfluence * 1.5f);
RV._minSuitTargetDistance = sphereOfInfluence;
RV._maxTargetDistance = 0;
RV._autopilotArrivalDistance = 2.0f * sphereOfInfluence;
RV._autoAlignmentDistance = sphereOfInfluence * 1.5f;
RV.SetValue("_hideLandingModePrompt", false);
RV.SetValue("_matchAngularVelocity", true);
RV.SetValue("_minMatchAngularVelocityDistance", 70);
RV.SetValue("_maxMatchAngularVelocityDistance", 400);
RV.SetValue("_bracketsRadius", sphereOfInfluence);
RV._hideLandingModePrompt = false;
RV._matchAngularVelocity = true;
RV._minMatchAngularVelocityDistance = 70;
RV._maxMatchAngularVelocityDistance = 400;
RV._bracketsRadius = sphereOfInfluence;
RFV.SetValue("_referenceFrame", RV);
RFV.SetValue("_minColliderRadius", sphereOfInfluence);
RFV.SetValue("_maxColliderRadius", sphereOfInfluence * 2f);
RFV.SetValue("_isPrimaryVolume", true);
RFV.SetValue("_isCloseRangeVolume", false);
RFV._referenceFrame = RV;
RFV._minColliderRadius = sphereOfInfluence;
RFV._maxColliderRadius = sphereOfInfluence * 2f;
RFV._isPrimaryVolume = true;
RFV._isCloseRangeVolume = false;
rfGO.SetActive(true);
}

View File

@ -22,7 +22,7 @@ namespace NewHorizons.Builder.General
playerSpawn = spawnGO.AddComponent<SpawnPoint>();
spawnGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, (playerSpawn.transform.position - body.transform.position).normalized);
spawnGO.transform.position = spawnGO.transform.position + spawnGO.transform.TransformDirection(Vector3.up) * 2f;
spawnGO.transform.position = spawnGO.transform.position + spawnGO.transform.TransformDirection(Vector3.up) * 4f;
GameObject.FindObjectOfType<PlayerSpawner>().SetInitialSpawnPoint(playerSpawn);
}
@ -41,7 +41,7 @@ namespace NewHorizons.Builder.General
ship.transform.position = spawnPoint.transform.position;
ship.transform.rotation = Quaternion.FromToRotation(Vector3.up, (spawnPoint.transform.position - body.transform.position).normalized);
// Move it up a bit more
ship.transform.position = ship.transform.position + ship.transform.TransformDirection(Vector3.up) * 5f;
ship.transform.position = ship.transform.position + ship.transform.TransformDirection(Vector3.up) * 4f;
ship.GetRequiredComponent<MatchInitialMotion>().SetBodyToMatch(rb);

View File

@ -21,10 +21,15 @@ namespace NewHorizons.Builder.Orbital
return Update(initialMotion, body, primaryBody, OWRB, orbit);
}
public static float SiderealPeriodToAngularSpeed(float siderealPeriod)
{
return siderealPeriod == 0 ? 0f : 2f * Mathf.PI / (siderealPeriod * 60f);
}
public static InitialMotion Update(InitialMotion initialMotion, GameObject body, AstroObject primaryBody, OWRigidbody OWRB, OrbitModule orbit)
{
// Rotation
initialMotion.SetValue("_initAngularSpeed", orbit.SiderealPeriod == 0 ? 0f : 2f * Mathf.PI / (orbit.SiderealPeriod * 60f));
initialMotion.SetValue("_initAngularSpeed", SiderealPeriodToAngularSpeed(orbit.SiderealPeriod));
var rotationAxis = Quaternion.AngleAxis(orbit.AxialTilt + 90f, Vector3.right) * Vector3.up;
body.transform.rotation = Quaternion.FromToRotation(Vector3.up, rotationAxis);

View File

@ -16,10 +16,12 @@ namespace NewHorizons.Builder.Props
{
public static void Make(GameObject go, Sector sector, IPlanetConfig config, IModAssets assets, string uniqueModName, PropModule.DetailInfo detail)
{
GameObject detailGO = null;
if (detail.assetBundle != null)
{
var prefab = PropBuildManager.LoadPrefab(detail.assetBundle, detail.path, uniqueModName, assets);
MakeDetail(go, sector, prefab, detail.position, detail.rotation, detail.scale, detail.alignToNormal, detail.generateColliders);
detailGO = MakeDetail(go, sector, prefab, detail.position, detail.rotation, detail.scale, detail.alignToNormal);
}
else if (detail.objFilePath != null)
{
@ -27,24 +29,33 @@ namespace NewHorizons.Builder.Props
{
var prefab = assets.Get3DObject(detail.objFilePath, detail.mtlFilePath);
prefab.SetActive(false);
MakeDetail(go, sector, prefab, detail.position, detail.rotation, detail.scale, detail.alignToNormal, detail.generateColliders);
detailGO = MakeDetail(go, sector, prefab, detail.position, detail.rotation, detail.scale, detail.alignToNormal);
}
catch (Exception e)
{
Logger.LogError($"Could not load 3d object {detail.objFilePath} with texture {detail.mtlFilePath} : {e.Message}");
}
}
else MakeDetail(go, sector, detail.path, detail.position, detail.rotation, detail.scale, detail.alignToNormal, detail.generateColliders);
else detailGO = MakeDetail(go, sector, detail.path, detail.position, detail.rotation, detail.scale, detail.alignToNormal);
if(detailGO != null && detail.removeChildren != null)
{
foreach(var childPath in detail.removeChildren)
{
var childObj = SearchUtilities.Find(SearchUtilities.GetPath(detailGO.transform) + "/" + childPath);
childObj.gameObject.SetActive(false);
}
}
}
public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal, bool generateColliders)
public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal)
{
var prefab = SearchUtilities.Find(propToClone);
if (prefab == null) Logger.LogError($"Couldn't find detail {propToClone}");
return MakeDetail(go, sector, prefab, position, rotation, scale, alignWithNormal, generateColliders);
return MakeDetail(go, sector, prefab, position, rotation, scale, alignWithNormal);
}
public static GameObject MakeDetail(GameObject go, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal, bool generateColliders)
public static GameObject MakeDetail(GameObject go, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal)
{
if (prefab == null) return null;
@ -77,7 +88,11 @@ namespace NewHorizons.Builder.Props
if (component is GhostIK) (component as GhostIK).enabled = false;
if (component is GhostEffects) (component as GhostEffects).enabled = false;
if (component is Animator) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => (component as Animator).enabled = true);
// If it's not a moving anglerfish make sure the anim controller is off
if(component is AnglerfishAnimController && component.GetComponentInParent<AnglerfishController>() == null)
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => (component as AnglerfishAnimController).enabled = false);
if (component is Animator) Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => (component as Animator).enabled = true, 5);
if (component is Collider) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => (component as Collider).enabled = true);
if(component is Shape) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => (component as Shape).enabled = true);
@ -104,17 +119,6 @@ namespace NewHorizons.Builder.Props
Logger.LogError($"Couldn't update AnglerFish chase speed: {e.Message}");
}
}
// Mesh colliders
if (generateColliders)
{
if (component is MeshFilter && component.gameObject.GetComponent<MeshCollider>() == null)
{
var mesh = (component as MeshFilter).mesh;
if (mesh.isReadable) component.gameObject.AddComponent<MeshCollider>();
else Logger.LogError($"Couldn't change mesh for {component.gameObject.name} because it is not readable");
}
}
}
prop.transform.position = position == null ? go.transform.position : go.transform.TransformPoint((Vector3)position);

View File

@ -71,7 +71,7 @@ namespace NewHorizons.Builder.Props
height -= 0.2f;
}
var prop = DetailBuilder.MakeDetail(go, sector, prefab, (MVector3)(point.normalized * height), null, propInfo.scale, true, propInfo.generateColliders);
var prop = DetailBuilder.MakeDetail(go, sector, prefab, (MVector3)(point.normalized * height), null, propInfo.scale, true);
if (propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset);
if (propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation);
points.RemoveAt(randomInd);

View File

@ -0,0 +1,69 @@
using NewHorizons.Builder.Orbital;
using NewHorizons.OrbitalPhysics;
using NewHorizons.Utility;
using PacificEngine.OW_CommonResources.Game.Resource;
using PacificEngine.OW_CommonResources.Game.State;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Builder.Updater
{
public static class OrbitUpdater
{
public static void Update(NewHorizonsBody body, GameObject go)
{
var mapping = Planet.defaultMapping;
var heavenlyBody = CommonResourcesUtilities.HeavenlyBodyFromAstroObject(AstroObjectLocator.GetAstroObject(body.Config.Name));
Logger.Log($"Updating position of {body.Config.Name}/{heavenlyBody}");
if (heavenlyBody != HeavenlyBody.None)
{
var original = mapping[heavenlyBody];
var coords = OrbitalHelper.KeplerCoordinatesFromOrbitModule(body.Config.Orbit);
var parent = original.state.parent;
if (body.Config.Orbit.PrimaryBody != null)
{
var parentAO = AstroObjectLocator.GetAstroObject(body.Config.Orbit.PrimaryBody);
var newParent = CommonResourcesUtilities.HeavenlyBodyFromAstroObject(parentAO);
if (newParent != HeavenlyBody.None)
{
Logger.LogWarning($"Sorry, can't change primary body for planets yet. You tried making {body.Config.Name} orbit {newParent}");
/*
parent = newParent;
// Have to change the gravity stuff
go.GetComponentInChildren<ConstantForceDetector>()._detectableFields = new ForceVolume[] { parentAO.GetGravityVolume() };
go.GetComponent<AstroObject>()._primaryBody = parentAO;
*/
}
else Logger.LogError($"Couldn't find new parent {body.Config.Orbit.PrimaryBody}");
}
var planetoid = new Planet.Plantoid(
original.size,
original.gravity,
go.transform.rotation,
InitialMotionBuilder.SiderealPeriodToAngularSpeed(body.Config.Orbit.SiderealPeriod),
parent,
coords
);
mapping[heavenlyBody] = planetoid;
Planet.defaultMapping = mapping;
Planet.mapping = mapping;
}
else
{
Logger.LogError($"Couldn't find heavenlyBody for {body.Config.Name}");
}
}
}
}

View File

@ -9,7 +9,7 @@ namespace NewHorizons.External
{
public class OrbitModule : Module
{
public int SemiMajorAxis { get; set; } = 5000;
public int SemiMajorAxis { get; set; }
public float Inclination { get; set; }
public string PrimaryBody { get; set; }
public bool IsMoon { get; set; }

View File

@ -33,7 +33,7 @@ namespace NewHorizons.External
public PlanetConfig(Dictionary<string, object> dict)
{
// Always have to have a base module and orbit module
// Always have to have a base module
Base = new BaseModule();
Orbit = new OrbitModule();

View File

@ -25,7 +25,6 @@ namespace NewHorizons.External
public MVector3 offset;
public MVector3 rotation;
public float scale { get; set; } = 1f;
public bool generateColliders = false;
}
public class DetailInfo
@ -38,7 +37,7 @@ namespace NewHorizons.External
public MVector3 rotation;
public float scale { get; set; } = 1f;
public bool alignToNormal;
public bool generateColliders = false;
public string[] removeChildren;
}
public class RaftInfo

View File

@ -4,6 +4,7 @@ using NewHorizons.Builder.Body;
using NewHorizons.Builder.General;
using NewHorizons.Builder.Orbital;
using NewHorizons.Builder.Props;
using NewHorizons.Builder.Updater;
using NewHorizons.Components;
using NewHorizons.External;
using NewHorizons.External.VariableSize;
@ -14,6 +15,8 @@ using OWML.Common;
using OWML.ModHelper;
using OWML.Utils;
using PacificEngine.OW_CommonResources.Game.Player;
using PacificEngine.OW_CommonResources.Game.Resource;
using PacificEngine.OW_CommonResources.Game.State;
using System;
using System.Collections.Generic;
using System.IO;
@ -421,7 +424,16 @@ namespace NewHorizons
}
// Do stuff that's shared between generating new planets and updating old ones
return SharedGenerateBody(body, go, sector, rb);
go = SharedGenerateBody(body, go, sector, rb);
// Update a position using CommonResources
// Since orbits are always there just check if they set a semi major axis
if (body.Config.Orbit != null && body.Config.Orbit.SemiMajorAxis != 0f)
{
OrbitUpdater.Update(body, go);
}
return go;
}
#endregion Load
@ -485,7 +497,7 @@ namespace NewHorizons
var sector = MakeSector.Make(go, owRigidBody, sphereOfInfluence * 2f);
ao.SetValue("_rootSector", sector);
VolumesBuilder.Make(go, body.Config.Base.SurfaceSize, sphereOfInfluence);
VolumesBuilder.Make(go, body.Config.Base.SurfaceSize, sphereOfInfluence, body.Config);
if (body.Config.HeightMap != null)
HeightMapBuilder.Make(go, body.Config.HeightMap, body.Mod.Assets);
@ -504,13 +516,7 @@ namespace NewHorizons
body.Object = go;
// Now that we're done move the planet into place
go.transform.parent = Locator.GetRootTransform();
go.transform.position = OrbitalHelper.GetCartesian(new OrbitalHelper.Gravity(1, 100), body.Config.Orbit).Item1 + (primaryBody == null ? Vector3.zero : primaryBody.transform.position);
if (go.transform.position.magnitude > FurthestOrbit)
{
FurthestOrbit = go.transform.position.magnitude + 30000f;
}
UpdatePosition(go, body, primaryBody);
// Have to do this after setting position
var initialMotion = InitialMotionBuilder.Make(go, primaryBody, owRigidBody, body.Config.Orbit);
@ -603,6 +609,17 @@ namespace NewHorizons
return go;
}
private void UpdatePosition(GameObject go, NewHorizonsBody body, AstroObject primaryBody)
{
go.transform.parent = Locator.GetRootTransform();
go.transform.position = OrbitalHelper.GetCartesian(new OrbitalHelper.Gravity(1, 100), body.Config.Orbit).Item1 + (primaryBody == null ? Vector3.zero : primaryBody.transform.position);
if (go.transform.position.magnitude > FurthestOrbit)
{
FurthestOrbit = go.transform.position.magnitude + 30000f;
}
}
#endregion Body generation
#region Change star system

View File

@ -0,0 +1,61 @@
using PacificEngine.OW_CommonResources.Game.Resource;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.Utility
{
public static class CommonResourcesUtilities
{
public static HeavenlyBody HeavenlyBodyFromAstroObject(AstroObject obj)
{
switch (obj.GetAstroObjectName())
{
case AstroObject.Name.CustomString:
return HeavenlyBody.FromString(obj.GetCustomName());
case AstroObject.Name.BrittleHollow:
return HeavenlyBodies.BrittleHollow;
case AstroObject.Name.CaveTwin:
return HeavenlyBodies.EmberTwin;
case AstroObject.Name.Comet:
return HeavenlyBodies.Interloper;
case AstroObject.Name.DarkBramble:
return HeavenlyBodies.DarkBramble;
case AstroObject.Name.DreamWorld:
return HeavenlyBodies.DreamWorld;
case AstroObject.Name.GiantsDeep:
return HeavenlyBodies.GiantsDeep;
case AstroObject.Name.HourglassTwins:
return HeavenlyBodies.HourglassTwins;
case AstroObject.Name.MapSatellite:
return HeavenlyBodies.SatiliteMapping;
case AstroObject.Name.ProbeCannon:
return HeavenlyBodies.ProbeCannon;
case AstroObject.Name.QuantumMoon:
return HeavenlyBodies.QuantumMoon;
case AstroObject.Name.RingWorld:
return HeavenlyBodies.Stranger;
case AstroObject.Name.Sun:
return HeavenlyBodies.Sun;
case AstroObject.Name.SunStation:
return HeavenlyBodies.SunStation;
case AstroObject.Name.TimberHearth:
return HeavenlyBodies.TimberHearth;
case AstroObject.Name.TimberMoon:
return HeavenlyBodies.Attlerock;
case AstroObject.Name.TowerTwin:
return HeavenlyBodies.AshTwin;
case AstroObject.Name.VolcanicMoon:
return HeavenlyBodies.HollowLantern;
case AstroObject.Name.WhiteHole:
return HeavenlyBodies.WhiteHole;
case AstroObject.Name.WhiteHoleTarget:
return HeavenlyBodies.WhiteHoleStation;
default:
return HeavenlyBodies.None;
}
}
}
}

View File

@ -17,7 +17,7 @@ namespace NewHorizons.Utility
public int B { get; }
public int A { get; }
public Color32 ToColor32() => new Color(R, G, B, A);
public Color32 ToColor32() => new Color32((byte)R, (byte)G, (byte)B, (byte)A);
public Color ToColor() => new Color(R / 255f, G / 255f, B / 255f, A / 255f);
}

View File

@ -98,6 +98,8 @@ namespace NewHorizons.Utility
*/
public static GameObject Find(string path)
{
try
{
var go = GameObject.Find(path);
@ -113,18 +115,18 @@ namespace NewHorizons.Utility
if (t == null)
{
Logger.LogWarning($"Couldn't find root object in path ({names[0]})");
return null;
}
else
{
for (int i = 1; i < names.Length; i++)
{
var child = t.transform.Find(names[i]);
if(child == null)
if (child == null)
{
foreach(Transform c in t.GetComponentsInChildren<Transform>(true))
foreach (Transform c in t.GetComponentsInChildren<Transform>(true))
{
if(t.name.Equals(names[i]))
if (t.name.Equals(names[i]))
{
child = c;
break;
@ -141,11 +143,12 @@ namespace NewHorizons.Utility
t = child;
}
}
go = t?.gameObject;
}
if(go == null)
if (go == null)
{
var name = names.Last();
Logger.LogWarning($"Couldn't find object {path}, will look for potential matches for name {name}");
@ -154,5 +157,10 @@ namespace NewHorizons.Utility
return go;
}
catch(Exception)
{
return null;
}
}
}
}