Restore daemon cockpit thermal medicine
This commit is contained in:
parent
7fdfdff99a
commit
b50c8a9053
12 changed files with 361 additions and 11 deletions
|
|
@ -670,6 +670,13 @@ namespace GameCult.Aetheria.State.Verse
|
|||
var maximumWear = equipmentStates.Where(value => value != null)
|
||||
.Select(value => value.Wear).DefaultIfEmpty(0).Max();
|
||||
var offlineEquipmentCount = equipmentStates.Count(value => value != null && !value.Online);
|
||||
var cockpitTemperature = EntityStat(entity, "cockpit-temperature");
|
||||
var thermalRiskThreshold = simulationSettings.SevereThermalRiskThreshold;
|
||||
var heatstrokePostWeight = thermalRiskThreshold <= 0 ? 1 :
|
||||
Math.Max(0, Math.Min(1, entity.Heatstroke / thermalRiskThreshold));
|
||||
var severeHeatstrokeWeight = thermalRiskThreshold >= 1 ? 0 :
|
||||
Math.Max(0, Math.Min(1,
|
||||
(entity.Heatstroke - thermalRiskThreshold) / (1 - thermalRiskThreshold)));
|
||||
var weaponCooldown = (entity.WeaponStates ?? Array.Empty<AetheriaRuntimeWeaponStateCommit>())
|
||||
.Select(state => state?.CooldownProgress ?? 0)
|
||||
.DefaultIfEmpty(0)
|
||||
|
|
@ -715,8 +722,14 @@ namespace GameCult.Aetheria.State.Verse
|
|||
["minimumTemperature"] = FormatNumber(minimumTemperature),
|
||||
["maximumTemperature"] = FormatNumber(maximumTemperature),
|
||||
["thermalVisibility"] = FormatNumber(thermalVisibility),
|
||||
["cockpitTemperature"] = FormatNumber(cockpitTemperature),
|
||||
["heatstroke"] = FormatRatio(entity.Heatstroke, 1),
|
||||
["hypothermia"] = FormatRatio(entity.Hypothermia, 1),
|
||||
["heatstrokeRisk"] = entity.Heatstroke > thermalRiskThreshold ? "true" : "false",
|
||||
["hypothermiaRisk"] = entity.Hypothermia > thermalRiskThreshold ? "true" : "false",
|
||||
["heatstrokePostWeight"] = FormatNumber(heatstrokePostWeight),
|
||||
["severeHeatstrokeWeight"] = FormatNumber(severeHeatstrokeWeight),
|
||||
["causeOfDeath"] = entity.CauseOfDeath ?? "",
|
||||
["visibility"] = FormatNumber(entity.Visibility),
|
||||
["targetEntityId"] = targetEntityId,
|
||||
["targetedByPlayer"] = player != null && player.TargetEntityIndex == entity.EntityIndex ? "true" : "false",
|
||||
|
|
|
|||
|
|
@ -376,6 +376,12 @@ namespace GameCult.Aetheria.State.Verse
|
|||
AetheriaRuntimeEnergySimulation.StepRadiators(entity, catalog, deltaSeconds);
|
||||
AetheriaRuntimeEnergySimulation.SettleReactors(entity, catalog, deltaSeconds);
|
||||
AetheriaRuntimeThermalSimulation.Step(entity, deltaSeconds, catalog);
|
||||
var medical = AetheriaRuntimeThermalMedicalSimulation.Step(
|
||||
entity, catalog, deltaSeconds, settings);
|
||||
PublishThermalMedicalEvents(run, zone, entity, medical, frameId);
|
||||
if (medical.Died)
|
||||
CommitDestruction(run, zone, entity, -1,
|
||||
$"thermal:{medical.DeathCause}", "", frameId, settings, medical.DeathCause);
|
||||
entity.IsActive = IsAlive(entity);
|
||||
if (!entity.IsActive)
|
||||
{
|
||||
|
|
@ -450,6 +456,29 @@ namespace GameCult.Aetheria.State.Verse
|
|||
}
|
||||
}
|
||||
|
||||
private static void PublishThermalMedicalEvents(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeZoneSnapshotCommit zone,
|
||||
AetheriaRuntimeEntitySnapshotCommit entity,
|
||||
AetheriaRuntimeThermalMedicalResult result,
|
||||
long frameId)
|
||||
{
|
||||
void Append(string kind, double exposure)
|
||||
{
|
||||
AetheriaRuntimeGameEvents.Append(run, new AetheriaRuntimeGameEventCommit
|
||||
{
|
||||
EventId = $"frame:{frameId}:zone:{zone.ZoneIndex}:entity:{entity.EntityIndex}:{kind}",
|
||||
Kind = kind, FrameId = frameId, ZoneIndex = zone.ZoneIndex,
|
||||
TargetEntityIndex = entity.EntityIndex, SubjectKey = entity.EntityId,
|
||||
ScalarValue = exposure, AuxiliaryValue = result.CockpitTemperature,
|
||||
PositionX = entity.PositionX, PositionZ = entity.PositionZ
|
||||
});
|
||||
}
|
||||
|
||||
if (result.HeatstrokeRiskCrossed) Append("pilot.heatstroke.risk", entity.Heatstroke);
|
||||
if (result.HypothermiaRiskCrossed) Append("pilot.hypothermia.risk", entity.Hypothermia);
|
||||
}
|
||||
|
||||
private static void ResolveDeployableDetonations(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeZoneSnapshotCommit zone,
|
||||
|
|
@ -1236,13 +1265,15 @@ namespace GameCult.Aetheria.State.Verse
|
|||
string subjectKey,
|
||||
string weaponItemKey,
|
||||
long frameId,
|
||||
AetheriaRuntimeDaemonSimulationSettings settings)
|
||||
AetheriaRuntimeDaemonSimulationSettings settings,
|
||||
string causeOfDeath = "hull-destroyed")
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(target.DestructionId)) return;
|
||||
|
||||
var destructionId = $"destruction:{run.RunId}:{zone.ZoneIndex}:{target.EntityIndex}:{frameId}";
|
||||
target.DestructionId = destructionId;
|
||||
target.DestroyedFrameId = frameId;
|
||||
target.CauseOfDeath = causeOfDeath ?? "";
|
||||
target.IsActive = false;
|
||||
target.TargetEntityIndex = -1;
|
||||
target.TractorPower = 0;
|
||||
|
|
@ -1332,7 +1363,8 @@ namespace GameCult.Aetheria.State.Verse
|
|||
EventId = destructionId, Kind = "entity.destroyed", FrameId = frameId,
|
||||
ZoneIndex = zone.ZoneIndex, SourceEntityIndex = sourceEntityIndex,
|
||||
TargetEntityIndex = target.EntityIndex, SubjectKey = subjectKey,
|
||||
ItemKey = weaponItemKey, PositionX = target.PositionX, PositionZ = target.PositionZ
|
||||
ItemKey = weaponItemKey, Reason = target.CauseOfDeath,
|
||||
PositionX = target.PositionX, PositionZ = target.PositionZ
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,16 @@ namespace GameCult.Aetheria.State.Verse
|
|||
weaponLockDecayPerSecond: 1.0,
|
||||
lootDropProbability: 0.25,
|
||||
lootDropVelocity: 25.0,
|
||||
pickupLifetimeSeconds: 30.0);
|
||||
pickupLifetimeSeconds: 30.0,
|
||||
severeThermalRiskThreshold: 0.25,
|
||||
heatstrokeTemperature: 330.0,
|
||||
heatstrokeMultiplier: 0.00001,
|
||||
heatstrokeExponent: 2.0,
|
||||
heatstrokeRecoveryPerSecond: 0.2,
|
||||
hypothermiaTemperature: 273.0,
|
||||
hypothermiaMultiplier: 0.00001,
|
||||
hypothermiaExponent: 2.0,
|
||||
hypothermiaRecoveryPerSecond: 0.2);
|
||||
|
||||
public AetheriaRuntimeDaemonSimulationSettings(
|
||||
double pawnSpeed,
|
||||
|
|
@ -68,7 +77,16 @@ namespace GameCult.Aetheria.State.Verse
|
|||
double weaponLockDecayPerSecond = AetheriaDefaultRaw.WeaponLockDecayPerSecond,
|
||||
double lootDropProbability = AetheriaDefaultRaw.LootDropProbability,
|
||||
double lootDropVelocity = AetheriaDefaultRaw.LootDropVelocity,
|
||||
double pickupLifetimeSeconds = AetheriaDefaultRaw.PickupLifetimeSeconds)
|
||||
double pickupLifetimeSeconds = AetheriaDefaultRaw.PickupLifetimeSeconds,
|
||||
double severeThermalRiskThreshold = AetheriaDefaultRaw.SevereThermalRiskThreshold,
|
||||
double heatstrokeTemperature = AetheriaDefaultRaw.HeatstrokeTemperature,
|
||||
double heatstrokeMultiplier = AetheriaDefaultRaw.HeatstrokeMultiplier,
|
||||
double heatstrokeExponent = AetheriaDefaultRaw.HeatstrokeExponent,
|
||||
double heatstrokeRecoveryPerSecond = AetheriaDefaultRaw.HeatstrokeRecoveryPerSecond,
|
||||
double hypothermiaTemperature = AetheriaDefaultRaw.HypothermiaTemperature,
|
||||
double hypothermiaMultiplier = AetheriaDefaultRaw.HypothermiaMultiplier,
|
||||
double hypothermiaExponent = AetheriaDefaultRaw.HypothermiaExponent,
|
||||
double hypothermiaRecoveryPerSecond = AetheriaDefaultRaw.HypothermiaRecoveryPerSecond)
|
||||
{
|
||||
PawnSpeed = PositiveOr(pawnSpeed, AetheriaDefaultRaw.PawnSpeed);
|
||||
RaiderSpeed = PositiveOr(raiderSpeed, AetheriaDefaultRaw.RaiderSpeed);
|
||||
|
|
@ -99,6 +117,15 @@ namespace GameCult.Aetheria.State.Verse
|
|||
LootDropProbability = Clamp01Or(lootDropProbability, AetheriaDefaultRaw.LootDropProbability);
|
||||
LootDropVelocity = NonNegativeOr(lootDropVelocity, AetheriaDefaultRaw.LootDropVelocity);
|
||||
PickupLifetimeSeconds = PositiveOr(pickupLifetimeSeconds, AetheriaDefaultRaw.PickupLifetimeSeconds);
|
||||
SevereThermalRiskThreshold = Clamp01Or(severeThermalRiskThreshold, AetheriaDefaultRaw.SevereThermalRiskThreshold);
|
||||
HeatstrokeTemperature = PositiveOr(heatstrokeTemperature, AetheriaDefaultRaw.HeatstrokeTemperature);
|
||||
HeatstrokeMultiplier = NonNegativeOr(heatstrokeMultiplier, AetheriaDefaultRaw.HeatstrokeMultiplier);
|
||||
HeatstrokeExponent = PositiveOr(heatstrokeExponent, AetheriaDefaultRaw.HeatstrokeExponent);
|
||||
HeatstrokeRecoveryPerSecond = NonNegativeOr(heatstrokeRecoveryPerSecond, AetheriaDefaultRaw.HeatstrokeRecoveryPerSecond);
|
||||
HypothermiaTemperature = PositiveOr(hypothermiaTemperature, AetheriaDefaultRaw.HypothermiaTemperature);
|
||||
HypothermiaMultiplier = NonNegativeOr(hypothermiaMultiplier, AetheriaDefaultRaw.HypothermiaMultiplier);
|
||||
HypothermiaExponent = PositiveOr(hypothermiaExponent, AetheriaDefaultRaw.HypothermiaExponent);
|
||||
HypothermiaRecoveryPerSecond = NonNegativeOr(hypothermiaRecoveryPerSecond, AetheriaDefaultRaw.HypothermiaRecoveryPerSecond);
|
||||
}
|
||||
|
||||
public double PawnSpeed { get; }
|
||||
|
|
@ -130,6 +157,15 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public double LootDropProbability { get; }
|
||||
public double LootDropVelocity { get; }
|
||||
public double PickupLifetimeSeconds { get; }
|
||||
public double SevereThermalRiskThreshold { get; }
|
||||
public double HeatstrokeTemperature { get; }
|
||||
public double HeatstrokeMultiplier { get; }
|
||||
public double HeatstrokeExponent { get; }
|
||||
public double HeatstrokeRecoveryPerSecond { get; }
|
||||
public double HypothermiaTemperature { get; }
|
||||
public double HypothermiaMultiplier { get; }
|
||||
public double HypothermiaExponent { get; }
|
||||
public double HypothermiaRecoveryPerSecond { get; }
|
||||
|
||||
private static double PositiveOr(double value, double fallback)
|
||||
{
|
||||
|
|
@ -177,6 +213,15 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public const double LootDropProbability = 0.25;
|
||||
public const double LootDropVelocity = 25.0;
|
||||
public const double PickupLifetimeSeconds = 30.0;
|
||||
public const double SevereThermalRiskThreshold = 0.25;
|
||||
public const double HeatstrokeTemperature = 330.0;
|
||||
public const double HeatstrokeMultiplier = 0.00001;
|
||||
public const double HeatstrokeExponent = 2.0;
|
||||
public const double HeatstrokeRecoveryPerSecond = 0.2;
|
||||
public const double HypothermiaTemperature = 273.0;
|
||||
public const double HypothermiaMultiplier = 0.00001;
|
||||
public const double HypothermiaExponent = 2.0;
|
||||
public const double HypothermiaRecoveryPerSecond = 0.2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1049,6 +1049,9 @@ namespace GameCult.Aetheria.State.Verse
|
|||
[Key(47)]
|
||||
public IReadOnlyList<AetheriaRuntimeEquipmentStateCommit> EquipmentStates { get; set; } =
|
||||
Array.Empty<AetheriaRuntimeEquipmentStateCommit>();
|
||||
|
||||
[Key(48)]
|
||||
public string CauseOfDeath { get; set; } = "";
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Verse
|
||||
{
|
||||
public static class AetheriaRuntimeThermalMedicalSimulation
|
||||
{
|
||||
public static AetheriaRuntimeThermalMedicalResult Step(
|
||||
AetheriaRuntimeEntitySnapshotCommit entity,
|
||||
AetheriaRuntimeCatalogSnapshot? catalog,
|
||||
double deltaSeconds,
|
||||
AetheriaRuntimeDaemonSimulationSettings settings)
|
||||
{
|
||||
if (entity == null || catalog == null || deltaSeconds <= 0 || !entity.IsActive)
|
||||
return default;
|
||||
|
||||
var cockpit = AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, "Cockpit")
|
||||
.OrderBy(value => value.EquipmentIndex)
|
||||
.FirstOrDefault();
|
||||
if (cockpit == null)
|
||||
return default;
|
||||
|
||||
var temperature = AetheriaRuntimeThermalSimulation.EquipmentTemperature(
|
||||
entity, catalog, cockpit.EquipmentIndex);
|
||||
SetScalar(entity, "cockpit-temperature", temperature);
|
||||
var previousHeatstroke = Clamp01(entity.Heatstroke);
|
||||
var previousHypothermia = Clamp01(entity.Hypothermia);
|
||||
|
||||
entity.Heatstroke = temperature > settings.HeatstrokeTemperature
|
||||
? Clamp01(previousHeatstroke + Math.Pow(
|
||||
temperature - settings.HeatstrokeTemperature,
|
||||
settings.HeatstrokeExponent) * settings.HeatstrokeMultiplier * deltaSeconds)
|
||||
: Clamp01(previousHeatstroke - settings.HeatstrokeRecoveryPerSecond * deltaSeconds);
|
||||
entity.Hypothermia = temperature < settings.HypothermiaTemperature
|
||||
? Clamp01(previousHypothermia + Math.Pow(
|
||||
settings.HypothermiaTemperature - temperature,
|
||||
settings.HypothermiaExponent) * settings.HypothermiaMultiplier * deltaSeconds)
|
||||
: Clamp01(previousHypothermia - settings.HypothermiaRecoveryPerSecond * deltaSeconds);
|
||||
|
||||
var heatstrokeRisk = Crossed(previousHeatstroke, entity.Heatstroke,
|
||||
settings.SevereThermalRiskThreshold);
|
||||
var hypothermiaRisk = Crossed(previousHypothermia, entity.Hypothermia,
|
||||
settings.SevereThermalRiskThreshold);
|
||||
var deathCause = entity.Heatstroke > 0.99 ? "heatstroke" :
|
||||
entity.Hypothermia > 0.99 ? "hypothermia" : "";
|
||||
return new AetheriaRuntimeThermalMedicalResult(
|
||||
cockpit.EquipmentIndex, temperature, heatstrokeRisk, hypothermiaRisk, deathCause);
|
||||
}
|
||||
|
||||
private static bool Crossed(double previous, double current, double threshold) =>
|
||||
previous < threshold && current > threshold;
|
||||
|
||||
private static void SetScalar(AetheriaRuntimeEntitySnapshotCommit entity, string name, double value)
|
||||
{
|
||||
var grids = (entity.StatGrids ?? Array.Empty<AetheriaRuntimeEntityStatGridCommit>()).ToList();
|
||||
var grid = grids.FirstOrDefault(candidate => string.Equals(candidate.Name, name, StringComparison.Ordinal));
|
||||
if (grid == null)
|
||||
{
|
||||
grid = new AetheriaRuntimeEntityStatGridCommit { Name = name, Width = 1, Height = 1 };
|
||||
grids.Add(grid);
|
||||
}
|
||||
grid.Values = new[] { value };
|
||||
entity.StatGrids = grids;
|
||||
}
|
||||
|
||||
private static double Clamp01(double value) => value < 0 ? 0 : value > 1 ? 1 : value;
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeThermalMedicalResult
|
||||
{
|
||||
public AetheriaRuntimeThermalMedicalResult(int cockpitEquipmentIndex, double cockpitTemperature,
|
||||
bool heatstrokeRiskCrossed, bool hypothermiaRiskCrossed, string deathCause)
|
||||
{
|
||||
CockpitEquipmentIndex = cockpitEquipmentIndex;
|
||||
CockpitTemperature = cockpitTemperature;
|
||||
HeatstrokeRiskCrossed = heatstrokeRiskCrossed;
|
||||
HypothermiaRiskCrossed = hypothermiaRiskCrossed;
|
||||
DeathCause = deathCause ?? "";
|
||||
}
|
||||
|
||||
public int CockpitEquipmentIndex { get; }
|
||||
public double CockpitTemperature { get; }
|
||||
public bool HeatstrokeRiskCrossed { get; }
|
||||
public bool HypothermiaRiskCrossed { get; }
|
||||
public string DeathCause { get; }
|
||||
public bool Died => !string.IsNullOrWhiteSpace(DeathCause);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 741e91657d8b412ebf96032d567ecfc7
|
||||
Loading…
Reference in a new issue