Upstream/public/js/data.js
jvanvik 249818a7aa Stage 3-5 server (military, expansion, social), web client for stages 1-2, ops/deploy
Built: units/research/training, movements (scan, raid, attack, takeover, reinforce, settle, transport), deterministic
combat resolved in the event queue, reports, power/offline units, founding + conquest + incumbent sites; alliances,
roles, diplomacy (24h pact cancel via events), messages, rankings; vanilla-JS phone-first client (auth, POP, map,
alerts, settings, en/nb); systemd units, backup timer, DEPLOY.md, tools/admin.js.
Tested: npm test 96/96 (fake clock, in-memory db, a few real-HTTP tests); client checked with headless Chromium
screenshots only. NOT done: marketplace/transport trade, client screens for military/social, WebSocket push,
bots/balance, e2e suite. All unit stats and costs are unbalanced first guesses.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
2026-10-11 18:32:36 +02:00

240 lines
15 KiB
JavaScript

'use strict';
/*
* ALL content and balance for UPSTREAM. Plain data, no logic: rules.js turns it into formulas.
* Loads as a browser script (window.UpstreamData) and as a Node module. Player-facing names live in i18n.js;
* ids here are the generic genre terms used by the code.
*
* Every number is a first-pass starting point for the bot balance runs (stage 7), not a promise.
* Times are in seconds at world speed 1x. Costs are for level 1 and grow with COST_GROWTH.
*/
(function (root, factory) {
if (typeof module === 'object' && module.exports) module.exports = factory();
else root.UpstreamData = factory();
}(typeof self !== 'undefined' ? self : this, function () {
const HOUR_MS = 3600 * 1000;
// Storable resources. Power is a rate plus a battery buffer, not an accumulating stock.
const RESOURCES = ['fiber', 'hardware', 'capital'];
const FORMULAS = {
productionBase: 6, // per hour at level 1
productionGrowth: 1.25,
costGrowth: 1.28,
timeGrowth: 1.16,
storageBase: 1000, // Rack hall level 1
storageGrowth: 1.22,
batteryBase: 200, // Battery bank level 1, in power points
batteryGrowth: 1.22,
coreSpeedPerLevel: 0.04, // build time / (1 + 0.04 * core router level)
firewallPerLevel: 0.03, // defence multiplier 1 + 0.03 * level
ruralBonus: 0.25, // production bonus per rural area in reach
ruralMax: 3,
ruralReach: 2, // tiles
footprintBase: 1, // per level-step per day: 1 + L / 5
footprintDivisor: 5,
footprintNeedBase: 500, // need(n) = 500 * n^1.8 for the n-th extra POP
footprintNeedExp: 1.8,
loyaltyRegenPerHour: 1,
loyaltyMax: 100,
secondQueueCoreLevel: 10, // Core router level that opens the second build slot
minBuildMs: 5000,
};
// Resource fields: 18 slots per POP, 4 fixed to each production type plus 2 wild slots chosen at founding.
const FIELD_SLOTS = 18;
const FIELD_TYPES = ['cable_yard', 'supply_depot', 'sales_office', 'substation'];
const FIELD_PRODUCES = { cable_yard: 'fiber', supply_depot: 'hardware', sales_office: 'capital', substation: 'power' };
const FIELDS_PER_TYPE = 4;
const WILD_SLOTS = 2;
// kind: 'field' | 'infra'. draw: power draw per level. requires: [{ type, level }] (all must hold).
// The key of an infra building is its type; field keys are f1..f18.
const BUILDINGS = {
cable_yard: { kind: 'field', maxLevel: 20, cost: { fiber: 40, hardware: 25, capital: 15 }, time: 120, draw: 0, requires: [] },
supply_depot: { kind: 'field', maxLevel: 20, cost: { fiber: 45, hardware: 20, capital: 20 }, time: 130, draw: 0, requires: [] },
sales_office: { kind: 'field', maxLevel: 20, cost: { fiber: 50, hardware: 30, capital: 10 }, time: 140, draw: 0, requires: [] },
substation: { kind: 'field', maxLevel: 20, cost: { fiber: 35, hardware: 40, capital: 25 }, time: 150, draw: 0, requires: [] },
core_router: { kind: 'infra', maxLevel: 20, cost: { fiber: 90, hardware: 70, capital: 60 }, time: 300, draw: 1, requires: [] },
rack_hall: { kind: 'infra', maxLevel: 20, cost: { fiber: 80, hardware: 50, capital: 40 }, time: 240, draw: 1, requires: [] },
battery_bank: { kind: 'infra', maxLevel: 20, cost: { fiber: 60, hardware: 80, capital: 40 }, time: 240, draw: 1, requires: [] },
firewall: { kind: 'infra', maxLevel: 20, cost: { fiber: 100, hardware: 90, capital: 50 }, time: 360, draw: 1, requires: [{ type: 'core_router', level: 2 }] },
noc: { kind: 'infra', maxLevel: 20, cost: { fiber: 120, hardware: 80, capital: 60 }, time: 360, draw: 1, requires: [{ type: 'core_router', level: 2 }] },
research_lab: { kind: 'infra', maxLevel: 20, cost: { fiber: 140, hardware: 120, capital: 90 }, time: 420, draw: 1, requires: [{ type: 'core_router', level: 3 }] },
ops_lab: { kind: 'infra', maxLevel: 20, cost: { fiber: 150, hardware: 130, capital: 80 }, time: 420, draw: 1, requires: [{ type: 'core_router', level: 3 }, { type: 'research_lab', level: 3 }] },
internet_exchange: { kind: 'infra', maxLevel: 20, cost: { fiber: 130, hardware: 100, capital: 140 }, time: 420, draw: 1, requires: [{ type: 'core_router', level: 4 }] },
peering_office: { kind: 'infra', maxLevel: 20, cost: { fiber: 110, hardware: 90, capital: 120 }, time: 420, draw: 1, requires: [{ type: 'core_router', level: 5 }] },
rollout_depot: { kind: 'infra', maxLevel: 20, cost: { fiber: 300, hardware: 250, capital: 250 }, time: 600, draw: 1, requires: [{ type: 'core_router', level: 10 }] },
// Only buildable on backbone landing sites (end game, stage 5+). Cost is deliberately far above the rest.
backbone_node: { kind: 'infra', maxLevel: 100, cost: { fiber: 4000, hardware: 4000, capital: 4000 }, time: 7200, draw: 0, requires: [], special: 'backbone' },
};
// A brand-new capital POP: fields at level 1, a little infrastructure, some resources.
const START = {
fieldLevel: 1,
infra: { core_router: 1, rack_hall: 1, battery_bank: 1 },
resources: { fiber: 750, hardware: 750, capital: 750 },
battery: 100,
loyalty: 100,
// Wild slots: the two wild fields get these types unless the signup picks (stage 1: fixed, stage 4 lets you choose)
wild: ['cable_yard', 'supply_depot'],
};
const TILE = {
ruralShare: 0.06, // share of tiles that are rural areas
incumbentShare: 0.02, // share of tiles that are incumbent (NPC) sites
ruralTypes: ['fiber', 'hardware', 'capital'], // which resource a rural area boosts
spawnMinSpacing: 3,
spawnRingStart: 4, // first spawn ring radius (tiles from the centre)
spawnRingStep: 3,
};
const PROTECTION_HOURS = 72;
// AS numbers come from the 32-bit private range (RFC 6996). Display name only.
const AS_RANGE = { min: 4200000000, max: 4294967294 };
// Alliances, diplomacy, messages (stage 5). Roles are listed most senior first. `permissions` maps an action to the
// roles allowed to do it; rules.allianceCan reads it. Times in hours are at world speed 1x unless noted "real".
const SOCIAL = {
roles: ['leader', 'diplomat', 'officer', 'member'],
permissions: {
invite: ['leader', 'officer'],
cancelInvite: ['leader', 'officer'],
viewInvites: ['leader', 'officer'],
kick: ['leader', 'officer'], // and only members the actor outranks
setRole: ['leader'],
transfer: ['leader'],
diplomacy: ['leader', 'diplomat'],
editNotes: ['leader', 'diplomat', 'officer'],
broadcast: ['leader', 'diplomat', 'officer', 'member'],
disband: ['leader'],
},
allianceBaseSize: 10, // size cap = base + perLevel * Peering office level (best POP of the leader)
allianceSizePerLevel: 2,
minPeeringLevel: 1, // needed to found or join
nameLen: [3, 30], tagLen: [2, 5],
inviteTtlHours: 168, // real time, not divided by world speed
proposalTtlHours: 72, // real time
maxPendingInvites: 25,
maxNotes: 10, noteMax: 1000,
// Diplomacy. from -> to -> how the change happens: 'immediate' (one side decides), 'proposal' (the other side
// must accept) or 'delayed' (one side cancels, takes pactCancelHours / world speed). Missing = not allowed.
diplomacyStates: ['war', 'neutral', 'nap', 'confed'],
diplomacyMoves: {
neutral: { war: 'immediate', nap: 'proposal', confed: 'proposal' },
nap: { neutral: 'delayed', war: 'delayed', confed: 'proposal' },
confed: { neutral: 'delayed', nap: 'delayed', war: 'delayed' },
war: { neutral: 'proposal', nap: 'proposal' },
},
pactCancelHours: 24,
// Messages: plain text, DB-backed send limits per sender (counted over the window, real time).
messageMax: 2000,
messageLimits: { dm10min: 15, dmHour: 60, broadcastHour: 20 },
maxBlocks: 100,
rankingsPageMax: 100,
};
const WORLD_DEFAULTS = {
name: 'World 1',
speed: 1,
mapRadius: 50, // coordinates -50..50 (101 x 101). DESIGN.md says shrink for the first world.
preset: 'standard',
};
// ------------------------------------------------------------------ military (stages 3 and 4)
// Units. Stats: attack, defence, speed (tiles/hour at 1x), carry (loot per unit), draw (power points/hour while
// stationed), cost (per unit), time (seconds per unit at 1x, before building level), building (where it is trained),
// requires (all must hold; the training building is always required at level 1). `fixed: true` = never moves.
// role: scout | defender | attacker | siege | settler | conquest. Ids are generic; i18n.js holds the names.
const UNITS = {
port_scanner: { role: 'scout', building: 'noc', attack: 0, defence: 1, speed: 20, carry: 0, draw: 1, cost: { fiber: 30, hardware: 30, capital: 20 }, time: 90, requires: [{ type: 'noc', level: 1 }] },
soc_analyst: { role: 'defender', building: 'noc', attack: 5, defence: 25, speed: 7, carry: 0, draw: 1, cost: { fiber: 60, hardware: 20, capital: 10 }, time: 120, requires: [{ type: 'noc', level: 1 }] },
blue_team: { role: 'defender', building: 'noc', attack: 10, defence: 80, speed: 5, carry: 0, draw: 2, cost: { fiber: 100, hardware: 90, capital: 50 }, time: 300, requires: [{ type: 'noc', level: 5 }, { type: 'research_lab', level: 2 }] },
honeypot: { role: 'defender', building: 'noc', attack: 0, defence: 100, speed: 0, carry: 0, draw: 1, cost: { fiber: 120, hardware: 80, capital: 40 }, time: 280, requires: [{ type: 'noc', level: 3 }, { type: 'research_lab', level: 1 }], fixed: true },
script_crew: { role: 'attacker', building: 'ops_lab', attack: 40, defence: 10, speed: 8, carry: 50, draw: 1, cost: { fiber: 80, hardware: 40, capital: 30 }, time: 180, requires: [{ type: 'ops_lab', level: 1 }] },
botnet: { role: 'attacker', building: 'ops_lab', attack: 90, defence: 25, speed: 14, carry: 150, draw: 3, cost: { fiber: 200, hardware: 160, capital: 120 }, time: 420, requires: [{ type: 'ops_lab', level: 5 }, { type: 'research_lab', level: 5 }] },
ddos_rig: { role: 'siege', building: 'ops_lab', attack: 60, defence: 20, speed: 5, carry: 0, draw: 3, cost: { fiber: 300, hardware: 250, capital: 100 }, time: 600, requires: [{ type: 'ops_lab', level: 8 }, { type: 'research_lab', level: 6 }] },
exploit_kit: { role: 'siege', building: 'ops_lab', attack: 40, defence: 10, speed: 5, carry: 0, draw: 3, cost: { fiber: 280, hardware: 300, capital: 150 }, time: 720, requires: [{ type: 'ops_lab', level: 10 }, { type: 'research_lab', level: 8 }] },
rollout_crew: { role: 'settler', building: 'rollout_depot', attack: 0, defence: 5, speed: 6, carry: 0, draw: 2, cost: { fiber: 400, hardware: 300, capital: 300 }, time: 900, requires: [{ type: 'rollout_depot', level: 1 }] },
ma_team: { role: 'conquest', building: 'rollout_depot', attack: 0, defence: 5, speed: 6, carry: 0, draw: 2, cost: { fiber: 700, hardware: 600, capital: 800 }, time: 1200, requires: [{ type: 'rollout_depot', level: 5 }] },
};
// Display / UI order.
const UNIT_ORDER = ['port_scanner', 'soc_analyst', 'blue_team', 'honeypot', 'script_crew', 'botnet', 'ddos_rig', 'exploit_kit', 'rollout_crew', 'ma_team'];
const MILITARY = {
researchPerLevel: 0.05, // +5% attack or defence per research level of one unit type
trainSpeedPerLevel: 0.03, // training time / (1 + 0.03 * level of the training building)
maxTrainQueue: 8, // batches waiting per training building
maxBatch: 5000,
defenceBase: 10, // flat defence of any POP, before the firewall multiplier
rigFirewallDivisor: 10, // every 10 DDoS rigs lower the effective firewall by one level
lossExponent: 1.5,
raidLossFactor: 0.5, // raid: both sides lose 0.5 * (weak/strong)^1.5
cachePerLevel: 0.10, // Rack hall hides 10% of the stock per level from raids ...
cacheMax: 0.5, // ... up to 50%
kitsMin: 5, // exploit kits (survivors) needed to damage a building at all
kitsPerLevel: 20, // levels destroyed = max(1, floor(kits / 20))
loyaltyDrop: [15, 30], // inclusive range, rolled from the world seed
scanBuildingsRatio: 2, // attacking scanners needed per defending scanner to see buildings
scanLossExponent: 1.5,
recallWindowMs: 90 * 1000,
reportRetentionMs: 14 * 24 * HOUR_MS, // real time
pointsPerCost: 0.01, // battle points per resource point of killed units (operator_stats)
decommissionHours: 24, // offline this long (divided by world speed) and units are decommissioned
batteryEpsilon: 1e-6,
maxLists: 200,
};
// Research: +5% (MILITARY.researchPerLevel) attack or defence for ONE unit type per level, per POP, in the Research lab.
// Level n needs a Research lab of level n + labOffset. One research at a time per POP.
const RESEARCH = {
stats: ['attack', 'defence'],
maxLevel: 10,
labOffset: 2,
costFactor: 8, // times the unit's own cost, per level, growing with costGrowth
costGrowth: 1.35,
timeBase: 1800, // seconds at level 1
timeGrowth: 1.3,
labSpeedPerLevel: 0.03,
};
// Founding and conquering POPs (stage 4).
const EXPANSION = {
settleUnit: 'rollout_crew',
crews: 3, // exactly this many found a POP; consumed
maxDistance: 15, // from any own POP
startResources: { fiber: 250, hardware: 250, capital: 250 }, // "1 h of resources" for a POP that produces nothing yet
foundedLoyalty: 100,
conqueredLoyalty: 25,
conquestUnit: 'ma_team', // one per takeover counts and is used up when it lowers loyalty
};
// Resource transport between POPs (trade is built on it): `links` concurrent transports = Internet exchange level.
const TRANSPORT = { building: 'internet_exchange', speed: 12, capacityPerLink: 500 };
// Which unit roles may go on which movement type.
const MOVE_ROLES = {
scan: ['scout'],
raid: ['attacker', 'defender'],
attack: ['attacker', 'defender', 'siege'],
takeover: ['attacker', 'defender', 'siege', 'conquest'],
reinforce: ['scout', 'defender', 'attacker', 'siege', 'settler', 'conquest'],
settle: ['settler'],
};
// Incumbent (NPC) sites: static defence that grows with world age. Taking one (first time per operator) gives a
// one-time Hardware bonus; each distinct site taken adds +10% research speed, up to researchSpeedMax.
const INCUMBENT = {
baseDefence: 600,
variance: 0.25, // per-site factor 1 +- variance, from the world seed
perDayGrowth: 0.04, // +4% of base per world day (world days = real days * speed)
scanStrength: 12, // counts as this many scanners when scanned
hardwareBonus: 2500,
researchSpeedBonus: 0.10,
researchSpeedMax: 0.5,
};
return { UNITS, UNIT_ORDER, MILITARY, RESEARCH, EXPANSION, TRANSPORT, MOVE_ROLES, INCUMBENT, HOUR_MS, RESOURCES, FORMULAS, FIELD_SLOTS, FIELD_TYPES, FIELD_PRODUCES, FIELDS_PER_TYPE, WILD_SLOTS,
SOCIAL, BUILDINGS, START, TILE, PROTECTION_HOURS, AS_RANGE, WORLD_DEFAULTS };
}));