Split the game page into partials under src/, assembled into one index.html at build
site/index.html (900 KB of HTML, CSS and JS in one file) becomes src/: a shell (src/index.html), styles/ and game/, concatenated in path order by scripts/lib/page.js. The assembled page is byte-identical to the old file, so load time and in-game performance are unchanged. - scripts/build.js replaces build.sh (same env vars, same output) - npm run dev: a zero-dependency dev server that assembles on every request - tests assemble the page in memory; npm test runs every tests/*.test.js - perf-bench takes --base-ref to build a git ref's page - scripts/legacy/split-index-html.js is the splitter, kept for older branches
This commit is contained in:
parent
295e68cc46
commit
67a40942b4
113 changed files with 5584 additions and 5195 deletions
39
src/game/80-simulation/80-geography-and-latency.js
Normal file
39
src/game/80-simulation/80-geography-and-latency.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
function cnOk(){return S.cnLic&&S.cnLic.state==='ok';}
|
||||
function regionMult(c){const C=CITY[c];if(!C||C.cn)return 1;if(C.kr)return KR_TRANSIT;if(C.au)return AU_TRANSIT;if(C.tape)return 1.5;return C.reg==='AS'?2.5:C.reg==='AF'?2:C.reg==='OC'?1.8:C.reg==='SA'?1.6:1;}
|
||||
const uaePair=(a,b)=>!!CITY[a].uae&&!!CITY[b].uae;
|
||||
const rainPair=(a,b)=>!!(CITY[a].rain||CITY[b].rain);
|
||||
const borderPair=(a,b)=>!!CITY[a].cc&&!!CITY[b].cc&&CITY[a].cc!==CITY[b].cc;
|
||||
// Perth to the east coast: the sea route round the south coast is domestic (AU_WAVE.ew), and the Nullarbor
|
||||
// fiber costs a little more again because the incumbents own it.
|
||||
const NULLARBOR=1.7,nullPair=(a,b)=>!!CITY[a].au&&!!CITY[b].au&&(a==='per')!==(b==='per');
|
||||
const andesPair=(a,b)=>!!CITY[a].andes&&!!CITY[b].andes&&CITY[a].andes!==CITY[b].andes;
|
||||
/* Overland between continents (Europe to the Middle East and Asia) crosses a dozen borders and as many
|
||||
carriers, each taking a cut: in real life it costs ten times the subsea route or more (#40). */
|
||||
const LAND_X=45,landX=(a,b)=>!isSub(a,b)&&CITY[a].reg!==CITY[b].reg;
|
||||
function landMult(a,b){if(isSub(a,b))return 1;if(uaePair(a,b))return 3;return (landX(a,b)?LAND_X:1)*(andesPair(a,b)?2:1)*(nullPair(a,b)?NULLARBOR:1)*(rainPair(a,b)?2:1)*(borderPair(a,b)?2:1);}
|
||||
function landWhy(a,b){if(isSub(a,b))return '';if(uaePair(a,b))return tr('Inside the UAE only the two licensed operators, Etis-a-lot and Du-opoly, may run fiber. No dark fiber, no digging your own, and waves cost 3×.');
|
||||
const r=[];if(CITY[a].reg!==CITY[b].reg)r.push(tr('Overland between continents crosses a dozen borders, and every carrier on the way takes a cut: {x}× the price. Subsea is far cheaper.',{x:LAND_X}));if(andesPair(a,b))r.push(tr('This route crosses the Andes: 2× the price, and landslides and snow cut it far more often than flat fiber.'));if(nullPair(a,b))r.push(tr('This route crosses the Nullarbor: {x}× the price. A thousand kilometres of nothing, and the incumbents own all of it.',{x:NULLARBOR}));if(borderPair(a,b))r.push(tr('This route crosses a border in Africa: 2× the price. Every country wants its own permits, its own carrier and its own cut.'));if(rainPair(a,b))r.push(tr('This route goes into the Amazon: 2× the price. The fiber runs along rivers and jungle roads, and repairs go by boat.'));return r.join(' ');}
|
||||
function linkLat(l){const f=l.kind==='df'?(l.own?(l.sub?seaLatencyFactor(l):1.1):1.25):l.kind==='vxc'?1.4:l.cable?(CAB[l.cable].lat||1):1.3;return l.km*f/200;}
|
||||
/* Wave prices differ a lot by market (TeleGeography): Europe's dense, competitive metro and
|
||||
long-haul routes are cheap (Frankfurt–London 100G ≈ $1,150/mo), the US costs more, and
|
||||
routes into Africa are several times dearer (Africa–Europe ≈ 5.9× London–New York).
|
||||
Each route also gets its own market mood, and new leases get cheaper every year (~8%). */
|
||||
const WAVE_LAND={EU:0.65,AM:1,SA:1.6,AS:1.4,OC:1.2,AF:2.2},WAVE_SUB={EU:0.8,AM:1,SA:2,AS:1.5,OC:1.5,AF:4.5};
|
||||
const WAVE_NAME={EU:tr('Europe'),AM:tr('North America'),SA:tr('South America'),AS:tr('Asia'),OC:tr('Oceania'),AF:tr('Africa')};
|
||||
function waveMarket(a,b,sub){const ra=CITY[a].reg,rb=CITY[b].reg,T=sub?WAVE_SUB:WAVE_LAND,au=sub?AU_WAVE.sub:AU_WAVE.land;
|
||||
const fa=CITY[a].au?au:(T[ra]||1),fb=CITY[b].au?au:(T[rb]||1),reg=sub&&nullPair(a,b)?AU_WAVE.ew:sub?Math.max(fa,fb):(fa+fb)/2;
|
||||
const key=a<b?a+b:b+a,mood=0.85+(hstr(key+'|mood')%31)/100;
|
||||
const ero=Math.max(0.55,Math.pow(0.92,Math.floor((S?S.day:0)/360)));
|
||||
return {m:reg*mood*ero,reg,mood,ero};}
|
||||
function marketNote(a,b,sub){const k=waveMarket(a,b,sub),ra=CITY[a].reg,rb=CITY[b].reg;const where=ra===rb?WAVE_NAME[ra]:tr('{a} to {b}',{a:WAVE_NAME[ra],b:WAVE_NAME[rb]});
|
||||
const lvl=k.reg<0.9?tr('cheap: lots of competing fiber'):k.reg<=1.05?tr('about average'):k.reg<2?tr('pricey: fewer carriers'):tr('expensive: scarce capacity');const since=k.ero<1?tr(', and prices have fallen {p}% since you started',{p:Math.round((1-k.ero)*100)}):'';
|
||||
return k.mood<0.97?tr('{where}: {lvl}. This route is {p}% below the going rate{since}.',{where,lvl,p:Math.round((1-k.mood)*100),since}):k.mood>1.03?tr('{where}: {lvl}. This route is {p}% above the going rate{since}.',{where,lvl,p:Math.round((k.mood-1)*100),since}):tr('{where}: {lvl}. This route is right at the going rate{since}.',{where,lvl,since});}
|
||||
function waveRoute(a,b,mult,border){const cabs=cablesOk(a,b),sub=isSub(a,b);let via=UI.via;
|
||||
if(!cabs.find(c=>c.cid===via))via=sub?(cabs[0]?cabs[0].cid:null):(via==='land'||!via?'land':'land');
|
||||
if(!via)return null;const bf=border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1;
|
||||
if(via==='land')return {via,cabs,cab:null,km:kmBetween(a,b),sub:false,wm:mult*landMult(a,b)*waveMarket(a,b,false).m};
|
||||
const c=cabs.find(x=>x.cid===via);return {via,cabs,cab:via,km:c.km,sub:true,wm:bf*CAB[via].price*waveMarket(a,b,true).m};}
|
||||
function viaSeg(a,b){const cabs=cablesOk(a,b),sub=isSub(a,b);if(!cabs.length)return landMult(a,b)>1?`<p class="note">${landWhy(a,b)}</p>`:'';const wr=waveRoute(a,b,1,false);
|
||||
const opts=(sub?[]:[{v:'land',l:`${tr('Overland')} <small>${landMult(a,b)>1?landMult(a,b)+'× · ':''}${(kmBetween(a,b)*1.3/200).toFixed(1)} ms</small>`}]).concat(cabs.map(c=>({v:c.cid,l:`${esc(CAB[c.cid].name)} <small>${CAB[c.cid].price}× · ${(c.km*(CAB[c.cid].lat||1)/200).toFixed(1)} ms${CAB[c.cid].age==='old'?' · '+tr('old, cuts often'):''}</small>`})));
|
||||
return `<h4 class="sub4">${tr('Route')}</h4><div class="seg">${opts.map(o=>btn(o.l,'via',{v:o.v},wr&&wr.via===o.v?'pink':'ghost')).join('')}</div>${wr&&wr.cab?`<p class="note">${esc(CAB[wr.cab].blurb)} ${tr('All your waves on one cable share its fate when it is cut.')}</p>`:''}`;}
|
||||
function bestLat(a,b){const ls=S.links.filter(l=>!linkDown(l));const dist={[a]:0},done=new Set();for(;;){let u=null,ud=Infinity;for(const k in dist)if(!done.has(k)&&dist[k]<ud){u=k;ud=dist[k];}if(u===null)break;if(u===b)return ud;done.add(u);for(const l of ls){if(l.a!==u&&l.b!==u)continue;const v=l.a===u?l.b:l.a,nd=ud+linkLat(l)+0.05;if(nd<(dist[v]??Infinity))dist[v]=nd;}}return Infinity;}
|
||||
Loading…
Add table
Add a link
Reference in a new issue