Files
EscapistsReintroduced/tests/test_guard_cancellation_policy.py
T
jakub cab998fb64 Combine Workshop addon and fix prison startup
Merge owned systems into one addon while preserving resource identities. Gate player admission on the replicated prison scene, restore the original framed door, and hold enemy AI until escape. Correct scenario branding and author metadata, include publishing assets, and retain regression and native verification evidence.
2026-09-20 16:42:52 +02:00

66 lines
3.3 KiB
Python

"""Run actual ownership cancellation/Stop bodies with shared-array fixtures."""
from policy_harness import ROOT, body, run
p=ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_SiteService.c'
s='\n'.join(body(p, sig) for sig in ('void CancelInitialGuardRequests(', 'void Stop('))
for old,new in [
('GetGame().','GetGame()->'),
('ChimeraAIWorld world', 'ChimeraAIWorld* world'),
('ChimeraAIWorld.Cast', 'ChimeraAIWorld::Cast'),
('foreach (ERR_SiteRuntime site : m_Sites)', 'for (ERR_SiteRuntime* site : m_Sites)'),
('site.Group', 'site->Group'),
('site.InitialGuardCount', 'site->InitialGuardCount'),
('site->Group.', 'site->Group->'),
('new array<ResourceName>()', 'std::make_shared<Array<std::string>>()'),
('world.Purge', 'world->Purge'),
('m_ExtractionPlacement.', 'm_ExtractionPlacement->'),
('ERR_PrepareResult.', 'ERR_PrepareResult::'),
]: s=s.replace(old,new)
run('''#include <cassert>
#include <memory>
#include <string>
#include <vector>
template<typename T> using Array=std::vector<T>;
enum class ERR_PrepareResult {FAILED=-1,PENDING,READY};
struct Group {bool immediate=true; std::shared_ptr<Array<std::string>> m_aUnitPrefabSlots; int physical=0; void SetSpawnImmediately(bool b){immediate=b;} };
struct ERR_SiteRuntime {struct Group* Group; int InitialGuardCount;};
struct ChimeraAIWorld {
Array<Group*> purged;
static ChimeraAIWorld* Cast(ChimeraAIWorld* p){return p;}
void PurgeSpawnRequestsForGroup(Group* group){
assert(!group->immediate && group->m_aUnitPrefabSlots->empty());
purged.push_back(group);
}
};
struct Game {ChimeraAIWorld* world; ChimeraAIWorld* GetAIWorld(){return world;}};
Game* game;
Game* GetGame(){return game;}
struct Placement { int stops=0; void Stop(){stops++;} };
struct Owner {
std::shared_ptr<Placement> m_ExtractionPlacement;
Array<ERR_SiteRuntime*> m_Sites;
bool m_Stopped=false;
ERR_PrepareResult m_State=ERR_PrepareResult::PENDING;
int routeStops=0;
void StopPatrols(){routeStops++;}
''' + s + '''
};
int main(){
ChimeraAIWorld world; Game instance{&world}; game=&instance;
auto authored=std::make_shared<Array<std::string>>(6,"soldier");
Group empty{true,authored,0}, partial{true,authored,2}, control{true,authored,6}, unrequested{true,authored,0};
ERR_SiteRuntime a{&empty,6},b{&partial,6},c{&control,6},ignored{&unrequested,0},missing{nullptr,6};
Owner owner; owner.m_ExtractionPlacement=std::make_shared<Placement>(); owner.m_Sites={&a,&b,&ignored,&missing};
owner.Stop(); owner.Stop();
assert(owner.m_Stopped && owner.routeStops==1 && world.purged.size()==2 && owner.m_ExtractionPlacement->stops==1);
assert(empty.m_aUnitPrefabSlots->empty() && partial.m_aUnitPrefabSlots->empty());
assert(authored->size()==6 && control.m_aUnitPrefabSlots==authored && unrequested.m_aUnitPrefabSlots==authored);
assert(empty.physical==0 && partial.physical==2 && control.physical==6);
assert(control.immediate && unrequested.immediate);
Owner ready; ready.m_State=ERR_PrepareResult::READY; ready.m_Sites={&c}; ready.Stop();
assert(world.purged.size()==2 && control.immediate && control.m_aUnitPrefabSlots->size()==6);
game=nullptr; Owner deletedGame; deletedGame.m_Sites={&c}; deletedGame.Stop();
assert(world.purged.size()==2);
}
''')
print('PASS: pending-only cancellation retires copied instance intent, preserves physical/control actors, and stops once')