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.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879// Validation of ruin (abandoned-building) redevelopment (sim/growth_scan.hpp): an ELIGIBLE ruin (powered +// job-reachable) with demand clears its footprint and rebuilds; a DISCONNECTED ruin stays abandoned.#include "sc2k/sim/growth_scan.hpp"#include <cstdio>
#include "test_harness.hpp"
namespace {using namespace sc2k;// An I ruin (code 138, a 1×1) at (30,30), powered, with a road run to an R + C job — so it's eligible.// XZON = 0xF6: all four corner bits (as a real 1×1 from decline_building has) so the scan's anchor check// processes the tile, plus the dense-I zone nibble 6.City connected_ruin() { City c; c.xzon.at(30, 30) = 0xF6; // dense I + 1×1 anchor corners c.xbld.at(30, 30) = 138; // a 1×1 ruin (level 1) c.xbit.at(30, 30) = 0x40; // powered for (int x = 31; x <= 35; ++x) c.xbld.at(30, x) = 0x1D; // road c.xzon.at(30, 36) = 0x01; c.xzon.at(29, 35) = 0x03; // reachable R + C jobs c.xval.at(15, 15) = 0xC0; // high land value (so a rebuild can grow) return c;}} // namespace
int main() { using namespace sc2k;
// (1) is_abandoned_code matches exactly the original's ruin set. { for (int code : {138, 139, 170, 171, 172, 173, 194, 195}) CHECK(is_abandoned_code(code)); for (int code : {130, 140, 168, 169, 112, 0, 137, 193}) CHECK(!is_abandoned_code(code)); }
// (2) An ELIGIBLE ruin redevelops in place: after enough scans the tile is a normal building (≥112, // not a ruin) — the faithful flag-2 rebuild, not a clear-to-empty. { bool gone = false; for (int seed = 1; seed <= 5 && !gone; ++seed) { City c = connected_ruin(); MsRand rng(seed); ZonePops pops; for (int it = 0; it < 400; ++it) { growth_tile_step(c, 30, 30, /*I demand*/ 1800, rng, 0, pops); if (!is_abandoned_code(c.xbld.at(30, 30))) { gone = true; break; } // cleared or rebuilt } } CHECK(gone); // an eligible ruin does not sit forever }
// (3) A DISCONNECTED ruin (no road / no reachable job) stays abandoned. { City c; c.xzon.at(30, 30) = 0xF6; c.xbld.at(30, 30) = 138; c.xbit.at(30, 30) = 0x40; // powered but isolated MsRand rng(1); ZonePops pops; bool stillRuin = true; for (int it = 0; it < 400; ++it) { growth_tile_step(c, 30, 30, 1800, rng, 0, pops); if (!is_abandoned_code(c.xbld.at(30, 30))) { stillRuin = false; break; } } CHECK(stillRuin); // no job access ⇒ correctly left abandoned }
if (failures == 0) std::printf("test_ruin_redevelop: ALL CHECKS PASSED\n"); else std::printf("test_ruin_redevelop: %d CHECK(S) FAILED\n", failures); return failures ? 1 : 0;}