Files
EscapistsReintroduced/tests/test_crash_random_loot.py
T
2026-11-06 23:26:57 +01:00

42 lines
2.2 KiB
Python

"""Execute real quality rolls and verify poor/rich ranges without a guaranteed premium weapon."""
from policy_harness import ROOT,body,run
path=ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_CrashLoot.c'
code='\n'.join(body(path,s) for s in ['static void Plan(', 'static void QualityPlan(', 'static void RandomPlan('])
code=code.replace('array<ResourceName> items','array<ResourceName>& items').replace('Math.RandomInt','Roll').replace('ERR_EnemyLoadoutCatalog.FIM','FIM').replace('ERR_Supplies.Magazine()','PistolMagazine()').replace('ERR_Supplies.Pistol()','Pistol()')
run(r"""
#include <cassert>
#include <string>
#include <vector>
using ResourceName=std::string;
template<class T> struct array:std::vector<T>{void Clear(){this->clear();}void Insert(T v){this->push_back(v);}};
bool enabled=true;int extreme=0,qualityRoll=-1;
int Roll(int low,int high){if(low==0&&high==100&&qualityRoll>=0){int q=qualityRoll;qualityRoll=-1;return q;}return extreme?high-1:low;}
ResourceName FIM="AA";
bool RifleAllowed(bool){return enabled;}
bool Allowed(ResourceName){return enabled;}
ResourceName Rifle(bool w){return w?"W":"E";}
ResourceName Magazine(bool w){return w?"WM":"EM";}
ResourceName RPG(){return "RPG";}
ResourceName Rocket(){return "ROCKET";}
ResourceName Pistol(){return "PM";}
ResourceName PistolMagazine(){return "PMM";}
"""+code+r"""
int main(){
array<ResourceName> items;
for(int q=0;q<100;q++){
for(extreme=0;extreme<=1;extreme++){
QualityPlan(q,items);
if(q<30){assert(items.size()>=1&&items.size()<=4);for(auto item:items)assert(item=="PM"||item=="PMM");}
else if(q<65)assert(items.size()>=2&&items.size()<=4);
else if(q<90)assert(items.size()>=6&&items.size()<=22);
else assert(items.size()>=20&&items.size()<=58);
}
}
extreme=0;qualityRoll=0;RandomPlan(items);assert(items.size()==1&&items[0]=="PMM");
qualityRoll=99;RandomPlan(items);assert(items.size()>=20&&items.size()<=58);
// Disabled content remains excluded even on the richest roll.
enabled=false;QualityPlan(99,items);assert(items.empty());QualityPlan(0,items);assert(items.empty());
}
""")
print('PASS: every quality boundary, ammunition-only poor rolls, rich rolls, one random quality draw and content exclusion')