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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364// Numeric verification of the Landscape + transit-connector tools wired this session: Raise / Lower /// Level terrain (sim/terrain_edit.hpp, the verified slope autotiler) and Onramp / Sub-to-Rail /// Tunnel (ui/tools.hpp, ports of the original tools). Synthetic cities — no game assets (the English// string catalog is repo-owned and loads so the tunnel-message keys resolve to the original's text).#include "sc2k/i18n.hpp"#include "sc2k/render/asset_loader.hpp"#include "sc2k/ui/tools.hpp"#include <cstdio>
using namespace sc2k;
#include "test_harness.hpp"
// Fill a patch to a uniform altitude so the autotiler has a clean baseline (water level defaults to 0).static void flatten(City& c, int alt) { for (int r = 0; r < City::kDim; ++r) for (int col = 0; col < City::kDim; ++col) c.altm.at(r, col) = std::uint16_t(alt);}
int main() { i18n::load_locale(render::assets_dir() + "/lang", "en"); // tunnel messages are catalog keys
// ---- Raise terrain: a tile goes up one step; its lower neighbours acquire a slope code ---- { City c; c.set_funds(1000); flatten(c, 5); auto r = ui::apply_tool(c, ui::Tool::RaiseTerrain, 40, 40); CHECK(r.ok); CHECK((c.altm.at(40, 40) & 0x1F) == 6); // raised by one CHECK(c.funds() == 975); // $25 (cost-table group 0) int sloped = 0; for (auto [dr, dc] : {std::pair{-1, 0}, {1, 0}, {0, -1}, {0, 1}}) if (c.xter.at(40 + dr, 40 + dc) != 0) ++sloped; CHECK(sloped == 4); // all four cardinal neighbours now slope toward it } // ---- Lower terrain: a tile goes down one step ---- { City c; c.set_funds(1000); flatten(c, 5); auto r = ui::apply_tool(c, ui::Tool::LowerTerrain, 40, 40); CHECK(r.ok); CHECK((c.altm.at(40, 40) & 0x1F) == 4); // lowered by one // A tile already at sea-floor (alt 0) can't be lowered. City c2; c2.set_funds(1000); flatten(c2, 0); CHECK(!ui::apply_tool(c2, ui::Tool::LowerTerrain, 40, 40).ok); } // ---- Level terrain: steps one toward the reference altitude, stops when equal ---- { City c; c.set_funds(1000); flatten(c, 5); c.altm.at(40, 40) = 8; // a peak amid the altitude-5 plain auto r = ui::apply_tool(c, ui::Tool::LevelTerrain, 40, 40, /*target=*/5); CHECK(r.ok); CHECK((c.altm.at(40, 40) & 0x1F) == 7); // one step down toward 5 // Already level → no-op (target == current). CHECK(!ui::apply_tool(c, ui::Tool::LevelTerrain, 41, 41, /*target=*/5).ok); // Without a reference altitude (arg < 0) the tool declines. CHECK(!ui::apply_tool(c, ui::Tool::LevelTerrain, 40, 40).ok); } // ---- Terrain editing DEMOLISHES occupied tiles (faithful to the slope autotiler) ---- { City c; c.set_funds(1000); flatten(c, 5); c.xbld.at(40, 40) = 0x80; // a building on the tile we raise const auto r = ui::apply_tool(c, ui::Tool::RaiseTerrain, 40, 40); CHECK(r.ok); // the raise SUCCEEDS now (was blocked before), CHECK(c.funds() == 975); // charging the normal $25, CHECK(c.xbld.at(40, 40) < 0x70); // and razing the building (it's gone), CHECK((c.altm.at(40, 40) & 0x1F) == 6); // the tile rose one step.
// A 2×2 building with only ONE tile inside the edited 3×3 box: the WHOLE building is demolished and // its tiles outside the box are left as rubble (debris) — the user-described "remaining tiles" case. City c2; c2.set_funds(1000); flatten(c2, 5); for (int dr = 0; dr < 2; ++dr) for (int dc = 0; dc < 2; ++dc) c2.xbld.at(51 + dr, 51 + dc) = 0x90; ui::apply_tool(c2, ui::Tool::RaiseTerrain, 50, 50); // raise (50,50): only (51,51) falls in the box int standing = 0, rubble = 0; for (int dr = 0; dr < 2; ++dr) for (int dc = 0; dc < 2; ++dc) { const int v = c2.xbld.at(51 + dr, 51 + dc); standing += (v == 0x90); // no original building tile still stands, rubble += (v >= 1 && v <= 4); // and the out-of-box tiles are debris. } CHECK(standing == 0); CHECK(rubble == 3); // (51,51) cleared to terrain, the other 3 → rubble
// Trees SURVIVE a terrain edit — they render on slopes, so an edit doesn't flatten a forest (only // structures are razed). The tree stays put on the now-raised tile. City c3; c3.set_funds(1000); flatten(c3, 5); c3.xbld.at(60, 60) = 8; // a mature tree (XBLD 6-12) CHECK(ui::apply_tool(c3, ui::Tool::RaiseTerrain, 60, 60).ok); CHECK(c3.xbld.at(60, 60) == 8); // untouched, CHECK((c3.altm.at(60, 60) & 0x1F) == 6); // on the raised tile }
// ---- Onramp: bridges an adjacent highway to an adjacent road ---- { City c; c.set_funds(1000); flatten(c, 0); c.xbld.at(39, 40) = 0x4A; // highway to the North c.xbld.at(40, 41) = 0x1D; // road to the East auto r = ui::apply_tool(c, ui::Tool::Onramp, 40, 40); CHECK(r.ok); CHECK(c.xbld.at(40, 40) == 0x5D); // East-road, hwy-North → on-ramp 0x5D CHECK(c.xbld.at(40, 41) == 0x2B); // road connector LEFT as the raw 0x2B (the original doesn't re-autotile it) CHECK(c.xbit.at(40, 40) & 0x02); // East case sets the mirror bit CHECK(c.funds() == 975); // $25 // No adjacent highway+road → reject. City c2; c2.set_funds(1000); flatten(c2, 0); CHECK(!ui::apply_tool(c2, ui::Tool::Onramp, 40, 40).ok); }
// ---- Sub-to-Rail: faces adjacent surface rail, writes XUND 0x23 ---- { City c; c.set_funds(1000); flatten(c, 0); c.xbld.at(41, 40) = 0x2C; // rail to the South (dir index 0) auto r = ui::apply_tool(c, ui::Tool::SubRail, 40, 40); CHECK(r.ok); CHECK(c.xbld.at(40, 40) == 0x6C); // dir 0 → 0x6C (Sub-Rail Top) CHECK(c.xund.at(40, 40) == 0x23); // 35, the sub-rail underground code CHECK(c.funds() == 750); // $250 (cost-table group 7) // Also reaches an adjacent subway (opposite side) when no surface rail is present. City c2; c2.set_funds(1000); flatten(c2, 0); c2.xund.at(40, 41) = 1; // a subway tile to the East (dir index 1) auto r2 = ui::apply_tool(c2, ui::Tool::SubRail, 40, 40); CHECK(r2.ok); CHECK(c2.xbld.at(40, 40) >= 0x6C && c2.xbld.at(40, 40) <= 0x6F); // No rail/subway anywhere → reject. City c3; c3.set_funds(1000); flatten(c3, 0); CHECK(!ui::apply_tool(c3, ui::Tool::SubRail, 40, 40).ok); }
// ---- Tunnel: bores from a slope through a hill and emerges at the opposite slope ---- // Build the canonical West-bore hill at (r,c): entrance slope 2 (dir West), two raised interior tiles, exit // slope 4 where the ground drops back to the entrance altitude. Caller can then perturb one tile per case. auto west_hill = [](City& c, int r, int col) { c.xter.at(r, col) = 2; c.altm.at(r, col) = 5; // entrance c.altm.at(r, col - 1) = 6; // interior (higher) c.altm.at(r, col - 2) = 6; // interior (higher) c.xter.at(r, col - 3) = 4; c.altm.at(r, col - 3) = 5; // exit (matching opposite slope) }; { City c; c.set_funds(5000); flatten(c, 5); west_hill(c, 40, 40); auto r = ui::apply_tool(c, ui::Tool::Tunnel, 40, 40); CHECK(r.ok); CHECK(c.xbld.at(40, 40) == 0x40); // entrance mouth (slope 2 + 62) CHECK(c.xbld.at(40, 37) == 0x42); // exit mouth (((2+1)&3) + 63) CHECK((c.altm.at(40, 40) & 0x400) != 0); // entrance carries the tunnel flag CHECK((c.altm.at(40, 39) & 0x7C00) != 0); // interior carries the passage depth CHECK(r.spent == 600); // (span 3 + 1) · $150 CHECK(c.funds() == 4400); } // ---- Tunnel probe: each failure mode returns the original's status + message (ids 0x6F-0x74). // The probe hands back catalog KEYS; resolved through the English catalog they must read // exactly as the original's strings. ---- { using ui::detail::tunnel_probe; using ui::detail::TunnelStatus; using ui::detail::tunnel_status_msg; auto msg = [](TunnelStatus s) { return i18n::tr(tunnel_status_msg(s)); }; // NotSlope — flat ground isn't a hillside (0x74). { City c; flatten(c, 5); CHECK(tunnel_probe(c, 40, 40, 150).status == TunnelStatus::NotSlope); CHECK(msg(TunnelStatus::NotSlope) == "Tunnel must start on hillside"); } // Silent — an occupied / radioactive / already-underground entrance fails with NO message (goto LABEL_2). { City c; flatten(c, 5); west_hill(c, 40, 40); c.xbld.at(40, 40) = 0x1D; // a road on the slope CHECK(tunnel_probe(c, 40, 40, 150).status == TunnelStatus::Silent); CHECK(msg(TunnelStatus::Silent).empty()); } // CrossTunnel — the bore line meets an existing tunnel (ALTM bit 10) at an interior tile (0x6F). { City c; flatten(c, 5); west_hill(c, 40, 40); c.altm.at(40, 39) = std::uint16_t(6 | 0x400); CHECK(tunnel_probe(c, 40, 40, 150).status == TunnelStatus::CrossTunnel); CHECK(msg(TunnelStatus::CrossTunnel) == "We Cannot Cross Tunnels"); } // TooDeep — an interior tile rises >30 levels above the entrance (0x71). { City c; flatten(c, 0); west_hill(c, 40, 40); c.altm.at(40, 40) = 0; c.altm.at(40, 39) = 31; CHECK(tunnel_probe(c, 40, 40, 150).status == TunnelStatus::TooDeep); CHECK(msg(TunnelStatus::TooDeep) == "Tunnel is too Deep to Build"); } // Blocked — a subway/sewer fouls a shallow (h==1) tile along the bore (0x73). { City c; flatten(c, 5); west_hill(c, 40, 40); c.xund.at(40, 39) = 1; // a subway 1 level up CHECK(tunnel_probe(c, 40, 40, 150).status == TunnelStatus::Blocked); CHECK(msg(TunnelStatus::Blocked) == "Subway or Sewer Block Construction"); } // BadExit — the far side surfaces but isn't the matching opposite slope (0x72). { City c; flatten(c, 5); west_hill(c, 40, 40); c.xter.at(40, 37) = 0; // exit is flat, not slope 4 CHECK(tunnel_probe(c, 40, 40, 150).status == TunnelStatus::BadExit); CHECK(msg(TunnelStatus::BadExit) == "Unstable Terrain at Exit Point"); } // CityLimits — an EAST-bore hill (entrance slope 4) runs to the map edge without surfacing (0x70). { City c; flatten(c, 5); c.xter.at(40, 124) = 4; c.altm.at(40, 124) = 5; c.altm.at(40, 125) = 6; c.altm.at(40, 126) = 6; c.altm.at(40, 127) = 6; // still rising at col 127 CHECK(tunnel_probe(c, 40, 124, 150).status == TunnelStatus::CityLimits); CHECK(msg(TunnelStatus::CityLimits) == "Tunnel Exceeds City Limits"); } } // ---- Tunnel lay: abutting roads re-autotile to JOIN the mouth (the road autotiler on the 4 neighbours) ---- { City c; c.set_funds(5000); flatten(c, 5); west_hill(c, 40, 40); ui::detail::place_road(c, 39, 41); // a N-S road pair east of the entrance ui::detail::place_road(c, 40, 41); CHECK(c.xbld.at(40, 41) == 0x1E); // before: a straight (only its N road neighbour) CHECK(ui::apply_tool(c, ui::Tool::Tunnel, 40, 40).ok); CHECK(c.xbld.at(40, 41) == 0x26); // after: a CORNER bending toward the mouth to its west } // ---- Tunnel cost: confirmed but unaffordable → "Costs Exceed Operating Funds" (0x102), nothing built ---- { City c; c.set_funds(100); flatten(c, 5); west_hill(c, 40, 40); auto r = ui::apply_tool(c, ui::Tool::Tunnel, 40, 40); // cost $600 > $100 CHECK(!r.ok); CHECK(i18n::tr(r.msg) == "Costs Exceed Operating Funds"); CHECK(c.xbld.at(40, 40) == 0); // no mouth laid (the slope lives in XTER, still 2) CHECK(c.xter.at(40, 40) == 2); CHECK(c.funds() == 100); // untouched } // ---- Tunnel removal: bulldozing EITHER mouth razes the WHOLE tunnel — both ends + the buried passage // (the demolisher's tunnel branch). The far mouth must not be left orphaned (user-reported intuition). ---- auto tunnel_intact = [](City& c) { // both mouths laid + passage depth set return c.xbld.at(40, 40) == 0x40 && c.xbld.at(40, 37) == 0x42 && (c.altm.at(40, 39) & 0x7C00) != 0 && (c.altm.at(40, 38) & 0x7C00) != 0; }; auto tunnel_gone = [](City& c) { // both mouths gone + ALL depth bits cleared for (int cc = 37; cc <= 40; ++cc) if (c.altm.at(40, cc) & 0x7C00) return false; return c.xbld.at(40, 40) == 0 && c.xbld.at(40, 37) == 0; }; { // bulldoze the ENTRANCE mouth → whole tunnel removed City c; c.set_funds(5000); flatten(c, 5); west_hill(c, 40, 40); CHECK(ui::apply_tool(c, ui::Tool::Tunnel, 40, 40).ok); CHECK(tunnel_intact(c)); auto r = ui::apply_tool(c, ui::Tool::Bulldoze, 40, 40); // click the entrance CHECK(r.ok); CHECK(std::string(r.msg) == "tunnel removed"); CHECK(tunnel_gone(c)); } { // bulldoze the EXIT mouth → walks the bore back to the entrance, same result City c; c.set_funds(5000); flatten(c, 5); west_hill(c, 40, 40); CHECK(ui::apply_tool(c, ui::Tool::Tunnel, 40, 40).ok); CHECK(tunnel_intact(c)); auto r = ui::apply_tool(c, ui::Tool::Bulldoze, 40, 37); // click the FAR (exit) mouth CHECK(r.ok); CHECK(std::string(r.msg) == "tunnel removed"); CHECK(tunnel_gone(c)); } { // a road that joined the mouth drops its connection once the tunnel is gone City c; c.set_funds(5000); flatten(c, 5); west_hill(c, 40, 40); ui::detail::place_road(c, 39, 41); ui::detail::place_road(c, 40, 41); CHECK(ui::apply_tool(c, ui::Tool::Tunnel, 40, 40).ok); CHECK(c.xbld.at(40, 41) == 0x26); // corner bending toward the mouth CHECK(ui::apply_tool(c, ui::Tool::Bulldoze, 40, 40).ok); CHECK(c.xbld.at(40, 41) == 0x1E); // back to a plain N-S straight (only its N neighbour) }
// ---- Native water mains and subways have independent ownership layers. Pipe art is derived from // waterMains adjacency, while XUND remains available for subway geometry on the same tile. ---- { City c; c.set_funds(100000); flatten(c, 5); // A 4-way pipe cross at (40,40): all four arms → center mask 1111 → shape 14, +16 = 30. for (auto [r, cc] : {std::pair{40, 40}, {39, 40}, {41, 40}, {40, 39}, {40, 41}}) CHECK(ui::apply_tool(c, ui::Tool::Pipe, r, cc).ok); for (auto [r, cc] : {std::pair{40, 40}, {39, 40}, {41, 40}, {40, 39}, {40, 41}}) { CHECK(c.xund.at(r, cc) == 0); // XUND remains subway-only CHECK(sim::has_water_main(c, r, cc)); CHECK((c.xbit.at(r, cc) & 0x20) != 0); // joined the water network } CHECK(sim::water_main_presentation_code(c, 40, 40) == 30); // derived 4-way cross shape
// A subway tile lands in 1-15 and is not automatically on the water network. City s; s.set_funds(100000); flatten(s, 5); CHECK(ui::apply_tool(s, ui::Tool::Subway, 50, 50).ok); CHECK(s.xund.at(50, 50) >= 1 && s.xund.at(50, 50) <= 15); CHECK((s.xbit.at(50, 50) & 0x20) == 0);
// Pipe and subway side by side stay disjoint: each autotiles as if the other were not there. City m; m.set_funds(100000); flatten(m, 5); CHECK(ui::apply_tool(m, ui::Tool::Pipe, 40, 40).ok); // pipe … CHECK(ui::apply_tool(m, ui::Tool::Subway, 40, 41).ok); // … with a subway immediately East CHECK(m.xund.at(40, 40) == 0); // pipe does not consume the subway layer CHECK(sim::has_water_main(m, 40, 40)); CHECK(m.xund.at(40, 41) >= 1 && m.xund.at(40, 41) <= 15); // isolated subway — ignores the pipe to its W }
if (failures == 0) std::printf("terrain+transit tools: all checks passed\n"); else std::printf("terrain+transit tools: %d FAILED\n", failures); return failures ? 1 : 0;}