diff --git a/CHANGELOG.md b/CHANGELOG.md index 8da11b2..7eb47aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to this project are documented here. The project follows - Your pies now carry traffic and earn money: homes and boats in the remotest places (Pitcairn, the Arctic, the outer islands), airlines, cruise ships and the Mars mission sign up once a baked crust and a pie dish can serve them. With laser links, trading circuits between cities more than 3,000 km apart take the faster path through space, where light runs about half again as fast as in glass; everything else stays on your fiber. A dish whose POP is cut off from your backbone serves only the customers next to it, and a full constellation takes years to pay for itself. - Pie Control now shows what traffic rides your satellites: a new Traffic tab lists who is in orbit (homes, boats, airlines, the Mars mission and trading circuits), how many Gbps each one uses, what it pays, and how much faster orbit is than your fiber. Each crust and pie dish gets a load bar and a plain reason when it sits idle (half-baked, raining, jammed, cut off from your backbone, no landing rights, no lasers, no customers), and an empty sky gets a checklist of what is missing. The globe draws each customer's traffic as a glowing arc you can highlight from the list, dishes on the globe and the map get a load ring, and the traceroute shows a circuit's hops up to orbit, across space and back down. - A town with no cable can now reach your network through your satellites: a pie dish at a POP your fiber does not reach sends all of that town's traffic up to a baked crust and down at one of your dishes on the backbone, nearby or, with laser links, anywhere. The pipe is small (the dishes' antennas and the crust's room) and adds the orbit's delay, so a big town fills it quickly and laying fiber stays the real fix; it never carries traffic between your other cities. Pie Control's Traffic tab shows each backhaul, how full it is, where it lands and how many ms it adds, or why it is missing, the globe draws it, and the traceroute shows its hops through space. +- The globe in Pie Control now replays your last few launches: a good one climbs and spills its pies into orbit (and a reusable booster flies home), a failed one goes up in a fireball with debris raining down. - Your own subsea cables now land right on the city's dot, also in Fujairah, Dubai, Karachi, Barcelona, Osaka and other cities the map shifts slightly so they do not overlap (#305). - Starting a new network no longer leaves the last one's "New POP!" and money pop-ups frozen all over the map until a reload. 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 3c8b41b..29a419f 100644 --- a/src/game/60-features/99-pie-in-the-sky.js +++ b/src/game/60-features/99-pie-in-the-sky.js @@ -35,6 +35,7 @@ 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):[];} +const PIE_LOG=[]; 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'), and a // cut-off POP's backhaul up from its dish and down at the landing dish (k 'b'). @@ -42,7 +43,7 @@ function pieGlobeData(){const P=S&&S.pie;if(!P)return {crusts:[],dishes:[],pads: else if(f.k==='t'&&f.dish)flows.push({id:f.id,k:'t',g:f.g,pts:[f.city,f.dish]}); else if(f.k==='b')flows.push({id:f.id,k:'b',g:f.g,pts:[f.city,f.dish],alt:CRUSTS[f.cr].alt});} 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),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})), + 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})),flown:PIE_LOG.filter(x=>x.day<=S.day&&S.day-x.day<=60&&P.pads.some(p=>p.city===x.pad)).map(x=>({pad:x.pad,ok:x.ok,rk:x.rk})), 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);}} @@ -87,6 +88,8 @@ function pieFly(L){const P=S.pie,R0=ROCKETS[L.rk],C=P.crusts[L.cr],pad=P.pads.fi if(ok){pieCohort(L.cr,L.n,!!L.las);pieFounder(N_('pie.fp_launch'),{n:L.n,c:L.cr});toast(tr('pie.t_launch',{n:L.n,crust:tr(CRUSTS[L.cr].n),p:pct(pieCov(L.cr))}),'good');} else{S.stats.pieFail=(S.stats.pieFail||0)+1;if(L.ins)pieRefund(L.cost);pieFounder(N_('pie.fp_fail')); toast(tr('pie.t_fail',{n:L.n})+(L.ins?' '+tr('pie.t_insured',{amt:fmt$(L.cost)}):''),'bad');for(const f of PIE_ON.fail)f(L);}} + // The globe replays the last few flights (UI only, never saved): a climb and a payload, or a fireball. + PIE_LOG.push({pad:L.pad,ok,rk:L.rk,day:S.day});if(PIE_LOG.length>6)PIE_LOG.shift(); if(b&&pad){if(ok&&!(cm>0&&Math.random()<(R0.land||0)*cm)){b.flights++;if(b.flights>=PIE_BOOST_MAX)pad.boosters=pad.boosters.filter(x=>x!==b);} else if(!L.test){pad.boosters=pad.boosters.filter(x=>x!==b);if(ok){pieFounder(N_('pie.fp_booster'));toast(tr('pie.t_booster'),'bad');}}} for(const f of PIE_ON.launch)f(L,ok);} diff --git a/src/game/96-map/89-pie-globe.js b/src/game/96-map/89-pie-globe.js index 2c11088..20c227f 100644 --- a/src/game/96-map/89-pie-globe.js +++ b/src/game/96-map/89-pie-globe.js @@ -11,7 +11,7 @@ const PG_ST={ 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:[],fl:[],hi:null,pads:[],lch:[],on:null,g:null,frames:0,m:new Float64Array(9)}; + data:null,dAt:-1e9,sig:'',sm:[],dish:[],fl:[],hi:null,pads:[],lch:[],fly:[],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. @@ -31,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,u:typeof o.u==='number'&&isFinite(o.u)?Math.max(0,Math.min(1,o.u)):null});}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,ok:o.ok!==false,re:o.rk==='again'||o.rk==='heavy',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(','); @@ -41,7 +41,7 @@ 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{const ph=((t+li*2.3)%5)/2.6;if(ph>1)return;const b=pgRot(L.v,tp,1);if(b[0]<0.05)return; - // Climb and lean east: the trail is the launch's path so far. - const la=Math.asin(L.v[2])/PG_D,lo=Math.atan2(L.v[1],L.v[0])/PG_D;for(let s=0;s<=10;s++){const f=ph*s/10,r=1+f*f*0.7;pgUnit(lo+f*f*28,la+f*6,tv,s*3);tv[s*3]*=r;tv[s*3+1]*=r;tv[s*3+2]*=r;} - pgRot(tv,tp,11);ctx.beginPath();for(let s=0;s<=10;s++){const x=cx+R*tp[s*3+1],y=cy-R*tp[s*3+2];if(s)ctx.lineTo(x,y);else ctx.moveTo(x,y);} - ctx.lineCap='round';ctx.lineWidth=4;ctx.strokeStyle='rgba(255,138,61,.85)';ctx.stroke();ctx.lineWidth=1.5;ctx.strokeStyle='#FFD23F';ctx.stroke();ctx.lineCap='butt'; - ctx.beginPath();ctx.arc(cx+R*tp[31],cy-R*tp[32],3.5,0,7);ctx.fillStyle='#FFFFFF';ctx.fill();ctx.strokeStyle=night?'#0B1030':st.ink;ctx.lineWidth=1.2;ctx.stroke();});} + const tv=new Float32Array(33),tp=new Float32Array(33),ink=night?'#0B1030':st.ink; + // Climb and lean east from a pad, f of the way up: fills tp with the trail and returns false when the pad faces away. + const climb=(L,f)=>{const b=pgRot(L.v,tp,1);if(b[0]<0.05)return false;const la=Math.asin(L.v[2])/PG_D,lo=Math.atan2(L.v[1],L.v[0])/PG_D; + for(let s=0;s<=10;s++){const g=f*s/10,r=1+g*g*0.7;pgUnit(lo+g*g*28,la+g*6,tv,s*3);tv[s*3]*=r;tv[s*3+1]*=r;tv[s*3+2]*=r;}pgRot(tv,tp,11);return true;}; + const trail=(a)=>{ctx.beginPath();for(let s=0;s<=10;s++){const x=cx+R*tp[s*3+1],y=cy-R*tp[s*3+2];if(s)ctx.lineTo(x,y);else ctx.moveTo(x,y);} + ctx.globalAlpha=a;ctx.lineCap='round';ctx.lineWidth=4;ctx.strokeStyle='rgba(255,138,61,.85)';ctx.stroke();ctx.lineWidth=1.5;ctx.strokeStyle='#FFD23F';ctx.stroke();ctx.lineCap='butt';ctx.globalAlpha=1;}; + const dot=(x,y,r,fill)=>{ctx.beginPath();ctx.arc(x,y,r,0,7);ctx.fillStyle=fill;ctx.fill();ctx.strokeStyle=ink;ctx.lineWidth=1.2;ctx.stroke();}; + const tip=()=>[cx+R*tp[31],cy-R*tp[32]]; + PG.lch.forEach((L,li)=>{const ph=((t+li*2.3)%5)/2.6;if(ph>1||!climb(L,ph))return;trail(1);const [x,y]=tip();dot(x,y,3.5,'#FFFFFF');}); + // The last few flights, replayed every six seconds: pies spill out at the top and a reusable booster flies home; or it + // goes up a third of the way and becomes a fireball with debris raining down. + PG.fly.forEach((L,li)=>{const ph=((t+li*1.9)%6)/6; + if(L.ok){const up=Math.min(1,ph/0.5);if(!climb(L,up))return;trail(ph<0.5?1:Math.max(0,1-(ph-0.5)*3));const [x,y]=tip(); + if(ph<0.5)dot(x,y,3.5,'#FFFFFF');else{const k=(ph-0.5)/0.5;ctx.globalAlpha=1-k; + for(let i=0;i<6;i++){const a=i/6*2*Math.PI+li,d=4+k*16;dot(x+Math.cos(a)*d,y+Math.sin(a)*d*0.6,1.8,'#FFD23F');}ctx.globalAlpha=1; + if(L.re&&climb(L,1-k)){const [bx,by]=tip();dot(bx,by,2.4,'#E8EDF7');}}} + else{const bang=0.4,z=R/100;if(!climb(L,Math.min(ph,bang)))return;const [x,y]=tip(); + if(phf.id===PG.hi)?PG.hi:null,n=PG_ARC+1; const line=(f)=>{const a=f.pos;let on=false;ctx.beginPath();for(let i=0;i { + const { ev, errors } = page(); + ev("ACT.modeSet({m:'sandbox'});ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.nextFail=1e9;S.nextEvent=1e9;if(!S.pops.mia)ACT.buildPop({city:'mia'});ACT.pieFound();ACT.piePad({city:'mia'});closeModal()"); + assert.equal(ev('S.pie.pads.length'), 1); + const fly = (rk, test, rnd) => ev(`{const m=Math.random;Math.random=()=>${rnd};try{pieFly({id:${Math.round(rnd * 100)},rk:'${rk}',cr:'short',n:20,day:S.day,pad:'mia',cost:1,test:${test}});}finally{Math.random=m;}}`); + fly('falcon', false, 0.99); + fly('heavy', true, 0.99); + const flown = JSON.parse(ev('JSON.stringify(pieGlobeData().flown)')); + assert.deepEqual(flown.map((f) => [f.pad, f.ok, f.rk]), [['mia', true, 'falcon'], ['mia', false, 'heavy']]); + for (let i = 0; i < 8; i++) fly('falcon', false, 0.99); + assert.equal(ev('pieGlobeData().flown.length'), 6, 'only the last six flights'); + ev('S.day+=61'); + assert.equal(ev('pieGlobeData().flown.length'), 0, 'old flights stop replaying'); + // Drawing: an ok flight, a reusable one, a crash and junk, across a whole replay cycle. + ev(`pieGlobeOpen($('pgTest'),()=>({crusts:[],dishes:[],pads:[{city:'mia'}],launches:[],flown:[{pad:'mia',ok:true,rk:'falcon'},{pad:'mia',ok:true,rk:'again'},{pad:'mia',ok:false},{pad:'nowhere'},null]}));PG.anim=true`); + for (let i = 0; i < 40; i++) assert.equal(ev(`pgFrame(${1000 + i * 160},true)`), true); + assert.equal(ev('PG.fly.length'), 3, 'unknown pads dropped'); + assert.deepEqual(JSON.parse(ev('JSON.stringify(PG.fly.map(f=>[f.ok,f.re]))')), [[true, false], [true, true], [false, false]]); + ev('pieGlobeClose()'); + assert.deepEqual(errors, []); +});