Thermal Performance Threshold & Thermal Override

Items will switch themselves off below a customizable threshold to avoid damage
Player can toggle thermal override to disable safety shutdown
Selecting an item allows player to select whether the item will override
Clicking on the background of an inventory panel will display general ship settings (including thermal shutdown threshold)
Performance Stat evaluation has been moved to EquippedItem, slight performance improvement
Item online and active status are now reactive properties
Created player settings file to store e.g. shutdown threshold
Fixed crash when entering wormhole while enemies are visible
This commit is contained in:
Reinier Vens 2021-03-07 01:10:31 +00:00
commit 1092159063
66 changed files with 756 additions and 206 deletions

View file

@ -22,6 +22,7 @@ public abstract class Entity
{
public Zone Zone;
public MegaCorporation Faction;
public PlayerSettings PlayerSettings;
public EquippableItem Hull;
public float3 Position;
@ -82,10 +83,12 @@ public abstract class Entity
if (value == _heatsinksEnabled) return;
_heatsinksEnabled = value;
foreach (var heatsink in _heatsinks)
heatsink.Item.Enabled = value;
heatsink.Item.Enabled.Value = value;
}
}
public bool OverrideShutdown { get; set; }
public bool Active
{
get => _active;
@ -110,8 +113,8 @@ public abstract class Entity
public Subject<(int2 pos, float damage)> ArmorDamage = new Subject<(int2, float)>();
public Subject<(EquippedItem item, float damage)> ItemDamage = new Subject<(EquippedItem, float)>();
public Subject<EquippedItem> ItemOffline = new Subject<EquippedItem>();
public Subject<EquippedItem> ItemOnline = new Subject<EquippedItem>();
// public Subject<EquippedItem> ItemOffline = new Subject<EquippedItem>();
// public Subject<EquippedItem> ItemOnline = new Subject<EquippedItem>();
public Subject<float> HullDamage = new Subject<float>();
public Subject<Entity> Docked = new Subject<Entity>();
public Subject<Unit> HeatstrokeRisk = new Subject<Unit>();
@ -543,8 +546,8 @@ public abstract class Entity
Cockpit = cockpit;
}
equippedItem.OnOnline += () => ItemOnline.OnNext(equippedItem);
equippedItem.OnOffline += () => ItemOffline.OnNext(equippedItem);
// equippedItem.OnOnline += () => ItemOnline.OnNext(equippedItem);
// equippedItem.OnOffline += () => ItemOffline.OnNext(equippedItem);
foreach (var i in itemData.Shape.Coordinates)
{
@ -597,7 +600,7 @@ public abstract class Entity
public bool CanConsumeEnergy(float energy)
{
var capEnergy = _capacitors.Sum(cap => cap.Charge);
int onlineReactors = _reactors.Count(reactor=>reactor.Item.Online);
int onlineReactors = _reactors.Count(reactor=>reactor.Item.Online.Value);
return capEnergy > energy || onlineReactors > 0;
}
@ -622,10 +625,10 @@ public abstract class Entity
if (energy < .01f) return true;
int onlineReactors = _reactors.Count(reactor=>reactor.Item.Online);
int onlineReactors = _reactors.Count(reactor=>reactor.Item.Online.Value);
foreach (var reactor in _reactors)
{
if (reactor.Item.Online)
if (reactor.Item.Online.Value)
{
reactor.ConsumeEnergy(energy / onlineReactors);
}
@ -877,67 +880,66 @@ public abstract class Entity
public class EquippedItem
{
public int SortPosition;
public EquippableItem EquippableItem;
public int2 Position;
public IBehavior[] Behaviors;
public Dictionary<int, BehaviorGroup> BehaviorGroups;
public bool Enabled = true;
public event Action OnOffline;
public event Action OnOnline;
private bool _thermalOnline;
private bool _durabilityOnline;
public IBehavior[] Behaviors { get; }
public float Conductivity { get; }
public float ThermalPerformance { get; private set; }
public float ThermalExponent { get; }
public float DurabilityPerformance { get; private set; }
public float DurabilityExponent { get; }
public float Wear { get; private set; }
public Shape InsetShape { get; }
public Entity Entity { get; }
public EquippableItemData Data { get; }
public int SortPosition;
public bool Active
{
get => _online && Enabled;
}
public ReactiveProperty<bool> ThermalOnline { get; } = new ReactiveProperty<bool>(false);
public ReactiveProperty<bool> DurabilityOnline { get; } = new ReactiveProperty<bool>(false);
public ReadOnlyReactiveProperty<bool> Online { get; }
public ReactiveProperty<bool> Enabled { get; } = new ReactiveProperty<bool>(true);
public ReadOnlyReactiveProperty<bool> Active { get; }
public bool Online
{
get => _online;
}
public float Temperature
{
get
{
float sum = 0;
foreach (var x in InsetShape.Coordinates) sum += _entity.Temperature[x.x, x.y];
foreach (var x in InsetShape.Coordinates) sum += Entity.Temperature[x.x, x.y];
return sum/InsetShape.Coordinates.Length;
}
}
public Entity Entity
{
get => _entity;
}
protected readonly ItemManager _itemManager;
private readonly EquippableItemData _data;
private Entity _entity;
private bool _online;
//private bool _online;
public EquippedItem(ItemManager itemManager, EquippableItem item, int2 position, Entity entity)
{
_itemManager = itemManager;
_data = _itemManager.GetData(item);
_entity = entity;
Data = _itemManager.GetData(item);
Entity = entity;
EquippableItem = item;
Position = position;
Conductivity = _data.Conductivity;
Conductivity = Data.Conductivity;
ThermalExponent = _itemManager.Evaluate(Data.HeatExponent, EquippableItem);
DurabilityExponent = _itemManager.Evaluate(Data.DurabilityExponent, EquippableItem);
var hullData = itemManager.GetData(entity.Hull);
InsetShape = hullData.Shape.Inset(_data.Shape, position, item.Rotation);
InsetShape = hullData.Shape.Inset(Data.Shape, position, item.Rotation);
Behaviors = _data.Behaviors
Online = new ReadOnlyReactiveProperty<bool>(ThermalOnline
.CombineLatest(DurabilityOnline, (thermal, durability) => thermal && durability).DistinctUntilChanged());
Active = new ReadOnlyReactiveProperty<bool>(Enabled
.CombineLatest(Online, (enabled, online) => enabled && online).DistinctUntilChanged());
Behaviors = Data.Behaviors
.Select(bd => bd.CreateInstance(itemManager, entity, this))
.ToArray();
@ -946,9 +948,7 @@ public class EquippedItem
.OrderBy(g => g.Key)
.ToDictionary(g => g.Key, g => new BehaviorGroup
{
Behaviors = g.ToArray(),
// Switch = (Switch) g.FirstOrDefault(b => b is Switch),
// Trigger = (Trigger) g.FirstOrDefault(b => b is Trigger)
Behaviors = g.ToArray()
});
foreach (var behavior in Behaviors)
@ -960,10 +960,32 @@ public class EquippedItem
}
}
public float Evaluate(PerformanceStat stat)
{
var heat = 1f;
if(stat.HeatDependent)
heat = pow(ThermalPerformance, ThermalExponent * stat.HeatExponentMultiplier);
var durability = 1f;
if(stat.DurabilityDependent)
durability = pow(DurabilityPerformance, DurabilityExponent);
var quality = pow(_itemManager.Quality(stat, EquippableItem), stat.QualityExponent);
var scaleModifier = 1.0f;
foreach (var value in stat.GetScaleModifiers(Entity).Values) scaleModifier = scaleModifier * value;
float constantModifier = 0;
foreach (var value in stat.GetConstantModifiers(Entity).Values) constantModifier += value;
var result = lerp(stat.Min, stat.Max, durability * quality * heat) * scaleModifier + constantModifier;
if (float.IsNaN(result))
return stat.Min;
return result;
}
public void AddHeat(float heat, bool ignoreThermalMass = false)
{
foreach(var hullCoord in InsetShape.Coordinates)
_entity.AddHeat(hullCoord, heat / InsetShape.Coordinates.Length, ignoreThermalMass);
Entity.AddHeat(hullCoord, heat / InsetShape.Coordinates.Length, ignoreThermalMass);
}
public void Update(float delta)
@ -971,13 +993,18 @@ public class EquippedItem
foreach (var behavior in Behaviors)
if(behavior is IAlwaysUpdatedBehavior alwaysUpdatedBehavior) alwaysUpdatedBehavior.Update(delta);
var previouslyOnline = _online;
_online = EquippableItem.Durability > .01f && Temperature > _data.MinimumTemperature && Temperature < _data.MaximumTemperature;
var temp = Temperature;
ThermalPerformance = Data.Performance(temp);
DurabilityPerformance = EquippableItem.Durability / Data.Durability;
var performanceThreshold = Entity.PlayerSettings?.ShutdownPerformance ?? _itemManager.GameplaySettings.DefaultShutdownPerformance;
Wear = (1 - pow(Data.Performance(temp),
(1 - pow(_itemManager.CompoundQuality(EquippableItem), _itemManager.GameplaySettings.QualityWearExponent)) *
_itemManager.GameplaySettings.ThermalWearExponent)
) * Data.Durability / Data.ThermalResilience;
ThermalOnline.Value = ThermalPerformance > performanceThreshold || Entity.OverrideShutdown && EquippableItem.OverrideShutdown;
DurabilityOnline.Value = EquippableItem.Durability > .01f;
if (!previouslyOnline && _online) OnOnline?.Invoke();
if (previouslyOnline && !_online) OnOffline?.Invoke();
if (Active)
if (Active.Value)
{
foreach (var group in BehaviorGroups.Values)
{