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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104// Known-answer test for the original's RCI demand update.//// Expected values are produced by an INDEPENDENT Python reference that mirrors the// original's x87 operation order (not by this code), so this is a genuine// cross-implementation check of the verified formula — not a self-fulfilling one.#include "sc2k/sim/demand.hpp"#include <array>#include <cstdio>
#include "test_harness.hpp"
int main() { using namespace sc2k;
// --- Vector 1: no infrastructure, neutral tier 7, city class 1 --- // Python ref: bases=[252.0, 28.41965, 135.45817] demand_out=[897,-265,-195] newSat=100 { std::array<std::uint32_t, 256> hist{}; // all zero -> no infra caps bite DemandInputs in; in.pop = {0, 100, 0, 50, 0, 200, 0, 0}; // R=100, C=50, I=200 in.satNum = 100; in.valueLV = 50; in.cityClass = 1; in.ordinances = 0; in.conn1000 = 0; in.conn1500 = 0; in.tileCount = hist.data(); in.tier = {7, 7, 7}; in.demand = {0, 0, 0};
std::int32_t ns = rci_demand_update(in); std::printf(" V1: demand R=%d C=%d I=%d satNum=%d\n", in.demand[0], in.demand[1], in.demand[2], ns); CHECK(in.demand[0] == 897); CHECK(in.demand[1] == -265); CHECK(in.demand[2] == -195); CHECK(ns == 100); // satNum re-seeded to R CHECK(in.satNum == 100); }
// --- Vector 2: infra caps present + ordinances (sales+income tax, pollution controls) --- // Python ref: bases=[540.0, 70.86102, 158.64407] demand_out=[216,-878,-34] newSat=500 { std::array<std::uint32_t, 256> hist{}; hist[0xD5] = 6; hist[0xD7] = 2; hist[0xDA] = 1; hist[0xF8] = 0; // R-cap census hist[0xDD] = 3; hist[0xDE] = 1; // C-cap (runways) hist[0xE0] = 4; // I-cap (crane) DemandInputs in; in.pop = {0, 400, 100, 300, 50, 150, 30, 0}; // R=500, C=350, I=180 in.satNum = 520; in.valueLV = -20; in.cityClass = 2; in.ordinances = 0x1u | 0x2u | 0x80000u; // sales tax, income tax, pollution controls in.conn1000 = 5; in.conn1500 = 7; in.tileCount = hist.data(); in.tier = {4, 9, 6}; in.demand = {120, -300, 40};
std::int32_t ns = rci_demand_update(in); std::printf(" V2: demand R=%d C=%d I=%d satNum=%d\n", in.demand[0], in.demand[1], in.demand[2], ns); CHECK(in.demand[0] == 216); CHECK(in.demand[1] == -878); CHECK(in.demand[2] == -34); CHECK(ns == 500); }
// --- Clamp behaviour: demand saturates at +/-2000, never wraps --- { std::array<std::uint32_t, 256> hist{}; DemandInputs in; in.pop = {0, 1, 0, 1, 0, 1, 0, 0}; // tiny pops -> large per-capita pressure in.satNum = 1; in.valueLV = 1000; in.cityClass = 1; in.tileCount = hist.data(); in.tier = {0, 0, 0}; // velLUT[0] = +200 (max positive step) in.demand = {1990, 1990, 1990}; // already near the ceiling rci_demand_update(in); std::printf(" Vclamp+: R=%d C=%d I=%d\n", in.demand[0], in.demand[1], in.demand[2]); CHECK(in.demand[0] <= 2000 && in.demand[1] <= 2000 && in.demand[2] <= 2000); CHECK(in.demand[0] == 2000); // strong positive pressure pins R at the cap
in.tier = {15, 15, 15}; // velLUT[15] = -350 (max negative step) in.demand = {-1990, -1990, -1990}; in.valueLV = -1000; rci_demand_update(in); std::printf(" Vclamp-: R=%d C=%d I=%d\n", in.demand[0], in.demand[1], in.demand[2]); CHECK(in.demand[0] >= -2000 && in.demand[1] >= -2000 && in.demand[2] >= -2000); }
if (failures == 0) { std::printf("demand: all checks passed\n"); return 0; } std::printf("demand: %d failure(s)\n", failures); return 1;}