; ; /* ============================================================================ 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;i({wall,roof,edge:edge==null?gun:edge,trim}); /* Screenshot-critical outpost pieces are deliberately semantic: pale composite walls separate from graphite structure, while barracks/depot service roofs share one readable ventilation-deck material. */ WORLD_KIT_MAT={ /* Command views primarily see decks. Keep those decks dark gunmetal or ventilated service metal, and reserve the lighter blue composite for vertical facade bays. This creates a stable roof/facade/trim hierarchy without the chalk-white roofs in the close mobile capture. */ gatehouse:style(composite,gun,trim), barracks:style(composite,vent,gun), depot:style(gun,vent,trim), tower:style(composite,gun,trim), block:style(composite,gun,vent), watchtower:style(gun,vent,trim), gauss:style(gun,gun,vent), ruinApartment:style(composite,gun,trim), ruinHighrise:style(composite,gun,trim), ruinFactory:style(gun,vent,trim), ruinSpire:style(composite,gun,trim), fuelFarm:style(gun,composite,vent), fuelTank:style(gun,gun,trim), ruinTower:style(composite,gun,trim) }; return WORLD_KIT_MAT; } function worldKitAssignMats(geo, kitStyle){ /* MeshBuilder stores MAT+1 (shader does floor(abs)-1). The converter wrote material 0 and baked window light into vertex RGB; writing raw MAT.CONC made every kit vert read as LAMP — the orange orb tile civic already rejected. Keep the established bright-facade window classifier verbatim; assign the remaining triangle soup by architectural job. */ const M=(typeof MAT!=='undefined')?MAT:{}; const fallback=M.CONC!=null?M.CONC:6; const s=(kitStyle&&typeof kitStyle==='object')?kitStyle: {wall:kitStyle!=null?kitStyle:fallback,roof:kitStyle!=null?kitStyle:fallback, edge:kitStyle!=null?kitStyle:fallback,trim:kitStyle!=null?kitStyle:fallback}; const cool=(M.BUILD_OFFICE_COOL!=null?M.BUILD_OFFICE_COOL:6)+1; const warm=(M.BUILD_OFFICE_LIT!=null?M.BUILD_OFFICE_LIT:6)+1; const n=geo.count, lumas=new Float32Array(n); for(let i=0;ia-b); const cut=sorted[Math.min(n-1,(n*0.74)|0)]; const darkCut=sorted[Math.min(n-1,(n*0.20)|0)]; for(let t=0;t+2avgR+0.04&&avgG>avgR-0.03; const amber=avgR>avgB+0.07&&avgR>avgG-0.03; const hasWindow=facade&&avgL>=cut&&(cyan||amber||avgL>0.78); let base; if(hasWindow) base=(amber&&!cyan?warm:cool)-1; else if(ny>0.52) base=avgL<=darkCut?s.edge:s.roof; else if(ny<-0.58) base=s.trim; else if(ay<0.30) base=avgL<=darkCut?s.trim:s.wall; else base=avgL<=darkCut?s.trim:s.edge; base=(base!=null?base:fallback)+1; for(let k=0;k<3;k++){ const o=o0+k*12; /* vMat is flat in FS3D: one triangle must carry one semantic id. Mixed per-vertex window ids depended on the provoking vertex and produced unstable grey facets across otherwise continuous facades. */ geo.v[o+11]=base; /* aInst.w applies the placed building scale later. Reducing source UVs here yields one coherent architectural bay instead of vehicle-scale panel repetition. Never rescale a mixed window triangle: keeping one projection across all three vertices avoids a warped interpolation. */ if(!hasWindow){ geo.v[o+9]*=WORLD_KIT_ARCH_UV; geo.v[o+10]*=WORLD_KIT_ARCH_UV; } } } } 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]); const mesh=new InstMesh(gl,geo,320); /* Atomically promotes all four WORLDKIT_* ids to the compact 512px/cell triplet when it finishes decoding. Until then the same semantic ids stay visible through the shared atlas -- no double-render or blank. */ if(typeof mfWorldKitSkin==='function') mfWorldKitSkin(gl,mesh); WORLD_KIT[k]={mesh,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]; if(typeof mfWorldKitSkinReset==='function') mfWorldKitSkinReset(); 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)0&&plots>0) return 'REQUIRED_PLOT_ROLLBACK'; if(env>0) return 'ENVIRONMENTAL_EXHAUSTION'; if(hits===0) return 'TEMPLATE_MISSING'; return 'ENVIRONMENTAL_EXHAUSTION'; } function siteStampBegin(preflight){ /* Production always derives compatibility from the live map. A leftover SITE_TPL_QUERY.context from a fixture must not leak into planDistricts. */ const full=preflight&&preflight.status==='FULL_V1'; if(!full&&typeof SITE_TPL_QUERY==='object'&&SITE_TPL_QUERY){ SITE_TPL_QUERY.context=null; SITE_TPL_QUERY.force=null; } if(!full&&typeof siteTplTelemReset==='function') siteTplTelemReset(); SITE_STAMP.map=(typeof curMap!=='undefined'?String(curMap):''); const def=(typeof MAPDEFS!=='undefined'&&MAPDEFS[SITE_STAMP.map])||{}; SITE_STAMP.requested=siteStampCounts(); if(full){ for(let i=0;i({id:R.id,requestId:R.requestId,instance:R.instance, siteClass:R.siteClass,template:R.template,purpose:R.purpose,era:R.era,condition:R.condition, semanticSignature:R.semanticSignature,layoutSignature:R.layoutSignature}))}; SITE_STAMP.zones=[]; SITE_STAMP.fails=[]; SITE_STAMP.rej=null; SITE_STAMP.telem=null; SITE_STAMP.ok=true; SITE_STAMP.hash='';SITE_STAMP.realizationHash=''; } function siteStampEnd(executionError){ const names=[],realization=[]; const errorDetail=executionError&&executionError.locationPlan||{}; if(!executionError&&typeof cityZones!=='undefined'){ for(let i=0;i[D.x,D.y,D.rich?1:0,D.starter||'']):[], energy:!executionError&&typeof geysers!=='undefined'?geysers.map(G=>[G.x,G.y,G.starter||'']):[] }; const realizationSig=JSON.stringify({zones:realization,relocation:relocation,resources:resources}); for(let i=0;i>>0).toString(16); SITE_STAMP.plan.realizationHash=SITE_STAMP.realizationHash; const failSig=SITE_STAMP.fails.map(function(f){ return f.class+':'+f.reason; }).join(','); const telemSig=telem?JSON.stringify(telem.reason):''; const s=SITE_STAMP.map+'|'+SITE_STAMP.plan.status+'|'+SITE_STAMP.plan.planHash+'|'+ JSON.stringify(req)+'|'+JSON.stringify(got)+'|'+names.join(',')+'|'+failSig+'|'+telemSig+'|'+SITE_STAMP.realizationHash; for(let i=0;i>>0).toString(16); } function siteStampPreflight(){ if(typeof mfPreflightLocationPlanV1==='function')return mfPreflightLocationPlanV1(curMap); const authored=typeof LocationMapPlanV1==='object'&&LocationMapPlanV1&&LocationMapPlanV1.plans&& Object.prototype.hasOwnProperty.call(LocationMapPlanV1.plans,curMap); return authored?{ok:false,status:'FAIL',map:curMap,planHash:'',requests:[], error:{code:'LOCATION_PREFLIGHT_UNAVAILABLE'}}: {ok:true,status:'LEGACY_V0',map:curMap,planHash:'',requests:[]}; } function siteStampWrapPlan(){ const preflight=siteStampPreflight(); if(!preflight.ok||preflight.status==='HYBRID_V1'){ const code=!preflight.ok?(preflight.error&&preflight.error.code||'LOCATION_PREFLIGHT_FAILED'): 'LOCATION_HYBRID_UNSUPPORTED'; const e=new Error(code);e.code=code;e.locationPlan=preflight;throw e; } siteStampBegin(preflight); try{ const args=[preflight];for(let i=0;i