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,19 +26,24 @@
(import rivers)
(import terra)
(import strata)
(import ores)
(pub define MAX-TILES 65536)
;;; Not worldgen maps: Rivers' distance to the nearest river, the
;;; terrain height, and the rock at the surface, at a depth or at a Y,
;;; or where one rock lies at any depth.
;;; or where one rock lies at any depth; and the prospecting pick's
;;; reading of one mineral.
(pub define LAYER-RIVERS 6)
(pub define LAYER-HEIGHT 7)
(pub define LAYER-ROCK 8)
(pub define LAYER-MINERAL 9)
(pub define ROCK-AT-SURFACE 0)
(pub define ROCK-AT-DEPTH 1)
(pub define ROCK-AT-Y 2)
;;; The param's value is then the rock's index.
(pub define ROCK-ANY-DEPTH 3)
;;; Mineral tile values: this plus the reading's category.
(pub define MINERAL-VALUE-BASE 64)
;;; Rock tile values besides rock indices.
(pub define VALUE-WATER 253)
(pub define VALUE-AIR 254)
@@ -54,11 +59,13 @@
(define TILE-DRAWN 4)
;;; STRATUM is the stratum for MAP-STRATA, the samples per region side
;;; for the sampled layers; PARAM is the rock layer's mode * 1024 + value.
;;; for the sampled layers; PARAM is the rock layer's mode * 1024 + value,
;;; or the mineral layer's mineral.
(pub record tile-key ((map int) (stratum int) (rx int) (rz int) (param int)))
;;; Rock tiles keep their VALUES, rock indices, and are coloured from
;;; the palette on upload, so a new palette only re-uploads them.
;;; Rock and mineral tiles keep their VALUES, rock indices or reading
;;; categories, and are coloured from the palette on upload, so a new
;;; palette only re-uploads them.
(pub record tile
((key tile-key) (state int) (generation int) (size int) (pixels (* u32)) (values (* u8))
(texture (* SDL-Texture)) (last-used u64)))
@@ -324,6 +331,41 @@
(= (* size) res)
(return out))
;;; The mineral tile: per sample, MINERAL-VALUE-BASE plus the category
;;; of the pick's reading there.
(fn render-minerals ((tr (* terra)) (rocks (* strata)) (o (* ores)) (k tile-key) (size (* int)))
(* u8)
(var res int (. k stratum))
(var step int (/ 512 res))
(var map int-map)
(ores/map o (. k param) (. k rx) (. k rz) (& map))
(var out (* u8) (malloc (* res res)))
(var heights [u16 1024])
(var column (* u8) (malloc (+ (. tr size-y) 1)))
(var per-chunk int (/ 32 step))
(if (< per-chunk 1) (= per-chunk 1))
(for (var cz int 0) (< cz 16) (++ cz)
(for (var cx int 0) (< cx 16) (++ cx)
(if (|| (!= (% (* cx 32) step) 0) (!= (% (* cz 32) step) 0))
(continue))
(var chunk-x int (+ (* (. k rx) 16) cx))
(var chunk-z int (+ (* (. k rz) 16) cz))
(terra/chunk-heights tr chunk-x chunk-z (if (> step 32) 32 step) heights)
(for (var dz int 0) (< dz per-chunk) (++ dz)
(for (var dx int 0) (< dx per-chunk) (++ dx)
(var lx int (* dx step))
(var lz int (* dz step))
(var h int [heights (+ (* lz 32) lx)])
(strata/column rocks chunk-x chunk-z lx lz h column)
(var r mineral-reading (ores/reading o (. k param) (& map) (+ (* chunk-x 32) lx)
(+ (* chunk-z 32) lz) column h))
(= [out (+ (* (+ (/ (* cz 32) step) dz) res) (/ (* cx 32) step) dx)]
(cast (+ MINERAL-VALUE-BASE (ores/category (. r total))) u8))))))
(free column)
(free (. map data))
(= (* size) res)
(return out))
;;; Workers -------------------------------------------------------
(fn worker-main ((arg (* void))) (* void)
@@ -334,6 +376,7 @@
(memset (& cache) 0 (sizeof cache))
(var tr (* terra) NULL)
(var rocks (* strata) NULL)
(var minerals (* ores) NULL)
(pthread-mutex-lock (& (. t lock)))
(while (! (. t quit))
(if (>= (. t queue-pos) (. t queue-len))
@@ -356,6 +399,8 @@
(do
(if tr (terra/free tr))
(= tr NULL)
(if minerals (ores/free minerals))
(= minerals NULL)
(if rocks (strata/free rocks))
(= rocks NULL)
(if g (worldgen/free g))
@@ -363,6 +408,7 @@
(= g (worldgen/make settings (. t assets-dir)))
(if g (= tr (terra/make g rivers)))
(if g (= rocks (strata/make g (. t assets-dir))))
(if rocks (= minerals (ores/make settings (. t assets-dir) rocks)))
(= (. cache sampler) (river-sampler/make (& rivers) (. settings size-y)))
(= g-generation generation)))
(var size int 0)
@@ -374,6 +420,8 @@
(= px (render-heights tr key (& size)))
(&& tr rocks (== (. key map) LAYER-ROCK))
(= values (render-rocks tr rocks key (& size)))
(&& tr rocks minerals (== (. key map) LAYER-MINERAL))
(= values (render-minerals tr rocks minerals key (& size)))
g
(= px (render g key (& size))))
@@ -390,6 +438,7 @@
(if (&& (== generation (. t generation)) (== (. tl state) TILE-WORKING))
(= (. tl state) TILE-QUEUED)))))
(pthread-mutex-unlock (& (. t lock)))
(if minerals (ores/free minerals))
(if rocks (strata/free rocks))
(if tr (terra/free tr))
(if g (worldgen/free g))