Merge pull request #142 from LookedPath:fix/subsea-upgrade-scheduling

This commit is contained in:
Frederic Jung 2026-10-27 07:19:16 +00:00
commit 813e8d95e3
No known key found for this signature in database
7 changed files with 220 additions and 7 deletions

View file

@ -1286,7 +1286,6 @@
"<b>Dark fiber IRU signed.</b><br>{a}–{b} will be spliced and handed over in about 30 days.":"<b>IRU de fibre noire signé.</b><br>{a}–{b} sera soudée et livrée dans environ 30 jours.",
"<b>Can't add {optic}.</b><br>{why}":"<b>Impossible d’ajouter {optic}.</b><br>{why}",
"<b>Line system swap</b><br>All channels are dark for a day while the ROADMs go in.":"<b>Changement de système de ligne</b><br>Tous les canaux sont éteints pendant une journée, le temps de poser les ROADM.",
"<b>More crews on site.</b><br>Construction is 30 days ahead.":"<b>Plus d’équipes sur le chantier.</b><br>Les travaux ont 30 jours d’avance.",
"Generator!":"Groupe électrogène !",
"Start {name}?":"Lancer {name} ?",
"{name} will be replaced. Export it from the menu first if you want to keep it.":"{name} sera remplacé. Exporte-le d’abord depuis le menu si tu veux le garder.",
@ -2897,4 +2896,7 @@
"A ferry dropped anchor in Cook Strait and found your {a}–{b} cable. The ferry is fine.":"Un ferry a jeté l’ancre dans le détroit de Cook et a trouvé ton câble {a}–{b}. Le ferry va bien.",
"The smelter at Tiwai Point pulled a little harder on the grid, and your POP in {city} blinked first.":"La fonderie de Tiwai Point a tiré un peu plus fort sur le réseau, et ton POP à {city} a flanché le premier.",
"<b>Australia got more Australian.</b><br>Transit there now costs three times the usual price, only carriers that really sell transit in Australia sell it, and Telstraya and Floptus only peer privately, so their exchange sessions have ended. Check your Australian POPs.":"<b>L’Australie est devenue plus australienne.</b><br>Le transit y coûte désormais trois fois le prix habituel, seuls les opérateurs qui en vendent vraiment en Australie en vendent, et Telstraya et Floptus ne font plus que du peering privé, donc leurs sessions à l’IX sont terminées. Vérifie tes POP australiens.",
"Finish in 1 day <small>{price}</small>":"Terminer en 1 jour <small>{price}</small>",
"<b>More crews on site.</b><br>Construction is {n} days ahead.":"<b>Des équipes en renfort.</b><br>Les travaux ont {n} jours d’avance.",
"<b>More crews on site.</b><br>Construction is {n} day ahead.":"<b>Des équipes en renfort.</b><br>Les travaux ont {n} jour d’avance.",
};

View file

@ -1287,7 +1287,6 @@
"<b>Dark fiber IRU signed.</b><br>{a}–{b} will be spliced and handed over in about 30 days.":"<b>IRU di dark fiber firmato.</b><br>{a}–{b} sarà giuntata e consegnata in circa 30 giorni.",
"<b>Can't add {optic}.</b><br>{why}":"<b>Impossibile aggiungere {optic}.</b><br>{why}",
"<b>Line system swap</b><br>All channels are dark for a day while the ROADMs go in.":"<b>Cambio del line system</b><br>Tutti i canali restano spenti per un giorno mentre si installano i ROADM.",
"<b>More crews on site.</b><br>Construction is 30 days ahead.":"<b>Più squadre in cantiere.</b><br>I lavori sono avanti di 30 giorni.",
"Generator!":"Generatore!",
"Start {name}?":"Vuoi iniziare {name}?",
"{name} will be replaced. Export it from the menu first if you want to keep it.":"La partita con {name} verrà sostituita. Se vuoi tenerla, prima esportala dal menu.",
@ -2897,4 +2896,7 @@
"A ferry dropped anchor in Cook Strait and found your {a}–{b} cable. The ferry is fine.":"Un traghetto ha gettato l’ancora nello Stretto di Cook e ha trovato il tuo cavo {a}–{b}. Il traghetto sta bene.",
"The smelter at Tiwai Point pulled a little harder on the grid, and your POP in {city} blinked first.":"La fonderia di Tiwai Point ha tirato un po’ di più dalla rete, e il tuo POP a {city} ha ceduto per primo.",
"<b>Australia got more Australian.</b><br>Transit there now costs three times the usual price, only carriers that really sell transit in Australia sell it, and Telstraya and Floptus only peer privately, so their exchange sessions have ended. Check your Australian POPs.":"<b>L’Australia è diventata più australiana.</b><br>Il transito lì ora costa tre volte il prezzo normale, lo vendono solo gli operatori che lo vendono davvero in Australia, e Telstraya e Floptus fanno peering solo in privato, quindi le loro sessioni all’exchange sono terminate. Controlla i tuoi POP australiani.",
"Finish in 1 day <small>{price}</small>":"Termina in 1 giorno <small>{price}</small>",
"<b>More crews on site.</b><br>Construction is {n} days ahead.":"<b>Più squadre sul posto.</b><br>I lavori sono in anticipo di {n} giorni.",
"<b>More crews on site.</b><br>Construction is {n} day ahead.":"<b>Più squadre sul posto.</b><br>I lavori sono in anticipo di {n} giorno.",
};

