TECH TREES WHOO

Implemented procedural tech tree generation by porting GraphSharp to Unity.
Also, some database editor convenience changes.
This commit is contained in:
hyperion51 2020-04-11 19:18:02 +01:00
commit d5f2e3734a
573 changed files with 31001 additions and 222 deletions

View file

@ -34,9 +34,9 @@ public class UpdateOrderAttribute : Attribute
[AttributeUsage(AttributeTargets.Class)]
public class EntityTypeRestrictionAttribute : Attribute
{
public readonly Type Type;
public readonly HullType Type;
public EntityTypeRestrictionAttribute(Type type)
public EntityTypeRestrictionAttribute(HullType type)
{
Type = type;
}

View file

@ -3,7 +3,7 @@ using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(typeof(Ship))]
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship)]
public class ThrusterData : IBehaviorData
{
[InspectableField, JsonProperty("thrust"), Key(0)]

View file

@ -42,4 +42,11 @@ public enum BodyType
Planet = 1 << 2,
GasGiant = 1 << 3,
Sun = 1 << 4
}
public enum HullType
{
Ship,
Station,
Turret
}

View file

@ -9,6 +9,7 @@ using MessagePack;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using Random = Unity.Mathematics.Random;
using Unity.Tiny;
public static class Extensions
{
@ -67,7 +68,7 @@ public static class Extensions
private static Random? _random;
private static Random Random => (Random) (_random ?? (_random = new Random(1337)));
public static T RandomElement<T>(this IEnumerable<T> enumerable) => enumerable.ElementAt(Random.NextInt(0, enumerable.Count()));
//public static T RandomElement<T>(this IEnumerable<T> enumerable) => enumerable.ElementAt(Random.NextInt(0, enumerable.Count()));
public static float NextUnbounded(this Random random) => 1 / (1 - random.NextFloat()) - 1;
public static float NextUnbounded(this Random random, float bias, float power) => 1 / (1 - pow(random.NextFloat(), 1 - pow(clamp(bias,0,.99f), 1 / power))) - 1;
@ -284,6 +285,12 @@ public static class ObjectExtensions
{
return (T)Copy((Object)original);
}
public static bool IntersectsWith(this Rect r1, Rect r2)
{
return (r2.x + r2.width >= r1.x && r2.x <= r1.x + r1.width) &&
(r2.y + r2.height >= r1.y && r2.y <= r1.y + r1.height);
}
}
public class ReferenceEqualityComparer : EqualityComparer<Object>

View file

