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
Type
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
BuildingKind::Marketvariant +BuildingDefregistry entryChunk 2 -- Caravan NPCs
Job::TraderNPC type spawned by Market buildingsCarriedResourcescomponent (similar toCarriedLootpattern from Stage 18)Chunk 3 -- Scheduled Trades
Chunk 4 -- AI Faction Trading
Dependencies
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