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
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
79
src/game/85-incidents/50-cable-ships.js
Normal file
79
src/game/85-incidents/50-cable-ships.js
Normal 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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue