// Known-answer test for new-game setup (the original's new-game reset). #include "sc2k/sim/new_game.hpp" #include "sc2k/sim/terrain_gen.hpp" // make_new_city / start_game_on_map / repair_city_header #include "sc2k/sim/inventions.hpp" // invention-year seeding into MISC 0x738 #include #include "test_harness.hpp" int main() { using namespace sc2k; // Deterministic parameters: start year (50·(era+38)), era funds, treasury by difficulty. struct { int era, diff, year, funds, eraFunds; } cases[] = { {0, 1, 1900, 20000, 10000}, // easy, 1900 {1, 2, 1950, 10000, 25000}, // medium, 1950 {2, 1, 2000, 20000, 60000}, // easy, 2000 {3, 3, 2050, 10000, 150000}, // hard, 2050 }; for (auto& t : cases) { MsRand rng(1); NewGame g = new_game_setup(t.era, t.diff, rng); CHECK(g.startYear == t.year); CHECK(g.funds == t.funds); CHECK(g.eraFunds == t.eraFunds); } // Invention years: each is 0 (already invented) or within [base, base+19] and >= start year. { MsRand rng(12345); NewGame g = new_game_setup(2, 2, rng); // start 2000 for (int i = 0; i < 17; ++i) { std::int16_t y = g.inventionYears[i]; bool ok = (y == 0) || (y >= kInventionBaseYears[i] && y <= kInventionBaseYears[i] + 19 && y >= g.startYear); CHECK(ok); } // a tech whose whole base+0..19 window is before 2000 must be already invented (0) // base[9]=1900 → window 1900..1919, all < 2000 → 0 CHECK(g.inventionYears[9] == 0); // base[16]=2190 → window 2190..2209, all >= 2000 → not zeroed CHECK(g.inventionYears[16] >= 2190 && g.inventionYears[16] <= 2209); } // Cross-compat MISC header: a fresh city seeds wCityMode (0x04)=1 and city class (0x1C)=difficulty (1..3). // Both are what the real game's loader reads for the mode + demand/disaster multipliers; leaving them 0 // (the old bug) makes the real game open the save in MAP-EDITOR mode and jams industrial demand. { for (int diff = 1; diff <= 3; ++diff) { City c = make_new_city(0x99u, 0, diff, 20, 20, 20, 1, 1); CHECK(c.misc_be32(sc2k::misc::kCityMode) == 1); // wCityMode = play CHECK(c.misc_be32(sc2k::misc::kCityClass) == diff); // city class = 1-based difficulty } // repair_city_header fixes an early port save that left them 0 (recover class from trend 0x5C+1). City c = make_new_city(0x99u, 0, 2, 20, 20, 20, 1, 1); c.set_misc_be32(sc2k::misc::kCityMode, 0); c.set_misc_be32(sc2k::misc::kCityClass, 0); // simulate a pre-fix save (0x5C trend stays = diff-1 = 1) CHECK(repair_city_header(c)); CHECK(c.misc_be32(sc2k::misc::kCityMode) == 1); CHECK(c.misc_be32(sc2k::misc::kCityClass) == 2); // trend(1)+1 = class 2 recovered CHECK(!repair_city_header(c)); // a valid header → no-op } // Invention year-gating: a fresh 1900 city seeds the 17 invention years into MISC 0x738..0x778 (a // future year per gated tech), NOT all-zero — else `0 = invented` would unlock everything from 1900. { City c = make_new_city(0x99u, 0, 1, 20, 20, 20, 1, 1); // era 0 = founded 1900 CHECK(c.invention_year(16) >= 2190 && c.invention_year(16) <= 2209); // highway_2 (base 2190) gated far out CHECK(c.invention_year(5) >= 2050 && c.invention_year(5) <= 2069); // fusion (base 2050) gated CHECK(c.city_status() == 0); // new city starts at reward tier 0 (earns rewards by growing) CHECK(!sc2k::sim::repair_inventions_if_unseeded(c)); // a properly-seeded city is left untouched } if (failures == 0) { std::printf("new_game: all checks passed\n"); return 0; } std::printf("new_game: %d failure(s)\n", failures); return 1; }