place hot springs as GenHotSprings does, and find the nearest

Carving records hot spring candidates where the game does: deep, wide
tunnel steps that pass the water check where geologic activity is
over 128. A candidate becomes a hot spring unless the surface over
twice its radius, after caves, is rough, below sea level + 1 or high
in the mountains, or a story location keeps hot springs away; carved
chunks are kept so their neighbours' heights come cheap. The Caves
overlay paints them as discs, and Find nearest looks for one.

Against the save, 173 of the 180 stored candidates match in centre and
radius; five differ only in the radius's last float bits, from a
rounding not yet found. Of the 102 hot springs placed, 84 hold the
save's sludgy gravel, and 94.8% of that gravel lies in one. Which edge
blocks are gravel or mat the game rolls each time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 18:24:10 +03:00
parent 82774445af
commit 40defbd367
9 changed files with 421 additions and 46 deletions

View File

@@ -25,6 +25,7 @@
(import lcg)
(import noise)
(pub import worldgen)
(pub import terra)
;;; How many chunks a cave reaches, and the states of a carved column.
(pub define CAVE-RANGE 5)
@@ -38,12 +39,24 @@
(pub define TRACE-SLOTS 4096)
;;; One SetBlocks call: the ellipsoid's centre in its source chunk's
;;; coordinates, and its radii.
(record carve ((x double) (y double) (z double) (hr float) (vr float)))
;;; coordinates, its radii, and whether it may make a hot spring.
(record carve ((x double) (y double) (z double) (hr float) (vr float) (hot bool)))
;;; The carves of one source chunk's cave, in order.
(pub record trace ((sx int) (sz int) (valid bool) (carves (* carve)) (count int) (cap int)))
;;; A place a hot spring may go, as SetBlocks records it in its chunk's
;;; "hotspringlocations": the centre within the chunk, and the radius.
(pub record spring-candidate ((x int) (y int) (z int) (radius double)))
(pub define MAX-CANDIDATES 16)
;;; A carved chunk column, kept: its heights after carving and its
;;; candidates, in the order they were first recorded.
(pub record carved
((cx int) (cz int) (valid bool) (heights [int 1024]) (count int)
(candidates [spring-candidate MAX-CANDIDATES])))
(pub define CARVED-SLOTS 512)
(pub record caves
((g (* worldgen)) (seed i32) (size-y int) (sea-level int)
(height-noise (* simplex-noise)) (basalt-noise (* simplex-noise))
@@ -53,7 +66,10 @@
;; the climate map of the region last asked about
(climate int-map) (climate-rx int) (climate-rz int)
;; the trace being made, and its random numbers
(cave-rand lcg) (current (* trace))))
(cave-rand lcg) (current (* trace))
(carved [carved CARVED-SLOTS])
;; room to carve a neighbour in, for hot springs
(scratch-states (* u8)) (scratch-solid (* u32))))
(define PI-F 3.14159274)
@@ -79,6 +95,8 @@
(for (var i int 0) (< i TRACE-SLOTS) (++ i)
(free (. [(. c traces) i] carves)))
(free (. c climate data))
(free (. c scratch-states))
(free (. c scratch-solid))
(free (. c height-noise))
(free (. c basalt-noise))
(free c))
@@ -101,13 +119,13 @@
;;; Tracing ----------------------------------------------------------
(fn add-carve ((c (* caves)) (x double) (y double) (z double) (hr float) (vr float)) void
(fn add-carve ((c (* caves)) (x double) (y double) (z double) (hr float) (vr float) (hot bool)) void
(var t (* trace) (. c current))
(if (>= (. t count) (. t cap))
(do
(= (. t cap) (if (> (. t cap) 0) (* (. t cap) 2) 256))
(= (. t carves) (realloc (. t carves) (* (. t cap) (sizeof carve))))))
(= [(. t carves) (. t count)] #(carve : x y z hr vr))
(= [(. t carves) (. t count)] #(carve : x y z hr vr hot))
(++ (. t count)))
;; declared ahead: a tunnel branches into shafts, a shaft into tunnels
@@ -153,7 +171,7 @@
(return)))
(if (&& (== (.next-int r 5) 0) (>= hor-radius (cast 2 float)))
(continue))
(add-carve c pos-x pos-y pos-z hor-radius vert-radius)))
(add-carve c pos-x pos-y pos-z hor-radius vert-radius false)))
;;; CarveTunnel.
(fn carve-tunnel ((c (* caves)) (pos-x double) (pos-y double) (pos-z double) (hor-angle float)
@@ -254,8 +272,9 @@
(var e float (.next-float r))
(var f float (.next-float r))
(= hor-radius-gain (+ (cast 4 float) (* (* e f) (cast 9 float)))))))
;; GenHotSprings, a later pass, would put a hot spring here when
;; -5 < y < 16, the radii pass 4 and 2 and geologic activity 128
;; deep and wide enough for a hot spring, if the carving gets there
(var hot bool (&& (> pos-y -5) (< pos-y 16) (> hor-radius (cast 4 float))
(> vert-radius (cast 2 float))))
(= size-change-speed-accum (fmaxf (cast 0.1 float) (+ size-change-speed-accum
(* size-change-speed-gain (cast 0.05 float)))))
@@ -318,7 +337,7 @@
(if (&& (>= hor-radius (cast 2 float)) (== (% rrnd 5) 0))
(continue))
(add-carve c pos-x (+ pos-y (/ ver-height-gain-accum (cast 2 float))) pos-z hor-radius
(+ vert-radius ver-height-gain-accum))))
(+ vert-radius ver-height-gain-accum) hot)))
;;; GeneratePartial's cave for source chunk (sx, sz), into T.
(fn trace-chunk ((c (* caves)) (t (* trace)) (sx int) (sz int)) void
@@ -402,7 +421,8 @@
;;; A target chunk column while it is carved.
(record column
((tx int) (tz int) (states (* u8)) (heights (* int)) (water-top (* int)) (distort [u8 1024])
(solid (* const u32)) (words int)))
(solid (* const u32)) (words int)
(candidates [spring-candidate MAX-CANDIDATES]) (count int)))
;;; The terrain pass put water in every block below sea level that it
;;; left open; with the terrain's solidity at hand that is exact, else
@@ -419,7 +439,7 @@
;;; SetBlocks, at centre (x, y, z) in the target chunk's coordinates.
(fn set-blocks ((c (* caves)) (k (* column)) (hor-radius float) (vert-radius float)
(x double) (y double) (z double)) void
(x double) (y double) (z double) (hot bool)) void
(var top int (- (. c size-y) 1))
;; one size more, to see whether it would run into liquid
(+= hor-radius (cast 1 float))
@@ -459,6 +479,20 @@
(= h-sq (* hor-radius hor-radius))
(= v-sq (* vert-radius vert-radius))
(var geo int (geologic-activity c (+ (* (. k tx) CHUNK) (cast x int)) (+ (* (. k tz) CHUNK) (cast z int))))
;; a hot spring candidate, keyed by its whole centre as the game's
;; dictionary is: a later one at the same key takes its place there
(if (&& hot (> geo 128) (>= x 0) (< x CHUNK) (>= z 0) (< z CHUNK))
(do
(var cand spring-candidate #(spring-candidate : (cast x int) (cast y int) (cast z int) hor-radius))
(var i int 0)
(while (&& (< i (. k count))
(! (&& (== (. [(. k candidates) i] x) (. cand x)) (== (. [(. k candidates) i] y) (. cand y))
(== (. [(. k candidates) i] z) (. cand z)))))
(++ i))
(if (< i MAX-CANDIDATES)
(do
(= [(. k candidates) i] cand)
(if (== i (. k count)) (++ (. k count)))))))
(var lava-top int (/ (* geo 16) 128))
(for (var lx int min-x) (<= lx max-x) (++ lx)
(var xd double (/ (* (- lx x) (- lx x)) h-sq))
@@ -497,12 +531,31 @@
;;; surface. SOLID, terra/chunk-solidity's bits with WORDS per column,
;;; tells where the terrain left water; without it, NULL, water is
;;; taken to be the columns above their surface.
(fn slot-of ((c (* caves)) (cx int) (cz int)) (* carved)
(var h u32 (+ (* (cast cx u32) 73856093) (* (cast cz u32) 19349663)))
(return (& [(. c carved) (% h CARVED-SLOTS)])))
;;; Keeps a carved chunk's heights and candidates.
(fn keep-carved ((c (* caves)) (cx int) (cz int) (heights (* const int))
(candidates (* const spring-candidate)) (count int)) void
(var e (* carved) (slot-of c cx cz))
(= (. e cx) cx)
(= (. e cz) cz)
(= (. e valid) true)
(memcpy (. e heights) heights (sizeof (. e heights)))
(= (. e count) count)
(if (> count 0)
(memcpy (. e candidates) candidates (* count (sizeof spring-candidate)))))
(pub fn caves/carve-column ((c (* caves)) (tx int) (tz int) (heights (* int)) (solid (* const u32))
(words int) (states (* u8))) void
(memset states 0 (* CHUNK CHUNK (. c size-y)))
(if (worldgen/caves-blocked (. c g) (+ (* tx CHUNK) 16) (+ (* tz CHUNK) 16))
(return))
(do
(keep-carved c tx tz heights NULL 0)
(return)))
(var k column)
(= (. k count) 0)
(= (. k tx) tx)
(= (. k tz) tz)
(= (. k states) states)
@@ -533,7 +586,19 @@
(var reach float (* (. cv hr) (cast 2 float)))
(if (|| (<= x (- reach)) (>= x (+ CHUNK reach)) (<= z (- reach)) (>= z (+ CHUNK reach)))
(continue))
(set-blocks c (& k) (. cv hr) (. cv vr) x (. cv y) z)))))
(set-blocks c (& k) (. cv hr) (. cv vr) x (. cv y) z (. cv hot)))))
(keep-carved c tx tz heights (. k candidates) (. k count)))
;;; The hot spring candidates of the chunk column last carved at (cx,
;;; cz), into OUT; how many, or -1 if it isn't kept.
(pub fn caves/candidates ((c (* caves)) (cx int) (cz int) (out (* spring-candidate)) (max int)) int
(var e (* carved) (slot-of c cx cz))
(if (! (&& (. e valid) (== (. e cx) cx) (== (. e cz) cz)))
(return -1))
(var n int (if (< (. e count) max) (. e count) max))
(if (> n 0)
(memcpy out (. e candidates) (* n (sizeof spring-candidate))))
(return n))
;;; Columns ----------------------------------------------------------
@@ -542,7 +607,9 @@
;;; one starts.
(pub define CAVE-NONE 0)
(pub define CAVE-ENTRANCE 1)
(pub define CAVE-CATEGORIES 7)
;;; Not a column's own: what the Caves overlay paints over a hot spring.
(pub define CAVE-HOT-SPRING 7)
(pub define CAVE-CATEGORIES 8)
(var depth-bands [int 4] #(10 25 50 100))
;;; The category of column (lx, lz) of a carved chunk column: SURFACE is
@@ -582,3 +649,86 @@
(++ n)))
(= prev s))
(return n))
;;; Hot springs ------------------------------------------------------
;;; A hot spring GenHotSprings makes: a disc of RADIUS around (x, z) at
;;; height y. Its middle, out to about a third of the radius, is boiling
;;; water, the rest sludgy gravel and bacterial mats; where exactly the
;;; edge of each falls the game rolls with a random generator of its
;;; own.
(pub record hot-spring ((x int) (y int) (z int) (radius double)))
;;; Chunk column (cx, cz) carved, from what is kept or carved now.
(fn carved-of ((c (* caves)) (tr (* terra)) (cx int) (cz int)) (* carved)
(var e (* carved) (slot-of c cx cz))
(if (&& (. e valid) (== (. e cx) cx) (== (. e cz) cz))
(return e))
(var words int (terra/solid-words tr))
(if (! (. c scratch-states))
(do
(= (. c scratch-states) (malloc (* CHUNK CHUNK (. c size-y))))
(= (. c scratch-solid) (malloc (* 1024 words (sizeof u32))))))
(var heights16 [u16 1024])
(var heights [int 1024])
(terra/chunk-solidity tr cx cz heights16 (. c scratch-solid))
(for (var i int 0) (< i 1024) (++ i)
(= [heights i] [heights16 i]))
(caves/carve-column c cx cz heights (. c scratch-solid) words (. c scratch-states))
(return (slot-of c cx cz)))
(fn surface-at ((c (* caves)) (tr (* terra)) (x int) (z int)) int
(var e (* carved) (carved-of c tr (/ x CHUNK) (/ z CHUNK)))
(return [(. e heights) (+ (* (% z CHUNK) CHUNK) (% x CHUNK))]))
;;; GenHotSprings for chunk column (cx, cz): its candidates that become
;;; hot springs, into OUT; how many, up to MAX. A candidate is kept
;;; unless the ground over twice its radius is rough (4 or more blocks
;;; between highest and lowest), anywhere below sea level + 1, or high
;;; in the mountains. The game also leaves out one with water standing
;;; at the surface; above sea level that can only be a pond, which comes
;;; later, or a neighbour's, which it does not see here.
(pub fn caves/hot-springs ((c (* caves)) (tr (* terra)) (cx int) (cz int) (out (* hot-spring)) (max int))
int
(if (worldgen/springs-blocked (. c g) (+ (* cx CHUNK) 16) (+ (* cz CHUNK) 16))
(return 0))
(var candidates [spring-candidate MAX-CANDIDATES])
(var e (* carved) (carved-of c tr cx cz))
(var count int (. e count))
(memcpy candidates (. e candidates) (* count (sizeof spring-candidate)))
(var n int 0)
(var base-x int (* cx CHUNK))
(var base-z int (* cz CHUNK))
(for (var k int 0) (&& (< k count) (< n max)) (++ k)
(var cand (* spring-candidate) (& [candidates k]))
(var radius double (* 2 (. cand radius)))
(var min-x int (cast (clampd (- (. cand x) radius) (- CHUNK) (- (* 2 CHUNK) 1)) int))
(var max-x int (cast (clampd (+ (+ (. cand x) radius) 1) (- CHUNK) (- (* 2 CHUNK) 1)) int))
(var min-z int (cast (clampd (- (. cand z) radius) (- CHUNK) (- (* 2 CHUNK) 1)) int))
(var max-z int (cast (clampd (+ (+ (. cand z) radius) 1) (- CHUNK) (- (* 2 CHUNK) 1)) int))
(var r-sq double (* radius radius))
(var lowest int 99999)
(var highest int 0)
(var checks int 0)
(var sum i64 0)
(for (var lx int min-x) (<= lx max-x) (++ lx)
(var xd double (/ (* (- lx (. cand x)) (- lx (. cand x))) r-sq))
(for (var lz int min-z) (<= lz max-z) (++ lz)
(var zd double (/ (* (- lz (. cand z)) (- lz (. cand z))) r-sq))
(if (>= (+ xd zd) 1)
(continue))
(var surface int (surface-at c tr (+ base-x lx) (+ base-z lz)))
(if (< surface lowest) (= lowest surface))
(if (> surface highest) (= highest surface))
(++ checks)
(+= sum surface)))
(if (== checks 0)
(continue))
;; Math.Round rounds halves to even, as rint does
(var average int (cast (rint (/ (cast sum double) checks)) int))
(if (|| (>= (- highest lowest) 4) (< lowest (+ (. c sea-level) 1))
(> lowest (* (cast (. c size-y) float) (cast 0.88 float))))
(continue))
(= [out n] #(hot-spring : (+ base-x (. cand x)) average (+ base-z (. cand z)) radius))
(++ n))
(return n))

View File

@@ -562,6 +562,60 @@
(sqlite3-finalize stmt)
(return ok))
;;; A hot spring candidate GenCaves stored in a map chunk's
;;; "hotspringlocations": centre within the chunk, and radius.
(pub record saved-spring ((x i32) (y i32) (z i32) (radius double)))
;;; The map chunk's "hotspringlocations" (mod data, field 1): a
;;; Dictionary<Vec3i, HotSpringGenData> of {1: {1: x, 2: y, 3: z},
;;; 2: {1: radius}} entries. Fills up to MAX and returns how many.
(pub fn save/hot-spring-locations ((s (* const save)) (cx i32) (cz i32) (out (* saved-spring)) (max int))
int
(var stmt (* sqlite3-stmt) NULL)
(var r pb (query-blob s "select data from mapchunk where position = ?1" (position cx cz) (& stmt)))
(var n int 0)
(var wire int)
(var f u32)
(while (&& (! (. r err)) (> (= f (.field (& r) (& wire))) 0))
(if (!= f 1)
(do (.skip (& r) wire) (continue)))
(var entry pb (.bytes (& r)))
(var key pb #(pb : NULL NULL false))
(var value pb #(pb : NULL NULL false))
(var g u32)
(while (> (= g (.field (& entry) (& wire))) 0)
(if (== g 1) (= key (.bytes (& entry)))
(== g 2) (= value (.bytes (& entry)))
(.skip (& entry) wire)))
(if (! (.equals key "hotspringlocations"))
(continue))
(while (&& (< n max) (> (.field (& value) (& wire)) 0))
(var item pb (.bytes (& value)))
(var spring saved-spring #(saved-spring : 0 0 0 0))
(var h u32)
(while (> (= h (.field (& item) (& wire))) 0)
(if (== h 1)
(do
(var pos pb (.bytes (& item)))
(var k u32)
(while (> (= k (.field (& pos) (& wire))) 0)
(if (== k 1) (= (. spring x) (.int32 (& pos)))
(== k 2) (= (. spring y) (.int32 (& pos)))
(== k 3) (= (. spring z) (.int32 (& pos)))
(.skip (& pos) wire))))
(== h 2)
(do
(var data pb (.bytes (& item)))
(var k u32)
(while (> (= k (.field (& data) (& wire))) 0)
(if (== k 1) (= (. spring radius) (read-double (& data)))
(.skip (& data) wire))))
(.skip (& item) wire)))
(= [out n] spring)
(++ n)))
(sqlite3-finalize stmt)
(return n))
;;; The stored extent of a table, in its own units (regions or chunks):
;;; inclusive bounds and the row count.
(pub record extent ((x0 i32) (z0 i32) (x1 i32) (z1 i32) (count i64)))

View File

@@ -1,7 +1,7 @@
;;; Finds the block nearest a point where one of a set of rocks lies, at
;;; the surface, at a depth below it, at a Y or at any depth; where the
;;; prospecting pick reads a mineral at least so high; or where a cave
;;; opens at the surface.
;;; prospecting pick reads a mineral at least so high; where a cave
;;; opens at the surface; or a hot spring.
;;;
;;; Regions are taken in order of their distance from the point and
;;; sampled every 16 blocks by several threads at once, each with its
@@ -26,6 +26,8 @@
(pub define SEARCH-MINERAL 4)
;;; The mode that looks for a cave entrance.
(pub define SEARCH-CAVE-ENTRANCE 5)
;;; The mode that looks for a hot spring.
(pub define SEARCH-HOT-SPRING 6)
(define SEARCH-STEP 16)
(pub define MAX-SEARCH-THREADS 16)
@@ -119,6 +121,13 @@
(var heights [u16 1024])
;; caves are carved a chunk at a time, so every column is looked at:
;; an entrance can be a block wide
(if (== (. s mode) SEARCH-HOT-SPRING)
(do
(var springs [hot-spring MAX-CANDIDATES])
(var n int (caves/hot-springs (. sc caves) (. sc tr) cx cz springs MAX-CANDIDATES))
(for (var i int 0) (< i n) (++ i)
(offer s (. [springs i] x) (. [springs i] z)))
(return)))
(if (== (. s mode) SEARCH-CAVE-ENTRANCE)
(do
(var carved [int 1024])
@@ -151,13 +160,13 @@
(if (&& (. sc rocks) (== (. s mode) SEARCH-MINERAL))
(= (. sc minerals) (ores/make (. s settings) (. s assets-dir) (. sc rocks))))
(= (. sc column) (malloc (+ (. s settings size-y) 1)))
(if (&& g (. sc tr) (== (. s mode) SEARCH-CAVE-ENTRANCE))
(if (&& g (. sc tr) (|| (== (. s mode) SEARCH-CAVE-ENTRANCE) (== (. s mode) SEARCH-HOT-SPRING)))
(do
(= (. sc caves) (caves/make g))
(= (. sc solid) (malloc (* 1024 (terra/solid-words (. sc tr)) (sizeof u32))))
(= (. sc states) (malloc (* 1024 (. s settings size-y))))))
(var ready bool (&& (. sc tr) (. sc rocks) (|| (!= (. s mode) SEARCH-MINERAL) (. sc minerals))
(|| (!= (. s mode) SEARCH-CAVE-ENTRANCE) (. sc caves))))
(|| (< (. s mode) SEARCH-CAVE-ENTRANCE) (. sc caves))))
(while ready
(pthread-mutex-lock (& (. s lock)))
(var i int (. s next))

View File

@@ -348,7 +348,7 @@
(return out))
;;; The cave tile: per sample, CAVE-VALUE-BASE plus its column's cave
;;; category. Caves are carved chunk by chunk, and a chunk needs every
;;; category, or CAVE-HOT-SPRING inside a hot spring. Caves are carved chunk by chunk, and a chunk needs every
;;; block of its terrain, so this costs a whole chunk per sample when
;;; zoomed out.
(fn render-caves ((tr (* terra)) (c (* caves)) (k tile-key) (size (* int))) (* u8)
@@ -380,6 +380,27 @@
(var cat int (caves/category c states lx lz [heights i] [carved i]))
(= [out (+ (* (+ (/ (* cz 32) step) dz) res) (/ (* cx 32) step) dx)]
(cast (+ CAVE-VALUE-BASE cat) u8))))))
;; hot springs over it, from the chunks of the region and around it,
;; whose discs may reach in
(var springs [hot-spring MAX-CANDIDATES])
(for (var cz int -1) (<= cz 16) (++ cz)
(for (var cx int -1) (<= cx 16) (++ cx)
(var chunk-x int (+ (* (. k rx) 16) cx))
(var chunk-z int (+ (* (. k rz) 16) cz))
(if (|| (< chunk-x 0) (< chunk-z 0) (>= (* chunk-x 32) (. (. c g) settings size-x))
(>= (* chunk-z 32) (. (. c g) settings size-z)))
(continue))
(var n int (caves/hot-springs c tr chunk-x chunk-z springs MAX-CANDIDATES))
(for (var i int 0) (< i n) (++ i)
(var sp (* hot-spring) (& [springs i]))
(for (var iz int 0) (< iz res) (++ iz)
(var dz double (- (+ (* (. k rz) 512) (* iz step)) (. sp z)))
(if (> (fabs dz) (. sp radius))
(continue))
(for (var ix int 0) (< ix res) (++ ix)
(var dx double (- (+ (* (. k rx) 512) (* ix step)) (. sp x)))
(if (< (+ (* dx dx) (* dz dz)) (* (. sp radius) (. sp radius)))
(= [out (+ (* iz res) ix)] (cast (+ CAVE-VALUE-BASE CAVE-HOT-SPRING) u8))))))))
(free solid)
(free states)
(= (* size) res)

View File

@@ -378,11 +378,24 @@
(var t (* terra) (terra/make g config))
(var c (* caves) (caves/make g))
(var size-y int (. s size-y))
;; hot springs: the stored candidates against ours, and ours placed
;; against the sludgy gravel the save has
(var sludgy int -1)
(var gravel (* i32) NULL)
(var gravel-count int 0)
(var gravel-cap int 0)
(var springs (* hot-spring) NULL)
(var spring-count int 0)
(var spring-cap int 0)
(var cand-same i64 0)
(var cand-ours-only i64 0)
(var cand-saved-only i64 0)
(var saved (* u8) (malloc (+ (. s block-count) 1)))
(for (var id int 0) (< id (. s block-count)) (++ id)
(var code (* const char) (save/block-code s id))
(= [saved id] SAVED-OTHER)
(var len size-t (strlen code))
(if (== (strcmp code "sludgygravel") 0) (= sludgy id))
(if (== id 0) (= [saved id] SAVED-AIR)
(== (strcmp code "rock-basalt") 0) (= [saved id] SAVED-BASALT)
(|| (== (strcmp code "rock-obsidian") 0)
@@ -432,6 +445,37 @@
(= [after i] [heights i])
(if (> [heights i] top) (= top [heights i])))
(caves/carve-column c cx cz after solid words states)
;; the candidates, each against the stored one at its key
(var ours [spring-candidate MAX-CANDIDATES])
(var mine int (caves/candidates c cx cz ours MAX-CANDIDATES))
(var theirs-c [saved-spring MAX-CANDIDATES])
(var stored int (save/hot-spring-locations s cx cz theirs-c MAX-CANDIDATES))
(for (var a int 0) (< a mine) (++ a)
(var hit bool false)
(for (var b int 0) (< b stored) (++ b)
(if (&& (== (. [ours a] x) (. [theirs-c b] x)) (== (. [ours a] y) (. [theirs-c b] y))
(== (. [ours a] z) (. [theirs-c b] z)) (== (. [ours a] radius) (. [theirs-c b] radius)))
(= hit true)))
(if hit (++ cand-same) (++ cand-ours-only)))
(for (var b int 0) (< b stored) (++ b)
(var hit bool false)
(for (var a int 0) (< a mine) (++ a)
(if (&& (== (. [ours a] x) (. [theirs-c b] x)) (== (. [ours a] y) (. [theirs-c b] y))
(== (. [ours a] z) (. [theirs-c b] z)) (== (. [ours a] radius) (. [theirs-c b] radius)))
(= hit true)))
(if (! hit) (++ cand-saved-only)))
;; and which of ours become hot springs
(if (> mine 0)
(do
(var placed [hot-spring MAX-CANDIDATES])
(var n int (caves/hot-springs c t cx cz placed MAX-CANDIDATES))
(for (var a int 0) (< a n) (++ a)
(if (>= spring-count spring-cap)
(do
(= spring-cap (+ (* spring-cap 2) 16))
(= springs (realloc springs (* spring-cap (sizeof hot-spring))))))
(= [springs spring-count] [placed a])
(++ spring-count))))
(for (var i int 0) (< i 1024) (++ i)
(++ columns)
(if (== [before i] [(. m terrain-height) i]) (++ height-before))
@@ -446,6 +490,16 @@
(for (var i int 0) (< i CHUNK-VOLUME) (++ i)
(var y int (+ (* cy 32) (/ i 1024)))
(var col int (% i 1024))
(if (&& (== [blocks i] sludgy) (>= sludgy 0))
(do
(if (>= (+ gravel-count 3) gravel-cap)
(do
(= gravel-cap (+ (* gravel-cap 2) 768))
(= gravel (realloc gravel (* gravel-cap (sizeof i32))))))
(= [gravel gravel-count] (+ (* cx 32) (% col 32)))
(= [gravel (+ gravel-count 1)] y)
(= [gravel (+ gravel-count 2)] (+ (* cz 32) (/ col 32)))
(+= gravel-count 3)))
(if (|| (< y 1) (> y [before col]))
(continue))
(var id i32 [blocks i])
@@ -498,6 +552,33 @@
over-in over-out)
(printf " terrain height: %lld/%lld columns before carving, %lld after\n" height-before columns
height-after)
;; each sludgy gravel block, in one of our hot springs at its height?
(var gravel-in int 0)
(var found (* bool) (calloc (+ spring-count 1) (sizeof bool)))
(for (var g3 int 0) (< g3 gravel-count) (+= g3 3)
(var gx int [gravel g3])
(var gy int [gravel (+ g3 1)])
(var gz int [gravel (+ g3 2)])
(var in bool false)
(for (var k int 0) (< k spring-count) (++ k)
(var sp (* hot-spring) (& [springs k]))
(var dx double (- gx (. sp x)))
(var dz double (- gz (. sp z)))
;; the base goes 2 below, the walls up to the surface + 1
(if (&& (>= gy (- (. sp y) 2)) (<= gy (+ (. sp y) 4))
(< (+ (* dx dx) (* dz dz)) (* (+ (. sp radius) 1) (+ (. sp radius) 1))))
(do (= in true) (= [found k] true))))
(if in (++ gravel-in)))
(var springs-found int 0)
(for (var k int 0) (< k spring-count) (++ k)
(if [found k] (++ springs-found)))
(printf "hot springs candidates: %lld as stored, %lld only ours, %lld only stored\n" cand-same cand-ours-only
cand-saved-only)
(printf " %d placed, %d of them with the save's sludgy gravel; %d of %d sludgy gravel blocks in one\n"
spring-count springs-found gravel-in (/ gravel-count 3))
(free found)
(free gravel)
(free springs)
(var path [char 1024])
(snprintf path (sizeof path) "%s/diff-caves.png" dir)
(.write (& diff) path)

View File

@@ -5,6 +5,7 @@
;;; [--base ocean|rivers|height] [--overlay NAME]... [--opacity F]
;;; [--rock-depth N | --rock-y Y | --rock-any] [--highlight ROCK]... [--find]
;;; [--mineral CODE] [--min-reading NAME] [--find-mineral] [--find-cave]
;;; [--find-hot-spring]
;;; [--probe X Z] [--mouse X Y]
;;; [--screenshot FILE.png] [WORLD.vcdbs | serverconfig.json]
;;;
@@ -98,15 +99,17 @@
;;; The cave categories, caves/category's numbering, and their colours
;;; on the Caves overlay: entrances stand out, then the deeper the
;;; topmost cave, the darker.
(var cave-names [(* const char) 7]
#("none" "entrance" "10 deep or less" "11-25 deep" "26-50 deep" "51-100 deep" "deeper"))
(var cave-colours [u32 7]
#(0x000000 0x00E5FF 0xFFD54F 0xFF9800 0xE64A19 0x8E24AA 0x303F9F))
(var cave-names [(* const char) 8]
#("none" "entrance" "10 deep or less" "11-25 deep" "26-50 deep" "51-100 deep" "deeper"
"hot spring"))
(var cave-colours [u32 8]
#(0x000000 0x00E5FF 0xFFD54F 0xFF9800 0xE64A19 0x8E24AA 0x303F9F 0xFF4081))
;;; What Find nearest is looking for, for which panel shows its status.
(define FIND-ROCK 0)
(define FIND-MINERAL 1)
(define FIND-CAVE 2)
(define FIND-HOT-SPRING 3)
(define MAX-PROBE-CAVES 16)
;;; The strata of the column clicked last: top down, as (rock, top y,
@@ -145,6 +148,7 @@
(min-reading int) (find-mineral-requested bool)
;; caves: their share of the view per category, the probe's carver
(cave-coverage [i64 256]) (cave-coverage-total i64) (find-cave-requested bool)
(find-spring-requested bool)
(probe-caves (* caves))
(search-kind int)
(show-stories bool) (show-cursor-rock bool)
@@ -848,16 +852,21 @@
(nk-labelf ctx NK-TEXT-LEFT "%-16s %5.1f%%" [cave-names c]
(/ (* 100.0 [(. a cave-coverage) (+ CAVE-VALUE-BASE c)]) (. a cave-coverage-total)))
(nk-label ctx [cave-names c] NK-TEXT-LEFT)))
(nk-layout-row-dynamic ctx 24 1)
(if (&& (. a searching) (== (. a search-kind) FIND-CAVE))
(nk-layout-row-dynamic ctx 24 2)
(var finding bool (&& (. a searching) (|| (== (. a search-kind) FIND-CAVE)
(== (. a search-kind) FIND-HOT-SPRING))))
(if finding
(if (nk-button-label ctx "Cancel")
(do
(search/stop (. a search))
(= (. a searching) false)
(snprintf (. a search-status) (sizeof (. a search-status)) "cancelled")))
(if (nk-button-label ctx "Find nearest entrance")
(= (. a find-cave-requested) true)))
(if (&& (* (. a search-status)) (== (. a search-kind) FIND-CAVE))
(do
(if (nk-button-label ctx "Nearest entrance")
(= (. a find-cave-requested) true))
(if (nk-button-label ctx "Nearest hot spring")
(= (. a find-spring-requested) true))))
(if (&& (* (. a search-status)) (|| (== (. a search-kind) FIND-CAVE) (== (. a search-kind) FIND-HOT-SPRING)))
(do
(nk-layout-row-dynamic ctx 34 1)
(nk-label-wrap ctx (. a search-status)))))
@@ -1144,6 +1153,14 @@
(- (SDL-GetNumLogicalCPUCores) 1))
(= (. a searching) true)
(= (. a search-kind) FIND-CAVE)))
(if (. a find-spring-requested)
(do
(= (. a find-spring-requested) false)
(search/start (. a search) (. a source settings) (. a rivers) (. a assets-dir)
SEARCH-HOT-SPRING 0 0 (. a center-x) (. a center-z)
(- (SDL-GetNumLogicalCPUCores) 1))
(= (. a searching) true)
(= (. a search-kind) FIND-HOT-SPRING)))
(if (! (. a searching))
(return))
(var s (* search) (. a search))
@@ -1373,6 +1390,8 @@
(= (. a find-mineral-requested) true)
(== (strcmp [argv i] "--find-cave") 0)
(= (. a find-cave-requested) true)
(== (strcmp [argv i] "--find-hot-spring") 0)
(= (. a find-spring-requested) true)
(&& (== (strcmp [argv i] "--highlight") 0) more)
(do
(++ i)
@@ -1454,7 +1473,8 @@
(SDL-SetRenderClipRect (. a renderer) NULL)
(nk-sdl-render (. a ctx) NK-ANTI-ALIASING-ON)
(if (&& (. a screenshot) (== (. a pending) 0) (! (. a searching)) (! (. a find-requested))
(! (. a find-mineral-requested)) (! (. a find-cave-requested)))
(! (. a find-mineral-requested)) (! (. a find-cave-requested))
(! (. a find-spring-requested)))
(do
(if (! (save-screenshot a))
(fprintf stderr "%s: %s\n" (. a screenshot) (SDL-GetError)))

View File

@@ -768,10 +768,10 @@
(pub record story
((code [char 64]) (x int) (z int) (dir-x int) (landform-radius int)
(landform int) (forces-climate bool) (climate int)
;; skipGenerationCategories' "caves": no caves within this radius, or
;; in the schematic's footprint when it is 0; -1 when caves are not
;; skipped
(cave-skip int) (size-x int) (size-z int)))
;; skipGenerationCategories' "caves" and "hotsprings": none within
;; this radius, or in the schematic's footprint when it is 0; -1 when
;; not skipped
(cave-skip int) (spring-skip int) (size-x int) (size-z int)))
;;; The footprints of the story schematics that skip caves by footprint
;;; rather than by radius. The schematics are not among the assets this
@@ -837,8 +837,11 @@
(= (. st z) (+ base-z (* dist-z dir-z)))
(= (. st dir-x) dir-x)
(= (. st landform-radius) (json-int c "landformRadius" 0))
(var skip (* cJSON) (cJSON-GetObjectItem (cJSON-GetObjectItem c "skipGenerationCategories") "caves"))
(var skips (* cJSON) (cJSON-GetObjectItem c "skipGenerationCategories"))
(var skip (* cJSON) (cJSON-GetObjectItem skips "caves"))
(= (. st cave-skip) (if (cJSON-IsNumber skip) (cast (cJSON-GetNumberValue skip) int) -1))
(var spring-skip (* cJSON) (cJSON-GetObjectItem skips "hotsprings"))
(= (. st spring-skip) (if (cJSON-IsNumber spring-skip) (cast (cJSON-GetNumberValue spring-skip) int) -1))
(for (var k int 0) (< k 1) (++ k)
(if (== (strcmp (. [story-sizes k] code) (. st code)) 0)
(do
@@ -1104,12 +1107,13 @@
(for (var i int 0) (< i (. g strata count)) (++ i)
(worldgen/map g MAP-STRATA i rx rz (& [(. out strata) i]))))
;;; GenStoryStructures.GetBlockingStructureAt for the "caves" category:
;;; whether a story location keeps caves out of block column (x, z).
(pub fn worldgen/caves-blocked ((g (* const worldgen)) (x int) (z int)) bool
;;; GenStoryStructures.GetBlockingStructureAt: whether a story location
;;; keeps a category out of block column (x, z), by the radius SKIP
;;; reads off it.
(fn story-blocks ((g (* const worldgen)) (x int) (z int) (springs bool)) bool
(for (var i int 0) (< i (. g story-count)) (++ i)
(var st (* const story) (& [(. g stories) i]))
(var r int (. st cave-skip))
(var r int (if springs (. st spring-skip) (. st cave-skip)))
(if (< r 0)
(continue))
(if (== r 0)
@@ -1128,6 +1132,14 @@
(return true)))
(return false))
;;; For the "caves" category.
(pub fn worldgen/caves-blocked ((g (* const worldgen)) (x int) (z int)) bool
(return (story-blocks g x z false)))
;;; For the "hotsprings" category.
(pub fn worldgen/springs-blocked ((g (* const worldgen)) (x int) (z int)) bool
(return (story-blocks g x z true)))
(pub fn worldgen/free ((g (* worldgen))) void
(for (var i int 0) (< i (. g landform-table count)) (++ i)
(free (. [(. g landform-table all) i] y-thresholds)))