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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980// Integration: with live demand ENABLED, demand is recomputed each month from the city's real inputs// and stays in range — and crucially it does NOT break the build→grow loop (a fresh district still// develops). Demand is RNG-free here but depends on the (verified) inputs; this checks the live wiring.#include "sc2k/sim/simulation.hpp"#include "sc2k/io/sc2_file.hpp"#include "sc2k/ui/tools.hpp"#include <cstdio>#include "test_paths.hpp"
using namespace sc2k;
#include "test_harness.hpp"
static int developed(const City& c) { int n = 0; for (int t = 0; t < City::kTiles; t++) if (c.xbld.cells[t] >= 112) ++n; return n;}int main() { const std::string root = test_root();
// Part 1 — demand stays bounded and moves on a real city. if (exists(city_file("LONDON.SC2"))) { City c; CHECK(io::load_sc2(city_file("LONDON.SC2"), c).ok); const int r0 = c.demand(0), c0 = c.demand(1), i0 = c.demand(2); Simulation sim(c); sim.set_demand_enabled(true); sim.set_growth_enabled(true); for (int k = 0; k < 25 * 24; ++k) sim.tick(); // 2 years for (int s = 0; s < 3; ++s) CHECK(sim.demand(s) >= -2000 && sim.demand(s) <= 2000); std::printf("demand_live: LONDON demand R/C/I %d/%d/%d -> %d/%d/%d\n", r0, c0, i0, sim.demand(0), sim.demand(1), sim.demand(2)); }
// Part 2 — live demand must NOT kill growth: a fresh powered+roaded district still develops. if (exists(root + "/DEFAULT.SC2")) { City f; CHECK(io::load_sc2(root + "/DEFAULT.SC2", f).ok); f.set_funds(100000000); auto T = [&](ui::Tool t, int r, int col) { ui::apply_tool(f, t, r, col); }; T(ui::Tool::PowerPlant, 24, 20); for (int col = 20; col <= 44; ++col) { T(ui::Tool::PowerLine, 28, col); T(ui::Tool::PowerLine, 32, col); T(ui::Tool::Road, 30, col); T(ui::Tool::Road, 34, col); T(ui::Tool::ZoneR, 29, col); T(ui::Tool::ZoneC, 31, col); T(ui::Tool::ZoneI, 33, col); } // Join the two horizontal power and road buses outside the zoned strip. Without these // connectors only Residential receives power and Industrial cannot reach the other sectors, // so the fixture does not satisfy the powered+roaded premise it is intended to test. for (int row = 27; row <= 32; ++row) T(ui::Tool::PowerLine, row, 19); for (int row = 30; row <= 34; ++row) T(ui::Tool::Road, row, 45); const int dev0 = developed(f); Simulation sim(f); sim.set_demand_enabled(true); sim.set_growth_enabled(true); sim.set_finance_enabled(true); for (int k = 0; k < 25 * 12 * 8; ++k) sim.tick(); // 8 years const int dev1 = developed(f); std::printf("demand_live: fresh district developed %d -> %d; demand R/C/I %d/%d/%d\n", dev0, dev1, sim.demand(0), sim.demand(1), sim.demand(2)); CHECK(dev1 > dev0); // the district still grew with live demand for (int s = 0; s < 3; ++s) CHECK(sim.demand(s) >= -2000 && sim.demand(s) <= 2000); }
if (failures == 0) { std::printf("demand_live: all checks passed\n"); return 0; } std::printf("demand_live: %d failure(s)\n", failures); return 1;}