Express lightpaths: regen cards for their channels, and dirty connectors dim them (#58)

A regen site added to a fiber that already carries expresses now charges a
regen card for every express channel in that glass, as it does for the
fiber's own channels. One helper, regenAddCost(), prices it for the action,
the fiber panel's button and the MCP dry-run quote, so the three agree.
Lighting an express over existing regen sites already paid its cards
(xpCost); only adding a site later was free for them.

A dirty connector on a fiber is in the glass, so it now dims the expresses
riding that fiber by the same factor (capOf multiplies xpG by xpGlassF over
the express's fibers), and the express's panel names the fiber. The other
link-degrading incidents (MTU mismatch, microbursts, a marginal optic's CRC
errors) belong to the fiber's own routers and optics, which an express
bypasses, as the optic-failure incident already treats them, so they leave
expresses alone. The incident marks the connector with loss.glass=true;
sanitize keeps the flag only when it is true, so an old save's loss loads
as router-side, as it behaved before. A fiber that only carries expresses
can now get the dirty connector too (never the router-side variants), like
the backhoe and amp-hut incidents already find it.
This commit is contained in:
jvanvik 2026-11-09 22:50:04 +01:00
parent 2dc8274f34
commit ae78e82ddb
17 changed files with 123 additions and 9 deletions

View file

@ -20,6 +20,7 @@ All notable changes to this project are documented here. The project follows
- Teleports bring satellites to small islands and remote towns, long before you have a cable there or a rocket company (#83). Build one at a POP from level 2 and rent GEO circuits (about 600 ms round trip, and users notice) or, with tracking antennas from level 3, MEO circuits (about 130 ms) to any island or town its satellites see. Next to an island's only cable a circuit waits on standby (whether the cable or the circuit came first) and carries the island when the cable is cut, and a city with no cable at all gets a POP and a circuit in one order.
- Set a build standard for your whole network: routers, a second building and a generator at every POP, LAGs, exchange ports and PNIs, line systems, optics and wave sizes, all in one sheet. New POPs get the POP part the day they open, the sheet shows what is below the standard and what fixing it costs, one tap brings everything up, and the new "Keep to the build standard" order has your intern do it a few jobs a day with money to spare. Find it in the menu, the Standing orders sheet and every POP's router section.
- IPv4 is scarce now: business customers need public address blocks, and the homes that do not fit share addresses behind CGNAT. A new network starts with a /21 from its registry, enough for its first months; buy, lease or sell blocks from /24 to /16 on the transfer market in the bank's new Address space section, or lease spare ones out for a monthly income. An offer you have no addresses for says so and waits, a customer that wants to grow at renewal stays at its size until you have the addresses, CGNAT costs a little and annoys some gamers, and you pick how many homes share an address. IPv6 stays free for everyone. This is part of On-call and BGP at 3 a.m.; the gentler rules, Sandbox, puzzles and scenarios keep IPv4 plentiful, and saved games get the addresses they already use plus room to grow (#150).
- Express lightpaths now pay their share when you add a regen site, and a dirty connector on a fiber dims the expresses riding it too (#58). A regen site added to a fiber that already carries expresses needs a regen card for each of their channels, just as for the fiber's own, and the price on the fiber's button includes them. A dirty connector dims every wave in that fiber, and the express's panel says which fiber it is; an MTU mismatch, microbursts or a marginal optic stay with that fiber's own routers and optics, which an express passes by.
## [3.3.0] — 2026-11-09

View file

@ -2068,6 +2068,7 @@
"express.dark_gone":"Eine der Glasfasern darunter gibt es nicht mehr.",
"express.dark_reach":"Keine ihrer Optiken schafft diese Strecke.",
"express.dark_system":"Auf {span} ist das Line System down.",
"express.dim":"{span} hat einen verschmutzten Stecker: Jede Welle in dieser Faser, auch dieser Express, läuft mit {p}, bis jemand ihn reinigt.",
"express.express_to":"Express nach …",
"express.eyebrow":"Express-Lightpath · {km} km",
"express.fiber_busy":{"one":"<b>Über diese Glasfaser läuft ein Express-Lightpath.</b><br>Bau ihn zuerst ab: Öffne ihn im Express-Abschnitt dieser Glasfaser.","other":"<b>Über diese Glasfaser laufen {n} Express-Lightpaths.</b><br>Bau sie zuerst ab: Öffne sie im Express-Abschnitt dieser Glasfaser."},

View file

@ -2066,6 +2066,7 @@
"express.dark_gone":"Una de las fibras por debajo ya no existe.",
"express.dark_reach":"Ninguna de sus ópticas llega tan lejos.",
"express.dark_system":"{span} tiene el sistema de línea caído.",
"express.dim":"{span} tiene un conector sucio: cada onda de esa fibra, también este exprés, va al {p} hasta que alguien lo limpie.",
"express.express_to":"Exprés a…",
"express.eyebrow":"Lightpath exprés · {km} km",
"express.fiber_busy":{"one":"<b>Un lightpath exprés va por esta fibra.</b><br>Desmóntalo primero: ábrelo desde la sección Exprés de esta fibra.","other":"<b>{n} lightpaths exprés van por esta fibra.</b><br>Desmóntalos primero: ábrelos desde la sección Exprés de esta fibra."},

View file

@ -2066,6 +2066,7 @@
"express.dark_gone":"Une des fibres en dessous n’existe plus.",
"express.dark_reach":"Aucune de ses optiques ne porte aussi loin.",
"express.dark_system":"{span} a son système de ligne en panne.",
"express.dim":"{span} a un connecteur sale : chaque onde de cette fibre, cet express aussi, tourne à {p} jusqu’à ce que quelqu’un le nettoie.",
"express.express_to":"Express vers…",
"express.eyebrow":"Lightpath express · {km} km",
"express.fiber_busy":{"one":"<b>Un lightpath express passe par cette fibre.</b><br>Démonte-le d’abord : ouvre-le depuis la section Express de cette fibre.","other":"<b>{n} lightpaths express passent par cette fibre.</b><br>Démonte-les d’abord : ouvre-les depuis la section Express de cette fibre."},

View file

@ -2066,6 +2066,7 @@
"express.dark_gone":"Una delle fibre sotto non c’è più.",
"express.dark_reach":"Nessuna delle sue ottiche arriva così lontano.",
"express.dark_system":"{span} ha il line system giù.",
"express.dim":"{span} ha un connettore sporco: ogni onda in quella fibra, anche questo express, va al {p} finché qualcuno non lo pulisce.",
"express.express_to":"Express verso…",
"express.eyebrow":"Lightpath express · {km} km",
"express.fiber_busy":{"one":"<b>Su questa fibra passa un lightpath express.</b><br>Smontalo prima: aprilo dalla sezione Express di questa fibra.","other":"<b>Su questa fibra passano {n} lightpath express.</b><br>Smontali prima: aprili dalla sezione Express di questa fibra."},

View file

@ -2066,6 +2066,7 @@
"express.dark_gone":"Uma das fibras por baixo não existe mais.",
"express.dark_reach":"Nenhuma das suas ópticas alcança essa distância.",
"express.dark_system":"{span} está com o line system fora do ar.",
"express.dim":"{span} tem um conector sujo: cada onda nessa fibra, este expresso também, roda a {p} até alguém limpá-lo.",
"express.express_to":"Expresso para…",
"express.eyebrow":"Lightpath expresso · {km} km",
"express.fiber_busy":{"one":"<b>Um lightpath expresso passa por esta fibra.</b><br>Desmonte-o primeiro: abra-o na seção Expresso desta fibra.","other":"<b>{n} lightpaths expressos passam por esta fibra.</b><br>Desmonte-os primeiro: abra-os na seção Expresso desta fibra."},

View file

@ -226,7 +226,7 @@ const API_CMD={
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:REGEN_COST+Math.round((l.ch||[]).reduce((x,c)=>x+optCost(c),0)*REGEN_CH)}:{setup:0};},
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.'},

View file

@ -76,7 +76,7 @@ const dfCap0=l=>Math.max(0,dfLit(l)-mwG(l));
// Whether a fiber carries anything for you (linkDown() asks of every fiber, often): dfCap(l)>0 without adding up every
// channel. An optic out of service, or managed waves sold on it, take the sum.
const dfOn=l=>{if(l.ready>S.day||l.eqDown>S.day)return false;if(l.chFail&&l.chFail.until>S.day||mwG(l)>0)return dfCap(l)>0;let o=null;for(const c of l.ch||[])if(c!==o){o=c;if(optG(c,l)>0)return true;}return false;};
const capOf=l=>(l.kind==='vxc'?VXC[l.vt].g:l.kind==='df'?dfCap(l):l.kind==='xp'?xpG(l):l.kind==='sat'?l.g:LT[l.tier].g)*(l.deg>S.day?0.5:1)*(l.loss&&l.loss.until>S.day?l.loss.f:1);
const capOf=l=>(l.kind==='vxc'?VXC[l.vt].g:l.kind==='df'?dfCap(l):l.kind==='xp'?xpG(l)*xpGlassF(l):l.kind==='sat'?l.g:LT[l.tier].g)*(l.deg>S.day?0.5:1)*(l.loss&&l.loss.until>S.day?l.loss.f:1);
// A sick LAG (LACP trouble) keeps only part of its capacity until the incident clears.
const lagF=o=>o&&o.lacp&&o.lacp.until>S.day?o.lacp.f:1,ixLagF=x=>lagF(S.ev&&S.ev.ixlacp&&{lacp:S.ev.ixlacp[x]});
const tierW=l=>{if(l.kind==='wave')return l.tier;if(l.kind==='vxc'||l.kind==='sat')return 0;const g=l.kind==='xp'?xpG(l):dfCap(l);return g>=6400?4:g>=1600?3:g>=400?2:g>=100?1:0;};

View file

@ -21,7 +21,7 @@ function sanitize(s){
if(!isCity(s.home))s.home=Object.keys(s.pops)[0]||'fra';
opsSanitize(s);
const tier=v=>int(v,0,PORT.length-1,0),lag=v=>int(v,1,LAG_MAX,1),sid=v=>String(v==null?uid():v).slice(0,40);
s.links=s.links.filter(l=>l&&isCity(l.a)&&isCity(l.b)&&l.a!==l.b).map(l=>{l.id=sid(l.id);if(l.list!==undefined){const L=l.kind==='df'?cmClean(l.list):null;if(L)l.list=L;else delete l.list;}l.km=num(l.km,kmBetween(l.a,l.b));l.mo=num(l.mo,0);l.cut=num(l.cut,0);if(l.cname!=null)l.cname=String(l.cname).slice(0,60);if(l.pairs!==undefined)l.pairs=Math.min(l.sub?SUB_PAIRS_MAX:s.lvl>=PAIRS_LV?PAIRS_BIG:PAIRS_MAX,Math.max(1,Math.floor(+l.pairs)||1));if(l.kind!=='df'&&l.kind!=='vxc'&&l.kind!=='xp'&&l.kind!=='sat')l.kind='wave';if(l.kind==='wave')l.tier=int(l.tier,0,LT.length-1,0);if(l.cable&&(!own(CAB,l.cable)||!cablePair(l.cable,l.a,l.b)))l.cable=null;if(l.kind==='vxc'&&!own(VXC,l.vt))l.vt=0;if(l.kind==='df'){if(!own(DF_SYS,l.sys))l.sys='lite';l.ch=Array.isArray(l.ch)?l.ch.filter(o=>own(OPT,o)):[];l.ready=num(l.ready,0);if(l.day!==undefined)l.day=Math.min(s.day,Math.max(0,num(l.day,s.day)));for(const k of Object.keys(SUB_UPGRADES)){const f='sub'+k;if(l[f]!==undefined){if(l.own&&l.sub&&Number.isFinite(l[f])&&l[f]>=0)l[f]=Math.round(l[f]);else delete l[f];}}if(l.seaPath!==undefined){if(l.own&&l.sub&&Array.isArray(l.seaPath)&&l.seaPath.length>=2&&l.seaPath.length<=2048&&l.seaPath.every(p=>Array.isArray(p)&&p.length===2&&p.every(Number.isFinite)&&Math.abs(p[0])<=180&&Math.abs(p[1])<=90))l.seaPath=l.seaPath.map(p=>p.slice());else delete l.seaPath;}if(l.paid!==undefined){if(l.own&&l.sub&&Number.isFinite(l.paid)&&l.paid>=0)l.paid=Math.round(l.paid);else delete l.paid;}if(l.own&&l.sub&&!own(SEA_DESIGNS,l.seaDesign))l.seaDesign='standard';l.regen=int(l.regen,0,REGEN_MAX,0);}const deg=v=>v&&typeof v==='object'?{until:num(v.until,0),f:Math.min(1,Math.max(0,num(v.f,1)))}:null;if(l.loss)l.loss=deg(l.loss);return l;});
s.links=s.links.filter(l=>l&&isCity(l.a)&&isCity(l.b)&&l.a!==l.b).map(l=>{l.id=sid(l.id);if(l.list!==undefined){const L=l.kind==='df'?cmClean(l.list):null;if(L)l.list=L;else delete l.list;}l.km=num(l.km,kmBetween(l.a,l.b));l.mo=num(l.mo,0);l.cut=num(l.cut,0);if(l.cname!=null)l.cname=String(l.cname).slice(0,60);if(l.pairs!==undefined)l.pairs=Math.min(l.sub?SUB_PAIRS_MAX:s.lvl>=PAIRS_LV?PAIRS_BIG:PAIRS_MAX,Math.max(1,Math.floor(+l.pairs)||1));if(l.kind!=='df'&&l.kind!=='vxc'&&l.kind!=='xp'&&l.kind!=='sat')l.kind='wave';if(l.kind==='wave')l.tier=int(l.tier,0,LT.length-1,0);if(l.cable&&(!own(CAB,l.cable)||!cablePair(l.cable,l.a,l.b)))l.cable=null;if(l.kind==='vxc'&&!own(VXC,l.vt))l.vt=0;if(l.kind==='df'){if(!own(DF_SYS,l.sys))l.sys='lite';l.ch=Array.isArray(l.ch)?l.ch.filter(o=>own(OPT,o)):[];l.ready=num(l.ready,0);if(l.day!==undefined)l.day=Math.min(s.day,Math.max(0,num(l.day,s.day)));for(const k of Object.keys(SUB_UPGRADES)){const f='sub'+k;if(l[f]!==undefined){if(l.own&&l.sub&&Number.isFinite(l[f])&&l[f]>=0)l[f]=Math.round(l[f]);else delete l[f];}}if(l.seaPath!==undefined){if(l.own&&l.sub&&Array.isArray(l.seaPath)&&l.seaPath.length>=2&&l.seaPath.length<=2048&&l.seaPath.every(p=>Array.isArray(p)&&p.length===2&&p.every(Number.isFinite)&&Math.abs(p[0])<=180&&Math.abs(p[1])<=90))l.seaPath=l.seaPath.map(p=>p.slice());else delete l.seaPath;}if(l.paid!==undefined){if(l.own&&l.sub&&Number.isFinite(l.paid)&&l.paid>=0)l.paid=Math.round(l.paid);else delete l.paid;}if(l.own&&l.sub&&!own(SEA_DESIGNS,l.seaDesign))l.seaDesign='standard';l.regen=int(l.regen,0,REGEN_MAX,0);}const deg=v=>v&&typeof v==='object'?{until:num(v.until,0),f:Math.min(1,Math.max(0,num(v.f,1)))}:null;if(l.loss){const g=l.loss.glass===true;l.loss=deg(l.loss);if(g&&l.loss)l.loss.glass=true;}return l;});
for(const l of s.links)repairSubUpgradeDates(l,s.day);
xpSanitize(s);
/* Metrics moved from each link to its city pair (#122). Older saves routed a pair at the lowest metric of its

View file

@ -32,6 +32,11 @@ function xpRunKm(sp){let cur=0,mx=0;for(const s of sp){const r=s.regen|0,p=s.km/
// What optic o carries over that run (0: out of reach), cached like every channel (optG).
const xpOptG=(o,run)=>OPT[o]?optG(o,{km:run}):0;
function xpG(l){const sp=xpSpans(l);if(!sp)return 0;const run=xpRunKm(sp);let g=0;for(const o of l.ch||[])g+=xpOptG(o,run);return g;}
/* What still gets through: a dirty connector in the glass of a fiber under it dims every wave there, this one's too. An
MTU mismatch, microbursts or a marginal optic on that fiber belong to its routers and optics, which the express skips. */
function xpGlassF(l){const sp=xpSpans(l);if(!sp)return 1;let f=1;for(const s of sp){const x=s.loss;if(x&&x.glass&&x.until>S.day)f*=x.f;}return f;}
// The fibers under it with a dirty connector today, for its panel.
const xpDim=l=>(xpSpans(l)||[]).filter(s=>s.loss&&s.loss.glass&&s.loss.until>S.day);
// The fastest single channel, as a scenario's fast path asks of every hop.
function xpHopG(l){const sp=xpSpans(l);if(!sp)return 0;const run=xpRunKm(sp);return Math.max(0,...(l.ch||[]).map(o=>xpOptG(o,run)));}
// Dark when a fiber under it is cut, still being built or has its line system down, or nothing lit reaches.

View file

@ -28,7 +28,7 @@ function* failureRun(only){
let tot=opts.reduce((a,o)=>a+o[1],0),r=Math.random()*tot,type=opts[0][0];
for(const o of opts){r-=o[1];if(r<=0){type=o[0];break;}}
if(only)type=only;
if(type==='funny'){const f=['oops','cleaner','harmless','harmless','harmless','ac'];if(live.length)f.push('fatwave','fatwave','mtu','label','loss','loss');if(lagsN().length)f.push('lacp','lacp');if(R.demand>1)f.push('pmtud');if(S.transit.length)f.push('prepend');if(S.day>30)f.push('rpki');if(amps.length)f.push('roadmff');type=pick(f);}
if(type==='funny'){const f=['oops','cleaner','harmless','harmless','harmless','ac'];if(live.length)f.push('fatwave','fatwave','mtu','label','loss','loss');else if(bare.length)f.push('loss','loss');if(lagsN().length)f.push('lacp','lacp');if(R.demand>1)f.push('pmtud');if(S.transit.length)f.push('prepend');if(S.day>30)f.push('rpki');if(amps.length)f.push('roadmff');type=pick(f);}
const before=R.served;
if(type==='harmless'){const m=pick(HARMLESS);S.stats.incidents++;S.stats.survived++;toast(`<b>${m[0]}</b><br>${m[1]}`,'goal');sfx('alert');return;}
if(type==='ring'){const cs=Object.keys(S.pops).filter(c=>S.pops[c].site2),c=pick(cs),pp=S.pops[c],dur=2+Math.floor(Math.random()*3);pp.ringcut=S.day+dur;
@ -55,9 +55,11 @@ function* failureRun(only){
addInc({type,ref:g.k+':'+g.id,until,msg:tr(msg,{lab}),cost:600,fix:tr('failures.fix_the_lacp_config')},msg);
}else if(type==='loss'){
const deep=l=>[l.a,l.b].every(c=>S.pops[c]&&/deep-buffer/.test(RG[S.pops[c].rgen||0].chip));
const l=pick(live),v=Math.floor(Math.random()*3);
// Only the dirty connector (v 0) is in the glass, so it dims the expresses riding the fiber too; microbursts and a
// marginal optic are its own routers' and optics'. A fiber that only carries expresses has nothing else to go wrong.
const l=pick(live.concat(bare)),r=Math.floor(Math.random()*3),v=xpBare(l)?0:r;
if(v===1&&deep(l)){S.stats.incidents++;S.stats.survived++;toast(tr('failures.microbursts_on_a_b_your_deep',{a:CITY[l.a].name,b:CITY[l.b].name}),'goal');return;}
const f=[0.6,0.8,0.7][v],dur=2+Math.floor(Math.random()*3);l.loss={until:S.day+dur,f};
const f=[0.6,0.8,0.7][v],dur=2+Math.floor(Math.random()*3);l.loss=v?{until:S.day+dur,f}:{until:S.day+dur,f,glass:true};
const msg=[N_('failures.a_dirty_connector_on_a_b'),
N_('failures.microbursts_on_a_b_overflow_shallow'),
N_('failures.crc_errors_on_a_b_a')][v];

View file

@ -24,7 +24,7 @@ Object.assign(ACT,{
toast(own?tr('fiber_and_hardware.groundbreaking_your_own_fiber_from_a',{a:CITY[a].name,b:CITY[b].name,n:dfBuildDays(km)}):tr('fiber_and_hardware.dark_fiber_iru_signed_a_b',{a:CITY[a].name,b:CITY[b].name}),'goal');after();},
regen:({id,d})=>{d=+d;const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||(l.sub&&!l.seat)||(d!==1&&d!==-1))return;const n=(l.regen|0)+d;if(n<0||n>REGEN_MAX)return;
if(d<0&&((l.ch||[]).some(o=>!optMode(o,Object.assign({},l,{regen:n})))||xpRegenBad(l,n))){toast(tr('fiber_and_hardware.those_optics_need_the_regen_site'),'bad');sfx('err');return;}
if(d>0&&!spend(REGEN_COST+Math.round((l.ch||[]).reduce((a,c)=>a+optCost(c),0)*REGEN_CH)))return;l.regen=n;toast(d>0?tr('fiber_and_hardware.regen_site_n_is_up_optical',{n,a:CITY[l.a].name,b:CITY[l.b].name,km:spanKm(l).toLocaleString()}):tr('fiber_and_hardware.regen_site_removed'),'good');sfx('build');after();},
if(d>0&&!spend(regenAddCost(l)))return;l.regen=n;toast(d>0?tr('fiber_and_hardware.regen_site_n_is_up_optical',{n,a:CITY[l.a].name,b:CITY[l.b].name,km:spanKm(l).toLocaleString()}):tr('fiber_and_hardware.regen_site_removed'),'good');sfx('build');after();},
addCh:({id,o})=>{const l=S.links.find(x=>x.id===id),O=OPT[o];if(!l||!O||l.kind!=='df')return;const why=chWhy(l,o);if(why){toast(tr('fiber_and_hardware.can_t_add_optic_why',{optic:O.n,why:esc(why)}),'bad');sfx('err');return;}if(!portGate(l.a,chPorts(o,l.a))||!portGate(l.b,chPorts(o,l.b)))return;const sp=spareN(o)>0;if(!spend(chCost(l,o)))return;if(sp)S.spares[o]--;(l.ch=l.ch||[]).push(o);floater((CITY[l.a].x+CITY[l.b].x)/2,(CITY[l.a].y+CITY[l.b].y)/2-20,`+${O.n}`,'#FF4F9A');after();},
rmCh:({id,o})=>{const l=S.links.find(x=>x.id===id);if(!l||!OPT[o]||l.kind==='xp')return;const i=(l.ch||[]).lastIndexOf(o);if(i<0)return;l.ch.splice(i,1);S.spares=S.spares||{};S.spares[o]=(S.spares[o]||0)+1;floater((CITY[l.a].x+CITY[l.b].x)/2,(CITY[l.a].y+CITY[l.b].y)/2-20,tr('fiber_and_hardware.optic_to_spares',{optic:OPT[o].n}),'#7B61FF');after();},
hwLock:()=>{if(hwLock())return;const c=hwLockCost();if(!spend(c))return;S.hw=S.hw||{};S.hw.lock={until:S.day+HW_LOCK_DAYS,mul:hwTrend(S.day)};toast(tr('fiber_and_hardware.prices_locked_until_date_your_vendor',{date:dateStr(S.hw.lock.until)}),'good');after();},

View file

@ -28,6 +28,8 @@ const SPARE_RESALE=0.4,spareN=o=>(S&&S.spares&&S.spares[o])|0,spareValue=o=>Math
// A fiber given up (a cancelled IRU, a cable called off, a decommissioned POP) keeps its optics: they go on the shelf too (#229).
const chBack=links=>{let n=0;for(const l of links)for(const o of (l&&l.ch)||[])if(OPT[o]){S.spares=S.spares||{};S.spares[o]=(S.spares[o]||0)+1;n++;}return n;};
function chCost(l,o){const r=REGEN_CH*(l.regen|0);return Math.round(optCost(o)*(spareN(o)>0?r:1+r));}
// One more regen site on fiber l: the hut, and a regen card for every channel in its glass, the expresses riding it too.
function regenAddCost(l){let o=(l.ch||[]).reduce((a,c)=>a+optCost(c),0);for(const x of xpOver(l.id))for(const c of x.ch||[])o+=optCost(c);return REGEN_COST+Math.round(o*REGEN_CH);}
function optCost(o){return Math.round(OPT[o].cost*techMul(OPT[o].lvl)*hwMul('opt')*(S&&S.ev&&S.ev.tariff>S.day?1.4:1));}
// Line systems upgrade in place: Rainbow → ROADMaster → C+L. Every lit pair gets the new gear.
const sysNext=l=>l.sys==='lite'?'roadm':l.sys==='roadm'?'cl':null,sysUpCost=l=>{const t=sysNext(l);return t?sysCost(t)*(t==='cl'&&l.own?Math.max(1,l.pairs|0):1):0;};

View file

@ -131,7 +131,7 @@ function dfPanel(l){
h+=`<div class="row"><div class="grow"><div class="nm">${O.n} <span class="meta">${optModes(k,l).map(([g,r])=>tr('link_panels.g_to_km_km',{g:fmtG(g),km:r.toLocaleString()})).join(' · ')}</span></div><div class="meta">${esc(O.blurb)}${n?` · <b>${tr('link_panels.n_lit',{n})}</b>`:''}${sp?` · ${trn('link_panels.n_spare_on_the_shelf',sp)}`:''}${(np=>np>1?` · ${trn('link_panels.takes_n_router_ports_per_end',np)}`:'')(Math.max(chPorts(k,l.a),chPorts(k,l.b)))}</div>${md&&!md.full?`<div class="meta">⚠️ ${tr('link_panels.runs_at_g_per_channel_on',{g:fmtG(md.g)})} ${(!l.sub||l.seat)&&regenNeed(k,l)>(l.regen|0)?trn('link_panels.n_regen_site_would_bring_it',regenNeed(k,l),{g:fmtG(O.g)}):''}</div>`:''}${why?`<div class="why">${esc(why)}</div>`:''}${!techOk('opt',k,O.lvl)&&demoCan(O.lvl)?`<div class="btns">${demoBtn('opt',k,O.lvl,'','ghost sm')}</div>`:''}${opticCountControl(l,k,n)}</div>${n?btn('−','rmCh',{id:l.id,o:k},'ghost sm'):''}${btn(sp?`+ <small>${cc?tr('link_panels.spare_price',{price:fmt$(cc)}):tr('common.spare')}</small>`:`+ <small>${fmt$(cc)}</small>`,'addCh',{id:l.id,o:k},'sm',!!why||S.cash<cc)}</div>`;}
{const st=Object.keys(OPT).filter(k=>spareN(k)>0);h+=`<p class="note">${tr('link_panels.unplugged_optics_go_on_the_spares')}</p>`;
{const used=[...new Set(l.ch||[])].filter(k=>OPT[k]&&OPT[k].lvl<=glassLvl());if(used.length)h+=`<div class="btns">${used.map(k=>btn(tr('link_panels.stock_a_spare_optic_price',{optic:OPT[k].n,price:fmt$(optCost(k))}),'buySpare',{o:k},'ghost sm',S.cash<optCost(k)||spareN(k)>=64)).join('')}</div><p class="meta">${tr('link_panels.spares_bought_now_are_already_paid')}</p>`;}if(st.length)h+=`<h4 class="sub4">${tr('common.spares_shelf')}</h4>`+st.map(k=>`<div class="row"><div class="grow"><div class="nm">${spareN(k)} × ${OPT[k].n}</div></div>${btn(tr('link_panels.sell_one_price',{price:fmt$(spareValue(k))}),'sellSpare',{o:k},'ghost sm')}</div>`).join('');}
const rg=l.regen|0,rgAdd=REGEN_COST+Math.round((l.ch||[]).reduce((a,c)=>a+optCost(c),0)*REGEN_CH);
const rg=l.regen|0,rgAdd=regenAddCost(l);
h+=`</section><section><h3>${tr('common.line_system')}</h3><div class="kv"><span>${esc(sysD.n)}</span><b>${tr('link_panels.n_amplifiers',{n:amps})}</b></div>
<div class="kv"><span>${tr('common.regen_sites')}</span><b>${rg?tr('link_panels.n_optical_spans_of_km_km',{n:rg,km:spanKm(l).toLocaleString()}):tr('common.none')}</b></div><p class="note">${tr('link_panels.a_regen_site_turns_the_light',{price:fmt$(REGEN_MO)})}</p>${l.seat?`<p class="note">${tr('broker.seat_regen_note')}</p>`:''}${l.sub&&l.own&&!l.seat?`<p class="note">${tr('link_panels.no_regen_sites_in_the_middle')}</p>`:`<div class="btns">${rg<REGEN_MAX?btn(tr('link_panels.regen_site_price',{price:fmt$(rgAdd)}),'regen',{id:l.id,d:1},'sm',S.cash<rgAdd):''}${rg?btn(tr('common.regen_site'),'regen',{id:l.id,d:-1},'ghost sm'):''}</div>`}<p class="note">${esc(sysD.blurb)}</p><div class="btns">${(()=>{const t=sysNext(l);if(!t)return '';const T=DF_SYS[t],c=sysUpCost(l);return !techOk('sys',t,T.lvl)?demoBtn('sys',t,T.lvl,tr('link_panels.sys_level_n',{sys:T.n,n:T.lvl}),'sm'):btn(tr('link_panels.upgrade_to_sys_price',{sys:T.n,price:fmt$(c)}),'upSys',{id:l.id},'sm',S.cash<c);})()}${pairBtn(l)}${btn(l.spares?tr('link_panels.spares_kit_on'):tr('link_panels.keep_a_spares_kit_price_mo',{price:fmt$(Math.round(150+(l.ch||[]).length*80))}),'spares',{id:l.id},l.spares?'green sm':'sm')}</div><p class="note">${tr('link_panels.spare_optics_and_amplifier_cards_on')}</p></section>`;
h+=xpDfSection(l);

View file

@ -13,7 +13,7 @@ function xpPanel(l){const sp=xpSpans(l),load=R.load[l.id]||0,cap=capOf(l),u=cap?
let h=`<div class="ph"><div><div class="eyebrow">${tr('express.eyebrow',{km:Math.round(l.km).toLocaleString()})}</div><h2>${A} ⇄ ${B}</h2></div><button class="x" data-act="closePanel" aria-label="${tr('common.close')}">×</button></div><div class="scroll">`;
if(down)h+=`<section><h3 style="color:var(--tx-red,var(--bad))">${tr('common.dark_6bf5')}</h3>${xpDarkWhy(l).map(t=>`<p class="lead">${t}</p>`).join('')}</section>`;
h+=`<section><h3>${tr('common.capacity')}</h3><div class="kv"><span>${trn('express.n_channels',ch.length)}</span><b>${fmtG(load)} / ${fmtG(cap)}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100)}%"></i></div>
<div class="kv"><span>${tr('common.latency')}</span><b>${tr('common.ms_ms_one_way',{ms:linkLat(l).toFixed(1)})}</b></div><div class="kv"><span>${tr('express.optical_run')}</span><b>${run.toLocaleString()} km</b></div>
${down?'':xpDim(l).map(s=>`<p class="why">${tr('express.dim',{span:xpSpanName(s),p:pct(s.loss.f)})}</p>`).join('')}<div class="kv"><span>${tr('common.latency')}</span><b>${tr('common.ms_ms_one_way',{ms:linkLat(l).toFixed(1)})}</b></div><div class="kv"><span>${tr('express.optical_run')}</span><b>${run.toLocaleString()} km</b></div>
<p class="note">${tr('express.passes',{via:esc(xpVia(l))})}</p></section>`;
if(sp)h+=`<section><h3>${tr('express.its_fibers')}</h3>${sp.map(s=>`<div class="row"><div class="grow"><div class="nm">${xpSpanName(s)} ${linkCut(s)?'<span class="tag restrictive">'+tr('common.cut')+'</span>':''}</div><div class="meta">${xpSpanMeta(s)}</div></div>${btn(tr('common.open'),'selLink',{id:s.id},'ghost sm')}</div>`).join('')}<p class="note">${tr('express.slot_note')}</p></section>`;
if(sp){h+=`<section><h3>${tr('common.optics')}</h3>`;

View file

@ -2067,6 +2067,7 @@
"express.dark_gone":"One of the fibers under it is gone.",
"express.dark_reach":"None of its optics reach over this run.",
"express.dark_system":"{span} has its line system down.",
"express.dim":"{span} has a dirty connector: every wave in that fiber, this express too, runs at {p} until someone cleans it.",
"express.express_to":"Express to…",
"express.eyebrow":"Express lightpath · {km} km",
"express.fiber_busy":{"one":"<b>An express lightpath rides this fiber.</b><br>Tear it down first: open it from this fiber's Express section.","other":"<b>{n} express lightpaths ride this fiber.</b><br>Tear them down first: open them from this fiber's Express section."},

View file

@ -4,6 +4,7 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
const { createSession, TOOLS } = require('../scripts/lib/mcp-game');
// Three POPs on routers that take 400G optics, broadband in Paris, transit in Frankfurt, and two ROADM fibers
// (s1 Frankfurt–Brussels, s2 Brussels–Paris), finished and dark. df(a,b,extra) lays another one.
@ -139,6 +140,103 @@ test('reach: the light must make the whole run between regen sites, through Brus
assert.deepEqual(errors, []);
});
test('a regen site added later under an express needs a regen card for its channels too: the fiber panel and the MCP quote say so', (t) => {
const { ev, errors } = game(t, SPANS + "ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;window.s3=df('fra','ams');compute();");
ev(BUILD + "ACT.xpCh({id:x,o:'zr4',d:1});L(s1).ch=['zr4'];compute()");
assert.equal(ev('L(x).ch.length'), 2);
const card = ev("Math.round(optCost('zr4')*REGEN_CH)"), two = ev("Math.round(optCost('zr4')*2*REGEN_CH)"), three = ev("Math.round(optCost('zr4')*3*REGEN_CH)");
assert.equal(ev('regenAddCost(L(s3))'), ev('REGEN_COST'), 'a dark fiber with nothing in it: the hut alone');
assert.equal(ev('regenAddCost(L(s2))'), ev('REGEN_COST') + two, 'two express channels and nothing of its own');
assert.equal(ev('regenAddCost(L(s1))'), ev('REGEN_COST') + three, 'its own channel and the two expresses');
// The fiber panel's button shows that price, and adding the site charges it.
ev('selectLink(s2)');
assert.ok(ev("$('panel').textContent").includes('Regen site ' + ev('fmt$(REGEN_COST+' + two + ')')), "the price on the fiber's regen button");
let cash = ev('S.cash');
ev('ACT.regen({id:s2,d:1})');
assert.equal(ev('L(s2).regen'), 1);
assert.equal(cash - ev('S.cash'), ev('REGEN_COST') + two);
cash = ev('S.cash');
ev('ACT.regen({id:s3,d:1})');
assert.equal(cash - ev('S.cash'), ev('REGEN_COST'), 'no express on it: no card');
// Lighting another channel afterwards pays its card at the new site, as before.
cash = ev('S.cash');
ev("ACT.xpCh({id:x,o:'zr4',d:1})");
assert.equal(cash - ev('S.cash'), ev("optCost('zr4')") + card);
assert.deepEqual(errors, []);
});
test('a dirty connector in the glass under an express dims it too; an MTU mismatch, microbursts or a marginal optic there do not', (t) => {
const { ev, errors } = game(t);
ev(BUILD + "L(s1).ch=['zr4'];compute()");
const cap = (id) => Math.round(ev(`capOf(L(${id}))`));
assert.equal(cap('x'), 400);
// The fiber's own routers and optics: the fiber suffers, the express riding past them does not.
for (const [set, name] of [['L(s1).deg=S.day+3', 'an MTU mismatch'], ['L(s1).loss={until:S.day+3,f:0.8}', 'microbursts'], ['L(s1).loss={until:S.day+3,f:0.7}', 'a marginal optic']]) {
ev(`L(s1).deg=0;L(s1).loss=null;${set};compute()`);
assert.ok(cap('s1') < 400, name + ' slows the fiber');
assert.equal(cap('x'), 400, name + ' leaves the express alone');
}
// A dirty connector is in the glass: every wave there, the express too.
ev('L(s1).deg=0;L(s1).loss=null;L(s2).loss={until:S.day+3,f:0.6,glass:true};compute()');
assert.equal(cap('x'), 240, 'Brussels–Paris lets 60% through');
assert.equal(ev('linkDown(L(x))'), false, 'dimmed, not dark');
assert.ok(ev('R.load[x]') > 1, 'it still carries traffic');
ev('selectLink(x)');
assert.match(ev("$('panel').textContent"), /Brussels ⇄ Paris has a dirty connector: every wave in that fiber, this express too, runs at 60%/);
ev('L(s1).loss={until:S.day+3,f:0.6,glass:true};compute()');
assert.equal(cap('x'), 144, 'two dirty fibers: both bite');
ev('L(s1).loss.until=S.day;L(s2).loss.until=S.day;compute();selectLink(x)');
assert.equal(cap('x'), 400, 'cleaned: full rate again');
assert.doesNotMatch(ev("$('panel').textContent"), /dirty connector/);
// Dealt by the dice: on a fiber with channels of its own, only the dirty connector (the first of the three) is in the glass.
for (const v of [0, 1, 2]) {
ev(`L(s1).loss=null;L(s2).loss=null;S.inc=[];compute();{const q=[0.5,0.1,${(v + 0.5) / 3},0];const r0=Math.random;Math.random=()=>q.length?q.shift():r0();fireFailure('loss');Math.random=r0;}compute()`);
assert.equal(ev('!!L(s2).loss'), false, 'the dice picked the fiber with its own channel');
if (v !== 1) assert.ok(cap('s1') < 400, 'the fiber itself slows, variant ' + v);
assert.equal(ev('!!(L(s1).loss&&L(s1).loss.glass)'), v === 0, 'variant ' + v);
assert.equal(cap('x'), v === 0 ? 240 : 400, 'variant ' + v);
}
// A fiber that only carries expresses has nothing but glass to go wrong: the dice find it, and it is always the connector.
ev("L(s1).ch=[];L(s1).loss=null;S.inc=[];compute();fireFailure('loss');compute()");
assert.equal(ev('S.inc.at(-1).type'), 'loss');
assert.ok(ev('[s1,s2].includes(S.inc.at(-1).ref)'));
assert.equal(ev('L(S.inc.at(-1).ref).loss.glass'), true);
assert.equal(cap('x'), 240);
// Fixed: the express is back.
ev('clearInc(S.inc.at(-1));compute()');
assert.equal(cap('x'), 400);
assert.deepEqual(errors, []);
});
test('saves: a dirty connector keeps dimming the express after a reload; an old save\'s loss stays on its own fiber', (t) => {
const { ev, errors } = game(t);
ev(BUILD + "L(s2).loss={until:S.day+3,f:0.6,glass:true};compute()");
ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
assert.equal(ev('JSON.stringify(L(s2).loss)'), ev('JSON.stringify({until:S.day+3,f:0.6,glass:true})'));
assert.equal(Math.round(ev('capOf(L(x))')), 240);
// A loss from before the connector was told apart, or a hand-edited flag that is not true: router-side, as it was.
for (const loss of ['{until:S.day+3,f:0.6}', '{until:S.day+3,f:0.6,glass:"yes"}']) {
ev(`{const o=JSON.parse(JSON.stringify(S));o.links.find(l=>l.id===s2).loss=${loss};S=migrate(o);compute();}`);
assert.equal(ev('JSON.stringify(L(s2).loss)'), ev('JSON.stringify({until:S.day+3,f:0.6})'), loss);
assert.equal(Math.round(ev('capOf(L(x))')), 400, loss);
}
assert.deepEqual(errors, []);
});
test('MCP: the dry run of a regen site under an express quotes what the game then charges', () => {
const s = createSession(), T = (n, a = {}) => TOOLS.find((x) => x.name === n).run(s, a), ev = (x) => s.game.ev(x);
T('new_game', { city: 'fra', preset: 'sandbox', seed: 7, name: 'Probe' });
ev(BASE.replace(/^ACT\.start\(\{\}\);if\(UI\.pendGame\)ACT\.pitchSkip\(\);/, '') + SPANS + BUILD);
assert.equal(ev("S.links.filter(l=>l.kind==='xp').length"), 1);
const q = T('act', { action: 'regen', args: { id: ev('s1'), d: 1 }, dryRun: true }).quote;
assert.deepEqual(q.blocked, []);
assert.equal(q.setup, ev("REGEN_COST+Math.round(optCost('zr4')*REGEN_CH)"), 'the hut and a card for the express channel');
const c0 = ev('S.cash');
T('act', { action: 'regen', args: { id: ev('s1'), d: 1 } });
assert.equal(q.setup, c0 - ev('S.cash'), 'quote equals charge');
assert.deepEqual(s.errors(), []);
});
test('slots: lit channels, sold alien waves and express channels share every line system', (t) => {
const { ev, errors } = game(t);
ev("L(s1).ch=Array(10).fill('zr4');S.biz.push({id:uid(),city:'fra',city2:'bru',link:s1,slots:53,type:'wwave',name:'Alien Co',bw:1,rate:1000,reqs:[],mood:100,since:S.day});for(const c of ['fra','bru','par'])S.pops[c].routers=4;compute()");