From ee0bba31b15392ae7ad11753e027d05c3fc9c3f6 Mon Sep 17 00:00:00 2001 From: Reinier Vens Date: Mon, 1 Mar 2021 01:53:56 +0000 Subject: [PATCH] Active Cooling Radiators now have a heat pump built into them --- Assets/Resources/Settings.asset | 4 +- Assets/Scripts/Gameplay/EntityInstance.cs | 23 +++---- .../ServerShared/Behaviors/Radiator.cs | 58 ++++++++++++++++-- Assets/Scripts/ServerShared/Entity.cs | 11 ++-- Assets/Scripts/UI/SchematicDisplay.cs | 6 +- GameData/Loadouts/Djinni.preset | Bin 7259 -> 7259 bytes 6 files changed, 71 insertions(+), 31 deletions(-) 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 39a79f45d4e4e98fbd5de3c1038fef4aad899739..8698bc17ab2fff490ee95a5da4ce39b167303c81 100644 GIT binary patch delta 891 zcmZXRTSydP6vy42nO#?RcP_g*yEBV7kU~~mrE*nvR+B6ZydYg9qN0Mp9xRGV7P6iy zUuO4jrbQxU5Oz^9=s^wJ?IEm(p0+@uheX5&TazTZZQsnAS;5Dd^Z%dU`OcY{8UKu5 z&8Aj{4u$g?Qje1G9f_)&cZH`KXeCGBAQ&2H`$aCb*?3 zp^F|O0`Ja^5Ya;Iu2gk%8$*bzJ|7-2TLH#J(c52>yn)W0d)|j;v&dAm_|pJ`%|)Hc z*@GopF&#W3c9TRzrM(@q8OQL&A~1^Bnx4W+hvrh)#`e%Zn1eoGU(hHr^z)M`QY|r> z{r^E($)l;O+Hx=HR|VQetJYCx8KrvsMFdNxEG%U1z+@(w?~Bj>c3Np=d5qROgQu?z zt#x{>WbXLg0b=;5A3OgH)(aONYYUOrJKs^b+7hKc81F?`^5a73n<8u(uCU}YZ;3Br zkljTq@e{|f%s#_@=VtUfZ3qf19ynMy_a zTe-C9ny%zWEzD}+Cz?44^PC66Tt=$6qWLei@DP)NmrP*LCy2JLJT3C12 zW!?sbEHUC_P|ve?FYpLCd_^c8i~fp!F|a~Yc^)2Vp7*k zaB`6)s-qfRD;FAKI4PHsI4GCmmYlveC?T8iRb~;A1!Q|Rz~`}|+~YP)sbN)Be*td* BQC|Q6 delta 962 zcmZWmT}V@57~Xciv+3MAXJ@OkvyIe}{9(2!=1=C1xmckwXQ5573yE&Tz%EK5iLRnZ zXxkH#6c#4k1d`T8V1{kdg;da8VnG*mV-RXLA~XBWH-FOL@SN}Yd(ZoE=BwwcWBWP# zrN{C7aOPDOf8yc_zxw0TVWKuqjzH2k6E!ruj7~!hhV?R0txFY*ENdiK^^}p2fs)41 z3MDOE&FfJn{?bHi$3sevBFM?y@w_+8802J9cdox4<6MLUVtG9nC$*?2H12EdU}R7u zPR{{K&T{r2T}*7?so2$>#u#4-@J{a3`6xYyNpWG@5L!$!ubzH42I#Far{=a|(OSk` z=NqtOl~KE=2j9&Xv63zE0q2M3EJcnjOx~cjj|8r~iu|AZ68V8ysSSb_GZWCa)MYHa#ug?Z4P;)O-M;2nX{M-SZem1xPI?Z0wAkBi* zK-_T%i;@v(o5i&&`9}*e_>6qJ9X~|{cO^4cMYEBON@Gg$Y71dVlCdV5w&lj1!v=J$ z!1mLIRf^o!R++D&MJ!-T*W1i^L~qn?^TF>hZ{9M;pcPn)gJ3IWp6c-6rC34F5+Y*t zi#f-8!X*2V8W_f&<4