; ; /* ============================================================================ WORLD SITES — settlements that are places, not scatter ---------------------------------------------------------------------------- Every map dressed itself the same way: one generic city plan, the same block meshes. Land anywhere and you saw the same civilisation — the "worlds all look the same" complaint. It is a content-STRUCTURE problem, not a texture one, so the answer is ARCHETYPES: a purpose, a silhouette vocabulary, a density, a state of repair. Frontier town (low, gridded, intact); dead city (tall, broken, silent); mining station (tanks and depots round the ore); military outpost (wall, gate, watchtower, gun); alien bloom (not human at all). Which ones a map grows is read from its own authored city/indus ratings and planet theme, so it scales to all 56 maps with none hand-placed. TWO GEOMETRY SOURCES on purpose. Landmarks come from the authored GLB kit (assets/data/worldkit.js): they carry identity — you know an outpost the moment you see the gate. But a town built only from imported pieces is three buildings repeated thirty times, which the eye catches instantly and which would REINTRODUCE the sameness this file removes. So the BULK is procedural: every filler building derives footprint, height, setbacks, window banding and damage from the site seed, and no two are identical. The kit is decoded from a quantised buffer (pos int16, normal int8, colour uint8, material uint8 — 13 bytes a vertex) into the engine's 12-float vertex layout. Base colour was baked+brightened into vertex colour at conversion so no per-model PBR texture ships, honouring the asset policy (runtime models take a material id per vertex from the one shared atlas). Normals were made smooth and outward-facing at conversion so the props are lit, not black. ============================================================================ */ const WORLD_KIT = {}; let worldSites = [], worldSitesBuilt = ''; let WORLDSITES_ENABLED = false; /* HOTFIX 1.33.31: crude procedural boxes were a regression vs the authored city system; disabled while the fill is rebuilt from the detailed city meshes (FX.cityT/H/D/K) */ /* ---------- kit decode ---------------------------------------------------- */ function worldKitDecode(rec){ const raw = atob(rec.b64), stride = 13, count = raw.length / stride | 0; const v = new Float32Array(count * 12); for(let i=0;i>16)/16384; v[i*12+1]=((raw.charCodeAt(o+2)|(raw.charCodeAt(o+3)<<8))<<16>>16)/16384; v[i*12+2]=((raw.charCodeAt(o+4)|(raw.charCodeAt(o+5)<<8))<<16>>16)/16384; v[i*12+3]=(raw.charCodeAt(o+6)<<24>>24)/127; v[i*12+4]=(raw.charCodeAt(o+7)<<24>>24)/127; v[i*12+5]=(raw.charCodeAt(o+8)<<24>>24)/127; v[i*12+6]=raw.charCodeAt(o+9)/255; v[i*12+7]=raw.charCodeAt(o+10)/255; v[i*12+8]=raw.charCodeAt(o+11)/255; /* Placeholder UV — overwritten per-triangle below. A constant (0,0) UV made the cotangent frame NaN (pure black). Vertex colour used to carry the look; office-glass now samples a window tile, so the projection must be face-stable. */ v[i*12+9]=0; v[i*12+10]=0; v[i*12+11]=raw.charCodeAt(o+12); } /* FACE-STABLE planar UV. Kit normals are smoothed, so a per-vert dominant axis assigned XZ to one corner of a wall and ZY to the other — the office-glass tile stair-stepped. One geometric face axis, all three verts. */ for(let t=0;t+2=ax&&ay>=az?0:ax>=az?2:0, wA=ay>=ax&&ay>=az?2:1; for(let k=0;k<3;k++){ const o=o0+k*12; v[o+9]=v[o+uA]*2.0; v[o+10]=v[o+wA]*2.0; } } /* InstMesh draws indexed; the converter emits expanded soup, so the index is the identity. Counts top out near 3,800 — inside Uint16. */ const idx=new Uint16Array(count); for(let i=0;ia-b); const cut=sorted[Math.min(n-1,(n*0.74)|0)]; for(let i=0;ir+0.04&&g>r-0.03; const amber=r>b+0.07&&r>g-0.03; if(facade&&lumas[i]>=cut&&(cyan||amber||lumas[i]>0.78)) geo.v[o+11]=amber&&!cyan?warm:cool; else geo.v[o+11]=hull; } } function initWorldKit(){ if(typeof WORLD_KIT_DATA==='undefined'||typeof gl==='undefined'||!gl) return 0; let n=0; const mats=worldKitMats(); for(const k in WORLD_KIT_DATA){ if(WORLD_KIT[k]) continue; try{ const geo=worldKitDecode(WORLD_KIT_DATA[k]); worldKitAssignMats(geo, mats[k]); WORLD_KIT[k]={mesh:new InstMesh(gl,geo,320),height:WORLD_KIT_DATA[k].height,tris:WORLD_KIT_DATA[k].tris}; n++; }catch(e){ console.warn('worldkit '+k+':',e&&e.message); } } return n; } function worldKitGLReset(){ for(const k in WORLD_KIT) delete WORLD_KIT[k]; worldSites.length=0; worldSitesBuilt=''; } /* ---------- archetypes ---------------------------------------------------- */ const SITE_ARCH={ town:{ r:190, kit:['block','tower','depot'], kitN:[3,2,1], fill:{n:14,w:[16,30],h:[14,34],lit:0.55,ruin:0}, pal:[[176,172,160],[150,156,164]] }, city:{ r:250, kit:['tower','block','gatehouse'], kitN:[4,3,1], fill:{n:20,w:[18,36],h:[26,72],lit:0.7,ruin:0}, pal:[[168,174,186],[142,150,166]] }, dead:{ r:250, kit:['tower','block'], kitN:[4,3], fill:{n:18,w:[16,34],h:[18,58],lit:0.04,ruin:1}, pal:[[128,124,118],[104,102,100]] }, mining:{ r:170, kit:['depot','block'], kitN:[3,2], fill:{n:8,w:[14,26],h:[10,22],lit:0.4,ruin:0.2}, pal:[[150,132,110],[128,118,104]] }, outpost:{ r:130, kit:['gatehouse','watchtower','gauss','barracks'], kitN:[1,2,2,3], fill:{n:5,w:[12,20],h:[8,16],lit:0.5,ruin:0}, pal:[[126,132,124],[104,112,106]] }, derelict:{ r:160, kit:['depot','block'], kitN:[2,2], fill:{n:9,w:[14,28],h:[10,26],lit:0.06,ruin:1}, pal:[[122,112,102],[98,94,90]] }, alien:{ r:180, kit:[], kitN:[], fill:{n:12,w:[10,22],h:[16,52],lit:0.9,ruin:0,alien:1}, pal:[[118,86,150],[86,120,138]] } }; function worldSitePlan(MD,rnd){ const out=[], theme=(MD&&MD.theme)||curTheme||'verdant'; const city=MD.city|0, indus=MD.indus|0, dead=theme==='ashland'||MD.crater; if(city>=3) out.push(dead?'dead':'city'); if(city>=2) out.push(dead?'dead':'town'); if(city>=1) out.push(rnd()<0.45&&dead?'derelict':'town'); for(let i=0;iMath.max(0,Math.min(1,(q+(rnd()*34-17))/255)); const body=[jit(pal[0]),jit(pal[1]),jit(pal[2])]; if(F.alien){ const seg=3+((rnd()*3)|0); let cw=w*0.5, cy=0; for(let k=0;k34?2+((rnd()*2)|0):1; let cy=0, cw=w, cd=d, ch=h/steps; for(let k=0;kcy+ch-2.5) break; const lit=rnd(){ s=(Math.imul(s,1664525)+1013904223)|0; return ((s>>>9)&0x7fffff)/0x800000; }; initWorldKit(); const plan=worldSitePlan(MD,rnd), placed=[]; const hh=(x,y)=>typeof hAt==='function'?hAt(x,y):(typeof terrainNH==='function'?terrainNH(x,y):WATER_H+1); for(const kind of plan){ const A=SITE_ARCH[kind]; if(!A) continue; let spot=null; for(let t=0;t<180&&!spot;t++){ const x=160+rnd()*(MAP-320), y=160+rnd()*(MAP-320); if(typeof battlefieldContains==='function'&&!battlefieldContains(x,y,A.r*0.6)) continue; if(hh(x,y)