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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556// Validates the zoned-population census against a saved city.//// The map census (census_zone_pops) reproduces the original's per-building accounting;// for a city built from 1x1/2x2 buildings it equals the saved zonePops array byte-for-byte.// BIGGESTC.SC2 is such a city and its saved zonePops (MISC +0x5F0) is the ground truth.#include "sc2k/sim/population.hpp"#include "sc2k/io/sc2_file.hpp"#include <cstdio>#include "test_paths.hpp"
#include "test_harness.hpp"
int main() { using namespace sc2k;
// Table spot-checks (extracted from the original game). CHECK(kPopPerCode[0x70 - 0x70] == 1); // code 0x70 = smallest house, pop 1 CHECK(kPopPerCode[0x8C - 0x70] == 8); // code 0x8C = a dense-R 2x2, pop 8 CHECK(kPopPerCode[0xAE - 0x70] == 36); // code 0xAE = a large (v15=4) building, pop 36 CHECK(kPopPerCode[0xC2 - 0x70] == 0); // code 0xC2 contributes no zoned population
City c; auto r = io::load_sc2((city_file("BIGGESTC.SC2")), c); if (!r.ok) { std::printf("population: skipped (%s)\n", r.error.c_str()); return 0; }
ZonePops z = census_zone_pops(c); // from the map ZonePops s = saved_zone_pops(c); // from MISC +0x5F0 (what the game persisted)
std::printf(" BIGGESTC census : [%d,%d,%d,%d,%d,%d,%d] R=%d C=%d I=%d\n", z.cat[0], z.cat[1], z.cat[2], z.cat[3], z.cat[4], z.cat[5], z.cat[6], z.r(), z.c(), z.i()); std::printf(" BIGGESTC saved : [%d,%d,%d,%d,%d,%d,%d]\n", s.cat[0], s.cat[1], s.cat[2], s.cat[3], s.cat[4], s.cat[5], s.cat[6]);
// The map census reproduces the saved zonePops exactly for this city. for (int k = 0; k <= 6; ++k) CHECK(z.cat[k] == s.cat[k]);
// Pinned values + the R/C/I derivation (cat1+cat2 / cat3+cat4 / cat5+cat6, as the original). CHECK(z.r() == 1466); CHECK(z.c() == 444); CHECK(z.i() == 1236); CHECK(z.total() == 3146); CHECK(z.total() == z.r() + z.c() + z.i()); CHECK(s.total() == s.cat[1] + s.cat[2] + s.cat[3] + s.cat[4] + s.cat[5] + s.cat[6]);
if (failures == 0) { std::printf("population: all checks passed\n"); return 0; } std::printf("population: %d failure(s)\n", failures); return 1;}