Files
EscapistsReintroduced/docs/evidence/small-terrain-placement-2026-10-24/native-fixture.c
T
2026-10-24 03:03:10 +02:00

90 lines
4.1 KiB
C

#ifdef WORKBENCH
modded class ERR_CampTerrain
{
void ERR_TestAirport(vector position) { m_Airfields.Clear(); m_Airfields.Insert(position); }
}
class ERR_SmallTerrainPlacementProbe : ERR_TerrainSites
{
protected ref ERR_SiteDefinition m_TestPrison;
protected vector m_Center;
protected int m_Samples;
void Setup(vector center)
{
m_Began = System.GetTickCount();
m_Center = center; m_Low = center - "1000 0 1000"; m_High = center + "1000 0 1000";
m_TestPrison = new ERR_SiteDefinition();
m_TestPrison.Id = "fixture-prison"; m_TestPrison.Kind = ERR_LocationKind.PRISON;
m_TestPrison.Guarded = true; m_TestPrison.GuardOffset = "20 0 0";
}
bool Check(bool ok, string label)
{
if (ok) Print("ERR SMOKE PASS: small-terrain " + label);
else Print("ERR SMOKE FAIL: small-terrain " + label, LogLevel.ERROR);
return ok;
}
int Test()
{
if (!m_HaveCandidate)
{
if (m_Samples++ >= 12000) { Check(false, "native clear-ground sample budget"); return -1; }
m_Candidate = m_Center + Vector(Math.RandomFloat(-800,800),0,Math.RandomFloat(-800,800));
m_Attempts = m_Samples;
m_CandidateHeading = Math.RandomFloat(0,360); m_CandidateBegan = System.GetTickCount();
m_HaveCandidate = true;
}
float floor;
m_WaitingNav = false;
if (!Survey(m_TestPrison,m_Candidate,m_CandidateHeading,floor))
{
if (!m_WaitingNav || System.GetTickCount() - m_CandidateBegan >= 5000) m_HaveCandidate = false;
return 0;
}
if (!Check(Bounds("-500 0 -500","500 0 500") && !Bounds(vector.Zero,"999 0 2000"), "one-kilometre terrains admitted with bounded size validation")) return -1;
if (!Check(PrisonAirportBuffer(m_Low,m_High) == 300, "two-kilometre survey uses 300m airport separation")) return -1;
m_Terrain.ERR_TestAirport(m_Candidate + "600 0 0");
if (!Check(!m_Terrain.Site(m_TestPrison,m_Candidate,m_CandidateHeading,floor), "original 1500m rule rejects the arranged nearby airport")) return -1;
if (!Check(m_Terrain.Rejection() == "airport separation", "native rejection exposes the exact airport-distance reason")) return -1;
RecordRejection(m_Terrain.Rejection());
if (!Check(RejectionSummary().Contains("airport separation=1"), "native diagnostic aggregates the failed check")) return -1;
ReportSearch(m_TestPrison,"fixture checks complete");
if (!Check(Survey(m_TestPrison,m_Candidate,m_CandidateHeading,floor), "scaled rule accepts the same real clear navigable ground and guard area")) return -1;
ERR_SiteDefinition extraction = new ERR_SiteDefinition();
extraction.Id = "fixture-extraction"; extraction.Kind = ERR_LocationKind.EXTRACTION; extraction.RequireAirfield = true;
m_Attempts = 12000; m_Began = System.GetTickCount(); m_HaveCandidate = true;
int began = m_Began;
ExpandExtractionSearch(extraction);
if (!Check(!extraction.RequireAirfield && !m_HaveCandidate && extraction.Label == "Extraction landing zone", "exhausted airport preference transitions to off-airport survey")) return -1;
if (!Check(m_Began == began && m_Attempts == 12000 && SearchAttempts() == 48000 && SearchMilliseconds() == 120000, "fallback retains finite total deadline and attempt budget")) return -1;
Print("ERR SMOKE COMPLETE: small-terrain-placement");
return 1;
}
}
modded class ERR_GameMode
{
protected ref ERR_SmallTerrainPlacementProbe m_SmallTerrainTest;
protected int m_SmallTerrainDeadline;
override protected void EOnInit(IEntity owner)
{
super.EOnInit(owner);
string kind;
if (SCR_Global.IsEditMode() || !System.GetCLIParam("errSmokeOutcome",kind) || kind != "small-terrain-placement") return;
GetGame().GetCallqueue().CallLater(ERR_TestSmallTerrain,10,true);
}
void ERR_TestSmallTerrain()
{
if (!Active()) return;
if (!m_SmallTerrainTest)
{
m_SmallTerrainTest = new ERR_SmallTerrainPlacementProbe();
m_SmallTerrainTest.Setup(PrisonPosition()); m_SmallTerrainDeadline = System.GetTickCount() + 60000;
}
if (System.GetTickCount() > m_SmallTerrainDeadline)
{
Print("ERR SMOKE FAIL: small-terrain native survey deadline",LogLevel.ERROR);
GetGame().GetCallqueue().Remove(ERR_TestSmallTerrain); return;
}
if (m_SmallTerrainTest.Test() != 0) GetGame().GetCallqueue().Remove(ERR_TestSmallTerrain);
}
}
#endif