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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869// Rail autotiler KAT (ui/tools.hpp). Rail codes were recovered from the saved-city XBLD histogram as the// road codes + 0x0F (straights 0x2c/0x2d, corners 0x32-0x35, tees 0x36-0x39, cross 0x3a). Verify the// offset relationship and that laying rail produces the right straight / corner / cross codes — numerically.#include "sc2k/city.hpp"#include "sc2k/ui/tools.hpp"#include <cstdio>
#include "test_harness.hpp"
int main() { using namespace sc2k; // Rail table = road table + 0x0F, for every connectivity mask. for (int m = 0; m < 16; ++m) CHECK(ui::detail::rail_tile(m) == ui::detail::kRoadTile[m] + 0x0F); CHECK(ui::detail::is_rail(0x2c) && ui::detail::is_rail(0x3a) && !ui::detail::is_rail(0x2b));
// A horizontal rail line: the interior tiles are the E-W straight (0x2c). City c; for (int x = 10; x < 20; ++x) ui::detail::place_rail(c, 10, x); CHECK(c.xbld.at(10, 15) == 0x2c);
// Add a vertical leg down from the right end → the join is a corner (0x32-0x35). for (int y = 11; y < 16; ++y) ui::detail::place_rail(c, y, 19); const int corner = c.xbld.at(10, 19); CHECK(corner >= 0x32 && corner <= 0x35);
// A plus shape → the centre is the 4-way cross (0x3a). City c2; for (int x = 30; x < 41; ++x) ui::detail::place_rail(c2, 35, x); for (int y = 30; y < 41; ++y) ui::detail::place_rail(c2, y, 35); CHECK(c2.xbld.at(35, 35) == 0x3a); // A tee where the line meets the cross's arm one step out (3 connections). const int tee = c2.xbld.at(35, 34); CHECK(tee == 0x2c || (tee >= 0x36 && tee <= 0x39)); // straight run, or a tee at a junction
// ---- Bridges are now a faithful SPAN action via the Select Bridge dialog, not a per-tile // apply_tool plop. apply_tool DEFERS on water (the UI layer runs the dialog); the span/lay/remove // mechanics are verified thoroughly in test_bridge.cpp. Here we only confirm the deferral. ---- { City c; c.set_funds(100000); for (int r = 20; r < 40; ++r) c.xbit.at(r, 64) = 0x04; // a water channel (col 64) CHECK(!ui::apply_tool(c, ui::Tool::Road, 30, 64).ok); // road over water → deferred to the bridge dialog CHECK(!ui::apply_tool(c, ui::Tool::Rail, 30, 64).ok); // rail too CHECK(c.xbld.at(30, 64) == 0); // nothing plopped per-tile }
// ---- Port tools: Seaport / Airport zone a special-zone area (nibble 9/8 as the original, constrained) ---- { City c; c.set_funds(100000); c.xbit.at(40, 41) = 0x04; // water beside (40,40) CHECK(ui::apply_tool(c, ui::Tool::Seaport, 40, 40).ok && (c.xzon.at(40, 40) & 0x0F) == 9); // seaport = nibble 9 CHECK(ui::apply_tool(c, ui::Tool::Seaport, 90, 90).ok); // dry land away from water is ALLOWED (faithful) c.xbit.at(50, 50) = 0x04; CHECK(!ui::apply_tool(c, ui::Tool::Seaport, 50, 50).ok); // but ON water → refused (dry-land zone gate) CHECK(ui::apply_tool(c, ui::Tool::Airport, 70, 70).ok && (c.xzon.at(70, 70) & 0x0F) == 8); // airport = nibble 8 c.xbit.at(80, 80) = 0x04; CHECK(!ui::apply_tool(c, ui::Tool::Airport, 80, 80).ok); // airport refuses water }
if (failures == 0) { std::printf("rail: all checks passed\n"); return 0; } std::printf("rail: %d failure(s)\n", failures); return 1;}