Skip to content

Instantly share code, notes, and snippets.

@leb2
Last active March 11, 2026 07:20
Show Gist options
  • Select an option

  • Save leb2/0db23412d936eadc6c6fae945629d5ed to your computer and use it in GitHub Desktop.

Select an option

Save leb2/0db23412d936eadc6c6fae945629d5ed to your computer and use it in GitHub Desktop.
Shattered Dominion: Building Graph Economy System Design

Building Graph Economy System

Overview

Replace the abstract settlement building-slot system with a spatial economy where all buildings exist on hex tiles and are connected via a player-configured supply graph. Workers physically carry resources along graph edges. The Town Hall is the central storage node; all other buildings are independent map structures linked to it directly or through processing chains.

Core Concepts

Buildings on the Map

Every building occupies one or more hex tiles. No building slots. A settlement is defined by its Town Hall — all buildings linked (directly or transitively) to a Town Hall belong to that settlement.

  • Placement: Player selects a tile, chooses a building type. Server validates terrain requirements, range from Town Hall, and that the tile is unoccupied.
  • Range: Buildings must be within a configurable radius of their Town Hall (e.g., 8 tiles for Tier 1, expanding with tier).
  • Tile requirements: Each building type specifies valid terrain (e.g., lumber camp → forest, mine → highlands/mountain, farm → lowlands).
  • Multi-tile buildings: Some buildings occupy multiple adjacent tiles (e.g., a Tier 3+ Town Hall might occupy a hex cluster). For MVP, all buildings are single-tile.
  • Construction: When a player places a building, the settlement spawns a builder unit that walks to the site and constructs it over N ticks. The building is non-functional until construction completes.

The Supply Graph

Buildings form a directed graph. Players create supply links (edges) between buildings. Each link represents a route along which workers carry a specific resource.

                    ┌─── Sawmill ───┐
Lumber Camp ────────┤               ├──── Town Hall
  (raw_timber)      └───────────────┘       (storage)
                         (lumber)

Mine ──────────── Foundry ──────────── Town Hall
  (iron_ore)       (iron)               (storage)

Link properties:

  • Source building — the building producing or holding the resource
  • Destination building — the building consuming or storing the resource
  • Resource type — what is carried along this link (e.g., raw_timber, lumber)
  • Assigned workers — how many workers service this link (more workers = higher throughput)
  • Distance — hex distance between the two buildings (auto-calculated)

Rules:

  • A link can only carry one resource type.
  • The source must produce or hold that resource type.
  • The destination must consume or store that resource type.
  • Links can connect any two buildings in the same settlement (no range limit beyond settlement radius, since both buildings are already within range of the Town Hall).
  • A building can have multiple outgoing and incoming links.

Workers and Transport

Workers are units that service supply links. They are drawn from the settlement's population (not recruited like military units).

Worker cycle:

  1. Worker departs source building
  2. Walks to source building (if not already there)
  3. Loads up to CARRY_CAPACITY of the link's resource
  4. Walks to destination building (travel time = hex distance × TICKS_PER_HEX)
  5. Deposits resources at destination
  6. Walks back to source
  7. Repeat

Constants (tunable):

  • CARRY_CAPACITY: 10 units per trip
  • TICKS_PER_HEX: 5 ticks per hex of travel (at 1 Hz tick rate = 5 seconds per hex)
  • Workers are visible on the map as small units moving between buildings

Throughput formula:

throughput_per_tick = (num_workers × CARRY_CAPACITY) / (2 × distance × TICKS_PER_HEX)

Two workers on a 3-hex link: (2 × 10) / (2 × 3 × 5) = 0.67 resources/tick

Workers stagger their departure times automatically so resources flow steadily rather than in bursts.

Building Types (Revised)

Buildings no longer exist in zone-specific slots. Instead, terrain determines what you can build where.

Extraction Buildings (placed on resource tiles)

Building Terrain Produces Workers
Lumber Camp forest raw_timber 2-4
Mine highlands, mountain iron_ore, copper, coal (depends on tile deposits) 3-6
Quarry highlands stone 2-4
Saltpeter Works desert saltpeter 2-3
Sulfur Vent volcanic_scar sulfur 2-3

Processing Buildings (placed on any owned land tile)

Building Consumes Produces Workers
Sawmill raw_timber lumber 3-5
Foundry iron_ore iron 4-6
Workshop lumber + iron tools 3-5
Powder Mill saltpeter + sulfur gunpowder 2-4

