From 66aaaec5f1cca7e2efd834b1d3d89ef7193ec704 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Sun, 1 Nov 2026 11:52:42 +0000 Subject: [PATCH] A waiting subsea cut offers a charter only when it beats waiting for the club's first ship home --- src/game/85-incidents/50-cable-ships.js | 6 ++++-- tests/cable-ships.test.js | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/game/85-incidents/50-cable-ships.js b/src/game/85-incidents/50-cable-ships.js index 0ff088c..a09e9e5 100644 --- a/src/game/85-incidents/50-cable-ships.js +++ b/src/game/85-incidents/50-cable-ships.js @@ -38,8 +38,10 @@ function shipUntil(i,u){i.until=u;for(const l of S.links)if((l.trench||l.id)===i function shipSend(i,l,P,D){const g=linkGeom(l),pt=polyAt(g.pts,g.cum,i.st); S.fleet[P.s.id]={inc:i.id,link:l.id,t:i.st,e:shipEnd(P.s,l,D),dep:P.dep,arr:P.arr,done:P.done,back:P.back,fx:pt[0],fy:pt[1]}; i.ship=P.s.id;delete i.seaq;shipUntil(i,P.done);} -// The quickest free ship from anywhere, if it would finish sooner than the plan: what a private charter offers. -function shipQuote(i,l,D){D=D||shipFrom(i,l);let best=null;const cur=i.ship!=null&&S.fleet[i.ship]?S.fleet[i.ship].done:Infinity; +// A cut waiting for its club: when the first of the club's ships home again would have it mended. +function shipWait(i,l,D){const z=shipZone(D);let best=Infinity;for(const s of SHIPS)if(s.club===z){const f=S.fleet[s.id];best=Math.min(best,shipPlan(s,i,l,D).done+(f?Math.max(0,f.back-S.day):0));}return best;} +// The quickest free ship from anywhere, if it would finish sooner than the plan (or than waiting): what a private charter offers. +function shipQuote(i,l,D){D=D||shipFrom(i,l);let best=null;const cur=i.ship!=null&&S.fleet[i.ship]?S.fleet[i.ship].done:i.seaq?shipWait(i,l,D):Infinity; for(const s of SHIPS)if(shipFree(s)){const P=shipPlan(s,i,l,D);if(!best||P.done { 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); + assert.equal(ev("S.inc[0].cost"), 0, 'no charter on offer: waiting two days for the club ship is quicker than a ship from Cornwall'); ev('dayTick();dayTick()'); assert.equal(ev("S.inc[0].ship"), 'mend'); assert.equal(ev("S.inc[0].until"), ev("S.fleet.mend.done"));