Cable ships: club repair ships sail out to subsea cuts, private charters jump the queue, lay ships build your cables
A subsea cut sends the nearest free ship of its region's maintenance club from its port, along the cable routes at about 500 km a day; the cut lasts while it sails, waits for permits in slow countries and splices (3-5 days shallow, 6-12 deep). Ships stay busy until home (S.fleet). With the club's ships all out the cut waits; a private charter of the quickest free ship costs $1M + $200/km sailed. Own subsea builds show survey/factory, then a lay ship at 150 km/day; a second lay ship can be booked before laying ($3M + $150k/day saved), and crews no longer speed up cables at sea. Ships are drawn on the map and can be tapped.
This commit is contained in:
parent
1fa5566d66
commit
96e2c2f537
28 changed files with 606 additions and 138 deletions
238
tests/cable-ships.test.js
Normal file
238
tests/cable-ships.test.js
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// Cable ships (src/game/20-world/70-cable-ships.js, src/game/85-incidents/50-cable-ships.js): a subsea cut sends a club
|
||||
// ship from its port, the cut lasts until it has sailed out and spliced, the ship is busy until it is home again, and a
|
||||
// cut waits when every ship of its zone's club is out, unless a private charter jumps the queue.
|
||||
const start = "ACT.start({});S.cash=1e9;S.lvl=13;S.day=200;S.nextFail=S.nextEvent=1e8;for(const g of GOALS)S.done[g.id]=0;";
|
||||
const wave = (id, a, b, cable, km) => `{id:'${id}',a:'${a}',b:'${b}',kind:'wave',sub:true,tier:0,km:${km},cable:'${cable}',cut:0,mo:1000}`;
|
||||
// A cut with a known fault: t of the way from a, sw days of splicing, sp days of permits.
|
||||
const cut = (id, link, t, sw = 4, sp = 0) => `(()=>{const l=S.links.find(x=>x.id==='${link}');S.inc.push({id:'${id}',type:'cut',ref:l.trench||l.id,until:S.day+15,msg:'cut',cost:4000,start:S.day});
|
||||
const i=S.inc[S.inc.length-1];i.sl=l.id;i.st=${t};i.sw=${sw};i.sp=${sp};shipAssign(i,l);})()`;
|
||||
const J = (ev, code) => JSON.parse(ev(`JSON.stringify(${code})`));
|
||||
|
||||
test('a subsea cut sends the nearest free club ship, and lasts until it has sailed out and spliced', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + `S.links=[${wave('med', 'bcn', 'mrs', 'medusa', 365)}];S.inc=[];` + cut('c1', 'med', 0.9));
|
||||
const i = J(ev, "S.inc[0]"), f = J(ev, "S.fleet[S.inc[0].ship]");
|
||||
assert.ok(['mend', 'tea'].includes(i.ship), 'a Mediterranean Mending Club ship from Marseille');
|
||||
// 10% of 365 km from Marseille: one day to sail, one to get going, four to splice.
|
||||
assert.equal(f.arr, 200 + 1 + 1);
|
||||
assert.equal(f.done, f.arr + 4);
|
||||
assert.equal(f.back, f.done + 1);
|
||||
assert.equal(i.until, f.done);
|
||||
assert.equal(ev("S.links[0].cut"), f.done);
|
||||
assert.equal(ev("linkDown(S.links[0])"), true);
|
||||
assert.match(ev("shipStatus(S.inc[0])"), /is sailing from Marseille: on site in 2d, cable back in about 6d/);
|
||||
// The cut ends with the splice; the ship sails home and only then takes another job.
|
||||
for (let d = 200; d < f.done; d++) ev('dayTick()');
|
||||
assert.equal(ev("S.inc.length"), 0);
|
||||
assert.equal(ev("linkDown(S.links[0])"), false);
|
||||
assert.ok(ev(`!shipFree(SHIP.${i.ship})`), 'still sailing home');
|
||||
ev('dayTick()');
|
||||
assert.ok(ev(`shipFree(SHIP.${i.ship})`));
|
||||
assert.equal(ev(`S.fleet.${i.ship}`), undefined);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('with every club ship out the cut waits; a private charter jumps the queue, for millions', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + `S.links=[${wave('med', 'bcn', 'mrs', 'medusa', 365)}];S.inc=[];`
|
||||
+ "for(const id of ['mend','tea'])S.fleet[id]={inc:null,link:'x',t:0.5,e:'a',dep:190,arr:195,done:205,back:230,fx:0,fy:0};" + cut('c1', 'med', 0.5));
|
||||
const i = J(ev, "S.inc[0]");
|
||||
assert.equal(i.ship, null);
|
||||
assert.equal(i.seaq, 1);
|
||||
assert.equal(ev("linkDown(S.links[0])"), true);
|
||||
assert.match(ev("shipStatus(S.inc[0])"), /Every Mediterranean Mending Club ship is out on a job/);
|
||||
// The charter is the quickest free ship anywhere: from Cornwall, about 4,800 km away.
|
||||
assert.ok(i.cost >= 1000000 + 4000 * 200, `charter costs ${i.cost}`);
|
||||
assert.match(i.fix, /^Charter /);
|
||||
const cash = ev('S.cash');
|
||||
ev("ACT.fixInc({id:'c1'})");
|
||||
assert.equal(cash - ev('S.cash'), i.cost);
|
||||
const now = J(ev, "S.inc[0]"), f = J(ev, "S.fleet[S.inc[0].ship]");
|
||||
assert.ok(now.ship && !['mend', 'tea'].includes(now.ship), `chartered ${now.ship}`);
|
||||
assert.equal(now.seaq, undefined);
|
||||
assert.equal(now.until, f.done);
|
||||
assert.ok(f.done < 260, 'back well within the next weeks');
|
||||
assert.equal(ev("S.inc[0].cost"), 0, 'nothing more to buy');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a waiting cut gets the first club ship home', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + `S.links=[${wave('med', 'bcn', 'mrs', 'medusa', 365)}];S.inc=[];`
|
||||
+ "S.fleet.mend={inc:null,link:'x',t:0.5,e:'a',dep:190,arr:195,done:200,back:202,fx:0,fy:0};S.fleet.tea={...S.fleet.mend,back:260};" + cut('c1', 'med', 0.5));
|
||||
assert.equal(ev("S.inc[0].seaq"), 1);
|
||||
ev('dayTick();dayTick()');
|
||||
assert.equal(ev("S.inc[0].ship"), 'mend');
|
||||
assert.equal(ev("S.inc[0].until"), ev("S.fleet.mend.done"));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a charter while a club ship is on its way turns that ship round', () => {
|
||||
const { ev, errors } = load();
|
||||
// Both Cornwall ships are out, so the club sends the next one, from Curaçao: a long way round by the cable routes.
|
||||
ev(start + `S.links=[${wave('atl', 'nyc', 'bde', 'apollo', 5564)}];S.inc=[];`
|
||||
+ "for(const id of ['knot','splice'])S.fleet[id]={inc:null,link:'x',t:0.5,e:'a',dep:190,arr:195,done:200,back:201,fx:0,fy:0};" + cut('c1', 'atl', 0.7));
|
||||
const first = ev("S.inc[0].ship");
|
||||
assert.ok(['reel', 'cguy'].includes(first), `another Atlantic Splice Society ship: ${first}`);
|
||||
// Next day a Cornwall ship is home: chartering it beats waiting for the long voyage.
|
||||
ev('S.day=201;shipDay()');
|
||||
const i = J(ev, "S.inc[0]");
|
||||
assert.ok(i.cost > 0, 'the Cornwall ship would be there sooner');
|
||||
ev("ACT.fixInc({id:'c1'})");
|
||||
assert.ok(['knot', 'splice'].includes(ev("S.inc[0].ship")));
|
||||
const f = J(ev, `S.fleet.${first}`);
|
||||
assert.equal(f.inc, null, 'the first ship has no job any more');
|
||||
assert.equal(f.rs, 201);
|
||||
assert.ok(f.back <= 202, 'it turns back after a day under way');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('repairs in slow-permit waters wait for the paperwork; deep water takes longer on site', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + `S.links=[${wave('in', 'bom', 'maa', 'bbg', 2315)},${wave('atl', 'nyc', 'bde', 'apollo', 5564)}];S.inc=[];`);
|
||||
for (let seed = 1; seed <= 24; seed++) {
|
||||
ev(`window.__reseed(${seed});S.fleet={};S.inc=[];(()=>{const l=S.links[${seed % 2}];S.inc.push({id:'c',type:'cut',ref:l.id,until:S.day+15,msg:'',cost:0,start:S.day});shipCut(S.inc[0],l);})()`);
|
||||
const i = J(ev, "S.inc[0]"), km = seed % 2 ? 5564 : 2315, shallow = Math.min(i.st, 1 - i.st) * km <= 300;
|
||||
if (seed % 2 === 0 && shallow) assert.ok(i.sp >= 21 && i.sp <= 42, `Indian waters: ${i.sp} days of permits`);
|
||||
else assert.equal(i.sp, 0, 'no permit in the open sea, nor off New York or Cornwall');
|
||||
if (shallow) assert.ok(i.sw >= 3 && i.sw <= 5); else assert.ok(i.sw >= 6 && i.sw <= 12);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('fireFailure on a subsea wave calls a ship; a cut on land does not', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + `S.links=[${wave('med', 'bcn', 'mrs', 'medusa', 365)}];S.inc=[];fireFailure('cut')`);
|
||||
const sea = J(ev, "S.inc.find(i=>i.type==='cut')");
|
||||
assert.ok(sea.ship || sea.seaq);
|
||||
assert.ok(sea.st > 0 && sea.st < 1);
|
||||
ev("S.links=[{id:'land',a:'fra',b:'ams',kind:'wave',tier:0,km:400,cut:0,mo:1000}];S.inc=[];S.fleet={};fireFailure('cut')");
|
||||
const land = J(ev, "S.inc.find(i=>i.type==='cut')");
|
||||
assert.equal(land.ship, undefined);
|
||||
assert.equal(land.cost, 4000);
|
||||
assert.deepEqual(J(ev, "Object.keys(S.fleet)"), []);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('ships and their jobs survive a save; broken or old saves are repaired', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + `S.links=[${wave('med', 'bcn', 'mrs', 'medusa', 365)}];S.inc=[];` + cut('c1', 'med', 0.9));
|
||||
const before = J(ev, "[S.inc[0],S.fleet]");
|
||||
ev('S=migrate(JSON.parse(JSON.stringify(S)))');
|
||||
assert.deepEqual(J(ev, "[S.inc[0],S.fleet]"), before);
|
||||
// Unknown ships, nonsense numbers and a job that points nowhere.
|
||||
ev("S.fleet.titanic={dep:1,arr:2,done:3,back:9e9};S.fleet[S.inc[0].ship].arr='soon';S.inc[0].st=7;S=migrate(JSON.parse(JSON.stringify(S)))");
|
||||
assert.equal(ev("S.fleet.titanic"), undefined);
|
||||
assert.ok(ev("Number.isFinite(S.fleet[S.inc[0].ship].arr)"));
|
||||
assert.equal(ev("S.inc[0].st"), 0.97);
|
||||
ev("S.inc[0].ship='titanic';S=migrate(JSON.parse(JSON.stringify(S)))");
|
||||
assert.equal(ev("S.inc[0].ship"), null);
|
||||
assert.equal(ev("S.inc[0].seaq"), 1, 'a cut that lost its ship waits for the next one');
|
||||
// A save from before cable ships: no fleet, and a cut with no ship keeps working as it did.
|
||||
ev("const o=JSON.parse(JSON.stringify(S));delete o.fleet;o.inc=[{id:'old',type:'cut',ref:'med',until:o.day+5,msg:'old cut',cost:4000}];S=migrate(o)");
|
||||
assert.deepEqual(J(ev, 'S.fleet'), {});
|
||||
assert.equal(ev("S.inc[0].ship"), undefined);
|
||||
assert.equal(ev("shipSea(S.inc[0])"), false);
|
||||
ev('dayTick()');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('ships are drawn where their voyage puts them, and tapping one says what it does', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev(start + `S.links=[${wave('med', 'bcn', 'mrs', 'medusa', 365)}];S.inc=[];` + cut('c1', 'med', 0.5));
|
||||
const id = ev("S.inc[0].ship");
|
||||
const home = J(ev, `shipHomePt(SHIP.${id})`), f = J(ev, `S.fleet.${id}`);
|
||||
assert.equal(J(ev, `shipAt(SHIP.${id},200.5)`).m, 'port', 'getting under way');
|
||||
const out = J(ev, `shipAt(SHIP.${id},${f.arr - 0.5})`);
|
||||
assert.equal(out.m, 'out');
|
||||
const work = J(ev, `shipAt(SHIP.${id},${f.arr + 1})`);
|
||||
assert.equal(work.m, 'work');
|
||||
assert.ok(Math.abs(work.x - f.fx) < 1 && Math.abs(work.y - f.fy) < 1, 'on the fault');
|
||||
const back = J(ev, `shipAt(SHIP.${id},${f.back + 1})`);
|
||||
assert.ok(Math.abs(back.x - home[0]) < 1e-6 && Math.abs(back.y - home[1]) < 1e-6, 'home again');
|
||||
// Drawn on the map, and found by a tap.
|
||||
ev(`const C=CITY.mrs;cam.x=C.x;cam.y=C.y;cam.z=3;UI.speed=1;draw(0)`);
|
||||
assert.ok(ev('SHIP_HITS.length') >= 2, 'the ship at work and its sister ship in port');
|
||||
const hit = J(ev, `SHIP_HITS.find(h=>h.it.s&&h.it.s.id==='${id}')`);
|
||||
ev(`(()=>{const r=cv.getBoundingClientRect();shipTap(shipHit(${hit.x}+r.left,${hit.y}+r.top))})()`);
|
||||
assert.match(dom.window.document.body.innerHTML, /Mediterranean Mending Club/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the link panel and the NOC say where the ship is, on a phone too', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev(start + `S.links=[${wave('med', 'bcn', 'mrs', 'medusa', 365)}];S.inc=[];` + cut('c1', 'med', 0.5));
|
||||
ev("window.innerWidth=360;UI.sel={type:'link',id:'med'};renderPanel()");
|
||||
const panel = dom.window.document.querySelector('#panelBody').textContent;
|
||||
assert.match(panel, /is sailing from Marseille/);
|
||||
assert.doesNotMatch(panel, /Back in \d+ days/);
|
||||
ev("UI.left='noc';UI.leftOpen=true;renderLeft()");
|
||||
assert.match(dom.window.document.querySelector('#leftBody').textContent, /is sailing from Marseille/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('your own subsea cable: survey and factory first, then a lay ship; a second one can be booked, crews cannot help', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev(start + "S.links=[{id:'own',a:'lag',b:'bde',kind:'df',own:true,sub:true,sys:'roadm',km:6000,ch:[],day:200,ready:800,cut:0,mo:1}];");
|
||||
assert.equal(ev('layDays(S.links[0])'), 40);
|
||||
assert.equal(ev('layStart(S.links[0])'), 760);
|
||||
assert.deepEqual(J(ev, 'layQuote(S.links[0])'), { save: 20, cost: 3000000 + 20 * 150000 });
|
||||
ev("UI.sel={type:'link',id:'own'};renderPanel()");
|
||||
const panel = () => dom.window.document.querySelector('#panelBody').textContent;
|
||||
assert.match(panel(), /Survey, permits and the cable factory/);
|
||||
assert.match(panel(), /Laying starts in 560 days/);
|
||||
assert.match(panel(), /Book a second lay ship/);
|
||||
assert.doesNotMatch(panel(), /Hire extra crews|Finish in 1 day/);
|
||||
const cash = ev('S.cash');
|
||||
ev("ACT.crews({id:'own'})");
|
||||
assert.equal(ev('S.cash'), cash, 'no crews at sea');
|
||||
ev("ACT.layShip({id:'own'})");
|
||||
assert.equal(cash - ev('S.cash'), 6000000);
|
||||
assert.equal(ev('S.links[0].ready'), 780);
|
||||
assert.equal(ev('layStart(S.links[0])'), 760, 'laying starts the same day, two ships finish sooner');
|
||||
assert.equal(ev('layQuote(S.links[0])'), null, 'one second ship is all');
|
||||
ev("ACT.layShip({id:'own'})");
|
||||
assert.equal(cash - ev('S.cash'), 6000000);
|
||||
// At sea: both ships on the map, from both ends.
|
||||
ev("S.day=770;UI.sel={type:'link',id:'own'};renderPanel();const C=CITY.lag;cam.x=C.x;cam.y=C.y;cam.z=0.5;UI.speed=0;draw(0)");
|
||||
assert.match(panel(), /at sea, laying/);
|
||||
assert.match(panel(), /3,000 of 6,000 km/);
|
||||
assert.equal(ev("SHIP_HITS.filter(h=>h.it.lay).length>=1"), true);
|
||||
// Too late to book once laying has started.
|
||||
ev("S.links[0].ship2=undefined;S.links[0].ready=800");
|
||||
assert.equal(ev('layQuote(S.links[0])'), null);
|
||||
ev('S=migrate(JSON.parse(JSON.stringify(S)))');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a second lay ship moves pending subsea upgrades with the finish', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + "S.links=[{id:'own',a:'lag',b:'bde',kind:'df',own:true,sub:true,sys:'roadm',km:15000,ch:[],day:200,ready:1000,cut:0,mo:1}];");
|
||||
ev("ACT.subUpgrade({id:'own',k:'terminal'});ACT.subUpgrade({id:'own',k:'engineering'})");
|
||||
const before = J(ev, '[S.links[0].ready,S.links[0].subterminal,S.links[0].subengineering]');
|
||||
ev("ACT.layShip({id:'own'})");
|
||||
const save = Math.floor(Math.ceil(15000 / 150) / 2);
|
||||
assert.deepEqual(J(ev, '[S.links[0].ready,S.links[0].subterminal,S.links[0].subengineering]'), before.map((d) => d - save));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the NOC intern’s rush-repair order pays a charter only within its budget', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;S.lvl=3;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.rules=makeRules('freeze');"
|
||||
+ "ACT.opsHire({id:'kevin'});S.ops.floor=0;closeModal();S.day=200;"
|
||||
+ `S.links=[${wave('med', 'bcn', 'mrs', 'medusa', 365)}];S.inc=[];`
|
||||
+ "for(const id of ['mend','tea'])S.fleet[id]={inc:null,link:'x',t:0.5,e:'a',dep:190,arr:195,done:205,back:230,fx:0,fy:0};" + cut('c1', 'med', 0.5));
|
||||
const cost = ev('S.inc[0].cost'), cash = ev('S.cash');
|
||||
ev("S.ops.on.repair=true;S.ops.p.repair={};S.ops.cap.repair=1e6;opsDay(S.day)");
|
||||
assert.equal(ev('S.inc[0].seaq'), 1, 'over budget: the cut keeps waiting');
|
||||
assert.equal(ev('S.cash'), cash);
|
||||
assert.ok(cost > 1e6 && cost < 5e6, `a charter from Cornwall: ${cost}`);
|
||||
ev('S.ops.cap.repair=5e6;opsDay(S.day)');
|
||||
assert.equal(cash - ev('S.cash'), cost);
|
||||
assert.ok(ev('S.inc[0].ship') && !ev('S.inc[0].seaq'));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -99,6 +99,8 @@ const REAL_NAMES = [
|
|||
'AMS-IX', 'Any2', 'BCIX', 'CoreSite', 'DE-CIX', 'Digital Realty', 'Equinix', 'France-IX', 'Interxion', 'IX.br', 'JPIX', 'LINX', 'NAPAfrica', 'NetIX', 'NIX', 'NL-ix', 'SIX', 'Telehouse',
|
||||
// cables
|
||||
'2Africa', 'Amitié', 'Dunant', 'EllaLink', 'Equiano', 'Grace Hopper', 'Hibernia Express', 'Jupiter', 'MAREA', 'PEACE', 'SEA-ME-WE 6',
|
||||
// cable ships, their operators and maintenance clubs
|
||||
'ACMA', 'ASEAN Explorer', 'ASEAN Protector', 'ASEAN Restorer', 'Cable Innovator', 'Cable Retriever', 'Global Marine', 'Léon Thévenin', 'MECMA', 'Orange Marine', 'Pierre de Fermat', 'René Descartes', 'SEAIOCMA', 'Sophie Germain', 'Sovereign', 'Wave Sentinel', 'Yokohama Zone',
|
||||
// vendors
|
||||
'Arista', 'Brocade', 'Ciena', 'Cisco', 'Extreme Networks', 'Huawei', 'Infinera', 'Juniper', 'MikroTik', 'Nokia',
|
||||
];
|
||||
|
|
@ -159,11 +161,11 @@ test('N1: network ids and ASNs are unique, ASNs are valid', () => {
|
|||
fail('N1', J("NETS.filter(n=>!Number.isInteger(n.asn)||n.asn<1||n.asn>4294967294||n.asn>=64512&&n.asn<=65534).map(n=>n.id)"), 'use the real, public ASN');
|
||||
});
|
||||
|
||||
test('N2: names are puns: no network, cable, exchange, data center, router or optic carries a real name', () => {
|
||||
test('N2: names are puns: no network, cable, exchange, data center, router, optic or cable ship carries a real name', () => {
|
||||
const norm = (s) => String(s).toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[’`]/g, "'").replace(/\s+/g, ' ').trim();
|
||||
const real = new Set(REAL_NAMES.map(norm));
|
||||
const names = J(`[...NETS.map(n=>['network',n.name]),...CABLES.map(c=>['cable',c.name]),...XIX.map(x=>['exchange',x.name]),
|
||||
...CITIES.flatMap(c=>[['exchange',c.ix],['data center',c.dc],['data center',c.dc2]]),...RG.map(r=>['router',r.n]),...Object.values(OPT).map(o=>['optic',o.n]),...Object.values(SEAT_ROUTES).flat().map(r=>['cable',r[2]])].filter(x=>x[1])`);
|
||||
...CITIES.flatMap(c=>[['exchange',c.ix],['data center',c.dc],['data center',c.dc2]]),...RG.map(r=>['router',r.n]),...Object.values(OPT).map(o=>['optic',o.n]),...Object.values(SEAT_ROUTES).flat().map(r=>['cable',r[2]]),...SHIPS.map(x=>['cable ship',x.n]),...LAY_SHIPS.map(n=>['cable ship',n]),...Object.values(SHIP_CLUBS).map(c=>['maintenance club',c.n])].filter(x=>x[1])`);
|
||||
fail('N2', names.filter(([, n]) => real.has(norm(n))).map(([k, n]) => `${k} “${n}” is a real name`), 'find a pun');
|
||||
fail('N2', names.filter(([, n]) => /-ish\b/i.test(n)).map(([k, n]) => `${k} “${n}”`), 'no lazy -ish names: find a real pun, or keep the plain word');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// Hurrying anything at sea takes a cable ship: a charter for a build, a place in the repair queue for a cut. Both cost
|
||||
// millions, while the same hurry on land stays cheap.
|
||||
const start = "ACT.start({});S.cash=1e9;S.lvl=13;S.day=200;for(const g of GOALS)S.done[g.id]=0;";
|
||||
|
||||
test('more crews on a subsea build means chartering a cable ship, for millions', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev(start + "S.links=[{id:'sea',a:'lag',b:'bde',kind:'df',own:true,sub:true,sys:'roadm',km:6000,ch:[],day:200,ready:800,cut:0,mo:1},"
|
||||
+ "{id:'land',a:'fra',b:'ams',kind:'df',own:true,sys:'roadm',km:400,ch:[],day:200,ready:500,cut:0,mo:1}]");
|
||||
assert.equal(ev("crewCost(S.links[0])"), 3000000 + 6000 * 500, 'mobilising a ship plus its time at sea');
|
||||
assert.ok(ev("crewCost(S.links[1])") < 50000, 'land crews stay cheap');
|
||||
const cash = ev('S.cash');
|
||||
ev("ACT.crews({id:'sea'})");
|
||||
assert.equal(cash - ev('S.cash'), 6000000);
|
||||
assert.equal(ev('S.links[0].ready'), 770);
|
||||
assert.match(dom.window.document.body.innerHTML, /Another cable ship joins the lay/);
|
||||
ev("UI.sel={type:'link',id:'sea'};renderPanel()");
|
||||
const panel = () => dom.window.document.querySelector('#panelBody').textContent;
|
||||
assert.match(panel(), /Charter another cable ship/);
|
||||
assert.match(panel(), /Only a few dozen cable ships exist/);
|
||||
assert.doesNotMatch(panel(), /Hire extra crews/);
|
||||
ev("UI.sel={type:'link',id:'land'};renderPanel()");
|
||||
assert.match(panel(), /Hire extra crews/);
|
||||
assert.doesNotMatch(panel(), /cable ship/);
|
||||
// The whole lay in one go is the charter times every 30 days left.
|
||||
ev("S.cash=1e9;UI.sel={type:'link',id:'sea'};renderPanel()");
|
||||
assert.equal(ev("crewSteps(S.links[0])*crewCost(S.links[0])"), 19 * 6000000);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a rush repair on a subsea cut, even on a leased wave, costs a cable ship, a trench cut stays cheap', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + "S.links=[{id:'sea',a:'lag',b:'bde',kind:'wave',sub:true,tier:0,km:6000,cut:0,mo:1000}];S.inc=[];fireFailure('cut')");
|
||||
const sea = JSON.parse(ev("JSON.stringify(S.inc.find(i=>i.type==='cut'))"));
|
||||
assert.equal(sea.cost, 1000000 + 6000 * 200);
|
||||
assert.equal(sea.fix, 'Jump the cable-ship queue');
|
||||
ev("S.links=[{id:'land',a:'fra',b:'ams',kind:'wave',tier:0,km:400,cut:0,mo:1000}];S.inc=[];fireFailure('cut')");
|
||||
const land = JSON.parse(ev("JSON.stringify(S.inc.find(i=>i.type==='cut'))"));
|
||||
assert.equal(land.cost, 4000);
|
||||
assert.equal(land.fix, undefined);
|
||||
// Paying it brings the cable back at once, like any rush repair.
|
||||
ev("S.links=[{id:'sea',a:'lag',b:'bde',kind:'wave',sub:true,tier:0,km:6000,cut:0,mo:1000}];S.inc=[];fireFailure('cut')");
|
||||
const id = ev("S.inc.find(i=>i.type==='cut').id"), cash = ev('S.cash');
|
||||
ev(`ACT.fixInc({id:'${id}'})`);
|
||||
assert.equal(cash - ev('S.cash'), 2200000);
|
||||
assert.equal(ev("linkDown(S.links[0])"), false);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the chaos monkey snipping a subsea cable prices the rush the same way', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start + "S.links=[{id:'sea',a:'lag',b:'bde',kind:'wave',sub:true,tier:0,km:3000,cut:0,mo:1000}];S.inc=[];"
|
||||
+ "S.monkey={n:0,hurt:0,until:S.day+100};mkSnip()");
|
||||
const i = JSON.parse(ev("JSON.stringify(S.inc.find(i=>i.type==='cut'))"));
|
||||
assert.equal(i.cost, 1000000 + 3000 * 200);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
@ -2,51 +2,50 @@ const test = require('node:test');
|
|||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
function setup(ev) {
|
||||
// A 15,000 km cable of your own: 100 days of laying at the end of the build, and a second lay ship saves 50.
|
||||
function setup(ev, sub = true) {
|
||||
ev(`ACT.start({});S.cash=1e11;S.lvl=13;S.day=100;for(const g of GOALS)S.done[g.id]=0;
|
||||
S.links=[{id:'cable',a:'lag',b:'bde',kind:'df',own:true,sub:true,sys:'roadm',km:15000,ch:[],day:100,ready:1000,cut:0,mo:1}];`);
|
||||
S.links=[{id:'cable',a:'lag',b:'bde',kind:'df',own:true,sub:${sub},sys:'roadm',km:15000,ch:[],day:100,ready:1000,cut:0,mo:1}];`);
|
||||
}
|
||||
|
||||
function dates(ev) {
|
||||
return JSON.parse(ev('JSON.stringify([S.links[0].ready,S.links[0].subterminal,S.links[0].subengineering])'));
|
||||
}
|
||||
|
||||
test('upgrades queued during construction follow crews and keep their 30/180-day commissioning time', () => {
|
||||
test('upgrades queued during construction follow a second lay ship and keep their 30/180-day commissioning time', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
try {
|
||||
setup(ev);
|
||||
ev("ACT.subUpgrade({id:'cable',k:'terminal'});ACT.subUpgrade({id:'cable',k:'engineering'})");
|
||||
assert.deepEqual(dates(ev), [1000, 1030, 1180]);
|
||||
const paid = ev('S.links[0].paid');
|
||||
ev("ACT.crews({id:'cable'})");
|
||||
assert.deepEqual(dates(ev), [970, 1000, 1150]);
|
||||
ev("for(let i=0;i<29;i++)ACT.crews({id:'cable'})");
|
||||
assert.deepEqual(dates(ev), [101, 131, 281], 'last crew purchase shifts dates by 29 days, not 30');
|
||||
ev("ACT.layShip({id:'cable'})");
|
||||
assert.deepEqual(dates(ev), [950, 980, 1130]);
|
||||
const cash = ev('S.cash');
|
||||
ev("ACT.crews({id:'cable'})");
|
||||
assert.equal(ev('S.cash'), cash, 'one day remaining: crews cannot charge for saving zero days');
|
||||
assert.deepEqual(dates(ev), [101, 131, 281], 'commissioning cannot be rushed further through the cable');
|
||||
ev("ACT.layShip({id:'cable'})");
|
||||
assert.equal(ev('S.cash'), cash, 'one second ship: a second booking charges nothing');
|
||||
assert.deepEqual(dates(ev), [950, 980, 1130], 'commissioning cannot be rushed further through the cable');
|
||||
ev("UI.sel={type:'link',id:'cable'};renderPanel()");
|
||||
assert.equal(dom.window.document.querySelector('#panelBody [data-act=crews]').disabled, true);
|
||||
assert.equal(dom.window.document.querySelector('#panelBody [data-act=layShip]'), null);
|
||||
assert.equal(ev('S.links[0].paid'), paid, 'no second upgrade charge');
|
||||
ev('S=migrate(JSON.parse(JSON.stringify(S)))');
|
||||
assert.deepEqual(dates(ev), [101, 131, 281], 'save round trip preserves commissioning windows');
|
||||
ev('S.day=130');assert.equal(ev("subUpgradeReady(S.links[0],'terminal')"), false);
|
||||
ev('S.day=131');assert.equal(ev("subUpgradeReady(S.links[0],'terminal')"), true);
|
||||
ev('S.day=280');assert.equal(ev("subUpgradeReady(S.links[0],'engineering')"), false);
|
||||
ev('S.day=281');assert.equal(ev("subUpgradeReady(S.links[0],'engineering')"), true);
|
||||
assert.deepEqual(dates(ev), [950, 980, 1130], 'save round trip preserves commissioning windows');
|
||||
ev('S.day=979');assert.equal(ev("subUpgradeReady(S.links[0],'terminal')"), false);
|
||||
ev('S.day=980');assert.equal(ev("subUpgradeReady(S.links[0],'terminal')"), true);
|
||||
ev('S.day=1129');assert.equal(ev("subUpgradeReady(S.links[0],'engineering')"), false);
|
||||
ev('S.day=1130');assert.equal(ev("subUpgradeReady(S.links[0],'engineering')"), true);
|
||||
assert.deepEqual(errors, []);
|
||||
} finally { dom.window.close(); }
|
||||
});
|
||||
|
||||
test('ordering upgrades early is as fast as ordering after rushing the cable', () => {
|
||||
test('ordering upgrades early is as fast as ordering after booking the second lay ship', () => {
|
||||
const { ev, dom } = load();
|
||||
try {
|
||||
setup(ev);
|
||||
ev("ACT.subUpgrade({id:'cable',k:'terminal'});ACT.subUpgrade({id:'cable',k:'engineering'});for(let i=0;i<30;i++)ACT.crews({id:'cable'})");
|
||||
ev("ACT.subUpgrade({id:'cable',k:'terminal'});ACT.subUpgrade({id:'cable',k:'engineering'});ACT.layShip({id:'cable'})");
|
||||
const early = dates(ev);
|
||||
setup(ev);
|
||||
ev("for(let i=0;i<30;i++)ACT.crews({id:'cable'});S.day=101;ACT.subUpgrade({id:'cable',k:'terminal'});ACT.subUpgrade({id:'cable',k:'engineering'})");
|
||||
ev("ACT.layShip({id:'cable'});S.day=101;ACT.subUpgrade({id:'cable',k:'terminal'});ACT.subUpgrade({id:'cable',k:'engineering'})");
|
||||
assert.deepEqual(dates(ev), early);
|
||||
} finally { dom.window.close(); }
|
||||
});
|
||||
|
|
@ -58,7 +57,9 @@ test('packages included in the original order stay aligned with its accelerated
|
|||
ev("S.won=true;UI.pending={a:'sin',b:'lax'};UI.seaterminal=UI.seaengineering=true;ACT.orderCable();S.links=[S.links.at(-1)]");
|
||||
assert.equal(ev('S.links[0].subterminal'), ev('S.links[0].ready'));
|
||||
assert.equal(ev('S.links[0].subengineering'), ev('S.links[0].ready'));
|
||||
ev("ACT.crews({id:S.links[0].id})");
|
||||
const ready = ev('S.links[0].ready');
|
||||
ev("ACT.layShip({id:S.links[0].id})");
|
||||
assert.ok(ev('S.links[0].ready') < ready, 'the second lay ship finishes sooner');
|
||||
assert.equal(ev('S.links[0].subterminal'), ev('S.links[0].ready'));
|
||||
assert.equal(ev('S.links[0].subengineering'), ev('S.links[0].ready'));
|
||||
ev('S=migrate(JSON.parse(JSON.stringify(S)))');
|
||||
|
|
@ -103,11 +104,11 @@ test('old saves repair excessive pending waits without changing valid dates, cha
|
|||
} finally { dom.window.close(); }
|
||||
});
|
||||
|
||||
test('land fiber, leased cables, invalid upgrades and rejected crew purchases remain unaffected', () => {
|
||||
test('land fiber, leased cables, invalid upgrades and rejected lay ship bookings remain unaffected', () => {
|
||||
const { ev, dom } = load();
|
||||
try {
|
||||
setup(ev);
|
||||
ev("S.links[0].subterminal=1030;S.links[0].subengineering=1180;S.cash=0;ACT.crews({id:'cable'})");
|
||||
ev("S.links[0].subterminal=1030;S.links[0].subengineering=1180;S.cash=0;ACT.layShip({id:'cable'})");
|
||||
assert.deepEqual(dates(ev), [1000, 1030, 1180]);
|
||||
ev(`S.links.push({...S.links[0],id:'land',sub:false},{...S.links[0],id:'leased',own:false});
|
||||
setCableReady(S.links[1],970);setCableReady(S.links[2],970);`);
|
||||
|
|
@ -121,27 +122,32 @@ test('land fiber, leased cables, invalid upgrades and rejected crew purchases re
|
|||
} finally { dom.window.close(); }
|
||||
});
|
||||
|
||||
test('one-click completion costs the same as repeated crew hires and advances pending upgrades identically', () => {
|
||||
test('one-click completion on land costs the same as repeated crew hires', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
try {
|
||||
setup(ev);
|
||||
ev("ACT.subUpgrade({id:'cable',k:'terminal'});ACT.subUpgrade({id:'cable',k:'engineering'});UI.sel={type:'link',id:'cable'};renderPanel()");
|
||||
setup(ev, false);
|
||||
ev("UI.sel={type:'link',id:'cable'};renderPanel()");
|
||||
const button = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')].find(b => JSON.parse(b.dataset.args).all);
|
||||
assert.ok(button && !button.disabled, 'one-click option is available');
|
||||
const cash = ev('S.cash');
|
||||
assert.ok(button.textContent.includes(ev('fmt$(30*Math.round(3000000+15000*500))')), 'full price is shown before purchase');
|
||||
assert.ok(button.textContent.includes(ev('fmt$(30*Math.round(15000+15000*6))')), 'full price is shown before purchase');
|
||||
button.click();
|
||||
const bulkDates = dates(ev), bulkCash = ev('S.cash');
|
||||
assert.deepEqual(bulkDates, [101, 131, 281]);
|
||||
assert.equal(cash - bulkCash, 30 * 10500000);
|
||||
const bulkReady = ev('S.links[0].ready'), bulkCash = ev('S.cash');
|
||||
assert.equal(bulkReady, 101);
|
||||
assert.equal(cash - bulkCash, 30 * 105000);
|
||||
const after = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')];
|
||||
assert.ok(after.every(b => b.disabled), 'both options stop at one day');
|
||||
ev("ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(ev('S.cash'), bulkCash, 'repeat submission cannot charge again');
|
||||
setup(ev);
|
||||
ev("ACT.subUpgrade({id:'cable',k:'terminal'});ACT.subUpgrade({id:'cable',k:'engineering'});for(let i=0;i<30;i++)ACT.crews({id:'cable'})");
|
||||
assert.deepEqual(dates(ev), bulkDates);
|
||||
setup(ev, false);
|
||||
ev("for(let i=0;i<30;i++)ACT.crews({id:'cable'})");
|
||||
assert.equal(ev('S.links[0].ready'), bulkReady);
|
||||
assert.equal(ev('S.cash'), bulkCash);
|
||||
// At sea crews cannot help: no crew buttons, and the action does nothing.
|
||||
setup(ev);
|
||||
ev("UI.sel={type:'link',id:'cable'};renderPanel();ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(dom.window.document.querySelector('#panelBody [data-act=crews]'), null);
|
||||
assert.equal(ev('S.links[0].ready'), 1000);
|
||||
assert.deepEqual(errors, []);
|
||||
} finally { dom.window.close(); }
|
||||
});
|
||||
|
|
@ -149,19 +155,19 @@ test('one-click completion costs the same as repeated crew hires and advances pe
|
|||
test('one-click completion is atomic when unaffordable and handles short or completed construction', () => {
|
||||
const { ev, dom } = load();
|
||||
try {
|
||||
setup(ev);
|
||||
ev("S.cash=30*10500000-1;UI.sel={type:'link',id:'cable'};renderPanel()");
|
||||
setup(ev, false);
|
||||
ev("S.cash=30*105000-1;UI.sel={type:'link',id:'cable'};renderPanel()");
|
||||
const bulk = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')].find(b => JSON.parse(b.dataset.args).all);
|
||||
assert.equal(bulk.disabled, true);
|
||||
ev("ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(ev('S.cash'), 30 * 10500000 - 1);
|
||||
assert.equal(ev('S.cash'), 30 * 105000 - 1);
|
||||
assert.equal(ev('S.links[0].ready'), 1000, 'no partial purchase');
|
||||
ev("S.cash=10500000;S.links[0].ready=102;ACT.crews({id:'cable',all:1})");
|
||||
ev("S.cash=105000;S.links[0].ready=102;ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(ev('S.cash'), 0);
|
||||
assert.equal(ev('S.links[0].ready'), 101, 'two days remaining costs one normal hire');
|
||||
assert.match(dom.window.document.body.textContent, /The cable is 1 day ahead\./);
|
||||
ev("S.cash=10500000;S.day=101;ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(ev('S.cash'), 10500000, 'completed construction cannot be rushed');
|
||||
assert.match(dom.window.document.body.textContent, /Construction is 1 day ahead\./);
|
||||
ev("S.cash=105000;S.day=101;ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(ev('S.cash'), 105000, 'completed construction cannot be rushed');
|
||||
ev("S.day=100;S.links[0].ready=1000;S.links[0].own=false;ACT.crews({id:'cable',all:1})");
|
||||
assert.equal(ev('S.links[0].ready'), 1000, 'leased handovers cannot buy construction crews');
|
||||
} finally { dom.window.close(); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue