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
|
|
@ -135,7 +135,7 @@ public class DatabaseInspector : EditorWindow
|
|||
var range = inspectable as RangedFloatInspectableAttribute;
|
||||
field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (float) value, range.Min, range.Max));
|
||||
}
|
||||
else if (inspectable is TemperatureInspectableAttribute)
|
||||
else if (inspectable is InspectableTemperatureAttribute)
|
||||
field.SetValue(obj, InspectTemperature(field.Name.SplitCamelCase(), (float) value));
|
||||
else
|
||||
field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (float) value));
|
||||
|
|
@ -158,6 +158,13 @@ public class DatabaseInspector : EditorWindow
|
|||
{
|
||||
field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (int2) field.GetValue(obj)));
|
||||
}
|
||||
else if (type == typeof(float3))
|
||||
{
|
||||
if (inspectable is InspectableColorAttribute)
|
||||
{
|
||||
field.SetValue(obj, ColorField(field.Name.SplitCamelCase(), ((float3)field.GetValue(obj)).ToColor()).ToFloat3());
|
||||
}
|
||||
}
|
||||
else if (type.IsEnum)
|
||||
{
|
||||
var isflags = type.GetCustomAttributes<FlagsAttribute>().Any();
|
||||
|
|
@ -179,6 +186,8 @@ public class DatabaseInspector : EditorWindow
|
|||
field.SetValue(obj, InspectUnityObject<GameObject>(field.Name.SplitCamelCase(), (string) value));
|
||||
else if(inspectable is InspectableTextureAttribute)
|
||||
field.SetValue(obj, InspectUnityObject<Texture2D>(field.Name.SplitCamelCase(), (string) value));
|
||||
else if(inspectable is InspectableTextAssetAttribute)
|
||||
field.SetValue(obj, InspectUnityObject<TextAsset>(field.Name.SplitCamelCase(), (string) value));
|
||||
else
|
||||
field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (string) value, inspectable is InspectableTextAttribute));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
using System.Buffers.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
|
@ -13,6 +16,7 @@ public class NameTools : EditorWindow
|
|||
private int minWordLength = 4;
|
||||
private TextAsset nameFile;
|
||||
private MarkovNameGenerator _nameGenerator;
|
||||
private bool _stripNumberTokens;
|
||||
|
||||
// Add menu named "My Window" to the Window menu
|
||||
[MenuItem("Window/Aetheria/Name Tools")]
|
||||
|
|
@ -30,6 +34,32 @@ public class NameTools : EditorWindow
|
|||
NameGeneratorMinLength = EditorGUILayout.IntField("Generated Minimum Word Length", NameGeneratorMinLength);
|
||||
NameGeneratorMaxLength = EditorGUILayout.IntField("Generated Maximum Word Length", NameGeneratorMaxLength);
|
||||
NameGeneratorOrder = EditorGUILayout.IntField("Generator Order", NameGeneratorOrder);
|
||||
_stripNumberTokens = GUILayout.Toggle(_stripNumberTokens, "Strip Number Tokens");
|
||||
|
||||
if (GUILayout.Button("Clean Name File"))
|
||||
{
|
||||
var lines = nameFile.text.Split('\n');
|
||||
using StreamWriter outputFile = new StreamWriter(Path.Combine(Application.dataPath, nameFile.name + ".csv"));
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (!_stripNumberTokens)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(line) && Regex.IsMatch(line, "^[\\x00-\\x7F]+$") && !char.IsDigit(line[0]))
|
||||
{
|
||||
outputFile.WriteLine(line.Trim());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var tokens = line.Split('_', '-', ' ');
|
||||
if(!(tokens.Any(t => t.Length == 2 && char.IsUpper(t[0]) && char.IsUpper(t[1]))))
|
||||
//if (Regex.IsMatch(line, "^[\\x00-\\x7F]+$") && !tokens.Any(t=>int.TryParse(t, out _)) && !tokens.Any(t=>t=="AM"||t=="FM"||t=="TV"))
|
||||
{
|
||||
outputFile.WriteLine(line.Trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Process Name File") && nameFile != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,15 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using static Unity.Mathematics.noise;
|
||||
using Random = UnityEngine.Random;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
|
||||
public class SectorMap : MonoBehaviour
|
||||
{
|
||||
|
|
@ -14,45 +17,67 @@ public class SectorMap : MonoBehaviour
|
|||
public SectorGenerationSettings Settings;
|
||||
public Prototype ZonePrototype;
|
||||
public Prototype LinkPrototype;
|
||||
public Prototype EntrancePrototype;
|
||||
public Prototype ExitPrototype;
|
||||
public float ExitDistance = 1;
|
||||
public int ZoneCount = 64;
|
||||
public int MegaCount = 2;
|
||||
public float LinkDensity = .5f;
|
||||
public float LabelDistance = .4f;
|
||||
|
||||
[Header("Name Generation")]
|
||||
public TextAsset NameFile;
|
||||
public int NameFileMinWordLength = 4;
|
||||
public int NameGeneratorMinLength = 5;
|
||||
public int NameGeneratorMaxLength = 10;
|
||||
public int NameGeneratorOrder = 4;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
var names = new HashSet<string>();
|
||||
var lines = NameFile.text.Split('\n');
|
||||
foreach (var line in lines)
|
||||
{
|
||||
foreach(var word in line.ToUpperInvariant().Split(' ', ',', '.', '"'))
|
||||
if (word.Length >= NameGeneratorMinLength && !names.Contains(word))
|
||||
names.Add(word);
|
||||
}
|
||||
var filePath = new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
|
||||
var cache = new DatabaseCache();
|
||||
cache.Load(Path.Combine(filePath.FullName, "AetherDB.msgpack"));
|
||||
|
||||
var random = new Unity.Mathematics.Random(1337);
|
||||
for (int i = 0; i < 4096; i++) random.NextFloat();
|
||||
var nameGenerator = new MarkovNameGenerator(ref random, names, NameGeneratorOrder, NameGeneratorMinLength, NameGeneratorMaxLength);
|
||||
var megas = cache.GetAll<MegaCorporation>();
|
||||
|
||||
var sectorMegas = megas.OrderBy(x => Random.value).Take(MegaCount).ToArray();
|
||||
foreach (var mega in sectorMegas)
|
||||
{
|
||||
var nameFile = UnityHelpers.LoadAsset<TextAsset>(mega.GeonameFile);
|
||||
var names = new HashSet<string>();
|
||||
var lines = nameFile.text.Split('\n');
|
||||
foreach (var line in lines)
|
||||
{
|
||||
foreach(var word in line.ToUpperInvariant().Split(' ', ',', '.', '"'))
|
||||
if (word.Length >= NameGeneratorMinLength && !names.Contains(word))
|
||||
names.Add(word);
|
||||
}
|
||||
|
||||
var random = new Unity.Mathematics.Random((uint) (DateTime.Now.Ticks % uint.MaxValue));
|
||||
mega.NameGenerator = new MarkovNameGenerator(ref random, names, NameGeneratorOrder, NameGeneratorMinLength, NameGeneratorMaxLength);
|
||||
}
|
||||
|
||||
Settings.NoisePosition = Random.value * 100;
|
||||
var sector = SectorGenerator.GenerateSector(Settings, nameGenerator, ZoneCount, LinkDensity);
|
||||
var sector = SectorGenerator.GenerateSector(Settings, sectorMegas, ZoneCount, LinkDensity);
|
||||
var visitedZones = new HashSet<SectorZone>();
|
||||
Debug.Log($"Found {sector.Zones.Count(z=>!z.AdjacentZones.Any())} orphaned zones!");
|
||||
foreach (var zone in sector.Zones)
|
||||
{
|
||||
var zoneInstance = ZonePrototype.Instantiate<Transform>();
|
||||
zoneInstance.localPosition = new Vector3(zone.Position.x, zone.Position.y);
|
||||
var zoneInstance = ZonePrototype.Instantiate<SectorZoneUI>();
|
||||
zoneInstance.transform.localPosition = new Vector3(zone.Position.x, zone.Position.y);
|
||||
zoneInstance.Background.material.SetColor("_TintColor", zone.Occupants[0].PrimaryColor.ToColor());
|
||||
zoneInstance.Background.transform.localScale = Vector3.one * (sector.OccupantSources.Values.Any(os=>os==zone) ? 4 : 2);
|
||||
var linkDirection = float2.zero;
|
||||
foreach (var link in zone.AdjacentZones)
|
||||
{
|
||||
linkDirection += normalize(link.Position - zone.Position);
|
||||
if (!visitedZones.Contains(link))
|
||||
{
|
||||
var linkInstance = LinkPrototype.Instantiate<Transform>();
|
||||
var pos = (zone.Position + link.Position) / 2;
|
||||
linkInstance.localPosition = new Vector3(pos.x, pos.y);
|
||||
if (zone.Occupants.Length == 1 && link.Occupants.Length == 1 && zone.Occupants[0] == link.Occupants[0])
|
||||
{
|
||||
linkInstance.GetComponent<MeshRenderer>().material.SetColor("_TintColor", zone.Occupants[0].PrimaryColor.ToColor());
|
||||
}
|
||||
|
||||
var localScale = linkInstance.localScale;
|
||||
localScale = new Vector3(length(zone.Position - link.Position), localScale.y, localScale.z);
|
||||
|
|
@ -62,7 +87,30 @@ public class SectorMap : MonoBehaviour
|
|||
linkInstance.rotation = Quaternion.Euler(0,0,atan2(dir.y,dir.x) * Mathf.Rad2Deg);
|
||||
}
|
||||
}
|
||||
|
||||
linkDirection = normalize(linkDirection);
|
||||
var zoneText = zoneInstance.Label;
|
||||
zoneText.text = zone.Name;
|
||||
var zoneTextTransform = zoneText.GetComponent<RectTransform>();
|
||||
zoneTextTransform.pivot = new Vector2(sign(linkDirection.x)/2+.5f,sign(linkDirection.y)/2+.5f);
|
||||
zoneTextTransform.localPosition = new Vector3(-linkDirection.x * LabelDistance, -linkDirection.y * LabelDistance);
|
||||
visitedZones.Add(zone);
|
||||
|
||||
if (zone == sector.Entrance)
|
||||
{
|
||||
var entranceInstance = EntrancePrototype.Instantiate<Transform>();
|
||||
entranceInstance.localPosition = new Vector3(
|
||||
zone.Position.x - linkDirection.x * ExitDistance,
|
||||
zone.Position.y - linkDirection.y * ExitDistance);
|
||||
}
|
||||
|
||||
if (zone == sector.Exit)
|
||||
{
|
||||
var entranceInstance = ExitPrototype.Instantiate<Transform>();
|
||||
entranceInstance.localPosition = new Vector3(
|
||||
zone.Position.x - linkDirection.x * ExitDistance,
|
||||
zone.Position.y - linkDirection.y * ExitDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
11
Assets/Scripts/UI/SectorZoneUI.cs
Normal file
11
Assets/Scripts/UI/SectorZoneUI.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SectorZoneUI : MonoBehaviour
|
||||
{
|
||||
public MeshRenderer Background;
|
||||
public TextMeshPro Label;
|
||||
}
|
||||
11
Assets/Scripts/UI/SectorZoneUI.cs.meta
Normal file
11
Assets/Scripts/UI/SectorZoneUI.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c8b54233e980c94096777e19a4e070a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -111,6 +111,7 @@ public static class UnityExtensions
|
|||
}
|
||||
|
||||
public static Color ToColor(this float3 v) => new Color(v.x,v.y,v.z);
|
||||
public static float3 ToFloat3(this Color c) => float3(c.r,c.g,c.b);
|
||||
|
||||
public static Vector3 Flatland(this Vector2 v, float y = 0) => new Vector3(v.x,y,v.y);
|
||||
public static Vector2 Flatland(this Vector3 v) => new Vector2(v.x,v.z);
|
||||
|
|
|
|||
Loading…
Reference in a new issue