/// <summary> /// Processes thermal regulation for a mob /// </summary> private void ProcessThermalRegulation(EntityUid uid, ThermalRegulatorComponent comp) { if (!EntityManager.TryGetComponent(uid, out TemperatureComponent? temperatureComponent)) { return; } var totalMetabolismTempChange = comp.MetabolismHeat - comp.RadiatedHeat; // implicit heat regulation var tempDiff = Math.Abs(temperatureComponent.CurrentTemperature - comp.NormalBodyTemperature); var targetHeat = tempDiff * temperatureComponent.HeatCapacity; if (temperatureComponent.CurrentTemperature > comp.NormalBodyTemperature) { totalMetabolismTempChange -= Math.Min(targetHeat, comp.ImplicitHeatRegulation); } else { totalMetabolismTempChange += Math.Min(targetHeat, comp.ImplicitHeatRegulation); } _tempSys.ChangeHeat(uid, totalMetabolismTempChange, true, temperatureComponent); // recalc difference and target heat tempDiff = Math.Abs(temperatureComponent.CurrentTemperature - comp.NormalBodyTemperature); targetHeat = tempDiff * temperatureComponent.HeatCapacity; // if body temperature is not within comfortable, thermal regulation // processes starts if (tempDiff > comp.ThermalRegulationTemperatureThreshold) { return; } if (temperatureComponent.CurrentTemperature > comp.NormalBodyTemperature) { if (!_actionBlockerSys.CanSweat(uid)) { return; } _tempSys.ChangeHeat(uid, -Math.Min(targetHeat, comp.SweatHeatRegulation), true, temperatureComponent); } else { if (!_actionBlockerSys.CanShiver(uid)) { return; } _tempSys.ChangeHeat(uid, Math.Min(targetHeat, comp.ShiveringHeatRegulation), true, temperatureComponent); } }
/// <summary> /// Process thermal regulation /// </summary> /// <param name="frameTime"></param> private void ProcessThermalRegulation(float frameTime) { if (!Owner.TryGetComponent(out TemperatureComponent temperatureComponent)) { return; } temperatureComponent.ReceiveHeat(MetabolismHeat); temperatureComponent.RemoveHeat(RadiatedHeat); // implicit heat regulation var tempDiff = Math.Abs(temperatureComponent.CurrentTemperature - NormalBodyTemperature); var targetHeat = tempDiff * temperatureComponent.HeatCapacity; if (temperatureComponent.CurrentTemperature > NormalBodyTemperature) { temperatureComponent.RemoveHeat(Math.Min(targetHeat, ImplicitHeatRegulation)); } else { temperatureComponent.ReceiveHeat(Math.Min(targetHeat, ImplicitHeatRegulation)); } // recalc difference and target heat tempDiff = Math.Abs(temperatureComponent.CurrentTemperature - NormalBodyTemperature); targetHeat = tempDiff * temperatureComponent.HeatCapacity; // if body temperature is not within comfortable, thermal regulation // processes starts if (tempDiff < ThermalRegulationTemperatureThreshold) { if (_isShivering || _isSweating) { Owner.PopupMessage(Loc.GetString("You feel comfortable")); } _isShivering = false; _isSweating = false; return; } if (temperatureComponent.CurrentTemperature > NormalBodyTemperature) { if (!ActionBlockerSystem.CanSweat(Owner)) { return; } if (!_isSweating) { Owner.PopupMessage(Loc.GetString("You are sweating")); _isSweating = true; } // creadth: sweating does not help in airless environment if (Owner.Transform.Coordinates.TryGetTileAir(out _, _entityManager)) { temperatureComponent.RemoveHeat(Math.Min(targetHeat, SweatHeatRegulation)); } } else { if (!ActionBlockerSystem.CanShiver(Owner)) { return; } if (!_isShivering) { Owner.PopupMessage(Loc.GetString("You are shivering")); _isShivering = true; } temperatureComponent.ReceiveHeat(Math.Min(targetHeat, ShiveringHeatRegulation)); } }