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.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182// Integration: a year of live sim actually FEEDS the data windows — the month's zone census is// published to MISC (dwZonePops, the Population window's demographic target), the XGRP graph rings// advance with fresh samples, and unemployment/land-value/crime/traffic totals land in their MISC// mirrors. This is the regression net for "the Population/Graph windows show nothing": the port// computed all of this but never wrote it where the windows (and the demographics target) read it.#include "sc2k/sim/simulation.hpp"#include "sc2k/io/sc2_file.hpp"#include "sc2k/sim/industry.hpp"#include "sc2k/ui/graph_view.hpp"#include <cstdio>#include "test_paths.hpp"
using namespace sc2k;
#include "test_harness.hpp"
int main() { City c; auto r = io::load_sc2((city_file("TOKYO.SC2")), c); if (!r.ok) { std::printf("graph_live: skipped (%s)\n", r.error.c_str()); return 0; }
const int newest0 = ui::graph_entry(c, 0, 0); // City Size sample before ticking
Simulation sim(c); sim.set_growth_enabled(true); sim.set_finance_enabled(true); sim.set_demand_enabled(true); for (int i = 0; i < 25 * 12; ++i) sim.tick(); // a full game year (12 recorder fires)
// Zone census published: MISC zonePops[0] = Σ[1..6], nonzero for a living city. std::int32_t s16 = 0; for (int k = 1; k <= 6; ++k) s16 += c.zone_pop(k); CHECK(c.zone_pop(0) > 0 && c.zone_pop(0) == s16);
// The demographics target now tracks the census → age brackets stay populated. long brackets = 0; for (int b = 0; b < 20; ++b) brackets += c.misc_be32(sc2k::misc::kAgeHistRaw + 12 * b); CHECK(brackets > 0);
// Graph rings advanced: the newest City-Size sample is this month's (10·zonePops[0] — Tokyo has // no arcologies), and a year of samples filled the 1-yr ring with the same magnitude. CHECK(ui::graph_entry(c, 0, 0) == 10 * c.zone_pop(0)); CHECK(ui::graph_entry(c, 0, 11) != newest0 || ui::graph_entry(c, 0, 0) != newest0); for (int e = 0; e < 12; ++e) CHECK(ui::graph_entry(c, 0, e) > 0); CHECK(c.graph_max[0] >= ui::graph_entry(c, 0, 0));
// Power/Water % (headroom), Health/Education, Fed Rate all recorded with sane ranges. CHECK(ui::graph_entry(c, 8, 0) >= 0 && ui::graph_entry(c, 8, 0) <= 100); CHECK(ui::graph_entry(c, 9, 0) >= 0 && ui::graph_entry(c, 9, 0) <= 100); CHECK(ui::graph_entry(c, 10, 0) > 0 && ui::graph_entry(c, 11, 0) > 0); CHECK(ui::graph_entry(c, 15, 0) > 0);
// The MISC mirrors of the live totals (unemployment / traffic / pollution / value / crime). CHECK(c.misc_be32(sc2k::misc::kUnemployment) >= 0 && c.misc_be32(sc2k::misc::kUnemployment) <= 100); CHECK(c.misc_be32(sc2k::misc::kLandValueTotal) > 0 && c.misc_be32(sc2k::misc::kCrimeTotal) >= 0 && c.misc_be32(sc2k::misc::kPollutionTotal) >= 0);
// The industry model (sim/industry.hpp): demands evolved to nonzero words and the industry pops // rebalanced to roughly the I-sector census total (City Industry window now has data). int liveDemands = 0; std::int64_t indPops = 0; for (int s = 0; s < 11; ++s) { if (industry_demand(c, s) != 0) ++liveDemands; indPops += industry_pop(c, s); } CHECK(liveDemands >= 8); const std::int64_t itotal = c.zone_pop(5) + c.zone_pop(6); CHECK(indPops > itotal / 2 && indPops < 2 * itotal + 100);
std::printf("graph_live: TOKYO 1yr — pop=%d citySize=%d brackets=%ld power%%=%d unemp=%d\n", 10 * c.zone_pop(0), ui::graph_entry(c, 0, 0), brackets, ui::graph_entry(c, 8, 0), c.misc_be32(sc2k::misc::kUnemployment)); if (failures == 0) { std::printf("graph_live: all checks passed\n"); return 0; } std::printf("graph_live: %d failure(s)\n", failures); return 1;}