Files
EscapistsReintroduced/tests/test_terrain_airfields.py
T
jakub 6a667d8deb Capture current mission, AI, map and administration development
Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
2026-10-13 22:52:53 +02:00

50 lines
3.3 KiB
Python

"""Execute production marker lookup and prefab detection with world adapters."""
import re
from policy_harness import ROOT, body, run
path = ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_AirfieldPlacement.c'
s = body(path, 'static void AuthoredAirports(') + '\n' + body(path, 'static bool AirportPrefab(')
s = s.replace('array<vector> positions', 'std::vector<vector>& positions').replace('positions.Insert(', 'positions.push_back(')
s = s.replace('GetGame().GetWorldEntity()', 'GetGame()->GetWorldEntity()').replace('GetGame().GetWorld()', 'GetGame()->GetWorld()')
s = s.replace('GetWorldEntity().', 'GetWorldEntity()->').replace('GetWorld().', 'GetWorld()->')
s = s.replace('IEntity marker', 'IEntity* marker').replace('marker.', 'marker->')
s = s.replace('ERR_Actors.', 'ERR_Actors::').replace('ChimeraWorldUtils.', 'ChimeraWorldUtils::').replace('index.ToString()', 'std::to_string(index)')
s = s.replace('path.ToLower();', 'std::transform(path.begin(),path.end(),path.begin(),[](unsigned char c){return std::tolower(c);});')
s = re.sub(r'path.Contains\(("[^"]+")\)', r'(path.find(\1)!=string::npos)', s)
run(r'''
#include <cassert>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
using string=std::string;
struct vector{float v[3];float&operator[](int i){return v[i];}};
struct IEntity{vector p;vector GetOrigin(){return p;}};
struct World{std::map<string,IEntity> entities;IEntity* FindEntityByName(string name){auto i=entities.find(name);return i==entities.end()?nullptr:&i->second;}};
struct WorldEntity{void GetWorldBounds(vector&lo,vector&hi){lo={{-1000,0,-2000}};hi={{5000,0,6000}};}};
struct Game{World world;WorldEntity bounds;bool ready=true;World*GetWorld(){return &world;}WorldEntity*GetWorldEntity(){return ready?&bounds:nullptr;}} game;
Game* GetGame(){return &game;}
struct ERR_Actors{static vector Ground(vector p){p[1]=42;return p;}};
struct ChimeraWorldUtils{static bool TryGetWaterSurfaceSimple(World*,vector p){return p[0]==123;}};
'''+s+r'''
int main(){
assert(AirportPrefab("Prefabs/Structures/Military/RunwayLong.et"));
assert(AirportPrefab("PREFABS/STRUCTURES/AirControlTowerA.et"));
assert(AirportPrefab("Prefabs/Structures/ControlTowerA.et"));
assert(!AirportPrefab("Prefabs/Props/AirportCrate.et"));
assert(!AirportPrefab("Prefabs/Structures/AirportBunker.et"));
assert(!AirportPrefab("Prefabs/Map/RunwayIcon.et"));
std::vector<vector> out;game.ready=false;AuthoredAirports(out);assert(out.empty());game.ready=true;
game.world.entities["ERR_Airfield_0"]={{{100,999,200}}};
game.world.entities["ERR_Airfield_2"]={{{-500,0,-1000}}}; // Noncontiguous IDs and off-origin terrain.
game.world.entities["ERR_Airfield_3"]={{{6000,0,200}}}; // Outside terrain.
game.world.entities["ERR_Airfield_4"]={{{123,0,200}}}; // Water.
game.world.entities["ERR_Airfield_16"]={{{400,0,200}}}; // Bounded marker namespace.
game.world.entities["Airport"]={{{500,0,200}}}; // Unrelated map label.
game.world.entities["ERR_ReconAirport"]={{{600,0,200}}}; // Existing author marker remains compatible.
AuthoredAirports(out);assert(out.size()==3&&out[0][0]==600&&out[1][0]==100&&out[2][0]==-500);
for(auto p:out)assert(p[1]==42);
}
''')
print('PASS: airfield detection accepts physical runways/towers and bounded authored markers, rejects unrelated props, water and out-of-world markers, and samples terrain height')