seriesoftubes/src/agent/20-commands.js
jvanvik 7967a29083 Rent low-orbit satellite capacity from Starblink (#83)
A Starblink gateway on a teleport at a POP on your fiber (level 5, within
56 degrees of the equator) rents LEO circuits of 5 to 50 Gbps to small
islands and remote towns within 1,200 km: a bent pipe 550 km up, about
30 ms round trip, 3% of the service counted as bad, and no selective
network refuses it. LEO puts GEO and MEO circuits on the same pair on
standby and waits beside a cable. The gateway's Infra section shows its
POP's forwarding load and the fiber out of the city, the islands'
bottleneck. A rare solar storm (and Pie's own) puts LEO in safe mode for
a day or two. Once your own crust carries traffic Starblink sells nothing
new. Rule O8. Hooks for island Wi-Fi: leoReachLL, leoKmLL, leoMsLL.
2026-11-12 01:34:46 +01:00

715 lines
71 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ================= AGENT API: the command tables =================
Every action in ACT is in exactly one class (tests/mcp-commands.test.js fails otherwise, so a new action forces a
decision): API_CMD, a game command with typed arguments; API_VIEW, which changes only what is on screen; API_BOUND,
which only drafts an input another command reads; API_SESSION, which starts, retries or leaves a game or dismisses a
coaching screen; or API_DENY, never run by a tool. CMD fields: args [name, domain|'string'|'boolean'|'integer',
required]; bind(args) writes the UI a panel would set (bindsUI: the UI keys it touches, restored after a dry run);
open/dom: the window an input lives in and the fields that must exist before dispatch; pass(args) reshapes the args
for the action (confirmations); confirm 'arg' (passed through) or 'double' (the game arms a button first); decides
(may end in a question); reads 'modal' (the window's text is the report); watch (extra fingerprint paths, #name
filled from args); quote (the dry run, priced with the game's own helpers); doc. */
const API_CMD={
/* ---------- Pie in the Sky: the rocket company (Tier 1 in a new game, or a sandbox) ---------- */
pieFound:{args:[],watch:['pie'],quote:a=>({setup:piePrice(PIE_CO),monthly:PIE_CO_MO}),doc:'Found the rocket company. Needs Tier 1 (or a sandbox).'},
pieFactory:{args:[],watch:['pie'],quote:a=>({setup:piePrice(PIE_FAC)}),doc:'Build the pie factory: it bakes the satellites ("pies") that rockets carry.'},
piePad:{args:[['city','cityId']],watch:['pie'],doc:'Build a launch pad in a city. Pads near the equator lift more.'},
pieRd:{args:[['k','pieRdId']],watch:['pie'],quote:a=>({setup:piePrice(PIE_RD[a.k].cost)}),doc:'Fund rocket R&D: reuse (reusable boosters, cheaper launches) or heavy (a bigger rocket, after test flights).'},
pieLaunch:{args:[['rk','rocketId'],['cr','crustId']],watch:['pie'],doc:'Queue a launch of a rocket into a crust (an orbital shell). Insurance and lasers follow the Launch tab toggles (pieIns, pieLas).'},
pieDish:{args:[['city','cityId']],watch:['pie'],doc:'Build a pie dish (ground station) at one of your POPs. Needs landing rights in its country.'},
pieAnt:{args:[['id','entityId']],watch:['pie'],quote:a=>({setup:piePrice(PIE_ANT)}),doc:'Add an antenna to a pie dish (20 Gbps each, 16 at most).'},
pieLic:{args:[['cc','countryCode']],watch:['pie'],doc:'Buy or renew landing rights in a country, for its dishes and orbit customers.'},
pieSafe:{args:[],watch:['pie'],doc:'Toggle safe mode: pies ride out solar storms, carrying nothing meanwhile.'},
pieName:{args:[],watch:['pie'],doc:'Rename the rocket company to the next name on the list.'},
pieBid:{args:[['id','entityId'],['f','pieBidShare']],watch:['pie'],doc:'Bid in a Rural Digital Pie Fund auction, asking this share of the reserve. The lower ask wins.'},
pieExim:{args:[],watch:['pie','loans'],doc:'Take the Export-Import Pie Bank loan, with its space covenants.'},
pieSpatPick:{args:[['id','pieSpatId'],['c','pieSpatChoice']],watch:['pie'],doc:'Answer a geopolitical spat over orbit: choice 0 or 1, as its sheet offers.'},
downIx:{args:[['city','ixId']],watch:['ixp'],doc:'Step an exchange port down one size.'},
downT:{args:[['id','entityId']],watch:['transit.#id'],doc:'Step a transit port down one size (a LAG steps down together).'},
downP:{args:[['id','entityId']],watch:['pni.#id'],doc:'Step a PNI down one size. Not while an augment is on order.'},
/* ---------- footprint: buildings, routers, POPs ---------- */
buildPop:{args:[['city','cityId']],
quote:a=>({setup:popCost(a.city),blocked:[cityOn(a.city)?'':popOffWhy(a.city),cnCity(a.city)&&!cnOk()?tr('pops_transit_ix.you_need_a_license_first_foreign'):''].filter(Boolean)}),
doc:'Open a POP in a city you do not have one in. Costs popCost(city). Not in a retired small city (off the map in new games).'},
launchBB:{args:[['city','cityId']],watch:['pops.#city'],
quote:a=>({setup:bbCost(a.city)}),
doc:'Launch broadband to the eyeballs of a city you have a POP in. The core revenue source; one per POP.'},
ad:{args:[['city','cityId']],watch:['pops.#city'],
quote:a=>({setup:8000}),
doc:'A 30-day ad campaign that boosts eyeball growth in a broadband city.'},
addRouter:{args:[['city','cityId']],watch:['pops.#city'],
quote:a=>{const p=S.pops[a.city];return {setup:p?routerCost(p.rgen||0,p.routers||1):0};},
doc:'Add a router to a POP, up to RMAX. Cost rises with the model and the count.'},
rmRouter:{args:[['city','cityId']],watch:['pops.#city'],
quote:a=>{const p=S.pops[a.city];return {setup:-((p&&tradeIn(p.rgen||0,1))||0),blocked:p&&portsUsed(a.city)>portsMax(a.city,undefined,p.routers-1)?[tr('routing_and_routers.unplug_something_first_used_ports',{used:fmtPorts(portsUsed(a.city)),max:portsMax(a.city,undefined,p.routers-1)})]:[]};},
doc:'Remove a router and sell it on eBuy for a trade-in. Refused while the rest cannot carry the ports.'},
upRouter:{args:[['city','cityId'],['g','routerModel',false]],watch:['pops.#city'],
quote:a=>{const p=S.pops[a.city];if(!p)return {};const g=a.g===undefined?mainRG(RG[p.rgen||0].cls+1):+a.g;
return {setup:swapCost(a.city,g),blocked:[(!RG[g]||g===(p.rgen||0))?'no such model':modelFits(a.city,g)||''].filter(Boolean)};},
doc:'Swap every router in a city for another model. Omit g for the next class up. One swap per day per city.'},
addGen:{args:[['city','cityId']],watch:['pops.#city'],quote:a=>({setup:GEN_COST,monthly:GEN_MO}),
doc:'Install a generator, so a power cut does not take the POP out.'},
addSite:{args:[['city','cityId']],watch:['pops.#city'],quote:a=>({setup:SITE2_COST,monthly:SITE2_MO}),
doc:'Add a second building in the city, so one dark data centre does not take everything down.'},
rmSite:{args:[['city','cityId']],confirm:'double',watch:['pops.#city'],
doc:'Remove the second building. Every port, PNI and cache there moves back to site A.'},
decomGo:{args:[['cities','cityIdArray']],bindsUI:['decom'],bind:a=>{UI.decom=new Set((a.cities||[]).filter(c=>S.pops[c]));},
doc:'Close POPs: cancels their ports, links, peerings and customers. Refuses to close every POP you have. Irreversible.'},
/* ---------- upstream (transit) ---------- */
buyTransit:{args:[['city','cityId'],['net','netId'],['tier','portTier']],
quote:a=>({setup:PORT[a.tier].setup,monthly:PORT[a.tier].tmo}),
doc:'Order a transit port from a network that sells in that city. Billed monthly on the 95th percentile. A higher tier on an existing port upgrades it.'},
lagT:{args:[['id','entityId'],['d','step']],watch:['transit.#id'],
quote:a=>{const t=S.transit.find(x=>x.id===a.id);return {setup:a.d>0&&t?PORT[t.tier].setup:0};},
doc:'Add or remove one LAG member on a transit port, up to LAG_MAX. Adding charges another port setup.'},
cancelTransit:{args:[['id','entityId']],confirm:'arg',pass:a=>({id:a.id,ok:1}),
doc:'Cancel a transit port.'},
togglePrem:{args:[['id','entityId']],watch:['transit.#id'],
doc:'Turn the premium upstream product on or off, where the network sells one in that city.'},
cleanPipe:{args:[['id','entityId']],watch:['transit.#id'],
quote:a=>{const t=S.transit.find(x=>x.id===a.id);return t?{monthly:cleanMo(t)}:{};},
doc:'Add or remove the upstream DDoS-scrubbing add-on. Monthly.'},
/* ---------- exchanges ---------- */
buyIx:{args:[['city','ixId'],['tier','portTier'],['signed','boolean',false]],decides:true,
quote:a=>({setup:ixPortMo(a.city,a.tier),monthly:ixPortMo(a.city,a.tier),blocked:[portOk(ixCity(a.city),a.tier)?'':tr('actions.your_router_can_t_take_a',{port:PORT[a.tier].n})].filter(Boolean)}),
doc:'Take a port on an internet exchange. Monthly. At a De-Kicks exchange the first order returns a personalised quote to answer. A remote port (no POP) is possible at 10G over a fabric.'},
lagIx:{args:[['city','ixId'],['d','step']],watch:['ixn'],
doc:'Add or remove one LAG member on an IX port. Not on your own exchange.'},
cancelIx:{args:[['city','ixId']],confirm:'arg',pass:a=>({city:a.city,ok:1}),decides:true,
doc:'Leave an exchange; drops every peering session there. De-Kicks may answer with a retention offer.'},
rs:{args:[['city','ixId']],watch:['rs'],
doc:'Toggle the route-server session, which peers you with everyone on the server at once.'},
foundIx:{args:[['city','cityId']],watch:['myIx.#city'],quote:a=>({setup:MYIX_COST,monthly:MYIX_MO,blocked:[foundIxWhy(a.city)].filter(Boolean)}),
doc:'Found your own exchange in a city with no IX where you have a POP. Not in mainland China. Networks join over the following days.'},
myIxUp:{args:[['city','cityId']],watch:['myIx.#city'],
quote:a=>{const m=S.myIx[a.city];const f=m?(m.fab|0)+1:0,N=f<MYIX_FAB.length?MYIX_FAB[f]:null;return N?{setup:N.cost,monthly:N.mo}:{};},
doc:'Upgrade your own exchange\'s switch fabric. Each step has a level gate.'},
/* ---------- peering and PNIs ---------- */
peer:{args:[['city','ixId'],['net','netId']],
doc:'Ask one network at an exchange for a session. Rejected with the network\'s own reason if its policy says no.'},
unpeer:{args:[['city','ixId'],['net','netId']],
doc:'Drop a peering session.'},
peerAll:{args:[['city','ixId']],
doc:'Ask everyone at that exchange who would say yes. No effect if there is nobody new.'},
pni:{args:[['city','cityId'],['net','netId'],['tier','pniTier']],
quote:a=>{const t=a.tier===-1?0:a.tier,ex=S.pni.find(p=>p.city===a.city&&p.net===a.net),r=peerOk(a.net,'pni',a.city);
return {setup:a.tier===-1?PNI_G1_COST:(1500+PORT[t].setup/2)*((ex&&ex.n)||1),monthly:(a.tier===-1?Math.round(PORT[0].pni/2):PORT[t].pni)*((ex&&ex.n)||1),days:pniLead(a.net),
blocked:[r.ok?'':r.why,portOk(a.city,t)?'':tr('actions.your_router_can_t_take_a',{port:PORT[t].n}),
a.tier!==-1&&a.tier<pniMin(a.net)?tr('sites_peering_caches.net_does_not_do_port_pnis',{net:NET[a.net].name,port:PORT[t].n}):''].filter(Boolean)};},
doc:'Order a private interconnect. tier:-1 asks for the 1G courtesy PNI where a network offers one. Takes weeks to months; an existing PNI is augmented instead.'},
pniChase:{args:[['id','entityId']],watch:['pni.#id'],
doc:'Chase the provisioning ticket. 15% pulls the date in by 30 days; otherwise an excuse.'},
cancelPni:{args:[['id','entityId']],confirm:'arg',pass:a=>({id:a.id,ok:1}),
doc:'Cancel a PNI or its pending augment.'},
lagP:{args:[['id','entityId'],['d','step']],watch:['pni.#id'],
doc:'Add or remove a LAG member on a PNI, up to 8 per router at the POP (pniLagMax, at most PNI_LAG_MAX). Adding is an augment with a lead time.'},
sacrif:{args:[['id','entityId']],watch:['pni.#id'],
doc:'Mark a PNI sacrificial, so attack traffic is steered into it.'},
peerPol:{args:[['p','peerPolicy']],watch:['ppol'],
doc:'Set your published peering policy: open, selective or closed. It answers every peering request for you: open accepts everyone, selective takes small networks on the exchange and newcomers with an up-to-date PeeringDB, closed declines them all. The NOC log sums the week up.'},
/* ---------- caches ---------- */
cache:{args:[['city','cityId'],['net','netId']],
quote:a=>{const n=NET[a.net];return {monthly:n&&n.cache?CACHE_MO:0,
blocked:n&&n.cache&&(R.demTo[a.net]||0)<n.cache.min?[tr('sites_peering_caches.net_says_not_yet_send_them',{net:n.name,min:n.cache.min})]:[]};},
doc:'Ask a CDN to ship you a cache. Monthly. Rejected until you send that network enough traffic.'},
rmCache:{args:[['id','entityId']],
doc:'Send a cache box back.'},
cacheSite:{args:[['city','cityId'],['net','netId'],['s','site']],watch:['caches'],
doc:'Move one of that CDN\'s boxes to the other building.'},
/* ---------- backbone links ---------- */
buildLink:{args:[['a','cityId'],['b','cityId'],['tier','linkTier'],['cable','cableId',false],['route','string',false],['premiumCrossing','boolean',false]],
bindsUI:['pending','route','via','cnPrem'],
bind:a=>{UI.pending={a:a.a,b:a.b};UI.route=a.route||'';UI.via=a.cable||'';UI.cnPrem=!!a.premiumCrossing;},
pass:a=>({tier:a.tier}),
quote:a=>{const A=a.a,B=a.b,tier=a.tier;
if(!S.pops[A])return {blocked:[linkFromWhy(A)]};
if(!waveOk(A,B,tier))return {blocked:[tr('links.a_wave_wave_needs_need_at',{wave:LT[tier].n,need:waveNeed(tier)})]};
const sib=pairLinks(A,B).filter(l=>l.kind!=='vxc'&&l.kind!=='xp'&&l.kind!=='sat'),jn=sib.length?routeJoin(A,B):null,border=cnCity(A)!==cnCity(B);
const mult=(sib.length&&!(jn&&jn.k===(landTrenches(A,B)[0]||{}).k)?DIVERSE:1)*(border?3*((a.premiumCrossing&&(A==='hkg'||B==='hkg'))?1.6:1):1);
const wr=waveRoute(A,B,mult,border);if(!wr)return {blocked:[tr('links.no_cable_available_for_that_route')]};
const blocked=[],so=soldOut(A,B,tier,wr.cab);
if(so)blocked.push(tr('links.no_wave_capacity_on_this_route',{wave:LT[tier].n,why:tr(so.why),n:Math.max(1,so.until-S.day)}));
const w=subWaveWhy(tier,wr.km,wr.sub);if(w)blocked.push(tr('links.no_wave_waves_on_this_cable',{wave:LT[tier].n,why:w}));
return {setup:Math.round(waveMo(wr.km,wr.sub,tier)*wr.wm)+(S.pops[B]?0:popCost(B)),monthly:Math.round(waveMo(wr.km,wr.sub,tier)*wr.wm),blocked};},
doc:'Lease a wave from one of your POPs (a) to any city; opens a POP in b if there is none. A second wave on a pair costs 1.4x unless it joins an existing trench; cross-border into mainland China costs 3x. premiumCrossing applies only via Hong Kong.'},
upLink:{args:[['id','entityId'],['tier','linkTier']],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id);if(!l)return {};
const blocked=[waveOk(l.a,l.b,a.tier)?'':tr('links.a_wave_wave_needs_need_at',{wave:LT[a.tier].n,need:waveNeed(a.tier)})];
const w=subWaveWhy(a.tier,l.km,l.sub);if(w)blocked.push(tr('links.no_wave_waves_on_this_cable',{wave:LT[a.tier].n,why:w}));
return {monthly:Math.round(waveMo(l.km,l.sub,a.tier)*(l.mult||1)),blocked:blocked.filter(Boolean)};},
doc:'Upgrade a leased wave in place. Upward only, and only if the span and cable support it.'},
rmLink:{args:[['id','entityId']],confirm:'double',
quote:a=>{const l=S.links.find(x=>x.id===a.id);return {setup:-((l&&cabBack(l))||0)};},
doc:'Decommission a link. A cancelled own-cable build refunds part of the money. Irreversible.'},
setMetric:{args:[['id','entityId'],['v','metric']],watch:['pairMet'],
doc:'Routing preference for the city pair this link belongs to (not the link): prefer, normal, avoid, backup, or custom (then metricMode and metricSet tune the number).'},
setCarry:{args:[['id','entityId'],['on','boolean']],watch:['transit.#id'],
doc:'Turn a transit port\'s Carry here on or off: it pulls that carrier\'s traffic (and its customers\') across your network from POPs that have no port of that carrier. Prefer, Backup only and RouteScript still win.'},
setStandby:{args:[['id','entityId'],['on','boolean']],watch:['links.#id'],
doc:'Hold a link in reserve: its capacity fills last.'},
/* ---------- fabrics and VXCs ---------- */
buyNni:{args:[['city','cityId'],['prov','fabId'],['tier','nniTier']],
quote:a=>{const ex=nniPort(a.city,a.prov),n=ex?(ex.n||1):1,m=NNI[a.tier]?NNI[a.tier].mo*n:undefined;return {setup:m,monthly:m};},
doc:'Take a port on an interconnection fabric, at any port speed the router takes. Monthly, the first month up front. A higher tier upgrades every member of the port.'},
lagNni:{args:[['city','cityId'],['prov','fabId'],['d','step']],watch:['nni'],
quote:a=>{const pt=nniPort(a.city,a.prov),m=pt&&a.d>0&&NNI[pt.tier]?NNI[pt.tier].mo:0;return {setup:m,monthly:m};},
doc:'Add (d:1) or remove (d:-1) a member of the fabric port\'s LAG: same speed, one more router port, up to 8. Removing is rejected while the circuits would not fit.'},
rmNni:{args:[['city','cityId'],['prov','fabId']],
doc:'Give the fabric port back. Rejected while circuits still use it.'},
buyVxc:{args:[['a','cityId'],['b','cityId'],['prov','fabId'],['t','vxcTier']],
quote:a=>({monthly:vxcMo(kmBetween(a.a,a.b),isSub(a.a,a.b),a.t)}),
doc:'Buy a virtual circuit between two fabric ports. Up in 59 seconds, which is the joke.'},
upVxc:{args:[['id','entityId'],['t','vxcTier']],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id);return l&&l.kind==='vxc'?{monthly:vxcMo(l.km,l.sub,a.t)}:{};},
doc:'Grow a circuit. Needs headroom at both ends.'},
cancelVxc:{args:[['id','entityId']],confirm:'double',
doc:'Cancel a circuit; any remote IX ports it reached go with it.'},
setPref:{args:[['kind','connKind'],['id','entityId'],['v','egress']],watch:['transit.#id','pni.#id'],
doc:'Egress preference for one exit: high sends more traffic that way, low keeps it for backup.'},
siteSet:{args:[['k','connKind'],['id','entityId'],['s','site']],watch:['transit.#id','pni.#id'],
doc:'Put a transit port, PNI or IX port in building A, B or both. Choosing both with a single member adds a LAG member first, and charges for it.'},
/* ---------- teleports and satellite capacity (#83) ---------- */
teleBuild:{args:[['city','cityId']],watch:['pops.#city'],
quote:a=>({setup:TPORT_COST,monthly:TPORT_MO,blocked:[teleOf(a.city)?'there is a teleport here already':teleWhy(a.city)].filter(Boolean)}),
doc:'Build a teleport (a satellite gateway) at one of your POPs: it rents circuits on GEO birds to small islands and remote towns in their footprint. Refused where no satellite on sale at your level sees the city.'},
teleTrk:{args:[['city','cityId']],watch:['pops.#city'],
quote:a=>({setup:TRK_COST,monthly:TRK_MO,blocked:[teleOf(a.city)===2?'this teleport has tracking antennas already':trkWhy(a.city)].filter(Boolean)}),
doc:'Add tracking antennas to a teleport, so it can work the MEO ring (about 130 ms round trip instead of GEO\'s 600). Only within 50 degrees of the equator, where the ring is in view.'},
teleRm:{args:[['city','cityId']],confirm:'double',watch:['pops.#city'],
doc:'Close a teleport (and its LEO gateway). Refused while circuits still start there.'},
teleLeo:{args:[['city','cityId']],watch:['pops.#city'],
quote:a=>({setup:LEO_GW_COST,monthly:LEO_GW_MO,blocked:[leoGw(a.city)?'there is a LEO gateway here already':leoGwWhy(a.city)].filter(Boolean)}),
doc:'Host a Starblink LEO gateway at your teleport (level 5, a POP on your fiber or with transit, within 56 degrees of the equator): LEO circuits from it reach small islands and remote towns within 1,200 km, about 30 ms round trip. Refused once your own constellation carries traffic.'},
teleLeoRm:{args:[['city','cityId']],confirm:'double',watch:['pops.#city'],
doc:'Close a LEO gateway. Refused while LEO circuits still start there.'},
buySat:{args:[['a','cityId'],['b','cityId'],['bird','satBird'],['g','satG']],
quote:a=>{const ok=own(SATS,a.bird),mo=ok?satMo(a.bird,+a.g):0;return {setup:mo+(S.pops[a.b]||!CITY[a.b]?0:popCost(a.b)),monthly:mo,days:ok?leadDays(SAT_ORB[SATS[a.bird].orb].days):0,blocked:[satWhy(a.a,a.b,a.bird,+a.g)].filter(Boolean)};},
doc:'Rent a satellite circuit from your teleport in a to b (a small island or a remote town) on a bird that sees both: GEO 1-10 Gbps, MEO 2-20 with tracking antennas, LEO 5-50 from a LEO gateway within 1,200 km (about 30 ms round trip; it puts GEO and MEO circuits on the same pair on standby, and one ordered beside it waits on standby). The first month up front; builds a POP at b if there is none. Next to an existing link between the two it goes on standby, as backup; a link built later between the two puts it on standby too. Cancel with rmLink.'},
satSize:{args:[['id','entityId'],['g','satG']],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id&&x.kind==='sat'),g=+a.g,ok=!!l&&g!==l.g&&SAT_ORB[SATS[l.bird].orb].g.includes(g),mo=ok?satMo(l.bird,g):0;
return {setup:ok&&g>l.g?mo:0,monthly:mo,blocked:!l?['not a satellite circuit']:ok?[g>l.g&&leoLink(l)?leoGrowWhy(l):''].filter(Boolean):[tr('satellites.no_such_circuit')]};},
doc:'Resize a satellite circuit on the same bird. A bigger one pays its new month up front; a LEO circuit grows only while its gateway is on your fiber and your own constellation carries nothing.'},
/* ---------- dark fiber and own cable ---------- */
orderDf:{args:[['a','cityId'],['b','cityId'],['source','dfSource'],['system','systemId']],
bindsUI:['pending','dfSrc','dfSys'],bind:a=>{UI.pending={a:a.a,b:a.b};UI.dfSrc=a.source;UI.dfSys=a.system;},
quote:a=>{const A=a.a,B=a.b,sc=isSub(A,B)?subDfCable(A,B):null,km=sc?sc.km:kmBetween(A,B);
const building=a.source==='build'&&glassLvl()>=3&&!sc,sys=DF_SYS[a.system]&&DF_SYS[a.system].lvl<=glassLvl()?a.system:'lite';
const amps=ampCount(km),blocked=[];
if(!S.pops[A])blocked.push(linkFromWhy(A));
if(isSub(A,B)&&!sc)blocked.push(tr('fiber_modals.nobody_sells_dark_fiber_on_a'));
else if(uaePair(A,B))blocked.push(tr('fiber_modals.no_dark_fiber_inside_the_uae'));
else if(landX(A,B)&&cnCity(A)===cnCity(B))blocked.push(tr('fiber_modals.nobody_sells_one_fiber_pair_across'));
else if(!dfAllowed(A,B))blocked.push(tr('fiber_modals.dark_fiber_across_the_chinese_border'));
if(glassLvl()<2)blocked.push(tr('fiber_modals.dark_fiber_unlocks_at_customer_level'));
return {setup:(building?dfBuildCost(km):0)+DF_SYS[sys].cost+amps*AMP_COST+(S.pops[B]?0:popCost(B)),
monthly:(building?Math.round(km*0.15):dfLeaseMo(km))+amps*AMP_MO,days:building?dfBuildDays(km):30,blocked};},
doc:'Get dark fiber from one of your POPs (a): lease an IRU, dig your own (level 3+), or take a pair on a subsea cable; opens a POP in b if there is none. Then light it with a line system.'},
orderCable:{args:[['a','cityId'],['b','cityId'],['design','designId',false],['terminal','boolean',false],['engineering','boolean',false]],
bindsUI:['pending','seaDesign','seaterminal','seaengineering'],
bind:a=>{UI.pending={a:a.a,b:a.b};UI.seaDesign=a.design||'standard';UI.seaterminal=!!a.terminal;UI.seaengineering=!!a.engineering;},
quote:a=>{const why=linkFromWhy(a.a)||ownCabWhy(a.a,a.b);if(why)return {blocked:[why]};
const design=own(SEA_DESIGNS,a.design)?a.design:'standard',up={terminal:!!a.terminal,engineering:!!a.engineering};
const q=seaQuote(a.a,a.b,design,up),lack=seaLack(q.km,up);
return {setup:q.cost+(S.pops[a.b]?0:popCost(a.b)),monthly:ownCabMo(q.km),days:q.days,
blocked:lack.map(k=>k==='design'?tr('own_cable.this_design_s_route_is_km',{km:q.km.toLocaleString()})
:tr('own_cable.km_km_is_too_far_for',{km:q.km.toLocaleString(),what:lack.length>1?tr('own_cable.a_and_b',{a:tr(SUB_UPGRADES[lack[0]].n),b:tr(SUB_UPGRADES[lack[1]].n)}):tr(SUB_UPGRADES[lack[0]].n)}))};},
doc:'Commission your own submarine cable. A ship sails; it takes months. The most expensive thing in the game.'},
subUpgrade:{args:[['id','entityId'],['k','upgradeId']],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id);return l?{setup:subUpgradeCost(l,a.k),days:SUB_UPGRADES[a.k].days}:{};},
doc:'Add premium submarine terminals or extra optical engineering to your own subsea cable. Level 4+, once each.'},
crews:{args:[['id','entityId'],['all','boolean',false]],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id);if(!l)return {};const n=a.all?crewSteps(l):Math.min(1,crewSteps(l));return {setup:n*crewCost(l),days:n?l.ready-Math.max(crewFloor(l),l.ready-30*n):0};},
doc:'Pay for more crews on a cable build: 30 days off per step, down to half of the planned build at most.'},
addCh:{args:[['id','entityId'],['o','opticId']],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id);return l?{setup:chCost(l,a.o),blocked:[chWhy(l,a.o)].filter(Boolean)}:{};},
doc:'Light one channel on a dark-fiber span with a given optic; uses a spare from the shelf if you have one.'},
rmCh:{args:[['id','entityId'],['o','opticId']],watch:['links.#id'],
doc:'Unplug a channel; the optic goes on the spares shelf.'},
addPair:{args:[['id','entityId']],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id);return l?{setup:pairCost(l)}:{};},
doc:'Light another fiber pair on your own cable. ROADM system, finished construction, current pair full.'},
upSys:{args:[['id','entityId']],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id);return l?{setup:sysUpCost(l)}:{};},
doc:'Upgrade the line system: Rainbow to ROADMaster to C+L. Every channel goes down for a day.'},
regen:{args:[['id','entityId'],['d','step']],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id);return l&&a.d>0?{setup:regenAddCost(l)}:{setup:0};},
doc:'Add or remove a regeneration site on a terrestrial span, up to REGEN_MAX. Removing is refused if the optics then cannot reach.'},
spares:{args:[['id','entityId']],watch:['links.#id'],
doc:'Toggle keeping spare optics on site for this span, so a card failure is fixed in hours instead of days.'},
/* ---------- hardware ---------- */
hwLock:{args:[],quote:a=>({setup:hwLockCost()}),
doc:'Lock router, optic and build prices for a year, shortages included. Costs twice as much while a shortage runs.'},
buySpare:{args:[['o','opticId']],
quote:a=>({setup:optCost(a.o),blocked:[OPT[a.o]&&OPT[a.o].lvl>glassLvl()?tr('action_helpers.unlocks_at_customer_level_n',{n:OPT[a.o].lvl}):''].filter(Boolean)}),
doc:'Buy a spare optic for the shelf, up to 64 of a kind. The next channel of that type is then free of optic cost.'},
sellSpare:{args:[['o','opticId']],quote:a=>({setup:-spareValue(a.o)}),
doc:'Sell a spare on eBuy for 40% of list.'},
/* ---------- capacity broker ---------- */
listFiber:{args:[['id','entityId'],['w','integer'],['p','integer',false]],watch:['links.#id'],
doc:'List spare capacity on a dark-fiber span with a capacity broker as a standing listing: w alien waves, and p (own cables only) your spare fiber pair. The broker sells them off over time as carriers on that route want capacity; a busy route sells in days, a road to nowhere maybe once.'},
mktHold:{args:[['v','integer']],watch:['cm'],
doc:'Capacity market (Lambda Bazaar): the share of every fiber (0, 10, 25 or 50%) the broker never sells, kept for your own traffic.'},
mktCfg:{args:[['p','string'],['k','string'],['v','integer']],watch:['cm'],
doc:'Capacity market: for product p (spec = alien-wave spectrum, w100/w400 = managed 100G/400G waves carved from your lit capacity, iru = dark pairs on fiber you dug), set k: on (v 1 or 0: the broker lists it on every route by your thresholds), min (list only while the route wants at least v units; spec/w400 1,2,4,8, w100 1,4,8,16, iru 1,2) or floor (never sell below v% of list: 60, 80, 100, 120). Demand and prices move every day.'},
mktRoute:{args:[['k','string']],watch:['cm'],
doc:'Capacity market: toggle whether the broker trades on a route (k = the two city ids sorted and joined by |, e.g. ams|fra).'},
unlistFiber:{args:[['id','entityId']],watch:['links.#id'],
doc:'Take the listing down. What the broker already sold stays sold.'},
setChCount:{args:[['id','entityId'],['o','opticId'],['n','integer']],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id);return l?{setup:opticCountCost(l,a.o,a.n)}:{};},
doc:'Set how many channels of one optic model a dark-fiber span carries, in one change. Added optics come from the spares shelf when you have them (regen cards still cost their share); removed ones go back to the shelf.'},
xpBuild:{args:[['a','cityId'],['b','cityId'],['via','string'],['o','opticId']],
quote:a=>{const sp=xpParse(a.a,a.b,a.via);if(!sp||!OPT[a.o])return {setup:0,blocked:[tr('express.no_such_path')]};const old=xpFind(a.a,a.b,sp.map(s=>s.id));
return {setup:xpCost(sp,a.o,!old),blocked:[xpWhy(a.a,a.b,sp,a.o)].filter(Boolean)};},
doc:'Light an express lightpath from a to b straight through the ROADMs of the cities between: via is the ids of your ROADM dark fibers (land, own or IRU) in order from a, comma-separated, 2 to 6 of them. One optic, one channel slot on every fiber, ports only at a and b, and the light must reach the whole run between regen sites. The same path again adds a channel to that express. Give one up with rmLink.'},
xpCh:{args:[['id','entityId'],['o','opticId'],['d','step']],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id),sp=l&&l.kind==='xp'&&xpSpans(l);if(!sp||!OPT[a.o]||a.d<0)return {setup:0};return {setup:xpCost(sp,a.o,false),blocked:[xpWhy(l.a,l.b,sp,a.o)].filter(Boolean)};},
doc:'Add (d:1) or unplug (d:-1) one channel of an optic on an express lightpath; unplugged optics go on the spares shelf. The last channel stays: rmLink gives the express up.'},
/* ---------- customers ---------- */
accept:{args:[['id','entityId']],
doc:'Sign a pending offer. Rejected without a POP in every city it needs, without the IPv4 addresses it needs (rule ip4: see the bank\'s Address space), without free channels for a wave sale, or after an event\'s start date. Extra waves for a carrier you already serve grow that contract.'},
acceptFix:{args:[['id','entityId'],['cost','integer',false]],watch:['pops','biz','offers'],
quote:a=>{const q=S?reqFix(S.offers.find(x=>x.id===a.id)):null;return q?{setup:q.cost,monthly:q.mo}:{setup:0};},
pass:a=>({id:a.id,cost:a.cost??((reqFix(S.offers.find(x=>x.id===a.id))||{}).cost)}),
doc:'Buy what an offer asks for at POPs you already have (backup generator, a second router, a second site), then sign it. Pass the quoted setup as cost; the game checks it still matches (within 1%: hardware prices drift by the day).'},
decline:{args:[['id','entityId']],
doc:'Throw an offer away.'},
salesHire:{args:[['id','salesPersona']],
doc:'Put one salesperson at the sales desk: eng (engineer turned salesdroid: books every NOG at the usual ticket price, more small and mid deals, never the huge ones, customers stay longer), shark (bigger deals at higher prices plus a month of commission, oversells promises, no nerdy customers, peering desks want more traffic) or ceo (free, signs huge discounted deals on the golf course, sometimes signs what you declined, cannot be fired). One at a time; from customer level 2.'},
salesFire:{args:[],confirm:'double',
doc:'Let the salesperson go (not the CEO: ask the board for a VP of Sales instead).'},
salesVp:{args:[],
doc:'With the CEO running sales: pay for a board meeting that brings a VP of Sales, who frees the desk a month later.'},
salesAuto:{args:[],watch:['slAuto'],
doc:'With someone at the sales desk: switch automatic signing on or off. Once a game day they sign the offers that fit, in their own style: eng and ceo after a routing trial (one a day; an offer that did not fit waits a week), shark every offer whose POPs are up, promises and all, while the cash covers the commission. Orbit offers sign where the landing dish has room (the shark ignores that). Nobody at the desk: nothing is signed for you.'},
salesRen:{args:[],watch:['slAuto'],
doc:'Switch whether the sales desk answers renewal haggles for you, 3 days after each opens (only while someone runs sales). The engineer gives business customers their discount and keeps nerdy ones at the market price; the shark holds the old price (sometimes with a new promise, billing a month of the saving) but some walk; the CEO gives 10% more off for a double term, says yes, or picks a fight and loses them.'},
salesMin:{args:[],watch:['slAuto'],
doc:'Step the minimum monthly value under which the sales desk declines offers: never, 2k, 5k, 10k, 25k, 50k. With the CEO, about one decline in three is signed anyway.'},
renewMatch:{args:[['id','entityId']],watch:['biz.#id'],
doc:'Answer a renewal haggle (a customer with hag): renew at the price they asked. Unanswered, this happens on its own when the term ends.'},
renewMeet:{args:[['id','entityId']],watch:['biz.#id'],
doc:'Answer a renewal haggle by meeting halfway between their price and today\'s market price. They accept about two times in three; otherwise they leave.'},
renewLet:{args:[['id','entityId']],
doc:'Answer a renewal haggle by letting the customer go now.'},
dropBiz:{args:[['id','entityId']],confirm:'double',
doc:'Terminate a signed customer. Rejected once an event contract\'s event has started.'},
setRoute:{args:[['id','entityId'],['m','routeMode']],watch:['biz.#id'],
doc:'How a customer\'s traffic is routed: normal follows metrics, fast takes the lowest latency, scenic the quietest links. Clears a pinned path.'},
pathMove:{args:[['id','entityId'],['link','entityId']],watch:['biz.#id'],
doc:'Move a fiber customer (alien wave, dark fiber pair, fiber pairs) to another working fiber between the same two cities. Free. Rejected if that fiber has no room for it.'},
pathPin:{args:[['id','entityId'],['via','string']],watch:['biz.#id'],
doc:'Pin a circuit to a path: via is its city ids in order, comma-separated, from the customer\'s city to its city2, every hop a working link. Free. While a link on it is down the circuit follows routing.'},
pathAuto:{args:[['id','entityId']],watch:['biz.#id'],
doc:'Unpin a circuit, so routing chooses its path again.'},
/* ---------- traffic engineering ---------- */
buyTE:{args:[],quote:a=>({setup:TE_COST,monthly:TE_MO,blocked:coreTE()||(S&&S.te)?[]:[tr('core.auto_te_needs_an_rsvp_te_or')]}),
doc:'Buy the Auto-TE controller, which spills overflow onto alternate paths. Level 3+, and it needs an RSVP-TE-or-higher backbone.'},
teToggle:{args:[],watch:['te'],
doc:'Turn Auto-TE on or off.'},
teCheck:{args:[['script','string']],open:'teEdit',dom:['teSrc'],reads:'modal',
bind:a=>{$('teSrc').value=String(a.script);},
doc:'Parse and dry-run a RouteScript without deploying it. The parse errors, or served traffic and transit cost before and after, come back as the report. No state change.'},
teDeploy:{args:[['script','string']],open:'teEdit',dom:['teSrc'],watch:['te'],
bind:a=>{$('teSrc').value=String(a.script).slice(0,4000);},
quote:a=>({setup:0}),
doc:'Deploy a RouteScript, up to 4000 characters. Rejected with the parse errors. A deploy that cuts traffic by more than 10% says so in messages.'},
teClear:{args:[],watch:['te'],
doc:'Delete the script and fall back to plain Auto-TE.'},
traceRun:{args:[['from','cityId'],['to','traceTo']],open:'trace',dom:['trFrom','trTo'],reads:'modal',
bind:a=>{$('trFrom').value=a.from;$('trTo').value=(NET[a.to]?'net:':'city:')+a.to;},
doc:'Run a traceroute to a network or one of your own POPs. The hops come back as report text; they are not stored in the game state.'},
/* ---------- money ---------- */
takeLoan:{args:[['id','entityId']],
doc:'Accept a loan offer. Terms vary wildly by bank; the crypto one pays out 55-135% of face value. Equity banks take a share of the company.'},
callBank:{args:[['amount','callAmount']],watch:['loanOffers'],
doc:'Call a bank for a loan offer of this size, with a credit rating of AA or better (weird conditions apply). The terms follow from the rating, and the amount must fit the limit of a few months of revenue less current debt. Nothing is borrowed until you take the offer.'},
declineLoan:{args:[['id','entityId']],
doc:'Throw a loan offer away.'},
repayLoan:{args:[['id','entityId']],confirm:'double',
quote:a=>{const l=S.loans.find(x=>x.id===a.id);return l?{setup:repayCost(l,BANKS[l.bank])}:{};},
doc:'Repay a loan early, or buy an equity investor out.'},
/* ---------- address space (IPv4, rule ip4: On-call and BGP at 3 a.m.) ---------- */
ip4Buy:{args:[['len','ip4Len']],watch:['ip4'],
quote:a=>({setup:ip4Cost(Number(a.len)),blocked:[ip4On()?'':tr('ip4.off'),ip4On()&&ip4Full()?tr('ip4.too_many',{n:IP4_BLK}):''].filter(Boolean)}),
doc:'Buy an IPv4 block of this prefix length (24 = 256 addresses up to 16 = 65,536) on the transfer market at today\'s price. It can be sold again two years after this transfer. A network holds at most 256 blocks, bought, leased in and from the registry together.'},
ip4Lease:{args:[['len','ip4Len']],watch:['ip4'],
quote:a=>({setup:0,monthly:ip4InMo(Number(a.len)),blocked:[ip4On()?'':tr('ip4.off'),ip4On()&&ip4Full()?tr('ip4.too_many',{n:IP4_BLK}):''].filter(Boolean)}),
doc:'Lease an IPv4 block of this prefix length by the month, at today\'s rate (fixed for the lease). Hand it back with ip4Return. Refused at 256 blocks, like ip4Buy.'},
ip4Sell:{args:[['id','entityId']],confirm:'double',watch:['ip4'],
doc:'Sell an owned block (not leased out) for 92% of the market price. Refused within two years of its last transfer, or when the customers signed would no longer fit with every dual-stack home behind CGNAT and the IPv6-only homes in the NAT64 pool.'},
ip4Out:{args:[['id','entityId']],watch:['ip4'],
doc:'Lease an owned block out through a broker for a monthly income, while your own customers still fit without it.'},
ip4Back:{args:[['id','entityId']],watch:['ip4'],
doc:'End the lease of a block you leased out; its addresses are yours to use again.'},
ip4Return:{args:[['id','entityId']],watch:['ip4'],
doc:'Hand a leased-in block back, ending its monthly fee, when your customers still fit without it.'},
ip4Nat:{args:[['v','ip4Ratio']],watch:['ip4'],
doc:'Set how many broadband homes share one IPv4 address behind CGNAT (8, 16, 32 or 64). More frees space for business customers but more gamers ask for refunds; fewer is refused when the customers signed would not fit.'},
ip4Nat64:{args:[['v','ip4Ratio64']],watch:['ip4'],
doc:'Set how many IPv6-only homes share one IPv4 address in the NAT64 pool (64, 128 or 256). Their refunds are well under CGNAT\'s at the same ratio and shrink as the world moves to IPv6; fewer is refused when the customers signed would not fit.'},
ip6Go:{args:[['city','cityId']],watch:['pops.#city'],
quote:a=>({setup:ip6Cost(a.city),days:ip6Days(a.city),monthly:Math.round(ip6Mo(a.city,(R.rev&&R.rev.eyeballs)||0)),blocked:[ip6Why(a.city)].filter(Boolean)}),
doc:'Take a broadband city IPv6-only (464XLAT): swap its dual-stack home routers for ones with a CLAT over the quoted days, paid day by day as they go in (setup is the whole swap; starting needs only the first day\'s share on hand, and it waits while cash is short). Those homes then need no IPv4 of their own, only a share of the NAT64 pool; new homes there get the new router too, at the swap\'s price a router, paid the day they join (even short of cash: a new home needs it). monthly is what it does to the IPv4 bill (NAT64 gateways and refunds against the CGNAT it saves; negative saves). Frees what the city panel says for new customers.'},
ip6Stop:{args:[['city','cityId']],watch:['pops.#city'],
doc:'Stop a city\'s swap to IPv6-only. The homes already swapped stay IPv6-only (their routers are paid for, nothing comes back); new homes come dual stack again. ip6Go resumes it for the rest.'},
/* ---------- security, China, incidents ---------- */
buildScrub:{args:[['city','cityId'],['tier','scrubTier',false]],watch:['scrubs'],
quote:a=>{const T=SCRUB_TIERS[a.tier||0];return {setup:T?T.cost:undefined,monthly:T?T.mo:undefined};},
doc:'Build a scrubbing centre: 100G, 1T, 10T or 100T. Level-gated per tier; one per city.'},
scrubUp:{args:[['city','cityId'],['tier','scrubTier']],watch:['scrubs'],
quote:a=>({setup:Math.round(SCRUB_TIERS[a.tier].cost*0.6)}),
doc:'Upgrade a scrubbing centre, at 60% of the tier price. Upward only.'},
rmScrub:{args:[['city','cityId']],confirm:'double',watch:['scrubs'],
doc:'Tear a scrubbing centre down.'},
scrubMode:{args:[],watch:['scrubMode'],
doc:'Switch scrubbing between always-on and on-demand.'},
rtbh:{args:[['id','entityId',false]],watch:['ev'],
doc:'Announce a remote-triggered blackhole for the target under attack: it goes dark at your transits, most exchanges and about half your private peers, and everyone else is saved. Withdraw with unrtbh.'},
unrtbh:{args:[['id','entityId',false]],watch:['ev'],
doc:'Withdraw the blackhole.'},
ddosEngage:{args:[['id','entityId',false]],watch:['ev'],
doc:'Engage on-demand scrubbing now: start the diversion to the nearest active scrubbing centre instead of waiting for it to engage by itself.'},
ddosAuto:{args:[['k','ddosKey']],watch:['ddosAuto'],
doc:'Flip a NOC auto-mitigation switch: rtbh blackholes the target of a flood on its own, scrub engages on-demand scrubbing.'},
ddosTest:{args:[],watch:['ev'],
doc:'Sandbox only: send yourself a test flood, to try the tools on.'},
hackback:{args:[['id','entityId',false]],watch:['ev'],quote:a=>({setup:20000}),
doc:'Fire the Hackback 3000(tm) at the botnet. 35% it ends the attack; otherwise a fine and a story.'},
applyCn:{args:[],watch:['cnLic'],quote:a=>({setup:CN_LIC,days:45}),
doc:'File for a mainland China licence through a local partner. Required before a POP in mainland China. 45 days.'},
fixInc:{args:[['id','entityId']],watch:['inc'],
quote:a=>{const i=S.inc.find(x=>x.id===a.id);return i&&i.cost>0?{setup:i.cost}:{};},
doc:'Pay to rush a repair. A slow router reboot is cut to one day; anything else clears immediately.'},
/* ---------- conferences ---------- */
confGo:{args:[['key','confKey']],watch:['confReg'],
quote:a=>{const cf=upcomingConfs(75).find(x=>x.key===a.key);return cf?{setup:confCost(cf)}:{};},
doc:'Register for an upcoming conference. Keys come from catalog(\'conferences\'). Peering gets easier in that region for 45 days. Capacity conferences need level 3.'},
confSponsor:{args:[['key','confKey']],watch:['confReg'],
quote:a=>{const cf=upcomingConfs(75).find(x=>x.key===a.key);return cf&&confSp(cf)?{setup:CONF_SP-(S.confReg&&S.confReg[a.key]?CONF_COST:0)}:{};},
doc:'Sponsor it instead: your logo on every lanyard, a bigger effect, a bigger bill. Only where sponsorships are offered; upgrades an existing registration for the difference.'},
/* ---------- the NOC intern (standing orders) ---------- */
opsHire:{args:[['id','internId']],quote:a=>({setup:INTERN_MO}),watch:['ops'],
doc:'Hire the NOC intern. They run your standing orders once a game day and cost a salary a month. Level 2+, and only in a game with a clock.'},
opsFire:{args:[],confirm:'double',watch:['ops'],
doc:'Let the intern go. The standing orders stop; the rest of the month\'s salary is lost.'},
opsToggle:{args:[['k','opsKey']],watch:['ops'],
doc:'Pause or resume one standing order. Keys come from catalog(\'OPSK\'); the sheet in the game shows what each one does.'},
opsParam:{args:[['k','opsKey'],['p','string'],['v','string',false]],watch:['ops'],
// The routers order's model and the optup order's line system were settings once: they are the build standard's now.
pass:a=>{const b={routers:{model:'g'},optup:{sys:'sys'}}[a.k],t=b&&b[a.p];
if(t)throw new Error(`the ${a.k} order takes its ${t==='g'?'router model':'line system'} from the build standard: set it with bstdSet (k "${t}")`);return a;},
doc:'Step one of a standing order\'s settings to its next value (the provider to prefer, the port size to order, the load ceiling…). With v (a position in the list the sheet shows, 0 first) it picks that value instead. The routers order\'s model and the optup order\'s line system are not settings: both orders take them from the build standard (bstdSet k "g" and k "sys"; "keep" leaves them to the next model or line system up, when needed).'},
opsCap:{args:[['k','opsKey'],['v','string',false]],watch:['ops'],
doc:'Step the monthly budget of an order that has one: 10k, 50k, 250k, 1M, 5M, no limit (for caches, a cap on the rent it adds: 1k, 2.5k, 5k, 10k, 25k, no limit). With v (a position in that list, 0 first) it picks that one.'},
opsFloor:{args:[['v','string',false]],watch:['ops'],
doc:'Step the floor under your cash that the intern keeps clear when paying for jobs: 0, 50k, 250k, 1M, 5M. With v (a position in that list, 0 first) it picks that one.'},
opsPop:{args:[['k','opsPopKind'],['city','cityId']],watch:['ops'],
doc:'Add or remove one POP as an exception to an order: the intern never touches the POPs you except.'},
opsTpl:{args:[['k','opsTplKey']],watch:['ops'],
doc:'Toggle a piece of the one-tap new-POP template: broadband, a transit port, an IX port, the redundancy kit.'},
opsNewPop:{args:[['city','cityId']],watch:['pops.#city'],
quote:a=>{const q=S&&S.ops?opsTplQuote(a.city):null;return q?{setup:q.cost}:{};},
doc:'Open a city from the template in one go: the POP, then broadband, transit, an IX port and the redundancy kit as the template says — all or nothing on the price.'},
/* ---------- the bulk PNI order ---------- */
pniAll:{args:[['net','pniAllNet'],['tier','pniTier'],['q','shownTotal',false]],
quote:a=>{const b=pniBatch(a.net,a.tier);return b?{setup:b.cost,monthly:b.mo,blocked:(b.blocked||[]).map(q=>q.why).filter(Boolean)}:{};},
watch:['pni'],
doc:'Order PNIs with one network (net) or every network (net:null) at all shared POPs: missing connections are added, smaller ones upgraded, each at its own minimum size. The quote is the batch total, lead times as for one PNI. q (optional): the total you were shown; a different one now is refused and the sheet shown again.'},
/* ---------- backbone technology ---------- */
coreUp:{args:[],watch:['core'],
quote:a=>{const n=S&&S.core?S.core.lv+1:1;return n<=4?{setup:CORE_COST[n],blocked:[(lvl()||1)<CORE_REQ[n]?tr('core.needs_customer_level_n',{n:CORE_REQ[n]}):''].filter(Boolean)}:{};},
doc:'Buy the next backbone technology: IGP, LDP/MPLS, RSVP-TE, SR-MPLS, SRv6. One step at a time, level-gated; each step passes transit through a POP cheaper and RSVP-TE or higher unlocks Auto-TE.'},
coreLab:{args:[],watch:['core'],quote:a=>({setup:CORE_LAB}),
doc:'Build the interop lab in the NOC: it tests your vendors against each other first and cuts interop incidents by 60%.'},
coreSet:{args:[['v','integer']],watch:['core'],
doc:'Run the backbone at any level already paid for, 0 up to the highest bought.'},
/* ---------- the specialist's offers ---------- */
demoAsk:{args:[['k','string'],['id','string']],watch:['demo'],
doc:'Ask a vendor for a demo unit: a router, line system or optic one level above yours, delivered in about two weeks, at 60% over list until your level catches up. k and id name the thing (as the game\'s buttons pass them).'},
seatBuy:{args:[['n','seatPairs']],decides:true,watch:['seatOff','links'],
quote:a=>{const o=S&&S.seatOff;if(!o||!SEAT_N.includes(a.n))return {};const miss=[o.a,o.b].filter(c=>!S.pops[c]);
return {setup:seatCost(o.km,a.n)+miss.reduce((x,c)=>x+popCost(c),0),days:seatDays(o.km)};},
doc:'Take the consortium cable offer: own 1, 2 or 4 fiber pairs on a new subsea cable for your share of the build, and light them with your own optics. POPs open at both landings if you have none.'},
seatNo:{args:[],watch:['seatOff'],
doc:'Decline the consortium cable offer.'},
charter:{args:[['k','charterKey']],watch:['charter'],
doc:'Sign the charter a new normal game asks for before anything else (the player sees a popup until it is signed): global backbone (the classic game), low-latency boutique (trading firms pay 40% more, and it has its own win) or broker (dark fiber, line systems, optics and own subsea cables from day one at the usual prices, its own goals and its own win, Glass Baron). One choice per network, normal games only.'},
mkBanana:{args:[],watch:['monkey'],
quote:a=>({setup:mkBananaCost()}),
doc:'Throw the chaos monkey a banana and it leaves early. Only while it is in your network; the price scales with your revenue.'},
/* ---------- link tools ---------- */
metricMode:{args:[['id','entityId'],['k','metricKind']],watch:['pairMet'],
doc:'Set the custom routing metric of a link\'s city pair as a factor (k:"f", the preset way) or an exact cost weight (k:"w"). Starts from the current preset\'s value; edit the number with metricSet.'},
metricSet:{args:[['id','entityId'],['v','string']],dom:['metIn'],watch:['pairMet'],
bind:a=>{$('metIn').value=String(a.v);},
doc:'Write the custom metric\'s number for the link\'s city pair, in the mode metricMode set. Select the link first (view.selLink), so the panel is showing the input.'},
seaRush:{args:[['id','entityId'],['all','boolean',false]],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id);if(!l)return {};const k=prepSteps(l),n=a.all?k:Math.min(1,k);return {setup:n*prepCost(l),days:Math.min(n*PREP_STEP,Math.max(0,l.ready-prepFloor(l)))};},
doc:'Hurry the survey, permits and factory of your own subsea cable before laying starts: 30 days sooner per step (all: as fast as money goes), never sooner than the factory can make the cable.'},
layShip:{args:[['id','entityId']],watch:['links.#id'],
quote:a=>{const l=S.links.find(x=>x.id===a.id),q=l&&layQuote(l);return q?{setup:q.cost}:{};},
doc:'Book a second lay ship on your own cable before laying starts: it lays from the other end and halves that part of the build.'},
/* ---------- the build standard ---------- */
popStdSet:{args:[['city','cityId']],watch:['popStd'],
doc:'Make a POP\'s build the standard\'s POP part: its router model, router count, second building and generator. New POPs start with them at once; the other targets are kept.'},
popStdClear:{args:[],watch:['popStd'],
doc:'Clear the whole build standard; new POPs go back to one basic router.'},
bstdSet:{args:[['k','bstdKey'],['v','string',false]],watch:['popStd'],
doc:'Set one target of the build standard: g router model, rt routers, site2 second building, gen generator, v6 every broadband city IPv6-only (ip6Go, only while IPv4 is scarce: rule ip4), lag LAG members on transit, IX and PNI ports, split LAGs across both buildings, ix an IX port wherever the city has an exchange, pni PNIs per network in at least that many cities, sys line system, opt fastest optics, wv waves at least that size. g and sys are also what the intern\'s routers and optup orders standardize on. Without v it steps to the next value; with v (a position in the list the sheet shows, 0 first, "keep" first) it picks that one.'},
bstdApply:{args:[['quote','string',false],['q','shownTotal',false]],watch:['pops','transit','pni','ixp','ixn','ixSite','links','spares'],
quote:a=>{const q=bstdQuote(false),nm=w=>w.split('|').map(c=>CITY[c].name).join('–');return {setup:q.cost,monthly:q.mo,key:bstdPlanKey(bstdPlan(false)),
blocked:[...q.wait.map(w=>nm(w)+': its line system waits until the fiber is quiet or a parallel link can carry its load for the day it goes dark'),
...q.wv.map(w=>nm(w)+': its line system waits: a customer\'s wave rides it and would go dark with it for the day (upSys on the fiber still swaps it)')]};},
doc:'Bring everything up to the build standard now, the busiest first, while cash lasts: routers, buildings, generators, IPv6-only swaps (the cities with the most dual-stack homes first; each priced as its whole swap, paid as the routers go in, and started only with that much cash on top of what the swaps under way still owe), LAG members, IX ports, PNIs, line systems, optics and waves. A line-system swap waits unless the fiber is quiet or a parallel link carries its load, and while a customer\'s alien or managed wave rides the fiber (leased pairs and IRUs do not count: they are glass): such a fiber gets the best optics its line system takes, and the quote lists it under blocked. The quote is the whole bill. quote and q (optional): the plan\'s key and the total you were shown; another plan, or a total more than 1% away, is refused and the sheet shown again.'},
/* ---------- utilities ---------- */
utilityRouteServers:{args:[['city','cityId',false]],watch:['rs'],
doc:'Join the route server at every IX you have a port at. One call does what the button does.'},
utilityKit:{args:[['city','cityId'],['cost','integer',false]],watch:['pops.#city','caches'],
quote:a=>{const q=S?utilityKit(a.city):null;return q?{setup:q.cost,monthly:q.mo}:{};},
pass:a=>({city:a.city,cost:a.cost??((utilityKit(a.city)||{}).cost)}),
doc:'Install the POP redundancy kit in one go: generator, second building, a second router, and the cache boxes balanced between sites. Pass the quoted setup as cost; the game checks it still matches (within 1%: hardware prices drift by the day). Nothing to do reads as no_effect.'},
utilityKitAll:{args:[['cost','integer',false],['city','cityId',false]],watch:['pops','caches'],
quote:a=>{const q=S?utilityKitAll():null;return q?{setup:q.cost,monthly:q.mo}:{setup:0};},
pass:a=>({city:a.city,cost:a.cost??((utilityKitAll()||{}).cost)}),
doc:'Install the redundancy kit at every POP still missing part of it, at one quoted price. From customer level 2. Pass the quoted setup as cost; the game checks it still matches (within 1%).'},
utilityKitNew:{args:[['city','cityId',false]],watch:['ops'],
doc:'Put the redundancy kit in the intern\'s new-POP template, or take it out (the same switch as in the Ops sheet).'},
ptSave:{args:[['city','cityId'],['k','popTier']],watch:['popTiers'],
doc:'Save a POP\'s routers (model and count) as one of three POP standards: micro, medium or hub. The POP is marked as that kind. From customer level 2.'},
ptApply:{args:[['city','cityId'],['k','popTier'],['cost','integer',false]],watch:['pops.#city','popTiers'],
quote:a=>{const q=S?ptPlan(a.city,a.k):null;return q?{setup:q.cost,monthly:q.mo,blocked:q.why?[q.why]:[]}:{setup:0};},
pass:a=>({city:a.city,k:a.k,cost:a.cost??((S&&ptPlan(a.city,a.k))||{cost:0}).cost}),
doc:'Mark a POP as one kind and bring its routers up to that standard: add routers, swap to the standard\'s model if it is bigger. Never a step down. Pass the quoted setup as cost; the game checks it still matches (within 1%), and 0 only marks a POP that already meets it.'},
ptAll:{args:[['k','popTier'],['cost','integer',false],['city','cityId',false]],watch:['pops','popTiers'],
quote:a=>{const A=S?ptAll(a.k):null;return A?{setup:A.cost}:{setup:0};},
pass:a=>({k:a.k,city:a.city,cost:a.cost??(ptAll(a.k)||{}).cost}),
doc:'Bring every POP marked as one kind up to that standard, at one quoted price. Pass the quoted setup as cost; the game checks it still matches (within 1%).'},
utilityCaches:{args:[['city','cityId'],['quote','string',false]],watch:['caches'],
quote:a=>{const q=S?utilityCaches(a.city):null;return q?{key:q.key}:{};},
pass:a=>({city:a.city,quote:a.quote??((utilityCaches(a.city)||{}).key)}),
doc:'Request a cache from each eligible provider at each site of the city, as many as demand asks for. Pass the quote\'s key back; the game checks the list has not moved under it.'},
utilityPeers:{args:[['city','cityId',false]],watch:['peers'],
doc:'Request peering with every eligible peer across every IX you have joined.'},
/* ---------- renaming ---------- */
renameGo:{args:[['name','string']],open:'rename',dom:['rnIn'],watch:['name'],
bind:a=>{$('rnIn').value=String(a.name).slice(0,24);},
doc:'Rename your network. act opens the menu\'s rename sheet and types the name in; it is trimmed to 24 characters.'},
/* ---------- puzzles and architect runs ---------- */
pzLinkTo:{args:[['a','cityId'],['b','cityId']],bindsUI:['pending'],decides:true,watch:['links'],
bind:a=>{UI.pending={a:a.a,b:a.b};},
doc:'Puzzles only: open the link picker between two cities. Answer the decision with pzLink.'},
pzLink:{args:[['tier','pztTier']],watch:['links'],
doc:'Puzzles only: light the pending link (from pzLinkTo) at a tier, on the picked route, in the picked trench.'},
pzTier:{args:[['id','entityId'],['tier','pztTier']],watch:['links.#id'],
doc:'Puzzles only: change a link\'s wave size.'},
pzRmLink:{args:[['id','entityId']],watch:['links.#id'],
doc:'Puzzles only: tear a link down.'},
pzPop:{args:[['city','cityId']],watch:['pops.#city'],
doc:'Puzzles only: open a POP in a puzzle city.'},
pzRmPop:{args:[['city','cityId']],watch:['pops.#city'],
doc:'Puzzles only: close a POP and the links that reach it.'},
pzRtAdd:{args:[['city','cityId']],watch:['pops.#city'],
doc:'Puzzles only: add a router to a POP, up to RMAX.'},
pzRtRm:{args:[['city','cityId']],watch:['pops.#city'],
doc:'Puzzles only: remove a router, if the ports still fit.'},
pzRtModel:{args:[['city','cityId'],['g','pzRouterModel']],watch:['pops.#city'],
doc:'Puzzles only: swap every router in a POP for another model.'},
pzRoute:{args:[['i','integer'],['m','pzRouteMode']],watch:['biz'],
doc:'Puzzles only: send one flow (index i, as state(\'biz\') lists them) along the metrics or the lowest-latency path.'},
pzUndo:{args:[],watch:['pops','links','pairMet'],
doc:'Puzzles only: undo the last build step, up to sixty of them.'},
pzReset:{args:[],watch:['pops','links','pairMet'],
doc:'Puzzles only: clear the whole build and start the puzzle over.'},
pzArGo:{args:[],watch:['ar'],
doc:'Architect runs only: run the chaos monkey\'s review of this brief, every tube snipped in turn.'},
pzArSkip:{args:[],watch:['ar'],
doc:'Architect runs only: fast-forward the review to the first cut that hurts.'},
pzArNext:{args:[],watch:['ar'],
doc:'Architect runs only: pass the review and sign the next brief. Rejected while the current one does not pass.'},
/* ---------- answering decisions ---------- */
dkAccept:{args:[],watch:['dk'],
doc:'Take the De-Kicks quote as offered and order the port.'},
dkHaggle:{args:[],watch:['dk'],
doc:'Haggle. 45% a better price, 30% a worse one, 25% sales stops returning your calls for a few days. Three attempts.'},
dkWalk:{args:[],watch:['dk'],
doc:'Walk away; the quote is remembered for 90 days.'},
dkStay:{args:[['city','ixId']],watch:['dk'],
doc:'Take the retention discount instead of leaving: 40% off for six months.'},
dkOptOut:{args:[['city','ixId'],['n','string']],confirm:'double',watch:['dk'],
doc:'Opt out of an add-on De-Kicks slipped onto the bill.'},
closeModal:{args:[],
doc:'Close the open window, answering nothing. Always available, so you are never stuck in front of one.'},
};
const API_VIEW={
pieOpen:{args:[],doc:'Open Pie Control, the rocket company\'s panel.'},
ip4Open:{args:[],doc:'Open the bank at its Address space section: your IPv4 blocks, who uses them, CGNAT, the NAT64 pool and the transfer market.'},
ip4Pick:{args:[['v','ip4Len']],doc:'Pick the block size the Address space market quotes (a prefix length, 24 to 16).'},
pieGovOpen:{args:[],doc:'Open the bank at its Government money section: the rocket company\'s fund auctions, the Pitcairn grant and the Ex-Im Pie Bank (it used to be Pie Control\'s Gov tab).'},
pieTab:{args:[['t','pieTab']],doc:'Switch the Pie Control tab: traffic, co (the company, its books and the Founder\'s posts), fly (launches) or dish.'},
pieCity:{args:[['v','cityId']],doc:'Pick the POP the Dishes tab works on.'},
pieHi:{args:[['id','string']],doc:'Highlight one orbit flow on the Pie Control globe.'},
pieIns:{args:[],doc:'Toggle launch insurance for the next launches.'},
pieLas:{args:[],doc:'Toggle lasers (inter-satellite links) for the next launches.'},
pieGlobeNight:{args:[],doc:'Flip the Pie Control globe between day and night.'},
pieSpatOpen:{args:[['id','pieSpatId']],doc:'Open the sheet of a geopolitical spat over orbit.'},
traceMode:{args:[['m','string']],doc:'Redo the open traceroute in a routing mode: normal, fast or scenic.'},
chartToggle:{args:[['c','string'],['k','string']],doc:'Hide or show one series of a dashboard chart (a legend click); hiding every series shows them all again.'},
help:{args:[],doc:'Open the how-to-play modal.'},
dash:{args:[],doc:'Open the NOC dashboard.'},
dashClose:{args:[],doc:'Close the NOC dashboard.'},
nocWindow:{args:[],doc:'Open the NOC dashboard in a window of its own, for a second display.'},
dashTab:{args:[['k','dashTab']],doc:'Switch the NOC dashboard tab.'},
marketOpen:{args:[],doc:'Open the NOC dashboard at the capacity market (Lambda Bazaar).'},
dashSort:{args:[['k','dashSortKey']],doc:'Flip a dashboard column\'s sort.'},
dashLink:{args:[['id','entityId']],doc:'Jump from the dashboard to a link\'s panel.'},
bank:{args:[],doc:'Open the bank.'},
bankClose:{args:[],doc:'Close the bank.'},
closePanel:{args:[],doc:'Close the selection panel.'},
tab:{args:[['t','string']],doc:'Switch the city panel\'s tab.'},
pzCity:{args:[['c','cityId']],doc:'Puzzles on a phone: open a city\'s card from its flow chip.'},
pzTab:{args:[['k','string'],['t','string']],doc:'Puzzles on a phone: switch the city (k:"city") or link (k:"link") card\'s tab.'},
leftTab:{args:[['t','leftTab']],doc:'Switch the left drawer and open it.'},
toggleLeft:{args:[],doc:'Open or close the left drawer.'},
netFocus:{args:[['id','netId']],doc:'Focus one network in the left drawer.'},
netFilter:{args:[['f','netFilter']],doc:'All networks, or only the out-of-reach ones.'},
meetGo:{args:[['city','cityId']],doc:'Go to a city and open where to meet networks there.'},
phoneTab:{args:[['t','leftTab']],doc:'Phone tab bar: switch bottom-sheet tab.'},
logOpen:{args:[['id','entityId']],doc:'Open the thing a notification refers to.'},
logAll:{args:[],doc:'Show every notification in the drawer.'},
focusCity:{args:[['city','cityId']],doc:'Select and centre a city.'},
selLink:{args:[['id','entityId']],doc:'Select a link.'},
custGo:{args:[['id','entityId']],doc:'Jump from the dashboard to a customer.'},
pathOpen:{args:[['id','entityId']],doc:'Open the window listing the other paths a customer can move to: fibers for a fiber customer, routes for a circuit. pathMove and pathPin make the move.'},
listMore:{args:[['k','listPage']],doc:'Show another page of the dashboard list.'},
custF:{args:[['v','string']],doc:'Filter the customers list.'},
custCity:{args:[['v','string']],doc:'Filter the customers list by city.'},
custSort:{args:[['k','custSortKey']],doc:'Flip the customers list sort.'},
custOpen:{args:[['sad','boolean',false]],doc:'Open the customers dashboard tab.'},
popGo:{args:[['city','cityId']],doc:'Jump from the dashboard to a city with no POP yet.'},
popsReg:{args:[['v','string']],doc:'Filter the list of cities with no POP by region.'},
popsSort:{args:[['k','popsSortKey']],doc:'Flip the sort of the list of cities with no POP.'},
goConn:{args:[['city','cityId'],['k','connKind']],doc:'Open a city\'s connections tab.'},
goEgress:{args:[['city','cityId'],['k','egressKind']],doc:'Open a city\'s connections tab (l2 for the customer list).'},
connOpen:{args:[],doc:'Open the connections tab of the NOC dashboard (also the Peering tab\'s "All connections" button).'},
connF:{args:[['f','connFilter'],['v','string',false]],doc:'Filter the connections list.'},
connCity:{args:[['v','string']],doc:'Filter the connections list by city.'},
connNet:{args:[['v','string']],doc:'Filter the connections list by network.'},
connSort:{args:[['k','connSortKey']],doc:'Flip the connections list sort.'},
connFor:{args:[['net','netId']],doc:'Open the connections of one network.'},
linkCheck:{args:[['id','entityId']],doc:'Open the redundancy check for a link: what a single cut would drop, without changing anything.'},
findOpen:{args:[],doc:'Open the city finder (the 🔍 in the top bar).'},
findGo:{args:[['city','cityId']],doc:'Close the finder and jump to a city.'},
findLink:{args:[['city','cityId']],doc:'Open the city finder to pick where a new link from this POP goes (the "Link to a city" button in its panel).'},
linkTo:{args:[['a','cityId'],['b','cityId']],doc:'From the link finder: open the new-link window from POP a to city b, as dragging between them would.'},
popStep:{args:[['d','integer']],doc:'Select and centre the previous (d<0) or next (d>0) of your POPs, by name: the [ and ] keys.'},
offerStep:{args:[],doc:'Select the next open offer (soonest to expire first), centre its city and mark it under Offers here: the $ key.'},
zoomStep:{args:[['d','integer']],doc:'Zoom the map out (d<0) or in (d>0) around its middle: the - and = keys.'},
keys:{args:[],doc:'Open the list of keyboard shortcuts (the ? key).'},
routingOpen:{args:[],doc:'Open the Routing & DDoS window: the traceroute, backbone, Auto-TE and DDoS settings (the button at the top of the NOC tab).'},
opsOpen:{args:[],doc:'Open the Ops sheet: the NOC intern\'s mood, weekly shift report and standing orders.'},
bstdOpen:{args:[],doc:'Open the build standard sheet: every target, how many POPs, ports and links are below it, what bringing them up costs, and the intern\'s order that keeps them there.'},
salesOpen:{args:[],doc:'Open the sales desk sheet: the three kinds of salesperson, who is at the desk and what they cost.'},
opsCity:{args:[['v','cityId',false]],doc:'Show one POP\'s standing-order exceptions in the Ops sheet.'},
utilities:{args:[['city','cityId',false]],doc:'Open the utilities sheet: route servers, the redundancy kit, caches and bulk peering, for one city or the whole network.'},
pniAllOpen:{args:[['net','pniAllNet']],doc:'Open the bulk PNI order sheet for one network (or every network with null).'},
pniFilter:{args:[['f','pniFilter']],doc:'Filter the PNI list: all, via transit, worth it, already PNI.'},
pniGrp:{args:[['g','string'],['o','boolean',false]],doc:'Fold or unfold one group of the PNI list.'},
pniSort:{args:[],doc:'Flip the PNI list sort between A-Z and worth-it-first.'},
netFind:{args:[['q','string']],doc:'Filter a POP\'s transit, exchange, PNI and cache lists by network name or AS number.'},
netOnly:{args:[],doc:'Show only the networks you are connected to in a POP\'s lists, or all of them again.'},
netClear:{args:[],doc:'Clear the network search and the connected-only switch.'},
puzzleMenu:{args:[],doc:'Open the puzzle list.'},
puzzleDoor:{args:[],doc:'From the title screen: open the puzzle list (keeps the typed name).'},
pzFinish:{args:[],doc:'Puzzles only: run the star count and show the results sheet.'},
pzMonkey:{args:[],doc:'Puzzles only: send the chaos monkey round the build to prove the N-1 star.'},
pzMkSkip:{args:[],doc:'Puzzles only: skip the monkey\'s tour to the verdict.'},
pzLook:{args:[['c','cityId',false],['u','string',false]],doc:'Puzzles only: move the map to the city (c) or the cut (u, a link unit) that the sheet\'s next line names.'},
pzArAll:{args:[],doc:'Architect runs only: show every city on the map, not just the run\'s own.'},
tailTog:{args:[],doc:'Show or hide the long tail of small networks.'},
teEdit:{args:[],doc:'Open the RouteScript editor.'},
teClose:{args:[],doc:'Close the RouteScript editor.'},
teHelp:{args:[],doc:'Open the RouteScript reference.'},
teBack:{args:[],doc:'Back to the RouteScript editor.'},
models:{args:[],doc:'Open the router catalogue.'},
decomOpen:{args:[['city','cityId',false]],doc:'Open the decommissioning sheet.'},
scenarios:{args:[],doc:'Open the scenario picker. Start one with startScn.'},
helpClose:{args:[],doc:'Close the help modal.'},
whatsNewShow:{args:[],doc:'Open the release notes.'},
};
const API_BOUND={
pieRename:{command:'pieName',note:'the typed company name'},
leaseSwap:{command:'orderDf',note:'presets the dark-fiber modal on a leased pair'},
teOpt:{command:'teDeploy',arg:'script',note:'the optimiser drafts a script'},
teSlop:{command:'teDeploy',arg:'script',note:'the AI drafts a script'},
teExample:{command:'teDeploy',arg:'script',note:'the worked example'},
teRecipe:{command:'teDeploy',arg:'script',note:'a recipe from catalog(\'TE_RECIPES\')'},
trace:{command:'traceRun',arg:'from'},
decomToggle:{command:'decomGo',arg:'cities'},
satOpen:{command:'buySat',note:'opens the satellite order sheet from a teleport (a) or for a city (b); buySat takes a, b, bird and g itself'},
openVxc:{command:'buyVxc',note:'opens the circuit picker from a fabric port ({from, prov}); buyVxc takes a, b, prov and t itself'},
connCancel:{command:'cancelTransit',note:'the connections list\'s cancel button: it arms, then dispatches cancelTransit, cancelPni, cancelIx, rmCache or rmNni'},
cnPrem:{command:'buildLink',arg:'premiumCrossing'},
addParallel:{command:'buildLink',note:'opens the link modal on the same pair',arg:'a/b'},
via:{command:'buildLink',arg:'cable'},
route:{command:'buildLink',arg:'route'},
dfMode:{command:'orderDf',note:'opens the dark-fiber modal',arg:'a/b'},
xpOpen:{command:'xpBuild',note:'opens the link window on its Express tab: the ways your ROADM fibers chain from a to b (via, fiber ids comma-separated, puts that path first)',arg:'a/b/via'},
dfSrc:{command:'orderDf',arg:'source'},
dfSys:{command:'orderDf',arg:'system'},
seaDesign:{command:'orderCable',arg:'design'},
seaPackage:{command:'orderCable',arg:'terminal/engineering'},
ownCab:{command:'orderCable',note:'presets the own-cable flow'},
randomName:{command:'start',note:'drafts the title-screen name; new_game starts games'},
pickStart:{command:'start',note:'drafts the home city; new_game starts games'},
pickHome:{command:'start',note:'drafts the home city; new_game starts games'},
modeSet:{command:'start',note:'drafts the game mode; new_game starts games'},
presetSet:{command:'start',note:'drafts the difficulty preset; new_game starts games'},
chaosSet:{command:'start',note:'drafts the sandbox chaos dial; new_game starts games'},
rename:{command:'renameGo',note:'opens the rename sheet; renameGo opens it itself'},
pniAllSize:{command:'pniAll',arg:'tier',note:'steps the port size in the bulk sheet'},
utilityPick:{command:'utilities',note:'the sheet\'s city picker; pass city to utilities itself'},
pzAddPar:{command:'pzLink',note:'opens the puzzle picker on the same pair',arg:'tier'},
pzVia:{command:'pzLink',note:'picks the route (cable or land) for the pending link'},
pzDiv:{command:'pzLink',note:'same trench or a diverse one for the pending link'},
};
/* Starting, retrying and leaving scenarios, puzzles and architect runs, and the screens a player dismisses. They run
as their buttons run them; new_game, load_save and export_save are the other half of the session, and exist only in
the MCP server's own page (scripts/lib/mcp-headless.js). In the player's tab the player owns the game, so the ones
that replace or leave it are refused there (API_PLAYER_OWNS). */
const API_SESSION={
startScn:{args:[['id','scnId']],doc:'Start a scenario (ids from catalog SCN), replacing the current game.'},
startWeekly:{args:[],doc:'Start this week\'s weekly scenario, replacing the current game. The week follows the real date.'},
pzStart:{args:[['id','string']],doc:'Start a puzzle by id (the puzzle list, view.puzzleMenu, shows them), replacing the current game.'},
pzWeekly:{args:[],doc:'Start this week\'s weekly puzzle, replacing the current game.'},
pzArStart:{args:[['id','string']],doc:'Start an architect run by id (view.puzzleMenu lists them), replacing the current game.'},
pzRetry:{args:[],doc:'Puzzles and architect runs: start the same one over from scratch.'},
pzLeave:{args:[],doc:'Leave the running puzzle or architect run.'},
keepPlaying:{args:[],doc:'Dismiss the win screen and keep playing.'},
pitchSkip:{args:[],doc:'Skip the opening pitch; a game waiting behind it starts.'},
tutSkip:{args:[],doc:'Skip the tutorial coaching.'},
};
// Session actions that would replace or leave the game in the player's tab: refused over the relay.
const API_OWN_WHY='the game in this tab is the player\'s: only the player starts, loads or leaves one';
const API_PLAYER_OWNS={startScn:1,startWeekly:1,pzStart:1,pzWeekly:1,pzArStart:1,pzRetry:1,pzLeave:1};
/* Actions no tool runs, by reason: files, storage slots, settings and the title screen are not the game's, and time
moves only through advance (or the page's own clock). */
const API_WHY={
time:'use advance to move time, or wait when the clock runs on its own',start:'use new_game',files:'use load_save or export_save',
slots:'saved networks in browser storage are not part of this game',prefs:'device and player settings are not part of the game',
browser:'it needs the browser itself (a share sheet, the clipboard, an install prompt or a reload)',
mp:'multiplayer talks to a session server for the player: only the player starts, joins, chats in or leaves a session',
};
const API_DENY={
speed:'time',phonePlay:'time',phoneSpeed:'time',
start:'start',newgame:'start',cont:'start',toTitle:'start',resetAsk:'start',
exportSave:'files',importGo:'files',importPick:'files',slotExport:'files',xfer:'files',xferFile:'files',xferPaste:'files',xferRecv:'files',
slotBack:'slots',slotDel:'slots',slotDelGo:'slots',slotMenu:'slots',slotRetry:'slots',slotSpace:'slots',slotSwitch:'slots',slotTake:'slots',
animSet:'prefs',langSet:'prefs',mapSet:'prefs',menu:'prefs',mute:'prefs',prefSet:'prefs',settings:'prefs',settingsClose:'prefs',soundSet:'prefs',themeSet:'prefs',vpSet:'prefs',
mpDoor:'mp',mpBack:'mp',mpStart:'mp',mpJoin:'mp',mpOpen:'mp',mpShare:'mp',mpCopyLink:'mp',mpChat:'mp',mpLeaveAsk:'mp',mpLeave:'mp',mpNewer:'mp',mpKeep:'mp',
install:'browser',share:'browser',shareDl:'browser',shareGo:'browser',traceCopy:'browser',updateLater:'browser',updateNow:'browser',wsShare:'browser',pzShare:'browser',xferLink:'browser',xferShare:'browser',
};