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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465// Trees tool KAT (ui/tools.hpp place_trees): empty → sapling (6/7), repeated touches// grow it up the chain (≤12); refuses water / occupied tiles. Numeric, no SDL.#include "sc2k/city.hpp"#include "sc2k/ui/tools.hpp"#include <cstdio>#include "test_harness.hpp"int main() { using namespace sc2k; City c; // flat empty c.set_funds(20000); // apply_tool needs funds ≥ cost // first plant → sapling 6 or 7 CHECK(ui::apply_tool(c, ui::Tool::Trees, 10, 10).ok); CHECK(c.xbld.at(10, 10) == 6 || c.xbld.at(10, 10) == 7); // repeated touches grow density toward 12, never beyond for (int k = 0; k < 10; k++) ui::apply_tool(c, ui::Tool::Trees, 10, 10); CHECK(c.xbld.at(10, 10) >= 6 && c.xbld.at(10, 10) <= 12); // water refuses c.xbit.at(20, 20) |= 0x04; CHECK(!ui::apply_tool(c, ui::Tool::Trees, 20, 20).ok); // occupied (a building) refuses c.xbld.at(30, 30) = 0x40; CHECK(!ui::apply_tool(c, ui::Tool::Trees, 30, 30).ok); // cost is $3 (cost-table group 1 / Trees+Water, variant 0; matches manual p.55) CHECK(ui::tool_cost(ui::Tool::Trees) == 3);
// --- Water tool (group 1 subtool 1): lay water, autotile, de-zone; $100 --- City w; w.set_funds(20000); CHECK(ui::apply_tool(w, ui::Tool::Water, 40, 40).ok); CHECK(w.xbit.at(40, 40) & 0x04); // tile is now water CHECK(w.xbld.at(40, 40) == 0); // building cleared CHECK(w.xter.at(40, 40) >= 0x30 && w.xter.at(40, 40) <= 0x45); // a water-surface XTER code CHECK(!ui::apply_tool(w, ui::Tool::Water, 40, 40).ok); // can't re-water w.xbld.at(50, 50) = 0x40; // occupied refuses CHECK(!ui::apply_tool(w, ui::Tool::Water, 50, 50).ok); CHECK(ui::tool_cost(ui::Tool::Water) == 100); // cost-table group 1 variant 1 (Water; manual p.55)
// --- Water LEVEL: the surface sits flush with the land (the original sets ALTM water-level = ground // altitude), NOT at the map floor — the user-reported "massive hole with water at the bottom" bug. --- City wl; wl.set_funds(20000); const std::size_t i = std::size_t(45) * 128 + 45; wl.altm.cells[i] = 7; // ground altitude 7, water level 0 CHECK(ui::apply_tool(wl, ui::Tool::Water, 45, 45).ok); CHECK((wl.altm.cells[i] & 0x1F) == 7); // ground unchanged, CHECK(((wl.altm.cells[i] >> 5) & 0x1F) == 7); // water level now == ground (flush — was 0)
// --- Water on a SLOPE becomes a waterfall (XTER 0x3e), not a flat pool. --- City wf; wf.set_funds(20000); wf.xter.at(46, 46) = 0x03; // a cardinal slope wf.altm.cells[std::size_t(46) * 128 + 46] = 5; CHECK(ui::apply_tool(wf, ui::Tool::Water, 46, 46).ok); CHECK(wf.xter.at(46, 46) == 0x3e); // the waterfall code (0x0e + 0x30) CHECK(wf.xbit.at(46, 46) & 0x04); // and it's now water CHECK(((wf.altm.cells[std::size_t(46) * 128 + 46] >> 5) & 0x1F) == 5); // level set here too
if (failures == 0) { std::printf("trees+water: all checks passed\n"); return 0; } std::printf("trees+water: %d failure(s)\n", failures); return 1;}