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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159// Validation of the Query-tool analyzer (ui/query.hpp build_query): names, the resource (power/water/// road/job) rows, and the abandonment-reason chain (no power → no road → can't reach jobs → no demand).// Deterministic (the job-access probe uses a fixed-seed RNG internally).#include "sc2k/ui/query.hpp"#include <cstdio>
#include "test_harness.hpp"
namespace {using namespace sc2k;
std::string row_value(const ui::QueryInfo& q, const std::string& label) { for (const auto& r : q.rows) if (r.label == label) return r.value; return "";}bool has_row(const ui::QueryInfo& q, const std::string& label) { for (const auto& r : q.rows) if (r.label == label) return true; return false;}const int kNoDemand[3] = {-1500, -1500, -1500};const int kHiDemand[3] = {1800, 1800, 1800};
// A building of zone-nibble `znib` (and optional XBLD `bcode`) at (30,30), powered + watered, with a road// run leading to BOTH an R and a C job zone — so a commute from R, C, or I all reach a job (high score).City connected(int znib, int bcode) { City c; c.xzon.at(30, 30) = std::uint8_t(znib); if (bcode) c.xbld.at(30, 30) = std::uint8_t(bcode); c.xbit.at(30, 30) = 0x40 | 0x10; // powered + watered for (int x = 31; x <= 35; ++x) c.xbld.at(30, x) = 0x1D; // a road run east c.xzon.at(30, 36) = 0x01; // an R job past the road end c.xzon.at(29, 35) = 0x03; // a C job beside the road return c;}} // namespace
int main() { using namespace sc2k;
// (1) Bare terrain / water / trees / loose rubble are NOT queryable. { City c; CHECK(!ui::build_query(c, 40, 40, kHiDemand).queryable); c.xbld.at(40, 40) = 8; CHECK(!ui::build_query(c, 40, 40, kHiDemand).queryable); // tree c.xbld.at(40, 40) = 3; CHECK(!ui::build_query(c, 40, 40, kHiDemand).queryable); // rubble, unzoned }
// (2) A road network tile IS queryable and names correctly. { City c; c.xbld.at(20, 20) = 0x1D; ui::QueryInfo q = ui::build_query(c, 20, 20, kHiDemand); CHECK(q.queryable); CHECK(q.title == "Road"); }
// (3) A developed, powered, watered R building WITH reachable jobs → all-good + "Stable". Labels match // the game (Powered/Watered). { ui::QueryInfo q = ui::build_query(connected(0x01, 130), 30, 30, kHiDemand); CHECK(q.queryable); CHECK(q.subtitle.find("Residential") != std::string::npos); CHECK(q.subtitle.find("low-density") != std::string::npos); CHECK(row_value(q, "Powered") == "Yes"); CHECK(row_value(q, "Watered") == "Yes"); CHECK(row_value(q, "Job access") == "Yes"); CHECK(row_value(q, "Outlook") == "Stable"); CHECK(has_row(q, "Land Value") && has_row(q, "Crime") && has_row(q, "Pollution") && has_row(q, "Altitude")); }
// (4) NO POWER → at risk, named via the red Powered row. { City c = connected(0x01, 130); c.xbit.at(30, 30) = 0; // strip power (keep road + jobs) ui::QueryInfo q = ui::build_query(c, 30, 30, kHiDemand); CHECK(row_value(q, "Powered") == "No"); CHECK(row_value(q, "Outlook") == "At risk of abandonment"); }
// (5) Powered but NO ROAD adjacent → can't reach jobs. { City c; c.xzon.at(30, 30) = 0x01; c.xbld.at(30, 30) = 130; c.xbit.at(30, 30) = 0x40; ui::QueryInfo q = ui::build_query(c, 30, 30, kHiDemand); CHECK(row_value(q, "Job access") == "No"); CHECK(row_value(q, "Outlook") == "At risk of abandonment"); }
// (6) A road is adjacent but there's NO reachable job → Job access No, at risk. { City c; c.xzon.at(30, 30) = 0x01; c.xbld.at(30, 30) = 130; c.xbit.at(30, 30) = 0x40 | 0x10; for (int x = 31; x <= 33; ++x) c.xbld.at(30, x) = 0x1D; // a short dead-end road, no jobs anywhere ui::QueryInfo q = ui::build_query(c, 30, 30, kHiDemand); CHECK(row_value(q, "Job access") == "No"); // jobs are unreachable CHECK(row_value(q, "Outlook") == "At risk of abandonment"); }
// (7) Eligible (powered + reachable) but low demand → NOT falsely warned (the bug the user caught): a // reachable, powered building reads "Stable", because that's what the sim does. { ui::QueryInfo q = ui::build_query(connected(0x01, 130), 30, 30, kNoDemand); CHECK(row_value(q, "Job access") == "Yes"); CHECK(row_value(q, "Outlook") == "Stable"); }
// (8) A zoned-but-VACANT lot: won't develop without power. { City c; c.xzon.at(30, 30) = 0x03; // empty C zone ui::QueryInfo q = ui::build_query(c, 30, 30, kHiDemand); CHECK(q.queryable); CHECK(q.title.find("Commercial") != std::string::npos); CHECK(row_value(q, "Outlook") == "Will not develop"); }
// (9) Names: density wording + civic + power-plant. { ui::QueryInfo q = ui::build_query(connected(0x02, 130), 30, 30, kHiDemand); CHECK(q.subtitle.find("high-density") != std::string::npos); City c2; c2.xbld.at(10, 10) = 210; CHECK(ui::build_query(c2, 10, 10, kHiDemand).title == "Police Station"); c2.xbld.at(11, 11) = 207; CHECK(ui::build_query(c2, 11, 11, kHiDemand).title == "Coal Power Plant"); }
// (10) An ABANDONED ruin (code 172) is named "Abandoned building", never "Stable" — eligible ⇒ // "Redeveloping"; no power ⇒ "Abandoned". { City c = connected(0x06, 172); // dense-I ruin, powered + road + jobs ui::QueryInfo q = ui::build_query(c, 30, 30, kHiDemand); CHECK(q.title == "Abandoned building"); CHECK(row_value(q, "Job access") == "Yes"); CHECK(row_value(q, "Outlook") == "Redeveloping");
City c2 = connected(0x06, 172); c2.xbit.at(30, 30) = 0; // strip power CHECK(row_value(ui::build_query(c2, 30, 30, kHiDemand), "Outlook") == "Abandoned");
c2.xbld.at(30, 30) = 164; // a legit (non-ruin) I building CHECK(ui::build_query(c2, 30, 30, kHiDemand).title != "Abandoned building"); }
if (failures == 0) std::printf("test_query: ALL CHECKS PASSED\n"); else std::printf("test_query: %d CHECK(S) FAILED\n", failures); return failures ? 1 : 0;}