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:
Frederic Jung 2026-11-01 11:24:37 +00:00
parent 1fa5566d66
commit 96e2c2f537
No known key found for this signature in database
28 changed files with 606 additions and 138 deletions

View file

@ -20,11 +20,8 @@ function setCableReady(l,ready,day=S.day){const shift=ready-l.ready;
const f='sub'+k;if(Number.isFinite(l[f])&&l[f]>day)l[f]=Math.max(day+1,l[f]+shift);
}l.ready=ready;
}
// Hurrying anything at sea means a cable ship, and there are only a few dozen in the world, booked months ahead:
// a second one for your build is a multi-million charter, and jumping the repair queue costs about what a repair does.
const SHIP_MOB=3000000,SHIP_KM=500,SHIP_FIX=1000000,SHIP_FIX_KM=200;
const crewCost=l=>Math.round(l.sub?SHIP_MOB+l.km*SHIP_KM:15000+l.km*6);
const shipFix=km=>Math.round(SHIP_FIX+km*SHIP_FIX_KM);
// Crews hurry a build on land. At sea only a cable ship does (85-incidents/50-cable-ships.js).
const crewCost=l=>Math.round(15000+l.km*6);
const crewSteps=l=>Math.max(0,Math.ceil((l.ready-S.day-1)/30));
// Old saves lack purchase dates. Only shorten dates beyond any valid remaining
// commissioning window. Credit elapsed time since the actual cable finish;

View file

@ -0,0 +1,35 @@
/* ---------- cable ships ----------
About sixty ships in the world can lay or repair a subsea cable, and only a few dozen do mostly repairs. Cable owners
pay a yearly fee per km to a regional maintenance club, which keeps ships on standby in fixed ports, ready to sail
within a day. When every club ship is out, the next cut waits. A private charter jumps the queue, for millions.
The game keeps one or two ships at the real clubs' bases (Cornwall, Curaçao, Cape Town, the French Riviera,
Vancouver Island, Yokohama, Subic Bay, Singapore) and two private operators. Names are puns, as everywhere. */
const SHIP_CLUBS={atl:{n:'Atlantic Splice Society'},med:{n:'Mediterranean Mending Club'},naz:{n:'North Pacific Patch Pact'},prv:{n:''},sea:{n:'SEA-IO Fix-It Club'},yok:{n:'Knot-a-hama Zone'}};
const SHIPS=[
{id:'buoy',n:'Buoy Oh Buoy',club:'naz',home:'van'},
{id:'cguy',n:'Cable Guy',club:'atl',home:'cpt'},
{id:'grap',n:'Grapnel Grandma',club:'sea',home:'mnl'},
{id:'hook',n:'Hook, Line & Splicer',club:'sea',home:'sin'},
{id:'joint',n:'Jointly Liable',club:'sea',home:'sin'},
{id:'junk',n:'Junk Bond',club:'prv',home:'sha'},
{id:'knot',n:'Knot Again',club:'atl',home:'bde'},
{id:'loose',n:'Loose Ends',club:'yok',home:'tok'},
{id:'mend',n:'Mend & Tonic',club:'med',home:'mrs'},
{id:'reel',n:'Reel Deal',club:'atl',home:'cur'},
{id:'saw',n:'Sea-Saw',club:'prv',home:'fuj'},
{id:'splice',n:'Splice Girl',club:'atl',home:'bde'},
{id:'spool',n:'Spool of Thought',club:'yok',home:'tok'},
{id:'tea',n:'Spliced Tea',club:'med',home:'mrs'},
];
const SHIP=Object.fromEntries(SHIPS.map(s=>[s.id,s]));
// The installation fleet lays new cables: your own cable gets one of these, and a second one can be booked.
const LAY_SHIPS=['Lay-Z Susan','Long Haul Lass','Reel Estate','Spoolhardy'];
/* Real numbers, rounded: a cable ship cruises at 10 to 12 knots (about 500 km a day) and leaves within a day of the
call; a repair takes 3 to 5 days on site in shallow water and a week or two in deep water; most faults (anchors and
fishing gear) are in shallow water near the shore; some countries take weeks to grant a repair permit in their
waters. A repair costs $0.5M to $1M; jumping the queue with a private charter costs more. A lay ship lays a
transoceanic cable at roughly 150 km a day. */
const SHIP_KMD=500,SHIP_MOB_D=1,SHIP_SHALLOW=300,LAY_KMD=150;
const SHIP_FIX=1000000,SHIP_FIX_KM=200,SHIP_MOB=3000000,LAY_DAY=150000;
// Days to get a repair permit in a country's waters, [fewest, most]; anywhere else the ship just goes.
const SHIP_PERMIT={CN:[14,28],EG:[7,21],ID:[21,42],IN:[21,42],VN:[14,28]};

View file

@ -1,6 +1,6 @@
function newGame(name,home){
S={v:1,name,asn:200000+Math.floor(_rand()*15000),home,day:0,cash:START_CASH,
ltv:2,t1v:3,auV:1,ops:opsNew(),achP:{},seen:NETS.map(n=>n.id),spares:{},pops:{[home]:{day:0,bb:null,boost:0,down:0,routers:1,gen:false}},links:[],nni:[],transit:[],ixp:{},rs:{},peers:{},pni:[],caches:[],biz:[],offers:[],myIx:{},pairMet:{},
done:{},inc:[],ev:{ddosMore:[]},ddosStarts:[],priceMul:1,nextFail:45,nextEvent:40,usedNames:[],stats:{survived:0,incidents:0,peak:0},cnLic:{state:'none'},scrubs:[],scrubMode:'always',ddosAuto:{rtbh:false,scrub:true},capDeal:null,core:{lv:0,run:0},popStd:null,won:false,lost:false,neg:0,loans:[],loanOffers:[],loanStrikes:0,ppol:'open',pdesk:null,pdeskRep:null,hw:{},rules:makeRules('oncall'),charter:'global',chartSet:false,demo:{},seatOff:null,solWon:0,monkey:{next:null,on:0}};
done:{},inc:[],fleet:{},ev:{ddosMore:[]},ddosStarts:[],priceMul:1,nextFail:45,nextEvent:40,usedNames:[],stats:{survived:0,incidents:0,peak:0},cnLic:{state:'none'},scrubs:[],scrubMode:'always',ddosAuto:{rtbh:false,scrub:true},capDeal:null,core:{lv:0,run:0},popStd:null,won:false,lost:false,neg:0,loans:[],loanOffers:[],loanStrikes:0,ppol:'open',pdesk:null,pdeskRep:null,hw:{},rules:makeRules('oncall'),charter:'global',chartSet:false,demo:{},seatOff:null,solWon:0,monkey:{next:null,on:0}};
}

View file

