Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
43 lines
2.8 KiB
Python
43 lines
2.8 KiB
Python
"""Execute exact HQ mounted-root admission; force identity and native lookup are doubles."""
|
|
import re
|
|
from policy_harness import ROOT, body, run
|
|
p=ROOT/'addons/core/Scripts/Game/ERR/10_AI/ERR_HQ.c'
|
|
s=body(p,' bool BindVehicle(')
|
|
for name in ('Replication','ERR_ForceKind'):s=s.replace(name+'.',name+'::')
|
|
for name in ('SCR_AIGroup','IEntity','ERR_ForceRecord','ERR_HQUnit'):
|
|
s=re.sub(r'\b'+name+r' (?=\w)',name+'* ',s)
|
|
for name in ('m_Mode','record','unit'):s=s.replace(name+'.',name+'->')
|
|
s=s.replace('Forces().','Forces()->').replace('foreach (','for (')
|
|
run(r'''
|
|
#include <cassert>
|
|
#include <vector>
|
|
struct Replication{inline static bool server=true;static bool IsServer(){return server;}};
|
|
struct SCR_AIGroup{};struct IEntity{};
|
|
enum class ERR_ForceKind{GARRISON,CONVOY};
|
|
struct ERR_ForceRecord{bool Physical=true,Eliminated=false;ERR_ForceKind Kind=ERR_ForceKind::CONVOY;};
|
|
struct Ledger{ERR_ForceRecord record;SCR_AIGroup* group=nullptr;ERR_ForceRecord* FindGroup(SCR_AIGroup* g){return g==group?&record:nullptr;}};
|
|
struct Mode{Ledger ledger;Ledger* Forces(){return &ledger;}};
|
|
struct Sampler{int calls=0;bool admitted=true;IEntity* original=nullptr;
|
|
bool BindVehicle(IEntity* root){calls++;if(!admitted)return false;if(!original)original=root;return original==root;}};
|
|
struct ERR_HQUnit{SCR_AIGroup* Group;Sampler StatusSampler;};
|
|
struct HQ{Mode* m_Mode;std::vector<ERR_HQUnit*>m_Units;int physical=0;
|
|
void BindPhysical(ERR_HQUnit*){physical++;}
|
|
'''+s+r'''
|
|
};
|
|
int main(){
|
|
Mode mode;HQ h{&mode,{},0};SCR_AIGroup group,other;IEntity root,replacement;ERR_HQUnit unit{&group,{}};h.m_Units.push_back(&unit);mode.ledger.group=&group;
|
|
assert(!h.BindVehicle(nullptr,&root)&&!h.BindVehicle(&group,nullptr));
|
|
Replication::server=false;assert(!h.BindVehicle(&group,&root));Replication::server=true;
|
|
assert(!h.BindVehicle(&other,&root)&&unit.StatusSampler.calls==0);
|
|
mode.ledger.record.Physical=false;assert(!h.BindVehicle(&group,&root));mode.ledger.record.Physical=true;
|
|
mode.ledger.record.Eliminated=true;assert(!h.BindVehicle(&group,&root));mode.ledger.record.Eliminated=false;
|
|
mode.ledger.record.Kind=ERR_ForceKind::GARRISON;assert(!h.BindVehicle(&group,&root));mode.ledger.record.Kind=ERR_ForceKind::CONVOY;
|
|
assert(unit.StatusSampler.calls==0&&h.physical==0);
|
|
unit.StatusSampler.admitted=false;assert(!h.BindVehicle(&group,&root));unit.StatusSampler.admitted=true;
|
|
assert(h.BindVehicle(&group,&root)&&h.BindVehicle(&group,&root));assert(!h.BindVehicle(&group,&replacement));
|
|
assert(unit.StatusSampler.original==&root&&unit.StatusSampler.calls==4&&h.physical==4);
|
|
h.m_Units.clear();assert(!h.BindVehicle(&group,&root));h.m_Mode=nullptr;assert(!h.BindVehicle(&group,&root));
|
|
}
|
|
''')
|
|
print('PASS: actual HQ original convoy-root admission rejects wrong force/server/group and never supplies replacement lookup')
|