Restore progressive weapon lock

This commit is contained in:
Meta Vens 2026-07-11 20:16:39 +01:00
commit 664e4c2de4
4 changed files with 79 additions and 9 deletions

View file

@ -249,16 +249,16 @@ namespace GameCult.Aetheria.State.Verse
!IsAlive(target) ||
!Hostile(attacker, target))
{
weaponState.LockTargetEntityIndex = -1;
weaponState.LockProgress = 0;
continue;
}
if (DistanceSq(attacker, target) > settings.AttackRange * settings.AttackRange)
UpdateWeaponLock(attacker, target, weaponState, deltaSeconds, settings);
if (DistanceSq(attacker, target) > settings.AttackRange * settings.AttackRange ||
weaponState.LockProgress <= 0.99)
continue;
Face(attacker, target.PositionX - attacker.PositionX, target.PositionZ - attacker.PositionZ);
weaponState.LockTargetEntityIndex = target.EntityIndex;
weaponState.LockProgress = 1.0;
if (weaponState.CooldownProgress > 0)
continue;
@ -308,6 +308,43 @@ namespace GameCult.Aetheria.State.Verse
}
}
private static void UpdateWeaponLock(
AetheriaRuntimeEntitySnapshotCommit attacker,
AetheriaRuntimeEntitySnapshotCommit target,
AetheriaRuntimeWeaponStateCommit weaponState,
double deltaSeconds,
AetheriaRuntimeDaemonSimulationSettings settings)
{
if (weaponState.LockTargetEntityIndex != target.EntityIndex)
{
weaponState.LockTargetEntityIndex = target.EntityIndex;
weaponState.LockProgress = 0;
}
var targetDirection = Normalize(target.PositionX - attacker.PositionX, target.PositionZ - attacker.PositionZ);
var lookDirection = Normalize(attacker.DirectionX, attacker.DirectionY);
var dot = Math.Max(-1.0, Math.Min(1.0,
targetDirection.X * lookDirection.X + targetDirection.Y * lookDirection.Y));
var angleDegrees = Math.Acos(dot) * 180.0 / Math.PI;
if (angleDegrees >= settings.WeaponLockAngleDegrees)
{
weaponState.LockProgress = Clamp01(
weaponState.LockProgress - deltaSeconds * settings.WeaponLockDecayPerSecond);
return;
}
var contact = (attacker.Contacts ?? Array.Empty<AetheriaRuntimeEntityContactCommit>())
.FirstOrDefault(candidate => candidate != null && candidate.TargetEntityIndex == target.EntityIndex);
var information = Clamp01(contact?.InfoGathered ?? 0);
var directionalQuality = Math.Max(0, 1.0 - angleDegrees / 90.0);
var acquisition =
Math.Pow(directionalQuality, settings.WeaponLockDirectionImpact) *
deltaSeconds *
settings.WeaponLockSpeed *
Math.Pow(information, settings.WeaponLockSensorImpact);
weaponState.LockProgress = Clamp01(weaponState.LockProgress + acquisition);
}
private static void PrepareProjectiles(
AetheriaRuntimeZoneSnapshotCommit zone,
IReadOnlyDictionary<int, AetheriaRuntimeEntitySnapshotCommit> entities,

View file

@ -29,7 +29,12 @@ namespace GameCult.Aetheria.State.Verse
playerEntityHull: 120.0,
raiderEntityHull: 80.0,
stationShield: 120.0,
entityShield: 45.0);
entityShield: 45.0,
weaponLockSpeed: 2.0,
weaponLockSensorImpact: 1.0,
weaponLockAngleDegrees: 45.0,
weaponLockDirectionImpact: 1.0,
weaponLockDecayPerSecond: 1.0);
public AetheriaRuntimeDaemonSimulationSettings(
double pawnSpeed,
@ -52,7 +57,12 @@ namespace GameCult.Aetheria.State.Verse
double playerEntityHull,
double raiderEntityHull,
double stationShield,
double entityShield)
double entityShield,
double weaponLockSpeed = AetheriaDefaultRaw.WeaponLockSpeed,
double weaponLockSensorImpact = AetheriaDefaultRaw.WeaponLockSensorImpact,
double weaponLockAngleDegrees = AetheriaDefaultRaw.WeaponLockAngleDegrees,
double weaponLockDirectionImpact = AetheriaDefaultRaw.WeaponLockDirectionImpact,
double weaponLockDecayPerSecond = AetheriaDefaultRaw.WeaponLockDecayPerSecond)
{
PawnSpeed = PositiveOr(pawnSpeed, AetheriaDefaultRaw.PawnSpeed);
RaiderSpeed = PositiveOr(raiderSpeed, AetheriaDefaultRaw.RaiderSpeed);
@ -75,6 +85,11 @@ namespace GameCult.Aetheria.State.Verse
RaiderEntityHull = PositiveOr(raiderEntityHull, AetheriaDefaultRaw.RaiderEntityHull);
StationShield = NonNegativeOr(stationShield, AetheriaDefaultRaw.StationShield);
EntityShield = NonNegativeOr(entityShield, AetheriaDefaultRaw.EntityShield);
WeaponLockSpeed = PositiveOr(weaponLockSpeed, AetheriaDefaultRaw.WeaponLockSpeed);
WeaponLockSensorImpact = NonNegativeOr(weaponLockSensorImpact, AetheriaDefaultRaw.WeaponLockSensorImpact);
WeaponLockAngleDegrees = PositiveOr(weaponLockAngleDegrees, AetheriaDefaultRaw.WeaponLockAngleDegrees);
WeaponLockDirectionImpact = NonNegativeOr(weaponLockDirectionImpact, AetheriaDefaultRaw.WeaponLockDirectionImpact);
WeaponLockDecayPerSecond = NonNegativeOr(weaponLockDecayPerSecond, AetheriaDefaultRaw.WeaponLockDecayPerSecond);
}
public double PawnSpeed { get; }
@ -98,6 +113,11 @@ namespace GameCult.Aetheria.State.Verse
public double RaiderEntityHull { get; }
public double StationShield { get; }
public double EntityShield { get; }
public double WeaponLockSpeed { get; }
public double WeaponLockSensorImpact { get; }
public double WeaponLockAngleDegrees { get; }
public double WeaponLockDirectionImpact { get; }
public double WeaponLockDecayPerSecond { get; }
private static double PositiveOr(double value, double fallback)
{
@ -137,6 +157,11 @@ namespace GameCult.Aetheria.State.Verse
public const double RaiderEntityHull = 80.0;
public const double StationShield = 120.0;
public const double EntityShield = 45.0;
public const double WeaponLockSpeed = 2.0;
public const double WeaponLockSensorImpact = 1.0;
public const double WeaponLockAngleDegrees = 45.0;
public const double WeaponLockDirectionImpact = 1.0;
public const double WeaponLockDecayPerSecond = 1.0;
}
}
}