// Pure test of the in-world debug overlay's colour/selection logic (debug/overlay.hpp). Guards the two // correctness facts the design hinges on: // (1) coverage (XFIR/XPLC) is FULL-BYTE — a small strength must still tint, not collapse to blank; // (2) the coarse field layers do NOT rotate, so the overlay must sample the UNROTATED city. // Also pins that the overlay agrees with the City Map (render::view_index) on the tiles it tints. #include "sc2k/city.hpp" #include "sc2k/debug/overlay.hpp" #include "sc2k/render/minimap.hpp" #include "sc2k/render/rotate.hpp" #include using namespace sc2k; #include "test_harness.hpp" int main() { // (1) Fire/Police FULL-BYTE ramp: a tiny strength of 6 still tints (the City Map's (x>>4) would be 0). { City c; c.xfir.at(0, 0) = 6; // quarter-cell (0,0) = map tiles 0..3 const int idx = debug::overlay_palette_index(c, debug::OverlayField::Fire, 1, 1); CHECK(idx >= 156 && idx <= 170); // visible, in the grey heat band — NOT -1, NOT 0 CHECK(debug::overlay_palette_index(c, debug::OverlayField::Fire, 100, 100) == -1); // no coverage -> transparent // Stronger coverage ramps darker (higher index). c.xfir.at(2, 2) = 250; // quarter-cell (2,2) = map tiles 8..11 const int idxHi = debug::overlay_palette_index(c, debug::OverlayField::Fire, 9, 9); CHECK(idxHi > idx); } // (2) Rotation contract: the coarse fields don't rotate, so the overlay MUST read the original city. { City c; c.xfir.at(0, 0) = 200; // coverage only in map tiles [0..3]x[0..3] c.xbld.at(0, 5) = 0x70; // an asymmetric building, so we can see rotation move it const City v = render::rotate_city(c, 1); // one quarter-turn CW CHECK(v.xbld.cells != c.xbld.cells); // sanity: rotation DID move the render layers... CHECK(v.xfir.cells == c.xfir.cells); // ...but FACT: rotate_once leaves the XFIR field untouched // The overlay draw maps each VIEW tile back to its ORIGINAL tile and samples there. View tile // (0,0) maps to a tile OUTSIDE the coverage block, so the correct overlay leaves it untinted... int orow, ocol; render::view_tile_to_original(1, 0, 0, orow, ocol); CHECK(!(orow < 4 && ocol < 4)); // (0,0) view is not the coverage block CHECK(debug::overlay_palette_index(c, debug::OverlayField::Fire, orow, ocol) == -1); // ...whereas the BUGGY approach (sampling the view's own XFIR at that tile) WOULD tint it — which // is exactly the rotation bug we avoid by reading the unrotated city. CHECK(debug::overlay_palette_index(v, debug::OverlayField::Fire, 0, 0) != -1); } // (3) Heat fields match the City Map exactly on tinted tiles, and are transparent where it shows base. { City c; c.xcrm.at(5, 5) = 0x90; // crime field, high nibble 9; covers map tiles 10..11 const int ov = debug::overlay_palette_index(c, debug::OverlayField::Crime, 10, 10); const int mm = render::view_index(c, render::MapView::Crime, 10, 10); CHECK(ov == mm && ov >= 0); // overlay colour == City Map colour CHECK(debug::overlay_palette_index(c, debug::OverlayField::Crime, 100, 100) == -1); // zero crime -> transparent } // (4) None is always transparent; the cycle wraps through every field back to None. { City c; CHECK(debug::overlay_palette_index(c, debug::OverlayField::None, 0, 0) == -1); debug::OverlayField f = debug::OverlayField::None; for (int i = 0; i < static_cast(debug::OverlayField::Count); ++i) f = debug::next_overlay(f); CHECK(f == debug::OverlayField::None); // full cycle returns to None } if (failures == 0) { std::printf("overlay: all checks passed\n"); return 0; } std::printf("overlay: %d failure(s)\n", failures); return 1; }