// Per-city OPTION sync KAT — the settings the original snapshots into the .SC2 MISC chunk on save // on save and reinstalls on load, and that Libreopolis now mirrors into the // live runtime/menu (app/main.cpp apply_city_options). Verified MISC offsets (vs real Win95 saves): // No Disasters @0x1000 · Auto-Budget @0xFF0 · Auto-Goto @0xFF4 // Sound/Music are app-wide INI prefs; speed is transient runtime state. None are stored in the city. #include "sc2k/city.hpp" #include "sc2k/io/sc2_file.hpp" #include "sc2k/sim/terrain_gen.hpp" #include "sc2k/render/asset_loader.hpp" #include #include #include #include "test_harness.hpp" #include "test_paths.hpp" int main() { using namespace sc2k; // 1) Accessors land on the exact verified MISC byte offsets and are independent booleans. { City c; c.set_no_disasters(true); c.set_auto_budget(false); c.set_auto_goto(false); CHECK(c.no_disasters() && !c.auto_budget() && !c.auto_goto()); CHECK(c.misc_be32(sc2k::misc::kNoDisasters) == 1 && c.misc_be32(sc2k::misc::kAutoBudget) == 0 && c.misc_be32(sc2k::misc::kAutoGoto) == 0); c.set_no_disasters(false); c.set_auto_budget(true); c.set_auto_goto(true); CHECK(!c.no_disasters() && c.auto_budget() && c.auto_goto()); CHECK(c.misc_be32(sc2k::misc::kNoDisasters) == 0 && c.misc_be32(sc2k::misc::kAutoBudget) == 1 && c.misc_be32(sc2k::misc::kAutoGoto) == 1); // Any nonzero reads as "on" — the original loads a vestigial 255 (BABAR's Auto-Goto) as on. c.set_misc_be32(sc2k::misc::kAutoGoto, 255); CHECK(c.auto_goto()); } // 2) New-city defaults match the original reset: disasters ON, Auto-Budget off, Auto-Goto on. { City n = make_new_city(0x1234567u, 0, 1, 20, 20, 20, 1, 1); CHECK(!n.no_disasters()); // disasters ENABLED for a fresh city CHECK(!n.auto_budget()); // Auto-Budget OFF CHECK(n.auto_goto()); // Auto-Goto ON } // 3) Real Win95 saves carry the per-city option state (values measured from the files themselves). const std::string cdir = cities_dir(); if (exists(cdir + "AMAZINGC.SC2")) { City a; CHECK(io::load_sc2(cdir + "AMAZINGC.SC2", a).ok); CHECK(a.no_disasters()); // AMAZINGC was saved with No Disasters ON CHECK(a.auto_budget()); // ...and Auto-Budget ON CHECK(a.auto_goto()); } else std::printf("options: (skip AMAZINGC — not present)\n"); if (exists(cdir + "CAPE.SC2")) { City c; CHECK(io::load_sc2(cdir + "CAPE.SC2", c).ok); CHECK(!c.no_disasters()); // CAPE: disasters on, Auto-Budget off, Auto-Goto on CHECK(!c.auto_budget()); CHECK(c.auto_goto()); } else std::printf("options: (skip CAPE — not present)\n"); // 4) A toggled option survives File → Save → Load (player flips it in-game, then saves the city). if (exists(cdir + "CAPE.SC2")) { City c; CHECK(io::load_sc2(cdir + "CAPE.SC2", c).ok); CHECK(!c.no_disasters()); c.set_no_disasters(true); // player switches No Disasters ON const std::string tmp = "/tmp/sc2k_opts_roundtrip.sc2"; CHECK(io::save_sc2(tmp, c).ok); City d; CHECK(io::load_sc2(tmp, d).ok); CHECK(d.no_disasters()); // ...and it persists across the round-trip CHECK(d.auto_goto() == c.auto_goto() && d.auto_budget() == c.auto_budget()); } if (failures == 0) { std::printf("options: No-Disasters/Auto-Budget/Auto-Goto sync OK\n"); return 0; } std::printf("options: %d failure(s)\n", failures); return 1; }