Satellite teleports: GEO and MEO circuits for islands and remote towns (#83)

The early and mid-game satellite option, before Pie in the Sky. Build a
teleport at a POP that a satellite sees, then rent capacity from it to
a remote POP: GEO (Intelsplat, Kacophony) needs no capex but costs a lot
a month per Gbps, 1-10 Gbps at about 600 ms; MEO (O3bservant) needs
tracking antennas at the teleport and gives multi-Gbps at about 130 ms
where both ends are under its ring, at least 5 degrees up. Coverage
follows each bird's footprint by ocean region. Latency feeds the latency
model: users who ride a satellite notice, in proportion to the share.

A circuit beside a cable goes on standby, whichever came first, and
carries only what the cable cannot: the classic single-cable island
backup. Satellites are not subsea links for covenants, scenario goals or
subsidies (Pitcairn's UK grant needs a cable). Express fiber and the
build standard leave satellite circuits alone.
This commit is contained in:
jvanvik 2026-11-07 01:12:23 +01:00
parent 8e1f2d66a5
commit e1ae8e0164
46 changed files with 1176 additions and 55 deletions

View file

@ -0,0 +1,73 @@
/* ---------- 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()<SAT_ORB.geo.lv)return tr('satellites.teleports_unlock_at_level',{lv:SAT_ORB.geo.lv});
const ids=teleSees(c);if(!ids.length)return tr('satellites.no_bird_sees_this_city');
if(!ids.some(id=>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()<O.lv)return tr('satellites.orbit_unlocks_at_level',{orb:O.n,lv:O.lv});
if(!isCity(c)||!teleOf(c))return tr('satellites.no_teleport_in_city',{city:isCity(c)?CITY[c].name:'?'});
if(!teleSees(c).some(id=>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].orb<SATS[y].orb)||SAT_PROV[SATS[x].p].pg-SAT_PROV[SATS[y].p].pg);}
// Why a circuit from teleport a to b over bird id (g Gbps, when given) cannot be ordered; '' when it can.
function satWhy(a,b,id,g){const B=own(SATS,id)?SATS[id]:null;if(!B||!isCity(a)||!isCity(b)||a===b)return tr('satellites.no_such_circuit');const O=SAT_ORB[B.orb];
if(lvl()<O.lv)return tr('satellites.orbit_unlocks_at_level',{orb:O.n,lv:O.lv});
if(!teleOf(a))return tr('satellites.no_teleport_in_city',{city:CITY[a].name});
if(B.orb==='meo'&&teleOf(a)<2)return tr('satellites.needs_tracking_antennas',{city:CITY[a].name});
if(!satRemote(b))return tr('satellites.not_remote',{city:CITY[b].name});
if(!satPairOk(id,a,b))return tr('satellites.out_of_footprint',{bird:B.n,a:CITY[a].name,b:CITY[b].name});
if(g!==undefined&&!O.g.includes(g))return tr('satellites.no_such_circuit');
const nt=noTalk(a,b);if(nt)return tr(nt);
if(!S.pops[b]){if(!cityOn(b))return popOffWhy(b);if(cnCity(b)&&!cnOk())return tr('pops_transit_ix.you_need_a_license_first_foreign');}
return '';}
// Where a teleport can reach: small islands and remote towns that one of its birds sees with it, your POPs first.
function satTargets(a){return CITIES.filter(C=>C.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;k<se.length;k++){const x=se[k],v=x.sv,m=x.sa||(x.sa=new Map());let a=m.get(ci);if(!a)m.set(ci,a=new Float64Array(1+v.length));
a[0]+=ok;for(let j=0;j<v.length;j++)if(v[j]>tl)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;j<v.length;j++)all+=sh[j];if(all<=1e-12)continue;
for(const [ci,x] of e.sa){let p=0;for(let j=0;j<v.length;j++)p+=sh[j]*x[1+j];LATP[ci]+=p;SATU[ci]+=all*x[0];}}}
// The share of city c's served traffic that rode a satellite in r (0 to 1).
const satShare=(r,c)=>r&&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;});}