@ -62,6 +62,16 @@ function sanitize(s){
{const c=s.core&&typeof s.core==='object'?s.core:null,lv=c?int(c.lv,0,4,0):(s.te?2:0);s.core={lv,run:c?int(c.run,0,lv,lv):lv};if(c?c.legacy===true:!!s.te)s.core.legacy=true;if(c&&c.lab===true)s.core.lab=true;if(c&&c.since!==undefined)s.core.since=num(c.since,0);}
s.capDeal=s.capDeal&&typeof s.capDeal==='object'&&own(CAP_ROUTES,s.capDeal.c)?{at:num(s.capDeal.at,0),c:s.capDeal.c}:null;
s.inc=s.inc.filter(i=>i&&typeof i.type==='string').map(i=>(i.type==='maxpfx'&&(i.type='ixloop'),i.id=sid(i.id),i.until=num(i.until,s.day),i.cost=num(i.cost,0),i.msg=String(i.msg||'').slice(0,400),i.fix=i.fix==null?undefined:String(i.fix).slice(0,60),i));
// Cable ships (85-incidents/50-cable-ships.js): voyages of known ships, and what a subsea cut knows about its ship.
{const F=s.fleet&&typeof s.fleet==='object'&&!Array.isArray(s.fleet)?s.fleet:{},o={};
for(const id of Object.keys(F)){const f=F[id];if(!own(SHIP,id)||!f||typeof f!=='object')continue;const n=k=>num(f[k],s.day);
const v={inc:typeof f.inc==='string'?f.inc.slice(0,40):null,link:typeof f.link==='string'?f.link.slice(0,40):'',t:clamp(num(f.t,0.5),0,1),e:f.e==='b'?'b':'a',dep:n('dep'),arr:n('arr'),done:n('done'),back:n('back'),fx:num(f.fx,0),fy:num(f.fy,0)};
if(f.rs!=null){v.rs=n('rs');v.rt=clamp(num(f.rt,0),0,1);}v.arr=Math.max(v.arr,v.dep);v.done=Math.max(v.done,v.arr);v.back=Math.max(v.back,v.done);if(v.back>s.day)o[id]=v;}
s.fleet=o;
for(const i of s.inc){if(i.type!=='cut'||i.st==null){for(const k of ['ship','seaq','st','sw','sp','sl'])delete i[k];continue;}
i.st=clamp(num(i.st,0.5),0.03,0.97);i.sw=int(i.sw,1,30,4);i.sp=int(i.sp,0,60,0);i.sl=typeof i.sl==='string'?i.sl.slice(0,40):'';i.rushed=!!i.rushed||undefined;
if(i.ship!=null&&!(own(SHIP,i.ship)&&o[i.ship]&&o[i.ship].inc===i.id))i.ship=null;if(i.ship==null){i.ship=null;i.seaq=1;}else delete i.seaq;}
for(const l of s.links)if(l.ship2&&l.kind==='df'&&l.own&&l.sub)l.ship2=1;else delete l.ship2;}
s.loans=s.loans.filter(l=>l&&own(BANKS,l.bank));for(const l of s.loans){if(l.model!==undefined&&!['balloon','storm','transit','astro'].includes(l.model))delete l.model;for(const k of ['apr0','cut','share'])if(l[k]!==undefined&&!isFinite(+l[k]))delete l[k];if(!Array.isArray(l.covs))l.covs=[];l.covs=l.covs.filter(c=>own(COVS,c));}s.loanOffers=s.loanOffers.filter(l=>l&&own(BANKS,l.bank));
s.usedNames=[...new Set(s.usedNames.filter(x=>typeof x==='string'))];s.log=s.log.filter(e=>e&&typeof e.t==='string').slice(0,LOG_KEEP).map(e=>{const o=e.o&&typeof e.o==='object'&&e.o.a==='inbox'?{a:'tab',v:'nets'}:e&&e.o&&typeof e.o==='object'&&LOG_OPEN.includes(e.o.a)?(e.o.a==='bank'||e.o.a==='ops'?{a:e.o.a}:typeof e.o.v==='string'&&e.o.v.length<=64&&(e.o.a!=='city'||isCity(e.o.v))&&(e.o.a!=='tab'||LOG_TABS.includes(e.o.v))?{a:e.o.a,v:e.o.v}:null):null;
return {id:typeof e.id==='string'&&e.id.length<=40?e.id:uid(),d:num(e.d,0),t:e.t.slice(0,600),h:typeof e.h==='string'?e.h.slice(0,200):'',k:LOG_KINDS.includes(e.k)?e.k:'',at:Number.isFinite(+e.at)?+e.at:0,o,n:int(e.n,1,9999,1)};});

View file

@ -84,7 +84,9 @@ function fireFailure(only){
const pool=only&&scnRule('anchors')?live.filter(anchorProne):live;if(!pool.length)return;const l=pick(pool.flatMap(x=>{const w=(x.cable&&CAB[x.cable].age==='old'?3:1)*(x.cable&&CAB[x.cable].fragile?3:1)*(tw(x)?4*(scnRule('anchors')?3:1):1)*(scnRule('sharks')&&x.sub?2:1)*(vn(x)?3:1)*(!x.sub&&andesPair(x.a,x.b)?4:1)*(monsoon&&inl(x)?3:1)*(x.sub&&(x.a==='oos'||x.b==='oos')?3:1);return Array(w).fill(x);})),dur=10+Math.floor(Math.random()*8),trc=l.trench||l.id,hit=S.links.filter(x=>(x.trench||x.id)===trc);hit.forEach(x=>x.cut=Math.max(x.cut||0,S.day+dur));
const A=CITY[l.a].name,B=CITY[l.b].name,au=CITY[l.a].au&&CITY[l.b].au,auSummer=mon>=11||mon<=1;
const en=l.sub&&(CITY[l.a].au||CITY[l.b].au)&&!(l.cable&&CAB[l.cable].fragile)&&Math.random()<0.35?pick([N_('failures.box_jellyfish_season_at_the_a'),N_('failures.a_great_white_took_an_interest')]):l.cable&&CAB[l.cable].fragile&&Math.random()<0.8?pick([N_('failures.your_a_b_cable_is_cut'),N_('failures.a_b_is_down_same_cable')]):!l.sub&&CITY[l.a].land==='nzs'&&CITY[l.b].land==='nzs'&&Math.random()<0.75?pick([N_('failures.a_kea_pulled_the_rubber_seals'),N_('failures.the_sandflies_drove_your_splicing'),N_('failures.a_farmer_s_post_hole_digger')]):l.cable==='cook'&&Math.random()<0.6?N_('failures.a_ferry_dropped_anchor_in_cook'):!l.sub&&au&&Math.random()<0.75?pick([N_('failures.a_sulphur_crested_cockatoo_chewed'),N_('failures.a_kangaroo_hit_the_fiber_hut'),N_('failures.thieves_dug_up_your_a_b'),N_('failures.a_kilometre_of_copper_went_missing'),N_('failures.a_backhoe_putting_in_a_new'),N_('failures.the_emus_won_again_a_mob'),N_('failures.a_kangaroo_boxed_your_field_tech'),N_('failures.a_drop_bear_fell_on_the'),N_('failures.an_eastern_brown_snake_moved_into'),...((S.day%365)/30.42>=8&&(S.day%365)/30.42<11?[N_('failures.magpie_swooping_season_the_field')]:[]),...(auSummer?[N_('failures.bushfire_season_the_fiber_along_a')]:[]),...(nullPair(l.a,l.b)?[N_('failures.your_a_b_fiber_broke_somewhere')]:[])]):l.sub&&(l.a==='bda'||l.b==='bda')&&Math.random()<0.7?pick([N_('failures.your_a_b_cable_went_quiet'),N_('failures.the_repair_ship_s_compass_spun')]):l.sub&&(l.a==='tbu'||l.b==='tbu')&&Math.random()<0.7?pick([N_('failures.an_undersea_volcano_erupted_next_to'),N_('failures.the_seabed_off_tonga_slid_down')]):vn(l)&&Math.random()<0.8?pick([N_('failures.another_of_vietnam_s_subsea_cables'),N_('failures.your_a_b_cable_broke_in')]):!l.sub&&(l.a==='drw'||l.b==='drw')&&Math.random()<0.7?pick([N_('failures.a_crocodile_took_a_bite_out'),N_('failures.termites_ate_the_duct_on_a')]):tw(l)&&Math.random()<0.8?pick([N_('failures.a_cargo_ship_forgot_to_raise'),N_('failures.another_anchor_another_cut_your_a'),N_('failures.a_fishing_boat_with_an_unusually')]):l.sub&&(l.a==='oos'||l.b==='oos')&&Math.random()<0.8?pick([N_('failures.a_trawler_off_ostend_dragged_its'),N_('failures.a_wind_farm_service_vessel_dropped')]):!l.sub&&(CITY[l.a].ca||CITY[l.b].ca)&&Math.random()<0.4?pick([N_('failures.a_beaver_chewed_through_your_a'),N_('failures.your_a_b_fiber_is_down'),N_('failures.frost_heave_cracked_the_duct_on')]):!l.sub&&andesPair(l.a,l.b)?pick([N_('failures.a_landslide_in_the_andes_buried'),N_('failures.snow_closed_the_mountain_pass_and'),N_('failures.an_earthquake_shook_your_a_b'),N_('failures.a_llama_herd_trampled_the_fiber')]):!l.sub&&(CITY[l.a].india||CITY[l.b].india)?pick([N_('failures.road_widening_near_a_cut_your'),N_('failures.the_monsoon_flooded_a_manhole_on'),N_('failures.a_digger_found_your_a_b')]):l.sub?pick([N_('failures.a_curious_shark_bit_your_subsea'),N_('failures.a_ship_dragged_its_anchor_across'),N_('failures.an_undersea_landslide_snapped_a_b')]):pick([N_('failures.a_backhoe_found_your_fiber_between'),N_('failures.squirrels_chewed_through_a_b_they'),N_('failures.road_works_cut_a_b_nobody')]);
addInc({type,ref:trc,until:S.day+dur,msg:tr(en,{a:A,b:B})+(hit.length>1?' '+tr('failures.all_n_links_in_that_trench',{n:hit.length}):''),...cutFix(l,hit)},en);
addInc({type,ref:trc,until:S.day+dur,msg:tr(en,{a:A,b:B})+(hit.length>1?' '+tr('failures.all_n_links_in_that_trench',{n:hit.length}):''),cost:Math.max(4000,Math.round(hit.reduce((a,x)=>a+x.mo,0)*0.5))},en);
// At sea a cable ship sails out to it (50-cable-ships.js): it sets how long the cut lasts and what a charter costs.
if(l.sub&&!pzOn())shipCut(S.inc[S.inc.length-1],l);
}else if(type==='crash'||type==='power'){
const c=pick(Object.keys(S.pops).flatMap(x=>type==='power'&&(CITY[x].za||CITY[x].blackout)?[x,x,x]:type==='crash'&&RG[S.pops[x].rgen||0].flaky?[x,x,x]:[x])),pp=S.pops[c],slow=slowBoot(c),dur=(type==='crash'?2+Math.floor(Math.random()*2):3+Math.floor(Math.random()*3))*(type==='crash'&&S.ev.sanction>S.day?2:1)+(slow?2+Math.floor(Math.random()*3):0);
if(type==='crash'&&(pp.routers||1)>=2){pp.rdown=S.day+dur;S.stats.incidents++;S.stats.survived++;toast(tr('failures.router_crash_in_city_one_router',{city:CITY[c].name,slow:slow?' '+tr('failures.the_crashed_one_what',{what:esc(pick(SLOW_BOOT))}):'',d:dur}),'good');sfx('alert');return;}
@ -119,8 +121,6 @@ const gamingCount=()=>S.biz.reduce((n,b)=>n+(BIZ_T[b.type]?.gaming?1:0),0);
const FLOOD_WHO=[N_('failures.a_botnet_of_40_000_smart'),N_('failures.every_unpatched_baby_monitor_in'),N_('failures.a_gaming_clan_that_lost_one'),N_('failures.a_fridge_that_achieved_sentience_and'),N_('failures.a_crypto_bro_shorting_your_stock'),N_('failures.a_teenager_with_a_stolen_credit'),N_('failures.a_rival_isp_s_stress_test'),N_('failures.ten_thousand_smart_light_bulbs'),N_('failures.a_printer_just_one_printer_nobody'),N_('failures.a_botnet_run_from_a_cloud'),N_('failures.somebody_who_did_not_like_your'),N_('failures.the_internet_connected_kettles_of_a')];
function incTitle(t){return {ring:tr('failures.metro_ring_cut'),site:tr('common.site_outage'),cut:tr('common.fiber_cut'),crash:tr('common.router_crash'),power:tr('common.power_outage'),transit:tr('common.upstream_outage'),ixloop:tr('common.ix_meltdown'),leak:tr('common.route_leak'),ddos:tr('common.ddos_attack'),fabric:tr('common.fabric_outage'),depeer:tr('common.peering_spat'),fatwave:tr('failures.fat_fingered_wave'),label:tr('failures.patch_panel_mishap'),interop:tr('core.interop_failure'),mtu:tr('common.mtu_mismatch'),krroute:tr('failures.rerouted_via_hong_kong'),ctrlplane:tr('failures.control_plane_meltdown'),lacp:tr('common.lacp_trouble'),loss:tr('common.packet_loss'),pmtud:tr('failures.pmtud_black_hole'),oops:tr('common.oops'),cleaner:tr('common.vacuum_incident'),prepend:tr('common.prepend_ageddon'),rpki:tr('common.rpki_invalid'),amp:tr('common.amplifier_failure'),roadmff:tr('failures.fat_fingered_roadm'),optic:tr('common.dead_optic'),maint:tr('common.maintenance_window_3a92'),ac:tr('common.cooling_failure'),hijack:tr('common.bgp_hijack'),shutdown:tr('common.government_shutdown'),redsea:tr('failures.geopolitical_cable_cut')}[t]||tr('common.incident');}
const LINKCUT_TR=['cut','redsea'],LINKCUT_ID=['fatwave','label','interop'],POPDOWN=['crash','power','oops','cleaner','maint','shutdown'],IXDOWN=['ixloop'],TDOWN=['transit','prepend'],LINKEQ=['mtu','amp','roadmff','optic'];
// A rush repair: crews for a trench, a cable ship for the sea (shipFix, 60-reach-and-subsea.js).
const cutFix=(l,hit)=>{const c=Math.max(4000,Math.round(hit.reduce((a,x)=>a+x.mo,0)*0.5));return l.sub?{cost:Math.max(c,shipFix(l.km)),fix:tr('failures.jump_the_cable_ship_queue')}:{cost:c};};
function remainUntil(pred){let u=0;for(const x of S.inc)if(pred(x))u=Math.max(u,x.until);return u;}
// Remove an incident, then restore each affected thing to whatever other incidents still hold it down.
function clearInc(i){

View file

@ -35,7 +35,7 @@ function mkSnip(){const M=S.monkey,live=S.links.filter(l=>l.kind!=='vxc'&&!linkD
const smp=live.length>40?Array.from({length:40},()=>pick(live)):live,l=pick(smp.flatMap(x=>mkWeak(x)?[x,x,x,x,x]:[x]));
const dur=rint(3,4),trc=l.trench||l.id,hit=S.links.filter(x=>(x.trench||x.id)===trc),A=CITY[l.a].name,B=CITY[l.b].name,before=R.served;
hit.forEach(x=>x.cut=Math.max(x.cut||0,S.day+dur));M.n++;M.c=l.a;
addInc({type:'cut',ref:trc,until:S.day+dur,msg:tr(pick(MK_SNIPS),{a:A,b:B}),...cutFix(l,hit)},'');
addInc({type:'cut',ref:trc,until:S.day+dur,msg:tr(pick(MK_SNIPS),{a:A,b:B}),cost:Math.max(4000,Math.round(hit.reduce((a,x)=>a+x.mo,0)*0.5))},'');
compute();const i=S.inc[S.inc.length-1],imp=Math.max(0,before-R.served);if(i)i.impact=imp;
const felt=before>1&&imp>=before*0.03;if(felt)M.hurt++;else S.stats.survived++;
toast(felt?`<b>🐒 ${incTitle('cut')}</b><br>${esc(i?i.msg:'')}`:tr('chaos_monkey.rerouted',{a:A,b:B}),felt?'bad':'good',[],i?incOpen(i):null);sfx(felt?'err':'alert');

View file

@ -0,0 +1,79 @@
/* ---------- cable ships at work (data and real numbers: 20-world/70-cable-ships.js) ----------
A subsea cut sends a ship from its club's port: it leaves a day after the call, sails the cable routes at about
500 km a day, may wait for a permit, splices for days, and sails home before it can take the next job. The cut lasts
until the splice is done. With every ship of the zone's club out, the cut waits; a private charter (any free ship,
from anywhere) jumps the queue for $1M plus $200 per km it sails. Voyages live in S.fleet so a ship on its way
home stays busy after the cut is mended; positions are worked out from them, so the map needs no state of its own. */
let SHIP_G=null;
// The cable routes as a graph of landing cities: ships sail where the cables are, which is open sea.
function shipGraph(){if(SHIP_G)return SHIP_G;const g=new Map(),add=(u,e)=>{let L=g.get(u);if(!L)g.set(u,L=[]);L.push(e);};
CABLE_PAIRS.forEach((p,i)=>{add(p.a,{to:p.b,km:p.km,i});add(p.b,{to:p.a,km:p.km,i});});return SHIP_G=g;}
// Shortest sailing distance from the sources ({city: km already to go}) to every port, with the way back.
function shipDij(src){const G=shipGraph(),dist=new Map(),prev=new Map(),h=[];for(const c in src){dist.set(c,src[c]);h.push([src[c],c]);}
while(h.length){let b=0;for(let i=1;i<h.length;i++)if(h[i][0]<h[b][0])b=i;const [d,u]=h[b];h[b]=h[h.length-1];h.pop();if(d>dist.get(u))continue;
for(const e of G.get(u)||[]){const nd=d+e.km;if(nd<(dist.get(e.to)??Infinity)){dist.set(e.to,nd);prev.set(e.to,{from:u,e});h.push([nd,e.to]);}}}
return {dist,prev};}
const shipFree=s=>{const f=S.fleet[s.id];return !f||S.day>=f.back;};
const shipLink=i=>S.links.find(x=>x.id===i.sl)||S.links.find(x=>(x.trench||x.id)===i.ref);
const shipSea=i=>i.type==='cut'&&(i.ship!=null||!!i.seaq);
// Where on the cable the fault is (share of the way from l.a): mostly in shallow water near a shore, where anchors and
// trawls reach the cable; sometimes out in the deep.
function shipFaultT(l){const near=Math.min(0.45,SHIP_SHALLOW/Math.max(1,l.km||1));
if(Math.random()<0.75){const d=Math.random()*near;return Math.random()<0.5?0.03+d:0.97-d;}return 0.03+Math.random()*0.94;}
const shipShallow=(l,t)=>Math.min(t,1-t)*(l.km||0)<=SHIP_SHALLOW;
// A fault seen from the sea: sailing distances from it to every port.
const shipFrom=(i,l)=>shipDij({[l.a]:i.st*l.km,[l.b]:(1-i.st)*l.km});
// The club whose zone the fault is in: the one with the nearest port.
function shipZone(D){let best=null,bd=Infinity;for(const s of SHIPS){if(s.club==='prv')continue;const d=D.dist.get(s.home)??Infinity;if(d<bd){bd=d;best=s.club;}}return best;}
// Sailing distance for a ship, and the timetable if it left today.
function shipPlan(s,i,l,D){let km=D.dist.get(s.home);
if(!(km<Infinity)){const A=CITY[l.a],B=CITY[l.b],H=CITY[s.home];km=Math.round(hav(H.lon,H.lat,A.lon+(B.lon-A.lon)*i.st,A.lat+(B.lat-A.lat)*i.st)*1.4);}
const sail=Math.max(1,Math.ceil(km/SHIP_KMD)),dep=S.day,arr=dep+SHIP_MOB_D+sail,done=arr+(i.sp||0)+(i.sw||4);return {s,km:Math.round(km),dep,arr,done,back:done+sail};}
// The way a ship sails to the fault: the cable endpoint it comes in by (following the shortest route back from its port).
function shipEnd(s,l,D){let c=s.home;
if(!D.dist.has(c)){const H=CITY[c],A=CITY[l.a],B=CITY[l.b];return hav(H.lon,H.lat,A.lon,A.lat)<=hav(H.lon,H.lat,B.lon,B.lat)?'a':'b';}
for(let n=0;n<999;n++){const p=D.prev.get(c);if(!p)break;c=p.from;}return c===l.b?'b':'a';}
// The cut ends with the splice: every link in the trench follows, as clearInc() works it out.
function shipUntil(i,u){i.until=u;for(const l of S.links)if((l.trench||l.id)===i.ref)l.cut=remainUntil(x=>(LINKCUT_TR.includes(x.type)&&x.ref===(l.trench||l.id))||(LINKCUT_ID.includes(x.type)&&x.ref===l.id));}
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;
for(const s of SHIPS)if(shipFree(s)){const P=shipPlan(s,i,l,D);if(!best||P.done<best.done)best=P;}
if(best&&best.done<cur-1){i.cost=Math.round(SHIP_FIX+best.km*SHIP_FIX_KM);i.fix=tr('cable_ships.charter_ship',{ship:best.s.n});}else{i.cost=0;delete i.fix;}return best;}
// Send the zone's club ship that gets there first; with none free, the cut waits for one.
function shipAssign(i,l){const D=shipFrom(i,l),z=shipZone(D);let best=null;
for(const s of SHIPS)if(s.club===z&&shipFree(s)){const P=shipPlan(s,i,l,D);if(!best||P.done<best.done)best=P;}
if(best)shipSend(i,l,best,D);else if(!i.seaq){i.seaq=1;i.ship=null;shipUntil(i,S.day+365);}
shipQuote(i,l,D);}
// A fresh cut on a subsea cable: roll where it is and how long the work takes, then call the club.
function shipCut(i,l){if(!S.fleet)S.fleet={};i.sl=l.id;i.st=+shipFaultT(l).toFixed(3);i.sw=shipShallow(l,i.st)?rint(3,3):rint(6,7);
const near=CITY[i.st<0.5?l.a:l.b],pm=shipShallow(l,i.st)&&SHIP_PERMIT[near.cc];i.sp=pm?rint(pm[0],pm[1]-pm[0]+1):0;shipAssign(i,l);}
// A ship whose job went away (the cable was given up, or another ship was chartered) turns round where it is.
function shipRecall(id){const f=S.fleet[id];if(!f||S.day>=f.done)return;const m=f.dep+SHIP_MOB_D;
if(S.day>=f.arr){const sail=f.back-f.done;f.done=S.day;f.back=S.day+sail;f.inc=null;return;}
const out=Math.max(0,S.day-m);f.rt=+(out/Math.max(1,f.arr-m)).toFixed(4);f.rs=S.day;f.arr=f.done=S.day;f.back=S.day+out;f.inc=null;}
// Pay for the charter: the quickest free ship goes, whichever club or company it sails for.
function shipRush(i){const l=shipLink(i);if(!l||!shipSea(i))return false;const D=shipFrom(i,l),P=shipQuote(i,l,D);if(!P||!i.cost)return false;
if(!spend(i.cost))return false;if(i.ship!=null)shipRecall(i.ship);shipSend(i,l,P,D);i.cost=0;delete i.fix;i.rushed=true;return true;}
// Every day: ships home from a voyage are free again, waiting cuts get one, charter prices follow the fleet.
function shipDay(){if(!S.fleet)S.fleet={};
for(const id in S.fleet){const f=S.fleet[id];if(S.day>=f.back){delete S.fleet[id];continue;}if(f.inc&&S.day<f.done&&!S.inc.some(i=>i.id===f.inc&&i.ship===id))shipRecall(id);}
for(const i of S.inc.filter(shipSea).sort((a,b)=>(a.start||0)-(b.start||0))){const l=shipLink(i);if(!l)continue;if(i.seaq)shipAssign(i,l);else if(!i.rushed)shipQuote(i,l);}}
// What the ship on a cut is doing, for the panels and the NOC.
function shipStatus(i){if(!shipSea(i))return '';const l=shipLink(i);if(!l)return '';
if(i.seaq){const D=shipFrom(i,l),z=shipZone(D);return tr('cable_ships.every_club_ship_is_out',{club:SHIP_CLUBS[z]?SHIP_CLUBS[z].n:''});}
const s=SHIP[i.ship],f=S.fleet[i.ship];if(!s||!f)return '';const d=S.day,home=CITY[s.home].name,end=Math.max(1,f.done-d);
if(d<f.arr)return tr('cable_ships.ship_sails_from_home',{ship:s.n,home,n:f.arr-d,m:end});
if(d<f.arr+(i.sp||0))return tr('cable_ships.ship_waits_for_a_permit',{ship:s.n,n:f.arr+(i.sp||0)-d,m:end});
return trn('cable_ships.ship_is_splicing',end,{ship:s.n});}
/* Laying your own subsea cable: the last part of the build is a lay ship at sea, about 150 km a day. A second ship,
booked before laying starts, works from the other end and halves that part; nothing at sea speeds up the survey,
the permits or the cable factory. */
const layDays=l=>Math.max(1,Math.ceil((l.km||0)/LAY_KMD)),layLen=l=>l.ship2?Math.ceil(layDays(l)/2):layDays(l),layStart=l=>l.ready-layLen(l);
const layOwn=l=>l.kind==='df'&&l.own&&l.sub;
const layName=(l,k=0)=>{let h=0;for(const ch of String(l.id))h=(h*31+ch.charCodeAt(0))>>>0;return LAY_SHIPS[(h+k)%LAY_SHIPS.length];};
function layQuote(l){if(!layOwn(l)||l.ship2||S.day>=layStart(l)||l.ready<=S.day+1)return null;const save=Math.floor(layDays(l)/2);if(save<1)return null;return {save,cost:SHIP_MOB+save*LAY_DAY};}
// How much of the cable is on the seabed, 0 to 1.
const layDone=(l,T)=>clamp((T-layStart(l))/layLen(l),0,1);

View file

@ -18,6 +18,8 @@ function dayTick(){
for(const k in S.peers){const [id,c]=k.split('@'),sn=snub(id,c);if(!sn)continue;delete S.peers[k];S.stats.depeered=(S.stats.depeered||0)+1;
{const v={net:esc(NET[id].name),ix:esc(ixName(c)),city:esc(CITY[ixCity(c)].name),why:esc(sn.why)};toast(ixNamesCity(c)?tr('day_tick.net_de_peered_you_at_ix',v):tr('day_tick.net_de_peered_you_at_ix_caef',v),'bad');}}
if(S.cnLic&&S.cnLic.state==='pending'&&d>=S.cnLic.ready){S.cnLic.state='ok';toast(tr('day_tick.license_granted_your_joint_venture'),'goal');sfx('coin');}
// cable ships: home again, sent to waiting cuts (50-cable-ships.js)
shipDay();
// resolve incidents
for(const i of S.inc.slice())if(i.until<=d){const o=incOpen(i),l=o&&o.a==='link'&&S.links.find(x=>x.id===o.v),where=l?CITY[l.a].name+'–'+CITY[l.b].name:o&&o.a==='city'?CITY[o.v].name:'';clearInc(i);
toast(where?tr('day_tick.resolved_what_where_is_back_to',{what:incTitle(i.type),where:esc(where)}):tr('day_tick.resolved_what',{what:incTitle(i.type)}),'good',[],o);}

View file

@ -7,7 +7,9 @@ Object.assign(ACT,{
const n=chBack(l?[l]:[]);if(n)toast(trn('links.n_optic_back_on_the_spares_shelf',n),'good');}S.links=S.links.filter(l=>l.id!==id);prunePairMet();UI.sel=null;UI.confirm=null;after();},
// The chaos monkey takes a banana and goes home early (no bonus).
mkBanana:()=>{if(!mkOn())return;if(!spend(mkBananaCost()))return;S.stats.bananas=(S.stats.bananas||0)+1;mkLeave('banana');track('monkey_banana');after();},
fixInc:({id})=>{const i=S.inc.find(x=>x.id===id);if(!i||!(i.cost>0))return;if(i.slow&&i.rushed)return;if(!spend(i.cost))return;
fixInc:({id})=>{const i=S.inc.find(x=>x.id===id);if(!i||!(i.cost>0))return;
// At sea, paying means a private charter: another ship sails, it does not appear (50-cable-ships.js).
if(shipSea(i)){if(shipRush(i)){const s=SHIP[i.ship];toast(tr('cable_ships.ship_chartered',{ship:esc(s.n),home:esc(CITY[s.home].name),n:Math.max(1,i.until-S.day)}),'good');sfx('coin');after();}return;}if(i.slow&&i.rushed)return;if(!spend(i.cost))return;
if(i.slow&&i.until>S.day+1){i.rushed=true;i.cost=0;i.until=S.day+1;const p=S.pops[i.ref];if(p)p.down=Math.min(p.down,S.day+1);toast(tr('links.power_cycled_the_router_in_city',{city:esc(CITY[i.ref].name),chip:esc(RG[(p&&p.rgen)||0].chip)}),'good');after();return;}clearInc(i);toast(tr('links.fixed_what_resolved_early',{what:incTitle(i.type)}),'good');after();},
myIxUp:({city})=>{const m=S.myIx[city];if(!m)return;const f=(m.fab|0)+1,N=MYIX_FAB[f];if(!N)return;if(N.lvl>lvl()){toast(tr('links.a_fab_fabric_unlocks_at_customer',{fab:N.n,lv:N.lvl}),'bad');sfx('err');return;}if(!spend(N.cost))return;m.fab=f;toast(tr('links.ix_now_runs_a_fab_fabric',{ix:esc(m.name),fab:N.n,max:N.max}),'good');m.next=Math.min(m.next,S.day+3);after();},
foundIx:({city})=>{if(!S.pops[city]||S.myIx[city]||CITY[city].ix||CITY[city].cn)return;if(!spend(MYIX_COST))return;const nm=(S.name.split(' ')[0]||'My').replace(/[^A-Za-z0-9]/g,'').slice(0,10)+'-IX '+CITY[city].name;

View file

@ -33,6 +33,9 @@ Object.assign(ACT,{
addPair:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||!isRdm(l.sys)||l.ready>S.day)return;const n=Math.max(1,l.pairs|0);if(n>=pairsMax(l))return;if((l.ch||[]).length+soldSlots(l)<chMax(l)){toast(tr('fiber_and_hardware.fill_this_pair_first_light_all',{max:chMax(l)}),'bad');sfx('err');return;}if(!spend(pairCost(l)))return;l.pairs=n+1;toast(tr('fiber_and_hardware.fiber_pair_n_is_lit_a',{n:n+1,a:CITY[l.a].name,b:CITY[l.b].name,m:DF_SYS[l.sys].max}),'good');sfx('build');after();},
upSys:({id})=>{const l=S.links.find(x=>x.id===id),to=l&&sysNext(l);if(!to||!techOk('sys',to,DF_SYS[to].lvl))return;if(!spend(sysUpCost(l)))return;l.sys=to;if(l.ready<=S.day){l.eqDown=S.day+1;toast(tr('fiber_and_hardware.line_system_swap_all_channels_are'),'bad');}after();},
spares:({id})=>{const l=S.links.find(x=>x.id===id);if(!l)return;l.spares=!l.spares;sfx('click');after();},
crews:({id,all})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||l.ready<=S.day+1)return;const n=all?crewSteps(l):1,c=n*crewCost(l);if(!spend(c))return;const ready=Math.max(S.day+1,l.ready-30*n),saved=l.ready-ready;setCableReady(l,ready);toast(l.sub?trn('fiber_and_hardware.another_cable_ship_joins_the_lay',saved,{n:saved}):trn('fiber_and_hardware.more_crews_on_site_construction_is',saved,{n:saved}),'good');after();},
// Your own subsea cable: book a second lay ship before laying starts; it lays from the other end (50-cable-ships.js).
layShip:({id})=>{const l=S.links.find(x=>x.id===id);const q=l&&layQuote(l);if(!q||!spend(q.cost))return;l.ship2=1;setCableReady(l,l.ready-q.save);
toast(trn('cable_ships.second_lay_ship_booked',q.save,{ship:esc(layName(l,1)),n:q.save}),'good');sfx('coin');after();},
crews:({id,all})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||l.sub||l.ready<=S.day+1)return;const n=all?crewSteps(l):1,c=n*crewCost(l);if(!spend(c))return;const ready=Math.max(S.day+1,l.ready-30*n),saved=l.ready-ready;setCableReady(l,ready);toast(trn('fiber_and_hardware.more_crews_on_site_construction_is',saved,{n:saved}),'good');after();},
addGen:({city})=>{const p=S.pops[city];if(!p||p.gen)return;if(!spend(GEN_COST))return;p.gen=true;floater(CITY[city].x,CITY[city].y-30,tr('common.generator'),'#FF8A3D');after();},
});

View file

@ -52,7 +52,7 @@ function renderLeft(){checkLayer();
h+=`<p class="lead">${tr('hud_and_panels.your_network_operations_center_every')}</p>`;
h+=opsCard()+mkCard()+ddosPanel();
// Incidents come first, the ones you can fix with one click at the top (#63): no scrolling past hot ports to replace an optic.
for(const i of S.inc.filter(i=>i.type!=='ddos').sort((a,b)=>(b.cost?1:0)-(a.cost?1:0)||(b.impact||0)-(a.impact||0))){h+=`<div class="inc"><div class="nm">${incTitle(i.type)}</div><div class="meta">${esc(i.msg)}</div><div class="meta">${trn('hud_and_panels.auto_fix_in_n_day',i.until-S.day)}${i.impact?` · ${tr('hud_and_panels.g_lost',{g:fmtG(i.impact)})}`:''}</div>${i.cost?`<div class="btns">${btn(`${esc(i.fix||tr('common.rush_repair'))} ${fmt$(i.cost)}`,'fixInc',{id:i.id},'red sm',S.cash<i.cost)}</div>`:''}</div>`;}
for(const i of S.inc.filter(i=>i.type!=='ddos').sort((a,b)=>(b.cost?1:0)-(a.cost?1:0)||(b.impact||0)-(a.impact||0))){h+=`<div class="inc"><div class="nm">${incTitle(i.type)}</div><div class="meta">${esc(i.msg)}</div><div class="meta">${shipSea(i)?'🚢 '+esc(shipStatus(i)):trn('hud_and_panels.auto_fix_in_n_day',i.until-S.day)}${i.impact?` · ${tr('hud_and_panels.g_lost',{g:fmtG(i.impact)})}`:''}</div>${i.cost?`<div class="btns">${btn(`${esc(i.fix||tr('common.rush_repair'))} ${fmt$(i.cost)}`,'fixInc',{id:i.id},'red sm',S.cash<i.cost)}</div>`:''}</div>`;}
h+=logSection();UI.logSeen=Date.now();
h+=ddosSettings();
if(S.grace&&S.grace.until>S.day&&R.graceNets)h+=`<div class="kv"><span>${tr('common.courtesy_route')}</span><b>${tr('hud_and_panels.n_networks_d_days_left',{n:R.graceNets,d:S.grace.until-S.day})}</b></div><p class="meta" style="margin:0 0 6px">${tr('hud_and_panels.reaches_networks_from_the_last')}</p>`;

View file

@ -99,12 +99,21 @@ function subUpgradePanel(l){return `<h4 class="sub4">${tr('common.submarine_tran
const at=l['sub'+k],done=subUpgradeReady(l,k),cost=subUpgradeCost(l,k),preview={...l,['sub'+k]:S.day},use=at!==undefined||subHelps(l.km,k,l['sub'+subOther(k)]!==undefined);
const status=done?tr('common.installed'):at!==undefined?tr('link_panels.ready_in_n_days',{n:Math.max(0,at-S.day)}):tr('link_panels.price_n_days',{price:fmt$(cost),n:leadDays(U.days)});
return `<div class="row"><div class="grow"><div class="nm">${tr(U.n)}</div><div class="meta">${status}</div><div class="meta">${tr('common.up_to_g_per_channel',{g:fmtG(submarineRate(preview))})}</div>${use?'':`<div class="why">${tr('reach_and_subsea.makes_no_difference_on_this_cable')}</div>`}</div>${at===undefined?btn(tr('common.install'),'subUpgrade',{id:l.id,k},'sm',!use||lvl()<4||S.cash<cost):''}</div>`;}).join('');}
// The cable ship on a subsea cut (50-cable-ships.js), under the cut's story.
const shipNote=i=>{const t=i&&shipStatus(i);return t?`<p class="note">🚢 ${esc(t)}</p>`:'';};
// Building your own subsea cable: survey and factory first, then the lay ship at sea; a second one can be booked.
function layPanel(l){const d=S.day,st=layStart(l),q=layQuote(l),km=Math.round(layDone(l,d)*l.km),two=l.ship2?tr('cable_ships.ship_and_ship',{a:layName(l),b:layName(l,1)}):layName(l);
let h=d<st?`<div class="kv"><span>${tr('cable_ships.survey_permits_and_the_cable_factory')}</span><b>${trn('cable_ships.laying_starts_in_n_days',st-d)}</b></div>`
:`<div class="kv"><span>${tr('cable_ships.ships_lay_the_cable',{ships:esc(two)})}</span><b>${tr('cable_ships.km_of_km',{km:km.toLocaleString(),of:Math.round(l.km).toLocaleString()})}</b></div>`;
if(q)h+=`<div class="btns">${btn(tr('cable_ships.book_a_second_lay_ship',{price:fmt$(q.cost),n:q.save}),'layShip',{id:l.id},'sm',S.cash<q.cost)}</div><p class="note">${tr('link_panels.only_a_few_dozen_cable_ships')}</p>`;
else if(!l.ship2&&d<st)h+=`<p class="note">${tr('link_panels.only_a_few_dozen_cable_ships')}</p>`;
return h;}
function dfPanel(l){
const load=R.load[l.id]||0,cap=dfCap(l),u=cap?load/cap:0,bld=l.ready>S.day,A=CITY[l.a].name,B=CITY[l.b].name,inc=S.inc.find(i=>i.ref===l.id||i.ref===(l.trench||l.id)),amps=ampCount(l.km),sysD=DF_SYS[l.sys];
let h=`<div class="ph"><div><div class="eyebrow">${tr('link_panels.dark_fiber_kind_km_km',{kind:l.own?tr('link_panels.your_own_build'):tr('common.leased_iru'),km:l.km.toLocaleString()})}</div><h2>${A} ⇄ ${B}</h2></div><button class="x" data-act="closePanel" aria-label="${tr('common.close')}">×</button></div><div class="scroll">`;
if(bld){const tot=Math.max(1,l.ready-l.day),done=clamp((S.day-l.day)/tot,0,1);
h+=`<section><h3>${l.own?tr('common.under_construction'):tr('common.being_spliced')}</h3><div class="kv"><span>${l.own?tr('link_panels.permits_trenching_splicing'):tr('common.iru_handover')}</span><b>${tr('common.n_days_left',{n:l.ready-S.day})}</b></div><div class="bar me"><i style="width:${done*100}%"></i></div>${l.own?`<div class="btns">${btn(l.sub?tr('link_panels.charter_another_cable_ship_price_30',{price:fmt$(crewCost(l))}):tr('link_panels.hire_extra_crews_price_30_days',{price:fmt$(crewCost(l))}),'crews',{id:l.id},'sm',l.ready<=S.day+1||S.cash<crewCost(l))}${btn(tr('link_panels.finish_in_1_day_price',{price:fmt$(crewSteps(l)*crewCost(l))}),'crews',{id:l.id,all:1},'sm',!crewSteps(l)||S.cash<crewSteps(l)*crewCost(l))}</div>${l.sub?`<p class="note">${tr('link_panels.only_a_few_dozen_cable_ships')}</p>`:''}`:''}<p class="note">${tr('link_panels.you_can_pre_install_optics_now')}</p></section>`;}
else if(inc&&linkDown(l))h+=`<section><h3 style="color:var(--bad)">${tr('common.dark_6bf5')}</h3><p class="lead">${esc(inc.msg)}</p>${inc.cost?btn(`${esc(inc.fix||tr('common.rush_repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash<inc.cost):''}</section>`;
h+=`<section><h3>${l.own?tr('common.under_construction'):tr('common.being_spliced')}</h3><div class="kv"><span>${l.own?tr('link_panels.permits_trenching_splicing'):tr('common.iru_handover')}</span><b>${tr('common.n_days_left',{n:l.ready-S.day})}</b></div><div class="bar me"><i style="width:${done*100}%"></i></div>${l.own&&l.sub?layPanel(l):l.own?`<div class="btns">${btn(tr('link_panels.hire_extra_crews_price_30_days',{price:fmt$(crewCost(l))}),'crews',{id:l.id},'sm',l.ready<=S.day+1||S.cash<crewCost(l))}${btn(tr('link_panels.finish_in_1_day_price',{price:fmt$(crewSteps(l)*crewCost(l))}),'crews',{id:l.id,all:1},'sm',!crewSteps(l)||S.cash<crewSteps(l)*crewCost(l))}</div>`:''}<p class="note">${tr('link_panels.you_can_pre_install_optics_now')}</p></section>`;}
else if(inc&&linkDown(l))h+=`<section><h3 style="color:var(--bad)">${tr('common.dark_6bf5')}</h3><p class="lead">${esc(inc.msg)}</p>${shipNote(inc)}${inc.cost?btn(`${esc(inc.fix||tr('common.rush_repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash<inc.cost):''}</section>`;
h+=`<section><h3>${tr('common.capacity')}</h3><div class="kv"><span>${tr('link_panels.n_of_max_channels_lit',{n:(l.ch||[]).length,max:chMax(l)})}${soldSlots(l)?` · ${tr('link_panels.n_sold_as_alien_waves',{n:soldSlots(l)})}`:''}</span><b>${fmtG(load)} / ${fmtG(cap)}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100)}%"></i></div>
${seatPanel(l)}${l.own&&l.sub?`<div class="kv"><span>${tr('common.cable_design')}</span><b>${tr((SEA_DESIGNS[l.seaDesign]||SEA_DESIGNS.standard).n)}</b></div>`:''}
<div class="kv"><span>${tr('common.latency')}</span><b>${tr('common.ms_ms_one_way',{ms:linkLat(l).toFixed(1)})}</b></div><div class="kv"><span>${l.own?tr('link_panels.right_of_way_upkeep'):tr('common.iru_lease')}</span><b>${tr('common.price_mo',{price:fmt$(l.mo)})}</b></div><div class="kv"><span>${tr('link_panels.n_amp_huts',{n:amps})}</span><b>${tr('common.price_mo',{price:fmt$(amps*AMP_MO)})}</b></div>${!bld&&!(l.ch||[]).length?`<p class="why">${tr('link_panels.this_fiber_is_dark_add_optics')}</p>`:''}</section>`;
@ -136,7 +145,7 @@ function linkPanel(id){
if(l.kind==='df')return dfPanel(l);
const load=R.load[l.id]||0,cap=LT[l.tier].g,u=load/cap,cut=l.cut>S.day,trk=l.trench||l.id,inc=S.inc.find(i=>(LINKCUT_TR.includes(i.type)&&i.ref===trk)||((i.type==='fatwave'||i.type==='label'||i.type==='mtu')&&i.ref===l.id)),sib=pairLinks(l.a,l.b).filter(x=>x!==l&&x.kind!=='vxc'),mates=sib.filter(x=>(x.trench||x.id)===trk);
let h=`<div class="ph"><div><div class="eyebrow">${l.cable?esc(CAB[l.cable].name):l.sub?tr('common.subsea_cable'):tr('common.terrestrial_fiber')} · ${l.km.toLocaleString()} km</div><h2>${CITY[l.a].name} ⇄ ${CITY[l.b].name}</h2></div><button class="x" data-act="closePanel" aria-label="${tr('common.close')}">×</button></div><div class="scroll">`;
if(cut)h+=`<section><h3 style="color:var(--bad)">${tr('common.cut_2e50')}</h3><p class="lead">${inc?esc(inc.msg):''} ${tr('link_panels.back_in_n_days',{n:l.cut-S.day})}</p>${inc&&inc.cost?btn(`${esc(inc.fix||tr('common.rush_repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash<inc.cost):''}</section>`;
if(cut)h+=`<section><h3 style="color:var(--bad)">${tr('common.cut_2e50')}</h3><p class="lead">${inc?esc(inc.msg):''} ${inc&&shipSea(inc)?'':tr('link_panels.back_in_n_days',{n:l.cut-S.day})}</p>${shipNote(inc)}${inc&&inc.cost?btn(`${esc(inc.fix||tr('common.rush_repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash<inc.cost):''}</section>`;
h+=`<section><h3>${tr('common.capacity')}</h3><div class="kv"><span>${tr('link_panels.name_wave',{name:LT[l.tier].n})}</span><b>${fmtG(load)} / ${fmtG(cap)}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100)}%"></i></div>
<div class="kv"><span>${tr('common.latency')}</span><b>${tr('common.ms_ms_one_way',{ms:linkLat(l).toFixed(1)})}</b></div>${l.cable?`<div class="kv"><span>${tr('common.cable_system')}</span><b>${esc(CAB[l.cable].name)}</b></div>`:''}
<div class="kv"><span>${tr('common.wave_lease')}</span><b>${tr('common.price_mo',{price:fmt$(l.mo)})}</b></div>${u>=0.9?`<p class="why">${tr('link_panels.congested_upgrade_it_or_add_a')}</p>`:''}

View file

@ -94,6 +94,8 @@ function drawFrame(now){
if(ly===null&&(prio(v)===0||(prio(v)===1&&(v.C.id===S.home||UI.hover===v.C.id)))){ly=below;const r={x:v.sx-tw/2,y:below-10,w:tw,h:21};rects.push(r);labs.push(r);}
v.ly=ly;}
if(pzOn()){for(const v of vis.slice().reverse())pzDrawCity(v,csc,now);}else for(const v of vis.slice().reverse())drawCity(v.C,v.sx,v.sy,csc,now,v.ly,v.dem);
// cable ships at sea (88-cable-ships.js), over the city labels so a ship leaving port stays in sight
drawShips(ks,now);
// Architect runs: what the tubes between two cities are (one trench, or separate paths), above the cities.
for(const [x,y,t,one] of AR_PILLS){ctx.font='800 11px "Baloo 2", sans-serif';const tw=ctx.measureText(t).width+12;ctx.fillStyle=one?'#FFE3C2':'#DDF7E7';ctx.strokeStyle=one?'#FF8A3D':'#16A866';ctx.lineWidth=2;rr(x-tw/2,y-9,tw,17,8);ctx.fill();ctx.stroke();ctx.fillStyle='#1E2640';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(t,x,y+1);}
// the chaos monkey (woken here after a reload, wherever it last snipped)

View file

@ -0,0 +1,49 @@
/* Cable ships on the map (85-incidents/50-cable-ships.js): club ships at anchor off their ports, sailing out to a cut,
splicing on site and sailing home; lay ships along a cable you are building. Where they are comes from S.fleet and
the clock, so nothing here is saved; their routes are worked out once per voyage and kept in SHIP_PATH. */
const SHIP_PATH=new Map(),SHIP_HITS=[];
// Off the port: the first point of a cable leaving it, so a ship rides at anchor at sea and not in town.
function shipHomePt(s){const k='h:'+s.id;let p=SHIP_PATH.get(k);if(p)return p;const C=CITY[s.home];p=[C.x,C.y];
for(const cp of CABLE_PAIRS){if(cp.a===s.home){p=cp.pts[1].slice();break;}if(cp.b===s.home){p=cp.pts[cp.pts.length-2].slice();break;}}
const n=SHIPS.filter(x=>x.home===s.home).indexOf(s);p[0]+=n*7;p[1]+=n*4;SHIP_PATH.set(k,p);return p;}
// Out along the cable routes to the cable's end, then along the cable to the fault.
function shipRoute(s,f){const key=s.id+'|'+f.dep+'|'+f.link+'|'+f.e+'|'+f.t;let r=SHIP_PATH.get(key);if(r)return r;if(SHIP_PATH.size>300)SHIP_PATH.clear();
const pts=[shipHomePt(s).slice()],push=q=>{const b=pts[pts.length-1];pts.push([q[0]+W*Math.round((b[0]-q[0])/W),q[1]]);},l=S.links.find(x=>x.id===f.link);
if(l){const end=f.e==='b'?l.b:l.a,D=shipDij({[end]:0});let c=s.home;
for(let n=0;n<999&&c!==end;n++){const p=D.prev.get(c);if(!p)break;const cp=CABLE_PAIRS[p.e.i],q=cp.a===c?cp.pts:cp.pts.slice().reverse();for(let j=1;j<q.length-1;j++)push(q[j]);c=p.from;}
const g=linkGeom(l);if(f.e==='a'){for(let j=1;j<g.pts.length-1&&g.cum[j]<f.t;j++)push(g.pts[j]);}else for(let j=g.pts.length-2;j>0&&g.cum[j]>f.t;j--)push(g.pts[j]);
push(polyAt(g.pts,g.cum,f.t));}
else push([f.fx,f.fy]);
const cum=[0];let L=0;for(let j=1;j<pts.length;j++){L+=Math.hypot(pts[j][0]-pts[j-1][0],pts[j][1]-pts[j-1][1]);cum.push(L);}for(let j=0;j<cum.length;j++)cum[j]/=L||1;
r={pts,cum};SHIP_PATH.set(key,r);return r;}
// Where a ship is at time T (days, with the part of today gone by) and what it is doing.
function shipAt(s,T){const f=S.fleet&&S.fleet[s.id],H=shipHomePt(s);if(!f||T>=f.back)return {x:H[0],y:H[1],m:'port',dx:1};
const r=shipRoute(s,f),m=f.dep+SHIP_MOB_D;let p,mode;
if(f.rs!=null&&T>=f.rs){p=f.rt*(1-clamp((T-f.rs)/Math.max(0.01,f.back-f.rs),0,1));mode='back';}
else if(T<m){p=0;mode='port';}else if(T<f.arr){p=(T-m)/Math.max(0.01,f.arr-m);mode='out';}else if(T<f.done){p=1;mode='work';}
else{p=1-(T-f.done)/Math.max(0.01,f.back-f.done);mode='back';}
p=clamp(p,0,1);const [x,y]=polyAt(r.pts,r.cum,p),[x2]=polyAt(r.pts,r.cum,clamp(p+(mode==='back'?-0.01:0.01),0,1));return {x,y,m:mode,dx:x2-x||1};}
// A cartoon cable ship: red hull, white bridge, the yellow bow sheave cable ships are known by; a wake when under way.
function shipSprite(x,y,face,sc,col,now,mode){const c=ctx;c.save();c.translate(x,y+Math.sin(now/420+x*0.05)*1.2*sc);c.scale(face*sc,sc);
if(mode!=='port'&&mode!=='work'){c.strokeStyle='rgba(255,255,255,.85)';c.lineWidth=1.6;c.beginPath();c.moveTo(-10,3);c.quadraticCurveTo(-16,1,-22,4);c.moveTo(-10,5);c.quadraticCurveTo(-15,8,-21,9);c.stroke();}
c.fillStyle=col;c.strokeStyle='#1E2640';c.lineWidth=1.6;c.lineJoin='round';c.beginPath();c.moveTo(-11,0);c.lineTo(11,0);c.lineTo(8,6);c.lineTo(-9,6);c.closePath();c.fill();c.stroke();
c.fillStyle='#fff';c.beginPath();c.rect(-7,-7,8,7);c.fill();c.stroke();c.fillStyle='#1E2640';c.fillRect(-5,-5,4,2);
c.beginPath();c.arc(9,-2,2.6,0,7);c.fillStyle='#FFD23F';c.fill();c.stroke();
if(mode==='work'&&Math.floor(now/350)%2){c.fillStyle='#FFD23F';c.font='900 11px sans-serif';c.textAlign='center';c.fillText('✦',12,-8);}
c.restore();}
function drawShips(ks,now){SHIP_HITS.length=0;if(!S||pzOn()||!S.fleet)return;
const T=S.day+(UI.speed?clamp(acc/DAY_MS,0,0.999):0),z=cam.z,sc=Math.max(0.75,Math.min(1.4,Math.sqrt(z)))*(lodFar()?0.8:1),list=[];
for(const s of SHIPS){const p=shipAt(s,T);if(p.m==='port'&&z<1.1)continue;list.push({p,s,col:s.club==='prv'?'#7A5CFF':'#FF4D5E'});}
for(const l of S.links)if(layOwn(l)&&l.ready>S.day&&T>=layStart(l)){const g=linkGeom(l),q=layDone(l,T),two=!!l.ship2;
const put=(t,k,dir)=>{const [x,y]=polyAt(g.pts,g.cum,clamp(t,0,1)),[x2]=polyAt(g.pts,g.cum,clamp(t+dir*0.01,0,1));list.push({p:{x,y,m:'lay',dx:x2-x||dir},lay:l,k,col:'#16A866'});};
if(two){put(q/2,0,1);put(1-q/2,1,-1);}else put(q,0,1);}
for(const it of list)for(const k of ks){const [sx,sy]=toS(it.p.x,it.p.y,k);if(sx<-30||sx>CW+30||sy<-30||sy>CH+30)continue;
shipSprite(sx,sy,it.p.dx<0?-1:1,sc,it.col,now,it.p.m);SHIP_HITS.push({x:sx,y:sy,r:14*sc,it});}}
function shipHit(cx,cy){const r=cv.getBoundingClientRect(),x=cx-r.left,y=cy-r.top;let best=null,bd=Infinity;
for(const h of SHIP_HITS){const d=Math.hypot(h.x-x,h.y-y);if(d<=h.r+6&&d<bd){bd=d;best=h.it;}}return best;}
// Tapping a ship says who it is and what it is doing, with a way to the cable it works on.
function shipTap(it){if(it.lay){const l=it.lay;sfx('click');toast(tr('cable_ships.lay_ship_tap',{ship:esc(layName(l,it.k)),a:esc(CITY[l.a].name),b:esc(CITY[l.b].name),km:Math.round(layDone(l,S.day)*l.km).toLocaleString(),of:Math.round(l.km).toLocaleString()}),'',[{l:tr('common.open'),act:'selLink',args:{id:l.id}}]);return;}
const s=it.s,f=S.fleet[s.id],club=s.club==='prv'?tr('cable_ships.private_operator'):SHIP_CLUBS[s.club].n,home=esc(CITY[s.home].name);sfx('click');
const i=f&&f.inc&&S.inc.find(x=>x.id===f.inc&&x.ship===s.id),l=f&&S.links.find(x=>x.id===f.link);
const what=!f||S.day>=f.back?(s.club==='prv'?tr('cable_ships.private_at_anchor',{home}):tr('cable_ships.at_anchor_off_home',{home})):i?esc(shipStatus(i)):trn('cable_ships.sailing_home_to_home',Math.max(1,f.back-S.day),{home});
toast(`<b>${esc(s.n)}</b><br>${esc(club)} · ${what}`,'',l&&i?[{l:tr('common.open'),act:'selLink',args:{id:l.id}}]:[]);}

View file

@ -26,6 +26,7 @@ function endPtr(e){
ptrs.delete(e.pointerId);const d=UI.drag;if(!d)return;
if(d.mode==='pinch'){if(ptrs.size===0){UI.drag=null;UI.snap=null;cv.classList.remove('linking');}return;}
if(d.mode==='link'){if(UI.snap&&UI.snap.id!==d.from){if(pzOn())pzLinkModal(d.from,UI.snap.id);else openLinkModal(d.from,UI.snap.id);sfx('click');}}
else if(!d.moved&&S&&shipHit(e.clientX,e.clientY))shipTap(shipHit(e.clientX,e.clientY));
else if(!d.moved&&S&&mkOn()&&mkHit(e.clientX,e.clientY)){sfx('click');toast(tr('chaos_monkey.tap'),'',[{l:tr('chaos_monkey.banana',{cost:fmt$(mkBananaCost())}),act:'mkBanana',args:{}}]);}
else if(!d.moved&&S){const h=pickCity(e.clientX,e.clientY);
if(h){selectCity(h.id);renderLeft();sfx('click');}

View file

@ -419,6 +419,24 @@
"businesses.your_network_diagram_is_a_photo":"Your network diagram is a photo of a whiteboard.",
"businesses.your_noc_has_a_chat_channel":"Your NOC has a chat channel called #its-always-the-fiber, and it is always the fiber.",
"businesses.your_routing_table_needs_its_own":"Your routing table needs its own routing table.",
"cable_ships.at_anchor_off_home":"at anchor off {home}, ready to sail within a day.",
"cable_ships.book_a_second_lay_ship":"Book a second lay ship <small>{price} · −{n} days</small>",
"cable_ships.charter_ship":"Charter {ship}",
"cable_ships.every_club_ship_is_out":"Every {club} ship is out on a job. The cut waits for the first one back, or a private charter.",
"cable_ships.km_of_km":"{km} of {of} km",
"cable_ships.lay_ship_tap":"<b>{ship}</b><br>Laying your cable from {a} to {b}: {km} of {of} km on the seabed.",
"cable_ships.laying_starts_in_n_days":{"one":"Laying starts in {n} day","other":"Laying starts in {n} days"},
"cable_ships.private_at_anchor":"at anchor off {home}, for charter to anyone who pays.",
"cable_ships.private_operator":"Private operator",
"cable_ships.sailing_home_to_home":{"one":"sailing home to {home}, free again in {n} day.","other":"sailing home to {home}, free again in {n} days."},
"cable_ships.second_lay_ship_booked":{"one":"<b>{ship} is booked.</b><br>It lays from the other end: the cable is ready {n} day sooner.","other":"<b>{ship} is booked.</b><br>It lays from the other end: the cable is ready {n} days sooner."},
"cable_ships.ship_and_ship":"{a} and {b}",
"cable_ships.ship_chartered":"<b>{ship} is chartered.</b><br>It sails from {home}; the cable is back in about {n}d.",
"cable_ships.ship_is_splicing":{"one":"{ship} is splicing the cable: back in {n} day.","other":"{ship} is splicing the cable: back in {n} days."},
"cable_ships.ship_sails_from_home":"{ship} is sailing from {home}: on site in {n}d, cable back in about {m}d.",
"cable_ships.ship_waits_for_a_permit":"{ship} is on site, waiting {n}d for a repair permit. Cable back in about {m}d.",
"cable_ships.ships_lay_the_cable":"{ships} at sea, laying",
"cable_ships.survey_permits_and_the_cable_factory":"Survey, permits and the cable factory",
"cables.a_bet_on_a_tiny_island":"A bet on a tiny island in the middle of the Pacific.",
"cables.a_buffet_of_landings_down_norway":"A buffet of landings down the Norwegian coast, from the oil fields to Oslo.",
"cables.a_friendly_cable_with_french_manners":"A friendly cable with French manners.",
@ -1917,7 +1935,6 @@
"failures.geopolitical_cable_cut":"Geopolitical cable cut",
"failures.hash_polarisation_on_your_lab_nearly":"Hash polarisation on your {lab}: nearly every flow hashes onto the same member. The bundle says it is up. It is also full.",
"failures.hide_the_vacuum":"Hide the vacuum",
"failures.jump_the_cable_ship_queue":"Jump the cable-ship queue",
"failures.lacp_fast_slow_timer_mismatch_on":"LACP fast/slow timer mismatch on your {lab}: one member keeps timing out of the bundle and coming back.",
"failures.lightning_hit_an_amp_site_on":"Lightning hit an amp site on {a}–{b}. The surge protector was decorative.",
"failures.load_shedding_in_city_stage_n":"<b>Load shedding in {city}</b><br>Stage {n} today. Your generator coughed, then kept the lights on.",
@ -1998,7 +2015,6 @@
"failures.your_spares_kit_gets_it_back":"Your spares kit gets it back tomorrow.",
"features.done_in_d_days":"done in {d} days",
"features.weekly_challenge_key":"Weekly challenge {key}",
"fiber_and_hardware.another_cable_ship_joins_the_lay":{"one":"<b>Another cable ship joins the lay.</b><br>The cable is {n} day ahead.","other":"<b>Another cable ship joins the lay.</b><br>The cable is {n} days ahead."},
"fiber_and_hardware.can_t_add_optic_why":"<b>Can't add {optic}.</b><br>{why}",
"fiber_and_hardware.dark_fiber_iru_signed_a_b":"<b>Dark fiber IRU signed.</b><br>{a}–{b} will be spliced and handed over in about 30 days.",
"fiber_and_hardware.fiber_pair_n_is_lit_a":"<b>Fiber pair {n} is lit: {a}–{b}.</b><br>Another ROADMaster 9000 and a fresh chain of amplifiers. Room for {m} more channels.",
@ -2414,7 +2430,6 @@
"link_panels.build_a_pop_here_first":"Build a POP here first.",
"link_panels.cancel_the_iru":"Cancel the IRU",
"link_panels.carry_here":"Carry here",
"link_panels.charter_another_cable_ship_price_30":"Charter another cable ship <small>{price} · −30 days</small>",
"link_panels.click_to_tear_down":"Click to tear down",
"link_panels.collecting_data_check_back_in_a":"Collecting data. Check back in a few days.",
"link_panels.congested_upgrade_it_or_add_a":"Congested. Upgrade it or add a parallel path.",