Stage 0-2 server spine: db, scheduler, REST, auth, economy, map
Built: SQLite (node:sqlite) via server/db.js with checksummed migrations, injectable clock, persistent event scheduler with catch-up, tiny REST router (error envelope, idempotency keys, rate limits, bearer tokens with scrypt passwords), lazy-resource economy in public/js/rules.js + data.js, build/cancel/rename commands, seeded map + spawn ring, generated docs/openapi.json. NETWALL net.js/static.js reused. Tested: manual smoke run only (signup, town view, build, map). No unit tests or e2e yet. NOT done: military, expansion, social, client, push, deploy docs, bots/admin. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
parent
9fa76d53a8
commit
b56b13880e
39 changed files with 4450 additions and 0 deletions
106
public/js/data.js
Normal file
106
public/js/data.js
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
'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 };
|
||||
|
||||
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',
|
||||
};
|
||||
|
||||
return { HOUR_MS, RESOURCES, FORMULAS, FIELD_SLOTS, FIELD_TYPES, FIELD_PRODUCES, FIELDS_PER_TYPE, WILD_SLOTS,
|
||||
BUILDINGS, START, TILE, PROTECTION_HOURS, AS_RANGE, WORLD_DEFAULTS };
|
||||
}));
|
||||
Loading…
Add table
Add a link
Reference in a new issue