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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163// Population window data KAT (ui/graph_view.hpp): the 20-bracket age-distribution series for each radio// mode, read from the MISC histograms (pRawPopTable/pEQTable/pLETable @ dwords 31-90). Health = LE per// bracket (pLETable/pop). Verified against LONDON. Skips without the city.#include "sc2k/io/sc2_file.hpp"#include "sc2k/render/asset_loader.hpp"#include "sc2k/ui/graph_view.hpp"#include <cstdint>#include <cstdio>#include <fstream>#include <string>
#include "test_harness.hpp"#include "test_paths.hpp"int main() { using namespace sc2k; CHECK(i18n::load_locale(render::assets_dir() + "/lang", "en")); sim::AnnualDemographicsState annual; annual.ages[0] = {3, 6, 240}; annual.ages[4] = {1, 100, 60}; annual.ages[5] = {7, 350, 490}; const sim::AnnualDemographicsDiagnostics diagnostics = sim::annual_demographics_diagnostics(annual); const ui::PopulationViewModel view = ui::population_view_model(diagnostics); const auto& annualPopulation = ui::population_series(view, 0); const auto& annualHealth = ui::population_series(view, 1); const auto& annualEducation = ui::population_series(view, 2); CHECK(annualPopulation[0] == 36'363'636 && annualPopulation[1] == 63'636'363); CHECK(annualHealth[0] == 70 && annualHealth[1] == 70); CHECK(annualEducation[0] == 51 && annualEducation[1] == 50); CHECK(annualPopulation[18] == 0 && annualPopulation[19] == 0); CHECK(view.workforce == diagnostics.workforce); CHECK(view.schoolAges == diagnostics.schoolAges); CHECK(view.collegeAges == diagnostics.collegeAges); CHECK(view.libraryMuseumAges == diagnostics.libraryMuseumAges);
CHECK(ui::population_chart_maximum(0) == 15'000'000); CHECK(ui::population_chart_maximum(1) == 100); CHECK(ui::population_chart_maximum(2) == 150); const ui::PopulationChartTicks populationTicks = ui::population_chart_ticks(0); const ui::PopulationChartTicks healthTicks = ui::population_chart_ticks(1); const ui::PopulationChartTicks educationTicks = ui::population_chart_ticks(2); CHECK(populationTicks.count == 4 && populationTicks.values[0] == 0 && populationTicks.values[3] == 15'000'000); CHECK(healthTicks.count == 11 && healthTicks.values[10] == 100); CHECK(educationTicks.count == 9 && educationTicks.values[7] == 140 && educationTicks.values[8] == 150); const ui::PopulationChartGeometry geometry = ui::population_chart_geometry(700, 390); CHECK(geometry.plotX == 58 && geometry.plotY == 32); CHECK(geometry.plotWidth == 632 && geometry.plotHeight == 212); CHECK(geometry.workforceX == 185 && geometry.workforceWidth == 289); CHECK(geometry.summaryY == 266 && geometry.summaryHeight == 58); CHECK(geometry.buttonY == 332 && geometry.buttonHeight == 48); const ui::PopulationChartContent content = ui::population_chart_content(view, 0); CHECK(content.unit == "Share of residents"); CHECK(content.workforceBand == "Workforce ages 20–65"); CHECK(content.residents.find("11") != std::string::npos);
const std::string fontPath = render::assets_dir() + "/fonts/NotoSans-Regular.ttf"; if (exists(fontPath)) { sim::AnnualDemographicsState uniform; for (auto& age : uniform.ages) age = {1, 50, 75}; const ui::PopulationViewModel uniformView = ui::population_view_model( sim::annual_demographics_diagnostics(uniform)); ui::Font font(fontPath, 15); render::Framebuffer frame(700, 390); ui::draw_population_chart(frame, font, uniformView, 0); constexpr render::Rgba workforceColor{0xFF, 0xF3, 0xC4, 0xFF}; constexpr render::Rgba summaryColor{0xEB, 0xEF, 0xF2, 0xFF}; CHECK(frame.at(geometry.workforceX + 3, geometry.plotY + 5) == workforceColor); CHECK(frame.at(300, geometry.summaryY + 5) == summaryColor); CHECK(frame.at(5, geometry.buttonY + 8) == ui::theme::kTitle); const int firstX = geometry.plotX + 2 + 2 * (geometry.plotWidth - 4) / 100; const int firstValue = ui::population_series(uniformView, 0)[0]; const int firstY = geometry.plotY + geometry.plotHeight - 2 - static_cast<int>(std::int64_t(firstValue) * (geometry.plotHeight - 4) / ui::kPopulationChartMaximum); CHECK(frame.at(firstX, firstY) == ui::population_chart_line_color(0));
for (const char* locale : {"en", "uk"}) { CHECK(i18n::load_locale( render::assets_dir() + "/lang", locale)); for (int mode = 0; mode < 3; ++mode) { const ui::PopulationChartContent localized = ui::population_chart_content(uniformView, mode); const int workforceLegendX = geometry.plotX + font.text_width(localized.title) + 18; const int workforceLegendEnd = workforceLegendX + 14 + font.text_width(localized.workforceBand); const int unitX = std::max(geometry.plotX, 700 - 10 - font.text_width(localized.unit)); CHECK(workforceLegendEnd + 8 < unitX); const int summaryColumnWidth = 700 / 2 - 16; CHECK(font.text_width(localized.residents) < summaryColumnWidth); CHECK(font.text_width(localized.workforce) < summaryColumnWidth); CHECK(font.text_width(localized.workforceMetrics) < summaryColumnWidth); CHECK(font.text_width(localized.serviceAges) < summaryColumnWidth); } } }
annual = {}; annual.ages[0].population = 1; annual.ages[5].population = 999; const ui::PopulationViewModel lowPopulationView = ui::population_view_model( sim::annual_demographics_diagnostics(annual)); CHECK(ui::population_series(lowPopulationView, 0)[0] == ui::kPopulationChartPositiveFloor);
const std::string p = city_file("LONDON.SC2"); if (!exists(p)) { std::printf("popview: SKIP (no LONDON)\n"); return 0; } City c; CHECK(io::load_sc2(p, c).ok);
const auto pop = ui::population_series(c, 0); // headcount per age bracket const auto hp = ui::population_series(c, 1); // life expectancy per bracket // LONDON's known first brackets (verified vs the raw MISC tables). CHECK(pop[0] == 11218 && pop[1] == 10745 && pop[2] == 10292); CHECK(pop[12] == 14629); // the peak bracket int argmax = 0; for (int i = 1; i < 20; ++i) if (pop[i] > pop[argmax]) argmax = i; CHECK(argmax == 12); // Health = life expectancy = pLETable/pop ≈ 86 for the youngest bracket (a sane LE). CHECK(hp[0] >= 80 && hp[0] <= 95); // Education mode is also populated, non-negative. const auto eq = ui::population_series(c, 2); CHECK(eq[0] > 0); std::printf("popview: LONDON brackets pop[0]=%d peak[12]=%d LE[0]=%d — offsets verified\n", pop[0], pop[12], hp[0]);
if (failures == 0) { std::printf("popview: all checks passed\n"); return 0; } std::printf("popview: %d failure(s)\n", failures); return 1;}