Files
Viano-Core/tests/clientless/test_flight_terrain_fallback.py
T
Nico 3056063f12
clang PCH / build (push) Canceled after 0s
GCC PCH / build (push) Canceled after 0s
Allow validated vertical approaches to elevated flight landings
2026-11-02 08:32:21 +01:00

44 lines
2.9 KiB
Python

"""Exercise the production terrain-selection and flight-surface guard."""
from pathlib import Path
import subprocess,tempfile
root=Path(__file__).resolve().parents[2]
s=(root/'src/server/game/World/ClientlessFlightMgr.cpp').read_text()
a=s.index('Surface ClientlessFlightMgr::Sample(');b=s.index('\nbool ClientlessFlightMgr::Start(',a)
code=r'''
#include <cassert>
#include <cmath>
#include <limits>
#include <string>
#include <unordered_map>
#include <set>
using uint32=unsigned;using int32=int;
constexpr int MAX_NUMBER_OF_GRIDS=64;constexpr float MAX_HEIGHT=100000,INVALID_HEIGHT=-100000;
struct Grid{int x_coord=35,y_coord=23;};namespace Trinity{Grid ComputeGridCoord(float,float){return {};}}
struct Terrain{float floor=5;bool child=false;float GetStaticHeight(int,unsigned,float,float,float,bool,float){return floor;}uint32 GetId(){return 1;}
bool HasChildTerrainGridFile(unsigned,int,int){return child;}float GetMaxHeight(int,unsigned,float,float){return 1000;}}terrain;
struct Map{unsigned GetId(){return 1;}Terrain*GetTerrain(){return &terrain;}void LoadGrid(float,float){}
float GetHeight(int,float,float,float,bool,float){return 20;}float GetWaterLevel(int,float,float){return -100000;}}map;
struct Player{Map*GetMap(){return &map;}int GetPhaseShift(){return 0;}};
namespace PhasingHandler{unsigned swap=719;unsigned GetTerrainMapId(int,unsigned,Terrain*,float,float){return swap;}}
struct TerrainMgr{static inline std::set<unsigned>files{1};static inline unsigned checked=0;
static bool ExistMapAndVMap(unsigned id,float,float){checked=id;return files.count(id);}};
struct Surface{float Ground=0,Ceiling=0;bool Valid=false;float TerrainFloor=0;};
struct Record{std::unordered_map<std::string,bool>Tiles;};
struct ClientlessFlightMgr{Surface Sample(Player*,Record&,float,float)const;};
'''+s[a:b]+r'''
int main(){ClientlessFlightMgr mgr;Player p;Record a;
auto surface=mgr.Sample(&p,a,1751,-4389);assert(surface.Valid&&surface.Ground==20&&TerrainMgr::checked==1);
assert(surface.TerrainFloor==5);
terrain.floor=INVALID_HEIGHT;Record missingFloor;assert(!std::isfinite(mgr.Sample(&p,missingFloor,1751,-4389).TerrainFloor));terrain.floor=5;
terrain.child=true;Record b;assert(!mgr.Sample(&p,b,1751,-4389).Valid&&TerrainMgr::checked==719);
TerrainMgr::files.insert(719);Record c;assert(mgr.Sample(&p,c,1751,-4389).Valid&&TerrainMgr::checked==719);
TerrainMgr::files.clear();Record d;assert(!mgr.Sample(&p,d,1751,-4389).Valid);
terrain.child=false;TerrainMgr::files.insert(1);PhasingHandler::swap=1;
Record e;assert(mgr.Sample(&p,e,1751,-4389).Valid&&TerrainMgr::checked==1);}
'''
with tempfile.TemporaryDirectory()as d:
p=Path(d);(p/'test.cpp').write_text(code)
subprocess.run(['c++','-std=c++17',str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)
print('Missing phase tile uses native base terrain; an existing phase tile with missing collision stays forbidden')