Skip to main content

Module node

Module node 

Source
Expand description

Per-lot node generator.

node_at(x, y) returns either Some(NodeSpec) (this lot carries a node) or None (empty lot — procedural gap). The result is a pure function of (TREE_SEED, x, y): the same input always produces byte-identical output.

Lot geometry: the canvas is an infinite grid of lots, each LOT_W × LOT_H cells. A lot’s node (if any) is a procedurally-sized rectangular box placed at a procedurally-jittered offset inside the lot. Boxes never overlap because each lives strictly inside its lot interior.

Edges: any two lots whose (x, y) differ by at most 1 on each axis (“8-king” adjacency) may be connected. Existence is rolled with edge_exists(a, b) from a position-seeded RNG, so the connectivity pattern is also stable forever.

Structs§

NodeSpec
A single tree node, regenerated from (TREE_SEED, lot) on demand.

Enums§

Rarity
Visual classification, computed from the rolled primitive stack. Drives box dimensions, edge weight, and biome tinting in the renderer.

Constants§

LOT_H
LOT_W
Size of one “lot” cell in the infinite tree grid, in terminal cells. 36 wide × 10 tall comfortably holds a Notable box (16×5) with breathing room for edge routing.
NODE_BASE_COST
Base cost at distance 0 (before rarity and jitter). The origin lot is auto-owned so this never quotes a real purchase, but it anchors the ramp: cost(d) = NODE_COST_MULT * NODE_BASE_COST * NODE_COST_GROWTH^d * rarity_factor * jitter.
NODE_COST_GROWTH
Per-lot exponential growth rate. Each step further from the origin multiplies the node’s cost by this factor (manhattan distance). The shape of the late-game wall lives here — bump it to make deep nodes balloon faster, lower it for a gentler ramp.
NODE_COST_MULT
Cost scales with Manhattan distance from origin: deeper = pricier. Flat multiplier on every node’s rolled cost — shifts the whole pricing curve up or down without bending it. Use this when “the tree feels too cheap” but the SHAPE of the ramp is correct.

Functions§

anchor_of
For a populated lot, return its “anchor parent” — the deterministic king-neighbor that is GUARANTEED to have an edge to this lot.
bresenham_path
Bresenham-style staircase between (ax, ay) and (bx, by) in canvas-grid coords. Single-axis steps only, interleaved by cross-multiplied normalized progress so the staircase doesn’t degenerate into a one-big-L jolt. Returns cells in start→end order.
count_leading_in_rect
Count cells at the START of path whose canvas-grid coords lie inside the rect (box_x, box_y, box_w, box_h). Used by the edge renderer + the unlock-anim’s completion check to skip the “inside the source box” prefix when seeding the wavefront. Iteration stops at the first cell that’s outside the rect — interior gaps don’t inflate the count.
count_trailing_in_rect
Mirror of count_leading_in_rect but counting from the END of the path inward.
diagonal_route_via
For a diagonal edge between a and b, return the “L-bend corner lot” the renderer should route through — the corner lot that’s empty. None for non-diagonal pairs (renderer chooses by longer-axis heuristic instead).
edge_exists
Procgen decision: does an edge exist between two neighboring lots? Returns false for non-neighbors. Both lots must actually contain a node — call node_at first.
edge_path_cells
Cells along the rendered edge between two nodes, in canonical lo→hi lot order (lex on (x, y)). Returns an empty Vec if either endpoint has no node.
is_king_neighbor
True when the lots at a and b are 8-king neighbors (chebyshev distance 1). Returns false for the same lot (a node isn’t its own neighbor) and for any pair further away.
neighbors_of
The 8 neighboring lots of c.
neighbors_with_nodes
Helper: all TreeCoords that are king-neighbors of c AND have a node.
node_at
Procgen entry point: returns the node at lot (x, y), or None if the lot is empty.
roll_cost