View file

@ -1286,7 +1286,6 @@
"<b>Dark fiber IRU signed.</b><br>{a}–{b} will be spliced and handed over in about 30 days.":"<b>IRU de dark fiber assinado.</b><br>{a}–{b} será emendada e entregue em uns 30 dias.",
"<b>Can't add {optic}.</b><br>{why}":"<b>Não dá para adicionar {optic}.</b><br>{why}",
"<b>Line system swap</b><br>All channels are dark for a day while the ROADMs go in.":"<b>Troca do line system</b><br>Todos os canais ficam apagados por um dia enquanto os ROADMs são instalados.",
"<b>More crews on site.</b><br>Construction is 30 days ahead.":"<b>Mais equipes na obra.</b><br>A construção está 30 dias adiantada.",
"Generator!":"Gerador!",
"Start {name}?":"Começar {name}?",
"{name} will be replaced. Export it from the menu first if you want to keep it.":"{name} será substituído. Exporte pelo menu antes se quiser guardar.",
@ -2897,4 +2896,7 @@
"A ferry dropped anchor in Cook Strait and found your {a}–{b} cable. The ferry is fine.":"Uma balsa lançou âncora no Estreito de Cook e achou seu cabo {a}–{b}. A balsa está bem.",
"The smelter at Tiwai Point pulled a little harder on the grid, and your POP in {city} blinked first.":"A fundição de Tiwai Point puxou um pouco mais da rede, e seu POP em {city} piscou primeiro.",
"<b>Australia got more Australian.</b><br>Transit there now costs three times the usual price, only carriers that really sell transit in Australia sell it, and Telstraya and Floptus only peer privately, so their exchange sessions have ended. Check your Australian POPs.":"<b>A Austrália ficou mais australiana.</b><br>O trânsito lá agora custa três vezes o preço normal, só as operadoras que realmente vendem trânsito na Austrália o vendem, e Telstraya e Floptus só fazem peering privado, então as sessões delas no IX terminaram. Confira seus POPs australianos.",
"Finish in 1 day <small>{price}</small>":"Concluir em 1 dia <small>{price}</small>",
"<b>More crews on site.</b><br>Construction is {n} days ahead.":"<b>Mais equipes no local.</b><br>A construção está {n} dias adiantada.",
"<b>More crews on site.</b><br>Construction is {n} day ahead.":"<b>Mais equipes no local.</b><br>A construção está {n} dia adiantada.",
};

View file

