Entity Properties & Thermal Regulation
Entities such as colonies and ships can now be clicked on to reveal their properties or context menus Orbital Colony loadout now has a new item (thermostatic heater) which itself has a new behavior type (Thermotoggle) allowing it to regulate its temperature for more agreeable living conditions Fixed stat modifiers for hull stats (e.g. Hull Expansion) Widened property label in DB inspector
This commit is contained in:
parent
110ff883b8
commit
698263ce63
15 changed files with 143 additions and 33 deletions
|
|
@ -87,6 +87,8 @@ public abstract class PersistentBehaviorData
|
|||
Union(20, typeof(SwitchData)),
|
||||
Union(21, typeof(TriggerData)),
|
||||
Union(22, typeof(VisibilityData)),
|
||||
Union(23, typeof(ThermotoggleData)),
|
||||
Union(24, typeof(EnergyDrawData)),
|
||||
JsonConverter(typeof(JsonKnownTypesConverter<BehaviorData>)), JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class BehaviorData
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ public class Radiator : IBehavior
|
|||
public GameContext Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public float Emissivity;
|
||||
|
||||
private RadiatorData _data;
|
||||
|
||||
|
|
@ -35,7 +37,8 @@ public class Radiator : IBehavior
|
|||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
var rad = pow(Entity.Temperature, Context.GlobalData.HeatRadiationPower) * Context.GlobalData.HeatRadiationMultiplier;
|
||||
Emissivity = Context.Evaluate(_data.Emissivity, Item, Entity);
|
||||
var rad = pow(Entity.Temperature, Context.GlobalData.HeatRadiationPower) * Context.GlobalData.HeatRadiationMultiplier * Emissivity;
|
||||
Entity.Temperature -= rad * delta;
|
||||
Entity.VisibilitySources[this] = rad;
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ public class Reactor : IBehavior
|
|||
public GameContext Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
public float Capacitance;
|
||||
|
||||
public Reactor(GameContext context, ReactorData data, Entity entity, Gear item)
|
||||
{
|
||||
|
|
@ -45,17 +46,17 @@ public class Reactor : IBehavior
|
|||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
var cap = Context.Evaluate(_data.Capacitance, Item, Entity);
|
||||
Capacitance = Context.Evaluate(_data.Capacitance, Item, Entity);
|
||||
var charge = Context.Evaluate(_data.Charge, Item, Entity) * delta;
|
||||
var efficiency = Context.Evaluate(_data.Efficiency, Item, Entity);
|
||||
|
||||
Entity.AddHeat(charge / efficiency);
|
||||
Entity.Energy += charge;
|
||||
|
||||
if (Entity.Energy > cap)
|
||||
if (Entity.Energy > Capacitance)
|
||||
{
|
||||
Entity.AddHeat(-(Entity.Energy - cap) / efficiency * (1 - 1 / Context.Evaluate(_data.UnderloadRecovery, Item, Entity)));
|
||||
Entity.Energy = cap;
|
||||
Entity.AddHeat(-(Entity.Energy - Capacitance) / efficiency * (1 - 1 / Context.Evaluate(_data.UnderloadRecovery, Item, Entity)));
|
||||
Entity.Energy = Capacitance;
|
||||
}
|
||||
|
||||
if (Entity.Energy < 0)
|
||||
|
|
|
|||
|
|
@ -54,14 +54,14 @@ public class StatModifier : IBehavior, IInitializableBehavior, IDisposableBehavi
|
|||
if (statField != null)
|
||||
{
|
||||
if (typeof(EquippableItemData).IsAssignableFrom(targetType))
|
||||
_stats = Entity.EquippedItems
|
||||
_stats = Entity.EquippedItems.Append(Entity.Hull)
|
||||
.Select(id => Context.Cache.Get<Gear>(id))
|
||||
.Where(gear => _data.RequireBehavior == null || gear.ItemData.Behaviors.Any(behavior => behavior.GetType() == _data.RequireBehavior))
|
||||
.Where(gear => gear.ItemData.GetType() == targetType)
|
||||
.Select(gear => statField.GetValue(gear.ItemData) as PerformanceStat)
|
||||
.ToArray();
|
||||
else
|
||||
_stats = Entity.EquippedItems
|
||||
_stats = Entity.EquippedItems.Append(Entity.Hull)
|
||||
.Select(id => Context.Cache.Get<Gear>(id))
|
||||
.Where(gear => _data.RequireBehavior == null || gear.ItemData.Behaviors.Any(behavior => behavior.GetType() == _data.RequireBehavior))
|
||||
.SelectMany(gear => gear.ItemData.Behaviors)
|
||||
|
|
|
|||
43
Assets/Scripts/ServerShared/Behaviors/Thermotoggle.cs
Normal file
43
Assets/Scripts/ServerShared/Behaviors/Thermotoggle.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-22)]
|
||||
public class ThermotoggleData : BehaviorData
|
||||
{
|
||||
[TemperatureInspectable, JsonProperty("targetTemp"), Key(1)]
|
||||
public float TargetTemperature;
|
||||
|
||||
[InspectableField, JsonProperty("perSecond"), Key(2)]
|
||||
public bool HighPass;
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
{
|
||||
return new Thermotoggle(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Thermotoggle : IBehavior
|
||||
{
|
||||
private ThermotoggleData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private Gear Item { get; }
|
||||
private GameContext Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public Thermotoggle(GameContext context, ThermotoggleData data, Entity entity, Gear item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return Entity.Temperature < _data.TargetTemperature ^ _data.HighPass;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Behaviors/Thermotoggle.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Behaviors/Thermotoggle.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8e461bdbde38ffb4486490d7998d62af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -42,6 +42,7 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
private Dictionary<Gear, List<IBehavior>> ItemBehaviors;
|
||||
|
||||
[IgnoreMember] public float Mass { get; private set; }
|
||||
[IgnoreMember] public float OccupiedCapacity { get; private set; }
|
||||
[IgnoreMember] public float SpecificHeat { get; private set; }
|
||||
[IgnoreMember] public float Visibility => VisibilitySources.Values.Sum();
|
||||
|
||||
|
|
@ -128,6 +129,9 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
EquippedItems.Select(i => Context.Cache.Get<Gear>(i)).Sum(i => i.HeatCapacity) +
|
||||
Cargo.Select(i => Context.Cache.Get<ItemInstance>(i)).Sum(ii => ii.HeatCapacity) +
|
||||
Children.Select(i => Context.Cache.Get<Entity>(i)).Sum(c=>c.SpecificHeat);
|
||||
|
||||
OccupiedCapacity = EquippedItems.Select(i => Context.Cache.Get<Gear>(i)).Sum(i => i.ItemData.Size) +
|
||||
Cargo.Select(i => Context.Cache.Get<ItemInstance>(i)).Sum(ii => Context.GetSize(ii));
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetBehaviors<T>() where T : class, IBehavior
|
||||
|
|
@ -165,7 +169,14 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
|
||||
public void AddHeat(float heat)
|
||||
{
|
||||
Temperature += heat / SpecificHeat;
|
||||
if (Parent != Guid.Empty)
|
||||
{
|
||||
var parent = Context.Cache.Get<Entity>(Parent);
|
||||
parent.AddHeat(heat);
|
||||
}
|
||||
else
|
||||
Temperature += heat / SpecificHeat;
|
||||
|
||||
}
|
||||
|
||||
public virtual void Update(float delta)
|
||||
|
|
@ -189,6 +200,7 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
var parent = Context.Cache.Get<Entity>(Parent);
|
||||
Position = parent.Position;
|
||||
Velocity = parent.Velocity;
|
||||
Temperature = parent.Temperature;
|
||||
}
|
||||
|
||||
// Processing stale item data properly was a pain in my ass, so the shortcut is just persisting and restoring everything
|
||||
|
|
|
|||
|
|
@ -405,6 +405,20 @@ public class GameContext
|
|||
return 0;
|
||||
}
|
||||
|
||||
public float GetSize(ItemInstance item)
|
||||
{
|
||||
var data = GetData(item);
|
||||
switch (item)
|
||||
{
|
||||
case CraftedItemInstance _:
|
||||
return data.Size;
|
||||
case SimpleCommodity commodity:
|
||||
return data.Size * commodity.Quantity;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float GetHeatCapacity(ItemInstance item)
|
||||
{
|
||||
var data = GetData(item);
|
||||
|
|
@ -659,7 +673,8 @@ public class GameContext
|
|||
var entity = new OrbitalEntity(this, hull.ID, gear.Select(g => g.ID),
|
||||
cargo.Select(c => c.ID).Concat(simpleCargo.Select(c => c.ID)), orbit.ID, zone)
|
||||
{
|
||||
Name = $"{loadoutData.Name} {Random.NextInt(1,255):X}"
|
||||
Name = $"{loadoutData.Name} {Random.NextInt(1,255):X}",
|
||||
Temperature = 293
|
||||
};
|
||||
Cache.Add(entity);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue