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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111// sc2k/debug/overlay.hpp — the *selection + colour* half of the in-world debug field overlays (the// drawing half is render/overlay_draw.hpp). Given an ORIGINAL (unrotated) tile, it returns the palette// index to tint it with, or -1 for "leave the real city showing here". Pure (no Framebuffer/SDL) so it// is unit-testable against the City Map.//// TWO things to know (both verified against the source, both easy to get wrong):// 1. Coordinates are UNROTATED. rotate_once() does NOT rotate the coarse field layers (XFIR/XPLC/XCRM/// …), so the overlay must sample the original `city` — the caller maps view→original first// (render/rotate.hpp view_tile_to_original). Sampling the rotated `view` would be wrong for any// rotation != 0.// 2. XFIR/XPLC are FULL-BYTE magnitudes (coverage.hpp, saturating 0..255), NOT nibble-packed like the// heat fields. The City Map's `(field>>4)` ramp would crush most coverage to blank, so Fire/Police// get a dedicated full-byte ramp here. Every other field delegates to the City Map's own// render::view_index so the overlay and the Map window agree exactly.#pragma once#include <array>#include <cstdint>#include "sc2k/city.hpp"#include "sc2k/debug/field_stats.hpp"#include "sc2k/render/minimap.hpp"
namespace sc2k::debug {
enum class OverlayField { None, Fire, Police, Crime, Pollution, LandValue, Traffic, Density, Growth, Power, Water, Count };
inline const char* overlay_field_name(OverlayField f) { switch (f) { case OverlayField::Fire: return "Fire Coverage"; case OverlayField::Police: return "Police Coverage"; case OverlayField::Crime: return "Crime"; case OverlayField::Pollution: return "Pollution"; case OverlayField::LandValue: return "Land Value"; case OverlayField::Traffic: return "Traffic"; case OverlayField::Density: return "Density"; case OverlayField::Growth: return "Growth"; case OverlayField::Power: return "Power Grid"; case OverlayField::Water: return "Water Pipes"; default: return "Off"; }}
// Cycle to the next overlay (F3): None → Fire → … → Water → None.inline OverlayField next_overlay(OverlayField f) { return OverlayField((static_cast<int>(f) + 1) % static_cast<int>(OverlayField::Count));}
// The City Map view that a (non-coverage) overlay field delegates to — so the colours match exactly.inline render::MapView overlay_mapview(OverlayField f) { switch (f) { case OverlayField::Crime: return render::MapView::Crime; case OverlayField::Pollution: return render::MapView::Pollution; case OverlayField::LandValue: return render::MapView::Value; case OverlayField::Traffic: return render::MapView::Traffic; case OverlayField::Density: return render::MapView::Density; case OverlayField::Growth: return render::MapView::Growth; case OverlayField::Power: return render::MapView::Power; case OverlayField::Water: return render::MapView::Water; default: return render::MapView::Structures; }}
// Palette index to tint ORIGINAL tile (row,col) with for field `f`, or -1 = no tint (show the city).inline int overlay_palette_index(const City& c, OverlayField f, int row, int col) { if (f == OverlayField::None) return -1; if (f == OverlayField::Fire || f == OverlayField::Police) { // Full-byte coverage strength → the same 156..170 heat band the City Map uses, but ramped // over the WHOLE byte (so a strength of e.g. 6 still shows, instead of (6>>4)=0 → blank). const int b = (f == OverlayField::Fire) ? c.xfir.at(row / 4, col / 4) : c.xplc.at(row / 4, col / 4); if (b <= 0) return -1; const int step = 1 + (b * 14) / 255; // 1..15 (light→dark = low→high coverage) return 156 + step - 1; // → 156..170 } // Every other field: defer to the City Map's own per-tile index, and treat "would draw as plain // terrain/building" (== the base index) as transparent, so the overlay tints ONLY the field and // leaves the rendered city visible everywhere else. This makes the overlay agree with the Map // window pixel-for-pixel on the tiles it does tint. const std::uint8_t base = render::minimap_base_index(c.xbld.at(row, col), c.xbit.at(row, col), c.altm.at(row, col)); const std::uint8_t idx = render::view_index(c, overlay_mapview(f), row, col); return (idx == base) ? -1 : static_cast<int>(idx);}
// Field stats for the legend / HUD (the coverage and heat layers; Power/Water are categorical → empty).inline FieldStats overlay_field_summary(const City& c, OverlayField f) { switch (f) { case OverlayField::Fire: return field_stats(c.xfir); case OverlayField::Police: return field_stats(c.xplc); case OverlayField::Crime: return field_stats(c.xcrm); case OverlayField::Pollution: return field_stats(c.xplt); case OverlayField::LandValue: return field_stats(c.xval); case OverlayField::Traffic: return field_stats(c.xtrf); case OverlayField::Density: return field_stats(c.xpop); case OverlayField::Growth: return field_stats(c.xrog); default: return FieldStats{}; }}
} // namespace sc2k::debug