41 lines
2.6 KiB
Python
41 lines
2.6 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 <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{bool child=false;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 ↦}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;};
|
|
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);
|
|
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')
|