Beginning tlo make progress on integrating mw-engine
This commit is contained in:
parent
833d69132f
commit
a6dbe8d1cc
|
@ -13,11 +13,13 @@
|
|||
:cucumber-feature-paths ["test/features/"]
|
||||
:dependencies [[com.taoensso/timbre "6.5.0"]
|
||||
[environ "1.2.0"]
|
||||
[hiccup "2.0.0-RC3"]
|
||||
[jme-clj "0.1.13"]
|
||||
;; [jme3-core "3.4.0-stable"]
|
||||
[journeyman-cc/walkmap "0.1.0-SNAPSHOT"]
|
||||
[me.raynes/fs "1.4.6"]
|
||||
[mw-engine "0.3.0-SNAPSHOT"]
|
||||
[mw-parser "0.3.0-SNAPSHOT"]
|
||||
[org.apache.commons/commons-math3 "3.6.1"] ;; for mersenne-twister implementation
|
||||
[org.clojure/algo.generic "1.0.0"]
|
||||
[org.clojure/clojure "1.11.2"]
|
||||
|
|
59
resources/data/baking/biome-rules.txt
Normal file
59
resources/data/baking/biome-rules.txt
Normal file
|
@ -0,0 +1,59 @@
|
|||
## Basic ruleset which just grows trees
|
||||
|
||||
;; This ruleset is not very interesting in itself, but is useful as a starting
|
||||
;; point from which to build more interesting rulesets.
|
||||
|
||||
## Vegetation rules
|
||||
;; rules which populate the world with plants
|
||||
|
||||
;; Occasionally, passing birds plant tree seeds into grassland
|
||||
|
||||
if state is grassland then 1 chance in 10 state should be heath
|
||||
|
||||
;; heath below the treeline grows gradually into forest
|
||||
|
||||
if state is heath and altitude is less than 120 then state should be scrub
|
||||
if state is scrub then 1 chance in 5 state should be forest
|
||||
|
||||
;; Forest on fertile land grows to climax
|
||||
|
||||
if state is forest and fertility is more than 5 and altitude is less than 70 then state should be climax
|
||||
|
||||
;; Climax forest occasionally catches fire (e.g. lightning strikes)
|
||||
|
||||
if state is climax then 1 chance in 500 state should be fire
|
||||
|
||||
;; Climax forest neighbouring fires is likely to catch fire
|
||||
if state is climax and some neighbours are fire then 1 chance in 3 state should be fire
|
||||
|
||||
;; After fire we get waste
|
||||
|
||||
if state is fire then state should be waste
|
||||
|
||||
;; And after waste we get pioneer species; if there's a woodland seed
|
||||
;; source, it's going to be heath, otherwise grassland.
|
||||
|
||||
if state is waste and some neighbours are scrub then state should be heath
|
||||
if state is waste and some neighbours are forest then state should be heath
|
||||
if state is waste and some neighbours are climax then state should be heath
|
||||
if state is waste then state should be grassland
|
||||
|
||||
## Potential blockers
|
||||
|
||||
;; Forest increases soil fertility.
|
||||
if state is in forest or climax then fertility should be fertility + 1
|
||||
|
||||
|
||||
## Initialisation rules
|
||||
|
||||
;; Rules which deal with state 'new' will waste less time if they're near the
|
||||
;; end of the file
|
||||
|
||||
;; below the waterline we have water.
|
||||
if state is new and altitude is less than 10 then state should be water
|
||||
|
||||
;; above the snowline we have snow.
|
||||
if state is new and altitude is more than 200 then state should be snow
|
||||
|
||||
;; otherwise, we have grassland.
|
||||
if state is new then state should be grassland
|
159
resources/data/baking/settlement-rules.txt
Normal file
159
resources/data/baking/settlement-rules.txt
Normal file
|
@ -0,0 +1,159 @@
|
|||
# Human settlement
|
||||
|
||||
;; This rule set attempts to model human settlement in a landscape. It models
|
||||
;; western European pre-history moderately well. Settlement first occurs as
|
||||
;; nomadic camps on coastal promentaries (cells with four or more neighbours
|
||||
;; that are water). This represents 'kitchen-midden' mesolithic settlement.
|
||||
;;
|
||||
;; As grassland becomes available near camps, pastoralists appear, and will
|
||||
;; follow their herds inland. When pastoralists have available fertile land,
|
||||
;; they will till the soil and plant crops, and in doing so will establish
|
||||
;; permanent settlements; this is approximately a neolithic stage.
|
||||
;;
|
||||
;; Where soil is fertile, settlements will cluster, and markets will appear.
|
||||
;; where there is sufficient settlement, the markets become permanent, and you
|
||||
;; have the appearance of towns. This takes us roughly into the bronze age.
|
||||
;;
|
||||
;; This is quite a complex ruleset, and runs quite slowly. However, it does
|
||||
;; model some significant things. Soil gains in fertility under woodland; deep
|
||||
;; loams and podzols build up over substantial time. Agriculture depletes
|
||||
;; fertility. So if forest has become well established before human settlement
|
||||
;; begins, a higher population (more crops) will eventually be sustainable,
|
||||
;; whereas if human population starts early the deep fertile soils will not
|
||||
;; establish and you will have more pastoralism, supporting fewer permanent
|
||||
;; settlements.
|
||||
|
||||
;; where people are camping beside water and there's enough land to give shelter,
|
||||
;; we'll get fishing. This rule is going to be EXPENSIVE, so may cause problems.
|
||||
if state is water and some neighbours are camp and more than 3 neighbours are pasture then state should be harbour
|
||||
if state is water then state should be water
|
||||
|
||||
;; nomads make their first significant camp near water because of fish and
|
||||
;; shellfish (kitchen-midden people)
|
||||
if state is in grassland or heath and more than 3 neighbours are water and generation is more than 20 then state should be camp
|
||||
|
||||
;; sooner or later nomads learn to keep flocks
|
||||
if state is in grassland or heath and some neighbours are camp then 1 chance in 2 state should be pasture
|
||||
|
||||
;; and more herds support more people
|
||||
if state is in grassland or heath and more than 2 neighbours are pasture then 1 chance in 3 state should be camp
|
||||
if state is pasture and more than 3 neighbours are pasture and fewer than 1 neighbours are camp and fewer than 1 neighbours within 2 are house then state should be camp
|
||||
|
||||
;; the idea of agriculture spreads
|
||||
if state is in grassland or heath and some neighbours within 2 are house then state should be pasture
|
||||
|
||||
;; nomads don't move on while the have crops growing. That would be silly!
|
||||
if state is camp and some neighbours are ploughland then state should be camp
|
||||
|
||||
;; once the idea of settled habitation is established, people will settle near harbours
|
||||
if state is camp and some neighbours are harbour and some neighbours are house then state should be house
|
||||
|
||||
;; Impoverished pasture can't be grazed permanently
|
||||
if state is pasture and fertility is less than 2 then 1 chance in 3 state should be heath
|
||||
|
||||
;; nomads move on
|
||||
if state is camp then 1 chance in 5 state should be waste
|
||||
|
||||
;; pasture that's too far from a house or camp will be abandoned
|
||||
if state is pasture and fewer than 1 neighbours within 3 are house and fewer than 1 neighbours within 2 are camp then state should be heath
|
||||
|
||||
;; markets spring up near settlements
|
||||
if state is in grassland or pasture and more than 1 neighbours are house then 1 chance in 10 state should be market
|
||||
|
||||
;; good fertile pasture close to settlement will be ploughed for crops
|
||||
if state is pasture and fertility is more than 10 and altitude is less than 100 and some neighbours are camp or some neighbours are house then state should be ploughland
|
||||
|
||||
if state is ploughland then state should be crop
|
||||
|
||||
;; after the crop is harvested, the land is allowed to lie fallow. But cropping
|
||||
;; depletes fertility.
|
||||
if state is crop then state should be grassland and fertility should be fertility - 1
|
||||
|
||||
;; if there's reliable food available, nomads build permanent settlements
|
||||
if state is in camp or abandoned and some neighbours are crop then state should be house
|
||||
if state is abandoned and some neighbours are pasture then state should be house
|
||||
;; people camp near to markets
|
||||
if state is in waste or grassland and some neighbours are market then state should be camp
|
||||
|
||||
;; a market in a settlement survives
|
||||
if state is market and some neighbours are inn then state should be market
|
||||
if state is market then state should be grassland
|
||||
|
||||
;; a house near a market in a settlement will become an inn
|
||||
if state is house and some neighbours are market and more than 1 neighbours are house then 1 chance in 5 state should be inn
|
||||
;; but it will need some local custom to survive
|
||||
if state is inn and fewer than 3 neighbours are house then state should be house
|
||||
|
||||
;; if there aren't enough resources houses should be abandoned
|
||||
;; resources from fishing
|
||||
if state is house and some neighbours are harbour then state should be house
|
||||
;; from farming
|
||||
if state is house and some neighbours are pasture then state should be house
|
||||
if state is house and some neighbours are ploughland then state should be house
|
||||
if state is house and some neighbours are crop then state should be house
|
||||
;; from the market
|
||||
if state is house and some neighbours are market then state should be house
|
||||
if state is house then 1 chance in 2 state should be abandoned
|
||||
if state is abandoned then 1 chance in 5 state should be waste
|
||||
|
||||
## Vegetation rules
|
||||
;; rules which populate the world with plants
|
||||
|
||||
;; Occasionally, passing birds plant tree seeds into grassland
|
||||
|
||||
if state is grassland then 1 chance in 10 state should be heath
|
||||
|
||||
;; heath below the treeline grows gradually into forest
|
||||
|
||||
if state is heath and altitude is less than 120 then state should be scrub
|
||||
if state is scrub then 1 chance in 5 state should be forest
|
||||
|
||||
;; Forest on fertile land grows to climax
|
||||
|
||||
if state is forest and fertility is more than 5 and altitude is less than 70 then state should be climax
|
||||
|
||||
;; Climax forest occasionally catches fire (e.g. lightning strikes)
|
||||
|
||||
if state is climax then 1 chance in 500 state should be fire
|
||||
|
||||
;; Forest neighbouring fires is likely to catch fire. So are buildings.
|
||||
if state is in forest or climax or camp or house or inn and some neighbours are fire then 1 chance in 3 state should be fire
|
||||
|
||||
;; Climax forest near to settlement may be cleared for timber
|
||||
if state is in climax and more than 3 neighbours within 2 are house then state should be scrub
|
||||
|
||||
;; After fire we get waste
|
||||
|
||||
if state is fire then state should be waste
|
||||
|
||||
;; waste near settlement that is fertile becomes ploughland
|
||||
if state is waste and fertility is more than 10 and some neighbours are house or some neighbours are camp then state should be ploughland
|
||||
|
||||
;; And after waste we get pioneer species; if there's a woodland seed
|
||||
;; source, it's going to be heath, otherwise grassland.
|
||||
|
||||
if state is waste and some neighbours are scrub then state should be heath
|
||||
if state is waste and some neighbours are forest then state should be heath
|
||||
if state is waste and some neighbours are climax then state should be heath
|
||||
if state is waste then state should be grassland
|
||||
|
||||
## Potential blockers
|
||||
|
||||
;; Forest increases soil fertility.
|
||||
if state is in forest or climax then fertility should be fertility + 1
|
||||
|
||||
## Initialisation rules
|
||||
|
||||
;; Rules which deal with state 'new' will waste less time if they're near the
|
||||
;; end of the file
|
||||
|
||||
;; below the waterline we have water.
|
||||
|
||||
if state is new and altitude is less than 10 then state should be water
|
||||
|
||||
;; above the snowline we have snow.
|
||||
if state is new and altitude is more than 200 then state should be snow
|
||||
|
||||
;; otherwise, we have grassland.
|
||||
if state is new then state should be grassland
|
||||
|
355844
resources/test/galloway-biome-20240407.edn
Normal file
355844
resources/test/galloway-biome-20240407.edn
Normal file
File diff suppressed because it is too large
Load diff
331393
resources/test/galloway-drainage-20240407.edn
Normal file
331393
resources/test/galloway-drainage-20240407.edn
Normal file
File diff suppressed because it is too large
Load diff
355844
resources/test/galloway-populated-20240407.edn
Normal file
355844
resources/test/galloway-populated-20240407.edn
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,27 +1,53 @@
|
|||
(ns cc.journeyman.the-great-game.proving.core
|
||||
"Phase one of '[Baking the World](Bakine-the-world.html#phase-one-proving-the-procedural-world)'"
|
||||
(require [mw-engine.core :refer []]
|
||||
[mw-engine.drainage :refer []]
|
||||
[mw-engine.flow :refer []]))
|
||||
(:require [mw-engine.core :refer [run-world]]
|
||||
[mw-engine.drainage :refer [run-drainage]]
|
||||
;;[mw-engine.flow :refer []]
|
||||
[mw-engine.heightmap :refer [apply-heightmap]]
|
||||
[mw-parser.declarative :refer [compile]]))
|
||||
|
||||
(defn get-drainage-map
|
||||
"Given this `height-map` (a monochrome raster) and optionally this
|
||||
`rainfall-map` (also a monochrome raster), return a drainage map (exact
|
||||
format uncertain, probably still a raster)."
|
||||
([height-map])
|
||||
([height-map rainfall-map]))
|
||||
`rainfall-map` (also a monochrome raster), return a drainage map
|
||||
(a microworld style world tagged with drainage data)."
|
||||
([height-map]
|
||||
(run-drainage (apply-heightmap height-map)))
|
||||
([height-map _rainfall-map]
|
||||
;; TODO: currently I'm ignoring the rainfall map and relying on
|
||||
;; `rain-world` in `mw-engine.drainage`, but I should not do so.
|
||||
(get-drainage-map height-map)))
|
||||
|
||||
(defn get-biome-map
|
||||
"Given this `height-map` (a monochrome raster) and optionally this
|
||||
`rainfall-map` (also a monochrome raster), return a biome map."
|
||||
([height-map])
|
||||
([height-map rainfall-map]))
|
||||
`rainfall-map` (also a monochrome raster), return a biome map (a
|
||||
microworld style world tagged with vegetation, etc, data). "
|
||||
([height-map]
|
||||
(let [drained-world (get-drainage-map height-map)]
|
||||
(run-world drained-world (compile (slurp "resources/baking/biome-rules.txt")) (count drained-world))))
|
||||
([height-map _rainfall-map]
|
||||
(get-biome-map height-map)))
|
||||
|
||||
(defn populate-world
|
||||
"Given this `biome-map` (as returned by `get-biome-map`), populate a world
|
||||
(probably some form of database) and return a structure which allows that
|
||||
database o be interrogated."
|
||||
[biome-map drainage-map])
|
||||
[biome-map]
|
||||
(let [world (run-world biome-map (compile (slurp "resources/baking/settlement-rules.txt")) (count biome-map))]
|
||||
;; right, with that settled world, I'm going to put one herdsman with
|
||||
;; five animals (either all sheep, all cattle, all goats, all horses or
|
||||
;; all camels on each cell with state camp, and one settler; one farmer
|
||||
;; on each cell with state farm, and one settler; one innkeeper on each
|
||||
;; cell with state inn. Given that our cells are currently one kilometer
|
||||
;; squares (i.e. 100 hectares) the 'inn' cell will be sufficient to
|
||||
;; start a village, and the 'farm' cells will ultimately support about
|
||||
;; five farming households.
|
||||
|
||||
;; Settlers should move around, forming roads
|
||||
|
||||
;; what I return at the end of this is a structure which contains keys
|
||||
;; to a database I've stored all the NPCs in, and a (vector) roadmap of
|
||||
;; all the roads that have been created, and a (vector) drainage map.
|
||||
{:world world}))
|
||||
|
||||
(defn get-road-map
|
||||
[populated-world])
|
||||
|
@ -32,7 +58,7 @@
|
|||
([height-map rainfall-map]
|
||||
(let [drainage-map (get-drainage-map height-map)
|
||||
biome-map (get-biome-map height-map rainfall-map)
|
||||
populated-world (populate-world biome-map drainage-map)]
|
||||
populated-world (populate-world biome-map)]
|
||||
{:height-map height-map
|
||||
:drainage-map drainage-map
|
||||
:populated-world populated-world
|
||||
|
|
Loading…
Reference in a new issue