Spaces:
Paused
Odyssey Phase 2: the research tree (Datacenter + deeper industry)
Browse filesSecond slice of the economy import: an Odyssey-only research tree that gates and
deepens the production chain — paid in gathered commodities and developed over
time, no separate tech currency (the game's law: the resources you gather are the
resources you spend). Reconciled from a three-way design brainstorm.
- engine/techtree.js (new): TECHS (6 nodes — 3 unlock the buildable spine, 3 are
industry passives), researchTech (start a project: prereq/afford checks, pay,
timer), updateResearch (dt-driven progress → banks the node into player.upgrades,
a no-op for any non-Datacenter — same inert pattern as updateProduction),
researchTimeScale (a world's tech rating makes it develop faster — Syndicate
hubs out-research), techMult (the tech-tree twin of upgradeMult for passives).
- Research lives in player.upgrades — the SAME bag the doctrines use — so nodes
gate buildings via the existing prereqsMet with zero new gating machinery, and
committedDoctrine/upgradeMult (which guard on UPGRADES membership) never see them.
- entities.js: Datacenter (hosts research), Chip Fab (→ electronics), Machine
Works (→ machinery), all odysseyOnly and tech-gated via requires; the Phase-1
Assembly Plant now needs Metallurgy research (the tree's first teeth).
- industry.js: the passives — Fusion Containment (+Power), Automation (+speed),
Heavy Alloys (+yield) — applied via techMult.
- market.js: electronics + machinery are now sellable.
- sim.js: updateResearch wired into the building loop (no-op off the Datacenter).
- hud.js: the Datacenter research panel (flat lock-tip buttons + an in-progress
row — the existing idiom, no tree UI), the deeper buildings in the build menu,
and tech-node names in lock tooltips.
- Tests: test/techtree.test.js (node well-formedness, research start/gate/afford,
timed completion, planet-tech scaling, passives, Odyssey-only gating), an
industry passive-effect test, and a galaxy-persist round-trip for researched +
in-progress tech.
Persistence is free (nodes ride in player.upgrades, the in-progress job on the
building object — both already serialized; no save-version bump). Odyssey-only, so
the byte-identical skirmish path is untouched. 417 tests pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AEQUVetLk31Jj7niDQAsXL
- engine/entities.js +33 -1
- engine/industry.js +14 -7
- engine/market.js +1 -1
- engine/sim.js +2 -0
- engine/techtree.js +102 -0
- hud.js +35 -2
- test/galaxy-persist.test.js +15 -0
- test/industry.test.js +12 -0
- test/techtree.test.js +98 -0
|
@@ -109,7 +109,39 @@ export const BUILDINGS = {
|
|
| 109 |
cost: { ore: 180 }, buildTime: 20, sight: 140,
|
| 110 |
dropOff: true,
|
| 111 |
recipe: "alloy", prodRate: 1.5, // metals + power → alloys (data.js RECIPES.alloy)
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
odysseyOnly: true,
|
| 114 |
},
|
| 115 |
};
|
|
|
|
| 109 |
cost: { ore: 180 }, buildTime: 20, sight: 140,
|
| 110 |
dropOff: true,
|
| 111 |
recipe: "alloy", prodRate: 1.5, // metals + power → alloys (data.js RECIPES.alloy)
|
| 112 |
+
// The chain reads as a chain (needs a Smelter for metals) AND is the first
|
| 113 |
+
// thing the tech tree gates: Metallurgy research (engine/techtree.js) unlocks
|
| 114 |
+
// it, so the free tier (Smelter → metals) gives an immediate payoff while
|
| 115 |
+
// deeper refining is an investment. `metallurgy` is a tech-node token that
|
| 116 |
+
// prereqsMet resolves out of player.upgrades, exactly like a building token.
|
| 117 |
+
requires: ["smelter", "metallurgy"],
|
| 118 |
+
odysseyOnly: true,
|
| 119 |
+
},
|
| 120 |
+
|
| 121 |
+
/* ---- Phase 2 research + deeper industry (Odyssey only). The Datacenter hosts
|
| 122 |
+
the tech tree (engine/techtree.js); the Chip Fab and Machine Works are the
|
| 123 |
+
next two hops of the chain, each gated behind a research node so unlocking a
|
| 124 |
+
node visibly unlocks new production. All ore-costed and odysseyOnly, like the
|
| 125 |
+
Phase-1 factories. ---- */
|
| 126 |
+
datacenter: {
|
| 127 |
+
id: "datacenter", name: "Datacenter", hp: 420, radius: 17,
|
| 128 |
+
cost: { ore: 200 }, buildTime: 22, sight: 140,
|
| 129 |
+
odysseyOnly: true,
|
| 130 |
+
// Hosts research — no `recipe` (updateProduction ignores it) and no `produces`
|
| 131 |
+
// (stays out of the rally UI). Selecting it opens the research panel (hud.js).
|
| 132 |
+
},
|
| 133 |
+
chipfab: {
|
| 134 |
+
id: "chipfab", name: "Chip Fab", hp: 440, radius: 17,
|
| 135 |
+
cost: { ore: 190 }, buildTime: 20, sight: 140, dropOff: true,
|
| 136 |
+
recipe: "chipfab", prodRate: 1.5, // crystals + metals + power → electronics
|
| 137 |
+
requires: ["smelter", "electronics"], // needs the metals chain + Microelectronics research
|
| 138 |
+
odysseyOnly: true,
|
| 139 |
+
},
|
| 140 |
+
machineworks: {
|
| 141 |
+
id: "machineworks", name: "Machine Works", hp: 460, radius: 18,
|
| 142 |
+
cost: { ore: 220 }, buildTime: 24, sight: 140, dropOff: true,
|
| 143 |
+
recipe: "machine", prodRate: 1, // alloys + electronics + power → machinery
|
| 144 |
+
requires: ["assembler", "chipfab", "machining"], // the capstone: the whole chain + Precision Machining
|
| 145 |
odysseyOnly: true,
|
| 146 |
},
|
| 147 |
};
|
|
@@ -25,6 +25,7 @@
|
|
| 25 |
|
| 26 |
import { BUILDINGS } from "./entities.js";
|
| 27 |
import { RECIPES } from "../data.js";
|
|
|
|
| 28 |
|
| 29 |
// data.js RECIPES is an array; index it by id once for O(1) lookup.
|
| 30 |
const RECIPE_BY_ID = Object.fromEntries(RECIPES.map(r => [r.id, r]));
|
|
@@ -35,12 +36,13 @@ export function recipeOf(building) {
|
|
| 35 |
return def && def.recipe ? RECIPE_BY_ID[def.recipe] : null;
|
| 36 |
}
|
| 37 |
|
| 38 |
-
// Total industrial Power a player's completed buildings grant (Reactors)
|
|
|
|
| 39 |
export function powerCap(state, owner) {
|
| 40 |
let cap = 0;
|
| 41 |
for (const b of state.buildings.values())
|
| 42 |
if (b.owner === owner && !b.constructing) cap += BUILDINGS[b.type].energyGrants || 0;
|
| 43 |
-
return cap;
|
| 44 |
}
|
| 45 |
|
| 46 |
// Total Power a player's completed factories draw at full rate — a factory
|
|
@@ -79,11 +81,14 @@ export function updateProduction(state, building, dt) {
|
|
| 79 |
if (!recipe) return;
|
| 80 |
const throttle = powerThrottle(state, building.owner);
|
| 81 |
if (throttle <= 0) return;
|
| 82 |
-
const
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
// How much of a batch we can run this tick: the power-throttled target
|
| 85 |
-
// by the
|
| 86 |
-
|
|
|
|
| 87 |
for (const com in recipe.in) {
|
| 88 |
if (com === "energy") continue;
|
| 89 |
frac = Math.min(frac, (res[com] || 0) / recipe.in[com]);
|
|
@@ -94,5 +99,7 @@ export function updateProduction(state, building, dt) {
|
|
| 94 |
if (com === "energy") continue;
|
| 95 |
res[com] = (res[com] || 0) - frac * recipe.in[com];
|
| 96 |
}
|
| 97 |
-
|
|
|
|
|
|
|
| 98 |
}
|
|
|
|
| 25 |
|
| 26 |
import { BUILDINGS } from "./entities.js";
|
| 27 |
import { RECIPES } from "../data.js";
|
| 28 |
+
import { techMult } from "./techtree.js";
|
| 29 |
|
| 30 |
// data.js RECIPES is an array; index it by id once for O(1) lookup.
|
| 31 |
const RECIPE_BY_ID = Object.fromEntries(RECIPES.map(r => [r.id, r]));
|
|
|
|
| 36 |
return def && def.recipe ? RECIPE_BY_ID[def.recipe] : null;
|
| 37 |
}
|
| 38 |
|
| 39 |
+
// Total industrial Power a player's completed buildings grant (Reactors), lifted
|
| 40 |
+
// by the Fusion Containment tech (techtree.js `reactors` node, +50%) if researched.
|
| 41 |
export function powerCap(state, owner) {
|
| 42 |
let cap = 0;
|
| 43 |
for (const b of state.buildings.values())
|
| 44 |
if (b.owner === owner && !b.constructing) cap += BUILDINGS[b.type].energyGrants || 0;
|
| 45 |
+
return cap * techMult(state.players[owner]?.upgrades, "powerMult");
|
| 46 |
}
|
| 47 |
|
| 48 |
// Total Power a player's completed factories draw at full rate — a factory
|
|
|
|
| 81 |
if (!recipe) return;
|
| 82 |
const throttle = powerThrottle(state, building.owner);
|
| 83 |
if (throttle <= 0) return;
|
| 84 |
+
const player = state.players[building.owner];
|
| 85 |
+
const res = player.resources;
|
| 86 |
+
const ups = player.upgrades;
|
| 87 |
|
| 88 |
+
// How much of a batch we can run this tick: the power-throttled target — sped up
|
| 89 |
+
// by the Factory Automation tech (techtree.js `automation`) — capped by the
|
| 90 |
+
// scarcest input in stock.
|
| 91 |
+
let frac = (BUILDINGS[building.type].prodRate || 1) * techMult(ups, "rateMult") * throttle * dt;
|
| 92 |
for (const com in recipe.in) {
|
| 93 |
if (com === "energy") continue;
|
| 94 |
frac = Math.min(frac, (res[com] || 0) / recipe.in[com]);
|
|
|
|
| 99 |
if (com === "energy") continue;
|
| 100 |
res[com] = (res[com] || 0) - frac * recipe.in[com];
|
| 101 |
}
|
| 102 |
+
// Heavy Alloys (techtree.js `heavyalloys`) lifts output per batch — same inputs,
|
| 103 |
+
// more goods out.
|
| 104 |
+
res[recipe.out] = (res[recipe.out] || 0) + frac * recipe.qty * techMult(ups, "yieldMult");
|
| 105 |
}
|
|
@@ -28,7 +28,7 @@ import { COM } from "../data.js";
|
|
| 28 |
// (engine/industry.js) are tradeable too — and since no world DEPOSITS them,
|
| 29 |
// createMarket prices them at the "scarce" ceiling everywhere, so refining a raw
|
| 30 |
// haul into them and selling is the whole point of building a factory.
|
| 31 |
-
const TRADEABLE = ["ore", "crystals", "radioactives", "gas", "ice", "relics", "metals", "alloys"];
|
| 32 |
const BASE = Object.fromEntries(TRADEABLE.map(id => [id, COM[id].base]));
|
| 33 |
|
| 34 |
export const TRADE_LOT = 25; // units bought/sold per click
|
|
|
|
| 28 |
// (engine/industry.js) are tradeable too — and since no world DEPOSITS them,
|
| 29 |
// createMarket prices them at the "scarce" ceiling everywhere, so refining a raw
|
| 30 |
// haul into them and selling is the whole point of building a factory.
|
| 31 |
+
const TRADEABLE = ["ore", "crystals", "radioactives", "gas", "ice", "relics", "metals", "alloys", "electronics", "machinery"];
|
| 32 |
const BASE = Object.fromEntries(TRADEABLE.map(id => [id, COM[id].base]));
|
| 33 |
|
| 34 |
export const TRADE_LOT = 25; // units bought/sold per click
|
|
@@ -14,6 +14,7 @@ import { updateRepair } from "./repair.js";
|
|
| 14 |
import { updateCombat, updateBuildingCombat, updateWorkerCombat } from "./combat.js";
|
| 15 |
import { updateBuildingConstruction, updateProductionQueue, BUILD_REACH } from "./production.js";
|
| 16 |
import { updateProduction } from "./industry.js";
|
|
|
|
| 17 |
import { applySeparation } from "./separation.js";
|
| 18 |
import { updateFog } from "./fog.js";
|
| 19 |
import { UNITS } from "./entities.js";
|
|
@@ -48,6 +49,7 @@ export function tick(state, dt) {
|
|
| 48 |
updateBuildingConstruction(state, building, dt);
|
| 49 |
updateProductionQueue(state, building, dt);
|
| 50 |
updateProduction(state, building, dt); // Odyssey factories refine raw hauls into goods (no-op without a recipe)
|
|
|
|
| 51 |
updateBuildingCombat(state, building, dt);
|
| 52 |
}
|
| 53 |
|
|
|
|
| 14 |
import { updateCombat, updateBuildingCombat, updateWorkerCombat } from "./combat.js";
|
| 15 |
import { updateBuildingConstruction, updateProductionQueue, BUILD_REACH } from "./production.js";
|
| 16 |
import { updateProduction } from "./industry.js";
|
| 17 |
+
import { updateResearch } from "./techtree.js";
|
| 18 |
import { applySeparation } from "./separation.js";
|
| 19 |
import { updateFog } from "./fog.js";
|
| 20 |
import { UNITS } from "./entities.js";
|
|
|
|
| 49 |
updateBuildingConstruction(state, building, dt);
|
| 50 |
updateProductionQueue(state, building, dt);
|
| 51 |
updateProduction(state, building, dt); // Odyssey factories refine raw hauls into goods (no-op without a recipe)
|
| 52 |
+
updateResearch(state, building, dt); // Odyssey Datacenter develops the tech tree (no-op for any other building)
|
| 53 |
updateBuildingCombat(state, building, dt);
|
| 54 |
}
|
| 55 |
|
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* ============================================================
|
| 2 |
+
The Odyssey research tree (Phase 2). Nodes are researched at a Datacenter,
|
| 3 |
+
PAID IN GATHERED COMMODITIES (the game's law — the resources you gather are the
|
| 4 |
+
resources you spend, no separate research currency) and DEVELOPED OVER TIME,
|
| 5 |
+
scaled by the world's tech rating so a Syndicate hub out-researches a frontier
|
| 6 |
+
rock. A researched node is an id in player.upgrades — the SAME bag the combat
|
| 7 |
+
doctrines use — so it gates buildings/recipes through the existing prereqsMet
|
| 8 |
+
primitive with zero new gating machinery. committedDoctrine/upgradeMult
|
| 9 |
+
(entities.js) both guard on UPGRADES membership, so a tech id parked in upgrades
|
| 10 |
+
is invisible to the doctrine system; the passive-effect nodes are read here via
|
| 11 |
+
techMult instead.
|
| 12 |
+
|
| 13 |
+
Odyssey-only and inert-by-construction: the Datacenter is `odysseyOnly`,
|
| 14 |
+
updateResearch is a no-op for any other building, and the skirmish AI never
|
| 15 |
+
builds one — so the skirmish sim/AI path is untouched and stays byte-identical
|
| 16 |
+
(a tech id is never in a skirmish player.upgrades). Deterministic and DOM-free:
|
| 17 |
+
accrual is dt-driven float math with no wall-clock and no unseeded randomness.
|
| 18 |
+
============================================================ */
|
| 19 |
+
|
| 20 |
+
"use strict";
|
| 21 |
+
|
| 22 |
+
import { PLANETS } from "../data.js";
|
| 23 |
+
import { canAfford, payCost, prereqsMet } from "./entities.js";
|
| 24 |
+
|
| 25 |
+
// The tree. `cost` is gathered commodities (paid on start); `time` is seconds to
|
| 26 |
+
// develop at a tech-5 world (scaled by researchTimeScale). `requires` are prereq
|
| 27 |
+
// tokens resolved by prereqsMet (a building type or another node). A node either
|
| 28 |
+
// UNLOCKS content (its id gates a building/recipe via `requires` elsewhere) or is
|
| 29 |
+
// a PASSIVE that multiplies industry (powerMult / rateMult / yieldMult, read by
|
| 30 |
+
// techMult). The three unlock nodes form the buildable spine; the three passives
|
| 31 |
+
// branch off it so "research next building" vs "boost what I have" is a real fork.
|
| 32 |
+
export const TECHS = {
|
| 33 |
+
metallurgy: { id: "metallurgy", name: "Metallurgy", cost: { crystals: 80 }, time: 20,
|
| 34 |
+
desc: "Unlock the Assembly Plant — refine metals into alloys." },
|
| 35 |
+
reactors: { id: "reactors", name: "Fusion Containment", cost: { crystals: 70 }, time: 18,
|
| 36 |
+
powerMult: 1.5, desc: "+50% Power from every Reactor." },
|
| 37 |
+
heavyalloys: { id: "heavyalloys", name: "Heavy Alloys", cost: { crystals: 110 }, time: 24, requires: ["metallurgy"],
|
| 38 |
+
yieldMult: 1.4, desc: "+40% output from the Smelter and Assembly Plant." },
|
| 39 |
+
electronics: { id: "electronics", name: "Microelectronics", cost: { crystals: 120 }, time: 28, requires: ["metallurgy"],
|
| 40 |
+
desc: "Unlock the Chip Fab — make electronics from crystals and metals." },
|
| 41 |
+
automation: { id: "automation", name: "Factory Automation", cost: { crystals: 130, radioactives: 40 }, time: 30, requires: ["electronics"],
|
| 42 |
+
rateMult: 1.25, desc: "+25% production speed at every factory." },
|
| 43 |
+
machining: { id: "machining", name: "Precision Machining", cost: { crystals: 150, radioactives: 60 }, time: 36, requires: ["electronics"],
|
| 44 |
+
desc: "Unlock the Machine Works — build machinery from alloys and electronics." },
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
// Research develops faster on a high-tech world (data.js PLANETS.tech, 1..10) and
|
| 48 |
+
// slower on a frontier rock — clamped so no world is punishing. Pure data lookup;
|
| 49 |
+
// the sole reason WHERE you research is a strategic choice. Deterministic.
|
| 50 |
+
export function researchTimeScale(state) {
|
| 51 |
+
const t = PLANETS.find(p => p.id === state.planetId)?.tech ?? 5;
|
| 52 |
+
const s = 5 / t; // tech 5 → 1.0×, tech 10 → 0.5×, tech 1 → 5× (clamped)
|
| 53 |
+
return s < 0.5 ? 0.5 : s > 2 ? 2 : s;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// Product of a passive node's multiplier field across a player's researched techs
|
| 57 |
+
// (1 when none apply) — the tech-tree twin of entities.js upgradeMult, reading
|
| 58 |
+
// TECHS instead of UPGRADES. Inert in skirmish (no TECH id is ever in a skirmish
|
| 59 |
+
// player.upgrades).
|
| 60 |
+
export function techMult(upgrades, field) {
|
| 61 |
+
let m = 1;
|
| 62 |
+
if (!upgrades) return m;
|
| 63 |
+
for (const id in upgrades) if (upgrades[id] && TECHS[id] && TECHS[id][field]) m *= TECHS[id][field];
|
| 64 |
+
return m;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
// Advance a Datacenter's in-progress research by dt — a no-op for anything that
|
| 68 |
+
// isn't a completed Datacenter with an active job. On completion the node lands in
|
| 69 |
+
// player.upgrades (where prereqsMet/techMult read it) and the job clears. Same
|
| 70 |
+
// dt-driven float pattern as buildProgress — deterministic, engine-pure.
|
| 71 |
+
export function updateResearch(state, building, dt) {
|
| 72 |
+
if (building.constructing || building.type !== "datacenter") return;
|
| 73 |
+
const job = building.research;
|
| 74 |
+
if (!job) return;
|
| 75 |
+
const def = TECHS[job.techId];
|
| 76 |
+
if (!def) { building.research = null; return; }
|
| 77 |
+
job.progress += dt / (def.time * researchTimeScale(state));
|
| 78 |
+
if (job.progress >= 1) {
|
| 79 |
+
state.players[building.owner].upgrades[job.techId] = true;
|
| 80 |
+
building.research = null;
|
| 81 |
+
state.events.push({ type: "researchComplete", techId: def.id, x: building.x, y: building.y, owner: building.owner });
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// Begin researching a node at a Datacenter: needs an IDLE completed Datacenter,
|
| 86 |
+
// the node not already owned, prereqs met, and affordability — then pay (gathered
|
| 87 |
+
// commodities) and start the timer. Mirrors production.js researchUpgrade, but
|
| 88 |
+
// timed rather than instant, and one project at a time.
|
| 89 |
+
export function researchTech(state, buildingId, techId) {
|
| 90 |
+
const building = state.buildings.get(buildingId);
|
| 91 |
+
if (!building || building.type !== "datacenter" || building.constructing) return false;
|
| 92 |
+
if (building.research) return false; // one project at a time
|
| 93 |
+
const player = state.players[building.owner];
|
| 94 |
+
if (player.upgrades[techId]) return false; // already researched
|
| 95 |
+
const def = TECHS[techId];
|
| 96 |
+
if (!def) return false;
|
| 97 |
+
if (!prereqsMet(state, building.owner, def)) return false;
|
| 98 |
+
if (!canAfford(player.resources, def.cost)) return false;
|
| 99 |
+
payCost(player.resources, def.cost);
|
| 100 |
+
building.research = { techId, progress: 0 };
|
| 101 |
+
return true;
|
| 102 |
+
}
|
|
@@ -17,6 +17,7 @@ import {
|
|
| 17 |
import { queueProduction, cancelProduction, researchUpgrade } from "./engine/production.js";
|
| 18 |
import { supplyUsed, supplyCap } from "./engine/supply.js";
|
| 19 |
import { powerCap, powerDraw } from "./engine/industry.js";
|
|
|
|
| 20 |
import { BUILDINGS, UNITS, UPGRADES, canAfford, prereqsMet, committedDoctrine } from "./engine/entities.js";
|
| 21 |
import { repairCost, repairConvoy, departNow } from "./engine/scenarios.js";
|
| 22 |
import { JUMP_COST, stagedRiders } from "./engine/galaxy.js";
|
|
@@ -447,6 +448,36 @@ function rebuildSelectionPanel(sel) {
|
|
| 447 |
});
|
| 448 |
}
|
| 449 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
// Spaceport (Odyssey): the interplanetary jump panel. Relocate the capital +
|
| 451 |
// the units staged nearby to another world; the world you leave carries on as
|
| 452 |
// a colony.
|
|
@@ -477,7 +508,7 @@ function rebuildSelectionPanel(sel) {
|
|
| 477 |
// refine raw hauls into goods worth real credits). A skirmish still allows
|
| 478 |
// expansion CCs, has no Spaceport, and no industry.
|
| 479 |
const buildables = ["barracks", "foundry", "arsenal", "refinery", "turret", "habitat"];
|
| 480 |
-
if (state.endless) buildables.push("reactor", "smelter", "assembler", "spaceport");
|
| 481 |
else buildables.push("command");
|
| 482 |
for (const t of buildables) {
|
| 483 |
const def = BUILDINGS[t];
|
|
@@ -595,8 +626,10 @@ function makeButton(label, onClick, { cost = null, tip = null, locked = false, l
|
|
| 595 |
}
|
| 596 |
|
| 597 |
// "Requires Foundry" style tooltip listing a def's unmet prerequisites by name.
|
|
|
|
|
|
|
| 598 |
function lockTipFor(def) {
|
| 599 |
-
return `Requires ${(def.requires || []).map(r => BUILDINGS[r]?.name || UPGRADES[r]?.name || r).join(", ")}`;
|
| 600 |
}
|
| 601 |
|
| 602 |
// A compact stat line for a unit/building button tooltip.
|
|
|
|
| 17 |
import { queueProduction, cancelProduction, researchUpgrade } from "./engine/production.js";
|
| 18 |
import { supplyUsed, supplyCap } from "./engine/supply.js";
|
| 19 |
import { powerCap, powerDraw } from "./engine/industry.js";
|
| 20 |
+
import { TECHS, researchTech } from "./engine/techtree.js";
|
| 21 |
import { BUILDINGS, UNITS, UPGRADES, canAfford, prereqsMet, committedDoctrine } from "./engine/entities.js";
|
| 22 |
import { repairCost, repairConvoy, departNow } from "./engine/scenarios.js";
|
| 23 |
import { JUMP_COST, stagedRiders } from "./engine/galaxy.js";
|
|
|
|
| 448 |
});
|
| 449 |
}
|
| 450 |
|
| 451 |
+
// Datacenter (Odyssey): the industrial tech tree. Researches one node at a time,
|
| 452 |
+
// paid in gathered commodities and developed over time — flat lock-tip buttons,
|
| 453 |
+
// the same idiom as the Refinery's doctrine research (no separate tree UI).
|
| 454 |
+
const datacenter = sel.find(e => e.kind === "building" && e.type === "datacenter" && !e.constructing);
|
| 455 |
+
if (datacenter) {
|
| 456 |
+
const upgrades = state.players.player.upgrades;
|
| 457 |
+
if (datacenter.research) {
|
| 458 |
+
const def = TECHS[datacenter.research.techId];
|
| 459 |
+
const row = document.createElement("div");
|
| 460 |
+
row.className = "sel-row";
|
| 461 |
+
row.textContent = `Researching ${def.name} — ${Math.round(datacenter.research.progress * 100)}%`;
|
| 462 |
+
panelEl.appendChild(row);
|
| 463 |
+
}
|
| 464 |
+
const busy = !!datacenter.research;
|
| 465 |
+
Object.values(TECHS).forEach(t => {
|
| 466 |
+
if (upgrades[t.id]) {
|
| 467 |
+
const row = document.createElement("div");
|
| 468 |
+
row.className = "sel-row";
|
| 469 |
+
row.textContent = `${t.name} — researched`;
|
| 470 |
+
panelEl.appendChild(row);
|
| 471 |
+
return;
|
| 472 |
+
}
|
| 473 |
+
const prereqLocked = !prereqsMet(state, "player", t);
|
| 474 |
+
panelEl.appendChild(makeButton(`Research ${t.name} (${costText(t.cost)})`,
|
| 475 |
+
() => researchTech(state, datacenter.id, t.id),
|
| 476 |
+
{ cost: t.cost, tip: t.desc, locked: prereqLocked || busy,
|
| 477 |
+
lockTip: prereqLocked ? lockTipFor(t) : busy ? "A research project is already in progress" : null }));
|
| 478 |
+
});
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
// Spaceport (Odyssey): the interplanetary jump panel. Relocate the capital +
|
| 482 |
// the units staged nearby to another world; the world you leave carries on as
|
| 483 |
// a colony.
|
|
|
|
| 508 |
// refine raw hauls into goods worth real credits). A skirmish still allows
|
| 509 |
// expansion CCs, has no Spaceport, and no industry.
|
| 510 |
const buildables = ["barracks", "foundry", "arsenal", "refinery", "turret", "habitat"];
|
| 511 |
+
if (state.endless) buildables.push("reactor", "smelter", "assembler", "datacenter", "chipfab", "machineworks", "spaceport");
|
| 512 |
else buildables.push("command");
|
| 513 |
for (const t of buildables) {
|
| 514 |
const def = BUILDINGS[t];
|
|
|
|
| 626 |
}
|
| 627 |
|
| 628 |
// "Requires Foundry" style tooltip listing a def's unmet prerequisites by name.
|
| 629 |
+
// A prereq token is a building type, a doctrine upgrade, or a tech-tree node — the
|
| 630 |
+
// name lookup covers all three (prereqsMet resolves them the same way).
|
| 631 |
function lockTipFor(def) {
|
| 632 |
+
return `Requires ${(def.requires || []).map(r => BUILDINGS[r]?.name || UPGRADES[r]?.name || TECHS[r]?.name || r).join(", ")}`;
|
| 633 |
}
|
| 634 |
|
| 635 |
// A compact stat line for a unit/building button tooltip.
|
|
@@ -95,6 +95,21 @@ test("the Odyssey AI wave-cadence clock survives a save/load (continue-identical
|
|
| 95 |
assert.equal(activeState(restored).aiNextWaveAt, 123.5, "the next-wave clock is preserved, not reset to wave-ready");
|
| 96 |
});
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
test("the galaxy save is seed+delta (no terrain), and guards its version", () => {
|
| 99 |
const json = JSON.stringify(serializeGalaxy(evolved(1)));
|
| 100 |
assert.ok(!/"terrain"/.test(json), "terrain arrays regenerate from the seed, not stored");
|
|
|
|
| 95 |
assert.equal(activeState(restored).aiNextWaveAt, 123.5, "the next-wave clock is preserved, not reset to wave-ready");
|
| 96 |
});
|
| 97 |
|
| 98 |
+
test("researched tech and an in-progress Datacenter project survive a save/load", () => {
|
| 99 |
+
const g = createGalaxy({ seed: 8 });
|
| 100 |
+
const s = activeState(g);
|
| 101 |
+
s.players.player.upgrades.metallurgy = true; // a completed research node
|
| 102 |
+
const dc = makeBuilding("datacenter", "player", 600, 500);
|
| 103 |
+
dc.research = { techId: "electronics", progress: 0.4 }; // a project mid-flight
|
| 104 |
+
s.buildings.set(dc.id, dc);
|
| 105 |
+
const restored = deserializeGalaxy(JSON.parse(JSON.stringify(serializeGalaxy(g))));
|
| 106 |
+
const rs = activeState(restored);
|
| 107 |
+
assert.equal(rs.players.player.upgrades.metallurgy, true, "the researched node persists (rides in player.upgrades)");
|
| 108 |
+
const rdc = [...rs.buildings.values()].find(b => b.type === "datacenter");
|
| 109 |
+
assert.ok(rdc && rdc.research && rdc.research.techId === "electronics", "the in-progress project persists on the building");
|
| 110 |
+
assert.ok(Math.abs(rdc.research.progress - 0.4) < 1e-9, "…with its progress intact");
|
| 111 |
+
});
|
| 112 |
+
|
| 113 |
test("the galaxy save is seed+delta (no terrain), and guards its version", () => {
|
| 114 |
const json = JSON.stringify(serializeGalaxy(evolved(1)));
|
| 115 |
assert.ok(!/"terrain"/.test(json), "terrain arrays regenerate from the seed, not stored");
|
|
@@ -122,6 +122,18 @@ test("end-to-end: a built chain refines through the real Odyssey tick, and the a
|
|
| 122 |
assert.equal(g.credits, creditsBefore + proceeds, "credits banked the sale");
|
| 123 |
});
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
test("industry is Odyssey-only: the buildings are flagged, and a skirmish makes no refined goods", () => {
|
| 126 |
for (const t of ["reactor", "smelter", "assembler"]) assert.equal(BUILDINGS[t].odysseyOnly, true, `${t} is Odyssey-only`);
|
| 127 |
const state = createGameState({ planetId: "ferros" }); // a plain skirmish (not endless)
|
|
|
|
| 122 |
assert.equal(g.credits, creditsBefore + proceeds, "credits banked the sale");
|
| 123 |
});
|
| 124 |
|
| 125 |
+
test("a researched passive tech lifts production — Heavy Alloys yields ~40% more from the same ore", () => {
|
| 126 |
+
const plain = stub([reactor(), smelter()], { ore: 1000 });
|
| 127 |
+
const teched = stub([reactor(), smelter()], { ore: 1000 });
|
| 128 |
+
teched.players.player.upgrades = { heavyalloys: true };
|
| 129 |
+
const sm1 = [...plain.buildings.values()].find(b => b.type === "smelter");
|
| 130 |
+
const sm2 = [...teched.buildings.values()].find(b => b.type === "smelter");
|
| 131 |
+
updateProduction(plain, sm1, 0.1);
|
| 132 |
+
updateProduction(teched, sm2, 0.1);
|
| 133 |
+
const m1 = plain.players.player.resources.metals, m2 = teched.players.player.resources.metals;
|
| 134 |
+
assert.ok(near(m2, m1 * 1.4), "Heavy Alloys yields 40% more metals per batch");
|
| 135 |
+
});
|
| 136 |
+
|
| 137 |
test("industry is Odyssey-only: the buildings are flagged, and a skirmish makes no refined goods", () => {
|
| 138 |
for (const t of ["reactor", "smelter", "assembler"]) assert.equal(BUILDINGS[t].odysseyOnly, true, `${t} is Odyssey-only`);
|
| 139 |
const state = createGameState({ planetId: "ferros" }); // a plain skirmish (not endless)
|
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { test } from "node:test";
|
| 2 |
+
import assert from "node:assert/strict";
|
| 3 |
+
import { createGameState, makeBuilding } from "../engine/state.js";
|
| 4 |
+
import { TECHS, researchTech, updateResearch, researchTimeScale, techMult } from "../engine/techtree.js";
|
| 5 |
+
import { BUILDINGS, prereqsMet } from "../engine/entities.js";
|
| 6 |
+
|
| 7 |
+
// A datacenter owned by the player on an endless world, with commodities to burn.
|
| 8 |
+
function odysseyWithDatacenter(planetId = "ferros") {
|
| 9 |
+
const state = createGameState({ planetId, endless: true });
|
| 10 |
+
const dc = makeBuilding("datacenter", "player", 600, 500);
|
| 11 |
+
state.buildings.set(dc.id, dc);
|
| 12 |
+
state.players.player.resources.crystals = 1000;
|
| 13 |
+
state.players.player.resources.radioactives = 1000;
|
| 14 |
+
return { state, dc };
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
test("every TECH node is well-formed: a commodity cost (no separate currency), a time, resolvable prereqs", () => {
|
| 18 |
+
for (const t of Object.values(TECHS)) {
|
| 19 |
+
assert.ok(t.cost && Object.keys(t.cost).length > 0, `${t.id} costs gathered commodities`);
|
| 20 |
+
assert.ok(!t.cost.tech, `${t.id} must not invent a separate tech currency`);
|
| 21 |
+
assert.ok(t.time > 0, `${t.id} takes time to develop`);
|
| 22 |
+
assert.ok(t.desc, `${t.id} has a description`);
|
| 23 |
+
for (const r of t.requires || []) {
|
| 24 |
+
assert.ok(BUILDINGS[r] || TECHS[r], `${t.id} prereq ${r} resolves to a building or another node`);
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
test("researchTech starts a project: pays the commodity cost, one project at a time", () => {
|
| 30 |
+
const { state, dc } = odysseyWithDatacenter();
|
| 31 |
+
const before = state.players.player.resources.crystals;
|
| 32 |
+
assert.equal(researchTech(state, dc.id, "metallurgy"), true);
|
| 33 |
+
assert.equal(state.players.player.resources.crystals, before - TECHS.metallurgy.cost.crystals, "paid on start");
|
| 34 |
+
assert.ok(dc.research && dc.research.techId === "metallurgy", "the project is in progress");
|
| 35 |
+
assert.equal(researchTech(state, dc.id, "reactors"), false, "a Datacenter researches one node at a time");
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
test("research is prereq-gated and afford-gated", () => {
|
| 39 |
+
const { state, dc } = odysseyWithDatacenter();
|
| 40 |
+
assert.equal(researchTech(state, dc.id, "electronics"), false, "electronics needs metallurgy first");
|
| 41 |
+
state.players.player.upgrades.metallurgy = true;
|
| 42 |
+
assert.equal(researchTech(state, dc.id, "electronics"), true, "unlocked once metallurgy is owned");
|
| 43 |
+
|
| 44 |
+
const poor = odysseyWithDatacenter();
|
| 45 |
+
poor.state.players.player.resources.crystals = 0;
|
| 46 |
+
assert.equal(researchTech(poor.state, poor.dc.id, "metallurgy"), false, "can't afford → refused");
|
| 47 |
+
});
|
| 48 |
+
|
| 49 |
+
test("updateResearch develops the node over time and banks it into player.upgrades", () => {
|
| 50 |
+
const { state, dc } = odysseyWithDatacenter();
|
| 51 |
+
researchTech(state, dc.id, "metallurgy");
|
| 52 |
+
const need = TECHS.metallurgy.time * researchTimeScale(state);
|
| 53 |
+
for (let t = 0; t < need + 1; t += 0.5) updateResearch(state, dc, 0.5);
|
| 54 |
+
assert.equal(state.players.player.upgrades.metallurgy, true, "the node completes and lands in upgrades");
|
| 55 |
+
assert.equal(dc.research, null, "the project clears on completion");
|
| 56 |
+
assert.ok(state.events.some(e => e.type === "researchComplete" && e.techId === "metallurgy"), "an event fires for the HUD/sound");
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
test("updateResearch is a no-op for a non-Datacenter and for an idle Datacenter", () => {
|
| 60 |
+
const { state, dc } = odysseyWithDatacenter();
|
| 61 |
+
const smelter = makeBuilding("smelter", "player", 700, 500);
|
| 62 |
+
smelter.research = { techId: "metallurgy", progress: 0 }; // even if mis-set, a non-datacenter ignores it
|
| 63 |
+
state.buildings.set(smelter.id, smelter);
|
| 64 |
+
updateResearch(state, smelter, 100);
|
| 65 |
+
assert.ok(!state.players.player.upgrades.metallurgy, "a Smelter never researches");
|
| 66 |
+
updateResearch(state, dc, 100); // dc has no research job
|
| 67 |
+
assert.ok(!state.players.player.upgrades.metallurgy, "an idle Datacenter accrues nothing");
|
| 68 |
+
});
|
| 69 |
+
|
| 70 |
+
test("research develops faster on a high-tech world than a frontier one, and is clamped", () => {
|
| 71 |
+
const hi = createGameState({ planetId: "kybernet", endless: true }); // tech 10
|
| 72 |
+
const lo = createGameState({ planetId: "oort", endless: true }); // tech 2
|
| 73 |
+
assert.ok(researchTimeScale(hi) < researchTimeScale(lo), "Kybernet out-researches Oort");
|
| 74 |
+
assert.ok(researchTimeScale(hi) >= 0.5 && researchTimeScale(lo) <= 2, "clamped so no world is punishing");
|
| 75 |
+
});
|
| 76 |
+
|
| 77 |
+
test("passive nodes multiply industry through techMult; unlock nodes carry no passive field", () => {
|
| 78 |
+
assert.equal(techMult({}, "powerMult"), 1, "nothing researched → no multiplier");
|
| 79 |
+
assert.equal(techMult({ reactors: true }, "powerMult"), 1.5, "Fusion Containment lifts Power");
|
| 80 |
+
assert.equal(techMult({ automation: true }, "rateMult"), 1.25, "Automation speeds factories");
|
| 81 |
+
assert.equal(techMult({ heavyalloys: true }, "yieldMult"), 1.4, "Heavy Alloys lifts yield");
|
| 82 |
+
assert.equal(techMult({ metallurgy: true }, "powerMult"), 1, "an unlock node has no passive field");
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
+
test("the research + deeper-industry buildings are Odyssey-only and tech-gated through prereqsMet", () => {
|
| 86 |
+
for (const t of ["datacenter", "chipfab", "machineworks"]) assert.equal(BUILDINGS[t].odysseyOnly, true, `${t} is Odyssey-only`);
|
| 87 |
+
assert.ok(BUILDINGS.assembler.requires.includes("metallurgy"), "the Assembly Plant is gated behind Metallurgy research");
|
| 88 |
+
assert.ok(BUILDINGS.chipfab.requires.includes("electronics"), "the Chip Fab is gated behind Microelectronics");
|
| 89 |
+
assert.ok(BUILDINGS.machineworks.requires.includes("machining"), "the Machine Works is gated behind Precision Machining");
|
| 90 |
+
|
| 91 |
+
// A tech node gates a building through the SAME prereqsMet used by building tokens.
|
| 92 |
+
const state = createGameState({ planetId: "ferros", endless: true });
|
| 93 |
+
const smelter = makeBuilding("smelter", "player", 600, 500);
|
| 94 |
+
state.buildings.set(smelter.id, smelter);
|
| 95 |
+
assert.equal(prereqsMet(state, "player", BUILDINGS.assembler), false, "no metallurgy → Assembly Plant locked");
|
| 96 |
+
state.players.player.upgrades.metallurgy = true;
|
| 97 |
+
assert.equal(prereqsMet(state, "player", BUILDINGS.assembler), true, "metallurgy researched → unlocked");
|
| 98 |
+
});
|