42 lines
2.7 KiB
Python
42 lines
2.7 KiB
Python
"""Area destinations select a reachable native graph node inside the area."""
|
|
from pathlib import Path
|
|
import subprocess,tempfile
|
|
root=Path(__file__).resolve().parents[2]
|
|
s=(root/'src/server/game/World/AdventureBehaviorMgr.cpp').read_text()
|
|
a=s.index('std::string AdventureBehaviorMgr::AreaNode(');start=s.index('{',a);b=start+1;depth=1
|
|
while depth:
|
|
depth+=(s[b]=='{')-(s[b]=='}');b+=1
|
|
code=r'''
|
|
#include <algorithm>
|
|
#include <cassert>
|
|
#include <cmath>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <cstdint>
|
|
using uint32=uint32_t;
|
|
struct Position {float x=0;void Relocate(float a,float,float){x=a;}float GetPositionX(){return x;}float GetPositionY(){return 0;}};
|
|
struct Player{int map=0;int GetPhaseShift(){return 0;}int GetMapId(){return map;}float GetExactDist(Position p){return p.x;}};
|
|
struct AdventureLocation{struct{int MapId=0;float X=0,Y=0;}Point;uint32 AreaId=12;};
|
|
struct Field{float value=0;std::string text;float GetFloat(){return value;}std::string GetString(){return text;}};
|
|
struct Rows{std::vector<std::vector<Field>> data;unsigned row=0;operator bool(){return !data.empty();}Rows* operator->(){return this;}Field* Fetch(){return data[row].data();}bool NextRow(){return ++row<data.size();}};
|
|
struct Database{Rows rows;Rows PQuery(char const*,int){return rows;}}WorldDatabase;
|
|
struct Terrain{void GetZoneAndAreaId(int,int,uint32&zone,uint32&area,Position p){zone=p.x==1?99:12;area=zone;}}terrain;
|
|
struct TerrainMgr{bool available=true;Terrain* LoadTerrain(int){return available?&terrain:nullptr;}}sTerrainMgr;
|
|
struct ClientlessTravelRouteStep{};
|
|
struct Graph{std::vector<std::string> tried;bool PlanAdaptiveRoute(Player*,std::string const&key,int,int,std::vector<ClientlessTravelRouteStep>&,bool& complete,std::string&,std::string&){tried.push_back(key);complete=key=="reachable";return true;}}graph;auto sClientlessTravelGraphMgr=&graph;
|
|
struct AdventureBehaviorMgr{std::string AreaNode(Player*,AdventureLocation const&);};
|
|
'''+s[a:b]+r'''
|
|
int main(){
|
|
WorldDatabase.rows.data={{{0,"outside"},{1,""},{},{}},{{0,"blocked"},{2,""},{},{}},{{0,"reachable"},{3,""},{},{}}};
|
|
Player p;AdventureLocation l;AdventureBehaviorMgr mgr;
|
|
assert(mgr.AreaNode(&p,l)=="reachable");assert((graph.tried==std::vector<std::string>{"blocked","reachable"}));
|
|
sTerrainMgr.available=false;assert(mgr.AreaNode(&p,l).empty());sTerrainMgr.available=true;
|
|
l.AreaId=42;graph.tried.clear();assert(mgr.AreaNode(&p,l).empty()&&graph.tried.empty());
|
|
}
|
|
'''
|
|
with tempfile.TemporaryDirectory(prefix='vcore-area-node-') as folder:
|
|
cpp=Path(folder)/'test.cpp';binary=Path(folder)/'test';cpp.write_text(code)
|
|
subprocess.run(['c++','-std=c++17',str(cpp),'-o',str(binary)],check=True)
|
|
subprocess.run([str(binary)],check=True)
|
|
print('Production area destination excludes outside and unreachable graph nodes.')
|