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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148// Verifies the live funding-% plumbing (simulation.hpp phase_fields → coverage.hpp): the police/fire// coverage strength now scales with the budget funding rate (records 5/6), and new cities default to// 100% service funding + 7% tax (the original's default). Synthetic city — no assets needed.#include "sc2k/sim/simulation.hpp"#include "sc2k/sim/terrain_gen.hpp"#include <cstdio>
using namespace sc2k;
#include "test_harness.hpp"
// Sum of the XPLC police-coverage field after running the sim past the tick-2 field scan.static long police_coverage_at(int fundingPct) { City c; c.set_funds(50000); c.xbld.at(40, 40) = 0xD2; // a police station tile c.xzon.at(40, 40) = std::uint8_t(c.xzon.at(40, 40) | 0x80); // active (XZON bit 7) c.xbit.at(40, 40) = std::uint8_t(c.xbit.at(40, 40) | 0x40); // powered c.set_budget_rate(5, fundingPct); // police funding % Simulation sim(c); // holds a City& — mutates `c` in place for (int i = 0; i < 30; ++i) sim.tick(); // run past tick 2 (the police/fire stencil) long s = 0; for (auto v : c.xplc.cells) s += v; return s;}
static int powered_tiles_at(int fundingPct) { City city{MapSize::Tiny}; city.xbld.at(20, 5) = xbld::kCoalPlant; city.xbit.at(20, 5) = xbit::kConductive; for (int column = 6; column < 64; ++column) { city.xbld.at(20, column) = xbld::kHomesFirst; city.xbit.at(20, column) = xbit::kConductive; } city.set_budget_rate(11, fundingPct); Simulation simulation(city); simulation.tick(); // phase 1: power int powered = 0; for (const std::uint8_t bits : city.xbit.cells) if (bits & xbit::kPowered) ++powered; return powered;}
static int watered_buildings_at(int fundingPct) { City city{MapSize::Tiny}; sim::initialize_modern_water_network(city); city.set_misc_be32(misc::kWeatherRain, 100); city.xbld.at(10, 10) = xbld::kWaterPump; city.xbit.at(10, 10) |= xbit::kPowered; sim::set_water_main(city, 10, 10, true); int placed = 0; for (int row = 11; row <= 17 && placed < 60; ++row) for (int column = 3; column <= 17 && placed < 60; ++column) { city.xbld.at(row, column) = xbld::kHomesFirst; ++placed; } sim::MunicipalDebt debt; sim::OperatingBudgetState operating; operating.waterFundingPercent = fundingPct; Simulation simulation(city, debt, operating); simulation.recompute_water_delivery(); int watered = 0; for (int index = 0; index < city.tile_count(); ++index) if (city.xbld.cells[static_cast<std::size_t>(index)] == xbld::kHomesFirst && (city.xbit.cells[static_cast<std::size_t>(index)] & xbit::kWatered)) ++watered; return watered;}
int main() { // --- New cities default to the faithful budget rates --- { City nc = make_new_city(0x1234u, 2, 1, 50, 50, 50, 0, 0); CHECK(nc.budget_rate(5) == 100); // police funding 100% CHECK(nc.budget_rate(6) == 100); // fire funding 100% CHECK(nc.budget_rate(0) == 7); // residential tax 7% CHECK(nc.budget_rate(3) == 1); // ordinances }
// --- Coverage scales with police funding (monotone; zero funding → no coverage) --- const long c100 = police_coverage_at(100); const long c150 = police_coverage_at(150); const long c50 = police_coverage_at(50); const long c0 = police_coverage_at(0); std::printf(" police coverage Σ XPLC: fund150=%ld fund100=%ld fund50=%ld fund0=%ld\n", c150, c100, c50, c0); CHECK(c100 > 0); CHECK(c0 == 0); // 0% funding → no police coverage at all CHECK(c100 > c50 && c50 > c0); // under-funding strictly degrades coverage CHECK(c150 > c100 && c150 < c100 * 3 / 2); // over-funding helps with diminishing returns
// Electricity maintenance record 11 drives the same common efficiency curve in the live phase. CHECK(powered_tiles_at(0) == 0); CHECK(powered_tiles_at(50) == 22); CHECK(powered_tiles_at(100) == 44); CHECK(powered_tiles_at(150) == 52);
// The native water-department appropriation drives local source capacity in both the live // phase and paused edit-time recomputes. CHECK(watered_buildings_at(0) == 0); CHECK(watered_buildings_at(50) == 25); CHECK(watered_buildings_at(100) == 50); CHECK(watered_buildings_at(150) == 59);
// The new effectiveness seam is currently a fully-funded identity over the live appropriation. { City c; c.set_budget_rate(5, 73); sim::MunicipalDebt debt; sim::OperatingBudgetState operatingBudget; operatingBudget.coverageBasisPoints = 5000; Simulation sim(c, debt, operatingBudget); const sim::OperatingFundingSnapshot funding = sim.operating_funding_snapshot(); CHECK(funding.coverageBasisPoints == 5000); CHECK(funding.band == sim::OperatingFundingBand::Rationed); CHECK(funding.rate(5) == 36); CHECK(funding.funding_basis_points(5) == 3650); CHECK(funding.efficiency_basis_points(5) == 3650); CHECK(&sim.operating_budget_state() == &operatingBudget); }
// Transit receives the exact same cash-rationed snapshot at the live Simulation boundary. // Private-car cost remains full while the three operated modes retain fractional funding. { City city; city.set_budget_rate(10, 50); city.set_budget_rate(13, 150); city.set_budget_rate(14, 80); sim::MunicipalDebt debt; sim::OperatingBudgetState operating; operating.coverageBasisPoints = 5000; Simulation simulation(city, debt, operating); const CommuteRouteConfig config = simulation.commute_route_config(); CHECK(config.serviceEfficiency.basis_points(CommuteTravelMode::Car) == 10000); CHECK(config.serviceEfficiency.basis_points(CommuteTravelMode::Bus) == 2500); CHECK(config.serviceEfficiency.basis_points(CommuteTravelMode::Rail) == 7500); CHECK(config.serviceEfficiency.basis_points(CommuteTravelMode::Subway) == 4000); }
if (failures == 0) std::printf("funding: all checks passed\n"); else std::printf("funding: %d FAILED\n", failures); return failures ? 1 : 0;}