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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118// Verifies the scenario system (sim/scenario.hpp + the loader's SCEN/TEXT capture + the tick-22 win/lose// check): goal-block parsing against the real bundled scenarios, and the evaluator's win / lose-timeout /// bankruptcy outcomes. The parse checks need the game's SCENARIO/ folder; the evaluator checks are pure.#include "sc2k/sim/scenario.hpp"#include "sc2k/sim/disaster_sched.hpp"#include "sc2k/io/sc2_file.hpp"#include "sc2k/render/asset_loader.hpp"#include <cstdio>#include <fstream>
using namespace sc2k;
#include "test_harness.hpp"#include "test_paths.hpp"
int main() { // ---- Evaluator logic (pure, no assets) ---- { ScenarioGoals g; g.active = true; g.citySize = 20000; g.timeLimitMonths = 12; ScenarioStats s; s.fundsBaseline = 0; // Below the goal, time ticking down. s.population = 1700; s.funds = 1000; CHECK(scenario_evaluate(g, s) == ScenarioResult::Playing); CHECK(g.timeLimitMonths == 11); // decremented on an unmet tick // Meet the goal → win (time stops mattering). s.population = 20000; CHECK(scenario_evaluate(g, s) == ScenarioResult::Win); // Run the clock out while unmet → lose on timeout. ScenarioGoals g2; g2.active = true; g2.citySize = 999999; g2.timeLimitMonths = 1; ScenarioStats s2; s2.population = 0; CHECK(scenario_evaluate(g2, s2) == ScenarioResult::LoseTime); // Bankruptcy is a game-over regardless of goals / scenario. ScenarioStats sb; sb.funds = -100001; ScenarioGoals none; // inactive CHECK(scenario_evaluate(none, sb) == ScenarioResult::LoseBankrupt); ScenarioStats sok; sok.funds = -50000; CHECK(scenario_evaluate(none, sok) == ScenarioResult::Playing); // inactive city just plays on }
// ---- Real .SCN parsing (needs the game's SCENARIO/ folder) ---- const std::string scenDir = scenario_dir(); if (!exists(scenDir + "FLINT.SCN")) { std::printf("scenario: parse checks SKIPPED (no SCENARIO/ folder)\n"); } else { struct Want { const char* name; int time; long size, ind, cash; }; const Want wants[] = { {"FLINT", 60, 0, 21000, 0}, // grow industry to 21,000 {"DULLSVIL", 121, 20000, 0, 5000}, // grow the town to 20,000 + bank $5,000 {"HOLLYWOO", 60, 100000, 0, 0}, // survive the monster, reach 100,000 }; for (const auto& w : wants) { City c; CHECK(io::load_sc2(scenDir + w.name + std::string(".SCN"), c).ok); CHECK(!c.scen.empty()); // the SCEN chunk was captured const ScenarioGoals g = parse_scen(c.scen); CHECK(g.active); CHECK(g.timeLimitMonths == w.time); CHECK(g.citySize == w.size); CHECK(g.ind == w.ind); CHECK(g.cash == w.cash); std::printf(" %-9s time=%dmo size=%ld ind=%ld cash=%ld disaster=%d brief=%zuB\n", w.name, g.timeLimitMonths, g.citySize, g.ind, g.cash, g.disasterId, c.briefing.size()); } // Hollywood scripts a monster (disaster id 8) at the studio lot (80,52) — the SCEN X/Y bytes. City hw; CHECK(io::load_sc2(scenDir + "HOLLYWOO.SCN", hw).ok); const ScenarioGoals hg = parse_scen(hw.scen); CHECK(hg.disasterId == 8); CHECK(hg.disasterX == 80 && hg.disasterY == 52);
// The scripted disaster fires AT the scripted epicentre (LoadScenario → SimulationPrepareDisaster // → the creator reads it back): San Francisco's type-6 quake must strike its SCEN (41,61), not a // random roll — start_earthquake records the epicentre it used in d.epiX/epiY (auto-goto anchor). City sf; CHECK(io::load_sc2(scenDir + "SANFRANC.SCN", sf).ok); const ScenarioGoals sg = parse_scen(sf.scen); CHECK(sg.disasterId == 6); CHECK(sg.disasterX == 41 && sg.disasterY == 61); sim::DisasterSim d; MsRand rng(1234); CHECK(sim::start_disaster_type(sf, d, rng, sg.disasterId, sg.disasterX, sg.disasterY)); CHECK(d.active && d.type == 6); CHECK(d.epiX == 41 && d.epiY == 61); // Portland's scripted disaster is the volcano (0xB) at (60,53) — a type the old partial trigger // dropped entirely; the dispatcher must arm the eruption at the scripted vent. City pd; CHECK(io::load_sc2(scenDir + "PORTLAND.SCN", pd).ok); const ScenarioGoals pg = parse_scen(pd.scen); CHECK(pg.disasterId == 0xB); sim::DisasterSim dv; MsRand rngv(99); CHECK(sim::start_disaster_type(pd, dv, rngv, pg.disasterId, pg.disasterX, pg.disasterY)); CHECK(dv.active && dv.type == 0x0B); CHECK(dv.volcanoX == 60 && dv.volcanoY == 53); }
if (failures == 0) std::printf("scenario: all checks passed\n"); else std::printf("scenario: %d FAILED\n", failures); return failures ? 1 : 0;}