// Numeric test for the XBLD → feature-category classifier (xbld::features_of) and feature_shown, // which drive the "View City Layers" toggles. Pure logic — no assets, always runs. Locks every // category boundary, the dual-category power crossings, and the masking rule. #include "sc2k/render/city_renderer_tables.hpp" // render::ViewToggles + feature_shown #include "sc2k/tile_codes.hpp" #include using namespace sc2k; namespace feat = sc2k::xbld::feat; #include "test_harness.hpp" int main() { auto F = [](int xb) { return xbld::features_of(std::uint8_t(xb)); }; // Groundcover: clear / rubble / radioactive → 0 (always drawn, not toggleable). for (int xb = 0x00; xb <= 0x05; ++xb) CHECK(F(xb) == 0); // Flora = trees only; the small park (0x0D) is a placed amenity → Other, not Flora. CHECK(F(0x06) == feat::Flora); CHECK(F(0x0C) == feat::Flora); CHECK(F(0x0D) == feat::Other); // Power lines (0x0E-0x1C) and the raised-power deck (0x5C) → Power. CHECK(F(0x0E) == feat::Power); CHECK(F(0x1C) == feat::Power); CHECK(F(0x5C) == feat::Power); // Transport: roads / rail / tunnels / highways / bridges / ramps / sub-rail portals. for (int xb : {0x1D, 0x2B, 0x2C, 0x3E, 0x3F, 0x42, 0x49, 0x4A, 0x51, 0x5B, 0x5D, 0x60, 0x61, 0x6B, 0x6C, 0x6F}) CHECK(F(xb) == feat::Transport); // Crossings: only the power-bearing ones carry Power. Road×rail and highway×road/rail are pure Transport. for (int xb : {0x43, 0x44, 0x47, 0x48, 0x4F, 0x50}) CHECK(F(xb) == (feat::Transport | feat::Power)); for (int xb : {0x45, 0x46, 0x4B, 0x4C, 0x4D, 0x4E}) CHECK(F(xb) == feat::Transport); // Buildings: zoned R/C/I (0x70-0xC5) → Zoned; everything 0xC6+ (plants/civic/park/rewards/arco) → Other. CHECK(F(0x70) == feat::Zoned); CHECK(F(0xC5) == feat::Zoned); for (int xb : {0xC6, 0xCF, 0xD5, 0xFB, 0xFF}) CHECK(F(xb) == feat::Other); // Every developed/network code is categorised; only 0x00-0x05 are groundcover (0). for (int xb = 0x06; xb <= 0xFF; ++xb) CHECK(F(xb) != 0); // feature_shown masking. All on → everything shows (incl. groundcover). CHECK(render::feature_shown(0x1D, render::ViewToggles{})); CHECK(render::feature_shown(0x00, render::ViewToggles{})); // Transportation off hides roads but not power lines; power off is the mirror. const render::ViewToggles noT{.transportation = false}; CHECK(!render::feature_shown(0x1D, noT)); // road hidden CHECK(render::feature_shown(0x0E, noT)); // power line still shown const render::ViewToggles noP{.powerLines = false}; CHECK(render::feature_shown(0x1D, noP)); // road still shown CHECK(!render::feature_shown(0x0E, noP)); // power line hidden // A power crossing shows while EITHER network is on; hidden only when both are off. CHECK(render::feature_shown(0x43, noT)); CHECK(render::feature_shown(0x43, noP)); const render::ViewToggles noTP{.transportation = false, .powerLines = false}; CHECK(!render::feature_shown(0x43, noTP)); // Zoned vs Other buildings gate independently. const render::ViewToggles noZoned{.zonedBuildings = false}; CHECK(!render::feature_shown(0x70, noZoned)); // a house hides CHECK(render::feature_shown(0xC6, noZoned)); // a power plant stays const render::ViewToggles noOther{.otherBuildings = false}; CHECK(render::feature_shown(0x70, noOther)); // the house stays CHECK(!render::feature_shown(0xC6, noOther)); // the plant hides if (failures == 0) { std::printf("layer_classify: all checks passed\n"); return 0; } std::printf("layer_classify: %d failure(s)\n", failures); return 1; }