mw-engine.drainage

Experimental, probably of no interest to anyone else; attempt to compute drainage on a world, assumed to have altitudes already set from a heightmap.

*sealevel*

dynamic

TODO: write docs

explore-lake

(explore-lake _world _cell)

Return a sequence of cells starting with this cell in this world which form a contiguous lake

find-lakes

(find-lakes world)

Identify cells in this world which are lakes.

flood-hollow

(flood-hollow _world cell neighbours)(flood-hollow world cell)

Raise the altitude of a copy of this cell of this world to the altitude of the lowest of its neighbours.

flood-hollows

(flood-hollows world)

Flood all local hollows in this world. At this stage only floods single cell hollows.

flow

Compute the total flow upstream of this cell in this world, and return a cell identical to this one but having a value of its flow property set from that computation. The function is memoised because the consequence of mapping a recursive function across an array is that many cells will be revisited - potentially many times.

Flow comes from a higher cell to a lower only if the lower is the lowest neighbour of the higher.

flow-contributors

(flow-contributors cell world)

Return a list of the cells in this world which are higher than this cell and for which this cell is the lowest neighbour, or which are at the same altitude and have greater flow

flow-nr

(flow-nr cell world)

Experimental non recursive flow algorithm, needs to be run on a world as many times as there are distinct altitude values. This algorithm works only if applied sequentially from the highest altitude to the lowest, see flow-world-nr.

flow-world

(flow-world world)

Return a world like this world, but with cells tagged with the amount of water flowing through them.

flow-world-nr

(flow-world-nr world)

Experimental non-recursive flow-world algorithm

is-hollow

(is-hollow world cell)

Detects point hollows - that is, individual cells all of whose neighbours are higher. Return true if this cell has an altitude lower than any of its neighbours in this world

is-lake?

(is-lake? world cell)

If this cell in this world is not part of a lake, return nil. If it is, return a cell like this cell tagged as part of a lake.

max-altitude

TODO: write docs

rain-row

(rain-row row)(rain-row row rain-probability)(rain-row row map-width previous-altitude drops-in-cloud)

Return a row like this row, across which rainfall has been distributed; if rain-probability is specified, it is the probable rainfall on a cell with no gradient.

rain-world

(rain-world world)

Simulate rainfall on this world. TODO: Doesn’t really work just now - should rain more on west-facing slopes, and less to the east of high ground

rainfall

(rainfall gradient remaining map-width)

Compute rainfall for a cell with this gradient west-east, given remaining drops to distribute, and this overall map width.

run-drainage

(run-drainage hmap)

Create a world from the heightmap hmap, rain on it, and then compute river flows.