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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213// Over-water HIGHWAY bridges — faithful port of the original (sim/highway_bridge.hpp), the highway analogue of// the road/rail/power span builder. Numeric, asset-free. These checks pin: the block span walk (count to land,// off-map = no land, occupied start/span), the low/high style mask (32 vs 96 — high only on a long span with// clean shore ramps), the FLAT causeway lay (style 5: raw 0x49/0x4A, water bit kept), the ELEVATED lay// (style 6: 0x6A/0x6B decks + 0x61-0x64 shore ramps + the N-S XBIT 0x02 axis marker), and the per-block cost.#include "sc2k/sim/highway_bridge.hpp"#include "sc2k/ui/tools.hpp"#include <cstdio>
using namespace sc2k;using sim::hwy_bridge_probe;using sim::hwy_bridge_lay;using sim::HwyBridgeStatus;namespace hb = sc2k::sim::hwybridgedetail;
#include "test_harness.hpp"
// Mark a tile as open water (XTER in the water band, water bit set) at altitude `alt`.static void water(City& c, int r, int col, int alt = 0) { c.xter.at(r, col) = 0x20; c.xbit.at(r, col) = std::uint8_t(c.xbit.at(r, col) | 0x04); c.altm.at(r, col) = std::uint16_t((c.altm.at(r, col) & ~0x1F) | (alt & 0x1F));}// Mark a tile as flat dry land at altitude `alt` (clears the water bit, XTER 0).static void land(City& c, int r, int col, int alt = 0) { c.xter.at(r, col) = 0; c.xbit.at(r, col) = std::uint8_t(c.xbit.at(r, col) & ~0x04); c.altm.at(r, col) = std::uint16_t((c.altm.at(r, col) & ~0x1F) | (alt & 0x1F));}// Fill a 2×2 block with water / land.static void wblock(City& c, int r, int col, int alt = 0) { for (int a = 0; a < 2; ++a) for (int b = 0; b < 2; ++b) water(c, r + a, col + b, alt);}static void lblock(City& c, int r, int col, int alt = 0) { for (int a = 0; a < 2; ++a) for (int b = 0; b < 2; ++b) land(c, r + a, col + b, alt);}static int xb(const City& c, int r, int col) { return c.xbld.at(r, col); }
int main() { const int R = 40;
// ---- 1. Probe an E-W channel of 3 water blocks → span 3, status Ok, low-only mask (flat shores sit a // level below the water-block "top", so the high ramp doesn't qualify). ---- { City c; lblock(c, R, 36); // near shore (cols 36,37) at alt 0 wblock(c, R, 38); wblock(c, R, 40); wblock(c, R, 42); // 3 water blocks (cols 38..43) lblock(c, R, 44); // far shore (cols 44,45) const auto sp = hwy_bridge_probe(c, R, 38, /*dir=*/2); // launch East CHECK(sp.status == HwyBridgeStatus::Ok); CHECK(sp.span == 3); CHECK(sp.mask == 32); // low only CHECK(sp.sr == R && sp.sc == 38 && sp.dir == 2); }
// ---- 2. Lay the LOW style (5): flat E-W causeway deck (0x49) on every block tile, water bit KEPT, the // dezone marker stamped; cost = span·$200. ---- { City c; lblock(c, R, 36); wblock(c, R, 38); wblock(c, R, 40); wblock(c, R, 42); lblock(c, R, 44); auto sp = hwy_bridge_probe(c, R, 38, 2); CHECK(sp.status == HwyBridgeStatus::Ok && sp.span == 3); hwy_bridge_lay(c, sp, /*style=*/5); for (int cc = 38; cc <= 43; ++cc) { // all 3 deck blocks CHECK(xb(c, R, cc) == 0x49 && xb(c, R + 1, cc) == 0x49); // E-W flat straight CHECK(c.xbit.at(R, cc) & 0x04); // deck KEEPS the water bit CHECK((c.xzon.at(R, cc) & 0xF0) == 0xF0); // dezone / corner marker } CHECK(sp.span * hb::BR_COST[5] == 600); // 3·$200 }
// ---- 3. A long, clean span with shores one level up → high style offered (mask 96). Lay HIGH (6): // alternating 0x6A/0x6B decks + a directional ramp (0x61-0x64) on each shore block. ---- { City c; lblock(c, R, 36, /*alt=*/1); // shores raised one level (= water-block top) wblock(c, R, 38, 0); wblock(c, R, 40, 0); wblock(c, R, 42, 0); lblock(c, R, 44, 1); auto sp = hwy_bridge_probe(c, R, 38, 2); CHECK(sp.status == HwyBridgeStatus::Ok && sp.span == 3); CHECK(sp.mask == 96); // low + high both offered hwy_bridge_lay(c, sp, /*style=*/6); // decks alternate 0x6B (i=0,2) / 0x6A (i=1): CHECK(xb(c, R, 38) == 0x6B && xb(c, R, 40) == 0x6A && xb(c, R, 42) == 0x6B); // ramps on the shore blocks (E-W → 0x64 entrance / 0x62 exit), elevated highway codes: CHECK(xb(c, R, 36) == 0x64 && xb(c, R, 37) == 0x64); CHECK(xb(c, R, 44) == 0x62 && xb(c, R, 45) == 0x62); CHECK(sp.span * hb::BR_COST[6] == 900); // 3·$300 }
// ---- 4. A N-S bridge: orientation flips to 0x4A (low) and the high deck sets the XBIT 0x02 axis marker. ---- { City d; lblock(d, 36, 40, 1); wblock(d, 38, 40, 0); wblock(d, 40, 40, 0); wblock(d, 42, 40, 0); lblock(d, 44, 40, 1); auto sp = hwy_bridge_probe(d, 38, 40, /*dir=*/1); // launch South CHECK(sp.status == HwyBridgeStatus::Ok && sp.span == 3); // low lay → N-S flat straight 0x4A: City lo = d; auto slo = hwy_bridge_probe(lo, 38, 40, 1); hwy_bridge_lay(lo, slo, 5); CHECK(xb(lo, 38, 40) == 0x4A && xb(lo, 39, 41) == 0x4A); CHECK(!(lo.xbit.at(38, 40) & 0x02)); // low decks do NOT mark the axis // high lay → decks set XBIT 0x02 (N-S raised bridge marker): hwy_bridge_lay(d, sp, 6); CHECK(xb(d, 38, 40) == 0x6B && xb(d, 40, 40) == 0x6A); CHECK((d.xbit.at(38, 40) & 0x02) && (d.xbit.at(40, 41) & 0x02)); }
// ---- 5. Failure modes: off-map (no far shore) → NoLand; a built tile on the span → OccupiedSpan; a built // tile on the start block → OccupiedStart. ---- { City c; // water all the way to the East edge for (int cc = 120; cc < 128; ++cc) { water(c, R, cc); water(c, R + 1, cc); } const auto sp = hwy_bridge_probe(c, R, 120, 2); CHECK(sp.status == HwyBridgeStatus::NoLand);
City d; lblock(d, R, 36); wblock(d, R, 38); wblock(d, R, 40); wblock(d, R, 42); lblock(d, R, 44); d.xbld.at(R, 40) = 0x90; // a building squats on a mid-span water block const auto sp2 = hwy_bridge_probe(d, R, 38, 2); CHECK(sp2.status == HwyBridgeStatus::OccupiedSpan);
City e; wblock(e, R, 38); e.xbld.at(R, 38) = 0x90; // and on the start block const auto sp3 = hwy_bridge_probe(e, R, 38, 2); CHECK(sp3.status == HwyBridgeStatus::OccupiedStart); }
// ---- 6. Short span (<3 blocks) never offers the high style, even with raised shores. ---- { City c; lblock(c, R, 36, 1); wblock(c, R, 38, 0); wblock(c, R, 40, 0); lblock(c, R, 42, 1); const auto sp = hwy_bridge_probe(c, R, 38, 2); CHECK(sp.status == HwyBridgeStatus::Ok && sp.span == 2); CHECK(sp.mask == 32); // low only (span 2 < 3) }
// ---- 7. ALL-OR-NOTHING removal (2026-07-01, user-reported): a high bridge = elevated decks + a shore RAMP // block on each end. Destroying ANY part — a deck, a shore ramp, or a terrain edit that clips a shore // ramp — removes the WHOLE bridge, leaving no orphaned deck in open water (like the road bridge). auto build_high = [&](City& c) { c.set_funds(10000000); for (int r = 34; r <= 48; ++r) for (int col = 30; col <= 50; ++col) land(c, r, col, 1); lblock(c, R, 36, 1); wblock(c, R, 38, 0); wblock(c, R, 40, 0); wblock(c, R, 42, 0); lblock(c, R, 44, 1); auto sp = hwy_bridge_probe(c, R, 38, 2); hwy_bridge_lay(c, sp, 6); }; auto bridge_tiles_left = [&](City& c) { int n = 0; for (int col = 36; col <= 45; ++col) for (int r = R; r <= R + 1; ++r) { int x = xb(c, r, col); if ((x >= 0x61 && x <= 0x6b)) ++n; } // any elevated highway (deck/ramp) remaining return n; }; { City c; build_high(c); CHECK(bridge_tiles_left(c) > 0); // bulldoze a DECK tile → whole bridge gone ui::detail::demolish_highway(c, R, 40); CHECK(bridge_tiles_left(c) == 0); } { City c; build_high(c); ui::detail::demolish_highway(c, R, 36); // bulldoze a SHORE RAMP tile → whole bridge gone CHECK(bridge_tiles_left(c) == 0); } { City c; build_high(c); sc2k::raise_terrain(c, R + 2, 36); // raise terrain clipping the near shore ramp CHECK(bridge_tiles_left(c) == 0); } // → no orphaned deck left in the water
if (failures == 0) std::printf("test_highway_bridge: ALL CHECKS PASSED\n"); else std::printf("test_highway_bridge: %d CHECK(S) FAILED\n", failures); return failures ? 1 : 0;}