/* ---------- Teleports and rented satellite capacity (#83) ---------- The rules, the money and save repair. Catalog and physics: 10-catalog/75-satellites.js; actions: 90-actions/87-teleports.js; panels: 93-ui/72-teleport-panels.js. A circuit is a link (kind 'sat'): routing, standby, metrics and the map treat it like any other, with the radio path as its km and its orbit's latency. */ // A POP's teleport (S.pops[c].tele): 0 none, 1 dishes for GEO birds, 2 with tracking antennas for the MEO ring too. const teleOf=c=>{const p=S&&S.pops[c];return p&&(p.tele===1||p.tele===2)?p.tele:0;}; const teleCities=()=>Object.keys(S.pops).filter(teleOf); // The birds that see city c, whatever your level. const teleSees=c=>Object.keys(SATS).filter(id=>satSees(id,c)); // Why no teleport can go up at city c (nothing on sale sees it at your level, or no POP); '' when it can. function teleWhy(c){if(!isCity(c)||!S.pops[c])return tr('satellites.no_pop_in_city',{city:isCity(c)?CITY[c].name:'?'}); if(lvl()lvl()>=SAT_ORB[SATS[id].orb].lv)){const O=SAT_ORB[SATS[ids[0]].orb];return tr('satellites.orbit_unlocks_at_level',{orb:O.n,lv:O.lv});} return '';} // Why the teleport at c cannot add MEO tracking antennas; '' when it can. function trkWhy(c){const O=SAT_ORB.meo;if(lvl()SATS[id].orb==='meo'))return tr('satellites.meo_ring_misses_city',{city:CITY[c].name,lat:O.lat}); return '';} // The birds that see both ends of a circuit: GEO first, then the cheapest. function satBirds(a,b){return Object.keys(SATS).filter(id=>satPairOk(id,a,b)).sort((x,y)=>(SATS[x].orb>SATS[y].orb)-(SATS[x].orbC.id!==a&&satRemote(C.id)&&(S.pops[C.id]||cityOn(C.id))&&satBirds(a,C.id).length).map(C=>C.id) .sort((x,y)=>(!S.pops[x])-(!S.pops[y])||kmBetween(a,x)-kmBetween(a,y));} // Your teleports that can reach city b. const satFrom=b=>satRemote(b)?teleCities().filter(a=>a!==b&&satBirds(a,b).length):[]; // A new link between a and b (a wave, fiber, a fabric circuit, a cable): the circuits already there go on standby beside // it, as one ordered next to a link does, and the player hears about it. Without this the pair's load is shared with orbit. function satBeside(a,b){const ls=pairLinks(a,b).filter(l=>l.kind==='sat'&&!l.standby);for(const l of ls)l.standby=true; if(ls.length)toast(trn('satellites.n_circuits_go_on_standby',ls.length,{a:CITY[a].name,b:CITY[b].name}));return ls.length;} // What the teleports and their circuits cost a month (R.cost.sat). function satMoAll(){let m=0;for(const c in S.pops){const t=teleOf(c);if(t)m+=TPORT_MO+(t>1?TRK_MO:0);}for(const l of S.links)if(l.kind==='sat')m+=l.mo||0;return m;} /* compute(): what users notice on the edges a satellite circuit is on. sv: the losses of the orbits there; sx: the edge's latency is the satellite's (no cable carries ahead of it), so it is no haul to transit on the ground. Returns how many edges there were, for compute() to know a satellite is in the picture at all. */ function satEdges(SE){for(const e of SE){let ta=false,ts=false,act=false;const v=e.sv; for(const l of e.links){const sb=!!l.standby;if(!sb)act=true;if(l.kind==='sat'){const x=SAT_ORB[SATS[l.bird].orb].loss;if(!v.includes(x))v.push(x);}else if(sb)ts=true;else ta=true;} e.sx=act?!ta:!ts;} return SE.length;} // A flow of ok Gbps from city index ci crossed these edges: keep it, and what each orbit would cost it beyond the tl its // haul to transit already does (users count the worse of the two, not both). function satNote(se,ci,ok,tl){for(let k=0;ktl)a[1+j]+=ok*(v[j]-tl);}} /* After routing: each orbit's share of the edge's traffic, split as compute() splits it (active links by capacity, standby ones the overflow). A satellite on standby beside a cable that has room carries nothing and costs nobody anything; one that takes the overflow, or shares the load, costs the users of that share. LATP gets the lost service and SATU the Gbps that rode a satellite, by city index. */ function satAfter(SE,LATP,SATU){for(const e of SE){const ld=e.ld||0;if(!e.sa||ld<=1e-9)continue; const v=e.sv,sh=new Float64Array(v.length),ac=e.cap-e.scap,a=Math.min(ld,ac),sp=ld-a;let only=true,all=0; for(const l of e.links){if(l.kind!=='sat'){only=false;continue;}const c=capOf(l);sh[v.indexOf(SAT_ORB[SATS[l.bird].orb].loss)]+=(l.standby?(e.scap>0?sp*c/e.scap:0):(ac>0?a*c/ac:0))/ld;} if(only&&v.length===1)sh[0]=1;for(let j=0;jr&&r.satU&&r.citySrv&&r.citySrv[c]>0?Math.min(1,(r.satU[c]||0)/r.citySrv[c]):0; // Saves: a teleport is 1 or 2; a circuit needs a known bird that sees both POPs, a teleport able to work it, a size it sells. function satSanitize(s){ for(const c of Object.keys(s.pops)){const p=s.pops[c];if(p.tele!==undefined&&p.tele!==1&&p.tele!==2)delete p.tele;} s.links=s.links.filter(l=>{if(l.kind!=='sat')return true;const B=typeof l.bird==='string'&&own(SATS,l.bird)?SATS[l.bird]:null,p=s.pops[l.a]; if(!B||!p||!p.tele||B.orb==='meo'&&p.tele<2||!s.pops[l.b]||!satPairOk(l.bird,l.a,l.b))return false; const G=SAT_ORB[B.orb].g;if(!G.includes(l.g))l.g=G.reduce((x,v)=>v<=num(l.g,0)?v:x,G[0]); l.km=satKm(l.bird,l.a,l.b);l.sub=true;l.ready=num(l.ready,0);l.day=Math.min(s.day,Math.max(0,num(l.day,s.day)));for(const k of ['tier','cable','trench','mult','border','premium','vt','prov','own','sys','ch'])delete l[k];return true;});}