Map: cities show their size, and crowded small ones step back to a dot
Five sizes from a city's eyeballs (P: under 15, 100, 350, 800 and up). Far view: dots grow with size and megacities glow. Near view: the skyline goes from a hut to five towers with an antenna. cityRoom() lets the selected city, your POPs and cities with an offer, outage or puzzle part claim space first, then the biggest; a city with no room is a small dot without a label until you zoom in, still tappable. IX tags for exchanges you haven't joined are smaller, and on outposts and towns only from zoom 1.5. Phones draw city icons at 82% (taps unchanged).
This commit is contained in:
parent
e1a6a582fa
commit
cb90e735fd
6 changed files with 147 additions and 17 deletions
|
|
@ -78,19 +78,22 @@ function drawFrame(now){
|
|||
const prio=v=>(UI.sel&&UI.sel.type==='city'&&UI.sel.id===v.C.id?0:S.pops[v.C.id]?1:2);vis.sort((a,b)=>prio(a)-prio(b)||b.C.P-a.C.P);
|
||||
const rects=[],labs=[],hit=(r)=>rects.some(q=>r.x<q.x+q.w&&q.x<r.x+r.w&&r.y<q.y+q.h&&q.y<r.y+r.h);
|
||||
const farL=lodFar();
|
||||
for(const v of vis){if(farL){rects.push({x:v.sx-7,y:v.sy-7,w:14,h:14});continue;}const h=(12+Math.sqrt(v.C.P)*0.75)*sc;rects.push({x:v.sx-18*sc,y:v.sy-h-4*sc,w:40*sc,h:h+14*sc});}
|
||||
// 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;
|
||||
// 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);
|
||||
for(const v of vis){if(farL){const r=FAR_R[cTier(v.C.id)]+3;rects.push({x:v.sx-r,y:v.sy-r,w:2*r,h:2*r});continue;}
|
||||
if(v.dem){rects.push({x:v.sx-5*csc,y:v.sy-5*csc,w:10*csc,h:10*csc});continue;}const h=cityTop(v.C.id,S.pops[v.C.id])*csc;rects.push({x:v.sx-v.r,y:v.sy-h,w:2*v.r,h:h+10*csc});}
|
||||
for(const v of vis){const p=S.pops[v.C.id];ctx.font=`800 ${p?13:12}px "Baloo 2", sans-serif`;const tw=(LBLW[v.C.id+(p?1:0)]||(LBLW[v.C.id+(p?1:0)]=ctx.measureText(v.C.name).width+14));
|
||||
if(farL&&prio(v)>1&&UI.hover!==v.C.id){v.ly=null;continue;}
|
||||
const h=farL?6:12+Math.sqrt(v.C.P)*0.75;const below=farL?v.sy+15:v.sy+16*sc+8,above=farL?v.sy-15:v.sy-h*sc-17*sc;let ly=null;
|
||||
if((farL&&prio(v)>1&&UI.hover!==v.C.id)||v.dem){v.ly=null;continue;}
|
||||
const h=farL?6:cityTop(v.C.id,p);const below=farL?v.sy+15:v.sy+16*csc+8,above=farL?v.sy-15:v.sy-h*csc-17*csc;let ly=null;
|
||||
for(const y of [below,above]){const r={x:v.sx-tw/2-2,y:y-10,w:tw+4,h:21};if(!hit(r)){ly=y;rects.push(r);labs.push(r);break;}}
|
||||
// Your POPs may sit over a city icon, but not over another name: that one waits until you zoom in.
|
||||
if(ly===null&&prio(v)===1)for(const y of [below,above]){const r={x:v.sx-tw/2,y:y-10,w:tw,h:21};if(!labs.some(q=>r.x<q.x+q.w&&q.x<r.x+r.w&&r.y<q.y+q.h&&q.y<r.y+r.h)){ly=y;rects.push(r);labs.push(r);break;}}
|
||||
if(ly===null&&(prio(v)===0||(prio(v)===1&&(v.C.id===S.home||UI.hover===v.C.id)))){ly=below;const r={x:v.sx-tw/2,y:below-10,w:tw,h:21};rects.push(r);labs.push(r);}
|
||||
v.ly=ly;}
|
||||
// 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;
|
||||
if(pzOn()){for(const v of vis.slice().reverse())pzDrawCity(v,sc,now);}else for(const v of vis.slice().reverse())drawCity(v.C,v.sx,v.sy,sc,now,v.ly);
|
||||
if(pzOn()){for(const v of vis.slice().reverse())pzDrawCity(v,csc,now);}else for(const v of vis.slice().reverse())drawCity(v.C,v.sx,v.sy,csc,now,v.ly,v.dem);
|
||||
// Architect runs: what the tubes between two cities are (one trench, or separate paths), above the cities.
|
||||
for(const [x,y,t,one] of AR_PILLS){ctx.font='800 11px "Baloo 2", sans-serif';const tw=ctx.measureText(t).width+12;ctx.fillStyle=one?'#FFE3C2':'#DDF7E7';ctx.strokeStyle=one?'#FF8A3D':'#16A866';ctx.lineWidth=2;rr(x-tw/2,y-9,tw,17,8);ctx.fill();ctx.stroke();ctx.fillStyle='#1E2640';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(t,x,y+1);}
|
||||
// the chaos monkey (woken here after a reload, wherever it last snipped)
|
||||
|
|
|
|||
36
src/game/96-map/75-city-size.js
Normal file
36
src/game/96-map/75-city-size.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* City size: a city's icon says how many eyeballs live there, in five steps from an outpost to a megacity.
|
||||
P is the city's eyeball demand (about 40G per million people), so it stands in for population.
|
||||
Zoomed out the dots grow with it; zoomed in the skyline does. Crowded cities give way to bigger ones. */
|
||||
const CTIER_AT=[15,100,350,800],ctier=P=>{let t=0;while(t<4&&P>=CTIER_AT[t])t++;return t;};
|
||||
const CTIER=new Map(CITIES.map(C=>[C.id,ctier(C.P)])),cTier=id=>{const t=CTIER.get(id);return t===undefined?ctier((CITY[id]||{}).P||0):t;};
|
||||
// Near view: each tier's skyline, one [x, height, colour] per 10 px wide building, and a gentle extra scale on top.
|
||||
const SKY=[
|
||||
[[-5,7,'#FFFFFF']],
|
||||
[[-10,9,'#FFFFFF'],[0,12,'#FFE7A1']],
|
||||
[[-15,11,'#FFFFFF'],[-5,16,'#FFE7A1'],[5,9,'#BDE8FF']],
|
||||
[[-20,13,'#BDE8FF'],[-10,20,'#FFFFFF'],[0,16,'#FFE7A1'],[10,10,'#FFFFFF']],
|
||||
[[-25,15,'#BDE8FF'],[-15,22,'#FFFFFF'],[-5,31,'#FFE7A1'],[5,20,'#BDE8FF'],[15,13,'#FFFFFF']],
|
||||
];
|
||||
const SKY_H=SKY.map(b=>Math.max(...b.map(x=>x[1]))),SKY_W=SKY.map(b=>b.length*10),CSC=[0.8,0.88,0.95,1.03,1.1];
|
||||
// Far view: the dot's radius per tier. Megacities also glow a little.
|
||||
const FAR_R=[1.7,2.3,3.1,4.3,6];
|
||||
// How tall a city's icon stands above its spot, in icon units (×iconScale on screen).
|
||||
const cityTop=(id,p)=>p?24:SKY_H[cTier(id)]*CSC[cTier(id)]+6;
|
||||
// Phones show cities a little smaller: the screen is narrow and every city would touch the next (taps stay as big).
|
||||
const cityScale=sc=>sc*(innerWidth<=760?0.82:1);
|
||||
// An exchange you have not joined is a quiet tag, and on outposts and towns only once you zoom in close.
|
||||
const ixQuiet=id=>!S.myIx[id]&&!hasIxAt(id),ixShown=(id,p)=>!!ixName(id)&&(p||!ixQuiet(id)||cTier(id)>=2||cam.z>=1.5);
|
||||
/* Room on the map (near view only). Cities claim space in order: the selected or hovered city, your POPs, cities with
|
||||
an offer, an outage or a part in the puzzle, then the biggest. A city whose skyline would sit on one already placed
|
||||
becomes a small dot (v.dem): still there and still tappable, just quiet. */
|
||||
function cityRoom(vis,sc){
|
||||
const sel=UI.sel&&UI.sel.type==='city'?UI.sel.id:null,pz=pzOn();
|
||||
const pr=v=>{const id=v.C.id;return id===sel||UI.hover===id?0:S.pops[id]?1:CM.off.has(id)||CM.inc.has(id)||(pz&&pzKind(id)&&pzKind(id)!=='off')?2:3;};
|
||||
for(const v of vis)v.pr=pr(v);
|
||||
const ord=vis.slice().sort((a,b)=>a.pr-b.pr||b.C.P-a.C.P),cell=64,grid=new Map(),at=(i,j)=>i*8192+j;
|
||||
for(const v of ord){const t=cTier(v.C.id),p=S.pops[v.C.id],r=(p?22:(SKY_W[t]/2+3+(ixShown(v.C.id,p)?7:0))*CSC[t])*sc;v.r=r;v.dem=false;
|
||||
const i0=Math.floor(v.sx/cell),j0=Math.floor(v.sy/cell);let clash=false;
|
||||
if(v.pr>2)for(let i=i0-2;i<=i0+2&&!clash;i++)for(let j=j0-2;j<=j0+2&&!clash;j++){const L=grid.get(at(i,j));if(L)for(const q of L)if(Math.hypot(q.sx-v.sx,q.sy-v.sy)<q.r+r){clash=true;break;}}
|
||||
if(clash){v.dem=true;continue;}
|
||||
const k=at(i0,j0);let L=grid.get(k);if(!L)grid.set(k,L=[]);L.push(v);}
|
||||
}
|
||||
|
|
@ -11,7 +11,9 @@ function drawCityFar(C,sx,sy,sc,now,lyOverride){
|
|||
if(p.site2){ctx.setLineDash([2,2]);ctx.beginPath();ctx.moveTo(0,0);ctx.lineTo(9,6);ctx.stroke();ctx.setLineDash([]);ctx.fillStyle=col;rr(5,3,9,7,3);ctx.fill();ctx.stroke();}
|
||||
if((p.routers||1)>=2){ctx.fillStyle=down?'#6E7590':'#D63B7F';rr(-6,-7,15,10,4);ctx.fill();ctx.stroke();}
|
||||
ctx.fillStyle=col;rr(-8,-5,16,10,4);ctx.fill();ctx.stroke();
|
||||
}else{ctx.fillStyle=hasIxAt(C.id)?'#FFD23F':'#FFFFFF';ctx.lineWidth=1.5;ctx.beginPath();ctx.arc(0,0,hov?4.5:3.4,0,7);ctx.fill();ctx.stroke();}
|
||||
}else{// The dot grows with the city's eyeballs; a megacity glows a little (75-city-size.js).
|
||||
const t=cTier(C.id),r=FAR_R[t]*(hov?1.3:1);if(t===4){ctx.fillStyle='rgba(255,255,255,.55)';ctx.beginPath();ctx.arc(0,0,r+4.5,0,7);ctx.fill();}
|
||||
ctx.fillStyle=hasIxAt(C.id)?'#FFD23F':'#FFFFFF';ctx.lineWidth=t>=3?1.6:1.3;ctx.beginPath();ctx.arc(0,0,r,0,7);ctx.fill();ctx.stroke();}
|
||||
if(CM.off.has(C.id)){ctx.fillStyle='#16A866';ctx.lineWidth=1.2;ctx.beginPath();ctx.arc(p?9:5,p?-7:-5,3,0,7);ctx.fill();ctx.stroke();}
|
||||
if(CM.inc.has(C.id)){ctx.fillStyle='#FF4D5E';ctx.lineWidth=1.2;ctx.beginPath();ctx.arc(p?-9:-5,p?-7:-5,3.4,0,7);ctx.fill();ctx.stroke();}
|
||||
ctx.restore();
|
||||
|
|
@ -19,20 +21,25 @@ function drawCityFar(C,sx,sy,sc,now,lyOverride){
|
|||
ctx.fillStyle=p?'#FF4F9A':'#FFFFFF';ctx.strokeStyle='#1E2640';ctx.lineWidth=1.6;rr(sx-tw/2,ly-8,tw,16,8);ctx.fill();ctx.stroke();
|
||||
ctx.fillStyle=p?'#FFFFFF':'#1E2640';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(t,sx,ly+1);}
|
||||
}
|
||||
function drawCity(C,sx,sy,sc,now,lyOverride){
|
||||
function drawCity(C,sx,sy,sc,now,lyOverride,dem){
|
||||
if(CM.far)return drawCityFar(C,sx,sy,sc,now,lyOverride);
|
||||
const hot=(UI.hotMap||{})[C.id];
|
||||
const p=S.pops[C.id],down=p&&p.down>S.day,sel=UI.sel&&UI.sel.type==='city'&&UI.sel.id===C.id,hov=UI.hover===C.id||(UI.snap&&UI.snap.id===C.id);
|
||||
// No room for its skyline here: a quiet dot, a little bigger for bigger cities, until you zoom in (cityRoom).
|
||||
if(dem&&!p&&!sel&&!hov){const r=(2.6+cTier(C.id)*0.35)*sc;ctx.fillStyle=hasIxAt(C.id)?'#FFD23F':'#FFFFFF';ctx.strokeStyle='#1E2640';ctx.lineWidth=1.6;ctx.beginPath();ctx.arc(sx,sy+2*sc,r,0,7);ctx.fill();ctx.stroke();return;}
|
||||
const t=cTier(C.id),cs=p?1:CSC[t];
|
||||
const k=sc*(hov?1.15:1);
|
||||
ctx.save();ctx.translate(sx,sy);
|
||||
if(UI.feed&&UI.feed.has(C.id)){ctx.strokeStyle='#FF8A3D';ctx.lineWidth=4;ctx.setLineDash([3,5]);ctx.beginPath();ctx.arc(0,-6*k,36*k,0,7);ctx.stroke();ctx.setLineDash([]);}
|
||||
if(sel){ctx.strokeStyle='#FF4F9A';ctx.lineWidth=3;ctx.setLineDash([6,6]);ctx.lineDashOffset=-now/40;ctx.beginPath();ctx.arc(0,-6*k,30*k,0,7);ctx.stroke();ctx.setLineDash([]);}
|
||||
if(p&&!down&&R.cityDem[C.id]>0&&sfOf(R,C.id)<0.9){const a=.35+.25*Math.sin(now/200);ctx.fillStyle=`rgba(255,77,94,${a})`;ctx.beginPath();ctx.arc(0,-6*k,26*k,0,7);ctx.fill();}
|
||||
ctx.scale(k,k);
|
||||
ctx.fillStyle='rgba(30,38,64,.2)';ctx.beginPath();ctx.ellipse(0,9,20,5,0,0,7);ctx.fill();
|
||||
const h=p?18:12+Math.sqrt(C.P)*0.75;
|
||||
ctx.scale(k*cs,k*cs);
|
||||
ctx.fillStyle='rgba(30,38,64,.2)';ctx.beginPath();ctx.ellipse(0,9,p?20:SKY_W[t]/2+5,5,0,0,7);ctx.fill();
|
||||
const h=p?18:SKY_H[t];
|
||||
ctx.strokeStyle='#1E2640';ctx.lineWidth=2.2;
|
||||
if(!p){const bl=[[-15,h*.65,'#FFFFFF'],[-5,h,'#FFE7A1'],[5,h*.5,'#BDE8FF']];
|
||||
// The skyline says how big the city is: a hut for an outpost, up to five towers for a megacity.
|
||||
if(!p){const bl=SKY[t];
|
||||
if(t===4){ctx.lineWidth=2;ctx.beginPath();ctx.moveTo(0,8-h);ctx.lineTo(0,1-h);ctx.stroke();ctx.fillStyle='#FF4D5E';ctx.beginPath();ctx.arc(0,-h,2.2,0,7);ctx.fill();ctx.stroke();ctx.lineWidth=2.2;}
|
||||
for(const [x,hh,col] of bl){ctx.fillStyle=col;rr(x,8-hh,10,hh,2);ctx.fill();ctx.stroke();}
|
||||
ctx.fillStyle='rgba(30,38,64,.35)';ctx.beginPath();for(const [x,hh] of bl)for(let yy=8-hh+4;yy<5;yy+=5){ctx.rect(x+2.5,yy,2,2);ctx.rect(x+5.5,yy,2,2);}ctx.fill();}
|
||||
if(p){
|
||||
|
|
@ -56,8 +63,10 @@ function drawCity(C,sx,sy,sc,now,lyOverride){
|
|||
ctx.translate(0,-2);
|
||||
}
|
||||
const ixn=ixName(C.id);
|
||||
if(ixn){const mine=!!S.myIx[C.id],joined=hasIxAt(C.id);const ixHot=hot&&hot.ix;ctx.fillStyle=ixHot?(Math.sin(now/180)>0?'#FF4D5E':'#FF8A3D'):mine?'#FF4F9A':joined?'#FFD23F':'#FFFFFF';ctx.beginPath();for(let i=0;i<6;i++){const a=Math.PI/3*i+Math.PI/6;ctx.lineTo(19+8.5*Math.cos(a),-h+2+8.5*Math.sin(a));}ctx.closePath();ctx.fill();ctx.lineWidth=2;ctx.stroke();
|
||||
ctx.fillStyle=mine||ixHot?'#fff':'#1E2640';ctx.font='900 8px Nunito, sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText('IX',19,-h+2.5);}
|
||||
// The IX badge sits at the skyline's top right, whatever its width.
|
||||
if(ixn&&(ixShown(C.id,p)||(hot&&hot.ix)||sel||hov)){const mine=!!S.myIx[C.id],joined=hasIxAt(C.id),ixHot=hot&&hot.ix,q=!p&&!ixHot&&ixQuiet(C.id),R=q?6.5:8.5,ix=p?19:SKY_W[t]/2+(q?2:4);
|
||||
ctx.fillStyle=ixHot?(Math.sin(now/180)>0?'#FF4D5E':'#FF8A3D'):mine?'#FF4F9A':joined?'#FFD23F':'#FFFFFF';ctx.beginPath();for(let i=0;i<6;i++){const a=Math.PI/3*i+Math.PI/6;ctx.lineTo(ix+R*Math.cos(a),-h+2+R*Math.sin(a));}ctx.closePath();ctx.fill();ctx.lineWidth=q?1.4:2;ctx.stroke();
|
||||
ctx.fillStyle=mine||ixHot?'#fff':'#1E2640';ctx.font=`900 ${q?6.5:8}px Nunito, sans-serif`;ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText('IX',ix,-h+2.5);}
|
||||
if(hot&&p){let y=-14;const pulse=.75+.25*Math.sin(now/200);for(const k of ['r','t','p','c']){if(!hot[k])continue;ctx.globalAlpha=pulse;ctx.fillStyle='#FF4D5E';ctx.beginPath();ctx.arc(-29,y,6.5,0,7);ctx.fill();ctx.globalAlpha=1;ctx.lineWidth=2;ctx.strokeStyle='#1E2640';ctx.stroke();ctx.fillStyle='#fff';ctx.font='900 8px Nunito, sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(HOTL[k],-29,y+0.5);y+=14;}}
|
||||
const off=CM.off.has(C.id);
|
||||
if(off){const by=-h-16+Math.sin(now/250)*3;ctx.fillStyle='#fff';ctx.lineWidth=2.2;ctx.beginPath();ctx.ellipse(-2,by,11,9,0,0,7);ctx.fill();ctx.stroke();ctx.beginPath();ctx.moveTo(-5,by+8);ctx.lineTo(-7,by+14);ctx.lineTo(0,by+8);ctx.fillStyle='#fff';ctx.fill();const big=CM.big.has(C.id);ctx.fillStyle=big?'#FF4F9A':'#16A866';ctx.font='900 13px "Baloo 2", sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(big?'$$':'$',-2,by+1);}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
build in but not emphasised. */
|
||||
function pzBadge(c){const P=S.pz;if(S.ar)return c===S.ar.hq?'🏠':S.ar.gold.includes(c)?'🚨':'';return P.src.includes(c)?'🗄️':P.dem.some(f=>f.t==='eye'&&f.a===c)?'👀':P.dem.some(f=>f.t==='l2'&&(f.a===c||f.b===c))?'🔗':'';}
|
||||
function pzDrawCity(v,sc,now){const k=pzKind(v.C.id);
|
||||
if(!k||k==='off'){drawCity(v.C,v.sx,v.sy,sc,now,v.ly===null?undefined:v.ly);return;}
|
||||
if(!k||k==='off'){drawCity(v.C,v.sx,v.sy,sc,now,v.ly===null?undefined:v.ly,v.dem);return;}
|
||||
const r=(CM.far?16:34)*sc,y=v.sy-(CM.far?0:6*sc),p=S.pops[v.C.id];
|
||||
ctx.save();ctx.lineWidth=3;
|
||||
if(k==='avoid'){ctx.strokeStyle='#FF4D5E';ctx.beginPath();ctx.arc(v.sx,y,r,0,7);ctx.moveTo(v.sx-r*.7,y-r*.7);ctx.lineTo(v.sx+r*.7,y+r*.7);ctx.stroke();}
|
||||
else{const a=animOn()?.55+.35*Math.sin(now/300):.8,gold=S.ar&&S.ar.gold.includes(v.C.id),dk=S.ar&&arDarkNow(v.C.id);ctx.strokeStyle=dk?`rgba(255,77,94,${a})`:gold?`rgba(224,160,0,${p?1:a})`:k==='goal'?`rgba(255,79,154,${p?1:a})`:'rgba(30,38,64,.7)';if(gold||dk)ctx.lineWidth=5;if(k==='via')ctx.setLineDash([5,5]);
|
||||
ctx.fillStyle=k==='goal'&&!p?'rgba(255,210,63,.35)':'rgba(255,255,255,.25)';ctx.beginPath();ctx.arc(v.sx,y,r,0,7);ctx.fill();ctx.stroke();ctx.setLineDash([]);}
|
||||
ctx.restore();drawCity(v.C,v.sx,v.sy,sc,now,v.ly===null?undefined:v.ly);
|
||||
ctx.restore();drawCity(v.C,v.sx,v.sy,sc,now,v.ly===null?undefined:v.ly,v.dem);
|
||||
const b=k==='goal'&&!CM.far?pzBadge(v.C.id):'';if(b){ctx.font=`${Math.round(15*sc)}px sans-serif`;ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(b,v.sx-r*.75,y-r*.75);}} // top left: the IX badge has the top right
|
||||
// In a puzzle every line says what it is ("2×100G · 70%"), and a selected POP lights up every pair it has links on.
|
||||
function pzLinkLab(grp,up,load,cap){if(S.ar)return groupLabel(grp,up)+(cap?` · ${Math.round(load/cap*100)}%`:'');return groupLabel(grp,up)+(cap?` · ${Math.round(load/cap*100)}%`:'');}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue