Files
Viano-Core/tests/clientless/test_waiting_capital.py
T
Nico 3aa780662e Complete AdventureBot navigation, instance travel and shutdown fixes
Finish capital waiting travel and adaptive flight entry up to 10,000 yards.
Preserve checked vertical climbs, recover blocked ground departures and find
validated dry landings. Retain group routes and Undercity arrival constraints.

Restore defense from native combat references, coordinate instance rendezvous
and browser reentry, finalize clientless sessions before map destruction and
transfer Halaa capture-point ownership safely.

Include the associated regression tests, investigation reports and reusable
diagnostic scripts. Keep generated runtime evidence and server binaries local
through scoped ignore rules. Validation/build/live evidence is recorded in the
session checkpoint and individual reports.
2026-11-05 10:35:34 +01:00

85 lines
6.6 KiB
Python

"""Execute production capital-wait routing, preserving the remote activity intent."""
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('bool AdventureBehaviorMgr::UpdateWaitingCapital(');b=s.index('void AdventureBehaviorMgr::Begin(',a)
code=r'''
#include "AdventureGroupPolicy.h"
#include <map>
#include <vector>
#include <unordered_map>
#include <string>
#include <cassert>
#include <cmath>
using uint32=unsigned;
#define TC_LOG_INFO(...) ((void)0)
#define TC_LOG_WARN(...) ((void)0)
struct Guid{unsigned id=1;unsigned GetCounter()const{return id;}bool operator!=(Guid o)const{return id!=o.id;}};
struct Group{Guid leader{2};Guid GetLeaderGUID(){return leader;}}group;
struct Player{unsigned map=530,zone=3519,level=68,faction=2;float x=0;Group* group=nullptr;Guid GetGUID(){return {};}Group* GetGroup(){return group;}unsigned GetMapId(){return map;}unsigned GetZoneId(){return zone;}float GetExactDist(float v,float,float){return std::abs(v-x);}};
struct Position{void Relocate(Player*){}};
struct AdventureLocation{struct{std::string Id;unsigned MapId;float X,Y=0,Z=0;}Point;unsigned ZoneId,AreaId=0;bool IsArea=false;unsigned faction,min;};
struct Locations{std::vector<AdventureLocation> sites{{{"org",1,10},1637,0,false,2,1},{{"sw",0,20},1519,0,false,1,1},{{"shatt",530,30},3703,0,false,0,58},{{"dalaran",571,40},4395,0,false,0,70}};auto const& Locations(){return sites;}AdventureLocation const* Find(std::string const&key){for(auto const&s:sites)if(s.Point.Id==key)return &s;return nullptr;}bool LevelEligible(Player*p,AdventureLocation const&s,std::string const&,bool strict){assert(strict);return p->level>=s.min;}}locations;
auto sAdventureLocationMgr=&locations;
enum class ClientlessActionExecutionState{Moving,Completed,Failed};
struct Executor{struct{ClientlessActionExecutionState State=ClientlessActionExecutionState::Moving;}status;auto GetStatus(unsigned){return &status;}}executor;auto sClientlessActionExecutorMgr=&executor;
struct Manager{unsigned queued=0;unsigned GetQueuedActionCount(unsigned){return queued;}}manager;auto sClientlessPlayerMgr=&manager;
struct Groups{bool BotLed(Player*){return true;}}groups;auto sAdventureGroupMgr=&groups;
struct AdventureBehaviorMgr{
enum class Phase{Idle,WaitingGroup};
struct Record{Phase State=Phase::WaitingGroup;std::string WaitingLocation,Intent="raid",Location="remote-raid",Micro,Detail;bool WaitingTravel=false,WaitingArrived=false,Queued=false;time_t WaitingRetryAt=0;Position Anchor;unsigned AnchorMap=0;std::mt19937 Random{123};};
std::unordered_map<unsigned,Record>_records;
bool busy=false,accept=true;unsigned queues=0,reset=0;std::string target;
bool Busy(unsigned){return busy;}
bool Allowed(Player*p,AdventureLocation const&s,std::string const&i){assert(i=="groupformation");return !s.faction||s.faction==p->faction;}
void ResetMicro(Player*,Record&r){++reset;r.Micro.clear();}
void Queue(Player*,Record&r,std::string const&a,std::string const&key,std::string const&value,bool hard){assert(a=="travel_to_location"&&key=="id"&&hard);++queues;target=value;r.Queued=accept;}
bool UpdateWaitingCapital(Player*,Record&,time_t);
};
'''.replace('struct Locations{','struct Catalog{')+s[a:b]+r'''
int main(){
AdventureBehaviorMgr m;AdventureBehaviorMgr::Record r;Player p;
assert(!m.UpdateWaitingCapital(&p,r,100));assert(m.queues==1&&(m.target=="org"||m.target=="shatt"));
assert(r.Intent=="raid"&&r.Location=="remote-raid"&&r.WaitingTravel);
auto chosen=r.WaitingLocation;manager.queued=1;m.UpdateWaitingCapital(&p,r,101);assert(m.queues==1&&r.WaitingLocation==chosen);
// Cross-continent transitions leave destination stable while the action owns travel.
manager.queued=0;m.busy=true;p.map=0;m.UpdateWaitingCapital(&p,r,102);assert(m.queues==1&&r.WaitingLocation==chosen);
m.busy=false;executor.status.State=ClientlessActionExecutionState::Failed;
assert(!m.UpdateWaitingCapital(&p,r,103));assert(r.WaitingLocation.empty()&&r.WaitingRetryAt==133);
m.UpdateWaitingCapital(&p,r,132);assert(m.queues==1);
m.UpdateWaitingCapital(&p,r,133);assert(m.queues==2);
// Actual arrival required: completion far away cannot start activities.
executor.status.State=ClientlessActionExecutionState::Completed;
assert(!m.UpdateWaitingCapital(&p,r,134));assert(!r.WaitingArrived);
m.UpdateWaitingCapital(&p,r,164);auto site=locations.Find(r.WaitingLocation);assert(site);
p.map=site->Point.MapId;p.zone=site->ZoneId;p.x=site->Point.X;
assert(m.UpdateWaitingCapital(&p,r,165));assert(r.WaitingArrived&&r.AnchorMap==p.map);
// Completed activities may roam without repeatedly recalling the bot to the POI.
p.x+=50;r.Micro.clear();unsigned n=m.queues;
assert(m.UpdateWaitingCapital(&p,r,166));assert(m.queues==n);
// Followers wait for their leader to select, instead of choosing another city.
p.group=&group;m._records[2]={};AdventureBehaviorMgr::Record pending;
unsigned before=m.queues;m.UpdateWaitingCapital(&p,pending,199);assert(m.queues==before&&pending.WaitingLocation.empty()&&pending.WaitingRetryAt==200);
// Partial groups inherit a permitted leader waiting target.
AdventureBehaviorMgr::Record follower;m._records[2].WaitingLocation="shatt";p.group=&group;
assert(!m.UpdateWaitingCapital(&p,follower,200));assert(follower.WaitingLocation=="shatt");
// An enemy capital / underlevel neutral capital can never be adopted.
m._records[2].WaitingLocation="sw";AdventureBehaviorMgr::Record other;
m.UpdateWaitingCapital(&p,other,201);assert(other.WaitingLocation!="sw"&&other.WaitingLocation!="dalaran");
// Current permitted capital is retained; low-level Horde cannot enter neutral capitals.
p.group=nullptr;p.level=10;p.zone=1637;p.map=1;p.x=10;AdventureBehaviorMgr::Record low;
assert(m.UpdateWaitingCapital(&p,low,202)&&low.WaitingLocation=="org");
p.faction=1;p.zone=3519;p.map=530;p.x=0;AdventureBehaviorMgr::Record alliance;
m.UpdateWaitingCapital(&p,alliance,203);assert(alliance.WaitingLocation=="sw");
// No eligible destination: fail closed and throttle, preserve PvP activity.
locations.sites.clear();AdventureBehaviorMgr::Record none;none.Intent="pvp";
assert(!m.UpdateWaitingCapital(&p,none,300));assert(none.WaitingLocation.empty()&&none.WaitingRetryAt==360&&none.Intent=="pvp");
}
'''
with tempfile.TemporaryDirectory() as d:
p=Path(d);(p/'test.cpp').write_text(code)
subprocess.run(['c++','-std=c++17','-I'+str(root/'src/server/game/World'),str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)
print('Capital waiting: faction/level/neutral access, stable random selection, leader destination, cross-map travel, arrival, roaming and retry passed.')