@ -754,6 +754,23 @@ const SUB_MAXKM=()=>subReach(1,1);
const SUB_UPGRADES={terminal:{n:N_('Premium submarine terminals'),cost:5000000,days:30},engineering:{n:N_('Optical engineering'),cost:12000000,days:180}};
const subUpgradeReady=(l,k)=>l.kind==='df'&&l.sub&&l.own&&Number.isFinite(l['sub'+k])&&l['sub'+k]<=S.day;
const subUpgradeCost=(l,k)=>SUB_UPGRADES[k].cost+(k==='engineering'?Math.round(l.km*1000):0);
// Pending transmission work follows the construction schedule. Keep the actual
// shift (the last crew purchase can save fewer than 30 days) and completed work.
function setCableReady(l,ready,day=S.day){const shift=ready-l.ready;
if(l.kind==='df'&&l.own&&l.sub)for(const k of Object.keys(SUB_UPGRADES)){
const f='sub'+k;if(Number.isFinite(l[f])&&l[f]>day)l[f]=Math.max(day+1,l[f]+shift);
}l.ready=ready;
}
const crewCost=l=>Math.round(15000+l.km*6);
const crewSteps=l=>Math.max(0,Math.ceil((l.ready-S.day-1)/30));
// Old saves lack purchase dates. Only shorten dates beyond any valid remaining
// commissioning window. Credit elapsed time since the actual cable finish;
// recent purchases and installed upgrades stay untouched.
function repairSubUpgradeDates(l,day){if(l.kind!=='df'||!l.own||!l.sub)return;
for(const [k,U] of Object.entries(SUB_UPGRADES)){const f='sub'+k;
if(Number.isFinite(l[f])&&l[f]>Math.max(day,l.ready)+U.days)l[f]=l.ready+U.days;
}
}
function optModes(o,l){return (OPT[o].modes||[[OPT[o].g,OPT[o].reach]]).map(([g,r])=>{
let reach=reachOn(r,l.sub);
if(l.sub&&['tp16','tp32'].includes(o)&&g<=1200){
@ -2438,6 +2455,7 @@ function sanitize(s){
if(!isCity(s.home))s.home=Object.keys(s.pops)[0]||'fra';
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);l.km=num(l.km,kmBetween(l.a,l.b));l.mo=num(l.mo,0);l.cut=num(l.cut,0);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='wave';if(l.kind==='wave')l.tier=int(l.tier,0,LT.length-1,0);if(l.cable&&!own(CAB,l.cable))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);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);if(l.metric&&!own(MET,l.metric))l.metric='normal';return l;});
for(const l of s.links)repairSubUpgradeDates(l,s.day);
const degO=v=>v&&typeof v==='object'?{until:num(v.until,0),f:Math.min(1,Math.max(0,num(v.f,1)))}:null;
s.transit=s.transit.filter(t=>t&&isCity(t.city)&&isNet(t.net)).map(t=>(t.lacp=degO(t.lacp),t.site=['a','b','ab'].includes(t.site)?t.site:'a',t.id=sid(t.id),t.tier=tier(t.tier),t.n=lag(t.n),t.down=num(t.down,0),t.clean=!!t.clean,t));
s.pni=s.pni.filter(x=>x&&isCity(x.city)&&isNet(x.net)).map(x=>(x.lacp=degO(x.lacp),x.site=['a','b','ab'].includes(x.site)?x.site:'a',x.id=sid(x.id),x.tier=tier(x.tier),x.n=lag(x.n),x.sacrif=!!x.sacrif,x));
@ -2990,7 +3008,7 @@ function dayTick(){
{const top=custLevel();if(top>(S.lvl||1)){for(let lv=(S.lvl||1)+1;lv<=top;lv++){track('level_'+lv);toast(tr('<b>Customer level {lv}: {name}</b><br>New customers unlocked: {unlock}',{lv,name:LEVELS[lv-1].n,unlock:LEVELS[lv-1].unlock})+`<br><i>${esc(LEVELS[lv-1].q)}</i>`,'goal');}S.lvl=top;sfx('coin');}}
for(const l of S.links){if(l.kind!=='df')continue;
if(l.ready===d){toast(`<b>${l.own?tr('Your fiber is finished: {a}–{b}',{a:CITY[l.a].name,b:CITY[l.b].name}):tr('Dark fiber handed over: {a}–{b}',{a:CITY[l.a].name,b:CITY[l.b].name})}</b><br>${(l.ch||[]).length?tr('Channels are lighting up now.'):tr('It is dark. Add optics to light it up.')}`,'goal',[{l:tr('Open'),act:'selLink',args:{id:l.id}}]);sfx('coin');}
if(l.own&&l.ready>d&&Math.random()<0.012){const extra=10+Math.floor(Math.random()*40);l.ready+=extra;toast(tr('<b>Construction delay: +{n} days</b><br>{why} ({a}–{b})',{n:extra,why:pick(l.sub?SEA_DELAYS.map(x=>tr(x)):[tr('Archaeologists found a Roman bathhouse on your route.'),tr('A protected hamster species lives along the right-of-way.'),tr('The railway changed its mind about the easement.'),tr('The drilling crew hit a granite boulder the size of a bus.'),tr('A town council wants a public hearing. About the color of the manhole covers.'),tr('Somebody else’s gas main was exactly where the map said it was not.'),tr('The permit office lost your permit. And then the replacement.')]),a:CITY[l.a].name,b:CITY[l.b].name}),'bad');}}
if(l.own&&l.ready>d&&Math.random()<0.012){const extra=10+Math.floor(Math.random()*40);setCableReady(l,l.ready+extra);toast(tr('<b>Construction delay: +{n} days</b><br>{why} ({a}–{b})',{n:extra,why:pick(l.sub?SEA_DELAYS.map(x=>tr(x)):[tr('Archaeologists found a Roman bathhouse on your route.'),tr('A protected hamster species lives along the right-of-way.'),tr('The railway changed its mind about the easement.'),tr('The drilling crew hit a granite boulder the size of a bus.'),tr('A town council wants a public hearing. About the color of the manhole covers.'),tr('Somebody else’s gas main was exactly where the map said it was not.'),tr('The permit office lost your permit. And then the replacement.')]),a:CITY[l.a].name,b:CITY[l.b].name}),'bad');}}
// DDoS protection SLA: if a protected customer's own city is hit and still goes down, you pay out (once per attack).
if(S.ev.ddos&&S.ev.ddos.until>d){const a=S.ev.ddos;
for(const b of S.biz)if(b.type==='scrub'&&b.city===a.city&&b.slaFor!==a.start&&sfOf(R,b.city)<0.85){
@ -3407,7 +3425,7 @@ const ACT={
addPair:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||!isRdm(l.sys)||l.ready>S.day)return;const n=Math.max(1,l.pairs|0);if(n>=pairsMax(l))return;if((l.ch||[]).length+soldSlots(l)<chMax(l)){toast(tr('<b>Fill this pair first.</b><br>Light all {max} channels before you light another fiber pair.',{max:chMax(l)}),'bad');sfx('err');return;}if(!spend(pairCost(l)))return;l.pairs=n+1;toast(tr('<b>Fiber pair {n} is lit: {a}–{b}.</b><br>Another ROADMaster 9000 and a fresh chain of amplifiers. Room for {m} more channels.',{n:n+1,a:CITY[l.a].name,b:CITY[l.b].name,m:DF_SYS[l.sys].max}),'good');sfx('build');after();},
upSys:({id})=>{const l=S.links.find(x=>x.id===id),to=l&&sysNext(l);if(!to||DF_SYS[to].lvl>lvl())return;if(!spend(sysUpCost(l)))return;l.sys=to;if(l.ready<=S.day){l.eqDown=S.day+1;toast(tr('<b>Line system swap</b><br>All channels are dark for a day while the ROADMs go in.'),'bad');}after();},
spares:({id})=>{const l=S.links.find(x=>x.id===id);if(!l)return;l.spares=!l.spares;sfx('click');after();},
crews:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||l.ready<=S.day)return;const c=Math.round(15000+l.km*6);if(!spend(c))return;l.ready=Math.max(S.day+1,l.ready-30);toast(tr('<b>More crews on site.</b><br>Construction is 30 days ahead.'),'good');after();},
crews:({id,all})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||l.ready<=S.day+1)return;const n=all?crewSteps(l):1,c=n*crewCost(l);if(!spend(c))return;const ready=Math.max(S.day+1,l.ready-30*n),saved=l.ready-ready;setCableReady(l,ready);toast(trn('<b>More crews on site.</b><br>Construction is {n} day ahead.','<b>More crews on site.</b><br>Construction is {n} days ahead.',saved,{n:saved}),'good');after();},
addGen:({city})=>{const p=S.pops[city];if(!p||p.gen)return;if(!spend(GEN_COST))return;p.gen=true;floater(CITY[city].x,CITY[city].y-30,tr('Generator!'),'#FF8A3D');after();},
randomName:()=>{const input=$('nmIn');if(input)input.value=UI.nm=randomNetworkName(input.value);},
start:()=>{const nm=(($('nmIn')&&$('nmIn').value)||randomNetworkName()).slice(0,24);beginGame(nm,UI.startCity,{mode:UI.mode==='sandbox'?'sandbox':'normal'});},
@ -3874,7 +3892,7 @@ function dfPanel(l){
const load=R.load[l.id]||0,cap=dfCap(l),u=cap?load/cap:0,bld=l.ready>S.day,A=CITY[l.a].name,B=CITY[l.b].name,inc=S.inc.find(i=>i.ref===l.id||i.ref===(l.trench||l.id)),amps=ampCount(l.km),sysD=DF_SYS[l.sys];
let h=`<div class="ph"><div><div class="eyebrow">${tr('Dark fiber · {kind} · {km} km',{kind:l.own?tr('your own build'):tr('leased IRU'),km:l.km.toLocaleString()})}</div><h2>${A} ⇄ ${B}</h2></div><button class="x" data-act="closePanel" aria-label="${tr('Close')}">×</button></div><div class="scroll">`;
if(bld){const tot=Math.max(1,l.ready-l.day),done=clamp((S.day-l.day)/tot,0,1);
h+=`<section><h3>${l.own?tr('Under construction'):tr('Being spliced')}</h3><div class="kv"><span>${l.own?tr('Permits, trenching, splicing'):tr('IRU handover')}</span><b>${tr('{n} days left',{n:l.ready-S.day})}</b></div><div class="bar me"><i style="width:${done*100}%"></i></div>${l.own?btn(tr('Hire extra crews <small>{price} · −30 days</small>',{price:fmt$(Math.round(15000+l.km*6))}),'crews',{id:l.id},'sm',S.cash<15000+l.km*6):''}<p class="note">${tr("You can pre-install optics now so it lights up the day it's ready.")}</p></section>`;}
h+=`<section><h3>${l.own?tr('Under construction'):tr('Being spliced')}</h3><div class="kv"><span>${l.own?tr('Permits, trenching, splicing'):tr('IRU handover')}</span><b>${tr('{n} days left',{n:l.ready-S.day})}</b></div><div class="bar me"><i style="width:${done*100}%"></i></div>${l.own?`<div class="btns">${btn(tr('Hire extra crews <small>{price} · −30 days</small>',{price:fmt$(crewCost(l))}),'crews',{id:l.id},'sm',l.ready<=S.day+1||S.cash<crewCost(l))}${btn(tr('Finish in 1 day <small>{price}</small>',{price:fmt$(crewSteps(l)*crewCost(l))}),'crews',{id:l.id,all:1},'sm',!crewSteps(l)||S.cash<crewSteps(l)*crewCost(l))}</div>`:''}<p class="note">${tr("You can pre-install optics now so it lights up the day it's ready.")}</p></section>`;}
else if(inc&&linkDown(l))h+=`<section><h3 style="color:var(--bad)">${tr('Dark!')}</h3><p class="lead">${esc(inc.msg)}</p>${inc.cost?btn(`${esc(inc.fix||tr('Rush repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash<inc.cost):''}</section>`;
h+=`<section><h3>${tr('Capacity')}</h3><div class="kv"><span>${tr('{n} of {max} channels lit',{n:(l.ch||[]).length,max:chMax(l)})}${soldSlots(l)?` · ${tr('{n} sold as alien waves',{n:soldSlots(l)})}`:''}</span><b>${fmtG(load)} / ${fmtG(cap)}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100)}%"></i></div>
${l.own&&l.sub?`<div class="kv"><span>${tr('Cable design')}</span><b>${tr((SEA_DESIGNS[l.seaDesign]||SEA_DESIGNS.standard).n)}</b></div>`:''}