// test_thread_local — the ship-nav thread_local must not leak a route across a city load. // // ShipNav (sim/things.hpp) is per-thread runtime storage. FE10 restores it from THNG; this test covers the // classic/pre-THNG boundary, which drops saved ambient traffic and must clear every slot explicitly. #include "sc2k/sim/things.hpp" #include #include "test_harness.hpp" using namespace sc2k; using namespace sc2k::sim; int main() { // City A: give a few ship slots a fully-planned route + berth, as cargoship_step would leave them. for (int slot : {1, 5, 30}) { ShipNav& r = ship_nav(slot); r.rawGoalX = 40; r.rawGoalY = 50; r.berthX = 41; r.berthY = 51; r.pierX = 42; r.pierY = 52; r.failed = true; r.dwell = 7; r.cursor = 3; r.wp.push_back({10, 10}); r.wp.push_back({11, 12}); r.trail.push_back({10, 10}); } CHECK(ship_nav(5).berthX == 41 && !ship_nav(5).wp.empty()); // the route really is set // Cross the legacy reset boundary into city B: every nav slot must clear. City cityB; reset_ambient_things(cityB); for (int slot : {1, 5, 30}) { const ShipNav& r = ship_nav(slot); CHECK(r.rawGoalX == -1 && r.rawGoalY == -1); // no stale goal CHECK(r.berthX == -1 && r.berthY == -1 && r.pierX == -1 && r.pierY == -1); // no stale berth/pier CHECK(!r.failed && r.dwell == 0 && r.cursor == 0); CHECK(r.wp.empty() && r.trail.empty()); // no stale route / trail } // ship_nav_reset_all clears all kCount slots directly too (the reset hook itself). ship_nav(2).berthX = 99; ship_nav_reset_all(); for (int i = 0; i < thg::kCount; ++i) CHECK(ship_nav(i).berthX == -1); if (failures == 0) std::printf("test_thread_local: ship nav resets across a city load — OK\n"); else std::printf("test_thread_local: %d CHECK(S) FAILED\n", failures); return failures ? 1 : 0; }