// Regression: every building placed through construct_building must CONDUCT and // REQUIRE power — i.e. carry XBIT 0x80 (conductive) across its footprint, exactly like the RCI // growth stamp. This covers the special-zone structures (airport/seaport) and every civic // Building-tool plop (police, fire, schools, hospitals, parks, stadium, water pump, …). The bug: // the port's construct_building wrote XBLD/XZON but omitted the conductive/powered stamp // stamp, so the power flood (gated on 0x80) skipped them — "ports/airports don't transmit power". #include "sc2k/sim/growth.hpp" #include "sc2k/sim/power.hpp" #include #include "test_harness.hpp" using namespace sc2k; int main() { // --- 1. construct_building stamps the conductive|powered bits over the whole footprint --- { City c; c.modernWaterSystem = true; // a 2×2 special/civic structure (e.g. an airport terminal, code 240) on default flat dry land CHECK(construct_building(c, 10, 10, 240, 2, /*rot*/ 0)); for (int r = 10; r <= 11; ++r) for (int cc = 10; cc <= 11; ++cc) { const std::uint8_t b = c.xbit.cells[r * 128 + cc]; CHECK((b & 0x80) != 0); // conductive — power floods through it CHECK((b & 0x40) != 0); // optimistic powered bit CHECK((b & 0x20) == 0); // buildings no longer create hidden water capillaries } } // --- 2. a 1×1 civic building (code 225) likewise conducts --- { City c; c.modernWaterSystem = true; CHECK(construct_building(c, 5, 5, 225, 1, 0)); CHECK((c.xbit.cells[5 * 128 + 5] & 0x80) != 0); } // --- 3. the two non-conductive exceptions receive no native utility-main bits --- { City c; c.modernWaterSystem = true; CHECK(construct_building(c, 7, 7, 213, 1, 0)); CHECK((c.xbit.cells[7 * 128 + 7] & 0x80) == 0); // not conductive CHECK((c.xbit.cells[7 * 128 + 7] & 0x20) == 0); } // --- 4. low XBIT bits (water-adjacency 0x04) survive the stamp --- { City c; c.modernWaterSystem = true; c.xbit.cells[3 * 128 + 3] |= 0x01; // a low-bit flag set before construction CHECK(construct_building(c, 3, 3, 226, 1, 0)); CHECK((c.xbit.cells[3 * 128 + 3] & 0x01) != 0); // preserved (the original masks with 0x1F) CHECK((c.xbit.cells[3 * 128 + 3] & 0x80) != 0); // and now conductive } // --- 5. end-to-end: a plant feeds power THROUGH a civic building's tiles --- { City c; c.modernWaterSystem = true; // a coal plant tile at (20,20) (XBLD 0xCA supplies 48 MW), seed conductive c.xbld.cells[20 * 128 + 20] = 0xCA; c.xbit.cells[20 * 128 + 20] |= 0x80; // a power line linking the plant to the building tile at (20,22) c.xbld.cells[20 * 128 + 21] = 221; // a power-line code (>= 0x70 → counts demand too) c.xbit.cells[20 * 128 + 21] |= 0x80; // a civic building plopped at (20,22), orthogonally adjacent to the line CHECK(construct_building(c, 20, 22, 225, 1, 0)); update_power(c); // clears + recomputes 0x40 from the plant CHECK((c.xbit.cells[20 * 128 + 22] & 0x40) != 0); // the building is now POWERED // sanity: a disconnected building far away stays unpowered (conductive but no plant) CHECK(construct_building(c, 60, 60, 225, 1, 0)); update_power(c); CHECK((c.xbit.cells[60 * 128 + 60] & 0x80) != 0); // conductive… CHECK((c.xbit.cells[60 * 128 + 60] & 0x40) == 0); // …but not powered (isolated) } if (failures == 0) { std::printf("power_conduct: all checks passed\n"); return 0; } std::printf("power_conduct: %d failure(s)\n", failures); return 1; }