@vimp-games/tanks 0.22.20 → 0.22.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{vimp_tanks_core_bg-CDHaJJaw.wasm → vimp_tanks_core_bg-6RnMvtoz.wasm} +0 -0
- package/dist/client-se-N9EV5.js +210 -0
- package/dist/client-se-N9EV5.js.map +1 -0
- package/dist/core-node/vimp_tanks_core_bg.wasm +0 -0
- package/dist/host-Cq_deDqg.js +1 -0
- package/dist/host-Cq_deDqg.js.map +1 -0
- package/dist/manifest.json +5 -5
- package/dist/maps/garden.json +1 -1
- package/dist/sounds/bomb-has-been-planted.webm +0 -0
- package/dist/sounds/bomb-has-been-planted2.webm +0 -0
- package/dist/sounds/defeat.webm +0 -0
- package/dist/sounds/empty-bullet.webm +0 -0
- package/dist/sounds/explosion.webm +0 -0
- package/dist/sounds/frag.webm +0 -0
- package/dist/sounds/game-over.webm +0 -0
- package/dist/sounds/hit.webm +0 -0
- package/dist/sounds/round-start.webm +0 -0
- package/dist/sounds/shot.webm +0 -0
- package/dist/sounds/tank-engine.webm +0 -0
- package/dist/sounds/tank-landing.webm +0 -0
- package/dist/sounds/tank-water.webm +0 -0
- package/dist/sounds/victory.webm +0 -0
- package/package.json +6 -6
- package/dist/client-D_wPcGVf.js +0 -210
- package/dist/client-D_wPcGVf.js.map +0 -1
- package/dist/host-DRRV0CQv.js +0 -1
- package/dist/host-DRRV0CQv.js.map +0 -1
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import{UniformGroup as $e,Filter as ro,GpuProgram as ao,GlProgram as Ls,defaultFilterVert as lo,Ticker as J,Container as G,Sprite as Z,Rectangle as nt,Spritesheet as ho,MeshSimple as co,Text as tn,BlurFilter as Ps,Assets as ms,Texture as Ze,Graphics as V,Shader as en,Geometry as uo,Mesh as sn,AlphaFilter as nn,PerspectiveMesh as fo,Particle as _o,ParticleContainer as ts,MeshGeometry as po}from"pixi.js";const mo=4;class gs{__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,Ws.unregister(this),t}free(){const t=this.__destroy_into_raw();E.__wbg_clientcore_free(t,0)}abi_describe(){let t,e;try{const s=E.clientcore_abi_describe(this.__wbg_ptr);return t=s[0],e=s[1],Pt(s[0],s[1])}finally{E.__wbindgen_free(t,e,1)}}apply_aim(t,e,s,n){E.clientcore_apply_aim(this.__wbg_ptr,t,e,s,n)}apply_input(t,e,s){const n=Vt(t,E.__wbindgen_malloc,E.__wbindgen_realloc),o=_t,r=Vt(e,E.__wbindgen_malloc,E.__wbindgen_realloc),a=_t;E.clientcore_apply_input(this.__wbg_ptr,n,o,r,a,s)}cycle_weapon(t){E.clientcore_cycle_weapon(this.__wbg_ptr,t)}debug_json(){let t,e;try{const s=E.clientcore_debug_json(this.__wbg_ptr);return t=s[0],e=s[1],Pt(s[0],s[1])}finally{E.__wbindgen_free(t,e,1)}}decode_frame(t){let e,s;try{const n=is(t,E.__wbindgen_malloc),o=_t,r=E.clientcore_decode_frame(this.__wbg_ptr,n,o);return e=r[0],s=r[1],Pt(r[0],r[1])}finally{E.__wbindgen_free(e,s,1)}}dispatch(t,e){const s=Vt(t,E.__wbindgen_malloc,E.__wbindgen_realloc),n=_t,o=is(e,E.__wbindgen_malloc),r=_t,a=E.clientcore_dispatch(this.__wbg_ptr,s,n,o,r);var l=xo(a[0],a[1]).slice();return E.__wbindgen_free(a[0],a[1]*1,1),l}floor_level(t,e,s){return E.clientcore_floor_level(this.__wbg_ptr,t,e,s)}hot_ptr(){return E.clientcore_hot_ptr(this.__wbg_ptr)>>>0}hot_values(){const t=E.clientcore_hot_values(this.__wbg_ptr);var e=ss(t[0],t[1]).slice();return E.__wbindgen_free(t[0],t[1]*4,4),e}map_dynamics_to_world(t,e,s){const n=Vt(t,E.__wbindgen_malloc,E.__wbindgen_realloc),o=_t,r=E.clientcore_map_dynamics_to_world(this.__wbg_ptr,n,o,e,s);var a=ss(r[0],r[1]).slice();return E.__wbindgen_free(r[0],r[1]*4,4),a}map_generation(){return E.clientcore_map_generation(this.__wbg_ptr)>>>0}my_game_id(){return E.clientcore_my_game_id(this.__wbg_ptr)}constructor(t){const e=Vt(t,E.__wbindgen_malloc,E.__wbindgen_realloc),s=_t,n=E.clientcore_new(e,s);if(n[2])throw Gs(n[1]);return this.__wbg_ptr=n[0],Ws.register(this,this.__wbg_ptr,this),this}offset(){return E.clientcore_offset(this.__wbg_ptr)}push_frame(t,e){const s=is(t,E.__wbindgen_malloc),n=_t;return E.clientcore_push_frame(this.__wbg_ptr,s,n,e)!==0}ramp_runs(){let t,e;try{const s=E.clientcore_ramp_runs(this.__wbg_ptr);return t=s[0],e=s[1],Pt(s[0],s[1])}finally{E.__wbindgen_free(t,e,1)}}reset(){E.clientcore_reset(this.__wbg_ptr)}resync(){E.clientcore_resync(this.__wbg_ptr)}sample(t){return E.clientcore_sample(this.__wbg_ptr,t)>>>0}set_active(t){E.clientcore_set_active(this.__wbg_ptr,t)}set_map(t){const e=Vt(t,E.__wbindgen_malloc,E.__wbindgen_realloc),s=_t,n=E.clientcore_set_map(this.__wbg_ptr,e,s);if(n[1])throw Gs(n[0])}set_model(t){const e=Vt(t,E.__wbindgen_malloc,E.__wbindgen_realloc),s=_t;E.clientcore_set_model(this.__wbg_ptr,e,s)}shot_segments(t,e,s,n,o,r){const a=E.clientcore_shot_segments(this.__wbg_ptr,t,e,s,n,o,r);var l=ss(a[0],a[1]).slice();return E.__wbindgen_free(a[0],a[1]*4,4),l}surface_at(t,e,s){return E.clientcore_surface_at(this.__wbg_ptr,t,e,s)}surface_dir_at(t,e,s){return E.clientcore_surface_dir_at(this.__wbg_ptr,t,e,s)}surface_types(){let t,e;try{const s=E.clientcore_surface_types(this.__wbg_ptr);return t=s[0],e=s[1],Pt(s[0],s[1])}finally{E.__wbindgen_free(t,e,1)}}sync_panel(t){const e=Vt(t,E.__wbindgen_malloc,E.__wbindgen_realloc),s=_t;E.clientcore_sync_panel(this.__wbg_ptr,e,s)}take_divergence(){let t,e;try{const s=E.clientcore_take_divergence(this.__wbg_ptr);return t=s[0],e=s[1],Pt(s[0],s[1])}finally{E.__wbindgen_free(t,e,1)}}take_frames(){let t,e;try{const s=E.clientcore_take_frames(this.__wbg_ptr);return t=s[0],e=s[1],Pt(s[0],s[1])}finally{E.__wbindgen_free(t,e,1)}}try_fire(t){const e=E.clientcore_try_fire(this.__wbg_ptr,t);let s;return e[0]!==0&&(s=Pt(e[0],e[1]).slice(),E.__wbindgen_free(e[0],e[1]*1,1)),s}}Symbol.dispose&&(gs.prototype[Symbol.dispose]=gs.prototype.free);function go(){return{__proto__:null,"./vimp_tanks_core_bg.js":{__proto__:null,__wbg_Error_92b29b0548f8b746:function(t,e){return Error(Pt(t,e))},__wbg___wbindgen_throw_344f42d3211c4765:function(t,e){throw new Error(Pt(t,e))},__wbindgen_init_externref_table:function(){const t=E.__wbindgen_externrefs,e=t.grow(4);t.set(0,void 0),t.set(e+0,void 0),t.set(e+1,null),t.set(e+2,!0),t.set(e+3,!1)}}}}const Ws=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(i=>E.__wbg_clientcore_free(i,1));typeof FinalizationRegistry>"u"||new FinalizationRegistry(i=>E.__wbg_gamecore_free(i,1));function ss(i,t){return i=i>>>0,yo().subarray(i/4,i/4+t)}function xo(i,t){return i=i>>>0,ce().subarray(i/1,i/1+t)}let be=null;function yo(){return(be===null||be.byteLength===0)&&(be=new Float32Array(E.memory.buffer)),be}function Pt(i,t){return vo(i>>>0,t)}let ke=null;function ce(){return(ke===null||ke.byteLength===0)&&(ke=new Uint8Array(E.memory.buffer)),ke}function is(i,t){const e=t(i.length*1,1)>>>0;return ce().set(i,e/1),_t=i.length,e}function Vt(i,t,e){if(e===void 0){const a=Le.encode(i),l=t(a.length,1)>>>0;return ce().subarray(l,l+a.length).set(a),_t=a.length,l}let s=i.length,n=t(s,1)>>>0;const o=ce();let r=0;for(;r<s;r++){const a=i.charCodeAt(r);if(a>127)break;o[n+r]=a}if(r!==s){r!==0&&(i=i.slice(r)),n=e(n,s,s=r+i.length*3,1)>>>0;const a=ce().subarray(n+r,n+s),l=Le.encodeInto(i,a);r+=l.written,n=e(n,s,r,1)>>>0}return _t=r,n}function Gs(i){const t=E.__wbindgen_externrefs.get(i);return E.__externref_table_dealloc(i),t}let Ue=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});Ue.decode();const wo=2146435072;let ns=0;function vo(i,t){return ns+=t,ns>=wo&&(Ue=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),Ue.decode(),ns=t),Ue.decode(ce().subarray(i,i+t))}const Le=new TextEncoder;"encodeInto"in Le||(Le.encodeInto=function(i,t){const e=Le.encode(i);return t.set(e),{read:i.length,written:e.length}});let _t=0,E;function So(i,t){return E=i.exports,be=null,ke=null,E.__wbindgen_start(),E}async function Mo(i,t){if(typeof Response=="function"&&i instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(i,t)}catch(n){if(i.ok&&e(i.type)&&i.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",n);else throw n}const s=await i.arrayBuffer();return await WebAssembly.instantiate(s,t)}else{const s=await WebAssembly.instantiate(i,t);return s instanceof WebAssembly.Instance?{instance:s,module:i}:s}function e(s){switch(s){case"basic":case"cors":case"default":return!0}return!1}}async function bo(i){if(E!==void 0)return E;i!==void 0&&(Object.getPrototypeOf(i)===Object.prototype?{module_or_path:i}=i:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),i===void 0&&(i=new URL("/assets/vimp_tanks_core_bg-6RnMvtoz.wasm",import.meta.url));const t=go();(typeof i=="string"||typeof Request=="function"&&i instanceof Request||typeof URL=="function"&&i instanceof URL)&&(i=fetch(i));const{instance:e,module:s}=await Mo(await i,t);return So(e)}const ko='@charset "UTF-8";#panel table td#panel-bullet:before{content:"bullet: "}#panel table td#panel-bomb:before{content:"bomb: "}#panel table td#panel-time:before{content:"time: "}#vimp{background:#222;position:absolute;inset:0;margin:auto;z-index:1}#radar{position:absolute;right:1%;top:35px;z-index:2;border-radius:50%;background-color:#00be5acc;box-shadow:inset 0 0 47px #ee6,0 0 0 3px #054}#team1{color:#f56}#team2{color:#7ed}#spectators{color:#fe5}#team1 tHead tr,#team2 tHead tr,#spectators tHead tr{border-bottom:1px solid #888;text-transform:capitalize;font-weight:700}#team1 tBody tr,#team2 tBody tr{border-bottom:1px solid #444}#team1 tHead td:first-child:before{content:"team1 ("}#team1 tHead td:first-child:after{content:")"}#team2 tHead td:first-child:before{content:"team2 ("}#team2 tHead td:first-child:after{content:")"}#spectators tHead td:first-child:before{content:"spectators"}#spectators tBody td:nth-child(1){padding:0 1%;line-height:1.4em}#spectators tBody td:nth-child(2),#spectators tBody td:nth-child(3),#spectators tBody td:nth-child(4),#spectators tBody td:nth-child(5){display:none}',Ao={mode:"hole",radius:260,softness:.45,minAlpha:.12,layerAlpha:.4,fadeRate:6,roofMargin:0,lowerTint:11579584},N={shear:.22,levelZStride:100},Ft={faceTilesPerLevel:3,faceSegments:4,faceBleedPx:2,rampSegments:4,sideTint:10133674},Lt={scaleGain:.1,baseAlpha:.4,alphaFalloff:.12,sizeFactor:1.05,groundOffset:3,groundAlpha:.3},Rt={lift:.35,vertices:6,shading:.28,lightDir:[-.7,-.7]},Qt={ambient:.55,diffuse:.6,lightZ:1},qt={duration:80,attack:.15,gunKick:1.8,bodyKick:.3,rock:.13},bt={enabled:!0,trackHeight:5,hullBase:2,hullTop:6,turretBase:6,turretTop:10,barrelHeight:8,barrelRadius:1.5,brakeRadius:2,levelHeight:12.8,leanGain:.3,maxLean:.6,shadowBlur:1},pe={rock:.22,wobbleHz:5,decay:180,duration:700,hop:.3,hopDuration:420,underShare:.5,shake:1.2,shakeDuration:220},$={referenceSize:3,maxFire:64,maxSmoke:80,wind:{x:5,y:-3},joltRadius:18,sound:"tankExplosion",flash:{duration:180,startSize:12,endSize:40,alpha:1,color:16773576},fireball:{count:14,speed:{min:15,max:50},drag:4,size:{min:4,max:7},grow:2.2,lifetime:{min:450,max:850},rise:.5,alpha:.95},sparks:{count:12,speed:{min:70,max:160},drag:3,length:2.4,width:.5,lifetime:{min:300,max:700},colors:[16770728,16738842]},fire:{duration:9e3,fadeOut:5e3,rate:36,points:[[-.3,0],[.05,0]],spread:.4,size:{min:2.5,max:4.5},grow:1.6,lifetime:{min:300,max:650},jitter:4,rise:.35,alpha:.85,ramp:[[0,16774344],[.2,16761418],[.5,15885850],[.8,9184266],[1,2361348]]},glow:{size:28,alpha:.3,color:16747056,flicker:.35},smoke:{rate:12,tailRate:7,tail:15e3,burst:{count:12,speed:{min:12,max:30},alpha:.55},size:{min:3,max:5},grow:3.8,lifetime:{min:2600,max:4200},speed:6,drag:1.5,rise:1.4,alpha:.42,tailAlpha:.2,burning:[1315344,2762274],cooling:[4867908,6446682]},scorch:{size:26,alpha:.55,fadeIn:400}},Cs={color:16751178,coreColor:16774368},on=[{scale:1.35,alpha:.18},{scale:1,alpha:.45},{scale:.55,alpha:.95,core:!0}],rn=.3,He={speed:19e3,minDuration:45,maxDuration:80,trailLength:55,trailShare:.4,...Cs,coreWidth:.4,glowWidth:1.3,glowAlpha:.2,taper:.3,alphaStart:1,alphaEnd:.6,height:.19,fadeSteps:8},To={duration:80,spikes:7,length:13,width:3.6,spread:.28,jitter:.35,sideLength:6,sideWidth:2.4,ball:{radius:2.8},ring:null,layers:on,shrink:rn,...Cs},Lo={duration:110,spikes:6,length:8,width:3,spread:1.1,jitter:.5,sideLength:0,ball:{radius:3.4},ring:{radius:10,width:.8,alpha:.3,duration:150,color:16769712},layers:on,shrink:rn,...Cs},an={count:5,speed:{min:8,max:26},spread:1.2,drag:3,size:{min:3,max:5},grow:2.5,lifetime:{min:600,max:1e3},alpha:.5,colors:[6249045,8025196,9340798]},Ct={sand:{color:14205834,rate:24,fullSpeed:60,minSpeed:4,lifetime:{min:350,max:750},sizeFactor:1,alpha:.35},mud:{color:3878430,rate:14,fullSpeed:60,minSpeed:4,lifetime:{min:180,max:380},sizeFactor:1.8,alpha:.6},water:{color:10474751,rate:20,fullSpeed:60,minSpeed:4,lifetime:{min:250,max:550},sizeFactor:1.1,alpha:.5,sideSpeed:{min:25,max:60},entryBurst:10,entryMinSpeed:20,sound:{minVolume:.25,fullSpeed:120,rate:{min:.9,max:1.1}}},boost:{color:16765024,burst:16,lifetime:{min:200,max:420},sizeFactor:1.4,alpha:.8,tailSpeed:{min:60,max:140},boostMinSpeed:20,resetDistance:40},tracks:{oil:{alpha:2,lifetime:3,tint:2105384,trail:1.5},mud:{alpha:1.5,lifetime:1,tint:5917242},noMarks:["water"]}},jt={fullImpact:6,squash:.14,duration:260,minImpact:1.5},Po={maxFps:30},yt={enabled:!0,resolution:.5,maxLights:96,headlights:{length:90,spread:.55,intensity:.9,color:16773572,offset:.5,occlusion:{enabled:!0,rays:64},bounce:{intensity:.35,radius:30,maxDistance:80},wash:{height:.6,intensity:1}},rampSpill:1,tankGlow:{radius:26,intensity:.35,color:12570879},flash:{explosion:{radius:140,intensity:1,duration:260,color:16756832},shot:{radius:90,intensity:.9,duration:120,color:16773280},hit:{radius:60,intensity:.8,duration:110,color:16760944},wreck:{radius:150,intensity:1.1,duration:320,color:16752720}},wreckFire:{radius:70,intensity:.75,color:16748608,flicker:.45},glints:{enabled:!0,intensity:.8,size:1.2},shafts:{enabled:!0,rays:14,length:1.3,intensity:.35,shadows:!0,maxShadowCasters:4}},ln={size:7,offsetY:11,arcs:3,period:900,popIn:120,color:3854699},me={period:900,maxScale:3.2,alpha:.9,color:3854699},hn=N.levelZStride,H=(i,t)=>i+hn*(t||0),cn=5,Ce=(i,t)=>Math.min(i||0,Math.round(t)),Co=hn*9;function ut(i,t){const e=t?.screen;return!i||i.destroyed||!e||!i.scale.x||!i.scale.y?null:{x:(e.width/2-i.position.x)/i.scale.x,y:(e.height/2-i.position.y)/i.scale.y,scaleX:i.scale.x,scaleY:i.scale.y}}function mt(i,t,e,s){return!e||!s?{x:i,y:t}:{x:i+(i-e.x)*s,y:t+(t-e.y)*s}}function gt(i,t,e,s=1){const n=typeof s=="number"?s:s.x,o=typeof s=="number"?s:s.y;if(!t||!e){i.scale.set(n,o),i.position.set(0,0);return}i.scale.set(n*(1+e),o*(1+e)),i.position.set(-t.x*e,-t.y*e)}function Pe(i,t,e,s,n){if(!e)return{x:i,y:t,scale:1};const o=(1+(n||0))/(1+(s||0));return{x:e.x+(i-e.x)*o,y:e.y+(t-e.y)*o,scale:o}}function ze(i){const t=typeof i=="number"?i:i.x,e=typeof i=="number"?i:i.y;return{x:t,y:e}}function ue(i,t,e){return Math.floor(i/t/e)}function Eo(i,t,e){return Math.round(i/t/e)}function zo(i,t,e){return{map:i,scale:t,step:e}}function un(i,t,e,s){const n=ue(t,i.scale.x,i.step),o=ue(e,i.scale.y,i.step),r=i.map?.[o]?.[n];return r!==void 0&&s.has(r)}function fn(i,t,e,s,n){if(!e||!t)return!1;const o=n>0?[[0,0],[n,0],[-n,0],[0,n],[0,-n]]:[[0,0]];for(const r of s){const a=1+r;for(const[l,h]of o)if(i((t.x+l+e.x*r)/a,(t.y+h+e.y*r)/a))return!0}return!1}function Io(i,t,e,s,n,o){return i?.map?fn((r,a)=>un(i,r,a,t),e,s,n,o):!1}function Ro(i,t,e,s,n,o,r){return!i||i.size===0?!1:fn((a,l)=>i.has(`${ue(a,e.x,t)},${ue(l,e.y,t)}`),s,n,o,r)}const dn=i=>i.radius*(1-i.softness),Fo=(i,t,e)=>{if(t<=i)return e<t?0:1;const s=Math.min(1,Math.max(0,(e-i)/(t-i)));return s*s*(3-2*s)};function Do({viewLevel:i,viewX:t,viewY:e,level:s,x:n,y:o,cfg:r}){if((s||0)<=(i||0))return 1;if(r.mode==="layer")return r.layerAlpha;const a=n-t,l=o-e,h=Math.sqrt(a*a+l*l),u=Fo(dn(r),r.radius,h);return r.minAlpha+(1-r.minAlpha)*u}function Xo(i,t,e){return(t||0)<(i||0)?e.lowerTint:16777215}const Yo=`
|
|
2
|
+
precision highp float;
|
|
3
|
+
|
|
4
|
+
in vec2 vTextureCoord;
|
|
5
|
+
|
|
6
|
+
out vec4 finalColor;
|
|
7
|
+
|
|
8
|
+
uniform sampler2D uTexture;
|
|
9
|
+
uniform vec4 uInputSize;
|
|
10
|
+
uniform vec4 uOutputFrame;
|
|
11
|
+
|
|
12
|
+
uniform vec2 uHoleCenter;
|
|
13
|
+
// x - внешний радиус, y - внутренний, z - alpha в центре дыры
|
|
14
|
+
uniform vec3 uHoleParams;
|
|
15
|
+
|
|
16
|
+
void main(void)
|
|
17
|
+
{
|
|
18
|
+
vec4 color = texture(uTexture, vTextureCoord);
|
|
19
|
+
vec2 pixel = uOutputFrame.xy + vTextureCoord * uInputSize.xy;
|
|
20
|
+
float d = distance(pixel, uHoleCenter);
|
|
21
|
+
float t = smoothstep(uHoleParams.y, uHoleParams.x, d);
|
|
22
|
+
|
|
23
|
+
finalColor = color * mix(uHoleParams.z, 1.0, t);
|
|
24
|
+
}
|
|
25
|
+
`,Ks=`
|
|
26
|
+
struct GlobalFilterUniforms {
|
|
27
|
+
uInputSize:vec4<f32>,
|
|
28
|
+
uInputPixel:vec4<f32>,
|
|
29
|
+
uInputClamp:vec4<f32>,
|
|
30
|
+
uOutputFrame:vec4<f32>,
|
|
31
|
+
uGlobalFrame:vec4<f32>,
|
|
32
|
+
uOutputTexture:vec4<f32>,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
struct HoleUniforms {
|
|
36
|
+
uHoleCenter:vec2<f32>,
|
|
37
|
+
uHoleParams:vec3<f32>,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
|
41
|
+
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
|
42
|
+
@group(0) @binding(2) var uSampler : sampler;
|
|
43
|
+
|
|
44
|
+
@group(1) @binding(0) var<uniform> holeUniforms : HoleUniforms;
|
|
45
|
+
|
|
46
|
+
struct VSOutput {
|
|
47
|
+
@builtin(position) position: vec4<f32>,
|
|
48
|
+
@location(0) uv : vec2<f32>
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
|
52
|
+
{
|
|
53
|
+
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
|
54
|
+
|
|
55
|
+
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
|
56
|
+
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y)
|
|
57
|
+
- gfu.uOutputTexture.z;
|
|
58
|
+
|
|
59
|
+
return vec4(position, 0.0, 1.0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
|
63
|
+
{
|
|
64
|
+
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@vertex
|
|
68
|
+
fn mainVertex(@location(0) aPosition : vec2<f32>) -> VSOutput {
|
|
69
|
+
return VSOutput(
|
|
70
|
+
filterVertexPosition(aPosition),
|
|
71
|
+
filterTextureCoord(aPosition)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@fragment
|
|
76
|
+
fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
|
|
77
|
+
var color = textureSample(uTexture, uSampler, uv);
|
|
78
|
+
var pixel = gfu.uOutputFrame.xy + uv * gfu.uInputSize.xy;
|
|
79
|
+
var d = distance(pixel, holeUniforms.uHoleCenter);
|
|
80
|
+
var t = smoothstep(holeUniforms.uHoleParams.y, holeUniforms.uHoleParams.x, d);
|
|
81
|
+
|
|
82
|
+
return color * mix(holeUniforms.uHoleParams.z, 1.0, t);
|
|
83
|
+
}
|
|
84
|
+
`;function Oo(i){const t=new $e({uHoleCenter:{value:new Float32Array([0,0]),type:"vec2<f32>"},uHoleParams:{value:new Float32Array([i.radius,dn(i),i.minAlpha]),type:"vec3<f32>"}});return new ro({glProgram:Ls.from({vertex:lo,fragment:Yo,name:"see-through-hole-filter"}),gpuProgram:ao.from({vertex:{source:Ks,entryPoint:"mainVertex"},fragment:{source:Ks,entryPoint:"mainFragment"}}),resources:{holeUniforms:t}})}function Vo(i,{centerX:t,centerY:e,radius:s,softness:n,minAlpha:o}){const r=i.resources.holeUniforms.uniforms;r.uHoleCenter[0]=t,r.uHoleCenter[1]=e,r.uHoleParams[0]=s,r.uHoleParams[1]=s*(1-n),r.uHoleParams[2]=o}const Bo=.01;function xs(){return{strength:0,filter:null,attached:!1,tick:null}}function _n(i,t){const e=J.shared.lastTime;return i.tick===e?0:(i.tick=e,Math.min(1,t*(J.shared.deltaMS/1e3)))}function Es(i,t,e){return i.strength+=((t?1:0)-i.strength)*e,i.strength}function pn(i,t){return 1+(t.minAlpha-1)*i.strength}function zs(i,t,e,s,n,o){if(t.strength<Bo||!n){t.attached&&(i.filters=[],t.attached=!1);return}t.filter||(t.filter=Oo(e)),t.attached||(i.filters=[t.filter],t.attached=!0);const r=mt(s.x,s.y,o,s.z*N.shear);Vo(t.filter,{centerX:r.x*n.scale.x+n.position.x,centerY:r.y*n.scale.y+n.position.y,radius:e.radius*n.scale.x,softness:e.softness,minAlpha:pn(t,e)})}function ys(i,t){if(!i.filter){i.attached=!1;return}t.filters=[],i.attached=!1,i.filter.destroy(),i.filter=null}async function mn(i,t){const e={};t.frames.forEach((o,r)=>{const[a,l,h,u]=o;e[`frame${r}`]={frame:{x:a,y:l,w:h,h:u}}});const s={frames:e,meta:{scale:"1"}},n=new ho(i,s);return await n.parse(),n}async function Is({baseTexture:i,spriteSheetData:t,map:e,tiles:s,step:n,renderer:o,exclude:r=[]}){const a=await mn(i,t),l=new Set(r),h=s.filter(p=>!l.has(p)),u=e[0].length*n,c=e.length*n,d=new G;for(let p=0,_=e.length;p<_;p+=1)for(let m=0,g=e[p].length;m<g;m+=1){const y=e[p][m];if(h.includes(y)){const S=`frame${y}`,b=a.textures[S];if(b){const v=new Z(b);v.x=m*n,v.y=p*n,d.addChild(v)}else console.warn(`Texture not found. Tile: ${y}, sprite: ${S}`)}}const f=o.generateTexture({target:d,frame:new nt(0,0,u,c)});return d.destroy({children:!0}),a.destroy(),f}function No(i,t){const e=[];if(!Array.isArray(i))return e;for(const s of i){const n=s.axis===0?0:1,o=n===0?1:0,r=t(s.min,n),a=t(s.max,n),l=t(s.crossMin,o),h=t(s.crossMax,o),u=typeof s.railMin=="number"&&typeof s.railMax=="number";e.push({axis:s.axis,sign:s.sign,from:s.from,to:s.to,block:s.block,rail0:u?t(s.railMin,n):null,rail1:u?t(s.railMax,n):null,col0:n===0?r:l,col1:n===0?a:h,row0:n===0?l:r,row1:n===0?h:a})}return Uo(e)}function Uo(i){const t=new Map;for(const s of i){const n=t.get(s.block);n?n.push(s):t.set(s.block,[s])}const e=[];for(const s of t.values()){const n=a=>a.axis===1?a.col0:a.row0,o=a=>a.axis===1?a.col1:a.row1;s.sort((a,l)=>n(a)-n(l));let r=null;for(const a of s){if(r&&n(a)===o(r)){r.axis===1?r.col1=a.col1:r.row1=a.row1;continue}r={...a},e.push(r)}}return e}function Rs(i){const t=new co(i);return t.geometry.batchMode="batch",t}const Ho=1e-6,Wo=1e3,gn=[0,1,3,0,3,2];function Go(i,t){const e=[],s=i.length,n=i.reduce((r,a)=>Math.max(r,a.length),0),o=(r,a)=>{const l=i[a]?.[r];return l!==void 0&&t.has(l)};for(let r=0;r<s;r+=1)for(let a=0;a<n;a+=1)if(o(a,r)){for(const l of[-1,1]){if(o(a,r+l))continue;const h=l<0?r:r+1;e.push({tile:i[r][a],col:a,row:r,nx:0,ny:l,x0:a,y0:h,x1:a+1,y1:h})}for(const l of[-1,1]){if(o(a+l,r))continue;const h=l<0?a:a+1;e.push({tile:i[r][a],col:a,row:r,nx:l,ny:0,x0:h,y0:r,x1:h,y1:r+1})}}return e}function xn(i,t){return Math.max(1,Math.ceil(i*t-1e-9))}function Ko({map:i,tiles:t,step:e,baseScale:s,level:n,volume:o,shear:r,sideTint:a,textures:l,tilesPerLevel:h=1,segments:u=1}){const c=Go(i,new Set(t)),d=n*r,f=(n+o)*r,p=f-Ho,_=Math.max(1,Math.ceil(o*u-1e-9)),m=xn(o,h),g=o*h/m,y=(_+1)*2,S=Math.max(1,Math.floor(Wo/_)),b=[],v=new Map;for(const M of c)v.has(M.tile)||v.set(M.tile,[]),v.get(M.tile).push(M);for(const[M,w]of v){const C=l?.get(M);if(!C){console.warn(`buildVolumeWalls: no side texture for tile ${M}`);continue}for(let A=0;A<w.length;A+=S){const L=w.slice(A,A+S),R=L.length,Y=R*y,I=new Float32Array(Y*2),D=new Float32Array(Y),X=new Float32Array(Y*2),U=new Uint32Array(R*_*6),O=new Float32Array(R*2),K=new Float32Array(R*2);for(let W=0;W<R;W+=1){const{nx:xt,ny:zt,x0:Ut,y0:Ht,x1:Wt,y1:Gt}=L[W],ot=Ut*e,Kt=Ht*e,$t=Wt*e,ft=Gt*e,x=W*y;for(let k=0;k<=_;k+=1)for(let P=0;P<2;P+=1){const T=x+k*2+P;I[T*2]=(P===1?$t:ot)*s.x,I[T*2+1]=(P===1?ft:Kt)*s.y,D[T]=f-(f-d)*k/_,X[T*2]=P,X[T*2+1]=g*k/_}for(let k=0;k<_;k+=1){const P=x+k*2,T=(W*_+k)*6;for(let z=0;z<6;z+=1)U[T+z]=P+gn[z]}O[W*2]=xt,O[W*2+1]=zt,K[W*2]=(ot+$t)/2*s.x,K[W*2+1]=(Kt+ft)/2*s.y}const j=Rs({texture:C,vertices:I.slice(),uvs:X,indices:U});j.tint=a,b.push({target:j,k:p,base:I,heights:D,rows:_,k0:d,k1:f,occluder:!0,walls:!0,normals:O,centers:K,facing:new Uint8Array(R).fill(2)})}}return b}function yn(i,t,e){return i.cameraX===t.x&&i.cameraY===t.y&&i.cameraScale===t.scaleX&&i.cameraBleed===e?!0:(i.cameraX=t.x,i.cameraY=t.y,i.cameraScale=t.scaleX,i.cameraBleed=e,!1)}function $o(i,t,e=0){if(yn(i,t,e))return;const{target:s,base:n,heights:o,rows:r}=i,a=s.vertices,l=(r+1)*2,h=e&&t.scaleX?e/t.scaleX:0;for(let u=0,c=o.length;u<c;u+=1){const d=n[u*2],f=n[u*2+1],p=d-t.x,_=f-t.y,m=u%l<2,g=Math.sqrt(p*p+_*_)||1e-6,y=o[u]+(m?h/g:0);a[u*2]=d+p*y,a[u*2+1]=f+_*y}s.vertices=a}function Zo(i,t){if(i.orderX===t.x&&i.orderY===t.y)return!1;i.orderX=t.x,i.orderY=t.y;const{target:e,normals:s,centers:n,facing:o,rows:r}=i,a=o.length,l=(r+1)*2;let h=!1;for(let d=0;d<a;d+=1){const p=s[d*2]*(t.x-n[d*2])+s[d*2+1]*(t.y-n[d*2+1])>0?1:0;o[d]!==p&&(o[d]=p,h=!0)}if(!h)return!1;const u=e.geometry.indices;let c=0;for(let d=0;d<2;d+=1)for(let f=0;f<a;f+=1)if(o[f]===d)for(let p=0;p<r;p+=1){const _=f*l+p*2;for(let m=0;m<6;m+=1)u[c]=_+gn[m],c+=1}return e.geometry.indices=u,!0}function qo({runs:i,texture:t,step:e,shear:s,baseScale:n,segments:o,sideTint:r}){const a=[],l=t.width||1,h=t.height||1,u=Math.max(1,Math.round(o)||1);for(const c of i){const d=c.axis===0,f=d?c.col1-c.col0:c.row1-c.row0,p=Math.max(1,f*u),_=d?c.col0:c.row0,m=typeof c.rail0=="number"&&typeof c.rail1=="number"?{first:(c.rail0-_)*u,last:(c.rail1-_)*u}:null,g=c.col0*e,y=c.col1*e,S=c.row0*e,b=c.row1*e,v=p+1,M=Math.min(c.from,c.to),w=Math.max(c.from,c.to),C=M*s,A=new Float32Array(v*4),L=new Float32Array(v*4),R=new Float32Array(v*4),Y=new Float32Array(v*2),I=new Uint32Array(p*6),D=1;for(let U=0;U<v;U+=1){const O=U/p,K=c.sign>0?O:1-O,j=(c.from+(c.to-c.from)*K)*s,W=d?g:S,zt=W+((d?y:b)-W)*O,Ut=d?zt:g,Ht=d?S:zt,Wt=d?zt:y,Gt=d?b:zt,ot=U*4;A[ot]=Ut*n.x,A[ot+1]=Ht*n.y,A[ot+2]=Wt*n.x,A[ot+3]=Gt*n.y,L[ot]=Ut/l,L[ot+1]=Ht/h,L[ot+2]=Wt/l,L[ot+3]=Gt/h;const Kt=d?Ht+D:Ut+D,$t=d?Gt-D:Wt-D,ft=Math.min(Math.max(zt,(d?g:S)+D),(d?y:b)-D);R[ot]=(d?ft:Kt)/l,R[ot+1]=(d?Kt:ft)/h,R[ot+2]=(d?ft:$t)/l,R[ot+3]=(d?$t:ft)/h,Y[U*2]=j,Y[U*2+1]=j}for(let U=0;U<p;U+=1){const O=U*2,K=U*6;I[K]=O,I[K+1]=O+1,I[K+2]=O+3,I[K+3]=O,I[K+4]=O+3,I[K+5]=O+2}const X=Rs({texture:t,vertices:A.slice(),uvs:L,indices:I});a.push(jo({base:A,uvs:R,heights:Y,points:v,texture:t,kBase:C,sideTint:r,endIndex:c.sign>0?v-1:0,rails:m})),a.push({target:X,k:w*s,base:A,heights:Y})}return a}function jo(i){const{base:t,uvs:e,heights:s,points:n,texture:o,kBase:r,endIndex:a,sideTint:l,rails:h}=i,u=h?Math.max(0,Math.min(h.first,n-1)):0,c=h?Math.max(u,Math.min(h.last,n-1)):-1,d=h?c-u+1:0,f=d*2+2,p=new Float32Array(f*4),_=new Float32Array(f*4),m=new Float32Array(f*2),g=Math.max(0,d-1)*2+1,y=new Uint32Array(g*6),S=M=>M<d?(u+M)*2:M<d*2?(u+M-d)*2+1:a*2+(M-d*2);for(let M=0;M<f;M+=1){const w=S(M),C=M*4,A=t[w*2],L=t[w*2+1];p[C]=A,p[C+1]=L,p[C+2]=A,p[C+3]=L,_[C]=e[w*2],_[C+1]=e[w*2+1],_[C+2]=e[w*2],_[C+3]=e[w*2+1],m[M*2]=s[w],m[M*2+1]=r}let b=0;for(let M=0;M<3;M+=1){const w=M===2?d*2:M*d,C=M===2?d*2+1:w+d-1;for(let A=w;A<C;A+=1){const L=A*2,R=b*6;y[R]=L,y[R+1]=L+1,y[R+2]=L+3,y[R+3]=L,y[R+4]=L+3,y[R+5]=L+2,b+=1}}const v=Rs({texture:o,vertices:p.slice(),uvs:_,indices:y});return v.tint=l,{target:v,k:r,base:p,heights:m}}function Qo(i,t){if(yn(i,t,0))return;const{target:e,base:s,heights:n}=i,o=e.vertices;for(let r=0,a=n.length;r<a;r+=1){const l=s[r*2],h=s[r*2+1],u=n[r];o[r*2]=l+(l-t.x)*u,o[r*2+1]=h+(h-t.y)*u}e.vertices=o}const ge={mapSprite:null,occluder:null,slices:[],rampTexture:null,wallTextures:[]};function Jo({mapSprite:i,bakedTexture:t,occluder:e,slices:s,rampTexture:n,wallTextures:o}){for(const r of s)r.target.parent?.removeChild(r.target),r.target.destroy({texture:!1,textureSource:!1});e?.destroy({children:!0,texture:!1,textureSource:!1}),n&&n.destroy(!0);for(const r of o??[])r.destroy(!0);i&&(i.parent?.removeChild(i),i.destroy({texture:!1,textureSource:!1})),t?.destroy(!0)}async function tr(i){try{const t=await i.baseTexture;if(i.isAborted())return ge;const e=await Is({baseTexture:t,spriteSheetData:i.spriteSheetData,map:i.map,tiles:i.tiles,step:i.step,renderer:i.renderer,exclude:i.exclude});if(i.isAborted())return e.destroy(!0),ge;const s=new Z(e);if(i.layerRoot.addChildAt(s,0),!i.extruding)return{...ge,mapSprite:s};const n=await er(i,t,e),o={mapSprite:s,...n};return i.isAborted()?(Jo({...o,bakedTexture:e}),ge):o}catch(t){return console.error(`Failed to create static map with asset ${i.assetUrl}:`,t),ge}}async function er(i,t,e){const s=N.shear,n=[],o=[];let r=null,a=null;if(i.volume>0){r=new G,r.zIndex=H(Math.max(i.layer,cn),i.level);{const h=await sr(i,t,o);if(i.isAborted())return{occluder:r,slices:n,rampTexture:a,wallTextures:o};n.push(...Ko({map:i.map,tiles:i.tiles,step:i.step,baseScale:i.baseScale,level:i.level,volume:i.volume,shear:s,sideTint:Ft.sideTint,textures:h,tilesPerLevel:Ft.faceTilesPerLevel,segments:Ft.faceSegments}));const u=new Z(e);u.tint=16777215,n.push({target:u,k:(i.level+i.volume)*s,occluder:!0})}}const l=wn(i);if(l.length){if(a=await Is({baseTexture:t,spriteSheetData:i.spriteSheetData,map:i.map,tiles:i.ramps.map(h=>h.tile),step:i.step,renderer:i.renderer}),i.isAborted())return{occluder:r,slices:n,rampTexture:a,wallTextures:o};n.push(...qo({runs:l,texture:a,step:i.step,shear:s,baseScale:i.baseScale,segments:Ft.rampSegments,sideTint:Ft.sideTint}))}if(i.isAborted())return{occluder:r,slices:n,rampTexture:a,wallTextures:o};n.sort((h,u)=>h.k-u.k);for(const h of n)h.base||gt(h.target,null,h.k,i.baseScale),(h.occluder?r:i.container).addChild(h.target);return{occluder:r,slices:n,rampTexture:a,wallTextures:o}}async function sr(i,t,e){const s=new Map,n=xn(i.volume,Ft.faceTilesPerLevel);for(const o of i.tiles){const r=await Is({baseTexture:t,spriteSheetData:i.spriteSheetData,map:Array.from({length:n},()=>[o]),tiles:[o],step:i.step,renderer:i.renderer});e.push(r),s.set(o,r)}return s}function wn(i){if(!i.ramps?.length||!i.rampRuns)return[];const t=new Set(i.ramps.map(n=>`${n.from}:${n.to}`)),e=i.rampRuns.forLevel(i.level).filter(n=>t.has(`${n.from}:${n.to}`));return No(e,(n,o)=>Eo(n,o===0?i.baseScale.x:i.baseScale.y,i.step))}function ir(i,t){if(!i.levelView)return;const e=i.levelView.cfg,s=_n(i.hole,e.fadeRate);i.hasSprite&&nr(i,e,s,t),i.occluder&&or(i,e,s,t)}function nr(i,t,e,s){const{levelView:n,container:o}=i,r=i.roof?n.level<i.level&&ar(i,t,s):null;if(n.mode==="layer"){const h=(i.roof?r:n.level<i.level&&un(i.grid,n.x,n.y,i.floorSet))?t.layerAlpha:1;o.alpha+=(h-o.alpha)*e;return}const a=i.roof?r:n.level<i.level;Es(i.hole,a,e),zs(o,i.hole,t,n,i.stage,s)}function or(i,t,e,s){const{levelView:n,occluder:o}=i,r=i.level>n.level;if(n.mode==="layer"){const a=r?t.layerAlpha:1;o.alpha+=(a-o.alpha)*e;return}Es(i.occluderHole,r,e),zs(o,i.occluderHole,t,n,i.stage,s)}function rr(i,t){const e=i.levelView;return mt(e.x,e.y,t,e.z*N.shear)}function ar(i,t,e){return e?Io(i.grid,i.tileSet,rr(i,e),e,[i.level*N.shear],t.roofMargin??0):!1}const lr=40,vn=45,hr=1.5;function cr(i){let t=2166136261;for(let e=0;e<i.length;e+=1)t^=i.charCodeAt(e),t=Math.imul(t,16777619)>>>0;return t>>>0}function ur(i){const t=i?.map?.length||0,e=i?.map?.[0]?.length||0,s=cr(JSON.stringify(i?.game?.lighting??null));return`${e}x${t}:${s.toString(16)}`}function fr(i,t,e,s){const{x:n,y:o}=ze(s);return{x:(i+.5)*e*n,y:(t+.5)*e*o}}function $s(i,t){const e=new Set(t||[]),s=[];if(!i||e.size===0)return s;for(let n=0;n<i.length;n+=1){const o=i[n]||[];for(let r=0;r<o.length;r+=1)e.has(o[r])&&s.push([r,n])}return s}function Zs(i){const t=new Map;for(const[s,n]of i)t.has(n)||t.set(n,new Set),t.get(n).add(s);const e=[];for(const s of[...t.keys()].sort((n,o)=>n-o)){const n=[...t.get(s)].sort((a,l)=>a-l);let o=n[0],r=n[0];for(let a=1;a<=n.length;a+=1){const l=n[a];l===r+1||(e.push({col:o,row:s,length:r-o+1}),o=l),r=l}}return e}function We(i,t,e,s,n,o){const r=e*o,a=mt(i,t,s,r);return{x:a.x,y:a.y,scale:1+r,screenX:a.x*n.scale.x+n.position.x,screenY:a.y*n.scale.y+n.position.y}}function Sn(i,t,e){return!e&&Math.abs(t-Math.round(t))>.001?[Math.floor(t),Math.ceil(t)]:[Ce(i,t)]}function ws(i,t,e,s,n){return i+e>=0&&i-e<=s&&t+e>=0&&t-e<=n}function fe(i,t,e){if(!e)return 1;const s=t/1e3,n=Math.sin(s*7.3+i*12.9898)*.5+Math.sin(s*13.1+i*78.233)*.3+Math.sin(s*23.7+i*3.7)*.2;return 1-e*((n+1)/2)}function Mn(i,t){if(!(t>0)||i>=t)return 0;const e=1-Math.max(0,i)/t;return e*e}function bn(i){return(1-i)*(1-i)}const dr=.35;function kn(i){return(1-i)*(1-i*dr)}function _r(i,t){return!(t>0)||i>=t?0:bn(Math.max(0,i)/t)}function An(i,t,e){const s=t-i.x,n=e-i.y,o=i.intensity??1;if(i.kind!=="cone")return o*_r(Math.hypot(s,n),i.radius);const r=Math.cos(i.rotation||0),a=Math.sin(i.rotation||0),l=s*r+n*a,h=Math.abs(n*r-s*a);if(!(i.radius>0)||l<=0||l>=i.radius)return 0;const u=l*(i.spread??.5);if(h>=u)return 0;const c=l/i.radius;return o*kn(c)*(1-h/u)}function pr(i,t,e,s){const n=[];for(const{light:o,factor:r}of i){const a=An(o,t,e)*r;a>0&&n.push({light:o,strength:a,angle:Math.atan2(o.y-e,o.x-t),color:o.color??16777215})}return n.sort((o,r)=>r.strength-o.strength),n.slice(0,Math.max(0,s))}const Tn=(i,t)=>`${i},${t}`;function mr(i,t){const e=t>0?t:1,s=new Map;for(const n of i){const o=n.radius||0,r=Math.floor((n.x-o)/e),a=Math.floor((n.x+o)/e),l=Math.floor((n.y-o)/e),h=Math.floor((n.y+o)/e);for(let u=l;u<=h;u+=1)for(let c=r;c<=a;c+=1){const d=Tn(c,u);s.has(d)||s.set(d,[]),s.get(d).push(n)}}return{cellSize:e,cells:s}}function gr(i,t,e){if(!i)return[];const s=Math.floor(t/i.cellSize),n=Math.floor(e/i.cellSize);return i.cells.get(Tn(s,n))||[]}function xr(i,t,e,s,n,o){const r=Math.hypot(e-i,s-t);if(!(n>0)||r<=n)return null;const a=Math.sqrt(r*r-n*n);if(a>=o)return null;const l=Math.atan2(s-t,e-i),h=Math.asin(n/r),u=l-h,c=l+h;return[i+Math.cos(u)*a,t+Math.sin(u)*a,i+Math.cos(u)*o,t+Math.sin(u)*o,i+Math.cos(c)*o,t+Math.sin(c)*o,i+Math.cos(c)*a,t+Math.sin(c)*a]}function yr(i,t,e){const s=t/1e3;return e*(Math.sin(s*.37+i*1.7)*.6+Math.sin(s*.61+i*4.1)*.4)}function wr(i=J.shared){let t=null,e=0;return{now(){const s=i.lastTime;return s!==t&&(t!==null&&(e+=Math.max(0,s-t)/1e3),t=s),e}}}const vr=wr();function Sr(i,t){return Math.floor(i*t)/t}function Mr(i){return new Set(Object.keys(i||{}).map(Number))}function br(i,t,e=1){if(i.speed!==void 0){const s=i.frames?.length||0,n=t*(typeof e=="number"?e:e.x);return n>0?i.speed*s/n:0}return i.fps||0}function Ln(i,t,e){return!(e>0)||!(t>0)?0:Math.floor(i*t)%e}function kr(i,t,e){const s=new G,n=[];if(s.label="animatedTiles",!e)return{container:s,groups:n};const o=new Set(i.tiles);for(const[r,a]of Object.entries(e)){const l=Number(r);if(!o.has(l))continue;const h=(a.frames||[]).map(c=>t.textures[`frame${c}`]).filter(Boolean);if(h.length===0){console.warn(`Animated tile ${l}: no frames found in the sprite sheet`);continue}const u={id:l,fps:br(a,i.step,i.scale),textures:h,sprites:[],container:new G,frame:0};u.container.label=`animatedTile-${l}`;for(let c=0;c<i.map.length;c+=1){const d=i.map[c];for(let f=0;f<d.length;f+=1){if(d[f]!==l)continue;const p=new Z(h[0]);p.x=f*i.step,p.y=c*i.step,p.cullable=!0,u.sprites.push(p),u.container.addChild(p)}}if(u.sprites.length===0){u.container.destroy();continue}s.addChild(u.container),n.push(u)}return{container:s,groups:n}}function Ar(i,t,e=()=>!0){for(let s=0;s<i.length;s+=1){const n=i[s];if(!e(n.container))continue;const o=Ln(t,n.fps,n.textures.length);if(o===n.frame)continue;n.frame=o;const r=n.textures[o];for(let a=0;a<n.sprites.length;a+=1)n.sprites[a].texture=r}}function Tr(i){i.container.parent?.removeChild(i.container),i.container.destroy({children:!0,texture:!1,textureSource:!1}),i.groups.length=0}function qs(i,t,e){return(i||[]).filter(s=>(s.level||0)===t&&Number(s.layer)===e)}function Lr(i,t,e,s){const n=[];for(const o of i){const[r,a]=o.cell||[0,0],h=(o.kind==="frames"?o.frames||[o.frame]:[o.frame]).map(c=>t.textures[`frame${c}`]).filter(Boolean);if(h.length===0){console.warn(`Decal at [${r}, ${a}]: frame not found in the sprite sheet`);continue}const u=new Z(h[0]);u.anchor.set(.5),u.position.set((r+.5)*e,(a+.5)*e),s.addChild(u),n.push({item:o,sprite:u,textures:h,frame:0})}return n}function Pr(i,t){for(let e=0;e<i.length;e+=1){const s=i[e];if(s.item.kind==="rotate"){s.sprite.rotation=(s.item.rps||0)*2*Math.PI*t;continue}if(s.item.kind==="frames"){const n=Ln(t,s.item.fps,s.textures.length);n!==s.frame&&(s.frame=n,s.sprite.texture=s.textures[n])}}}function Cr(i){for(const t of i)t.sprite.parent?.removeChild(t.sprite),t.sprite.destroy({texture:!1,textureSource:!1});i.length=0}const Er=.8,os=.6,js=.09,zr=.12,Ir=.55;function Pn(i){let t=i+2654435769>>>0;return t=Math.imul(t^t>>>16,2246822507)>>>0,t=Math.imul(t^t>>>13,3266489909)>>>0,(t^t>>>16)>>>0}function Rr(i,t,e=0){return Pn((Math.imul(i,73856093)^Math.imul(t,19349663)^Math.imul(e,83492791))>>>0)}function Qs(i,t,e){return Pn((i^Math.imul(t+e,668265261))>>>0)/4294967296}const xe=i=>Math.min(1,Math.max(0,i));function Fr(i,t,e){if(!(e>0))return!1;const s=Math.floor(i/os);if(Qs(t,s,0)>=e)return!1;const n=s*os+Qs(t,s,1)*(os-js);return i>=n&&i<n+js}function Dr(i,t,e){const s=xe(e?.pulse||0),n=t%1e3/1e3,o=1-s*(.5+.5*Math.sin(2*Math.PI*(Er*i+n)));return Fr(i,t,e?.dropouts||0)?{core:xe(o*zr),glow:xe(o*Ir)}:{core:xe(o),glow:xe(o)}}const Xr=4;function Tt(i){return Math.ceil(i*Xr)}function Cn(i){return Tt(i)*2}const vs=new WeakMap;function En({text:i,size:t}){return`${t}|${i}`}function Yr(i){return Math.max(2,Math.round(i/4))}function Or(i,{text:t,size:e}){const s=Yr(e),n=Tt(s),o=new G,r=new tn({text:String(t),style:{fontFamily:"monospace",fontWeight:"bold",fontSize:e,fill:16777215}});r.position.set(n,n),o.addChild(r);const a=new nt(0,0,Math.ceil(r.width)+n*2,Math.ceil(r.height)+n*2),l=i.generateTexture({target:o,frame:a}),h=new Ps({strength:s,quality:6});h.padding=Cn(s),r.filters=[h];const u=i.generateTexture({target:o,frame:a});return r.filters=[],h.destroy(),o.destroy({children:!0}),{core:l,glow:u}}function Vr(i,t){let e=vs.get(i);e||(e=new Map,vs.set(i,e));const s=En(t);let n=e.get(s);return n||(n={...Or(i,t),count:0},e.set(s,n)),n.count+=1,{core:n.core,glow:n.glow}}function Br(i,t){const e=vs.get(i),s=En(t),n=e?.get(s);n&&(n.count-=1,!(n.count>0)&&(e.delete(s),n.core.destroy(!0),n.glow.destroy(!0)))}class Nr{constructor({sign:t,renderer:e,lighting:s,animated:n,step:o,scale:r,level:a}){const[l,h]=t.cell||[0,0];this._sign=t,this._renderer=e,this._lighting=s||null,this._level=a,this._seed=Rr(l,h,a),this._scale=r,this._light=null,this._gridX=(l+.5)*o,this._gridY=(h+.5)*o,this._worldX=this._gridX*r.x,this._worldY=this._gridY*r.y;const u=Vr(e,t);this.glow=this._sprite(u.glow),this.core=this._sprite(u.core),this.emissive=!!this._lighting?.addEmissive(this.glow,a)&&this._lighting.addEmissive(this.core,a),this.emissive?t.light&&(this._light=this._lighting.addLight({kind:"radial",level:a,x:this._worldX,y:this._worldY,z:a,radius:t.light.radius??0,color:t.color??16777215,intensity:t.light.intensity??1})):(this._lighting?.removeEmissive(this.glow),this.glow.position.set(this._gridX,this._gridY),this.core.position.set(this._gridX,this._gridY),n.addChild(this.glow,this.core))}_sprite(t){const e=new Z(t);return e.anchor.set(.5),e.blendMode="add",e.tint=this._sign.color??16777215,e.angle=this._sign.angle||0,e}update(t,e,s,n=null){const o=t===null?{core:1,glow:1}:Dr(t,this._seed,this._sign.flicker);if(!this.emissive){this.glow.alpha=o.glow,this.core.alpha=o.core;return}const r=this._level*N.shear,a=mt(this._worldX,this._worldY,e,r);let l=1;n!==null?l=n:s&&(l=s.alphaFor(this._level,a.x,a.y,0));for(const h of[this.glow,this.core])h.position.set(a.x,a.y),h.scale.set(this._scale.x*(1+r),this._scale.y*(1+r));this.glow.alpha=l*o.glow,this.core.alpha=l*o.core,this._light&&this._lighting.updateLight(this._light,{intensity:(this._sign.light.intensity??1)*o.glow})}destroy(){this._lighting&&(this._light&&(this._lighting.removeLight(this._light),this._light=null),this._lighting.removeEmissive(this.glow),this._lighting.removeEmissive(this.core));for(const s of[this.glow,this.core])s.parent?.removeChild(s),s.destroy({texture:!1,textureSource:!1});const t=this._renderer,e=this._sign;return this._lighting=null,this._renderer=null,()=>Br(t,e)}}function Ur(i,t,e,s){const n=Mr(i?.animatedTiles),o=new Set(t);return{exclude:[...n],hasTiles:[...n].some(r=>o.has(r)),signs:qs(i?.signs,e,s),decals:qs(i?.decals,e,s)}}function Js(i){return i.hasTiles||i.signs.length>0||i.decals.length>0}async function Hr({spec:i,game:t,baseTexture:e,spriteSheetData:s,map:n,tiles:o,step:r,scale:a,level:l,animated:h,renderer:u,lighting:c,isAborted:d}){let f=null;if((i.hasTiles||i.decals.length>0)&&(f=await mn(e,s),d()))return f.destroy(),null;const p={sheet:f,tiles:null,decals:[],signs:[],tick:null};return i.hasTiles&&(p.tiles=kr({map:n,tiles:o,step:r,scale:a},f,t.animatedTiles),h.addChild(p.tiles.container)),f&&(p.decals=Lr(i.decals,f,r,h)),p.signs=i.signs.map(_=>new Nr({sign:_,renderer:u,lighting:c,animated:h,step:r,scale:a,level:l})),p}function Wr(i){return i?t=>{const e=t.getBounds();return e.maxX>=0&&e.minX<=i.width&&e.maxY>=0&&e.minY<=i.height}:()=>!0}function Gr(i,{camera:t,levelView:e,screen:s,roofAlpha:n=null}){const o=Sr(vr.now(),Po.maxFps),r=J.shared.lastTime;i.tick!==r&&(i.tick=r,i.tiles&&Ar(i.tiles.groups,o,Wr(s)),Pr(i.decals,o));for(let a=0;a<i.signs.length;a+=1)i.signs[a].update(o,t,e,n)}function Kr(i){if(!i)return()=>{};i.tiles&&(Tr(i.tiles),i.tiles=null),Cr(i.decals);const t=i.signs.map(s=>s.destroy()),e=i.sheet;return i.signs=[],i.sheet=null,()=>{t.forEach(s=>s()),e?.destroy()}}class $r{constructor(t,e,s,n,o={}){this._container=t,this._renderer=s.renderer,this._levelView=s.levelView||null,this._levelView?.setDiagnostics(s.diagnostics??null),this._rampRuns=s.rampRuns||null,this._hole=xs(),this._occluderHole=xs(),this._occluder=null,this._baseScale=ze(e.scale),this._slices=[],this._rampTexture=null,this._wallTextures=[],this.mapSprite=null,this._assetUrl=`${n}${e.spriteSheet.img}`,this._baseTexturePromise=ms.load(this._assetUrl),this._map=e.map,this._tiles=e.tiles,this._level=e.level||0,this._floor=e.floor||[],this._tileSet=new Set(this._tiles),this._floorSet=new Set(this._floor),this._roof=Zr(e.game,this._level,this._tiles),this._spriteSheetData=e.spriteSheet,this._step=e.step,this._layer=Number(e.layer)||1,t.zIndex=H(this._layer,this._level),this._parallaxK=this._level*N.shear,this._layerRoot=new G,this._layerRoot.label="layerRoot",this._animated=new G,this._animated.label="animated",this._layerRoot.addChild(this._animated),gt(this._layerRoot,null,this._parallaxK,this._baseScale),t.addChild(this._layerRoot),this._animationSpec=Ur(e.game,this._tiles,this._level,this._layer),this._animations=null,this._game=e.game,this._volume=Number(e.volume)||0,this._ramps=(e.ramps||[]).filter(r=>this._tiles.includes(r.tile)),this._extruding=this._volume>0||this._ramps.length>0,this._grid=zo(this._map,this._baseScale,this._step),this._lighting=s.lighting?.enabled?s.lighting:null,this._mapKey=null,this._lighting&&(this._lighting.registerTextures({radial:o.lightRadialTexture,head:o.lampHeadTexture,glint:o.glintTexture,shaft:o.lightShaftTexture}),this._mapKey=ur(e),this._lighting.acquireMap(this._mapKey,e.game?.lighting,this._step,e.scale,{cols:Math.max(0,...this._map.map(r=>r.length)),rows:this._map.length}),this._level>=1&&this._lighting.setLevelMask(this._level,$s(this._map,this._roof?this._tiles:this._floor),this,{roof:this._roof}),this._ramps.length&&this._lighting.setRampWedges(this._level,wn({ramps:this._ramps,rampRuns:this._rampRuns,level:this._level,baseScale:this._baseScale,step:this._step}),this)),this._volumes=s.volumes||null,this._volume>0&&this._volumes?.setLayerVolume(this._level,$s(this._map,this._tiles),this._volume,this,{step:this._step,scale:e.scale}),this.needsRender=this._level>=1||this._extruding||!!this._lighting?.isNight()||Js(this._animationSpec),this._build(e)}async _build(t){const e=await tr({container:this._container,layerRoot:this._layerRoot,exclude:this._animationSpec.exclude,baseTexture:this._baseTexturePromise,spriteSheetData:t.spriteSheet,map:this._map,tiles:this._tiles,step:this._step,renderer:this._renderer,level:this._level,layer:this._layer,volume:this._volume,ramps:this._ramps,rampRuns:this._rampRuns,baseScale:this._baseScale,parallaxK:this._parallaxK,extruding:this._extruding,assetUrl:this._assetUrl,isAborted:()=>this._container.destroyed});this.mapSprite=e.mapSprite,this._occluder=e.occluder,this._slices=e.slices,this._rampTexture=e.rampTexture,this._wallTextures=e.wallTextures??[],!(!this.mapSprite||this._container.destroyed||!Js(this._animationSpec))&&(this._animations=await Hr({spec:this._animationSpec,game:this._game,baseTexture:await this._baseTexturePromise,spriteSheetData:t.spriteSheet,map:this._map,tiles:this._tiles,step:this._step,scale:this._baseScale,level:this._level,animated:this._animated,renderer:this._renderer,lighting:this._lighting,isAborted:()=>this._container.destroyed}))}_seeThroughView(){return{levelView:this._levelView,container:this._container,stage:this._container.parent,occluder:this._occluder,hasSprite:!!this.mapSprite,hole:this._hole,occluderHole:this._occluderHole,level:this._level,grid:this._grid,tileSet:this._tileSet,floorSet:this._floorSet,roof:this._roof}}_roofAlpha(){return!this._roof||!this._levelView?null:this._levelView.mode==="layer"?this._container.alpha:pn(this._hole,this._levelView.cfg)}render(){this._attachOccluder(),this._levelView&&this._levelView.attachStage(this._container.parent,this._renderer);const t=this._levelView?this._levelView.camera():ut(this._container.parent,this._renderer);if(this._lighting&&(this._lighting.attachStage(this._container.parent,this._renderer),this._lighting.render()),(this._level>=1||this._occluder)&&ir(this._seeThroughView(),t),this._animations&&Gr(this._animations,{camera:t,levelView:this._levelView,screen:this._renderer?.screen,roofAlpha:this._roofAlpha()}),!(!this._parallaxK&&!this._slices.length)&&t){gt(this._layerRoot,t,this._parallaxK,this._baseScale);for(let e=0;e<this._slices.length;e+=1){const s=this._slices[e];s.walls?($o(s,t,Ft.faceBleedPx),Zo(s,t)):s.base?Qo(s,t):gt(s.target,t,s.k,this._baseScale)}}}_attachOccluder(){const t=this._container.parent;!this._occluder||!t||this._occluder.parent===t||t.addChild(this._occluder)}destroy(){const t=this._container,e=Kr(this._animations);if(this._animations=null,this._lighting&&(this._lighting.releaseMap(this._mapKey,this),this._lighting=null),this._volumes?.release(this),this._volumes=null,ys(this._hole,t),this._occluder){const a=this._occluder;this._occluder=null,a.filters=[],ys(this._occluderHole,a),a.parent?.removeChild(a),a.destroy({children:!0,texture:!1,textureSource:!1})}const s=this.mapSprite,n=this._rampTexture,o=this._wallTextures,r=this._slices;this.mapSprite=null,this._rampTexture=null,this._wallTextures=[],this._slices=[];for(const a of r)a.target.destroyed||(a.target.texture=Ze.EMPTY);return s&&s.parent?.removeChild(s),this._baseTexturePromise=null,this._assetUrl=null,this._map=null,this._tiles=null,this._floor=null,this._tileSet=null,this._floorSet=null,this._grid=null,this._ramps=null,this._spriteSheetData=null,this._renderer=null,this._levelView=null,this._game=null,()=>{e(),n&&n.destroy(!0);for(const a of o)a.destroy(!0);s&&s.destroy({children:!0,texture:!0,textureSource:!0})}}}function Zr(i,t,e){const s=i?.roofs?.[t]??i?.roofs?.[String(t)];if(!Array.isArray(s)||s.length===0||!e?.length)return!1;const n=new Set(s),o=e.filter(r=>n.has(r)).length;return o>0&&o<e.length?(console.warn(`MapLayer: level ${t} layer mixes roof tiles with others; a roof needs its own layer`),!1):o===e.length}const rt=(i,t,e)=>i+(t-i)*e,St=(i,t,e)=>Math.min(e,Math.max(t,i)),qr=i=>i*(Math.PI/180),jr=i=>{for(;i>Math.PI;)i-=Math.PI*2;for(;i<-Math.PI;)i+=Math.PI*2;return i},F=(i,t)=>Math.random()*(t-i)+i;class Nt extends G{constructor(t){super(),this._tickListener=null,this._isStarted=!1,this.isComplete=!1,this.onComplete=t}run(){this.isComplete||this._isStarted||(this._isStarted=!0,this._tickListener=t=>this._update(t.deltaMS),J.shared.add(this._tickListener),this._onEffectStart(),this.isComplete||this._update(0))}_onEffectStart(){}_update(){}_completeEffect(){this.isComplete||(this.isComplete=!0,this._tickListener&&(J.shared.remove(this._tickListener),this._tickListener=null),typeof this.onComplete=="function"&&this.onComplete())}destroy(t){this.isComplete=!0,this._tickListener&&(J.shared.remove(this._tickListener),this._tickListener=null),this.parent&&this.parent.removeChild(this),super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}class Qr extends Nt{constructor(t,e,s,n,o){super(n),this.x=t,this.y=e,this._textures=o.textures,this._contentSize=o.contentSize,this.config={particleCount:Math.round(F(6,10)),particleMinSize:1.5,particleMaxSize:4,minInitialSpeed:30,maxInitialSpeed:140,maxSpin:12,dragCoefficient:5,minLifetime:1200,maxLifetime:2200,fadeOutStart:.6,color:[7035460,5917240,8022613,4143667]},this.particlesData=[],this._createParticles(s/2)}_createParticles(t){const{config:e}=this;for(let s=0;s<e.particleCount;s+=1){const n=Math.random()*Math.PI*2,o=F(e.minInitialSpeed,e.maxInitialSpeed),r=this._textures[Math.floor(Math.random()*this._textures.length)],a=new Z(r),l=F(0,t);a.anchor.set(.5),a.tint=e.color[Math.floor(Math.random()*e.color.length)],a.scale.set(F(e.particleMinSize,e.particleMaxSize)/this._contentSize),this.particlesData.push({sprite:a,x:Math.cos(n)*l,y:Math.sin(n)*l,vx:Math.cos(n)*o,vy:Math.sin(n)*o,rotation:Math.random()*Math.PI*2,spin:F(-e.maxSpin,e.maxSpin),lifetime:F(e.minLifetime,e.maxLifetime),age:0}),this.addChild(a)}}_update(t){if(this.isComplete)return;const{config:e}=this,s=t/1e3,n=Math.max(0,1-e.dragCoefficient*s);let o=0;for(const r of this.particlesData){if(r.age>=r.lifetime)continue;r.age+=t,r.vx*=n,r.vy*=n,r.spin*=n,r.x+=r.vx*s,r.y+=r.vy*s,r.rotation+=r.spin*s;const a=r.age/r.lifetime,{sprite:l}=r;l.position.set(r.x,r.y),l.rotation=r.rotation,l.alpha=a<e.fadeOutStart?1:rt(1,0,Math.min((a-e.fadeOutStart)/(1-e.fadeOutStart),1)),r.age>=r.lifetime?l.visible=!1:o+=1}o===0&&this._isStarted&&this._completeEffect()}destroy(t){this.particlesData=[],super.destroy(t)}}function zn(i,{x:t,y:e,z:s,level:n,reach:o,exclude:r=null}){const a=i?.texture("glint");return!yt.glints?.enabled||!a||!i.isNight()||!i.onScreen(t,e,s,o)?null:i.lightsAt(t,e,n,1,r)[0]||null}function In(i,t,e){if(i)return i;const s=new Z(e),n=new Z;return s.anchor.set(.5),s.blendMode="add",s.mask=n,t.addChild(n,s),{sprite:s,mask:n}}function Rn(i){i&&(i.sprite.visible=!1)}function Fn(i,{hit:t,asset:e,x:s,y:n,rotation:o,size:r}){const{sprite:a}=i,l=yt.glints;a.texture=e.texture,a.visible=!0,a.position.set(s,n),a.rotation=o,a.scale.set(r*l.size/e.contentSize),a.tint=t.color,a.alpha=Math.min(1,l.intensity*t.strength)}const kt=0,At=1,Dt=2,ti=3,de=4,_e=5,Bt=6,Mt=7,Ie=8,qe=9,te=11,pt=12,Ee=13,ei=14,si=15,Jr=0,ta=1,ea=2,sa=3,ia=4,na=5,oa=6,rs=7,ra=8,aa=9,ii=10,ni=2,la=3,oi=0,ri=1,ai=2,ha=3,ca=4,ua=6,fa=0,da=1,_a=2,pa=3,li=0,hi=1,ci=2,ma=3,ga=4,xa=5,ui=0,ya=1,ye=2,wa=1,va=2,Sa=1.4;class Ma{constructor(t,e,s,n,o={}){this._container=t,this._renderer=s.renderer,this._soundManager=s.soundManager||null,this._assets=o||{},this._levelView=s.levelView||null,this._lighting=s.lighting?.enabled?s.lighting:null,this._glint=null,this._caster=null,this._baseScale=ze(e.scale),t.scale=e.scale,this._assetUrl=`${n}${e.img}`,this._baseTexturePromise=ms.load(this._assetUrl),this._damagedUrl=e.game?.imgDamaged?`${n}${e.game.imgDamaged}`:null,this._destroyedUrl=e.game?.imgDestroyed?`${n}${e.game.imgDestroyed}`:null,this._z=e.level||0,this._level=e.level||0,this._layer=Number(e.layer)||2,t.zIndex=H(this._layer,this._level),this._rotation=qr(e.angle),this._width=e.width,this._height=e.height,this._x=e.position[0],this._y=e.position[1],this._worldX=this._x*this._baseScale.x,this._worldY=this._y*this._baseScale.y,this._state=null,this.sprite=null,this._scorch=null,this._effects=new Set,this.needsRender=!!this._levelView,this._create()}async _create(){try{const t=await this._baseTexturePromise;if(this._container.destroyed)return;this.sprite=new Z(t),this.sprite.x=this._x,this.sprite.y=this._y,this.sprite.width=this._width,this.sprite.height=this._height,this.sprite.rotation=this._rotation,this._container.addChild(this.sprite),this._state!==null&&this._state!==ui&&this._showState(this._state)}catch(t){console.error(`Failed to create dynamic map with asset ${this._assetUrl}:`,t)}}render(){if(!this._levelView||!this.sprite)return;this._updateGlint(),this._updateCaster();const t=this._container;t.alpha=this._levelView.alphaFor(this._level,this._worldX,this._worldY,this._z),t.tint=this._levelView.tintFor(this._level),!(!this._level&&!this._z)&>(t,this._levelView.camera()??ut(t.parent,this._renderer),this._z*N.shear,this._baseScale)}update(t){this.sprite&&(this.sprite.x=t[li]/this._baseScale.x,this.sprite.y=t[hi]/this._baseScale.y,this.sprite.rotation=t[ci]),this._worldX=t[li],this._worldY=t[hi],this._rotation=t[ci],this._z=t[ma]||0;const e=Ce(t[ga],this._z);e!==this._level&&(this._level=e,this._container.zIndex=H(this._drawLayer(),e),!e&&!this._z&>(this._container,null,0,this._baseScale));const s=t[xa]||ui;if(s!==this._state){const n=this._state===null;this._state=s,this._showState(s),s===ye&&!n&&this._burst()}this._placeScorch()}_drawLayer(){return this._state===ye?wa:this._layer}_standing(){return this._state!==ye||!!this._destroyedUrl}_updateGlint(){const t=this._localCenter(),e=this.sprite.visible&&this._standing()?zn(this._lighting,{x:t.x*this._baseScale.x,y:t.y*this._baseScale.y,z:this._z,level:this._level,reach:Math.max(this._width*this._baseScale.x,this._height*this._baseScale.y)}):null;if(!e){Rn(this._glint);return}const s=this._lighting.texture("glint");this._glint=In(this._glint,this._container,s.texture);const{mask:n}=this._glint,o=this.sprite;n.texture=o.texture,n.position.copyFrom(o.position),n.scale.copyFrom(o.scale),n.rotation=o.rotation,Fn(this._glint,{hit:e,asset:s,x:t.x,y:t.y,rotation:e.angle,size:Math.max(this._width,this._height)})}_updateCaster(){if(!this._lighting)return;if(!this._lighting.castsShadows()||!this._standing()){this._caster&&(this._lighting.setCaster(this,null),this._caster=null);return}this._caster||(this._caster={},this._lighting.setCaster(this,this._caster));const t=this._localCenter();this._caster.x=t.x*this._baseScale.x,this._caster.y=t.y*this._baseScale.y,this._caster.z=this._z,this._caster.level=this._level,this._caster.radius=Math.hypot(this._width*this._baseScale.x,this._height*this._baseScale.y)/2}_showState(t){if(this._container.zIndex=H(this._drawLayer(),this._level),!this.sprite)return;if(t===ye&&!this._destroyedUrl){this.sprite.visible=!1,this._showScorch();return}this._scorch&&(this._scorch.visible=!1),this.sprite.visible=!0;let e=null;t===ya?e=this._damagedUrl:t===ye&&(e=this._destroyedUrl),this._setTexture(e?ms.load(e):this._baseTexturePromise,t,e??this._assetUrl)}async _setTexture(t,e,s){try{const n=await t;if(this._container.destroyed||!this.sprite||this._state!==e)return;this.sprite.texture=n,this.sprite.width=this._width,this.sprite.height=this._height}catch(n){console.error(`Failed to load map object state asset ${s}:`,n)}}_showScorch(){const t=this._assets.scorchTexture;if(t){if(!this._scorch){const{textures:e,contentSize:s}=t,n=new Z(e[Math.floor(Math.random()*e.length)]);n.anchor.set(.5),n.rotation=Math.random()*Math.PI*2,n.scale.set(Math.max(this._width,this._height)*Sa/s),this._scorch=n,this._container.addChild(n)}this._scorch.visible=!0,this._placeScorch()}}_placeScorch(){if(!this._scorch?.visible)return;const t=this._localCenter();this._scorch.position.set(t.x,t.y)}_localCenter(){const t=Math.cos(this._rotation),e=Math.sin(this._rotation),s=this._width/2,n=this._height/2;return{x:this._worldX/this._baseScale.x+t*s-e*n,y:this._worldY/this._baseScale.y+e*s+t*n}}_burst(){const t=this._localCenter(),e=t.x*this._baseScale.x,s=t.y*this._baseScale.y;this._soundManager?.registerSound("propBreak",{position:{x:e,y:s}});const n=this._container.parent,o=this._assets.debrisTexture;if(!n||!o)return;const r=Math.max(this._width*this._baseScale.x,this._height*this._baseScale.y),a=new Qr(e,s,r,()=>{this._effects.delete(a),a.destroy()},o);a.zIndex=H(va,this._level),n.addChild(a),this._effects.add(a),a.run()}destroy(){for(const t of this._effects)t.destroy();this._effects.clear(),this._lighting?.setCaster(this,null),this._lighting=null,this._glint=null,this.sprite=null,this._scorch=null,this._baseTexturePromise=null,this._assetUrl=null,this._renderer=null,this._levelView=null,this._soundManager=null}}let ba=class extends G{constructor(t,e,s){if(super(),this._mode=null,typeof s.assetsBase!="string"){console.error("Map: сервис assetsBase недоступен — карта останется пустой. Объявите assetsBase в componentDependencies и запустите игру на vimp-engine >= 0.9.0");return}const n=`${s.assetsBase}img/`;this._mode=t.type==="dynamic"?new Ma(this,t,s,n,e):new $r(this,t,s,n,e),this._mode.needsRender&&(this.onRender=()=>this._mode.render())}update(t){this._mode?.update?.(t)}destroy(t){const e=this._mode?.destroy();this._mode=null,super.destroy({children:!0,texture:!1,textureSource:!1,...t}),e?.()}};const fi=[16777215,9418751,10477760,15783820,14721232,10541296,15773836,12632280],Dn=i=>fi[i]??fi[0],ka=2,Aa=.35;class Ta extends G{constructor(t,e,s={}){super(),this._map=t.map,this._level=t.level||0,this._solid=t.solid||t.physicsStatic||[],this._tiles=t.tiles||[],this._step=t.step,this.zIndex=H(ka,this._level),this.scale=t.scale,this._draws=this._tiles.some(n=>this._solid.includes(n)),this.radarGraphics=new V,this.addChild(this.radarGraphics),this._levelView=s.levelView||null,this._levelView&&this._draws&&(this.onRender=()=>{this.alpha=this._levelView.level===this._level?1:Aa}),this.createRadarMap()}createRadarMap(){if(!this._draws)return;const t=this.radarGraphics;if(t.clear(),Array.isArray(this._map))for(let e=0;e<this._map.length;e+=1){const s=this._map[e];if(Array.isArray(s))for(let n=0;n<s.length;n+=1){const o=s[n];this._solid.includes(o)&&t.rect(n*this._step,e*this._step,this._step/2,this._step/2)}}t.fill(Dn(this._level))}update(){}destroy(t){super.destroy({children:!0,texture:!1,textureSource:!1,...t}),this.radarGraphics=null,this._map=null,this._solid=null,this._tiles=null}}const di=2,La=9,Pa=1.5;class Ca extends G{constructor(t,e,s,n){super(),this._level=t[pt]||0,this.zIndex=H(di,this._level),this._textures=e.tankRadarTexture,this.body=new Z,this.body.anchor.set(.5),this.levelRing=new V,this.addChild(this.levelRing,this.body),this._voice=s?.voice??null,this._partId=n?.id,this.ping=null,this._voice&&e.radarPingTexture&&(this.ping=new Z(e.radarPingTexture.ring),this.ping.anchor.set(.5),this.ping.tint=me.color,this.ping.visible=!1,this.addChildAt(this.ping,0),this.onRender=()=>this._updatePing()),this._drawLevelRing(),this.x=t[kt]||0,this.y=t[At]||0,this._condition=t[Mt],this._teamId=t[qe],this.scale.set(5,5),this.create()}_drawLevelRing(){this.levelRing.clear(),this._level>0&&this.levelRing.circle(0,0,La).stroke({width:Pa,color:Dn(this._level)})}_updatePing(){const t=this._condition!==0&&this._voice.isTalking(this._partId)===!0;if(this.ping.visible=t,!t)return;const e=this._voice.talkingSince(this._partId)??0,s=(performance.now()-e)%me.period/me.period;this.ping.scale.set(1+(me.maxScale-1)*s),this.ping.alpha=me.alpha*(1-s)}create(){this._condition===0?this.body.texture=this._textures.destroyed:this._teamId===1?this.body.texture=this._textures.liveTeamId1:this._teamId===2&&(this.body.texture=this._textures.liveTeamId2)}update(t){this.x=t[kt],this.y=t[At];const e=t[pt]||0;e!==this._level&&(this._level=e,this.zIndex=H(di,e),this._drawLevelRing());const s=t[Mt],n=t[qe];let o=!1;s!==void 0&&s!==this._condition&&(this._condition=s,o=!0),n!==void 0&&n!==this._teamId&&(this._teamId=n,o=!0),o&&this.create()}destroy(t){super.destroy({children:!0,texture:!1,textureSource:!1,...t}),this.body=null,this.levelRing=null,this.ping=null,this._voice=null,this._textures=null}}function Ea({width:i,height:t,anchorX:e,anchorY:s,rotation:n,heading:o=0,pitch:r,roll:a,shear:l,lift:h}){const u=-e*i,c=(1-e)*i,d=-s*t,f=(1-s)*t,p=[[u,d],[c,d],[c,f],[u,f]],_=Math.cos(n),m=Math.sin(n),g=Math.cos(r),y=Math.sin(r),S=Math.cos(a),b=Math.sin(a),v=-Math.sin(o),M=-Math.cos(o),w=[];for(const[C,A]of p){const L=C*_-A*m,R=C*m+A*_,Y=L*g,I=L*y,D=R*S,X=R*b,U=I+X,O=t?U/t*l:0,K=U*h;w.push(Y*(1+O)+v*K,D*(1+O)+M*K)}return w}function za({angle:i,pitch:t,roll:e,lightDir:s,shading:n}){if(!s)return 1;const o=Math.cos(i),r=Math.sin(i),a=-Math.sin(t)*o+Math.sin(e)*r,l=-Math.sin(t)*r-Math.sin(e)*o,h=Math.hypot(s[0],s[1])||1,u=(a*s[0]+l*s[1])/h;return 1-Math.max(0,-u)*n}function Jt(i,t){const e=s=>{const n=Math.round((i>>s&255)*t);return Math.min(255,Math.max(0,n))};return e(16)<<16|e(8)<<8|e(0)}function Xn(i,t,{minImpact:e,fullImpact:s}){return!(i<-e)||t!==0?0:Math.min(1,-i/s)}function Ia(i,t,e){if(i<0||i>=t)return 0;const s=i/t;if(s<e)return s/e;const n=(s-e)/(1-e);return(1-n)*(1-n)}function Ra({amount:i,gunRotation:t,config:e}){const s=Math.cos(t),n=Math.sin(t),o=e.gunKick*i,r=e.bodyKick*i,a=e.rock*i;return{gun:{x:-s*o,y:-n*o},body:{x:-s*r,y:-n*r},pitch:a*s,roll:a*n}}const Ge=Math.PI*2,Fa=.09,Da=.113;function Xa(i,t){return!(t>0)||i>=t?0:1-i/t}function Ya({x:i,y:t,level:e,heading:s,hullLength:n,blast:o,config:r,rng:a=Math.random}){if((o.level||0)!==(e||0))return null;const l=o.x-i,h=o.y-t,u=Math.hypot(l,h),c=Xa(u,o.radius);if(!c)return null;const d=u<r.underShare*n,f=d?a()*Ge:Math.atan2(h,l)-s;return{strength:c,dirU:Math.cos(f),dirV:Math.sin(f),hop:d,phaseX:a()*Ge,phaseY:a()*Ge}}function _i({elapsed:i,kick:t,config:e}){const s=t.strength,n=e.decay>0?Math.exp(-i/e.decay):0,o=n*Math.cos(Ge*e.wobbleHz*(i/1e3)),r=e.rock*s*o,a=t.hop&&i<e.hopDuration,l=a?e.hop*s*Math.sin(Math.PI*i/e.hopDuration):0,u=i<e.shakeDuration?e.shake*s*(1-i/e.shakeDuration):0;return{pitch:r*t.dirU,roll:r*t.dirV,lift:l,shakeX:u*Math.sin(i*Fa+t.phaseX),shakeY:u*Math.sin(i*Da+t.phaseY),envelope:s*n,done:i>=e.duration&&!a}}const pi=[[1.33,-.42],[.42,-1],[-.42,-1],[-1.33,-.42],[-1.33,.42],[-.42,1],[.42,1],[1.33,.42]].map(([i,t])=>[i*10,t*10]),mi={track:0,hull:1,turret:2,barrel:3};function Yn(i){let t=0;for(let e=0;e<i.length;e+=1){const[s,n]=i[e],[o,r]=i[(e+1)%i.length];t+=s*r-o*n}return t}function Oa(i){let t=0,e=0,s=0;for(let o=0;o<i.length;o+=1){const[r,a,l]=i[o],[h,u,c]=i[(o+1)%i.length];t+=(a-u)*(l+c),e+=(l-c)*(r+h),s+=(r-h)*(a+u)}const n=Math.hypot(t,e,s)||1;return[t/n,e/n,s/n]}const we=(i,t,e,s)=>[[i,e],[t,e],[t,s],[i,s]],Va=(i,t)=>i.map(([e,s])=>[e*t,s*t]);function Ba(i=bt){const t=[],e=[],s=({bottom:r,top:a,w0:l,w1:h,part:u,topMaterial:c,sideMaterial:d})=>{let f=r,p=a;Yn(f)<0&&(f=[...f].reverse(),p=[...p].reverse());const _=t.length,m=f.length;for(const[S,b]of f)t.push([S,b,l]);for(const[S,b]of p)t.push([S,b,h]);const g=S=>_+S,y=S=>_+m+S;e.push({indices:p.map((S,b)=>y(b)),part:u,material:c,kind:"top"}),e.push({indices:f.map((S,b)=>g(m-1-b)),part:u,material:"bottom",kind:"bottom"});for(let S=0;S<m;S+=1){const b=(S+1)%m;e.push({indices:[g(S),g(b),y(b),y(S)],part:u,material:d,kind:"side"})}};for(const[r,a]of[[-15,-9],[9,15]]){const l=we(-20,20,r,a);s({bottom:l,top:l,w0:0,w1:i.trackHeight,part:"track",topMaterial:"trackTop",sideMaterial:"trackSide"})}s({bottom:we(-18,18,-9,9),top:we(-16,14,-7,7),w0:i.hullBase,w1:i.hullTop,part:"hull",topMaterial:"hullTop",sideMaterial:"hullSide"}),s({bottom:pi,top:Va(pi,.6),w0:i.turretBase,w1:i.turretTop,part:"turret",topMaterial:"turretTop",sideMaterial:"turretSide"});const n=we(2.5,21,-2.5,2.5);s({bottom:n,top:n,w0:i.barrelHeight-i.barrelRadius,w1:i.barrelHeight+i.barrelRadius,part:"barrel",topMaterial:"barrel",sideMaterial:"barrel"});const o=we(21,24.5,-3.6,3.6);return s({bottom:o,top:o,w0:i.barrelHeight-i.brakeRadius,w1:i.barrelHeight+i.brakeRadius,part:"barrel",topMaterial:"brake",sideMaterial:"brake"}),{vertices:t,faces:e}}const gi=new Set(["turret","barrel"]);function Na({model:i,size:t,gunRotation:e=0,pitch:s=0,roll:n=0,gunKick:o={x:0,y:0},shift:r={x:0,y:0},squash:a=0}){const l=t/10,h=Math.cos(e),u=Math.sin(e),c=Math.cos(s),d=Math.sin(s),f=Math.cos(n),p=Math.sin(n),_=1-a,m=new Array(i.vertices.length);for(const v of i.faces)for(const M of v.indices)m[M]=v.part;const g=([v,M,w])=>{const C=M*f-w*p,A=M*p+w*f;return[v*c-A*d,C,v*d+A*c]},y=([v,M,w])=>[v*h-M*u,v*u+M*h,w],S=i.vertices.map(([v,M,w],C)=>{let A=[v*l,M*l,w*l*_];const L=m[C];return gi.has(L)&&(A=y(A)),L==="barrel"&&(A=[A[0]+o.x,A[1]+o.y,A[2]]),A=g(A),[A[0]+r.x,A[1]+r.y,A[2]]}),b=i.faces.map(v=>{let M=Ua(i,v,_);return gi.has(v.part)&&(M=y(M)),g(M)});return{points:S,normals:b}}function Ua(i,t,e){return Oa(t.indices.map(s=>{const[n,o,r]=i.vertices[s];return[n,o,r*e]}))}function Ha({x:i,y:t,camera:e,heading:s,shear:n,levelHeight:o,maxLean:r,topHeight:a,gain:l=1}){if(!e)return{x:0,y:0};let h=(i-e.x)*n*l/o,u=(t-e.y)*n*l/o;const c=Math.hypot(h,u)*a;if(c>0&&r>0){const p=r*Math.tanh(c/r)/c;h*=p,u*=p}const d=Math.cos(s),f=Math.sin(s);return{x:h*d+u*f,y:-h*f+u*d}}function Wa({points:i,lean:t,zScale:e=1}){return i.map(([s,n,o])=>[(s+t.x*o)*e,(n+t.y*o)*e])}function Ga({model:i,points:t,projected:e}){const s=[];return i.faces.forEach((n,o)=>{const r=n.indices.map(a=>e[a]);if(Yn(r)>1e-9){let a=0;for(const l of n.indices)a+=t[l][2];s.push({index:o,height:a/n.indices.length,face:n})}}),s.sort((n,o)=>mi[n.face.part]-mi[o.face.part]||n.height-o.height||n.index-o.index),s.map(n=>n.index)}function Ka(i,t,e){const s=Math.cos(t),n=Math.sin(t),o=i[0]*s-i[1]*n,r=i[0]*n+i[1]*s,a=o*e.uLight[0]+r*e.uLight[1]+i[2]*e.uLight[2];return(e.uAmbient+e.uDiffuse*Math.max(a,0))*e.uNorm}const $a={track:"body",hull:"body",turret:"gun",barrel:"gun"},Za={trackSide:"trackSide",barrel:"barrelSide",brake:"brakeSide"};function qa(i,t){const[e,s,n,o]=t.indices.map(r=>i.vertices[r]);return t.indices.length===4&&e[0]===o[0]&&e[1]===o[1]&&s[0]===n[0]&&s[1]===n[1]}function ja(i,t){const{width:e,height:s,regions:n}=t,o=([r,a])=>[r/e,a/s];return i.faces.map(r=>{if(r.kind==="bottom"){const{x:h,y:u,w:c,h:d}=n.bottom;return r.indices.map(()=>o([h+c/2,u+d/2]))}const a=Za[r.material];if(r.kind==="side"&&a&&qa(i,r)){const h=n[a],[u,c]=r.indices.map(_=>i.vertices[_]),d=Math.min(Math.hypot(c[0]-u[0],c[1]-u[1]),h.w),f=h.y,p=h.y+h.h;return[o([h.x,p]),o([h.x+d,p]),o([h.x+d,f]),o([h.x,f])]}const l=n[$a[r.part]];return r.indices.map(h=>{const[u,c]=i.vertices[h];return o([l.originX+u,l.originY+c])})})}const Qa=`#version 300 es
|
|
85
|
+
in vec2 aPosition;
|
|
86
|
+
in vec2 aUv;
|
|
87
|
+
in float aShade;
|
|
88
|
+
|
|
89
|
+
out vec2 vUV;
|
|
90
|
+
out float vShade;
|
|
91
|
+
out vec4 vColor;
|
|
92
|
+
|
|
93
|
+
uniform mat3 uProjectionMatrix;
|
|
94
|
+
uniform mat3 uWorldTransformMatrix;
|
|
95
|
+
uniform vec4 uWorldColorAlpha;
|
|
96
|
+
uniform vec2 uResolution;
|
|
97
|
+
|
|
98
|
+
uniform mat3 uTransformMatrix;
|
|
99
|
+
uniform vec4 uColor;
|
|
100
|
+
uniform float uRound;
|
|
101
|
+
|
|
102
|
+
uniform mat3 uTextureMatrix;
|
|
103
|
+
|
|
104
|
+
void main(void) {
|
|
105
|
+
mat3 mvp = uProjectionMatrix * uWorldTransformMatrix * uTransformMatrix;
|
|
106
|
+
|
|
107
|
+
gl_Position = vec4((mvp * vec3(aPosition, 1.0)).xy, 0.0, 1.0);
|
|
108
|
+
|
|
109
|
+
if (uRound == 1.0) {
|
|
110
|
+
gl_Position.xy =
|
|
111
|
+
(floor(((gl_Position.xy * 0.5 + 0.5) * uResolution) + 0.5) /
|
|
112
|
+
uResolution) * 2.0 - 1.0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
vUV = (uTextureMatrix * vec3(aUv, 1.0)).xy;
|
|
116
|
+
vShade = aShade;
|
|
117
|
+
vColor = uColor * uWorldColorAlpha;
|
|
118
|
+
}
|
|
119
|
+
`,Ja=`#version 300 es
|
|
120
|
+
in vec2 vUV;
|
|
121
|
+
in float vShade;
|
|
122
|
+
in vec4 vColor;
|
|
123
|
+
|
|
124
|
+
out vec4 finalColor;
|
|
125
|
+
|
|
126
|
+
uniform sampler2D uTexture;
|
|
127
|
+
|
|
128
|
+
void main(void) {
|
|
129
|
+
vec4 color = texture(uTexture, vUV);
|
|
130
|
+
|
|
131
|
+
finalColor = vec4(color.rgb * vShade, color.a) * vColor;
|
|
132
|
+
}
|
|
133
|
+
`;let xi=null;function tl(i){return xi||=Ls.from({vertex:Qa,fragment:Ja,name:"tank-model"}),new en({glProgram:xi,resources:{uTexture:i.source,textureUniforms:new $e({uTextureMatrix:{value:i.textureMatrix.mapCoord,type:"mat3x3<f32>"}})}})}function el(i,t){i.resources.uTexture=t.source,i.resources.textureUniforms.uniforms.uTextureMatrix=t.textureMatrix.mapCoord}function sl(i,t){const e=[];let s=0,n=0;for(const f of i.faces)e.push(s),s+=f.indices.length,n+=f.indices.length-2;const o=new Float32Array(s*2),r=new Float32Array(s*2),a=new Float32Array(s).fill(1),l=new Uint32Array(n*3),h=f=>{ja(i,f).forEach((p,_)=>{p.forEach(([m,g],y)=>{r[(e[_]+y)*2]=m,r[(e[_]+y)*2+1]=g})})};h(t);const u=new uo({attributes:{aPosition:{buffer:o,format:"float32x2"},aUv:{buffer:r,format:"float32x2"},aShade:{buffer:a,format:"float32"}},indexBuffer:l}),c=tl(t.texture),d=new sn({geometry:u,shader:c,texture:t.texture});return{mesh:d,setAtlas(f){h(f),u.getBuffer("aUv").update(),el(c,f.texture),d.texture=f.texture},update(f,p,_){i.faces.forEach((g,y)=>{const S=e[y];g.indices.forEach((b,v)=>{o[(S+v)*2]=f[b][0],o[(S+v)*2+1]=f[b][1],a[S+v]=p[y]})});let m=0;for(const g of _){const y=e[g],S=i.faces[g].indices.length;for(let b=1;b<S-1;b+=1)l[m]=y,l[m+1]=y+b,l[m+2]=y+b+1,m+=3}l.fill(0,m),u.getBuffer("aPosition").update(),u.getBuffer("aShade").update(),u.indexBuffer.update()},destroy(){d.destroy(),c.destroy(),u.destroy()}}}function il(i){const t=[...i].sort((o,r)=>o[0]-r[0]||o[1]-r[1]);if(t.length<3)return t;const e=(o,r,a)=>(r[0]-o[0])*(a[1]-o[1])-(r[1]-o[1])*(a[0]-o[0]),s=[],n=[];for(const o of t){for(;s.length>=2&&e(s[s.length-2],s[s.length-1],o)<=0;)s.pop();s.push(o)}for(let o=t.length-1;o>=0;o-=1){const r=t[o];for(;n.length>=2&&e(n[n.length-2],n[n.length-1],r)<=0;)n.pop();n.push(r)}return s.pop(),n.pop(),s.concat(n)}function nl(i,t,e){if(!i)return{x:0,y:0};const s=Math.hypot(i[0],i[1])||1,n=-i[0]/s/t,o=-i[1]/s/t,r=Math.cos(e),a=Math.sin(e);return{x:n*r+o*a,y:-n*a+o*r}}function ol({model:i,points:t,lift:e=0,drift:s}){const n=new Map;for(const r of i.faces){n.has(r.part)||n.set(r.part,new Set);for(const a of r.indices)n.get(r.part).add(a)}const o=[];for(const r of n.values()){const a=[...r].map(l=>{const[h,u,c]=t[l],d=Math.max(0,c+e);return[h+s.x*d,u+s.y*d]});o.push(il(a))}return o}const rl=`#version 300 es
|
|
134
|
+
in vec2 aPosition;
|
|
135
|
+
in vec2 aUV;
|
|
136
|
+
|
|
137
|
+
out vec2 vUV;
|
|
138
|
+
out vec4 vColor;
|
|
139
|
+
|
|
140
|
+
uniform mat3 uProjectionMatrix;
|
|
141
|
+
uniform mat3 uWorldTransformMatrix;
|
|
142
|
+
uniform vec4 uWorldColorAlpha;
|
|
143
|
+
uniform vec2 uResolution;
|
|
144
|
+
|
|
145
|
+
uniform mat3 uTransformMatrix;
|
|
146
|
+
uniform vec4 uColor;
|
|
147
|
+
uniform float uRound;
|
|
148
|
+
|
|
149
|
+
uniform mat3 uTextureMatrix;
|
|
150
|
+
|
|
151
|
+
void main(void) {
|
|
152
|
+
mat3 mvp = uProjectionMatrix * uWorldTransformMatrix * uTransformMatrix;
|
|
153
|
+
|
|
154
|
+
gl_Position = vec4((mvp * vec3(aPosition, 1.0)).xy, 0.0, 1.0);
|
|
155
|
+
|
|
156
|
+
if (uRound == 1.0) {
|
|
157
|
+
gl_Position.xy =
|
|
158
|
+
(floor(((gl_Position.xy * 0.5 + 0.5) * uResolution) + 0.5) /
|
|
159
|
+
uResolution) * 2.0 - 1.0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
vUV = (uTextureMatrix * vec3(aUV, 1.0)).xy;
|
|
163
|
+
// тинт уровня и прозрачность (премультиплицированы, как у меша PixiJS)
|
|
164
|
+
vColor = uColor * uWorldColorAlpha;
|
|
165
|
+
}
|
|
166
|
+
`,al=`#version 300 es
|
|
167
|
+
in vec2 vUV;
|
|
168
|
+
in vec4 vColor;
|
|
169
|
+
|
|
170
|
+
out vec4 finalColor;
|
|
171
|
+
|
|
172
|
+
uniform sampler2D uTexture;
|
|
173
|
+
uniform sampler2D uNormal;
|
|
174
|
+
|
|
175
|
+
uniform vec2 uSpin;
|
|
176
|
+
uniform vec2 uPitch;
|
|
177
|
+
uniform vec2 uRoll;
|
|
178
|
+
uniform vec2 uHeading;
|
|
179
|
+
uniform vec3 uLight;
|
|
180
|
+
uniform float uAmbient;
|
|
181
|
+
uniform float uDiffuse;
|
|
182
|
+
uniform float uNorm;
|
|
183
|
+
|
|
184
|
+
vec2 turn(vec2 v, vec2 cs) {
|
|
185
|
+
return vec2(v.x * cs.x - v.y * cs.y, v.x * cs.y + v.y * cs.x);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
void main(void) {
|
|
189
|
+
vec4 color = texture(uTexture, vUV);
|
|
190
|
+
vec4 encoded = texture(uNormal, vUV);
|
|
191
|
+
vec3 n = vec3(0.0, 0.0, 1.0);
|
|
192
|
+
|
|
193
|
+
// запечённая текстура премультиплицирована: на кромке антиалиасинга
|
|
194
|
+
// нормаль делится на свою альфу, а пустота считается плоской
|
|
195
|
+
if (encoded.a > 0.01) {
|
|
196
|
+
n = normalize(encoded.rgb / encoded.a * 2.0 - 1.0);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
n.xy = turn(n.xy, uSpin);
|
|
200
|
+
// тангаж: нос +u вверх — нормаль к корме
|
|
201
|
+
n = vec3(n.x * uPitch.x - n.z * uPitch.y, n.y, n.x * uPitch.y + n.z * uPitch.x);
|
|
202
|
+
// крен: борт +v вверх — нормаль к борту −v
|
|
203
|
+
n = vec3(n.x, n.y * uRoll.x - n.z * uRoll.y, n.y * uRoll.y + n.z * uRoll.x);
|
|
204
|
+
n.xy = turn(n.xy, uHeading);
|
|
205
|
+
|
|
206
|
+
float light = (uAmbient + uDiffuse * max(dot(n, uLight), 0.0)) * uNorm;
|
|
207
|
+
|
|
208
|
+
finalColor = vec4(color.rgb * light, color.a) * vColor;
|
|
209
|
+
}
|
|
210
|
+
`,De=i=>[Math.cos(i),Math.sin(i)];function On({heading:i,rotation:t,pitch:e,roll:s,lightDir:n,lightZ:o,ambient:r,diffuse:a}){const[l,h]=n||[0,0],u=Math.hypot(l,h,o)||1,c=[l/u,h/u,o/u],d=r+a*Math.max(c[2],0);return{uSpin:De(t),uPitch:De(e),uRoll:De(s),uHeading:De(i),uLight:c,uAmbient:r,uDiffuse:a,uNorm:d?1/d:1}}let yi=null;function ll(i,t){return yi||=Ls.from({vertex:rl,fragment:al,name:"tank-light"}),new en({glProgram:yi,resources:{uTexture:i.source,uNormal:t.source,textureUniforms:new $e({uTextureMatrix:{value:i.textureMatrix.mapCoord,type:"mat3x3<f32>"}}),tankLight:new $e({uSpin:{value:new Float32Array([1,0]),type:"vec2<f32>"},uPitch:{value:new Float32Array([1,0]),type:"vec2<f32>"},uRoll:{value:new Float32Array([1,0]),type:"vec2<f32>"},uHeading:{value:new Float32Array([1,0]),type:"vec2<f32>"},uLight:{value:new Float32Array([0,0,1]),type:"vec3<f32>"},uAmbient:{value:1,type:"f32"},uDiffuse:{value:0,type:"f32"},uNorm:{value:1,type:"f32"}})}})}function hl(i,t,e){i.resources.uTexture=t.source,i.resources.uNormal=e.source,i.resources.textureUniforms.uniforms.uTextureMatrix=t.textureMatrix.mapCoord}function cl(i,t){const e=i.resources.tankLight.uniforms;for(const s of["uSpin","uPitch","uRoll","uHeading","uLight"])e[s].set(t[s]);e.uAmbient=t.uAmbient,e.uDiffuse=t.uDiffuse,e.uNorm=t.uNorm}const ul=-Math.PI/4,fl=.35,dl=.35,_l=.6,pl=.6,ml=i=>1-Math.pow(1-i,3);class gl{constructor(t,e=ln){this._config=e;const s=new Z(t.icon),n=e.size/t.icon.width;s.anchor.set(.5),s.scale.set(n),this._arcs=[],this._view=new G,this._view.zIndex=Co,this._view.visible=!1,this._view.addChild(s);for(let o=0;o<e.arcs;o+=1){const r=new Z(t.arc);r.anchor.set(.5),r.rotation=ul,r.tint=e.color,this._arcs.push({sprite:r,baseScale:e.size/t.arc.width}),this._view.addChild(r)}}get view(){return this._view}update({active:t,x:e,y:s,nowMs:n,sinceMs:o}){const r=this._view;if(!r||(r.visible=t,!t))return;const a=this._config,l=Math.max(0,n-o);r.position.set(e,s-a.offsetY),r.scale.set(ml(Math.min(1,l/a.popIn))),this._arcs.forEach(({sprite:h,baseScale:u},c)=>{const d=(l/a.period+c/a.arcs)%1,f=a.size*(fl+dl*d);h.position.set(f,-f),h.alpha=1-d,h.scale.set(u*(_l+pl*d))})}destroy(){this._view?.destroy({children:!0,texture:!1,textureSource:!1}),this._view=null,this._arcs=[]}}const xl=0,yl=1,Xe=3;let wi=null;const as=()=>(wi||=Ba(bt),wi),wl=()=>On({heading:0,rotation:0,pitch:0,roll:0,lightDir:Rt.lightDir,lightZ:Qt.lightZ,ambient:Qt.ambient,diffuse:Qt.diffuse}),vl=.55,Sl=.6,vi=7,Ml=1,Si=1.15,bl=1.25,kl=.6,Al=1,Tl=.015,Ll=2.5;function Pl(i,t=0){const e=Number.isFinite(i)?i:0,s=St(e,0,1),n=Math.max(0,e-1),o=rt(Ml,Si,s)+(bl-Si)*n,r=rt(kl,Al,s),a=1+Tl*(1-s)*Math.sin(2*Math.PI*Ll*(t/1e3));return{rate:o*a,volumeFactor:r}}function Cl(i=Rt.lightDir,t=Lt.groundOffset){const e=i?Math.hypot(i[0],i[1]):0;return!e||!t?{x:0,y:0}:{x:-i[0]/e*t,y:-i[1]/e*t}}class El extends G{constructor(t,e,s,n){super();const o=()=>{const c=new fo({verticesX:Rt.vertices,verticesY:Rt.vertices});return c.geometry.batchMode="batch",c};this.body=o(),this.gun=o(),this.wreck=o(),this._bodyAnchor={x:.5,y:.5},this._wreckAnchor={x:.5,y:.5},this.addChild(this.body,this.gun,this.wreck),this._lightShaders=new Map,this._textures=e.tankTexture,this._modelAtlases=bt.enabled&&e.tankModelTexture?e.tankModelTexture:null,this._model=null,this._modelShadow=null,this._wreckSkew=0,this._shadowAsset=e.tankShadowTexture||null,this._renderer=s.renderer||null,this._shadow=null,this._voice=s.voice??null,this._radioTextures=e.radioBadgeTexture??null,this._radioBadge=null,this._partId=n?.id,this._worldX=t[kt]||0,this._worldY=t[At]||0,this.x=this._worldX,this.y=this._worldY,this.rotation=t[Dt]||0,this._gunRotation=t[ti]||0,this._engineLoad=t[Bt]||0,this._condition=t[Mt],this._size=t[Ie],this._teamId=t[qe],this._z=t[te]||0,this._physLevel=t[pt]||0,this._vz=t[Ee]||0,this._prevVz=this._vz,this._pitch=t[ei]||0,this._roll=t[si]||0,this._landImpact=0,this._landTimer=0,this._squash=0,this._level=Ce(t[pt],this._z),this.zIndex=H(Xe,this._level),this._isLocal=()=>s.localPlayer?.is(n?.id)===!0,this._recoilElapsed=1/0,this._recoilTilt={pitch:0,roll:0},this._recoilOffsets={body:{x:0,y:0},gun:{x:0,y:0}},this._blastKick=null,this._blastElapsed=0,this._blastTilt={pitch:0,roll:0},this._blastLift=0,this._blastShake={x:0,y:0},this._unsubscribeBlasts=s.blasts?s.blasts.subscribe(c=>this._onBlast(c)):null,this._unsubscribeShots=s.shots&&n?.id!==void 0?s.shots.subscribe(n.id,{fired:()=>this._onFired(),muzzle:()=>this._muzzleWorld()}):null,this._levelView=s.levelView||null,this._levelView?.setDiagnostics(s.diagnostics??null),this._lighting=s.lighting?.enabled?s.lighting:null,this._headlights=null,this._ownLights=null,this._glint=null,this._caster=null,this._lighting&&e.headlightConeTexture&&this._lighting.registerTextures({cone:e.headlightConeTexture}),this.onRender=()=>this._updateView();const r=this._teamId===1?this._textures.liveTeamId1:this._textures.liveTeamId2,a=r?r.gunAnchor:null;this._gunAnchor=a?{x:a.x,y:a.y}:{x:.5,y:.5};const l=10;this._scaleFactor=this._size/l,this._soundManager=s.soundManager,this._soundId=null;const h=this._soundManager.getSoundConfig("tankEngine");this._baseEngineVolume=h?.volume||0,this._hasEngineSound=!!h,this._surfaces=s.surfaces||null,this._waterSoundId=null,this._speed=Math.hypot(t[de]||0,t[_e]||0);const u=this._soundManager.getSoundConfig("tankWater");this._baseWaterVolume=u?.volume||0,this._hasWaterSound=!!u,this.create()}_initSounds(){this._soundId||this._condition===0||!this._hasEngineSound||(this._soundId=this._soundManager.registerSound("tankEngine",this._getSoundData()))}_getSoundData(){const{rate:t,volumeFactor:e}=Pl(this._engineLoad,performance.now());return{position:{x:this._worldX,y:this._worldY},rate:t,volume:this._baseEngineVolume*e,spatial:!this._isLocal()}}create(){if(this._condition===0){this.body.visible=!1,this.gun.visible=!1,this._setTexture(this.wreck,this._textures.destroyed,this._textures.destroyedNormal);const t=this._modelAtlases?.destroyed;t?(this._wreckSkew=(Math.random()*2-1)*Sl,this._showModel(t),this.wreck.visible=!1):(this._model&&(this._model.mesh.visible=!1),this.wreck.visible=!0),this._gunRotation=0,this._resetRecoil(),this.destroySounds(),this._removeLights()}else{this.wreck.visible=!1;let t;this._teamId===1?t=this._textures.liveTeamId1:this._teamId===2&&(t=this._textures.liveTeamId2),this._setTexture(this.body,t.body,t.bodyNormal),this._setTexture(this.gun,t.gun,t.gunNormal);const e=this._modelAtlas();e?this._showModel(e):(this.body.visible=!0,this.gun.visible=!0),this._initSounds(),this._addLights()}this._applyTilt()}update(t){this._worldX=t[kt],this._worldY=t[At],this.rotation=t[Dt],this._gunRotation=t[ti],this._engineLoad=t[Bt]||0,this._speed=Math.hypot(t[de]||0,t[_e]||0),this._z=t[te]||0,this._physLevel=t[pt]||0,this._vz=t[Ee]||0,this._pitch=t[ei]||0,this._roll=t[si]||0;const e=Xn(this._prevVz,this._vz,jt);e>0&&(this._landImpact=e,this._landTimer=jt.duration),this._prevVz=this._vz;const s=Ce(t[pt],this._z);s!==this._level&&(this._level=s,this.zIndex=H(Xe,s)),this._applyTilt(),this._levelView&&this._isLocal()&&this._levelView.set(s,this._worldX,this._worldY,this._z),this._condition>0&&(this._soundId===null?this._initSounds():this._soundManager.updateSoundData(this._soundId,this._getSoundData()));const n=t[Mt],o=t[qe];let r=!1;n!==void 0&&n!==this._condition&&(this._condition=n,r=!0),o!==void 0&&o!==this._teamId&&(this._teamId=o,r=!0),r&&this.create(),this._updateLights(),this._updateWaterSound()}_updateWaterSound(){if(!(this._hasWaterSound&&this._condition>0&&this._vz===0&&this._surfaces?.kindAt(this._worldX,this._worldY,this._physLevel)==="water")){this._removeWaterSound();return}this._waterSoundId===null?this._waterSoundId=this._soundManager.registerSound("tankWater",this._getWaterSoundData()):this._soundManager.updateSoundData(this._waterSoundId,this._getWaterSoundData())}_getWaterSoundData(){const{minVolume:t,fullSpeed:e,rate:s}=Ct.water.sound,n=St(this._speed/e,0,1);return{position:{x:this._worldX,y:this._worldY},rate:rt(s.min,s.max,n),volume:this._baseWaterVolume*(t+(1-t)*n),spatial:!this._isLocal()}}_removeWaterSound(){this._waterSoundId&&(this._soundManager.unregisterSound(this._waterSoundId),this._waterSoundId=null)}_headlightPoints(){const t=Math.cos(this.rotation),e=Math.sin(this.rotation),s=this._size*2,n=this._size*1.5*yt.headlights.offset,o=this._worldX+t*s,r=this._worldY+e*s;return[{x:o+e*n,y:r-t*n},{x:o-e*n,y:r+t*n}]}_addLights(){if(!this._lighting||this._headlights)return;const{headlights:t,tankGlow:e}=yt,s=()=>this._lighting.addLight({kind:"cone",radius:t.length,spread:t.spread,color:t.color,intensity:t.intensity});this._headlights={cones:[s(),s()],glow:this._lighting.addLight({kind:"radial",radius:e.radius,color:e.color,intensity:e.intensity})},this._ownLights=[...this._headlights.cones,this._headlights.glow],this._updateLights()}_updateLights(){if(!this._headlights)return;const t=this._level,e=this._z,s=Sn(this._physLevel,e,this._vz!==0),n=this._headlightPoints();for(let o=0;o<2;o+=1)this._lighting.updateLight(this._headlights.cones[o],{x:n[o].x,y:n[o].y,z:e,level:t,levels:s,rotation:this.rotation});this._lighting.updateLight(this._headlights.glow,{x:this._worldX,y:this._worldY,z:e,level:t,levels:s})}_removeLights(){this._headlights&&(this._lighting.removeLight(this._headlights.cones[0]),this._lighting.removeLight(this._headlights.cones[1]),this._lighting.removeLight(this._headlights.glow),this._headlights=null,this._ownLights=null)}_onFired(){if(this._condition===0)return;const t=qt.attack*qt.duration;this._recoilElapsed=this._recoilElapsed<qt.duration?Math.min(this._recoilElapsed,t):0}_muzzleWorld(){if(this._condition===0||this.destroyed)return null;const t=this.rotation+this._gunRotation,e=this._size*4*vl;return{x:this._worldX+Math.cos(t)*e,y:this._worldY+Math.sin(t)*e}}_resetRecoil(){this._recoilElapsed=1/0,this._recoilTilt.pitch=0,this._recoilTilt.roll=0,this._recoilOffsets.body.x=0,this._recoilOffsets.body.y=0,this._recoilOffsets.gun.x=0,this._recoilOffsets.gun.y=0}_stepRecoil(){if(this._recoilElapsed===1/0)return;this._recoilElapsed+=J.shared.deltaMS;const t=Ia(this._recoilElapsed,qt.duration,qt.attack);if(t===0&&this._recoilElapsed>=qt.duration){this._resetRecoil();return}const e=Ra({amount:t,gunRotation:this._gunRotation,config:qt});this._recoilOffsets.body=e.body,this._recoilOffsets.gun=e.gun,this._recoilTilt.pitch=e.pitch,this._recoilTilt.roll=e.roll}_onBlast(t){if(this.destroyed)return;const e=Ya({x:this._worldX,y:this._worldY,level:this._physLevel,heading:this.rotation,hullLength:this._size*4,blast:t,config:pe});if(!e)return;const s=this._blastKick?_i({elapsed:this._blastElapsed,kick:this._blastKick,config:pe}).envelope:0;e.strength>=s&&(this._blastKick=e,this._blastElapsed=0)}_stepBlast(){if(!this._blastKick)return;const t=this._blastKick.hop&&this._blastElapsed<pe.hopDuration;this._blastElapsed+=J.shared.deltaMS;const e=_i({elapsed:this._blastElapsed,kick:this._blastKick,config:pe});if(t&&this._blastElapsed>=pe.hopDuration&&jt.duration>0&&(this._landImpact=this._blastKick.strength,this._landTimer=jt.duration),e.done){this._resetBlast();return}this._blastTilt.pitch=e.pitch,this._blastTilt.roll=e.roll,this._blastLift=e.lift,this._blastShake.x=e.shakeX,this._blastShake.y=e.shakeY}_resetBlast(){this._blastKick=null,this._blastElapsed=0,this._blastTilt.pitch=0,this._blastTilt.roll=0,this._blastLift=0,this._blastShake.x=0,this._blastShake.y=0}_viewZ(){return this._z+this._blastLift}_applyMeshOffsets(){const t=1+this._viewZ()*N.shear,{body:e,gun:s}=this._recoilOffsets,n=e.x+this._blastShake.x,o=e.y+this._blastShake.y;this.body.position.set(n*t,o*t),this.wreck.position.set(this._blastShake.x*t,this._blastShake.y*t),this.gun.position.set((n+s.x)*t,(o+s.y)*t)}_setTexture(t,e,s){t.texture=e;const n=this._lightShaders.get(t);if(!s){n&&(t.shader=null,n.destroy(),this._lightShaders.delete(t));return}if(n)hl(n,e,s);else{const o=ll(e,s);t.shader=o,this._lightShaders.set(t,o)}}_applyLight(){for(const[t,e]of this._lightShaders)cl(e,On({heading:this.rotation,rotation:t===this.gun?this._gunRotation:0,pitch:this._pitch+this._recoilTilt.pitch+this._blastTilt.pitch,roll:this._roll+this._recoilTilt.roll+this._blastTilt.roll,lightDir:Rt.lightDir,lightZ:Qt.lightZ,ambient:Qt.ambient,diffuse:Qt.diffuse}))}_setCorners(t,e,s,n,o){const{texture:r}=t;t.setCorners(...Ea({width:r.width*n,height:r.height*n*o,anchorX:e.x,anchorY:e.y,rotation:s,heading:this.rotation,pitch:this._pitch+this._recoilTilt.pitch+this._blastTilt.pitch,roll:this._roll+this._recoilTilt.roll+this._blastTilt.roll,shear:N.shear,lift:Rt.lift}))}_groundZ(){return this._vz!==0?this._physLevel:this._z}_applyTilt(){const t=1+this._viewZ()*N.shear,e=this._scaleFactor*t,s=1-this._squash;this._setCorners(this.body,this._bodyAnchor,0,e,s),this._setCorners(this.gun,this._gunAnchor,this._gunRotation,e,s),this._setCorners(this.wreck,this._wreckAnchor,0,e,s)}_updateView(){this._levelView&&this._levelView.attachStage(this.parent,this._renderer);const t=this._levelView?this._levelView.camera():ut(this.parent,this._renderer);this._lighting&&(this._lighting.attachStage(this.parent,this._renderer),this._lighting.render());let e=16777215;this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._worldX,this._worldY,this._z),e=this._levelView.tintFor(this._level),this.tint=e),this._stepBlast();const s=mt(this._worldX,this._worldY,t,this._viewZ()*N.shear);if(this.position.set(s.x,s.y),this._lightShaders.size===0&&!this._model?.mesh.visible){const n=St(za({angle:this.rotation,pitch:this._pitch,roll:this._roll,lightDir:Rt.lightDir,shading:Rt.shading}),xl,yl);this.tint=Jt(e,n)}if(this._landTimer>0){this._landTimer=Math.max(0,this._landTimer-J.shared.deltaMS);const n=this._landTimer/jt.duration;this._squash=Math.sin(n*Math.PI)*jt.squash*this._landImpact}else this._squash=0;this._stepRecoil(),this._applyMeshOffsets(),this._applyTilt(),this._applyLight(),this._applyModel(t),this._updateShadow(t),this._updateGlint(),this._updateCaster(),this._updateRadioBadge(s)}_updateRadioBadge(t){const e=this._condition!==0&&this._voice?.isTalking(this._partId)===!0;if(!(!e&&!this._radioBadge)){if(!this._radioBadge){if(!this._radioTextures||!this.parent)return;this._radioBadge=new gl(this._radioTextures,ln),this.parent.addChild(this._radioBadge.view)}this._radioBadge.update({active:e,x:t.x,y:t.y,nowMs:performance.now(),sinceMs:this._voice?.talkingSince(this._partId)??0})}}_updateGlint(){const t=1+this._viewZ()*N.shear,e=zn(this._lighting,{x:this._worldX,y:this._worldY,z:this._viewZ(),level:this._level,reach:this._size*2*t,exclude:this._ownLights});if(!e){Rn(this._glint);return}const s=this._lighting.texture("glint");this._glint=In(this._glint,this,s.texture);const{sprite:n,mask:o}=this._glint,r=this._condition===0,a=r?this.wreck:this.body,l=r?this._wreckAnchor:this._bodyAnchor,h=this._scaleFactor*t;this.children.at(-1)!==n&&this.addChild(n),o.texture=a.texture,o.anchor.set(l.x,l.y),o.position.copyFrom(a.position),o.scale.set(h,h*(1-this._squash)),Fn(this._glint,{hit:e,asset:s,x:a.position.x,y:a.position.y,rotation:e.angle-this.rotation,size:Math.max(a.texture.width,a.texture.height)*h})}_updateCaster(){if(this._lighting){if(!this._lighting.castsShadows()){this._caster&&(this._lighting.setCaster(this,null),this._caster=null);return}this._caster||(this._caster={},this._lighting.setCaster(this,this._caster)),this._caster.x=this._worldX,this._caster.y=this._worldY,this._caster.z=this._z,this._caster.level=this._level,this._caster.radius=this._size*2}}_modelAtlas(){return this._modelAtlases?this._teamId===2?this._modelAtlases.liveTeamId2:this._modelAtlases.liveTeamId1:null}_showModel(t){this._model?this._model.setAtlas(t):(this._model=sl(as(),t),this.addChild(this._model.mesh)),this._model.mesh.visible=!0,this.body.visible=!1,this.gun.visible=!1}_applyModel(t){if(!this._model||!this._model.mesh.visible)return;const e=as(),s=Na({model:e,size:this._size,gunRotation:this._condition===0?this._wreckSkew:this._gunRotation,pitch:this._pitch+this._recoilTilt.pitch+this._blastTilt.pitch,roll:this._roll+this._recoilTilt.roll+this._blastTilt.roll,gunKick:this._recoilOffsets.gun,shift:{x:this._recoilOffsets.body.x+this._blastShake.x,y:this._recoilOffsets.body.y+this._blastShake.y},squash:this._squash}),n=Ha({x:this._worldX,y:this._worldY,camera:t,heading:this.rotation,shear:N.shear,levelHeight:bt.levelHeight,maxLean:bt.maxLean,gain:bt.leanGain,topHeight:bt.turretTop*this._size/10}),o=Wa({points:s.points,lean:n,zScale:1+this._viewZ()*N.shear});this._modelPose=s;const r=Ga({model:e,points:s.points,projected:o}),a=wl(),l=s.normals.map(h=>Ka(h,this.rotation,a));this._model.update(o,l,r)}_modelShadowActive(){return this._condition!==0&&this._model!==null&&this._model.mesh.visible&&this._modelPose!==void 0&&this.parent!==null}_updateModelShadow(t){if(!this._modelShadow){const h=new V;this._modelShadowAlpha=new nn({alpha:1}),h.filters=bt.shadowBlur?[new Ps({strength:bt.shadowBlur,quality:2}),this._modelShadowAlpha]:[this._modelShadowAlpha],this.parent.addChild(h),this._modelShadow=h}const e=this._modelShadow,s=this._groundZ(),n=mt(this._worldX,this._worldY,t,s*N.shear),o=Math.max(0,this._viewZ()-s);e.visible=!0,e.position.set(n.x,n.y),e.rotation=this.rotation,e.scale.set(1+s*N.shear),e.zIndex=H(Xe-1,Math.min(vi,Math.floor(s)));const r=ol({model:as(),points:this._modelPose.points,lift:o*bt.levelHeight,drift:nl(Rt.lightDir,Qt.lightZ,this.rotation)});e.clear();for(const h of r)e.poly(h.flat()).fill(0);const l=this._vz!==0||this._blastLift>0?Math.max(0,Lt.baseAlpha-o*Lt.alphaFalloff):Lt.groundAlpha;this._modelShadowAlpha.alpha=l*this.alpha}_updateShadow(t){if(this._modelShadowActive()){this._shadow&&(this._shadow.visible=!1),this._updateModelShadow(t);return}if(this._modelShadow&&(this._modelShadow.visible=!1),!this._shadowAsset||!this.parent)return;const e=this._vz!==0;if(!(this._condition!==0&&(e||Lt.groundOffset>0))){this._shadow&&(this._shadow.visible=!1);return}if(!this._shadow){const{texture:u,contentSize:c}=this._shadowAsset;this._shadow=new Z(u),this._shadow.anchor.set(.5),this._shadowScale=this._size*4*Lt.sizeFactor/c,this.parent.addChild(this._shadow)}const n=this._shadow;n.visible=!0;const o=this._groundZ(),r=mt(this._worldX,this._worldY,t,o*N.shear),a=Cl();n.x=r.x+a.x,n.y=r.y+a.y,n.rotation=this.rotation;const l=Math.max(0,this._z-o);n.scale.set(this._shadowScale*(1+l*Lt.scaleGain));const h=e?Math.max(0,Lt.baseAlpha-l*Lt.alphaFalloff):Lt.groundAlpha;n.alpha=h*this.alpha,n.zIndex=H(Xe-1,Math.min(vi,Math.floor(o)))}destroySounds(){this._soundId&&(this._soundManager.unregisterSound(this._soundId),this._soundId=null),this._removeWaterSound()}destroy(t){this.destroySounds(),this._removeLights(),this._lighting?.setCaster(this,null),this._glint=null,this._shadow&&(this._shadow.destroy({texture:!1,textureSource:!1}),this._shadow=null),this._radioBadge?.destroy(),this._radioBadge=null,this._modelShadow&&(this._modelShadow.destroy(),this._modelShadow=null),this._unsubscribeShots&&(this._unsubscribeShots(),this._unsubscribeShots=null),this._unsubscribeBlasts&&(this._unsubscribeBlasts(),this._unsubscribeBlasts=null),this._model&&(this._model.destroy(),this._model=null);for(const e of this._lightShaders.values())e.destroy();this._lightShaders.clear(),super.destroy({children:!0,texture:!1,textureSource:!1,...t})}}const zl=2;class Il extends G{constructor(t,e,s){super(),this._level=t[ua]||0,this.zIndex=H(zl,this._level),this._levelView=s.levelView||null,this._renderer=s.renderer||null,(this._levelView||this._renderer)&&(this.onRender=()=>{this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._worldX,this._worldY),this.tint=this._levelView.tintFor(this._level)),this._applyHeight()}),this.body=new Z(e.bombTexture),this.body.anchor.set(.5),this._worldX=t[oi],this._worldY=t[ri],this.x=this._worldX,this.y=this._worldY,this.rotation=t[ai],this._size=t[ha],this._totalDurationMs=t[ca],this._soundManager=s.soundManager,this._soundId=null;const n=e.bombTexture.width,o=this._size/n;this.body.scale.set(o);const r=64,a=this._size/1.2/r;this.text=new tn({style:{fontFamily:"Arial",fontSize:r,fill:16777215,align:"center"}}),this.text.anchor.set(.5),this.text.scale.set(a),this.text.x=0,this.text.y=0,this._accumulatedTimeMs=0,this._secondsLeft="",this.addChild(this.body,this.text),this._updateTimerDisplay(this._totalDurationMs),this._tickListener=l=>this._updateTimer(l.deltaMS),J.shared.add(this._tickListener),this._soundId=this._soundManager.registerSound("bombHasBeenPlanted",{position:{x:this.x,y:this.y}})}_updateTimer(t){this._accumulatedTimeMs+=t;const e=Math.max(0,this._totalDurationMs-this._accumulatedTimeMs);this._updateTimerDisplay(e),e<=0&&(this._stopTimer(),this._updateTimerDisplay(0))}_updateTimerDisplay(t){const e=Math.round(t/1e3);this._secondsLeft!==e&&(this._secondsLeft=e,this.text.text=`${this._secondsLeft}`)}update(t){this._worldX=t[oi],this._worldY=t[ri],this.x=this._worldX,this.y=this._worldY,this.rotation=t[ai],this._soundId&&(this._soundManager.updateSoundData(this._soundId,{position:{x:this._worldX,y:this._worldY}})||(this._soundId=null))}_applyHeight(){const t=this._level*N.shear,e=ut(this.parent,this._renderer),s=mt(this._worldX,this._worldY,e,t);this.position.set(s.x,s.y),this.scale.set(1+t)}_stopTimer(){this._tickListener&&(J.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer(),this._soundId&&(this._soundManager.releaseSound(this._soundId),this._soundId=null),super.destroy({children:!0,texture:!1,textureSource:!1,...t}),this.body=null,this.text=null}}class Rl extends Nt{constructor(t,e,s,n,o){super(n);const{texture:r,contentSize:a}=o.explosionTexture;this.x=t,this.y=e,this._radius=s,this._durationMs=1500,this._elapsedMs=0,this._baseScale=this._radius*2/a,this._mainBody=new Z(r),this._mainBody.anchor.set(.5),this._mainBody.tint=11393254,this._mainBody.scale.set(this._baseScale),this._core=new Z(r),this._core.anchor.set(.5),this._core.tint=13882323,this._core.scale.set(this._baseScale),this.addChild(this._mainBody,this._core)}_update(t){if(!this.isComplete)if(this._elapsedMs+=t,this._elapsedMs<=this._durationMs){const e=this._elapsedMs/this._durationMs;this._draw(e)}else this._completeEffect()}_draw(t){const e=n=>n*n;this._mainBody.alpha=.6*(1-e(t));const s=Math.min(1,t*1.5);this._core.alpha=.7-s,this._core.scale.set(this._baseScale*(1-s))}destroy(t){super.destroy(t)}}const ls=[],vt={get(i){if(ls.length>0){const t=ls.pop();return t.texture=i,t.alpha=1,t.scaleX=1,t.scaleY=1,t.rotation=0,t.tint=16777215,t.anchorX=.5,t.anchorY=.5,t}return new _o({texture:i,anchorX:.5,anchorY:.5})},release(i){i&&ls.push(i)}},Ss=50,Fl=400,Dl=800;class Xl extends Nt{constructor(t,e=Ss){super();const s=e/Ss;this._blastScale=s;const{texture:n,contentSize:o}=t.explosionTexture;this.explosionTexture=n,this._unitScale=1/o;const r=Fl*s,a=Dl*s;this._particleContainer=new ts({texture:this.explosionTexture,boundsArea:new nt(-r/2,-a/2,r,a),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.addChild(this._particleContainer),this._particles=[],this._isSpawning=!0,this._particleSpawnRateMs=50,this._particleMaxLifeMs=2e3,this._minStartSize=2.1*s,this._maxStartSize=5.2*s,this._minTargetSize=8.3*s,this._maxTargetSize=16.6*s,this._startAlpha=.1,this._initialOffsetX=15*s,this._initialOffsetY=15*s,this._lastSpawnTime=0;for(let l=0;l<30;l+=1)this._createParticle()}stopSpawning(){this._isSpawning=!1}_createParticle(){const t=vt.get(this.explosionTexture),e=.2+Math.random()*.4,s=Math.floor(e*255);t.tint=s<<16|s<<8|s;const n=(this._minStartSize+Math.random()*(this._maxStartSize-this._minStartSize))*this._unitScale,o=.6+Math.random()*.8,r=.6+Math.random()*.8;t.scaleX=n*o,t.scaleY=n*r,t.alpha=this._startAlpha+Math.random()*.1,t.rotation=Math.random()*Math.PI*2,t.x=(Math.random()-.5)*this._initialOffsetX,t.y=(Math.random()-.5)*this._initialOffsetY;const a={view:t,life:0,maxLife:this._particleMaxLifeMs*(.7+Math.random()*.6),aspectRatioX:o,aspectRatioY:r,vx:(Math.random()-.5)*.2*this._blastScale,vy:(-.3-Math.random()*.4)*this._blastScale,swaySpeed:.002+Math.random()*.003,swayAmp:(.025+Math.random()*.05)*this._blastScale,swayOffset:Math.random()*100,rotationSpeed:(Math.random()-.5)*.05,targetScale:(this._minTargetSize+Math.random()*(this._maxTargetSize-this._minTargetSize))*this._unitScale,startScale:n};this._particleContainer.addParticle(t),this._particles.push(a)}_update(t){if(!this.isComplete){if(t=Math.min(t,100),this._isSpawning)for(this._lastSpawnTime+=t;this._lastSpawnTime>this._particleSpawnRateMs;)this._createParticle(),this._lastSpawnTime-=this._particleSpawnRateMs;for(let e=this._particles.length-1;e>=0;e-=1){const s=this._particles[e],n=s.view;if(s.life+=t,s.life>=s.maxLife)this._particleContainer.removeParticle(n),vt.release(n),this._particles.splice(e,1);else{const o=s.life/s.maxLife;s.vy*=.98,s.vx*=.95;const r=Math.sin(s.life*s.swaySpeed+s.swayOffset)*s.swayAmp;n.x+=(s.vx+r)*(t/16),n.y+=s.vy*(t/16),n.rotation+=s.rotationSpeed*(t/16);const a=1-Math.pow(1-o,3),l=s.startScale+(s.targetScale-s.startScale)*a;if(n.scaleX=l*s.aspectRatioX,n.scaleY=l*s.aspectRatioY,o<.1)n.alpha=o/.1*this._startAlpha;else if(o>.4){const h=(o-.4)/.6;n.alpha=this._startAlpha*(1-h)}else n.alpha=this._startAlpha}}!this._isSpawning&&this._particles.length===0&&this._isStarted&&(this._completeEffect(),this.destroyed||this.destroy())}}destroy(t){for(let e=0;e<this._particles.length;e+=1)vt.release(this._particles[e].view);this._particles=[],super.destroy(t)}}const Yl=.168,Ol=.225,Mi=.15,Vl=2e4,Bl=50,Nl=4e3,Ul=4e3;class Hl extends Nt{constructor(t,e,s,n,o){super(n),this._assets=o,this._radius=s,this.x=t,this.y=e,this._funnelDurationMs=Vl,this._funnelFadeInDurationMs=Bl,this._funnelFadeDurationMs=Nl,this._elapsedMs=0,this._smokeDurationMs=Ul,this._smokeSpawningStopped=!1,this._funnel=this._createFunnelSprite(),this._smoke=new Xl(this._assets,this._radius),this.addChild(this._funnel,this._smoke)}_createFunnelSprite(){const{textures:t,contentSize:e}=this._assets.funnelTexture,s=t[Math.floor(Math.random()*t.length)],n=new Z(s);n.anchor.set(.5),n.alpha=0,n.rotation=Math.random()*Math.PI*2;const o=this._radius*Yl*F(1-Mi,1+Mi);return n.scale.set(o/e),n}_onEffectStart(){super._onEffectStart(),this._smoke&&this._smoke.run()}_update(t){if(this.isComplete)return;this._elapsedMs+=t,!this._smokeSpawningStopped&&this._elapsedMs>=this._smokeDurationMs&&(this._smoke.stopSpawning(),this._smokeSpawningStopped=!0);const e=this._funnelDurationMs-this._elapsedMs,s=this._funnelFadeInDurationMs>0?this._elapsedMs/this._funnelFadeInDurationMs:1,n=e/this._funnelFadeDurationMs;this._funnel.alpha=Ol*St(Math.min(s,n),0,1),e<=0&&this._completeEffect()}destroy(t){this._smoke&&(this._smoke.destroy(),this._smoke=null),this._funnel=null,super.destroy(t)}}const Wl=4,Gl=2;class Kl extends G{constructor(t,e,s){super(),this.originX=t[fa],this.originY=t[da],this.radius=t[_a]??Ss,this._level=t[pa]||0,this._assets=e,this._soundManager=s.soundManager,this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._lighting=s.lighting||null,s.blasts?.exploded({x:this.originX,y:this.originY,radius:this.radius,level:this._level}),(this._levelView||this._renderer)&&(this.onRender=()=>{this._levelView&&this._updateSeeThrough(),this._applyHeight()}),this.x=this.originX,this.y=this.originY,this.explosion=null,this.funnel=null,this._isStarted=!1,this._isDestroyed=!1,this._soundId=this._soundManager.registerSound("explosion",{position:{x:this.originX,y:this.originY}})}_updateSeeThrough(){const t=this._levelView.alphaFor(this._level,this.originX,this.originY),e=this._levelView.tintFor(this._level);this.explosion&&(this.explosion.alpha=t,this.explosion.tint=e),this.funnel&&(this.funnel.alpha=t,this.funnel.tint=e)}_applyHeight(){const t=this._level*N.shear,e=ut(this.parent,this._renderer),s=mt(this.originX,this.originY,e,t);for(const n of[this.explosion,this.funnel])n&&(n.position.set(s.x,s.y),n.scale.set(1+t))}run(){if(!(this._isDestroyed||this._isStarted)){if(this._isStarted=!0,!this.parent){this.destroy();return}this._lighting?.flash({...yt.flash.explosion,level:this._level,x:this.originX,y:this.originY,z:this._level}),this.explosion=new Rl(this.originX,this.originY,this.radius,this._onExplosionComplete.bind(this),this._assets),this.explosion.zIndex=H(Wl,this._level),this.funnel=new Hl(this.originX,this.originY,this.radius,this._onFunnelComplete.bind(this),this._assets),this.funnel.zIndex=H(Gl,this._level),this.parent.addChild(this.explosion,this.funnel),this.parent.sortChildren(),this.explosion.run(),this.funnel.run()}}_onExplosionComplete(){this._isDestroyed||this.explosion&&(this.explosion.destroy(),this.explosion=null)}_onFunnelComplete(){this._isDestroyed||this.destroy()}destroy(){this._isDestroyed||(this._isDestroyed=!0,this._soundId&&(this._soundManager.unregisterSound(this._soundId),this._soundId=null),this.explosion&&(this.explosion.destroy(),this.explosion=null),this.funnel&&(this.funnel.destroy(),this.funnel=null),this.parent&&this.parent.removeChild(this),super.destroy({children:!0}))}}const bi=4,ie=400,$l=0,Zl=0,ql=8,it={particleLifetime:{min:800,max:1800},particleStartSizeFactor:{1:2,2:1},particleEndSizeFactor:{1:3,2:2},particleStartAlpha:.08,particleEndAlpha:0,particleColor:3355443,particleSpawnRate:{1:60,2:50},particleInitialVelocity:{away:{min:-10,max:100},side:{min:-30,max:30}},airResistance:.92,particleVelocityVariance:10,streamOffsetFactor:.1,burstParticleCount:3,exhaust:{spawnRate:45,idleSpawnRate:4,minLoad:.05,startSizeFactor:.6,endSizeFactor:1.6,startAlpha:.05,color:5592405,lifetime:{min:350,max:750}}};class jl extends G{constructor(t,e,s={}){super(),this._level=t[pt]||0,this.zIndex=H(bi,this._level);const{texture:n,contentSize:o}=e.smokeTexture;this._smokeTexture=n,this._textureScale=ql/o,this._emitterX=t[kt],this._emitterY=t[At],this._emitterRotation=t[Dt],this._emitterVX=t[de],this._emitterVY=t[_e],this._engineLoad=t[Bt],this._condition=t[Mt],this._z=t[te]||0,this._size=t[Ie],this._width=this._size*4,this._height=this._size*3,this._particleScaleMultiplier=Math.max(.5,Math.sqrt(this._width*this._height*.001)),this._particles=[],this._levelView=s.levelView||null,this._renderer=s.renderer||null,(this._levelView||this._renderer)&&(this.onRender=()=>{this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._emitterX,this._emitterY,this._z),this.tint=this._levelView.tintFor(this._level)),gt(this,ut(this.parent,this._renderer),this._z*N.shear,1)}),this._particleContainer=new ts({texture:this._smokeTexture,boundsArea:new nt(this._emitterX-ie,this._emitterY-ie,ie*2,ie*2),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.addChild(this._particleContainer),this._timeSinceLastSpawn=0,this._timeSinceExhaust=0,this._tickListener=r=>this._updateParticles(r.deltaMS),J.shared.add(this._tickListener)}update(t){const e=this._condition,s=t[pt]||0;s!==this._level&&(this._level=s,this.zIndex=H(bi,s)),this._emitterX=t[kt],this._emitterY=t[At],this._emitterRotation=t[Dt],this._emitterVX=t[de],this._emitterVY=t[_e],this._engineLoad=t[Bt],this._condition=t[Mt],this._z=t[te]||0,this._particleContainer.boundsArea.x=this._emitterX-ie,this._particleContainer.boundsArea.y=this._emitterY-ie,this._condition!==e&&(this._condition===1||this._condition===2)&&this._triggerSmokeBurst()}_triggerSmokeBurst(){let t=0;if(this._condition===1?t=2:this._condition===2&&(t=1),t>0){const e=it.burstParticleCount,s=Math.ceil(e/t);for(let n=0;n<s;n+=1)for(let o=0;o<t;o+=1)this.spawnParticle(o,t,"burst")}}_updateParticles(t){if(t<=0)return;const e=t/1e3;this._timeSinceLastSpawn+=t,this._timeSinceExhaust+=t;let s=0;this._condition===3?s=0:this._condition===1?s=2:this._condition===2&&(s=1);const n=it.particleSpawnRate[this._condition]||0,o=n>0?1e3/n:1/0;if(s>0&&n>0)for(;this._timeSinceLastSpawn>=o;){for(let u=0;u<s;u+=1)this.spawnParticle(u,s);this._timeSinceLastSpawn-=o}else this._timeSinceLastSpawn=0;const r=Math.min(this._engineLoad,1),a=this._condition>0&&r>=it.exhaust.minLoad?rt(it.exhaust.idleSpawnRate,it.exhaust.spawnRate,r):0;if(a>0){const u=1e3/a;for(;this._timeSinceExhaust>=u;)this.spawnParticle(0,1,"exhaust"),this._timeSinceExhaust-=u}else this._timeSinceExhaust=0;const h=1-Math.pow(it.airResistance,t/16);for(let u=this._particles.length-1;u>=0;u-=1){const c=this._particles[u];if(c.age+=t,c.age>=c.lifetime){this._particleContainer.removeParticle(c.view),vt.release(c.view),this._particles.splice(u,1);continue}c.vx=c.vx+($l-c.vx)*h,c.vy=c.vy+(Zl-c.vy)*h,c.x+=c.vx*e,c.y+=c.vy*e;const d=c.age/c.lifetime,f=1-(1-d)*(1-d),p=rt(c.startSizeFactor,c.endSizeFactor,f),_=rt(c.startAlpha,c.endAlpha,d),m=p*this._particleScaleMultiplier*this._textureScale,g=c.view;g.x=c.x,g.y=c.y,g.scaleX=m,g.scaleY=m,g.alpha=_,g.rotation+=c.rotSpeed*e}}spawnParticle(t,e,s="damage"){const n=s==="burst",o=s==="exhaust",r=it.exhaust,a=o?F(r.lifetime.min,r.lifetime.max):F(it.particleLifetime.min,it.particleLifetime.max);let l=o?r.startSizeFactor:it.particleStartSizeFactor[this._condition]||.3,h=o?r.endSizeFactor:it.particleEndSizeFactor[this._condition]||1,u=o?r.startAlpha:it.particleStartAlpha,c=1;n&&(l*=2,h*=2.5,u=.8,c=2);const d=this._emitterRotation,f=d+Math.PI,p=Math.cos(f),_=Math.sin(f),m=d+Math.PI/2,g=Math.cos(m),y=Math.sin(m);let S=0;const b=this._width/2*it.streamOffsetFactor;e===2?S=t===0?-b:b:e===3&&(S=(t-1)*b);const v=this._height*.22,M=this._emitterX+p*v+g*S,w=this._emitterY+_*v+y*S;let C=F(it.particleInitialVelocity.away.min,it.particleInitialVelocity.away.max),A=F(it.particleInitialVelocity.side.min,it.particleInitialVelocity.side.max);C*=c,A*=c;let L=p*C+g*A,R=_*C+y*A;const Y=it.particleVelocityVariance;L+=F(-Y,Y),R+=F(-Y,Y),L+=this._emitterVX,R+=this._emitterVY;const I=vt.get(this._smokeTexture);I.tint=o?r.color:it.particleColor,I.x=M,I.y=w,I.alpha=u;const D=l*this._particleScaleMultiplier*this._textureScale;I.scaleX=D,I.scaleY=D,I.rotation=F(0,Math.PI*2);const X={view:I,x:M,y:w,vx:L,vy:R,age:0,lifetime:a,startSizeFactor:l,endSizeFactor:h,startAlpha:u,endAlpha:it.particleEndAlpha,rotSpeed:F(-1,1)};this._particleContainer.addParticle(I),this._particles.push(X)}_stopTimer(){this._tickListener&&(J.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer();for(let e=0;e<this._particles.length;e+=1)vt.release(this._particles[e].view);this._particles=[],super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}class Ql extends Z{constructor(t,e,s,n,o,r,a,l=1){super(a),this.anchor.set(.5),this.x=t,this.y=e,this.rotation=s,this.width=o,this.height=n,this.alpha=r,this._initialAlpha=r,this._elapsedTime=0,this._fadeDuration=(1800+Math.random()*700)*l}update(t){this._elapsedTime+=t;const e=Math.min(this._elapsedTime/this._fadeDuration,1);return this.alpha=(1-e)*this._initialAlpha,e>=1}}const hs=1;class Jl extends G{constructor(t,e,s={}){super(),this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._surfaces=s.surfaces||null,this._level=t[pt]||0,this._markLayers=new Map,this.zIndex=H(hs,this._level),this._currentX=t[kt]||0,this._currentY=t[At]||0,this._currentRotation=t[Dt]||0,this._engineLoad=t[Bt]||0,this._condition=t[Mt],this._size=t[Ie],this._prevX=this._currentX,this._prevY=this._currentY,this._prevRotation=this._currentRotation,this._prevSpeed=0,this._prevAngularSpeed=0,this._assets=e,this._trackMarkCooldown=2,this._lastTrackMarkTime=0,this._minAbsAccelerationForMark=4,this._minAngularSpeedForMark=.02,this._minRotationAccelerationForMark=.4,this._minSpeedForRotationMarks=1.4,this._trackWidth=this._size*.4,this._trackLength=this._size*.5;const n=this._size*3;this._trackOffset=n/2*.7,this._backwardOffset=n*.4,this._trackInitialAlpha=.4,this._trailKind=null,this._trailLeft=0,this._tickListener=o=>this._internalUpdate(o.deltaMS),J.shared.add(this._tickListener),this._levelView&&(this.onRender=()=>this._updateLayers())}update(t){this._currentX=t[kt],this._currentY=t[At],this._currentRotation=t[Dt],this._engineLoad=t[Bt],this._condition=t[Mt];const e=t[pt]||0;e!==this._level&&(this._level=e,this.zIndex=H(hs,e))}_markLayer(t){let e=this._markLayers.get(t);if(e)return e;e=new G,e.zIndex=H(hs,t),this._markLayers.set(t,e);const s=this.parent||this;return s.addChild(e),s.sortChildren(),e}_internalUpdate(t){if(t<=0)return;for(const f of this._markLayers.values())for(let p=f.children.length-1;p>=0;p-=1){const _=f.children[p];_.update(t)&&_.destroy()}this._stepTrail(t/1e3);const e=this._currentX-this._prevX,s=this._currentY-this._prevY,n=Math.sqrt(e*e+s*s),o=jr(this._currentRotation-this._prevRotation),r=Math.abs(o),a=n-this._prevSpeed,l=Math.abs(a),h=r-this._prevAngularSpeed,u=Math.abs(h),c=performance.now();let d=!1;this._condition!==0&&c-this._lastTrackMarkTime>this._trackMarkCooldown&&(l>this._minAbsAccelerationForMark&&(d=!0),n>this._minSpeedForRotationMarks&&(r>this._minAngularSpeedForMark||u>this._minRotationAccelerationForMark)&&(d=!0)),this._engineLoad>1&&(d=!0),d&&(this.createTrackMarksAtPreviousPosition(),this._lastTrackMarkTime=c),this._prevX=this._currentX,this._prevY=this._currentY,this._prevRotation=this._currentRotation,this._prevSpeed=n,this._prevAngularSpeed=r}_stepTrail(t){if(!this._surfaces)return;const e=this._surfaces.kindAt(this._currentX,this._currentY,this._level),s=e&&Ct.tracks[e]?.trail;s?(this._trailKind=e,this._trailLeft=s):this._trailLeft>0&&(this._trailLeft=Math.max(0,this._trailLeft-t))}createTrackMarksAtPreviousPosition(){const t=this._surfaces?this._surfaces.kindAt(this._prevX,this._prevY,this._level):null;if(t&&Ct.tracks.noMarks.includes(t))return;let e=t&&Ct.tracks[t]||null,s=1;!e&&this._trailLeft>0&&(e=Ct.tracks[this._trailKind],s=this._trailLeft/e.trail);const n=this._markLayer(this._level);for(let o=-1;o<=1;o+=2){const r=Math.cos(this._prevRotation+Math.PI/2)*this._trackOffset*o,a=Math.sin(this._prevRotation+Math.PI/2)*this._trackOffset*o,l=-Math.cos(this._prevRotation)*this._backwardOffset,h=-Math.sin(this._prevRotation)*this._backwardOffset,u=this._prevX+r+l,c=this._prevY+a+h,d=new Ql(u,c,this._prevRotation,this._trackWidth,this._trackLength,Math.min(1,this._trackInitialAlpha*(e?e.alpha:1))*s,this._assets.trackMarkTexture,e?e.lifetime:1);e&&(d.tint=e.tint),n.addChild(d)}}_updateLayers(){if(!this._markLayers.size)return;const t=ut(this.parent,this._renderer);for(const[e,s]of this._markLayers)s.alpha=this._levelView.alphaFor(e,this._currentX,this._currentY),s.tint=this._levelView.tintFor(e),e&>(s,t,e*N.shear)}_stopTimer(){this._tickListener&&(J.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer();for(const e of this._markLayers.values())e.destroyed||e.destroy({children:!0});this._markLayers.clear(),super.destroy({children:!0,texture:!1,textureSource:!1,...t})}}const ki=2,ne=300,th=6,st={lifetime:{min:300,max:700},startSizeFactor:.7,endSizeFactor:2,startAlpha:.35,endAlpha:0,color:10260343,airResistance:.86,spawnRate:30,maxSpinSpeed:8,spinVelocity:{back:{min:20,max:70},side:{min:-25,max:25}},landingBurst:14,landingVelocity:{min:40,max:110},landingSizeFactor:1.6},eh={color:st.color,alpha:st.startAlpha,lifetime:st.lifetime},sh=["sand","mud","water"],Ai=.35,ih=(i,t)=>i.kind==="boost"&&i.dir!==null&&i.dir[0]===t[0]&&i.dir[1]===t[1];class nh extends G{constructor(t,e,s={}){super(),this._level=t[pt]||0,this.zIndex=H(ki,this._level);const{texture:n,contentSize:o}=e.dustTexture;this._dustTexture=n,this._textureScale=th/o,this._x=t[kt],this._y=t[At],this._rotation=t[Dt],this._vx=t[de]||0,this._vy=t[_e]||0,this._engineLoad=t[Bt]||0,this._condition=t[Mt],this._z=t[te]||0,this._vz=t[Ee]||0,this._prevVz=this._vz,this._size=t[Ie];const r=this._size*3;this._trackOffset=r/2*.7,this._backwardOffset=r*.4,this._particleScaleMultiplier=Math.max(.5,Math.sqrt(this._size*4*r*.001)),this._particles=[],this._timeSinceSpawn=0,this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._soundManager=s.soundManager||null,this._surfaces=s.surfaces||null,this._surfaceKind=null,this._surfaceCell=null,this._timeSinceSurfaceSpawn=0;const a=this._soundManager?.getSoundConfig("tankLanding");this._landingVolume=a?.volume||0,this._hasLandingSound=!!a,(this._levelView||this._renderer)&&(this.onRender=()=>{this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._x,this._y,this._z),this.tint=this._levelView.tintFor(this._level)),gt(this,ut(this.parent,this._renderer),this._z*N.shear,1)}),this._particleContainer=new ts({texture:this._dustTexture,boundsArea:new nt(this._x-ne,this._y-ne,ne*2,ne*2),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.addChild(this._particleContainer),this._tickListener=l=>this._updateParticles(l.deltaMS),J.shared.add(this._tickListener)}update(t){const e=this._x,s=this._y,n=this._condition>0,o=t[pt]||0;o!==this._level&&(this._level=o,this.zIndex=H(ki,o)),this._x=t[kt],this._y=t[At],this._rotation=t[Dt],this._vx=t[de]||0,this._vy=t[_e]||0,this._engineLoad=t[Bt]||0,this._condition=t[Mt],this._z=t[te]||0,this._vz=t[Ee]||0,this._particleContainer.boundsArea.x=this._x-ne,this._particleContainer.boundsArea.y=this._y-ne;const r=Xn(this._prevVz,this._vz,jt);r>0&&(this._triggerLandingBurst(r),this._playLandingSound(r)),this._prevVz=this._vz,this._updateSurface(e,s,n)}_updateSurface(t,e,s){if(!this._surfaces)return;const n=this._surfaces.kindAt(this._x,this._y,this._level),o=n==="boost"?this._surfaces.dirAt(this._x,this._y,this._level):null,r=this._surfaceCell,a=Math.hypot(this._x-t,this._y-e)>Ct.boost.resetDistance,l=!s&&this._condition>0;this._surfaceKind=n,this._surfaceCell={kind:n,dir:o},!(r===null||l||a||this._condition<=0||this._vz!==0)&&(n==="water"&&r.kind!=="water"&&this._triggerWaterEntry(),o&&!ih(r,o)&&this._vx*o[0]+this._vy*o[1]>=Ct.boost.boostMinSpeed&&this._triggerBoostFlash(o))}_triggerWaterEntry(){const t=Ct.water;if(!(Math.hypot(this._vx,this._vy)<t.entryMinSpeed))for(let e=-1;e<=1;e+=2){const s=this._contactPoint(e);for(let n=0;n<t.entryBurst;n+=1){const[o,r]=this._sideSprayVelocity(e,t);this._spawnParticle(s.x,s.y,o,r,t.sizeFactor*1.5,t)}}}_triggerBoostFlash(t){const e=Ct.boost,s=Math.atan2(-t[1],-t[0]);for(let n=0;n<e.burst;n+=1){const o=s+F(-Ai,Ai),r=F(e.tailSpeed.min,e.tailSpeed.max);this._spawnParticle(this._x,this._y,Math.cos(o)*r,Math.sin(o)*r,e.sizeFactor,e)}}_sideSprayVelocity(t,e){const s=this._rotation+Math.PI/2,n=this._rotation+Math.PI,o=F(e.sideSpeed.min,e.sideSpeed.max)*t,r=F(0,e.sideSpeed.min);return[Math.cos(s)*o+Math.cos(n)*r,Math.sin(s)*o+Math.sin(n)*r]}_spawnSurfaceDust(t,e){for(let s=-1;s<=1;s+=2){const n=this._contactPoint(s);let o,r;if(t==="water")[o,r]=this._sideSprayVelocity(s,e);else{const a=this._rotation+Math.PI,l=this._rotation+Math.PI/2,h=F(st.spinVelocity.back.min,st.spinVelocity.back.max),u=F(st.spinVelocity.side.min,st.spinVelocity.side.max);o=Math.cos(a)*h+Math.cos(l)*u,r=Math.sin(a)*h+Math.sin(l)*u}this._spawnParticle(n.x,n.y,o,r,e.sizeFactor,e)}}_playLandingSound(t){this._hasLandingSound&&this._soundManager.registerSound("tankLanding",{position:{x:this._x,y:this._y},volume:this._landingVolume*t})}_contactPoint(t){const e=this._rotation+Math.PI/2;return{x:this._x+Math.cos(e)*this._trackOffset*t-Math.cos(this._rotation)*this._backwardOffset,y:this._y+Math.sin(e)*this._trackOffset*t-Math.sin(this._rotation)*this._backwardOffset}}_triggerLandingBurst(t){const e=Math.round(st.landingBurst*t);if(!(e<=0))for(let s=-1;s<=1;s+=2){const n=this._contactPoint(s);for(let o=0;o<e;o+=1){const r=F(0,Math.PI*2),a=F(st.landingVelocity.min,st.landingVelocity.max)*t;this._spawnParticle(n.x,n.y,Math.cos(r)*a,Math.sin(r)*a,st.landingSizeFactor*t)}}}_spawnSpinDust(){const t=this._rotation+Math.PI,e=this._rotation+Math.PI/2;for(let s=-1;s<=1;s+=2){const n=this._contactPoint(s),o=F(st.spinVelocity.back.min,st.spinVelocity.back.max),r=F(st.spinVelocity.side.min,st.spinVelocity.side.max);this._spawnParticle(n.x,n.y,Math.cos(t)*o+Math.cos(e)*r,Math.sin(t)*o+Math.sin(e)*r,1)}}_spawnParticle(t,e,s,n,o,r=eh){const a=st.startSizeFactor*o,l=st.endSizeFactor*o,h=vt.get(this._dustTexture),u=a*this._particleScaleMultiplier*this._textureScale;h.tint=r.color,h.x=t,h.y=e,h.alpha=r.alpha,h.scaleX=u,h.scaleY=u,h.rotation=F(0,Math.PI*2),this._particles.push({view:h,x:t,y:e,vx:s,vy:n,age:0,lifetime:F(r.lifetime.min,r.lifetime.max),startAlpha:r.alpha,startSizeFactor:a,endSizeFactor:l,rotSpeed:F(-1,1)}),this._particleContainer.addParticle(h)}_updateParticles(t){if(t<=0)return;const e=t/1e3;this._timeSinceSpawn+=t;const s=Math.max(0,this._engineLoad-1),n=Math.hypot(this._vx,this._vy),r=this._condition>0&&s>0&&n<st.maxSpinSpeed&&this._surfaceKind!=="oil"?st.spawnRate*Math.min(s,1):0;if(r>0){const l=1e3/r;for(;this._timeSinceSpawn>=l;)this._spawnSpinDust(),this._timeSinceSpawn-=l}else this._timeSinceSpawn=0;this._emitSurface(t,n);const a=Math.pow(st.airResistance,t/16);for(let l=this._particles.length-1;l>=0;l-=1){const h=this._particles[l];if(h.age+=t,h.age>=h.lifetime){this._particleContainer.removeParticle(h.view),vt.release(h.view),this._particles.splice(l,1);continue}h.vx*=a,h.vy*=a,h.x+=h.vx*e,h.y+=h.vy*e;const u=h.age/h.lifetime,c=1-(1-u)*(1-u),d=(h.startSizeFactor+(h.endSizeFactor-h.startSizeFactor)*c)*this._particleScaleMultiplier*this._textureScale,f=h.view;f.x=h.x,f.y=h.y,f.scaleX=d,f.scaleY=d,f.alpha=h.startAlpha+(st.endAlpha-h.startAlpha)*u,f.rotation+=h.rotSpeed*e}}_emitSurface(t,e){const s=this._surfaceKind,n=sh.includes(s)?Ct[s]:null;if(!n||this._condition<=0||this._vz!==0||e<n.minSpeed){this._timeSinceSurfaceSpawn=0;return}const o=1e3/(n.rate*Math.min(e/n.fullSpeed,1));for(this._timeSinceSurfaceSpawn+=t;this._timeSinceSurfaceSpawn>=o;)this._spawnSurfaceDust(s,n),this._timeSinceSurfaceSpawn-=o}_stopTimer(){this._tickListener&&(J.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer();for(let e=0;e<this._particles.length;e+=1)vt.release(this._particles[e].view);this._particles=[],super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}function oh({progress:i,totalDist:t,trailLength:e,trailShare:s=0}){const n=t*St(i,0,1),o=Math.max(e,t*s),r=rt(o,0,St(i,0,1));return{tail:Math.max(0,n-r),head:n}}class rh extends Nt{constructor(t,e,s,n,o,r=He,a={}){super(o),this.startPositionX=t,this.startPositionY=e,this.endPositionX=s,this.endPositionY=n,this.config=r,this._layerFor=a.layerFor||null,this._stopLine=a.stopLine||null,this.pieces=a.pieces?.length?a.pieces:[{from:0,to:1/0,level:null}],this._graphics=new Map;for(const{level:l}of this.pieces)if(!this._graphics.has(l)){const h=new V;h.blendMode="add",(this._layerFor?.(l)||this).addChild(h),this._graphics.set(l,h)}this.elapsedTime=0,this.progress=0,this._aim(),this.animationDuration=St(this.totalDist/r.speed*1e3,r.minDuration,r.maxDuration)}_aim(){const t=this.endPositionX-this.startPositionX,e=this.endPositionY-this.startPositionY;this.totalDist=Math.hypot(t,e),this.totalDist>.001?(this.nx=t/this.totalDist,this.ny=e/this.totalDist):(this.nx=0,this.ny=0,this.totalDist=0)}shiftTo(t,e){this.isComplete||(this.endPositionX+=t-this.startPositionX,this.endPositionY+=e-this.startPositionY,this.startPositionX=t,this.startPositionY=e,this._clipToStopLine(),this._draw())}_clipToStopLine(){const t=this._stopLine;if(!t)return;const e=t.axis==="x",s=e?this.nx:this.ny;if(Math.abs(s)<1e-9)return;const n=e?this.startPositionX:this.startPositionY,o=(t.coord-n)/s;o<this.totalDist&&(this.totalDist=Math.max(0,o),this.endPositionX=this.startPositionX+this.nx*this.totalDist,this.endPositionY=this.startPositionY+this.ny*this.totalDist)}_clear(){for(const t of this._graphics.values())t.clear()}_draw(){this._clear();const{tail:t,head:e}=oh({progress:this.progress,totalDist:this.totalDist,trailLength:this.config.trailLength,trailShare:this.config.trailShare});e-t>.001&&this._drawTrail(t,e,rt(this.config.alphaStart,this.config.alphaEnd,this.progress))}_update(t){this.isComplete||(this.elapsedTime+=t,this.progress=Math.min(this.elapsedTime/this.animationDuration,1),this._draw(),this.elapsedTime>=this.animationDuration&&(this._clear(),this._completeEffect()))}_drawTrail(t,e,s){const{color:n,coreColor:o,coreWidth:r,glowWidth:a,glowAlpha:l}=this.config,h=this.config.taper??1,u=Math.max(1,this.config.fadeSteps),c=[];for(let f=0;f<u;f+=1){const p=rt(t,e,f/u),_=rt(t,e,(f+1)/u),m=(f+1)/u;c.push({from:p,to:_,fade:m*m,thin:rt(h,1,m)})}const d=this._split(c);for(const{graphics:f,from:p,to:_,fade:m,thin:g}of d)f.moveTo(p[0],p[1]).lineTo(_[0],_[1]).stroke({width:a*g,color:n,alpha:s*l*m,cap:"round"});for(const{graphics:f,from:p,to:_,fade:m,thin:g}of d)f.moveTo(p[0],p[1]).lineTo(_[0],_[1]).stroke({width:r*g,color:o,alpha:s*m,cap:"round"})}_split(t){const e=n=>[this.startPositionX+this.nx*n,this.startPositionY+this.ny*n],s=[];for(const{from:n,to:o,fade:r,thin:a}of t)for(const l of this.pieces){const h=Math.max(n,l.from),u=Math.min(o,l.to);u-h>1e-6&&s.push({graphics:this._graphics.get(l.level),from:e(h),to:e(u),fade:r,thin:a})}return s}destroy(t){for(const e of this._graphics.values())e.destroyed||(e.clear(),e.parent!==this&&e.destroy());this._graphics.clear(),super.destroy(t)}}function ah(i,t,e){const s=e||0;if(!(t>0))return[{from:0,to:0,level:s}];const n=(i||[]).filter(c=>c.t1>c.t0&&c.t0<t);if(n.length===0)return[{from:0,to:t,level:s}];const o=c=>Math.min(t,Math.max(0,c)),r=[...new Set([0,t,...n.flatMap(c=>[o(c.t0),o(c.t1)])])].sort((c,d)=>c-d),a=[];for(let c=0;c+1<r.length;c+=1){const d=r[c],f=r[c+1];if(f-d<1e-6)continue;const p=(d+f)/2;let _=null;for(const g of n)g.t0<=p&&p<g.t1&&(_===null||g.t0<_.t0)&&(_=g);const m=_?_.level:a.at(-1)?.level??s;cs(a,d,f,m)}if(a.at(-1).level===s)return a;const l=n.filter(c=>c.level===s&&c.t0<t&&c.t1>=t-.001).sort((c,d)=>d.t0-c.t0)[0],h=l?o(l.t0):a.at(-1).from,u=[];for(const c of a)c.from<h&&cs(u,c.from,Math.min(c.to,h),c.level);return cs(u,h,t,s),u}function cs(i,t,e,s){if(e-t<1e-6)return;const n=i.at(-1);n&&n.level===s&&Math.abs(n.to-t)<1e-6?n.to=e:i.push({from:t,to:e,level:s})}class lh extends Nt{constructor(t,e,s,n,o,r,{surfaceK:a=null,startK:l=null}={}){super(o),this.x=t,this.y=e,this._assets=r;const{texture:h,contentSize:u}=this._assets.impactParticleTexture;this._particleTexture=h,this._textureContentSize=u,this.config={particleCount:F(5,9),particleMinSize:.8,particleMaxSize:2.8,minInitialSpeed:10,maxInitialSpeed:380,minLifetime:8e3,maxLifetime:15e3,color:[3355443,2236962,4473924],fadeOutStart:.8,impactDirectionX:s,impactDirectionY:n,spreadAngle:60,dragCoefficient:13,minSpeedThreshold:1,lingerDuration:6e3,fallDuration:250},this.config.impactDirectionX===0&&this.config.impactDirectionY===0?this.useOmnidirectionalSpread=!0:this.useOmnidirectionalSpread=!1,this.particlesData=[],this.elapsedTime=0,this._surfaceK=typeof a=="function"?a:null,this._startK=typeof l=="number"?l:null,this._createParticles()}_kAt(t){return this._surfaceK?this._surfaceK(this.x+t.x,this.y+t.y):null}_createParticles(){let t;this.useOmnidirectionalSpread||(t=Math.atan2(this.config.impactDirectionY,this.config.impactDirectionX));const s=this.config.spreadAngle*(Math.PI/180)/2;for(let n=0,o=this.config.particleCount;n<o;n+=1){let r;this.useOmnidirectionalSpread?r=Math.random()*Math.PI*2:r=t+F(-s,s);const a=F(this.config.minInitialSpeed,this.config.maxInitialSpeed),l=new Z(this._particleTexture);l.anchor.set(.5);const h={sprite:l,x:0,y:0,vx:Math.cos(r)*a,vy:Math.sin(r)*a,size:F(this.config.particleMinSize,this.config.particleMaxSize),color:Array.isArray(this.config.color)?this.config.color[Math.floor(Math.random()*this.config.color.length)]:this.config.color,lifetime:F(this.config.minLifetime,this.config.maxLifetime),age:0,alpha:1,active:!0,isMoving:!0,timeSinceStopped:0,k:null,lift:1};h.k=this._kAt(h),l.tint=h.color,this.particlesData.push(h),this.addChild(l)}}_update(t){if(this.isComplete)return;this.elapsedTime+=t;const e=t/1e3;let s=0;for(let n=0,o=this.particlesData.length;n<o;n+=1){const r=this.particlesData[n];if(!r.active)continue;s+=1,r.age+=t;const a=Math.min(r.age/this.config.fallDuration,1);if(r.lift=1-a*a,r.isMoving){const c=Math.hypot(r.vx,r.vy);if(c>0){const f=c*this.config.dragCoefficient*e,p=Math.max(0,1-f/c);r.vx*=p,r.vy*=p}r.x+=r.vx*e,r.y+=r.vy*e,r.k=this._kAt(r),Math.hypot(r.vx,r.vy)<this.config.minSpeedThreshold&&(r.isMoving=!1,r.vx=0,r.vy=0)}else r.timeSinceStopped+=t;const l=r.age/r.lifetime;if(!r.isMoving&&r.timeSinceStopped>=this.config.lingerDuration){const c=r.timeSinceStopped-this.config.lingerDuration,d=Math.min(500,r.lifetime*(1-this.config.fadeOutStart));r.alpha=rt(1,0,Math.min(c/d,1))}else if(l>=this.config.fadeOutStart){const c=r.age-r.lifetime*this.config.fadeOutStart,d=r.lifetime*(1-this.config.fadeOutStart);r.alpha=d>0?rt(1,0,Math.min(c/d,1)):0}(r.age>=r.lifetime||r.alpha<.01)&&(r.active=!1,r.alpha=0);const h=r.sprite;h.position.set(r.x,r.y),h.alpha=r.alpha,h.visible=r.active;const u=r.size/this._textureContentSize;h.scale.set(u)}s===0&&this._isStarted&&this._completeEffect()}isFalling(){return this._startK!==null&&this.particlesData.some(t=>t.active&&t.lift>0)}project(t,e){if(!(!this._surfaceK&&this._startK===null))for(const s of this.particlesData){if(!s.active)continue;const n=s.k??e,o=this._startK===null?n:n+(this._startK-n)*s.lift,r=Pe(this.x+s.x,this.y+s.y,t,e,o);s.sprite.position.set(r.x-this.x,r.y-this.y),s.sprite.scale.set(s.size/this._textureContentSize*r.scale)}}destroy(t){this.particlesData=[],super.destroy(t)}}function hh(i,t=Math.random){const e=[],s=Math.max(1,i.spikes);for(let o=0;o<s;o+=1){const r=s===1?.5:(o+t())/s;e.push({angle:(r*2-1)*i.spread,length:1-t()*i.jitter})}const n=i.sideLength?[1-t()*i.jitter,1-t()*i.jitter]:[];return{forward:e,sides:n}}const Ti=12,ch=Array.from({length:Ti},(i,t)=>{const e=t/Ti*Math.PI*2;return[Math.cos(e),Math.sin(e)]}),Li=(i,t)=>i.core?t.coreColor:t.color;function uh(i){return Math.max(i.duration||0,i.ring?.duration||0)}function fh(i,t){const e=t.ring;if(!e||!(e.duration>0)||i>=e.duration)return null;const s=St(i/e.duration,0,1),n=1-(1-s)*(1-s),o=1-s;return{radius:e.radius*n,width:e.width,alpha:e.alpha*o*o,color:e.color??t.coreColor}}function dh({dirX:i,dirY:t,t:e,roll:s,config:n}){const o=1-St(e,0,1),r=o*o,a=1-n.shrink*(1-o),l=Math.atan2(t,i),h=[],u=(c,d,f)=>{const p=Math.cos(c),_=Math.sin(c),m=f/2;return[-_*m,p*m,p*d,_*d,_*m,-p*m]};for(const c of n.layers){const d=c.scale*a,f=Li(c,n),p=c.alpha*r;if(!(p<=0)){for(const{angle:_,length:m}of s.forward)h.push({points:u(l+_,n.length*m*d,n.width*d),color:f,alpha:p});s.sides.forEach((_,m)=>{h.push({points:u(l+(m===0?Math.PI/2:-Math.PI/2),n.sideLength*_*d,n.sideWidth*d),color:f,alpha:p})})}}if(n.ball?.radius>0)for(const c of n.layers){const d=c.alpha*r;if(d<=0)continue;const f=n.ball.radius*c.scale*a,p=[];for(const[_,m]of ch)p.push(_*f,m*f);h.push({points:p,color:Li(c,n),alpha:d})}return h}class Pi extends Nt{constructor(t,e,s,n,o,r=To,a=Math.random){super(o),this.position.set(t,e),this.dirX=s,this.dirY=n,this.config=r,this.roll=hh(r,a),this.elapsedTime=0,this.graphics=new V,this.graphics.blendMode="add",this.addChild(this.graphics)}_update(t){if(this.isComplete)return;if(this.elapsedTime+=t,this.graphics.clear(),this.elapsedTime>=uh(this.config)){this._completeEffect();return}const e=this.config.duration?this.elapsedTime/this.config.duration:1;if(e<1){const n=dh({dirX:this.dirX,dirY:this.dirY,t:e,roll:this.roll,config:this.config});for(const{points:o,color:r,alpha:a}of n)this.graphics.poly(o).fill({color:r,alpha:a})}const s=fh(this.elapsedTime,this.config);s&&s.radius>0&&s.alpha>0&&this.graphics.circle(0,0,s.radius).stroke({width:s.width,color:s.color,alpha:s.alpha})}destroy(t){this.graphics&&this.graphics.clear(),super.destroy(t)}}function _h(i,t,e,s=Math.random){const n=[],o=Math.max(0,Math.round(i.count)),r=Math.atan2(e,t),a=(l,h)=>l.min+(l.max-l.min)*h;for(let l=0;l<o;l+=1){const h=t===0&&e===0?s()*Math.PI*2:r+(s()*2-1)*i.spread,u=a(i.speed,s());n.push({vx:Math.cos(h)*u,vy:Math.sin(h)*u,size:a(i.size,s()),lifetime:a(i.lifetime,s()),color:i.colors[Math.floor(s()*i.colors.length)],rotation:s()*Math.PI*2})}return n}function ph(i,t,e){if(t>=i.lifetime)return null;const s=St(t/i.lifetime,0,1),n=t/1e3,o=e.drag>0?(1-Math.exp(-e.drag*n))/e.drag:n,r=1-(1-s)*(1-s),a=1-s;return{x:i.vx*o,y:i.vy*o,size:i.size*(1+(e.grow-1)*r),alpha:e.alpha*a*a}}class mh extends Nt{constructor(t,e,s,n,o,r,a=an,l=Math.random){super(o),this.position.set(t,e),this.config=a,this.elapsedTime=0;const{texture:h,contentSize:u}=r.smokeTexture;this._unitScale=1/u,this.puffs=_h(a,s,n,l),this.sprites=this.puffs.map(c=>{const d=new Z(h);return d.anchor.set(.5),d.tint=c.color,d.rotation=c.rotation,this.addChild(d),d})}_update(t){if(this.isComplete)return;this.elapsedTime+=t;let e=0;this.puffs.forEach((s,n)=>{const o=ph(s,this.elapsedTime,this.config),r=this.sprites[n];r.visible=o!==null,o&&(e+=1,r.position.set(o.x,o.y),r.scale.set(o.size*this._unitScale),r.alpha=o.alpha)}),e===0&&this._completeEffect()}destroy(t){this.puffs=[],this.sprites=[],super.destroy(t)}}const Ci=(i,t)=>Math.round(i/t)*t;function Vn(i,t,e,s,n,o,r){const a=Ci(i,n),l=Ci(t,o),h=Math.abs(e)>1e-9&&Math.abs(i-a)<=r,u=Math.abs(s)>1e-9&&Math.abs(t-l)<=r;return h&&(!u||Math.abs(e)>=Math.abs(s))?{axis:"x",coord:a,nx:e>0?-1:1,ny:0}:u?{axis:"y",coord:l,nx:0,ny:s>0?-1:1}:null}function Ei(i,t,e,s){return i.nx*(s.x-t)+i.ny*(s.y-e)>0}function gh({x0:i,y0:t,dx:e,dy:s,face:n,camera:o,kBase:r,kLine:a}){const l=n.axis==="x",h=l?i:t,u=l?e:s,c=l?o.x:o.y;return Math.abs(u)<1e-9?null:(n.coord+(n.coord-c)*a+c*r-h*(1+r))/(u*(1+r))}const us=2,zi=cn+.5,fs=.15;class xh extends G{constructor(t,e,s){super(),this.startPositionX=t[Jr],this.startPositionY=t[ta],this.endPositionX=t[ea],this.endPositionY=t[sa],this.soundPositionX=t[ia],this.soundPositionY=t[na],this.hitCode=t[oa]||0,this.hit=this.hitCode!==0,this.endLevel=t[aa]||0,this.startLevel=t[ra]||0,this.zIndex=H(us,this.endLevel),this.anchorKey=null,this.anchorLocalX=0,this.anchorLocalY=0,Array.isArray(t[ii])&&([this.anchorKey,this.anchorLocalX,this.anchorLocalY]=t[ii]),this._assets=e,this._soundManager=s.soundManager,this._isLocalShot=s.localPlayer?.is(t[rs])===!0,s.shots?.fired(t[rs]),this._mapDynamics=s.mapDynamics||null,this._shots=s.shots||null,this._shooterId=t[rs],this._levelView=s.levelView||null,this._lighting=s.lighting||null,this._volumes=s.volumes||null,this._rampRuns=s.rampRuns||null,this._wall=null,this._renderer=s.renderer||null,(this._levelView||this._renderer)&&(this.onRender=()=>{this._levelView&&(this.alpha=this._levelView.alphaFor(this.endLevel,this.endPositionX,this.endPositionY),this.tint=this._levelView.tintFor(this.endLevel));const n=ut(this.parent,this._renderer);gt(this,n,this.endLevel*N.shear,1);for(const[o,r]of this.layers)this._levelView&&(r.alpha=this._levelView.alphaFor(o,r.refX,r.refY),r.tint=this._levelView.tintFor(o)),gt(r,n,o*N.shear,1);this._followMuzzle(),this._placeFlash(n),this._placeDebris(n),this._placeImpactZ(n)}),this.tracer=null,this.layers=new Map,this.impact=null,this.flash=null,this._flashComplete=!0,this.hitFlash=null,this.hitSmoke=null,this._burstPending=0,this._visibleEnd=null,this._isDestroyed=!1,this._visualsComplete=!1,this._soundComplete=!1,this._soundId=this._soundManager.registerSound("shot",{position:{x:this.soundPositionX,y:this.soundPositionY},spatial:!this._isLocalShot},()=>{this._soundComplete=!0,this._soundId=null,this._tryDestroy()}),this._soundId||(this._soundComplete=!0)}run(){if(this._isDestroyed)return;this._lighting?.flash({...yt.flash.shot,level:this.startLevel,x:this.startPositionX,y:this.startPositionY,z:this.startLevel});const t=this.endPositionX-this.startPositionX,e=this.endPositionY-this.startPositionY,s=Math.hypot(t,e);s>.001&&(this._flashComplete=!1,this.flash=new Pi(this.startPositionX,this.startPositionY,t/s,e/s,()=>{this._flashComplete=!0,this._tryDestroy()}),this.addChild(this.flash),this.flash.run());const n=this._slopeEnd(s)??this._wallEnd(t,e,s);this._visibleEnd=n;const o=ah(this._shots?.path?.(this.startPositionX,this.startPositionY,n.x,n.y,this.startLevel),n.dist,this.endLevel);this.tracer=new rh(this.startPositionX,this.startPositionY,n.x,n.y,this._onTracerComplete.bind(this),He,{pieces:o,layerFor:r=>this._layerFor(r,o),stopLine:n.stopLine}),this.addChild(this.tracer),this.tracer.run()}_wallAt(t,e){if(!this.hit)return null;if(this.hitCode===la){const c=2*fs,d=this._floorAt(this.endPositionX+t*c,this.endPositionY+e*c),f=this._rampRuns?.faceAt?.(d,this.endPositionX,this.endPositionY,t,e,fs);return f?{...f,base:d}:null}if(!this._volumes)return null;const{cellW:s,cellH:n}=this._volumes.cellSize();if(!(s>0&&n>0))return null;const o=Vn(this.endPositionX,this.endPositionY,t,e,s,n,fs);if(!o)return null;const r=.01*Math.min(s,n),a=this.endPositionX+t*r,l=this.endPositionY+e*r,h=this._floorAt(a,l),u=this._volumes.heightAt(h,a,l);return u>0?{face:o,volume:u,base:h}:null}_floorAt(t,e){const s=this._rampRuns?.floorAt?.(this.endLevel,t,e);return Number.isInteger(s)?s:this.endLevel}_wallEnd(t,e,s){const n={x:this.endPositionX,y:this.endPositionY,dist:s,stopLine:null};if(!(s>.001))return n;const o=t/s,r=e/s;if(this._wall=this._wallAt(o,r),!this._wall)return n;const a=this._levelView?.camera()??ut(this.parent,this._renderer);if(!a)return n;const{face:l,volume:h,base:u}=this._wall,{shear:c}=N,d=this.endLevel*c;let f,p;if(Ei(l,this.endPositionX,this.endPositionY,a))({x:f,y:p}=Pe(this.endPositionX,this.endPositionY,a,d,(this.endLevel+He.height)*c)),this.zIndex=H(zi,this.endLevel);else{const _=gh({x0:this.startPositionX,y0:this.startPositionY,dx:o,dy:r,face:l,camera:a,kBase:d,kLine:(u+h)*c}),m=_===null?s:Math.min(s,Math.max(0,_));f=this.startPositionX+o*m,p=this.startPositionY+r*m}return{x:f,y:p,dist:Math.hypot(f-this.startPositionX,p-this.startPositionY),stopLine:{axis:l.axis,coord:l.axis==="x"?f:p}}}_slopeEnd(t){const e=this.hitCode===ni&&t>.001?this._rampRuns?.slopeAt?.(this.endLevel,this.endPositionX,this.endPositionY):null;if(!e)return null;const s=this._levelView?.camera()??ut(this.parent,this._renderer),{shear:n}=N,{x:o,y:r}=Pe(this.endPositionX,this.endPositionY,s,this.endLevel*n,e.height*n);return{x:o,y:r,dist:Math.hypot(o-this.startPositionX,r-this.startPositionY),stopLine:{axis:e.axis===0?"x":"y",coord:e.axis===0?o:r}}}_debrisSurface(){const t=this._rampRuns;if(typeof t?.heightAt!="function")return null;const e=this.endLevel,{shear:s}=N;return(n,o)=>{const r=this._floorAt(n,o),a=t.heightAt(r,n,o);return a!==null?a*s:r<e?r*s:null}}_debrisStartK(){const{shear:t}=N;return this._wall?(this.endLevel+He.height)*t:this.hitCode===ni?null:this._floorAt(this.endPositionX,this.endPositionY)<this.endLevel?this.endLevel*t:null}_placeDebris(t){const e=this.impact;!e||e.destroyed||e.parent!==this||e.project(t,this.endLevel*N.shear)}_placeImpactZ(t){const e=this.impact;if(!this._wall||!e||e.destroyed)return;const s=!!(t&&Ei(this._wall.face,this.endPositionX,this.endPositionY,t));this.zIndex=H(s&&(e.isFalling()||this._burstPending>0)?zi:us,this.endLevel)}_layerFor(t,e){const s=!!this._lighting?.isNight?.();if(!s&&t===this.endLevel||!this.parent)return this;let n=this.layers.get(t);if(!n){const o=e.find(u=>u.level===t),r=o?(o.from+o.to)/2:0,a=this.endPositionX-this.startPositionX,l=this.endPositionY-this.startPositionY,h=Math.hypot(a,l)||1;n=new G,n.label=`shot-tracer-${t}`,n.eventMode="none",n.zIndex=H(s?vn:us,t),n.refX=this.startPositionX+a/h*r,n.refY=this.startPositionY+l/h*r,this.parent.addChild(n),this.layers.set(t,n)}return n}_followMuzzle(){if(!this._shots||this.impact)return;const t=this.tracer&&!this.tracer.isComplete,e=this.flash&&!this.flash.isComplete;if(!t&&!e)return;const s=this._shots.muzzle(this._shooterId);s&&(this.startPositionX=s.x,this.startPositionY=s.y,t&&this.tracer.shiftTo(s.x,s.y))}_placeFlash(t){if(!this.flash||this.flash.destroyed)return;const{shear:e}=N,s=Pe(this.startPositionX,this.startPositionY,t,this.endLevel*e,this.startLevel*e);this.flash.position.set(s.x,s.y),this.flash.scale.set(s.scale)}_onTracerComplete(){if(!this._isDestroyed)if(this.hit){let t=this.endPositionX,e=this.endPositionY;if(this.anchorKey!==null&&this._mapDynamics){const l=this._mapDynamics.toWorld(this.anchorKey,this.anchorLocalX,this.anchorLocalY);l&&(t=l.x,e=l.y)}const s=t-this.startPositionX,n=e-this.startPositionY,o=Math.hypot(s,n);let r=0,a=0;o>.001&&(r=-(s/o),a=-(n/o)),this.impact=new lh(t,e,r,a,this._onImpactComplete.bind(this),this._assets,{surfaceK:this._debrisSurface(),startK:this._debrisStartK()}),this.addChild(this.impact),this.impact.run(),this._burst(t,e,r,a)}else this._visualsComplete=!0,this._tryDestroy()}_burst(t,e,s,n){const o=this._visibleEnd,r=t!==this.endPositionX||e!==this.endPositionY,a=o&&!r?o.x:t,l=o&&!r?o.y:e,h=()=>{this._burstPending-=1,this._tryDestroy()};yt.flash.hit&&this._lighting?.flash({...yt.flash.hit,level:this.endLevel,x:t,y:e,z:this.endLevel}),this._assets?.smokeTexture&&an.count>0&&(this._burstPending+=1,this.hitSmoke=new mh(a,l,s,n,h,this._assets),this.addChild(this.hitSmoke),this.hitSmoke.run()),this._burstPending+=1,this.hitFlash=new Pi(a,l,s,n,h,Lo),this.addChild(this.hitFlash),this.hitFlash.run()}_onImpactComplete(){this._isDestroyed||(this._visualsComplete=!0,this._tryDestroy())}_tryDestroy(){this._visualsComplete&&this._soundComplete&&this._flashComplete&&this._burstPending===0&&this.destroy()}destroy(){if(!this._isDestroyed){this._isDestroyed=!0,this._soundId&&(this._soundManager.unregisterSound(this._soundId),this._soundId=null),this.tracer&&(this.tracer.destroy(),this.tracer=null);for(const t of this.layers.values())t.destroy({children:!0});this.layers.clear(),this.impact&&(this.impact.destroy(),this.impact=null),this.flash&&(this.flash.destroy(),this.flash=null),this.hitFlash&&(this.hitFlash.destroy(),this.hitFlash=null),this.hitSmoke&&(this.hitSmoke.destroy(),this.hitSmoke=null),this.parent&&this.parent.removeChild(this),super.destroy({children:!0})}}}class Ii{constructor({texture:t,max:e,blendMode:s="normal",padding:n}){this.texture=t,this.max=e,this.items=[],this._padding=n,this.container=new ts({texture:t,boundsArea:new nt(-n,-n,n*2,n*2),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.container.blendMode=s}get size(){return this.items.length}follow(t,e){this.container.boundsArea.x=t-this._padding,this.container.boundsArea.y=e-this._padding}spawn(t){if(this.items.length>=this.max)return null;const e=vt.get(this.texture);return t.view=e,this.container.addParticle(e),this.items.push(t),t}removeAt(t){const[e]=this.items.splice(t,1);e&&(this.container.removeParticle(e.view),vt.release(e.view))}clear(){this.container.removeParticles();for(let t=0;t<this.items.length;t+=1)vt.release(this.items[t].view);this.items.length=0}}const yh=2,wh=Math.PI*2;class vh{constructor(t,e,{x:s,y:n,z:o,level:r,sizeScale:a}){const{textures:l}=e,h=new Z(l[Math.floor(Math.random()*l.length)]);h.anchor.set(.5),h.rotation=Math.random()*wh,h.alpha=0,h.zIndex=H(yh,r),this.sprite=h,this.x=s,this.y=n,this.z=o,this.level=r,this.scale=$.scorch.size*a/e.contentSize,this.age=0,this.alpha=0,t.addChild(h),t.sortChildren()}get settled(){return this.age>=$.scorch.fadeIn}step(t){const{alpha:e,fadeIn:s}=$.scorch;this.age+=t,this.alpha=e*St(this.age/s,0,1)}render(t,e){const s=this.z*N.shear,n=mt(this.x,this.y,t,s);this.sprite.position.set(n.x,n.y),this.sprite.scale.set(this.scale*(1+s));const o=e?e.alphaFor(this.level,this.x,this.y,this.z):1;this.sprite.alpha=this.alpha*o,e&&(this.sprite.tint=e.tintFor(this.level))}destroy(){this.sprite.destroy({texture:!1,textureSource:!1})}}const Ri=(i,t)=>i>>t&255;function Ae(i,t,e){const s=Math.min(Math.max(e,0),1),n=o=>{const r=Ri(i,o);return Math.round(r+(Ri(t,o)-r)*s)};return n(16)<<16|n(8)<<8|n(0)}function Sh(i,t){const[e,s]=i[0];if(t<=e)return s;for(let n=1;n<i.length;n+=1){const[o,r]=i[n];if(t<=o){const[a,l]=i[n-1];return Ae(l,r,(t-a)/(o-a))}}return i[i.length-1][1]}function Bn(i,t){return i<=t.duration?1:t.fadeOut>0?Math.max(0,1-(i-t.duration)/t.fadeOut):0}function Nn(i){return i.duration+i.fadeOut}function Mh(i,t,e){const s=Nn(t);if(i<s){const n=Bn(i,t);return e.tailRate+(e.rate-e.tailRate)*n}return e.tailRate*Math.max(0,1-(i-s)/e.tail)}function bh(i,t){return Nn(i)+t.tail}function kh(i,t){return i<=0||i>=1?0:i<.12?t*(i/.12):i<=.45?t:t*(1-(i-.45)/.55)}const Fi=4,Di=400,Ah=100,oe=Math.PI*2,Ye={min:.8,max:1.2},Oe=1,Xi={min:.7,max:1.3},Yi=.3,Th=.6,Oi=.5,Lh=.8,Ph=[[0,0]],Ch=.8,Eh=1.3,zh=.5,ht=i=>F(i.min,i.max),Ve=i=>({kind:"flame",x:0,y:0,vx:0,vy:0,windX:0,windY:0,drag:0,h:0,rise:0,age:0,life:1,size0:0,width:0,grow:1,aspectX:1,aspectY:1,spin:0,alpha:1,scaleX:0,scaleY:0,...i});class Ih extends G{constructor(t,e,s={}){super(),this._readRow(t),this._condition=t[Mt],this.zIndex=H(Fi,this._level),this.visible=!1;const n=e.wreckFireTexture,o=e.wreckSmokeTexture;this._fireAsset=n||null,this._smokeAsset=o||null,this._scorchAsset=e.wreckScorchTexture||null,this._fireUnit=n?1/n.contentSize:0,this._smokeUnit=o?1/o.contentSize:0,this._enabled=!!n&&!!o,this._renderer=s.renderer||null,this._levelView=s.levelView||null,this._soundManager=s.soundManager||null,this._blasts=s.blasts||null,this._lighting=s.lighting?.enabled?s.lighting:null,this._active=!1,this._elapsed=0,this._flameAcc=0,this._smokeAcc=0,this._seed=0,this._tickListener=null,this._light=null,this._soundId=null,this._scorch=null,this._scorchPending=!1,this._fire=null,this._smoke=null,this._glow=null,this._flash=null,this._flashAge=0}_readRow(t){this._x=t[kt],this._y=t[At],this._heading=t[Dt],this._z=t[te]||0,this._physLevel=t[pt]||0,this._vz=t[Ee]||0,this._level=Ce(t[pt],this._z);const e=t[Ie]||$.referenceSize;this._length=e*4,this._width=e*3,this._sizeScale=e/$.referenceSize}update(t){const e=this._condition,s=this._level;this._readRow(t),this._level!==s&&(this.zIndex=H(Fi,this._level)),this._active&&(this._fire.follow(this._x,this._y),this._smoke.follow(this._x,this._y));const n=t[Mt];n!==void 0&&n!==e&&(this._condition=n,n===0&&e>0?this._ignite():n>0&&e===0&&this._reset()),this._scorchPending&&this._vz===0&&this._addScorch()}_ensureViews(){if(this._fire)return;const t=this._fireAsset.texture;this._smoke=new Ii({texture:this._smokeAsset.texture,max:$.maxSmoke,padding:Di}),this._fire=new Ii({texture:t,max:$.maxFire,blendMode:"add",padding:Di});const e=()=>{const s=new Z(t);return s.anchor.set(.5),s.blendMode="add",s.visible=!1,s};this._glow=e(),this._flash=e(),this.addChild(this._glow,this._smoke.container,this._fire.container,this._flash)}_ignite(){this._enabled&&(this._reset(),this._ensureViews(),this._elapsed=0,this._flameAcc=0,this._smokeAcc=0,this._seed=Math.random()*1e3,this._active=!0,this.visible=!0,this._fire.follow(this._x,this._y),this._smoke.follow(this._x,this._y),this._explode(),this._notify(),this._addLight(),this._addScorch(),this._tickListener=t=>this._tick(t.deltaMS),J.shared.add(this._tickListener),this.onRender=()=>this._render())}_explode(){const t=this._flash;this._flashAge=0,t.position.set(this._x,this._y),t.tint=$.flash.color,t.visible=!0,this._stepFlash(0);for(let e=0;e<$.fireball.count;e+=1)this._spawnFireball();for(let e=0;e<$.sparks.count;e+=1)this._spawnSpark();for(let e=0;e<$.smoke.burst.count;e+=1)this._spawnBurstSmoke()}_notify(){this._soundManager&&(this._soundId=this._soundManager.registerSound($.sound,{position:{x:this._x,y:this._y}})),this._lighting?.flash({...yt.flash.wreck,level:this._level,x:this._x,y:this._y,z:this._z}),this._blasts?.exploded({x:this._x,y:this._y,radius:$.joltRadius*this._sizeScale,level:this._physLevel})}_addLight(){this._lighting&&(this._light=this._lighting.addLight({kind:"radial",radius:yt.wreckFire.radius*this._sizeScale,color:yt.wreckFire.color,intensity:0}))}_addScorch(){const t=this._scorchAsset;if(!(!t||!this.parent)){if(this._vz!==0){this._scorchPending=!0;return}this._scorchPending=!1,this._scorch=new vh(this.parent,t,{x:this._x,y:this._y,z:this._z,level:this._level,sizeScale:this._sizeScale})}}_hullPoint(t,e){const[s,n]=t[Math.floor(Math.random()*t.length)],o=(s+F(-e,e)/2)*this._length,r=(n+F(-e,e)/2)*this._width,a=Math.cos(this._heading),l=Math.sin(this._heading);return{x:this._x+a*o-l*r,y:this._y+l*o+a*r}}_spawnFlame(t){const{fire:e,wind:s}=$,n=this._hullPoint(e.points,e.spread),o=this._fire.spawn(Ve({kind:"flame",x:n.x,y:n.y,vx:s.x*Oi+F(-4,e.jitter)*this._sizeScale,vy:s.y*Oi+F(-4,e.jitter)*this._sizeScale,windX:s.x,windY:s.y,rise:e.rise,life:ht(e.lifetime),size0:ht(e.size)*this._sizeScale*rt(Th,1,t)*this._fireUnit,grow:e.grow,aspectX:ht(Ye),aspectY:ht(Ye),spin:F(-Oe,Oe),alpha:e.alpha}));o&&(o.view.rotation=Math.random()*oe,this._applyFire(o,0))}_spawnFireball(){const{fireball:t,wind:e}=$,s=this._hullPoint(Ph,Lh),n=Math.random()*oe,o=ht(t.speed)*this._sizeScale,r=this._fire.spawn(Ve({kind:"fireball",x:s.x,y:s.y,vx:Math.cos(n)*o,vy:Math.sin(n)*o,windX:e.x,windY:e.y,drag:t.drag,rise:t.rise,life:ht(t.lifetime),size0:ht(t.size)*this._sizeScale*this._fireUnit,grow:t.grow,aspectX:ht(Ye),aspectY:ht(Ye),spin:F(-Oe,Oe),alpha:t.alpha}));r&&(r.view.rotation=Math.random()*oe,this._applyFire(r,0))}_spawnSpark(){const{sparks:t}=$,e=Math.random()*oe,s=ht(t.speed)*this._sizeScale,n=this._fire.spawn(Ve({kind:"spark",x:this._x,y:this._y,vx:Math.cos(e)*s,vy:Math.sin(e)*s,drag:t.drag,life:ht(t.lifetime),size0:t.length*this._sizeScale*this._fireUnit,width:t.width*this._sizeScale*this._fireUnit}));n&&(n.view.rotation=e,this._applyFire(n,0))}_spawnSmoke(t){const{smoke:e}=$;this._emitSmoke({heat:t,speed:F(0,e.speed),lifeFactor:1,sizeFactor:1,alpha:rt(e.tailAlpha,e.alpha,t)})}_spawnBurstSmoke(){const{smoke:t}=$;this._emitSmoke({heat:1,speed:ht(t.burst.speed),lifeFactor:Ch,sizeFactor:Eh,alpha:t.burst.alpha})}_emitSmoke({heat:t,speed:e,lifeFactor:s,sizeFactor:n,alpha:o}){const{fire:r,smoke:a,wind:l}=$,h=this._hullPoint(r.points,r.spread),u=Math.random()*oe,c=e*this._sizeScale,d=Math.random(),f=Ae(Ae(a.cooling[0],a.cooling[1],d),Ae(a.burning[0],a.burning[1],d),t),p=this._smoke.spawn(Ve({kind:"smoke",x:h.x,y:h.y,vx:Math.cos(u)*c+l.x,vy:Math.sin(u)*c+l.y,windX:l.x,windY:l.y,drag:a.drag,rise:a.rise,life:ht(a.lifetime)*s,size0:ht(a.size)*this._sizeScale*n*this._smokeUnit,grow:a.grow,aspectX:ht(Xi),aspectY:ht(Xi),spin:F(-Yi,Yi),alpha:o}));p&&(p.view.tint=f,p.view.rotation=Math.random()*oe,this._applySmoke(p,0))}_tick(t){if(!this._active)return;const e=St(t,0,Ah);this._elapsed+=e;const s=Bn(this._elapsed,$.fire);for(this._flameAcc+=$.fire.rate*s*e/1e3;this._flameAcc>=1;)this._flameAcc-=1,this._spawnFlame(s);for(this._smokeAcc+=Mh(this._elapsed,$.fire,$.smoke)*e/1e3;this._smokeAcc>=1;)this._smokeAcc-=1,this._spawnSmoke(s);this._stepChannel(this._fire,e,n=>this._applyFire(n,e)),this._stepChannel(this._smoke,e,n=>this._applySmoke(n,e)),this._stepFlash(e),this._stepGlow(s),this._stepLight(s),this._stepScorch(e),this._elapsed>=bh($.fire,$.smoke)&&this._fire.size===0&&this._smoke.size===0&&!this._flash.visible&&this._scorchSettled()&&this._finish()}_stepChannel(t,e,s){const{items:n}=t;for(let o=n.length-1;o>=0;o-=1){const r=n[o];r.age+=e,r.age>=r.life?t.removeAt(o):s(r)}}_move(t,e){const s=Math.exp(-t.drag*e);return t.vx=t.windX+(t.vx-t.windX)*s,t.vy=t.windY+(t.vy-t.windY)*s,t.x+=t.vx*e,t.y+=t.vy*e,t.age/t.life}_applyFire(t,e){const s=e/1e3,n=this._move(t,s),o=t.view;if(t.kind==="spark"){const{colors:r}=$.sparks;t.scaleX=t.size0*(1-zh*n),t.scaleY=t.width,o.rotation=Math.atan2(t.vy,t.vx),o.tint=Ae(r[0],r[1],n),o.alpha=1-n}else{const r=1-(1-n)*(1-n),a=t.size0*(1+(t.grow-1)*r);t.scaleX=a*t.aspectX,t.scaleY=a*t.aspectY,t.h=t.rise*r,o.rotation+=t.spin*s,o.tint=Sh($.fire.ramp,n),o.alpha=t.alpha*(1-n*n)}}_applySmoke(t,e){const s=e/1e3,n=this._move(t,s),o=t.view,r=t.size0*(1+(t.grow-1)*(1-(1-n)**3));t.scaleX=r*t.aspectX,t.scaleY=r*t.aspectY,t.h=t.rise*(1-(1-n)*(1-n)),o.rotation+=t.spin*s,o.alpha=kh(n,t.alpha)}_stepFlash(t){const e=this._flash;if(!e.visible)return;const{duration:s,startSize:n,endSize:o,alpha:r}=$.flash;this._flashAge+=t;const a=this._flashAge/s;if(a>=1){e.visible=!1;return}const l=rt(n,o,1-(1-a)*(1-a))*this._sizeScale;e.scale.set(l*this._fireUnit),e.alpha=r*(1-a)*(1-a)}_stepGlow(t){const e=this._glow,s=$.glow;e.visible=t>0,e.visible&&(e.position.set(this._x,this._y),e.scale.set(s.size*this._sizeScale*this._fireUnit),e.tint=s.color,e.alpha=s.alpha*t*fe(this._seed,this._elapsed,s.flicker))}_stepLight(t){if(!this._light)return;if(t<=0){this._removeLight();return}const e=yt.wreckFire;this._lighting.updateLight(this._light,{x:this._x,y:this._y,z:this._z,level:this._level,levels:Sn(this._physLevel,this._z,this._vz!==0),intensity:e.intensity*t*fe(this._seed+1,this._elapsed,e.flicker)})}_stepScorch(t){this._scorch?.step(t)}_scorchSettled(){return!this._scorchPending&&(!this._scorch||this._scorch.settled)}_render(){const t=ut(this.parent,this._renderer),e=N.shear;if(this._active){const s=this._z*e;gt(this,t,s,1),this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._x,this._y,this._z),this.tint=this._levelView.tintFor(this._level));for(const n of[this._fire,this._smoke])for(const o of n.items){const r=Pe(o.x,o.y,t,s,s+o.h*e);o.view.x=r.x,o.view.y=r.y,o.view.scaleX=o.scaleX*r.scale,o.view.scaleY=o.scaleY*r.scale}}this._scorch?.render(t,this._levelView)}_finish(){this._stopTicker(),this._active=!1,this._flash.visible=!1,this._glow.visible=!1,this._removeLight(),this.visible=!1,this._scorch||(this.onRender=null)}_reset(){this._stopTicker(),this._fire&&(this._fire.clear(),this._smoke.clear(),this._flash.visible=!1,this._glow.visible=!1),this._removeLight(),this._soundId!==null&&(this._soundManager?.releaseSound(this._soundId),this._soundId=null),this._scorch?.destroy(),this._scorch=null,this._scorchPending=!1,this._active=!1,this.visible=!1,this.onRender=null}_stopTicker(){this._tickListener&&(J.shared.remove(this._tickListener),this._tickListener=null)}_removeLight(){this._light&&(this._lighting.removeLight(this._light),this._light=null)}destroy(t){this._reset(),super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}const Rh={Map:ba,MapRadar:Ta,TankRadar:Ca,Tank:El,Bomb:Il,ExplosionEffect:Kl,Smoke:jl,Tracks:Jl,Dust:nh,ShotEffect:xh,WreckFire:Ih};function Xt(i,t,{blur:e,quality:s=10,width:n,height:o}){const r=new Ps({strength:e,quality:s});r.padding=Cn(e),t.filters=[r];const a=i.generateTexture({target:t,frame:new nt(0,0,n,o)});return t.destroy(!0),r.destroy(),a}function ve(i,t){const{radius:e,blur:s,color:n,quality:o=40}=i,r=new V,a=(e+Tt(s))*2,l=a/2;return r.circle(l,l,e),r.fill(n),{texture:Xt(t,r,{blur:s,quality:o,width:a,height:a}),contentSize:e*2}}function Fh(i,t){const{baseRadius:e,irregularity:s=0,blur:n=0,numPoints:o=20,colorFill:r,colorRim:a=r,rimWidth:l=0,variants:h=1}=i,u=Math.max(1,Math.floor(h)||1),c=(e+s+l)*2,d=c+Tt(n)*2,f=d/2,p=[];for(let _=0;_<u;_+=1){const m=new V,g=[];for(let y=0;y<o;y+=1){const S=y/o*Math.PI*2,b=e+F(-s,s);g.push(f+b*Math.cos(S),f+b*Math.sin(S))}m.poly(g).fill(r).stroke({width:l,color:a,alignment:1}),p.push(Xt(t,m,{blur:n,width:d,height:d}))}return{textures:p,contentSize:c}}function wt(i,t,e){const s=Math.hypot(i,t,e)||1,n=o=>Math.round((o/s*.5+.5)*255);return n(i)<<16|n(t)<<8|n(e)}const re=wt(0,0,1);function Un(i,{x:t,y:e,w:s,h:n},{l:o,r,t:a,b:l},h){i.poly([t,e,t+s,e,t+s-r,e+a,t+o,e+a]).fill(h.t),i.poly([t,e+n,t+s,e+n,t+s-r,e+n-l,t+o,e+n-l]).fill(h.b),i.poly([t,e,t+o,e+a,t+o,e+n-l,t,e+n]).fill(h.l),i.poly([t+s,e,t+s-r,e+a,t+s-r,e+n-l,t+s,e+n]).fill(h.r)}function Hn(i,t,e,s){const n=t.length/2;for(let o=0;o<n;o+=1){const r=(o+1)%n,a=t[o*2],l=t[o*2+1],h=t[r*2],u=t[r*2+1];let c=u-l,d=-(h-a);c*(a+h)+d*(l+u)<0&&(c=-c,d=-d),i.poly([a,l,h,u,h*e,u*e,a*e,l*e]).fill(s(c,d))}}const at=10,je=at*4,Qe=at*3,Dh=13158852,tt={x:-je/2,y:-Qe/2,w:je,h:Qe},he={x:-18,y:-9,w:36,h:18},Wn={l:2,r:4,t:2,b:2},Xh=[{x:-19,y:-14,w:38,h:5},{x:-19,y:9,w:38,h:5}],Je=[1.33,-.42,.42,-1,-.42,-1,-1.33,-.42,-1.33,.42,-.42,1,.42,1,1.33,.42].map(i=>i*at),Gn=.6,Ke={x:.25*at,y:-.25*at,w:2.08*at},Te={x:2.1*at,y:-.36*at,w:.35*at,h:.72*at},ds={x:-.45*at,y:.35*at,r:.28*at},Ms={width:.08*at},Yh=.55;function Kn(i){i.rect(tt.x,tt.y,tt.w,tt.h).fill(5592405);for(const t of Xh){i.rect(t.x,t.y,t.w,t.h).fill(3947580);for(let e=t.x+1;e<t.x+t.w;e+=3)i.rect(e,t.y,1,t.h).fill(2763306)}i.rect(he.x,he.y,he.w,he.h).fill(Dh),Un(i,he,Wn,{l:11119269,r:11974578,t:11119269,b:11119269});for(let t=-6;t<=5;t+=3)i.rect(-15,t,4,1).fill(7829619)}function bs(i,t){const e={...Ms,color:Jt(t,Yh)},s={width:.06*at,color:e.color};i.poly(Je).fill(t).stroke(e),Hn(i,Je,Gn,()=>Jt(t,.8)),i.circle(ds.x,ds.y,ds.r).fill(Jt(t,.65)).stroke(s),i.rect(Ke.x,Ke.y,Ke.w,2.5*2).fill(t).stroke(e),i.rect(Te.x,Te.y,Te.w,Te.h).fill(Jt(t,.7)).stroke(s)}const Se={width:je,height:Qe};function Oh(i,t){const{colors:e}=i,s={},n=Kn,o=bs,r=f=>{f.rect(tt.x,tt.y,tt.w,tt.h).fill(re),f.rect(tt.x,tt.y,tt.w,1).fill(wt(0,-1,1)),f.rect(tt.x,tt.y+tt.h-1,tt.w,1).fill(wt(0,1,1)),f.rect(tt.x,tt.y+1,1,tt.h-2).fill(wt(-1,0,1)),f.rect(tt.x+tt.w-1,tt.y+1,1,tt.h-2).fill(wt(1,0,1)),Un(f,he,Wn,{l:wt(-1,0,1),r:wt(1,0,2),t:wt(0,-1,1),b:wt(0,1,1)})},a=f=>{f.poly(Je).fill(re).stroke({...Ms,color:re}),Hn(f,Je,Gn,(_,m)=>wt(_,m,1));const p=({x:_,y:m,w:g,h:y},S)=>{f.rect(_,m,g,y).fill(re).stroke({...S,color:re}),f.rect(_,m,g,y/2).fill(wt(0,-1,1)),f.rect(_,m+y/2,g,y/2).fill(wt(0,1,1))};p({...Ke,h:2.5*2},Ms),p(Te,{width:.06*at})},l=(f,p)=>{const _=new V;f(_);const m=t.generateTexture({target:_,frame:p});return _.destroy(!0),m},h=f=>{const p=new V;f(p);const _=p.getBounds();return p.destroy(!0),new nt(_.x,_.y,_.width,_.height)},u=f=>{const p=h(n),_=h(g=>o(g,f)),m={x:-_.x/_.width,y:-_.y/_.height};return{body:l(n,p),bodyNormal:l(r,p),gun:l(g=>o(g,f),_),gunNormal:l(a,_),gunAnchor:m}},c=()=>{const f=new G,p=new V,_=new V;f.addChild(p,_);const m=3815994,g=2434341,y=3158064,S=1579032,b=5263440,v=je,M=Qe,w=at;p.moveTo(-v/2-w*.1,-M/2+w*.2).lineTo(v/2+w*.2,-M/2-w*.1).lineTo(v/2-w*.1,M/2+w*.3).lineTo(-v/2+w*.3,M/2-w*.2).closePath().fill(m).stroke({width:w*.2,color:b,alignment:.5}),p.moveTo(-v/2+w*.4,-M/2+w*.5).lineTo(v/2-w*.3,-M/2+w*.2).lineTo(v/2-w*.4,M/2-w*.1).lineTo(-v/2+w*.2,M/2-w*.4).closePath().fill(g),p.circle(v*.15,M*.1,w*1.2).fill(S),p.circle(-v*.3,-M*.25,w*.5).fill(S),_.position.set(w*.3,-w*.2);const C=[w*1.1,-w*.7,w*.2,-w*1,-w*.6,-w*.9,-w*1.3,-w*.2,-w*1.1,w*.6,-w*.2,w*1,w*.7,w*.8,w*1.3,w*.1];_.poly(C).fill(y).stroke({width:w*.15,color:b,alignment:0});const A=[w*.8,-w*.25,w*1.5,-w*.4,w*1.4,w*.15,w*.7,w*.05];_.poly(A).fill(y).stroke({width:w*.1,color:b,alignment:0}),_.circle(w*.1,-w*.2,w*.4).fill(S);const L=f.getBounds(),R=t.generateTexture({target:f,frame:new nt(L.x,L.y,L.width,L.height)});f.destroy({children:!0});const Y=new V().rect(L.x,L.y,L.width,L.height).fill(re),I=t.generateTexture({target:Y,frame:new nt(L.x,L.y,L.width,L.height)});return Y.destroy(!0),{texture:R,normal:I}};s.liveTeamId1=u(e.teamId1),s.liveTeamId2=u(e.teamId2);const d=c();return s.destroyed=d.texture,s.destroyedNormal=d.normal,s}const ct=2;function Vh(i,{x:t,y:e,w:s,h:n}){i.rect(t,e,s,n).fill(3026478),i.rect(t,e,s,1).fill(3947580);const o=Math.max(1,n*.38);for(let r=t+o+1;r<t+s-o;r+=o*2.6)i.circle(r,e+n*.58,o).fill(4868682),i.circle(r,e+n*.58,o*.4).fill(2236962)}function Vi(i,{x:t,y:e,w:s,h:n},o){i.rect(t,e,s,n).fill(Jt(o,.75)),n>2&&i.rect(t,e+1,s,n-2).fill(o)}function Bh(i,t,e=bt){const{colors:s}=i,n=(o,r=!1)=>{const a=new V;bs(a,o);const l=a.getBounds();a.destroy(!0);const h=Math.ceil(l.width),u=Math.ceil(l.height),c={x:ct,y:ct,w:Se.width,h:Se.height,originX:ct+Se.width/2,originY:ct+Se.height/2},d={x:c.x+c.w+ct,y:ct,w:h,h:u,originX:c.x+c.w+ct-l.x,originY:ct-l.y},f=ct+Math.max(c.h,d.h)+ct,p={x:ct,y:f,w:Se.width,h:e.trackHeight},_={x:p.x+p.w+ct,y:f,w:22,h:e.barrelRadius*2},m={x:_.x+_.w+ct,y:f,w:8,h:e.brakeRadius*2},g={x:m.x+m.w+ct,y:f,w:4,h:4},y=Math.max(d.x+d.w,g.x+g.w)+ct,S=f+Math.max(p.h,_.h,m.h,g.h)+ct,b=new G,v=new V,M=new V,w=new V;if(Kn(v),v.position.set(c.originX,c.originY),bs(M,o),M.position.set(d.originX,d.originY),Vh(w,p),Vi(w,_,o),Vi(w,m,Jt(o,.7)),w.rect(g.x,g.y,g.w,g.h).fill(1710618),b.addChild(v,M,w),r){const A=new V;for(const L of[c,d,p,_,m])A.rect(L.x,L.y,L.w,L.h).fill({color:789e3,alpha:.62});A.circle(c.originX+4,c.originY+2,6).fill({color:0,alpha:.5}),A.circle(c.originX-9,c.originY-4,3).fill({color:0,alpha:.5}),A.circle(d.originX-2,d.originY+1,4).fill({color:0,alpha:.5}),b.addChild(A)}const C=t.generateTexture({target:b,frame:new nt(0,0,y,S)});return b.destroy({children:!0}),{texture:C,width:y,height:S,regions:{body:c,gun:d,trackSide:p,barrelSide:_,brakeSide:m,bottom:g}}};return{liveTeamId1:n(s.teamId1),liveTeamId2:n(s.teamId2),destroyed:n(3815994,!0)}}function Nh(i,t){const{radius:e,borderWidth:s,crossSize:n,crossThickness:o,colors:r}=i,a={},l=(e+s)*2,h=l/2,u=15658734,c=3355443,d=p=>{const _=new V;_.circle(h,h,e).fill(u),_.circle(h,h,e-s).fill(p);const m=t.generateTexture({target:_,frame:new nt(0,0,l,l)});return _.destroy(!0),m},f=()=>{const p=new V,_=n/2;p.moveTo(h-_,h-_).lineTo(h+_,h+_).moveTo(h-_,h+_).lineTo(h+_,h-_).stroke({width:o,color:c});const m=t.generateTexture({target:p,frame:new nt(0,0,l,l)});return p.destroy(!0),m};return a.liveTeamId1=d(r.teamId1),a.liveTeamId2=d(r.teamId2),a.destroyed=f(),a}function Uh(i,t){const{colorOuter:e,colorInner:s}=i,n=new V,o=20,r=1;n.rect(0,0,o,o).fill(e),n.rect(r,r,o-r*2,o-r*2).fill(s);const a=t.generateTexture({target:n,frame:new nt(0,0,o,o)});return n.destroy(!0),a}function Hh(i,t){const{width:e,length:s,color:n}=i,o=new V;o.rect(0,0,s,e).fill(n);const r=t.generateTexture({target:o,frame:new nt(0,0,s,e)});return o.destroy(!0),r}function Wh(i,t){const{width:e,height:s,radius:n,blur:o,color:r,quality:a=20}=i,l=new V,h=Tt(o),u=e+h*2,c=s+h*2;return l.roundRect(h,h,e,s,n),l.fill(r),{texture:Xt(t,l,{blur:o,quality:a,width:u,height:c}),contentSize:e}}function Bi(i,t){const{baseRadius:e,irregularity:s=0,blur:n=0,numPoints:o=16,color:r,coreColor:a=r,coreRatio:l=.5,variants:h=1}=i,u=Math.max(1,Math.floor(h)||1),c=(e+s)*2,d=c+Tt(n)*2,f=d/2,p=[],_=(m,g)=>{const y=[];for(let S=0;S<o;S+=1){const b=S/o*Math.PI*2,v=m+F(-g,g);y.push(f+v*Math.cos(b),f+v*Math.sin(b))}return y};for(let m=0;m<u;m+=1){const g=new V;g.poly(_(e,s)).fill(r).poly(_(e*l,s*l)).fill(a),p.push(Xt(t,g,{blur:n,width:d,height:d}))}return{textures:p,contentSize:c}}function Gh(i,t){const{length:e,width:s,color:n,variants:o=1}=i,r=Math.max(1,Math.floor(o)||1),a=e/2,l=[];for(let h=0;h<r;h+=1){const u=new V,c=F(s*.3,s)/2,d=F(s*.1,s*.6)/2;u.poly([0,a-d,e,a-c,e,a+c,0,a+d]).fill(n),l.push(t.generateTexture({target:u,frame:new nt(0,0,e,e)})),u.destroy(!0)}return{textures:l,contentSize:e}}function $n(i,t,e,s,n){for(let o=0;o<s;o+=1){const r=e*o/s,a=e*(o+1)/s,l=n((o+.5)/s);l<=0||(i.circle(t,t,a),i.fill({color:16777215,alpha:l}),r>0&&(i.circle(t,t,r),i.cut()))}}function Ni(i,t){const{radius:e,rings:s=32,blur:n=2,quality:o=10}=i,r=new V,a=Tt(n),l=(e+a)*2,h=l/2;return $n(r,h,e,s,bn),{texture:Xt(t,r,{blur:n,quality:o,width:l,height:l}),contentSize:e*2}}function Kh(i,t){const{length:e,halfWidth:s,strips:n=24,blur:o=4,quality:r=10}=i,a=new V,l=Tt(o),h=e+l*2,u=(s+l)*2,c=l,d=u/2;for(let p=0;p<n;p+=1){const _=e*p/n,m=e*(p+1)/n,g=s*p/n,y=s*(p+1)/n,S=(p+.5)/n,b=kn(S);a.poly([c+_,d-g,c+m,d-y,c+m,d+y,c+_,d+g]),a.fill({color:16777215,alpha:b})}return{texture:Xt(t,a,{blur:o,quality:r,width:h,height:u}),length:e,halfWidth:s,margin:l}}function $h(i,t){const{core:e,halo:s,rings:n=12,blur:o=1,quality:r=10}=i,a=new V,l=Tt(o),h=(s+l)*2,u=h/2,c=e/s;return $n(a,u,s,n,f=>f<=c?1:.6*(1-(f-c)/(1-c))**2),{texture:Xt(t,a,{blur:o,quality:r,width:h,height:h}),contentSize:s*2}}function Zh(i,t){const{radius:e,strips:s=16,blur:n=2,quality:o=10}=i,r=new V,a=Tt(n),l=(e+a)*2,h=l/2;for(let c=0;c<s;c+=1){const d=e*c/s,f=e*(c+1)/s,p=(c+.5)/s;r.rect(h+d,h-e,f-d,e*2),r.fill({color:16777215,alpha:p*p})}return{texture:Xt(t,r,{blur:n,quality:o,width:l,height:l}),contentSize:e*2}}function qh(i){let t=i>>>0;return()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}function jh(i,t){const{radius:e,rays:s=14,width:n=.05,strips:o=8,seed:r=1,blur:a=3,quality:l=10}=i,h=new V,u=Tt(a),c=(e+u)*2,d=c/2,f=qh(r);for(let _=0;_<s;_+=1){const m=(_+(f()-.5)*.8)/s*Math.PI*2,g=e*(.55+.45*f()),y=.35+.65*f(),S=n*(.5+f()),b=Math.cos(m-S),v=Math.sin(m-S),M=Math.cos(m+S),w=Math.sin(m+S);for(let C=0;C<o;C+=1){const A=g*C/o,L=g*(C+1)/o,R=(C+.5)/o;h.poly([d+b*A,d+v*A,d+b*L,d+v*L,d+M*L,d+w*L,d+M*A,d+w*A]),h.fill({color:16777215,alpha:y*(1-R)})}}return{texture:Xt(t,h,{blur:a,quality:l,width:c,height:c}),contentSize:e*2}}const Qh=64,_s=1053978,Ui=50*Math.PI/180;function Jh(i,t){const e=i.pixelSize??Qh,s=new nt(0,0,e,e),n=f=>{const p=t.generateTexture({target:f,frame:s});return f.destroy(!0),p},o=new V,r=e*.42,a=e*.62,l=(e-r)/2,h=e*.3,u=e/16;o.roundRect(e*.58,e*.06,e*.08,e*.28,e*.03).fill(i.color).stroke({width:u,color:_s}),o.roundRect(l,h,r,a,e*.08).fill(i.color).stroke({width:u,color:_s}),o.rect(l+r*.18,h+a*.12,r*.64,a*.24).fill(_s);const c=new V,d=e*.38;return c.arc(e/2,e/2,d,-Ui,Ui).stroke({width:d/3,color:16777215,cap:"round"}),{icon:n(o),arc:n(c)}}function tc(i,t){const{radius:e,width:s}=i,n=(e+s)*2,o=n/2,r=new V;r.circle(o,o,e).stroke({width:s,color:16777215});const a=t.generateTexture({target:r,frame:new nt(0,0,n,n)});return r.destroy(!0),{ring:a}}const ec={explosionTexture:ve,smokeTexture:ve,impactParticleTexture:ve,dustTexture:ve,wreckSmokeTexture:ve,wreckFireTexture:Ni,wreckScorchTexture:Bi,tankShadowTexture:Wh,funnelTexture:Fh,tankTexture:Oh,tankModelTexture:Bh,tankRadarTexture:Nh,bombTexture:Uh,trackMarkTexture:Hh,scorchTexture:Bi,debrisTexture:Gh,lightRadialTexture:Ni,headlightConeTexture:Kh,lampHeadTexture:$h,glintTexture:Zh,lightShaftTexture:jh,radioBadgeTexture:Jh,radarPingTexture:tc},sc=i=>(i??"").split(/[?#]/)[0].endsWith(".js"),ic=i=>import(i);function nc(i=Ao,t={}){const e={level:0,x:0,y:0,z:0,camera:null,key:null,stage:t.stage||null,renderer:t.renderer||null,warned:!1,diagnostics:null},s=()=>{if(e.warned)return;e.warned=!0;const o=e.stage,r=e.renderer?.screen,a={destroyed:o?o.destroyed:null,position:o?{x:o.position?.x,y:o.position?.y}:null,scale:o?{x:o.scale?.x,y:o.scale?.y}:null,screen:r?{width:r.width,height:r.height}:null};console.warn("[tanks] levelView: центра камеры нет — кадр без трансформа сцены",a),e.diagnostics?.warn("tanks.camera.missing",a)},n=()=>{if(!e.stage)return null;if(e.stage.destroyed)return s(),null;const{position:o,scale:r}=e.stage,a=e.renderer?.screen,l=a?a.width:0,h=a?a.height:0,u=e.key;return(e.camera===null||u===null||u.x!==o.x||u.y!==o.y||u.scaleX!==r.x||u.scaleY!==r.y||u.width!==l||u.height!==h)&&(e.key={x:o.x,y:o.y,scaleX:r.x,scaleY:r.y,width:l,height:h},e.camera=ut(e.stage,e.renderer),e.camera===null&&s()),e.camera};return{attachStage(o,r){!o||!r||e.stage&&!e.stage.destroyed||(e.stage=o,e.renderer=r,e.key=null,e.camera=null)},setDiagnostics(o){!e.diagnostics&&o&&(e.diagnostics=o)},camera(){return n()},set(o,r,a,l=0){e.level=o,e.x=r,e.y=a,e.z=l},alphaFor(o,r,a,l=o){const h=n(),u=mt(e.x,e.y,h,e.z*N.shear),c=mt(r,a,h,l*N.shear);return Do({viewLevel:e.level,viewX:u.x,viewY:u.y,level:o,x:c.x,y:c.y,cfg:i})},tintFor(o){return Xo(e.level,o,i)},get cfg(){return i},get mode(){return i.mode},get level(){return e.level},get x(){return e.x},get y(){return e.y},get z(){return e.z}}}function Fs(i,t,e){const s=i.axis===0;return{alongX:s,a0:s?i.col0*t:i.row0*e,a1:s?i.col1*t:i.row1*e,b0:s?i.row0*e:i.col0*t,b1:s?i.row1*e:i.col1*t}}function Zn(i,t){const e=i.sign>0?t:1-t;return i.from+(i.to-i.from)*e}function oc(i,t,e,s,n,o){const{alongX:r,a0:a,a1:l,b0:h,b1:u}=Fs(i,t*e.x,t*e.y),c=(g,y)=>r?[g,y]:[y,g],d=r?i.col1-i.col0:i.row1-i.row0,f=Math.max(1,d*Math.max(1,Math.round(o)||1)),p=(g,y,S)=>[g+(g-s.x)*S,y+(y-s.y)*S],_=[],m=[];for(let g=0;g<=f;g+=1){const y=g/f,S=Zn(i,y)*n,b=a+(l-a)*y;_.push(p(...c(b,h),S)),m.push(p(...c(b,u),S))}return[..._,...m.reverse()].flat()}function Ds(i,t,e,s,n,o,r,a){let l=Math.floor(i/r),h=Math.floor(t/a);if(o(l,h,null,null,i,t))return 0;const u=e>0?1:-1,c=s>0?1:-1,d=e!==0?Math.abs(r/e):1/0,f=s!==0?Math.abs(a/s):1/0;let p=1/0,_=1/0;for(e!==0&&(p=((e>0?l+1:l)*r-i)/e),s!==0&&(_=((s>0?h+1:h)*a-t)/s);;){const m=l,g=h;let y;if(p<_?(y=p,l+=u,p+=d):(y=_,h+=c,_+=f),!(y<n))return n;if(o(l,h,m,g,i+e*y,t+s*y))return Math.max(0,y)}}const rc=.2;function Xs(i,t,e,s,n){const{alongX:o,a0:r,a1:a}=Fs(i,s,n),l=o?t:e,h=a-r||1,u=Math.min(1,Math.max(0,(l-r)/h));return Zn(i,u)}function ac({lane:i,prevLane:t,col:e,row:s,prevCol:n,prevRow:o,x:r,y:a,z:l,cellW:h,cellH:u,clearance:c=rc}){if(t&&t!==i){const p=t.axis===0?s!==o:e!==n;return!!i||!p}return!i||t===i||n===null||n===void 0||(i.axis===0?e-n:s-o)===i.sign?!1:Xs(i,r,a,h,u)-(l||0)>c}function Hi(i,t,e,s,n,o,r){if(!i)return!1;const a=Math.max(0,s),l=Math.min(t-1,o),h=Math.max(0,n),u=Math.min(e-1,r);for(let c=h;c<=u;c+=1){const d=c*t;for(let f=a;f<=l;f+=1)if(i[d+f]!==0)return!0}return!1}function lc(i,t,e,s,n,o,r,a){const l=Ds(i,t,e,s,n,o,r,a);return l>=n?null:{distance:l,x:i+e*l,y:t+s*l}}function hc({x:i,y:t,rotation:e,alongMax:s,alongBack:n=0,acrossMax:o,rays:r},a,l,h){const u=Math.max(2,Math.round(r)||2),c=n>0,d=c?Math.max(3,Math.round(u/8)):0,f=[];for(let g=0;g<u;g+=1)f.push(-Math.PI/2+Math.PI*g/(u-1));for(let g=0;g<d;g+=1)f.push(Math.PI/2+Math.PI*(g+1)/(d+1));const p=new Float32Array((f.length+1)*2),_=new Float32Array(f.length);let m=!1;return p[0]=i,p[1]=t,f.forEach((g,y)=>{const S=e+g,b=Math.cos(S),v=Math.sin(S),M=Math.cos(g),w=Math.abs(Math.sin(g));let C=w>1e-9?o/w:1/0;M>1e-9?C=Math.min(C,s/M):M<-1e-9&&(C=Math.min(C,n/-M));const A=Ds(i,t,b,v,C,a,l,h);_[y]=C,A<C-1e-6&&(m=!0),p[(y+1)*2]=i+b*A,p[(y+1)*2+1]=t+v*A}),{points:p,clipped:m,closed:c,reaches:_,forward:u}}function Ys(i,t){const{width:e,height:s}=t.texture;if(i.kind==="cone")return{x:i.x,y:i.y,rotation:i.rotation||0,sx:i.radius/t.length,sy:i.radius*(i.spread??.5)/t.halfWidth,margin:t.margin,width:e,height:s};const n=i.radius*2/t.contentSize;return{x:i.x,y:i.y,rotation:0,sx:n,sy:n,margin:e/2,width:e,height:s}}function Os(i,t,{x:e,y:s,rotation:n,sx:o,sy:r,margin:a,width:l,height:h},u=Math.cos(n),c=Math.sin(n)){const d=i-e,f=t-s,p=d*u+f*c,_=f*u-d*c;return[(a+p/o)/l,(h/2+_/r)/h]}function cc(i,t){const e=Math.cos(t.rotation),s=Math.sin(t.rotation),n=new Float32Array(i.length);for(let o=0;o<i.length;o+=2){const[r,a]=Os(i[o],i[o+1],t,e,s);n[o]=r,n[o+1]=a}return n}const uc=[0,1,3,0,3,2];function fc({x:i,y:t,points:e,reaches:s,forward:n,uvOf:o,wallAt:r,cellW:a,cellH:l,height:h,level:u=0}){const c=.01*Math.min(a,l),d=v=>{const M=e[v*2],w=e[v*2+1],C=Math.hypot(M-i,w-t),A=s[v-1];if(!(C>1e-9)||!(C<A-1e-6))return null;const L=(M-i)/C,R=(w-t)/C,Y=Vn(M,w,L,R,a,l,.001);if(!Y)return null;const I=r(M+L*c,w+R*c);return I>0?{face:Y,x:M,y:w,endX:M+L*(A-C),endY:w+R*(A-C),height:Math.min(h,I)}:null},f=[];for(let v=1;v<=n;v+=1)f.push(d(v));const p=[];for(let v=0;v+1<f.length;v+=1){const M=f[v],w=f[v+1];M&&w&&M.face.axis===w.face.axis&&Math.abs(M.face.coord-w.face.coord)<1e-6&&p.push([M,w])}if(!p.length)return null;const _=new Float32Array(p.length*8),m=new Float32Array(p.length*4),g=new Float32Array(p.length*8),y=new Uint32Array(p.length*6),S=new Float32Array(p.length*2),b=new Float32Array(p.length*2);return p.forEach(([v,M],w)=>{[[v.x,v.y,v.height,v.endX,v.endY],[M.x,M.y,M.height,M.endX,M.endY],[v.x,v.y,0,v.x,v.y],[M.x,M.y,0,M.x,M.y]].forEach(([A,L,R,Y,I],D)=>{const X=w*4+D,[U,O]=o(Y,I);_[X*2]=A,_[X*2+1]=L,m[X]=u+R,g[X*2]=U,g[X*2+1]=O});for(let A=0;A<6;A+=1)y[w*6+A]=w*4+uc[A];S[w*2]=v.face.nx,S[w*2+1]=v.face.ny,b[w*2]=(v.x+M.x)/2,b[w*2+1]=(v.y+M.y)/2}),{base:_,heights:m,uvs:g,indices:y,normals:S,mids:b}}function qn(i,t=!1){const e=Math.max(0,i-1),s=new Uint32Array((e+(t&&i>2?1:0))*3);for(let n=0;n<e;n+=1)s[n*3]=0,s[n*3+1]=n+1,s[n*3+2]=n+2;return t&&i>2&&(s[e*3]=0,s[e*3+1]=i,s[e*3+2]=1),s}function ae(i,t,e,s){const n=[];for(let o=0;o<i.length;o+=1){const r=i[o],a=i[(o+1)%i.length],l=s?r[t]>=e:r[t]<=e,h=s?a[t]>=e:a[t]<=e;if(l&&n.push(r),l!==h){const u=(e-r[t])/(a[t]-r[t]);n.push([r[0]+(a[0]-r[0])*u,r[1]+(a[1]-r[1])*u])}}return n}function dc({points:i,closed:t,lane:e,frame:s,cellW:n,cellH:o,segmentsPerCell:r}){const{alongX:a,a0:l,a1:h,b0:u,b1:c}=Fs(e,n,o),d=I=>a?[i[I*2],i[I*2+1]]:[i[I*2+1],i[I*2]],f=i.length/2;let p=1/0,_=-1/0,m=1/0,g=-1/0;for(let I=0;I<f;I+=1){const[D,X]=d(I);p=Math.min(p,D),_=Math.max(_,D),m=Math.min(m,X),g=Math.max(g,X)}if(!(_>l&&p<h&&g>u&&m<c))return null;const y=a?e.col1-e.col0:e.row1-e.row0,S=Math.max(1,y*Math.max(1,Math.round(r)||1)),b=(h-l)/S,v=Math.cos(s.rotation),M=Math.sin(s.rotation),w=[],C=[],A=[],L=[],R=I=>{const D=C.length;for(const[X,U]of I){const O=a?X:U,K=a?U:X,[j,W]=Os(O,K,s,v,M);w.push(O,K),C.push(Xs(e,O,K,n,o)),A.push(j,W)}for(let X=1;X+1<I.length;X+=1)L.push(D,D+X,D+X+1)},Y=qn(f-1,t);for(let I=0;I<Y.length;I+=3){let D=[d(Y[I]),d(Y[I+1]),d(Y[I+2])];if(D=ae(D,1,u,!0),D=ae(D,1,c,!1),D=ae(D,0,l,!0),D=ae(D,0,h,!1),D.length<3)continue;const X=Math.min(...D.map(([j])=>j)),U=Math.max(...D.map(([j])=>j)),O=Math.max(0,Math.floor((X-l)/b)),K=Math.min(S-1,Math.ceil((U-l)/b)-1);for(let j=O;j<=K;j+=1){const W=ae(ae(D,0,l+j*b,!0),0,l+(j+1)*b,!1);W.length>=3&&R(W)}}return L.length?{base:new Float32Array(w),heights:new Float32Array(C),uvs:new Float32Array(A),indices:new Uint32Array(L)}:null}const Be=16777215;class Wi{constructor({level:t,ambient:e,resolution:s,area:n,roof:o=!1}){this.level=t,this.ambient=e,this.roof=o,this.overlay=new G,this.overlay.label=o?`lighting-roof-${t}`:`lighting-${t}`,this.overlay.zIndex=H(lr,t),this.overlay.eventMode="none",this.base=new Z(Ze.WHITE),this.base.tint=t===0?e:Be,this.base.position.set(n.x,n.y),this.base.width=n.width,this.base.height=n.height,this.overlay.addChild(this.base),this.mask=t>=1?new V:null,this.mask&&this.overlay.addChild(this.mask),this.lights=new G,this.overlay.addChild(this.lights),this.rampLights=new G,this.overlay.addChild(this.rampLights),this.rampMask=null,this.lightsMask=null,this.ramps=[],this.rampLightPool=[],this.shafts=new G,this.overlay.addChild(this.shafts),this.shaftPool=[],this.tops=new G,this.overlay.addChild(this.tops),this.topGroups=[],this.pool=[],this.fanPool=[],this.washPool=[],this.filter=new nn({alpha:1}),this.filter.resolution=s,this.filter.blendMode="multiply",this.overlay.filters=[this.filter],this.overlay.filterArea=new nt(n.x,n.y,n.width,n.height),this.resolution=s,this.hole=xs(),this.hasMask=!1}setMask(t,e,s){if(this.mask){this.mask.clear(),this.hasMask=t.length>0;for(const n of t)this.mask.rect(n.col*e*s.x,n.row*e*s.y,n.length*e*s.x,e*s.y);this.hasMask&&this.mask.fill(this.ambient)}}setTops(t,e,s){for(const n of this.topGroups)n.graphics.destroy();this.topGroups=[];for(const{volume:n,runs:o}of t){if(!o.length)continue;const r=new V;for(const a of o)r.rect(a.col*e*s.x,a.row*e*s.y,a.length*e*s.x,e*s.y);r.fill(this.ambient),this.tops.addChild(r),this.topGroups.push({graphics:r,volume:n})}}setRamps(t,e,s,n){this.ramps=t,this.rampGeometry={step:e,scale:s,segments:n},t.length&&!this.rampMask?(this.rampMask=new V,this.lightsMask=new V,this.overlay.addChild(this.rampMask,this.lightsMask),this.rampLights.mask=this.rampMask,this.lights.setMask({mask:this.lightsMask,inverse:!0})):!t.length&&this.rampMask&&(this.rampLights.mask=null,this.lights.mask=null,this.rampMask.destroy(),this.lightsMask.destroy(),this.rampMask=null,this.lightsMask=null)}rampLevels(){return new Set(this.ramps.map(t=>t.to))}place(t,e){if(this.mask&>(this.mask,t,this.level*e,1),this.rampMask){const{step:s,scale:n,segments:o}=this.rampGeometry;this.rampMask.clear(),this.lightsMask.clear();for(const r of this.ramps){const a=oc(r,s,n,t,e,o);this.rampMask.poly(a),this.lightsMask.poly(a)}this.rampMask.fill(Be),this.lightsMask.fill(Be)}for(const{graphics:s,volume:n}of this.topGroups)gt(s,t,(this.level+n)*e,1)}syncFilters(){this.hole.attached?(this.hole.filter.blendMode="multiply",this.hole.filter.resolution=this.resolution):this.overlay.filters?.[0]!==this.filter&&(this.overlay.filters=[this.filter])}layout(t){_c(this.pool,this.lights,t.filter(e=>!e.fan)),pc(this.fanPool,this.lights,t.filter(e=>e.fan))}layoutWashes(t,e,s){ks(this.washPool,this.lights,t.length);for(let n=0;n<this.washPool.length;n+=1){const o=this.washPool[n],r=t[n];if(!r){o.visible=!1;continue}const{wash:a}=r,l=o.geometry;o.wash!==a&&(l.positions=new Float32Array(a.base.length),l.uvs=a.uvs,l.indices=new Uint32Array(a.indices.length),o.wash=a,o.facing=new Int8Array(a.normals.length/2).fill(-1));const h=l.positions;Gi(h,a.base,a.heights,e,s),l.positions=h;const{normals:u,mids:c}=a,d=l.indices;let f=!1;for(let p=0;p<o.facing.length;p+=1){const _=e&&u[p*2]*(e.x-c[p*2])+u[p*2+1]*(e.y-c[p*2+1])>0?1:0;if(o.facing[p]!==_){o.facing[p]=_,f=!0;for(let m=0;m<6;m+=1)d[p*6+m]=_?a.indices[p*6+m]:p*4}}f&&(l.indices=d),As(o,r)}}layoutRampLights(t,e,s){ks(this.rampLightPool,this.rampLights,t.length);for(let n=0;n<this.rampLightPool.length;n+=1){const o=this.rampLightPool[n],r=t[n];if(!r){o.visible=!1;continue}const{ramp:a}=r,l=o.geometry;o.ramp!==a&&(l.positions=new Float32Array(a.base.length),l.uvs=a.uvs,l.indices=a.indices,o.ramp=a);const h=l.positions;Gi(h,a.base,a.heights,e,s),l.positions=h,As(o,r)}}layoutShafts(t){for(;this.shaftPool.length<t.length;){const e=new G,s=new Z,n=new V;s.anchor.set(.5),s.blendMode="add",e.addChild(s,n),this.shafts.addChild(e),this.shaftPool.push({container:e,sprite:s,shadow:n,masked:!1})}for(let e=0;e<this.shaftPool.length;e+=1){const s=this.shaftPool[e],n=t[e];if(!n){s.container.visible=!1;continue}const{container:o,sprite:r,shadow:a}=s,l=n.shadows||[];o.visible=!0,r.texture=n.texture,r.position.set(n.x,n.y),r.scale.set(n.scale),r.rotation=n.rotation,r.tint=n.color,r.alpha=n.alpha,a.clear();for(const u of l)a.poly(u);l.length&&a.fill(Be);const h=l.length>0;h!==s.masked&&(s.masked=h,h?o.setMask({mask:a,inverse:!0}):(o.mask=null,a.visible=!1)),h&&(a.visible=!0)}}destroy(){const t=this.overlay;t.parent?.removeChild(t),ys(this.hole,t),t.filters=[],this.filter.destroy();for(const e of this.pool)e.texture=null;for(const e of[...this.fanPool,...this.rampLightPool,...this.washPool])e.texture=Ze.EMPTY,e.geometry.destroy();this.pool=[],this.fanPool=[],this.rampLightPool=[],this.washPool=[],this.rampLights.mask=null,this.lights.mask=null,this.rampMask=null,this.lightsMask=null,this.ramps=[];for(const e of this.shaftPool)e.container.mask=null,e.sprite.texture=null;this.shaftPool=[],this.topGroups=[],t.destroy({children:!0,texture:!1,textureSource:!1})}}function jn(i,t){return i.levels.has(t)||i.roofLevels.has(t)}function ks(i,t,e){for(;i.length<e;){const s=new po({positions:new Float32Array(6),uvs:new Float32Array(6),indices:new Uint32Array(3)}),n=new sn({geometry:s,texture:Ze.EMPTY});n.blendMode="add",i.push(n),t.addChild(n)}}function As(i,t){i.visible=!0,i.texture=t.texture,i.tint=t.color,i.alpha=t.alpha}function Gi(i,t,e,s,n){for(let o=0;o<e.length;o+=1){const r=t[o*2],a=t[o*2+1],l=s?e[o]*n:0;i[o*2]=s?r+(r-s.x)*l:r,i[o*2+1]=s?a+(a-s.y)*l:a}}function _c(i,t,e){for(;i.length<e.length;){const s=new Z;s.blendMode="add",i.push(s),t.addChild(s)}for(let s=0;s<i.length;s+=1){const n=i[s],o=e[s];if(!o){n.visible=!1;continue}n.visible=!0,n.texture=o.texture,n.anchor.set(o.anchorX,o.anchorY),n.position.set(o.x,o.y),n.scale.set(o.scaleX,o.scaleY),n.rotation=o.rotation,n.tint=o.color,n.alpha=o.alpha}}function pc(i,t,e){ks(i,t,e.length);for(let s=0;s<i.length;s+=1){const n=i[s],o=e[s];if(!o){n.visible=!1;continue}const{fan:r}=o,{shape:a}=r;if(n.shape!==a){const l=n.geometry,h=a.points.length/2-1,u=`${h}:${!!a.closed}`;n.topology!==u&&(l.indices=qn(h,a.closed),n.topology=u),l.positions=a.points,l.uvs=a.uvs,n.shape=a}As(n,o),n.position.set(r.x,r.y),n.scale.set(r.scale)}}const mc=.6;function gc({getMap:i,cfg:t}){const e=new WeakMap;let s=0;const n=(f,p)=>{const _=i();_.blockers=new Map,_.rampCells=new Map,s+=1;const{cols:m,rows:g}=_;if(!(m>0&&g>0))return;const y=(S,b)=>S>=0&&S<m&&b>=0&&b<g;for(const[S,b]of f){let v=null;for(const{cells:M,volume:w}of b)for(const[C,A]of M)y(C,A)&&(v||=new Float32Array(m*g),v[A*m+C]=Math.max(v[A*m+C],w));v&&_.blockers.set(S,v)}for(const[S,b]of p){const v=[...b.values()].flat();if(!v.length)continue;const M=new Int32Array(m*g);v.forEach((w,C)=>{for(let A=w.row0;A<w.row1;A+=1)for(let L=w.col0;L<w.col1;L+=1)y(L,A)&&(M[A*m+L]=C+1)}),_.rampCells.set(S,{cells:M,lanes:v})}},o=f=>{const p=i(),_=f.level??0,m=p.blockers.get(_)||null,{cols:g,rows:y}=p,{cellW:S,cellH:b}=p,v=(A,L)=>A>=0&&A<g&&L>=0&&L<y?L*g+A:-1,M=p.rampCells.get(_)||null;if(!m&&!M)return null;const w=A=>M&&A>=0&&M.cells[A]>0?M.lanes[M.cells[A]-1]:null,C=w(v(Math.floor(f.x/S),Math.floor(f.y/b)));return(A,L,R,Y,I,D)=>{const X=v(A,L);if(m&&X>=0&&m[X]>0)return!0;if(!M||R===null||R===void 0)return!1;const U=w(X),O=w(v(R,Y));return C&&(U===C||O===C)?!1:ac({lane:U,prevLane:O,col:A,row:L,prevCol:R,prevRow:Y,x:I,y:D,z:f.z??_,cellW:S,cellH:b})}},r=(f,p,_,m,g)=>{const y=i(),S=f.level??0,{cols:b,rows:v}=y,{cellW:M,cellH:w}=y,C=Math.cos(p),A=Math.sin(p);let L=1/0,R=1/0,Y=-1/0,I=-1/0;for(const K of[-m,_])for(const j of[-g,g]){const W=f.x+K*C-j*A,xt=f.y+K*A+j*C;L=Math.min(L,W),R=Math.min(R,xt),Y=Math.max(Y,W),I=Math.max(I,xt)}const D=Math.floor(L/M)-1,X=Math.floor(R/w)-1,U=Math.floor(Y/M)+1,O=Math.floor(I/w)+1;return Hi(y.blockers.get(S),b,v,D,X,U,O)||Hi(y.rampCells.get(S)?.cells,b,v,D,X,U,O)},a=()=>t.headlights?.occlusion,l=(f,p,_)=>{const m=i(),g=m.blockers.get(f),y=Math.floor(p/m.cellW),S=Math.floor(_/m.cellH);return!g||y<0||y>=m.cols||S<0||S>=m.rows?0:g[S*m.cols+y]},h=(f,p,_)=>{const m=i(),g=m.rampCells.get(f),{cellW:y,cellH:S}=m,b=Math.floor(p/y),v=Math.floor(_/S);if(!g||b<0||b>=m.cols||v<0||v>=m.rows)return 0;const M=g.cells[v*m.cols+b];return M>0?Xs(g.lanes[M-1],p,_,y,S)-f:0};return{sync:n,occlusionOf:(f,p)=>{const _=a();if(!_?.enabled||!p||!(f.radius>0))return null;const m=f.level??0,g=f.rotation||0,y=f.spread??.5,S=`${f.x},${f.y},${f.z},${g},${m},${f.radius},${y},${s},${_.rays}`,b=e.get(f);if(b&&b.key===S&&b.texture===p.texture)return b;const v=o(f);if(!v)return null;const M=i(),{cellW:w,cellH:C}=M,A=Ys(f,p),L=(A.width-A.margin)*A.sx,R=A.margin*A.sx,Y=A.height/2*A.sy;if(!r(f,g,L,R,Y)){const W={key:S,texture:p.texture,shape:null,hit:null,wash:null,fan:null};return e.set(f,W),W}const{points:I,clipped:D,closed:X,reaches:U,forward:O}=hc({x:f.x,y:f.y,rotation:g,alongMax:L,alongBack:R,acrossMax:Y,rays:_.rays},v,w,C),K=t.headlights?.wash,j={key:S,texture:p.texture,shape:D?{points:I,closed:X,uvs:cc(I,A)}:null,hit:lc(f.x,f.y,Math.cos(g),Math.sin(g),f.radius,v,w,C),fan:{points:I,closed:X,frame:A},wash:K?.intensity>0?fc({x:f.x,y:f.y,points:I,reaches:U,forward:O,uvOf:(W,xt)=>Os(W,xt,A),wallAt:(W,xt)=>Math.max(l(m,W,xt),h(m,W,xt)),cellW:w,cellH:C,height:K.height,level:m}):null};return e.set(f,j),j},reachesPoint:(f,p,_)=>{if(f.kind!=="cone"||!a()?.enabled)return!0;const m=o(f);if(!m)return!0;const g=Math.hypot(p-f.x,_-f.y);if(g<1e-6)return!0;const y=i();return Ds(f.x,f.y,(p-f.x)/g,(_-f.y)/g,g,m,y.cellW,y.cellH)>=g},bounceOf:(f,p)=>{const _=t.headlights?.bounce;if(!_||!(_.intensity>0)||!(_.radius>0)||p.distance>(_.maxDistance??f.radius))return null;const m=f.rotation||0,g=_.radius*mc;return{kind:"radial",level:f.level,levels:f.levels,x:p.x-Math.cos(m)*g,y:p.y-Math.sin(m)*g,z:f.z,radius:_.radius,color:f.color,intensity:(f.intensity??1)*_.intensity*(1-p.distance/f.radius)}}}}function xc({getMap:i,textures:t}){const e=new WeakMap,s=new WeakMap,n=(a,l)=>{const h=`${a.kind},${a.x},${a.y},${a.rotation},${a.radius},${a.spread}`,u=e.get(a);if(u&&u.key===h&&u.texture===l.texture)return u.fan;const c=Ys(a,l),d=Math.cos(c.rotation),f=Math.sin(c.rotation),p=-c.margin*c.sx,_=(c.width-c.margin)*c.sx,m=c.height/2*c.sy,g=new Float32Array(10);g[0]=c.x,g[1]=c.y,[[p,-m],[_,-m],[_,m],[p,m]].forEach(([S,b],v)=>{g[(v+1)*2]=c.x+S*d-b*f,g[(v+1)*2+1]=c.y+S*f+b*d});const y={points:g,closed:!0,frame:c};return e.set(a,{key:h,texture:l.texture,fan:y}),y};return{push:(a,l,h,u,c,d)=>{if(!h?.length)return!1;const f=i(),p=u.kind==="cone"?t.cone:t.radial,_=c.rampFan??n(u,p);let m=s.get(_.points);m||(m=new Map,s.set(_.points,m));let g=!1;for(const y of h){m.has(y)||m.set(y,dc({points:_.points,closed:_.closed,lane:y,frame:_.frame,cellW:f.cellW,cellH:f.cellH,segmentsPerCell:Ft.rampSegments}));const S=m.get(y);S&&(a.has(l)||a.set(l,[]),a.get(l).push({ramp:S,texture:c.texture,color:c.color,alpha:d}),g=!0)}return g},targets:()=>{const a=new Map;for(const l of i().levels.values())for(const h of l.rampLevels())a.has(h)||a.set(h,[]),a.get(h).push(l.level);return a}}}function yc({getMap:i,lights:t,flashes:e,cfg:s,reachesPoint:n}){let o=null,r=0;const a=(h,u,c,d,f)=>{const p=i(),_=[],m=g=>(g.levels??[g.level??0]).includes(c);for(const g of gr(p.lampGrid,h,u))g.level===c&&_.push({light:g,factor:fe(g.seed,f,g.flicker)});for(const g of t)g.kind==="cone"&&!d?.includes(g)&&m(g)&&An(g,h,u)>0&&n(g,h,u)&&_.push({light:g,factor:1});for(const g of e){const y=Mn(f-g.start,g.duration);y>0&&m(g)&&_.push({light:g,factor:y})}return _};return{lightsAt:(h,u,c,d=1,f=null)=>{if(!(d>0))return[];const p=J.shared.lastTime;if(o!==p&&(o=p,r=0),r>=s.maxLights)return[];const _=pr(a(h,u,c,f,p),h,u,d);return _.length&&(r+=1),_},candidatesAt:a}}const wc=.08;function vc({lamp:i,view:t,reach:e,camera:s,shaftsCfg:n,casters:o,shear:r}){if(!n.shadows||!(n.maxShadowCasters>0))return[];const a=i.radius*n.length,l=[];for(const u of o.values()){const c=Math.hypot(u.x-i.x,u.y-i.y);u.level===i.level&&c<a&&l.push({caster:u,distance:c})}l.sort((u,c)=>u.distance-c.distance);const h=[];for(const{caster:u}of l.slice(0,n.maxShadowCasters)){const c=(u.z??u.level)*r,d=mt(u.x,u.y,s,c),f=xr(t.x,t.y,d.x,d.y,u.radius*(1+c),e);f&&h.push(f)}return h}function Sc({map:i,casters:t,cfg:e,asset:s,camera:n,screen:o,now:r,stage:a,shear:l}){const h=new Map,u=e.shafts;if(!u?.enabled||!s)return h;let c=0;for(const d of i.lamps){if(!d.head||!jn(i,d.level))continue;if(c>=e.maxLights)break;const f=We(d.x,d.y,d.level,n,a,l),p=d.radius*u.length*f.scale;!(p>0)||!ws(f.screenX,f.screenY,p*a.scale.x,o.width,o.height)||(h.has(d.level)||h.set(d.level,[]),h.get(d.level).push({texture:s.texture,x:f.x,y:f.y,scale:p*2/s.contentSize,rotation:yr(d.seed,r,wc),color:d.color,alpha:u.intensity*d.intensity*fe(d.seed,r,d.flicker),shadows:vc({lamp:d,view:f,reach:p,camera:n,shaftsCfg:u,casters:t,shear:l})}),c+=1)}return h}const Mc=3818080,bc=["radial","cone","head","glint","shaft"];function kc(i,t,e){const s=(i?.cols??0)*t*e.x,n=(i?.rows??0)*t*e.y,o=Math.max(s,n);return{x:-o,y:-o,width:s+o*2,height:n+o*2}}function Ac(i=yt,t={}){const e=!!i.enabled,s=t.levelView||null,n=t.volumes||null,o=t.shear??N.shear;let r=null,a=null;const l={},h=new Set,u=new Map,c=[],d=new Map;let f=null;const p=new Map;let _=null;const m=new Map,g=new Map;let y=null;const S=new Map;let b=!1,v=null;const M=gc({getMap:()=>_,cfg:i}),w=yc({getMap:()=>_,lights:h,flashes:c,cfg:i,reachesPoint:M.reachesPoint}),C=xc({getMap:()=>_,textures:l}),A=()=>s?.cfg||null,L=(x,k,P,T)=>{let z=x.get(T);return z||(z=new G,z.label=`${P}-${T}`,z.zIndex=H(k,T),z.eventMode="none",x.set(T,z)),z},R=x=>L(_.emissive,vn,"emissive",x),Y=x=>L(_.lampHeads,hr,"lamp-heads",x),I=()=>{if(!(!_?.night||!l.head||_.headsReady)){_.headsReady=!0;for(const x of _.lamps){if(!x.head)continue;const k=new Z(l.head.texture);k.anchor.set(.5),k.blendMode="add",k.tint=x.color,x.headSprite=k,Y(x.level).addChild(k)}}},D=(x,k,P,T)=>{const z=x||{},q=!!z.night,Q=ze(P??1);if(_={night:q,ambient:z.ambient??Mc,step:k,scale:Q,cellW:k*Q.x,cellH:k*Q.y,area:kc(T,k,Q),cols:T?.cols??0,rows:T?.rows??0,blockers:new Map,rampCells:new Map,lamps:[],headsReady:!1,levels:new Map,roofLevels:new Map,emissive:new Map,lampHeads:new Map,maskCells:new Map,roofCells:new Map},!!q){(z.lamps||[]).forEach((lt,It)=>{const[ee,Yt]=lt.cell||[0,0],se=lt.level||0,B=fr(ee,Yt,k,Q);_.lamps.push({kind:"radial",level:se,x:B.x,y:B.y,z:se,radius:lt.radius??0,rotation:0,color:lt.color??16777215,intensity:lt.intensity??1,flicker:lt.flicker||0,seed:It+1,head:!!lt.head,headSprite:null})});for(const[lt,It]of u)R(It).addChild(lt);_.lampGrid=mr(_.lamps,Math.max(1,..._.lamps.map(lt=>lt.radius))),I(),b=!0,v=null}},X=()=>{if(_){for(const x of[..._.emissive.values(),..._.lampHeads.values()])x.parent?.removeChild(x);for(const x of O())x.overlay.parent?.removeChild(x.overlay);for(const x of _.emissive.values())for(const k of u.keys())k.parent===x&&x.removeChild(k);for(const x of _.lamps)x.headSprite&&(x.headSprite.destroy({texture:!1,textureSource:!1}),x.headSprite=null);for(const x of[..._.emissive.values(),..._.lampHeads.values()])x.destroy({children:!0});for(const x of O())x.destroy();_=null,v=null}},U=()=>{X(),m.clear(),g.clear(),S.clear(),b=!1,y=null,f=null},O=()=>[..._.levels.values(),..._.roofLevels.values()],K=()=>n?.levels()??new Map,j=()=>n!==null&&n.version!==y,W=(x,k=null)=>{const P=[],T=new Set;for(const z of x?.values()||[])for(const q of z){const Q=`${q[0]},${q[1]}`;!T.has(Q)&&!k?.has(Q)&&(T.add(Q),P.push(q))}return[P,T]},xt=(x,k,P,T)=>{let z=x.get(k);if(P.length===0){z&&(z.destroy(),x.delete(k));return}z||(z=new Wi({level:k,ambient:_.ambient,resolution:i.resolution,area:_.area,roof:T}),x.set(k,z)),z.setMask(Zs(P),_.step,_.scale)},zt=x=>{const k=new Map;for(const{cells:P,volume:T}of K().get(x)||[])k.has(T)||k.set(T,[]),k.get(T).push(...P);return[...k].map(([P,T])=>({volume:P,runs:Zs(T)}))},Ut=()=>{j()&&(y=n.version,b=!0);const x=b;if(b){b=!1;const k=new Set([...m.keys(),...g.keys(),..._.levels.keys(),..._.roofLevels.keys()]);for(const P of k){if(P<1)continue;const[T,z]=W(g.get(P)),[q,Q]=W(m.get(P),z);_.maskCells.set(P,Q),_.roofCells.set(P,z),xt(_.levels,P,q,!1),xt(_.roofLevels,P,T,!0)}}if(_.levels.has(0)||_.levels.set(0,new Wi({level:0,ambient:_.ambient,resolution:i.resolution,area:_.area})),x){M.sync(K(),S);for(const k of _.levels.values())k.setTops(zt(k.level),_.step,_.scale),k.setRamps([...S.get(k.level)?.values()||[]].flat(),_.step,_.scale,Ft.rampSegments)}},Ht=()=>{for(const x of O())x.overlay.parent!==r&&r.addChild(x.overlay);for(const x of[..._.emissive.values(),..._.lampHeads.values()])x.parent!==r&&r.addChild(x)},Wt=(x,k,P)=>{const T=x.kind==="cone"?l.cone:l.radial;if(!T||!(x.intensity*P>0))return null;const z=We(x.x,x.y,x.z??x.level,k,r,o),q=Ys(x,T),Q={reach:x.radius*z.scale*r.scale.x,view:z,texture:T.texture,anchorX:q.margin/q.width,anchorY:.5,scaleX:q.sx*z.scale,scaleY:q.sy*z.scale,rotation:q.rotation,color:x.color,alpha:x.intensity*P};return x.kind==="cone"&&(Q.fan=null,Q.hit=null),Q},Gt=(x,k)=>{if(k.kind!=="cone")return;const P=M.occlusionOf(k,l.cone);if(!P)return;const{view:T}=x;P.shape&&(x.fan={shape:P.shape,x:T.x-k.x*T.scale,y:T.y-k.y*T.scale,scale:T.scale}),x.hit=P.hit,x.wash=P.wash,x.rampFan=P.fan},ot=(x,k,P)=>{const T=new Map,z=new Map,q=new Map;let Q=0;const lt=C.targets(),It=i.rampSpill??1,ee=[],Yt=(B,Ot)=>{const Zt=B.levels??[B.level],Ns=Zt.filter(dt=>jn(_,dt)),Us=It>0?Zt.flatMap(dt=>lt.get(dt)||[]).filter(dt=>!Zt.includes(dt)):[];if(Q>=i.maxLights||Ns.length===0&&Us.length===0)return;const et=Wt(B,x,Ot);if(!et||!ws(et.view.screenX,et.view.screenY,et.reach,k.width,k.height))return;et.x=et.view.x,et.y=et.view.y,Gt(et,B);const Fe=B.level??0;et.wash&&_.levels.has(Fe)&&(q.has(Fe)||q.set(Fe,[]),q.get(Fe).push({wash:et.wash,texture:et.texture,color:et.color,alpha:et.alpha*i.headlights.wash.intensity}));for(const dt of Ns){if(Q>=i.maxLights)return;T.has(dt)||T.set(dt,[]),T.get(dt).push(et),Q+=1,C.push(z,dt,_.levels.get(dt)?.ramps,B,et,et.alpha)}for(const dt of new Set(Us)){if(Q>=i.maxLights)return;const no=_.levels.get(dt)?.ramps.filter(oo=>Zt.includes(oo.to));C.push(z,dt,no,B,et,et.alpha*It)&&(Q+=1)}const Hs=et.hit?M.bounceOf(B,et.hit):null;Hs&&ee.push({light:Hs,factor:Ot})};for(let B=c.length-1;B>=0;B-=1){const Ot=c[B],Zt=Mn(P-Ot.start,Ot.duration);Zt<=0?c.splice(B,1):Yt(Ot,Zt)}for(const B of h)Yt(B,1);for(const B of _.lamps)Yt(B,fe(B.seed,P,B.flicker));for(const{light:B,factor:Ot}of ee)Yt(B,Ot);const se=Sc({map:_,casters:d,cfg:i,asset:l.shaft,camera:x,screen:k,now:P,stage:r,shear:o});for(const B of O())B.place(x,o),B.layout(T.get(B.level)||[]),B.roof||B.layoutWashes(q.get(B.level)||[],x,o),B.layoutRampLights(B.roof?[]:z.get(B.level)||[],x,o),B.layoutShafts(se.get(B.level)||[])},Kt=x=>{const k=A();if(!k)return;const P=mt(s.x,s.y,x,s.z*o);for(const T of O()){if(T.level<1)continue;const z=s.level<T.level,q=T.roof&&z&&Ro(_.roofCells.get(T.level),_.step,_.scale,P,x,[T.level*o],k.roofMargin??0),Q=T.overlay,lt=_n(T.hole,k.fadeRate);if(s.mode==="layer"){let It=q;if(!T.roof){const Yt=ue(s.x,_.scale.x,_.step),se=ue(s.y,_.scale.y,_.step);It=z&&!!_.maskCells.get(T.level)?.has(`${Yt},${se}`)}const ee=It?k.layerAlpha:1;Q.alpha+=(ee-Q.alpha)*lt;continue}Es(T.hole,T.roof?q:z,lt),zs(Q,T.hole,k,s,r,x),T.syncFilters()}},$t=(x,k)=>{for(const P of _.lamps){const T=P.headSprite;if(!T)continue;const z=We(P.x,P.y,P.level,x,r,o);T.position.set(z.x,z.y),T.scale.set(z.scale),T.alpha=(s?s.alphaFor(P.level,z.x,z.y,0):1)*fe(P.seed,k,P.flicker)}},ft=()=>e&&_?.night===!0;return{get enabled(){return e},attachStage(x,k){!e||r||!x||!k||(r=x,a=k,v=null,s?.attachStage(x,k))},acquireMap(x,k,P,T,z){e&&(p.set(x,(p.get(x)||0)+1),x!==f&&(X(),f=x,D(k,P,T,z)))},releaseMap(x,k){if(!e)return;if(k!==void 0)for(const T of[m,g,S])for(const z of T.values())z.delete(k)&&(b=!0);const P=p.get(x);if(P!==void 0){if(P>1){p.set(x,P-1);return}p.delete(x),x===f&&U()}},setLevelMask(x,k,P,{roof:T=!1}={}){if(!e||!(x>=1))return;const z=T?g:m;z.has(x)||z.set(x,new Map),k&&k.length>0?z.get(x).set(P,k):z.get(x).delete(P),b=!0},setRampWedges(x,k,P){if(!e||!(x>=0))return;S.has(x)||S.set(x,new Map);const T=(k||[]).filter(z=>z.from===x&&z.to>z.from);T.length>0?S.get(x).set(P,T):S.get(x).delete(P),b=!0},registerTextures(x){if(!(!e||!x)){for(const k of bc){const P=x[k];if(!P)continue;const T=l[k];if(l[k]=P,k==="head"&&T&&T!==P){for(const z of u.keys())z.texture===T.texture&&(z.texture=P.texture);for(const z of _?.lamps||[])z.headSprite&&(z.headSprite.texture=P.texture)}}l.head&&I()}},texture(x){return l[x]||null},addLight(x){if(!e)return null;const k={kind:"radial",level:0,x:0,y:0,radius:0,rotation:0,color:16777215,intensity:1,...x};return h.add(k),k},updateLight(x,k){x&&h.has(x)&&Object.assign(x,k)},removeLight(x){h.delete(x)},flash(x){!ft()||!l.radial||c.push({kind:"radial",level:0,color:16777215,intensity:1,...x,start:J.shared.lastTime})},addEmissive(x,k){return!ft()||!x?!1:(u.get(x)!==void 0&&x.parent&&x.parent.removeChild(x),u.set(x,k||0),R(k||0).addChild(x),!0)},removeEmissive(x){if(u.has(x)){u.delete(x);for(const k of _?.emissive.values()||[])x.parent===k&&k.removeChild(x)}},isNight:ft,lightsAt(x,k,P,T=1,z=null){return ft()?w.lightsAt(x,k,P,T,z):[]},onScreen(x,k,P,T){if(!r||!a?.screen)return!1;const z=s?s.camera():ut(r,a);if(!z)return!1;const q=We(x,k,P,z,r,o);return ws(q.screenX,q.screenY,T*q.scale*r.scale.x,a.screen.width,a.screen.height)},setCaster(x,k){e&&(k?d.set(x,k):d.delete(x))},castsShadows(){const x=i.shafts;return ft()&&!!(x?.enabled&&x.shadows&&x.maxShadowCasters>0)},render(){if(!ft()||!r||!a)return;const x=s?s.camera():ut(r,a),k=a.screen;if(!x||!k)return;const P=J.shared.lastTime,T=v;T!==null&&T.tick===P&&T.x===r.position.x&&T.y===r.position.y&&T.scaleX===r.scale.x&&T.scaleY===r.scale.y&&T.width===k.width&&T.height===k.height&&!b&&!j()||(v={tick:P,x:r.position.x,y:r.position.y,scaleX:r.scale.x,scaleY:r.scale.y,width:k.width,height:k.height},Ut(),I(),Ht(),ot(x,k,P),s&&Kt(x),$t(x,P))},clear:U}}function Tc({segments:i=null}={}){const t=new Map;return{subscribe(e,s){const n=String(e);return t.has(n)||t.set(n,new Set),t.get(n).add(s),()=>{const o=t.get(n);o&&(o.delete(s),o.size===0&&t.delete(n))}},fired(e){const s=t.get(String(e));if(s)for(const n of s)n.fired?.()},muzzle(e){const s=t.get(String(e));if(s)for(const n of s){const o=n.muzzle?.();if(o)return o}return null},path(e,s,n,o,r){const a=Math.hypot(n-e,o-s);if(!i||!(a>.001))return null;const l=i(e,s,(n-e)/a,(o-s)/a,a,r||0),h=[];for(let u=0;u+2<(l?.length??0);u+=3)h.push({t0:l[u],t1:l[u+1],level:l[u+2]});return h.length?h:null}}}const es={click:12,squelch:120,deny:120,static:2e3},Ki=1200,Lc=1200,Pc=1800,Cc=28,Ec=[7,9,42,68,111],zc=16,Ic=.45,Rc=4,Fc=1.5,Dc=2e3,Xc=3,Yc=150,Oc=4,ps={noise:.5,high:.3,low:.6},Vc=.7,Bc=7,Nc=400,Uc=5e3,Hc=3,Wc=20,Gc=.01,Kc=.35,$c=250,Zc=[1,3,5,7],qc=160,jc=90,Qc=5,Qn=.35,Jc=1800,tu=.5,eu=.04,su=20;function Vs(i){let t=i>>>0;return()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}const Et=(i,t)=>Math.round(i*t/1e3);function Re(i,t){let e=0;for(let s=0;s<i.length;s+=1)e=Math.max(e,Math.abs(i[s]));if(e>0){const s=t/e;for(let n=0;n<i.length;n+=1)i[n]*=s}return i}function Jn(i,t,e){return e<=0?1:Math.min(1,i/e,(t-1-i)/e)}function to(i,t){return new Float32Array(Et(i,t))}function Ts(...i){const t=i.reduce((n,o)=>n+o.length,0),e=new Float32Array(t);let s=0;for(const n of i)e.set(n,s),s+=n.length;return e}function iu(i){let t=65535;for(const e of i){t^=e<<8;for(let s=0;s<8;s+=1)t=t&32768?(t<<1^4129)&65535:t<<1&65535}return t}function $i(i){const t=[];for(let e=0;e<i;e+=1)t.push(e%2===0?1:0);return t}function Zi(i){const t=[];for(const e of i)for(let s=7;s>=0;s-=1)t.push(e>>s&1);return t}function nu(i){const t=i&65535,e=[1,128,t>>8,t&255],s=iu(e),n=Zi([...e,s>>8,s&255]);return[...$i(Cc),...Zi(Ec),...n,...n.map(o=>1-o),...$i(zc)]}function ou(i,t){const e=nu(t),s=Math.round(i*e.length/Ki),n=Et(i,Rc),o=new Float32Array(s);let r=0;for(let a=0;a<s;a+=1){const l=Math.min(e.length-1,Math.floor(a*Ki/i)),h=e[l]===1?Lc:Pc;r+=2*Math.PI*h/i,o[a]=Math.sin(r)*Ic*Jn(a,s,n)}return o}function qi(i){const t=Et(i,es.click),e=Vs(Bc),s=new Float32Array(t);for(let n=0;n<t;n+=1){const o=n/i,r=o*1e3,a=(e()*2-1)*Math.exp(-r/Fc),l=Math.sin(2*Math.PI*Dc*o)*Math.exp(-r/Xc),h=Math.sin(2*Math.PI*Yc*o)*Math.exp(-r/Oc);s[n]=a*ps.noise+l*ps.high+h*ps.low}return Re(s,Vc)}function ji(i,t){const e=Et(i,es.squelch),s=Vs(t),n=new Float32Array(e),o=Et(i,Hc),r=o+Et(i,Wc),a=Math.exp(-2*Math.PI*Nc/i),l=Math.exp(-2*Math.PI*Uc/i);let h=0,u=0,c=0;for(let d=0;d<e;d+=1){const f=s()*2-1;u=a*(u+f-h),h=f,c=(1-l)*u+l*c;let p;d<o?p=d/o:d<r?p=1:p=Math.pow(Gc,(d-r)/(e-r)),n[d]=c*p}return Re(n,Kc)}function eo(i,t){const e=Et(i,t),s=Et(i,Qc),n=new Float32Array(e);for(let o=0;o<e;o+=1){const r=o/i;let a=0;for(const l of Zc)a+=Math.sin(2*Math.PI*$c*l*r)/l;n[o]=a*Jn(o,e,s)}return n}function ru(i){const t=eo(i,qc);return Re(Ts(t,to(i,jc),t),Qn)}function au(i){return Re(eo(i,es.deny),Qn)}function lu(i,t,e,s){const n=2*Math.PI*e/t,o=Math.sin(n)/(2*s),r=1+o,a=o/r,l=-o/r,h=-2*Math.cos(n)/r,u=(1-o)/r,c=new Float32Array(i.length);let d=0,f=0,p=0,_=0;for(let m=0;m<i.length;m+=1){const g=i[m],y=a*g+l*f-h*p-u*_;f=d,d=g,_=p,p=y,c[m]=y}return c}function hu(i,t){const e=Et(i,es.static),s=Et(i,su),n=Vs(t),o=new Float32Array(e+s);let r=0,a=0,l=0,h=0,u=0,c=0,d=0;for(let _=0;_<o.length;_+=1){const m=n()*2-1;r=.99886*r+m*.0555179,a=.99332*a+m*.0750759,l=.969*l+m*.153852,h=.8665*h+m*.3104856,u=.55*u+m*.5329522,c=-.7616*c-m*.016898,o[_]=r+a+l+h+u+c+d+m*.5362,d=m*.115926}const f=lu(o,i,Jc,tu),p=f.slice(0,e);for(let _=0;_<s;_+=1){const m=_/s;p[_]=f[_]*m+f[e+_]*(1-m)}return Re(p,eu)}const cu=256,uu=15,fu=.6,du=1,_u=2,pu=3;function le(i){for(let t=0;t<i.length;t+=1)i[t]*=fu;return i}function mu({sampleRate:i}){const t=e=>le(Ts(qi(i),to(i,uu),ou(i,cu+(e??0))));return{talkStart:t,incomingStart:t,talkEnd:()=>le(Ts(qi(i),ji(i,du))),incomingEnd:()=>le(ji(i,_u)),busy:()=>le(ru(i)),deny:()=>le(au(i)),bed:()=>le(hu(i,pu))}}const Qi=300,Ji=3400,Ne=.707,Me={threshold:-30,knee:6,ratio:6,attack:.003,release:.12},gu=.5,xu=1800,yu=4,wu=1,vu=2,Su=.9;function Mu(i=2,t=2048){const e=new Float32Array(t),s=Math.tanh(i);for(let n=0;n<t;n+=1){const o=n/(t-1)*2-1;e[n]=Math.tanh(i*o)/s}return e}function bu(i){const t=i.createGain(),e=i.createGain(),s=(f,p,_)=>{const m=i.createBiquadFilter();return m.type=f,m.frequency.value=p,m.Q.value=_,m},n=s("highpass",Qi,Ne),o=s("highpass",Qi,Ne),r=s("lowpass",Ji,Ne),a=s("lowpass",Ji,Ne),l=i.createDynamicsCompressor();l.threshold.value=Me.threshold,l.knee.value=Me.knee,l.ratio.value=Me.ratio,l.attack.value=Me.attack,l.release.value=Me.release;const h=i.createGain();h.gain.value=gu;const u=s("peaking",xu,wu);u.gain.value=yu;const c=i.createWaveShaper();c.curve=Mu(vu),c.oversample="4x",e.gain.value=Su;const d=[t,n,o,r,a,l,h,u,c,e];for(let f=0;f<d.length-1;f+=1)d[f].connect(d[f+1]);return{input:t,output:e,dispose(){for(const f of d)f.disconnect()}}}function ku(){const i=new Set;return{subscribe(t){return i.add(t),()=>{i.delete(t)}},exploded(t){for(const e of i)e(t)}}}function Au(){const i=new Map;let t=0,e=0,s=null,n=null,o=0;const r=()=>{s=null,n=null,o+=1},a=()=>{s=new Map;for(const{level:l,cells:h,volume:u}of i.values()){s.has(l)||s.set(l,new Map);const c=s.get(l);for(const[d,f]of h){const p=`${d},${f}`;c.set(p,Math.max(c.get(p)||0,u))}}return s};return{setLayerVolume(l,h,u,c,{step:d,scale:f}){const{x:p,y:_}=ze(f??1);t=d*p,e=d*_,i.set(c,{level:l||0,cells:h,volume:u}),r()},release(l){i.delete(l)&&r()},get version(){return o},levels(){if(!n){n=new Map;for(const{level:l,cells:h,volume:u}of i.values())n.has(l)||n.set(l,[]),n.get(l).push({cells:h,volume:u})}return n},heightAt(l,h,u){if(!(t>0&&e>0))return 0;const c=(s||a()).get(l||0);return c&&c.get(`${Math.floor(h/t)},${Math.floor(u/e)}`)||0},cellSize(){return{cellW:t,cellH:e}}}}const Tu=(i,t)=>t>=Math.min(i.from,i.to)&&t<=Math.max(i.from,i.to),Bs=(i,t)=>{const e=i.max-i.min,s=e>0?(t-i.min)/e:0,n=i.sign>0?s:1-s;return i.from+(i.to-i.from)*n},so=(i,t,e)=>{const s=i.axis===0?t:e,n=i.axis===0?e:t;return s>=i.min&&s<=i.max&&n>=i.crossMin&&n<=i.crossMax};function Lu(i,t,e,s){const n=io(i,t,e,s);return n?Bs(n,n.axis===0?e:s):null}function io(i,t,e,s){return Array.isArray(i)?i.find(n=>Tu(n,t)&&so(n,e,s))??null:null}function Pu(i,t,e,s){const n=io(i,t,e,s);return n?{height:Bs(n,n.axis===0?e:s),axis:n.axis}:null}function Cu(i,t,e,s,n,o,r){if(!Array.isArray(i))return null;const a=2*r,l=e+n*a,h=s+o*a;for(const u of i){if(Math.min(u.from,u.to)!==t||!so(u,l,h))continue;const c=u.axis===0,d=c?e:s,f=c?s:e,p=c?n:o,_=c?o:n,m=[{coord:u.min,dist:Math.abs(d-u.min),end:!0,d:p},{coord:u.max,dist:Math.abs(d-u.max),end:!0,d:p},{coord:u.crossMin,dist:Math.abs(f-u.crossMin),end:!1,d:_},{coord:u.crossMax,dist:Math.abs(f-u.crossMax),end:!1,d:_}].filter(b=>b.dist<=r&&Math.abs(b.d)>1e-9);if(m.length===0)continue;const g=m.reduce((b,v)=>v.dist<b.dist?v:b),y=g.end===c?"x":"y",S=g.d>0?-1:1;return{face:{axis:y,coord:g.coord,nx:y==="x"?S:0,ny:y==="y"?S:0},volume:Bs(u,c?l:h)-t}}return null}const Eu=[[0,-1],[0,1],[-1,0],[1,0]],Ru={id:"tanks",engineApi:mo,requires:["map.layers","map.levelsN","map.gameData","map.bodyState"],async createClientCore(i,{wasmUrl:t}){if(sc(t)){const s=await ic(t);return{core:new s.ClientCore(i),memory:null}}const e=await bo({module_or_path:t});return{core:new gs(i),memory:e.memory}},parts:Rh,bakers:ec,styles:ko,serviceNames:["levelView","mapDynamics","rampRuns","surfaces","volumes","lighting","shots","blasts"],hooks:{services(i){const t=nc(),e=Au(),s=Ac(void 0,{levelView:t,volumes:e});let n=[],o=null;const r=()=>{const h=i.map_generation();return h!==o&&(o=h,n=JSON.parse(i.ramp_runs())),n};let a=[],l=null;return{levelView:t,lighting:s,shots:Tc({segments:(h,u,c,d,f,p)=>i.shot_segments(h,u,c,d,f,p)}),blasts:ku(),volumes:e,mapDynamics:{toWorld(h,u,c){const d=i.map_dynamics_to_world(h,u,c);return d.length===0?null:{x:d[0],y:d[1]}}},rampRuns:{forLevel(h){return r().filter(u=>u.from===h)},heightAt(h,u,c){return Lu(r(),h,u,c)},slopeAt(h,u,c){return Pu(r(),h,u,c)},faceAt(h,u,c,d,f,p){return Cu(r(),h,u,c,d,f,p)},floorAt(h,u,c){return i.floor_level(h,u,c)}},surfaces:{kindAt(h,u,c){const d=i.surface_at(h,u,c);if(d<0)return null;const f=i.map_generation();return f!==l&&(l=f,a=JSON.parse(i.surface_types())),a[d]??null},dirAt(h,u,c){return Eu[i.surface_dir_at(h,u,c)]??null}}}},voiceSounds:i=>mu(i),voiceFilter:i=>bu(i),onAuth(i,t){i.set_model(t.model)},onPanel(i,t){i.sync_panel(JSON.stringify(t))},onLocalAction(i,t,e,s){return t!=="down"?null:e==="fire"?i.try_fire(s)||null:((e==="nextWeapon"||e==="prevWeapon")&&i.cycle_weapon(e==="prevWeapon"),null)}}};export{Ru as default};
|