Spaces:
Running
Running
File size: 18,789 Bytes
3597f5a 84bc42a eeb3b99 84bc42a eeb3b99 84bc42a 3597f5a eeb3b99 3597f5a eeb3b99 3597f5a eeb3b99 3597f5a 502e0c9 3597f5a 84bc42a 3597f5a 84bc42a 3597f5a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | ;
;
/* ============================================================================
BATTLEFIELD INTEL — vision, radar, detection, stealth
----------------------------------------------------------------------------
Fog already hid models, bars, FX and the minimap. What it did not do was
read the intel data the roster already carried:
TYPES[].scout Kestrel (and faction scouts) used the same air bubble as a
Wasp. The card said "150 sight"; fog stamped 14 cells.
umode === 4 GHOST: findEnemy skipped them, firing broke cover, hulls
went translucent — and the player still SAW them the
moment they entered a sensor circle. "Unseen until you
fire" was targeting-only.
BT.uplink Targeting Array / radar dish. Boosted towers and the build
grid. Vision was the generic 10-cell building stamp, so a
radar mast saw the same as a silo.
WC.dark "vision suffers" only forced night. Fog Bank (fogb) was
the only wildcard that actually shortened sensors.
Jamming has no authored radius/flag. Ghost Net already stuns and scans; a
dedicated radar-denial layer is a later plan item, not invented here.
Radar is a COMMAND-MAP layer, not a second 3D reveal. Uplink/techlab stamp
fogRadar; the minimap draws those contacts; render3d keeps using
fogEntityVisible (visual). That split is why this file must not live in
the renderer — and why it never writes GL state.
Detection is the answer to GHOST. Scouts, uplinks, techlabs, HQs and live
survey scans stamp fogDetect. intelCanTarget (sim.js seam) lets a detector
lock a silent-running hull; fogEntityVisible hides it from the player
until then. Same numbers both ways, so a cloak that fools the eye also
fools the gun until a sensor is in range.
============================================================================ */
const INTEL_VIS_GROUND=10, INTEL_VIS_AIR=14, INTEL_VIS_SCOUT=18, INTEL_VIS_GHOST=4;
const INTEL_VIS_HQ=22, INTEL_VIS_TURRET=12, INTEL_VIS_BLD=10, INTEL_VIS_CARRIER=24;
/* Radar cells are larger than visual on purpose: the mast hears further than
it sees. Contacts are minimap-only (see intelRadarContact). */
const INTEL_RADAR_UPLINK=22, INTEL_RADAR_TECHLAB=16;
/* Detect is shorter than radar. Omni-style pierce, not a second map hack. */
const INTEL_DET_SCOUT=16, INTEL_DET_UPLINK=14, INTEL_DET_TECHLAB=12, INTEL_DET_HQ=8;
const fogRadar=new Uint8Array(FN*FN);
const fogDetect=new Uint8Array(FN*FN);
const intelGhostIdx=[];
let intelGhostStamp=-1;
const intelHasGhost=[0,0,0];
/* Last-known contacts are a derived command-intel ledger, not gameplay or save
authority. `stats.t` is the only clock: replays therefore age the same way
at every render rate and pausing the renderer cannot create or expire intel.
Unit slot + generation is the stable identity because slots are recycled. */
const INTEL_CONTACT_CAP=256;
const INTEL_CONTACT_TTL={visual:10,radar:18,scan:14,aerial:16,manual:10};
const INTEL_CONTACT_CONF={visual:1,radar:.72,scan:.86,aerial:.92,manual:.65};
const intelContacts=[];
let intelContactClock=0;
function intelContactNow(){
return typeof stats!=='undefined'&&stats&&Number.isFinite(stats.t)?stats.t:0;
}
function intelContactAdvanceClock(now){
now=Number.isFinite(now)?now:intelContactNow();
if(now>intelContactClock) intelContactClock=now;
return intelContactClock;
}
function intelContactDefaults(source){
source=typeof source==='string'&&source?source:'manual';
return {source,
confidence:INTEL_CONTACT_CONF[source]===undefined?INTEL_CONTACT_CONF.manual:INTEL_CONTACT_CONF[source],
ttl:INTEL_CONTACT_TTL[source]===undefined?INTEL_CONTACT_TTL.manual:INTEL_CONTACT_TTL[source]};
}
function intelContactSnapshot(C){
return {team:C.team,target:C.target,generation:C.generation,x:C.x,y:C.y,
source:C.source,confidence:C.confidence,age:C.age,timestamp:C.timestamp,
expiresAt:C.expiresAt};
}
function intelContactTick(now){
now=intelContactAdvanceClock(now);
for(let i=intelContacts.length-1;i>=0;i--){
const C=intelContacts[i];
/* A living slot with another generation is a different chassis. A dead
slot with the same generation remains valid last-known intelligence. */
if(C.target<0||C.target>=MAXU||(ualive[C.target]&&ugen[C.target]!==C.generation)){
intelContacts.splice(i,1);continue;
}
C.age=Math.max(0,now-C.timestamp);
const span=Math.max(.000001,C.expiresAt-C.timestamp);
C.confidence=C.baseConfidence*clamp((C.expiresAt-now)/span,0,1);
if(now>=C.expiresAt||C.confidence<=0) intelContacts.splice(i,1);
}
return intelContacts.length;
}
function intelContactFind(team,target,generation){
for(let i=0;i<intelContacts.length;i++){
const C=intelContacts[i];
if(C.team===team&&C.target===target&&(generation===undefined||C.generation===generation)) return i;
}
return -1;
}
function intelContactWorse(A,B){
return A.confidence<B.confidence||
(A.confidence===B.confidence&&(A.timestamp<B.timestamp||
(A.timestamp===B.timestamp&&(A.team<B.team||
(A.team===B.team&&(A.target<B.target||
(A.target===B.target&&A.generation<B.generation)))))));
}
/* Minimal later-integration seam. Supplying x/y/generation/time is optional
for live units, but lets a fixed-step caller publish a sampled observation
without the renderer mutating the record. Stale updates never rewind it. */
function intelContactUpdate(team,target,source,confidence,ttl,x,y,generation,now){
team=team|0;target=target|0;
if(team<0||team>30||target<0||target>=MAXU) return null;
const sampledAt=Number.isFinite(now)?now:intelContactNow();
const staleSample=sampledAt<intelContactClock;
now=intelContactAdvanceClock(sampledAt);
generation=Number.isFinite(generation)?generation|0:ugen[target]|0;
if(ualive[target]&&ugen[target]!==generation) return null;
x=Number.isFinite(x)?x:+ux[target];y=Number.isFinite(y)?y:+uy[target];
if(!Number.isFinite(x)||!Number.isFinite(y)) return null;
const D=intelContactDefaults(source);
source=D.source;
confidence=Number.isFinite(confidence)?clamp(confidence,0,1):D.confidence;
ttl=Number.isFinite(ttl)?Math.max(.001,ttl):D.ttl;
if(confidence<=0) return null;
intelContactTick(now);
/* A recycled target slot cannot retain two generations for one observer. */
for(let i=intelContacts.length-1;i>=0;i--){
const C=intelContacts[i];
if(C.team===team&&C.target===target&&C.generation!==generation) intelContacts.splice(i,1);
}
let at=intelContactFind(team,target,generation),C=at>=0?intelContacts[at]:null;
/* Late packets/probe calls may describe an older simulation tick. They are
allowed to age the ledger to the current monotonic clock, but never to
refresh confidence or replace the newer sampled position. */
if(staleSample) return C?intelContactSnapshot(C):null;
if(C&&now<C.timestamp) return intelContactSnapshot(C);
if(C&&now===C.timestamp&&confidence<C.baseConfidence) return intelContactSnapshot(C);
if(!C){
if(intelContacts.length>=INTEL_CONTACT_CAP){
/* Deterministic pressure trim: weakest first, then oldest, then the
lowest stable identity. Active observations are not insertion-order
random and equal runs retain the same contact set. */
let worst=0;
for(let i=1;i<intelContacts.length;i++) if(intelContactWorse(intelContacts[i],intelContacts[worst])) worst=i;
const incoming={confidence,timestamp:now,team,target,generation};
if(intelContactWorse(incoming,intelContacts[worst])) return null;
intelContacts.splice(worst,1);
}
C={team,target,generation,x,y,source,confidence,baseConfidence:confidence,
age:0,timestamp:now,expiresAt:now+ttl};
intelContacts.push(C);
}else{
C.x=x;C.y=y;C.source=source;C.confidence=confidence;C.baseConfidence=confidence;
C.age=0;C.timestamp=now;C.expiresAt=now+ttl;
}
return intelContactSnapshot(C);
}
function intelContactGet(team,target,generation){
team=team|0;target=target|0;intelContactTick();
if(generation===undefined&&target>=0&&target<MAXU&&ualive[target]) generation=ugen[target]|0;
const at=intelContactFind(team,target,generation);
return at<0?null:intelContactSnapshot(intelContacts[at]);
}
function intelContactList(team,minConfidence){
team=team|0;minConfidence=Number.isFinite(minConfidence)?minConfidence:0;
intelContactTick();
return intelContacts.filter(C=>C.team===team&&C.confidence>=minConfidence)
.sort((A,B)=>A.target-B.target||A.generation-B.generation)
.map(intelContactSnapshot);
}
function intelArtillerySolution(team,request,now){
team=team|0;request=request&&typeof request==='object'?request:{};
now=intelContactAdvanceClock(now);
intelContactTick(now);
if(request.source==='player'&&Number.isFinite(request.x)&&Number.isFinite(request.y)){
return {eligible:true,team,target:-1,generation:-1,
x:clamp(request.x,0,MAP),y:clamp(request.y,0,MAP),source:'player',
confidence:1,age:0,timestamp:now,expiresAt:now};
}
const target=request.target|0;
if(target<0||target>=MAXU) return {eligible:false,team,reason:'invalid-target'};
const generation=Number.isFinite(request.generation)?request.generation|0:
(ualive[target]?ugen[target]|0:undefined);
const at=intelContactFind(team,target,generation);
if(at<0) return {eligible:false,team,target,generation,reason:'missing-contact'};
const C=intelContacts[at];
return {eligible:true,team,target:C.target,generation:C.generation,x:C.x,y:C.y,
source:C.source,confidence:C.confidence,age:C.age,timestamp:C.timestamp,
expiresAt:C.expiresAt};
}
function intelArtilleryScatterRadius(solution,weaponRadius){
if(!solution||!solution.eligible) return 0;
weaponRadius=Number.isFinite(weaponRadius)?Math.max(1,weaponRadius):64;
const sourceBias=solution.source==='visual'?.08:solution.source==='player'?.12:
solution.source==='aerial'?.14:solution.source==='scan'?.2:solution.source==='radar'?.28:.34;
const confidence=clamp(Number.isFinite(solution.confidence)?solution.confidence:0,0,1);
const ttl=Math.max(.001,(Number.isFinite(solution.expiresAt)?solution.expiresAt:0)-
(Number.isFinite(solution.timestamp)?solution.timestamp:0));
const ageRatio=clamp((Number.isFinite(solution.age)?solution.age:ttl)/ttl,0,1);
return weaponRadius*(sourceBias+(1-confidence)*.65+ageRatio*.25);
}
function intelArtilleryHash32(value){
value=(value|0)+0x6d2b79f5;
value=Math.imul(value^(value>>>15),value|1);
value^=value+Math.imul(value^(value>>>7),value|61);
return (value^(value>>>14))>>>0;
}
function intelArtilleryScatterPoint(solution,weaponRadius,shellIndex,seed){
if(!solution||!solution.eligible) return {x:NaN,y:NaN,radius:0};
const radius=intelArtilleryScatterRadius(solution,weaponRadius);
const identity=Math.imul((solution.target|0)+2,0x45d9f3b)^Math.imul((solution.generation|0)+2,0x119de1f3)^
Math.imul(Math.round(solution.x*16)|0,0x27d4eb2d)^Math.imul(Math.round(solution.y*16)|0,0x165667b1);
const h0=intelArtilleryHash32(identity^(seed|0)^Math.imul((shellIndex|0)+1,0x9e3779b1));
const h1=intelArtilleryHash32(h0^0x85ebca6b);
const angle=h0/4294967296*Math.PI*2;
const distance=Math.sqrt(h1/4294967296)*radius;
return {x:clamp(solution.x+Math.cos(angle)*distance,0,MAP),
y:clamp(solution.y+Math.sin(angle)*distance,0,MAP),radius};
}
function intelContactRefreshSensors(){
const active=typeof fogGameplayActive!=='function'||fogGameplayActive();
const now=intelContactNow();
intelContactTick(now);
if(!active) return;
const viewTeam=typeof mfFogViewTeam==='function'?mfFogViewTeam():0;
for(let i=0;i<unitHigh;i++){
if(!ualive[i]||(typeof uCrash!=='undefined'&&uCrash[i])) continue;
const cell=intelCell(ux[i],uy[i]);
for(let observer=0;observer<=1;observer++){
if(uteam[i]===observer) continue;
const bit=intelSensorBit(observer);
/* fogCov belongs to this client's local view. The other team's radar
sensors remain team-specific, but cannot borrow this visual grid. */
const visual=observer===viewTeam&&!!fogCov[cell]&&
(umode[i]!==4||intelDetectedAt(ux[i],uy[i],observer));
const radar=!!(fogRadar[cell]&bit)&&umode[i]!==4;
if(visual) intelContactUpdate(observer,i,'visual',undefined,undefined,
ux[i],uy[i],ugen[i],now);
else if(radar) intelContactUpdate(observer,i,'radar',undefined,undefined,
ux[i],uy[i],ugen[i],now);
}
}
}
function intelContactReset(){ intelContacts.length=0;intelContactClock=0; }
function intelVisionScale(r){
let s=r;
if(typeof WC!=='undefined'){
if(WC.fogb) s=Math.max(4,Math.round(s*0.6));
/* Total Eclipse already forces night (sim.js dayT). The card also promised
shorter sensors; without this it was a free payout on a cosmetic sky. */
if(WC.dark) s=Math.max(4,Math.round(s*0.72));
}
return s;
}
function intelUnitVision(i,vis,hm){
const T=TYPES[utype[i]];
let base=T.scout?INTEL_VIS_SCOUT:(T.air?INTEL_VIS_AIR:INTEL_VIS_GROUND);
if(umode[i]===4) base+=INTEL_VIS_GHOST;
const scaled=vis(base);
return Math.max(6,Math.round(6+(scaled-6)*hm));
}
function intelBldVision(B,vis,hm){
const t=B.type==='hq'?INTEL_VIS_HQ:B.type==='turret'?INTEL_VIS_TURRET:INTEL_VIS_BLD;
return Math.max(4,Math.round(vis(t)*hm));
}
function intelCell(wx,wy){
return clamp(wy/MAP*FN|0,0,FN-1)*FN+clamp(wx/MAP*FN|0,0,FN-1);
}
function intelStamp(grid,wx,wy,rc,bit){
if(rc<=0) return;
const cx=clamp(wx/MAP*FN|0,0,FN-1), cy=clamp(wy/MAP*FN|0,0,FN-1), r2=rc*rc;
for(let y=Math.max(0,cy-rc);y<=Math.min(FN-1,cy+rc);y++)
for(let x=Math.max(0,cx-rc);x<=Math.min(FN-1,cx+rc);x++){
const dx=x-cx,dy=y-cy;
if(dx*dx+dy*dy<=r2) grid[y*FN+x]|=bit;
}
}
function intelDetectedAt(wx,wy,team){
const bit=1<<(team|0);
return !!(fogDetect[intelCell(wx,wy)]&bit);
}
function intelRadarContact(wx,wy){
if(typeof fogGameplayActive==='function'&&!fogGameplayActive()) return false;
const viewTeam=typeof mfFogViewTeam==='function'?mfFogViewTeam():0;
return !!(fogRadar[intelCell(wx,wy)]&intelSensorBit(viewTeam));
}
function intelGhostRefresh(){
const t=(typeof stats!=='undefined'&&stats)?stats.t:-2;
if(t===intelGhostStamp) return;
intelGhostStamp=t;
intelGhostIdx.length=0;
intelHasGhost[0]=intelHasGhost[1]=intelHasGhost[2]=0;
for(let i=0;i<unitHigh;i++){
if(!ualive[i]||umode[i]!==4) continue;
intelGhostIdx.push(i);
intelHasGhost[uteam[i]]=1;
}
}
function intelGhostCloaked(team,wx,wy){
const viewTeam=typeof mfFogViewTeam==='function'?mfFogViewTeam():0;
if(team===viewTeam||!intelHasGhost[team]) return false;
intelGhostRefresh();
for(let n=0;n<intelGhostIdx.length;n++){
const j=intelGhostIdx[n];
if(!ualive[j]||uteam[j]!==team||umode[j]!==4) continue;
if(ux[j]!==wx||uy[j]!==wy) continue;
return !intelDetectedAt(wx,wy,viewTeam);
}
return false;
}
intelCanTarget=function(j,team){
if(!ualive[j]||uteam[j]===team) return false;
if(typeof uCrash!=='undefined'&&uCrash[j]) return false;
if(umode[j]===4&&!intelDetectedAt(ux[j],uy[j],team)) return false;
return true;
};
function intelSensorBit(team){ return team===1?2:team===0?1:0; }
function intelStampSensors(){
fogRadar.fill(0); fogDetect.fill(0);
const vis=intelVisionScale;
for(let i=0;i<unitHigh;i++){
if(!ualive[i]) continue;
const bit=intelSensorBit(uteam[i]); if(!bit) continue;
const T=TYPES[utype[i]];
if(T.scout){
const hm=typeof hazVisionMult==='function'?hazVisionMult(ux[i],uy[i],i):1;
intelStamp(fogDetect,ux[i],uy[i],Math.max(4,Math.round(vis(INTEL_DET_SCOUT)*hm)),bit);
}
}
for(const B of blds){
if(!B.alive||B.prog<1) continue;
const bit=intelSensorBit(B.team); if(!bit) continue;
const hm=typeof hazVisionMult==='function'?hazVisionMult(B.x,B.y,-1):1;
if(B.type==='uplink'){
intelStamp(fogRadar,B.x,B.y,Math.max(6,Math.round(vis(INTEL_RADAR_UPLINK)*hm)),bit);
intelStamp(fogDetect,B.x,B.y,Math.max(4,Math.round(vis(INTEL_DET_UPLINK)*hm)),bit);
}else if(B.type==='techlab'){
intelStamp(fogRadar,B.x,B.y,Math.max(6,Math.round(vis(INTEL_RADAR_TECHLAB)*hm)),bit);
intelStamp(fogDetect,B.x,B.y,Math.max(4,Math.round(vis(INTEL_DET_TECHLAB)*hm)),bit);
}else if(B.type==='hq'){
intelStamp(fogDetect,B.x,B.y,Math.max(4,Math.round(vis(INTEL_DET_HQ)*hm)),bit);
}
}
if(typeof carrier!=='undefined'&&carrier&&carrier.active)
intelStamp(fogDetect,carrier.x,carrier.y,vis(12),1);
if(typeof fogScans!=='undefined'){
for(let i=0;i<fogScans.length;i++){
const S=fogScans[i];
intelStamp(fogDetect,S.x,S.y,vis(S.r*2),1);
intelStamp(fogRadar,S.x,S.y,vis(S.r*2),1);
}
}
intelGhostStamp=-1;
intelGhostRefresh();
intelContactRefreshSensors();
}
function intelReset(){
fogRadar.fill(0); fogDetect.fill(0);
intelGhostIdx.length=0;
intelHasGhost[0]=intelHasGhost[1]=intelHasGhost[2]=0;
intelGhostStamp=-1;
intelContactReset();
}
(function mfIntelInstall(){
const baseFog=updateFog;
updateFog=function(){
baseFog();
intelStampSensors();
};
const baseVis=fogEntityVisible;
fogEntityVisible=function(team,wx,wy){
if(!baseVis(team,wx,wy)) return false;
/* Fog-off / attract / menus keep the old translucent GHOST hull. The
stance still needs a detector to be shot; hiding the model is a fog-on
intel rule so a silent Wasp cannot silhouette against black map. */
if(typeof fogGameplayActive==='function'&&!fogGameplayActive()) return true;
if(intelGhostCloaked(team,wx,wy)) return false;
return true;
};
if(typeof setMode==='function'&&!setMode._mfIntel){
const baseMode=setMode;
setMode=function(i,m){ const r=baseMode(i,m); intelGhostStamp=-1; return r; };
setMode._mfIntel=1;
}
if(typeof resetWorld==='function'&&!resetWorld._mfIntel){
const baseReset=resetWorld;
resetWorld=function(){ baseReset.apply(this,arguments); intelReset(); };
resetWorld._mfIntel=1;
}
const basePurpose=intelUnitPurpose;
intelUnitPurpose=function(T){
let s=basePurpose(T);
if(T.scout&&!/detect/i.test(s))
s=s.replace(/\.?$/,'')+'. Wider sensors, and it can detect silent-running chassis.';
return s;
};
const baseBld=intelBldPurpose;
intelBldPurpose=function(key){
let s=baseBld(key);
if(key==='uplink'&&!/radar/i.test(s))
s=s.replace(/\.?$/,'')+'. Paints radar contacts on the command map and detects GHOST chassis.';
else if(key==='techlab'&&!/detect/i.test(s))
s=s.replace(/\.?$/,'')+'. Sensor dish: shorter radar than an Uplink, still detects silent running.';
return s;
};
})();
|