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
|
|
@ -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)
|
||||
|
|
|
|||
49
src/game/96-map/88-cable-ships.js
Normal file
49
src/game/96-map/88-cable-ships.js
Normal 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}}]:[]);}
|
||||
|
|
@ -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');}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue