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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177// netpath_demo — an ASCII visualiser for the network PATH SOLVER (sim/network_path.hpp). It runs the REAL// compiled solver and draws the path it returns, so you can eyeball the L-bends, the clip box, where a drag// STOPS (building/water/military), and automatic perpendicular crossings — no SDL, no assets.//// build: make tools (or: c++ -std=c++20 -Iinclude tools/netpath_demo.cpp -o build/netpath_demo)// run: ./build/netpath_demo//// Legend: A = anchor (drag start) * = end (drag release, reached) X = end requested but NOT reached// > < ^ v = a laid network tile + the direction it was laid . = empty land// B = building (blocks) ~ = water (blocks surface nets) M = military (blocks)// # = a pre-existing perpendicular road (the drag CROSSES it → shown as + when on the path)// / = a slope tile (shape in the corner)#include "sc2k/sim/network_path.hpp"#include "sc2k/sim/network_commit.hpp"#include <cstdio>#include <string>
using namespace sc2k;
// Draw a window of the map [r0..r1] x [c0..c1] with the solved path overlaid.static void draw(const char* title, const City& c, const sim::NetworkPath& p, int anchorR, int anchorC, int endR, int endC, int r0, int r1, int c0, int c1) { static const char ARROW[4] = {'<', 'v', '>', '^'}; // dir 0=W 1=S 2=E 3=N // Base layer glyph for a tile (terrain/obstacle), before the path is drawn over it. auto base = [&](int r, int col) -> char { if (c.xbit.at(r, col) & 0x04) return '~'; if ((c.xzon.at(r, col) & 0x0F) == 7) return 'M'; const int xb = c.xbld.at(r, col); if (xb == 0x1E || xb == 0x1D) return '#'; // a perpendicular road already here if (xb >= 0x0D) return 'B'; if (c.xter.at(r, col) != 0) return '/'; return '.'; }; // Overlay grid. std::string grid[64]; for (int r = r0; r <= r1; ++r) { std::string& row = grid[r]; row.assign((c1 - c0 + 1), ' '); for (int col = c0; col <= c1; ++col) row[col - c0] = base(r, col); } for (const auto& s : p.steps) if (s.row >= r0 && s.row <= r1 && s.col >= c0 && s.col <= c1) { char& cell = grid[s.row][s.col - c0]; cell = (cell == '#') ? '+' : ARROW[s.dir & 3]; // crossing tile shows as + } if (anchorR >= r0 && anchorR <= r1 && anchorC >= c0 && anchorC <= c1) grid[anchorR][anchorC - c0] = 'A'; const bool reached = (p.endRow == endR && p.endCol == endC); if (endR >= r0 && endR <= r1 && endC >= c0 && endC <= c1) grid[endR][endC - c0] = reached ? '*' : 'X';
std::printf("\n%s\n", title); std::printf(" anchor(%d,%d) -> end(%d,%d) valid=%s tiles=%d reached=(%d,%d) %s\n", anchorR, anchorC, endR, endC, p.valid ? "yes" : "NO", (int)p.steps.size(), p.endRow, p.endCol, reached ? "[REACHED]" : "[STOPPED SHORT]"); for (int r = r0; r <= r1; ++r) std::printf(" %s\n", grid[r].c_str());}
int main() { using sim::solve_network_path; using sim::NetType;
std::printf("=== network path solver — ASCII demo (runs the real sim/network_path.hpp) ===\n");
{ City c; auto p = solve_network_path(c, 4, 2, 4, 13, NetType::Road); draw("1) Straight road, flat ground (drag East)", c, p, 4, 2, 4, 13, 1, 7, 0, 15); }
{ City c; auto p = solve_network_path(c, 1, 2, 7, 13, NetType::Road); draw("2) L-bend on flat ground (the alignment follows the drag)", c, p, 1, 2, 7, 13, 0, 8, 0, 15); }
{ City c; c.xbld.at(4, 8) = 0x80; // a building straddling the route auto p = solve_network_path(c, 4, 2, 4, 13, NetType::Road); draw("3) A building STOPS the drag (no bulldoze) — path ends before it", c, p, 4, 2, 4, 13, 1, 7, 0, 15); }
{ City c; c.xbld.at(4, 8) = 0x1E; // a perpendicular road (N-S straight) auto p = solve_network_path(c, 4, 2, 4, 13, NetType::Road); draw("4) A perpendicular road is CROSSED (auto intersection, shown +)", c, p, 4, 2, 4, 13, 1, 7, 0, 15); }
{ City c; for (int r = 2; r <= 6; ++r) c.xbit.at(r, 8) = 0x04; // a river auto p = solve_network_path(c, 4, 2, 4, 13, NetType::Road); draw("5) Open water STOPS a surface road (bridges are a later phase)", c, p, 4, 2, 4, 13, 1, 7, 0, 15); }
{ City c; c.xter.at(4, 2) = 0x01; // slope shape 1 = N/S gradient: blocks E/W auto pe = solve_network_path(c, 4, 2, 4, 13, NetType::Road); draw("6a) Slope (N-S gradient): an E-W drag can't cross it -> 1 tile", c, pe, 4, 2, 4, 13, 1, 7, 0, 15); City d; d.xter.at(4, 2) = 0x01; auto ps = solve_network_path(d, 4, 2, 13, 2, NetType::Road); draw("6b) …but building ALONG the gradient (drag South) is fine", d, ps, 4, 2, 13, 2, 1, 14, 0, 6); }
// ---------- Phase 2: the COMMITTED network (real road sprites the autotiler picks) ---------- auto glyph = [](int code) -> char { if (code == 0x1D) return '-'; // E-W straight if (code == 0x1E) return '|'; // N-S straight if (code >= 0x1F && code <= 0x22) return '/'; // sloped road if (code >= 0x23 && code <= 0x26) return 'o'; // curve / corner if (code >= 0x27 && code <= 0x2A) return 'T'; // tee if (code == 0x2B) return '+'; // 4-way cross if (code == 0x43 || code == 0x44) return 'p'; // road over power if (code == 0x45 || code == 0x46) return 'r'; // road over rail if (code == 0x4B || code == 0x4C) return 'h'; // road over highway if (code >= 0x2C && code <= 0x3A) return '='; // rail if (code >= 0x0E && code <= 0x1C) return 'e'; // power line if (code == 0x47 || code == 0x48) return 'x'; // power over rail if (code == 0) return '.'; return '?'; }; auto draw_commit = [&](const char* title, City& c, int r0, int r1, int c0, int c1) { std::printf("\n%s\n", title); for (int r = r0; r <= r1; ++r) { std::string row; for (int col = c0; col <= c1; ++col) row += glyph(c.xbld.at(r, col)); std::printf(" %s\n", row.c_str()); } };
std::printf("\n=== committed networks (the autotiler's actual sprites: - | o T + ) ===\n");
{ City c; c.set_funds(100000); // an L of road — straights + a corner auto p = solve_network_path(c, 2, 2, 6, 11, NetType::Road); commit_network_path(c, p, NetType::Road, 10); draw_commit("7) Committed L-bend road (o = curve pieces the autotiler chose)", c, 1, 7, 0, 13); }
{ City c; c.set_funds(100000); // a + intersection from two crossing roads auto h = solve_network_path(c, 4, 1, 4, 12, NetType::Road); commit_network_path(c, h, NetType::Road, 10); auto v = solve_network_path(c, 1, 6, 7, 6, NetType::Road); commit_network_path(c, v, NetType::Road, 10); draw_commit("8) Two roads crossing -> automatic + intersection (and T-junctions)", c, 1, 7, 0, 13); }
{ City c; c.set_funds(100000); // road crossing a pre-existing rail for (int r = 1; r <= 7; ++r) c.xbld.at(r, 6) = 0x2D; // a vertical rail line auto p = solve_network_path(c, 4, 1, 4, 12, NetType::Road); commit_network_path(c, p, NetType::Road, 10); draw_commit("9) Road over rail -> 'r' crossing sprite at the junction", c, 1, 7, 0, 13); }
{ City c; c.set_funds(1000000); // road + rail + power all crossing one spot auto rd = solve_network_path(c, 3, 1, 3, 12, NetType::Road); commit_network_path(c, rd, NetType::Road, 10); auto rl = solve_network_path(c, 1, 5, 6, 5, NetType::Rail); commit_network_path(c, rl, NetType::Rail, 25); auto pw = solve_network_path(c, 1, 9, 6, 9, NetType::Power); commit_network_path(c, pw, NetType::Power, 2); draw_commit("10) Road(-) crossing rail(=)->r and power(e)->p (auto crossing sprites)", c, 1, 6, 0, 13); }
std::printf("\n(Maps are the actual output of solve_network_path + commit_network_path — tweak & rebuild.)\n"); return 0;}