# BOLTSTEAD — Robot Frontier

## Vision
A single-player, open-world, 3D settlement-defense RTS: build the safest home for your villagers and the strongest robot-and-human army. Inspired by the economic/army loops of StarCraft and Clash of Clans and the playful chunky 3D feel described using Wobbly Life. Models and world geometry are built procedurally, including the requested Iron Man-inspired armor.

## Playable vertical slice
Desktop browser, Three.js/WebGL, keyboard and mouse. One explorable handcrafted frontier, two trade settlements, replenishing resource deposits, one expandable fortress, ten escalating raids, alternating regular-only and boss-only waves, optional continued play. No account, backend, paid assets, or runtime external service required. A full commercial open world, multiplayer, advanced navigation, animation rigs, and campaign are future work.

## Core loop
Explore → harvest wood/stone/diamonds → buy or salvage parts → assemble miners/builders/Army Bots → construct housing and defenses → welcome villagers → gain trade discounts → equip armor and train troops → defeat raids and bosses → expand the fortress.

## Controls
- WASD/arrows: move commander; camera follows. Click terrain: move selected unit. Click unit: select. Click resource: selected miner/commander harvests repeatedly. Click enemy: selected combat unit attacks.
- 1: commander; 2: all military units; H: return camera to home; mouse wheel: zoom; Space: pause; Escape: cancel placement/close panels; M: trade; B: build.
- Build menu selects a blueprint, then click an empty spot inside the wall boundary. Requires a builder; construction takes time and costs materials immediately. Canceled unplaced blueprints cost nothing.
- Trade requires the commander near one of two villages. A travel button sends the commander there.

## Economy and units
Starting stock supports choices without a grind. Resource deposits replenish after depletion. Commander and miners harvest at close range on a timer; miners automatically seek a new resource of the same type. Some mined stone yields robot parts; shops sell parts directly. Soldiers auto-defend nearby enemies, or can receive attack/move orders.
- Miner: harvests; initial miner begins collecting wood.
- Builder: constructs blueprints and repairs buildings near home.
- Army Bot: ranged robot combatant.
- Villager: resident with health and a home position, improves trade prices; training converts a resident to a guard.
- Commander: controllable gatherer/combatant. Respawns at base after defeat with a coin penalty.

## Settlement
Home starts walled, with a core, workshop, houses, and a watchtower. Houses increase villager capacity; villagers immigrate over time while housing and safety permit. Watchtowers defend at range. Workshops improve robot capacity. Expansion requires three robots and resources, increases build area, and reconstructs the perimeter. Builders finish structures then repair damaged structures. Walls intercept enemies; friendly navigation is simplified. Attacks can break perimeter sections.

## Trading and equipment
Village stores buy wood/stone/diamonds, sell supplies and parts, and equip three successive shared armor tiers: wood, iron, diamond. Armor strengthens commander and troops. Prices decrease with resident population, capped at 35%. Coins are also awarded for defeated raiders. Shop requires physical proximity to the settlement.

## Raids, loss, and success
First raid countdown begins only after pressing Play. Odd waves (1, 3, 5, 7, 9) spawn regular raiders only; even waves (2, 4, 6, 8, 10) spawn one stronger boss with no regular enemies. Next timer begins after the current raid is defeated. Enemies target defenses, residents, and the core. Each resident killed causes another resident to leave if any remain. Core destruction is a loss. Defeat wave 10 with at least one resident remaining to complete the prototype; continue into endless raids if desired. Long-term score combines residents, surviving core health, and military strength.

## Interface and art
Full-screen pastel low-poly isometric world, warm cream interface, teal technology, orange workshop accents, plum hostile robots, chunky trees, crystalline deposits, winding roads, river, mountains, pennants, visible construction, health bars, combat projectiles, dust/spark effects. Resource strip, selection card, build/robot/trade drawers, objective list, wave timer, minimap, contextual hints, pause/help and win/loss overlays.

## Technical architecture
- `src/simulation.js`: serializable deterministic state, actions, economy, AI, combat, construction, wave progression, versioned saves.
- `src/world.js`: Three.js scene/model factory, camera, picking, updates and effects.
- `src/main.js`: UI and inputs, fixed-step simulation loop, save/load and audio.
- Vite bundles local dependencies into `dist/`. Local static server binds port 4175.
- LocalStorage manual and periodic autosaves; failures reported in UI. No cloud persistence.

