Ultimate Sector Generation X Pro Max Silver Edition
Added entrances, exits and factions to sector generation Associated each corporation with a unique name database and color scheme
This commit is contained in:
parent
0f33e541c0
commit
f10804ac11
60 changed files with 1392 additions and 135031 deletions
|
|
@ -67,4 +67,49 @@ public static class AetheriaMath
|
|||
else //determinant = 0; one intercept path, pretty much never happens
|
||||
return max(-b/(2f*a), 0f); //don't shoot back in time
|
||||
}
|
||||
|
||||
// http://csharphelper.com/blog/2016/09/find-the-shortest-distance-between-a-point-and-a-line-segment-in-c/
|
||||
// Calculate the distance between
|
||||
// point pt and the segment p1 --> p2.
|
||||
public static float FindDistanceToSegment(
|
||||
float2 pt, float2 p1, float2 p2, out float2 closest)
|
||||
{
|
||||
float dx = p2.x - p1.x;
|
||||
float dy = p2.y - p1.y;
|
||||
if (dx == 0 && dy == 0)
|
||||
{
|
||||
// It's a point not a line segment.
|
||||
closest = p1;
|
||||
dx = pt.x - p1.x;
|
||||
dy = pt.y - p1.y;
|
||||
return sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
// Calculate the t that minimizes the distance.
|
||||
float t = ((pt.x - p1.x) * dx + (pt.y - p1.y) * dy) /
|
||||
(dx * dx + dy * dy);
|
||||
|
||||
// See if this represents one of the segment's
|
||||
// end points or a point in the middle.
|
||||
if (t < 0)
|
||||
{
|
||||
closest = float2(p1.x, p1.y);
|
||||
dx = pt.x - p1.x;
|
||||
dy = pt.y - p1.y;
|
||||
}
|
||||
else if (t > 1)
|
||||
{
|
||||
closest = float2(p2.x, p2.y);
|
||||
dx = pt.x - p2.x;
|
||||
dy = pt.y - p2.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
closest = float2(p1.x + t * dx, p1.y + t * dy);
|
||||
dx = pt.x - closest.x;
|
||||
dy = pt.y - closest.y;
|
||||
}
|
||||
|
||||
return sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,11 +74,17 @@ public class InspectablePrefabAttribute : InspectableFieldAttribute { }
|
|||
public class InspectableTextureAttribute : InspectableFieldAttribute { }
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class TemperatureInspectableAttribute : InspectableFieldAttribute { }
|
||||
public class InspectableTextAssetAttribute : InspectableFieldAttribute { }
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class InspectableTemperatureAttribute : InspectableFieldAttribute { }
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class InspectableAnimationCurveAttribute : InspectableFieldAttribute { }
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class InspectableColorAttribute : InspectableFieldAttribute { }
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class InspectableDatabaseLinkAttribute : InspectableFieldAttribute
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public class RadiatorData : BehaviorData
|
|||
[InspectableField, JsonProperty("pumpedHeat"), Key(2), RuntimeInspectable]
|
||||
public PerformanceStat PumpedHeat = new PerformanceStat();
|
||||
|
||||
[TemperatureInspectable, JsonProperty("temperatureFloor"), Key(3), RuntimeInspectable]
|
||||
[InspectableTemperature, JsonProperty("temperatureFloor"), Key(3), RuntimeInspectable]
|
||||
public float TemperatureFloor;
|
||||
|
||||
[InspectableField, JsonProperty("wasteHeat"), Key(4), RuntimeInspectable]
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using Newtonsoft.Json;
|
|||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-22)]
|
||||
public class ThermotoggleData : BehaviorData
|
||||
{
|
||||
[TemperatureInspectable, JsonProperty("targetTemp"), Key(1)]
|
||||
[InspectableTemperature, JsonProperty("targetTemp"), Key(1)]
|
||||
public float TargetTemperature;
|
||||
|
||||
[InspectableField, JsonProperty("highPass"), Key(2)]
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ using static Unity.Mathematics.math;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(1000), RuntimeInspectable]
|
||||
public class WearData : BehaviorData
|
||||
{
|
||||
[TemperatureInspectable, JsonProperty("perSecond"), Key(1)]
|
||||
[InspectableTemperature, JsonProperty("perSecond"), Key(1)]
|
||||
public bool PerSecond = true;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
|
||||
|
||||
[RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
|
|
@ -51,6 +52,17 @@ public class MegaCorporation : DatabaseEntry, INamedEntry
|
|||
|
||||
[InspectableField, JsonProperty("hostile"), Key(5)]
|
||||
public bool PlayerHostile;
|
||||
|
||||
[InspectableColor, JsonProperty("primaryColor"), Key(6)]
|
||||
public float3 PrimaryColor;
|
||||
|
||||
[InspectableColor, JsonProperty("secondaryColor"), Key(7)]
|
||||
public float3 SecondaryColor;
|
||||
|
||||
[InspectableTextAsset, JsonProperty("geonames"), Key(8)]
|
||||
public string GeonameFile;
|
||||
|
||||
[IgnoreMember] public MarkovNameGenerator NameGenerator { get; set; }
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
{
|
||||
|
|
|
|||
|
|
@ -282,10 +282,10 @@ public abstract class EquippableItemData : CraftedItemData
|
|||
[InspectableField, JsonProperty("durability"), Key(12)]
|
||||
public float Durability;
|
||||
|
||||
[TemperatureInspectable, JsonProperty("minTemp"), Key(13)]
|
||||
[InspectableTemperature, JsonProperty("minTemp"), Key(13)]
|
||||
public float MinimumTemperature;
|
||||
|
||||
[TemperatureInspectable, JsonProperty("maxTemp"), Key(14)]
|
||||
[InspectableTemperature, JsonProperty("maxTemp"), Key(14)]
|
||||
public float MaximumTemperature;
|
||||
|
||||
[InspectableField, JsonProperty("durabilityExponent"), Key(15), SimplePerformanceStat]
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
||||
//Generates random names based on the statistical weight of letter sequences
|
||||
|
|
@ -34,7 +35,7 @@ public class MarkovNameGenerator
|
|||
//split comma delimited lines
|
||||
foreach (string line in sampleNames)
|
||||
{
|
||||
string[] tokens = line.Split(' ','-','\'','(',')');
|
||||
string[] tokens = line.Split(' ','\'','(',')');
|
||||
foreach (string word in tokens)
|
||||
{
|
||||
string upper = word.Trim().ToLowerInvariant();
|
||||
|
|
@ -89,7 +90,7 @@ public class MarkovNameGenerator
|
|||
}
|
||||
while (_used.Contains(s) || s.Length < _minLength || s.Length > _maxLength);
|
||||
_used.Add(s);
|
||||
return s;
|
||||
return s.First().ToString().ToUpper() + s.Substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ public static class WeightedSampleElimination
|
|||
while (sample < inputSamples.Length)
|
||||
{
|
||||
var v = random.NextFloat2();
|
||||
accumulator += pow(saturate(density(v)), 2f) * envelope(v);
|
||||
accumulator += pow(saturate(density(v)), 2f) * saturate(envelope(v));
|
||||
if (accumulator > .5f)
|
||||
{
|
||||
accumulator = 0;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ using static Unity.Mathematics.math;
|
|||
public class Sector
|
||||
{
|
||||
public List<SectorZone> Zones = new List<SectorZone>();
|
||||
public Dictionary<MegaCorporation, SectorZone> OccupantSources = new Dictionary<MegaCorporation, SectorZone>();
|
||||
public SectorZone Entrance;
|
||||
public SectorZone Exit;
|
||||
|
||||
class DijkstraVertex
|
||||
{
|
||||
|
|
@ -21,7 +24,7 @@ public class Sector
|
|||
members.Add(v);
|
||||
while (true)
|
||||
{
|
||||
int lastCount = members.Count;
|
||||
var lastCount = members.Count;
|
||||
// For each member, add all vertices that are connected to it but are not already a member
|
||||
// Also, if there is a zone being ignored, do not traverse across it
|
||||
foreach (SectorZone m in members.ToArray())
|
||||
|
|
@ -32,6 +35,31 @@ public class Sector
|
|||
return members;
|
||||
}
|
||||
}
|
||||
|
||||
//public int TotalDistance(SectorZone v) => ConnectedRegionDistance(v).Sum(x => x.distance);
|
||||
|
||||
public Dictionary<SectorZone, int> ConnectedRegionDistance(SectorZone v)
|
||||
{
|
||||
Dictionary<SectorZone, int> members = new Dictionary<SectorZone, int>();
|
||||
members.Add(v,0);
|
||||
int cost = 1;
|
||||
while (true)
|
||||
{
|
||||
var lastCount = members.Count;
|
||||
// For each member, add all vertices that are connected to it but are not already a member
|
||||
// Also, if there is a zone being ignored, do not traverse across it
|
||||
foreach (var member in members.Keys.ToArray())
|
||||
foreach (var adjacentZone in member.AdjacentZones)
|
||||
{
|
||||
if(!members.ContainsKey(adjacentZone))
|
||||
members.Add(adjacentZone, cost);
|
||||
}
|
||||
// If we have stopped finding neighbors, stop traversing
|
||||
if (members.Count == lastCount)
|
||||
return members;
|
||||
cost++;
|
||||
}
|
||||
}
|
||||
|
||||
public List<SectorZone> FindPath(SectorZone source, SectorZone target, bool bestFirst = false)
|
||||
{
|
||||
|
|
@ -66,4 +94,7 @@ public class SectorZone
|
|||
public string Name;
|
||||
public float2 Position;
|
||||
public List<SectorZone> AdjacentZones = new List<SectorZone>();
|
||||
public int Isolation;
|
||||
public Dictionary<SectorZone, int> Distance;
|
||||
public MegaCorporation[] Occupants;
|
||||
}
|
||||
|
|
@ -8,23 +8,41 @@ using static Unity.Mathematics.math;
|
|||
|
||||
public static class SectorGenerator
|
||||
{
|
||||
public static Sector GenerateSector(SectorGenerationSettings settings, MarkovNameGenerator nameGenerator, int zoneCount, float linkDensity)
|
||||
public static Sector GenerateSector(SectorGenerationSettings settings, MegaCorporation[] megas, int zoneCount = 32, float linkDensity = .5f, float minLineSeparation = .01f)
|
||||
{
|
||||
var outputSamples = WeightedSampleElimination.GeneratePoints(zoneCount,
|
||||
settings.CloudDensity,
|
||||
v => (.2f - lengthsq(v - float2(.5f))) * 4);
|
||||
var sector = new Sector();
|
||||
foreach (var v in outputSamples) sector.Zones.Add(new SectorZone {Position = v, Name = nameGenerator.NextName});
|
||||
|
||||
foreach (var v in outputSamples) sector.Zones.Add(new SectorZone {Position = v});
|
||||
|
||||
#region Link Placement
|
||||
|
||||
// Create a delaunay triangulation to connect adjacent sectors
|
||||
var triangulation = DelaunayTriangulation<Vertex2<SectorZone>, Cell2<SectorZone>>
|
||||
.Create(sector.Zones.Select(z => new Vertex2<SectorZone>(z.Position, z)).ToList(), 1e-5f);
|
||||
var links = new List<(SectorZone, SectorZone)>();
|
||||
var links = new HashSet<(SectorZone, SectorZone)>();
|
||||
foreach(var cell in triangulation.Cells)
|
||||
{
|
||||
links.Add((cell.Vertices[0].StoredObject, cell.Vertices[1].StoredObject));
|
||||
links.Add((cell.Vertices[1].StoredObject, cell.Vertices[2].StoredObject));
|
||||
links.Add((cell.Vertices[0].StoredObject, cell.Vertices[2].StoredObject));
|
||||
if(!links.Contains((cell.Vertices[0].StoredObject, cell.Vertices[1].StoredObject)) &&
|
||||
!links.Contains((cell.Vertices[1].StoredObject, cell.Vertices[0].StoredObject)))
|
||||
links.Add((cell.Vertices[0].StoredObject, cell.Vertices[1].StoredObject));
|
||||
if(!links.Contains((cell.Vertices[1].StoredObject, cell.Vertices[2].StoredObject)) &&
|
||||
!links.Contains((cell.Vertices[2].StoredObject, cell.Vertices[1].StoredObject)))
|
||||
links.Add((cell.Vertices[1].StoredObject, cell.Vertices[2].StoredObject));
|
||||
if(!links.Contains((cell.Vertices[0].StoredObject, cell.Vertices[2].StoredObject)) &&
|
||||
!links.Contains((cell.Vertices[2].StoredObject, cell.Vertices[0].StoredObject)))
|
||||
links.Add((cell.Vertices[0].StoredObject, cell.Vertices[2].StoredObject));
|
||||
}
|
||||
|
||||
foreach (var link in links.ToArray())
|
||||
{
|
||||
foreach (var zone in sector.Zones)
|
||||
{
|
||||
if(zone != link.Item1 && zone != link.Item2)
|
||||
if (AetheriaMath.FindDistanceToSegment(zone.Position, link.Item1.Position, link.Item2.Position, out _) < minLineSeparation)
|
||||
links.Remove(link);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var link in links)
|
||||
|
|
@ -63,6 +81,62 @@ public static class SectorGenerator
|
|||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
foreach (var zone in sector.Zones)
|
||||
{
|
||||
zone.Distance = sector.ConnectedRegionDistance(zone);
|
||||
zone.Isolation = zone.Distance.Sum(x => x.Value);
|
||||
}
|
||||
|
||||
sector.Exit = sector.Zones.MaxBy(z => z.Isolation);
|
||||
sector.Entrance = sector.Zones.MaxBy(z => sector.Exit.Distance[z]);
|
||||
foreach (var mega in megas)
|
||||
{
|
||||
sector.OccupantSources[mega] = sector.Zones.MaxBy(z =>
|
||||
sector.Exit.Distance[z] * sector.Entrance.Distance[z] *
|
||||
sector.OccupantSources.Values.Aggregate(1, (i, os) => i * os.Distance[z]));
|
||||
}
|
||||
|
||||
foreach (var zone in sector.Zones)
|
||||
{
|
||||
var sourceDistances = new int[megas.Length];
|
||||
var minSourceDistance = int.MaxValue;
|
||||
var occupants = 0;
|
||||
for (var i = 0; i < megas.Length; i++)
|
||||
{
|
||||
sourceDistances[i] = sector.OccupantSources[megas[i]].Distance[zone];
|
||||
|
||||
if (sourceDistances[i] == minSourceDistance)
|
||||
{
|
||||
occupants++;
|
||||
}
|
||||
|
||||
if (sourceDistances[i] < minSourceDistance)
|
||||
{
|
||||
minSourceDistance = sourceDistances[i];
|
||||
occupants = 1;
|
||||
}
|
||||
}
|
||||
|
||||
zone.Occupants = new MegaCorporation[occupants];
|
||||
|
||||
var occupantIndex = 0;
|
||||
for (var i = 0; i < megas.Length; i++)
|
||||
{
|
||||
if (sourceDistances[i] == minSourceDistance)
|
||||
{
|
||||
zone.Occupants[occupantIndex++] = megas[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sector.Zones[0].Name = "Hello World!";
|
||||
foreach (var zone in sector.Zones)
|
||||
{
|
||||
zone.Name = zone.Occupants[0].NameGenerator.NextName; // TODO: Merge Naming
|
||||
}
|
||||
|
||||
return sector;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue