Game Loop Galaxy Integration
Added sector map in Galaxy tab of in-game menu Added player flag to Ship (replaces AGM.PlayerEntities) Refactored sector map to depend on AGM Moved sector generation to main menu Main menu now supports resuming previous playthrough Database and player settings now statically available via AGM AGM saves current game state in PlayerSettings on exit Sector generation is now asynchronous Added progress callbacks to sector gen + progress dialog in menu Confirmation Dialog / properties panel can now display dynamic text entry Added zone title to Zone map Eliminated ZoneData class (properties moved to ZonePack) Sector, Zone and Entity serialization now fully functional Entity settings now separate from player settings Cleaned up old unused networking message classes Name files now integrated with database cache Added ability to save/load additive DB cache files in database panel Cleaned up Wwise sound setup - removed redundant items & fixed spelling errors Deleted Wwise cache + added to .gitignore
This commit is contained in:
parent
6986ff2562
commit
73651bf16a
130 changed files with 13423 additions and 4406 deletions
|
|
@ -62,16 +62,14 @@ public class MegaCorporation : DatabaseEntry, INamedEntry
|
|||
[InspectableColor, JsonProperty("secondaryColor"), Key(8)]
|
||||
public float3 SecondaryColor;
|
||||
|
||||
[InspectableTextAsset, JsonProperty("geonames"), Key(9)]
|
||||
public string GeonameFile;
|
||||
[InspectableDatabaseLink(typeof(NameFile)), JsonProperty("nameFile"), Key(9)]
|
||||
public Guid GeonameFile;
|
||||
|
||||
[InspectableDatabaseLink(typeof(HullData)), JsonProperty("bossHull"), Key(10)]
|
||||
public Guid BossHull;
|
||||
|
||||
[InspectableField, JsonProperty("influence"), Key(11)]
|
||||
public int InfluenceDistance = 4;
|
||||
|
||||
[IgnoreMember] public MarkovNameGenerator NameGenerator { get; set; }
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
{
|
||||
|
|
@ -79,3 +77,10 @@ public class MegaCorporation : DatabaseEntry, INamedEntry
|
|||
set => Name = value;
|
||||
}
|
||||
}
|
||||
|
||||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class NameFile : DatabaseEntry
|
||||
{
|
||||
[JsonProperty("names"), Key(1)]
|
||||
public string[] Names;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,6 +118,6 @@ public class DatabaseCache
|
|||
{
|
||||
RegisterResolver.Register();
|
||||
var entries = AllEntries.ToArray();
|
||||
File.WriteAllBytes(Path.Combine(path, "AetherDB.msgpack"), MessagePackSerializer.Serialize(entries));
|
||||
File.WriteAllBytes(path, MessagePackSerializer.Serialize(entries));
|
||||
}
|
||||
}
|
||||
|
|
@ -27,8 +27,8 @@ public interface INamedEntry
|
|||
Union(6, typeof(EquippableItem)),
|
||||
Union(7, typeof(BlueprintData)),
|
||||
Union(8, typeof(GalaxyMapLayerData)),
|
||||
// Union(9, typeof(GlobalData)),
|
||||
Union(10, typeof(ZoneData)),
|
||||
Union(9, typeof(NameFile)),
|
||||
//Union(10, typeof(ZoneData)),
|
||||
Union(11, typeof(PlayerData)),
|
||||
Union(12, typeof(Corporation)),
|
||||
Union(13, typeof(MegaCorporation)),
|
||||
|
|
@ -56,4 +56,7 @@ public abstract class DatabaseEntry
|
|||
{
|
||||
[JsonProperty("id"), Key(0)]
|
||||
public Guid ID = Guid.NewGuid();
|
||||
|
||||
[IgnoreMember]
|
||||
public DatabaseCache Database;
|
||||
}
|
||||
|
|
@ -8,7 +8,6 @@ using Unity.Mathematics;
|
|||
|
||||
public static class EntitySerializer
|
||||
{
|
||||
|
||||
public static EntityPack Pack(Entity entity)
|
||||
{
|
||||
EntityPack pack;
|
||||
|
|
@ -21,9 +20,12 @@ public static class EntitySerializer
|
|||
pack = new ShipPack
|
||||
{
|
||||
Position = ship.Position,
|
||||
Direction = ship.Direction
|
||||
Direction = ship.Direction,
|
||||
IsPlayerShip = ship.IsPlayerShip
|
||||
};
|
||||
else throw new ArgumentException("Attempted to pack an instance of abstract class Entity!");
|
||||
|
||||
pack.Settings = entity.Settings;
|
||||
|
||||
// Filter item behavior collections by those with any persistent behaviors
|
||||
// For each item create an object containing the item position and a list of persistent behaviors
|
||||
|
|
@ -52,6 +54,8 @@ public static class EntitySerializer
|
|||
|
||||
public static Entity Unpack(ItemManager itemManager, Zone zone, EntityPack pack, bool instantiate = false)
|
||||
{
|
||||
pack.Settings ??= MessagePackSerializer.Deserialize<EntitySettings>(
|
||||
MessagePackSerializer.Serialize(itemManager.GameplaySettings.DefaultEntitySettings));
|
||||
return pack switch
|
||||
{
|
||||
ShipPack shipPack => Unpack(itemManager, zone, shipPack, instantiate),
|
||||
|
|
@ -63,8 +67,12 @@ public static class EntitySerializer
|
|||
|
||||
private static Ship Unpack(ItemManager itemManager, Zone zone, ShipPack pack, bool instantiate = false)
|
||||
{
|
||||
|
||||
var entity = new Ship(itemManager, zone, instantiate ? (EquippableItem) itemManager.Instantiate(pack.Hull) : pack.Hull, pack.Settings);
|
||||
Restore(itemManager, zone, pack, entity, instantiate);
|
||||
entity.Position = pack.Position;
|
||||
entity.Direction = pack.Direction;
|
||||
entity.IsPlayerShip = pack.IsPlayerShip;
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
|
@ -130,11 +138,9 @@ public static class EntitySerializer
|
|||
[MessagePackObject]
|
||||
public class ShipPack : EntityPack
|
||||
{
|
||||
[Key(15)]
|
||||
public float3 Position;
|
||||
|
||||
[Key(16)]
|
||||
public float2 Direction;
|
||||
[Key(15)] public float3 Position;
|
||||
[Key(16)] public float2 Direction;
|
||||
[Key(17)] public bool IsPlayerShip;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
@ -147,7 +153,7 @@ public class OrbitalEntityPack : EntityPack
|
|||
[MessagePackObject,
|
||||
Union(0, typeof(OrbitalEntityPack)),
|
||||
Union(1, typeof(ShipPack))]
|
||||
public class EntityPack
|
||||
public abstract class EntityPack
|
||||
{
|
||||
[Key(0)]
|
||||
public string Name;
|
||||
|
|
|
|||
|
|
@ -20,11 +20,10 @@ public class MarkovNameGenerator
|
|||
private int _maxLength;
|
||||
private Random _random;
|
||||
|
||||
public MarkovNameGenerator(ref Random random, string nameData, SectorGenerationSettings settings)
|
||||
public MarkovNameGenerator(ref Random random, IEnumerable<string> sampleNames, SectorGenerationSettings settings)
|
||||
{
|
||||
var names = new HashSet<string>();
|
||||
var lines = nameData.Split('\n');
|
||||
foreach (var line in lines)
|
||||
foreach (var line in sampleNames)
|
||||
{
|
||||
foreach(var word in line.ToUpperInvariant().Split(' ', ',', '.', '"'))
|
||||
if (word.Length >= settings.NameGeneratorMinLength && !names.Contains(word))
|
||||
|
|
|
|||
|
|
@ -18,12 +18,6 @@ using Unity.Mathematics;
|
|||
Union(6, typeof(ChatMessage)),
|
||||
Union(7, typeof(ChatBroadcastMessage)),
|
||||
Union(8, typeof(ChangeNameMessage)),
|
||||
Union(9, typeof(GalaxyRequestMessage)),
|
||||
Union(10, typeof(GalaxyResponseMessage)),
|
||||
Union(11, typeof(ZoneRequestMessage)),
|
||||
Union(12, typeof(ZoneResponseMessage)),
|
||||
Union(13, typeof(BlueprintsRequestMessage)),
|
||||
Union(14, typeof(BlueprintsResponseMessage)),
|
||||
MessagePackObject]
|
||||
public abstract class Message
|
||||
{
|
||||
|
|
@ -88,52 +82,3 @@ public class ChangeNameMessage : Message
|
|||
{
|
||||
[Key(0)] public string Name;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class GalaxyRequestMessage : Message
|
||||
{
|
||||
//[Key(0)] public int RequiredByMessagePack;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class GalaxyResponseMessage : Message
|
||||
{
|
||||
[Key(0)] public ZoneDefinition[] Zones;
|
||||
[Key(1)] public GalaxyMapLayerData StarDensity;
|
||||
// [Key(2)] public GlobalData GlobalData;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class ZoneDefinition
|
||||
{
|
||||
[Key(0)] public Guid ZoneID;
|
||||
[Key(1)] public Guid[] Links;
|
||||
[Key(2)] public string Name;
|
||||
[Key(3)] public float2 Position;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class ZoneRequestMessage : Message
|
||||
{
|
||||
[Key(0)] public Guid ZoneID;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class ZoneResponseMessage : Message
|
||||
{
|
||||
[Key(0)] public ZoneData Zone;
|
||||
[Key(1)] public DatabaseEntry[] Contents;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class BlueprintsRequestMessage : Message
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class BlueprintsResponseMessage : Message
|
||||
{
|
||||
[Key(0)] public BlueprintData[] Blueprints;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public static class WeightedSampleElimination
|
|||
}, d_max);
|
||||
}
|
||||
|
||||
public static float2[] GeneratePoints(int count, Func<float2, float> density = null, Func<float2, float> envelope = null, uint seed = 1337)
|
||||
public static float2[] GeneratePoints(int count, Func<float2, float> density = null, Func<float2, float> envelope = null, Action<string> progressCallback = null, uint seed = 1337)
|
||||
{
|
||||
if (density == null) density = v => .5f;
|
||||
if (envelope == null) envelope = v => 1;
|
||||
|
|
@ -101,9 +101,11 @@ public static class WeightedSampleElimination
|
|||
{
|
||||
accumulator = 0;
|
||||
inputSamples[sample++] = v;
|
||||
progressCallback?.Invoke($"Generating Samples: {sample} / {inputSamples.Length}");
|
||||
}
|
||||
}
|
||||
var outputSamples = new float2[count];
|
||||
progressCallback?.Invoke("Eliminating Samples");
|
||||
Eliminate(inputSamples, outputSamples, density);
|
||||
return outputSamples;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,11 +31,15 @@ public class SavedGame
|
|||
|
||||
[Key(7)]
|
||||
public int CurrentZoneEntity;
|
||||
|
||||
[Key(8)]
|
||||
public SectorGenerationSettings Settings;
|
||||
|
||||
public SavedGame() { }
|
||||
|
||||
public SavedGame(Sector sector)
|
||||
public SavedGame(Sector sector, Zone currentZone, Entity currentEntity)
|
||||
{
|
||||
Settings = sector.Settings;
|
||||
Factions = sector.HomeZones.Keys.Select(f => f.ID).ToArray();
|
||||
|
||||
HomeZones = sector.HomeZones.ToDictionary(
|
||||
|
|
@ -45,15 +49,18 @@ public class SavedGame
|
|||
x => Array.IndexOf(Factions, x.Key.ID),
|
||||
x => Array.IndexOf(sector.Zones, x.Value));
|
||||
|
||||
Zones = sector.Zones.Select(zone=> new SavedZone
|
||||
Zones = sector.Zones.Select(zone => new SavedZone
|
||||
{
|
||||
Name = zone.Name,
|
||||
Position = zone.Position,
|
||||
AdjacentZones = zone.AdjacentZones.Select(az=> Array.IndexOf(sector.Zones, az)).ToArray(),
|
||||
Factions = zone.Factions.Select(f=> Array.IndexOf(Factions, f.ID)).ToArray(),
|
||||
Contents = zone.Contents.Pack(),
|
||||
Owner = Array.IndexOf(Factions, zone.Owner.ID)
|
||||
Contents = zone.Contents?.PackZone(),
|
||||
Owner = zone.Owner == null ? -1 : Array.IndexOf(Factions, zone.Owner.ID)
|
||||
}).ToArray();
|
||||
|
||||
CurrentZone = Array.FindIndex(sector.Zones, zone => zone.Contents == currentZone);
|
||||
CurrentZoneEntity = currentZone.Entities.IndexOf(currentEntity);
|
||||
|
||||
Entrance = Array.IndexOf(sector.Zones, sector.Entrance);
|
||||
Exit = Array.IndexOf(sector.Zones, sector.Exit);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DataStructures.ViliWonka.Heap;
|
||||
using MIConvexHull;
|
||||
using JM.LinqFaster;
|
||||
|
|
@ -13,11 +15,14 @@ public class Sector
|
|||
public Dictionary<MegaCorporation, SectorZone> HomeZones = new Dictionary<MegaCorporation, SectorZone>();
|
||||
public Dictionary<MegaCorporation, SectorZone> BossZones = new Dictionary<MegaCorporation, SectorZone>();
|
||||
|
||||
public SectorGenerationSettings Settings { get; }
|
||||
public MegaCorporation[] Factions { get; }
|
||||
public SectorZone[] Zones { get; }
|
||||
public SectorZone Entrance { get; }
|
||||
public SectorZone Exit { get; }
|
||||
|
||||
private SectorZone[] _exitPath;
|
||||
private Dictionary<MegaCorporation, MarkovNameGenerator> _nameGenerators = new Dictionary<MegaCorporation, MarkovNameGenerator>();
|
||||
|
||||
public SectorZone[] ExitPath
|
||||
{
|
||||
|
|
@ -29,28 +34,30 @@ public class Sector
|
|||
|
||||
public Sector(DatabaseCache database, SavedGame savedGame)
|
||||
{
|
||||
var factions = savedGame.Factions.Select(database.Get<MegaCorporation>).ToArray();
|
||||
Settings = savedGame.Settings;
|
||||
Factions = savedGame.Factions.Select(database.Get<MegaCorporation>).ToArray();
|
||||
Zones = savedGame.Zones.Select(zone =>
|
||||
{
|
||||
return new SectorZone
|
||||
{
|
||||
Name = zone.Name,
|
||||
Position = zone.Position
|
||||
Position = zone.Position,
|
||||
PackedContents = zone.Contents
|
||||
};
|
||||
}).ToArray();
|
||||
for (var i = 0; i < Zones.Length; i++)
|
||||
{
|
||||
Zones[i].AdjacentZones = savedGame.Zones[i].AdjacentZones.Select(azi => Zones[azi]).ToList();
|
||||
Zones[i].Factions = savedGame.Zones[i].Factions.Select(mi => factions[mi]).ToArray();
|
||||
Zones[i].Owner = factions[savedGame.Zones[i].Owner];
|
||||
Zones[i].Factions = savedGame.Zones[i].Factions.Select(mi => Factions[mi]).ToArray();
|
||||
Zones[i].Owner = savedGame.Zones[i].Owner < 0 ? null : Factions[savedGame.Zones[i].Owner];
|
||||
}
|
||||
|
||||
HomeZones = savedGame.HomeZones.ToDictionary(
|
||||
x => factions[x.Key],
|
||||
x => Factions[x.Key],
|
||||
x => Zones[x.Value]);
|
||||
|
||||
BossZones = savedGame.BossZones.ToDictionary(
|
||||
x => factions[x.Key],
|
||||
x => Factions[x.Key],
|
||||
x => Zones[x.Value]);
|
||||
|
||||
Entrance = Zones[savedGame.Entrance];
|
||||
|
|
@ -59,15 +66,24 @@ public class Sector
|
|||
CalculateDistanceMatrix();
|
||||
}
|
||||
|
||||
public Sector(SectorGenerationSettings settings, MegaCorporation[] factions, ref Random random, float minLineSeparation = .01f)
|
||||
public Sector(SectorGenerationSettings settings, DatabaseCache database, uint seed = 0, Action<string> progressCallback = null, float minLineSeparation = .01f)
|
||||
{
|
||||
Settings = settings;
|
||||
var megas = database.GetAll<MegaCorporation>();
|
||||
var random = new Random(seed == 0 ? (uint) (DateTime.Now.Ticks % uint.MaxValue) : seed);
|
||||
Factions = megas.OrderBy(x => random.NextFloat()).Take(settings.MegaCount).ToArray();
|
||||
|
||||
var outputSamples = WeightedSampleElimination.GeneratePoints(settings.ZoneCount,
|
||||
settings.CloudDensity,
|
||||
v => (.2f - lengthsq(v - float2(.5f))) * 4);
|
||||
v => (.2f - lengthsq(v - float2(.5f))) * 4,
|
||||
progressCallback);
|
||||
Zones = outputSamples.Select(v => new SectorZone {Position = v}).ToArray();
|
||||
|
||||
#region Link Placement
|
||||
|
||||
progressCallback?.Invoke("Triangulating Zone Positions");
|
||||
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
|
||||
|
||||
// Create a delaunay triangulation to connect adjacent sectors
|
||||
var triangulation = DelaunayTriangulation<Vertex2<SectorZone>, Cell2<SectorZone>>
|
||||
.Create(Zones.Select(z => new Vertex2<SectorZone>(z.Position, z)).ToList(), 1e-5f);
|
||||
|
|
@ -85,6 +101,8 @@ public class Sector
|
|||
links.Add((cell.Vertices[0].StoredObject, cell.Vertices[2].StoredObject));
|
||||
}
|
||||
|
||||
progressCallback?.Invoke("Eliminating Zone Links");
|
||||
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
|
||||
foreach (var link in links.ToArray())
|
||||
{
|
||||
foreach (var zone in Zones)
|
||||
|
|
@ -133,25 +151,33 @@ public class Sector
|
|||
|
||||
#endregion
|
||||
|
||||
progressCallback?.Invoke("Calculating Distance Matrix");
|
||||
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
|
||||
CalculateDistanceMatrix();
|
||||
|
||||
progressCallback?.Invoke("Finding Chokepoints");
|
||||
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
|
||||
|
||||
// Entrance is the most isolated zone (highest total distance to all other zones
|
||||
Entrance = Zones.MaxBy(z => z.Isolation);
|
||||
|
||||
// Exit is the zone furthest from the exit
|
||||
Exit = Zones.MaxBy(z => Exit.Distance[z]);
|
||||
// Exit is the zone furthest from the entrance
|
||||
Exit = Zones.MaxBy(z => Entrance.Distance[z]);
|
||||
|
||||
// Find all zones on the exit path where removing that zone would disconnect the entrance from the exit
|
||||
// Disregard "corridor" zones with only two adjacent zones
|
||||
var chokePoints = ExitPath
|
||||
.Where(z => z.AdjacentZones.Count > 2 && !ConnectedRegion(Entrance, z).Contains(Exit));
|
||||
|
||||
|
||||
progressCallback?.Invoke("Placing Factions");
|
||||
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
|
||||
|
||||
// Choose some megas to have bosses placed based on whether a boss hull is assigned
|
||||
var bossMegas = factions
|
||||
var bossMegas = Factions
|
||||
.Where(m => m.BossHull != Guid.Empty)
|
||||
.Take(settings.BossCount)
|
||||
.ToArray();
|
||||
|
||||
|
||||
// Place boss zones along the critical path as far apart from each other as possible
|
||||
foreach (var mega in bossMegas)
|
||||
{
|
||||
|
|
@ -171,7 +197,7 @@ public class Sector
|
|||
}
|
||||
|
||||
// Place remaining headquarters away from existing megas while also maximizing territory
|
||||
foreach (var mega in factions.Where(m=>!bossMegas.Contains(m)))
|
||||
foreach (var mega in Factions.Where(m=>!bossMegas.Contains(m)))
|
||||
{
|
||||
HomeZones[mega] = Zones.MaxBy(z =>
|
||||
pow(ConnectedRegion(z, mega.InfluenceDistance).Count, HomeZones.Count) *
|
||||
|
|
@ -179,24 +205,53 @@ public class Sector
|
|||
HomeZones.Values.Aggregate(1f, (i, os) => i * sqrt(os.Distance[z])) *
|
||||
BossZones.Values.Aggregate(1f, (i, os) => i * sqrt(os.Distance[z])));
|
||||
}
|
||||
|
||||
progressCallback?.Invoke("Calculating Faction Influence");
|
||||
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
|
||||
|
||||
// Assign faction presence
|
||||
foreach (var zone in Zones)
|
||||
{
|
||||
// Factions are present in all zones within their sphere of influence
|
||||
zone.Factions = factions
|
||||
zone.Factions = Factions
|
||||
.Where(m => zone.Distance[HomeZones[m]] <= m.InfluenceDistance)
|
||||
.ToArray();
|
||||
|
||||
// Owner of a zone is the faction with the nearest headquarters
|
||||
var nearestFaction = factions.MinBy(m => zone.Distance[HomeZones[m]]);
|
||||
var nearestFaction = Factions.MinBy(m => zone.Distance[HomeZones[m]]);
|
||||
if (zone.Distance[HomeZones[nearestFaction]] <= nearestFaction.InfluenceDistance)
|
||||
zone.Owner = nearestFaction;
|
||||
}
|
||||
|
||||
for (var i = 0; i < Factions.Length; i++)
|
||||
{
|
||||
progressCallback?.Invoke($"Feeding Markov Chains: {i} / {Factions.Length}");
|
||||
//if(progressCallback!=null) Thread.Sleep(250); // Inserting Delay to make it seem like it's doing more work lmao
|
||||
var faction = Factions[i];
|
||||
_nameGenerators[faction] = new MarkovNameGenerator(ref random, database.Get<NameFile>(faction.GeonameFile).Names, settings);
|
||||
}
|
||||
|
||||
// Generate zone name using the owner's name generator, otherwise assign catalogue ID
|
||||
foreach (var zone in Zones)
|
||||
zone.Name = zone.Owner?.NameGenerator.NextName ?? $"EAC-{random.NextInt(99999).ToString()}";
|
||||
foreach (var zone in Zones)
|
||||
{
|
||||
if (zone.Owner != null)
|
||||
{
|
||||
zone.Name = _nameGenerators[zone.Owner].NextName.Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
zone.Name = $"EAC-{random.NextInt(99999).ToString()}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
progressCallback?.Invoke("Done!");
|
||||
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
|
||||
}
|
||||
|
||||
private void GenerateSector()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Cache distance matrix and calculate isolation for every zone (used extensively for placing stuff)
|
||||
|
|
@ -328,4 +383,5 @@ public class SectorZone
|
|||
public MegaCorporation[] Factions;
|
||||
public MegaCorporation Owner;
|
||||
public Zone Contents;
|
||||
public ZonePack PackedContents;
|
||||
}
|
||||
|
|
@ -61,7 +61,6 @@ public class SectorGenerationSettings
|
|||
public float NoiseGain;
|
||||
public float NoiseLacunarity;
|
||||
public float NoiseFrequency;
|
||||
public float Zoom = 1;
|
||||
|
||||
public float fBm(float2 p, int octaves)
|
||||
{
|
||||
|
|
@ -80,7 +79,7 @@ public class SectorGenerationSettings
|
|||
|
||||
public float CloudDensity(float2 uv)
|
||||
{
|
||||
float noise = fBm(uv / Zoom + NoisePosition, 10);
|
||||
float noise = fBm(uv + NoisePosition, 10);
|
||||
return pow(noise, CloudExponent) * CloudAmplitude;
|
||||
}
|
||||
}
|
||||
|
|
@ -133,6 +132,7 @@ public class ZoneGenerationSettings
|
|||
[Serializable, MessagePackObject(keyAsPropertyName: true), JsonObject]
|
||||
public class GameplaySettings
|
||||
{
|
||||
public EntitySettings DefaultEntitySettings;
|
||||
public RarityTier[] Tiers;
|
||||
public float DefaultShutdownPerformance = .25f;
|
||||
public float SevereHeatstrokeRiskThreshold = .25f;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ public class Ship : Entity
|
|||
// [IgnoreMember] public Targetable Target;
|
||||
public Entity HomeEntity;
|
||||
public float2 MovementDirection;
|
||||
public bool IsPlayerShip;
|
||||
|
||||
private HashSet<EquippedItem> _thrusterItems;
|
||||
private Thruster[] _allThrusters;
|
||||
|
|
|
|||
|
|
@ -3,4 +3,5 @@ using Unity.Mathematics;
|
|||
public class Wormhole
|
||||
{
|
||||
public float2 Position;
|
||||
public SectorZone Target;
|
||||
}
|
||||
|
|
@ -34,15 +34,18 @@ public class Zone
|
|||
private Random _random;
|
||||
public List<Agent> Agents = new List<Agent>();
|
||||
|
||||
public ZoneData Data { get; }
|
||||
private List<Task> BeltUpdates = new List<Task>();
|
||||
|
||||
public ZonePack Pack { get; }
|
||||
public SectorZone SectorZone { get; }
|
||||
|
||||
public Zone(ItemManager itemManager, PlanetSettings settings, ZonePack pack)
|
||||
public Zone(ItemManager itemManager, PlanetSettings settings, ZonePack pack, SectorZone sectorZone)
|
||||
{
|
||||
SectorZone = sectorZone;
|
||||
Pack = pack;
|
||||
_itemManager = itemManager;
|
||||
Data = pack.Data;
|
||||
Settings = settings;
|
||||
_random = new Random(Convert.ToUInt32(abs(Data.ID.GetHashCode())));
|
||||
_random = new Random(Convert.ToUInt32(abs(sectorZone?.Name.GetHashCode() ?? 1337)));
|
||||
|
||||
foreach (var orbit in pack.Orbits)
|
||||
{
|
||||
|
|
@ -66,19 +69,22 @@ public class Zone
|
|||
}
|
||||
}
|
||||
|
||||
foreach (var entity in pack.Entities)
|
||||
foreach (var entityPack in pack.Entities)
|
||||
{
|
||||
Entities.Add(EntitySerializer.Unpack(_itemManager, this, entity));
|
||||
var entity = EntitySerializer.Unpack(_itemManager, this, entityPack);
|
||||
Entities.Add(entity);
|
||||
entity.Activate();
|
||||
}
|
||||
|
||||
// TODO: Associate planets with stored entities for planetary colonies
|
||||
}
|
||||
|
||||
public ZonePack Pack()
|
||||
public ZonePack PackZone()
|
||||
{
|
||||
return new ZonePack
|
||||
{
|
||||
Data = Data,
|
||||
Radius = Pack.Radius,
|
||||
Mass = Pack.Mass,
|
||||
Entities = Entities.Select(EntitySerializer.Pack).ToList(),
|
||||
Orbits = Orbits.Values.Select(o=>o.Data).ToList(),
|
||||
Planets = Planets.Values.ToList()
|
||||
|
|
@ -118,12 +124,6 @@ public class Zone
|
|||
|
||||
foreach (var entity in Entities.ToArray()) entity.Update(deltaTime);
|
||||
}
|
||||
|
||||
public float2 WormholePosition(ZoneDefinition target)
|
||||
{
|
||||
var direction = target.Position - Data.Position;
|
||||
return normalize(direction) * Data.Radius * .95f;
|
||||
}
|
||||
|
||||
// Determine orbital position recursively, caching parent positions to avoid repeated calculations
|
||||
public float2 GetOrbitPosition(Guid orbitID)
|
||||
|
|
@ -284,7 +284,7 @@ public class Zone
|
|||
}
|
||||
public float GetHeight(float2 position)
|
||||
{
|
||||
float result = -PowerPulse(length(position)/(Data.Radius*2), Settings.ZoneDepthExponent) * Settings.ZoneDepth;
|
||||
float result = -PowerPulse(length(position)/(Pack.Radius*2), Settings.ZoneDepthExponent) * Settings.ZoneDepth;
|
||||
foreach (var body in PlanetInstances.Values)
|
||||
{
|
||||
var p = position - body.Orbit.Position; //GetOrbitPosition(body.BodyData.Orbit)
|
||||
|
|
@ -343,11 +343,6 @@ public class Zone
|
|||
float3 normal = new float3((hL - hR), (hD - hU), step*2);
|
||||
return normalize(normal).xzy;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Data.ID.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public class Planet
|
||||
|
|
|
|||
|
|
@ -13,60 +13,23 @@ using static Unity.Mathematics.math;
|
|||
using float2 = Unity.Mathematics.float2;
|
||||
using float3 = Unity.Mathematics.float3;
|
||||
|
||||
[RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ZoneData : DatabaseEntry, INamedEntry
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ZonePack
|
||||
{
|
||||
[JsonProperty("name"), Key(1)]
|
||||
public string Name;
|
||||
|
||||
[JsonProperty("position"), Key(2)]
|
||||
public float2 Position = 500;
|
||||
|
||||
[JsonProperty("planets"), Key(0)]
|
||||
public List<BodyData> Planets = new List<BodyData>();
|
||||
|
||||
[JsonProperty("orbits"), Key(1)]
|
||||
public List<OrbitData> Orbits = new List<OrbitData>();
|
||||
|
||||
[JsonProperty("entities"), Key(2)]
|
||||
public List<EntityPack> Entities = new List<EntityPack>();
|
||||
|
||||
[JsonProperty("radius"), Key(3)]
|
||||
public float Radius = 2000;
|
||||
|
||||
[JsonProperty("mass"), Key(4)]
|
||||
public float Mass = 10000;
|
||||
|
||||
// [JsonProperty("visited"), Key(5)]
|
||||
// public bool Visited;
|
||||
|
||||
[JsonProperty("wormholes"), Key(5)]
|
||||
public List<Guid> Wormholes = new List<Guid>();
|
||||
|
||||
// [JsonProperty("planets"), Key(7)]
|
||||
// public Guid[] Planets;// = new List<Guid>();
|
||||
//
|
||||
// [JsonProperty("orbits"), Key(8)]
|
||||
// public List<Guid> Orbits = new List<Guid>();
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
{
|
||||
get => Name;
|
||||
set => Name = value;
|
||||
}
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ZonePack : INamedEntry
|
||||
{
|
||||
[JsonProperty("data"), Key(0)]
|
||||
public ZoneData Data;
|
||||
|
||||
[JsonProperty("planets"), Key(1)]
|
||||
public List<BodyData> Planets = new List<BodyData>();
|
||||
|
||||
[JsonProperty("orbits"), Key(2)]
|
||||
public List<OrbitData> Orbits = new List<OrbitData>();
|
||||
|
||||
[JsonProperty("entities"), Key(3)]
|
||||
public List<EntityPack> Entities = new List<EntityPack>();
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
{
|
||||
get => Data.Name;
|
||||
set => Data.Name = value;
|
||||
}
|
||||
}
|
||||
|
||||
// [RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
|
|
@ -227,7 +190,7 @@ public class OrbitData : DatabaseEntry
|
|||
[JsonProperty("phase"), Key(3)]
|
||||
public float Phase;
|
||||
|
||||
[JsonProperty("phase"), Key(3)]
|
||||
[JsonProperty("phase"), Key(4)]
|
||||
public float2 FixedPosition = float2.zero;
|
||||
|
||||
// [JsonProperty("period"), Key(4)]
|
||||
|
|
|
|||
|
|
@ -73,19 +73,11 @@ public class ZoneGenerator
|
|||
Random random,
|
||||
int targetSubzoneCount)
|
||||
{
|
||||
var zone = new ZoneData
|
||||
{
|
||||
Name = name,
|
||||
Position = position
|
||||
};
|
||||
|
||||
var pack = new ZonePack();
|
||||
|
||||
var pack = new ZonePack
|
||||
{
|
||||
Data = zone
|
||||
};
|
||||
|
||||
zone.Radius = radius;
|
||||
zone.Mass = mass;
|
||||
pack.Radius = radius;
|
||||
pack.Mass = mass;
|
||||
|
||||
//Debug.Log($"Generating zone at position {zone.Position} with radius {zoneRadius} and mass {zoneMass}");
|
||||
|
||||
|
|
@ -122,11 +114,11 @@ public class ZoneGenerator
|
|||
var totalArea = occupiedAreas.Sum(c => c.Area);
|
||||
foreach (var c in occupiedAreas)
|
||||
{
|
||||
planets.AddRange(GenerateEntities(settings, ref random, c.Area / totalArea * zone.Mass, c.Radius, c.Center));
|
||||
planets.AddRange(GenerateEntities(settings, ref random, c.Area / totalArea * pack.Mass, c.Radius, c.Center));
|
||||
}
|
||||
}
|
||||
else
|
||||
planets.AddRange(GenerateEntities(settings, ref random, zone.Mass, zone.Radius, float2.zero));
|
||||
planets.AddRange(GenerateEntities(settings, ref random, pack.Mass, pack.Radius, float2.zero));
|
||||
|
||||
// Create collections to map between zone generator output and database entries
|
||||
var orbitMap = new Dictionary<GeneratorPlanet, OrbitData>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue