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.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364// New-game terrain generator KAT (sim/terrain_gen.hpp, a port of the original's generator). We can't byte-match the// original without its exact RNG-stream context, but the generator must be deterministic, produce valid// altitudes/slopes, carve water when asked, and plant trees — and make_new_city must lay a valid MISC.#include "sc2k/sim/terrain_gen.hpp"#include <cstdio>
#include "test_harness.hpp"
static void stats(const sc2k::City& c, long& water, long& trees, int& amax) { water = trees = 0; amax = 0; for (int i = 0; i < 128 * 128; ++i) { const bool isWater = c.xbit.cells[i] & 4; if (isWater) ++water; const int b = c.xbld.cells[i]; if (b >= 6 && b <= 0xc) ++trees; const int alt = c.altm.cells[i] & 0x1f; // altitude = low 5 bits const int wlev = (c.altm.cells[i] >> 5) & 0x1f; // water-surface level = bits 5-9 amax = std::max(amax, alt); CHECK(alt <= 31); // A water tile must carry a non-zero surface level (else the renderer draws it at the map floor — the // "water in a deep hole" bug); a dry-land tile carries none. CHECK(isWater ? (wlev > 0) : (wlev == 0)); }}
int main() { using namespace sc2k; // Deterministic: same seed/sliders → identical layers. City a = make_new_city(0xABCDEF, 0, 1, 24, 28, 30, 1, 1); City b = make_new_city(0xABCDEF, 0, 1, 24, 28, 30, 1, 1); CHECK(a.altm.cells == b.altm.cells && a.xter.cells == b.xter.cells && a.xbld.cells == b.xbld.cells); // Different seed → different terrain. City d = make_new_city(0x123456, 0, 1, 24, 28, 30, 1, 1); CHECK(d.altm.cells != a.altm.cells);
long water = 0, trees = 0; int amax = 0; stats(a, water, trees, amax); CHECK(water > 500); // coast + river carved real water CHECK(trees > 500); // forests planted CHECK(amax >= 4); // hills present
// A flat, water/tree-free map (all sliders 0, no coast/river) → no water, no trees. City flat = make_new_city(0x999, 0, 1, 0, 0, 0, 0, 0); long w2 = 0, t2 = 0; int am2 = 0; stats(flat, w2, t2, am2); CHECK(w2 == 0 && t2 == 0);
// make_new_city lays a valid MISC: magic 0x122, start year, starting funds. CHECK(a.misc_be32(0) == 0x122); CHECK(a.start_year() == 1900); // era 0 CHECK(a.funds() == 20000); // difficulty 1 (easy) CHECK(a.days() == 0);
if (failures == 0) { std::printf("terrain: deterministic; water=%ld trees=%ld maxAlt=%d; MISC valid\n", water, trees, amax); return 0; } std::printf("terrain: %d failure(s)\n", failures); return 1;}