32 lines
2.0 KiB
Python
32 lines
2.0 KiB
Python
"""Execute town activation and no-pop-in policy, including split/invalid observers."""
|
|
from policy_harness import ROOT, body, run
|
|
p=ROOT/'addons/core/Scripts/Game/ERR/10_AI/ERR_TownGarrisons.c'
|
|
code=body(p,'static bool Safe(')+'\n'+body(p,'static bool Approached(')
|
|
code=code.replace('array<vector> players','Array<Vec>* players').replace('vector ', 'Vec ').replace('foreach (','for (').replace(' : players)', ' : *players)').replace('players.', 'players->').replace('vector.DistanceXZ','Vec::DistanceXZ').replace('ERR_ForceRules.FiniteVector','Finite')
|
|
run(r'''
|
|
#include <cassert>
|
|
#include <cmath>
|
|
#include <limits>
|
|
#include <vector>
|
|
struct Vec{float x,y,z;static float DistanceXZ(Vec a,Vec b){return std::hypot(a.x-b.x,a.z-b.z);}};
|
|
bool Finite(Vec v){return std::isfinite(v.x)&&std::isfinite(v.y)&&std::isfinite(v.z);}
|
|
template<class T>struct Array:std::vector<T>{using std::vector<T>::vector;bool IsEmpty(){return this->empty();}};
|
|
constexpr float DISTANCE=700;
|
|
'''+code+r'''
|
|
int main(){
|
|
Array<Vec> empty,near={{0,1000,0}},far={{701,0,0}},edge={{700,0,0}},split={{700,0,0},{-699,0,0}};
|
|
Vec origin{0,0,0};
|
|
assert(!Safe(origin,nullptr)&&!Safe(origin,&empty)&&!Approached(origin,&empty));
|
|
assert(!Safe(origin,&near)&&Approached(origin,&near)); // Horizontal distance, including helicopters
|
|
assert(Safe(origin,&far)&&!Approached(origin,&far));
|
|
assert(Safe(origin,&edge)&&Approached(origin,&edge)); // Exact 700m is safe and activates
|
|
assert(!Safe(origin,&edge,702)); // Planning leaves a small ground-placement margin
|
|
assert(!Safe(origin,&split)); // A distant lead player cannot hide a nearby teammate
|
|
split[1]={-701,0,0}; assert(Safe(origin,&split));
|
|
split[0]={699.99f,0,0}; assert(!Safe(origin,&split)); // Crossing boundary before birth rejects it
|
|
split[0]={std::numeric_limits<float>::quiet_NaN(),0,0}; assert(!Safe(origin,&split));
|
|
assert(!Safe(split[0],&edge)&&!Approached(split[0],&edge));
|
|
}
|
|
''')
|
|
print('PASS: town trigger and hard 700m exclusion for all observers, empty/invalid positions and final-check crossings')
|