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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245// City Map overview KAT (render/minimap.hpp): the per-tile palette index reproduces the original's Map fill, and on// a real city the rendered water matches the source water tiles (numeric, not eyeballed). Skips without// assets/cities.#include "sc2k/io/sc2_file.hpp"#include "sc2k/render/asset_loader.hpp"#include "sc2k/render/minimap.hpp"#include "../app/minimap_resample.hpp"#include <cstdio>#include <fstream>#include <string>
#include "test_harness.hpp"#include "test_paths.hpp"int main() { using namespace sc2k; using render::minimap_index; // The exact index rules from the original. CHECK(minimap_index(0x20, 0, 0) == 0); // developed building (XBLD>=0x0D) → 0 CHECK(minimap_index(0x0D, 0, 0) == 0); CHECK(minimap_index(0x0C, 0, 0) == 67); // structure (6..12) → 67 CHECK(minimap_index(6, 0, 0) == 67); CHECK(minimap_index(5, 0, 0) == 53); // feature (1..5) → 53 CHECK(minimap_index(1, 0, 0) == 53); CHECK(minimap_index(0, 0x04, 0) == 98); // empty + XBIT&4 → water (98) CHECK(minimap_index(0, 0, 0) == 128); // empty terrain, alt 0 → 128 - 0 CHECK(minimap_index(0, 0, 16) == 116); // alt 16 → 128 - 12 CHECK(minimap_index(0, 0, 20) == 116); // alt (20 & 0x1F = 20) clamps to 16 → 128 - 12 CHECK(minimap_index(0x20, 0x04, 0) == 0); // XBLD wins over XBIT (building, not water)
// Fixed-size UI minimaps preserve the 128 map exactly and coverage-reduce larger maps. Point // sampling used to drop isolated tiles, including the final source edge, from 192/256 maps. { render::Framebuffer source(128, 128); source.set(127, 127, {17, 29, 43, 255}); const auto exact = app::sample_minimap_coverage(source, 127, 127, 128, 128); CHECK(exact.r == 17 && exact.g == 29 && exact.b == 43 && exact.a == 255); } for (const int dimension : {192, 256}) { render::Framebuffer source(dimension, dimension); const int isolated = dimension / 2 + 1; source.set(isolated, isolated, {255, 255, 255, 255}); source.set(dimension - 1, dimension - 1, {255, 255, 255, 255}); const int isolatedDestination = isolated * 128 / dimension; const auto covered = app::sample_minimap_coverage(source, isolatedDestination, isolatedDestination, 128, 128); CHECK(covered.r > 0 && covered.g > 0 && covered.b > 0 && covered.a > 0); const auto edge = app::sample_minimap_coverage(source, 127, 127, 128, 128); CHECK(edge.r > 0 && edge.g > 0 && edge.b > 0 && edge.a > 0); const auto untouched = app::sample_minimap_coverage(source, 126, 126, 128, 128); CHECK(untouched.r == 0 && untouched.g == 0 && untouched.b == 0 && untouched.a == 0); }
// Data views (Zones, Infrastructure). using render::MapView; CHECK(render::minimap_index_view(MapView::Zones, 0, 1, 0, 0) == 59); // R zone → idx 59 (green) CHECK(render::minimap_index_view(MapView::Zones, 0, 3, 0, 0) == 92); // C zone → 92 CHECK(render::minimap_index_view(MapView::Zones, 0, 5, 0, 0) == 50); // I zone → 50 CHECK(render::minimap_index_view(MapView::Zones, 0x20, 0, 0, 0) == 0); // unzoned building → structures colour CHECK(render::minimap_index_view(MapView::Infrastructure, 0x1d, 0, 0, 0) == 255); // a road → white CHECK(render::minimap_index_view(MapView::Infrastructure, 0x70, 0, 0, 0) == 0); // a building → not highlighted CHECK(render::is_transport_tile(0x1d) && render::is_transport_tile(0x3f) && !render::is_transport_tile(0x70)); CHECK(render::is_rail_tile(0x2c) && render::is_rail_tile(0x3e) && !render::is_rail_tile(0x1d)); CHECK(render::is_power_tile(0x0e) && render::is_power_tile(0x1c) && !render::is_power_tile(0x70)); { // Power view: power tile white, powered building → 50, conductive → 29. City pc; pc.xbld.at(7, 7) = 0x80; pc.xbit.at(7, 7) = 0x40; // a powered building CHECK(render::view_index(pc, render::MapView::Power, 7, 7) == 50); pc.xbld.at(8, 8) = 0x0e; // a power line → white CHECK(render::view_index(pc, render::MapView::Power, 8, 8) == 255); // Water view: a piped/subway underground tile → white. pc.xund.at(9, 9) = 0x12; CHECK(render::view_index(pc, render::MapView::Water, 9, 9) == 255); } CHECK(int(render::MapView::Count) == 19); // faithful 12 + our derived/service layers { // Growth view: XROG growth rate → declining/neutral/growing City gc; gc.xrog.at(0, 0) = 0x70; CHECK(render::view_index(gc, render::MapView::Growth, 0, 0) == 29); // ≤0x7C decline gc.xrog.at(0, 0) = 0x80; CHECK(render::view_index(gc, render::MapView::Growth, 0, 0) == 128); // neutral → base (empty,alt0) gc.xrog.at(0, 0) = 0x90; CHECK(render::view_index(gc, render::MapView::Growth, 0, 0) == 67); // ≥0x83 growth } // Heat-map views (Traffic etc.): high nibble → (field>>4)-101 grey ramp, else base. { City hc; hc.xtrf.at(5, 5) = 0xF0; // peak traffic at downsampled (5,5) CHECK(render::heatmap_index(hc, render::MapView::Traffic, 10, 10) == std::uint8_t(0xF - 101)); // = 170 hc.xtrf.at(5, 5) = 0; CHECK(render::heatmap_index(hc, render::MapView::Traffic, 10, 10) == 128); // no traffic → terrain base hc.xfir.at(2, 2) = 0xD0; const sim::ServiceCoverageDiagnostics coverage = sim::service_coverage_diagnostics(hc); CHECK(render::heatmap_index(hc, render::MapView::FireCoverage, 10, 10) == 128); CHECK(render::heatmap_index(hc, render::MapView::FireCoverage, 10, 10, nullptr, &coverage) == 167); } { // Native water pollution consumes only the validated WPOL diagnostic. Missing diagnostics fail // closed to the Structures colour; the 2x2 authority cell projects identically to all four tiles. City wc{MapSize::Tiny}; auto state = sim::make_water_pollution_state( wc.dimension(), wc.dimension()); CHECK(state.has_value()); if (state) { CHECK(sim::set_water_pollution(*state, 8, 10, sim::kExpectedMaximumWaterPollution)); const sim::WaterPollutionDiagnostics diagnostics = sim::water_pollution_diagnostics(*state); CHECK(diagnostics.ok()); CHECK(render::view_index(wc, render::MapView::WaterPollution, 8, 10) == 128); CHECK(render::view_index(wc, render::MapView::WaterPollution, 8, 10, &diagnostics) == 170); CHECK(render::view_index(wc, render::MapView::WaterPollution, 9, 11, &diagnostics) == 170); CHECK(render::view_index(wc, render::MapView::WaterPollution, 10, 10, &diagnostics) == 128); const render::Framebuffer waterPollution = render::render_minimap(wc, render::MapView::WaterPollution, nullptr, &diagnostics); CHECK(waterPollution.at(8, 10) == render::minimap_color(170)); CHECK(waterPollution.at(10, 10) == render::minimap_color(128)); } } { // Live satisfaction consumes only active CIVC diagnostics and repeats each authoritative 4x4 // cell across its full-resolution tiles. Dormant authority remains presentation-invisible. City sc{MapSize::Tiny}; auto state = sim::make_civic_satisfaction_state( sc.dimension(), sc.dimension(), 123, {}, 0); CHECK(state.has_value()); if (state) { CHECK(sim::set_civic_satisfaction(*state, 8, 12, 10000)); const sim::CivicSatisfactionDiagnostics diagnostics = sim::civic_satisfaction_diagnostics(*state); CHECK(diagnostics.active()); CHECK(render::view_index(sc, render::MapView::Satisfaction, 8, 12) == 128); CHECK(render::view_index(sc, render::MapView::Satisfaction, 8, 12, nullptr, nullptr, &diagnostics) == 185); CHECK(render::view_index(sc, render::MapView::Satisfaction, 11, 15, nullptr, nullptr, &diagnostics) == 185); CHECK(render::view_index(sc, render::MapView::Satisfaction, 12, 12, nullptr, nullptr, &diagnostics) == 178); } } { // Flammability (our own layer): water/bare never burn; trees ramp with density; the zone class // sets a building's base; fire coverage (XFIR, quarter-res) damps it by half its strength. City fc; fc.xbit.at(0, 0) = 0x04; // water CHECK(render::flammability_field(fc, 0, 0) == 0); CHECK(render::flammability_field(fc, 1, 1) == 0); // bare ground fc.xbld.at(1, 1) = 0x02; // rubble — already burnt CHECK(render::flammability_field(fc, 1, 1) == 0); fc.xbld.at(2, 2) = xbld::kTreeFirst; // lightest trees CHECK(render::flammability_field(fc, 2, 2) == 176); fc.xbld.at(3, 3) = xbld::kTreeLast; // veritable jungle CHECK(render::flammability_field(fc, 3, 3) == 224); fc.xbld.at(4, 4) = 0x70; fc.xzon.at(4, 4) = 5; // industrial building — worst CHECK(render::flammability_field(fc, 4, 4) == 208); fc.xzon.at(4, 4) = 1; // residential CHECK(render::flammability_field(fc, 4, 4) == 176); fc.xfir.at(1, 1) = 200; // a fire station covers (4..7,4..7) CHECK(render::flammability_field(fc, 4, 4) == 76); // 176 - 200/2 // The heat ramp picks it up like any faithful field view. CHECK(render::heatmap_index(fc, render::MapView::Flammability, 3, 3) == std::uint8_t((224 >> 4) - 101)); } { // Desirability (our own layer): land value dragged down by (pollution + crime)/2, clamped. City dc; dc.xval.at(3, 3) = 200; CHECK(render::desirability_field(dc, 6, 6) == 200); dc.xplt.at(3, 3) = 100; dc.xcrm.at(3, 3) = 60; CHECK(render::desirability_field(dc, 6, 6) == 120); // 200 - (100+60)/2 dc.xplt.at(3, 3) = 255; dc.xcrm.at(3, 3) = 255; CHECK(render::desirability_field(dc, 6, 6) == 0); // clamped at the floor CHECK(render::heatmap_index(dc, render::MapView::Desirability, 6, 6) == 128); // 0 → terrain base }
const std::string city_path = city_file("LONDON.SC2"); if (!have_render_assets() || !exists(city_path)) { std::printf("minimap: index rules OK; SKIP city render (no assets/LONDON)\n"); return failures ? 1 : 0; } City city; CHECK(io::load_sc2(city_path, city).ok); const auto mm = render::render_minimap(city); CHECK(mm.width() == 128 && mm.height() == 128); // Rendered water must sit on the source water tiles: same centroid. long wx = 0, wy = 0, wn = 0, bx = 0, by = 0, bn = 0; for (int y = 0; y < 128; ++y) for (int x = 0; x < 128; ++x) { const auto p = mm.at(x, y); if (p.r == render::MinimapColors::Water.r && p.g == render::MinimapColors::Water.g && p.b == render::MinimapColors::Water.b) { wx += x; wy += y; ++wn; } if (city.xbit.at(x, y) & 4) { bx += x; by += y; ++bn; } } CHECK(wn > 100 && bn > 100); CHECK(wn <= bn); // water pixels ⊆ XBIT&4 (buildings override) CHECK(std::abs(wx / wn - bx / bn) <= 1 && std::abs(wy / wn - by / bn) <= 1); // same centroid std::printf("minimap: LONDON water px=%ld centroid=(%ld,%ld) — matches source (%ld,%ld)\n", wn, wx / wn, wy / wn, bx / bn, by / bn); { // Our composite layers on a real city: a built-up town must burn somewhere and be worth // living in somewhere, and water must never be flammable. long flam = 0, wantWater = 0, desir = 0; for (int y = 0; y < 128; ++y) for (int x = 0; x < 128; ++x) { const int f = render::flammability_field(city, x, y); if (f > 0) ++flam; if ((city.xbit.at(x, y) & 4) && f != 0) ++wantWater; if (render::desirability_field(city, x, y) > 0) ++desir; } CHECK(flam > 1000); // LONDON is mostly buildings + parkland CHECK(wantWater == 0); // the Thames does not catch fire CHECK(desir > 1000); // land value dominates most of the map std::printf("minimap: LONDON flammable tiles=%ld desirable tiles=%ld\n", flam, desir); }
if (failures == 0) { std::printf("minimap: all checks passed\n"); return 0; } std::printf("minimap: %d failure(s)\n", failures); return 1;}