Production Buildings (terrain-dependent)

Building Terrain Produces Workers
Farm lowlands, river_delta food 3-6
Fishery coast (adjacent to ocean) food 2-4

Infrastructure Buildings

Building Function
Town Hall Central storage, defines settlement. Stores all resources.
Housing Increases max population within radius
Tavern Consumes food, boosts morale
Watchtower Extends vision radius
Barracks Recruits military units
Market Enables trade with other players

Production and Consumption

Extraction buildings produce at a flat rate per tick when staffed:

  • Lumber Camp: 5 raw_timber/tick (stored locally in a small buffer of 50)
  • Mine: 3 iron_ore/tick (buffer of 30)

Processing buildings consume inputs and produce outputs:

  • Sawmill: consumes 3 raw_timber → produces 2 lumber per tick
  • Foundry: consumes 4 iron_ore → produces 2 iron per tick

Local buffers: Each building has a small input and output buffer (e.g., 50 units). Workers carry resources between buildings. If the output buffer is full, production pauses. If the input buffer is empty, processing pauses. This creates natural backpressure through the graph.

The Town Hall has a large storage capacity (scales with tier). Resources deposited here are available for construction, trade, and military recruitment.

Construction Flow

  1. Player clicks a tile and selects "Build Lumber Camp"
  2. Server validates: terrain is forest, tile is within settlement radius, player has resources (if any cost), site limit not exceeded
  3. Server deducts build cost from Town Hall stockpile
  4. A builder worker spawns at the Town Hall
  5. Builder walks to the target tile (visible as a unit on the map)
  6. Builder arrives → construction begins (progress bar, N ticks)
  7. Construction completes → building appears on tile, builder walks home and is returned to population pool
  8. Player then creates supply links from the new building to connect it to the economy graph

Supply Link Configuration (UI)

The player configures links through the settlement/building UI:

  1. Select a building on the map
  2. Click "Add Supply Link"
  3. Click the destination building
  4. Choose which resource to carry (filtered to valid options)
  5. Assign workers to the link (slider or +/- buttons)

Links are shown visually on the map as dotted lines or paths between buildings, with tiny worker dots moving along them.

Settlement Tier and Radius

The Town Hall defines the settlement's tier and build radius:

Tier Build Radius Max Population Max Extraction Sites
1 5 tiles 30 3
2 7 tiles 50 5
3 9 tiles 80 8
4 11 tiles 120 12
5 14 tiles 180 18

Upgrading the Town Hall costs resources from its stockpile and expands the buildable area.

Strategic Implications

  • Geography matters: A settlement near forest AND highlands can run lumber + mining. One surrounded by desert has different options.
  • Distance optimization: Placing your sawmill between the lumber camp and town hall reduces total travel time.
  • Vulnerability: Workers traveling on links can be attacked by enemy military units. Longer links = more exposure. This makes compact settlements safer but limits resource diversity.
  • Expansion pressure: As nearby resources are claimed, you need to push further out or found new settlements.
  • Raiding: Attacking an enemy's supply links (killing workers) cripples their economy without needing to siege their Town Hall.
  • Chokepoints: Placing watchtowers or barracks along key supply routes protects your economy.

Trait and Adjacency Integration

The existing trait system carries over:

  • Fertile Soil trait on a tile boosts Farm output on that tile
  • Deep Vein trait boosts Mine output
  • Ley Line produces arcane_dust at the tile (needs a collection building)

Adjacency combos now have spatial meaning — the buildings must actually be on adjacent tiles for the combo to trigger, which happens naturally since they're on the map.

Migration from Current System

What Changes

  • building-types.ts — redefine all buildings with terrain requirements, local buffers, no slot zones
  • settlement.ts — remove building slots, add extraction site tracking, link graph
  • economy-loop.ts — rewrite to tick buildings on tiles, process supply links, move workers
  • Protocol — new messages for place-building-on-tile, create-supply-link, assign-workers

What Stays

  • Resource types and names
  • Trait system (applied to tiles, affects buildings on those tiles)
  • Trade system (operates from Town Hall stockpile)
  • Unit recruitment (from Barracks building on a tile)
  • Morale system (settlement-wide, based on food/housing/tavern as before)
  • Tile claiming (still exists, but buildings can be placed on unclaimed tiles too)

New Server State

interface ExtractionSite {
  id: string;
  buildingType: string;
  tileQ: number;
  tileR: number;
  settlementId: string; // owning Town Hall
  constructionProgress: number; // 0-1, 1 = complete
  inputBuffer: Record<string, number>;
  outputBuffer: Record<string, number>;
  assignedWorkers: number;
}

