Prompt specification
Build or customize the Three.js 3D scene "Island Exploration Camp" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Island Exploration Camp
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/island-exploration-camp-x3543
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: island exploration camp. Build an original exploration board with hills, resources, and blocked paths. Let players move a scout and make decisions from revealed information without showing hidden future events. Return one self-contained HTML file.
Working Three.js Starter (island-exploration-camp-x3543):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Verdant Relay — Island Exploration</title>
<style>
:root {
color-scheme: dark;
--ink: #e8f0e9;
--muted: #91aaa5;
--panel: rgba(12, 30, 34, 0.93);
--panel-2: rgba(19, 43, 45, 0.88);
--line: rgba(159, 202, 187, 0.16);
--mint: #8fe0b2;
--cyan: #66d5df;
--orange: #f2a65a;
--red: #e27c6d;
--shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
min-height: 100%;
background: #081a20;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body { overflow: hidden; }
button {
color: inherit;
font: inherit;
cursor: pointer;
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
button:disabled {
cursor: not-allowed;
opacity: 0.42;
}
[hidden] { display: none !important; }
#app {
height: 100dvh;
display: flex;
flex-direction: column;
background:
radial-gradient(circle at 52% 38%, rgba(40, 96, 92, 0.28), transparent 48%),
#081a20;
}
header {
height: 68px;
flex: 0 0 68px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: rgba(6, 20, 25, 0.92);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
width: 35px;
height: 35px;
position: relative;
transform: rotate(30deg) skewY(-10deg);
border: 2px solid var(--mint);
border-radius: 5px;
box-shadow: inset 0 0 0 5px rgba(143, 224, 178, 0.08);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--mint);
}
.brand-mark::before {
width: 6px;
height: 6px;
left: 6px;
top: 6px;
box-shadow: 11px 0 0 var(--mint), 0 11px 0 var(--mint), 11px 11px 0 var(--mint);
}
.brand-mark::after {
width: 25px;
height: 2px;
left: 3px;
bottom: 5px;
}
.brand strong {
display: block;
font-size: 15px;
letter-spacing: 0.13em;
}
.brand small {
display: block;
color: var(--muted);
margin-top: 3px;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.header-status {
display: flex;
align-items: center;
gap: 9px;
}
.status-pill {
display: flex;
align-items: center;
gap: 8px;
min-height: 34px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255,255,255,0.035);
color: var(--muted);
font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-pill b {
color: var(--ink);
font-weight: 700;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 12px var(--mint);
}
main {
flex: 1;
min-height: 0;
display: grid;
grid-template-columns: 272px minmax(360px, 1fr) 322px;
}
aside {
min-height: 0;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: rgba(143, 224, 178, 0.25) transparent;
background: rgba(8, 25, 30, 0.84);
}
.left-panel {
border-right: 1px solid var(--line);
padding: 20px;
}
.right-panel {
border-left: 1px solid var(--line);
padding: 18px;
}
.eyebrow {
color: var(--mint);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 8px 0 10px;
font-size: 29px;
line-height: 1.04;
letter-spacing: -0.04em;
}
.intro-copy {
color: var(--muted);
font-size: 13px;
line-height: 1.65;
margin: 0 0 20px;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 20px 0 10px;
color: #b9cdc6;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.section-label span:last-child {
color: #708d88;
}
.objective-list {
display: grid;
gap: 7px;
}
.objective {
display: grid;
grid-template-columns: 30px 1fr auto;
align-items: center;
gap: 9px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255,255,255,0.025);
transition: border-color 180ms ease, background 180ms ease;
}
.objective.done {
border-color: rgba(143, 224, 178, 0.38);
background: rgba(143, 224, 178, 0.07);
}
.objective-icon {
width: 29px;
height: 29px;
display: grid;
place-items: center;
border-radius: 7px;
background: rgba(255,255,255,0.055);
font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.objective.done .objective-icon {
color: #071b16;
background: var(--mint);
}
.objective strong {
display: block;
font-size: 12px;
font-weight: 650;
}
.objective small {
display: block;
color: var(--muted);
font-size: 10px;
margin-top: 3px;
}
.objective-value {
color: var(--muted);
font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.objective.done .objective-value {
color: var(--mint);
}
.inventory {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.inventory-card {
padding: 12px 8px;
text-align: center;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255,255,255,0.025);
}
.inventory-card b {
display: block;
font: 700 24px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.inventory-card span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.inventory-card.wood b { color: #d5b26e; }
.inventory-card.stone b { color: #b9c8c7; }
.inventory-card.food b { color: #8fe080; }
.chart-wrap {
border: 1px solid var(--line);
border-radius: 10px;
overflow: hidden;
background: #0a2025;
}
#minimap {
display: block;
width: 100%;
height: auto;
cursor: crosshair;
image-rendering: pixelated;
}
.chart-caption {
padding: 9px 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 10px;
color: var(--muted);
font-size: 10px;
}
.legend div {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
.known-note {
margin-top: 18px;
padding: 12px;
border-left: 2px solid var(--cyan);
background: rgba(102, 213, 223, 0.055);
color: #a7c3c1;
font-size: 10px;
line-height: 1.55;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #0c2830;
}
#stage canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.stage-badge {
position: absolute;
z-index: 3;
top: 16px;
left: 16px;
padding: 9px 12px;
border: 1px solid rgba(159, 202, 187, 0.18);
border-radius: 8px;
background: rgba(5, 20, 24, 0.72);
backdrop-filter: blur(10px);
pointer-events: none;
}
.stage-badge strong {
display: block;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
}
.stage-badge span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
}
.stage-help {
position: absolute;
z-index: 3;
left: 16px;
bottom: 15px;
color: rgba(216, 235, 226, 0.62);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
pointer-events: none;
}
.compass {
position: absolute;
z-index: 3;
right: 18px;
top: 17px;
width: 44px;
height: 44px;
display: grid;
place-items: center;
border: 1px solid rgba(159, 202, 187, 0.18);
border-radius: 50%;
background: rgba(5, 20, 24, 0.64);
color: var(--muted);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
pointer-events: none;
}
#compassArrow {
color: var(--orange);
font-size: 17px;
transform-origin: center;
}
.camera-controls {
position: absolute;
z-index: 5;
right: 15px;
bottom: 15px;
display: grid;
grid-template-columns: repeat(3, 34px);
gap: 5px;
}
.camera-controls button {
width: 34px;
height: 34px;
border: 1px solid rgba(159, 202, 187, 0.18);
border-radius: 7px;
background: rgba(5, 20, 24, 0.76);
color: #bdd0c9;
font-size: 14px;
backdrop-filter: blur(8px);
}
.camera-controls button:hover {
border-color: rgba(143, 224, 178, 0.55);
color: var(--mint);
}
.camera-controls .wide {
grid-column: span 3;
height: 30px;
font-size: 10px;
letter-spacing: 0.1em;
}
#tooltip {
position: absolute;
z-index: 7;
max-width: 230px;
padding: 8px 10px;
border: 1px solid rgba(159, 202, 187, 0.2);
border-radius: 7px;
background: rgba(5, 17, 21, 0.93);
color: var(--ink);
box-shadow: var(--shadow);
font-size: 10px;
pointer-events: none;
transform: translate(12px, 12px);
}
#toast {
position: absolute;
z-index: 20;
top: 18px;
left: 50%;
max-width: 78%;
padding: 10px 15px;
border: 1px solid rgba(242, 166, 90, 0.35);
border-radius: 8px;
background: rgba(40, 29, 18, 0.94);
color: #ffd3a2;
box-shadow: var(--shadow);
font-size: 11px;
transform: translate(-50%, -20px);
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.overlay {
position: absolute;
inset: 0;
z-index: 15;
display: grid;
place-items: center;
padding: 24px;
background: rgba(4, 16, 20, 0.72);
backdrop-filter: blur(7px);
}
.briefing-card,
.victory-card {
width: min(460px, 100%);
border: 1px solid rgba(143, 224, 178, 0.25);
border-radius: 16px;
padding: 28px;
background:
linear-gradient(145deg, rgba(28, 62, 58, 0.98), rgba(9, 28, 32, 0.98));
box-shadow: 0 30px 90px rgba(0,0,0,0.46);
}
.briefing-card h2,
.victory-card h2 {
margin: 9px 0 12px;
font-size: 29px;
line-height: 1.08;
letter-spacing: -0.04em;
}
.briefing-card p,
.victory-card p {
color: #abc0b9;
font-size: 13px;
line-height: 1.65;
}
.briefing-rules {
display: grid;
gap: 8px;
margin: 18px 0 22px;
}
.briefing-rules div {
display: grid;
grid-template-columns: 24px 1fr;
gap: 9px;
color: #c4d4ce;
font-size: 11px;
line-height: 1.45;
}
.briefing-rules b {
color: var(--mint);
font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.primary-button {
width: 100%;
min-height: 43px;
border: 0;
border-radius: 9px;
background: var(--mint);
color: #09201a;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.primary-button:hover {
background: #a7ebc2;
}
.inspector {
border: 1px solid var(--line);
border-radius: 12px;
overflow: hidden;
background: rgba(255,255,255,0.026);
}
.inspector-head {
padding: 14px 15px 13px;
border-bottom: 1px solid var(--line);
background: rgba(255,255,255,0.025);
}
.inspector-head h2 {
margin: 6px 0 4px;
font-size: 19px;
letter-spacing: -0.025em;
}
#inspectMeta {
color: var(--mint);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
}
.inspector-body {
padding: 14px 15px 15px;
}
#inspectText {
min-height: 52px;
margin: 0 0 13px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.action-stack {
display: grid;
gap: 8px;
}
.action-button {
width: 100%;
min-height: 40px;
padding: 9px 11px;
border: 1px solid rgba(159, 202, 187, 0.18);
border-radius: 8px;
background: rgba(255,255,255,0.035);
text-align: left;
font-size: 11px;
font-weight: 650;
transition: 150ms ease;
}
.action-button:hover:not(:disabled) {
border-color: rgba(143, 224, 178, 0.5);
background: rgba(143, 224, 178, 0.075);
}
.action-button.main {
color: #082019;
border-color: transparent;
background: var(--mint);
}
.action-button.main:hover:not(:disabled) {
background: #a8edc3;
}
.action-button.harvest {
border-color: rgba(213, 178, 110, 0.3);
color: #efd28b;
}
.action-button.build {
border-color: rgba(102, 213, 223, 0.3);
color: #8ce8ed;
}
.route-card {
margin-top: 12px;
padding: 11px;
border: 1px solid rgba(102, 213, 223, 0.16);
border-radius: 9px;
background: rgba(102, 213, 223, 0.045);
}
#routeSteps {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 8px;
}
.route-step {
padding: 4px 6px;
border-radius: 5px;
background: rgba(102, 213, 223, 0.1);
color: #bcecef;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.current-card {
margin-top: 15px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255,255,255,0.025);
}
.current-card strong {
font-size: 12px;
}
.current-card p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.day-card {
margin-top: 15px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255,255,255,0.025);
}
.day-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
}
#apDots {
display: flex;
gap: 5px;
}
.ap-dot {
width: 13px;
height: 13px;
border: 1px solid rgba(159, 202, 187, 0.28);
border-radius: 3px;
background: rgba(255,255,255,0.03);
}
.ap-dot.full {
border-color: var(--mint);
background: var(--mint);
box-shadow: 0 0 8px rgba(143, 224, 178, 0.25);
}
.day-buttons {
display: grid;
grid-template-columns: 1fr 38px;
gap: 8px;
margin-top: 11px;
}
.secondary-button {
min-height: 39px;
border: 1px solid rgba(159, 202, 187, 0.18);
border-radius: 8px;
background: rgba(255,255,255,0.035);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.secondary-button:hover {
border-color: rgba(143, 224, 178, 0.4);
}
.event-log {
display: grid;
gap: 8px;
}
.log-entry {
display: grid;
grid-template-columns: 31px 1fr;
gap: 8px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.log-entry time {
color: #65817d;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
padding-top: 1px;
}
@media (max-width: 980px) {
body { overflow: auto; }
#app { height: auto; min-height: 100dvh; }
header { position: sticky; top: 0; }
main { display: flex; flex-direction: column; }
#stage { order: -1; height: 64vh; min-height: 430px; }
aside { overflow: visible; }
.left-panel { border-right: 0; border-bottom: 1px solid var(--line); }
.right-panel { border-left: 0; border-top: 1px solid var(--line); }
.inventory { grid-template-columns: repeat(3, minmax(100px, 1fr)); }
}
@media (max-width: 600px) {
header { height: 60px; flex-basis: 60px; padding: 0 13px; }
.brand small { display: none; }
.brand strong { font-size: 12px; }
.status-pill.secondary { display: none; }
#stage { height: 58vh; min-height: 380px; }
.stage-help { display: none; }
.briefing-card, .victory-card { padding: 22px; }
.left-panel, .right-panel { padding: 16px; }
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<strong>VERDANT RELAY</strong>
<small>Island Survey / Expedition 07</small>
</div>
</div>
<div class="header-status">
<div class="status-pill secondary"><span class="live-dot"></span> Fixed terrain · no hidden events</div>
<div class="status-pill">Day <b id="dayValue">1</b></div>
<div class="status-pill">Actions <b id="apValue">6/6</b></div>
</div>
</header>
<main>
<aside class="left-panel">
<div class="eyebrow">Expedition brief</div>
<h1>The Quiet Ridge</h1>
<p class="intro-copy">
Survey a fractured island, gather what the land offers, and connect two signal cairns
before the camp is cut off.
</p>
<div class="section-label"><span>Objectives</span><span id="objectiveCount">0 / 5</span></div>
<div class="objective-list">
<div class="objective" id="objWood">
<div class="objective-icon">W</div>
<div><strong>Recover timber</strong><small>Collect 3 wood</small></div>
<div class="objective-value" id="objWoodValue">0/3</div>
</div>
<div class="objective" id="objStone">
<div class="objective-icon">S</div>
<div><strong>Recover stone</strong><small>Collect 3 stone</small></div>
<div class="objective-value" id="objStoneValue">0/3</div>
</div>
<div class="objective" id="objFood">
<div class="objective-icon">F</div>
<div><strong>Gather provisions</strong><small>Collect 3 food</small></div>
<div class="objective-value" id="objFoodValue">0/3</div>
</div>
<div class="objective" id="objBeacons">
<div class="objective-icon">⌁</div>
<div><strong>Build signal cairns</strong><small>Establish 2 cairns</small></div>
<div class="objective-value" id="objBeaconsValue">0/2</div>
</div>
<div class="objective" id="objMap">
<div class="objective-icon">⌗</div>
<div><strong>Complete the chart</strong><small>Survey 24 land tiles</small></div>
<div class="objective-value" id="objMapValue">0/24</div>
</div>
</div>
<div class="section-label"><span>Camp stores</span><span>Inventory</span></div>
<div class="inventory">
<div class="inventory-card wood"><b id="woodVal">0</b><span>Wood</span></div>
<div class="inventory-card stone"><b id="stoneVal">0</b><span>Stone</span></div>
<div class="inventory-card food"><b id="foodVal">0</b><span>Food</span></div>
</div>
<div class="section-label"><span>Known chart</span><span id="surveyCount">0 tiles</span></div>
<div class="chart-wrap">
<canvas id="minimap" width="286" height="234" aria-label="Chart of revealed terrain"></canvas>
<div class="chart-caption">Only surveyed terrain appears on the chart. Click a square to inspect it.</div>
</div>
<div class="section-label"><span>Terrain key</span><span>Revealed only</span></div>
<div class="legend">
<div><i class="swatch" style="background:#356049"></i>Wood</div>
<div><i class="swatch" style="background:#7b8280"></i>Stone</div>
<div><i class="swatch" style="background:#78a85c"></i>Food</div>
<div><i class="swatch" style="background:#989873"></i>Hill</div>
<div><i class="swatch" style="background:#61454b"></i>Blocked</div>
<div><i class="swatch" style="background:#d77d43"></i>Camp</div>
</div>
<div class="known-note">
Unsurveyed terrain is intentionally shown as neutral ground. Its resources, elevation,
and obstructions are revealed only after the scout observes them.
</div>
</aside>
<section id="stage" aria-label="Three-dimensional island board">
<div class="stage-badge">
<strong>THE QUIET RIDGE</strong>
<span>Orthographic-style tactical survey</span>
</div>
<div class="compass"><span id="compassArrow">▲</span></div>
<div class="stage-help">DRAG TO ORBIT · WHEEL TO ZOOM · CLICK A TILE</div>
<div class="camera-controls" aria-label="Camera controls">
<button data-camera="left" title="Rotate left">↶</button>
<button data-camera="up" title="Raise camera">↑</button>
<button data-camera="right" title="Rotate right">↷</button>
<button data-camera="down" title="Lower camera">↓</button>
<button data-camera="zoomIn" title="Zoom in">+</button>
<button data-camera="zoomOut" title="Zoom out">−</button>
<button class="wide" data-camera="focus">FOCUS SCOUT</button>
</div>
<div id="tooltip" hidden></div>
<div id="toast" role="status"></div>
<div class="overlay" id="briefing">
<div class="briefing-card">
<div class="eyebrow">Field orders / 07</div>
<h2>Plan with what is known.</h2>
<p>
The island is fixed and deterministic. There are no random overnight events or
concealed event previews. Every useful detail must be discovered first.
</p>
<div class="briefing-rules">
<div><b>01</b><span>Click a revealed tile to plot a route through known terrain.</span></div>
<div><b>02</b><span>Survey an unknown tile from up to three tiles away for 1 action.</span></div>
<div><b>03</span><span>Harvest on the tile you occupy. Build cairns with 1 wood and 1 stone.</span></div>
<div><b>04</b><span>Clear nearby boulders for 2 actions, then use the newly opened path.</span></div>
</div>
<button class="primary-button" id="startButton">Begin Survey</button>
</div>
</div>
<div class="overlay" id="victory" hidden>
<div class="victory-card">
<div class="eyebrow">Relay established</div>
<h2>The ridge is connected.</h2>
<p>
Your field chart is complete, both signal cairns stand, and camp stores are secure.
The Quiet Ridge can now relay messages beyond the shoreline.
</p>
<button class="primary-button" id="victoryButton">Keep Exploring</button>
</div>
</div>
</section>
<aside class="right-panel">
<div class="eyebrow">Scout console</div>
<div class="section-label" style="margin-top:8px"><span>Selected terrain</span><span>Live</span></div>
<div class="inspector">
<div class="inspector-head">
<h2 id="inspectTitle">Camp clearing</h2>
<div id="inspectMeta">X 0 · Z 0</div>
</div>
<div class="inspector-body">
<p id="inspectText"></p>
<div class="action-stack">
<button class="action-button main" id="primaryAction">Scout is here</button>
<button class="action-button harvest" id="gatherAction" hidden>Harvest resource</button>
<button class="action-button build" id="beaconAction" hidden>Build signal cairn</button>
</div>
<div class="route-card" id="routeCard" hidden>
<div class="eyebrow">Known route</div>
<div id="routeSteps"></div>
</div>
</div>
</div>
<div class="current-card">
<div class="eyebrow">Current position</div>
<strong id="currentType">Camp clearing</strong>
<p id="currentDetail"></p>
</div>
<div class="day-card">
<div class="day-row">
<span>Action points</span>
<div id="apDots"></div>
</div>
<div class="day-row" style="margin:0">
<span>End the day to restore all actions.</span>
<span id="dayNote">No overnight events</span>
</div>
<div class="day-buttons">
<button class="secondary-button" id="endDayButton">End Day</button>
<button class="secondary-button" id="resetButton" title="Restart expedition">↻</button>
</div>
</div>
<div class="section-label"><span>Field log</span><span>Latest entries</span></div>
<div class="event-log" id="eventLog"></div>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const GRID_W = 11;
const GRID_H = 9;
const CELL = 1.04;
const MAX_AP = 6;
const MAP_GOAL = 24;
const WOOD_GOAL = 3;
const STONE_GOAL = 3;
const FOOD_GOAL = 3;
const BEACON_GOAL = 2;
const stage = document.getElementById("stage");
const tooltip = document.getElementById("tooltip");
const toast = document.getElementById("toast");
const TILE_INFO = {
meadow: {
name: "Grass clearing",
description: "Open ground. It costs 1 action to enter and can support a signal cairn once its resources are spent.",
color: 0x73935d
},
forest: {
name: "Timber stand",
description: "Dense voxel trees. Entering costs 2 actions. Harvest here for 2 wood.",
color: 0x315d46
},
quarry: {
name: "Stone terrace",
description: "A useful but slow ridge. Entering costs 2 actions. Harvest here for 2 stone.",
color: 0x7b8280
},
grove: {
name: "Food grove",
description: "Low berry bushes. Entering costs 1 action. Harvest here for 2 food.",
color: 0x78a85c
},
hill: {
name: "High ridge",
description: "A steep, exposed hill. Entering costs 3 actions, but it remains visible once surveyed.",
color: 0x989873
},
blocked: {
name: "Boulder blockage",
description: "A fallen-rock wall blocks this route. Move adjacent and spend 2 actions to clear it.",
color: 0x61454b
},
camp: {
name: "Camp clearing",
description: "Your starting camp. The route out begins here.",
color: 0xd77d43
}
};
const RESOURCE_BY_TYPE = {
forest: "wood",
quarry: "stone",
grove: "food"
};
const RESOURCE_NAMES = {
wood: "Wood",
stone: "Stone",
food: "Food"
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0c2830);
scene.fog = new THREE.Fog(0x0c2830, 19, 38);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive voxel island");
stage.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(39, 1, 0.1, 100);
const cameraState = {
yaw: 0.62,
pitch: 0.66,
distance: 17.6,
target: new THREE.Vector3(0, 0.25, 0)
};
const hemi = new THREE.HemisphereLight(0xbde8df, 0x203037, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe2b2, 3.1);
sun.position.set(-7, 12, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x70cddd, 1.35);
rim.position.set(8, 5, -8);
scene.add(rim);
const material = (color, extra = {}) => new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
flatShading: true,
...extra
});
const materials = {
unknown: material(0x405956),
water: material(0x14505d, { roughness: 0.34, metalness: 0.08 }),
waterAlt: material(0x185967, { roughness: 0.3, metalness: 0.08 }),
meadow: material(0x628453),
forest: material(0x416747),
quarry: material(0x737b77),
grove: material(0x639052),
hill: material(0x858467),
blocked: material(0x66524d),
camp: material(0x687357),
trunk: material(0x6e4b32),
leaves: material(0x285c43),
leavesLight: material(0x3d7650),
rock: material(0x8d9691),
rockDark: material(0x606a68),
berry: material(0xe76552),
tent: material(0xe28d48),
tentDark: material(0x683b32),
scout: material(0xf0a456),
scoutDark: material(0x26343a),
scoutLight: material(0xf2e6c8),
backpack: material(0x47756c),
beacon: material(0xb6b39b),
beaconLight: material(0x73e0c2, { emissive: 0x1f5d4c, emissiveIntensity: 0.65 })
};
const ocean = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
material(0x0a3542, { roughness: 0.45, metalness: 0.05 })
);
ocean.rotation.x = -Math.PI / 2;
ocean.position.y = -0.31;
ocean.receiveShadow = true;
scene.add(ocean);
const boardShadow = new THREE.Mesh(
new THREE.BoxGeometry(GRID_W * CELL + 0.35, 0.38, GRID_H * CELL + 0.35),
material(0x102a2d)
);
boardShadow.position.y = -0.42;
boardShadow.receiveShadow = true;
scene.add(boardShadow);
const labelMaterials = new Map();
function labelMaterial(text, color = "#dff8eb") {
const key = `${text}|${color}`;
if (labelMaterials.has(key)) return labelMaterials.get(key);
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 64;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 128, 64);
ctx.fillStyle = "rgba(7, 24, 26, 0.88)";
ctx.fillRect(14, 8, 100, 48);
ctx.strokeStyle = "rgba(190, 255, 222, 0.34)";
ctx.lineWidth = 3;
ctx.strokeRect(14, 8, 100, 48);
ctx.fillStyle = color;
ctx.font = "bold 34px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 64, 33);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mat = new THREE.SpriteMaterial({ map: texture, transparent: true, depthWrite: false });
labelMaterials.set(key, mat);
return mat;
}
function hash(x, z, salt = 0) {
let n = Math.imul(x + salt * 17, 374761393) + Math.imul(z + salt * 29, 668265263);
n = Math.imul(n ^ (n >>> 13), 1274126177);
return ((n ^ (n >>> 16)) >>> 0) / 4294967295;
}
function worldX(x) {
return (x - (GRID_W - 1) / 2) * CELL;
}
function worldZ(z) {
return (z - (GRID_H - 1) / 2) * CELL;
}
function manhattan(a, b) {
return Math.abs(a.x - b.x) + Math.abs(a.z - b.z);
}
function tileKey(x, z) {
return `${x},${z}`;
}
function addBox(group, w, h, d, x, y, z, mat, shadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
const tiles = [];
const tilesByKey = new Map();
const pickables = [];
const waterMeshes = [];
let currentTile;
let selectedTile = null;
let hoveredTile = null;
let day = 1;
let ap = MAX_AP;
let started = false;
let victoryShown = false;
let moveAnimation = null;
let toastTimer = null;
const inventory = {
wood: 0,
stone: 0,
food: 0
};
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const selectionGroup = new THREE.Group();
scene.add(selectionGroup);
const selectionMaterial = new THREE.MeshBasicMaterial({
color: 0x83e8ef,
transparent: true,
opacity: 0.85
});
function isLandCell(x, z) {
const dx = (x - (GRID_W - 1) / 2) / 5.05;
const dz = (z - (GRID_H - 1) / 2) / 4.25;
const edgeNoise = (hash(x, z, 11) - 0.5) * 0.13;
return dx * dx + dz * dz + edgeNoise < 0.91;
}
function initialType(x, z, r) {
if (x === 5 && z === 4) return "camp";
if (x <= 3 && z <= 4 && r < 0.80) return "forest";
if (x >= 7 && z <= 4 && r < 0.78) return "quarry";
if (z >= 5 && x >= 3 && x <= 8 && r < 0.82) return "grove";
if ((x === 4 && z === 2) || (x === 6 && z === 3) || r > 0.945) return "hill";
return "meadow";
}
function createBoard() {
for (let z = 0; z < GRID_H; z++) {
for (let x = 0; x < GRID_W; x++) {
if (!isLandCell(x, z)) {
const water = new THREE.Mesh(
new THREE.BoxGeometry(CELL * 0.98, 0.14, CELL * 0.98),
hash(x, z, 19) > 0.5 ? materials.water : materials.waterAlt
);
water.position.set(worldX(x), -0.18 + hash(x, z, 21) * 0.025, worldZ(z));
water.receiveShadow = true;
water.userData.phase = hash(x, z, 23) * Math.PI * 2;
scene.add(water);
waterMeshes.push(water);
continue;
}
const r = hash(x, z, 2);
let type = initialType(x, z, r);
const tile = {
x,
z,
type,
revealed: false,
harvested: false,
beacon: false,
group: new THREE.Group()
};
if (hash(x, z, 7) > 0.89 && manhattan(tile, { x: 5, z: 4 }) > 1) {
type = "blocked";
}
tile.type = type;
tile.group.position.set(worldX(x), 0, worldZ(z));
scene.add(tile.group);
tiles.push(tile);
tilesByKey.set(tileKey(x, z), tile);
}
}
ensureConnectivity();
tiles.forEach(refreshTileVisual);
}
function passable(tile) {
return tile.type !== "blocked";
}
function neighbors(tile) {
return [
tilesByKey.get(tileKey(tile.x + 1, tile.z)),
tilesByKey.get(tileKey(tile.x - 1, tile.z)),
tilesByKey.get(tileKey(tile.x, tile.z + 1)),
tilesByKey.get(tileKey(tile.x, tile.z - 1))
].filter(Boolean);
}
function reachableTiles(blockedTiles) {
const blocked = new Set(blockedTiles.map(t => tileKey(t.x, t.z)));
const start = tilesByKey.get("5,4");
const found = new Set([tileKey(start.x, start.z)]);
const queue = [start];
while (queue.length) {
const tile = queue.shift();
for (const n of neighbors(tile)) {
const key = tileKey(n.x, n.z);
if (!found.has(key) && !blocked.has(key)) {
found.add(key);
queue.push(n);
}
}
}
return found;
}
function ensureConnectivity() {
let blocked = tiles.filter(t => t.type === "blocked");
for (let pass = 0; pass < 12; pass++) {
const reachable = reachableTiles(blocked);
const inaccessible = tiles.filter(t =>
RESOURCE_BY_TYPE[t.type] && !reachable.has(tileKey(t.x, t.z))
);
if (!inaccessible.length) break;
blocked.sort((a, b) => manhattan(a, { x: 5, z: 4 }) - manhattan(b, { x: 5, z: 4 }));
const remove = blocked.shift();
if (!remove) break;
remove.type = "meadow";
blocked = blocked.filter(t => t.type === "blocked");
}
}
function surfaceHeight(tile) {
if (!tile.revealed) return 0.3;
if (tile.type === "hill") return 1.18;
if (tile.type === "quarry") return 0.42;
if (tile.type === "blocked") return 0.46;
if (tile.type === "forest") return 0.38;
if (tile.type === "grove") return 0.36;
return 0.34;
}
function clearTileGroup(group) {
for (const child of [...group.children]) {
group.remove(child);
if (child.isMesh && child.geometry) child.geometry.dispose();
}
}
function addLabel(group, text, y, color = "#dff8eb") {
const sprite = new THREE.Sprite(labelMaterial(text, color));
sprite.position.set(0, y, 0);
sprite.scale.set(0.62, 0.31, 1);
group.add(sprite);
}
function refreshTileVisual(tile) {
const oldBaseIndex = pickables.findIndex(m => m.userData.tile === tile);
if (oldBaseIndex >= 0) pickables.splice(oldBaseIndex, 1);
clearTileGroup(tile.group);
let baseHeight = 0.3;
let baseMat = materials.unknown;
if (tile.revealed) {
baseHeight = surfaceHeight(tile);
baseMat = materials[tile.type] || materials.meadow;
}
const base = addBox(tile.group, 0.97, baseHeight, 0.97, 0, baseHeight / 2, 0, baseMat);
base.userData.tile = tile;
pickables.push(base);
if (!tile.revealed) return;
const h = baseHeight;
if (tile.type === "forest" && !tile.harvested) {
const positions = [
[-0.23, -0.17, 0.87],
[0.24, 0.16, 1.0],
[0.05, -0.28, 0.74]
];
positions.forEach(([x, z, size], i) => {
addBox(tile.group, 0.16, 0.62, 0.16, x, h + 0.31, z, materials.trunk);
addBox(tile.group, 0.57 * size, 0.38, 0.57 * size, x, h + 0.72, z, i === 1 ? materials.leavesLight : materials.leaves);
addBox(tile.group, 0.36 * size, 0.26, 0.36 * size, x, h + 0.98, z, materials.leavesLight);
});
addLabel(tile.group, "W", h + 1.48, "#e5cf83");
}
if (tile.type === "forest" && tile.harvested) {
addBox(tile.group, 0.22, 0.2, 0.22, 0, h + 0.1, 0, materials.trunk);
addBox(tile.group, 0.48, 0.08, 0.48, 0, h + 0.04, 0, materials.leaves);
}
if (tile.type === "quarry" && !tile.harvested) {
addBox(tile.group, 0.48, 0.42, 0.42, -0.2, h + 0.21, 0.12, materials.rock);
addBox(tile.group, 0.3, 0.56, 0.34, 0.25, h + 0.28, -0.17, materials.rockDark);
addBox(tile.group, 0.36, 0.22, 0.38, 0.05, h + 0.11, 0.3, materials.rock);
addLabel(tile.group, "S", h + 1.04, "#d8e2df");
}
if (tile.type === "quarry" && tile.harvested) {
addBox(tile.group, 0.32, 0.13, 0.3, -0.13, h + 0.065, 0.07, materials.rockDark);
addBox(tile.group, 0.2, 0.11, 0.24, 0.18, h + 0.055, -0.13, materials.rock);
}
if (tile.type === "grove" && !tile.harvested) {
[[-0.22, 0.14], [0.2, -0.18], [0.16, 0.22]].forEach(([x, z], i) => {
addBox(tile.group, 0.43, 0.3, 0.43, x, h + 0.15, z, i === 1 ? materials.leavesLight : materials.leaves);
addBox(tile.group, 0.1, 0.1, 0.1, x - 0.09, h + 0.32, z, materials.berry);
addBox(tile.group, 0.1, 0.1, 0.1, x + 0.08, h + 0.29, z + 0.06, materials.berry);
});
addLabel(tile.group, "F", h + 0.96, "#b8f09a");
}
if (tile.type === "grove" && tile.harvested) {
addBox(tile.group, 0.4, 0.08, 0.4, 0, h + 0.04, 0, materials.leaves);
}
if (tile.type === "hill") {
addBox(tile.group, 0.82, 0.34, 0.82, 0, h + 0.17, 0, materials.hill);
addBox(tile.group, 0.58, 0.3, 0.58, 0.03, h + 0.48, -0.02, materials.hill);
addBox(tile.group, 0.34, 0.26, 0.34, 0.04, h + 0.75, -0.04, materials.rockDark);
addLabel(tile.group, "^", h + 1.35, "#eee4ad");
}
if (tile.type === "blocked") {
addBox(tile.group, 0.47, 0.48, 0.4, -0.2, h + 0.24, 0.08, materials.rockDark);
addBox(tile.group, 0.38, 0.64, 0.36, 0.22, h + 0.32, -0.08, materials.rock);
addBox(tile.group, 0.3, 0.31, 0.3, 0.05, h + 0.66, 0.14, materials.rockDark);
addLabel(tile.group, "×", h + 1.06, "#f0a9a0");
}
if (tile.type === "camp") {
addBox(tile.group, 0.7, 0.46, 0.56, 0, h + 0.23, 0, materials.tent);
addBox(tile.group, 0.48, 0.18, 0.43, 0, h + 0.55, 0, materials.tent);
addBox(tile.group, 0.25, 0.29, 0.04, 0, h + 0.145, 0.3, materials.tentDark);
addBox(tile.group, 0.12, 0.12, 0.12, 0.35, h + 0.06, 0.28, materials.beaconLight);
addLabel(tile.group, "CAMP", h + 1.12, "#ffd09a");
}
if (tile.beacon) {
addBox(tile.group, 0.38, 0.14, 0.38, 0, h + 0.07, 0, materials.beacon);
addBox(tile.group, 0.28, 0.14, 0.28, 0.03, h + 0.21, 0, materials.beacon);
addBox(tile.group, 0.18, 0.17, 0.18, 0.05, h + 0.36, 0, materials.beaconLight);
}
}
createBoard();
currentTile = tilesByKey.get("5,4");
selectedTile = currentTile;
const scoutGroup = new THREE.Group();
const scoutVisual = new THREE.Group();
scoutGroup.add(scoutVisual);
scene.add(scoutGroup);
addBox(scoutVisual, 0.29, 0.34, 0.22, 0, 0.52, 0, materials.scout);
addBox(scoutVisual, 0.18, 0.2, 0.19, 0, 0.79, 0, materials.scoutLight);
addBox(scoutVisual, 0.25, 0.12, 0.18, 0, 0.83, -0.01, materials.scoutDark);
addBox(scoutVisual, 0.12, 0.3, 0.14, -0.09, 0.19, 0, materials.scoutDark);
addBox(scoutVisual, 0.12, 0.3, 0.14, 0.09, 0.19, 0, materials.scoutDark);
addBox(scoutVisual, 0.28, 0.29, 0.13, 0, 0.55, -0.17, materials.backpack);
const scoutShadow = new THREE.Mesh(
new THREE.PlaneGeometry(0.58, 0.58),
new THREE.MeshBasicMaterial({ color: 0x102327, transparent: true, opacity: 0.35, depthWrite: false })
);
scoutShadow.rotation.x = -Math.PI / 2;
scoutShadow.position.y = 0.015;
scoutGroup.add(scoutShadow);
function setScoutToTile(tile) {
scoutGroup.position.set(worldX(tile.x), surfaceHeight(tile) + 0.02, worldZ(tile.z));
}
setScoutToTile(currentTile);
function revealTile(tile) {
if (!tile || tile.revealed) return;
tile.revealed = true;
refreshTileVisual(tile);
}
function revealAround(tile, radius) {
tiles.forEach(t => {
if (manhattan(t, tile) <= radius) revealTile(t);
});
}
revealAround(currentTile, 1);
function entryCost(tile) {
if (tile.type === "hill") return 3;
if (tile.type === "forest" || tile.type === "quarry") return tile.harvested ? 1 : 2;
return 1;
}
function findPath(start, end) {
if (!end || !end.revealed || end.type === "blocked") return null;
if (start === end) return { path: [], total: 0 };
const distances = new Map();
const previous = new Map();
const visited = new Set();
const queue = [{ tile: start, cost: 0 }];
while (queue.length) {
queue.sort((a, b) => a.cost - b.cost);
const node = queue.shift();
if (!node || visited.has(node.tile)) continue;
visited.add(node.tile);
for (const n of neighbors(node.tile)) {
if (!n.revealed || !passable(n)) continue;
const cost = node.cost + entryCost(n);
if (!distances.has(n) || cost < distances.get(n)) {
distances.set(n, cost);
previous.set(n, node.tile);
queue.push({ tile: n, cost });
}
}
}
if (!distances.has(end)) return null;
const path = [];
let cursor = end;
while (cursor !== start) {
path.unshift(cursor);
cursor = previous.get(cursor);
if (!cursor) return null;
}
return { path, total: distances.get(end) };
}
function updateSelectionMarker() {
clearTileGroup(selectionGroup);
if (!selectedTile) return;
const size = 0.16;
const offset = 0.43;
const y = (selectedTile.revealed ? surfaceHeight(selectedTile) : 0.3) + 0.055;
const x = worldX(selectedTile.x);
const z = worldZ(selectedTile.z);
[[-offset, -offset], [offset, -offset], [-offset, offset], [offset, offset]].forEach(([dx, dz]) => {
const marker = new THREE.Mesh(new THREE.BoxGeometry(size, 0.045, size), selectionMaterial);
marker.position.set(x + dx, y, z + dz);
selectionGroup.add(marker);
});
}
function updateRouteVisual(path) {
clearTileGroup(routeGroup);
if (!path) return;
path.forEach((tile, index) => {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.07, 0.13),
new THREE.MeshBasicMaterial({ color: index === path.length - 1 ? 0xffca78 : 0x66d5df })
);
marker.position.set(
worldX(tile.x),
surfaceHeight(tile) + 0.085,
worldZ(tile.z)
);
routeGroup.add(marker);
});
}
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2400);
}
function addLog(message) {
const log = document.getElementById("eventLog");
const entry = document.createElement("div");
entry.className = "log-entry";
const time = document.createElement("time");
time.textContent = `D${String(day).padStart(2, "0")}`;
const text = document.createElement("span");
text.textContent = message;
entry.append(time, text);
log.prepend(entry);
while (log.children.length > 5) log.lastElementChild.remove();
}
function goalState() {
const surveyed = tiles.filter(t => t.revealed).length;
const beacons = tiles.filter(t => t.beacon).length;
return {
surveyed,
beacons,
wood: inventory.wood >= WOOD_GOAL,
stone: inventory.stone >= STONE_GOAL,
food: inventory.food >= FOOD_GOAL,
beaconGoal: beacons >= BEACON_GOAL,
mapGoal: surveyed >= MAP_GOAL
};
}
function updateHUD() {
document.getElementById("dayValue").textContent = day;
document.getElementById("apValue").textContent = `${ap}/${MAX_AP}`;
document.getElementById("woodVal").textContent = inventory.wood;
document.getElementById("stoneVal").textContent = inventory.stone;
document.getElementById("foodVal").textContent = inventory.food;
const surveyed = tiles.filter(t => t.revealed).length;
const beacons = tiles.filter(t => t.beacon).length;
document.getElementById("surveyCount").textContent = `${surveyed} tiles`;
document.getElementById("objWoodValue").textContent = `${Math.min(inventory.wood, WOOD_GOAL)}/${WOOD_GOAL}`;
document.getElementById("objStoneValue").textContent = `${Math.min(inventory.stone, STONE_GOAL)}/${STONE_GOAL}`;
document.getElementById("objFoodValue").textContent = `${Math.min(inventory.food, FOOD_GOAL)}/${FOOD_GOAL}`;
document.getElementById("objBeaconsValue").textContent = `${Math.min(beacons, BEACON_GOAL)}/${BEACON_GOAL}`;
document.getElementById("objMapValue").textContent = `${Math.min(surveyed, MAP_GOAL)}/${MAP_GOAL}`;
const goals = [
["objWood", inventory.wood >= WOOD_GOAL],
["objStone", inventory.stone >= STONE_GOAL],
["objFood", inventory.food >= FOOD_GOAL],
["objBeacons", beacons >= BEACON_GOAL],
["objMap", surveyed >= MAP_GOAL]
];
goals.forEach(([id, complete]) => {
document.getElementById(id).classList.toggle("done", complete);
});
document.getElementById("objectiveCount").textContent =
`${goals.filter(([, complete]) => complete).length} / ${goals.length}`;
document.getElementById("apDots").innerHTML = Array.from({ length: MAX_AP }, (_, i) =>
`<span class="ap-dot ${i < ap ? "full" : ""}"></span>`
).join("");
updateInspector();
drawMinimap();
checkVictory();
}
function updateInspector() {
const tile = selectedTile || currentTile;
const title = document.getElementById("inspectTitle");
const meta = document.getElementById("inspectMeta");
const text = document.getElementById("inspectText");
const primary = document.getElementById("primaryAction");
const routeCard = document.getElementById("routeCard");
const routeSteps = document.getElementById("routeSteps");
const gather = document.getElementById("gatherAction");
const beacon = document.getElementById("beaconAction");
primaryMode = null;
routeCard.hidden = true;
routeSteps.innerHTML = "";
if (!tile) return;
const coordinate = `X ${tile.x - 5} · Z ${tile.z - 4}`;
if (!tile.revealed) {
title.textContent = "Unsurveyed terrain";
meta.textContent = `${coordinate} · Details hidden`;
text.textContent =
"No resource, elevation, or obstruction can be inferred. Survey this tile from up to three tiles away to reveal its exact terrain.";
if (manhattan(tile, currentTile) <= 3) {
primary.textContent = "Survey tile · 1 action";
primary.disabled = ap < 1 || !started || !!moveAnimation;
primaryMode = "survey";
} else {
primary.textContent = "Move closer to survey";
primary.disabled = true;
}
} else {
const info = TILE_INFO[tile.type] || TILE_INFO.meadow;
title.textContent = tile.beacon ? `${info.name} + signal cairn` : info.name;
meta.textContent = `${coordinate} · ${tile.type === "blocked" ? "No entry" : `${entryCost(tile)} action to enter`}`;
text.textContent = info.description;
if (tile === currentTile) {
primary.textContent = "Scout is here";
primary.disabled = true;
} else if (tile.type === "blocked") {
if (manhattan(tile, currentTile) === 1) {
primary.textContent = "Clear boulders · 2 actions";
primary.disabled = ap < 2 || !started || !!moveAnimation;
primaryMode = "clear";
} else {
primary.textContent = "Move adjacent to clear";
primary.disabled = true;
}
} else {
const route = findPath(currentTile, tile);
if (route) {
routeCard.hidden = false;
routeSteps.innerHTML = route.path.map((step, index) => {
const name = step.type === "hill" ? "Hill" :
step.type === "forest" ? "Wood" :
step.type === "quarry" ? "Stone" :
step.type === "grove" ? "Food" : "Ground";
return `<span class="route-step">${index + 1}. ${name} +${entryCost(step)}</span>`;
}).join("");
primary.textContent = route.total > ap
? `Route needs ${route.total} actions`
: `Move route · ${route.total} action${route.total === 1 ? "" : "s"}`;
primary.disabled = route.total > ap || !started || !!moveAnimation;
primaryMode = "move";
} else {
primary.textContent = "No open route in known terrain";
primary.disabled = true;
}
}
}
const currentResource = RESOURCE_BY_TYPE[currentTile.type];
if (currentResource && !currentTile.harvested) {
gather.hidden = false;
gather.textContent = `Harvest 2 ${RESOURCE_NAMES[currentResource].toLowerCase()} · 1 action`;
gather.disabled = ap < 1 || !started || !!moveAnimation;
} else {
gather.hidden = true;
}
const canBuildSite =
currentTile.type === "meadow" ||
(RESOURCE_BY_TYPE[currentTile.type] && currentTile.harvested);
if (currentTile.beacon) {
beacon.hidden = false;
beacon.textContent = "Signal cairn established";
beacon.disabled = true;
} else if (canBuildSite) {
beacon.hidden = false;
beacon.textContent = "Build signal cairn · 1 wood + 1 stone";
beacon.disabled = inventory.wood < 1 || inventory.stone < 1 || ap < 1 || !started || !!moveAnimation;
} else {
beacon.hidden = true;
}
document.getElementById("currentType").textContent = TILE_INFO[currentTile.type].name;
document.getElementById("currentDetail").textContent =
`Coordinates ${currentTile.x - 5}, ${currentTile.z - 4}. ` +
(RESOURCE_BY_TYPE[currentTile.type] && !currentTile.harvested
? "Harvest before leaving if you want this resource."
: currentTile.type === "meadow"
? "Clear ground suitable for a signal cairn."
: "The scout is standing on revealed terrain.");
}
let primaryMode = null;
let selectedRoute = null;
document.getElementById("primaryAction").addEventListener("click", () => {
if (!started || moveAnimation) return;
if (primaryMode === "survey") {
performSurvey(selectedTile);
} else if (primaryMode === "clear") {
performClear(selectedTile);
} else if (primaryMode === "move") {
const route = findPath(currentTile, selectedTile);
if (route) performMove(route);
}
});
document.getElementById("gatherAction").addEventListener("click", performGather);
document.getElementById("beaconAction").addEventListener("click", performBeacon);
function performSurvey(tile) {
if (!tile || tile.revealed || manhattan(tile, currentTile) > 3 || ap < 1) return;
ap--;
revealTile(tile);
addLog(`Surveyed an unknown tile at ${tile.x - 5}, ${tile.z - 4}.`);
showToast(`Terrain revealed: ${TILE_INFO[tile.type].name}`);
updateHUD();
updateSelectionMarker();
}
function performClear(tile) {
if (!tile || tile.type !== "blocked" || manhattan(tile, currentTile) !== 1 || ap < 2) return;
ap -= 2;
tile.type = "meadow";
refreshTileVisual(tile);
addLog("Cleared a boulder wall and opened a new route.");
showToast("Boulders cleared. The path is now open.");
updateHUD();
updateSelectionMarker();
}
function performGather() {
const resource = RESOURCE_BY_TYPE[currentTile.type];
if (!resource || currentTile.harvested || ap < 1) return;
ap--;
inventory[resource] += 2;
currentTile.harvested = true;
refreshTileVisual(currentTile);
addLog(`Collected 2 ${resource} from the ${TILE_INFO[currentTile.type].name.toLowerCase()}.`);
showToast(`+2 ${RESOURCE_NAMES[resource]}`);
updateHUD();
}
function performBeacon() {
if (currentTile.beacon || ap < 1 || inventory.wood < 1 || inventory.stone < 1) return;
const canBuildSite =
currentTile.type === "meadow" ||
(RESOURCE_BY_TYPE[currentTile.type] && currentTile.harvested);
if (!canBuildSite) return;
ap--;
inventory.wood--;
inventory.stone--;
currentTile.beacon = true;
refreshTileVisual(currentTile);
addLog("Established a signal cairn at the current position.");
showToast("Signal cairn established");
updateHUD();
}
function performMove(route) {
if (!route || !route.path.length || route.total > ap || moveAnimation) return;
ap -= route.total;
selectedRoute = route;
moveAnimation = {
path: route.path,
index: 0,
startedAt: performance.now(),
segmentDuration: 245
};
addLog(`Plotted a ${route.total}-action route through revealed terrain.`);
updateHUD();
}
function updateScoutAnimation(now) {
if (!moveAnimation) {
scoutVisual.position.y = Math.sin(now * 0.0032) * 0.035;
scoutVisual.rotation.z = Math.sin(now * 0.0016) * 0.012;
return;
}
const anim = moveAnimation;
const targetTile = anim.path[anim.index];
const fromTile = anim.index === 0 ? currentTile : anim.path[anim.index - 1];
const from = new THREE.Vector3(worldX(fromTile.x), surfaceHeight(fromTile) + 0.02, worldZ(fromTile.z));
const to = new THREE.Vector3(worldX(targetTile.x), surfaceHeight(targetTile) + 0.02, worldZ(targetTile.z));
const elapsed = now - anim.startedAt;
const t = Math.min(1, elapsed / anim.segmentDuration);
const eased = t * t * (3 - 2 * t);
scoutGroup.position.lerpVectors(from, to, eased);
scoutGroup.position.y += Math.sin(Math.PI * t) * 0.18;
scoutVisual.position.y = Math.abs(Math.sin(Math.PI * t)) * 0.08;
scoutVisual.rotation.z = 0;
const direction = to.clone().sub(from);
if (direction.lengthSq() > 0.001) {
const desired = Math.atan2(direction.x, direction.z);
let delta = desired - scoutGroup.rotation.y;
delta = Math.atan2(Math.sin(delta), Math.cos(delta));
scoutGroup.rotation.y += delta * 0.22;
}
if (t >= 1) {
currentTile = targetTile;
anim.index++;
if (anim.index >= anim.path.length) {
moveAnimation = null;
selectedTile = currentTile;
setScoutToTile(currentTile);
revealAround(currentTile, 1);
addLog(`Scout arrived at the ${TILE_INFO[currentTile.type].name.toLowerCase()}.`);
updateSelectionMarker();
updateRouteVisual(findPath(currentTile, selectedTile)?.path || []);
updateHUD();
} else {
anim.startedAt = now;
}
}
}
function endDay() {
if (!started || moveAnimation) return;
day++;
ap = MAX_AP;
addLog("Camp was secured for the night. Action points restored; no random event occurred.");
showToast(`Day ${day} begins. All actions restored.`);
updateHUD();
}
document.getElementById("endDayButton").addEventListener("click", endDay);
document.getElementById("resetButton").addEventListener("click", () => {
if (confirm("Restart this expedition?")) location.reload();
});
function selectTile(tile) {
if (!tile || !started || moveAnimation) return;
selectedTile = tile;
selectedRoute = tile.revealed ? findPath(currentTile, tile) : null;
updateSelectionMarker();
updateRouteVisual(selectedRoute?.path || []);
updateInspector();
}
function checkVictory() {
const goals = goalState();
const complete = goals.wood && goals.stone && goals.food && goals.beaconGoal && goals.mapGoal;
if (complete && !victoryShown) {
victoryShown = true;
document.getElementById("victory").hidden = false;
addLog("Expedition objectives complete. The relay is online.");
}
}
document.getElementById("victoryButton").addEventListener("click", () => {
document.getElementById("victory").hidden = true;
});
document.getElementById("startButton").addEventListener("click", () => {
started = true;
document.getElementById("briefing").style.display = "none";
addLog("Scout departed the camp with six action points.");
showToast("Survey begun. Click terrain to inspect or plot a route.");
updateHUD();
updateSelectionMarker();
});
const mapCanvas = document.getElementById("minimap");
const mapCtx = mapCanvas.getContext("2d");
const MAP_CELL_W = 26;
const MAP_CELL_H = 26;
function drawMinimap() {
mapCtx.clearRect(0, 0, mapCanvas.width, mapCanvas.height);
mapCtx.fillStyle = "#0a2025";
mapCtx.fillRect(0, 0, mapCanvas.width, mapCanvas.height);
for (let z = 0; z < GRID_H; z++) {
for (let x = 0; x < GRID_W; x++) {
const tile = tilesByKey.get(tileKey(x, z));
const px = x * MAP_CELL_W;
const py = z * MAP_CELL_H;
mapCtx.fillStyle = tile ? "#213b3c" : "#0c303b";
mapCtx.fillRect(px + 1, py + 1, MAP_CELL_W - 2, MAP_CELL_H - 2);
if (!tile || !tile.revealed) continue;
const colors = {
meadow: "#73935d",
forest: "#315d46",
quarry: "#7b8280",
grove: "#78a85c",
hill: "#989873",
blocked: "#61454b",
camp: "#d77d43"
};
mapCtx.fillStyle = tile.harvested ? "#536459" : colors[tile.type];
mapCtx.fillRect(px + 3, py + 3, MAP_CELL_W - 6, MAP_CELL_H - 6);
if (tile.type === "blocked") {
mapCtx.strokeStyle = "#f0a9a0";
mapCtx.lineWidth = 2;
mapCtx.beginPath();
mapCtx.moveTo(px + 8, py + 8);
mapCtx.lineTo(px + 18, py + 18);
mapCtx.moveTo(px + 18, py + 8);
mapCtx.lineTo(px + 8, py + 18);
mapCtx.stroke();
}
if (tile.beacon) {
mapCtx.fillStyle = "#8fe0b2";
mapCtx.fillRect(px + 9, py + 9, 8, 8);
}
}
}
if (currentTile) {
const px = currentTile.x * MAP_CELL_W + MAP_CELL_W / 2;
const py = currentTile.z * MAP_CELL_H + MAP_CELL_H / 2;
mapCtx.fillStyle = "#ffd18b";
mapCtx.beginPath();
mapCtx.arc(px, py, 5.5, 0, Math.PI * 2);
mapCtx.fill();
mapCtx.strokeStyle = "#fff2cf";
mapCtx.lineWidth = 1.5;
mapCtx.stroke();
}
if (selectedTile) {
mapCtx.strokeStyle = "#80e2ec";
mapCtx.lineWidth = 2;
mapCtx.strokeRect(
selectedTile.x * MAP_CELL_W + 2,
selectedTile.z * MAP_CELL_H + 2,
MAP_CELL_W - 4,
MAP_CELL_H - 4
);
}
}
mapCanvas.addEventListener("click", event => {
const rect = mapCanvas.getBoundingClientRect();
const x = Math.floor(((event.clientX - rect.left) / rect.width) * GRID_W);
const z = Math.floor(((event.clientY - rect.top) / rect.height) * GRID_H);
const tile = tilesByKey.get(tileKey(x, z));
if (tile) selectTile(tile);
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
let dragging = false;
function pickTile(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(pickables, false)[0];
return hit ? hit.object.userData.tile : null;
}
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
pointerDown = { x: event.clientX, y: event.clientY, id: event.pointerId };
dragging = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.hypot(dx, dy) > 5) dragging = true;
if (dragging) {
cameraState.yaw -= dx * 0.008;
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch + dy * 0.005, 0.28, 1.18);
pointerDown.x = event.clientX;
pointerDown.y = event.clientY;
tooltip.hidden = true;
return;
}
}
const tile = pickTile(event);
hoveredTile = tile;
if (!tile) {
tooltip.hidden = true;
return;
}
const rect = stage.getBoundingClientRect();
tooltip.style.left = `${Math.min(event.clientX - rect.left, rect.width - 190)}px`;
tooltip.style.top = `${Math.min(event.clientY - rect.top, rect.height - 80)}px`;
tooltip.textContent = tile.revealed
? `${TILE_INFO[tile.type].name} · ${tile.type === "blocked" ? "clear for 2" : `${entryCost(tile)} action entry`}`
: "Unsurveyed terrain · click to inspect";
tooltip.hidden = false;
});
renderer.domElement.addEventListener("pointerup", event => {
if (pointerDown && !dragging) {
const tile = pickTile(event);
if (tile) selectTile(tile);
}
pointerDown = null;
dragging = false;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
dragging = false;
});
renderer.domElement.addEventListener("pointerleave", () => {
tooltip.hidden = true;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
10.5,
27
);
}, { passive: false });
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
document.querySelectorAll("[data-camera]").forEach(button => {
button.addEventListener("click", () => {
const action = button.dataset.camera;
if (action === "left") cameraState.yaw -= 0.22;
if (action === "right") cameraState.yaw += 0.22;
if (action === "up") cameraState.pitch = Math.min(1.18, cameraState.pitch + 0.08);
if (action === "down") cameraState.pitch = Math.max(0.28, cameraState.pitch - 0.08);
if (action === "zoomIn") cameraState.distance = Math.max(10.5, cameraState.distance - 1.2);
if (action === "zoomOut") cameraState.distance = Math.min(27, cameraState.distance + 1.2);
if (action === "focus") {
cameraState.target.x = worldX(currentTile.x);
cameraState.target.z = worldZ(currentTile.z);
cameraState.distance = 14.5;
}
});
});
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return;
const key = event.key.toLowerCase();
if (key === "w") cameraState.distance = Math.max(10.5, cameraState.distance - 0.8);
if (key === "s") cameraState.distance = Math.min(27, cameraState.distance + 0.8);
if (key === "a") cameraState.yaw -= 0.16;
if (key === "d") cameraState.yaw += 0.16;
if (key === "q") cameraState.pitch = Math.max(0.28, cameraState.pitch - 0.07);
if (key === "e") cameraState.pitch = Math.min(1.18, cameraState.pitch + 0.07);
});
function resize() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
function updateCamera() {
const { yaw, pitch, distance, target } = cameraState;
const horizontal = Math.cos(pitch) * distance;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * distance,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
document.getElementById("compassArrow").style.transform = `rotate(${-yaw}rad)`;
}
updateHUD();
updateSelectionMarker();
updateRouteVisual([]);
function animate(now) {
requestAnimationFrame(animate);
updateScoutAnimation(now);
updateCamera();
waterMeshes.forEach((water, index) => {
water.position.y = -0.18 + Math.sin(now * 0.0014 + water.userData.phase) * 0.018;
if (index % 3 === 0) {
water.material.color.setHex(Math.sin(now * 0.0007 + index) > 0.65 ? 0x185967 : 0x14505d);
}
});
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```