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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// Validates the tax-revenue formula against saved cities.//// The finance function accumulates `revenue += rate · value` per tick into each R/C/I budget record,// so the saved revenue (+104) must equal rate · value · (day-of-month). We confirm that the same// integer day-of-month explains all three R/C/I records of a city — a strong check that both the// pinned record offsets and the rate·value formula are correct.#include "sc2k/sim/budget.hpp"#include "sc2k/io/sc2_file.hpp"#include <cstdio>#include "test_paths.hpp"
#include "test_harness.hpp"
static void check_city(const char* name) { using namespace sc2k; std::string path = (cities_dir()) + name; City c; auto r = io::load_sc2(path, c); if (!r.ok) { std::printf(" %-13s skipped (%s)\n", name, r.error.c_str()); return; }
int rate[3], val[3]; long rev[3]; for (int s = 0; s < 3; ++s) { rate[s] = c.budget_rate(s); val[s] = c.budget_value(s); rev[s] = c.budget_revenue(s); } // The R/C/I tax rates must be sensible percentages — a wrong record offset would give garbage. for (int s = 0; s < 3; ++s) CHECK(rate[s] >= 0 && rate[s] <= 20);
if (rate[0] * val[0] <= 0) { std::printf(" %-13s rates(R/C/I)=%d/%d/%d (no R revenue)\n", name, rate[0], rate[1], rate[2]); return; } // revenue ≈ rate·value·(day-of-month); since value grows over the month the ratio is a plausible // tick count, and the same ratio should explain all three records. double ratio0 = double(rev[0]) / (double(rate[0]) * val[0]); std::printf(" %-13s rates(R/C/I)=%d/%d/%d revenue/(rate·value)≈%.2f ticks\n", name, rate[0], rate[1], rate[2], ratio0); CHECK(ratio0 >= 0.0 && ratio0 <= 26.0); for (int s = 1; s < 3; ++s) if (rate[s] * val[s] > 0) { double r = double(rev[s]) / (double(rate[s]) * val[s]); CHECK(r >= 0.0 && r <= 26.0 && (ratio0 < 0.5 || (r > ratio0 * 0.7 && r < ratio0 * 1.3))); }}
int main() { for (const char* n : {"TOKYO.SC2", "BAYVIEW.SC2", "LONDON.SC2", "NYC.SC2", "PARIS.SC2"}) check_city(n);
if (failures == 0) { std::printf("budget: all checks passed\n"); return 0; } std::printf("budget: %d failure(s)\n", failures); return 1;}