Something went wrong. Try again.
[Mirror] Libreopolis is a cross-platform city simulation game fully compatible with SimCity 2000. gitlab.com/conasg/libreopolis
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530// Numeric verification of the demolition fixes (2026-06-27):// * PIERS (0xDF/0xE0) raze one linear crane-and-deck object without crossing into an adjacent finger.// * RUNWAYS (0xDD/0xDE) flood-raze their whole 4-connected family from any one tile.// * HIGHWAYS are NOT re-autotiled on bulldoze (the original's post-bulldoze sweep only touches road/// rail/power) — so a 2-wide span no longer flips a neighbour sideways.#include "sc2k/ui/tools.hpp"#include <cstdio>
using namespace sc2k;
#include "test_harness.hpp"
int main() { // ---- PIER: bulldoze one deck → its whole linear pier goes; an edge-adjacent parallel pier survives ---- { City c; c.set_funds(100000); const int pier[5][2] = {{40, 40}, {40, 41}, {40, 42}, {40, 43}, {40, 44}}; const int neighbour[5][2] = {{41, 40}, {41, 41}, {41, 42}, {41, 43}, {41, 44}}; for (int i = 0; i < 5; ++i) { for (const auto* t : {pier[i], neighbour[i]}) { c.xbit.at(t[0], t[1]) = 0x04 | 0x80; c.xter.at(t[0], t[1]) = 0x20; c.xbld.at(t[0], t[1]) = i == 0 ? 0xE0 : 0xDF; c.xzon.at(t[0], t[1]) = std::uint8_t(0x10 | 9); } }
const auto res = ui::apply_tool(c, ui::Tool::Bulldoze, 40, 41); // bulldoze a middle pier tile CHECK(res.ok); CHECK(c.funds() == 100000 - 1); // one bulldoze charge for the whole flood for (auto& t : pier) { CHECK(c.xbld.at(t[0], t[1]) == 0); // every connected pier razed to bare CHECK(c.xbit.at(t[0], t[1]) & 0x04); // water bit KEPT (water shows through) CHECK((c.xbit.at(t[0], t[1]) & 0x80) == 0); // 0x80 masked off (XBIT &= 0x3D) CHECK((c.xzon.at(t[0], t[1]) & 0xF0) == 0); // corner bits dropped CHECK((c.xzon.at(t[0], t[1]) & 0x0F) == 9); // zone nibble kept (can re-develop) } for (auto& t : neighbour) CHECK(c.xbld.at(t[0], t[1]) == (t[1] == 40 ? 0xE0 : 0xDF)); }
// ---- RUNWAY: bulldoze one tile of a connected runway → the whole runway goes, leaving rubble ---- { City c; c.set_funds(100000); const int rw[3][2] = {{60, 60}, {60, 61}, {60, 62}}; for (auto& t : rw) { c.xbld.at(t[0], t[1]) = 0xDD; c.xzon.at(t[0], t[1]) = 8; } // airport zone nibble 8 const auto res = ui::apply_tool(c, ui::Tool::Bulldoze, 60, 61); CHECK(res.ok); for (auto& t : rw) { const int x = c.xbld.at(t[0], t[1]); CHECK(x >= 1 && x <= 4); } // all → Rubble 1..4 (on land) }
// ---- HIGHWAY is a 2×2-BLOCK structure: placement and deletion are block-atomic, never 1×1 ---- { // PLACEMENT: clicking an odd tile snaps to the even 2×2 block and lays all four tiles (E-W = 0x49). City c; c.set_funds(100000); CHECK(ui::apply_tool(c, ui::Tool::Highway, 21, 31, /*E-W*/ 0).ok); for (int r = 20; r <= 21; ++r) for (int col = 30; col <= 31; ++col) CHECK(c.xbld.at(r, col) == 0x49); CHECK(c.funds() == 100000 - 100); // one $100 block, not per-tile // N-S orientation (arg 1) lays Top-Bottom (0x4A); a partly-sloped block is refused. CHECK(ui::apply_tool(c, ui::Tool::Highway, 40, 40, /*N-S*/ 1).ok); for (int r = 40; r <= 41; ++r) for (int col = 40; col <= 41; ++col) CHECK(c.xbld.at(r, col) == 0x4A); c.xbld.at(50, 51) = 0x90; // a building inside the would-be block CHECK(!ui::apply_tool(c, ui::Tool::Highway, 50, 50).ok); // can't build a highway over a building // (slopes ARE buildable now — they become elevated ramps; see test_highway slope checks) } { // DELETION: bulldozing ONE tile of an on-land 2-wide highway razes its whole 2×2 block (never 1 tile), // and leaves highway in OTHER blocks untouched (no sideways flip — recompute_highway is gone). City c; c.set_funds(100000); for (int r = 4; r <= 11; ++r) for (int col = 10; col <= 11; ++col) { c.xbld.at(r, col) = 0x4A; c.xzon.at(r, col) = 0xF0; } CHECK(ui::apply_tool(c, ui::Tool::Bulldoze, 7, 10).ok); for (int r = 6; r <= 7; ++r) for (int col = 10; col <= 11; ++col) CHECK(c.xbld.at(r, col) >= 1 && c.xbld.at(r, col) <= 4); // whole block gone → rubble (flat land) CHECK(c.xbld.at(4, 10) == 0x4A && c.xbld.at(5, 11) == 0x4A); // block rows 4-5 untouched CHECK(c.xbld.at(8, 10) == 0x4A && c.xbld.at(9, 11) == 0x4A); // block rows 8-9 untouched CHECK(c.xbld.at(10, 10) == 0x4A && c.xbld.at(11, 11) == 0x4A); // block rows 10-11 untouched } { // DELETION re-autotiles survivors: deleting an arm off a junction reverts it (user: removing a highway // from a cloverleaf should turn it back into normal highway there). Build a W+E+S tee (centre 0x69), // bulldoze the south arm → the centre settles back to a plain E-W straight. City c; c.set_funds(100000); CHECK(ui::apply_tool(c, ui::Tool::Highway, 50, 50, /*E-W*/ 0).ok); // centre CHECK(ui::apply_tool(c, ui::Tool::Highway, 50, 48, /*E-W*/ 0).ok); // W CHECK(ui::apply_tool(c, ui::Tool::Highway, 50, 52, /*E-W*/ 0).ok); // E CHECK(ui::apply_tool(c, ui::Tool::Highway, 52, 50, /*N-S*/ 1).ok); // S → centre = W+E+S junction CHECK(c.xbld.at(50, 50) == 0x69); // a cloverleaf/junction CHECK(ui::apply_tool(c, ui::Tool::Bulldoze, 52, 50).ok); // delete the south arm CHECK(c.xbld.at(52, 50) >= 1 && c.xbld.at(52, 50) <= 4); // arm's whole block gone → rubble CHECK(c.xbld.at(53, 51) >= 1 && c.xbld.at(53, 51) <= 4); CHECK(c.xbld.at(50, 50) == 0x49); // centre reverted to a plain E-W straight }
// ---- HIGHWAY BRIDGE: bulldozing one over-water tile razes the whole over-water span (block flood); land kept ---- { City c; c.set_funds(100000); // A 2-wide E-W highway (rows 40,41; cols 30..37), block-aligned to even coords like the original lays it. // The middle 2×2 blocks (cols 32-33, 34-35) cross water (XBIT 0x04); the end blocks (30-31, 36-37) are land. for (int r = 40; r <= 41; ++r) for (int col = 30; col <= 37; ++col) { c.xbld.at(r, col) = 0x49; c.xzon.at(r, col) = 0xF0; if (col >= 32 && col <= 35) { c.xbit.at(r, col) = 0x04; c.xter.at(r, col) = 0x20; } // over water } CHECK(ui::apply_tool(c, ui::Tool::Bulldoze, 40, 33).ok); // bulldoze a mid-water highway tile for (int r = 40; r <= 41; ++r) for (int col = 32; col <= 35; ++col) { // whole over-water span gone CHECK(c.xbld.at(r, col) == 0); CHECK(c.xbit.at(r, col) & 0x04); // back to water CHECK((c.xzon.at(r, col) & 0xF0) == 0); // 2-wide corner bits dropped } for (int r = 40; r <= 41; ++r) { CHECK(c.xbld.at(r, 30) == 0x49); CHECK(c.xbld.at(r, 37) == 0x49); } // land approaches survive }
// ---- A plain ROAD still re-autotiles on bulldoze (faithful — the sweep DOES re-tile road/rail/power) ---- { City c; c.set_funds(100000); // A T-junction: a N-S road with an east stub at the centre → centre is a tee; remove the stub → straight. ui::detail::place_road(c, 20, 20); ui::detail::place_road(c, 21, 20); ui::detail::place_road(c, 22, 20); ui::detail::place_road(c, 21, 21); // the east stub makes (21,20) a tee CHECK(c.xbld.at(21, 20) != 0x1e && c.xbld.at(21, 20) != 0x1d); // a tee/junction, not a plain straight CHECK(ui::apply_tool(c, ui::Tool::Bulldoze, 21, 21).ok); // remove the stub CHECK(c.xbld.at(21, 20) == 0x1e); // (21,20) reverts to a N-S straight (0x1e) }
// ---- ROAD / RAIL / POWER bulldozed on FLAT ground leave RUBBLE (1-4), not bare — faithful to the // the original's raze loop (XTER==0 → rubble); on a SLOPE they clear to bare. (User-requested fix.) ---- { City c; c.set_funds(100000); ui::detail::place_road(c, 30, 30); // a lone flat road CHECK(ui::apply_tool(c, ui::Tool::Bulldoze, 30, 30).ok); CHECK(c.xbld.at(30, 30) >= 1 && c.xbld.at(30, 30) <= 4); // → rubble c.xbld.at(32, 32) = 0x2C; // a rail tile CHECK(ui::apply_tool(c, ui::Tool::Bulldoze, 32, 32).ok); CHECK(c.xbld.at(32, 32) >= 1 && c.xbld.at(32, 32) <= 4); // → rubble ui::detail::place_power_line(c, 34, 34); // a power line CHECK(ui::apply_tool(c, ui::Tool::Bulldoze, 34, 34).ok); CHECK(c.xbld.at(34, 34) >= 1 && c.xbld.at(34, 34) <= 4); // → rubble // On a SLOPE the bulldozed road clears to bare (XTER!=0 → 0), then re-slopes — no floating rubble: City d; d.set_funds(100000); d.altm.at(40, 40) = 1; d.xter.at(40, 40) = 2; // a cardinal slope tile d.xbld.at(40, 40) = 0x1F; // a road-on-slope piece CHECK(ui::apply_tool(d, ui::Tool::Bulldoze, 40, 40).ok); CHECK(d.xbld.at(40, 40) == 0); // bare, not rubble (it's a slope) }
// ================= 2026-07-01: unified destruction (bulldoze == terrain edit == disaster) =================
// ---- Bulldozing a BUILDING FAITHFULLY LEAVES its auto-laid water pipe (XBIT 0x20) — the original's demolisher // masks &0x3D (keeps 0x20/0x10) and never clears the piped bit on a surface demolish, so the pipe stub // lingers in the x-ray view (an earlier removal deviation was reverted 2026-07-01 at the user's ask). { City c; c.set_funds(100000); c.xbld.at(40, 40) = 0x80; c.xbit.at(40, 40) = 0xE0; c.xund.at(40, 40) = 0; // developed 1×1 building CHECK(ui::apply_tool(c, ui::Tool::Bulldoze, 40, 40).ok); CHECK(c.xbld.at(40, 40) >= 1 && c.xbld.at(40, 40) <= 4); // razed to rubble… CHECK((c.xbit.at(40, 40) & 0x20) != 0); // …but the auto-pipe bit is KEPT (faithful) CHECK((c.xbit.at(40, 40) & 0x80) == 0); // conductive/powered still dropped (&0x3D) }
// ---- Issue 4: bulldozing a Subway Station clears its underground platform (XUND 0x23) too. { City c; c.set_funds(100000); c.xbld.at(50, 50) = 233; c.xund.at(50, 50) = 0x23; // surface station + underground platform CHECK(ui::apply_tool(c, ui::Tool::Bulldoze, 50, 50).ok); CHECK(c.xund.at(50, 50) == 0); // platform gone with the surface station }
// (Issue 1 — a terrain edit over a real bridge deck removing the WHOLE span — is in test_bridge.cpp, // which has the make_channel helper to build a spanned bridge deterministically.)
// ---- Issue 5: raising/lowering terrain over a PIPE or SUBWAY destroys it (XUND cleared, not pushed up/down). { City c; c.set_funds(100000); for (int r = 38; r <= 42; ++r) for (int col = 38; col <= 42; ++col) { c.altm.at(r, col) = 4; c.xter.at(r, col) = 0; } ui::detail::place_pipe(c, 40, 40); // a manual pipe ui::detail::place_subway(c, 40, 41); // a subway tile CHECK((c.xbit.at(40, 40) & 0x20) != 0 && sim::has_water_main(c, 40, 40)); CHECK(c.xund.at(40, 40) == 0); CHECK(c.xund.at(40, 41) != 0); sc2k::raise_terrain(c, 40, 40); // edit the terrain right there CHECK(c.xund.at(40, 40) == 0); // pipe destroyed… CHECK(!sim::has_water_main(c, 40, 40)); CHECK((c.xbit.at(40, 40) & 0x20) == 0); // …incl. its water-conductive bit CHECK(c.xund.at(40, 41) == 0); // subway in the affected ring destroyed too }
// ---- Issue 2: leveling an area DOWN into water clears rubble AND trees (nothing floats/stands in the sea). { City c; c.set_funds(100000); c.set_misc_be32(sc2k::misc::kWaterLevel, 5); // sea level 5 (MISC wWaterLevel) const int wl = std::clamp<int>(c.water_level(), 0, 31); CHECK(wl == 5); // A plateau two steps above sea level, carrying rubble and a tree. for (int r = 60; r <= 66; ++r) for (int col = 60; col <= 66; ++col) { c.altm.at(r, col) = std::uint16_t(wl + 2); c.xter.at(r, col) = 0; c.xbit.at(r, col) &= ~0x04; } c.xbld.at(62, 62) = 3; // rubble c.xbld.at(62, 63) = 8; // a tree (XBLD 6-12) for (int n = 0; n < 4; ++n) { sc2k::lower_terrain(c, 62, 62); sc2k::lower_terrain(c, 62, 63); } CHECK((c.xbit.at(62, 62) & 0x04) != 0); // the tile is now submerged… CHECK(c.xbld.at(62, 62) == 0); // …so its rubble is gone CHECK((c.xbit.at(62, 63) & 0x04) != 0); CHECK(c.xbld.at(62, 63) == 0); // …and the tree is gone }
// ---- Terrain edit that demolishes a building DESTROYS its underground too — incl. the AUTO-pipe stub // (XBIT 0x20, no XUND shape). User-reported (CapeQuest): "the pipes under the demolished buildings // persisted when I raised the terrain." (A plain BULLDOZE keeps the stub — faithful; the terrain path // clears it — the deviation the user asked for.) { City c; c.set_funds(1000000); for (int r = 38; r <= 42; ++r) for (int col = 38; col <= 42; ++col) { c.altm.at(r, col) = 4; c.xter.at(r, col) = 0; } c.xbld.at(40, 40) = 0x80; c.xbit.at(40, 40) = 0xE0; c.xund.at(40, 40) = 0; // building + auto-pipe, no XUND CHECK((c.xbit.at(40, 40) & 0x20) != 0); sc2k::raise_terrain(c, 40, 40); // terrain edit demolishes the building CHECK(c.xbld.at(40, 40) < 0x0D); // building razed CHECK((c.xbit.at(40, 40) & 0x20) == 0); // …and its auto-pipe stub destroyed }
// ---- A TERRAIN edit that razes a road must NOT re-autotile its neighbours (the bulldoze-TOOL sweep // the sweep is not part of the bare demolisher that terrain/disasters use). User-reported (CapeQuest): // raising terrain next to a bridge razed the approach road and reshaped the bridge's still-sloped ramp // road (0x1F slope-road → 0x1E flat straight) — "the ramp persists and the road flattens." The slope- // road must keep its piece; only a BULLDOZE reshapes neighbours. { City c; c.set_funds(1000000); for (int r = 45; r <= 56; ++r) for (int col = 45; col <= 55; ++col) { c.altm.at(r, col) = 6; c.xter.at(r, col) = 0; } c.xter.at(50, 50) = 1; c.xbld.at(50, 50) = 0x1F; // a slope-road (bridge-ramp piece) on a cardinal slope c.xbld.at(51, 50) = 0x1E; // an adjacent flat road (in the edit footprint) sc2k::raise_terrain(c, 52, 50); // razes (51,50); (50,50) is outside the demolish/reslope ring CHECK(c.xbld.at(51, 50) == 0); // the neighbouring road was razed by the edit CHECK(c.xbld.at(50, 50) == 0x1F && c.xter.at(50, 50) == 1); // …but the slope-road keeps its piece (not flattened) }
// ---- Bulldoze DRAG-LOCK classification (DEVIATION): a drag only rakes up tiles of the SAME kind as the // one it started on, and manually-plopped structures are CLICK-ONLY (never drag-swept). This tests the // classifier + the drag_demolishable predicate the app's apply_at uses to gate each dragged-over tile. { using ui::DemoClass; City c; c.set_funds(1000000); c.xbld.at(10, 10) = 0x1d; // a road c.xbld.at(10, 11) = 0x2c; // rail c.xbld.at(10, 12) = 0x0e; // power line c.xbld.at(10, 13) = 8; // trees c.xbld.at(10, 14) = 3; // rubble c.xbld.at(10, 15) = 0x49; // highway c.xbld.at(10, 16) = 0x5d; // on-ramp → Highway c.xbld.at(10, 17) = 0x52; // a bridge deck c.xbld.at(10, 18) = 0xD2; // police station (special, ≥198) c.xbld.at(10, 19) = 0xCB; // nuclear power plant (special) c.xbld.at(10, 20) = 0xE0; // a pier (special) // developed RCI keyed by zone nibble c.xbld.at(11, 10) = 130; c.xzon.at(11, 10) = 0x10 | 1; // residential building (nibble 1) c.xbld.at(11, 11) = 150; c.xzon.at(11, 11) = 0x10 | 3; // commercial (nibble 3) c.xbld.at(11, 12) = 190; c.xzon.at(11, 12) = 0x10 | 5; // industrial (nibble 5) c.xbld.at(11, 13) = 0x70; c.xzon.at(11, 13) = 0; // a subway/rail junction (0x70, nibble 0) → Rail c.xbld.at(11, 14) = 0; // bare → None
CHECK(ui::demolish_class(c, 10, 10) == DemoClass::Road); CHECK(ui::demolish_class(c, 10, 11) == DemoClass::Rail); CHECK(ui::demolish_class(c, 10, 12) == DemoClass::Power); CHECK(ui::demolish_class(c, 10, 13) == DemoClass::Trees); CHECK(ui::demolish_class(c, 10, 14) == DemoClass::Rubble); CHECK(ui::demolish_class(c, 10, 15) == DemoClass::Highway); CHECK(ui::demolish_class(c, 10, 16) == DemoClass::Highway); CHECK(ui::demolish_class(c, 10, 17) == DemoClass::Bridge); CHECK(ui::demolish_class(c, 10, 18) == DemoClass::Building); CHECK(ui::demolish_class(c, 10, 19) == DemoClass::Building); CHECK(ui::demolish_class(c, 10, 20) == DemoClass::Building); CHECK(ui::demolish_class(c, 11, 10) == DemoClass::Residential); CHECK(ui::demolish_class(c, 11, 11) == DemoClass::Commercial); CHECK(ui::demolish_class(c, 11, 12) == DemoClass::Industrial); CHECK(ui::demolish_class(c, 11, 13) == DemoClass::Rail); CHECK(ui::demolish_class(c, 11, 14) == DemoClass::None);
// Infrastructure/terrain/RCI kinds are drag-sweepable; empty tiles and click-only structures are not. CHECK(ui::drag_demolishable(DemoClass::Road)); CHECK(ui::drag_demolishable(DemoClass::Trees)); CHECK(ui::drag_demolishable(DemoClass::Highway)); CHECK(ui::drag_demolishable(DemoClass::Residential)); CHECK(!ui::drag_demolishable(DemoClass::Building)); // police/plant/port need an individual click CHECK(!ui::drag_demolishable(DemoClass::None)); // nothing to sweep on bare ground
// Crossings participate in BOTH their networks (demolish_matches), so a road-drag follows the road // through a rail/power crossing and deletes the on-ramp; a rail/power drag follows its own net. CHECK(ui::demolish_matches(c, 10, 10, DemoClass::Road)); // plain road under a road lock CHECK(ui::demolish_matches(c, 10, 16, DemoClass::Road)); // on-ramp matches a road drag CHECK(ui::demolish_matches(c, 10, 16, DemoClass::Highway)); // …and a highway drag CHECK(!ui::demolish_matches(c, 10, 11, DemoClass::Road)); // rail is NOT a road CHECK(!ui::demolish_matches(c, 10, 18, DemoClass::Road)); // the police station is spared by any drag CHECK(ui::demolish_class(c, 10, 17) == DemoClass::Bridge); // (bridge decks classify, but aren't road-matched) CHECK(!ui::demolish_matches(c, 10, 17, DemoClass::Road)); }
// ---- Surgical CROSSING removal: a road-drag through a crossing deletes ONLY the road, healing the // crossed network (DEVIATION — the original razes the whole crossing tile). Codes from the road/rail connectors. { using ui::DemoClass; City c; c.set_funds(1000000); // road×power 0x43 (road over N-S power). A ROAD lock removes the road → power line 0x0E/0x0F survives. c.xbld.at(30, 30) = 0x0f; c.xbld.at(31, 30) = 0x43; c.xbld.at(32, 30) = 0x0f; // power line with a road crossing c.xbit.at(31, 30) = 0x80; CHECK(ui::demolish_matches(c, 31, 30, DemoClass::Road)); CHECK(ui::demolish_matches(c, 31, 30, DemoClass::Power)); CHECK(ui::demolish_component(c, 31, 30, DemoClass::Road)); // remove the road, keep the power CHECK(ui::detail::is_power_line(c.xbld.at(31, 30))); // power line healed here CHECK(c.xbit.at(31, 30) & 0x80); // still conductive
// road×rail 0x45 (E-W road over N-S rail). A ROAD lock → rail 0x2C/0x2D survives; a RAIL lock → road survives. c.xbld.at(40, 40) = 0x45; CHECK(ui::demolish_component(c, 40, 40, DemoClass::Road)); // remove road → rail remains CHECK(ui::detail::is_rail(c.xbld.at(40, 40))); c.xbld.at(41, 41) = 0x45; CHECK(ui::demolish_component(c, 41, 41, DemoClass::Rail)); // remove rail → road remains CHECK(ui::detail::is_road(c.xbld.at(41, 41))); CHECK((c.xbit.at(41, 41) & 0x80) == 0); // a road doesn't conduct
// road under a highway 0x4B: a ROAD lock removes the buried road → plain highway 0x49 survives. c.xbld.at(50, 50) = 0x4b; CHECK(ui::demolish_component(c, 50, 50, DemoClass::Road)); CHECK(c.xbld.at(50, 50) == 0x49); // highway straight remains, road gone
// A plain road is NOT a crossing → demolish_component declines (caller does the normal whole-tile raze). c.xbld.at(60, 60) = 0x1d; CHECK(!ui::demolish_component(c, 60, 60, DemoClass::Road)); }
// ---- Neighbour-connection SIGNPOST (XTXT 0xFA) removal (user-reported "the sign is stuck after demolishing // the connection"). DEVIATION: the original bulldozer leaves XTXT, so the connection is permanent; here the // sign — and thus the connection (demand caps recompute from the 0xFA markers) — goes with the network. { City c; c.set_funds(100000); // (1) a ROAD connection edge tile: razing the road clears its 0xFA marker. c.xbld.at(0, 40) = 0x1d; c.xtxt.at(0, 40) = 0xFA; CHECK(sim::demolish_at(c, 0, 40, true) == 1); CHECK(c.xtxt.at(0, 40) == 0); // sign gone with the road // (2) an ORPHANED sign on bare ground (its road was already removed): the Bulldoze TOOL clears it. c.xbld.at(0, 41) = 0; c.xtxt.at(0, 41) = 0xFA; CHECK(ui::apply_tool(c, ui::Tool::Bulldoze, 0, 41).ok); CHECK(c.xtxt.at(0, 41) == 0); // (3) bare ground with no sign is still "nothing to bulldoze" (unchanged). CHECK(!ui::apply_tool(c, ui::Tool::Bulldoze, 0, 42).ok); // (4) a USER sign (1-50) on a razed road tile is NOT collateral-cleared — only 0xFA connection markers are. c.xbld.at(70, 70) = 0x1d; c.xtxt.at(70, 70) = 7; CHECK(sim::demolish_at(c, 70, 70, true) == 1); CHECK(c.xtxt.at(70, 70) == 7); // placed sign survives the road raze }
// ---- FLUSH multi-tile buildings: razing one tower of a packed arco farm must stay inside its own // XZON-corner-bit footprint. The old same-code flood wandered across the seam between two identical // buildings placed flush (repro: two 4×4 Launch Arcos, cols 40-43 / 44-47 — demolishing at (40,40) // razed (40,44) in the NEIGHBOUR and left (42,40) of the clicked tower standing). ---- { City c; c.set_funds(1000000); // Two 4×4 Launch Arcologies (0xFE) side by side, corner bits as real saves carry them // (TL 0x10 / BL 0x20 / BR 0x40 / TR 0x80 at rotation 0). auto stamp_arco = [&](int r0, int c0) { for (int dr = 0; dr < 4; ++dr) for (int dc = 0; dc < 4; ++dc) { c.xbld.at(r0 + dr, c0 + dc) = 0xFE; c.xbit.at(r0 + dr, c0 + dc) = 0xE0; } c.xzon.at(r0, c0) |= 0x10; c.xzon.at(r0 + 3, c0) |= 0x20; c.xzon.at(r0 + 3, c0 + 3) |= 0x40; c.xzon.at(r0, c0 + 3) |= 0x80; }; stamp_arco(40, 40); stamp_arco(40, 44); CHECK(sim::demolish_at(c, 40, 40, true) == 1); // bulldoze the WEST tower (its TL corner tile) for (int r = 40; r <= 43; ++r) for (int col = 40; col <= 43; ++col) CHECK(c.xbld.at(r, col) >= 1 && c.xbld.at(r, col) <= 4); // the whole clicked tower → rubble for (int r = 40; r <= 43; ++r) for (int col = 44; col <= 47; ++col) CHECK(c.xbld.at(r, col) == 0xFE); // the flush neighbour untouched // …and clicking a NON-corner interior tile of the survivor razes it, not a rect snapped elsewhere. CHECK(sim::demolish_at(c, 42, 46, true) == 1); for (int r = 40; r <= 43; ++r) for (int col = 44; col <= 47; ++col) CHECK(c.xbld.at(r, col) >= 1 && c.xbld.at(r, col) <= 4); }
// ---- UNDERGROUND bulldozer: only what the x-ray shows is demolishable; the surface is never touched ---- { City c; c.set_funds(100000); c.xbld.at(60, 60) = 0x90; // a surface building over a subway c.xund.at(60, 60) = 1; // Surface protection: bulldozing underground on a built-over subway removes the SUBWAY, not the building. CHECK(ui::bulldoze_underground(c, 60, 60, true, true, true).ok); CHECK(c.xund.at(60, 60) == 0); CHECK(c.xbld.at(60, 60) == 0x90); // the building above is untouched // Hidden layers can't be hit: a pipe with Water pipes off, a subway with Subways off. sim::set_water_main(c, 61, 61, true); CHECK(!ui::bulldoze_underground(c, 61, 61, true, false, true).ok); CHECK(sim::has_water_main(c, 61, 61)); c.xund.at(62, 62) = 2; CHECK(!ui::bulldoze_underground(c, 62, 62, false, true, true).ok); CHECK(c.xund.at(62, 62) == 2); // Pipe removal clears the water-network bits. CHECK(ui::bulldoze_underground(c, 61, 61, true, true, true).ok); CHECK(!sim::has_water_main(c, 61, 61)); CHECK((c.xbit.at(61, 61) & 0x30) == 0); // Removing the centre severs only that main. Shape is derived; no pipe codes leak into XUND. for (int col = 58; col <= 62; ++col) sim::set_water_main(c, 56, col, true); CHECK(ui::bulldoze_underground(c, 56, 60, false, true, false).ok); CHECK(!sim::has_water_main(c, 56, 60)); CHECK(sim::has_water_main(c, 56, 59) && sim::has_water_main(c, 56, 61)); CHECK(c.xund.at(56, 59) == 0 && c.xund.at(56, 61) == 0); // Co-located subway + main: subways-only removes the subway and leaves the main… c.xund.at(64, 64) = 1; sim::set_water_main(c, 64, 64, true); CHECK(ui::bulldoze_underground(c, 64, 64, true, false, true).ok); CHECK(c.xund.at(64, 64) == 0); CHECK(sim::has_water_main(c, 64, 64)); // …pipes-only removes the pipe and leaves the subway straight… c.xund.at(65, 65) = 2; sim::set_water_main(c, 65, 65, true); CHECK(ui::bulldoze_underground(c, 65, 65, false, true, true).ok); CHECK(c.xund.at(65, 65) == 2); CHECK(!sim::has_water_main(c, 65, 65)); // …and both shown clears the whole tile. c.xund.at(66, 66) = 1; sim::set_water_main(c, 66, 66, true); CHECK(ui::bulldoze_underground(c, 66, 66, true, true, true).ok); CHECK(c.xund.at(66, 66) == 0); CHECK(!sim::has_water_main(c, 66, 66)); // Station undergrounds are tied to their visible surface structure and raze together from below. c.xbld.at(67, 67) = xbld::kSubwayStation; c.xzon.at(67, 67) = 0xF0; c.xund.at(67, 67) = 35; CHECK(!ui::bulldoze_underground(c, 67, 67, true, true, true).ok); CHECK(c.xbld.at(67, 67) == xbld::kSubwayStation && c.xund.at(67, 67) == 35); CHECK(ui::bulldoze_underground(c, 67, 67, true, true, true, true).ok); CHECK(c.xbld.at(67, 67) >= 1 && c.xbld.at(67, 67) <= 4); CHECK(c.xund.at(67, 67) == 0); // Water sources exposed on pipe foundations follow the same exact-object rule. c.xbld.at(68, 68) = xbld::kWaterPump; c.xzon.at(68, 68) = 0xF0; sim::set_water_main(c, 68, 68, true); CHECK(ui::bulldoze_underground(c, 68, 68, true, true, true, true).ok); CHECK(c.xbld.at(68, 68) >= 1 && c.xbld.at(68, 68) <= 4); // Bare tile: nothing to bulldoze, nothing charged. const auto funds0 = c.funds(); CHECK(!ui::bulldoze_underground(c, 70, 70, true, true, true).ok); CHECK(c.funds() == funds0); }
if (failures == 0) std::printf("test_demolish: all checks passed\n"); else std::printf("test_demolish: %d FAILED\n", failures); return failures ? 1 : 0;}