Files
Viano-Core/tests/clientless/test_route_approach_flight.py
T
Nico ba2a4e629c
clang PCH / build (push) Waiting to run
GCC PCH / build (push) Waiting to run
Recover stalled flights locally and fly rejected route approaches
2026-11-04 01:14:02 +01:00

56 lines
3.1 KiB
Python

"""Run the production local-flight adapter; preserve macro route and native checks."""
from pathlib import Path
import subprocess
import tempfile
root = Path(__file__).resolve().parents[2]
src = (root/'src/server/game/World/ClientlessActionExecutorMgr.cpp').read_text()
a = src.index('bool ClientlessActionExecutorMgr::TryRouteApproachFlight(')
b = src.index('bool ClientlessActionExecutorMgr::RecoverTravel(', a)
method = src[a:b]
harness = r'''
#include <cassert>
#include <cmath>
#include <string>
#include <vector>
#include <set>
using uint32=unsigned;
struct Position {float x=0,y=0,z=0;void Relocate(float a,float b,float c,float){x=a;y=b;z=c;}};
struct Player {unsigned GetMapId(){return 0;}float GetExactDist(float x,float y,float z){return std::sqrt(x*x+y*y+z*z);}};
struct Step {std::string NodeKey="portal",EdgeType="start";unsigned MapId=0,EdgeDatabaseId=0;float X=100,Y=0,Z=10,O=0;};
enum class ClientlessActionExecutionState{Moving,Failed};
struct Record {std::vector<Step> Route{Step{},Step{}};unsigned RouteStep=0;std::set<std::string> FailedBridgeKeys;bool DeferredStartActive=true,FlightActive=false,Active=false;std::vector<int> EdgePath{1,2};struct {ClientlessActionExecutionState State=ClientlessActionExecutionState::Failed;std::string Detail;}Status;};
struct Flight {bool available=true;unsigned calls=0;Position last;bool Start(Player*,Position const&p,std::string&error,bool owned){assert(owned);++calls;last=p;if(!available)error="no safe landing";return available;}}flight;
auto sClientlessFlightMgr=&flight;
#define TC_LOG_INFO(...) ((void)0)
struct ClientlessActionExecutorMgr {bool TryRouteApproachFlight(Player*,uint32,Record&);};
'''
harness += method + r'''
int main(){
Player p;Record r;ClientlessActionExecutorMgr mgr;
// Fly to the rejected connector, preserving the following portal edge.
assert(mgr.TryRouteApproachFlight(&p,163,r));
assert(r.FlightActive&&r.Active&&!r.DeferredStartActive&&r.EdgePath.empty());
assert(r.RouteStep==0&&r.Route.size()==2&&r.Route[0].EdgeType=="start");
assert(flight.last.x==100&&flight.last.z==10&&flight.calls==1);
assert(!mgr.TryRouteApproachFlight(&p,163,r)&&flight.calls==1);
// No flight permission/solid landing/ground connection means no fallback.
r=Record{};flight.available=false;
assert(!mgr.TryRouteApproachFlight(&p,163,r)&&!r.FlightActive&&r.Route.size()==2);
r=Record{};flight.available=true;r.Route[0].MapId=1;
assert(!mgr.TryRouteApproachFlight(&p,163,r));
r=Record{};r.Route[0].EdgeDatabaseId=42;
assert(!mgr.TryRouteApproachFlight(&p,163,r));
for(auto type:{"portal_use","taxi","free_flight","ship"}){
r=Record{};r.Route[0].EdgeType=type;assert(!mgr.TryRouteApproachFlight(&p,163,r));
}
r=Record{};r.Route[0].EdgeType="local_bridge";assert(mgr.TryRouteApproachFlight(&p,163,r));
}
'''
with tempfile.TemporaryDirectory(prefix='vcore-route-flight-') as folder:
cpp=Path(folder)/'test.cpp'; exe=Path(folder)/'test'
cpp.write_text(harness)
subprocess.run(['c++','-std=c++17',str(cpp),'-o',str(exe)],check=True)
subprocess.run([str(exe)],check=True)
print('Route approach flight: original route retained, one attempt, native refusal and transport boundaries passed.')