"""Actual delivered-memory road selector, geometry and native-query boundaries.""" from pathlib import Path import os,re from policy_harness import ROOT,body,run p=Path(os.environ.get('ERR_MOUNTED_INTERCEPT_SOURCE',ROOT/'addons/core/Scripts/Game/ERR/10_AI/ERR_HQMountedIntercept.c')) source=p.read_text() base=ROOT/'addons/core/Scripts/Game/ERR/10_AI/ERR_HQRoadIntercept.c' source='class ERR_HQRoadIntercept\n{\n'+'\n'.join(body(base,x) for x in ('static bool Eligible(', 'static bool Unreserved(', 'static bool Better('))+'\n}\n'+source for forbidden in ('GetPlayer','GetControlledEntity','GetOrigin','Spawn(', 'AddWaypoint','SetOrigin','CallLater'): assert forbidden not in source,forbidden rules='\n'.join(body(ROOT/'addons/core/Scripts/Game/ERR/10_AI/ERR_HQPursuit.c', x) for x in ('static bool Finite(', 'static bool PositionValid(', 'static bool Actionable(', 'static bool Heading(', 'static ERR_HQPursuitRole Role(', 'static vector Direction(', 'static vector Objective(')) rules=rules.replace('Math.','Math::').replace('vector.','vector::').replace('ERR_HQPursuitRole.','ERR_HQPursuitRole::').replace('vector offset;','vector offset{};') s=re.sub(r'//[^\n]*','',source).replace('ref ','').replace('class ERR_HQRoadIntercept','struct ERR_HQRoadIntercept').replace('class ERR_HQMountedInterceptRules','struct ERR_HQMountedInterceptRules').replace('class ERR_ConvoyInterceptOrder','struct ERR_ConvoyInterceptOrder') s=s.replace('out vector','vector&').replace('out float','float&').replace('array','Array').replace('array','Array').replace('foreach (','for (') s=s.replace('SCR_AIWorld.Cast(GetGame().GetAIWorld())','GetGame()->GetAIWorld()') for name in ('ERR_HQBelief','SCR_AIWorld','BaseRoad','TraceBox','SCR_AIGroup','ERR_ConvoyInterceptOrder','ERR_SettlementSafety','ERR_ConvoyPlacement','ERR_InterceptVehicleFootprint'): s=re.sub(r'\b'+name+r' (\w+)',name+r'* \1',s) for name in ('belief','world','road','body','order','settlements','placement','footprint'): s=s.replace(name+'.',name+'->') s=s.replace('Footprint.', 'Footprint->') s=s.replace('GetGame().','GetGame()->').replace('GetRoadNetworkManager().','GetRoadNetworkManager()->').replace('GetWorld().','GetWorld()->') for name in ('ERR_ForceRules','ERR_HQPursuitRules','ERR_HQPursuitRole','ERR_HQMemoryKind','vector','Math','ERR_Actors','ChimeraWorldUtils','TraceFlags','Replication','ERR_HQRoadIntercept'): s=s.replace(name+'.',name+'::') s=s.replace('null','nullptr').replace('string SourceId','std::string SourceId').replace('.IsEmpty()', '.empty()') s=re.sub(r'\b(bool|int|float) (\w+);',r'\1 \2{};',s).replace('float score, heading;', 'float score=0, heading=0;').replace('\n}\n','\n};\n') run(r''' #include #include #include #include #include #include #include enum class ERR_HQPursuitRole{SEARCH,INTERCEPT,CONTAIN};enum class ERR_HQMemoryKind{SIGHTING,DISTRESS,BODY}; struct SCR_AIGroup{};struct ERR_InterceptVehicleFootprint{bool valid=true;float radius=4;bool Valid(){return valid;}float Radius(){return radius;}}; struct Math{static float Max(float a,float b){return std::max(a,b);}static constexpr float RAD2DEG=57.2957795131f;static float Atan2(float x,float y){return std::atan2(x,y);}static float Clamp(float x,float a,float b){return std::clamp(x,a,b);}static float AbsFloat(float x){return std::abs(x);}}; struct vector{float x=0,y=0,z=0;vector()=default;vector(float a,float b,float c):x(a),y(b),z(c){}vector(const char*s){sscanf(s,"%f %f %f",&x,&y,&z);}float&operator[](int i){return i==0?x:i==1?y:z;}float operator[](int i)const{return i==0?x:i==1?y:z;} vector operator+(vector b)const{return{x+b.x,y+b.y,z+b.z};}vector operator-(vector b)const{return{x-b.x,y-b.y,z-b.z};}vector operator*(float n)const{return{x*n,y*n,z*n};}bool operator==(vector b)const{return x==b.x&&y==b.y&&z==b.z;} float Length()const{return std::sqrt(x*x+y*y+z*z);}vector Normalized()const{float n=Length();return{x/n,y/n,z/n};}static float Dot(vector a,vector b){return a.x*b.x+a.y*b.y+a.z*b.z;}static float DistanceXZ(vector a,vector b){return std::hypot(a.x-b.x,a.z-b.z);}static vector Lerp(vector a,vector b,float n){return a+(b-a)*n;}static const vector Zero;}; const vector vector::Zero{};vector Vector(float a,float b,float c){return{a,b,c};} templatestruct Array:std::vector{using std::vector::vector;using std::vector::operator=;int Count(){return this->size();}void Insert(T v){this->push_back(v);}explicit operator bool(){return true;}}; struct ERR_ForceRules{static bool Finite(float n){return std::isfinite(n);}static bool FiniteVector(vector p){return Finite(p.x)&&Finite(p.y)&&Finite(p.z);}}; struct ERR_HQPursuitRules{''' + rules + r'''}; struct ERR_HQBelief{ERR_HQMemoryKind Kind=ERR_HQMemoryKind::SIGHTING;int SampleCount=2,MessageId=1,BeliefId=3,BeliefRevision=2;vector Position={1000,10,1000};float ObservedAt=5000,LastDeliveredAt=7000,Confidence=.9,Radius=40;std::string TravelMode="on foot";vector PredictedPosition={1000,10,1000},Velocity={0,0,4};bool HasVelocity=true;}; struct TraceFlags{static constexpr int WORLD=1,ENTS=2;};struct TraceBox{vector Start,End,Mins,Maxs;int Flags=0;}; struct NativeWorld{int traces=0;float fraction=1;float TraceMove(TraceBox* t,void*){traces++;assert(t->Flags==3&&t->Mins.y==-.9f);return fraction;}}; struct BaseRoad{float width=6;Arraypoints={{900,10,1300},{1100,10,1300}};float GetWidth(){return width;}void GetPoints(Array&p){p=points;}}; struct RoadManager{Arrayroads;int queries=0;void GetRoadsInAABB(vector low,vector high,Array&out){queries++;assert(high.x-low.x==200&&high.z-low.z==200&&high.y-low.y==2000);out=roads;}}; struct SCR_AIWorld{RoadManager manager;bool available=true;RoadManager*GetRoadNetworkManager(){return available?&manager:nullptr;}}; struct Game{NativeWorld world;SCR_AIWorld ai;NativeWorld*GetWorld(){return &world;}SCR_AIWorld*GetAIWorld(){return &ai;}}game;Game*GetGame(){return &game;} struct Replication{static inline bool server=true;static bool IsServer(){return server;}}; struct ERR_Actors{static inline bool steep=false;static vector Ground(vector p){p.y=10;if(steep&&p.x>1000)p.y=11;return p;}}; struct ChimeraWorldUtils{static inline bool water=false;static bool TryGetWaterSurfaceSimple(NativeWorld*,vector){return water;}}; struct ERR_SettlementSafety{static inline bool clear=true;static inline int calls=0;bool OutsideSettlements(vector){calls++;return clear;}}; struct ERR_ConvoyPlacement{static inline bool clear=true;static inline int calls=0;static inline float heading=0;bool ClearFootprint(vector p,float h,ERR_InterceptVehicleFootprint*){return Clear(p,h);}bool Clear(vector p,float h){calls++;heading=h;assert(p.y==10);return clear;}}; ''' + s + r''' int main(){ using Rules=ERR_HQMountedInterceptRules;ERR_HQBelief belief;ERR_InterceptVehicleFootprint footprint;SCR_AIGroup group; Array reserved;BaseRoad road;road.width=8;game.ai.manager.roads={&road};vector result={1,2,3}; auto select=[&](){int q=game.ai.manager.queries;bool ok=Rules::SelectArmored(&belief,10000,reserved,&footprint,result);assert(game.ai.manager.queries-q==1);if(!ok)assert(result==vector::Zero);return ok;}; assert(select()&&result==vector(1000,10,1300)); road.width=7.999;assert(!select());road.width=8; road.points={{997,10,1300},{1000,10,1300},{1000,10,1303}};assert(!select()); road.points={{996,10,1300},{1004,10,1300}};assert(select()); road.points={{996,20,1300},{1004,20,1300}};assert(!select()); road.points={{996,7,1300},{1004,13,1300}};assert(!select()); // Center matches terrain but footprint ends do not. road.points={{900,10,1300},{1100,10,1300}}; ERR_ConvoyPlacement::clear=false;assert(!select());ERR_ConvoyPlacement::clear=true; ERR_SettlementSafety::clear=false;assert(!select());ERR_SettlementSafety::clear=true; reserved={{1000,10,1379.99f}};assert(!select());reserved={{1000,10,1380}};assert(select());reserved.clear(); footprint.valid=false;int q=game.ai.manager.queries;assert(!Rules::SelectArmored(&belief,10000,reserved,&footprint,result)&&q==game.ai.manager.queries);footprint.valid=true; auto saved=belief;belief.HasVelocity=false;assert(!Rules::SelectArmored(&belief,10000,reserved,&footprint,result)&&q==game.ai.manager.queries);belief=saved; road.width=NAN;assert(!select());road.width=8;road.points[0].x=NAN;assert(!select());road.points[0].x=900; game.ai.manager.roads.assign(129,&road);assert(!select());game.ai.manager.roads={&road}; BaseRoad many;many.width=1;many.points.assign(1024,{1000,10,1300});game.ai.manager.roads={&road,&many,&many,&many,&many,&many};assert(!select()); game.ai.manager.roads={&road};ERR_ConvoyInterceptOrder order;order.Token=400001;order.Group=&group;order.SourceId="original-convoy";order.VehicleIndex=4;order.Armored=true;order.Footprint=&footprint;order.ConfirmedLosses=6;order.Position={1000,10,1300};order.IssuedAt=8000;order.ExpiresAt=125000;order.ObservedAt=5000;order.BeliefId=3;order.BeliefRevision=2;order.ReportId=1; assert(Rules::Current(&order,&belief,10000));order.ConfirmedLosses=5;assert(!Rules::Current(&order,&belief,10000));order.ConfirmedLosses=6; order.Armored=false;assert(!Rules::Current(&order,&belief,10000));order.Armored=true; order.VehicleIndex=0;assert(!Rules::Current(&order,&belief,10000));order.VehicleIndex=4; footprint.valid=false;assert(!Rules::Current(&order,&belief,10000));footprint.valid=true;order.Footprint=nullptr;assert(!Rules::Current(&order,&belief,10000)); } ''') print('PASS: actual BMP singleton geometry and typed current order; one survey, full straight segment, width, known history, reservations, settlement/clearance and work caps; placement/footprint tested separately')