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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899// Read-out dialog data-binding KAT (ui/data_views.hpp): the Budget (102) and Ordinances (119) value// maps reproduce the original's owner-draw fills. We don't eyeball renders — we check the numeric// invariants of the binding against a real saved city (the project rule: verify numerically). Skips if// the assets / cities aren't present.#include "sc2k/io/sc2_file.hpp"#include "sc2k/render/asset_loader.hpp"#include "sc2k/ui/data_views.hpp"#include "sc2k/ui/resources.hpp"#include <cstdio>#include <fstream>#include <string>
#include "test_harness.hpp"#include "test_paths.hpp"
static int geti(const std::map<int, std::string>& m, int id) { auto it = m.find(id); return it == m.end() ? 0 : std::atoi(it->second.c_str());}static bool has(const std::map<int, std::string>& m, int id) { return m.count(id) != 0; }static std::string nth_line(const std::string& s, int n) { // 0-based line of a \n-joined value std::size_t a = 0; for (int i = 0; i < n; ++i) { a = s.find('\n', a); if (a == std::string::npos) return ""; ++a; } const std::size_t b = s.find('\n', a); return s.substr(a, b == std::string::npos ? b : b - a);}
int main() { using namespace sc2k; const std::string adir = render::assets_dir(); const std::string city_path = city_file("LONDON.SC2"); if (!exists(adir + "/ui/dialogs.txt") || !exists(city_path)) { std::printf("data_views: SKIP (need assets/ui/dialogs.txt + CITIES/LONDON.SC2)\n"); return 0; }
City city; if (const auto lr = io::load_sc2(city_path, city); !lr.ok) { std::printf("data_views: load failed: %s\n", lr.error.c_str()); return 1; } ui::DialogSet dialogs; dialogs.load(adir + "/ui/dialogs.txt");
// ── Budget (102) ──────────────────────────────────────────────────────────────────────────── { const auto v = ui::budget_values(city, 1950, 5, "Jun", "London"); // Every row's two columns + the summary controls are present. for (int id : {101, 305, 306, 200, 207, 210, 217, 102, 104, 108, 132, 133}) CHECK(has(v, id)); const int funds = city.funds(); // Summary box line 3 = current funds; End-of-Year (132) = funds + estimated cashflow (line 2). CHECK(std::atoi(nth_line(v.at(133), 2).c_str()) == funds); const int est = std::atoi(nth_line(v.at(133), 1).c_str()); CHECK(geti(v, 132) == funds + est); // Property ToDate (200) folds records 0-2 exactly (the binary's grouping). static const int kDiv[16] = {75, 75, 75, 75, -100, -1, -1, -2, -4, -1, -1000, -500, -400, -250, -250, -250}; int pTo = 0; for (int r = 0; r < 3; ++r) pTo += city.budget_revenue(r) / (12 * kDiv[r]); CHECK(geti(v, 200) == pTo); // YTD cashflow (133 line 1) = (Σ_16 rev/div)/12 — the per-row/summary consistency. int ytdSum = 0; for (int r = 0; r < 16; ++r) ytdSum += city.budget_revenue(r) / kDiv[r]; CHECK(std::atoi(nth_line(v.at(133), 0).c_str()) == ytdSum / 12); std::printf("data_views: Budget London — funds %d, EOY %d, YTD cashflow %s\n", funds, geti(v, 132), nth_line(v.at(133), 0).c_str()); }
// ── Ordinances (119) ──────────────────────────────────────────────────────────────────────── if (const ui::Dialog* d = dialogs.get(119)) { const auto v = ui::ordinance_values(*d, city); for (int id : {192, 193, 194, 195, 197, 201, 202}) CHECK(has(v, id)); CHECK(geti(v, 201) == geti(v, 202)); // YTD == Estimated (net annual) // Category subtotals reproduce ordinance_cost/75 for the enacted bits (cat = bit/4). const std::uint32_t ord = city.ordinances(); const int r10 = city.budget_value(0), c10 = city.budget_value(1), i10 = city.budget_value(2); int cat[5] = {0, 0, 0, 0, 0}; for (int b = 0; b < 20; ++b) if (ord & (1u << b)) cat[b / 4] += ordinance_cost(b, r10, c10, i10, r10, 0); CHECK(geti(v, 192) == cat[0] / 75); // Finance (bits 0–3) CHECK(geti(v, 193) == cat[1] / 75); // Safety & Health (bits 4–7) CHECK(geti(v, 194) == cat[2] / 75); // Education (bits 8–11) CHECK(geti(v, 195) == cat[3] / 75); // Promotional (bits 12–15) CHECK(geti(v, 197) == cat[4] / 75); // Other (bits 16–19) std::printf("data_views: Ordinances London — Finance %d, net %d\n", geti(v, 192), geti(v, 201)); } else CHECK(false);
if (failures == 0) { std::printf("data_views: all checks passed\n"); return 0; } std::printf("data_views: %d failure(s)\n", failures); return 1;}