Mega Placement
Megas now have unique placement algorithms for their home sectors PerformanceStats can be marked as simple to hide heat and durability PerformanceStats automatically hide exponents when min and max are the same Some behaviors now have options to spread their effects over time
This commit is contained in:
parent
98371fc453
commit
61072de924
19 changed files with 352 additions and 80 deletions
|
|
@ -105,4 +105,7 @@ public class InspectableTypeAttribute : InspectableFieldAttribute
|
|||
{
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class SimplePerformanceStatAttribute : Attribute { }
|
||||
44
Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs
Normal file
44
Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(12)]
|
||||
public class EnergyDrawData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("draw"), Key(1)]
|
||||
public PerformanceStat Draw = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("perSecond"), Key(2)]
|
||||
public bool PerSecond;
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
{
|
||||
return new EnergyDraw(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class EnergyDraw : IBehavior
|
||||
{
|
||||
private EnergyDrawData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private Gear Item { get; }
|
||||
private GameContext Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public EnergyDraw(GameContext context, EnergyDrawData data, Entity entity, Gear item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
Entity.Energy -= Context.Evaluate(_data.Draw, Item, Entity) * (_data.PerSecond ? delta : 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4f382d59677799f44b024f2a9b4577e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -9,6 +9,9 @@ public class HeatData : BehaviorData
|
|||
[InspectableField, JsonProperty("heat"), Key(1)]
|
||||
public PerformanceStat Heat = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("perSecond"), Key(2)]
|
||||
public bool PerSecond;
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
{
|
||||
return new Heat(context, this, entity, item);
|
||||
|
|
@ -35,7 +38,7 @@ public class Heat : IBehavior
|
|||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
Entity.AddHeat(Context.Evaluate(_data.Heat, Item, Entity));
|
||||
Entity.AddHeat(Context.Evaluate(_data.Heat, Item, Entity) * (_data.PerSecond ? delta : 1));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,9 @@ using Newtonsoft.Json;
|
|||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class HitscanData : WeaponData
|
||||
{
|
||||
[InspectableField, JsonProperty("perSecond"), Key(6)]
|
||||
public bool PerSecond;
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
{
|
||||
return new Hitscan(context, this, entity, item);
|
||||
|
|
@ -32,6 +35,7 @@ public class Hitscan : IBehavior
|
|||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
// TODO: Implement hitscan weapons!
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
44
Assets/Scripts/ServerShared/Behaviors/ResourceScanner.cs
Normal file
44
Assets/Scripts/ServerShared/Behaviors/ResourceScanner.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ResourceScannerData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("range"), Key(1)]
|
||||
public PerformanceStat Range = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("minDensity"), Key(2)]
|
||||
public PerformanceStat MinimumDensity = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
{
|
||||
return new ResourceScanner(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class ResourceScanner : IBehavior
|
||||
{
|
||||
private ResourceScannerData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private Gear Item { get; }
|
||||
private GameContext Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public ResourceScanner(GameContext context, ResourceScannerData data, Entity entity, Gear item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
// TODO: Implement resource scanners!
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c7dc37e3c3c74343adc476dd1981a48
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -113,6 +113,9 @@ public class MegaCorporation : DatabaseEntry, INamedEntry
|
|||
[JsonProperty("parent"), Key(7)]
|
||||
public Guid HomeZone;
|
||||
|
||||
[InspectableField, JsonProperty("placement"), Key(8)]
|
||||
public MegaPlacementType PlacementType;
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
{
|
||||
get => Name;
|
||||
|
|
|
|||
|
|
@ -264,7 +264,6 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
|
||||
AddItemBehaviors();
|
||||
|
||||
var index = 0;
|
||||
// Iterate only over the behaviors of items which contain persistent data
|
||||
// Filter the behaviors for each item to get the persistent ones, then cast them and combine with the persisted data array for that item
|
||||
foreach (var persistentBehaviorData in ItemBehaviors
|
||||
|
|
|
|||
|
|
@ -51,4 +51,13 @@ public enum HullType
|
|||
Ship,
|
||||
Station,
|
||||
Turret
|
||||
}
|
||||
|
||||
public enum MegaPlacementType
|
||||
{
|
||||
Mass = 0,
|
||||
Planets = 1,
|
||||
Resources = 2,
|
||||
Connected = 3,
|
||||
Isolated = 4
|
||||
}
|
||||
|
|
@ -237,6 +237,32 @@ public static class Extensions
|
|||
var d3 = directionAngle + 2 * PI - currentAngle;
|
||||
return abs(d1) < abs(d2) ? abs(d1) < abs(d3) ? d1 : d3 : abs(d2) < abs(d3) ? d2 : d3;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/3188835
|
||||
public static T MaxBy<T, U>(this IEnumerable<T> items, Func<T, U> selector)
|
||||
{
|
||||
if (!items.Any())
|
||||
{
|
||||
throw new InvalidOperationException("Empty input sequence");
|
||||
}
|
||||
|
||||
var comparer = Comparer<U>.Default;
|
||||
T maxItem = items.First();
|
||||
U maxValue = selector(maxItem);
|
||||
|
||||
foreach (T item in items.Skip(1))
|
||||
{
|
||||
// Get the value of the item and compare it to the current max.
|
||||
U value = selector(item);
|
||||
if (comparer.Compare(value, maxValue) > 0)
|
||||
{
|
||||
maxValue = value;
|
||||
maxItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
return maxItem;
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/Burtsev-Alexey/net-object-deep-copy
|
||||
|
|
@ -308,42 +334,6 @@ public static class ObjectExtensions
|
|||
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 static IEnumerable<T> FindPath<T>(this IEnumerable<Edge<T>> data, T source, T target, Func<T, T, double> costFunction, bool bestFirst = true) where T : class
|
||||
// {
|
||||
// List<DijkstraVertex<T>> members = new List<DijkstraVertex<T>>{new DijkstraVertex<T>{Vertex = source}};
|
||||
// List<T> searched = new List<T>();
|
||||
// while (true)
|
||||
// {
|
||||
// var v = members.Where(m=>!searched.Contains(m.Vertex)).OrderBy(m=>bestFirst?m.Heuristic:m.Cost).FirstOrDefault();
|
||||
// if (v == null) return null; // No vertices left unsearched
|
||||
// if (v.Vertex == target)
|
||||
// {
|
||||
// Stack<DijkstraVertex<T>> path = new Stack<DijkstraVertex<T>>();
|
||||
// path.Push(v);
|
||||
// while(path.Peek().Parent!=null)
|
||||
// path.Push(path.Peek().Parent);
|
||||
// return path.Select(dv => dv.Vertex).ToList();
|
||||
// }
|
||||
// members.AddRange(data.Where(l => l.Source == v.Vertex).Select(l => l.Target).Concat(data.Where(l => l.Target == v.Vertex).Select(l => l.Source))
|
||||
// .Where(n => members.All(m => m.Vertex != n)).Select(n =>
|
||||
// {
|
||||
// var c = new DijkstraVertex<T> {Parent = v, Vertex = n, Cost = v.Cost + costFunction(v.Vertex,n)};
|
||||
// if (bestFirst)
|
||||
// c.Heuristic = c.Cost + costFunction(c.Vertex,target);
|
||||
// return c;
|
||||
// }));
|
||||
// searched.Add(v.Vertex);
|
||||
// }
|
||||
// }
|
||||
|
||||
class DijkstraVertex<T>
|
||||
{
|
||||
public double Cost;
|
||||
public double Heuristic;
|
||||
public DijkstraVertex<T> Parent;
|
||||
public T Vertex;
|
||||
}
|
||||
}
|
||||
|
||||
public class ReferenceEqualityComparer : EqualityComparer<Object>
|
||||
|
|
|
|||
|
|
@ -132,7 +132,6 @@ public class GameContext
|
|||
nearestController.AssignTask(task.ID, nearestControllerPath);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach (var kvp in ZoneEntities)
|
||||
|
|
@ -251,6 +250,91 @@ public class GameContext
|
|||
{
|
||||
return pow(distance, GlobalData.OrbitPeriodExponent) * GlobalData.OrbitPeriodMultiplier;
|
||||
}
|
||||
|
||||
public void PlaceMegas()
|
||||
{
|
||||
var megas = Cache.GetAll<MegaCorporation>();
|
||||
|
||||
var availableZones = Cache.GetAll<ZoneData>()
|
||||
.Where(z => megas.All(m => m.HomeZone != z.ID))
|
||||
.ToList();
|
||||
|
||||
foreach(var megaPlacement in megas
|
||||
.OrderBy(m=>m.PlacementType)
|
||||
.GroupBy(m=>m.PlacementType))
|
||||
switch (megaPlacement.Key)
|
||||
{
|
||||
case MegaPlacementType.Mass:
|
||||
foreach (var mega in megaPlacement)
|
||||
{
|
||||
var zone = availableZones
|
||||
.MaxBy(z => z.Mass);
|
||||
availableZones.Remove(zone);
|
||||
mega.HomeZone = zone.ID;
|
||||
}
|
||||
break;
|
||||
case MegaPlacementType.Planets:
|
||||
foreach (var mega in megaPlacement)
|
||||
{
|
||||
var zone = availableZones
|
||||
.MaxBy(z => z.Planets.Length);
|
||||
availableZones.Remove(zone);
|
||||
mega.HomeZone = zone.ID;
|
||||
}
|
||||
break;
|
||||
case MegaPlacementType.Resources:
|
||||
foreach (var mega in megaPlacement)
|
||||
{
|
||||
var zone = availableZones
|
||||
.MaxBy(z => z.Planets
|
||||
.SelectMany(id=>Cache.Get<PlanetData>(id).Resources
|
||||
.Select(r=>r.Key))
|
||||
.Distinct()
|
||||
.Count());
|
||||
availableZones.Remove(zone);
|
||||
mega.HomeZone = zone.ID;
|
||||
}
|
||||
break;
|
||||
case MegaPlacementType.Connected:
|
||||
foreach (var mega in megaPlacement)
|
||||
{
|
||||
var zone = availableZones
|
||||
.OrderByDescending(z => z.Wormholes.Count)
|
||||
.ThenBy(z=>megas
|
||||
.Sum(m=>m.HomeZone==Guid.Empty?0:lengthsq(Cache.Get<ZoneData>(m.HomeZone).Position - z.Position)))
|
||||
.First();
|
||||
availableZones.Remove(zone);
|
||||
mega.HomeZone = zone.ID;
|
||||
}
|
||||
break;
|
||||
case MegaPlacementType.Isolated:
|
||||
foreach (var mega in megaPlacement)
|
||||
{
|
||||
var zone = availableZones
|
||||
.Where(z=>z.Wormholes.Count==1)
|
||||
.MaxBy(z =>
|
||||
{
|
||||
int soloChain = 0;
|
||||
var previous = z;
|
||||
var next = Cache.Get<ZoneData>(z.Wormholes.First());
|
||||
while (next.Wormholes.Count == 2)
|
||||
{
|
||||
var temp = next;
|
||||
next = Cache.Get<ZoneData>(next.Wormholes.First(w=>w != previous.ID));
|
||||
previous = temp;
|
||||
soloChain++;
|
||||
}
|
||||
|
||||
return soloChain;
|
||||
});
|
||||
availableZones.Remove(zone);
|
||||
mega.HomeZone = zone.ID;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
// public int ItemTier(CraftedItemData itemData)
|
||||
// {
|
||||
|
|
|
|||
|
|
@ -96,13 +96,13 @@ public abstract class EquippableItemData : CraftedItemData
|
|||
[TemperatureInspectable, JsonProperty("maxTemp"), Key(8)]
|
||||
public float MaximumTemperature;
|
||||
|
||||
[InspectableField, JsonProperty("durabilityStat"), Key(9)]
|
||||
[InspectableField, JsonProperty("durabilityStat"), Key(9), SimplePerformanceStat]
|
||||
public PerformanceStat Durability = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("durabilityExponent"), Key(10)]
|
||||
[InspectableField, JsonProperty("durabilityExponent"), Key(10), SimplePerformanceStat]
|
||||
public PerformanceStat DurabilityExponent = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("heatExponent"), Key(11)]
|
||||
[InspectableField, JsonProperty("heatExponent"), Key(11), SimplePerformanceStat]
|
||||
public PerformanceStat HeatExponent = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("behaviors"), Key(12)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue