"""Execute actual mounted sampler/snapshot methods against bounded native doubles.""" import re,os from pathlib import Path from policy_harness import ROOT, run p=Path(os.environ.get('ERR_MOUNTED_AMMO_SOURCE',ROOT/'addons/core/Scripts/Game/ERR/10_AI/ERR_HQMountedAmmoSampler.c')) s=p.read_text() for forbidden in ('SetAmmoCount','GetOrigin','GetWorld','Spawn','TryMove','DeleteEntity','GetAgents'): assert forbidden not in s, forbidden code=re.sub(r'//[^\n]*','',s).replace('protected ','').replace('class ','struct ') code=code.replace('BaseWeaponManagerComponent.Cast(part.FindComponent(BaseWeaponManagerComponent))','part->manager') code=code.replace('BaseWeaponComponent.Cast(part.FindComponent(BaseWeaponComponent))','part->weapon') code=code.replace('BaseWeaponComponent.Cast(mountedEntity.FindComponent(BaseWeaponComponent))','mountedEntity->weapon') code=code.replace('BaseWeaponComponent.Cast(owner.FindComponent(BaseWeaponComponent))','owner->weapon').replace('WeaponSlotComponent.Cast(component)','dynamic_cast(component)') code=code.replace('parent.FindComponents(WeaponSlotComponent, slots)','parent->FindMounts(slots)') code=code.replace('InventoryItemComponent.Cast(mountedEntity.FindComponent(InventoryItemComponent))','mountedEntity->item') code=code.replace('WeaponSlotComponent.Cast(weapon)','dynamic_cast(weapon)').replace('binding.GetParentContainer()','binding->mount') code=code.replace('InventoryItemComponent.Cast(entity.FindComponent(InventoryItemComponent))','entity->item') code=code.replace('InventoryItemComponent.Cast(owner.FindComponent(InventoryItemComponent))','owner->item').replace('ResourceName resource', 'string resource') code=code.replace('WeaponSlotComponent.Cast(slot.GetParentContainer())','slot->mount').replace('BaseMuzzleComponent.Cast(slot.GetParentContainer())','slot->muzzle') code=code.replace('WeaponSlotComponent.Cast(parent.GetParentContainer())','parent->mount').replace('WeaponSlotComponent.Cast(item.GetParentSlot().GetParentContainer())','item->GetParentSlot()->mount') code=code.replace('parent.GetParentContainer()', 'parent->Container()') code=code.replace('EStoragePurpose.','EStoragePurpose::').replace('GetParentSlot().','GetParentSlot()->') code=code.replace('ChimeraCharacter.Cast(entity) != nullptr','entity->character').replace('ChimeraCharacter.Cast(entity) != null','entity->character') code=code.replace('ChimeraCharacter.Cast(root)','root->character').replace('ChimeraCharacter.Cast(entity)','entity->character') code=code.replace('protected static ref ', 'inline static ').replace('static ref ', 'inline static ').replace('ref ', '') code=re.sub(r'\bERR_HQMountedAmmoDiagnostic (?=\w)', 'ERR_HQMountedAmmoDiagnostic* ',code) code=code.replace('s_Diagnostic.', 's_Diagnostic->').replace('GetPrefabData().', 'GetPrefabData()->') code=re.sub(r'\bERR_HQMountedAmmoSnapshot (?=\w)','ERR_HQMountedAmmoSnapshot* ',code) code=code.replace('array<','Array<').replace('foreach (','for (') code=re.sub(r'"[^"]*"|\bnull\b',lambda m:m.group() if m.group().startswith(chr(34)) else 'nullptr',code) code=code.replace('Array allowed, Array weapons,','Array& allowed, Array& weapons,') code=code.replace('Array allowed, Array weapons)', 'Array& allowed, Array& weapons)') for name in ('copy','result','weapon','root','entity','child','part','manager','mounted','muzzle','magazine','item','storage','mount','mountedEntity','mountedItem','owner','parent','binding','parentMount','parentOwner'): code=re.sub(r'\b'+name+r'\.',name+'->',code) code=re.sub(r'\b(bool|int) (\w+);',r'\1 \2=0;',code).replace('\n}\n','\n};\n') program=(r''' #include #include #include #include using string=std::string; struct Prefab{string name="fixture";string GetPrefabName(){return name;}}; templatestruct Array:std::vector{using std::vector::vector; int Count(){return this->size();}bool IsEmpty(){return this->empty();} void Insert(T n){this->push_back(n);}bool Contains(T n){return std::find(this->begin(),this->end(),n)!=this->end();}}; struct Entity;struct Weapon;struct Muzzle;struct Magazine;struct Manager;struct Mount; struct EStoragePurpose{static const int PURPOSE_UNSET=0,PURPOSE_DEPOSIT=1,PURPOSE_WEAPON_PROXY=2,PURPOSE_ATTACHMENT_PROXY=4,PURPOSE_ANY=127;}; struct Storage{int purpose=EStoragePurpose::PURPOSE_DEPOSIT;int GetPurpose(){return purpose;}}; struct Slot{Mount* mount=nullptr;Muzzle* muzzle=nullptr;Storage* storage=nullptr;Entity* attached=nullptr;Entity* GetAttachedEntity(){return attached;}void* Container(){return mount?static_cast(mount):muzzle?static_cast(muzzle):static_cast(storage);}Storage* GetStorage(){return storage;}}; struct Item{Slot* slot=nullptr;Slot* GetParentSlot(){return slot;}}; using InventoryStorageSlot=Slot*;using WeaponSlotComponent=Mount*; using InventoryItemComponent=Item*;using BaseInventoryStorageComponent=Storage*; using Managed=Weapon*;using IEntity=Entity*;using BaseWeaponComponent=Weapon*;using BaseMuzzleComponent=Muzzle*; using BaseMagazineComponent=Magazine*;using BaseWeaponManagerComponent=Manager*; struct Entity{Prefab prefab;Prefab*GetPrefabData(){return &prefab;}Item* item=nullptr;bool character=false;Entity* child=nullptr;Entity* sibling=nullptr;Manager* manager=nullptr;Weapon* weapon=nullptr; Entity* parent=nullptr;Array mounts;Entity* GetParent(){return parent;}void FindMounts(Array&out){out=mounts;} int reads=0;Entity* GetChildren(){reads++;assert(reads<=1);return child;}Entity* GetSibling(){return sibling;}}; struct Magazine{IEntity owner=nullptr;int rounds=25,capacity=100,reads=0; IEntity GetOwner(){return owner;}int GetAmmoCount(){reads++;return rounds;}int GetMaxAmmoCount(){return capacity;}}; struct Muzzle{IEntity owner=nullptr;Magazine* mag=nullptr;int barrels=1,chambered=1,reads=0; IEntity GetOwner(){return owner;}int GetBarrelsCount(){return barrels;} bool IsBarrelChambered(int b){reads++;return b muzzles;int reads=0; IEntity GetOwner(){return owner;}void GetMuzzlesList(Array& out){reads++;out=muzzles;}}; struct Mount:Weapon{IEntity weapon=nullptr;Slot* slot=nullptr; Slot* GetSlotInfo(){return slot;}IEntity GetWeaponEntity(){return weapon;}}; struct Manager{Array weapons;int reads=0;void GetWeapons(Array& out){reads++;out=weapons;}}; '''+code+r''' struct Rig{Entity root,gun,magazine,crew,rifle;Manager manager,crewManager;Weapon weapon,carried; Muzzle muzzle,carriedMuzzle;Magazine mag,carriedMag; Rig(){root.child=&gun;gun.sibling=&magazine;magazine.sibling=&crew;crew.character=true;crew.child=&rifle; root.manager=&manager;manager.weapons={&weapon,&weapon};gun.weapon=&weapon;weapon.owner=&gun;weapon.muzzles={&muzzle,&muzzle}; muzzle.owner=&gun;muzzle.mag=&mag;mag.owner=&magazine; crew.manager=&crewManager;crewManager.weapons={&carried};rifle.weapon=&carried;carried.owner=&rifle; carried.muzzles={&carriedMuzzle};carriedMuzzle.owner=&rifle;carriedMuzzle.mag=&carriedMag;carriedMag.owner=&rifle;} ERR_HQMountedAmmoSnapshot* Inspect(){return ERR_HQMountedAmmoSampler::Inspect(&root);} }; int main(){ // Native observed WCS empty control: no item or null reverse slot, but exact // immediate-parent structural slot. Keep real guns and the weapon cap intact. for(bool hasItem:{false,true})for(bool directFirst:{false,true}){ Rig r;Entity dummy;Weapon inert;Mount mount;Item item;Slot slot; dummy.prefab.name="{52120E4BA120661B}Prefabs/Weapons/Core/Armament_Empty.et"; dummy.parent=&r.root;r.root.mounts={&mount};r.crew.sibling=&dummy;dummy.weapon=&inert;inert.owner=&dummy; if(hasItem)dummy.item=&item; mount.owner=&r.root;mount.weapon=&dummy;mount.slot=&slot;slot.mount=&mount;slot.attached=&dummy; if(directFirst)r.manager.weapons={&inert,&mount,&inert,&r.weapon};else r.manager.weapons={&mount,&inert,&mount,&r.weapon}; auto s=r.Inspect();assert(s->Complete&&s->Valid()&&s->Weapons==1&&s->Muzzles==1&&s->Magazines==1&&s->Rounds==25&&s->Chambers==1); } for(int fault=0;fault<15;fault++){ Rig r;Entity dummy,foreign;Weapon inert,otherWeapon;Mount mount,otherMount;Item item;Slot slot,otherSlot; dummy.prefab.name="{52120E4BA120661B}Prefabs/Weapons/Core/Armament_Empty.et"; dummy.parent=&r.root;r.root.mounts={&mount};r.crew.sibling=&dummy;dummy.weapon=&inert;inert.owner=&dummy; mount.owner=&r.root;mount.weapon=&dummy;mount.slot=&slot;slot.mount=&mount;slot.attached=&dummy;r.manager.weapons={&mount,&inert,&r.weapon}; if(fault==0){dummy.item=&item;item.slot=&otherSlot;} if(fault==1)dummy.prefab.name="{0000000000000000}Prefabs/Weapons/Core/Armament_Empty.et"; if(fault==2)dummy.prefab.name="{52120E4BA120661B}Prefabs/Other.et"; if(fault==3)dummy.prefab.name="{7E1DD1CE4D6A23F4}Prefabs/Weapons/Core/VehiclePeriscope_DummyWeapon_Base.et"; if(fault==4)inert.muzzles={&r.muzzle}; if(fault==5)dummy.parent=nullptr; if(fault==6)dummy.parent=&foreign; if(fault==7)mount.slot=nullptr; if(fault==8)slot.mount=&otherMount; if(fault==9)slot.attached=&foreign; if(fault==10)mount.weapon=&foreign; if(fault==11)mount.owner=&foreign; if(fault==12)r.root.mounts.resize(9,&mount); if(fault==13)r.root.mounts={&mount,&mount}; if(fault==14){otherWeapon.owner=&dummy;dummy.weapon=&otherWeapon;} auto s=r.Inspect();assert(!s->Complete&&s->Valid()); } {Entity root,dummy;Weapon inert;Mount mount;Slot slot;root.child=&dummy;dummy.parent=&root;root.mounts={&mount}; dummy.prefab.name="{52120E4BA120661B}Prefabs/Weapons/Core/Armament_Empty.et";dummy.weapon=&inert;inert.owner=&dummy; mount.owner=&root;mount.weapon=&dummy;mount.slot=&slot;slot.mount=&mount;slot.attached=&dummy; auto s=ERR_HQMountedAmmoSampler::Inspect(&root);assert(s->Complete&&s->Valid()&&s->Weapons==0&&s->Magazines==0&&s->Rounds==0);} // Controls still occupy bounded collection slots before Inspect omits them. for(int count:{32,33}){Entity root;std::vector parents(count),dummies(count);std::vector mounts(count);std::vector slots(count);std::vector inert(count); root.child=&parents[0];for(int i=0;iComplete==(count==32)&&s->Valid()&&s->Weapons==0);} // Installed BMP has three live gun components plus two inert native controls. // Exercise actual Inspect using exact documented resources and reciprocal slots. for(string name:{string("{52120E4BA120661B}Prefabs/Weapons/Core/Armament_Empty.et"),string("{7E1DD1CE4D6A23F4}Prefabs/Weapons/Core/VehiclePeriscope_DummyWeapon_Base.et")}){ Rig r;Entity dummy;Weapon inert;Mount mount;Item item;Slot slot;dummy.prefab.name=name; r.crew.sibling=&dummy;dummy.weapon=&inert;inert.owner=&dummy;dummy.item=&item;item.slot=&slot;slot.mount=&mount;mount.owner=&r.root;mount.slot=&slot;mount.weapon=&dummy; r.manager.weapons.Insert(&mount);r.manager.weapons.Insert(&inert); auto s=r.Inspect();assert(s->Complete&&s->Valid()&&s->Weapons==1&&s->Muzzles==1&&s->Magazines==1&&s->Rounds==25&&s->Capacity==100&&s->Chambers==1&&inert.reads==1); } // A root containing only a known installed inert control is completely unarmed. {Entity root,dummy;Weapon inert;Mount mount;Item item;Slot slot;root.child=&dummy;dummy.prefab.name="{7E1DD1CE4D6A23F4}Prefabs/Weapons/Core/VehiclePeriscope_DummyWeapon_Base.et";dummy.weapon=&inert;inert.owner=&dummy;dummy.item=&item;item.slot=&slot;slot.mount=&mount;mount.owner=&root;mount.slot=&slot;mount.weapon=&dummy;auto s=ERR_HQMountedAmmoSampler::Inspect(&root);assert(s->Complete&&s->Valid()&&s->Weapons==0&&s->Muzzles==0&&s->Magazines==0&&s->Rounds==0&&s->Capacity==0&&s->Chambers==0&&inert.reads==1);} // Both BMP controls coexist: decrement each exactly once while retaining the gun. {Rig r;Entity dummy[2];Weapon inert[2];Mount mount[2];Item item[2];Slot slot[2];r.crew.sibling=&dummy[0];dummy[0].sibling=&dummy[1]; dummy[0].prefab.name="{52120E4BA120661B}Prefabs/Weapons/Core/Armament_Empty.et";dummy[1].prefab.name="{7E1DD1CE4D6A23F4}Prefabs/Weapons/Core/VehiclePeriscope_DummyWeapon_Base.et"; for(int i=0;i<2;i++){dummy[i].weapon=&inert[i];inert[i].owner=&dummy[i];dummy[i].item=&item[i];item[i].slot=&slot[i];slot[i].mount=&mount[i];mount[i].owner=&r.root;mount[i].slot=&slot[i];mount[i].weapon=&dummy[i];r.manager.weapons.Insert(&mount[i]);r.manager.weapons.Insert(&inert[i]);} auto s=r.Inspect();assert(s->Complete&&s->Valid()&&s->Weapons==1&&s->Muzzles==1&&s->Magazines==1&&s->Rounds==25&&s->Capacity==100&&s->Chambers==1&&inert[0].reads==1&&inert[1].reads==1);} // Unknown no-muzzle weapons and broken/foreign installation remain incomplete. for(int bad=0;bad<6;bad++){ Rig r;Entity dummy,foreign;Weapon inert;Mount mount;Item item;Slot slot,other;dummy.prefab.name="{52120E4BA120661B}Prefabs/Weapons/Core/Armament_Empty.et"; r.crew.sibling=&dummy;dummy.weapon=&inert;inert.owner=&dummy;dummy.item=&item;item.slot=&slot;slot.mount=&mount;mount.owner=&r.root;mount.slot=&slot;mount.weapon=&dummy; if(bad==0)dummy.prefab.name="{0000000000000000}Prefabs/Weapons/Core/Armament_Empty.et"; if(bad==1)dummy.item=nullptr; if(bad==2)item.slot=nullptr; if(bad==3)mount.owner=&foreign; if(bad==4)mount.slot=&other; if(bad==5)mount.weapon=&foreign; auto s=r.Inspect();assert(!s->Complete&&s->Valid()); } // A known resource carrying an actual muzzle is never silently omitted. {Rig r;r.gun.prefab.name="{52120E4BA120661B}Prefabs/Weapons/Core/Armament_Empty.et";auto s=r.Inspect();assert(s->Complete&&s->Weapons==1&&s->Rounds==25&&r.muzzle.reads==1);} // An excluded cargo subtree cannot turn a stored placeholder into mounted armament. {Rig r;Entity cargo;Weapon inert;Item item;Slot slot;Storage storage;r.crew.sibling=&cargo;cargo.prefab.name="{52120E4BA120661B}Prefabs/Weapons/Core/Armament_Empty.et";cargo.item=&item;item.slot=&slot;slot.storage=&storage;cargo.weapon=&inert;inert.owner=&cargo;auto s=r.Inspect();assert(s->Complete&&s->Weapons==1&&inert.reads==0);} {auto s=ERR_HQMountedAmmoSampler::Inspect(nullptr);assert(!s->Complete&&s->Valid());} {Entity root;root.character=true;auto s=ERR_HQMountedAmmoSampler::Inspect(&root);assert(!s->Complete&&root.reads==0);} {Entity root;auto s=ERR_HQMountedAmmoSampler::Inspect(&root);assert(s->Complete&&s->Valid()&&s->Weapons==0);} {Rig r;auto s=r.Inspect();assert(s->Complete&&s->Valid()&&s->Weapons==1&&s->Muzzles==1&&s->Magazines==1); assert(s->Rounds==25&&s->Capacity==100&&s->Chambers==1&&s->LowMagazines==1); assert(r.weapon.reads==1&&r.muzzle.reads==1&&r.mag.reads==1&&r.crew.reads==0&&r.crewManager.reads==0&&r.carried.reads==0); auto copy=s->Snapshot();s->Complete=false;s->Rounds=0;s->Capacity=0;s->LowMagazines=0; assert(copy->Complete&©->Rounds==25&©->Capacity==100&©->LowMagazines==1&©->Weapons==1&©->Muzzles==1&©->Magazines==1&©->Chambers==1);} for(int rounds:{0,24,25,26,100}){Rig r;r.mag.rounds=rounds;auto s=r.Inspect();assert(s->Complete&&s->Valid());assert(s->LowMagazines==(rounds<=25));} {Rig r;Muzzle second;second.owner=&r.gun;second.mag=&r.mag;second.chambered=0;r.weapon.muzzles.Insert(&second); auto s=r.Inspect();assert(s->Complete&&s->Muzzles==2&&s->Magazines==1&&s->Chambers==1&&s->Rounds==25&&r.mag.reads==1);} // Manager references into skipped characters, foreign roots, or nulls never count. for(int kind=0;kind<3;kind++){Rig r;Entity foreign;Weapon w;w.owner=&foreign; r.manager.weapons.Insert(kind==0?&r.carried:kind==1?&w:nullptr);auto s=r.Inspect();assert(!s->Complete&&s->Valid()&&s->Weapons==1);} for(int kind=0;kind<3;kind++){Rig r;Entity foreign; if(kind==0)r.muzzle.owner=&foreign; if(kind==1)r.mag.owner=&foreign; if(kind==2)r.mag.owner=nullptr; auto s=r.Inspect();assert(!s->Complete&&s->Valid()&&s->Rounds==0&&s->Magazines==0);} // Deposited rifles and nested magazines are excluded; installed magazine slots remain admitted. {Rig r;Entity cargo,rifle,magEntity;Item item;Slot slot;Storage storage;Weapon rifleWeapon; r.crew.sibling=&cargo;cargo.child=&rifle;rifle.child=&magEntity;rifle.item=&item;item.slot=&slot;slot.storage=&storage; rifle.weapon=&rifleWeapon;rifleWeapon.owner=&rifle;auto s=r.Inspect();assert(s->Complete&&s->Weapons==1&&rifle.reads==0&&magEntity.reads==0);} {Rig r;Item item;Slot slot;Storage storage;r.magazine.item=&item;item.slot=&slot;slot.storage=&storage; storage.purpose=EStoragePurpose::PURPOSE_ATTACHMENT_PROXY;auto s=r.Inspect();assert(s->Complete&&s->Rounds==25&&s->Magazines==1);} for(int purpose:{0,127}){Rig r;Item item;Slot slot;Storage storage;r.gun.item=&item;item.slot=&slot;slot.storage=&storage; storage.purpose=purpose;auto s=r.Inspect();assert(!s->Complete&&s->Weapons==0&&s->Valid());} // Native purposes support combined flags; any deposit bit excludes the subtree. {Rig r;Item item;Slot slot;Storage storage;r.gun.item=&item;item.slot=&slot;slot.storage=&storage; storage.purpose=EStoragePurpose::PURPOSE_DEPOSIT|EStoragePurpose::PURPOSE_ATTACHMENT_PROXY; auto s=r.Inspect();assert(!s->Complete&&s->Weapons==0&&s->Valid());} // Manager references cannot rescue a cargo weapon. {Rig r;Item item;Slot slot;Storage storage;r.gun.item=&item;item.slot=&slot;slot.storage=&storage; auto s=r.Inspect();assert(!s->Complete&&s->Weapons==0&&s->Valid());} // Exact native weapon-slot and muzzle containers are not deposit storage. for(int purpose:{-1,0,127}){Rig r;Item gunItem,magItem;Slot gunSlot,magSlot;Storage storage;Mount mount; mount.owner=&r.root;mount.weapon=&r.gun;mount.slot=&gunSlot;gunSlot.mount=&mount;r.gun.item=&gunItem;gunItem.slot=&gunSlot; magSlot.muzzle=&r.muzzle;r.magazine.item=&magItem;magItem.slot=&magSlot; if(purpose>=0){storage.purpose=purpose;gunSlot.storage=&storage;magSlot.storage=&storage;} auto s=r.Inspect();assert(s->Complete&&s->Valid()&&s->Weapons==1&&s->Magazines==1&&s->Rounds==25&&s->Chambers==1);} // No generic missing-storage bypass: foreign container owners, stale slots and // substituted attached items fail closed, including foreign loaded magazines. for(int fault=0;fault<6;fault++){Rig r;Entity foreign;Item item;Slot slot,other;Mount mount; r.gun.item=&item;item.slot=&slot;slot.mount=&mount;mount.owner=&r.root;mount.weapon=&r.gun;mount.slot=&slot; if(fault==0)mount.owner=&foreign; if(fault==1)mount.owner=&r.crew; if(fault==2)mount.weapon=&foreign; if(fault==3)mount.slot=&other; if(fault==4)slot.mount=nullptr; if(fault==5)mount.owner=nullptr; auto s=r.Inspect();assert(!s->Complete&&s->Weapons==0&&s->Rounds==0&&s->Valid());} for(int fault=0;fault<3;fault++){Rig r;Entity foreign;Item item;Slot slot; r.magazine.item=&item;item.slot=&slot;slot.muzzle=&r.muzzle; if(fault==0)r.muzzle.owner=&foreign; if(fault==1)r.muzzle.mag=nullptr; if(fault==2)r.mag.owner=&foreign; auto s=r.Inspect();assert(!s->Complete&&s->Magazines==0&&s->Rounds==0&&s->Valid());} // An exact loaded magazine inside an excluded cargo rifle does not re-admit it. {Rig r;Item item,magItem;Slot slot,magSlot;Storage deposit;r.gun.item=&item;item.slot=&slot;slot.storage=&deposit; r.magazine.item=&magItem;magItem.slot=&magSlot;magSlot.muzzle=&r.muzzle; auto s=r.Inspect();assert(!s->Complete&&s->Weapons==0&&s->Magazines==0&&s->Valid());} // Native manager/FindComponent expose the wrapper and the physical weapon. // A UAZ's single PKM must be one weapon even when all those paths overlap. {Rig r;Mount mount;Item item;Slot binding;mount.owner=&r.root;mount.weapon=&r.gun;mount.slot=&binding; binding.mount=&mount;item.slot=&binding;r.gun.item=&item;r.root.weapon=&mount;mount.muzzles=r.weapon.muzzles; r.manager.weapons={&mount,&r.weapon,&mount};auto s=r.Inspect(); assert(s->Complete&&s->Valid()&&s->Weapons==1&&s->Muzzles==1&&s->Magazines==1&&s->Rounds==25&&s->Chambers==1); assert(mount.reads==0&&r.weapon.reads==1&&r.mag.reads==1);} // Unknown/foreign/empty/nested/stale slot endpoints never become real guns. for(int fault=0;fault<11;fault++){Rig r;Entity foreign;Mount mount,other;Item item;Slot binding,stale; mount.owner=&r.root;mount.weapon=&r.gun;mount.slot=&binding;binding.mount=&mount;item.slot=&binding;r.gun.item=&item; r.root.weapon=&mount;r.manager.weapons={&mount}; if(fault==0)mount.weapon=nullptr; if(fault==1)mount.weapon=&foreign; if(fault==2)mount.weapon=&r.root; // nested/self wrapper if(fault==3)binding.mount=&other; if(fault==4)item.slot=&stale; if(fault==5)mount.slot=nullptr; if(fault==6)r.gun.item=nullptr; if(fault==7)mount.owner=&foreign; if(fault==8)r.gun.weapon=nullptr; if(fault==9){other.owner=&r.gun;r.gun.weapon=&other;} // valid first binding, nested wrapper endpoint if(fault==10)r.weapon.owner=&foreign; // component found on target belongs elsewhere auto s=r.Inspect();assert(!s->Complete&&s->Valid()&&s->Weapons<=1&&mount.reads==0&&other.reads==0);} // Thirty-two genuine installed guns still fit the weapon cap despite wrappers. {Entity root;Array hosts(32),guns(32),mags(32);Array weapons(32);Array mounts(32); Array muzzles(32);Array magazines(32);Array items(32);Array bindings(32); root.child=&hosts[0];for(int i=0;i<32;i++){ if(i+1<32)hosts[i].sibling=&hosts[i+1]; hosts[i].child=&guns[i];guns[i].child=&mags[i];hosts[i].weapon=&mounts[i];guns[i].weapon=&weapons[i]; mounts[i].owner=&hosts[i];mounts[i].weapon=&guns[i];mounts[i].slot=&bindings[i];bindings[i].mount=&mounts[i]; items[i].slot=&bindings[i];guns[i].item=&items[i];weapons[i].owner=&guns[i];weapons[i].muzzles={&muzzles[i]}; mounts[i].muzzles=weapons[i].muzzles;muzzles[i].owner=&guns[i];muzzles[i].mag=&magazines[i];magazines[i].owner=&mags[i];} auto s=ERR_HQMountedAmmoSampler::Inspect(&root);assert(s->Complete&&s->Valid()&&s->Weapons==32&&s->Muzzles==32&&s->Magazines==32&&s->Rounds==800);} // Missing/projectile-only magazines and unsupported native values stay incomplete. for(int kind=0;kind<9;kind++){Rig r; if(kind==0)r.muzzle.mag=nullptr; if(kind==1)r.weapon.muzzles={nullptr}; if(kind==2)r.weapon.muzzles={}; if(kind==3)r.muzzle.barrels=0; if(kind==4)r.muzzle.barrels=33; if(kind==5)r.mag.rounds=-1; if(kind==6)r.mag.capacity=0; if(kind==7)r.mag.capacity=100001; if(kind==8)r.mag.rounds=101; auto s=r.Inspect();assert(!s->Complete&&s->Valid());} {Rig r;r.weapon.muzzles=Array(9,&r.muzzle);auto s=r.Inspect();assert(!s->Complete&&s->Muzzles==0&&r.muzzle.reads==0);} {Rig r;r.manager.weapons=Array(9,&r.weapon);auto s=r.Inspect();assert(!s->Complete&&s->Weapons==1&&s->Valid());} // Entity budget also bounds enqueue and cycles, rather than only processed work. for(int count:{128,129,300}){std::vector nodes(count);for(int i=0;iComplete==(count==128));assert(s->Valid()); int reads=0;for(auto& e:nodes)reads+=e.reads;assert(reads==128);} {Entity root,child;root.child=&child;child.sibling=&child;auto s=ERR_HQMountedAmmoSampler::Inspect(&root);assert(!s->Complete&&s->Valid());} {Entity root,child;root.child=&child;child.child=&root;auto s=ERR_HQMountedAmmoSampler::Inspect(&root);assert(!s->Complete&&s->Valid());} // Maximum weapon and muzzle bounds remain valid detached counts on overflow. for(int count:{32,33}){Entity root;std::vector nodes(count);std::vector weapons(count); root.child=&nodes[0];for(int i=0;iComplete&&s->Weapons==32&&s->Valid());} {Entity root;std::vector nodes(18);std::vector weapons(17);std::vector muzzles(136);Magazine mag;mag.owner=&nodes[17]; root.child=&nodes[0];for(int i=0;i<18;i++){if(i+1<18)nodes[i].sibling=&nodes[i+1];if(i==17)continue; nodes[i].weapon=&weapons[i];weapons[i].owner=&nodes[i];for(int j=0;j<8;j++){auto& m=muzzles[i*8+j];m.owner=&nodes[i];m.mag=&mag;weapons[i].muzzles.Insert(&m);}} auto s=ERR_HQMountedAmmoSampler::Inspect(&root);assert(!s->Complete&&s->Muzzles==128&&s->Magazines==1&&s->Chambers==128&&s->Valid());} {Rig r;Magazine alias;alias.owner=&r.magazine;Muzzle second;second.owner=&r.gun;second.mag=&alias;r.weapon.muzzles.Insert(&second); auto s=r.Inspect();assert(!s->Complete&&s->Magazines==1&&s->Rounds==25&&alias.reads==0&&s->Valid());} // Realistic production load: 128 known deposited items plus mounted root, // gun, loaded magazine and a pruned original crew root exceed128 in total. // Cargo-first and structure-first traversal both retain the same mounted counts. for(bool cargoFirst:{false,true}){Rig r;std::vector cargoWeapons(128);std::vector cargo(128);std::vector items(128);std::vector slots(128);Storage deposit; for(int i=0;i<128;i++){cargo[i].weapon=&cargoWeapons[i];cargoWeapons[i].owner=&cargo[i];cargo[i].item=&items[i];items[i].slot=&slots[i];slots[i].storage=&deposit;if(i<127)cargo[i].sibling=&cargo[i+1];} if(cargoFirst){r.root.child=&cargo[0];cargo.back().sibling=&r.gun;}else{r.crew.sibling=&cargo[0];} auto snapshot=r.Inspect();assert(snapshot->Complete&&snapshot->Weapons==1&&snapshot->Magazines==1&&snapshot->Rounds==25&&snapshot->Valid()); for(auto& item:cargo){assert(item.reads==0);}for(auto& gun:cargoWeapons){assert(gun.reads==0);}assert(r.weapon.reads==1&&r.carried.reads==0);} // Independent128 structural/128 cargo limits, in either order and interleaved. for(int order:{0,1,2})for(int scenario:{0,1,2,3}){ int structures=scenario==1?129:128;int cargoCount=scenario==2||scenario==3?129:(scenario==1?100:128); if(scenario==2)structures=4; std::vector nodes(structures),cargo(cargoCount);std::vector items(cargoCount);std::vector slots(cargoCount);Storage deposit;std::vector sequence; for(int i=0;isibling=sequence[i+1]; auto snapshot=ERR_HQMountedAmmoSampler::Inspect(&nodes[0]);assert(snapshot->Complete==(scenario==0)&&snapshot->Weapons==0&&snapshot->Valid()); int reads=0;for(auto& e:nodes)reads+=e.reads;assert(reads<=128);for(auto& e:cargo)assert(e.reads==0); } // Wire validation rejects impossible or malicious counts. {ERR_HQMountedAmmoSnapshot s;assert(s.Valid());s.Weapons=33;assert(!s.Valid());s.Weapons=1;s.Muzzles=9;assert(!s.Valid()); s.Muzzles=1;s.Magazines=2;assert(!s.Valid());s.Magazines=1;s.Capacity=100001;assert(!s.Valid());s.Capacity=100;s.Rounds=101;assert(!s.Valid()); s.Rounds=25;s.Chambers=33;assert(!s.Valid());s.Chambers=1;s.LowMagazines=2;assert(!s.Valid());s.LowMagazines=1;s.Complete=true;assert(s.Valid());} } ''') run(program) print('PASS: actual mounted hierarchy sampling, ownership exclusion, deduplication, completeness/caps, quarter threshold and detached validation; no runtime policy or ammunition mutation') # WORKBENCH records are opt-in. Re-run every original geometry/count assertion # in that build too, plus exact failure witnesses from the same traversal. cases=r''' // Exact reason64 distinguishes absent item, null slot and differing slot, // while actual Inspect remains incomplete and retains the same ammunition. for(int fault=0;fault<3;fault++){ Rig r;Mount mount;Item item;Slot binding,other;Storage storage;storage.purpose=EStoragePurpose::PURPOSE_ATTACHMENT_PROXY;other.storage=&storage; mount.owner=&r.root;mount.weapon=&r.gun;mount.slot=&binding;binding.mount=&mount;binding.attached=&r.gun; r.manager.weapons={&mount};r.gun.item=fault==0?nullptr:&item; if(fault==2)item.slot=&other; other.mount=&mount;other.attached=&r.gun; ERR_HQMountedAmmoSampler::BeginDiagnostic();auto snap=r.Inspect();auto*d=ERR_HQMountedAmmoSampler::EndDiagnostic(); assert(!snap->Complete&&snap->Weapons==1&&snap->Rounds==25&&(d->Reasons&64)); assert(d->Detail.find(fault==0?"item=absent;":"item=present;")!=string::npos); assert(d->Detail.find(fault==2?"parent=different-binding;":"parent=null;")!=string::npos); assert(d->Detail.find("binding-attached=exact;")!=string::npos&&d->Detail.find("binding-container=exact-mount;")!=string::npos); assert(d->Detail.find("mount-owner=allowed;")!=string::npos&&d->Detail.find("mount-prefab=fixture;")!=string::npos); if(fault==2)assert(d->Detail.find("parent-mount-slot=other-or-null;")!=string::npos); } {Rig r;r.weapon.muzzles={};ERR_HQMountedAmmoSampler::BeginDiagnostic();auto snap=r.Inspect();auto*d=ERR_HQMountedAmmoSampler::EndDiagnostic(); assert(!snap->Complete&&snap->Weapons==1&&snap->Rounds==0&&(d->Reasons&4096)); assert(d->Detail.find("zero-muzzle-not-proven-placeholder;")!=string::npos&&d->Detail.find("zero-muzzle-slot-evidence:item=absent;parent=null;")!=string::npos);} ''' + r''' {Rig r;ERR_HQMountedAmmoSampler::BeginDiagnostic();auto snap=r.Inspect();auto*d=ERR_HQMountedAmmoSampler::EndDiagnostic();assert(snap->Complete&&d->Reasons==0&&d->Nodes==4&&d->Allowed==3&&d->Managers==1);assert(!ERR_HQMountedAmmoSampler::EndDiagnostic());} {Entity root;root.child=&root;ERR_HQMountedAmmoSampler::BeginDiagnostic();auto snap=ERR_HQMountedAmmoSampler::Inspect(&root);auto*d=ERR_HQMountedAmmoSampler::EndDiagnostic();assert(!snap->Complete&&d->Reasons==4&&d->Nodes==1&&d->Allowed==1&&root.reads==1);} {Entity root;std::vector children(128);root.child=&children[0];for(int i=0;i<127;i++)children[i].sibling=&children[i+1];ERR_HQMountedAmmoSampler::BeginDiagnostic();auto snap=ERR_HQMountedAmmoSampler::Inspect(&root);auto*d=ERR_HQMountedAmmoSampler::EndDiagnostic();assert(!snap->Complete&&d->Reasons==1024&&d->Nodes==129&&d->Allowed==128&&d->Structural==129&&d->Cargo==0&&children[127].reads==0);} for(int purpose:{-1,0,127}){Rig r;Item item;Slot slot;Storage storage;r.gun.item=&item;item.slot=&slot;r.gun.prefab.name="first-gun";if(purpose>=0){slot.storage=&storage;storage.purpose=purpose;}ERR_HQMountedAmmoSampler::BeginDiagnostic();auto snap=r.Inspect();auto*d=ERR_HQMountedAmmoSampler::EndDiagnostic();assert(!snap->Complete&&(d->Reasons&2)&&(d->Reasons&16)&&d->FirstPrefab=="first-gun"&&d->FirstPurpose==purpose&&d->Detail.find("ambiguous-storage;")!=string::npos);} {Entity root;Manager manager;root.manager=&manager;manager.weapons.resize(9,nullptr);ERR_HQMountedAmmoSampler::BeginDiagnostic();auto snap=ERR_HQMountedAmmoSampler::Inspect(&root);auto*d=ERR_HQMountedAmmoSampler::EndDiagnostic();assert(!snap->Complete&&d->Reasons==512&&d->Managers==1&&manager.reads==1);} {Rig r;Mount mount;mount.owner=&r.root;r.manager.weapons={&mount};ERR_HQMountedAmmoSampler::BeginDiagnostic();auto snap=r.Inspect();auto*d=ERR_HQMountedAmmoSampler::EndDiagnostic();assert(!snap->Complete&&(d->Reasons&32));} {ERR_HQMountedAmmoSampler::BeginDiagnostic();auto snap=ERR_HQMountedAmmoSampler::Inspect(nullptr);auto*d=ERR_HQMountedAmmoSampler::EndDiagnostic();assert(!snap->Complete&&d->Reasons==1&&d->Nodes==0&&d->Allowed==0);} ''' cases+=r''' for(int which:{0,1}){Entity root;int cargoCount=which==0?129:256;std::vector cargo(cargoCount);std::vector items(cargoCount);std::vector slots(cargoCount);Storage storage;root.child=&cargo[0]; for(int i=0;iComplete&&d->Cargo==129&&d->Structural==1&&(d->Reasons&2048)); if(which==0){assert(d->Nodes==130&&!(d->Reasons&8));}else{assert(d->Nodes==256&&(d->Reasons&8));}} ''' run('#define WORKBENCH\n'+program.replace('int main(){','int main(){'+cases)) print('PASS: WORKBENCH opt-in diagnostics distinguish cycles/cap/storage/manager/mount failures without repeated native traversal')