52 lines
3.8 KiB
Python
52 lines
3.8 KiB
Python
"""Exercise the production landing search, including distant and layered alternatives."""
|
|
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(' bool foundLanding = false;');b=s.index(' sClientlessTravelMgr->CancelTravel(',a)
|
|
code=r'''
|
|
#include <cmath>
|
|
#include <cassert>
|
|
#include <string>
|
|
#include <algorithm>
|
|
#include <array>
|
|
using uint32=unsigned;
|
|
constexpr float MAX_HEIGHT=100000;constexpr int NAV_GROUND=1;
|
|
struct Position{float x=0,y=0,z=0,o=0;float GetPositionX()const{return x;}float GetPositionY()const{return y;}float GetPositionZ()const{return z;}float GetOrientation()const{return o;}
|
|
void Relocate(float a,float b,float c,float d){x=a;y=b;z=c;o=d;}};
|
|
struct Surface{float Ground=0,Ceiling=500;bool Valid=true;};
|
|
struct Map{float GetHeight(int,float,float,float,bool,float){return 20;}}map;
|
|
struct Player{int GetPhaseShift(){return 0;}Map*GetMap(){return ↦}unsigned GetMapId(){return 530;}unsigned GetInstanceId(){return 0;}};
|
|
struct Record{struct{Position Landing;bool FollowingPlayer=false;}Status;struct{float Clearance=60;}Settings;};
|
|
struct Areas{bool allowed=true;bool AllowsSegment(Player*,unsigned,Position const&,Position const&){return allowed;}}areas;auto sAdventureAreaMgr=&areas;
|
|
struct PathGenerator{struct Path{bool complete=true;float FinalDistance=0,PathLength=180;bool IsComplete(){return complete;}};
|
|
static inline Path result;static inline bool roofReachable=false;static inline unsigned probes=0;
|
|
static Path AnalyzePositions(unsigned,unsigned,unsigned,Position const&a,Position const&,int){++probes;auto p=result;if(a.z==20&&!roofReachable)p.complete=false;return p;}};
|
|
bool column=true;float openAt=50;bool water=false;
|
|
bool OpenColumn(Player*,float x,float y,Surface const&,float){return column&&std::hypot(x,y)>=openAt;}
|
|
Surface Sample(Player*,Record&,float x,float y){return {water?30.f:std::hypot(x,y)<50?20.f:0.f,500,true};}
|
|
bool Find(Player*player,Record&record,Position const&target,std::string&error){bool following=false;
|
|
'''+s[a:b]+r'''
|
|
return true;
|
|
}
|
|
int main(){Player p;Record record;Position target;std::string error;
|
|
// Nearby roof candidates are unusable. A safe outdoor landing 80yd away works.
|
|
assert(Find(&p,record,target,error));assert(std::hypot(record.Status.Landing.x,record.Status.Landing.y)>=79&&record.Status.Landing.z==0);
|
|
// >5yd level difference is fine only when the native MMAP approach is complete.
|
|
openAt=0;PathGenerator::roofReachable=true;assert(Find(&p,record,target,error)&&record.Status.Landing.z==20);
|
|
PathGenerator::roofReachable=false;assert(Find(&p,record,target,error)&&record.Status.Landing.z==0);
|
|
PathGenerator::result.complete=false;assert(!Find(&p,record,target,error));PathGenerator::result.complete=true;
|
|
PathGenerator::result.FinalDistance=2;assert(!Find(&p,record,target,error));PathGenerator::result.FinalDistance=0;
|
|
PathGenerator::result.PathLength=601;assert(!Find(&p,record,target,error));PathGenerator::result.PathLength=180;
|
|
column=false;assert(!Find(&p,record,target,error));column=true;
|
|
areas.allowed=false;assert(!Find(&p,record,target,error));areas.allowed=true;
|
|
water=true;assert(!Find(&p,record,target,error));
|
|
}
|
|
'''
|
|
# Define the static aggregate out-of-line for older standalone compilers.
|
|
code=code.replace('static inline Path result;', 'static Path result;').replace('bool column=true;', 'PathGenerator::Path PathGenerator::result;\nbool column=true;')
|
|
with tempfile.TemporaryDirectory()as d:
|
|
p=Path(d);(p/'test.cpp').write_text(code)
|
|
subprocess.run(['c++','-std=c++17','-include',str(Path(__file__).with_name('telemetry_test_stub.h')),str(p/'test.cpp'),'-o',str(p/'test')],check=True)
|
|
subprocess.run([str(p/'test')],check=True)
|
|
print('Production landing search: distant/layered alternatives, native final ground approach, water/collision/area rejection.')
|