Active Cooling
Radiators now have a heat pump built into them
This commit is contained in:
parent
a71d01cb78
commit
ee0bba31b1
6 changed files with 70 additions and 30 deletions
BIN
Assets/Resources/Settings.asset
(Stored with Git LFS)
BIN
Assets/Resources/Settings.asset
(Stored with Git LFS)
Binary file not shown.
|
|
@ -41,7 +41,7 @@ public class EntityInstance : MonoBehaviour
|
|||
|
||||
public Dictionary<HardpointData, Transform[]> Barrels { get; private set; }
|
||||
public Dictionary<HardpointData, int> BarrelIndices { get; private set; }
|
||||
public Dictionary<HardpointData, MeshRenderer> RadiatorMeshes { get; private set; }
|
||||
public Dictionary<Radiator, MeshRenderer> RadiatorMeshes { get; private set; }
|
||||
public Transform LookAtPoint { get; private set; }
|
||||
public Entity Entity { get; private set; }
|
||||
public SectorRenderer SectorRenderer { get; private set; }
|
||||
|
|
@ -196,19 +196,23 @@ public class EntityInstance : MonoBehaviour
|
|||
}
|
||||
}
|
||||
}
|
||||
RadiatorMeshes = new Dictionary<HardpointData, MeshRenderer>();
|
||||
RadiatorMeshes = new Dictionary<Radiator, MeshRenderer>();
|
||||
Barrels = new Dictionary<HardpointData, Transform[]>();
|
||||
BarrelIndices = new Dictionary<HardpointData, int>();
|
||||
foreach (var hp in hullData.Hardpoints)
|
||||
foreach (var radiator in entity.GetBehaviors<Radiator>())
|
||||
{
|
||||
if (hp.Type == HardpointType.Radiator)
|
||||
var hp = Entity.Hardpoints[radiator.Item.Position.x, radiator.Item.Position.y];
|
||||
if (hp != null && hp.Type == HardpointType.Radiator)
|
||||
{
|
||||
var mesh = RadiatorHardpoints.FirstOrDefault(x => x.name == hp.Transform);
|
||||
if (mesh)
|
||||
{
|
||||
RadiatorMeshes.Add(hp, mesh.Mesh);
|
||||
RadiatorMeshes.Add(radiator, mesh.Mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var hp in hullData.Hardpoints)
|
||||
{
|
||||
if(hp.Type == HardpointType.Ballistic || hp.Type == HardpointType.Energy || hp.Type == HardpointType.Launcher)
|
||||
{
|
||||
var whp = WeaponHardpoints.FirstOrDefault(x => x.name == hp.Transform);
|
||||
|
|
@ -422,14 +426,7 @@ public class EntityInstance : MonoBehaviour
|
|||
|
||||
foreach (var x in RadiatorMeshes)
|
||||
{
|
||||
var temp = 0f;
|
||||
foreach (var v in x.Key.Shape.Coordinates)
|
||||
{
|
||||
var v2 = v + x.Key.Position;
|
||||
temp += Entity.Temperature[v2.x, v2.y];
|
||||
}
|
||||
temp /= x.Key.Shape.Coordinates.Length;
|
||||
x.Value.material.SetFloat("_Emission", Entity.ItemManager.GameplaySettings.TemperatureEmissionCurve.Evaluate(temp));
|
||||
x.Value.material.SetFloat("_Emission", Entity.ItemManager.GameplaySettings.TemperatureEmissionCurve.Evaluate(x.Key.Temperature));
|
||||
}
|
||||
|
||||
foreach (var x in Barrels)
|
||||
|
|
|
|||
|
|
@ -13,21 +13,37 @@ public class RadiatorData : BehaviorData
|
|||
[InspectableField, JsonProperty("emissivity"), Key(1), RuntimeInspectable]
|
||||
public PerformanceStat Emissivity = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("pumpedHeat"), Key(2), RuntimeInspectable]
|
||||
public PerformanceStat PumpedHeat = new PerformanceStat();
|
||||
|
||||
[TemperatureInspectable, JsonProperty("temperatureFloor"), Key(3), RuntimeInspectable]
|
||||
public float TemperatureFloor;
|
||||
|
||||
[InspectableField, JsonProperty("wasteHeat"), Key(4), RuntimeInspectable]
|
||||
public PerformanceStat WasteHeat = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("energyUsage"), Key(5), RuntimeInspectable]
|
||||
public PerformanceStat EnergyUsage = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new Radiator(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Radiator : IBehavior
|
||||
public class Radiator : IBehavior, IAlwaysUpdatedBehavior, IInitializableBehavior
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
public float Temperature { get; private set; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public float Emissivity;
|
||||
public float Emissivity { get; private set; }
|
||||
public float PumpedHeat { get; private set; }
|
||||
public float WasteHeat { get; private set; }
|
||||
public float EnergyUsage { get; private set; }
|
||||
|
||||
private RadiatorData _data;
|
||||
|
||||
|
|
@ -41,10 +57,40 @@ public class Radiator : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Emissivity = Context.Evaluate(_data.Emissivity, Item.EquippableItem, Entity);
|
||||
var rad = pow(Item.Temperature, Context.GameplaySettings.HeatRadiationExponent) * Context.GameplaySettings.HeatRadiationMultiplier * Emissivity;
|
||||
Item.AddHeat(-rad * delta);
|
||||
Entity.VisibilitySources[this] = rad;
|
||||
PumpedHeat = Context.Evaluate(_data.PumpedHeat, Item.EquippableItem, Entity);
|
||||
WasteHeat = Context.Evaluate(_data.WasteHeat, Item.EquippableItem, Entity);
|
||||
EnergyUsage = Context.Evaluate(_data.EnergyUsage, Item.EquippableItem, Entity);
|
||||
|
||||
var itemTemperature = Item.Temperature;
|
||||
var tempRatio = max(Temperature / itemTemperature, 1);
|
||||
|
||||
// Temperature ratio would cause more waste heat than pump capacity, stop executing
|
||||
if (tempRatio > PumpedHeat / WasteHeat) return true;
|
||||
|
||||
var pumpedHeat = PumpedHeat * max(itemTemperature - _data.TemperatureFloor, 0);
|
||||
|
||||
// Radiator temperature is below temperature floor, stop executing
|
||||
if (pumpedHeat < 0.01f) return true;
|
||||
|
||||
var wasteHeat = WasteHeat * tempRatio;
|
||||
Entity.Energy -= EnergyUsage * tempRatio * delta;
|
||||
|
||||
Item.AddHeat((wasteHeat - pumpedHeat) * delta);
|
||||
Temperature += pumpedHeat / Context.GetThermalMass(Item.EquippableItem) * delta;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
{
|
||||
Emissivity = Context.Evaluate(_data.Emissivity, Item.EquippableItem, Entity);
|
||||
var rad = pow(Temperature, Context.GameplaySettings.HeatRadiationExponent) * Context.GameplaySettings.HeatRadiationMultiplier * Emissivity;
|
||||
Temperature -= rad * delta;
|
||||
Entity.VisibilitySources[this] = rad;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
Temperature = Item.Temperature;
|
||||
}
|
||||
}
|
||||
|
|
@ -719,13 +719,10 @@ public abstract class Entity
|
|||
// For all cells on the border of the entity, radiate some heat into space, increasing the visibility of the ship
|
||||
if (Parent==null && !hullData.InteriorCells[v])
|
||||
{
|
||||
// for(int i = 0; i<4; i++)
|
||||
// {
|
||||
var rad = pow(NewTemperature[v.x, v.y], ItemManager.GameplaySettings.HeatRadiationExponent) *
|
||||
ItemManager.GameplaySettings.HeatRadiationMultiplier;
|
||||
NewTemperature[v.x, v.y] -= rad * delta / 4;
|
||||
r += rad;
|
||||
// }
|
||||
var rad = pow(NewTemperature[v.x, v.y], ItemManager.GameplaySettings.HeatRadiationExponent) *
|
||||
ItemManager.GameplaySettings.HeatRadiationMultiplier;
|
||||
NewTemperature[v.x, v.y] -= rad * delta;
|
||||
r += rad;
|
||||
}
|
||||
|
||||
radiation += r;
|
||||
|
|
|
|||
|
|
@ -211,11 +211,11 @@ public class SchematicDisplay : MonoBehaviour
|
|||
{
|
||||
|
||||
if (_radiators.Length == 1)
|
||||
RadiatorTemperatureLabel.text = $"{((int)(_radiators[0].Item.Temperature - 273.15f)).ToString()}°C";
|
||||
RadiatorTemperatureLabel.text = $"{((int)(_radiators[0].Temperature - 273.15f)).ToString()}°C";
|
||||
else if (_radiators.Length > 1)
|
||||
RadiatorTemperatureLabel.text =
|
||||
$"{((int)(_radiators.Min(r => r.Item.Temperature) - 273.15f)).ToString()}-" +
|
||||
$"{((int)(_radiators.Max(r => r.Item.Temperature) - 273.15f)).ToString()}°C";
|
||||
$"{((int)(_radiators.Min(r => r.Temperature) - 273.15f)).ToString()}-" +
|
||||
$"{((int)(_radiators.Max(r => r.Temperature) - 273.15f)).ToString()}°C";
|
||||
|
||||
if (_heatsinks.Length == 1)
|
||||
HeatsinkTemperatureLabel.text = $"{((int)(_heatsinks[0].Item.Temperature - 273.15f)).ToString()}°C";
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in a new issue