feat(cut5b-1): equal-start jackals, ai scavenging, naturalized aim, ots camera & interpolation
This commit is contained in:
parent
cdce8cd843
commit
1eb37e328a
12 changed files with 1548 additions and 225 deletions
|
|
@ -319,7 +319,7 @@ public partial class ArenaRenderer : Node3D
|
|||
_assetCache?.Dispose();
|
||||
}
|
||||
|
||||
public void Sync(ArenaSession session, float elapsedSeconds, float dt = 1f / 60f)
|
||||
public void Sync(ArenaSession session, float elapsedSeconds, float dt = 1f / 60f, float alpha = 1f)
|
||||
{
|
||||
var state = session.State;
|
||||
if (!ReferenceEquals(_builtForState, state))
|
||||
|
|
@ -335,8 +335,8 @@ public partial class ArenaRenderer : Node3D
|
|||
|
||||
_partPool.BeginFrame(hasCam ? cam : null);
|
||||
UpdateSafeCircleRing(state.Terrain, state.Spectators.SafeRadius);
|
||||
SyncContenders(session, dt, hasCam, camPos);
|
||||
SyncSpectators(session, elapsedSeconds, dt, hasCam, camPos);
|
||||
SyncContenders(session, dt, alpha, hasCam, camPos);
|
||||
SyncSpectators(session, elapsedSeconds, dt, alpha, hasCam, camPos);
|
||||
SyncGroundDrops(state, elapsedSeconds, hasCam, camPos);
|
||||
_debris.Step(dt, state.Terrain);
|
||||
_debris.SubmitToPool(_partPool);
|
||||
|
|
@ -496,9 +496,8 @@ public partial class ArenaRenderer : Node3D
|
|||
_safeRingImm.SurfaceEnd();
|
||||
}
|
||||
|
||||
private void SyncContenders(ArenaSession session, float dt, bool hasCam, Vector3 camPos)
|
||||
private void SyncContenders(ArenaSession session, float dt, float alpha, bool hasCam, Vector3 camPos)
|
||||
{
|
||||
var view = session.World.View;
|
||||
var contenders = session.State.Contenders;
|
||||
|
||||
for (int i = 0; i < contenders.Count; i++)
|
||||
|
|
@ -531,24 +530,11 @@ public partial class ArenaRenderer : Node3D
|
|||
|
||||
vis.Visual.Root.Visible = true;
|
||||
|
||||
Vector3 pos;
|
||||
Vector3 vel;
|
||||
var body = session.GetContenderBody(c.Id);
|
||||
if (body is { } h)
|
||||
{
|
||||
int lane = h.Lane;
|
||||
pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]);
|
||||
vis.Visual.Root.Transform = new Transform3D(new Basis(q), pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = new Vector3(c.X, c.Y, c.Z);
|
||||
vel = Vector3.Zero;
|
||||
vis.Visual.Root.Position = pos;
|
||||
vis.Visual.Root.Rotation = new Vector3(0f, c.Yaw, 0f);
|
||||
}
|
||||
var (interpPos, interpRot, interpVel) = session.GetInterpolatedContenderPose(c.Id, alpha);
|
||||
Vector3 pos = new Vector3(interpPos.X, interpPos.Y, interpPos.Z);
|
||||
Vector3 vel = new Vector3(interpVel.X, interpVel.Y, interpVel.Z);
|
||||
var q = new Quaternion(interpRot.X, interpRot.Y, interpRot.Z, interpRot.W);
|
||||
vis.Visual.Root.Transform = new Transform3D(new Basis(q), pos);
|
||||
|
||||
float distSq = hasCam ? pos.DistanceSquaredTo(camPos) : 0f;
|
||||
bool castShadows = !hasCam || c.IsPlayer || distSq <= 75f * 75f;
|
||||
|
|
@ -582,9 +568,8 @@ public partial class ArenaRenderer : Node3D
|
|||
}
|
||||
}
|
||||
|
||||
private void SyncSpectators(ArenaSession session, float elapsedSeconds, float dt, bool hasCam, Vector3 camPos)
|
||||
private void SyncSpectators(ArenaSession session, float elapsedSeconds, float dt, float alpha, bool hasCam, Vector3 camPos)
|
||||
{
|
||||
var view = session.World.View;
|
||||
var specs = session.State.Spectators.Spectators;
|
||||
|
||||
for (int i = 0; i < specs.Count; i++)
|
||||
|
|
@ -625,24 +610,11 @@ public partial class ArenaRenderer : Node3D
|
|||
}
|
||||
|
||||
vis.Visual.Root.Visible = true;
|
||||
var body = session.GetSpectatorBody(s.Id);
|
||||
Vector3 specPos;
|
||||
Vector3 vel;
|
||||
if (body is { } h)
|
||||
{
|
||||
int lane = h.Lane;
|
||||
specPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]);
|
||||
vis.Visual.Root.Transform = new Transform3D(new Basis(q), specPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
specPos = new Vector3(s.X, s.Y, s.Z);
|
||||
vel = Vector3.Zero;
|
||||
vis.Visual.Root.Position = specPos;
|
||||
vis.Visual.Root.Rotation = new Vector3(0f, s.Yaw, 0f);
|
||||
}
|
||||
var (interpPos, interpRot, interpVel) = session.GetInterpolatedSpectatorPose(s.Id, alpha);
|
||||
Vector3 specPos = new Vector3(interpPos.X, interpPos.Y, interpPos.Z);
|
||||
Vector3 vel = new Vector3(interpVel.X, interpVel.Y, interpVel.Z);
|
||||
var q = new Quaternion(interpRot.X, interpRot.Y, interpRot.Z, interpRot.W);
|
||||
vis.Visual.Root.Transform = new Transform3D(new Basis(q), specPos);
|
||||
|
||||
vis.Visual.SyncDamageAndHeat(s.Grid, _debris, vel);
|
||||
|
||||
|
|
|
|||
160
client/Main.cs
160
client/Main.cs
|
|
@ -28,7 +28,8 @@ public partial class Main : Node3D
|
|||
private float _cameraYaw;
|
||||
private float _cameraPitch = Mathf.DegToRad(5f);
|
||||
private float _cameraZoom = 1.0f;
|
||||
private Vector3 _cameraSmoothedAnchor = Vector3.Zero;
|
||||
private float _smoothedShoulderY;
|
||||
private string? _lastCamChassisId;
|
||||
private float _elapsedSeconds;
|
||||
private bool _interactQueued;
|
||||
private int _seed = 42;
|
||||
|
|
@ -161,8 +162,8 @@ public partial class Main : Node3D
|
|||
InteractPickup: false,
|
||||
Brake: false);
|
||||
|
||||
_arena.Sync(session, _elapsedSeconds, 0f);
|
||||
UpdateCamera(1f);
|
||||
_arena.Sync(session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_hud.Sync(session);
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +192,7 @@ public partial class Main : Node3D
|
|||
_cameraYaw = p.Yaw;
|
||||
_cameraPitch = _mapKind == ArenaMapKind.Sion ? Mathf.DegToRad(5f) : Mathf.DegToRad(12f);
|
||||
_cameraZoom = 1.0f;
|
||||
_cameraSmoothedAnchor = ComputeTargetAnchor(p);
|
||||
_lastCamChassisId = null;
|
||||
_camera.Far = _mapKind == ArenaMapKind.Sion ? 4200f : 1800f;
|
||||
ApplyEnvironmentForMap(_mapKind);
|
||||
|
||||
|
|
@ -200,8 +201,8 @@ public partial class Main : Node3D
|
|||
_terrain.Visible = false;
|
||||
_sionMap.Visible = true;
|
||||
_sionMap.EnsureBuilt(_session.State.SionMap!, _session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f);
|
||||
UpdateCamera(1f);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
}
|
||||
else
|
||||
|
|
@ -210,8 +211,8 @@ public partial class Main : Node3D
|
|||
_terrain.Visible = true;
|
||||
_terrain.InvalidateAll();
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f);
|
||||
UpdateCamera(1f);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
}
|
||||
|
||||
|
|
@ -337,6 +338,8 @@ public partial class Main : Node3D
|
|||
return;
|
||||
}
|
||||
|
||||
float alpha = Math.Clamp((float)Engine.GetPhysicsInterpolationFraction(), 0f, 1f);
|
||||
|
||||
if (_perfTargetFrames > 0)
|
||||
{
|
||||
double toMs = 1000.0 / Stopwatch.Frequency;
|
||||
|
|
@ -346,13 +349,13 @@ public partial class Main : Node3D
|
|||
_terrain.Sync(_session.State.Terrain);
|
||||
}
|
||||
long tt1 = Stopwatch.GetTimestamp();
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta);
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta, alpha);
|
||||
long ta1 = Stopwatch.GetTimestamp();
|
||||
_perfPendingTerrainMs = (tt1 - tt0) * toMs;
|
||||
_perfPendingArenaMs = (ta1 - tt1) * toMs;
|
||||
|
||||
long tc0 = Stopwatch.GetTimestamp();
|
||||
UpdateCamera((float)delta);
|
||||
UpdateCamera((float)delta, alpha);
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
|
|
@ -403,8 +406,8 @@ public partial class Main : Node3D
|
|||
{
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
}
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta);
|
||||
UpdateCamera((float)delta);
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta, alpha);
|
||||
UpdateCamera((float)delta, alpha);
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
|
|
@ -559,6 +562,7 @@ public partial class Main : Node3D
|
|||
private (float AimX, float AimY, float AimZ) ComputeCenterScreenAim()
|
||||
{
|
||||
var player = Session.State.Player;
|
||||
var spec = player.Grid.Spec;
|
||||
Vector2 screenSize = GetViewport().GetVisibleRect().Size;
|
||||
if (screenSize.X < 2f || screenSize.Y < 2f)
|
||||
{
|
||||
|
|
@ -574,6 +578,13 @@ public partial class Main : Node3D
|
|||
|
||||
const float maxAimDist = 450f;
|
||||
ulong playerStableId = ArenaSession.ContenderStableIdBase + (ulong)player.Id;
|
||||
Vector3 playerCenter = new Vector3(player.X, player.Y, player.Z);
|
||||
float camToCenterProj = (playerCenter - rayOrigin).Dot(rayDir);
|
||||
float minForwardDot = -MathF.Max(spec.HalfWidth, spec.HalfLength) * 0.35f;
|
||||
|
||||
bool IsValidForwardHit(Vector3 pt, float distFromCam) =>
|
||||
(pt - playerCenter).Dot(rayDir) >= minForwardDot &&
|
||||
distFromCam >= camToCenterProj - 0.5f;
|
||||
|
||||
Vector3 castOrigin = rayOrigin;
|
||||
float remainingDist = maxAimDist;
|
||||
|
|
@ -581,8 +592,8 @@ public partial class Main : Node3D
|
|||
Vector3 boxHitPt = Vector3.Zero;
|
||||
bool hasBoxHit = false;
|
||||
|
||||
// Cast against Ymir world, skipping the player's own chassis if hit along the shoulder ray.
|
||||
for (int attempt = 0; attempt < 2; attempt++)
|
||||
// Cast against Ymir world, skipping the player's own chassis and any surface behind the vehicle's forward plane.
|
||||
for (int attempt = 0; attempt < 4 && remainingDist > 1f; attempt++)
|
||||
{
|
||||
var hit = Session.World.CastRayClosest(
|
||||
(castOrigin.X, castOrigin.Y, castOrigin.Z),
|
||||
|
|
@ -593,25 +604,52 @@ public partial class Main : Node3D
|
|||
}
|
||||
|
||||
var pt = new Vector3(hit.Point.X, hit.Point.Y, hit.Point.Z);
|
||||
if (hit.StableId == playerStableId)
|
||||
float distFromCam = rayOrigin.DistanceTo(pt);
|
||||
if (hit.StableId == playerStableId || !IsValidForwardHit(pt, distFromCam))
|
||||
{
|
||||
float skip = rayOrigin.DistanceTo(pt) + 0.4f;
|
||||
float skip = distFromCam + 0.4f;
|
||||
castOrigin = rayOrigin + rayDir * skip;
|
||||
remainingDist = MathF.Max(1f, maxAimDist - skip);
|
||||
continue;
|
||||
}
|
||||
|
||||
boxHitPt = pt;
|
||||
boxDist = rayOrigin.DistanceTo(pt);
|
||||
boxDist = distFromCam;
|
||||
hasBoxHit = true;
|
||||
break;
|
||||
}
|
||||
|
||||
bool hasTerrainHit = Session.State.Terrain.Raycast(
|
||||
rayOrigin.X, rayOrigin.Y, rayOrigin.Z,
|
||||
rayDir.X, rayDir.Y, rayDir.Z,
|
||||
maxDistance: boxDist,
|
||||
out float tx, out float ty, out float tz, out float terrainDist);
|
||||
float terrainStartDist = 0f;
|
||||
bool hasTerrainHit = false;
|
||||
float tx = 0f, ty = 0f, tz = 0f, terrainDist = maxAimDist;
|
||||
for (int attempt = 0; attempt < 2 && terrainStartDist < boxDist; attempt++)
|
||||
{
|
||||
Vector3 tOrigin = rayOrigin + rayDir * terrainStartDist;
|
||||
float tMaxDist = boxDist - terrainStartDist;
|
||||
if (!Session.State.Terrain.Raycast(
|
||||
tOrigin.X, tOrigin.Y, tOrigin.Z,
|
||||
rayDir.X, rayDir.Y, rayDir.Z,
|
||||
maxDistance: tMaxDist,
|
||||
out float hx, out float hy, out float hz, out float localDist))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
float totalDist = terrainStartDist + localDist;
|
||||
var hitPt = new Vector3(hx, hy, hz);
|
||||
if (!IsValidForwardHit(hitPt, totalDist))
|
||||
{
|
||||
terrainStartDist = MathF.Max(totalDist + 0.5f, camToCenterProj - 0.4f);
|
||||
continue;
|
||||
}
|
||||
|
||||
tx = hx;
|
||||
ty = hy;
|
||||
tz = hz;
|
||||
terrainDist = totalDist;
|
||||
hasTerrainHit = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (hasTerrainHit && terrainDist <= boxDist)
|
||||
{
|
||||
|
|
@ -627,52 +665,74 @@ public partial class Main : Node3D
|
|||
return (farPt.X, farPt.Y, farPt.Z);
|
||||
}
|
||||
|
||||
private Vector3 ComputeTargetAnchor(ContenderState p)
|
||||
{
|
||||
var spec = p.Grid.Spec;
|
||||
float heightT = Math.Clamp((spec.HalfHeight - 0.75f) / (2.35f - 0.75f), 0f, 1.2f);
|
||||
float upOffset = Mathf.Lerp(3.2f, 6.5f, heightT);
|
||||
float rightOffset = Mathf.Lerp(1.6f, 2.8f, heightT);
|
||||
|
||||
var camRight = new Vector3(-MathF.Cos(_cameraYaw), 0f, MathF.Sin(_cameraYaw));
|
||||
return new Vector3(p.X, p.Y + (upOffset - spec.HalfHeight), p.Z) + camRight * rightOffset;
|
||||
}
|
||||
|
||||
private void UpdateCamera(float dt)
|
||||
private void UpdateCamera(float dt, float alpha)
|
||||
{
|
||||
var p = Session.State.Player;
|
||||
var spec = p.Grid.Spec;
|
||||
float heightT = Math.Clamp((spec.HalfHeight - 0.75f) / (2.35f - 0.75f), 0f, 1.2f);
|
||||
float backDist = Mathf.Lerp(7.5f, 12.5f, heightT) * _cameraZoom;
|
||||
var (posInterp, _, _) = Session.GetInterpolatedContenderPose(p.Id, alpha);
|
||||
|
||||
Vector3 targetAnchor = ComputeTargetAnchor(p);
|
||||
float blend = dt >= 1f ? 1f : 1f - MathF.Exp(-dt * 16f);
|
||||
_cameraSmoothedAnchor = _cameraSmoothedAnchor.Lerp(targetAnchor, blend);
|
||||
float rightOffset = MathF.Max(1.6f, spec.HalfWidth * 1.15f + 0.8f);
|
||||
float heightOffset = spec.HalfHeight * 1.45f + 1.4f;
|
||||
float boundingR = MathF.Max(spec.HalfWidth, MathF.Max(spec.HalfHeight * 0.72f, spec.HalfLength * 0.90f));
|
||||
float backDist = Math.Clamp(boundingR * 2.15f + 4.2f, 7.2f, 19.5f) * _cameraZoom;
|
||||
float targetShoulderY = (posInterp.Y - spec.HalfHeight) + heightOffset;
|
||||
|
||||
if (_lastCamChassisId != spec.Id || dt >= 1f)
|
||||
{
|
||||
_smoothedShoulderY = targetShoulderY;
|
||||
_lastCamChassisId = spec.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
float yBlend = 1f - MathF.Exp(-dt * 24f);
|
||||
_smoothedShoulderY = Mathf.Lerp(_smoothedShoulderY, targetShoulderY, yBlend);
|
||||
}
|
||||
|
||||
var pivot = new Vector3(posInterp.X, _smoothedShoulderY, posInterp.Z);
|
||||
var camRight = new Vector3(-MathF.Cos(_cameraYaw), 0f, MathF.Sin(_cameraYaw));
|
||||
var camFwdHoriz = new Vector3(MathF.Sin(_cameraYaw), 0f, MathF.Cos(_cameraYaw));
|
||||
var lookDir = (camFwdHoriz * MathF.Cos(_cameraPitch) - Vector3.Up * MathF.Sin(_cameraPitch)).Normalized();
|
||||
|
||||
// Pull camera forward along arm if terrain or static cover blocks the shoulder-to-camera ray
|
||||
// Segment 1: sweep terrain + static Box3D (StableId < ContenderStableIdBase) from pivot along camRight * rightOffset
|
||||
float effectiveRight = rightOffset;
|
||||
if (Session.State.Terrain.Raycast(
|
||||
pivot.X, pivot.Y, pivot.Z,
|
||||
camRight.X, camRight.Y, camRight.Z,
|
||||
rightOffset,
|
||||
out _, out _, out _, out float rightTerrainDist))
|
||||
{
|
||||
effectiveRight = MathF.Min(effectiveRight, MathF.Max(0f, rightTerrainDist - 0.45f));
|
||||
}
|
||||
var rightBoxHit = Session.World.CastRayClosest(
|
||||
(pivot.X, pivot.Y, pivot.Z),
|
||||
(camRight.X * effectiveRight, camRight.Y * effectiveRight, camRight.Z * effectiveRight));
|
||||
if (rightBoxHit.Hit && rightBoxHit.StableId < ArenaSession.ContenderStableIdBase)
|
||||
{
|
||||
var pt = new Vector3(rightBoxHit.Point.X, rightBoxHit.Point.Y, rightBoxHit.Point.Z);
|
||||
effectiveRight = MathF.Min(effectiveRight, MathF.Max(0f, pivot.DistanceTo(pt) - 0.45f));
|
||||
}
|
||||
Vector3 shoulderPos = pivot + camRight * effectiveRight;
|
||||
|
||||
// Segment 2: sweep terrain + static Box3D from shoulderPos along -lookDir * backDist
|
||||
float effectiveBack = backDist;
|
||||
if (Session.State.Terrain.Raycast(
|
||||
_cameraSmoothedAnchor.X, _cameraSmoothedAnchor.Y, _cameraSmoothedAnchor.Z,
|
||||
shoulderPos.X, shoulderPos.Y, shoulderPos.Z,
|
||||
-lookDir.X, -lookDir.Y, -lookDir.Z,
|
||||
backDist,
|
||||
out _, out _, out _, out float terrainDist))
|
||||
out _, out _, out _, out float backTerrainDist))
|
||||
{
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(1.6f, terrainDist - 0.6f));
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(0.6f, backTerrainDist - 0.5f));
|
||||
}
|
||||
|
||||
var boxHit = Session.World.CastRayClosest(
|
||||
(_cameraSmoothedAnchor.X, _cameraSmoothedAnchor.Y, _cameraSmoothedAnchor.Z),
|
||||
var backBoxHit = Session.World.CastRayClosest(
|
||||
(shoulderPos.X, shoulderPos.Y, shoulderPos.Z),
|
||||
(-lookDir.X * effectiveBack, -lookDir.Y * effectiveBack, -lookDir.Z * effectiveBack));
|
||||
if (boxHit.Hit && boxHit.StableId < ArenaSession.ContenderStableIdBase)
|
||||
if (backBoxHit.Hit && backBoxHit.StableId < ArenaSession.ContenderStableIdBase)
|
||||
{
|
||||
var pt = new Vector3(boxHit.Point.X, boxHit.Point.Y, boxHit.Point.Z);
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(1.6f, _cameraSmoothedAnchor.DistanceTo(pt) - 0.5f));
|
||||
var pt = new Vector3(backBoxHit.Point.X, backBoxHit.Point.Y, backBoxHit.Point.Z);
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(0.6f, shoulderPos.DistanceTo(pt) - 0.5f));
|
||||
}
|
||||
|
||||
Vector3 camPos = _cameraSmoothedAnchor - lookDir * effectiveBack;
|
||||
Vector3 camPos = shoulderPos - lookDir * effectiveBack;
|
||||
float minTerrainY = Session.State.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
|
||||
if (camPos.Y < minTerrainY)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ namespace RustToDust.Core
|
|||
Emit(timestamp, BroadcastKind.Elimination, line);
|
||||
}
|
||||
|
||||
public void EmitVictory(float timestamp, int winnerId) =>
|
||||
public void EmitVictory(float timestamp, int winnerId, ArenaMapKind mapKind = ArenaMapKind.Desert) =>
|
||||
Emit(timestamp, BroadcastKind.Victory,
|
||||
$"Contender {winnerId + 1:00} outlasts the dust and the gallery's patience. Broadcast closes with reluctant applause.");
|
||||
$"Contender {winnerId + 1:00} {(mapKind == ArenaMapKind.Sion ? "outlasts the alpine ring" : "outlasts the dust")} and the gallery's patience. Broadcast closes with reluctant applause.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -475,6 +475,26 @@ namespace RustToDust.Core
|
|||
return grid;
|
||||
}
|
||||
|
||||
public static int GetChassisUpgradeScore(ChassisSpec spec) => spec.Id.ToLowerInvariant() switch
|
||||
{
|
||||
"jackal" => 0,
|
||||
"hornet" => 1,
|
||||
"ferret" => 2,
|
||||
"kestrel" => 3,
|
||||
"mule" => 4,
|
||||
"condor" => 5,
|
||||
"raptor" => 6,
|
||||
"spectre" => 7,
|
||||
"manticore" => 8,
|
||||
"ironclad" => 9,
|
||||
"breaker" => 10,
|
||||
"mammoth" => 11,
|
||||
"paladin" => 12,
|
||||
"bastion" => 13,
|
||||
"anvil" => 14,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
public static ChassisGrid CreateWithDefaultLoadout(ChassisSpec spec)
|
||||
{
|
||||
var grid = new ChassisGrid(spec);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,214 @@ namespace RustToDust.Core
|
|||
{
|
||||
public delegate bool LineOfSightCheck(float ax, float ay, float az, float bx, float by, float bz);
|
||||
|
||||
public struct PhysicalAimTracker
|
||||
{
|
||||
public float AimYawWorld;
|
||||
public float AimPitchRad;
|
||||
public bool HasTarget;
|
||||
public int TargetId;
|
||||
public float EstPosX;
|
||||
public float EstPosY;
|
||||
public float EstPosZ;
|
||||
public float EstVelX;
|
||||
public float EstVelY;
|
||||
public float EstVelZ;
|
||||
public float PrevSampleX;
|
||||
public float PrevSampleY;
|
||||
public float PrevSampleZ;
|
||||
public bool HasPrevSample;
|
||||
public float DynamicSpreadRad;
|
||||
|
||||
public void Reset(float yaw)
|
||||
{
|
||||
AimYawWorld = MatchRules.NormalizeAngle(yaw);
|
||||
AimPitchRad = 0f;
|
||||
HasTarget = false;
|
||||
TargetId = -1;
|
||||
EstPosX = 0f;
|
||||
EstPosY = 0f;
|
||||
EstPosZ = 0f;
|
||||
EstVelX = 0f;
|
||||
EstVelY = 0f;
|
||||
EstVelZ = 0f;
|
||||
PrevSampleX = 0f;
|
||||
PrevSampleY = 0f;
|
||||
PrevSampleZ = 0f;
|
||||
HasPrevSample = false;
|
||||
DynamicSpreadRad = 0.012f;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AimTrackerHelper
|
||||
{
|
||||
private const float TauVel = 0.38f;
|
||||
private const float TauPos = 0.16f;
|
||||
|
||||
public static void StepTrackedAim(
|
||||
ref PhysicalAimTracker tracker,
|
||||
ChassisGrid shooterGrid,
|
||||
Vector3 shooterEyePos,
|
||||
float shooterYaw,
|
||||
float shooterSpeed,
|
||||
float shooterYawRate,
|
||||
ContenderState? target,
|
||||
float dt,
|
||||
out float aimX,
|
||||
out float aimY,
|
||||
out float aimZ,
|
||||
out bool wantFire,
|
||||
float maxFireRange = 165f)
|
||||
{
|
||||
float coreRatio = shooterGrid.MaxCoreHp > 0f
|
||||
? Math.Clamp(shooterGrid.CoreHp / shooterGrid.MaxCoreHp, 0f, 1f)
|
||||
: 1f;
|
||||
float healthRatio = 0.5f + 0.5f * coreRatio;
|
||||
var spec = shooterGrid.Spec;
|
||||
float yawDegS = Math.Clamp(185f - spec.MassKg * 0.022f, 65f, 165f) * healthRatio;
|
||||
float pitchDegS = Math.Clamp(135f - spec.MassKg * 0.015f, 52f, 120f) * healthRatio;
|
||||
const float degToRad = MathF.PI / 180f;
|
||||
float yawRadS = yawDegS * degToRad;
|
||||
float pitchRadS = pitchDegS * degToRad;
|
||||
float safeDt = MathF.Max(1e-4f, dt);
|
||||
|
||||
if (target is null)
|
||||
{
|
||||
tracker.HasTarget = false;
|
||||
tracker.TargetId = -1;
|
||||
tracker.HasPrevSample = false;
|
||||
tracker.EstVelX = 0f;
|
||||
tracker.EstVelY = 0f;
|
||||
tracker.EstVelZ = 0f;
|
||||
tracker.DynamicSpreadRad = 0.012f;
|
||||
|
||||
float yawDiff = MatchRules.NormalizeAngle(shooterYaw - tracker.AimYawWorld);
|
||||
float maxYawStep = yawRadS * 0.45f * safeDt;
|
||||
tracker.AimYawWorld = MatchRules.NormalizeAngle(
|
||||
tracker.AimYawWorld + Math.Clamp(yawDiff, -maxYawStep, maxYawStep));
|
||||
|
||||
float pitchDiff = 0f - tracker.AimPitchRad;
|
||||
float maxPitchStep = pitchRadS * 0.45f * safeDt;
|
||||
tracker.AimPitchRad = Math.Clamp(
|
||||
tracker.AimPitchRad + Math.Clamp(pitchDiff, -maxPitchStep, maxPitchStep),
|
||||
-1.25f,
|
||||
1.35f);
|
||||
|
||||
float cosP = MathF.Cos(tracker.AimPitchRad);
|
||||
Vector3 idleDir = new Vector3(
|
||||
MathF.Sin(tracker.AimYawWorld) * cosP,
|
||||
MathF.Sin(tracker.AimPitchRad),
|
||||
MathF.Cos(tracker.AimYawWorld) * cosP);
|
||||
Vector3 idlePt = shooterEyePos + idleDir * 25f;
|
||||
aimX = idlePt.X;
|
||||
aimY = idlePt.Y;
|
||||
aimZ = idlePt.Z;
|
||||
wantFire = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 targetPos = new Vector3(
|
||||
target.X,
|
||||
MatchRules.GetTargetAimY(target.Y, target.Grid.Spec.HalfHeight),
|
||||
target.Z);
|
||||
|
||||
if (!tracker.HasTarget || tracker.TargetId != target.Id || !tracker.HasPrevSample)
|
||||
{
|
||||
tracker.HasTarget = true;
|
||||
tracker.TargetId = target.Id;
|
||||
tracker.EstPosX = targetPos.X;
|
||||
tracker.EstPosY = targetPos.Y;
|
||||
tracker.EstPosZ = targetPos.Z;
|
||||
tracker.EstVelX = 0f;
|
||||
tracker.EstVelY = 0f;
|
||||
tracker.EstVelZ = 0f;
|
||||
tracker.PrevSampleX = targetPos.X;
|
||||
tracker.PrevSampleY = targetPos.Y;
|
||||
tracker.PrevSampleZ = targetPos.Z;
|
||||
tracker.HasPrevSample = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
float alphaVel = 1f - MathF.Exp(-safeDt / TauVel);
|
||||
float alphaPos = 1f - MathF.Exp(-safeDt / TauPos);
|
||||
Vector3 prevSample = new Vector3(tracker.PrevSampleX, tracker.PrevSampleY, tracker.PrevSampleZ);
|
||||
Vector3 rawObsVel = (targetPos - prevSample) / safeDt;
|
||||
Vector3 obsVel = new Vector3(
|
||||
Math.Clamp(rawObsVel.X, -70f, 70f),
|
||||
Math.Clamp(rawObsVel.Y, -70f, 70f),
|
||||
Math.Clamp(rawObsVel.Z, -70f, 70f));
|
||||
tracker.PrevSampleX = targetPos.X;
|
||||
tracker.PrevSampleY = targetPos.Y;
|
||||
tracker.PrevSampleZ = targetPos.Z;
|
||||
|
||||
Vector3 estVel = new Vector3(tracker.EstVelX, tracker.EstVelY, tracker.EstVelZ);
|
||||
estVel += (obsVel - estVel) * alphaVel;
|
||||
Vector3 estPos = new Vector3(tracker.EstPosX, tracker.EstPosY, tracker.EstPosZ);
|
||||
estPos = Vector3.Lerp(estPos + estVel * safeDt, targetPos, alphaPos);
|
||||
|
||||
tracker.EstVelX = estVel.X;
|
||||
tracker.EstVelY = estVel.Y;
|
||||
tracker.EstVelZ = estVel.Z;
|
||||
tracker.EstPosX = estPos.X;
|
||||
tracker.EstPosY = estPos.Y;
|
||||
tracker.EstPosZ = estPos.Z;
|
||||
}
|
||||
|
||||
Vector3 toActual = targetPos - shooterEyePos;
|
||||
float dist = toActual.Length();
|
||||
float leadTime = 0.22f * Math.Clamp(dist / 120f, 0f, 1f);
|
||||
Vector3 leadPos = new Vector3(tracker.EstPosX, tracker.EstPosY, tracker.EstPosZ) +
|
||||
new Vector3(tracker.EstVelX, tracker.EstVelY, tracker.EstVelZ) * leadTime;
|
||||
|
||||
Vector3 toLead = leadPos - shooterEyePos;
|
||||
float leadHoriz = MathF.Sqrt(toLead.X * toLead.X + toLead.Z * toLead.Z);
|
||||
float desiredYaw = leadHoriz > 1e-4f ? MathF.Atan2(toLead.X, toLead.Z) : tracker.AimYawWorld;
|
||||
float desiredPitch = Math.Clamp(MathF.Atan2(toLead.Y, MathF.Max(1e-3f, leadHoriz)), -1.25f, 1.35f);
|
||||
|
||||
float yawStep = yawRadS * safeDt;
|
||||
float yawErr = MatchRules.NormalizeAngle(desiredYaw - tracker.AimYawWorld);
|
||||
tracker.AimYawWorld = MatchRules.NormalizeAngle(
|
||||
tracker.AimYawWorld + Math.Clamp(yawErr, -yawStep, yawStep));
|
||||
|
||||
float pitchStep = pitchRadS * safeDt;
|
||||
float pitchErr = desiredPitch - tracker.AimPitchRad;
|
||||
tracker.AimPitchRad = Math.Clamp(
|
||||
tracker.AimPitchRad + Math.Clamp(pitchErr, -pitchStep, pitchStep),
|
||||
-1.25f,
|
||||
1.35f);
|
||||
|
||||
float cosPitch = MathF.Cos(tracker.AimPitchRad);
|
||||
Vector3 slewedDir = new Vector3(
|
||||
MathF.Sin(tracker.AimYawWorld) * cosPitch,
|
||||
MathF.Sin(tracker.AimPitchRad),
|
||||
MathF.Cos(tracker.AimYawWorld) * cosPitch);
|
||||
|
||||
float rayDist = MathF.Max(10f, dist);
|
||||
Vector3 aimPt = shooterEyePos + slewedDir * rayDist;
|
||||
aimX = aimPt.X;
|
||||
aimY = aimPt.Y;
|
||||
aimZ = aimPt.Z;
|
||||
|
||||
Vector3 actualDir = dist > 1e-4f ? toActual / dist : slewedDir;
|
||||
float angErr = MathF.Acos(Math.Clamp(Vector3.Dot(slewedDir, actualDir), -1f, 1f));
|
||||
|
||||
Vector3 targetVel = new Vector3(target.VelX, target.VelY, target.VelZ);
|
||||
if (targetVel.LengthSquared() < 1e-4f)
|
||||
{
|
||||
targetVel = new Vector3(tracker.EstVelX, tracker.EstVelY, tracker.EstVelZ);
|
||||
}
|
||||
Vector3 perpVel = targetVel - actualDir * Vector3.Dot(targetVel, actualDir);
|
||||
float vPerp = perpVel.Length();
|
||||
float crossOmega = vPerp / MathF.Max(8f, dist);
|
||||
|
||||
tracker.DynamicSpreadRad = Math.Clamp(
|
||||
0.012f + crossOmega * 0.18f + shooterSpeed * 0.0012f + MathF.Abs(shooterYawRate) * 0.032f,
|
||||
0.010f,
|
||||
0.145f);
|
||||
|
||||
wantFire = dist <= maxFireRange && angErr <= 0.24f;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MatchRules
|
||||
{
|
||||
public const float VtolMinClearanceAgl = 2.5f;
|
||||
|
|
@ -91,9 +299,6 @@ namespace RustToDust.Core
|
|||
float goalX = 0f;
|
||||
float goalZ = 0f;
|
||||
bool hasGoal = false;
|
||||
bool wantFire = false;
|
||||
float aimX = ai.X + MathF.Sin(ai.Yaw) * 25f;
|
||||
float aimZ = ai.Z + MathF.Cos(ai.Yaw) * 25f;
|
||||
|
||||
// 1. Stay inside the shrinking Safe Circle
|
||||
if (distFromCenter > safeLimit)
|
||||
|
|
@ -134,11 +339,19 @@ namespace RustToDust.Core
|
|||
}
|
||||
ai.AiTargetContenderId = target?.Id;
|
||||
|
||||
// 3. Scavenge nearby upgrades when safe
|
||||
// 3. Scavenge nearby chassis & module upgrades
|
||||
bool inStarter = string.Equals(ai.Grid.Spec.Id, "jackal", StringComparison.OrdinalIgnoreCase);
|
||||
if (!hasGoal && ai.AiScavengeCooldown <= 0f)
|
||||
{
|
||||
float scavengeRadius = (inStarter || CountMountedWeapons(ai.Grid) < 2)
|
||||
? (state.MapKind == ArenaMapKind.Sion ? 340f : 260f)
|
||||
: 140f;
|
||||
float scavengeRadiusSq = scavengeRadius * scavengeRadius;
|
||||
int currentUpgradeScore = Catalog.GetChassisUpgradeScore(ai.Grid.Spec);
|
||||
|
||||
GroundDrop? bestDrop = null;
|
||||
float bestDropDistSq = 85f * 85f;
|
||||
float bestDropScore = float.PositiveInfinity;
|
||||
float bestDropDistSq = float.PositiveInfinity;
|
||||
for (int d = 0; d < state.GroundDrops.Count; d++)
|
||||
{
|
||||
var drop = state.GroundDrops[d];
|
||||
|
|
@ -147,7 +360,8 @@ namespace RustToDust.Core
|
|||
continue;
|
||||
}
|
||||
|
||||
if (drop.Chassis is not null && drop.Chassis.MassKg <= ai.Grid.Spec.MassKg)
|
||||
if (drop.Chassis is not null &&
|
||||
Catalog.GetChassisUpgradeScore(drop.Chassis) <= currentUpgradeScore)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -155,8 +369,16 @@ namespace RustToDust.Core
|
|||
float dx = drop.X - ai.X;
|
||||
float dz = drop.Z - ai.Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 < bestDropDistSq)
|
||||
if (d2 > scavengeRadiusSq)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float dist = MathF.Sqrt(d2);
|
||||
float score = (inStarter && drop.Chassis is not null) ? dist * 0.45f : dist;
|
||||
if (score < bestDropScore)
|
||||
{
|
||||
bestDropScore = score;
|
||||
bestDropDistSq = d2;
|
||||
bestDrop = drop;
|
||||
}
|
||||
|
|
@ -164,9 +386,38 @@ namespace RustToDust.Core
|
|||
|
||||
if (bestDrop is not null)
|
||||
{
|
||||
goalX = bestDrop.X;
|
||||
goalZ = bestDrop.Z;
|
||||
hasGoal = true;
|
||||
bool pushScavenge;
|
||||
if (target is null)
|
||||
{
|
||||
pushScavenge = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
float enemyDist = MathF.Sqrt(bestEnemyDistSq);
|
||||
if (inStarter)
|
||||
{
|
||||
if (bestDrop.Chassis is not null)
|
||||
{
|
||||
float dropDist = MathF.Sqrt(bestDropDistSq);
|
||||
pushScavenge = dropDist < enemyDist * 0.85f || enemyDist > 65f;
|
||||
}
|
||||
else
|
||||
{
|
||||
pushScavenge = enemyDist > 65f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pushScavenge = enemyDist > 65f;
|
||||
}
|
||||
}
|
||||
|
||||
if (pushScavenge)
|
||||
{
|
||||
goalX = bestDrop.X;
|
||||
goalZ = bestDrop.Z;
|
||||
hasGoal = true;
|
||||
}
|
||||
|
||||
if (bestDropDistSq <= MatchState.PickupRadius * MatchState.PickupRadius)
|
||||
{
|
||||
|
|
@ -178,7 +429,7 @@ namespace RustToDust.Core
|
|||
{
|
||||
state.TrySwapNearbyChassis(ai.Id);
|
||||
}
|
||||
ai.AiScavengeCooldown = 2.5f;
|
||||
ai.AiScavengeCooldown = MathF.Max(ai.AiScavengeCooldown, 2.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -186,11 +437,7 @@ namespace RustToDust.Core
|
|||
// 4. Combat or third-party gunfire investigation
|
||||
if (target is not null)
|
||||
{
|
||||
aimX = target.X;
|
||||
aimZ = target.Z;
|
||||
float dist = MathF.Sqrt(bestEnemyDistSq);
|
||||
wantFire = dist <= 165f;
|
||||
|
||||
if (!hasGoal)
|
||||
{
|
||||
if (dist > 75f)
|
||||
|
|
@ -250,13 +497,44 @@ namespace RustToDust.Core
|
|||
{
|
||||
ai.VerticalThrottleCmd = 0f;
|
||||
}
|
||||
|
||||
float shooterYawRate = ai.SteerCmd * ai.Grid.ComputeTurnRate();
|
||||
AimTrackerHelper.StepTrackedAim(
|
||||
ref ai.AimTracker,
|
||||
ai.Grid,
|
||||
new Vector3(ai.X, aiEyeY, ai.Z),
|
||||
ai.Yaw,
|
||||
ai.Speed,
|
||||
shooterYawRate,
|
||||
target,
|
||||
dt,
|
||||
out float aimX,
|
||||
out float aimY,
|
||||
out float aimZ,
|
||||
out bool wantFire,
|
||||
maxFireRange: 165f);
|
||||
|
||||
ai.AimX = aimX;
|
||||
ai.AimY = target is not null ? GetTargetAimY(target.Y, target.Grid.Spec.HalfHeight) : float.NaN;
|
||||
ai.AimY = aimY;
|
||||
ai.AimZ = aimZ;
|
||||
ai.AiAimSpreadRad = ai.AimTracker.DynamicSpreadRad;
|
||||
ai.FireCmd = wantFire;
|
||||
}
|
||||
}
|
||||
|
||||
private static int CountMountedWeapons(ChassisGrid grid)
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < grid.Mounted.Count; i++)
|
||||
{
|
||||
if (grid.Mounted[i].Spec.Kind == HardpointKind.Weapon)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void ComputeSpectatorBehavior(
|
||||
SpectatorState spec,
|
||||
MatchState state,
|
||||
|
|
@ -264,11 +542,31 @@ namespace RustToDust.Core
|
|||
out float goalZ,
|
||||
out float aimX,
|
||||
out float aimZ,
|
||||
out bool shouldFire)
|
||||
out bool shouldFire,
|
||||
float dt = 1f / 60f)
|
||||
{
|
||||
float specEyeY = GetObserverEyeY(spec.Y, spec.Grid.Spec.HalfHeight);
|
||||
if (spec.Stance == SpectatorStance.Neutral || !spec.TargetContenderId.HasValue)
|
||||
{
|
||||
(goalX, goalZ) = state.Spectators.GetNeutralGoal(spec, state.Terrain, state.ArenaCoverBoxes, state.SionMap);
|
||||
AimTrackerHelper.StepTrackedAim(
|
||||
ref spec.AimTracker,
|
||||
spec.Grid,
|
||||
new Vector3(spec.X, specEyeY, spec.Z),
|
||||
spec.Yaw,
|
||||
0f,
|
||||
0f,
|
||||
target: null,
|
||||
dt,
|
||||
out float idleAimX,
|
||||
out float idleAimY,
|
||||
out float idleAimZ,
|
||||
out _);
|
||||
spec.AimX = idleAimX;
|
||||
spec.AimY = idleAimY;
|
||||
spec.AimZ = idleAimZ;
|
||||
spec.DynamicAimSpreadRad = spec.AimTracker.DynamicSpreadRad;
|
||||
spec.FireCmd = false;
|
||||
aimX = 0f;
|
||||
aimZ = 0f;
|
||||
shouldFire = false;
|
||||
|
|
@ -285,6 +583,24 @@ namespace RustToDust.Core
|
|||
if (target is null || !target.Alive)
|
||||
{
|
||||
(goalX, goalZ) = state.Spectators.GetNeutralGoal(spec, state.Terrain, state.ArenaCoverBoxes, state.SionMap);
|
||||
AimTrackerHelper.StepTrackedAim(
|
||||
ref spec.AimTracker,
|
||||
spec.Grid,
|
||||
new Vector3(spec.X, specEyeY, spec.Z),
|
||||
spec.Yaw,
|
||||
0f,
|
||||
0f,
|
||||
target: null,
|
||||
dt,
|
||||
out float idleAimX,
|
||||
out float idleAimY,
|
||||
out float idleAimZ,
|
||||
out _);
|
||||
spec.AimX = idleAimX;
|
||||
spec.AimY = idleAimY;
|
||||
spec.AimZ = idleAimZ;
|
||||
spec.DynamicAimSpreadRad = spec.AimTracker.DynamicSpreadRad;
|
||||
spec.FireCmd = false;
|
||||
aimX = 0f;
|
||||
aimZ = 0f;
|
||||
shouldFire = false;
|
||||
|
|
@ -298,8 +614,26 @@ namespace RustToDust.Core
|
|||
bool hasMemory = spec.TimeSinceLastSeen < SpectatorRing.TargetMemoryDuration;
|
||||
float focusX = spec.LastKnownTargetX;
|
||||
float focusZ = spec.LastKnownTargetZ;
|
||||
AimTrackerHelper.StepTrackedAim(
|
||||
ref spec.AimTracker,
|
||||
spec.Grid,
|
||||
new Vector3(spec.X, specEyeY, spec.Z),
|
||||
spec.Yaw,
|
||||
0f,
|
||||
0f,
|
||||
target: null,
|
||||
dt,
|
||||
out _,
|
||||
out float occAimY,
|
||||
out _,
|
||||
out _);
|
||||
spec.DynamicAimSpreadRad = spec.AimTracker.DynamicSpreadRad;
|
||||
spec.FireCmd = false;
|
||||
aimX = focusX;
|
||||
aimZ = focusZ;
|
||||
spec.AimX = aimX;
|
||||
spec.AimY = occAimY;
|
||||
spec.AimZ = aimZ;
|
||||
|
||||
if (!hasMemory)
|
||||
{
|
||||
|
|
@ -377,9 +711,6 @@ namespace RustToDust.Core
|
|||
return;
|
||||
}
|
||||
|
||||
aimX = target.X;
|
||||
aimZ = target.Z;
|
||||
|
||||
float dx = target.X - spec.X;
|
||||
float dz = target.Z - spec.Z;
|
||||
float dist = MathF.Sqrt(dx * dx + dz * dz);
|
||||
|
|
@ -396,7 +727,30 @@ namespace RustToDust.Core
|
|||
goalZ = target.Z + MathF.Sin(angle) * (spec.PreferredRange * 0.85f);
|
||||
}
|
||||
|
||||
shouldFire = dist <= 255f;
|
||||
float specSpeed = MathF.Sqrt(spec.VelX * spec.VelX + spec.VelZ * spec.VelZ);
|
||||
float desiredYaw = dist > 1e-3f ? MathF.Atan2(dx, dz) : spec.Yaw;
|
||||
float yawErr = NormalizeAngle(desiredYaw - spec.Yaw);
|
||||
float yawRate = Math.Clamp(yawErr * 3f, -5f, 5f);
|
||||
|
||||
AimTrackerHelper.StepTrackedAim(
|
||||
ref spec.AimTracker,
|
||||
spec.Grid,
|
||||
new Vector3(spec.X, specEyeY, spec.Z),
|
||||
spec.Yaw,
|
||||
specSpeed,
|
||||
yawRate,
|
||||
target,
|
||||
dt,
|
||||
out aimX,
|
||||
out float aimY,
|
||||
out aimZ,
|
||||
out shouldFire,
|
||||
maxFireRange: 255f);
|
||||
|
||||
spec.AimX = aimX;
|
||||
spec.AimY = aimY;
|
||||
spec.AimZ = aimZ;
|
||||
spec.DynamicAimSpreadRad = spec.AimTracker.DynamicSpreadRad;
|
||||
|
||||
// Tourists self-throttle when their Imperial weapons run hot
|
||||
if (shouldFire && spec.Tier == SpectatorTier.Tourist)
|
||||
|
|
@ -412,6 +766,8 @@ namespace RustToDust.Core
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
spec.FireCmd = shouldFire;
|
||||
}
|
||||
|
||||
public static void AdvanceTracers(MatchState state, float dt)
|
||||
|
|
@ -473,7 +829,7 @@ namespace RustToDust.Core
|
|||
if (aliveCount <= 1 && state.Player.Alive)
|
||||
{
|
||||
state.Phase = MatchPhase.Victory;
|
||||
state.Broadcast.EmitVictory(state.Time, state.Player.Id);
|
||||
state.Broadcast.EmitVictory(state.Time, state.Player.Id, state.MapKind);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace RustToDust.Core
|
||||
{
|
||||
|
|
@ -123,6 +124,13 @@ namespace RustToDust.Core
|
|||
AimX = x + MathF.Sin(yaw) * 20f;
|
||||
AimY = Y;
|
||||
AimZ = z + MathF.Cos(yaw) * 20f;
|
||||
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, yaw);
|
||||
CurrRotX = q.X;
|
||||
CurrRotY = q.Y;
|
||||
CurrRotZ = q.Z;
|
||||
CurrRotW = q.W;
|
||||
SnapPreviousPose();
|
||||
ResetAimTracker(yaw);
|
||||
}
|
||||
|
||||
public int Id { get; }
|
||||
|
|
@ -133,9 +141,25 @@ namespace RustToDust.Core
|
|||
public float Y { get; set; }
|
||||
public float Z { get; set; }
|
||||
public float Yaw { get; set; }
|
||||
public float PrevX { get; set; }
|
||||
public float PrevY { get; set; }
|
||||
public float PrevZ { get; set; }
|
||||
public float PrevRotX { get; set; }
|
||||
public float PrevRotY { get; set; }
|
||||
public float PrevRotZ { get; set; }
|
||||
public float PrevRotW { get; set; } = 1f;
|
||||
public float CurrRotX { get; set; }
|
||||
public float CurrRotY { get; set; }
|
||||
public float CurrRotZ { get; set; }
|
||||
public float CurrRotW { get; set; } = 1f;
|
||||
public float VelX { get; set; }
|
||||
public float VelY { get; set; }
|
||||
public float VelZ { get; set; }
|
||||
public float AimX { get; set; }
|
||||
public float AimY { get; set; }
|
||||
public float AimZ { get; set; }
|
||||
public PhysicalAimTracker AimTracker;
|
||||
public float AiAimSpreadRad { get; set; } = 0.012f;
|
||||
public float Speed { get; set; }
|
||||
public int Kills { get; set; }
|
||||
public bool OverheatWarned { get; set; }
|
||||
|
|
@ -154,6 +178,27 @@ namespace RustToDust.Core
|
|||
public int DisabledWeaponCount { get; set; }
|
||||
|
||||
public bool Alive => !Grid.IsDestroyed;
|
||||
|
||||
public void SnapPreviousPose()
|
||||
{
|
||||
PrevX = X;
|
||||
PrevY = Y;
|
||||
PrevZ = Z;
|
||||
PrevRotX = CurrRotX;
|
||||
PrevRotY = CurrRotY;
|
||||
PrevRotZ = CurrRotZ;
|
||||
PrevRotW = CurrRotW;
|
||||
}
|
||||
|
||||
public void ResetAimTracker(float yaw)
|
||||
{
|
||||
AimTracker.Reset(yaw);
|
||||
AiAimSpreadRad = AimTracker.DynamicSpreadRad;
|
||||
AimX = X + MathF.Sin(yaw) * 25f;
|
||||
AimY = Y;
|
||||
AimZ = Z + MathF.Cos(yaw) * 25f;
|
||||
FireCmd = false;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MatchState
|
||||
|
|
@ -502,55 +547,178 @@ namespace RustToDust.Core
|
|||
contender.VerticalThrottleCmd = 0f;
|
||||
contender.Y = Terrain.SampleHeight(contender.X, contender.Z) + contender.Grid.Spec.HalfHeight +
|
||||
(contender.Grid.Spec.IsVtol ? contender.TargetHoverAltAgl : 0.15f);
|
||||
contender.SnapPreviousPose();
|
||||
contender.ResetAimTracker(contender.Yaw);
|
||||
contender.AiScavengeCooldown = 4.0f;
|
||||
Broadcast.EmitChassisSwap(Time, contender.Id, contender.Grid.Spec.Name);
|
||||
ChassisSwapped?.Invoke(contender);
|
||||
return true;
|
||||
}
|
||||
|
||||
private float MinDistSqToPlacedContenders(float x, float z)
|
||||
{
|
||||
float minSq = float.PositiveInfinity;
|
||||
for (int k = 0; k < Contenders.Count; k++)
|
||||
{
|
||||
float dx = x - Contenders[k].X;
|
||||
float dz = z - Contenders[k].Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 < minSq)
|
||||
{
|
||||
minSq = d2;
|
||||
}
|
||||
}
|
||||
return minSq;
|
||||
}
|
||||
|
||||
private bool IsSionSpawnOccludedFromPlayer(ContenderState player, float cx, float cz, ChassisSpec spec)
|
||||
{
|
||||
float cY = Terrain.SampleHeight(cx, cz) + spec.HalfHeight + 0.15f;
|
||||
float pEyeY = MatchRules.GetObserverEyeY(player.Y, player.Grid.Spec.HalfHeight);
|
||||
float cAimY = MatchRules.GetTargetAimY(cY, spec.HalfHeight);
|
||||
float dx = cx - player.X;
|
||||
float dy = cAimY - pEyeY;
|
||||
float dz = cz - player.Z;
|
||||
float dist = MathF.Sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (dist <= 0.25f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
float invD = 1f / dist;
|
||||
float nx = dx * invD;
|
||||
float ny = dy * invD;
|
||||
float nz = dz * invD;
|
||||
if (Terrain.Raycast(player.X, pEyeY, player.Z, nx, ny, nz, MathF.Max(0.1f, dist - 0.5f), out _, out _, out _, out _))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return SionMap is not null && SionMap.IntersectsAnyBuildingAabb(player.X, pEyeY, player.Z, nx, ny, nz, dist);
|
||||
}
|
||||
|
||||
private bool IsNearCoverBox(float x, float z, float pad)
|
||||
{
|
||||
for (int i = 0; i < ArenaCoverBoxes.Count; i++)
|
||||
{
|
||||
var b = ArenaCoverBoxes[i];
|
||||
if (MathF.Abs(x - b.X) <= b.HalfX + pad && MathF.Abs(z - b.Z) <= b.HalfZ + pad)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SpawnContenders()
|
||||
{
|
||||
var aiRoster = new List<ChassisSpec>(Catalog.AllChassis);
|
||||
for (int k = aiRoster.Count - 1; k > 0; k--)
|
||||
{
|
||||
int j = Rng.Next(k + 1);
|
||||
(aiRoster[k], aiRoster[j]) = (aiRoster[j], aiRoster[k]);
|
||||
}
|
||||
const float minSepSq = 220f * 220f;
|
||||
|
||||
// Spawn 12 contenders (player + 11 AI) spread across r ~ 240..460m (well inside SafeRadius = 560m)
|
||||
// Equal-start: all 12 contenders (player + 11 AI) spawn in stock Jackals with >= 220m pairwise separation
|
||||
for (int i = 0; i < ContenderCount; i++)
|
||||
{
|
||||
float angle = (i / (float)ContenderCount) * MathF.Tau + (float)(Rng.NextDouble() - 0.5) * 0.16f;
|
||||
float baseR = 250f + (float)Rng.NextDouble() * 195f;
|
||||
float x = MathF.Cos(angle) * baseR;
|
||||
float z = MathF.Sin(angle) * baseR;
|
||||
float x = 0f;
|
||||
float z = 0f;
|
||||
float bestX = 0f;
|
||||
float bestZ = 0f;
|
||||
float bestMinDistSq = -1f;
|
||||
bool found = false;
|
||||
float sectorAngle = (i / (float)ContenderCount) * MathF.Tau;
|
||||
|
||||
// Nudge radially inside [240, 460] if landing on a steep mesa cliff edge
|
||||
for (int step = 0; step < 8; step++)
|
||||
for (int attempt = 0; attempt < 48; attempt++)
|
||||
{
|
||||
var (_, ny, _) = Terrain.SampleNormal(x, z);
|
||||
if (ny >= 0.88f)
|
||||
float angle = attempt < 8
|
||||
? sectorAngle + (float)(Rng.NextDouble() - 0.5) * (attempt == 0 ? 0.16f : 0.45f)
|
||||
: (float)(Rng.NextDouble() * MathF.Tau);
|
||||
float baseR = attempt < 24
|
||||
? (245f + (float)Rng.NextDouble() * 250f)
|
||||
: (380f + (float)Rng.NextDouble() * 115f);
|
||||
float cx = MathF.Cos(angle) * baseR;
|
||||
float cz = MathF.Sin(angle) * baseR;
|
||||
|
||||
// Nudge radially inside [245, 495] if landing on a slope, dune wall, or cover box
|
||||
for (int step = 0; step < 8; step++)
|
||||
{
|
||||
var (_, ny, _) = Terrain.SampleNormal(cx, cz);
|
||||
bool flatPatch = ny >= 0.96f &&
|
||||
Terrain.SampleNormal(cx + 10f, cz).Ny >= 0.93f &&
|
||||
Terrain.SampleNormal(cx - 10f, cz).Ny >= 0.93f &&
|
||||
Terrain.SampleNormal(cx, cz + 10f).Ny >= 0.93f &&
|
||||
Terrain.SampleNormal(cx, cz - 10f).Ny >= 0.93f;
|
||||
if (flatPatch && !IsNearCoverBox(cx, cz, 8f))
|
||||
{
|
||||
break;
|
||||
}
|
||||
float r = 245f + ((baseR - 245f + step * 31f) % 250f);
|
||||
cx = MathF.Cos(angle) * r;
|
||||
cz = MathF.Sin(angle) * r;
|
||||
}
|
||||
|
||||
if (IsNearCoverBox(cx, cz, 4f))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float minDistSq = MinDistSqToPlacedContenders(cx, cz);
|
||||
if (minDistSq > bestMinDistSq)
|
||||
{
|
||||
bestMinDistSq = minDistSq;
|
||||
bestX = cx;
|
||||
bestZ = cz;
|
||||
}
|
||||
if (minDistSq >= minSepSq)
|
||||
{
|
||||
x = cx;
|
||||
z = cz;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
float r = 245f + ((baseR - 245f + step * 28f) % 210f);
|
||||
x = MathF.Cos(angle) * r;
|
||||
z = MathF.Sin(angle) * r;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
for (int pass = 0; pass < 2 && !found; pass++)
|
||||
{
|
||||
float minNy = pass == 0 ? 0.88f : 0f;
|
||||
for (float r = 495f; r >= 245f && !found; r -= 15f)
|
||||
{
|
||||
for (int a = 0; a < 72; a++)
|
||||
{
|
||||
float ang = sectorAngle + (a / 72f) * MathF.Tau;
|
||||
float cx = MathF.Cos(ang) * r;
|
||||
float cz = MathF.Sin(ang) * r;
|
||||
if (minNy > 0f && Terrain.SampleNormal(cx, cz).Ny < minNy)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (IsNearCoverBox(cx, cz, 4f))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (MinDistSqToPlacedContenders(cx, cz) >= minSepSq)
|
||||
{
|
||||
x = cx;
|
||||
z = cz;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
x = bestX;
|
||||
z = bestZ;
|
||||
}
|
||||
|
||||
float yaw = MathF.Atan2(-x, -z);
|
||||
string name = i == 0 ? "Contender 01 (You)" : $"Contender {i + 1:00}";
|
||||
var grid = i == 0
|
||||
? Catalog.CreateStarterBuggy()
|
||||
: Catalog.CreateWithDefaultLoadout(aiRoster[(i - 1) % aiRoster.Count]);
|
||||
var grid = Catalog.CreateStarterBuggy();
|
||||
var contender = new ContenderState(i, name, i == 0, grid, x, z, yaw);
|
||||
if (grid.Spec.IsVtol)
|
||||
{
|
||||
contender.TargetHoverAltAgl = 10f;
|
||||
}
|
||||
contender.Y = Terrain.SampleHeight(x, z) + contender.Grid.Spec.HalfHeight +
|
||||
(grid.Spec.IsVtol ? contender.TargetHoverAltAgl : 0.15f);
|
||||
contender.Y = Terrain.SampleHeight(x, z) + contender.Grid.Spec.HalfHeight + 0.15f;
|
||||
contender.AimY = contender.Y;
|
||||
contender.SnapPreviousPose();
|
||||
contender.ResetAimTracker(yaw);
|
||||
Contenders.Add(contender);
|
||||
if (i > 0)
|
||||
{
|
||||
|
|
@ -682,17 +850,20 @@ namespace RustToDust.Core
|
|||
spec.Z = sz;
|
||||
spec.Y = Terrain.SampleHeight(sx, sz) + spec.Grid.Spec.HalfHeight + 0.15f;
|
||||
spec.Yaw = MathF.Atan2(-sx, -sz);
|
||||
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, spec.Yaw);
|
||||
spec.CurrRotX = q.X;
|
||||
spec.CurrRotY = q.Y;
|
||||
spec.CurrRotZ = q.Z;
|
||||
spec.CurrRotW = q.W;
|
||||
spec.SnapPreviousPose();
|
||||
spec.ResetAimTracker(spec.Yaw);
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnContendersSion()
|
||||
{
|
||||
var aiRoster = new List<ChassisSpec>(Catalog.AllChassis);
|
||||
for (int k = aiRoster.Count - 1; k > 0; k--)
|
||||
{
|
||||
int j = Rng.Next(k + 1);
|
||||
(aiRoster[k], aiRoster[j]) = (aiRoster[j], aiRoster[k]);
|
||||
}
|
||||
const float minSepSq = 220f * 220f;
|
||||
const float preferOccludedDistSq = 380f * 380f;
|
||||
|
||||
// Player starts in the open Sion Old Town / Rhone plaza facing Basilique de Valere & Chateau de Tourbillon.
|
||||
var playerGrid = Catalog.CreateStarterBuggy();
|
||||
|
|
@ -702,47 +873,114 @@ namespace RustToDust.Core
|
|||
var player = new ContenderState(0, "Contender 01 (You)", true, playerGrid, px, pz, pYaw);
|
||||
player.Y = Terrain.SampleHeight(px, pz) + playerGrid.Spec.HalfHeight + 0.15f;
|
||||
player.AimY = player.Y;
|
||||
player.SnapPreviousPose();
|
||||
player.ResetAimTracker(pYaw);
|
||||
Contenders.Add(player);
|
||||
|
||||
for (int i = 1; i < ContenderCount; i++)
|
||||
{
|
||||
var spec = aiRoster[(i - 1) % aiRoster.Count];
|
||||
var grid = Catalog.CreateWithDefaultLoadout(spec);
|
||||
float pad = MathF.Max(spec.HalfWidth, spec.HalfLength) + 2.0f;
|
||||
float minNy = spec.IsVtol ? 0f : 0.84f;
|
||||
var grid = Catalog.CreateStarterBuggy();
|
||||
float pad = MathF.Max(grid.Spec.HalfWidth, grid.Spec.HalfLength) + 2.0f;
|
||||
|
||||
float candX;
|
||||
float candZ;
|
||||
if (i <= 2)
|
||||
float x = 0f;
|
||||
float z = 0f;
|
||||
bool found = false;
|
||||
bool hasOpenCloseCandidate = false;
|
||||
float openCloseX = 0f;
|
||||
float openCloseZ = 0f;
|
||||
float bestFallbackX = 0f;
|
||||
float bestFallbackZ = 0f;
|
||||
float bestFallbackMinDistSq = -1f;
|
||||
|
||||
for (int attempt = 0; attempt < 48; attempt++)
|
||||
{
|
||||
// Put two visible rivals along the Old Town avenue ahead of the player so action is immediate.
|
||||
float fwdX = MathF.Sin(pYaw);
|
||||
float fwdZ = MathF.Cos(pYaw);
|
||||
float rightX = -fwdZ;
|
||||
float rightZ = fwdX;
|
||||
float dist = i == 1 ? 105f : 175f;
|
||||
float lat = i == 1 ? -18f : 28f;
|
||||
candX = px + fwdX * dist + rightX * lat;
|
||||
candZ = pz + fwdZ * dist + rightZ * lat;
|
||||
}
|
||||
else
|
||||
{
|
||||
float angle = ((i - 3) / (float)(ContenderCount - 3)) * MathF.Tau + (float)(Rng.NextDouble() - 0.5) * 0.25f;
|
||||
float r = 240f + (float)Rng.NextDouble() * 680f;
|
||||
candX = MathF.Cos(angle) * r;
|
||||
candZ = MathF.Sin(angle) * r;
|
||||
float angle = attempt == 0
|
||||
? ((i - 1) / (float)(ContenderCount - 1)) * MathF.Tau + (float)(Rng.NextDouble() - 0.5) * 0.25f
|
||||
: (float)(Rng.NextDouble() * MathF.Tau);
|
||||
float r = attempt < 24
|
||||
? (240f + (float)Rng.NextDouble() * 680f)
|
||||
: (440f + (float)Rng.NextDouble() * 480f);
|
||||
float candX = MathF.Cos(angle) * r;
|
||||
float candZ = MathF.Sin(angle) * r;
|
||||
|
||||
(float cx, float cz) = FindClearSionPoint(candX, candZ, pad, minNy: 0.84f, maxSearchRadius: 280f, avoidContenders: false);
|
||||
float minDistSq = MinDistSqToPlacedContenders(cx, cz);
|
||||
if (minDistSq > bestFallbackMinDistSq)
|
||||
{
|
||||
bestFallbackMinDistSq = minDistSq;
|
||||
bestFallbackX = cx;
|
||||
bestFallbackZ = cz;
|
||||
}
|
||||
if (minDistSq < minSepSq)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float playerDistSq = (cx - px) * (cx - px) + (cz - pz) * (cz - pz);
|
||||
if (playerDistSq >= preferOccludedDistSq || IsSionSpawnOccludedFromPlayer(player, cx, cz, grid.Spec))
|
||||
{
|
||||
x = cx;
|
||||
z = cz;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!hasOpenCloseCandidate)
|
||||
{
|
||||
openCloseX = cx;
|
||||
openCloseZ = cz;
|
||||
hasOpenCloseCandidate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
if (hasOpenCloseCandidate)
|
||||
{
|
||||
x = openCloseX;
|
||||
z = openCloseZ;
|
||||
found = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
float[] scanRadii = { 900f, 780f, 640f, 500f };
|
||||
for (int rIdx = 0; rIdx < scanRadii.Length && !found; rIdx++)
|
||||
{
|
||||
float r = scanRadii[rIdx];
|
||||
for (int a = 0; a < 36; a++)
|
||||
{
|
||||
float ang = (a / 36f) * MathF.Tau;
|
||||
(float cx, float cz) = FindClearSionPoint(
|
||||
MathF.Cos(ang) * r,
|
||||
MathF.Sin(ang) * r,
|
||||
pad,
|
||||
minNy: 0.84f,
|
||||
maxSearchRadius: 240f,
|
||||
avoidContenders: false);
|
||||
if (MinDistSqToPlacedContenders(cx, cz) >= minSepSq)
|
||||
{
|
||||
x = cx;
|
||||
z = cz;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
x = bestFallbackX;
|
||||
z = bestFallbackZ;
|
||||
}
|
||||
|
||||
(float x, float z) = FindClearSionPoint(candX, candZ, pad, minNy, maxSearchRadius: 280f, avoidContenders: true);
|
||||
float yaw = MathF.Atan2(-x, -z);
|
||||
var contender = new ContenderState(i, $"Contender {i + 1:00}", false, grid, x, z, yaw);
|
||||
if (spec.IsVtol)
|
||||
{
|
||||
contender.TargetHoverAltAgl = 10f;
|
||||
}
|
||||
contender.Y = Terrain.SampleHeight(x, z) + spec.HalfHeight +
|
||||
(spec.IsVtol ? contender.TargetHoverAltAgl : 0.15f);
|
||||
contender.Y = Terrain.SampleHeight(x, z) + grid.Spec.HalfHeight + 0.15f;
|
||||
contender.AimY = contender.Y;
|
||||
contender.SnapPreviousPose();
|
||||
contender.ResetAimTracker(yaw);
|
||||
Contenders.Add(contender);
|
||||
ContenderContacts[i] = new PlayerContactMemory();
|
||||
}
|
||||
|
|
@ -776,14 +1014,24 @@ namespace RustToDust.Core
|
|||
{
|
||||
int localIdx = i - (chassisPool.Count - 3);
|
||||
float localAng = pYaw + (localIdx - 1) * 0.65f;
|
||||
float localR = 26f + localIdx * 10f;
|
||||
float localR = 32f + localIdx * 14f;
|
||||
candX = p.X + MathF.Sin(localAng) * localR;
|
||||
candZ = p.Z + MathF.Cos(localAng) * localR;
|
||||
}
|
||||
else if (i < 3)
|
||||
{
|
||||
// 3 chassis drops within 110-190m of ring sectors on Sion
|
||||
float angle = (i / 3f) * MathF.Tau + 0.4f;
|
||||
float r = 120f + i * 32f;
|
||||
candX = MathF.Cos(angle) * r;
|
||||
candZ = MathF.Sin(angle) * r;
|
||||
}
|
||||
else
|
||||
{
|
||||
float angle = (i / (float)(chassisPool.Count - 3)) * MathF.Tau + 0.35f;
|
||||
float r = 180f + (i % 4) * 190f;
|
||||
int outerIdx = i - 3;
|
||||
int outerCount = chassisPool.Count - 6;
|
||||
float angle = (outerIdx / (float)Math.Max(1, outerCount)) * MathF.Tau + 0.35f;
|
||||
float r = 260f + (outerIdx % 4) * 185f;
|
||||
candX = MathF.Cos(angle) * r;
|
||||
candZ = MathF.Sin(angle) * r;
|
||||
}
|
||||
|
|
@ -809,13 +1057,23 @@ namespace RustToDust.Core
|
|||
if (i < 2)
|
||||
{
|
||||
float ang = pYaw + (i == 0 ? -0.4f : 0.4f);
|
||||
candX = p.X + MathF.Sin(ang) * 20f;
|
||||
candZ = p.Z + MathF.Cos(ang) * 20f;
|
||||
candX = p.X + MathF.Sin(ang) * 24f;
|
||||
candZ = p.Z + MathF.Cos(ang) * 24f;
|
||||
}
|
||||
else if (i < 6)
|
||||
{
|
||||
// Reachable crates within 110-190m of ring sectors on Sion
|
||||
float angle = ((i - 2) / 4f) * MathF.Tau + 0.25f;
|
||||
float r = 115f + (i - 2) * 22f;
|
||||
candX = MathF.Cos(angle) * r;
|
||||
candZ = MathF.Sin(angle) * r;
|
||||
}
|
||||
else
|
||||
{
|
||||
float angle = (i / (float)salvagePool.Length) * MathF.Tau + 0.19f;
|
||||
float r = 130f + (i % 5) * 180f;
|
||||
int outerIdx = i - 6;
|
||||
int outerCount = salvagePool.Length - 6;
|
||||
float angle = (outerIdx / (float)Math.Max(1, outerCount)) * MathF.Tau + 0.19f;
|
||||
float r = 240f + (outerIdx % 5) * 155f;
|
||||
candX = MathF.Cos(angle) * r;
|
||||
candZ = MathF.Sin(angle) * r;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace RustToDust.Core
|
||||
{
|
||||
|
|
@ -72,7 +73,51 @@ namespace RustToDust.Core
|
|||
public float Y { get; set; }
|
||||
public float Z { get; set; }
|
||||
public float Yaw { get; set; }
|
||||
|
||||
public float PrevX { get; set; }
|
||||
public float PrevY { get; set; }
|
||||
public float PrevZ { get; set; }
|
||||
public float PrevRotX { get; set; }
|
||||
public float PrevRotY { get; set; }
|
||||
public float PrevRotZ { get; set; }
|
||||
public float PrevRotW { get; set; } = 1f;
|
||||
public float CurrRotX { get; set; }
|
||||
public float CurrRotY { get; set; }
|
||||
public float CurrRotZ { get; set; }
|
||||
public float CurrRotW { get; set; } = 1f;
|
||||
public float VelX { get; set; }
|
||||
public float VelY { get; set; }
|
||||
public float VelZ { get; set; }
|
||||
|
||||
public PhysicalAimTracker AimTracker;
|
||||
public float DynamicAimSpreadRad { get; set; } = 0.012f;
|
||||
public float AimX { get; set; }
|
||||
public float AimY { get; set; }
|
||||
public float AimZ { get; set; }
|
||||
public bool FireCmd { get; set; }
|
||||
|
||||
public bool Alive => !Grid.IsDestroyed;
|
||||
|
||||
public void SnapPreviousPose()
|
||||
{
|
||||
PrevX = X;
|
||||
PrevY = Y;
|
||||
PrevZ = Z;
|
||||
PrevRotX = CurrRotX;
|
||||
PrevRotY = CurrRotY;
|
||||
PrevRotZ = CurrRotZ;
|
||||
PrevRotW = CurrRotW;
|
||||
}
|
||||
|
||||
public void ResetAimTracker(float yaw)
|
||||
{
|
||||
AimTracker.Reset(yaw);
|
||||
DynamicAimSpreadRad = AimTracker.DynamicSpreadRad;
|
||||
AimX = X + MathF.Sin(yaw) * 25f;
|
||||
AimY = Y;
|
||||
AimZ = Z + MathF.Cos(yaw) * 25f;
|
||||
FireCmd = false;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SpectatorRing
|
||||
|
|
@ -799,6 +844,13 @@ namespace RustToDust.Core
|
|||
spec.Y = spec.Grid.Spec.HalfHeight + 0.1f;
|
||||
spec.Z = pz;
|
||||
spec.Yaw = MathF.Atan2(-px, -pz);
|
||||
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, spec.Yaw);
|
||||
spec.CurrRotX = q.X;
|
||||
spec.CurrRotY = q.Y;
|
||||
spec.CurrRotZ = q.Z;
|
||||
spec.CurrRotW = q.W;
|
||||
spec.SnapPreviousPose();
|
||||
spec.ResetAimTracker(spec.Yaw);
|
||||
_spectators.Add(spec);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,11 @@ namespace RustToDust.Ymir
|
|||
{
|
||||
SpawnContenderBody(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.SnapPreviousPose();
|
||||
c.ResetAimTracker(c.Yaw);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSpectatorPose(int spectatorId, float x, float z, float? yaw = null)
|
||||
|
|
@ -120,6 +125,72 @@ namespace RustToDust.Ymir
|
|||
{
|
||||
SpawnSpectatorBody(index, spec);
|
||||
}
|
||||
else
|
||||
{
|
||||
spec.SnapPreviousPose();
|
||||
spec.ResetAimTracker(spec.Yaw);
|
||||
}
|
||||
}
|
||||
|
||||
public (Vector3 Pos, Quaternion Rot, Vector3 Vel) GetInterpolatedContenderPose(int contenderId, float alpha)
|
||||
{
|
||||
float t = Math.Clamp(alpha, 0f, 1f);
|
||||
if (contenderId < 0 || contenderId >= State.Contenders.Count)
|
||||
{
|
||||
return (Vector3.Zero, Quaternion.Identity, Vector3.Zero);
|
||||
}
|
||||
|
||||
var c = State.Contenders[contenderId];
|
||||
var prevPos = new Vector3(c.PrevX, c.PrevY, c.PrevZ);
|
||||
var currPos = new Vector3(c.X, c.Y, c.Z);
|
||||
var prevQ = new Quaternion(c.PrevRotX, c.PrevRotY, c.PrevRotZ, c.PrevRotW);
|
||||
var currQ = new Quaternion(c.CurrRotX, c.CurrRotY, c.CurrRotZ, c.CurrRotW);
|
||||
prevQ = prevQ.LengthSquared() < 1e-6f ? Quaternion.Identity : Quaternion.Normalize(prevQ);
|
||||
currQ = currQ.LengthSquared() < 1e-6f ? Quaternion.Identity : Quaternion.Normalize(currQ);
|
||||
if (Quaternion.Dot(prevQ, currQ) < 0f)
|
||||
{
|
||||
currQ = -currQ;
|
||||
}
|
||||
|
||||
return (
|
||||
Vector3.Lerp(prevPos, currPos, t),
|
||||
Quaternion.Slerp(prevQ, currQ, t),
|
||||
new Vector3(c.VelX, c.VelY, c.VelZ));
|
||||
}
|
||||
|
||||
public (Vector3 Pos, Quaternion Rot, Vector3 Vel) GetInterpolatedSpectatorPose(int spectatorId, float alpha)
|
||||
{
|
||||
float t = Math.Clamp(alpha, 0f, 1f);
|
||||
SpectatorState? spec = null;
|
||||
var list = State.Spectators.Spectators;
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (list[i].Id == spectatorId)
|
||||
{
|
||||
spec = list[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (spec is null)
|
||||
{
|
||||
return (Vector3.Zero, Quaternion.Identity, Vector3.Zero);
|
||||
}
|
||||
|
||||
var prevPos = new Vector3(spec.PrevX, spec.PrevY, spec.PrevZ);
|
||||
var currPos = new Vector3(spec.X, spec.Y, spec.Z);
|
||||
var prevQ = new Quaternion(spec.PrevRotX, spec.PrevRotY, spec.PrevRotZ, spec.PrevRotW);
|
||||
var currQ = new Quaternion(spec.CurrRotX, spec.CurrRotY, spec.CurrRotZ, spec.CurrRotW);
|
||||
prevQ = prevQ.LengthSquared() < 1e-6f ? Quaternion.Identity : Quaternion.Normalize(prevQ);
|
||||
currQ = currQ.LengthSquared() < 1e-6f ? Quaternion.Identity : Quaternion.Normalize(currQ);
|
||||
if (Quaternion.Dot(prevQ, currQ) < 0f)
|
||||
{
|
||||
currQ = -currQ;
|
||||
}
|
||||
|
||||
return (
|
||||
Vector3.Lerp(prevPos, currPos, t),
|
||||
Quaternion.Slerp(prevQ, currQ, t),
|
||||
new Vector3(spec.VelX, spec.VelY, spec.VelZ));
|
||||
}
|
||||
|
||||
public bool HasLineOfSight(float ax, float ay, float az, float bx, float by, float bz)
|
||||
|
|
@ -229,10 +300,24 @@ namespace RustToDust.Ymir
|
|||
return tMax >= tMin;
|
||||
}
|
||||
|
||||
private void SnapshotPreviousPoses()
|
||||
{
|
||||
for (int i = 0; i < State.Contenders.Count; i++)
|
||||
{
|
||||
State.Contenders[i].SnapPreviousPose();
|
||||
}
|
||||
for (int i = 0; i < State.Spectators.Spectators.Count; i++)
|
||||
{
|
||||
State.Spectators.Spectators[i].SnapPreviousPose();
|
||||
}
|
||||
}
|
||||
|
||||
public void Step(PlayerInput input)
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
SnapshotPreviousPoses();
|
||||
|
||||
State.Time += FixedDt;
|
||||
MatchRules.AdvanceTracers(State, FixedDt);
|
||||
MatchRules.AdvanceHitEvents(State, FixedDt);
|
||||
|
|
@ -397,6 +482,15 @@ namespace RustToDust.Ymir
|
|||
|
||||
_contenderBodies[c.Id] = handle;
|
||||
_entityByStableId[stableId] = (true, c.Id);
|
||||
c.CurrRotX = q.X;
|
||||
c.CurrRotY = q.Y;
|
||||
c.CurrRotZ = q.Z;
|
||||
c.CurrRotW = q.W;
|
||||
c.VelX = 0f;
|
||||
c.VelY = 0f;
|
||||
c.VelZ = 0f;
|
||||
c.SnapPreviousPose();
|
||||
c.ResetAimTracker(c.Yaw);
|
||||
}
|
||||
|
||||
private void OnContenderChassisSwapped(ContenderState c)
|
||||
|
|
@ -410,6 +504,11 @@ namespace RustToDust.Ymir
|
|||
{
|
||||
SpawnContenderBody(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.SnapPreviousPose();
|
||||
c.ResetAimTracker(c.Yaw);
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnSpectatorBodies()
|
||||
|
|
@ -441,6 +540,15 @@ namespace RustToDust.Ymir
|
|||
|
||||
_spectatorBodies[s.Id] = handle;
|
||||
_entityByStableId[stableId] = (false, index);
|
||||
s.CurrRotX = q.X;
|
||||
s.CurrRotY = q.Y;
|
||||
s.CurrRotZ = q.Z;
|
||||
s.CurrRotW = q.W;
|
||||
s.VelX = 0f;
|
||||
s.VelY = 0f;
|
||||
s.VelZ = 0f;
|
||||
s.SnapPreviousPose();
|
||||
s.ResetAimTracker(s.Yaw);
|
||||
}
|
||||
|
||||
private void UpdateRingClearance()
|
||||
|
|
@ -626,7 +734,7 @@ namespace RustToDust.Ymir
|
|||
continue;
|
||||
}
|
||||
|
||||
MatchRules.ComputeSpectatorBehavior(s, State, out float goalX, out float goalZ, out float aimX, out float aimZ, out _);
|
||||
MatchRules.ComputeSpectatorBehavior(s, State, out float goalX, out float goalZ, out float aimX, out float aimZ, out _, FixedDt);
|
||||
|
||||
var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
|
|
@ -1097,11 +1205,19 @@ namespace RustToDust.Ymir
|
|||
c.X = view.PositionX[lane];
|
||||
c.Y = view.PositionY[lane];
|
||||
c.Z = view.PositionZ[lane];
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
c.CurrRotX = view.RotationX[lane];
|
||||
c.CurrRotY = view.RotationY[lane];
|
||||
c.CurrRotZ = view.RotationZ[lane];
|
||||
c.CurrRotW = view.RotationW[lane];
|
||||
var q = new Quaternion(c.CurrRotX, c.CurrRotY, c.CurrRotZ, c.CurrRotW);
|
||||
var forward = Vector3.Transform(Vector3.UnitZ, q);
|
||||
c.Yaw = MathF.Atan2(forward.X, forward.Z);
|
||||
float vx = view.VelocityX[lane];
|
||||
float vy = view.VelocityY[lane];
|
||||
float vz = view.VelocityZ[lane];
|
||||
c.VelX = vx;
|
||||
c.VelY = vy;
|
||||
c.VelZ = vz;
|
||||
c.Speed = MathF.Sqrt(vx * vx + vz * vz);
|
||||
|
||||
float stepDist = MathF.Sqrt((c.X - prevX) * (c.X - prevX) + (c.Z - prevZ) * (c.Z - prevZ));
|
||||
|
|
@ -1129,7 +1245,14 @@ namespace RustToDust.Ymir
|
|||
s.X = view.PositionX[lane];
|
||||
s.Y = view.PositionY[lane];
|
||||
s.Z = view.PositionZ[lane];
|
||||
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||
s.CurrRotX = view.RotationX[lane];
|
||||
s.CurrRotY = view.RotationY[lane];
|
||||
s.CurrRotZ = view.RotationZ[lane];
|
||||
s.CurrRotW = view.RotationW[lane];
|
||||
s.VelX = view.VelocityX[lane];
|
||||
s.VelY = view.VelocityY[lane];
|
||||
s.VelZ = view.VelocityZ[lane];
|
||||
var q = new Quaternion(s.CurrRotX, s.CurrRotY, s.CurrRotZ, s.CurrRotW);
|
||||
var forward = Vector3.Transform(Vector3.UnitZ, q);
|
||||
s.Yaw = MathF.Atan2(forward.X, forward.Z);
|
||||
}
|
||||
|
|
@ -1353,7 +1476,7 @@ namespace RustToDust.Ymir
|
|||
aimX: c.AimX,
|
||||
aimY: c.AimY,
|
||||
aimZ: c.AimZ,
|
||||
extraSpread: 0f,
|
||||
extraSpread: c.IsPlayer ? 0f : c.AiAimSpreadRad,
|
||||
view: view);
|
||||
}
|
||||
|
||||
|
|
@ -1366,13 +1489,7 @@ namespace RustToDust.Ymir
|
|||
for (int i = 0; i < State.Spectators.Spectators.Count; i++)
|
||||
{
|
||||
var s = State.Spectators.Spectators[i];
|
||||
if (!s.Alive || s.Stance == SpectatorStance.Neutral || !_spectatorBodies.TryGetValue(s.Id, out var specHandle))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
MatchRules.ComputeSpectatorBehavior(s, State, out _, out _, out float aimX, out float aimZ, out bool shouldFire);
|
||||
if (!shouldFire)
|
||||
if (!s.Alive || s.Stance == SpectatorStance.Neutral || !s.FireCmd || !_spectatorBodies.TryGetValue(s.Id, out var specHandle))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1393,10 +1510,10 @@ namespace RustToDust.Ymir
|
|||
shooterPos: new Vector3(s.X, s.Y, s.Z),
|
||||
shooterYaw: s.Yaw,
|
||||
shooterQuat: specQuat,
|
||||
aimX: aimX,
|
||||
aimY: float.NaN,
|
||||
aimZ: aimZ,
|
||||
extraSpread: s.AimSpreadRad,
|
||||
aimX: s.AimX,
|
||||
aimY: s.AimY,
|
||||
aimZ: s.AimZ,
|
||||
extraSpread: s.AimSpreadRad + s.DynamicAimSpreadRad,
|
||||
view: view);
|
||||
}
|
||||
}
|
||||
|
|
@ -1606,15 +1723,11 @@ namespace RustToDust.Ymir
|
|||
float aimX,
|
||||
float aimZ)
|
||||
{
|
||||
Vector3 horizDir = new Vector3(aimX - shooterPos.X, 0f, aimZ - shooterPos.Z);
|
||||
if (horizDir.LengthSquared() < 1e-3f)
|
||||
{
|
||||
horizDir = Vector3.UnitZ;
|
||||
}
|
||||
else
|
||||
{
|
||||
horizDir = Vector3.Normalize(horizDir);
|
||||
}
|
||||
Vector3 aimFromCenter = new Vector3(aimX - shooterPos.X, 0f, aimZ - shooterPos.Z);
|
||||
float aimLen = aimFromCenter.Length();
|
||||
Vector3 horizDir = aimLen < 1e-3f
|
||||
? new Vector3(MathF.Sin(shooterYaw), 0f, MathF.Cos(shooterYaw))
|
||||
: aimFromCenter / aimLen;
|
||||
|
||||
float cosYaw = MathF.Cos(shooterYaw);
|
||||
float sinYaw = MathF.Sin(shooterYaw);
|
||||
|
|
@ -1625,10 +1738,14 @@ namespace RustToDust.Ymir
|
|||
MathF.Abs(localDirZ) * spec.HalfLength +
|
||||
0.35f;
|
||||
|
||||
float muzzleClearance = aimLen < clearance + 0.45f
|
||||
? MathF.Min(clearance, MathF.Max(0.25f, aimLen - 0.45f))
|
||||
: clearance;
|
||||
|
||||
return new Vector3(
|
||||
shooterPos.X + horizDir.X * clearance,
|
||||
shooterPos.X + horizDir.X * muzzleClearance,
|
||||
shooterPos.Y + spec.HalfHeight * 0.25f,
|
||||
shooterPos.Z + horizDir.Z * clearance);
|
||||
shooterPos.Z + horizDir.Z * muzzleClearance);
|
||||
}
|
||||
|
||||
private void FireSingleWeapon(
|
||||
|
|
@ -1694,12 +1811,36 @@ namespace RustToDust.Ymir
|
|||
float pitchJitter = ((float)State.Rng.NextDouble() * 2f - 1f) * (totalSpread * 0.35f);
|
||||
var dir = ApplyAimSpread(baseAim, yawJitter, pitchJitter);
|
||||
|
||||
var hit = _world.CastRayClosest(
|
||||
(muzzle.X, muzzle.Y, muzzle.Z),
|
||||
(dir.X * range, dir.Y * range, dir.Z * range));
|
||||
Vector3 castOrigin = muzzle;
|
||||
float remainingRange = range;
|
||||
bool hitAny = false;
|
||||
ulong hitStableId = 0;
|
||||
(float X, float Y, float Z) hitPoint = default;
|
||||
for (int hop = 0; hop < 4 && remainingRange > 0.2f; hop++)
|
||||
{
|
||||
var rayHit = _world.CastRayClosest(
|
||||
(castOrigin.X, castOrigin.Y, castOrigin.Z),
|
||||
(dir.X * remainingRange, dir.Y * remainingRange, dir.Z * remainingRange));
|
||||
if (!rayHit.Hit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (rayHit.StableId != shooterStableId)
|
||||
{
|
||||
hitAny = true;
|
||||
hitStableId = rayHit.StableId;
|
||||
hitPoint = rayHit.Point;
|
||||
break;
|
||||
}
|
||||
|
||||
float boxDist = hit.Hit
|
||||
? Vector3.Distance(muzzle, new Vector3(hit.Point.X, hit.Point.Y, hit.Point.Z))
|
||||
var selfPt = new Vector3(rayHit.Point.X, rayHit.Point.Y, rayHit.Point.Z);
|
||||
float skip = MathF.Max(0.15f, Vector3.Distance(castOrigin, selfPt) + 0.08f);
|
||||
castOrigin += dir * skip;
|
||||
remainingRange = MathF.Max(0f, remainingRange - skip);
|
||||
}
|
||||
|
||||
float boxDist = hitAny
|
||||
? Vector3.Distance(muzzle, new Vector3(hitPoint.X, hitPoint.Y, hitPoint.Z))
|
||||
: range;
|
||||
|
||||
bool hitTerrain = State.Terrain.Raycast(
|
||||
|
|
@ -1736,15 +1877,15 @@ namespace RustToDust.Ymir
|
|||
}
|
||||
else
|
||||
{
|
||||
endPt = hit.Hit
|
||||
? new Vector3(hit.Point.X, hit.Point.Y, hit.Point.Z)
|
||||
endPt = hitAny
|
||||
? new Vector3(hitPoint.X, hitPoint.Y, hitPoint.Z)
|
||||
: muzzle + dir * range;
|
||||
|
||||
if (hit.Hit && hit.StableId != shooterStableId && _entityByStableId.TryGetValue(hit.StableId, out var targetRef))
|
||||
if (hitAny && hitStableId != shooterStableId && _entityByStableId.TryGetValue(hitStableId, out var targetRef))
|
||||
{
|
||||
ApplyHitToTarget(
|
||||
targetRef,
|
||||
hit.Point,
|
||||
hitPoint,
|
||||
dir,
|
||||
shooterPos,
|
||||
weaponClass,
|
||||
|
|
@ -1757,7 +1898,7 @@ namespace RustToDust.Ymir
|
|||
isSpectatorShooter,
|
||||
view);
|
||||
}
|
||||
else if (hit.Hit && hit.StableId != shooterStableId)
|
||||
else if (hitAny && hitStableId != shooterStableId)
|
||||
{
|
||||
// Static cover box hit
|
||||
Vector3 rev = -dir;
|
||||
|
|
@ -1773,7 +1914,7 @@ namespace RustToDust.Ymir
|
|||
SourceY: shooterPos.Y,
|
||||
SourceZ: shooterPos.Z,
|
||||
TargetKind: HitTargetKind.StaticCover,
|
||||
TargetId: (int)hit.StableId,
|
||||
TargetId: (int)hitStableId,
|
||||
CellX: 0,
|
||||
CellY: 0,
|
||||
WeaponClass: weaponClass,
|
||||
|
|
|
|||
|
|
@ -452,9 +452,14 @@ namespace RustToDust.Tests
|
|||
// Test breaking LOS across multiple step-tick phases (would catch any % 3 stagger!)
|
||||
for (int phase = 0; phase < 3; phase++)
|
||||
{
|
||||
// Place both on the same open side of the cover box within firing range (< 165m)
|
||||
session.SetContenderPose(ai.Id, box.X, box.Z - box.HalfZ - 14f, yaw: 0f);
|
||||
session.SetContenderPose(player.Id, box.X + 18f, box.Z - box.HalfZ - 14f, yaw: 0f);
|
||||
// Place both on the same open side of the cover box within firing range (< 165m), AI facing player
|
||||
float openAiX = box.X;
|
||||
float openAiZ = box.Z - box.HalfZ - 14f;
|
||||
float openPlayerX = box.X + 18f;
|
||||
float openPlayerZ = box.Z - box.HalfZ - 14f;
|
||||
float facePlayerYaw = MathF.Atan2(openPlayerX - openAiX, openPlayerZ - openAiZ);
|
||||
session.SetContenderPose(ai.Id, openAiX, openAiZ, yaw: facePlayerYaw);
|
||||
session.SetContenderPose(player.Id, openPlayerX, openPlayerZ, yaw: 0f);
|
||||
|
||||
// Advance `phase` ticks in open LOS; open-LOS acquisition must be immediate on tick 0!
|
||||
for (int t = 0; t <= phase; t++)
|
||||
|
|
|
|||
456
tests/RustToDust.Tests/PlaytestFixesTests.cs
Normal file
456
tests/RustToDust.Tests/PlaytestFixesTests.cs
Normal file
|
|
@ -0,0 +1,456 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using RustToDust.Core;
|
||||
using RustToDust.Ymir;
|
||||
using Xunit;
|
||||
|
||||
namespace RustToDust.Tests
|
||||
{
|
||||
public sealed class PlaytestFixesTests
|
||||
{
|
||||
private static void IsolateContenders(ArenaSession session, params int[] keepIds)
|
||||
{
|
||||
var keep = keepIds.ToHashSet();
|
||||
for (int i = 0; i < session.State.Contenders.Count; i++)
|
||||
{
|
||||
var c = session.State.Contenders[i];
|
||||
if (!keep.Contains(c.Id))
|
||||
{
|
||||
session.SetContenderPose(c.Id, -680f + i * 10f, -680f);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < session.State.Spectators.Spectators.Count; i++)
|
||||
{
|
||||
var s = session.State.Spectators.Spectators[i];
|
||||
session.SetSpectatorPose(s.Id, 680f, -680f + i * 4f);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EqualStart_DesertAndSion_AllContendersStartJackal_MinSpacing220m_NoTick0Ambush()
|
||||
{
|
||||
int[] seeds = { 12, 42, 77 };
|
||||
ArenaMapKind[] maps = { ArenaMapKind.Desert, ArenaMapKind.Sion };
|
||||
|
||||
foreach (var map in maps)
|
||||
{
|
||||
foreach (int seed in seeds)
|
||||
{
|
||||
using var session = new ArenaSession(seed, map);
|
||||
var state = session.State;
|
||||
Assert.Equal(MatchState.ContenderCount, state.Contenders.Count);
|
||||
|
||||
// 1. Every contender (player + 11 AI) starts in stock Jackal with starter loadout
|
||||
for (int i = 0; i < state.Contenders.Count; i++)
|
||||
{
|
||||
var c = state.Contenders[i];
|
||||
Assert.Equal(Catalog.Jackal.Id, c.Grid.Spec.Id);
|
||||
Assert.NotNull(c.Grid.GetMountedOn("hp.weapon.roof"));
|
||||
Assert.NotNull(c.Grid.GetMountedOn("hp.engine.rear"));
|
||||
Assert.NotNull(c.Grid.GetMountedOn("hp.radiator.rear"));
|
||||
}
|
||||
|
||||
// 2. Pairwise minimum separation >= 220m across all 12 contenders
|
||||
for (int i = 0; i < state.Contenders.Count; i++)
|
||||
{
|
||||
for (int j = i + 1; j < state.Contenders.Count; j++)
|
||||
{
|
||||
var a = state.Contenders[i];
|
||||
var b = state.Contenders[j];
|
||||
float dx = a.X - b.X;
|
||||
float dz = a.Z - b.Z;
|
||||
float dist = MathF.Sqrt(dx * dx + dz * dz);
|
||||
Assert.True(dist >= 220f,
|
||||
$"Map={map}, Seed={seed}: Contenders {a.Id} and {b.Id} spawned too close ({dist:F1}m < 220m)");
|
||||
}
|
||||
}
|
||||
|
||||
// 3. All 14 non-Jackal chassis drops exist in GroundDrops
|
||||
var droppedChassisIds = state.GroundDrops
|
||||
.Where(d => d.Chassis is not null)
|
||||
.Select(d => d.Chassis!.Id)
|
||||
.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var spec in Catalog.AllChassis)
|
||||
{
|
||||
if (!string.Equals(spec.Id, Catalog.Jackal.Id, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Assert.Contains(spec.Id, droppedChassisIds);
|
||||
}
|
||||
}
|
||||
|
||||
if (map == ArenaMapKind.Sion)
|
||||
{
|
||||
int nearRingDrops = state.GroundDrops.Count(d =>
|
||||
{
|
||||
float r = MathF.Sqrt(d.X * d.X + d.Z * d.Z);
|
||||
return r >= 110f && r <= 190f;
|
||||
});
|
||||
Assert.True(nearRingDrops >= 3,
|
||||
$"Sion Seed={seed}: Expected >= 3 reachable drops within 110-190m ring sector, got {nearRingDrops}");
|
||||
}
|
||||
|
||||
// 4. Zero tick-0 spawn ambush
|
||||
var player = state.Player;
|
||||
float initialHp = player.Grid.CoreHp;
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 10f, false, false, true));
|
||||
|
||||
for (int i = 1; i < state.Contenders.Count; i++)
|
||||
{
|
||||
var ai = state.Contenders[i];
|
||||
Assert.False(ai.FireCmd, $"Map={map}, Seed={seed}: AI {ai.Id} fired on tick 0!");
|
||||
}
|
||||
Assert.Equal(initialHp, player.Grid.CoreHp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AiScavenge_JackalMovesTowardAndSwapsIntoHornetAndMechDrops()
|
||||
{
|
||||
// Part A: AI Jackal (950 kg) must pick up Hornet (820 kg) via GetChassisUpgradeScore (> 0)
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert);
|
||||
IsolateContenders(session, 0, 1);
|
||||
var player = session.State.Player;
|
||||
var ai = session.State.Contenders[1];
|
||||
|
||||
// Clear unrelated drops so Hornet is the clean target
|
||||
foreach (var d in session.State.GroundDrops)
|
||||
{
|
||||
d.PickedUp = true;
|
||||
}
|
||||
|
||||
session.SetContenderPose(player.Id, -450f, -450f, yaw: 0f);
|
||||
session.SetContenderPose(ai.Id, 0f, 0f, yaw: 0f);
|
||||
ai.AiScavengeCooldown = 0f;
|
||||
|
||||
session.State.SpawnChassisDrop(0f, 45f, Catalog.Hornet);
|
||||
Assert.True(Catalog.GetChassisUpgradeScore(Catalog.Hornet) > Catalog.GetChassisUpgradeScore(Catalog.Jackal));
|
||||
|
||||
for (int tick = 0; tick < 240 && ai.Grid.Spec.Id == Catalog.Jackal.Id; tick++)
|
||||
{
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
}
|
||||
|
||||
Assert.Equal(Catalog.Hornet.Id, ai.Grid.Spec.Id);
|
||||
}
|
||||
|
||||
// Part B: AI Jackal picks up heavy mech drop (Breaker)
|
||||
{
|
||||
using var session = new ArenaSession(seed: 77, ArenaMapKind.Desert);
|
||||
IsolateContenders(session, 0, 1);
|
||||
var player = session.State.Player;
|
||||
var ai = session.State.Contenders[1];
|
||||
|
||||
foreach (var d in session.State.GroundDrops)
|
||||
{
|
||||
d.PickedUp = true;
|
||||
}
|
||||
|
||||
session.SetContenderPose(player.Id, -450f, -450f, yaw: 0f);
|
||||
session.SetContenderPose(ai.Id, 0f, 0f, yaw: 0f);
|
||||
ai.AiScavengeCooldown = 0f;
|
||||
|
||||
session.State.SpawnChassisDrop(0f, 48f, Catalog.Breaker);
|
||||
for (int tick = 0; tick < 240 && ai.Grid.Spec.Id == Catalog.Jackal.Id; tick++)
|
||||
{
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
}
|
||||
|
||||
Assert.Equal(Catalog.Breaker.Id, ai.Grid.Spec.Id);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NaturalizedBotAim_OffAxisSlewAndJinkOvershoot_ZeroOccludedLeak()
|
||||
{
|
||||
// 1. 90-degree off-axis slew delay
|
||||
using (var session = new ArenaSession(seed: 42, ArenaMapKind.Desert))
|
||||
{
|
||||
IsolateContenders(session, 0, 1);
|
||||
var player = session.State.Player;
|
||||
var ai = session.State.Contenders[1];
|
||||
|
||||
// Place AI facing +Z (yaw = 0) and player 60m due +X (90 degrees off-axis) in open LOS
|
||||
session.SetContenderPose(ai.Id, 0f, 0f, yaw: 0f);
|
||||
session.SetContenderPose(player.Id, 60f, 0f, yaw: 0f);
|
||||
ai.AiScavengeCooldown = 999f;
|
||||
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
Assert.Equal(player.Id, ai.AiTargetContenderId);
|
||||
Assert.False(ai.FireCmd, "90-degree off-axis AI must not snap-fire on tick 0 before slewing into cone");
|
||||
|
||||
bool eventuallyFired = false;
|
||||
for (int t = 0; t < 75; t++)
|
||||
{
|
||||
session.SetContenderPose(player.Id, 60f, 0f, yaw: 0f);
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
if (ai.FireCmd)
|
||||
{
|
||||
eventuallyFired = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.True(eventuallyFired, "AI must acquire and fire after slewing onto 90-degree off-axis target");
|
||||
}
|
||||
|
||||
// 2. Lateral jink overshoot > 2.5m at 70m + dynamic spread scaling with crossing angular rate
|
||||
{
|
||||
const float dt = 1f / 60f;
|
||||
var shooterGrid = Catalog.CreateStarterBuggy();
|
||||
var targetGrid = Catalog.CreateStarterBuggy();
|
||||
var target = new ContenderState(9, "Jinker", false, targetGrid, 0f, 70f, 0f);
|
||||
target.Y = 1.5f;
|
||||
|
||||
var tracker = new PhysicalAimTracker();
|
||||
tracker.Reset(0f);
|
||||
var eyePos = new Vector3(0f, 2.0f, 0f);
|
||||
|
||||
// Stationary spread baseline
|
||||
AimTrackerHelper.StepTrackedAim(
|
||||
ref tracker, shooterGrid, eyePos, 0f, 0f, 0f, target, dt,
|
||||
out _, out _, out _, out _);
|
||||
float stationarySpread = tracker.DynamicSpreadRad;
|
||||
|
||||
// Steady lateral run at +30 m/s along +X for 1.2s (72 ticks)
|
||||
float vx = 30f;
|
||||
for (int t = 0; t < 72; t++)
|
||||
{
|
||||
target.X += vx * dt;
|
||||
target.VelX = vx;
|
||||
target.VelZ = 0f;
|
||||
AimTrackerHelper.StepTrackedAim(
|
||||
ref tracker, shooterGrid, eyePos, 0f, 0f, 0f, target, dt,
|
||||
out _, out _, out _, out _);
|
||||
}
|
||||
|
||||
float crossingSpread = tracker.DynamicSpreadRad;
|
||||
Assert.True(crossingSpread > stationarySpread + 0.04f,
|
||||
$"Expected crossing angular rate to inflate DynamicSpreadRad (stat={stationarySpread:F4}, cross={crossingSpread:F4})");
|
||||
|
||||
// Sudden lateral jink: reverse to -30 m/s for 0.18s (11 ticks)
|
||||
vx = -30f;
|
||||
float maxOvershootX = 0f;
|
||||
for (int t = 0; t < 11; t++)
|
||||
{
|
||||
target.X += vx * dt;
|
||||
target.VelX = vx;
|
||||
AimTrackerHelper.StepTrackedAim(
|
||||
ref tracker, shooterGrid, eyePos, 0f, 0f, 0f, target, dt,
|
||||
out float aimX, out _, out float aimZ, out _);
|
||||
float err = MathF.Sqrt((aimX - target.X) * (aimX - target.X) + (aimZ - target.Z) * (aimZ - target.Z));
|
||||
maxOvershootX = MathF.Max(maxOvershootX, err);
|
||||
}
|
||||
|
||||
Assert.True(maxOvershootX > 2.5f,
|
||||
$"Expected lateral jink overshoot > 2.5m at ~70m, got {maxOvershootX:F2}m");
|
||||
}
|
||||
|
||||
// 3. Zero occluded fire / target leak when LOS breaks behind cover
|
||||
using (var session = new ArenaSession(seed: 12, ArenaMapKind.Desert))
|
||||
{
|
||||
IsolateContenders(session, 0, 1);
|
||||
var box = session.State.ArenaCoverBoxes[0];
|
||||
var player = session.State.Player;
|
||||
var ai = session.State.Contenders[1];
|
||||
|
||||
float aiX = box.X;
|
||||
float aiZ = box.Z - box.HalfZ - 14f;
|
||||
float px = box.X + 12f;
|
||||
float pz = box.Z - box.HalfZ - 14f;
|
||||
session.SetContenderPose(ai.Id, aiX, aiZ, MathF.Atan2(px - aiX, pz - aiZ));
|
||||
session.SetContenderPose(player.Id, px, pz, 0f);
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
Assert.Equal(player.Id, ai.AiTargetContenderId);
|
||||
Assert.True(ai.AimTracker.HasTarget);
|
||||
|
||||
// Break LOS behind cover box and shift player laterally
|
||||
session.SetContenderPose(ai.Id, box.X, box.Z - box.HalfZ - 8f, 0f);
|
||||
session.SetContenderPose(player.Id, box.X, box.Z + box.HalfZ + 8f, 0f);
|
||||
for (int t = 0; t < 10; t++)
|
||||
{
|
||||
session.SetContenderPose(player.Id, box.X + (t % 2 == 0 ? 2f : -2f), box.Z + box.HalfZ + 8f, 0f);
|
||||
session.Step(new PlayerInput(0f, 0f, player.X, player.Z, false, false, true));
|
||||
|
||||
Assert.Null(ai.AiTargetContenderId);
|
||||
Assert.False(ai.FireCmd);
|
||||
Assert.False(ai.AimTracker.HasTarget);
|
||||
float distToHidden = MathF.Sqrt((ai.AimX - player.X) * (ai.AimX - player.X) + (ai.AimZ - player.Z) * (ai.AimZ - player.Z));
|
||||
Assert.True(distToHidden > 5f, $"Occluded AI aim leaked hidden target coords (dist={distToHidden:F2}m)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RenderInterpolation_CameraAnchorAndContenderPose_ZeroHorizPhaseMismatchAcrossAlpha()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert);
|
||||
IsolateContenders(session, 0);
|
||||
var player = session.State.Player;
|
||||
|
||||
// Accelerate player forward for 30 ticks so Prev != Curr with genuine horizontal displacement & rotation
|
||||
for (int t = 0; t < 30; t++)
|
||||
{
|
||||
session.Step(new PlayerInput(
|
||||
Throttle: 1f,
|
||||
Steer: 0.35f,
|
||||
AimWorldX: player.X + MathF.Sin(player.Yaw) * 40f,
|
||||
AimWorldZ: player.Z + MathF.Cos(player.Yaw) * 40f,
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: false));
|
||||
}
|
||||
|
||||
float stepHoriz = MathF.Sqrt(
|
||||
(player.X - player.PrevX) * (player.X - player.PrevX) +
|
||||
(player.Z - player.PrevZ) * (player.Z - player.PrevZ));
|
||||
Assert.True(stepHoriz > 0.05f, $"Expected non-trivial single-tick displacement, got {stepHoriz:F4}m");
|
||||
|
||||
float[] alphas = { 0f, 0.25f, 0.5f, 0.75f, 1.0f };
|
||||
foreach (float alpha in alphas)
|
||||
{
|
||||
var (contenderPos, contenderRot, _) = session.GetInterpolatedContenderPose(player.Id, alpha);
|
||||
|
||||
// Camera anchor pivot uses (contenderPos.X, _smoothedShoulderY, contenderPos.Z) with ZERO horizontal chase lag
|
||||
float expectedX = player.PrevX + (player.X - player.PrevX) * alpha;
|
||||
float expectedZ = player.PrevZ + (player.Z - player.PrevZ) * alpha;
|
||||
float camPivotX = contenderPos.X;
|
||||
float camPivotZ = contenderPos.Z;
|
||||
|
||||
float mismatch = MathF.Sqrt(
|
||||
(camPivotX - expectedX) * (camPivotX - expectedX) +
|
||||
(camPivotZ - expectedZ) * (camPivotZ - expectedZ));
|
||||
Assert.True(mismatch < 1e-4f,
|
||||
$"Alpha={alpha:F2}: Horizontal phase mismatch {mismatch:E3}m >= 1e-4m");
|
||||
Assert.InRange(contenderRot.Length(), 0.999f, 1.001f);
|
||||
}
|
||||
|
||||
// SnapPreviousPose collapses alpha=0 and alpha=1
|
||||
player.SnapPreviousPose();
|
||||
var (p0, _, _) = session.GetInterpolatedContenderPose(player.Id, 0f);
|
||||
var (p1, _, _) = session.GetInterpolatedContenderPose(player.Id, 1f);
|
||||
Assert.True(Vector3.Distance(p0, p1) < 1e-5f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PointBlankConvergence_LargeChassis_NeverFiresBackward()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 42, ArenaMapKind.Desert);
|
||||
IsolateContenders(session, 0, 1);
|
||||
var player = session.State.Player;
|
||||
var target = session.State.Contenders[1];
|
||||
|
||||
// Swap player to Bastion (largest heavy chassis) and target to Raptor (tall mech, small 0.8m footprint)
|
||||
session.SetContenderPose(player.Id, 0f, 0f, yaw: 0f);
|
||||
session.State.SpawnChassisDrop(0f, 0f, Catalog.Bastion);
|
||||
Assert.True(session.TrySwapNearbyChassis());
|
||||
Assert.Equal(Catalog.Bastion.Id, player.Grid.Spec.Id);
|
||||
|
||||
session.SetContenderPose(target.Id, 0f, 4.5f, yaw: MathF.PI);
|
||||
session.State.SpawnChassisDrop(0f, 4.5f, Catalog.Raptor);
|
||||
Assert.True(session.State.TrySwapNearbyChassis(target.Id));
|
||||
Assert.Equal(Catalog.Raptor.Id, target.Grid.Spec.Id);
|
||||
target.AiScavengeCooldown = 999f;
|
||||
|
||||
// Step 1 tick to seat bodies, re-pin poses, then fire point-blank 4.5m in front (+Z)
|
||||
float aimY = player.Y + player.Grid.Spec.HalfHeight * 0.25f;
|
||||
session.Step(new PlayerInput(0f, 0f, target.X, target.Z, false, false, true, AimWorldY: aimY));
|
||||
session.SetContenderPose(player.Id, 0f, 0f, yaw: 0f);
|
||||
session.SetContenderPose(target.Id, 0f, 4.5f, yaw: MathF.PI);
|
||||
session.State.Tracers.Clear();
|
||||
|
||||
aimY = player.Y + player.Grid.Spec.HalfHeight * 0.25f;
|
||||
float targetArmorBefore = target.Grid.TotalArmorRatio();
|
||||
session.Step(new PlayerInput(
|
||||
Throttle: 0f,
|
||||
Steer: 0f,
|
||||
AimWorldX: target.X,
|
||||
AimWorldZ: target.Z,
|
||||
Fire: true,
|
||||
InteractPickup: false,
|
||||
Brake: true,
|
||||
AimWorldY: aimY));
|
||||
|
||||
float bastionMuzzleY = player.Y + player.Grid.Spec.HalfHeight * 0.25f;
|
||||
var playerTracers1 = session.State.Tracers
|
||||
.Where(t => MathF.Abs(t.StartX - player.X) < 1f && MathF.Abs(t.StartY - bastionMuzzleY) < 0.25f)
|
||||
.ToList();
|
||||
Assert.NotEmpty(playerTracers1);
|
||||
foreach (var tracer in playerTracers1)
|
||||
{
|
||||
float dz = tracer.EndZ - tracer.StartZ;
|
||||
Assert.True(dz > 0f,
|
||||
$"Point-blank Bastion shot fired backward! startZ={tracer.StartZ:F2}, endZ={tracer.EndZ:F2}");
|
||||
Assert.True(tracer.StartZ < target.Z,
|
||||
$"Muzzle overshot target Z! startZ={tracer.StartZ:F2}, targetZ={target.Z:F2}");
|
||||
}
|
||||
|
||||
// Place target just outside Bastion's front nose (non-overlapping) to confirm forward ray hits target cleanly
|
||||
float clearFrontZ = player.Grid.Spec.HalfLength + target.Grid.Spec.HalfLength + 0.5f;
|
||||
session.SetContenderPose(player.Id, 0f, 0f, yaw: 0f);
|
||||
session.SetContenderPose(target.Id, 0f, clearFrontZ, yaw: MathF.PI);
|
||||
session.State.Tracers.Clear();
|
||||
foreach (var m in player.Grid.Mounted)
|
||||
{
|
||||
m.Cooldown = 0f;
|
||||
}
|
||||
session.Step(new PlayerInput(
|
||||
Throttle: 0f,
|
||||
Steer: 0f,
|
||||
AimWorldX: target.X,
|
||||
AimWorldZ: target.Z,
|
||||
Fire: true,
|
||||
InteractPickup: false,
|
||||
Brake: true,
|
||||
AimWorldY: aimY));
|
||||
|
||||
bastionMuzzleY = player.Y + player.Grid.Spec.HalfHeight * 0.25f;
|
||||
var playerTracersFront = session.State.Tracers
|
||||
.Where(t => MathF.Abs(t.StartX - player.X) < 1f && MathF.Abs(t.StartY - bastionMuzzleY) < 0.25f)
|
||||
.ToList();
|
||||
Assert.NotEmpty(playerTracersFront);
|
||||
foreach (var tracer in playerTracersFront)
|
||||
{
|
||||
Assert.True(tracer.EndZ > tracer.StartZ,
|
||||
$"Close front Bastion shot fired backward! startZ={tracer.StartZ:F2}, endZ={tracer.EndZ:F2}");
|
||||
Assert.True(tracer.StartZ < target.Z,
|
||||
$"Close front muzzle overshot target Z! startZ={tracer.StartZ:F2}, targetZ={target.Z:F2}");
|
||||
}
|
||||
Assert.True(target.Grid.TotalArmorRatio() < targetArmorBefore,
|
||||
"Expected close front Bastion fire to hit Raptor");
|
||||
|
||||
// Also verify even tighter point-blank (2.2m, strictly inside Bastion HalfLength) still fires strictly forward
|
||||
session.SetContenderPose(player.Id, 0f, 0f, yaw: 0f);
|
||||
session.SetContenderPose(target.Id, 0f, 2.2f, yaw: MathF.PI);
|
||||
session.State.Tracers.Clear();
|
||||
foreach (var m in player.Grid.Mounted)
|
||||
{
|
||||
m.Cooldown = 0f;
|
||||
}
|
||||
session.Step(new PlayerInput(
|
||||
Throttle: 0f,
|
||||
Steer: 0f,
|
||||
AimWorldX: target.X,
|
||||
AimWorldZ: target.Z,
|
||||
Fire: true,
|
||||
InteractPickup: false,
|
||||
Brake: true,
|
||||
AimWorldY: aimY));
|
||||
|
||||
bastionMuzzleY = player.Y + player.Grid.Spec.HalfHeight * 0.25f;
|
||||
var playerTracers2 = session.State.Tracers
|
||||
.Where(t => MathF.Abs(t.StartX - player.X) < 1f && MathF.Abs(t.StartY - bastionMuzzleY) < 0.25f)
|
||||
.ToList();
|
||||
Assert.NotEmpty(playerTracers2);
|
||||
foreach (var tracer in playerTracers2)
|
||||
{
|
||||
Assert.True(tracer.EndZ > tracer.StartZ,
|
||||
$"Ultra-close 2.2m Bastion shot fired backward! startZ={tracer.StartZ:F2}, endZ={tracer.EndZ:F2}");
|
||||
Assert.True(tracer.StartZ < target.Z,
|
||||
$"Ultra-close 2.2m muzzle overshot target Z! startZ={tracer.StartZ:F2}, targetZ={target.Z:F2}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -387,6 +387,8 @@ namespace RustToDust.Tests
|
|||
var (openPx, openPz) = FindClearBuildingAdjacentSpot(sion, bldg.CenterX + 10f, z1);
|
||||
session.SetContenderPose(player.Id, openPx, openPz, yaw: 0f);
|
||||
}
|
||||
float facePlayerYaw = MathF.Atan2(player.X - ai.X, player.Z - ai.Z);
|
||||
session.SetContenderPose(ai.Id, bldg.CenterX, z1, yaw: facePlayerYaw);
|
||||
|
||||
for (int t = 0; t <= phase; t++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@ namespace RustToDust.Tests
|
|||
session.SetContenderPose(distantGroundRig.Id, 0f, 154f, MathF.PI);
|
||||
session.State.SpawnChassisDrop(0f, 154f, Catalog.Anvil);
|
||||
Assert.True(session.State.TrySwapNearbyChassis(distantGroundRig.Id));
|
||||
Assert.True(distantGroundRig.Grid.TryMount(Catalog.Autocannon, "hp.weapon.siege_l"));
|
||||
session.SetContenderPose(distantGroundRig.Id, 0f, 154f, MathF.PI);
|
||||
// Unmount player's PD so only distant rig shoots now
|
||||
player.Grid.TryMount(Catalog.Mg762, "hp.weapon.sponson_r");
|
||||
|
|
|
|||
Loading…
Reference in a new issue