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// Density (XPOP) + growth-rate (XROG) maps (sim/density_growth.hpp) — the tail of the original's map-statistics scan. Verifies the// per-region density sum, the growth EMA centered at 128 (neutral), and that a fresh map reads neutral (not// all-red, the bug this fixes) while a growing region climbs to green and a demolished one falls to red.#include "sc2k/sim/density_growth.hpp"#include "sc2k/city.hpp"#include <algorithm>#include <cstdio>
using namespace sc2k;using namespace sc2k::sim;
#include "test_harness.hpp"
int main() { // A fresh city seeds XROG = 127 (neutral) — the Growth view must NOT read it as declining. City c; std::fill(c.xrog.cells.begin(), c.xrog.cells.end(), 127); std::fill(c.xpop.cells.begin(), c.xpop.cells.end(), 0); update_density_growth(c); // empty map, no buildings CHECK(c.xrog.at(5, 5) == 127); // stable region stays neutral (0x7F ∈ [0x7D,0x82]) CHECK(c.xrog.at(5, 5) > 0x7C && c.xrog.at(5, 5) < 0x83); // → base map in the Growth view, not red CHECK(c.xpop.at(5, 5) == 0);
// XPOP = min(255, 4·Σ weight). Fill region (10,10) = tiles [40..43]×[40..43] with a weight-2 building (0x8C). for (int r = 40; r < 44; ++r) for (int col = 40; col < 44; ++col) c.xbld.at(r, col) = 0x8C; update_density_growth(c); CHECK(c.xpop.at(10, 10) == std::min(255, 4 * (16 * 2))); // 16 tiles × weight 2 × 4 = 128 CHECK(c.xrog.at(10, 10) > 127); // density jumped up → growing (> neutral)
// Keep the buildings a few months → the region reads clearly GROWING (green, ≥ 0x83) then stabilises. for (int m = 0; m < 5; ++m) update_density_growth(c); CHECK(c.xrog.at(10, 10) >= 0x83);
// Demolish → density collapses → the region reads DECLINING (red, ≤ 0x7C). for (int r = 40; r < 44; ++r) for (int col = 40; col < 44; ++col) c.xbld.at(r, col) = 0; for (int m = 0; m < 6; ++m) update_density_growth(c); CHECK(c.xrog.at(10, 10) <= 0x7C); CHECK(c.xpop.at(10, 10) == 0);
// A weight-4 (arco-scale) building tops the density out higher than a weight-1 house. City d; std::fill(d.xrog.cells.begin(), d.xrog.cells.end(), 127); for (int r = 40; r < 44; ++r) for (int col = 40; col < 44; ++col) d.xbld.at(r, col) = 0xAE; // weight 4 update_density_growth(d); CHECK(d.xpop.at(10, 10) == std::min(255, 4 * (16 * 4))); // 16 × 4 × 4 = 256 → clamped 255
if (failures == 0) std::printf("test_density_growth: all checks passed\n"); else std::printf("test_density_growth: %d FAILURES\n", failures); return failures ? 1 : 0;}