46 lines
2.8 KiB
Python
46 lines
2.8 KiB
Python
"""Execute native phase visibility rules: implicit/default phase 169 is shared."""
|
|
from pathlib import Path
|
|
import subprocess,tempfile
|
|
root=Path(__file__).resolve().parents[2]
|
|
s=(root/'src/server/game/Phasing/PhaseShift.cpp').read_text()
|
|
def function(signature):
|
|
a=s.index(signature);b=s.index('{',a);e=b+1;depth=1
|
|
while depth:depth+=(s[e]=='{')-(s[e]=='}');e+=1
|
|
return s[a:e]
|
|
code=r'''
|
|
#include <algorithm>
|
|
#include <cassert>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
using uint32=uint32_t;using int32=int32_t;using ObjectGuid=int;
|
|
constexpr uint32 DEFAULT_PHASE=169;
|
|
enum class PhaseShiftFlags:uint32{None=0,AlwaysVisible=1,Inverse=2,InverseUnphased=4,Unphased=8,NoCosmetic=16};
|
|
enum class PhaseFlags:uint32{None=0,Cosmetic=1,Personal=2};
|
|
template<class T>struct EnumFlag{uint32 bits;EnumFlag(T v):bits(uint32(v)){}EnumFlag(uint32 v):bits(v){}bool HasFlag(T f)const{return (bits&uint32(f))!=0;}EnumFlag operator~()const{return EnumFlag(~bits);}EnumFlag& operator|=(T f){bits|=uint32(f);return *this;}EnumFlag& operator|=(EnumFlag f){bits|=f.bits;return *this;}EnumFlag& operator&=(EnumFlag f){bits&=f.bits;return *this;}};
|
|
struct PhaseShift{
|
|
struct PhaseRef{uint32 Id;EnumFlag<PhaseFlags> Flags{PhaseFlags::None};int References=0;bool operator==(PhaseRef const& p)const{return Id==p.Id;}};
|
|
using PhaseContainer=std::vector<PhaseRef>;PhaseContainer Phases;
|
|
EnumFlag<PhaseShiftFlags> Flags{PhaseShiftFlags::Unphased};int PersonalGuid=0,NonCosmeticReferences=0,CosmeticReferences=0,DefaultReferences=0;bool IsDbPhaseShift=false;
|
|
bool CanSee(PhaseShift const&)const;void ModifyPhasesReferences(PhaseContainer::iterator,int32);void UpdateUnphasedFlag();
|
|
void Add(uint32 id){Phases.push_back({id});ModifyPhasesReferences(Phases.end()-1,1);}
|
|
};
|
|
namespace Trinity{namespace Containers{
|
|
template<class I,class J,class P>bool Intersects(I a,I b,J c,J d,P p){for(;a!=b;++a)for(auto x=c;x!=d;++x)if(*a==*x&&p(*a,*x))return true;return false;}
|
|
}}
|
|
'''
|
|
for sig in ('bool PhaseShift::CanSee(', 'void PhaseShift::ModifyPhasesReferences(', 'void PhaseShift::UpdateUnphasedFlag('):code+=function(sig)+'\n'
|
|
code+=r'''
|
|
int main(){PhaseShift player,standard;standard.Add(169);
|
|
assert(player.CanSee(standard)&&standard.CanSee(player)); // no explicit membership required
|
|
PhaseShift custom;custom.Add(170);assert(!player.CanSee(custom));
|
|
custom.Add(169);assert(player.CanSee(custom));
|
|
custom.ModifyPhasesReferences(custom.Phases.begin()+1,-1);custom.Phases.pop_back();assert(!player.CanSee(custom));
|
|
PhaseShift anotherDefault;assert(player.CanSee(anotherDefault));
|
|
}
|
|
'''
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
src=Path(tmp)/'phase.cpp';exe=Path(tmp)/'phase';src.write_text(code)
|
|
subprocess.run(['g++','-std=c++17',str(src),'-o',str(exe)],check=True)
|
|
subprocess.run([str(exe)],check=True)
|
|
print('Native PhaseShift: implicit/default 169 visibility, genuine custom-phase separation and reference updates passed.')
|