interface SupplyLink {
  id: string;
  sourceId: string; // building/site ID
  destinationId: string;
  resourceType: string;
  assignedWorkers: number;
  workers: SupplyWorker[]; // active worker units on this link
}

interface SupplyWorker {
  id: string;
  linkId: string;
  state: 'to_source' | 'loading' | 'to_dest' | 'unloading';
  currentTileQ: number;
  currentTileR: number;
  carryingAmount: number;
  ticksRemaining: number; // ticks until next state transition
}

MVP Scope

For the first implementation:

  1. Lumber Camp only — one extraction building type to prove the system
  2. Town Hall + Lumber Camp + Sawmill — a minimal 3-node supply chain
  3. Worker movement — visible workers walking between buildings
  4. Supply link UI — basic link creation and worker assignment
  5. Local buffers — buildings store small amounts, workers carry between them

After MVP works:

  • Add Mine, Quarry, Farm, Fishery
  • Add processing buildings (Foundry, Workshop, Powder Mill)
  • Multi-tile buildings
  • Worker pathfinding improvements
  • Raiding/combat interaction with workers

Potential Add-Ons

These are ideas that could layer on top of the core supply graph system to make it more strategically interesting. None are required for MVP — they should be evaluated after the base system is fun.

Alchemical Transmutation Paths

The path resources take through the supply graph determines what you can produce. Same raw inputs routed through different building chains yield different outputs.

Iron Ore → Foundry → Iron                              (standard)
Iron Ore → Foundry → Alchemical Lab → Void Iron        (rare military material)
Raw Timber → Sawmill near Ley Line → Warded Lumber      (magical building material)

The supply graph becomes the crafting system. Players discover recipes by experimenting with building arrangements and link topologies. This fits the "volatile alchemy" theme — raw materials undergo different transformative processes depending on the buildings they pass through.

Design implications:

  • Recipe discovery could be explicit (recipe book unlocked by research) or emergent (players experiment and share discoveries)
  • Adds a reason to build unusual graph shapes rather than always optimizing for shortest path
  • Rare materials create trade value between players with different graph setups

Graph Resonance

Closed loops in the supply graph generate a resonance bonus. If resources flow in a cycle (A→B→C→A), all buildings in the loop get a production multiplier.

  • Short loop (3 nodes): +10% production boost
  • Medium loop (4-5 nodes): +20% boost
  • Long loop (6+ nodes): +30% boost, but harder to maintain and defend

This rewards creative graph design over simple star topologies (everything pointing at the Town Hall). A player who builds an elegant circular economy outproduces one with a naive layout.

Example:

Lumber Camp → Sawmill → Workshop → Lumber Camp
   (raw_timber)  (lumber)   (tools delivered back to camp, boosting harvest speed)

The tools flowing back to the Lumber Camp have a thematic justification (better tools = faster harvesting) while the resonance bonus rewards the player for creating the loop.

Contested Links as Gameplay

Supply links that cross unclaimed or enemy-adjacent territory are visible to nearby enemies. Workers walking between buildings act as unintentional scouts — and targets.

Tension: Short links through owned territory are safe but limit which resources you can reach. Long links to a distant forest tile yield valuable resources but expose workers to raids.

Counterplay:

  • Build watchtowers along supply routes to provide early warning
  • Route links through forested tiles for concealment (workers are harder to spot)
  • Use decoy links with few workers to mislead enemy scouts about your actual production
  • Escort valuable supply routes with military units

Your economy's shape on the map becomes strategic intelligence. A scout who spots a long supply line of workers carrying iron ore knows you're building up military capacity.

Worker Experience

Workers who repeatedly travel the same supply link accumulate experience, improving over time:

Level Trips Required Carry Capacity Travel Speed
Novice 0 10 (base) 1.0x
Skilled 50 trips 15 (+50%) 1.1x
Expert 150 trips 18 (+80%) 1.2x
Master 300 trips 20 (+100%) 1.3x

If a worker dies (killed by raiders), that accumulated experience is permanently lost. Replacing them with a novice worker halves throughput on that link until the new worker levels up.

Strategic implications:

  • Protecting veteran workers is critical — raiding an enemy's experienced supply lines is devastating
  • Players face a choice: consolidate experienced workers on key links, or spread novices across many links
  • Worker experience becomes a form of soft territory control — you're invested in the routes you've built up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment