diff --git a/Assets/Resources/Settings.asset b/Assets/Resources/Settings.asset index b41778774..e1b23fafe 100644 --- a/Assets/Resources/Settings.asset +++ b/Assets/Resources/Settings.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:654b727404adc4c8916f68efad8c103c05209f29f84ef103ad740636f5d04099 -size 7640 +oid sha256:203a866610401607644a06056190ce969e9914e852f09d6b2bbe70e11c6262d6 +size 7648 diff --git a/Assets/Scripts/Gameplay/EntityInstance.cs b/Assets/Scripts/Gameplay/EntityInstance.cs index ce6f83026..81b2db921 100644 --- a/Assets/Scripts/Gameplay/EntityInstance.cs +++ b/Assets/Scripts/Gameplay/EntityInstance.cs @@ -41,7 +41,7 @@ public class EntityInstance : MonoBehaviour public Dictionary Barrels { get; private set; } public Dictionary BarrelIndices { get; private set; } - public Dictionary RadiatorMeshes { get; private set; } + public Dictionary 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(); + RadiatorMeshes = new Dictionary(); Barrels = new Dictionary(); BarrelIndices = new Dictionary(); - foreach (var hp in hullData.Hardpoints) + foreach (var radiator in entity.GetBehaviors()) { - 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) diff --git a/Assets/Scripts/ServerShared/Behaviors/Radiator.cs b/Assets/Scripts/ServerShared/Behaviors/Radiator.cs index 922daf66b..f741f22f4 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Radiator.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Radiator.cs @@ -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; + } } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index e4d170403..8dd67833a 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -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; diff --git a/Assets/Scripts/UI/SchematicDisplay.cs b/Assets/Scripts/UI/SchematicDisplay.cs index 54df732cf..725fa5174 100644 --- a/Assets/Scripts/UI/SchematicDisplay.cs +++ b/Assets/Scripts/UI/SchematicDisplay.cs @@ -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"; diff --git a/GameData/Loadouts/Djinni.preset b/GameData/Loadouts/Djinni.preset index 39a79f45d..8698bc17a 100644 Binary files a/GameData/Loadouts/Djinni.preset and b/GameData/Loadouts/Djinni.preset differ