Cut 10a Soul Pass #1 fixes: allied ordnance immunity, squad ID sync, 12m AI drop split
This commit is contained in:
parent
26f5438ed5
commit
10df4ae522
9 changed files with 536 additions and 33 deletions
|
|
@ -891,14 +891,14 @@ namespace RustToDust.Core
|
|||
return;
|
||||
}
|
||||
|
||||
// Squad V-chevron formation-follow above 140m AGL
|
||||
// Squad V-chevron formation-follow above 140m AGL (only while leader is also above 140m split altitude)
|
||||
if (_state.SquadSize > 1 && pod.LastAgl > 140f)
|
||||
{
|
||||
var leader = _state.GetSquadLeader(ai.SquadId);
|
||||
if (leader is not null && leader.Id != ai.Id && leader.IsInDropPod && leader.ActivePodId.HasValue)
|
||||
{
|
||||
var leaderPod = FindPodById(leader.ActivePodId.Value);
|
||||
if (leaderPod is not null && leaderPod.Phase == OrbitalPodPhase.Freefall)
|
||||
if (leaderPod is not null && leaderPod.Phase == OrbitalPodPhase.Freefall && leaderPod.LastAgl > 140f)
|
||||
{
|
||||
Vector2 fwd = new(leaderPod.LookForwardX, leaderPod.LookForwardZ);
|
||||
if (fwd.LengthSquared() < 1e-4f)
|
||||
|
|
@ -941,29 +941,35 @@ namespace RustToDust.Core
|
|||
float goalX = 0f;
|
||||
float goalZ = 0f;
|
||||
bool hasGoal = false;
|
||||
bool urgentSplit = false;
|
||||
float safeLimit = MathF.Max(40f, _state.Spectators.SafeRadius - 35f);
|
||||
float distFromCenter = MathF.Sqrt(pod.X * pod.X + pod.Z * pod.Z);
|
||||
|
||||
if (_state.SquadSize > 1)
|
||||
{
|
||||
bool tooCloseToAlly = IsTooCloseToSquadmatePod(ai, pod.X, pod.Z, 12.5f, out float repulseX, out float repulseZ);
|
||||
bool tooCloseNow = IsTooCloseToSquadmate(ai, pod.X, pod.Z, 15.5f, out float repulseX, out float repulseZ);
|
||||
float predX = pod.X + pod.VelX * 0.65f;
|
||||
float predZ = pod.Z + pod.VelZ * 0.65f;
|
||||
bool tooClosePred = !tooCloseNow && IsTooCloseToSquadmate(ai, predX, predZ, 15.0f, out repulseX, out repulseZ, lookaheadSec: 0.65f);
|
||||
bool tooCloseToAlly = tooCloseNow || tooClosePred;
|
||||
|
||||
var surfNow = _state.DefaultDropSurfaceQuery(pod.X, pod.Z, OrbitalPodPreset.GetContender(_state.MapKind).PodFootRadius, pod.Y + 1.0f);
|
||||
bool overInvalidBuilding = surfNow.IsInsideBuildingFootprint || (surfNow.IsBuildingRoof && !pod.AllowFlatRoofLanding);
|
||||
if (tooCloseToAlly || overInvalidBuilding)
|
||||
{
|
||||
urgentSplit = tooCloseToAlly;
|
||||
float seekX = tooCloseToAlly ? repulseX : pod.X;
|
||||
float seekZ = tooCloseToAlly ? repulseZ : pod.Z;
|
||||
var (cx, cz) = _state.FindClearDropPoint(seekX, seekZ, 4.5f);
|
||||
if (!IsTooCloseToSquadmatePod(ai, cx, cz, 12.0f, out _, out _))
|
||||
{
|
||||
goalX = cx;
|
||||
goalZ = cz;
|
||||
}
|
||||
else
|
||||
{
|
||||
goalX = seekX;
|
||||
goalZ = seekZ;
|
||||
}
|
||||
var (cx, cz) = FindClearDropPointAvoidingSquadmates(
|
||||
ai,
|
||||
seekX,
|
||||
seekZ,
|
||||
4.5f,
|
||||
15.5f,
|
||||
_state.DefaultDropSurfaceQuery,
|
||||
pod.AllowFlatRoofLanding);
|
||||
goalX = cx;
|
||||
goalZ = cz;
|
||||
hasGoal = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -979,7 +985,9 @@ namespace RustToDust.Core
|
|||
{
|
||||
var d = _state.GroundDrops[i];
|
||||
if (d.PickedUp) continue;
|
||||
if (_state.SquadSize > 1 && IsTooCloseToSquadmatePod(ai, d.X, d.Z, 12.0f, out _, out _))
|
||||
if (_state.SquadSize > 1 &&
|
||||
(IsTooCloseToSquadmate(ai, d.X, d.Z, 16.0f, out _, out _) ||
|
||||
IsGroundDropClaimedBySquadmate(ai, pod, d.X, d.Z)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1001,11 +1009,14 @@ namespace RustToDust.Core
|
|||
float dx = goalX - pod.X;
|
||||
float dz = goalZ - pod.Z;
|
||||
float len = MathF.Sqrt(dx * dx + dz * dz);
|
||||
if (len > 4f)
|
||||
float minLen = urgentSplit ? 0.5f : 4f;
|
||||
if (len > minLen)
|
||||
{
|
||||
pod.LookForwardX = dx / len;
|
||||
pod.LookForwardZ = dz / len;
|
||||
pod.SteerForwardCmd = 0.65f;
|
||||
pod.SteerForwardCmd = urgentSplit
|
||||
? Math.Clamp(len * 0.15f, 0.5f, 1.0f)
|
||||
: Math.Clamp(len * 0.035f, 0.2f, 0.55f);
|
||||
pod.SteerRightCmd = 0f;
|
||||
return;
|
||||
}
|
||||
|
|
@ -1015,32 +1026,144 @@ namespace RustToDust.Core
|
|||
pod.SteerRightCmd = 0f;
|
||||
}
|
||||
|
||||
private bool IsTooCloseToSquadmatePod(ContenderState self, float x, float z, float minSepM, out float escapeX, out float escapeZ)
|
||||
private (float X, float Z) FindClearDropPointAvoidingSquadmates(
|
||||
ContenderState self,
|
||||
float targetX,
|
||||
float targetZ,
|
||||
float pad,
|
||||
float minSepM,
|
||||
DropSurfaceQuery surfaceQuery,
|
||||
bool allowFlatRoofLanding)
|
||||
{
|
||||
escapeX = x;
|
||||
escapeZ = z;
|
||||
float minSepSq = minSepM * minSepM;
|
||||
float footRadius = OrbitalPodPreset.GetContender(_state.MapKind).PodFootRadius;
|
||||
var (cx, cz) = _state.FindClearDropPoint(targetX, targetZ, pad);
|
||||
if (!IsTooCloseToSquadmate(self, cx, cz, minSepM, out _, out _))
|
||||
{
|
||||
var surf0 = surfaceQuery(cx, cz, footRadius, _state.Terrain.SampleHeight(cx, cz) + 250f);
|
||||
if (!surf0.IsInsideBuildingFootprint && !(surf0.IsBuildingRoof && !allowFlatRoofLanding))
|
||||
{
|
||||
return (cx, cz);
|
||||
}
|
||||
}
|
||||
|
||||
float baseAngle = self.Id * 2.1f;
|
||||
float[] radii = { 16f, 24f, 34f, 46f, 60f };
|
||||
for (int rIdx = 0; rIdx < radii.Length; rIdx++)
|
||||
{
|
||||
float radius = radii[rIdx];
|
||||
for (int k = 0; k < 12; k++)
|
||||
{
|
||||
float ang = baseAngle + k * (MathF.Tau / 12f);
|
||||
float rawX = targetX + MathF.Cos(ang) * radius;
|
||||
float rawZ = targetZ + MathF.Sin(ang) * radius;
|
||||
var (candX, candZ) = _state.FindClearDropPoint(rawX, rawZ, pad);
|
||||
if (IsTooCloseToSquadmate(self, candX, candZ, minSepM, out _, out _))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var surf = surfaceQuery(candX, candZ, footRadius, _state.Terrain.SampleHeight(candX, candZ) + 250f);
|
||||
if (surf.IsInsideBuildingFootprint || (surf.IsBuildingRoof && !allowFlatRoofLanding))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return (candX, candZ);
|
||||
}
|
||||
}
|
||||
|
||||
return (cx, cz);
|
||||
}
|
||||
|
||||
private bool IsGroundDropClaimedBySquadmate(ContenderState self, OrbitalPod selfPod, float dropX, float dropZ)
|
||||
{
|
||||
float selfDx = dropX - selfPod.X;
|
||||
float selfDz = dropZ - selfPod.Z;
|
||||
float selfDistSq = selfDx * selfDx + selfDz * selfDz;
|
||||
|
||||
for (int i = 0; i < _activePods.Count; i++)
|
||||
{
|
||||
var otherPod = _activePods[i];
|
||||
if (otherPod.PodKind != OrbitalPodKind.Contender || otherPod.ContenderId == self.Id) continue;
|
||||
if (!_state.AreAllies(self.Id, otherPod.ContenderId)) continue;
|
||||
float dx = x - otherPod.X;
|
||||
float dz = z - otherPod.Z;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 < minSepSq)
|
||||
float odx = dropX - otherPod.X;
|
||||
float odz = dropZ - otherPod.Z;
|
||||
float otherDistSq = odx * odx + odz * odz;
|
||||
if (otherDistSq < selfDistSq - 1e-2f ||
|
||||
(MathF.Abs(otherDistSq - selfDistSq) <= 1e-2f && otherPod.ContenderId < self.Id))
|
||||
{
|
||||
float dist = MathF.Sqrt(d2);
|
||||
float nx = dist > 0.1f ? dx / dist : MathF.Cos(self.Id * 2.1f);
|
||||
float nz = dist > 0.1f ? dz / dist : MathF.Sin(self.Id * 2.1f);
|
||||
escapeX = otherPod.X + nx * (minSepM + 4f);
|
||||
escapeZ = otherPod.Z + nz * (minSepM + 4f);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsTooCloseToSquadmate(
|
||||
ContenderState self,
|
||||
float x,
|
||||
float z,
|
||||
float minSepM,
|
||||
out float escapeX,
|
||||
out float escapeZ,
|
||||
float lookaheadSec = 0f)
|
||||
{
|
||||
escapeX = x;
|
||||
escapeZ = z;
|
||||
float minSepSq = minSepM * minSepM;
|
||||
bool any = false;
|
||||
int closeCount = 0;
|
||||
float sumRx = 0f;
|
||||
float sumRz = 0f;
|
||||
float singleOtherX = x;
|
||||
float singleOtherZ = z;
|
||||
|
||||
void Accumulate(int otherId, float ox, float oz)
|
||||
{
|
||||
float dx = x - ox;
|
||||
float dz = z - oz;
|
||||
float d2 = dx * dx + dz * dz;
|
||||
if (d2 < minSepSq)
|
||||
{
|
||||
float dist = MathF.Sqrt(d2);
|
||||
float nx = dist > 0.1f ? dx / dist : MathF.Cos((self.Id + otherId + 1) * 2.1f);
|
||||
float nz = dist > 0.1f ? dz / dist : MathF.Sin((self.Id + otherId + 1) * 2.1f);
|
||||
float weight = MathF.Max(1f, minSepM - dist + 2f);
|
||||
sumRx += nx * weight;
|
||||
sumRz += nz * weight;
|
||||
singleOtherX = ox;
|
||||
singleOtherZ = oz;
|
||||
closeCount++;
|
||||
any = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _activePods.Count; i++)
|
||||
{
|
||||
var otherPod = _activePods[i];
|
||||
if (otherPod.PodKind != OrbitalPodKind.Contender || otherPod.ContenderId == self.Id) continue;
|
||||
if (!_state.AreAllies(self.Id, otherPod.ContenderId)) continue;
|
||||
Accumulate(otherPod.ContenderId, otherPod.X + otherPod.VelX * lookaheadSec, otherPod.Z + otherPod.VelZ * lookaheadSec);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _state.Contenders.Count; i++)
|
||||
{
|
||||
var c = _state.Contenders[i];
|
||||
if (c.Id == self.Id || !c.Alive || c.IsInDropPod) continue;
|
||||
if (!_state.AreAllies(self.Id, c.Id)) continue;
|
||||
Accumulate(c.Id, c.X, c.Z);
|
||||
}
|
||||
|
||||
if (any)
|
||||
{
|
||||
float rLen = MathF.Sqrt(sumRx * sumRx + sumRz * sumRz);
|
||||
float rx = rLen > 1e-4f ? sumRx / rLen : MathF.Cos(self.Id * 2.1f);
|
||||
float rz = rLen > 1e-4f ? sumRz / rLen : MathF.Sin(self.Id * 2.1f);
|
||||
float anchorX = closeCount == 1 ? singleOtherX : x;
|
||||
float anchorZ = closeCount == 1 ? singleOtherZ : z;
|
||||
escapeX = anchorX + rx * (minSepM + 4.5f);
|
||||
escapeZ = anchorZ + rz * (minSepM + 4.5f);
|
||||
}
|
||||
return any;
|
||||
}
|
||||
|
||||
public void ApplyPlayerSteerInput(ContenderState human, DropSurfaceQuery? surfaceQuery = null)
|
||||
{
|
||||
if (!human.IsInDropPod || !human.ActivePodId.HasValue)
|
||||
|
|
@ -1097,12 +1220,24 @@ namespace RustToDust.Core
|
|||
for (int i = _activePods.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var pod = _activePods[i];
|
||||
DropClearPointQuery clearQuery = _state.FindClearDropPoint;
|
||||
if (pod.PodKind == OrbitalPodKind.Contender &&
|
||||
pod.ContenderId >= 0 &&
|
||||
pod.ContenderId < _state.Contenders.Count)
|
||||
{
|
||||
var c = _state.Contenders[pod.ContenderId];
|
||||
pod.AllowFlatRoofLanding = c.IsHuman && _state.MapKind == ArenaMapKind.Sion;
|
||||
if (_state.SquadSize > 1)
|
||||
{
|
||||
clearQuery = (qx, qz, qpad) => FindClearDropPointAvoidingSquadmates(
|
||||
c,
|
||||
qx,
|
||||
qz,
|
||||
qpad,
|
||||
14.5f,
|
||||
surfaceQuery,
|
||||
pod.AllowFlatRoofLanding);
|
||||
}
|
||||
}
|
||||
|
||||
bool touched = OrbitalDropKinematics.StepPod(
|
||||
|
|
@ -1110,7 +1245,7 @@ namespace RustToDust.Core
|
|||
dt,
|
||||
_state.Terrain,
|
||||
surfaceQuery,
|
||||
_state.FindClearDropPoint,
|
||||
clearQuery,
|
||||
out bool retroBurnStarted,
|
||||
out DropSurfaceSample touchSample);
|
||||
|
||||
|
|
|
|||
|
|
@ -322,6 +322,7 @@ namespace RustToDust.Core
|
|||
[Key(14)] public List<OrbitalPodDto> ActivePods { get; set; } = new();
|
||||
[Key(15)] public LobbySnapshotDto? Lobby { get; set; }
|
||||
[Key(16)] public byte SquadSize { get; set; } = 1;
|
||||
[Key(17)] public byte[]? ContenderSquadIds { get; set; }
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
|
|||
|
|
@ -822,6 +822,14 @@ namespace RustToDust.Net
|
|||
},
|
||||
WinnerContenderId = dto.WinnerContenderId
|
||||
};
|
||||
if (dto.ContenderSquadIds is { Length: > 0 } squadIds)
|
||||
{
|
||||
int count = Math.Min(squadIds.Length, _viewState.Contenders.Count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
_viewState.Contenders[i].SquadId = squadIds[i];
|
||||
}
|
||||
}
|
||||
_lobbyState = _viewState.Phase == MatchPhase.Lobby ? dto.Lobby : null;
|
||||
if (_lobbyState is not null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -283,7 +283,11 @@ namespace RustToDust.Net
|
|||
}
|
||||
|
||||
int maxSquads = (MatchState.ContenderCount + squadSize - 1) / squadSize;
|
||||
byte targetSq = (byte)Math.Clamp((int)targetSquadId, 0, Math.Max(0, maxSquads - 1));
|
||||
if (targetSquadId >= maxSquads)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
byte targetSq = targetSquadId;
|
||||
var srcSlot = lobby.Slots[contenderId];
|
||||
byte srcSq = srcSlot.SquadId;
|
||||
if (srcSq == targetSq)
|
||||
|
|
@ -1699,12 +1703,19 @@ namespace RustToDust.Net
|
|||
|
||||
private InitialMatchStateDto BuildInitialMatchStateDto(int forContenderId)
|
||||
{
|
||||
var squadIds = new byte[_session.State.Contenders.Count];
|
||||
for (int i = 0; i < squadIds.Length; i++)
|
||||
{
|
||||
squadIds[i] = _session.State.Contenders[i].SquadId;
|
||||
}
|
||||
|
||||
var dto = new InitialMatchStateDto
|
||||
{
|
||||
MatchGeneration = _matchGeneration,
|
||||
Seed = _session.State.Seed,
|
||||
MapKind = (byte)_session.State.MapKind,
|
||||
SquadSize = _session.State.SquadSize,
|
||||
ContenderSquadIds = squadIds,
|
||||
SimTime = _session.State.Time,
|
||||
SafeRadius = _session.State.Spectators.SafeRadius,
|
||||
Phase = (byte)(_session.State.Phase == MatchPhase.Completed ? 1 : _session.State.Phase == MatchPhase.Lobby ? 2 : 0),
|
||||
|
|
|
|||
|
|
@ -2025,6 +2025,11 @@ namespace RustToDust.Ymir
|
|||
for (int i = 0; i < State.Contenders.Count; i++)
|
||||
{
|
||||
_contenderPvs[obs.Id, i] = i == obs.Id;
|
||||
if (memState.ContenderContacts.TryGetValue(State.Contenders[i].Id, out var mem))
|
||||
{
|
||||
mem.VisibleToPlayer = false;
|
||||
mem.FaintHorizonPing = false;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < State.Spectators.Spectators.Count; i++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -301,6 +301,7 @@ namespace RustToDust.Ymir
|
|||
targetPos = Vector3.Zero;
|
||||
float bestDistSq = maxRange * maxRange;
|
||||
bool found = false;
|
||||
bool shooterIsContender = _sink.TryResolveActor(shooterStableId, out bool sIsC, out int shooterContenderId) && sIsC;
|
||||
|
||||
for (int i = 0; i < PoolCapacity; i++)
|
||||
{
|
||||
|
|
@ -309,7 +310,7 @@ namespace RustToDust.Ymir
|
|||
continue;
|
||||
}
|
||||
ref readonly var inst = ref _pool[i];
|
||||
if (inst.ShooterStableId == shooterStableId || inst.Def.InterceptHp <= 0f)
|
||||
if (inst.Def.InterceptHp <= 0f || IsFriendlyOrdnance(shooterStableId, shooterIsContender, shooterContenderId, in inst))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1582,6 +1583,33 @@ namespace RustToDust.Ymir
|
|||
}
|
||||
}
|
||||
|
||||
private bool IsFriendlyOrdnance(
|
||||
ulong shooterStableId,
|
||||
bool shooterIsContender,
|
||||
int shooterContenderId,
|
||||
in LiveOrdnanceInstance inst)
|
||||
{
|
||||
if (inst.ShooterStableId == shooterStableId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!shooterIsContender || shooterContenderId < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!inst.IsSpectatorShooter && inst.ShooterContenderId >= 0)
|
||||
{
|
||||
return _sink.State.AreAllies(shooterContenderId, inst.ShooterContenderId);
|
||||
}
|
||||
if (_sink.TryResolveActor(inst.ShooterStableId, out bool instIsContender, out int instContenderId) &&
|
||||
instIsContender &&
|
||||
instContenderId >= 0)
|
||||
{
|
||||
return _sink.State.AreAllies(shooterContenderId, instContenderId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryHitInterceptableOrdnance(
|
||||
Vector3 origin,
|
||||
Vector3 dir,
|
||||
|
|
@ -1594,6 +1622,7 @@ namespace RustToDust.Ymir
|
|||
bestSlot = -1;
|
||||
bestDist = maxDist;
|
||||
hitPt = Vector3.Zero;
|
||||
bool shooterIsContender = _sink.TryResolveActor(shooterStableId, out bool sIsC, out int shooterContenderId) && sIsC;
|
||||
|
||||
for (int i = 0; i < PoolCapacity; i++)
|
||||
{
|
||||
|
|
@ -1602,7 +1631,7 @@ namespace RustToDust.Ymir
|
|||
continue;
|
||||
}
|
||||
ref readonly var inst = ref _pool[i];
|
||||
if (inst.ShooterStableId == shooterStableId || inst.Def.InterceptHp <= 0f)
|
||||
if (inst.Def.InterceptHp <= 0f || IsFriendlyOrdnance(shooterStableId, shooterIsContender, shooterContenderId, in inst))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -708,5 +708,129 @@ namespace RustToDust.Tests
|
|||
Assert.True(listenHost.ViewState.AreAllies(0, remoteId));
|
||||
Assert.True(remote.ViewState.AreAllies(0, remoteId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LobbySquadSwap_MidMatchReconnectAndLateJoin_PreservesAll12SquadIdsOutsidePvs()
|
||||
{
|
||||
using var host = new ServerMatchHost(
|
||||
IPAddress.Loopback,
|
||||
0,
|
||||
seed: 42,
|
||||
mapKind: ArenaMapKind.Desert,
|
||||
startInLobby: true,
|
||||
minHumansToStart: 1,
|
||||
squadSize: 3);
|
||||
var ep = new IPEndPoint(IPAddress.Loopback, host.BoundPort);
|
||||
|
||||
using var clientA = new RemoteArenaSession(ep, "LeaderSwap");
|
||||
long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
var deadline = DateTime.UtcNow.AddSeconds(3);
|
||||
while (!clientA.IsJoined && DateTime.UtcNow < deadline)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientA.PumpNetwork();
|
||||
Thread.Sleep(2);
|
||||
}
|
||||
Assert.True(clientA.IsJoined);
|
||||
int slotA = clientA.LocalContenderId;
|
||||
Assert.Equal(0, slotA);
|
||||
|
||||
// Polish check: out-of-range TargetSquadId >= maxSquads (4 for SquadSize=3) must be rejected, not clamped
|
||||
Assert.False(host.MovePeerToSquad(slotA, 4));
|
||||
Assert.Equal((byte)0, host.Session.State.Contenders[slotA].SquadId);
|
||||
|
||||
// Swap Slot 0 (0 -> 2) and Slot 6 (2 -> 0) in Lobby (SquadSize = 3)
|
||||
Assert.True(clientA.RequestLobbySquad(2));
|
||||
for (int t = 0; t < 20; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientA.PumpNetwork();
|
||||
Thread.Sleep(2);
|
||||
}
|
||||
Assert.Equal((byte)2, host.Session.State.Contenders[0].SquadId);
|
||||
Assert.Equal((byte)0, host.Session.State.Contenders[6].SquadId);
|
||||
|
||||
// Launch to MatchPhase.Active
|
||||
Assert.True(host.SetLobbyReady(slotA, true));
|
||||
for (int tick = 0; tick < 340; tick++)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientA.PumpNetwork();
|
||||
if (host.Session.State.Phase == MatchPhase.Active && clientA.ViewState.Phase == MatchPhase.Active)
|
||||
{
|
||||
break;
|
||||
}
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
Assert.Equal(MatchPhase.Active, host.Session.State.Phase);
|
||||
|
||||
// Position contenders far apart across Desert so non-allies (including Slot 6) are outside PVS
|
||||
host.Session.SetContenderPose(0, -320f, -320f, 0f);
|
||||
for (int i = 1; i < MatchState.ContenderCount; i++)
|
||||
{
|
||||
if (host.Session.State.AreAllies(0, i))
|
||||
{
|
||||
host.Session.SetContenderPose(i, -310f + i * 3f, -320f, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
host.Session.SetContenderPose(i, 320f, 320f - i * 8f, MathF.PI);
|
||||
}
|
||||
}
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
Assert.False(host.Session.IsEntityInPeerPvs(0, true, 6));
|
||||
|
||||
// 1. Reconnect clientA mid-match and assert ALL 12 SquadIds and AreAllies match server 12/12
|
||||
Guid tokenA = clientA.ReconnectToken;
|
||||
clientA.DisconnectGracefully("ReconnectSquadTest");
|
||||
clientA.Dispose();
|
||||
for (int t = 0; t < 20; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
|
||||
using var clientARejoin = new RemoteArenaSession(ep, "LeaderSwap", tokenA);
|
||||
deadline = DateTime.UtcNow.AddSeconds(3);
|
||||
while (!clientARejoin.IsJoined && DateTime.UtcNow < deadline)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientARejoin.PumpNetwork();
|
||||
Thread.Sleep(2);
|
||||
}
|
||||
Assert.True(clientARejoin.IsJoined);
|
||||
Assert.Equal(0, clientARejoin.LocalContenderId);
|
||||
|
||||
// 2. Late-join a fresh clientB mid-match while non-allies are outside PVS
|
||||
using var clientB = new RemoteArenaSession(ep, "LateJoiner");
|
||||
deadline = DateTime.UtcNow.AddSeconds(3);
|
||||
while (!clientB.IsJoined && DateTime.UtcNow < deadline)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
clientARejoin.PumpNetwork();
|
||||
clientB.PumpNetwork();
|
||||
Thread.Sleep(2);
|
||||
}
|
||||
Assert.True(clientB.IsJoined);
|
||||
|
||||
var serverState = host.Session.State;
|
||||
for (int i = 0; i < MatchState.ContenderCount; i++)
|
||||
{
|
||||
Assert.Equal(serverState.Contenders[i].SquadId, clientARejoin.ViewState.Contenders[i].SquadId);
|
||||
Assert.Equal(serverState.Contenders[i].SquadId, clientB.ViewState.Contenders[i].SquadId);
|
||||
for (int j = 0; j < MatchState.ContenderCount; j++)
|
||||
{
|
||||
Assert.Equal(serverState.AreAllies(i, j), clientARejoin.ViewState.AreAllies(i, j));
|
||||
Assert.Equal(serverState.AreAllies(i, j), clientB.ViewState.AreAllies(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1539,6 +1539,68 @@ namespace RustToDust.Tests
|
|||
$"CorePvs wire frame {wire.Length}B > {SnapshotCodec.MaxLatestDatagramBytes}B");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SquadTrioDrop_AllSeedsAndMaps_AllLandedSquadmatesSeparatedAtLeast12Meters()
|
||||
{
|
||||
int[] seeds = { 1, 7, 42, 1337 };
|
||||
ArenaMapKind[] maps = { ArenaMapKind.Sion, ArenaMapKind.Desert };
|
||||
|
||||
foreach (var mapKind in maps)
|
||||
{
|
||||
foreach (int seed in seeds)
|
||||
{
|
||||
using var session = new ArenaSession(seed: seed, mapKind: mapKind, slot0Human: false, squadSize: 3);
|
||||
var state = session.State;
|
||||
|
||||
var tdPos = new (float X, float Z, int Tick)[MatchState.ContenderCount];
|
||||
var landed = new bool[MatchState.ContenderCount];
|
||||
for (int t = 0; t < 2400; t++)
|
||||
{
|
||||
session.Step();
|
||||
for (int i = 0; i < state.Contenders.Count; i++)
|
||||
{
|
||||
var c = state.Contenders[i];
|
||||
if (!landed[i] && c.IsGroundedActive)
|
||||
{
|
||||
landed[i] = true;
|
||||
tdPos[i] = (c.X, c.Z, t);
|
||||
}
|
||||
}
|
||||
if (state.Contenders.All(c => c.IsGroundedActive))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.All(state.Contenders, c => Assert.True(c.IsGroundedActive,
|
||||
$"Map={mapKind} Seed={seed} contender {c.Id} failed to land"));
|
||||
|
||||
foreach (var grp in state.Contenders.GroupBy(c => c.SquadId))
|
||||
{
|
||||
var members = grp.ToList();
|
||||
for (int a = 0; a < members.Count; a++)
|
||||
{
|
||||
for (int b = a + 1; b < members.Count; b++)
|
||||
{
|
||||
var ma = members[a];
|
||||
var mb = members[b];
|
||||
float tdDx = tdPos[ma.Id].X - tdPos[mb.Id].X;
|
||||
float tdDz = tdPos[ma.Id].Z - tdPos[mb.Id].Z;
|
||||
float tdDist = MathF.Sqrt(tdDx * tdDx + tdDz * tdDz);
|
||||
float dx = ma.X - mb.X;
|
||||
float dz = ma.Z - mb.Z;
|
||||
float d = MathF.Sqrt(dx * dx + dz * dz);
|
||||
Assert.True(tdDist >= 12.0f,
|
||||
$"Map={mapKind} Seed={seed} Squad={grp.Key} pair ({ma.Id}@t{tdPos[ma.Id].Tick},{mb.Id}@t{tdPos[mb.Id].Tick}) touchdown too close: td={tdDist:F2}m (now={d:F2}m)");
|
||||
Assert.True(d >= 12.0f,
|
||||
$"Map={mapKind} Seed={seed} Squad={grp.Key} pair ({ma.Id}@t{tdPos[ma.Id].Tick},{mb.Id}@t{tdPos[mb.Id].Tick}) landed too close: now={d:F2}m (td={tdDist:F2}m)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AssertZeroChassisPenetration(MatchState state, ContenderState c)
|
||||
{
|
||||
var spec = c.Grid.Spec;
|
||||
|
|
|
|||
|
|
@ -979,5 +979,133 @@ namespace RustToDust.Tests
|
|||
var ex = Assert.Throws<InvalidOperationException>(() => OrdnanceGraphValidator.ValidateAndFlatten(combined));
|
||||
Assert.Contains("sub-spawn budget", ex.Message, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlliedPdAndHitscan_DoNotInterceptSquadmateOrdnance()
|
||||
{
|
||||
using var session = new ArenaSession(seed: 101, slot0Human: true, skipInitialDrop: true, squadSize: 3);
|
||||
var ally0 = session.State.Contenders[0];
|
||||
var ally1 = session.State.Contenders[1];
|
||||
var enemy = session.State.Contenders[3];
|
||||
Assert.True(session.State.AreAllies(ally0.Id, ally1.Id));
|
||||
Assert.False(session.State.AreAllies(ally0.Id, enemy.Id));
|
||||
IsolateContenders(session, ally0.Id, ally1.Id, enemy.Id);
|
||||
|
||||
// Place Ally 0 and Ally 1 nearby facing Enemy so Ally 1's PD + RailPlasmaBeam shoot across Ally 0's ordnance
|
||||
session.SetContenderPose(ally0.Id, 0f, 0f, 0f);
|
||||
session.SetContenderPose(ally1.Id, 16f, 16f, -0.5f);
|
||||
session.SetContenderPose(enemy.Id, 0f, 80f, MathF.PI);
|
||||
|
||||
foreach (var c in new[] { ally0, ally1, enemy })
|
||||
{
|
||||
session.State.SpawnChassisDrop(c.X, c.Z, Catalog.Anvil);
|
||||
Assert.True(session.State.TrySwapNearbyChassis(c.Id));
|
||||
c.Grid.Mounted.RemoveAll(m => m.Spec.Kind == HardpointKind.Weapon);
|
||||
}
|
||||
session.SetContenderPose(ally0.Id, 0f, 0f, 0f);
|
||||
session.SetContenderPose(ally1.Id, 16f, 16f, -0.5f);
|
||||
session.SetContenderPose(enemy.Id, 0f, 80f, MathF.PI);
|
||||
|
||||
var droneSpec = ProceduralWeaponGenerator.CreateDreamLoiteringDrone();
|
||||
var swarmSpec = ProceduralWeaponGenerator.CreateDreamWeapon(WeaponArchetypeKind.HomingSwarmPod);
|
||||
var railSpec = ProceduralWeaponGenerator.CreateDreamWeapon(WeaponArchetypeKind.RailPlasmaBeam);
|
||||
Assert.True(ally0.Grid.TryMount(droneSpec.Module, "hp.weapon.siege_l"));
|
||||
Assert.True(ally0.Grid.TryMount(swarmSpec.Module, "hp.weapon.siege_r"));
|
||||
Assert.True(ally1.Grid.TryMount(Catalog.ImperialAegisPd, "hp.weapon.sponson_l"));
|
||||
Assert.True(ally1.Grid.TryMount(railSpec.Module, "hp.weapon.siege_l"));
|
||||
Assert.True(ally1.Grid.TryMount(Catalog.GoldRadiator, "hp.radiator.l"));
|
||||
Assert.True(ally1.Grid.TryMount(Catalog.GoldRadiator, "hp.radiator.r"));
|
||||
|
||||
session.SetHumanSlot(ally1.Id, true, "Ally1");
|
||||
session.SetHumanInput(ally0.Id, new PlayerInput(0f, 0f, enemy.X, enemy.Z, Fire: false, InteractPickup: false, Brake: true, AimWorldY: enemy.Y + 2f));
|
||||
session.SetHumanInput(ally1.Id, new PlayerInput(0f, 0f, 0f, 25f, Fire: false, InteractPickup: false, Brake: true, AimWorldY: 12f));
|
||||
session.Step();
|
||||
|
||||
var events = new List<ISimEvent>();
|
||||
session.DrainStepEvents(events);
|
||||
|
||||
int allyOrdnanceSpawned = 0;
|
||||
int allyOrdnanceIntercepted = 0;
|
||||
int railShotsWhileAllyOrdnanceAirborne = 0;
|
||||
|
||||
for (int tick = 0; tick < 360; tick++)
|
||||
{
|
||||
Vector3? allyAirbornePos = null;
|
||||
var pool = session.Ordnance.PoolSpan;
|
||||
for (int i = 0; i < pool.Length; i++)
|
||||
{
|
||||
ref readonly var inst = ref pool[i];
|
||||
if (!inst.Active || inst.IsSpectatorShooter || inst.ShooterContenderId != ally0.Id)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (inst.Def.InterceptHp > 0f &&
|
||||
inst.Def.Motion is OrdnanceMotion.LoiterOrbit or OrdnanceMotion.HomingMissile)
|
||||
{
|
||||
allyAirbornePos = inst.Pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Keep Ally 1 cool enough to continuously fire PD + RailPlasmaBeam directly at Ally 0's airborne ordnance
|
||||
foreach (var mod in ally1.Grid.Mounted)
|
||||
{
|
||||
mod.CurrentTemp = mod.Spec.OptimalTemp;
|
||||
}
|
||||
|
||||
session.SetHumanInput(ally0.Id, new PlayerInput(
|
||||
0f, 0f,
|
||||
enemy.X, enemy.Z,
|
||||
Fire: tick < 5,
|
||||
InteractPickup: false,
|
||||
Brake: true,
|
||||
AimWorldY: enemy.Y + 2f));
|
||||
|
||||
if (allyAirbornePos.HasValue)
|
||||
{
|
||||
var p = allyAirbornePos.Value;
|
||||
session.SetHumanInput(ally1.Id, new PlayerInput(
|
||||
0f, 0f,
|
||||
p.X, p.Z,
|
||||
Fire: true,
|
||||
InteractPickup: false,
|
||||
Brake: true,
|
||||
AimWorldY: p.Y));
|
||||
railShotsWhileAllyOrdnanceAirborne++;
|
||||
}
|
||||
else
|
||||
{
|
||||
session.SetHumanInput(ally1.Id, new PlayerInput(
|
||||
0f, 0f,
|
||||
enemy.X, enemy.Z,
|
||||
Fire: false,
|
||||
InteractPickup: false,
|
||||
Brake: true,
|
||||
AimWorldY: enemy.Y + 2f));
|
||||
}
|
||||
|
||||
session.Step();
|
||||
events.Clear();
|
||||
session.DrainStepEvents(events);
|
||||
foreach (var ev in events)
|
||||
{
|
||||
if (ev is OrdnanceNodeEvent one && !one.IsSpectatorShooter && one.ShooterId == ally0.Id)
|
||||
{
|
||||
if (one.Kind == (byte)OrdnanceEventKind.Spawned)
|
||||
{
|
||||
allyOrdnanceSpawned++;
|
||||
}
|
||||
else if (one.Kind == (byte)OrdnanceEventKind.Intercepted)
|
||||
{
|
||||
allyOrdnanceIntercepted++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(allyOrdnanceSpawned >= 2, $"Expected Ally 0 to spawn drone + swarm ordnance, got {allyOrdnanceSpawned}");
|
||||
Assert.True(railShotsWhileAllyOrdnanceAirborne >= 10, $"Expected Ally 1 to aim RailPlasmaBeam + PD at airborne ally ordnance, got {railShotsWhileAllyOrdnanceAirborne}");
|
||||
Assert.Equal(0, allyOrdnanceIntercepted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue