Fix stalled hunter recovery and document intel cleanup
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-10-20 15:47:18 +02:00
parent cc322572b4
commit ae2aedd131
9 changed files with 186 additions and 20 deletions
+74
View File
@@ -0,0 +1,74 @@
"""Execute recovery deadlines and cross-assignment rejection memory from production."""
from policy_harness import ROOT, body, run
ai = ROOT / 'addons/core/Scripts/Game/ERR/10_AI'
wait = body(ai / 'ERR_HunterCrewRecovery.c', 'class ERR_HunterRecoveryWait')
run('#include <cassert>\nstruct ' + wait.removeprefix('class ') + r''';
int main() {
ERR_HunterRecoveryWait wait;
assert(!wait.Expired(false,false,false,0,1000)); // admission owns its own deadline
assert(!wait.Expired(true,false,false,0,2000));
assert(!wait.Expired(true,false,false,0,121999));
assert(wait.Expired(true,false,false,0,122000));
// Repeated combat/seat-failure transitions cannot restart the deadline.
assert(!wait.Expired(true,false,true,0,123000));
assert(!wait.Expired(true,false,false,4,124000));
assert(!wait.Expired(true,false,false,-1,125000)); // no physics sample
assert(wait.Expired(true,false,false,3,126000));
assert(!wait.Expired(true,true,false,0,127000)); // recovered or adopted driver
assert(!wait.Expired(true,false,false,0,200000));
assert(!wait.Expired(true,false,false,0,319999));
assert(wait.Expired(true,false,false,0,320000));
wait.Reset(); // deliberate tactical dismount owns its separate time budget
assert(!wait.Expired(true,false,false,0,500000));
assert(!wait.Expired(true,false,false,0,1000)); // world clock reset
assert(!wait.Expired(true,false,false,0,120999));
assert(wait.Expired(true,false,false,0,121000));
}
''')
memory = body(ai / 'ERR_HunterTactics.c', 'class ERR_HunterApproachMemory')
memory = memory.replace('protected ', '').replace('ref array<vector>', 'Array<Vec>').replace('ref array<float>', 'Array<float>')
memory = memory.replace('array<vector> excluded', 'Array<Vec>& excluded').replace('foreach (vector position :', 'for (Vec position :')
memory = memory.replace('vector position', 'Vec position').replace('vector.DistanceXZ', 'Distance').replace('float RetryAfter;', 'float RetryAfter = 0;')
run(r'''
#include <cassert>
#include <vector>
#include <cmath>
struct Vec {float x=0;}; float Distance(Vec a,Vec b){return std::abs(a.x-b.x);}
template<class T>struct Array:std::vector<T>{
int Count(){return this->size();}void Remove(int i){this->erase(this->begin()+i);}void Insert(T value){this->push_back(value);}
};
struct ''' + memory.removeprefix('class ') + r''';
int main(){
ERR_HunterApproachMemory crew;crew.Reject({100},1000);
assert(crew.RetryAfter==61000);
Array<Vec> nextAssignment;crew.Append(nextAssignment,9000);
assert(nextAssignment.size()==1&&nextAssignment[0].x==100); // eight seconds after release
crew.Reject({101},2000);Array<Vec> refreshed;crew.Append(refreshed,301000);
assert(refreshed.size()==1); // nearly identical stage refreshes, does not duplicate
Array<Vec> expired;crew.Append(expired,302000);assert(expired.empty());
for(int i=0;i<12;i++)crew.Reject({float(i*100)},400000+i);
Array<Vec> bounded;crew.Append(bounded,400020);assert(bounded.size()==8&&bounded[0].x==400);
ERR_HunterApproachMemory otherCrew;Array<Vec> independent;otherCrew.Append(independent,400020);assert(independent.empty());
Array<Vec> cleared;crew.Append(cleared,700011);assert(cleared.empty());
}
''')
# Wiring guards complement execution: the blocked-seat branch must reach this
# clock before normal travel's invalid-crew early return, and every planner
# candidate (including already parked vehicles) must consult shared memory.
service = (ai / 'ERR_HunterService.c').read_text()
tick = body(ai / 'ERR_HunterService.c', 'override void Tick(float now)')
assert tick.index('unit.Recovery.Wait.Expired(') < tick.index('if (!unit.CrewValid(m_Mode)) continue;')
assert tick.count('unit.Recovery.Wait.Reset()') == 2
assert 'AbandonStuckVehicle(unit, "driver recovery timed out after two minutes")' in tick
assert 'ref ERR_HunterApproachMemory FailedApproaches' in service
plan = body(ai / 'ERR_HunterTactics.c', 'bool Plan(array<vector> occupied)')
assert 'if (!Delivered && now < Unit.FailedApproaches.RetryAfter) return false;' in plan
assert 'Unit.FailedApproaches.Append(excluded, now);' in plan
assert plan.count('approachForward, excluded)') == 2
assert 'foreach (vector failedPosition : excluded)' in plan
assert 'foreach (vector reserved : excluded)' in plan
assert 'Unit.FailedApproaches.Reject(Stage, now);' in body(ai / 'ERR_HunterTactics.c', 'protected void RejectStage(')
print('PASS: blocked crew deadline survives combat interruptions, defers unsafe exits, resets after recovery; failed stages survive assignments with bounded expiry')
+1
View File
@@ -40,6 +40,7 @@ int main(){
print('PASS: actual movement recovery retries delivered orders three times, respects combat/speed/arrival/progress, then abandons the stalled vehicle')
s=body(p,'protected void AbandonStuckVehicle(').replace('protected ', '').replace('ERR_HunterVehicle unit','Unit* unit').replace('unit.', 'unit->')
s=s.replace('string reason', 'std::string reason')
s=s.replace('SCR_AIGroupUtilityComponent utility = unit->Group.GetGroupUtilityComponent();','Utility* utility = unit->Group->GetGroupUtilityComponent();')
s=s.replace('SCR_AIVehicleUsageComponent usage = SCR_AIVehicleUsageComponent.Cast(unit->Entity.FindComponent(SCR_AIVehicleUsageComponent));','void* usage = unit->Entity;')
s=s.replace('foreach (IEntity member : unit->Members)','for (Actor* member : unit->Members)')
+3 -1
View File
@@ -60,6 +60,7 @@ struct UnitType{string Source="hunter";struct GroupType*Group=nullptr;IEntity*En
struct AttackType{Vec ReportPosition;float Started=0;bool alive=true,ready=false;bool CoverAlive(){return alive;}bool CoverReady(){return ready;}};
struct GunTeam{int ticks=0;void Tick(float){ticks++;}void Pause(){}};
struct Tactics{
int rejected=0;void RejectStage(float){rejected++;}
int m_ApproachRetries=0,m_CoverRetries=0,alternates=0;float m_BlindSince=-1;bool alternateWorks=true;
bool AlternateStage(float now){alternates++;if(!alternateWorks)return false;State=1;m_BlindSince=-1;m_ApproachProgress=now;Stage={500,0,-250};return true;}
GunTeam*m_GunTeam=nullptr;bool align=false,facing=false;bool TryAlign(){return align;}bool FacingSector(){return facing;}
@@ -224,6 +225,7 @@ struct UnitType{struct Entity entity;struct Entity*Entity=&entity;};
struct Tactics;struct AttackType{Array<Tactics*>Teams;};
float ManeuverBudget(float){return 240000;}
struct Tactics{
int rejected=0;void RejectStage(float){rejected++;}
UnitType unit;UnitType*Unit=&unit;AttackType attack;AttackType*Attack=&attack;
Vec Stage{0,0,-210},Approach{155,0,-240},Sector{105,0,35},m_ApproachPosition;
Array<Vec>m_RejectedStages,reservations;int State=3;float m_BlindSince=1000,m_ApproachProgress=0,m_ApproachStarted=1000,m_TravelDistance=1000,Deadline=100;
@@ -235,7 +237,7 @@ struct Tactics{
int main(){
for(int failure=0;failure<2;failure++){
Tactics t;t.plan=failure!=0;t.move=failure!=1;
assert(!t.AlternateStage(21000));assert(t.Stage.x==0&&t.Approach.x==155&&t.State==3&&t.m_RejectedStages.empty());
assert(!t.AlternateStage(21000));assert(t.Stage.x==0&&t.Approach.x==155&&t.State==3&&t.m_RejectedStages.empty()&&t.rejected==1);
}
Tactics t,other,dead;dead.live=false;other.Stage={-200,0,-210};t.attack.Teams={&t,&other,&dead};t.m_RejectedStages.Insert({-100,0,-300});
assert(t.AlternateStage(21000));assert(t.reservations.size()==4&&t.reservations.back().x==-200);
+18 -7
View File
@@ -7,12 +7,12 @@ from policy_harness import ROOT,body,run
P=Path(os.environ.get('ERR_DISCOVERY_SOURCE',ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_DiscoveryService.c'))
s=body(P,'protected void Recover(')
s=s.replace('protected ','').replace('null','nullptr').replace('foreach (','for (').replace('array<','Array<')
for typ in ('InventoryStorageManagerComponent','ERR_DocumentComponent','ERR_LocationComponent'):
for typ in ('InventoryStorageManagerComponent','SCR_InventoryStorageManagerComponent','ERR_DocumentComponent','ERR_LocationComponent'):
s=re.sub(r'\b'+typ+r' (\w+)',typ+r'* \1',s)
s=s.replace('Array<ERR_LocationComponent>','Array<ERR_LocationComponent*>').replace('bool mineRecovered;', 'bool mineRecovered=false;')
for ns in ('Replication','ERR_Actors','SCR_FactionManager','InventoryStorageManagerComponent','ERR_DocumentComponent','ERR_LocationKind','Math'):
for ns in ('Replication','ERR_Actors','SCR_FactionManager','InventoryStorageManagerComponent','SCR_InventoryStorageManagerComponent','SCR_EntityHelper','ERR_DocumentComponent','ERR_LocationKind','Math'):
s=s.replace(ns+'.',ns+'::')
for obj in ('m_Mode','player','folder','location','document','chosen'):
for obj in ('m_Mode','player','folder','location','document','chosen','scrInventory'):
s=re.sub(r'\b'+obj+r'\.',obj+'->',s)
for method in ('Players','Evidence','Settings','MineIntel','GetGame','GetPlayerManager'):
s=s.replace(method+'().',method+'()->')
@@ -27,8 +27,10 @@ template<class T>struct Array:std::vector<T>{using std::vector<T>::vector;using
struct Entity;using IEntity=Entity*;
struct Faction{};
struct ERR_DocumentComponent{string target;string TargetId(){return target;}static ERR_DocumentComponent* Cast(void*p){return (ERR_DocumentComponent*)p;}};
struct InventoryStorageManagerComponent{Array<IEntity> folders;static InventoryStorageManagerComponent* Cast(void*p){return (InventoryStorageManagerComponent*)p;}};
struct Entity{bool alive=true,canonical=true;Faction*faction=nullptr;InventoryStorageManagerComponent*inventory=nullptr;ERR_DocumentComponent*document=nullptr;void*FindComponent(std::string type){if(type=="InventoryStorageManagerComponent")return inventory;if(type=="ERR_DocumentComponent")return document;return nullptr;}};
struct InventoryStorageManagerComponent{virtual ~InventoryStorageManagerComponent()=default;Array<IEntity> folders;static InventoryStorageManagerComponent* Cast(void*p){return (InventoryStorageManagerComponent*)p;}};
struct SCR_InventoryStorageManagerComponent:InventoryStorageManagerComponent{bool acceptDelete=true;int deleteCalls=0;IEntity deleted=nullptr;static SCR_InventoryStorageManagerComponent*Cast(InventoryStorageManagerComponent*p){return dynamic_cast<SCR_InventoryStorageManagerComponent*>(p);}bool TryDeleteItem(IEntity item){deleteCalls++;if(acceptDelete)deleted=item;return acceptDelete;}};
struct Entity{bool alive=true,canonical=true,deleted=false;Faction*faction=nullptr;InventoryStorageManagerComponent*inventory=nullptr;ERR_DocumentComponent*document=nullptr;void*FindComponent(std::string type){if(type=="InventoryStorageManagerComponent")return inventory;if(type=="ERR_DocumentComponent")return document;return nullptr;}};
namespace SCR_EntityHelper{void DeleteEntityAndChildren(IEntity e){e->deleted=true;}}
namespace Replication{bool server=true;bool IsServer(){return server;}}
namespace ERR_Actors{bool Alive(IEntity e){return e&&e->alive;}}
namespace SCR_FactionManager{Faction*SGetFaction(IEntity e){return e?e->faction:nullptr;}}
@@ -36,7 +38,7 @@ namespace ERR_LocationKind{enum{PRISON,RADIO,EXTRACTION,DEPOT};}
namespace Math{int RandomInt(int,int){return 99;}}
struct ERR_LocationComponent{string id;int kind=ERR_LocationKind::RADIO,knowledge=0,calls=0;bool allow=true;int Kind(){return kind;}int Knowledge(){return knowledge;}string Id(){return id;}bool Discover(int,int){calls++;if(!allow)return false;knowledge++;return true;}};
struct Roster{IEntity CurrentActor(IEntity e){return e&&e->canonical?e:nullptr;}};
struct Evidence{IEntity sealed=nullptr;string target;string Target(IEntity e){return e==sealed?target:"";}};
struct Evidence{IEntity sealed=nullptr,retired=nullptr;string target;string Target(IEntity e){return e==sealed?target:"";}void Retire(IEntity e){retired=e;}};
struct Settings{int Runtime(string){return 15;}};
struct MineIntel{bool newlyRecovered=false;int calls=0;Array<IEntity> recovered;Array<IEntity>*spent=nullptr;IEntity lastPlayer=nullptr;bool Recover(IEntity player,IEntity folder){assert(spent&&!spent->Contains(folder));calls++;lastPlayer=player;recovered.Insert(folder);return newlyRecovered;}};
struct Mode{bool worldPreparing=false;bool WorldPreparing(){return worldPreparing;}Roster roster;struct Evidence evidence;struct Settings settings;struct MineIntel mine;Faction*faction=nullptr;bool haveMine=true;Array<ERR_LocationComponent*>locations;int exhausted=0;
@@ -46,7 +48,7 @@ template<class...T>void PrintFormat(T...){}
struct Discovery{Mode*m_Mode=nullptr;Array<IEntity>m_Spent;void Folders(InventoryStorageManagerComponent*i,Array<IEntity>&out){out=i->folders;}bool MarkSpent(IEntity e){if(!m_Spent.Contains(e))m_Spent.Insert(e);return true;}
'''+s+r'''
};
struct Fixture{Faction friendly,foreign;Mode mode;Discovery discovery;Entity player,second,folder;InventoryStorageManagerComponent firstInv,secondInv;ERR_DocumentComponent objective;ERR_LocationComponent radio,other;
struct Fixture{Faction friendly,foreign;Mode mode;Discovery discovery;Entity player,second,folder;SCR_InventoryStorageManagerComponent firstInv,secondInv;ERR_DocumentComponent objective;ERR_LocationComponent radio,other;
Fixture(){Replication::server=true;mode.faction=&friendly;discovery.m_Mode=&mode;mode.mine.spent=&discovery.m_Spent;player.faction=&friendly;second.faction=&friendly;player.inventory=&firstInv;second.inventory=&secondInv;firstInv.folders.Insert(&folder);radio.id="radio";other.id="other";mode.locations={&other,&radio};}}
;
int main(){
@@ -54,10 +56,19 @@ int main(){
// advances ordinary discovery once across transfer between two valid players.
Fixture f;f.objective.target="radio";f.folder.document=&f.objective;
f.discovery.Recover(&f.player);assert(f.radio.knowledge==1&&f.other.knowledge==0&&f.discovery.m_Spent.Contains(&f.folder));
assert(f.firstInv.deleteCalls==0&&!f.folder.deleted&&!f.mode.evidence.retired); // objective stays physical
assert(f.mode.mine.calls==1&&f.mode.mine.lastPlayer==&f.player&&f.mode.mine.recovered[0]==&f.folder);
f.firstInv.folders.clear();f.secondInv.folders.Insert(&f.folder);f.discovery.Recover(&f.second);assert(f.radio.calls==1&&f.other.calls==0&&f.mode.mine.calls==1);
// Existing sealed generic-folder target survives the supplemental hook.
Fixture sealed;sealed.mode.evidence.sealed=&sealed.folder;sealed.mode.evidence.target="radio";sealed.discovery.Recover(&sealed.player);assert(sealed.radio.knowledge==1&&sealed.other.knowledge==0);
assert(sealed.firstInv.deleted==&sealed.folder&&sealed.mode.evidence.retired==&sealed.folder&&!sealed.folder.deleted);
sealed.discovery.Recover(&sealed.player);assert(sealed.firstInv.deleteCalls==1); // never consume twice
Fixture refusal;refusal.firstInv.acceptDelete=false;refusal.discovery.Recover(&refusal.player);
assert(refusal.firstInv.deleteCalls==1&&refusal.folder.deleted&&refusal.mode.evidence.retired==&refusal.folder);
Fixture generic;InventoryStorageManagerComponent bare;bare.folders.Insert(&generic.folder);generic.player.inventory=&bare;generic.discovery.Recover(&generic.player);
assert(generic.folder.deleted&&generic.mode.evidence.retired==&generic.folder); // missing scripted manager fallback
Fixture failed;failed.other.allow=false;failed.discovery.Recover(&failed.player);
assert(failed.firstInv.deleteCalls==0&&!failed.folder.deleted&&!failed.mode.evidence.retired); // no clue, no deletion
// Unknown authored target stays unspent; a supplement cannot consume it first.
Fixture missing;missing.objective.target="absent";missing.folder.document=&missing.objective;missing.discovery.Recover(&missing.player);assert(missing.discovery.m_Spent.IsEmpty()&&missing.radio.calls==0&&missing.other.calls==0);
// Failed site discovery also retains the original retry semantics.