Gear Schematic HUD
Created in-flight equipment HUD & schematic display
This commit is contained in:
parent
6db7c65961
commit
1e273d691e
253 changed files with 19369 additions and 6296 deletions
|
|
@ -45,6 +45,11 @@ public interface IAlwaysUpdatedBehavior
|
|||
void AlwaysUpdate(float delta);
|
||||
}
|
||||
|
||||
public interface IProgressBehavior
|
||||
{
|
||||
float Progress { get; }
|
||||
}
|
||||
|
||||
public interface IOrderedBehavior
|
||||
{
|
||||
int Order { get; }
|
||||
|
|
@ -111,6 +116,7 @@ public abstract class PersistentBehaviorData
|
|||
Union(30, typeof(HaulingControllerData)),
|
||||
Union(31, typeof(CapacitorData)),
|
||||
Union(32, typeof(CockpitData)),
|
||||
Union(33, typeof(HeatsinkData)),
|
||||
JsonConverter(typeof(JsonKnownTypesConverter<BehaviorData>)), JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class BehaviorData
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ public class Cockpit : IBehavior
|
|||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public float Heatstroke { get; private set; }
|
||||
|
||||
public Cockpit(ItemManager context, CockpitData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
|
|
@ -33,10 +35,22 @@ public class Cockpit : IBehavior
|
|||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Heatstroke = 0;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
if (Item.Temperature > Context.GameplaySettings.HeatstrokeTemperature)
|
||||
{
|
||||
Heatstroke = saturate(
|
||||
Heatstroke +
|
||||
pow(Item.Temperature - Context.GameplaySettings.HeatstrokeTemperature, Context.GameplaySettings.HeatstrokeExponent) *
|
||||
Context.GameplaySettings.HeatstrokeMultiplier * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
Heatstroke = saturate(Heatstroke - Context.GameplaySettings.HeatstrokeRecoverySpeed * delta);
|
||||
}
|
||||
return Heatstroke < Context.GameplaySettings.HeatstrokeControlLimit;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,8 @@ using System;
|
|||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-10), RuntimeInspectable]
|
||||
public class CooldownData : BehaviorData
|
||||
|
|
@ -19,7 +21,7 @@ public class CooldownData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
public class Cooldown : IBehavior, IAlwaysUpdatedBehavior
|
||||
public class Cooldown : IBehavior, IAlwaysUpdatedBehavior, IProgressBehavior
|
||||
{
|
||||
private CooldownData _data;
|
||||
public BehaviorData Data => _data;
|
||||
|
|
@ -30,6 +32,8 @@ public class Cooldown : IBehavior, IAlwaysUpdatedBehavior
|
|||
|
||||
private float _cooldown; // Normalized
|
||||
|
||||
public float Progress => saturate(_cooldown);
|
||||
|
||||
public Cooldown(ItemManager context, CooldownData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
|
|
|
|||
42
Assets/Scripts/ServerShared/Behaviors/Heatsink.cs
Normal file
42
Assets/Scripts/ServerShared/Behaviors/Heatsink.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class HeatsinkData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new Heatsink(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Heatsink : IBehavior
|
||||
{
|
||||
private HeatsinkData _data;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public Heatsink(ItemManager context, HeatsinkData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Behaviors/Heatsink.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Behaviors/Heatsink.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0933c645c44822441a0d2d8e06c8d343
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -38,6 +38,8 @@ public class Reactor : IBehavior, IOrderedBehavior
|
|||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public float Surplus { get; private set; }
|
||||
|
||||
public int Order => 100;
|
||||
|
||||
|
|
@ -67,6 +69,8 @@ public class Reactor : IBehavior, IOrderedBehavior
|
|||
|
||||
Item.AddHeat(charge / efficiency);
|
||||
Entity.Energy += charge;
|
||||
|
||||
Surplus = Entity.Energy;
|
||||
|
||||
// We have an energy deficit, try to get some energy out of our capacitors first
|
||||
if (Entity.Energy < 0)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ public abstract class Entity
|
|||
public readonly Dictionary<string, float> Messages = new Dictionary<string, float>();
|
||||
public readonly Dictionary<object, float> VisibilitySources = new Dictionary<object, float>();
|
||||
|
||||
private List<IPopulationAssignment> PopulationAssignments = new List<IPopulationAssignment>();
|
||||
public readonly List<EquippedItem>[] TriggerGroups;
|
||||
|
||||
public List<IPopulationAssignment> PopulationAssignments = new List<IPopulationAssignment>();
|
||||
|
||||
public EquippedItem[,] GearOccupancy;
|
||||
public EquippedItem[,] ThermalOccupancy;
|
||||
|
|
@ -86,14 +88,15 @@ public abstract class Entity
|
|||
Hull = hull;
|
||||
Name = hull.Name;
|
||||
MapShip();
|
||||
TriggerGroups = new List<EquippedItem>[itemManager.GameplaySettings.TriggerGroupCount];
|
||||
for(int i=0; i<itemManager.GameplaySettings.TriggerGroupCount; i++)
|
||||
TriggerGroups[i] = new List<EquippedItem>();
|
||||
}
|
||||
|
||||
private void MapShip()
|
||||
{
|
||||
var hullData = ItemManager.GetData(Hull) as HullData;
|
||||
var hull = new EquippedItem(ItemManager, Hull, int2.zero, this);
|
||||
Equipment.Add(hull);
|
||||
Hydrate(hull);
|
||||
Equipment.Add(new EquippedItem(ItemManager, Hull, int2.zero, this));
|
||||
Mass = hullData.Mass;
|
||||
Temperature = new float[hullData.Shape.Width, hullData.Shape.Height];
|
||||
Conductivity = new float4[hullData.Shape.Width, hullData.Shape.Height];
|
||||
|
|
@ -118,45 +121,25 @@ public abstract class Entity
|
|||
}
|
||||
}
|
||||
|
||||
public void Hydrate(EquippedItem equippedItem)
|
||||
{
|
||||
if (equippedItem.EquippableItem == null)
|
||||
{
|
||||
ItemManager.Log("Attempted to hydrate EquippedGear with no gear on it! This should be impossible!");
|
||||
return;
|
||||
}
|
||||
|
||||
var gearData = ItemManager.GetData(equippedItem.EquippableItem);
|
||||
|
||||
equippedItem.Behaviors = gearData.Behaviors
|
||||
.Select(bd => bd.CreateInstance(ItemManager, this, equippedItem))
|
||||
.ToArray();
|
||||
|
||||
equippedItem.BehaviorGroups = equippedItem.Behaviors
|
||||
.GroupBy(b => b.Data.Group)
|
||||
.OrderBy(g=>g.Key)
|
||||
.Select(g=> new BehaviorGroup {
|
||||
Behaviors = g.ToArray(),
|
||||
//Axis = (IAnalogBehavior) g.FirstOrDefault(b=>b is IAnalogBehavior),
|
||||
Switch = (Switch) g.FirstOrDefault(b=>b is Switch),
|
||||
Trigger = (Trigger) g.FirstOrDefault(b=>b is Trigger)
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
foreach (var behavior in equippedItem.Behaviors)
|
||||
{
|
||||
if (behavior is IOrderedBehavior orderedBehavior)
|
||||
equippedItem.SortPosition = orderedBehavior.Order;
|
||||
if(behavior is IPopulationAssignment populationAssignment)
|
||||
PopulationAssignments.Add(populationAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddHeat(int2 position, float heat)
|
||||
{
|
||||
Temperature[position.x, position.y] += heat / ThermalMass[position.x, position.y];
|
||||
}
|
||||
|
||||
public int CountItemsInCargo(Guid itemDataID)
|
||||
{
|
||||
int sum = 0;
|
||||
foreach (var x in CargoBays)
|
||||
{
|
||||
if (x.ItemsOfType.ContainsKey(itemDataID))
|
||||
{
|
||||
foreach (var i in x.ItemsOfType[itemDataID]) sum += i is SimpleCommodity simpleCommodity ? simpleCommodity.Quantity : 1;
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
public EquippedCargoBay FindItemInCargo(Guid itemDataID)
|
||||
{
|
||||
return CargoBays.FirstOrDefault(c => c.ItemsOfType.ContainsKey(itemDataID));
|
||||
|
|
@ -376,7 +359,6 @@ public abstract class Entity
|
|||
}
|
||||
|
||||
Mass += itemData.Mass;
|
||||
Hydrate(equippedItem);
|
||||
_orderedEquipment = Equipment.OrderBy(x => x.SortPosition).ToArray();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -394,7 +376,6 @@ public abstract class Entity
|
|||
}
|
||||
|
||||
Mass += itemData.Mass;
|
||||
Hydrate(equippedItem);
|
||||
_orderedEquipment = Equipment.OrderBy(x => x.SortPosition).ToArray();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -642,6 +623,29 @@ public class EquippedItem
|
|||
Position = position;
|
||||
var hullData = itemManager.GetData(entity.Hull);
|
||||
InsetShape = hullData.Shape.Inset(_data.Shape, position, item.Rotation);
|
||||
|
||||
Behaviors = _data.Behaviors
|
||||
.Select(bd => bd.CreateInstance(itemManager, entity, this))
|
||||
.ToArray();
|
||||
|
||||
BehaviorGroups = Behaviors
|
||||
.GroupBy(b => b.Data.Group)
|
||||
.OrderBy(g=>g.Key)
|
||||
.Select(g=> new BehaviorGroup {
|
||||
Behaviors = g.ToArray(),
|
||||
//Axis = (IAnalogBehavior) g.FirstOrDefault(b=>b is IAnalogBehavior),
|
||||
Switch = (Switch) g.FirstOrDefault(b=>b is Switch),
|
||||
Trigger = (Trigger) g.FirstOrDefault(b=>b is Trigger)
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
foreach (var behavior in Behaviors)
|
||||
{
|
||||
if (behavior is IOrderedBehavior orderedBehavior)
|
||||
SortPosition = orderedBehavior.Order;
|
||||
if(behavior is IPopulationAssignment populationAssignment)
|
||||
entity.PopulationAssignments.Add(populationAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddHeat(float heat)
|
||||
|
|
|
|||
|
|
@ -79,7 +79,9 @@ public enum SimpleCommodityCategory
|
|||
Metals,
|
||||
Alloys,
|
||||
Compounds,
|
||||
Organics
|
||||
Organics,
|
||||
Ammo,
|
||||
Consumer
|
||||
}
|
||||
|
||||
public enum CompoundCommodityCategory
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ public class ZoneGenerationSettings
|
|||
[Serializable, MessagePackObject(keyAsPropertyName: true), JsonObject]
|
||||
public class GameplaySettings
|
||||
{
|
||||
public int TriggerGroupCount = 6;
|
||||
public float WarpDistance = 25;
|
||||
public float DockingDistance = 25;
|
||||
public int SignificantDigits = 3;
|
||||
|
|
@ -98,5 +99,9 @@ public class GameplaySettings
|
|||
public float HeatRadiationExponent = 1;
|
||||
public float HeatRadiationMultiplier = 1;
|
||||
public float HeatConductionMultiplier = 1;
|
||||
|
||||
public float HeatstrokeTemperature = 330;
|
||||
public float HeatstrokeMultiplier = .00001f;
|
||||
public float HeatstrokeExponent = 2;
|
||||
public float HeatstrokeRecoverySpeed = .2f;
|
||||
public float HeatstrokeControlLimit = .75f;
|
||||
}
|
||||
Loading…
Reference in a new issue