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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114// Traffic cars must render on ELEVATED highways (decks/ramps/curves/interchange), not just flat roads.//// Two coupled bugs that were fixed for elevated-highway cars:// (1) THRESHOLD (the big one): the original gates an elevated-highway car on the HIGHWAY threshold (XTRF>28),// but Libreopolis only treated surface highway (0x49-0x50) as highway, so elevated pieces (0x61-0x6b) used// the ROAD threshold (85). Moderately-busy ramps/curves (XTRF ~30-80) drew NO car → "no traffic on// highway slopes / interchanges".// (2) HEIGHT: the 2×2 elevated car was anchored at the ground base 17 instead of the deck base 25.// This test asserts a moderate-traffic elevated tile draws a car ONLY with the fix on (threshold), and that// a flat road is unaffected (targeted). Sensitive: flip the flag off and the elevated car vanishes.#include "sc2k/render/asset_loader.hpp"#include "sc2k/render/city_renderer.hpp"#include "sc2k/render/iso_projection.hpp"#include "sc2k/io/sc2_file.hpp"#include <cstdio>#include "test_paths.hpp"
using namespace sc2k;using namespace sc2k::render;
#include "test_harness.hpp"
// car pixels at (br,bc): difference between rendering with vs without that tile's traffic.static int car_pixels(CityRenderer& rend, const City& c, int br, int bc) { const int W = 120, H = 120; const int alt = c.altm.cells[br * 128 + bc] & 0x1F; const auto o = origin_centering_tile(br, bc, alt, 2, 60, 66); const Camera cam{o.x, o.y}; Framebuffer f1(W, H), f2(W, H); const City& on = c; City off = c; off.xtrf.at(br / 2, bc / 2) = 0; f1.clear(kBackground); f2.clear(kBackground); rend.render(on, f1, cam, 0, 0, 2); rend.render(off, f2, cam, 0, 0, 2); int n = 0; for (int i = 0; i < W * H; ++i) { const auto p = f1.pixels()[i], q = f2.pixels()[i]; if (p.r != q.r || p.g != q.g || p.b != q.b) ++n; } return n;}
int main() { Assets a; try { a = load_assets(); } catch (const std::exception& e) { std::printf("traffic_car: assets unavailable (%s) — skipped\n", e.what()); return 0; } CityRenderer rend(a.bank, a.palette);
City c; std::string used; // scan a few cities for a MODERATELY-busy (XTRF 29-85) elevated-highway tile away from the edges int er = -1, ec = -1, eX = 0, eD = 0; for (const char* nm : {"HI_LOH2O.SC2", "UTOPIA.SC2", "HILTON.SC2", "NEWYORK.SC2", "TOKYO.SC2"}) { City t; if (!io::load_sc2((cities_dir()) + nm, t).ok) continue; for (int r = 8; r < 120; ++r) for (int col = 8; col < 120; ++col) { const int xb = t.xbld.cells[r * 128 + col]; if (xb < 0x61 || xb > 0x69) continue; const int dd = t.xtrf.at(r / 2, col / 2); if (dd > 28 && dd <= 85 && dd > eD) { eD = dd; er = r; ec = col; eX = xb; c = t; used = nm; } } if (er >= 0) break; } if (er < 0) { std::printf("traffic_car: no moderate-traffic elevated highway found — skipped\n"); return 0; } std::printf(" %s elevated tile (%d,%d) XBLD=0x%02X XTRF=%d\n", used.c_str(), er, ec, eX, eD);
const int onCar = car_pixels(rend, c, er, ec); std::printf(" elevated car pixels: %d (expect >0)\n", onCar); CHECK(onCar > 0); // the elevated-highway car renders (XTRF>28 highway threshold, deck-anchored)
// targeted: a flat road's car is unaffected by the flag (its base is 17 and it's not in 0x61-0x6b) int fr = -1, fc = -1, fD = 0; for (int r = 8; r < 120; ++r) for (int col = 8; col < 120; ++col) { const int xb = c.xbld.cells[r * 128 + col]; if (xb != 0x1D && xb != 0x1E) continue; const int dd = c.xtrf.at(r / 2, col / 2); if (dd > 90 && dd > fD) { fD = dd; fr = r; fc = col; } } if (fr >= 0) { const int onFlat = car_pixels(rend, c, fr, fc); std::printf(" flat road car pixels: %d (expect >0)\n", onFlat); CHECK(onFlat > 0); // a flat road's car (base 17, not an elevated deck) still renders }
if (failures == 0) { std::printf("traffic_car: all checks passed\n"); return 0; } std::printf("traffic_car: %d failure(s)\n", failures); return 1;}