diff --git a/src/game/60-features/99-pie-in-the-sky.js b/src/game/60-features/99-pie-in-the-sky.js index 8dfa89f..746010e 100644 --- a/src/game/60-features/99-pie-in-the-sky.js +++ b/src/game/60-features/99-pie-in-the-sky.js @@ -12,8 +12,8 @@ - S.pie.spat[id] with PIE_SPATS[id]={fix(o,s),day?(o,d),end?(o)}: a spat's state, repaired by pieSanitize(), ticked and dropped when o.until<=d by pieSpatDay(d) - S.pie.crusts[id].down: day a crust is out until (a solar storm); S.pie.dishes[i].down likewise (a backhoe) - - pieGlobeData() -> {crusts:[{id,alt,inc,n,las}],dishes:[{city,lat,lon}],pads:[{city,lat,lon,next}], - launches:[{id,rk,cr,n,day,pad}]} + - pieGlobeData() -> {crusts:[{id,alt,inc,n,las}],dishes:[{city,lat,lon,up,u}],pads:[{city,lat,lon,next}], + launches:[{id,rk,cr,n,day,pad}],flows:[{id,k,g,pts:[city,city],alt?}],hi} - pieFounder(k,{n,c}) -> a Founder post (k from FOUNDER_POSTS); pieCharge(v) bills a cost (book kept) - book.earned: revenue from orbit, for the customers that come with routing. */ function pieBlank(day){const crusts={};for(const id in CRUSTS)crusts[id]={cohorts:[],queued:0}; @@ -35,9 +35,13 @@ const pieLiveLas=id=>{const c=S.pie&&S.pie.crusts[id];let n=0;if(pieLasCut(id))r const pieLicOk=cc=>{const l=S.pie&&S.pie.lic[cc];return !!l&&l.state==='ok'&&l.until>S.day;}; function pieDishes(){const P=S&&S.pie;if(!P)return [];const o=[];for(const x of P.dishes){if(!S.pops[x.city]||x.down>S.day)continue;const cc=CITY[x.city].cc;if(pieLicOk(cc))o.push({id:x.id,city:x.city,cc,ant:x.ant,g:x.ant*PIE_ANT_G*pieDishMul(x)});}return o;} function pieHubs(){return S&&S.pie?Object.keys(CRUSTS).filter(pieUp):[];} -function pieGlobeData(){const P=S&&S.pie;if(!P)return {crusts:[],dishes:[],pads:[],launches:[]};const ll=c=>({city:c,lat:CITY[c].lat,lon:CITY[c].lon}); +function pieGlobeData(){const P=S&&S.pie;if(!P)return {crusts:[],dishes:[],pads:[],launches:[]};const ll=c=>({city:c,lat:CITY[c].lat,lon:CITY[c].lon}),Q=R&&R.pie,ld=Q&&Q.load||{}; + // Traffic from the last compute: sky circuits dish to dish (k 'c'), terminals from their city to their dish (k 't'). + const flows=[];if(Q&&Q.flows)for(const f of Q.flows){if(!(f.g>0))continue;if(f.k==='c'&&f.via.length>1)flows.push({id:f.id,k:'c',g:f.g,pts:[f.via[0],f.via[f.via.length-1]],alt:f.cr?CRUSTS[f.cr].alt:550}); + else if(f.k==='t'&&f.dish)flows.push({id:f.id,k:'t',g:f.g,pts:[f.city,f.dish]});} return {crusts:Object.keys(CRUSTS).map(id=>({id,alt:CRUSTS[id].alt,inc:CRUSTS[id].inc,n:pieLive(id),las:pieLiveLas(id)})), - dishes:P.dishes.map(x=>ll(x.city)),pads:P.pads.map(p=>({...ll(p.city),next:p.next})),launches:P.q.map(L=>({id:L.id,rk:L.rk,cr:L.cr,n:L.n,day:L.day,pad:L.pad}))};} + dishes:P.dishes.map(x=>({...ll(x.city),up:!(x.down>S.day),u:ld[x.city]})),pads:P.pads.map(p=>({...ll(p.city),next:p.next})),launches:P.q.map(L=>({id:L.id,rk:L.rk,cr:L.cr,n:L.n,day:L.day,pad:L.pad})), + flows:flows.sort((a,b)=>b.g-a.g),hi:UI.pieHi||null};} // Spats (geopolitics) register in PIE_SPATS and keep their state in S.pie.spat; this ticks and ends them. function pieSpatDay(d){const sp=S.pie.spat;for(const k of Object.keys(sp)){const o=sp[k],D=PIE_SPATS[k];if(!D||o.until<=d){delete sp[k];if(D&&D.end)D.end(o);continue;}if(D.day)D.day(o,d);}} const pieYear=d=>1+Math.floor(d/360); diff --git a/src/game/96-map/60-draw.js b/src/game/96-map/60-draw.js index ae2dcdf..4753041 100644 --- a/src/game/96-map/60-draw.js +++ b/src/game/96-map/60-draw.js @@ -104,7 +104,7 @@ function drawFrame(now){ const farL=lodFar(); // Which cities show an offer bubble (a big one?) or an incident marker, worked out once for all of them. CM.off=new Set();CM.big=new Set();for(const o of S.offers){const big=BIZ_T[o.type].lv>=3||BIZ_T[o.type].event;for(const c of bCities(o)){CM.off.add(c);if(big)CM.big.add(c);}} - CM.inc=new Set(S.inc.filter(i=>i.type!=='leak').map(i=>i.ref));CM.far=farL;CM.dish=pieDishMap(); + CM.inc=new Set(S.inc.filter(i=>i.type!=='leak').map(i=>i.ref));CM.far=farL;CM.dish=pieDishMap();CM.dl=CM.dish&&R&&R.pie?R.pie.load:null; // Zoomed in, crowded small cities give way to bigger ones and become dots (75-city-size.js). const csc=cityScale(sc);if(farL)for(const v of vis)v.dem=false;else cityRoom(vis,csc); if(pzOn()&&!farL)for(const v of vis)if(pzQuiet(v.C.id))v.dem=true; diff --git a/src/game/96-map/80-cities.js b/src/game/96-map/80-cities.js index 44cc489..2e9c9ea 100644 --- a/src/game/96-map/80-cities.js +++ b/src/game/96-map/80-cities.js @@ -3,8 +3,10 @@ const LBLW={},LINKW=new Map(),LBLF=new Map(),FKEY=new Map(),QKEY=new Map(),CM={o // Pie dishes (Pie in the Sky): city -> up?, or null without any, so most maps pay one null check per city. function pieDishMap(){const d=S.pie&&S.pie.dishes;if(!Array.isArray(d)||!d.length)return null;const m=new Map();for(const x of d)if(x&&x.city)m.set(x.city,m.get(x.city)||!(x.down>S.day));return m;} // Painted once per look and drawn as a sprite, so it shows on the graphics-card map as well. -function dishBadge(x,y,up,k=1){stamp(up?'dish|1':'dish|0',16,16,8,8,k,x,y,()=>dishPaint(0,0,up));} -function dishPaint(x,y,up){ctx.fillStyle=up?'#FF4F9A':'#8A91A8';ctx.strokeStyle='#1E2640';ctx.lineWidth=1.6;ctx.beginPath();ctx.arc(x,y,5.5,0,7);ctx.fill();ctx.stroke();ctx.strokeStyle='#fff';ctx.lineWidth=1.4;ctx.beginPath();ctx.arc(x,y-1,3,0.15*Math.PI,0.85*Math.PI);ctx.moveTo(x,y+2);ctx.lineTo(x+2.6,y-2.6);ctx.stroke();ctx.strokeStyle='#1E2640';} +// Painted once per look (the load in 5% steps) and drawn as a sprite, so it shows on the graphics-card map as well. +function dishBadge(x,y,up,u,k=1){const q=u>0.005?Math.min(20,Math.round(u*20)):0;stamp('dish|'+(up?1:0)+'|'+q,20,20,10,10,k,x,y,()=>dishPaint(0,0,up,q/20));} +function dishPaint(x,y,up,u){if(u>0.005){ctx.lineWidth=1.8;ctx.strokeStyle='rgba(30,38,64,.3)';ctx.beginPath();ctx.arc(x,y,8,0,7);ctx.stroke();ctx.strokeStyle=u>=0.9?'#FF4D5E':u>=0.6?'#FFAA1F':'#22C47A';ctx.beginPath();ctx.arc(x,y,8,-Math.PI/2,-Math.PI/2+Math.min(1,u)*2*Math.PI);ctx.stroke();} + ctx.fillStyle=up?'#FF4F9A':'#8A91A8';ctx.strokeStyle='#1E2640';ctx.lineWidth=1.6;ctx.beginPath();ctx.arc(x,y,5.5,0,7);ctx.fill();ctx.stroke();ctx.strokeStyle='#fff';ctx.lineWidth=1.4;ctx.beginPath();ctx.arc(x,y-1,3,0.15*Math.PI,0.85*Math.PI);ctx.moveTo(x,y+2);ctx.lineTo(x+2.6,y-2.6);ctx.stroke();ctx.strokeStyle='#1E2640';} try{document.fonts&&document.fonts.ready.then(()=>{for(const k in LBLW)delete LBLW[k];LINKW.clear();LBLF.clear();FRAME.length=0;spritesReset();});}catch(e){} // A label on a pill: its text and look never change, so it is painted once (spriteEntry) and drawn as a picture. The // centre is x, y; the text sits at y+ty. The pill's box is w×h with corners r; the picture also takes the outline. @@ -26,7 +28,7 @@ function drawCityFar(C,sx,sy,sc,now,lyOverride){ // The key, kept per city and built again only when the picture changes. let m=FKEY.get(C.id);if(!m||m.f!==f||m.t!==t||m.ph!==ph)FKEY.set(C.id,m={f,t,ph,k:'far|'+t+'|'+f+'|'+ph}); stamp(m.k,36,36,18,18,1,sx,sy,()=>cityFarStatic(C,p,down,sel,hov,ph)); - if(CM.dish&&CM.dish.has(C.id))dishBadge(sx+(p?10:6),sy+(p?6:5),CM.dish.get(C.id)); + if(CM.dish&&CM.dish.has(C.id))dishBadge(sx+(p?10:6),sy+(p?6:5),CM.dish.get(C.id),CM.dl&&CM.dl[C.id]); if(lyOverride!==null&&(p||sel||hov)){ctx.font=`800 ${p?12:11}px "Baloo 2", sans-serif`;const t=C.name,wk=C.id+(p?1:0);let tw=LBLF.get(wk);if(tw===undefined)LBLF.set(wk,tw=ctx.measureText(t).width+12);const ly=lyOverride==null?sy+15:lyOverride; pill(t,ctx.font,tw,16,8,p?'#FF4F9A':'#FFFFFF',p?'#FFFFFF':'#1E2640','#1E2640',1.6,sx,ly,1);} } @@ -136,7 +138,7 @@ function drawCity(C,sx,sy,sc,now,lyOverride,dem){ if(ph.gl>=0)dot(sx,sy-6*k,26*k,'rgba(255,77,94,1)',.35+.25*(2*ph.gl/7-1)); blit(spr,sx-spr.ax*r,sy-spr.ay*r,spr.w*r,spr.h*r); cityMoving(C,p,t,cs,k,sx,sy,now,p?18:SKY_H[t],st,hot); - if(CM.dish&&p&&CM.dish.has(C.id))dishBadge(sx,sy-13*k,CM.dish.get(C.id),k); // between the antennas: the corners are taken + if(CM.dish&&p&&CM.dish.has(C.id))dishBadge(sx,sy-13*k,CM.dish.get(C.id),CM.dl&&CM.dl[C.id],k); // between the antennas: the corners are taken // label if((cam.z>=0.62||p||sel||hov)&&(lyOverride!==null||hov)){ ctx.font=`800 ${p?13:12}px "Baloo 2", sans-serif`;const t=C.name,tw=LBLW[C.id+(p?1:0)]||(LBLW[C.id+(p?1:0)]=ctx.measureText(t).width+14),ly=lyOverride==null?sy+16*sc+8:lyOverride; diff --git a/src/game/96-map/89-pie-globe.js b/src/game/96-map/89-pie-globe.js index dabf626..275b227 100644 --- a/src/game/96-map/89-pie-globe.js +++ b/src/game/96-map/89-pie-globe.js @@ -1,14 +1,17 @@ /* Pie in the Sky globe (Pie Control panel): an orthographic Earth on a 2D canvas with a sample of your pies in their crusts, laser links, pie-dish beams and launches. Never drawn on the world map. It costs nothing until the panel calls pieGlobeOpen(canvas,getData): then one rAF loop, at most 30 frames a second, idle while the canvas is hidden; it stops - by itself (pieGlobeClose()) once the canvas leaves the page. Positions come from the clock, so nothing is saved. */ -const PG_D=Math.PI/180,PG_XF=2.6,PG_FPS=30,PG_FULL={short:1584,frozen:520,upper:1200,flaky:2500},PG_CI={short:0,frozen:1,upper:2,flaky:3}; + by itself (pieGlobeClose()) once the canvas leaves the page. Positions come from the clock, so nothing is saved. + Traffic (data.flows, from the last compute): a sky circuit is a glowing arc from one dish up to its crust, across and + down to the other, as wide as its Gbps (log scale, capped), with packets riding it; a terminal customer is a hop from + its city off the sky to its dish. Each dish has a load ring. data.hi (a flow id) is drawn on top, the rest dimmed. */ +const PG_FLOWS=[24,48],PG_ARC=24,PG_D=Math.PI/180,PG_XF=2.6,PG_FPS=30,PG_FULL={short:1584,frozen:520,upper:1200,flaky:2500},PG_CI={short:0,frozen:1,upper:2,flaky:3}; const PG_ST={ - day:{sea:'#57C4E5',sea2:'#3AA6CF',land:'#9BDA6C',ink:'#1E2640',grid:'rgba(255,255,255,.35)',sat:['#FFFFFF','#FFD23F','#FF4F9A','#B9A6FF'],laser:'#FF4F9A',beam:['#FF8A3D','#FFD23F'],dish:'#FF4F9A',off:'#8A91A8'}, - night:{bg:'#0B1030',sea:'#14234F',sea2:'#0B1638',land:'#24396F',ink:'#3E5BB0',grid:'rgba(120,150,255,.10)',sat:['#7DF9FF','#FFD23F','#FF7AC0','#C9B8FF'],laser:'rgba(255,79,154,.75)',beam:['rgba(255,210,63,.65)','rgba(255,138,61,.5)'],dish:'#FFD23F',off:'#4A5378'}}; + day:{sea:'#57C4E5',sea2:'#3AA6CF',land:'#9BDA6C',ink:'#1E2640',grid:'rgba(255,255,255,.35)',sat:['#FFFFFF','#FFD23F','#FF4F9A','#B9A6FF'],laser:'#FF4F9A',beam:['#FF8A3D','#FFD23F'],dish:'#FF4F9A',off:'#8A91A8',flow:'#FFD23F',fglow:'#1E2640',hi:'#FF4F9A',pkt:'#FFFFFF'}, + night:{bg:'#0B1030',sea:'#14234F',sea2:'#0B1638',land:'#24396F',ink:'#3E5BB0',grid:'rgba(120,150,255,.10)',sat:['#7DF9FF','#FFD23F','#FF7AC0','#C9B8FF'],laser:'rgba(255,79,154,.75)',beam:['rgba(255,210,63,.65)','rgba(255,138,61,.5)'],dish:'#FFD23F',off:'#4A5378',flow:'rgba(255,230,140,.9)',fglow:'rgba(255,210,63,.22)',hi:'#FF7AC0',pkt:'#FFFFFF'}}; // The whole state of the globe. cv is null whenever it is closed, and then nothing below runs. const PG={cv:null,ctx:null,get:null,raf:0,last:0,t:0,yaw:-20,tilt:18,vy:0,drag:null,night:null,anim:true,dirty:true, - data:null,dAt:-1e9,sig:'',sm:[],dish:[],pads:[],lch:[],on:null,g:null,frames:0,m:new Float64Array(9)}; + data:null,dAt:-1e9,sig:'',sm:[],dish:[],fl:[],hi:null,pads:[],lch:[],on:null,g:null,frames:0,m:new Float64Array(9)}; let PG_LAND=null,PG_GRID=null,PG_LIGHT=null,PG_STAR=null; const pgNightPref=()=>{if(PG.night===null){try{PG.night=localStorage.getItem('sot-globe')==='night';}catch(e){PG.night=false;}}return PG.night;}; // Unit vectors for the land rings (LANDS_LL), the graticule, city lights and stars: worked out once, on first open. @@ -28,7 +31,7 @@ const pgBuf=n=>(PG.buf&&PG.buf.length>=n*3)?PG.buf:(PG.buf=new Float32Array(Math const pgNum=(x,d)=>typeof x==='number'&&isFinite(x)?x:d,pgArr=x=>Array.isArray(x)?x:[]; // A place is {lat,lon} or a city id in .city (or .pad, as launches name their pad). function pgPlace(list,cap){const out=[];for(const o of pgArr(list)){if(out.length>=cap)break;if(!o)continue;const id=typeof o.city==='string'?o.city:typeof o.pad==='string'?o.pad:null,C=id&&Object.prototype.hasOwnProperty.call(CITY,id)?CITY[id]:null; - const lat=pgNum(o.lat,C?C.lat:NaN),lon=pgNum(o.lon,C?C.lon:NaN);if(!isFinite(lat)||!isFinite(lon))continue;const v=new Float32Array(3);pgUnit(lon,lat,v,0);out.push({v,up:o.up!==false});}return out;} + const lat=pgNum(o.lat,C?C.lat:NaN),lon=pgNum(o.lon,C?C.lon:NaN);if(!isFinite(lat)||!isFinite(lon))continue;const v=new Float32Array(3);pgUnit(lon,lat,v,0);out.push({v,up:o.up!==false,u:typeof o.u==='number'&&isFinite(o.u)?Math.max(0,Math.min(1,o.u)):null});}return out;} function pgRefresh(now){PG.dAt=now;let d=null;try{d=PG.get?PG.get():null;}catch(e){d=null;}d=d&&typeof d==='object'?d:{}; const cr=pgArr(d.crusts).filter(c=>c&&pgNum(c.n,0)>0).slice(0,8),ph=isPhone(),cap=ph?80:160; const sig=ph+'|'+cr.map(c=>[c.id,c.n,c.alt,c.inc,!!c.las].join(':')).join(','); @@ -38,7 +41,19 @@ function pgRefresh(now){PG.dAt=now;let d=null;try{d=PG.get?PG.get():null;}catch( const P=Math.max(1,Math.round(polar?Math.sqrt(cnt/2):Math.sqrt(cnt*1.2))),K=Math.ceil(cnt/P),span=polar?Math.PI:2*Math.PI; const co=new Float32Array(P),so=new Float32Array(P);for(let p=0;p
{if(!f||typeof f.id!=='string'||seen.has(f.id))return;const g=pgNum(f.g,0),pts=pgPlace(pgArr(f.pts).map(c=>({city:c})),2);if(!(g>0)||pts.length<2)return;
+ const a=pts[0].v,b=pts[1].v,dot=Math.max(-1,Math.min(1,a[0]*b[0]+a[1]*b[1]+a[2]*b[2])),om=Math.acos(dot);if(om<1e-3)return;seen.add(f.id);
+ const sky=f.k==='c',h=(sky?Math.max(200,Math.min(2000,pgNum(f.alt,550))):550)/6371*PG_XF,raw=new Float32Array((PG_ARC+1)*3),so=Math.sin(om);
+ for(let i=0;i<=PG_ARC;i++){const s=i/PG_ARC,p=Math.sin((1-s)*om)/so,q=Math.sin(s*om)/so,r=1+h*(sky?Math.min(1,s/0.15,(1-s)/0.15):Math.sin(Math.PI*s));
+ raw[i*3]=(p*a[0]+q*b[0])*r;raw[i*3+1]=(p*a[1]+q*b[1])*r;raw[i*3+2]=(p*a[2]+q*b[2])*r;}
+ out.push({id:f.id,sky,w:Math.min(7,1.2+1.5*Math.log10(1+g)),raw,pos:new Float32Array(raw.length),pk:Math.min(4,1+Math.floor(Math.log10(1+g)))});};
+ if(hi)take(L.find(f=>f&&f.id===hi));for(const f of L){if(out.length>=cap)break;take(f);}return out;}
+const pgLoadCol=u=>u>=0.9?'#FF4D5E':u>=0.6?'#FFAA1F':'#22C47A';
function pgSats(){for(const c of PG.sm){const raw=pgBuf(c.cnt);let i=0;
for(let p=0;p