Skip to content

feature: market building with trade caravans between factions #108

@abix-

Description

@abix-

Type

  • feature (economy / diplomacy)

Problem

There is no way to trade resources between towns. The player's economy is isolated -- surplus resources in one town can't help a deficit in another, and there's no economic interaction with AI factions.

Goal

A Market building enables inter-faction trade via physical caravans that move across the terrain. Players can set up one-time or scheduled (recurring) trades, exchanging resources like food, gold, wood, and stone with other towns that also have a Market.

Scope

Chunk 1 -- Market Building + Trade UI

  • New BuildingKind::Market variant + BuildingDef registry entry
  • Market building placed in town grid (Economy category)
  • Trade UI panel when Market is selected: pick target town, resource type, amount, direction (buy/sell)
  • Trade offers listed per-market with accept/reject for incoming offers

Chunk 2 -- Caravan NPCs

  • New Job::Trader NPC type spawned by Market buildings
  • Caravan NPC carries resources physically across the map using existing pathfinding (A*/HPA*)
  • Caravan has a CarriedResources component (similar to CarriedLoot pattern from Stage 18)
  • Caravan walks from origin Market to destination Market, deposits resources on arrival
  • Vulnerable to raiders while traveling -- killing a caravan drops its goods

Chunk 3 -- Scheduled Trades

  • One-time trade: single caravan dispatch
  • Scheduled trade: recurring dispatch at configurable interval (e.g., every 2 game-hours)
  • Schedule stored as ECS component on Market entity
  • Cancel/modify schedules via Market UI
  • Trade requires both towns to have a Market building

Chunk 4 -- AI Faction Trading

  • AI towns with Markets can propose trades to the player
  • AI trade offers appear in the Market UI
  • AI evaluates trade value based on resource surplus/deficit
  • Ties into Stage 29 (Diplomacy) -- trade reputation affects faction relations

Dependencies

  • Stage 26 (Resources) for wood/stone/iron resource types
  • Stage 29 (Diplomacy) for faction reputation (Chunk 4 only)
  • Existing pathfinding (Stage 20) for caravan movement
  • Existing loot carry pattern (Stage 18) for resource transport

Design Notes

The Merchant building already exists but serves as a buy/sell equipment shop. The Market is a separate building focused on resource trade between towns. Consider whether the existing Merchant could be repurposed or if a distinct building makes more sense.

Caravans should use the existing NPC movement system (GPU compute for position, CPU for decision/pathfinding). They don't fight back -- they flee or die if attacked, dropping carried resources as loot.

Acceptance Criteria

  • Market building placeable in town grid
  • Trade UI: select target town, resource, amount
  • Caravan NPC physically walks between towns carrying resources
  • Resources transfer on caravan arrival at destination Market
  • Caravans are vulnerable to attack (drop resources on death)
  • Scheduled trades dispatch caravans at recurring intervals
  • cargo clippy --release -- -D warnings clean

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew functionality, behavior changes, or larger feature workwaitingWaiting on a decision, dependency, or prerequisite

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions