Created field bubble shields / propulsion, currently just a prototype with its own test scene
This commit is contained in:
Reinier Vens 2025-01-30 01:58:05 +00:00
commit c6ffcad3f1
213 changed files with 2145 additions and 1213 deletions

View file

@ -1,147 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// using System;
// using System.Collections;
// using System.Collections.Generic;
// using System.Linq;
// using MessagePack;
// using Newtonsoft.Json;
// using Unity.Mathematics;
// using static Unity.Mathematics.math;
//
// [MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), Order(-100)]
// public class HaulingControllerData : ControllerData
// {
// [InspectableField, JsonProperty("targetDistance"), Key(6)]
// public float DockTime = 2;
// public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
// {
// return new HaulingController(context, this, entity, item);
// }
// }
//
// public class HaulingController : ControllerBase<HaulingTask>, IBehavior, IPersistentBehavior
// {
// private HaulingControllerData _data;
// private EquippedItem Item { get; }
//
// private bool _taskStarted;
// private int _itemsDelivered;
// private int _itemsCarried;
// private SimpleCommodity _simpleCommodityDelivery;
// private List<CraftedItemInstance> _craftedItemDelivery = new List<CraftedItemInstance>();
//
// public HaulingController(ItemManager itemManager, HaulingControllerData data, Entity entity, EquippedItem item) : base(itemManager, data, entity)
// {
// _data = data;
// Item = item;
// }
//
// public new bool Execute(float delta)
// {
// if (Task != null)
// {
// if (!_taskStarted)
// {
// MoveTo(Task.Origin, true, OnPickup);
// //MoveTo(haulingTask.Zone, OnOriginZoneArrival);
// _taskStarted = true;
// }
// }
// return base.Execute(delta);
// }
//
// // void OnOriginZoneArrival()
// // {
// // var haulingTask = _context.ItemData.Get<HaulingTask>(Task);
// //
// // _entity.SetMessage("Entering pickup phase.");
// //
// // MoveTo(_context.ItemData.Get<Entity>(haulingTask.Origin), true, OnPickup);
// // }
//
// void OnPickup()
// {
// Entity.SetParent(Task.Origin);
//
// _itemsCarried = Task.Origin.TryTransferItems(Entity, Task.ItemType, Task.Quantity - _itemsDelivered);
//
// if (_itemsCarried == 0)
// {
// FinishTask();
// return;
// }
//
// Wait(_data.DockTime, OnItemObtained);
// }
//
// void OnItemObtained()
// {
// Entity.SetMessage("Entering delivery phase.");
//
// MoveTo(Task.Target, true, OnDelivery);
// //MoveTo(target.Zone.Data.ID, OnTargetZoneArrival);
// }
//
// // void OnTargetZoneArrival()
// // {
// // var haulingTask = _context.ItemData.Get<HaulingTask>(Task);
// //
// // MoveTo(_context.ItemData.Get<Entity>(haulingTask.Target), true, OnDelivery);
// // }
//
// void OnDelivery()
// {
// Entity.SetParent(Task.Target);
//
// var itemsDelivered = Entity.TryTransferItems(Task.Target, Task.ItemType, _itemsCarried);
// _itemsCarried -= itemsDelivered;
// _itemsDelivered += itemsDelivered;
//
// Wait(_data.DockTime, () =>
// {
// // We were unable to transfer all onboard items to target entity, cargo is probably full. Bring back the surplus and end the mission
// if(_itemsCarried > 0)
// MoveTo(Task.Origin, true, ReturnSurplusToOrigin);
// // We have delivered the target quantity of items, end the mission
// else if(_itemsDelivered >= Task.Quantity)
// FinishTask();
// // We aren't done yet. Resetting the task will make us go for another delivery run
// else
// _taskStarted = false;
// });
// }
//
// void ReturnSurplusToOrigin()
// {
// Entity.SetParent(Task.Origin);
//
// Entity.TryTransferItems(Task.Origin, Task.ItemType, _itemsCarried);
//
// Wait(_data.DockTime, OnItemObtained);
//
// FinishTask();
// }
//
// public PersistentBehaviorData Store()
// {
// return new HaulingControllerPersistence
// {
// Task = Task
// };
// }
//
// public void Restore(PersistentBehaviorData data)
// {
// var towingControllerPersistence = data as HaulingControllerPersistence;
// Task = towingControllerPersistence.Task;
// }
// }
//
// public class HaulingControllerPersistence : PersistentBehaviorData
// {
// [JsonProperty("task"), Key(0)]
// public HaulingTask Task;
// }

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: e8c5153aa2579174c901c552bfb495a4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,141 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
// [MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), Order(-100)]
// public class MiningControllerData : ControllerData
// {
// public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
// {
// return new MiningController(context, this, entity, item);
// }
// }
//
// public class MiningController : ControllerBase<Mining>, IBehavior, IPersistentBehavior, IInitializableBehavior
// {
//
// private MiningControllerData _data;
// private EquippedItem Item { get; }
// private bool _taskStarted;
// private int _asteroid = -1;
// private MiningTool _miningTool;
// private Switch _toolSwitch;
//
// public MiningController(ItemManager itemManager, MiningControllerData data, Entity entity, EquippedItem item) : base(itemManager, data, entity)
// {
// _data = data;
// Item = item;
// }
//
// public new void Initialize()
// {
// // _miningTool = Entity.GetBehavior<MiningTool>();
// // _toolSwitch = Entity.GetSwitch<MiningTool>();
// base.Initialize();
// }
//
// public new bool Execute(float delta)
// {
// // if (Task != null)
// // {
// // if (!_taskStarted)
// // {
// // NextAsteroid();
// // _taskStarted = true;
// // }
// // else
// // {
// // if (!Moving)
// // {
// // if (_entity.OccupiedCapacity < _entity.Capacity - 1)
// // {
// // var asteroidTransform = Zone.GetAsteroidTransform(Task.Asteroids, _asteroid);
// // if (length(_entity.Position - asteroidTransform.xy) - asteroidTransform.w > _miningTool.Range)
// // {
// // _entity.SetMessage("Moving to target asteroid.");
// // MoveTo(() => Zone.GetAsteroidTransform(Task.Asteroids, _asteroid).xy,
// // () => Zone.GetAsteroidVelocity(Task.Asteroids, _asteroid));
// // _toolSwitch.Activated = false;
// // }
// // else
// // {
// // if (Zone.AsteroidExists(Task.Asteroids, _asteroid))
// // {
// // _miningTool.AsteroidBelt = Task.Asteroids;
// // _miningTool.Asteroid = _asteroid;
// // _toolSwitch.Activated = true;
// // Aim.Objective = Zone.GetAsteroidTransform(Task.Asteroids, _asteroid).xy;
// // Aim.Update(delta);
// // }
// // else NextAsteroid();
// // }
// // }
// // else
// // {
// // _entity.SetMessage("Out of cargo space. Returning home to offload cargo.");
// // GoHome(OnArriveHome);
// // }
// // }
// // }
// // }
// return base.Execute(delta);
// }
//
// // private void OnArriveHome()
// // {
// // var homeEntity = _context.ItemData.Get<Entity>(HomeEntity);
// // foreach (var item in _entity.Cargo
// // .Select(id => _context.ItemData.Get<ItemInstance>(id))
// // .Where(item => item is SimpleCommodity)
// // .Cast<SimpleCommodity>()
// // .ToArray())
// // {
// // int quantity = min((int) ((homeEntity.Capacity - homeEntity.OccupiedCapacity) / _context.GetData(item).Size), item.Quantity);
// // var newItem = _entity.RemoveCargo(item, quantity);
// // homeEntity.AddCargo(newItem);
// //
// // if (quantity < item.Quantity)
// // {
// // homeEntity.SetMessage("Colony is out of cargo space. Closing Mining Task.");
// // FinishTask();
// // _taskStarted = false;
// // return;
// // }
// // }
// // }
//
// private void NextAsteroid()
// {
// _asteroid = Zone.NearestAsteroid(Task.Asteroids, Entity.Position.xz);
// Entity.SetMessage("Selecting new asteroid.");
// }
//
// public PersistentBehaviorData Store()
// {
// return new MiningControllerPersistence
// {
// Task = Task
// };
// }
//
// public void Restore(PersistentBehaviorData data)
// {
// var miningControllerPersistence = data as MiningControllerPersistence;
// Task = miningControllerPersistence.Task;
// }
// }
//
// public class MiningControllerPersistence : PersistentBehaviorData
// {
// [JsonProperty("task"), Key(0)]
// public Mining Task;
// }

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b476455dca4333e4da76388aae46ac5e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,56 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections.Generic;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
// [MessagePackObject, JsonObject(MemberSerialization.OptIn)]
// public class ParticleEffectData : BehaviorData
// {
// [InspectablePrefab, JsonProperty("Particles"), Key(1)]
// public string ParticlesPrefab;
//
// [InspectableField, JsonProperty("thrust"), Key(2)]
// public bool AreaEmitter;
//
// public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
// {
// return new ParticleEffect(context, this, entity, item);
// }
// }
//
// public class ParticleEffect : IBehavior, IAlwaysUpdatedBehavior
// {
// private ParticleEffectData _data;
//
// public Entity Entity { get; }
// public EquippedItem Item { get; }
// public ItemManager Context { get; }
//
// public BehaviorData Data => _data;
//
// public float Emission { get; private set; }
//
// public ParticleEffect(ItemManager context, ParticleEffectData data, Entity entity, EquippedItem item)
// {
// Context = context;
// _data = data;
// Entity = entity;
// Item = item;
// }
//
// public float Execute(float delta, float input)
// {
// Emission = saturate(input);
// return input;
// }
//
// public void Update(float delta)
// {
// Emission = 0;
// }
// }

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3c26dc8102d619a429a178bc6670242d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,104 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
// [MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), Order(-100)]
// public class TowingControllerData : ControllerData
// {
// public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
// {
// return new TowingController(context, this, entity, item);
// }
// }
//
// public class TowingController : ControllerBase<StationTowing>, IBehavior, IPersistentBehavior
// {
//
// private TowingControllerData _data;
// private EquippedItem Item { get; }
// private bool _taskStarted;
//
// public TowingController(ItemManager itemManager, TowingControllerData data, Entity entity, EquippedItem item) : base(itemManager, data, entity)
// {
// _data = data;
// Item = item;
// }
//
// public new bool Execute(float delta)
// {
// if (Task != null)
// {
// if (!_taskStarted)
// {
// MoveTo(Task.Station, true, OnPickup);
// _taskStarted = true;
// }
// }
// return base.Execute(delta);
// }
//
// // void OnZoneArrival()
// // {
// // var towingTask = _context.ItemData.Get<StationTowing>(Task);
// //
// // _entity.SetMessage("Entering pickup phase.");
// //
// // MoveTo(_context.ItemData.Get<Entity>(towingTask.Station), true, OnPickup);
// // }
//
// void OnPickup()
// {
// Task.Station.SetParent(Entity);
//
// Entity.SetMessage("Entering delivery phase.");
//
// MoveTo(() =>
// {
// var orbitParent = Zone.GetOrbitPosition(Task.OrbitParent);
// var parentToUs = Entity.Position.xz - orbitParent;
// return orbitParent + normalize(parentToUs) * Task.OrbitDistance;
// }, () => Zone.GetOrbitVelocity(Task.OrbitParent), OnDelivery);
// }
//
// void OnDelivery()
// {
// Task.Station.RemoveParent();
//
// Entity.SetMessage("Target delivered. Returning Home.");
//
// var orbit = Zone.CreateOrbit(Task.OrbitParent, Entity.Position.xz);
// Task.Station.OrbitData = orbit.ID;
//
// FinishTask();
// _taskStarted = false;
// }
//
// public PersistentBehaviorData Store()
// {
// return new TowingControllerPersistence
// {
// Task = Task
// };
// }
//
// public void Restore(PersistentBehaviorData data)
// {
// var towingControllerPersistence = data as TowingControllerPersistence;
// Task = towingControllerPersistence.Task;
// }
// }
//
// public class TowingControllerPersistence : PersistentBehaviorData
// {
// [JsonProperty("task"), Key(0)]
// public StationTowing Task;
// }

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: de134a549a7d86f43a3590b78a2edeee
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -135,4 +135,12 @@ public class OrderAttribute : Attribute
{
Order = order;
}
}
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true, Inherited = true)]
public class InspectorHeaderAttribute : Attribute
{
public readonly string header;
public InspectorHeaderAttribute(string header) => this.header = header;
}

View file

@ -12,7 +12,8 @@ public class ZoneEnvironment
[JsonProperty("nebula"), Key(0)] public NebulaSettings Nebula;
[JsonProperty("flow"), Key(1)] public FlowSettings Flow;
[JsonProperty("noise"), Key(2)] public NoiseSettings Noise;
[JsonProperty("lighting"), Key(2)] public AmbientLightingSettings Lighting;
[JsonProperty("lighting"), Key(3)] public AmbientLightingSettings Lighting;
[JsonProperty("grid"), Key(4)] public GridSettings Grid;
}
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
@ -33,6 +34,13 @@ public class NebulaSettings
[JsonProperty("safetyDistance"), Key(10)] public float SafetyDistance;
}
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class GridSettings
{
[JsonProperty("enabled"), Key(0)] public bool Enabled;
[JsonProperty("offset"), Key(1)] public float Offset;
}
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class AmbientLightingSettings
{
@ -50,7 +58,7 @@ public class FlowSettings
[JsonProperty("scrollSpeed"), Key(2)] public float GlobalScrollSpeed;
[JsonProperty("period"), Key(3)] public float Period;
[JsonProperty("amplitudeSlope"), Key(4)] public float SlopeAmplitude;
[JsonProperty("amplitudeSwirl"), Key(4)] public float SwirlAmplitude;
[JsonProperty("amplitudeSwirl"), Key(5)] public float SwirlAmplitude;
}
[Serializable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
@ -151,4 +159,3 @@ public class RadialWaveBrush : TextureBrush
return cos((ang + Phase.x) * Frequency.x * PI + (pow(dist, WaveExponent) + Phase.y) * Frequency.y);
}
}

View file

@ -523,7 +523,6 @@ public class Galaxy
{
MinHeap<DijkstraVertex> unsearchedNodes = new MinHeap<DijkstraVertex>();
unsearchedNodes.PushObj(new DijkstraVertex{Zone = source}, 0);
//SortedList<float,DijkstraVertex> members = new SortedList<float,DijkstraVertex>{{0, new DijkstraVertex{Zone = source}}};
var searched = new HashSet<GalaxyZone>();
while (true)
{
@ -543,7 +542,7 @@ public class Galaxy
foreach (var dijkstraStar in zonesToSearch
// Cost is parent cost plus distance squared
.Select(zone => new DijkstraVertex {Parent = s, Zone = zone, Cost = s.Cost + lengthsq(s.Zone.Position - zone.Position)}))
// Add new member to list, sorted by cost plus optional heuristic
// Add new member to list, sorted by cost plus optional heuristic
unsearchedNodes.PushObj(dijkstraStar, bestFirst ? dijkstraStar.Cost + lengthsq(dijkstraStar.Zone.Position - target.Position) : dijkstraStar.Cost);
searched.Add(s.Zone);
}
@ -582,4 +581,4 @@ public class LocationStory
public LocationType Type;
public int Turrets;
public Dictionary<string, List<GalaxyQuest>> KnotQuests = new Dictionary<string, List<GalaxyQuest>>();
}
}