show what the prospecting pick reads, and find it

The ore maps GenDeposits makes are ported and match the save's for all
31 minerals in every stored region. With them and the strata, a column
reads as the pick's density mode would read it: a Minerals overlay
colours the map by reading, the probe lists every mineral the pick
finds, and Find nearest looks for a mineral read at least so high.

Readings run slightly high: the pick's column already holds the ore of
its chunk's deposits, which are not generated yet. The check against
the 13 readings stored in the save asserts exactly that direction.
Silver, gold and peridot are read from ore inside other deposits, so
they wait for the deposits themselves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 22:02:34 +03:00
parent 75d734c2d6
commit e174bff7e2
12 changed files with 1310 additions and 80 deletions

View File

@@ -26,13 +26,19 @@
(pub record story-location ((code [char 64]) (x i32) (y i32) (z i32)))
;;; One mineral of a prospecting pick reading a player took: where,
;;; and the reading's TotalFactor and PartsPerThousand.
(pub record pick-reading ((x int) (y int) (z int) (code [char 32]) (total double) (ppt double)))
(pub record save
((db (* sqlite3)) (seed i32) (size-x i32) (size-y i32) (size-z i32)
(config-keys (* * char)) (config-values (* * char)) (config-count int)
(block-codes (* * char)) (block-count int)
;; TODO sex#50: write MAX-STORIES once constants in array types are
;; kebab-converted.
(stories [story-location MAX_STORIES]) (story-count int)))
(stories [story-location MAX_STORIES]) (story-count int)
;; every player's stored pick readings
(pick-readings (* pick-reading)) (pick-reading-count int)))
;;; Map regions and map chunks share one key: x in the low 27 bits,
;;; z above them.
@@ -172,6 +178,59 @@
(.skip (& body) wire))))
(++ (. s story-count))))
(fn read-double ((r (* pb))) double
(var bits u64 (read-le r 8))
(var d double)
(memcpy (& d) (& bits) 8)
(return d))
(fn add-pick-reading ((s (* save)) (reading pick-reading)) void
(var n int (. s pick-reading-count))
(= (. s pick-readings) (realloc (. s pick-readings) (* (+ n 1) (sizeof pick-reading))))
(= [(. s pick-readings) n] reading)
(= (. s pick-reading-count) (+ n 1)))
;;; oreMapMarkers-PLAYER: List<PropickReading>, entries {1: position
;;; {1: x, 2: y, 3: z}, 2: {1: code, 2: {2: total, 3: ppt}}*}.
(fn read-pick-readings ((s (* save)) (r pb)) void
(var wire int)
(while (> (.field (& r) (& wire)) 0)
(var body pb (.bytes (& r)))
(var at pick-reading)
(memset (& at) 0 (sizeof at))
(var f u32)
(while (> (= f (.field (& body) (& wire))) 0)
(if (== f 1)
(do
(var position pb (.bytes (& body)))
(var g u32)
(while (> (= g (.field (& position) (& wire))) 0)
(if (== g 1) (= (. at x) (cast (read-double (& position)) int))
(== g 2) (= (. at y) (cast (read-double (& position)) int))
(== g 3) (= (. at z) (cast (read-double (& position)) int))
(.skip (& position) wire))))
(== f 2)
(do
(var entry pb (.bytes (& body)))
(var reading pick-reading at)
(var g u32)
(while (> (= g (.field (& entry) (& wire))) 0)
(if (== g 1)
(do
(var code pb (.bytes (& entry)))
(snprintf (. reading code) 32 "%.*s" (cast (.len code) int) (. code p)))
(== g 2)
(do
(var value pb (.bytes (& entry)))
(var h u32)
(while (> (= h (.field (& value) (& wire))) 0)
(if (== h 2) (= (. reading total) (read-double (& value)))
(== h 3) (= (. reading ppt) (read-double (& value)))
(.skip (& value) wire))))
(.skip (& entry) wire)))
(add-pick-reading s reading))
(.skip (& body) wire)))))
;;; Game data --------------------------------------------------------
(fn read-gamedata ((s (* save)) (r pb)) void
@@ -194,7 +253,10 @@
(== g 2) (= value (.bytes (& entry)))
(.skip (& entry) wire)))
(if (.equals key "BlockIDs") (read-block-ids s value)
(.equals key "storystructurelocations") (read-stories s value)))
(.equals key "storystructurelocations") (read-stories s value)
(&& (. key p) (>= (.len key) 14)
(== (strncmp (cast (. key p) (* const char)) "oreMapMarkers-" 14) 0))
(read-pick-readings s value)))
(.skip (& r) wire))))
(fn query-blob ((s (* const save)) (sql (* const char)) (key i64)
@@ -243,6 +305,7 @@
(for (var i int 0) (< i (. s block-count)) (++ i)
(free [(. s block-codes) i]))
(free (. s block-codes))
(free (. s pick-readings))
(sqlite3-close (. s db))
(free s))
@@ -299,6 +362,36 @@
(sqlite3-finalize stmt)
(return found))
;;; ServerMapRegion field 8, OreMaps: one {1: code, 2: IntDataMap2D}
;;; entry per mineral. Fills up to MAX of CODES (each strdup'd) and
;;; MAPS, and returns how many; -1 when the save has no such region.
(pub fn save/ore-maps ((s (* const save)) (rx i32) (rz i32) (codes (* * char)) (maps (* int-map))
(max int)) int
(var stmt (* sqlite3-stmt) NULL)
(var r pb (query-blob s "select data from mapregion where position = ?1"
(position rx rz) (& stmt)))
(if (. r err)
(do (sqlite3-finalize stmt) (return -1)))
(var n int 0)
(var wire int)
(var f u32)
(while (> (= f (.field (& r) (& wire))) 0)
(if (|| (!= f 8) (>= n max))
(do (.skip (& r) wire) (continue)))
(var entry pb (.bytes (& r)))
(= [codes n] NULL)
(= [maps n] #(int-map : NULL 0 0 0))
(var g u32)
(while (> (= g (.field (& entry) (& wire))) 0)
(if (== g 1) (= [codes n] (strndup-pb (.bytes (& entry))))
(== g 2) (read-int-map (.bytes (& entry)) (& [maps n]))
(.skip (& entry) wire)))
(if [codes n]
(++ n)
(free (. [maps n] data))))
(sqlite3-finalize stmt)
(return n))
;;; Map chunks -------------------------------------------------------
;;; A repeated ushort field arrives one value per field, or packed.