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:
128
src/verify.sex
128
src/verify.sex
@@ -2,7 +2,7 @@
|
||||
;;; region over everything the save has. A port is right when every
|
||||
;;; map matches to the pixel, padding included.
|
||||
|
||||
(include stdio.h stdlib.h string.h time.h)
|
||||
(include stdio.h stdlib.h string.h math.h time.h)
|
||||
;; TODO sex#58: import only the modules used here once an import brings
|
||||
;; the types its interface needs; until then, every dependency, in
|
||||
;; dependency order.
|
||||
@@ -17,9 +17,13 @@
|
||||
(import rivers)
|
||||
(import terra)
|
||||
(import strata)
|
||||
(import ores)
|
||||
(import img)
|
||||
|
||||
(define MAP-KINDS 6)
|
||||
;;; How far below the computed reading the game's may be; see
|
||||
;;; verify-readings.
|
||||
(define READING-SLACK 0.85)
|
||||
|
||||
(var map-names [(* const char) 6] #("landform" "climate" "province" "upheaval" "ocean" "strata"))
|
||||
|
||||
@@ -116,6 +120,128 @@
|
||||
(.release (& [diffs k])))
|
||||
(return failed))
|
||||
|
||||
;;; Regenerates the ore map of every mineral in every region the save
|
||||
;;; stored and compares them; one diff image for all minerals, a region
|
||||
;;; red where any of its ore maps differs.
|
||||
(pub fn verify-ores ((s (* save)) (o (* ores)) (dir (* const char))) int
|
||||
(var e extent (save/extent s "mapregion"))
|
||||
(var cell int 32)
|
||||
(var diff image (image/make (* (+ (- (. e x1) (. e x0)) 1) cell) (* (+ (- (. e z1) (. e z0)) 1) cell)))
|
||||
;; TODO sex#50: write MAX-MINERALS once constants in array types are
|
||||
;; kebab-converted.
|
||||
(var codes [* char MAX_MINERALS])
|
||||
(var want [int-map MAX_MINERALS])
|
||||
(var t tally)
|
||||
(memset (& t) 0 (sizeof t))
|
||||
(var unknown int 0)
|
||||
(for (var rz int (. e z0)) (<= rz (. e z1)) (++ rz)
|
||||
(for (var rx int (. e x0)) (<= rx (. e x1)) (++ rx)
|
||||
(var n int (save/ore-maps s rx rz codes want MAX-MINERALS))
|
||||
(var ox int (* (- rx (. e x0)) cell))
|
||||
(var oz int (* (- rz (. e z0)) cell))
|
||||
(var ok bool true)
|
||||
(for (var i int 0) (< i n) (++ i)
|
||||
(var k int (ores/find o [codes i]))
|
||||
(if (< k 0)
|
||||
(++ unknown)
|
||||
(do
|
||||
(var got int-map)
|
||||
(ores/map o k rx rz (& got))
|
||||
(++ (. t regions))
|
||||
(if (!= (. got size) (. [want i] size))
|
||||
(do (++ (. t size-mismatch)) (= ok false))
|
||||
(for (var p int 0) (< p (* (. got size) (. got size))) (++ p)
|
||||
(++ (. t compared))
|
||||
(if (== [(. got data) p] [(. [want i] data) p])
|
||||
(++ (. t matched))
|
||||
(= ok false))))
|
||||
(free (. got data))))
|
||||
(free [codes i])
|
||||
(free (. [want i] data)))
|
||||
(if (> n 0)
|
||||
(for (var y int 0) (< y cell) (++ y)
|
||||
(for (var x int 0) (< x cell) (++ x)
|
||||
(.set (& diff) (+ ox x) (+ oz y) (if ok (grey 96) 16719904)))))))
|
||||
(var percent double (if (> (. t compared) 0) (/ (* 100.0 (. t matched)) (. t compared)) 0))
|
||||
(printf "%-9s %4d maps %10lld/%-10lld px %8.4f%%%s\n" "ore" (. t regions)
|
||||
(. t matched) (. t compared) percent
|
||||
(if (. t size-mismatch) " (size mismatch)" ""))
|
||||
(if (> unknown 0)
|
||||
(printf "ore %d stored maps of minerals the deposits don't define\n" unknown))
|
||||
(var path [char 1024])
|
||||
(snprintf path (sizeof path) "%s/diff-ore.png" dir)
|
||||
(.write (& diff) path)
|
||||
(.release (& diff))
|
||||
(return (if (|| (!= (. t matched) (. t compared)) (> unknown 0)) 1 0)))
|
||||
|
||||
;;; Recomputes the prospecting pick readings players took in the save
|
||||
;;; and compares each mineral's TotalFactor: per reading, every
|
||||
;;; mineral the save has or this reads above nothing.
|
||||
;;;
|
||||
;;; They can't match exactly. The pick's column already has the ore of
|
||||
;;; the deposits generated in its chunk, which no longer counts as host
|
||||
;;; rock, and the game's Y range is drawn from samples where this takes
|
||||
;;; the distribution's limits. Both only ever make the game's reading
|
||||
;;; lower, so a reading passes when the game's is at most this much
|
||||
;;; below it, and never above.
|
||||
(pub fn verify-readings ((s (* save)) (g (* worldgen)) (config river-config) (rocks (* strata))
|
||||
(o (* ores))) int
|
||||
(if (== (. s pick-reading-count) 0)
|
||||
(do (printf "readings none stored\n") (return 0)))
|
||||
(var t (* terra) (terra/make g config))
|
||||
(var column [u8 1024])
|
||||
(var compared int 0)
|
||||
(var passed int 0)
|
||||
(var same-category int 0)
|
||||
(var unreadable int 0)
|
||||
(var worst double 1)
|
||||
(var i int 0)
|
||||
(while (< i (. s pick-reading-count))
|
||||
;; the minerals of one reading are stored one after another
|
||||
(var at (* pick-reading) (& [(. s pick-readings) i]))
|
||||
(var end int i)
|
||||
(while (&& (< end (. s pick-reading-count)) (== (. [(. s pick-readings) end] x) (. at x))
|
||||
(== (. [(. s pick-readings) end] z) (. at z)))
|
||||
(++ end))
|
||||
(var x int (. at x))
|
||||
(var z int (. at z))
|
||||
(var h int (terra/column-height t x z))
|
||||
(strata/column rocks (/ x 32) (/ z 32) (% x 32) (% z 32) h column)
|
||||
(printf "reading %d, %d: stored height %d, computed %d\n" x z (. at y) h)
|
||||
(for (var k int 0) (< k (. o count)) (++ k)
|
||||
(var m (* mineral) (& [(. o minerals) k]))
|
||||
(var stored (* pick-reading) NULL)
|
||||
(for (var j int i) (< j end) (++ j)
|
||||
(if (== (strcmp (. [(. s pick-readings) j] code) (. m code)) 0)
|
||||
(= stored (& [(. s pick-readings) j]))))
|
||||
(var map int-map)
|
||||
(ores/map o k (/ x 512) (/ z 512) (& map))
|
||||
(var r mineral-reading (ores/reading o k (& map) x z column h))
|
||||
(free (. map data))
|
||||
(var want double (if stored (. stored total) 0))
|
||||
(if (&& (! stored) (== (ores/category (. r total)) 0))
|
||||
(continue))
|
||||
(if (! (. m readable))
|
||||
(do
|
||||
(++ unreadable)
|
||||
(printf " %-14s %9.6f (not read here)\n" (. m code) want)
|
||||
(continue)))
|
||||
(++ compared)
|
||||
;; the game's reading over this one's
|
||||
(var ratio double (if (> (. r total) 0) (/ want (. r total)) 0))
|
||||
(var ok bool (&& (<= want (+ (. r total) 1e-9)) (>= ratio READING-SLACK)))
|
||||
(var category bool (== (ores/category want) (ores/category (. r total))))
|
||||
(if ok (++ passed))
|
||||
(if category (++ same-category))
|
||||
(if (< ratio worst) (= worst ratio))
|
||||
(printf " %-14s %9.6f %9.6f %5.3f %s\n" (. m code) want (. r total) ratio
|
||||
(if ok "ok" "MISMATCH")))
|
||||
(= i end))
|
||||
(terra/free t)
|
||||
(printf "readings %d of %d no higher than computed and within %.0f%% of it (worst %.3f); %d of %d in the same category; %d child deposits not read\n"
|
||||
passed compared (* 100 (- 1 READING-SLACK)) worst same-category compared unreadable)
|
||||
(return (if (== passed compared) 0 1)))
|
||||
|
||||
;;; Recomputes Rivers' per-column riverDistance for every map chunk the
|
||||
;;; save stored and compares it with the moddata Rivers saved: exactly
|
||||
;;; where it saved some, and "nothing within 300 blocks" where it saved
|
||||
|
||||
Reference in New Issue
Block a user