## Acceptance checks
Production build succeeds; page renders without JS errors; start/pause work; resources harvest; robot costs deduct correctly; construction completes; housing enables immigration; trading requires village proximity and scales with population; training converts a villager; armor improves troops; raid and boss progression work; death penalty applies; core destruction loses; final wave wins; save/load round-trips.

## Interactive onboarding (September 12 update)
New expeditions offer Buddy’s Field Guide, automatically checked until completed or skipped in this browser. Seventeen short lessons highlight actual UI controls or projected 3D world objects with a glowing outline, a connecting line, and a contextual instruction card. The card avoids its target and open drawers. Action lessons require actual movement, commander harvesting, successful purchases, robot assembly, placement, or completed construction; explanatory lessons have a Next button. Every lesson can be skipped, and the whole guide can be dismissed.

The guide teaches selection/movement, wood and stone harvesting, diamonds and parts, robot assembly, cottage construction and villagers, physical travel to a market, earning coins, buying parts, armor, and Army Bot defense. Resource counters are clickable buttons with reusable explanations of all five resources; the help panel also contains the reference.

Raid countdown and manual raid spawning are held during training; economy, movement, construction, and immigration continue. The normal countdown resumes upon completion or skipping. Tutorial index and progress baselines are stored with expedition saves, so Continue resumes an unfinished guide. Completion preference is separate browser storage. Recheck “Guided first expedition” on the start screen to replay with a new town. Existing saves without tutorial data remain compatible and are not automatically interrupted.

## Harvesting animation (September 12 update)
Commander and miner bots face deposits and use an articulated shoulder/tool rig: an axe for trees, a pickaxe for stone and diamonds. Each gather cycle winds up before impact; inventory and node quantity change on the strike rather than immediately on arrival. Movement orders cancel an unfinished swing without awarding materials.

Deposit silhouettes shrink smoothly with their remaining quantity. Hits shake the tree/rock/crystals and eject material-colored chips, with a floating +resource reward and a brief inventory-counter pulse. Fully harvested trees retain a stump, rock deposits retain gravel, and crystal deposits retain their bare stone base; resources regrow when the existing replenishment timer finishes. Effects use shared geometry/materials and expire without accumulating scene objects. Tutorial world callouts track the smaller deposit silhouette. Existing saves remain compatible.

## Commander controls and raid warnings
- Combat robots are displayed as **Army Bot** throughout the game and guide; saved unit types remain compatible.
- **Settings (⚙) → Auto-select commander** is on by default and saved independently of expeditions. After a bot move, gather, attack, or army rally order, the bot continues its task while control returns to the commander. Turn it off to keep the selection.
- Scheduled raids show a prominent final 10-second countdown, including boss labeling. Calling a raid early also allows 10 seconds; it never resets a countdown already underway. Pausing freezes the countdown, and tutorials continue holding raids. An alert chime plays when sound is enabled.

## Extended campaign and equipment — September 12 update
- Commander armor is visible as body, helmet, shoulder, forearm, leg and boot plates. Wood, iron and diamond have distinct colors and materials; plates follow harvesting/walking animations.
- Defeating the Raid 6 boss unlocks and automatically equips free Iron Man armor (tier 4): red-and-gold plating, helmet, luminous eyes, chest arc reactor and palm repulsors. The campaign continues to Raid 10, then optional endless mode.
- Crew opens a large-button unit roster and focuses the camera on the selected robot. [ / ] cycle robots; world picking has a forgiving 23px hit area. Click ground or right-click to move. The explicit Go back to commander button and 1 key return selection without cancelling bot orders. Auto-select commander remains optional and saved.
- Watchtowers attack from point-blank to 28 world units, with no minimum-range blind spot.
- New expeditions group wood in Westwood Forest (west), stone in Northridge Mine (north), and diamonds in Eastlight Mine (east), all outside even the largest fortress perimeter.
- Each completed workshop supports 20 robots. New games start with a Heartcore, workshop, two cottages, watchtower and full perimeter walls—every building type is already present.
- Version 1 saves remain supported. Existing units, structures, resources, world layout and tutorial progress are retained. Completed old Raid 6 victories reopen the extended campaign with Iron Man armor unlocked. New resource zones require a new expedition.
