55 lines
2.6 KiB
Python
55 lines
2.6 KiB
Python
"""Execute native follow speed selection for server-driven player splines."""
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
|
|
root = Path(__file__).resolve().parents[2]
|
|
source = (root / 'src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp').read_text()
|
|
start = source.index('inline float GetVelocity(')
|
|
end = source.index('\nstatic void ApplyCatchUpMod', start)
|
|
code = r'''
|
|
#include <cassert>
|
|
enum UnitMoveType { MOVE_WALK, MOVE_RUN, MOVE_FLIGHT };
|
|
struct Spline {
|
|
bool finalized=true;float velocity=2.5f;
|
|
bool Finalized(){return finalized;}float Velocity(){return velocity;}
|
|
};
|
|
struct Unit {
|
|
bool player=false,flying=false,walking=false;
|
|
Spline spline;Spline* movespline=&spline;
|
|
struct { unsigned flags=0;unsigned GetMovementFlags(){return flags;} }m_movementInfo;
|
|
bool IsPlayer(){return player;}bool IsFlying(){return flying;}bool IsWalking(){return walking;}
|
|
float GetSpeed(UnitMoveType t){return t==MOVE_WALK?2.5f:t==MOVE_FLIGHT?14.f:7.f;}
|
|
};
|
|
UnitMoveType SelectSpeedType(unsigned flags){return flags?MOVE_WALK:MOVE_RUN;}
|
|
'''
|
|
code += source[start:end]
|
|
code += r'''
|
|
int main(){
|
|
Unit cat,target;target.player=true;target.spline.finalized=false;
|
|
// SetWalk changes spline speed while player movement flags still select running.
|
|
assert(target.m_movementInfo.flags==0);
|
|
assert(GetVelocity(&cat,&target,true)==2.5f);
|
|
// Explicit server velocities, running splines and creature targets follow suit.
|
|
target.spline.velocity=1.75f;assert(GetVelocity(&cat,&target,true)==1.75f);
|
|
target.spline.velocity=7.f;assert(GetVelocity(&cat,&target,true)==7.f);
|
|
target.player=false;target.spline.velocity=3.f;assert(GetVelocity(&cat,&target,true)==3.f);
|
|
// Ordinary client movement retains native flag-based gait selection.
|
|
target.player=true;target.spline.finalized=true;
|
|
assert(GetVelocity(&cat,&target,true)==7.f);
|
|
target.m_movementInfo.flags=1;assert(GetVelocity(&cat,&target,true)==2.5f);
|
|
target.player=false;assert(GetVelocity(&cat,&target,true)==7.f);
|
|
// Independent followers keep their own walk/run/flight speed.
|
|
cat.walking=true;assert(GetVelocity(&cat,&target,false)==2.5f);
|
|
cat.walking=false;assert(GetVelocity(&cat,&target,false)==7.f);
|
|
cat.flying=true;assert(GetVelocity(&cat,&target,false)==14.f);
|
|
}
|
|
'''
|
|
with tempfile.TemporaryDirectory(prefix='vcore-follow-velocity-') 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('Native follow: actual player/creature spline velocity, client gait and independent follower speeds passed.')
|