@ -8,7 +8,7 @@ using static Unity.Mathematics.math;
using static Unity.Mathematics.noise;
using static NoiseFbm;
[Serializable, RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[Inspectable, Serializable, RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class GlobalData : DatabaseEntry
{
[InspectableField, JsonProperty("targetPersistenceDuration"), Key(1)]

View file

@ -16,15 +16,18 @@ public abstract class ItemData : DatabaseEntry, INamedEntry
{
[InspectableField, JsonProperty("name"), Key(1)]
public string Name;
[InspectableText, JsonProperty("description"), Key(2)]
public string Description;
[InspectableField, JsonProperty("mass"), Key(2)]
[InspectableField, JsonProperty("mass"), Key(3)]
public float Mass;
[InspectableField, JsonProperty("size"), Key(3)]
[InspectableField, JsonProperty("size"), Key(4)]
public float Size;
// Heat needed to change temperature of 1 gram by 1 degree
[InspectableField, JsonProperty("specificHeat"), Key(4)]
[InspectableField, JsonProperty("specificHeat"), Key(5)]
public float SpecificHeat;
[IgnoreMember] public string EntryName
@ -38,19 +41,19 @@ public abstract class ItemData : DatabaseEntry, INamedEntry
public class SimpleCommodityData : ItemData
{
// Types of body where this resource can be found
[InspectableField, JsonProperty("resourceBodyType"), Key(5)]
[InspectableField, JsonProperty("resourceBodyType"), Key(6)]
public BodyType ResourceBodyType;
// Link to map(s) controlling density of resource, multiplied together when more than one
[InspectableDatabaseLink(typeof(GalaxyMapLayerData)), JsonProperty("resourceDensity"), Key(6)]
[InspectableDatabaseLink(typeof(GalaxyMapLayerData)), JsonProperty("resourceDensity"), Key(7)]
public List<Guid> ResourceDensity = new List<Guid>();
// Controls the bias power variable during resource placement
[InspectableField, JsonProperty("resourceDensityBiasPower"), Key(7)]
[InspectableField, JsonProperty("resourceDensityBiasPower"), Key(8)]
public float ResourceDensityBiasPower = 5;
// Minimum amount of resources needed for presence to register
[InspectableField, JsonProperty("resourceFloor"), Key(8)]
[InspectableField, JsonProperty("resourceFloor"), Key(9)]
public float ResourceFloor = 10f;
}
@ -149,13 +152,16 @@ public class HullData : EquippableItemData
[InspectablePrefab, JsonProperty("prefab"), Key(16)]
public string Prefab;
[InspectableField, JsonProperty("hullType"), Key(17)]
public HullType HullType;
[IgnoreMember] public override HardpointType HardpointType => HardpointType.Hull;
}
[RethinkTable("Items"), InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class HardpointData
{
[JsonProperty("type"), Key(0)] public HardpointType Type;
[InspectableField, JsonProperty("type"), Key(0)] public HardpointType Type;
}
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]

View file

@ -0,0 +1,109 @@
using Unity.Mathematics;
namespace Unity.Tiny
{
/// <summary>
/// 2D rectangle
/// </summary>
public struct Rect
{
/// <summary>
/// Default unit rectangle.
/// </summary>
public static Rect Default { get; } = new Rect()
{
x = 0f,
y = 0f,
width = 1f,
height = 1f
};
public Rect(float x, float y, float width, float height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public bool IsEmpty()
{
return !(width > 0.0f && height > 0.0f);
}
/// <summary>
/// Returns true if <paramref name="pos"/> is inside this rectangle.
/// </summary>
/// <remarks>
/// The left and bottom edges are inclusive, while the right and top edges
/// are exclusive. Also, while this class doesn't forbid 0 or negative
/// width / heights, Contains() will be always be false in that case.
/// </remarks>
public bool Contains(float2 pos)
{
return pos.x >= x && pos.y >= y && pos.x < x + width && pos.y < y + height;
}
/// <summary>
/// Returns a new rectangle translated and scaled by <paramref name="relative"/>.
/// </summary>
public Rect Region(in Rect relative)
{
return new Rect
{
x = x + relative.x * width,
y = y + relative.y * height,
width = width * relative.width,
height = height * relative.height
};
}
public void Clamp(Rect r)
{
float x2 = x + width;
float y2 = y + height;
float rx2 = r.x + r.width;
float ry2 = r.y + r.height;
if (x < r.x) x = r.x;
if (x2 > rx2) x2 = rx2;
if (y < r.y) y = r.y;
if (y2 > ry2) y2 = ry2;
width = x2 - x;
if (width < 0.0f) width = 0.0f;
height = y2 - y;
if (height < 0.0f) height = 0.0f;
}
public float x;
public float y;
public float width;
public float height;
/// <summary>
/// The width and height of the rectangle.
/// </summary>
public float2 Size
{
get => new float2(width, this.height);
set
{
width = value.x;
height = value.y;
}
}
/// <summary>
/// The position of the center of the rectangle.
/// </summary>
public float2 Center
{
get => new float2(x + width / 2f, y + height/ 2f);
set
{
x = value.x - width / 2f;
y = value.y - height / 2f;
}
}
}
}

View file

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

View file

@ -14,8 +14,6 @@ public class Ship : Entity
public Gear Hull;
[Key("hardpoints")]
public List<Hardpoint> Hardpoints = new List<Hardpoint>();
[Key("cargo")]
public List<ItemInstance> Cargo = new List<ItemInstance>();
// [Key("bindings")] public Dictionary<KeyCode,Guid> Bindings = new Dictionary<KeyCode,Guid>();
//[IgnoreMember] public int HullHardpointCount;
@ -31,29 +29,29 @@ public class Ship : Entity
{
}
public Gear GetEquipped(HardpointType type)
{
return Hardpoints.FirstOrDefault(hp => hp.HardpointData.Type == type)?.Item;
}
public T GetEquipped<T>() where T : EquippableItemData
{
var data = Hardpoints.FirstOrDefault(hp => Context.GetData(hp.Item) is T);
if (data != null)
return Context.GetData(data.Item) as T;
return null;
}
public void Hydrate()
{
GenerateBehaviors();
//HullHardpointCount = Hardpoints.Count(hp => hp.HardpointData.Type == HardpointType.Hull);
}
private void GenerateBehaviors()
{
}
// public Gear GetEquipped(HardpointType type)
// {
// return Hardpoints.FirstOrDefault(hp => hp.HardpointData.Type == type)?.Item;
// }
//
// public T GetEquipped<T>() where T : EquippableItemData
// {
// var data = Hardpoints.FirstOrDefault(hp => Context.GetData(hp.Item) is T);
// if (data != null)
// return Context.GetData(data.Item) as T;
// return null;
// }
//
// public void Hydrate()
// {
// GenerateBehaviors();
//
// //HullHardpointCount = Hardpoints.Count(hp => hp.HardpointData.Type == HardpointType.Hull);
// }
//
// private void GenerateBehaviors()
// {
// }
// public void GenerateBindings()
// {

View file

@ -0,0 +1,16 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using JsonKnownTypes;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using static Unity.Mathematics.noise;
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class Technology
{
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 32fff9332ceb4fa087d8987c1f9e838a
timeCreated: 1586562126