#include "runtime_fixture_tables.hpp" #include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include #include #include #include #include #include #include #include #include "formats/fbm.hpp" #include "formats/le.hpp" #include "game/career.hpp" #include "game/national.hpp" #include "game/save.hpp" #include "game/weekly.hpp" using namespace bmh; namespace { using bmh::test_support::check; struct Candidate { int player; int score; }; } int main(int argc,char**argv){try{ if(argc<3||argc>4)throw std::runtime_error("usage: national_nomination_tests [output stream]"); if(!*argv[1]) { std::cout<<"Nomination tests skipped: Original data not configured\n"; return 77; } const auto exe=bmh::test::load_executable(std::filesystem::path(argv[1])/"BMH.exe"); const auto texts=load_textd(std::filesystem::path(argv[1])/"TEXTD.BLK"); const auto file=load_savegame(argv[2]);check(file.checksum_ok,"native fixture checksum"); const DbCounts counts{exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField),exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3),exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2),exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4)}; GameState g=GameState::from_save(SaveState(file.stream,counts),counts); competition_pointers(g.memory,exe);g.texts=&texts;national_coach_after_load(g); check(g.manager_teams.size()==2,"fixture has two human managers and spare national slot"); // Independent ranking oracle: choose the strongest positional quota, preserving // first encountered players at equal score. This tests the national selection's // contract without reproducing its bounded ascending insertion loop. const std::array quotas{3,5,7,5}; std::array,4> candidates; for(size_t slot=0;slot<0xb70;++slot){ const int id=g.squad_slots.at(slot)&0xfff;if(id==0xfff)continue; const auto& p=g.players.at(size_t(id)); if(((p.w35c>>27)!=0 && ((p.w364>>16)&0x1f)!=0)||nationality(g,id)!=0)continue; const int pos=int(p.w364&3);int score=p.strength(false); if(pos>1)score+=int((p.w364>>2)&0x3f)+int(((p.w368>>18)&0x3f)>>1); if(slot>0x86f)score=score*11/10; candidates[size_t(pos)].push_back({id,score}); } std::set expected; for(size_t pos=0;pos<4;++pos){ auto& list=candidates[pos];check(list.size()>size_t(quotas[pos]),"more candidates than positional capacity"); std::stable_sort(list.begin(),list.end(),[](const Candidate& a,const Candidate& b){return a.score>b.score;}); for(int row=0;row actual;std::array actual_by_position{}; const auto national=squad_range(kNoTeam); for(size_t slot=national.first;slot(bytes.data()),std::streamsize(bytes.size()));} return 0; }catch(const std::exception& e){std::cerr<