Fix low-terrain startup and extraction placement; record Workshop 0.0.121
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -114,12 +114,22 @@ run(r'''
|
||||
#include <vector>
|
||||
#define null nullptr
|
||||
struct vector{float x=0,y=0,z=0;};vector operator+(vector a,vector b){return{a.x+b.x,a.y+b.y,a.z+b.z};}float DistanceXZ(vector a,vector b){return std::hypot(a.x-b.x,a.z-b.z);}
|
||||
namespace Kind{constexpr int PRISON=0;}
|
||||
namespace Kind{constexpr int PRISON=0,EXTRACTION=2;}
|
||||
struct SiteData{int Kind=0,ResponseCount=0;bool Guarded=false,crash=false;vector GuardOffset,ResponseOffset;};
|
||||
namespace StartSetup{bool measured=true;bool IsCrash(SiteData*s){return s->crash;}bool Geometry(vector&offset,vector¢er,float&half,float&height){offset={16,1,0};center={17,0,0};half=6;height=6;return measured;}}
|
||||
struct Road{};struct RoadManager{void GetClosestRoad(vector,Road*&,float&,bool){}};struct AIWorld{RoadManager roads;RoadManager*GetRoadNetworkManager(){return &roads;}};
|
||||
struct Call{vector p;float half,height;};
|
||||
struct Survey{std::string m_Rejection;bool Reject(std::string reason){m_Rejection=reason;return false;}AIWorld world;std::vector<vector>m_Airfields;std::vector<Call>calls;int refuse=0;vector Rotate(vector p,float h){assert(h==90);return{p.z,p.y,-p.x};}bool Clear(vector p,float,float half,float,float&floor,float height=4){calls.push_back({p,half,height});floor=42;return int(calls.size())!=refuse;}SITE};
|
||||
int main(){SiteData a;float floor=0;Survey airport;airport.m_Airfields.push_back({600,0,0});assert(!airport.Site(&a,{0,0,0},90,floor)&&airport.calls.empty());assert(airport.Site(&a,{0,0,0},90,floor,300)&&airport.calls.size()==1);Survey normal;assert(normal.Site(&a,{100,0,200},90,floor)&&normal.calls.size()==1&&normal.calls[0].half==10&&normal.calls[0].height==4);a.crash=true;Survey crash;assert(crash.Site(&a,{100,0,200},90,floor)&&crash.calls.size()==2);assert(crash.calls[1].p.x==100&&crash.calls[1].p.z==183&&crash.calls[1].half==6&&crash.calls[1].height==6);for(int refusal:{1,2}){Survey blocked;blocked.refuse=refusal;assert(!blocked.Site(&a,{100,0,200},90,floor));}StartSetup::measured=false;Survey unknown;assert(!unknown.Site(&a,{100,0,200},90,floor)&&unknown.calls.size()==1);}
|
||||
struct Road{};struct RoadManager{Road road;bool near=false;int queries=0;void GetClosestRoad(vector,Road*&r,float&distance,bool){queries++;r=near?&road:nullptr;distance=0;}};struct AIWorld{RoadManager roads;RoadManager*GetRoadNetworkManager(){return &roads;}};
|
||||
struct Call{vector p;float half,height,range;};
|
||||
struct Survey{std::string m_Rejection;bool Reject(std::string reason){m_Rejection=reason;return false;}AIWorld world;std::vector<vector>m_Airfields;std::vector<Call>calls;int refuse=0;float variation=0;vector Rotate(vector p,float h){assert(h==90);return{p.z,p.y,-p.x};}bool Clear(vector p,float,float half,float range,float&floor,float height=4){calls.push_back({p,half,height,range});floor=42;return int(calls.size())!=refuse&&variation<=range;}SITE};
|
||||
int main(){
|
||||
SiteData camp,pad;pad.Kind=Kind::EXTRACTION;float h;
|
||||
Survey roadside;roadside.world.roads.near=true;
|
||||
assert(!roadside.Site(&camp,{0,0,0},90,h)&&roadside.m_Rejection=="road proximity");
|
||||
assert(roadside.Site(&pad,{0,0,0},90,h)&&roadside.world.roads.queries==1);
|
||||
assert(roadside.calls.size()==1&&std::abs(roadside.calls[0].range-.8f)<.001);
|
||||
Survey gentle;gentle.variation=.7f;assert(!gentle.Site(&camp,{0,0,0},90,h)&&gentle.Site(&pad,{0,0,0},90,h));gentle.variation=.9f;assert(!gentle.Site(&pad,{0,0,0},90,h));
|
||||
Survey blockedPad;blockedPad.refuse=1;assert(!blockedPad.Site(&pad,{0,0,0},90,h));
|
||||
pad.Guarded=true;Survey blockedGuards;blockedGuards.refuse=2;assert(!blockedGuards.Site(&pad,{0,0,0},90,h));
|
||||
Survey guards;assert(guards.Site(&pad,{0,0,0},90,h)&&guards.calls.size()==2&&std::abs(guards.calls[1].range-.6f)<.001);
|
||||
SiteData a;float floor=0;Survey airport;airport.m_Airfields.push_back({600,0,0});assert(!airport.Site(&a,{0,0,0},90,floor)&&airport.calls.empty());assert(airport.Site(&a,{0,0,0},90,floor,300)&&airport.calls.size()==1);Survey normal;assert(normal.Site(&a,{100,0,200},90,floor)&&normal.calls.size()==1&&normal.calls[0].half==10&&normal.calls[0].height==4);a.crash=true;Survey crash;assert(crash.Site(&a,{100,0,200},90,floor)&&crash.calls.size()==2);assert(crash.calls[1].p.x==100&&crash.calls[1].p.z==183&&crash.calls[1].half==6&&crash.calls[1].height==6);for(int refusal:{1,2}){Survey blocked;blocked.refuse=refusal;assert(!blocked.Site(&a,{100,0,200},90,floor));}StartSetup::measured=false;Survey unknown;assert(!unknown.Site(&a,{100,0,200},90,floor)&&unknown.calls.size()==1);}
|
||||
'''.replace('SITE',site))
|
||||
print('PASS: actual GameMode readiness admission and common full-footprint survey require crash authorization and both surveyed areas')
|
||||
|
||||
@@ -31,28 +31,42 @@ int main(){
|
||||
d.m_Began=Clock::now;d.ReportProgress(&site);assert(reports.size()==3);d.RecordRejection("obstructed footprint");assert(d.RejectionSummary()=="obstructed footprint=1");
|
||||
}
|
||||
''')
|
||||
# Execute the actual water, elevation, flatness and physical-trace short circuits.
|
||||
# Execute actual terrain-height water queries, low dry land and physical checks.
|
||||
clear=body(p,'protected bool Reject(')+'\n'+body(p,'bool Clear(')
|
||||
clear=clear.replace('protected ', '').replace('out float lowest','float& lowest').replace('float.MAX','FLT_MAX').replace('Math.','Math::').replace('TraceBox trace','TraceBox* trace').replace('trace.','trace->').replace('TraceFlags.','TraceFlags::').replace('null','nullptr').replace('ChimeraWorldUtils.','ChimeraWorldUtils::')
|
||||
clear=clear.replace('protected ', '').replace('out float lowest','float& lowest').replace('float.MAX','FLT_MAX').replace('Math.','Math::').replace('TraceBox trace','TraceBox* trace').replace('trace.','trace->').replace('TraceFlags.','TraceFlags::').replace('null','nullptr').replace('ChimeraWorldUtils.','ChimeraWorldUtils::').replace('ERR_ForceRules.','ERR_ForceRules::')
|
||||
dry=body(p.parent/'ERR_Actors.c','static bool DryGround(').replace('ERR_ForceRules.','ERR_ForceRules::').replace('ChimeraWorldUtils.','ChimeraWorldUtils::')
|
||||
for a,b in [('"-1.42 0 -1.42"','Vector(-1.42,0,-1.42)'),('"1.42 0.1 1.42"','Vector(1.42,.1,1.42)')]:clear=clear.replace(a,b)
|
||||
run(r'''
|
||||
#include <cassert>
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
using string=std::string;
|
||||
struct vector{float p[3];float operator[](int i){return p[i];}};vector Vector(float x,float y,float z){return {{x,y,z}};}vector operator+(vector a,vector b){return Vector(a[0]+b[0],a[1]+b[1],a[2]+b[2]);}
|
||||
struct vector{float p[3];float& operator[](int i){return p[i];}};vector Vector(float x,float y,float z){return {{x,y,z}};}vector operator+(vector a,vector b){return Vector(a[0]+b[0],a[1]+b[1],a[2]+b[2]);}
|
||||
namespace Math{float Min(float a,float b){return std::min(a,b);}float Max(float a,float b){return std::max(a,b);}}
|
||||
namespace TraceFlags{int ENTS=1,WORLD=2;}struct TraceBox{vector Start,End,Mins,Maxs;int Flags;};
|
||||
struct World{bool water=false,blocked=false,slope=false;float height=42;int traces=0;float GetSurfaceY(float x,float){return height+(slope?x:0);}float TraceMove(TraceBox*,void*){traces++;return blocked?0:1;}};
|
||||
struct World{bool water=false,puddle=false,blocked=false,slope=false;float height=42,waterLevel=43;int traces=0;float GetSurfaceY(float x,float){return height+(slope?x:0);}float TraceMove(TraceBox*,void*){traces++;return blocked?0:1;}};
|
||||
struct Game{World world;World&GetWorld(){return world;}}game;Game&GetGame(){return game;}
|
||||
namespace ChimeraWorldUtils{bool TryGetWaterSurfaceSimple(World&w,vector){return w.water;}}
|
||||
namespace ERR_ForceRules{bool Finite(float n){return std::isfinite(n);}}
|
||||
namespace ChimeraWorldUtils{bool TryGetWaterSurfaceSimple(World&w,vector p){return (w.water||(w.puddle&&p[0]==2&&p[2]==2))&&p[1]<w.waterLevel;}}
|
||||
namespace ERR_Actors{'''+dry+r'''}
|
||||
struct Terrain{string m_Rejection;vector Rotate(vector p,float){return p;}
|
||||
'''+clear+r'''
|
||||
};
|
||||
int main(){Terrain t;float floor;auto check=[&](){return t.Clear(Vector(0,0,0),0,10,.6,floor);};
|
||||
game.world.water=true;assert(!check()&&t.m_Rejection=="water"&&game.world.traces==0);
|
||||
game.world.water=false;game.world.height=.5;assert(!check()&&t.m_Rejection=="ground below minimum elevation");
|
||||
// Placeholder Y=0 must not make high dry land look submerged.
|
||||
game.world.waterLevel=0;assert(check()&&t.m_Rejection.empty());
|
||||
game.world.water=false;
|
||||
for(float h:{.5f,0.f,-25.f}){game.world.height=h;assert(check()&&floor==h&&ERR_Actors::DryGround(Vector(0,999,0)));}
|
||||
// A terrain-relative ocean/lake still rejects both high and low submerged ground.
|
||||
for(float h:{42.f,-25.f,.5f}){game.world.height=h;game.world.waterLevel=h+.05f;game.world.water=true;assert(!check()&&t.m_Rejection=="water"&&!ERR_Actors::DryGround(Vector(0,999,0)));}
|
||||
game.world.water=false;game.world.height=42;game.world.waterLevel=43;game.world.puddle=true;
|
||||
assert(!check()&&t.m_Rejection=="water");game.world.puddle=false; // Water between the old nine sample points.
|
||||
game.world.height=std::numeric_limits<float>::quiet_NaN();assert(!check()&&t.m_Rejection=="invalid terrain height"&&!ERR_Actors::DryGround(Vector(0,0,0)));
|
||||
game.world.traces=0;
|
||||
game.world.height=42;game.world.slope=true;assert(!check()&&t.m_Rejection=="uneven ground"&&game.world.traces==0);
|
||||
game.world.slope=false;game.world.blocked=true;assert(!check()&&t.m_Rejection=="obstructed footprint"&&game.world.traces==1);
|
||||
game.world.blocked=false;assert(check()&&t.m_Rejection.empty()&&floor==42);
|
||||
@@ -65,3 +79,12 @@ for filename in ('ERR_GeneratedSites.c','ERR_TerrainSites.c'):
|
||||
assert 'ReportSearch(site, "placed"); ClearDiagnostics();' in source
|
||||
assert 'Checks: ' in source and 'RejectionSummary();' in source
|
||||
print('PASS: actual terrain refusal reasons, counted summaries, site/attempt/time context, 30-second rate limit and per-site reset')
|
||||
|
||||
# Every downstream startup gate uses actual dry terrain rather than map altitude.
|
||||
for filename in ('ERR_SiteService.c','ERR_SpawnPlacement.c','ERR_AirfieldPlacement.c'):
|
||||
source=(p.parent/filename).read_text()
|
||||
assert 'ERR_Actors.DryGround(' in source
|
||||
assert '[1] < 1' not in source and '[1] < 2' not in source
|
||||
source=(p.parent.parent/'10_AI/ERR_MortarSystem.c').read_text()
|
||||
assert 'ERR_Actors.DryGround(position)' in source and 'position[1] < 1' not in source
|
||||
print('PASS: actual low/negative dry terrain, height-correct shallow/lake/ocean/interior water refusal and downstream startup dry-ground gates')
|
||||
|
||||
@@ -79,7 +79,8 @@ int main(){
|
||||
assert(Actual::Coordinate(6501.4f,2)==6501);
|
||||
assert(Actual::PhaseDescription(nullptr,true).empty());
|
||||
mode.phase=ERR_Phase::PREPARING;assert(has(Actual::PhaseDescription(&mode,true),"Preparing mission"));
|
||||
mode.error="bad";assert(has(Actual::PhaseDescription(&mode,true),"could not start"));
|
||||
mode.error="bad";auto failure=Actual::PhaseDescription(&mode,true);
|
||||
assert(has(failure,"Reason: bad")&&has(failure,"restart the scenario")&&!has(failure,"/esc"));
|
||||
mode.phase=ERR_Phase::PRISON;assert(has(Actual::PhaseDescription(&mode,true),"Pick the gate lock"));
|
||||
mode.phase=ERR_Phase::RADIO_DEFENCE;assert(has(Actual::PhaseDescription(&mode,true),"interrupted"));
|
||||
mode.occupied=true;assert(has(Actual::PhaseDescription(&mode,true),"in progress"));
|
||||
|
||||
@@ -156,12 +156,12 @@ namespace Math {
|
||||
float Min(float a,float b){return a<b?a:b;}float Clamp(float v,float lo,float hi){return v<lo?lo:(v>hi?hi:v);}
|
||||
float Cos(float a){return std::cos(a);}float Sin(float a){return std::sin(a);}
|
||||
}
|
||||
namespace ERR_Actors {vector Ground(vector p){return p;}}
|
||||
namespace ERR_Actors {vector Ground(vector p){p[1]=42.5;return p;}}
|
||||
namespace ERR_CampTerrain {vector Rotate(vector p,float){return p;}}
|
||||
namespace ERR_AirfieldPlacement {
|
||||
bool airfield=false,ground=true;int airportChecks=0,groundChecks=0;
|
||||
bool Clear(vector){airportChecks++;return airfield;}
|
||||
bool ClearGround(vector){groundChecks++;return ground;}
|
||||
bool Clear(vector p){assert(p[1]==42.5);airportChecks++;return airfield;}
|
||||
bool ClearGround(vector p){assert(p[1]==42.5);groundChecks++;return ground;}
|
||||
}
|
||||
namespace ERR_RescueLanding {bool fits=true;int checks=0;bool Fits(vector){checks++;return fits;}}
|
||||
template<class T>struct Array:std::vector<T>{bool IsEmpty(){return this->empty();}int Count(){return this->size();}};
|
||||
@@ -196,7 +196,7 @@ int main(){
|
||||
site.Kind=Kind::PRISON;p=s.SamplePosition(&site);assert(p[0]==5000&&p[2]==-1000&&Math::indexed==1);
|
||||
site.Kind=Kind::EXTRACTION;site.RequireAirfield=false;
|
||||
p=s.SamplePosition(&site);assert(p[0]==5000&&p[2]==-1000&&Math::indexed==1);
|
||||
assert(s.Survey(&site,p,0,floor)&&floor==42);assert(ERR_AirfieldPlacement::groundChecks==1&&ERR_AirfieldPlacement::airportChecks==0&&s.m_Terrain.airportBuffer==1200);
|
||||
assert(s.Survey(&site,p,0,floor)&&floor==42.5);assert(ERR_AirfieldPlacement::groundChecks==1&&ERR_AirfieldPlacement::airportChecks==0&&s.m_Terrain.airportBuffer==1200);
|
||||
ERR_AirfieldPlacement::ground=false;assert(!s.Survey(&site,p,0,floor)&&s.m_PadRejected==1);
|
||||
site.RequireAirfield=true;ERR_AirfieldPlacement::ground=true;
|
||||
assert(!s.Survey(&site,p,0,floor));assert(ERR_AirfieldPlacement::airportChecks==1&&ERR_AirfieldPlacement::groundChecks==2);
|
||||
@@ -210,7 +210,7 @@ int main(){
|
||||
int rejected=s.m_PadRejected;assert(!s.Survey(&site,p,0,floor)&&s.m_PadRejected==rejected+1);
|
||||
ERR_RescueLanding::fits=true;assert(s.Survey(&site,p,0,floor));
|
||||
site.Kind=Kind::PRISON;ERR_RescueLanding::fits=false;int fleetChecks=ERR_RescueLanding::checks;
|
||||
assert(s.Survey(&site,p,0,floor)&&ERR_RescueLanding::checks==fleetChecks);
|
||||
assert(s.Survey(&site,p,0,floor)&&floor==42&&ERR_RescueLanding::checks==fleetChecks);
|
||||
}
|
||||
''')
|
||||
print('PASS: real sampling handles absent airports and extraction clearance preserves geometry/navigation/flatness while selecting the correct aircraft survey')
|
||||
|
||||
Reference in New Issue
Block a user