"""Actual qualification claim/footprint bounds and release bodies; native traces remain untested.""" from policy_harness import ROOT, body, run import re BASE=ROOT/'addons/core/Scripts/Game/ERR/10_AI' SOURCE=BASE/'ERR_AircraftFlightEnvelope.c' claim=body(SOURCE,'bool Claim(').replace('ERR_GameMode mode','ERR_GameMode* mode').replace('Vehicle aircraft','Vehicle* aircraft').replace('IEntity pilot','IEntity* pilot') claim=claim.replace('Replication.','Replication::').replace('ERR_GameMode.Get()', 'ERR_GameMode::Get()').replace('vector.','vector::').replace('mode.Active()', 'mode->Active()').replace('aircraft.GetOrigin()', 'aircraft->GetOrigin()').replace('GetGame().GetWorld().GetWorldTime()', 'GetGame()->GetWorld()->GetWorldTime()').replace('GetGame().GetWorld()', 'GetGame()->GetWorld()') claim=re.sub(r'(? #include struct vector {float x=0,y=0,z=0;static float Distance(vector a,vector b){return std::sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));}}; struct Vehicle {vector origin;vector GetOrigin(){return origin;}}; struct IEntity {}; struct ERR_GameMode {bool active=true;bool Active(){return active;}static ERR_GameMode* current;static ERR_GameMode* Get(){return current;}}; ERR_GameMode* ERR_GameMode::current=nullptr; struct World {float now=1000;float GetWorldTime(){return now;}}; struct Game {World* world;World* GetWorld(){return world;}}; Game* game=nullptr;Game* GetGame(){return game;} struct Replication {static bool server;static bool IsServer(){return server;}};bool Replication::server=true; struct Record {ERR_GameMode* m_Mode=nullptr;Vehicle* m_Aircraft=nullptr;IEntity* m_Pilot=nullptr;vector m_Home;float m_QualifiedAt=0;int m_Claim=0; '''+claim+r''' }; '''+rules+r''' int main(){ assert(CylinderSphere(4,12,1.5)==17.5f); assert(Fits(30,1,5)&&!Fits(31,1,5)); assert(!Fits(0,0,0)&&!Fits(32,0,0)&&!Fits(1,0,6)&&!Fits(NAN,0,0)); World world;Game env;env.world=&world;game=&env; ERR_GameMode mode,foreignMode;ERR_GameMode::current=&mode; Vehicle aircraft,other;IEntity pilot,otherPilot; Record blank;assert(!blank.Claim(&mode,&aircraft,&pilot,1)); // default constructed is never a certificate Record valid;valid.m_Mode=&mode;valid.m_Aircraft=&aircraft;valid.m_Pilot=&pilot;valid.m_QualifiedAt=1000; Record consumed=valid;assert(consumed.Claim(&mode,&aircraft,&pilot,11));assert(consumed.m_Claim==11); assert(!consumed.Claim(&mode,&aircraft,&pilot,11)&&!consumed.Claim(&mode,&aircraft,&pilot,12)); for(int fault=0;fault<11;fault++){ Record r=valid;world.now=1000;aircraft.origin={0,0,0};game=&env;env.world=&world;mode.active=true;Replication::server=true; if(fault==0)world.now=3001; if(fault==1)world.now=999; if(fault==2)aircraft.origin={.101f,0,0}; if(fault==3)aircraft.origin={0,.101f,0}; if(fault==4)mode.active=false; if(fault==5)Replication::server=false; if(fault==6)game=nullptr; if(fault==7)env.world=nullptr; if(fault==8)r.m_Aircraft=&other; if(fault==9)r.m_Pilot=&otherPilot; if(fault==10)r.m_Mode=&foreignMode; assert(!r.Claim(&mode,&aircraft,&pilot,1)&&r.m_Claim==0); } game=&env;env.world=&world;world.now=3000;mode.active=true;Replication::server=true;aircraft.origin={.1f,0,0}; Record edge=valid;assert(edge.Claim(&mode,&aircraft,&pilot,9)); Record nullToken=valid;assert(!nullToken.Claim(&mode,&aircraft,&pilot,0)); } ''') controller=BASE/'ERR_AircraftFlight.c' assert 'Release(true)' in body(controller,'void ~ERR_AircraftFlight(') methods='\n'.join(body(controller,key) for key in ['protected void Release(', 'protected void Fail(']) methods=methods.replace('protected ','').replace('ERR_AircraftFlightState.FAILED','FAILED') run(r'''#include #include using string=std::string; struct Registry {void* owner=nullptr;int removes=0;explicit operator bool()const{return true;}void* Get(void*){return owner;}void Remove(void*){owner=nullptr;removes++;}}; struct Controller {int writes=0;void SetAutohoverEnabled(bool){writes++;}void SetCollectiveMode(int){writes++;}}; struct Agent {int writes=0;void SetPermanentLOD(int){writes++;}}; struct Probe { static const int FAILED=10; bool m_SettingsOwned=true,owned=true,ground=false,m_OriginalAutohover=false; int m_State=5,m_OriginalMode=3,m_OriginalLOD=5,inputs=0,logs=0;string m_Reason; void* m_Aircraft=this;Registry s_Owners;Controller m_Controller;Agent m_Agent; Probe(){s_Owners.owner=this;}bool Owns(){return owned;}bool Grounded(){return ground;}bool Finished(){return m_State>=8;} bool Pair(const char*,const char*,float value){assert(value==0);inputs++;return true;}void RecordState(){logs++;} '''+methods+r''' }; int main(){ Probe airborne;airborne.Fail("deadline");assert(airborne.m_State==10&&airborne.logs==1&&airborne.inputs==4); assert(airborne.m_Controller.writes==0&&airborne.m_Agent.writes==0&&!airborne.m_SettingsOwned); Probe ground;ground.ground=true;ground.Fail("hooks unavailable");assert(ground.m_Controller.writes==2&&ground.m_Agent.writes==1&&ground.inputs==4); Probe captured;captured.owned=false;captured.Release(true);assert(captured.inputs==0&&captured.m_Controller.writes==0&&captured.m_Agent.writes==0); Probe unrelated;int other;unrelated.s_Owners.owner=&other;unrelated.owned=false;unrelated.Release(false);assert(unrelated.s_Owners.removes==0); ground.Release(true);assert(ground.inputs==4&&ground.m_Controller.writes==2); // idempotent, no repeated mode writes } ''') s=SOURCE.read_text();qualify=body(SOURCE,'static ERR_AircraftFlightEnvelope Qualify(') assert qualify.index('ClearColumn(')