A top-down, low-poly 3D trading simulation game built with Three.js where players manage a medieval caravan, buying and selling goods in a dynamic economy, navigating roads and obstacles, encountering random events, hiring mercenaries, and managing multiple save slots.
caravan/
├── index.html # Main HTML file with start screen and save slots
├── gamedesign.md # Complete game design document
├── game.js # Legacy monolithic game file (can be removed)
│
├── src/ # Source code
│ ├── css/
│ │ └── styles.css # All game styles (including start screen and save slots)
│ │
│ ├── data/ # Game data files
│ │ ├── config.js # Game configuration and constants
│ │ ├── goods.js # Tradeable goods definitions
│ │ ├── cities.js # 15 cities with unique backstories and economies
│ │ ├── roads.js # Road network connections between cities
│ │ ├── encounters.js # Random encounters by terrain type
│ │ └── mercenaries.js # Mercenary types and generation
│ │
│ ├── js/ # Core game logic
│ │ ├── main.js # Main game class and initialization with save/load
│ │ └── gameState.js # Game state management with history tracking
│ │
│ ├── managers/ # Game managers
│ │ ├── worldManager.js # 3D world creation with terrain types
│ │ ├── caravanManager.js # Player caravan control
│ │ ├── cityManager.js # 15 cities creation and management
│ │ └── roadManager.js # Road system with bridges and obstacles
│ │
│ ├── systems/ # Game systems
│ │ ├── marketSystem.js # Trading and economy logic
│ │ ├── inputSystem.js # Input handling (mouse, keyboard)
│ │ ├── resourceSystem.js # Food consumption and daily costs
│ │ ├── pathfindingSystem.js # BFS pathfinding through road network
│ │ ├── encounterSystem.js # Random encounter generation
│ │ ├── mercenarySystem.js # Mercenary hiring and management
│ │ └── saveManager.js # Save/load system with 3 save slots
│ │
│ └── ui/ # UI components
│ ├── uiManager.js # UI display and interactions with tabs
│ ├── debugManager.js # Debug console for testing
│ ├── minimapManager.js # 2D minimap with zoom controls
│ └── tooltipManager.js # City tooltips on hover
│
└── assets/ # Game assets
├── models/ # 3D models (.glb, .gltf files)
├── textures/ # Texture images
└── sounds/ # Audio files
- config.js: Central configuration for all game constants
- goods.js: Definitions for all tradeable items
- cities.js: 15 cities with positions, economies, backstories, and terrain types
- roads.js: Road network defining connections between cities
- encounters.js: 25+ random encounters organized by terrain type (plains, mountains, forest, desert, river)
- mercenaries.js: 6 mercenary types with unique skills and name pools
- main.js: Main Game class with save/load system, start screen, and slot management
- gameState.js: Manages game state with history tracking (journeys, trades, encounters)
- worldManager.js: Creates 3D world with color-coded terrain types
- caravanManager.js: Handles player caravan 3D model and movement
- cityManager.js: Creates 15 unique cities with 3D models
- roadManager.js: Manages road network with bridges and obstacles (mountains, rivers)
- marketSystem.js: All trading logic with buy/sell mechanics
- inputSystem.js: Mouse and keyboard input handling with raycasting
- resourceSystem.js: Food consumption, daily costs, and journey tracking
- pathfindingSystem.js: BFS pathfinding through road network, obstacle detection
- encounterSystem.js: Random encounter generation every 100 units traveled
- mercenarySystem.js: Mercenary hiring, interactive encounter resolution
- saveManager.js: Save/load with 3 independent save slots and auto-save
- uiManager.js: Manages all DOM elements, tabbed Caravan Chronicles modal
- debugManager.js: Debug console with teleport, reset, and test commands
- minimapManager.js: 2D minimap with zoom controls and city tracking
- tooltipManager.js: City information tooltips on hover
- Start a local web server (required for JavaScript modules):
cd /path/to/caravan python -m http.server 8000 - Open browser to
http://localhost:8000 - Start Screen: Choose "New Game" or "Load Game"
- Save Slot Selection: Pick one of 3 save slots
- Play: Click on cities to travel, trade goods, hire mercenaries
- Save: Click "💾 Save Game" button or auto-saves every 60 seconds
- Quit: Click "🚪 Quit to Menu" to return to start screen
- 15 Cities with unique economies and backstories
- 10 Tradeable goods with varying prices
- Market Interface with buy/sell controls and profit calculation
- Dynamic prices based on production and consumption
- Road network connecting all cities with bridges
- Pathfinding automatically finds routes between cities
- Obstacles: Mountains and rivers block direct travel
- Terrain types: Plains, mountains, forests, deserts, rivers
- Food consumption during travel (5 food/day base + mercenaries)
- Daily wages for mercenaries (6-10 gold/day per mercenary)
- 25+ random encounters based on terrain type
- Positive encounters: Traders, helpful travelers, abandoned supplies
- Negative encounters: Bandits, harsh weather, broken equipment
- Encounter frequency: Check every 100 units traveled
- Interactive encounters: Mercenaries provide choices (combat, negotiate, avoid, forage, trade)
- 6 mercenary types: Warrior, Scout, Diplomat, Cook, Ranger, Merchant
- Unique skills: Combat, negotiation, foraging, avoidance, trading, food efficiency
- Hiring: Available at city inns with hire costs and daily wages
- Encounter assistance: Mercenaries provide strategic options during encounters
- Success rates: Skill-based chance of success for encounter actions
- Start Screen: New Game / Load Game options
- Save Slot Management: 3 independent save slots with game info display
- HUD: Real-time display of gold, food, cargo, and date
- Caravan Chronicles: Tabbed modal with 5 sections:
- Cargo inventory with purchase prices
- Hired mercenaries with skill display
- Journey history with routes and distances
- Encounter history with outcomes
- Recent trades with profit tracking
- City Modal: Market, Inn, and general city information
- Minimap: 2D overview with zoom controls
- City Tooltips: Hover information with produced/consumed goods
- Debug Console: Press
~for development commands
- 3 Save Slots: Independent games in separate slots
- Auto-Save: Every 60 seconds
- Manual Save: Button in HUD with visual feedback
- Slot Info: Displays gold, day, and save date/time
- Persistent: Saves position, cargo, gold, food, mercenaries, history, city economies
- Quit to Menu: Auto-saves and returns to start screen
- Add to
src/data/goods.jswith name, basePrice, weight - Add market prices to cities in
src/data/cities.js(produces/consumes)
- Add city data to
src/data/cities.jswith position, produces, consumes, backstory, terrain - Add road connections in
src/data/roads.js - CityManager will automatically create it
- Add to
src/data/encounters.jsunder appropriate terrain type - Include name, type, chance, description, and effects (gold/food gains/losses)
- Add to
src/data/mercenaries.jswith type, skills, costs, and name pool - MercenarySystem will handle generation and hiring
- Create a new manager/system file in appropriate folder
- Initialize it in
main.jsinitializeSystems()method - Connect it to existing systems as needed
- Add UI elements in
index.htmlanduiManager.js
- Edit
src/data/config.js(colors, speeds, costs, world size, camera settings)
Implemented features:
- ✅ 3D world with terrain-based colors
- ✅ 15 cities with unique backstories
- ✅ Road network with bridges and obstacles
- ✅ Pathfinding system with obstacle detection
- ✅ Caravan movement with click-to-travel
- ✅ Trading system with 10 goods
- ✅ Food consumption and daily costs
- ✅ Journey tracking and history
- ✅ Random encounter system (25+ encounters)
- ✅ Mercenary system (6 types with skills)
- ✅ Interactive encounters with mercenary choices
- ✅ HUD with real-time stats
- ✅ Tabbed Caravan Chronicles modal
- ✅ Minimap with zoom controls
- ✅ City tooltips on hover
- ✅ Debug console for testing
- ✅ Start screen with save slot selection
- ✅ Save/load system with 3 slots
- ✅ Auto-save every 60 seconds
- ✅ Quit to menu functionality
- ✅ Modular, scalable architecture
Potential future enhancements:
- More dynamic economy (price fluctuations based on supply/demand)
- Caravan upgrades (larger cargo capacity, faster speed)
- More mercenary interactions (conversations, quests)
- Weather system affecting travel
- Seasons affecting production
- Guild system with reputation
- Quest system with objectives
- Custom 3D models replacing geometric shapes
- Sound effects and music
- Improved graphics and particle effects
- Mobile touch controls
- Multiplayer trading
When loading in the browser, files must be loaded in this order (set up in index.html):
- Three.js library
- Data files (config, goods, cities, roads, encounters, mercenaries)
- Game state
- Managers (world, caravan, city, road)
- Systems (market, input, resource, pathfinding, encounter, mercenary, save)
- UI (uiManager, debugManager, minimapManager, tooltipManager)
- Main game file
- Left Click: Select city to travel to
- Mouse Hover: View city tooltips
- ESC: Close modals
- Click Outside Modal: Close modals
- ~ (Tilde): Open debug console
- HUD Click: Open Caravan Chronicles
- Minimap +/-: Zoom in/out
Access via ~ key:
help- Show all commandsteleport <cityName>- Teleport to any cityaddgold <amount>- Add goldaddfood <amount>- Add foodsetday <day>- Change game dayreset- Reset caravan positionresetcamera- Reset camera view
- All classes are modular and independent
- Save data stored in browser localStorage
- Road network uses BFS pathfinding
- Encounters checked every 100 units of travel
- Auto-save runs every 60 seconds
- Each save slot is completely independent
- Food consumption: 5/day + 2/mercenary
- Daily wages: 6-10 gold per mercenary
- Mercenary hire cost: 120-200 gold