@vimp-games/tanks 0.22.10 → 0.22.11

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.
@@ -1,210 +0,0 @@
1
- import{UniformGroup as ze,Filter as nn,GpuProgram as on,GlProgram as ds,defaultFilterVert as rn,Ticker as st,Container as K,Sprite as Q,Rectangle as ht,Spritesheet as an,MeshSimple as ln,Text as _i,BlurFilter as _s,Assets as ss,Texture as oe,Graphics as W,Shader as pi,Geometry as hn,Mesh as Re,AlphaFilter as mi,PerspectiveMesh as cn,Particle as un,ParticleContainer as ps,MeshGeometry as is}from"pixi.js";const fn=4;class ns{__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,As.unregister(this),t}free(){const t=this.__destroy_into_raw();I.__wbg_clientcore_free(t,0)}abi_describe(){let t,e;try{const s=I.clientcore_abi_describe(this.__wbg_ptr);return t=s[0],e=s[1],Tt(s[0],s[1])}finally{I.__wbindgen_free(t,e,1)}}apply_aim(t,e,s,n){I.clientcore_apply_aim(this.__wbg_ptr,t,e,s,n)}apply_input(t,e,s){const n=Yt(t,I.__wbindgen_malloc,I.__wbindgen_realloc),o=ft,r=Yt(e,I.__wbindgen_malloc,I.__wbindgen_realloc),a=ft;I.clientcore_apply_input(this.__wbg_ptr,n,o,r,a,s)}cycle_weapon(t){I.clientcore_cycle_weapon(this.__wbg_ptr,t)}debug_json(){let t,e;try{const s=I.clientcore_debug_json(this.__wbg_ptr);return t=s[0],e=s[1],Tt(s[0],s[1])}finally{I.__wbindgen_free(t,e,1)}}decode_frame(t){let e,s;try{const n=Ue(t,I.__wbindgen_malloc),o=ft,r=I.clientcore_decode_frame(this.__wbg_ptr,n,o);return e=r[0],s=r[1],Tt(r[0],r[1])}finally{I.__wbindgen_free(e,s,1)}}dispatch(t,e){const s=Yt(t,I.__wbindgen_malloc,I.__wbindgen_realloc),n=ft,o=Ue(e,I.__wbindgen_malloc),r=ft,a=I.clientcore_dispatch(this.__wbg_ptr,s,n,o,r);var l=_n(a[0],a[1]).slice();return I.__wbindgen_free(a[0],a[1]*1,1),l}floor_level(t,e,s){return I.clientcore_floor_level(this.__wbg_ptr,t,e,s)}hot_ptr(){return I.clientcore_hot_ptr(this.__wbg_ptr)>>>0}hot_values(){const t=I.clientcore_hot_values(this.__wbg_ptr);var e=We(t[0],t[1]).slice();return I.__wbindgen_free(t[0],t[1]*4,4),e}map_dynamics_to_world(t,e,s){const n=Yt(t,I.__wbindgen_malloc,I.__wbindgen_realloc),o=ft,r=I.clientcore_map_dynamics_to_world(this.__wbg_ptr,n,o,e,s);var a=We(r[0],r[1]).slice();return I.__wbindgen_free(r[0],r[1]*4,4),a}map_generation(){return I.clientcore_map_generation(this.__wbg_ptr)>>>0}my_game_id(){return I.clientcore_my_game_id(this.__wbg_ptr)}constructor(t){const e=Yt(t,I.__wbindgen_malloc,I.__wbindgen_realloc),s=ft,n=I.clientcore_new(e,s);if(n[2])throw Ls(n[1]);return this.__wbg_ptr=n[0],As.register(this,this.__wbg_ptr,this),this}offset(){return I.clientcore_offset(this.__wbg_ptr)}push_frame(t,e){const s=Ue(t,I.__wbindgen_malloc),n=ft;return I.clientcore_push_frame(this.__wbg_ptr,s,n,e)!==0}ramp_runs(){let t,e;try{const s=I.clientcore_ramp_runs(this.__wbg_ptr);return t=s[0],e=s[1],Tt(s[0],s[1])}finally{I.__wbindgen_free(t,e,1)}}reset(){I.clientcore_reset(this.__wbg_ptr)}resync(){I.clientcore_resync(this.__wbg_ptr)}sample(t){return I.clientcore_sample(this.__wbg_ptr,t)>>>0}set_active(t){I.clientcore_set_active(this.__wbg_ptr,t)}set_map(t){const e=Yt(t,I.__wbindgen_malloc,I.__wbindgen_realloc),s=ft,n=I.clientcore_set_map(this.__wbg_ptr,e,s);if(n[1])throw Ls(n[0])}set_model(t){const e=Yt(t,I.__wbindgen_malloc,I.__wbindgen_realloc),s=ft;I.clientcore_set_model(this.__wbg_ptr,e,s)}shot_segments(t,e,s,n,o,r){const a=I.clientcore_shot_segments(this.__wbg_ptr,t,e,s,n,o,r);var l=We(a[0],a[1]).slice();return I.__wbindgen_free(a[0],a[1]*4,4),l}surface_at(t,e,s){return I.clientcore_surface_at(this.__wbg_ptr,t,e,s)}surface_dir_at(t,e,s){return I.clientcore_surface_dir_at(this.__wbg_ptr,t,e,s)}surface_types(){let t,e;try{const s=I.clientcore_surface_types(this.__wbg_ptr);return t=s[0],e=s[1],Tt(s[0],s[1])}finally{I.__wbindgen_free(t,e,1)}}sync_panel(t){const e=Yt(t,I.__wbindgen_malloc,I.__wbindgen_realloc),s=ft;I.clientcore_sync_panel(this.__wbg_ptr,e,s)}take_divergence(){let t,e;try{const s=I.clientcore_take_divergence(this.__wbg_ptr);return t=s[0],e=s[1],Tt(s[0],s[1])}finally{I.__wbindgen_free(t,e,1)}}take_frames(){let t,e;try{const s=I.clientcore_take_frames(this.__wbg_ptr);return t=s[0],e=s[1],Tt(s[0],s[1])}finally{I.__wbindgen_free(t,e,1)}}try_fire(t){const e=I.clientcore_try_fire(this.__wbg_ptr,t);let s;return e[0]!==0&&(s=Tt(e[0],e[1]).slice(),I.__wbindgen_free(e[0],e[1]*1,1)),s}}Symbol.dispose&&(ns.prototype[Symbol.dispose]=ns.prototype.free);function dn(){return{__proto__:null,"./vimp_tanks_core_bg.js":{__proto__:null,__wbg_Error_92b29b0548f8b746:function(t,e){return Error(Tt(t,e))},__wbg___wbindgen_throw_344f42d3211c4765:function(t,e){throw new Error(Tt(t,e))},__wbindgen_init_externref_table:function(){const t=I.__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 As=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(i=>I.__wbg_clientcore_free(i,1));typeof FinalizationRegistry>"u"||new FinalizationRegistry(i=>I.__wbg_gamecore_free(i,1));function We(i,t){return i=i>>>0,pn().subarray(i/4,i/4+t)}function _n(i,t){return i=i>>>0,re().subarray(i/1,i/1+t)}let ye=null;function pn(){return(ye===null||ye.byteLength===0)&&(ye=new Float32Array(I.memory.buffer)),ye}function Tt(i,t){return gn(i>>>0,t)}let xe=null;function re(){return(xe===null||xe.byteLength===0)&&(xe=new Uint8Array(I.memory.buffer)),xe}function Ue(i,t){const e=t(i.length*1,1)>>>0;return re().set(i,e/1),ft=i.length,e}function Yt(i,t,e){if(e===void 0){const a=ve.encode(i),l=t(a.length,1)>>>0;return re().subarray(l,l+a.length).set(a),ft=a.length,l}let s=i.length,n=t(s,1)>>>0;const o=re();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=re().subarray(n+r,n+s),l=ve.encodeInto(i,a);r+=l.written,n=e(n,s,r,1)>>>0}return ft=r,n}function Ls(i){const t=I.__wbindgen_externrefs.get(i);return I.__externref_table_dealloc(i),t}let Ae=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});Ae.decode();const mn=2146435072;let He=0;function gn(i,t){return He+=t,He>=mn&&(Ae=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),Ae.decode(),He=t),Ae.decode(re().subarray(i,i+t))}const ve=new TextEncoder;"encodeInto"in ve||(ve.encodeInto=function(i,t){const e=ve.encode(i);return t.set(e),{read:i.length,written:e.length}});let ft=0,I;function yn(i,t){return I=i.exports,ye=null,xe=null,I.__wbindgen_start(),I}async function xn(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 wn(i){if(I!==void 0)return I;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-CUAFeVPQ.wasm",import.meta.url));const t=dn();(typeof i=="string"||typeof Request=="function"&&i instanceof Request||typeof URL=="function"&&i instanceof URL)&&(i=fetch(i));const{instance:e,module:s}=await xn(await i,t);return yn(e)}const vn='@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}',Mn={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},kt={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},Kt={duration:150,attack:.15,gunKick:1,bodyKick:0,rock:.1},Mt={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},fe={rock:.22,wobbleHz:5,decay:180,duration:700,hop:.3,hopDuration:420,underShare:.5,shake:1.2,shakeDuration:220},Le={speed:19e3,minDuration:45,maxDuration:80,trailLength:55,trailShare:.4,color:16751178,coreColor:16774368,coreWidth:.3,glowWidth:1.2,glowAlpha:.2,alphaStart:1,alphaEnd:.6,height:.19,fadeSteps:8},Sn={duration:35,spikes:5,length:6,width:1.6,spread:.35,jitter:.5,sideLength:2.2,sideWidth:.9,layers:[{scale:1.35,alpha:.18},{scale:1,alpha:.45},{scale:.55,alpha:.95,core:!0}],shrink:.4,color:16751178,coreColor:16774368},At={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"]}},Zt={fullImpact:6,squash:.14,duration:260,minImpact:1.5},bn={maxFps:30},Qt={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:40,intensity:.6,duration:70,color:16773280}},glints:{enabled:!0,intensity:.8,size:1.2},shafts:{enabled:!0,rays:14,length:1.3,intensity:.35,shadows:!0,maxShadowCasters:4}},kn=N.levelZStride,Z=(i,t)=>i+kn*(t||0),gi=5,Fe=(i,t)=>Math.min(i||0,Math.round(t));function dt(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 _t(i,t,e,s){return!e||!s?{x:i,y:t}:{x:i+(i-e.x)*s,y:t+(t-e.y)*s}}function pt(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 Me(i){const t=typeof i=="number"?i:i.x,e=typeof i=="number"?i:i.y;return{x:t,y:e}}function ae(i,t,e){return Math.floor(i/t/e)}function Tn(i,t,e){return Math.round(i/t/e)}function An(i,t,e){return{map:i,scale:t,step:e}}function yi(i,t,e,s){const n=ae(t,i.scale.x,i.step),o=ae(e,i.scale.y,i.step),r=i.map?.[o]?.[n];return r!==void 0&&s.has(r)}function xi(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 Ln(i,t,e,s,n,o){return i?.map?xi((r,a)=>yi(i,r,a,t),e,s,n,o):!1}function Pn(i,t,e,s,n,o,r){return!i||i.size===0?!1:xi((a,l)=>i.has(`${ae(a,e.x,t)},${ae(l,e.y,t)}`),s,n,o,r)}const wi=i=>i.radius*(1-i.softness),Cn=(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 En({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),c=Cn(wi(r),r.radius,h);return r.minAlpha+(1-r.minAlpha)*c}function In(i,t,e){return(t||0)<(i||0)?e.lowerTint:16777215}const zn=`
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
- `,Ps=`
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 Rn(i){const t=new ze({uHoleCenter:{value:new Float32Array([0,0]),type:"vec2<f32>"},uHoleParams:{value:new Float32Array([i.radius,wi(i),i.minAlpha]),type:"vec3<f32>"}});return new nn({glProgram:ds.from({vertex:rn,fragment:zn,name:"see-through-hole-filter"}),gpuProgram:on.from({vertex:{source:Ps,entryPoint:"mainVertex"},fragment:{source:Ps,entryPoint:"mainFragment"}}),resources:{holeUniforms:t}})}function Fn(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 Dn=.01;function os(){return{strength:0,filter:null,attached:!1,tick:null}}function vi(i,t){const e=st.shared.lastTime;return i.tick===e?0:(i.tick=e,Math.min(1,t*(st.shared.deltaMS/1e3)))}function ms(i,t,e){return i.strength+=((t?1:0)-i.strength)*e,i.strength}function gs(i,t,e,s,n,o){if(t.strength<Dn||!n){t.attached&&(i.filters=[],t.attached=!1);return}t.filter||(t.filter=Rn(e)),t.attached||(i.filters=[t.filter],t.attached=!0);const r=_t(s.x,s.y,o,s.z*N.shear);Fn(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:1+(e.minAlpha-1)*t.strength})}function rs(i,t){if(!i.filter){i.attached=!1;return}t.filters=[],i.attached=!1,i.filter.destroy(),i.filter=null}async function Mi(i,t){const e={};t.frames.forEach((o,r)=>{const[a,l,h,c]=o;e[`frame${r}`]={frame:{x:a,y:l,w:h,h:c}}});const s={frames:e,meta:{scale:"1"}},n=new an(i,s);return await n.parse(),n}async function ys({baseTexture:i,spriteSheetData:t,map:e,tiles:s,step:n,renderer:o,exclude:r=[]}){const a=await Mi(i,t),l=new Set(r),h=s.filter(f=>!l.has(f)),c=e[0].length*n,u=e.length*n,_=new K;for(let f=0,p=e.length;f<p;f+=1)for(let m=0,y=e[f].length;m<y;m+=1){const x=e[f][m];if(h.includes(x)){const S=`frame${x}`,w=a.textures[S];if(w){const v=new Q(w);v.x=m*n,v.y=f*n,_.addChild(v)}else console.warn(`Texture not found. Tile: ${x}, sprite: ${S}`)}}const d=o.generateTexture({target:_,frame:new ht(0,0,c,u)});return _.destroy({children:!0}),a.destroy(),d}function Xn(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),c=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:c?t(s.railMin,n):null,rail1:c?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 Yn(e)}function Yn(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 xs(i){const t=new ln(i);return t.geometry.batchMode="batch",t}const Vn=1e-6,On=1e3,Si=[0,1,3,0,3,2];function Bn(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 bi(i,t){return Math.max(1,Math.ceil(i*t-1e-9))}function Nn({map:i,tiles:t,step:e,baseScale:s,level:n,volume:o,shear:r,sideTint:a,textures:l,tilesPerLevel:h=1,segments:c=1}){const u=Bn(i,new Set(t)),_=n*r,d=(n+o)*r,f=d-Vn,p=Math.max(1,Math.ceil(o*c-1e-9)),m=bi(o,h),y=o*h/m,x=(p+1)*2,S=Math.max(1,Math.floor(On/p)),w=[],v=new Map;for(const k of u)v.has(k.tile)||v.set(k.tile,[]),v.get(k.tile).push(k);for(const[k,M]of v){const E=l?.get(k);if(!E){console.warn(`buildVolumeWalls: no side texture for tile ${k}`);continue}for(let A=0;A<M.length;A+=S){const C=M.slice(A,A+S),R=C.length,X=R*x,z=new Float32Array(X*2),F=new Float32Array(X),Y=new Float32Array(X*2),B=new Uint32Array(R*p*6),V=new Float32Array(R*2),G=new Float32Array(R*2);for(let U=0;U<R;U+=1){const{nx:gt,ny:Et,x0:Nt,y0:Wt,x1:Ut,y1:Ht}=C[U],rt=Nt*e,Gt=Wt*e,$t=Ut*e,It=Ht*e,zt=U*x;for(let g=0;g<=p;g+=1)for(let b=0;b<2;b+=1){const L=zt+g*2+b;z[L*2]=(b===1?$t:rt)*s.x,z[L*2+1]=(b===1?It:Gt)*s.y,F[L]=d-(d-_)*g/p,Y[L*2]=b,Y[L*2+1]=y*g/p}for(let g=0;g<p;g+=1){const b=zt+g*2,L=(U*p+g)*6;for(let T=0;T<6;T+=1)B[L+T]=b+Si[T]}V[U*2]=gt,V[U*2+1]=Et,G[U*2]=(rt+$t)/2*s.x,G[U*2+1]=(Gt+It)/2*s.y}const j=xs({texture:E,vertices:z.slice(),uvs:Y,indices:B});j.tint=a,w.push({target:j,k:f,base:z,heights:F,rows:p,k0:_,k1:d,occluder:!0,walls:!0,normals:V,centers:G,facing:new Uint8Array(R).fill(2)})}}return w}function ki(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 Wn(i,t,e=0){if(ki(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 c=0,u=o.length;c<u;c+=1){const _=n[c*2],d=n[c*2+1],f=_-t.x,p=d-t.y,m=c%l<2,y=Math.sqrt(f*f+p*p)||1e-6,x=o[c]+(m?h/y:0);a[c*2]=_+f*x,a[c*2+1]=d+p*x}s.vertices=a}function Un(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 _=0;_<a;_+=1){const f=s[_*2]*(t.x-n[_*2])+s[_*2+1]*(t.y-n[_*2+1])>0?1:0;o[_]!==f&&(o[_]=f,h=!0)}if(!h)return!1;const c=e.geometry.indices;let u=0;for(let _=0;_<2;_+=1)for(let d=0;d<a;d+=1)if(o[d]===_)for(let f=0;f<r;f+=1){const p=d*l+f*2;for(let m=0;m<6;m+=1)c[u]=p+Si[m],u+=1}return e.geometry.indices=c,!0}function Hn({runs:i,texture:t,step:e,shear:s,baseScale:n,segments:o,sideTint:r}){const a=[],l=t.width||1,h=t.height||1,c=Math.max(1,Math.round(o)||1);for(const u of i){const _=u.axis===0,d=_?u.col1-u.col0:u.row1-u.row0,f=Math.max(1,d*c),p=_?u.col0:u.row0,m=typeof u.rail0=="number"&&typeof u.rail1=="number"?{first:(u.rail0-p)*c,last:(u.rail1-p)*c}:null,y=u.col0*e,x=u.col1*e,S=u.row0*e,w=u.row1*e,v=f+1,k=Math.min(u.from,u.to),M=Math.max(u.from,u.to),E=k*s,A=new Float32Array(v*4),C=new Float32Array(v*4),R=new Float32Array(v*4),X=new Float32Array(v*2),z=new Uint32Array(f*6),F=1;for(let B=0;B<v;B+=1){const V=B/f,G=u.sign>0?V:1-V,j=(u.from+(u.to-u.from)*G)*s,U=_?y:S,Et=U+((_?x:w)-U)*V,Nt=_?Et:y,Wt=_?S:Et,Ut=_?Et:x,Ht=_?w:Et,rt=B*4;A[rt]=Nt*n.x,A[rt+1]=Wt*n.y,A[rt+2]=Ut*n.x,A[rt+3]=Ht*n.y,C[rt]=Nt/l,C[rt+1]=Wt/h,C[rt+2]=Ut/l,C[rt+3]=Ht/h;const Gt=_?Wt+F:Nt+F,$t=_?Ht-F:Ut-F,It=Math.min(Math.max(Et,(_?y:S)+F),(_?x:w)-F);R[rt]=(_?It:Gt)/l,R[rt+1]=(_?Gt:It)/h,R[rt+2]=(_?It:$t)/l,R[rt+3]=(_?$t:It)/h,X[B*2]=j,X[B*2+1]=j}for(let B=0;B<f;B+=1){const V=B*2,G=B*6;z[G]=V,z[G+1]=V+1,z[G+2]=V+3,z[G+3]=V,z[G+4]=V+3,z[G+5]=V+2}const Y=xs({texture:t,vertices:A.slice(),uvs:C,indices:z});a.push(Gn({base:A,uvs:R,heights:X,points:v,texture:t,kBase:E,sideTint:r,endIndex:u.sign>0?v-1:0,rails:m})),a.push({target:Y,k:M*s,base:A,heights:X})}return a}function Gn(i){const{base:t,uvs:e,heights:s,points:n,texture:o,kBase:r,endIndex:a,sideTint:l,rails:h}=i,c=h?Math.max(0,Math.min(h.first,n-1)):0,u=h?Math.max(c,Math.min(h.last,n-1)):-1,_=h?u-c+1:0,d=_*2+2,f=new Float32Array(d*4),p=new Float32Array(d*4),m=new Float32Array(d*2),y=Math.max(0,_-1)*2+1,x=new Uint32Array(y*6),S=k=>k<_?(c+k)*2:k<_*2?(c+k-_)*2+1:a*2+(k-_*2);for(let k=0;k<d;k+=1){const M=S(k),E=k*4,A=t[M*2],C=t[M*2+1];f[E]=A,f[E+1]=C,f[E+2]=A,f[E+3]=C,p[E]=e[M*2],p[E+1]=e[M*2+1],p[E+2]=e[M*2],p[E+3]=e[M*2+1],m[k*2]=s[M],m[k*2+1]=r}let w=0;for(let k=0;k<3;k+=1){const M=k===2?_*2:k*_,E=k===2?_*2+1:M+_-1;for(let A=M;A<E;A+=1){const C=A*2,R=w*6;x[R]=C,x[R+1]=C+1,x[R+2]=C+3,x[R+3]=C,x[R+4]=C+3,x[R+5]=C+2,w+=1}}const v=xs({texture:o,vertices:f.slice(),uvs:p,indices:x});return v.tint=l,{target:v,k:r,base:f,heights:m}}function $n(i,t){if(ki(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],c=n[r];o[r*2]=l+(l-t.x)*c,o[r*2+1]=h+(h-t.y)*c}e.vertices=o}const de={mapSprite:null,occluder:null,slices:[],rampTexture:null,wallTextures:[]};function Kn({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 Zn(i){try{const t=await i.baseTexture;if(i.isAborted())return de;const e=await ys({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),de;const s=new Q(e);if(i.layerRoot.addChildAt(s,0),!i.extruding)return{...de,mapSprite:s};const n=await qn(i,t,e),o={mapSprite:s,...n};return i.isAborted()?(Kn({...o,bakedTexture:e}),de):o}catch(t){return console.error(`Failed to create static map with asset ${i.assetUrl}:`,t),de}}async function qn(i,t,e){const s=N.shear,n=[],o=[];let r=null,a=null;if(i.volume>0){r=new K,r.zIndex=Z(Math.max(i.layer,gi),i.level);{const h=await jn(i,t,o);if(i.isAborted())return{occluder:r,slices:n,rampTexture:a,wallTextures:o};n.push(...Nn({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 c=new Q(e);c.tint=16777215,n.push({target:c,k:(i.level+i.volume)*s,occluder:!0})}}const l=Ti(i);if(l.length){if(a=await ys({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(...Hn({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,c)=>h.k-c.k);for(const h of n)h.base||pt(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 jn(i,t,e){const s=new Map,n=bi(i.volume,Ft.faceTilesPerLevel);for(const o of i.tiles){const r=await ys({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 Ti(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 Xn(e,(n,o)=>Tn(n,o===0?i.baseScale.x:i.baseScale.y,i.step))}function Qn(i,t){if(!i.levelView)return;const e=i.levelView.cfg,s=vi(i.hole,e.fadeRate);i.hasSprite&&Jn(i,e,s,t),i.occluder&&to(i,e,s,t)}function Jn(i,t,e,s){const{levelView:n,container:o}=i,r=i.roof?n.level<i.level&&so(i,t,s):null;if(n.mode==="layer"){const h=(i.roof?r:n.level<i.level&&yi(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;ms(i.hole,a,e),gs(o,i.hole,t,n,i.stage,s)}function to(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}ms(i.occluderHole,r,e),gs(o,i.occluderHole,t,n,i.stage,s)}function eo(i,t){const e=i.levelView;return _t(e.x,e.y,t,e.z*N.shear)}function so(i,t,e){return e?Ln(i.grid,i.tileSet,eo(i,e),e,[i.level*N.shear],t.roofMargin??0):!1}const Cs=(i,t)=>Math.round(i/t)*t;function Ai(i,t,e,s,n,o,r){const a=Cs(i,n),l=Cs(t,o),h=Math.abs(e)>1e-9&&Math.abs(i-a)<=r,c=Math.abs(s)>1e-9&&Math.abs(t-l)<=r;return h&&(!c||Math.abs(e)>=Math.abs(s))?{axis:"x",coord:a,nx:e>0?-1:1,ny:0}:c?{axis:"y",coord:l,nx:0,ny:s>0?-1:1}:null}function Es(i,t,e,s){return i.nx*(s.x-t)+i.ny*(s.y-e)>0}function io({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,c=l?e:s,u=l?o.x:o.y;return Math.abs(c)<1e-9?null:(n.coord+(n.coord-u)*a+u*r-h*(1+r))/(c*(1+r))}const no=40,Li=45,oo=1.5;function ro(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 ao(i){const t=i?.map?.length||0,e=i?.map?.[0]?.length||0,s=ro(JSON.stringify(i?.game?.lighting??null));return`${e}x${t}:${s.toString(16)}`}function lo(i,t,e,s){const{x:n,y:o}=Me(s);return{x:(i+.5)*e*n,y:(t+.5)*e*o}}function Ge(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 Is(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 Ce(i,t,e,s,n,o){const r=e*o,a=_t(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 ho(i,t,e){return!e&&Math.abs(t-Math.round(t))>.001?[Math.floor(t),Math.ceil(t)]:[Fe(i,t)]}function as(i,t,e,s,n){return i+e>=0&&i-e<=s&&t+e>=0&&t-e<=n}function De(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 Pi(i,t){if(!(t>0)||i>=t)return 0;const e=1-Math.max(0,i)/t;return e*e}function Ci(i){return(1-i)*(1-i)}const co=.35;function Ei(i){return(1-i)*(1-i*co)}function uo(i,t){return!(t>0)||i>=t?0:Ci(Math.max(0,i)/t)}function Ii(i,t,e){const s=t-i.x,n=e-i.y,o=i.intensity??1;if(i.kind!=="cone")return o*uo(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 c=l*(i.spread??.5);if(h>=c)return 0;const u=l/i.radius;return o*Ei(u)*(1-h/c)}function fo(i,t,e,s){const n=[];for(const{light:o,factor:r}of i){const a=Ii(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 zi=(i,t)=>`${i},${t}`;function _o(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 c=l;c<=h;c+=1)for(let u=r;u<=a;u+=1){const _=zi(u,c);s.has(_)||s.set(_,[]),s.get(_).push(n)}}return{cellSize:e,cells:s}}function po(i,t,e){if(!i)return[];const s=Math.floor(t/i.cellSize),n=Math.floor(e/i.cellSize);return i.cells.get(zi(s,n))||[]}function mo(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),c=l-h,u=l+h;return[i+Math.cos(c)*a,t+Math.sin(c)*a,i+Math.cos(c)*o,t+Math.sin(c)*o,i+Math.cos(u)*o,t+Math.sin(u)*o,i+Math.cos(u)*a,t+Math.sin(u)*a]}function go(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 yo(i,t,e,s,n,o){const r=i.axis===0,a=r?i.col1-i.col0:i.row1-i.row0,l=Math.max(1,a*Math.max(1,Math.round(o)||1)),h=i.col0*t*e.x,c=i.col1*t*e.x,u=i.row0*t*e.y,_=i.row1*t*e.y,d=(m,y,x)=>[m+(m-s.x)*x,y+(y-s.y)*x],f=[],p=[];for(let m=0;m<=l;m+=1){const y=m/l,x=i.sign>0?y:1-y,S=(i.from+(i.to-i.from)*x)*n;if(r){const w=h+(c-h)*y;f.push(d(w,u,S)),p.push(d(w,_,S))}else{const w=u+(_-u)*y;f.push(d(h,w,S)),p.push(d(c,w,S))}}return[...f,...p.reverse()].flat()}function ws(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 c=e>0?1:-1,u=s>0?1:-1,_=e!==0?Math.abs(r/e):1/0,d=s!==0?Math.abs(a/s):1/0;let f=1/0,p=1/0;for(e!==0&&(f=((e>0?l+1:l)*r-i)/e),s!==0&&(p=((s>0?h+1:h)*a-t)/s);;){const m=l,y=h;let x;if(f<p?(x=f,l+=c,f+=_):(x=p,h+=u,p+=d),!(x<n))return n;if(o(l,h,m,y,i+e*x,t+s*x))return Math.max(0,x)}}const xo=.2;function vs(i,t,e,s,n){const o=i.axis===0,r=o?i.col0*s:i.row0*n,a=o?i.col1*s:i.row1*n,l=o?t:e,h=a-r||1,c=Math.min(1,Math.max(0,(l-r)/h)),u=i.sign>0?c:1-c;return i.from+(i.to-i.from)*u}function wo({lane:i,prevLane:t,col:e,row:s,prevCol:n,prevRow:o,x:r,y:a,z:l,cellW:h,cellH:c,clearance:u=xo}){if(t&&t!==i){const f=t.axis===0?s!==o:e!==n;return!!i||!f}return!i||t===i||n===null||n===void 0||(i.axis===0?e-n:s-o)===i.sign?!1:vs(i,r,a,h,c)-(l||0)>u}function zs(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),c=Math.min(e-1,r);for(let u=h;u<=c;u+=1){const _=u*t;for(let d=a;d<=l;d+=1)if(i[_+d]!==0)return!0}return!1}function vo(i,t,e,s,n,o,r,a){const l=ws(i,t,e,s,n,o,r,a);return l>=n?null:{distance:l,x:i+e*l,y:t+s*l}}function Mo({x:i,y:t,rotation:e,alongMax:s,alongBack:n=0,acrossMax:o,rays:r},a,l,h){const c=Math.max(2,Math.round(r)||2),u=n>0,_=u?Math.max(3,Math.round(c/8)):0,d=[];for(let y=0;y<c;y+=1)d.push(-Math.PI/2+Math.PI*y/(c-1));for(let y=0;y<_;y+=1)d.push(Math.PI/2+Math.PI*(y+1)/(_+1));const f=new Float32Array((d.length+1)*2),p=new Float32Array(d.length);let m=!1;return f[0]=i,f[1]=t,d.forEach((y,x)=>{const S=e+y,w=Math.cos(S),v=Math.sin(S),k=Math.cos(y),M=Math.abs(Math.sin(y));let E=M>1e-9?o/M:1/0;k>1e-9?E=Math.min(E,s/k):k<-1e-9&&(E=Math.min(E,n/-k));const A=ws(i,t,w,v,E,a,l,h);p[x]=E,A<E-1e-6&&(m=!0),f[(x+1)*2]=i+w*A,f[(x+1)*2+1]=t+v*A}),{points:f,clipped:m,closed:u,reaches:p,forward:c}}function Ms(i,t,{x:e,y:s,rotation:n,sx:o,sy:r,margin:a,width:l,height:h},c=Math.cos(n),u=Math.sin(n)){const _=i-e,d=t-s,f=_*c+d*u,p=d*c-_*u;return[(a+f/o)/l,(h/2+p/r)/h]}function So(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]=Ms(i[o],i[o+1],t,e,s);n[o]=r,n[o+1]=a}return n}const bo=[0,1,3,0,3,2];function ko({x:i,y:t,points:e,reaches:s,forward:n,uvOf:o,wallAt:r,cellW:a,cellH:l,height:h}){const c=.01*Math.min(a,l),u=w=>{const v=e[w*2],k=e[w*2+1],M=Math.hypot(v-i,k-t),E=s[w-1];if(!(M>1e-9)||!(M<E-1e-6))return null;const A=(v-i)/M,C=(k-t)/M,R=Ai(v,k,A,C,a,l,.001);if(!R)return null;const X=r(v+A*c,k+C*c);return X>0?{face:R,x:v,y:k,endX:v+A*(E-M),endY:k+C*(E-M),height:Math.min(h,X)}:null},_=[];for(let w=1;w<=n;w+=1)_.push(u(w));const d=[];for(let w=0;w+1<_.length;w+=1){const v=_[w],k=_[w+1];v&&k&&v.face.axis===k.face.axis&&Math.abs(v.face.coord-k.face.coord)<1e-6&&d.push([v,k])}if(!d.length)return null;const f=new Float32Array(d.length*8),p=new Float32Array(d.length*4),m=new Float32Array(d.length*8),y=new Uint32Array(d.length*6),x=new Float32Array(d.length*2),S=new Float32Array(d.length*2);return d.forEach(([w,v],k)=>{[[w.x,w.y,w.height,w.endX,w.endY],[v.x,v.y,v.height,v.endX,v.endY],[w.x,w.y,0,w.x,w.y],[v.x,v.y,0,v.x,v.y]].forEach(([E,A,C,R,X],z)=>{const F=k*4+z,[Y,B]=o(R,X);f[F*2]=E,f[F*2+1]=A,p[F]=C,m[F*2]=Y,m[F*2+1]=B});for(let E=0;E<6;E+=1)y[k*6+E]=k*4+bo[E];x[k*2]=w.face.nx,x[k*2+1]=w.face.ny,S[k*2]=(w.x+v.x)/2,S[k*2+1]=(w.y+v.y)/2}),{base:f,heights:p,uvs:m,indices:y,normals:x,mids:S}}function ls(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 te(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 c=(e-r[t])/(a[t]-r[t]);n.push([r[0]+(a[0]-r[0])*c,r[1]+(a[1]-r[1])*c])}}return n}function To({points:i,closed:t,lane:e,frame:s,cellW:n,cellH:o,segmentsPerCell:r}){const a=e.axis===0,l=a?e.col0*n:e.row0*o,h=a?e.col1*n:e.row1*o,c=a?e.row0*o:e.col0*n,u=a?e.row1*o:e.col1*n,_=z=>a?[i[z*2],i[z*2+1]]:[i[z*2+1],i[z*2]],d=i.length/2;let f=1/0,p=-1/0,m=1/0,y=-1/0;for(let z=0;z<d;z+=1){const[F,Y]=_(z);f=Math.min(f,F),p=Math.max(p,F),m=Math.min(m,Y),y=Math.max(y,Y)}if(!(p>l&&f<h&&y>c&&m<u))return null;const x=a?e.col1-e.col0:e.row1-e.row0,S=Math.max(1,x*Math.max(1,Math.round(r)||1)),w=(h-l)/S,v=Math.cos(s.rotation),k=Math.sin(s.rotation),M=[],E=[],A=[],C=[],R=z=>{const F=E.length;for(const[Y,B]of z){const V=a?Y:B,G=a?B:Y,[j,U]=Ms(V,G,s,v,k);M.push(V,G),E.push(vs(e,V,G,n,o)),A.push(j,U)}for(let Y=1;Y+1<z.length;Y+=1)C.push(F,F+Y,F+Y+1)},X=ls(d-1,t);for(let z=0;z<X.length;z+=3){let F=[_(X[z]),_(X[z+1]),_(X[z+2])];if(F=te(F,1,c,!0),F=te(F,1,u,!1),F=te(F,0,l,!0),F=te(F,0,h,!1),F.length<3)continue;const Y=Math.min(...F.map(([j])=>j)),B=Math.max(...F.map(([j])=>j)),V=Math.max(0,Math.floor((Y-l)/w)),G=Math.min(S-1,Math.ceil((B-l)/w)-1);for(let j=V;j<=G;j+=1){const U=te(te(F,0,l+j*w,!0),0,l+(j+1)*w,!1);U.length>=3&&R(U)}}return C.length?{base:new Float32Array(M),heights:new Float32Array(E),uvs:new Float32Array(A),indices:new Uint32Array(C)}:null}function Ao(i=st.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 Lo=Ao();function Po(i,t){return Math.floor(i*t)/t}function Co(i){return new Set(Object.keys(i||{}).map(Number))}function Eo(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 Ri(i,t,e){return!(e>0)||!(t>0)?0:Math.floor(i*t)%e}function Io(i,t,e){const s=new K,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(u=>t.textures[`frame${u}`]).filter(Boolean);if(h.length===0){console.warn(`Animated tile ${l}: no frames found in the sprite sheet`);continue}const c={id:l,fps:Eo(a,i.step,i.scale),textures:h,sprites:[],container:new K,frame:0};c.container.label=`animatedTile-${l}`;for(let u=0;u<i.map.length;u+=1){const _=i.map[u];for(let d=0;d<_.length;d+=1){if(_[d]!==l)continue;const f=new Q(h[0]);f.x=d*i.step,f.y=u*i.step,f.cullable=!0,c.sprites.push(f),c.container.addChild(f)}}if(c.sprites.length===0){c.container.destroy();continue}s.addChild(c.container),n.push(c)}return{container:s,groups:n}}function zo(i,t,e=()=>!0){for(let s=0;s<i.length;s+=1){const n=i[s];if(!e(n.container))continue;const o=Ri(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 Ro(i){i.container.parent?.removeChild(i.container),i.container.destroy({children:!0,texture:!1,textureSource:!1}),i.groups.length=0}function Rs(i,t,e){return(i||[]).filter(s=>(s.level||0)===t&&Number(s.layer)===e)}function Fo(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(u=>t.textures[`frame${u}`]).filter(Boolean);if(h.length===0){console.warn(`Decal at [${r}, ${a}]: frame not found in the sprite sheet`);continue}const c=new Q(h[0]);c.anchor.set(.5),c.position.set((r+.5)*e,(a+.5)*e),s.addChild(c),n.push({item:o,sprite:c,textures:h,frame:0})}return n}function Do(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=Ri(t,s.item.fps,s.textures.length);n!==s.frame&&(s.frame=n,s.sprite.texture=s.textures[n])}}}function Xo(i){for(const t of i)t.sprite.parent?.removeChild(t.sprite),t.sprite.destroy({texture:!1,textureSource:!1});i.length=0}const Yo=.8,$e=.6,Fs=.09,Vo=.12,Oo=.55;function Fi(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 Bo(i,t,e=0){return Fi((Math.imul(i,73856093)^Math.imul(t,19349663)^Math.imul(e,83492791))>>>0)}function Ds(i,t,e){return Fi((i^Math.imul(t+e,668265261))>>>0)/4294967296}const _e=i=>Math.min(1,Math.max(0,i));function No(i,t,e){if(!(e>0))return!1;const s=Math.floor(i/$e);if(Ds(t,s,0)>=e)return!1;const n=s*$e+Ds(t,s,1)*($e-Fs);return i>=n&&i<n+Fs}function Wo(i,t,e){const s=_e(e?.pulse||0),n=t%1e3/1e3,o=1-s*(.5+.5*Math.sin(2*Math.PI*(Yo*i+n)));return No(i,t,e?.dropouts||0)?{core:_e(o*Vo),glow:_e(o*Oo)}:{core:_e(o),glow:_e(o)}}const Uo=4;function St(i){return Math.ceil(i*Uo)}function Di(i){return St(i)*2}const hs=new WeakMap;function Xi({text:i,size:t}){return`${t}|${i}`}function Ho(i){return Math.max(2,Math.round(i/4))}function Go(i,{text:t,size:e}){const s=Ho(e),n=St(s),o=new K,r=new _i({text:String(t),style:{fontFamily:"monospace",fontWeight:"bold",fontSize:e,fill:16777215}});r.position.set(n,n),o.addChild(r);const a=new ht(0,0,Math.ceil(r.width)+n*2,Math.ceil(r.height)+n*2),l=i.generateTexture({target:o,frame:a}),h=new _s({strength:s,quality:6});h.padding=Di(s),r.filters=[h];const c=i.generateTexture({target:o,frame:a});return r.filters=[],h.destroy(),o.destroy({children:!0}),{core:l,glow:c}}function $o(i,t){let e=hs.get(i);e||(e=new Map,hs.set(i,e));const s=Xi(t);let n=e.get(s);return n||(n={...Go(i,t),count:0},e.set(s,n)),n.count+=1,{core:n.core,glow:n.glow}}function Ko(i,t){const e=hs.get(i),s=Xi(t),n=e?.get(s);n&&(n.count-=1,!(n.count>0)&&(e.delete(s),n.core.destroy(!0),n.glow.destroy(!0)))}class Zo{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=Bo(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 c=$o(e,t);this.glow=this._sprite(c.glow),this.core=this._sprite(c.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 Q(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}:Wo(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=_t(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,()=>Ko(t,e)}}function qo(i,t,e,s){const n=Co(i?.animatedTiles),o=new Set(t);return{exclude:[...n],hasTiles:[...n].some(r=>o.has(r)),signs:Rs(i?.signs,e,s),decals:Rs(i?.decals,e,s)}}function Xs(i){return i.hasTiles||i.signs.length>0||i.decals.length>0}async function jo({spec:i,game:t,baseTexture:e,spriteSheetData:s,map:n,tiles:o,step:r,scale:a,level:l,animated:h,renderer:c,lighting:u,isAborted:_}){let d=null;if((i.hasTiles||i.decals.length>0)&&(d=await Mi(e,s),_()))return d.destroy(),null;const f={sheet:d,tiles:null,decals:[],signs:[],tick:null};return i.hasTiles&&(f.tiles=Io({map:n,tiles:o,step:r,scale:a},d,t.animatedTiles),h.addChild(f.tiles.container)),d&&(f.decals=Fo(i.decals,d,r,h)),f.signs=i.signs.map(p=>new Zo({sign:p,renderer:c,lighting:u,animated:h,step:r,scale:a,level:l})),f}function Qo(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 Jo(i,{camera:t,levelView:e,screen:s,roofAlpha:n=null}){const o=Po(Lo.now(),bn.maxFps),r=st.shared.lastTime;i.tick!==r&&(i.tick=r,i.tiles&&zo(i.tiles.groups,o,Qo(s)),Do(i.decals,o));for(let a=0;a<i.signs.length;a+=1)i.signs[a].update(o,t,e,n)}function tr(i){if(!i)return()=>{};i.tiles&&(Ro(i.tiles),i.tiles=null),Xo(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 er{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=os(),this._occluderHole=os(),this._occluder=null,this._baseScale=Me(e.scale),this._slices=[],this._rampTexture=null,this._wallTextures=[],this.mapSprite=null,this._assetUrl=`${n}${e.spriteSheet.img}`,this._baseTexturePromise=ss.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=sr(e.game,this._level,this._tiles),this._spriteSheetData=e.spriteSheet,this._step=e.step,this._layer=Number(e.layer)||1,t.zIndex=Z(this._layer,this._level),this._parallaxK=this._level*N.shear,this._layerRoot=new K,this._layerRoot.label="layerRoot",this._animated=new K,this._animated.label="animated",this._layerRoot.addChild(this._animated),pt(this._layerRoot,null,this._parallaxK,this._baseScale),t.addChild(this._layerRoot),this._animationSpec=qo(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=An(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=ao(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,Ge(this._map,this._roof?this._tiles:this._floor),this,{roof:this._roof}),this._ramps.length&&this._lighting.setRampWedges(this._level,Ti({ramps:this._ramps,rampRuns:this._rampRuns,level:this._level,baseScale:this._baseScale,step:this._step}),this),this._volume>0&&this._lighting.setVolumeTops(this._level,Ge(this._map,this._tiles),this._volume,this)),this._volumes=s.volumes||null,this._volume>0&&this._volumes?.setLayerVolume(this._level,Ge(this._map,this._tiles),this._volume,this,{step:this._step,scale:e.scale}),this.needsRender=this._level>=1||this._extruding||!!this._lighting?.isNight()||Xs(this._animationSpec),this._build(e)}async _build(t){const e=await Zn({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||!Xs(this._animationSpec))&&(this._animations=await jo({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:1+(this._levelView.cfg.minAlpha-1)*this._hole.strength}render(){this._attachOccluder(),this._levelView&&this._levelView.attachStage(this._container.parent,this._renderer);const t=this._levelView?this._levelView.camera():dt(this._container.parent,this._renderer);if(this._lighting&&(this._lighting.attachStage(this._container.parent,this._renderer),this._lighting.render()),(this._level>=1||this._occluder)&&Qn(this._seeThroughView(),t),this._animations&&Jo(this._animations,{camera:t,levelView:this._levelView,screen:this._renderer?.screen,roofAlpha:this._roofAlpha()}),!(!this._parallaxK&&!this._slices.length)&&t){pt(this._layerRoot,t,this._parallaxK,this._baseScale);for(let e=0;e<this._slices.length;e+=1){const s=this._slices[e];s.walls?(Wn(s,t,Ft.faceBleedPx),Un(s,t)):s.base?$n(s,t):pt(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=tr(this._animations);if(this._animations=null,this._lighting&&(this._lighting.releaseMap(this._mapKey,this),this._lighting=null),this._volumes?.release(this),this._volumes=null,rs(this._hole,t),this._occluder){const a=this._occluder;this._occluder=null,a.filters=[],rs(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=oe.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 sr(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 mt=(i,t,e)=>i+(t-i)*e,Vt=(i,t,e)=>Math.min(e,Math.max(t,i)),ir=i=>i*(Math.PI/180),nr=i=>{for(;i>Math.PI;)i-=Math.PI*2;for(;i<-Math.PI;)i+=Math.PI*2;return i},O=(i,t)=>Math.random()*(t-i)+i;class Jt extends K{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),st.shared.add(this._tickListener),this._onEffectStart(),this.isComplete||this._update(0))}_onEffectStart(){}_update(){}_completeEffect(){this.isComplete||(this.isComplete=!0,this._tickListener&&(st.shared.remove(this._tickListener),this._tickListener=null),typeof this.onComplete=="function"&&this.onComplete())}destroy(t){this.isComplete=!0,this._tickListener&&(st.shared.remove(this._tickListener),this._tickListener=null),this.parent&&this.parent.removeChild(this),super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}class or extends Jt{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(O(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=O(e.minInitialSpeed,e.maxInitialSpeed),r=this._textures[Math.floor(Math.random()*this._textures.length)],a=new Q(r),l=O(0,t);a.anchor.set(.5),a.tint=e.color[Math.floor(Math.random()*e.color.length)],a.scale.set(O(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:O(-e.maxSpin,e.maxSpin),lifetime:O(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:mt(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 Yi(i,{x:t,y:e,z:s,level:n,reach:o,exclude:r=null}){const a=i?.texture("glint");return!Qt.glints?.enabled||!a||!i.isNight()||!i.onScreen(t,e,s,o)?null:i.lightsAt(t,e,n,1,r)[0]||null}function Vi(i,t,e){if(i)return i;const s=new Q(e),n=new Q;return s.anchor.set(.5),s.blendMode="add",s.mask=n,t.addChild(n,s),{sprite:s,mask:n}}function Oi(i){i&&(i.sprite.visible=!1)}function Bi(i,{hit:t,asset:e,x:s,y:n,rotation:o,size:r}){const{sprite:a}=i,l=Qt.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 Lt=0,Pt=1,Ot=2,Ys=3,le=4,he=5,Bt=6,Ct=7,Ne=8,Xe=9,ce=11,vt=12,Ye=13,Vs=14,Os=15,rr=0,ar=1,lr=2,hr=3,cr=4,ur=5,fr=6,Ke=7,dr=8,_r=9,Bs=10,Ns=2,pr=3,Ws=0,Us=1,Hs=2,mr=3,gr=4,yr=6,xr=0,wr=1,vr=2,Mr=3,Gs=0,$s=1,Ks=2,Sr=3,br=4,kr=5,Zs=0,Tr=1,pe=2,Ar=1,Lr=2,Pr=1.4;class Cr{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=Me(e.scale),t.scale=e.scale,this._assetUrl=`${n}${e.img}`,this._baseTexturePromise=ss.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=Z(this._layer,this._level),this._rotation=ir(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 Q(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!==Zs&&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)&&pt(t,this._levelView.camera()??dt(t.parent,this._renderer),this._z*N.shear,this._baseScale)}update(t){this.sprite&&(this.sprite.x=t[Gs]/this._baseScale.x,this.sprite.y=t[$s]/this._baseScale.y,this.sprite.rotation=t[Ks]),this._worldX=t[Gs],this._worldY=t[$s],this._rotation=t[Ks],this._z=t[Sr]||0;const e=Fe(t[br],this._z);e!==this._level&&(this._level=e,this._container.zIndex=Z(this._drawLayer(),e),!e&&!this._z&&pt(this._container,null,0,this._baseScale));const s=t[kr]||Zs;if(s!==this._state){const n=this._state===null;this._state=s,this._showState(s),s===pe&&!n&&this._burst()}this._placeScorch()}_drawLayer(){return this._state===pe?Ar:this._layer}_standing(){return this._state!==pe||!!this._destroyedUrl}_updateGlint(){const t=this._localCenter(),e=this.sprite.visible&&this._standing()?Yi(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){Oi(this._glint);return}const s=this._lighting.texture("glint");this._glint=Vi(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,Bi(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=Z(this._drawLayer(),this._level),!this.sprite)return;if(t===pe&&!this._destroyedUrl){this.sprite.visible=!1,this._showScorch();return}this._scorch&&(this._scorch.visible=!1),this.sprite.visible=!0;let e=null;t===Tr?e=this._damagedUrl:t===pe&&(e=this._destroyedUrl),this._setTexture(e?ss.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 Q(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)*Pr/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 or(e,s,r,()=>{this._effects.delete(a),a.destroy()},o);a.zIndex=Z(Lr,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 Er=class extends K{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 Cr(this,t,s,n,e):new er(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 qs=[16777215,9418751,10477760,15783820,14721232,10541296,15773836,12632280],Ni=i=>qs[i]??qs[0],Ir=2,zr=.35;class Rr extends K{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=Z(Ir,this._level),this.scale=t.scale,this._draws=this._tiles.some(n=>this._solid.includes(n)),this.radarGraphics=new W,this.addChild(this.radarGraphics),this._levelView=s.levelView||null,this._levelView&&this._draws&&(this.onRender=()=>{this.alpha=this._levelView.level===this._level?1:zr}),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(Ni(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 js=2,Fr=9,Dr=1.5;class Xr extends K{constructor(t,e){super(),this._level=t[vt]||0,this.zIndex=Z(js,this._level),this._textures=e.tankRadarTexture,this.body=new Q,this.body.anchor.set(.5),this.levelRing=new W,this.addChild(this.levelRing,this.body),this._drawLevelRing(),this.x=t[Lt]||0,this.y=t[Pt]||0,this._condition=t[Ct],this._teamId=t[Xe],this.scale.set(5,5),this.create()}_drawLevelRing(){this.levelRing.clear(),this._level>0&&this.levelRing.circle(0,0,Fr).stroke({width:Dr,color:Ni(this._level)})}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[Lt],this.y=t[Pt];const e=t[vt]||0;e!==this._level&&(this._level=e,this.zIndex=Z(js,e),this._drawLevelRing());const s=t[Ct],n=t[Xe];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._textures=null}}function Yr({width:i,height:t,anchorX:e,anchorY:s,rotation:n,heading:o=0,pitch:r,roll:a,shear:l,lift:h}){const c=-e*i,u=(1-e)*i,_=-s*t,d=(1-s)*t,f=[[c,_],[u,_],[u,d],[c,d]],p=Math.cos(n),m=Math.sin(n),y=Math.cos(r),x=Math.sin(r),S=Math.cos(a),w=Math.sin(a),v=-Math.sin(o),k=-Math.cos(o),M=[];for(const[E,A]of f){const C=E*p-A*m,R=E*m+A*p,X=C*y,z=C*x,F=R*S,Y=R*w,B=z+Y,V=t?B/t*l:0,G=B*h;M.push(X*(1+V)+v*G,F*(1+V)+k*G)}return M}function Vr({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,c=(a*s[0]+l*s[1])/h;return 1-Math.max(0,-c)*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 Wi(i,t,{minImpact:e,fullImpact:s}){return!(i<-e)||t!==0?0:Math.min(1,-i/s)}function Or(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 Br({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 Ee=Math.PI*2,Nr=.09,Wr=.113;function Ur(i,t){return!(t>0)||i>=t?0:1-i/t}function Hr({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,c=Math.hypot(l,h),u=Ur(c,o.radius);if(!u)return null;const _=c<r.underShare*n,d=_?a()*Ee:Math.atan2(h,l)-s;return{strength:u,dirU:Math.cos(d),dirV:Math.sin(d),hop:_,phaseX:a()*Ee,phaseY:a()*Ee}}function Qs({elapsed:i,kick:t,config:e}){const s=t.strength,n=e.decay>0?Math.exp(-i/e.decay):0,o=n*Math.cos(Ee*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,c=i<e.shakeDuration?e.shake*s*(1-i/e.shakeDuration):0;return{pitch:r*t.dirU,roll:r*t.dirV,lift:l,shakeX:c*Math.sin(i*Nr+t.phaseX),shakeY:c*Math.sin(i*Wr+t.phaseY),envelope:s*n,done:i>=e.duration&&!a}}const Js=[[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]),ti={track:0,hull:1,turret:2,barrel:3};function Ui(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 Gr(i){let t=0,e=0,s=0;for(let o=0;o<i.length;o+=1){const[r,a,l]=i[o],[h,c,u]=i[(o+1)%i.length];t+=(a-c)*(l+u),e+=(l-u)*(r+h),s+=(r-h)*(a+c)}const n=Math.hypot(t,e,s)||1;return[t/n,e/n,s/n]}const me=(i,t,e,s)=>[[i,e],[t,e],[t,s],[i,s]],$r=(i,t)=>i.map(([e,s])=>[e*t,s*t]);function Kr(i=Mt){const t=[],e=[],s=({bottom:r,top:a,w0:l,w1:h,part:c,topMaterial:u,sideMaterial:_})=>{let d=r,f=a;Ui(d)<0&&(d=[...d].reverse(),f=[...f].reverse());const p=t.length,m=d.length;for(const[S,w]of d)t.push([S,w,l]);for(const[S,w]of f)t.push([S,w,h]);const y=S=>p+S,x=S=>p+m+S;e.push({indices:f.map((S,w)=>x(w)),part:c,material:u,kind:"top"}),e.push({indices:d.map((S,w)=>y(m-1-w)),part:c,material:"bottom",kind:"bottom"});for(let S=0;S<m;S+=1){const w=(S+1)%m;e.push({indices:[y(S),y(w),x(w),x(S)],part:c,material:_,kind:"side"})}};for(const[r,a]of[[-15,-9],[9,15]]){const l=me(-20,20,r,a);s({bottom:l,top:l,w0:0,w1:i.trackHeight,part:"track",topMaterial:"trackTop",sideMaterial:"trackSide"})}s({bottom:me(-18,18,-9,9),top:me(-16,14,-7,7),w0:i.hullBase,w1:i.hullTop,part:"hull",topMaterial:"hullTop",sideMaterial:"hullSide"}),s({bottom:Js,top:$r(Js,.6),w0:i.turretBase,w1:i.turretTop,part:"turret",topMaterial:"turretTop",sideMaterial:"turretSide"});const n=me(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=me(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 ei=new Set(["turret","barrel"]);function Zr({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),c=Math.sin(e),u=Math.cos(s),_=Math.sin(s),d=Math.cos(n),f=Math.sin(n),p=1-a,m=new Array(i.vertices.length);for(const v of i.faces)for(const k of v.indices)m[k]=v.part;const y=([v,k,M])=>{const E=k*d-M*f,A=k*f+M*d;return[v*u-A*_,E,v*_+A*u]},x=([v,k,M])=>[v*h-k*c,v*c+k*h,M],S=i.vertices.map(([v,k,M],E)=>{let A=[v*l,k*l,M*l*p];const C=m[E];return ei.has(C)&&(A=x(A)),C==="barrel"&&(A=[A[0]+o.x,A[1]+o.y,A[2]]),A=y(A),[A[0]+r.x,A[1]+r.y,A[2]]}),w=i.faces.map(v=>{let k=qr(i,v,p);return ei.has(v.part)&&(k=x(k)),y(k)});return{points:S,normals:w}}function qr(i,t,e){return Gr(t.indices.map(s=>{const[n,o,r]=i.vertices[s];return[n,o,r*e]}))}function jr({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,c=(t-e.y)*n*l/o;const u=Math.hypot(h,c)*a;if(u>0&&r>0){const f=r*Math.tanh(u/r)/u;h*=f,c*=f}const _=Math.cos(s),d=Math.sin(s);return{x:h*_+c*d,y:-h*d+c*_}}function Qr({points:i,lean:t,zScale:e=1}){return i.map(([s,n,o])=>[(s+t.x*o)*e,(n+t.y*o)*e])}function Jr({model:i,points:t,projected:e}){const s=[];return i.faces.forEach((n,o)=>{const r=n.indices.map(a=>e[a]);if(Ui(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)=>ti[n.face.part]-ti[o.face.part]||n.height-o.height||n.index-o.index),s.map(n=>n.index)}function ta(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 ea={track:"body",hull:"body",turret:"gun",barrel:"gun"},sa={trackSide:"trackSide",barrel:"barrelSide",brake:"brakeSide"};function ia(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 na(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:c,w:u,h:_}=n.bottom;return r.indices.map(()=>o([h+u/2,c+_/2]))}const a=sa[r.material];if(r.kind==="side"&&a&&ia(i,r)){const h=n[a],[c,u]=r.indices.map(p=>i.vertices[p]),_=Math.min(Math.hypot(u[0]-c[0],u[1]-c[1]),h.w),d=h.y,f=h.y+h.h;return[o([h.x,f]),o([h.x+_,f]),o([h.x+_,d]),o([h.x,d])]}const l=n[ea[r.part]];return r.indices.map(h=>{const[c,u]=i.vertices[h];return o([l.originX+c,l.originY+u])})})}const oa=`#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
- `,ra=`#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 si=null;function aa(i){return si||=ds.from({vertex:oa,fragment:ra,name:"tank-model"}),new pi({glProgram:si,resources:{uTexture:i.source,textureUniforms:new ze({uTextureMatrix:{value:i.textureMatrix.mapCoord,type:"mat3x3<f32>"}})}})}function la(i,t){i.resources.uTexture=t.source,i.resources.textureUniforms.uniforms.uTextureMatrix=t.textureMatrix.mapCoord}function ha(i,t){const e=[];let s=0,n=0;for(const d of i.faces)e.push(s),s+=d.indices.length,n+=d.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=d=>{na(i,d).forEach((f,p)=>{f.forEach(([m,y],x)=>{r[(e[p]+x)*2]=m,r[(e[p]+x)*2+1]=y})})};h(t);const c=new hn({attributes:{aPosition:{buffer:o,format:"float32x2"},aUv:{buffer:r,format:"float32x2"},aShade:{buffer:a,format:"float32"}},indexBuffer:l}),u=aa(t.texture),_=new Re({geometry:c,shader:u,texture:t.texture});return{mesh:_,setAtlas(d){h(d),c.getBuffer("aUv").update(),la(u,d.texture),_.texture=d.texture},update(d,f,p){i.faces.forEach((y,x)=>{const S=e[x];y.indices.forEach((w,v)=>{o[(S+v)*2]=d[w][0],o[(S+v)*2+1]=d[w][1],a[S+v]=f[x]})});let m=0;for(const y of p){const x=e[y],S=i.faces[y].indices.length;for(let w=1;w<S-1;w+=1)l[m]=x,l[m+1]=x+w,l[m+2]=x+w+1,m+=3}l.fill(0,m),c.getBuffer("aPosition").update(),c.getBuffer("aShade").update(),c.indexBuffer.update()},destroy(){_.destroy(),u.destroy(),c.destroy()}}}function ca(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 ua(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 fa({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,c,u]=t[l],_=Math.max(0,u+e);return[h+s.x*_,c+s.y*_]});o.push(ca(a))}return o}const da=`#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
- `,_a=`#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
- `,Se=i=>[Math.cos(i),Math.sin(i)];function Hi({heading:i,rotation:t,pitch:e,roll:s,lightDir:n,lightZ:o,ambient:r,diffuse:a}){const[l,h]=n||[0,0],c=Math.hypot(l,h,o)||1,u=[l/c,h/c,o/c],_=r+a*Math.max(u[2],0);return{uSpin:Se(t),uPitch:Se(e),uRoll:Se(s),uHeading:Se(i),uLight:u,uAmbient:r,uDiffuse:a,uNorm:_?1/_:1}}let ii=null;function pa(i,t){return ii||=ds.from({vertex:da,fragment:_a,name:"tank-light"}),new pi({glProgram:ii,resources:{uTexture:i.source,uNormal:t.source,textureUniforms:new ze({uTextureMatrix:{value:i.textureMatrix.mapCoord,type:"mat3x3<f32>"}}),tankLight:new ze({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 ma(i,t,e){i.resources.uTexture=t.source,i.resources.uNormal=e.source,i.resources.textureUniforms.uniforms.uTextureMatrix=t.textureMatrix.mapCoord}function ga(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 ya=0,xa=1,be=3;let ni=null;const Ze=()=>(ni||=Kr(Mt),ni),wa=()=>Hi({heading:0,rotation:0,pitch:0,roll:0,lightDir:Rt.lightDir,lightZ:qt.lightZ,ambient:qt.ambient,diffuse:qt.diffuse}),va=.55,Ma=.6,oi=7,Sa=1,ri=1.15,ba=1.25,ka=.6,Ta=1,Aa=.015,La=2.5;function Pa(i,t=0){const e=Number.isFinite(i)?i:0,s=Vt(e,0,1),n=Math.max(0,e-1),o=mt(Sa,ri,s)+(ba-ri)*n,r=mt(ka,Ta,s),a=1+Aa*(1-s)*Math.sin(2*Math.PI*La*(t/1e3));return{rate:o*a,volumeFactor:r}}function Ca(i=Rt.lightDir,t=kt.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 Ea extends K{constructor(t,e,s,n){super();const o=()=>{const u=new cn({verticesX:Rt.vertices,verticesY:Rt.vertices});return u.geometry.batchMode="batch",u};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=Mt.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._worldX=t[Lt]||0,this._worldY=t[Pt]||0,this.x=this._worldX,this.y=this._worldY,this.rotation=t[Ot]||0,this._gunRotation=t[Ys]||0,this._engineLoad=t[Bt]||0,this._condition=t[Ct],this._size=t[Ne],this._teamId=t[Xe],this._z=t[ce]||0,this._physLevel=t[vt]||0,this._vz=t[Ye]||0,this._prevVz=this._vz,this._pitch=t[Vs]||0,this._roll=t[Os]||0,this._landImpact=0,this._landTimer=0,this._squash=0,this._level=Fe(t[vt],this._z),this.zIndex=Z(be,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(u=>this._onBlast(u)):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[le]||0,t[he]||0);const c=this._soundManager.getSoundConfig("tankWater");this._baseWaterVolume=c?.volume||0,this._hasWaterSound=!!c,this.create()}_initSounds(){this._soundId||this._condition===0||!this._hasEngineSound||(this._soundId=this._soundManager.registerSound("tankEngine",this._getSoundData()))}_getSoundData(){const{rate:t,volumeFactor:e}=Pa(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)*Ma,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[Lt],this._worldY=t[Pt],this.rotation=t[Ot],this._gunRotation=t[Ys],this._engineLoad=t[Bt]||0,this._speed=Math.hypot(t[le]||0,t[he]||0),this._z=t[ce]||0,this._physLevel=t[vt]||0,this._vz=t[Ye]||0,this._pitch=t[Vs]||0,this._roll=t[Os]||0;const e=Wi(this._prevVz,this._vz,Zt);e>0&&(this._landImpact=e,this._landTimer=Zt.duration),this._prevVz=this._vz;const s=Fe(t[vt],this._z);s!==this._level&&(this._level=s,this.zIndex=Z(be,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[Ct],o=t[Xe];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}=At.water.sound,n=Vt(this._speed/e,0,1);return{position:{x:this._worldX,y:this._worldY},rate:mt(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*Qt.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}=Qt,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=ho(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=Kt.attack*Kt.duration;this._recoilElapsed=this._recoilElapsed<Kt.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*va;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+=st.shared.deltaMS;const t=Or(this._recoilElapsed,Kt.duration,Kt.attack);if(t===0&&this._recoilElapsed>=Kt.duration){this._resetRecoil();return}const e=Br({amount:t,gunRotation:this._gunRotation,config:Kt});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=Hr({x:this._worldX,y:this._worldY,level:this._physLevel,heading:this.rotation,hullLength:this._size*4,blast:t,config:fe});if(!e)return;const s=this._blastKick?Qs({elapsed:this._blastElapsed,kick:this._blastKick,config:fe}).envelope:0;e.strength>=s&&(this._blastKick=e,this._blastElapsed=0)}_stepBlast(){if(!this._blastKick)return;const t=this._blastKick.hop&&this._blastElapsed<fe.hopDuration;this._blastElapsed+=st.shared.deltaMS;const e=Qs({elapsed:this._blastElapsed,kick:this._blastKick,config:fe});if(t&&this._blastElapsed>=fe.hopDuration&&Zt.duration>0&&(this._landImpact=this._blastKick.strength,this._landTimer=Zt.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)ma(n,e,s);else{const o=pa(e,s);t.shader=o,this._lightShaders.set(t,o)}}_applyLight(){for(const[t,e]of this._lightShaders)ga(e,Hi({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(...Yr({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():dt(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=_t(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=Vt(Vr({angle:this.rotation,pitch:this._pitch,roll:this._roll,lightDir:Rt.lightDir,shading:Rt.shading}),ya,xa);this.tint=jt(e,n)}if(this._landTimer>0){this._landTimer=Math.max(0,this._landTimer-st.shared.deltaMS);const n=this._landTimer/Zt.duration;this._squash=Math.sin(n*Math.PI)*Zt.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()}_updateGlint(){const t=1+this._viewZ()*N.shear,e=Yi(this._lighting,{x:this._worldX,y:this._worldY,z:this._viewZ(),level:this._level,reach:this._size*2*t,exclude:this._ownLights});if(!e){Oi(this._glint);return}const s=this._lighting.texture("glint");this._glint=Vi(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)),Bi(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=ha(Ze(),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=Ze(),s=Zr({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=jr({x:this._worldX,y:this._worldY,camera:t,heading:this.rotation,shear:N.shear,levelHeight:Mt.levelHeight,maxLean:Mt.maxLean,gain:Mt.leanGain,topHeight:Mt.turretTop*this._size/10}),o=Qr({points:s.points,lean:n,zScale:1+this._viewZ()*N.shear});this._modelPose=s;const r=Jr({model:e,points:s.points,projected:o}),a=wa(),l=s.normals.map(h=>ta(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 W;this._modelShadowAlpha=new mi({alpha:1}),h.filters=Mt.shadowBlur?[new _s({strength:Mt.shadowBlur,quality:2}),this._modelShadowAlpha]:[this._modelShadowAlpha],this.parent.addChild(h),this._modelShadow=h}const e=this._modelShadow,s=this._groundZ(),n=_t(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=Z(be-1,Math.min(oi,Math.floor(s)));const r=fa({model:Ze(),points:this._modelPose.points,lift:o*Mt.levelHeight,drift:ua(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,kt.baseAlpha-o*kt.alphaFalloff):kt.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||kt.groundOffset>0))){this._shadow&&(this._shadow.visible=!1);return}if(!this._shadow){const{texture:c,contentSize:u}=this._shadowAsset;this._shadow=new Q(c),this._shadow.anchor.set(.5),this._shadowScale=this._size*4*kt.sizeFactor/u,this.parent.addChild(this._shadow)}const n=this._shadow;n.visible=!0;const o=this._groundZ(),r=_t(this._worldX,this._worldY,t,o*N.shear),a=Ca();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*kt.scaleGain));const h=e?Math.max(0,kt.baseAlpha-l*kt.alphaFalloff):kt.groundAlpha;n.alpha=h*this.alpha,n.zIndex=Z(be-1,Math.min(oi,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._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 Ia=2;class za extends K{constructor(t,e,s){super(),this._level=t[yr]||0,this.zIndex=Z(Ia,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 Q(e.bombTexture),this.body.anchor.set(.5),this._worldX=t[Ws],this._worldY=t[Us],this.x=this._worldX,this.y=this._worldY,this.rotation=t[Hs],this._size=t[mr],this._totalDurationMs=t[gr],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 _i({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),st.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[Ws],this._worldY=t[Us],this.x=this._worldX,this.y=this._worldY,this.rotation=t[Hs],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=dt(this.parent,this._renderer),s=_t(this._worldX,this._worldY,e,t);this.position.set(s.x,s.y),this.scale.set(1+t)}_stopTimer(){this._tickListener&&(st.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 Ra extends Jt{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 Q(r),this._mainBody.anchor.set(.5),this._mainBody.tint=11393254,this._mainBody.scale.set(this._baseScale),this._core=new Q(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 qe=[],Dt={get(i){if(qe.length>0){const t=qe.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 un({texture:i,anchorX:.5,anchorY:.5})},release(i){i&&qe.push(i)}},cs=50,Fa=400,Da=800;class Xa extends Jt{constructor(t,e=cs){super();const s=e/cs;this._blastScale=s;const{texture:n,contentSize:o}=t.explosionTexture;this.explosionTexture=n,this._unitScale=1/o;const r=Fa*s,a=Da*s;this._particleContainer=new ps({texture:this.explosionTexture,boundsArea:new ht(-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=Dt.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),Dt.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)Dt.release(this._particles[e].view);this._particles=[],super.destroy(t)}}const Ya=.168,Va=.225,ai=.15,Oa=2e4,Ba=50,Na=4e3,Wa=4e3;class Ua extends Jt{constructor(t,e,s,n,o){super(n),this._assets=o,this._radius=s,this.x=t,this.y=e,this._funnelDurationMs=Oa,this._funnelFadeInDurationMs=Ba,this._funnelFadeDurationMs=Na,this._elapsedMs=0,this._smokeDurationMs=Wa,this._smokeSpawningStopped=!1,this._funnel=this._createFunnelSprite(),this._smoke=new Xa(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 Q(s);n.anchor.set(.5),n.alpha=0,n.rotation=Math.random()*Math.PI*2;const o=this._radius*Ya*O(1-ai,1+ai);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=Va*Vt(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 Ha=4,Ga=2;class $a extends K{constructor(t,e,s){super(),this.originX=t[xr],this.originY=t[wr],this.radius=t[vr]??cs,this._level=t[Mr]||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=dt(this.parent,this._renderer),s=_t(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({...Qt.flash.explosion,level:this._level,x:this.originX,y:this.originY,z:this._level}),this.explosion=new Ra(this.originX,this.originY,this.radius,this._onExplosionComplete.bind(this),this._assets),this.explosion.zIndex=Z(Ha,this._level),this.funnel=new Ua(this.originX,this.originY,this.radius,this._onFunnelComplete.bind(this),this._assets),this.funnel.zIndex=Z(Ga,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 li=4,ee=400,Ka=0,Za=0,qa=8,nt={particleLifetime:{min:800,max:1800},particleStartSizeFactor:{1:2,2:1,0:.25},particleEndSizeFactor:{1:3,2:2,0:1},particleStartAlpha:.08,particleEndAlpha:0,particleColor:3355443,particleSpawnRate:{1:60,2:50,0:30},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 ja extends K{constructor(t,e,s={}){super(),this._level=t[vt]||0,this.zIndex=Z(li,this._level);const{texture:n,contentSize:o}=e.smokeTexture;this._smokeTexture=n,this._textureScale=qa/o,this._emitterX=t[Lt],this._emitterY=t[Pt],this._emitterRotation=t[Ot],this._emitterVX=t[le],this._emitterVY=t[he],this._engineLoad=t[Bt],this._condition=t[Ct],this._z=t[ce]||0,this._size=t[Ne],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)),pt(this,dt(this.parent,this._renderer),this._z*N.shear,1)}),this._particleContainer=new ps({texture:this._smokeTexture,boundsArea:new ht(this._emitterX-ee,this._emitterY-ee,ee*2,ee*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),st.shared.add(this._tickListener)}update(t){const e=this._condition,s=t[vt]||0;s!==this._level&&(this._level=s,this.zIndex=Z(li,s)),this._emitterX=t[Lt],this._emitterY=t[Pt],this._emitterRotation=t[Ot],this._emitterVX=t[le],this._emitterVY=t[he],this._engineLoad=t[Bt],this._condition=t[Ct],this._z=t[ce]||0,this._particleContainer.boundsArea.x=this._emitterX-ee,this._particleContainer.boundsArea.y=this._emitterY-ee,this._condition!==e&&this._condition!==3&&this._triggerSmokeBurst()}_triggerSmokeBurst(){let t=0;if(this._condition===1?t=2:(this._condition===2||this._condition===0)&&(t=1),t>0){const e=nt.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||this._condition===0)&&(s=1);const n=nt.particleSpawnRate[this._condition]||0,o=n>0?1e3/n:1/0;if(s>0&&n>0)for(;this._timeSinceLastSpawn>=o;){for(let c=0;c<s;c+=1)this.spawnParticle(c,s);this._timeSinceLastSpawn-=o}else this._timeSinceLastSpawn=0;const r=Math.min(this._engineLoad,1),a=this._condition>0&&r>=nt.exhaust.minLoad?mt(nt.exhaust.idleSpawnRate,nt.exhaust.spawnRate,r):0;if(a>0){const c=1e3/a;for(;this._timeSinceExhaust>=c;)this.spawnParticle(0,1,"exhaust"),this._timeSinceExhaust-=c}else this._timeSinceExhaust=0;const h=1-Math.pow(nt.airResistance,t/16);for(let c=this._particles.length-1;c>=0;c-=1){const u=this._particles[c];if(u.age+=t,u.age>=u.lifetime){this._particleContainer.removeParticle(u.view),Dt.release(u.view),this._particles.splice(c,1);continue}u.vx=u.vx+(Ka-u.vx)*h,u.vy=u.vy+(Za-u.vy)*h,u.x+=u.vx*e,u.y+=u.vy*e;const _=u.age/u.lifetime,d=1-(1-_)*(1-_),f=mt(u.startSizeFactor,u.endSizeFactor,d),p=mt(u.startAlpha,u.endAlpha,_),m=f*this._particleScaleMultiplier*this._textureScale,y=u.view;y.x=u.x,y.y=u.y,y.scaleX=m,y.scaleY=m,y.alpha=p,y.rotation+=u.rotSpeed*e}}spawnParticle(t,e,s="damage"){const n=s==="burst",o=s==="exhaust",r=nt.exhaust,a=o?O(r.lifetime.min,r.lifetime.max):O(nt.particleLifetime.min,nt.particleLifetime.max);let l=o?r.startSizeFactor:nt.particleStartSizeFactor[this._condition]||.3,h=o?r.endSizeFactor:nt.particleEndSizeFactor[this._condition]||1,c=o?r.startAlpha:nt.particleStartAlpha,u=1;n&&(l*=2,h*=2.5,c=.8,u=2);const _=this._emitterRotation,d=_+Math.PI,f=Math.cos(d),p=Math.sin(d),m=_+Math.PI/2,y=Math.cos(m),x=Math.sin(m);let S=0;const w=this._width/2*nt.streamOffsetFactor;e===2?S=t===0?-w:w:e===3&&(S=(t-1)*w);const v=this._height*.22,k=this._emitterX+f*v+y*S,M=this._emitterY+p*v+x*S;let E=O(nt.particleInitialVelocity.away.min,nt.particleInitialVelocity.away.max),A=O(nt.particleInitialVelocity.side.min,nt.particleInitialVelocity.side.max);E*=u,A*=u;let C=f*E+y*A,R=p*E+x*A;const X=nt.particleVelocityVariance;C+=O(-X,X),R+=O(-X,X),C+=this._emitterVX,R+=this._emitterVY;const z=Dt.get(this._smokeTexture);z.tint=o?r.color:nt.particleColor,z.x=k,z.y=M,z.alpha=c;const F=l*this._particleScaleMultiplier*this._textureScale;z.scaleX=F,z.scaleY=F,z.rotation=O(0,Math.PI*2);const Y={view:z,x:k,y:M,vx:C,vy:R,age:0,lifetime:a,startSizeFactor:l,endSizeFactor:h,startAlpha:c,endAlpha:nt.particleEndAlpha,rotSpeed:O(-1,1)};this._particleContainer.addParticle(z),this._particles.push(Y)}_stopTimer(){this._tickListener&&(st.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer();for(let e=0;e<this._particles.length;e+=1)Dt.release(this._particles[e].view);this._particles=[],super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}class Qa extends Q{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 je=1;class Ja extends K{constructor(t,e,s={}){super(),this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._surfaces=s.surfaces||null,this._level=t[vt]||0,this._markLayers=new Map,this.zIndex=Z(je,this._level),this._currentX=t[Lt]||0,this._currentY=t[Pt]||0,this._currentRotation=t[Ot]||0,this._engineLoad=t[Bt]||0,this._condition=t[Ct],this._size=t[Ne],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),st.shared.add(this._tickListener),this._levelView&&(this.onRender=()=>this._updateLayers())}update(t){this._currentX=t[Lt],this._currentY=t[Pt],this._currentRotation=t[Ot],this._engineLoad=t[Bt],this._condition=t[Ct];const e=t[vt]||0;e!==this._level&&(this._level=e,this.zIndex=Z(je,e))}_markLayer(t){let e=this._markLayers.get(t);if(e)return e;e=new K,e.zIndex=Z(je,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 d of this._markLayers.values())for(let f=d.children.length-1;f>=0;f-=1){const p=d.children[f];p.update(t)&&p.destroy()}this._stepTrail(t/1e3);const e=this._currentX-this._prevX,s=this._currentY-this._prevY,n=Math.sqrt(e*e+s*s),o=nr(this._currentRotation-this._prevRotation),r=Math.abs(o),a=n-this._prevSpeed,l=Math.abs(a),h=r-this._prevAngularSpeed,c=Math.abs(h),u=performance.now();let _=!1;this._condition!==0&&u-this._lastTrackMarkTime>this._trackMarkCooldown&&(l>this._minAbsAccelerationForMark&&(_=!0),n>this._minSpeedForRotationMarks&&(r>this._minAngularSpeedForMark||c>this._minRotationAccelerationForMark)&&(_=!0)),this._engineLoad>1&&(_=!0),_&&(this.createTrackMarksAtPreviousPosition(),this._lastTrackMarkTime=u),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&&At.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&&At.tracks.noMarks.includes(t))return;let e=t&&At.tracks[t]||null,s=1;!e&&this._trailLeft>0&&(e=At.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,c=this._prevX+r+l,u=this._prevY+a+h,_=new Qa(c,u,this._prevRotation,this._trackWidth,this._trackLength,Math.min(1,this._trackInitialAlpha*(e?e.alpha:1))*s,this._assets.trackMarkTexture,e?e.lifetime:1);e&&(_.tint=e.tint),n.addChild(_)}}_updateLayers(){if(!this._markLayers.size)return;const t=dt(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&&pt(s,t,e*N.shear)}_stopTimer(){this._tickListener&&(st.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 hi=2,se=300,tl=6,et={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},el={color:et.color,alpha:et.startAlpha,lifetime:et.lifetime},sl=["sand","mud","water"],ci=.35,il=(i,t)=>i.kind==="boost"&&i.dir!==null&&i.dir[0]===t[0]&&i.dir[1]===t[1];class nl extends K{constructor(t,e,s={}){super(),this._level=t[vt]||0,this.zIndex=Z(hi,this._level);const{texture:n,contentSize:o}=e.dustTexture;this._dustTexture=n,this._textureScale=tl/o,this._x=t[Lt],this._y=t[Pt],this._rotation=t[Ot],this._vx=t[le]||0,this._vy=t[he]||0,this._engineLoad=t[Bt]||0,this._condition=t[Ct],this._z=t[ce]||0,this._vz=t[Ye]||0,this._prevVz=this._vz,this._size=t[Ne];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)),pt(this,dt(this.parent,this._renderer),this._z*N.shear,1)}),this._particleContainer=new ps({texture:this._dustTexture,boundsArea:new ht(this._x-se,this._y-se,se*2,se*2),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.addChild(this._particleContainer),this._tickListener=l=>this._updateParticles(l.deltaMS),st.shared.add(this._tickListener)}update(t){const e=this._x,s=this._y,n=this._condition>0,o=t[vt]||0;o!==this._level&&(this._level=o,this.zIndex=Z(hi,o)),this._x=t[Lt],this._y=t[Pt],this._rotation=t[Ot],this._vx=t[le]||0,this._vy=t[he]||0,this._engineLoad=t[Bt]||0,this._condition=t[Ct],this._z=t[ce]||0,this._vz=t[Ye]||0,this._particleContainer.boundsArea.x=this._x-se,this._particleContainer.boundsArea.y=this._y-se;const r=Wi(this._prevVz,this._vz,Zt);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)>At.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&&!il(r,o)&&this._vx*o[0]+this._vy*o[1]>=At.boost.boostMinSpeed&&this._triggerBoostFlash(o))}_triggerWaterEntry(){const t=At.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=At.boost,s=Math.atan2(-t[1],-t[0]);for(let n=0;n<e.burst;n+=1){const o=s+O(-ci,ci),r=O(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=O(e.sideSpeed.min,e.sideSpeed.max)*t,r=O(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=O(et.spinVelocity.back.min,et.spinVelocity.back.max),c=O(et.spinVelocity.side.min,et.spinVelocity.side.max);o=Math.cos(a)*h+Math.cos(l)*c,r=Math.sin(a)*h+Math.sin(l)*c}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(et.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=O(0,Math.PI*2),a=O(et.landingVelocity.min,et.landingVelocity.max)*t;this._spawnParticle(n.x,n.y,Math.cos(r)*a,Math.sin(r)*a,et.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=O(et.spinVelocity.back.min,et.spinVelocity.back.max),r=O(et.spinVelocity.side.min,et.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=el){const a=et.startSizeFactor*o,l=et.endSizeFactor*o,h=Dt.get(this._dustTexture),c=a*this._particleScaleMultiplier*this._textureScale;h.tint=r.color,h.x=t,h.y=e,h.alpha=r.alpha,h.scaleX=c,h.scaleY=c,h.rotation=O(0,Math.PI*2),this._particles.push({view:h,x:t,y:e,vx:s,vy:n,age:0,lifetime:O(r.lifetime.min,r.lifetime.max),startAlpha:r.alpha,startSizeFactor:a,endSizeFactor:l,rotSpeed:O(-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<et.maxSpinSpeed&&this._surfaceKind!=="oil"?et.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(et.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),Dt.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 c=h.age/h.lifetime,u=1-(1-c)*(1-c),_=(h.startSizeFactor+(h.endSizeFactor-h.startSizeFactor)*u)*this._particleScaleMultiplier*this._textureScale,d=h.view;d.x=h.x,d.y=h.y,d.scaleX=_,d.scaleY=_,d.alpha=h.startAlpha+(et.endAlpha-h.startAlpha)*c,d.rotation+=h.rotSpeed*e}}_emitSurface(t,e){const s=this._surfaceKind,n=sl.includes(s)?At[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&&(st.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer();for(let e=0;e<this._particles.length;e+=1)Dt.release(this._particles[e].view);this._particles=[],super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}function ol({progress:i,totalDist:t,trailLength:e,trailShare:s=0}){const n=t*Vt(i,0,1),o=Math.max(e,t*s),r=mt(o,0,Vt(i,0,1));return{tail:Math.max(0,n-r),head:n}}class rl extends Jt{constructor(t,e,s,n,o,r=Le,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 W;h.blendMode="add",(this._layerFor?.(l)||this).addChild(h),this._graphics.set(l,h)}this.elapsedTime=0,this.progress=0,this._aim(),this.animationDuration=Vt(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}=ol({progress:this.progress,totalDist:this.totalDist,trailLength:this.config.trailLength,trailShare:this.config.trailShare});e-t>.001&&this._drawTrail(t,e,mt(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=Math.max(1,this.config.fadeSteps),c=[];for(let _=0;_<h;_+=1){const d=mt(t,e,_/h),f=mt(t,e,(_+1)/h),p=(_+1)/h;c.push({from:d,to:f,fade:p*p})}const u=this._split(c);for(const{graphics:_,from:d,to:f,fade:p}of u)_.moveTo(d[0],d[1]).lineTo(f[0],f[1]).stroke({width:a,color:n,alpha:s*l*p,cap:"round"});for(const{graphics:_,from:d,to:f,fade:p}of u)_.moveTo(d[0],d[1]).lineTo(f[0],f[1]).stroke({width:r,color:o,alpha:s*p,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}of t)for(const a of this.pieces){const l=Math.max(n,a.from),h=Math.min(o,a.to);h-l>1e-6&&s.push({graphics:this._graphics.get(a.level),from:e(l),to:e(h),fade:r})}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 al(i,t,e){const s=e||0;if(!(t>0))return[{from:0,to:0,level:s}];const n=(i||[]).filter(u=>u.t1>u.t0&&u.t0<t);if(n.length===0)return[{from:0,to:t,level:s}];const o=u=>Math.min(t,Math.max(0,u)),r=[...new Set([0,t,...n.flatMap(u=>[o(u.t0),o(u.t1)])])].sort((u,_)=>u-_),a=[];for(let u=0;u+1<r.length;u+=1){const _=r[u],d=r[u+1];if(d-_<1e-6)continue;const f=(_+d)/2;let p=null;for(const y of n)y.t0<=f&&f<y.t1&&(p===null||y.t0<p.t0)&&(p=y);const m=p?p.level:a.at(-1)?.level??s;Qe(a,_,d,m)}if(a.at(-1).level===s)return a;const l=n.filter(u=>u.level===s&&u.t0<t&&u.t1>=t-.001).sort((u,_)=>_.t0-u.t0)[0],h=l?o(l.t0):a.at(-1).from,c=[];for(const u of a)u.from<h&&Qe(c,u.from,Math.min(u.to,h),u.level);return Qe(c,h,t,s),c}function Qe(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 ll extends Jt{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:c}=this._assets.impactParticleTexture;this._particleTexture=h,this._textureContentSize=c,this.config={particleCount:O(2,4),particleMinSize:.8,particleMaxSize:2.4,minInitialSpeed:10,maxInitialSpeed:300,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+O(-s,s);const a=O(this.config.minInitialSpeed,this.config.maxInitialSpeed),l=new Q(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:O(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:O(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 u=Math.hypot(r.vx,r.vy);if(u>0){const d=u*this.config.dragCoefficient*e,f=Math.max(0,1-d/u);r.vx*=f,r.vy*=f}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 u=r.timeSinceStopped-this.config.lingerDuration,_=Math.min(500,r.lifetime*(1-this.config.fadeOutStart));r.alpha=mt(1,0,Math.min(u/_,1))}else if(l>=this.config.fadeOutStart){const u=r.age-r.lifetime*this.config.fadeOutStart,_=r.lifetime*(1-this.config.fadeOutStart);r.alpha=_>0?mt(1,0,Math.min(u/_,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 c=r.size/this._textureContentSize;h.scale.set(c)}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 hl(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=[1-t()*i.jitter,1-t()*i.jitter];return{forward:e,sides:n}}function cl({dirX:i,dirY:t,t:e,roll:s,config:n}){const o=1-Vt(e,0,1),r=o*o,a=1-n.shrink*(1-o),l=Math.atan2(t,i),h=[],c=(u,_,d)=>{const f=Math.cos(u),p=Math.sin(u),m=d/2;return[-p*m,f*m,f*_,p*_,p*m,-f*m]};for(const u of n.layers){const _=u.scale*a,d=u.core?n.coreColor:n.color,f=u.alpha*r;if(!(f<=0)){for(const{angle:p,length:m}of s.forward)h.push({points:c(l+p,n.length*m*_,n.width*_),color:d,alpha:f});s.sides.forEach((p,m)=>{h.push({points:c(l+(m===0?Math.PI/2:-Math.PI/2),n.sideLength*p*_,n.sideWidth*_),color:d,alpha:f})})}}return h}class ul extends Jt{constructor(t,e,s,n,o,r=Sn,a=Math.random){super(o),this.position.set(t,e),this.dirX=s,this.dirY=n,this.config=r,this.roll=hl(r,a),this.elapsedTime=0,this.graphics=new W,this.graphics.blendMode="add",this.addChild(this.graphics)}_update(t){if(this.isComplete)return;this.elapsedTime+=t,this.graphics.clear();const e=this.config.duration?this.elapsedTime/this.config.duration:1;if(e<1){const s=cl({dirX:this.dirX,dirY:this.dirY,t:e,roll:this.roll,config:this.config});for(const{points:n,color:o,alpha:r}of s)this.graphics.poly(n).fill({color:o,alpha:r})}else this._completeEffect()}destroy(t){this.graphics&&this.graphics.clear(),super.destroy(t)}}const Je=2,ui=gi+.5,ts=.15;class fl extends K{constructor(t,e,s){super(),this.startPositionX=t[rr],this.startPositionY=t[ar],this.endPositionX=t[lr],this.endPositionY=t[hr],this.soundPositionX=t[cr],this.soundPositionY=t[ur],this.hitCode=t[fr]||0,this.hit=this.hitCode!==0,this.endLevel=t[_r]||0,this.startLevel=t[dr]||0,this.zIndex=Z(Je,this.endLevel),this.anchorKey=null,this.anchorLocalX=0,this.anchorLocalY=0,Array.isArray(t[Bs])&&([this.anchorKey,this.anchorLocalX,this.anchorLocalY]=t[Bs]),this._assets=e,this._soundManager=s.soundManager,this._isLocalShot=s.localPlayer?.is(t[Ke])===!0,s.shots?.fired(t[Ke]),this._mapDynamics=s.mapDynamics||null,this._shots=s.shots||null,this._shooterId=t[Ke],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=dt(this.parent,this._renderer);pt(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)),pt(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._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({...Qt.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 ul(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),o=al(this._shots?.path?.(this.startPositionX,this.startPositionY,n.x,n.y,this.startLevel),n.dist,this.endLevel);this.tracer=new rl(this.startPositionX,this.startPositionY,n.x,n.y,this._onTracerComplete.bind(this),Le,{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===pr){const u=2*ts,_=this._floorAt(this.endPositionX+t*u,this.endPositionY+e*u),d=this._rampRuns?.faceAt?.(_,this.endPositionX,this.endPositionY,t,e,ts);return d?{...d,base:_}:null}if(!this._volumes)return null;const{cellW:s,cellH:n}=this._volumes.cellSize();if(!(s>0&&n>0))return null;const o=Ai(this.endPositionX,this.endPositionY,t,e,s,n,ts);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),c=this._volumes.heightAt(h,a,l);return c>0?{face:o,volume:c,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()??dt(this.parent,this._renderer);if(!a)return n;const{face:l,volume:h,base:c}=this._wall,{shear:u}=N,_=this.endLevel*u;let d,f;if(Es(l,this.endPositionX,this.endPositionY,a))({x:d,y:f}=Pe(this.endPositionX,this.endPositionY,a,_,(this.endLevel+Le.height)*u)),this.zIndex=Z(ui,this.endLevel);else{const p=io({x0:this.startPositionX,y0:this.startPositionY,dx:o,dy:r,face:l,camera:a,kBase:_,kLine:(c+h)*u}),m=p===null?s:Math.min(s,Math.max(0,p));d=this.startPositionX+o*m,f=this.startPositionY+r*m}return{x:d,y:f,dist:Math.hypot(d-this.startPositionX,f-this.startPositionY),stopLine:{axis:l.axis,coord:l.axis==="x"?d:f}}}_slopeEnd(t){const e=this.hitCode===Ns&&t>.001?this._rampRuns?.slopeAt?.(this.endLevel,this.endPositionX,this.endPositionY):null;if(!e)return null;const s=this._levelView?.camera()??dt(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+Le.height)*t:this.hitCode===Ns?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&&Es(this._wall.face,this.endPositionX,this.endPositionY,t));this.zIndex=Z(s&&e.isFalling()?ui:Je,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(c=>c.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 K,n.label=`shot-tracer-${t}`,n.eventMode="none",n.zIndex=Z(s?Li:Je,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 ll(t,e,r,a,this._onImpactComplete.bind(this),this._assets,{surfaceK:this._debrisSurface(),startK:this._debrisStartK()}),this.addChild(this.impact),this.impact.run()}else this._visualsComplete=!0,this._tryDestroy()}_onImpactComplete(){this._isDestroyed||(this._visualsComplete=!0,this._tryDestroy())}_tryDestroy(){this._visualsComplete&&this._soundComplete&&this._flashComplete&&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.parent&&this.parent.removeChild(this),super.destroy({children:!0})}}}const dl={Map:Er,MapRadar:Rr,TankRadar:Xr,Tank:Ea,Bomb:za,ExplosionEffect:$a,Smoke:ja,Tracks:Ja,Dust:nl,ShotEffect:fl};function Xt(i,t,{blur:e,quality:s=10,width:n,height:o}){const r=new _s({strength:e,quality:s});r.padding=Di(e),t.filters=[r];const a=i.generateTexture({target:t,frame:new ht(0,0,n,o)});return t.destroy(!0),r.destroy(),a}function ke(i,t){const{radius:e,blur:s,color:n,quality:o=40}=i,r=new W,a=(e+St(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 _l(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,c=Math.max(1,Math.floor(h)||1),u=(e+s+l)*2,_=u+St(n)*2,d=_/2,f=[];for(let p=0;p<c;p+=1){const m=new W,y=[];for(let x=0;x<o;x+=1){const S=x/o*Math.PI*2,w=e+O(-s,s);y.push(d+w*Math.cos(S),d+w*Math.sin(S))}m.poly(y).fill(r).stroke({width:l,color:a,alignment:1}),f.push(Xt(t,m,{blur:n,width:_,height:_}))}return{textures:f,contentSize:u}}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 ie=wt(0,0,1);function Gi(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 $i(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],c=t[r*2+1];let u=c-l,_=-(h-a);u*(a+h)+_*(l+c)<0&&(u=-u,_=-_),i.poly([a,l,h,c,h*e,c*e,a*e,l*e]).fill(s(u,_))}}const at=10,Ve=at*4,Oe=at*3,pl=13158852,J={x:-Ve/2,y:-Oe/2,w:Ve,h:Oe},ne={x:-18,y:-9,w:36,h:18},Ki={l:2,r:4,t:2,b:2},ml=[{x:-19,y:-14,w:38,h:5},{x:-19,y:9,w:38,h:5}],Be=[1.33,-.42,.42,-1,-.42,-1,-1.33,-.42,-1.33,.42,-.42,1,.42,1,1.33,.42].map(i=>i*at),Zi=.6,Ie={x:.25*at,y:-.25*at,w:2.08*at},we={x:2.1*at,y:-.36*at,w:.35*at,h:.72*at},es={x:-.45*at,y:.35*at,r:.28*at},us={width:.08*at},gl=.55;function qi(i){i.rect(J.x,J.y,J.w,J.h).fill(5592405);for(const t of ml){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(ne.x,ne.y,ne.w,ne.h).fill(pl),Gi(i,ne,Ki,{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 fs(i,t){const e={...us,color:jt(t,gl)},s={width:.06*at,color:e.color};i.poly(Be).fill(t).stroke(e),$i(i,Be,Zi,()=>jt(t,.8)),i.circle(es.x,es.y,es.r).fill(jt(t,.65)).stroke(s),i.rect(Ie.x,Ie.y,Ie.w,2.5*2).fill(t).stroke(e),i.rect(we.x,we.y,we.w,we.h).fill(jt(t,.7)).stroke(s)}const ge={width:Ve,height:Oe};function yl(i,t){const{colors:e}=i,s={},n=qi,o=fs,r=d=>{d.rect(J.x,J.y,J.w,J.h).fill(ie),d.rect(J.x,J.y,J.w,1).fill(wt(0,-1,1)),d.rect(J.x,J.y+J.h-1,J.w,1).fill(wt(0,1,1)),d.rect(J.x,J.y+1,1,J.h-2).fill(wt(-1,0,1)),d.rect(J.x+J.w-1,J.y+1,1,J.h-2).fill(wt(1,0,1)),Gi(d,ne,Ki,{l:wt(-1,0,1),r:wt(1,0,2),t:wt(0,-1,1),b:wt(0,1,1)})},a=d=>{d.poly(Be).fill(ie).stroke({...us,color:ie}),$i(d,Be,Zi,(p,m)=>wt(p,m,1));const f=({x:p,y:m,w:y,h:x},S)=>{d.rect(p,m,y,x).fill(ie).stroke({...S,color:ie}),d.rect(p,m,y,x/2).fill(wt(0,-1,1)),d.rect(p,m+x/2,y,x/2).fill(wt(0,1,1))};f({...Ie,h:2.5*2},us),f(we,{width:.06*at})},l=(d,f)=>{const p=new W;d(p);const m=t.generateTexture({target:p,frame:f});return p.destroy(!0),m},h=d=>{const f=new W;d(f);const p=f.getBounds();return f.destroy(!0),new ht(p.x,p.y,p.width,p.height)},c=d=>{const f=h(n),p=h(y=>o(y,d)),m={x:-p.x/p.width,y:-p.y/p.height};return{body:l(n,f),bodyNormal:l(r,f),gun:l(y=>o(y,d),p),gunNormal:l(a,p),gunAnchor:m}},u=()=>{const d=new K,f=new W,p=new W;d.addChild(f,p);const m=3815994,y=2434341,x=3158064,S=1579032,w=5263440,v=Ve,k=Oe,M=at;f.moveTo(-v/2-M*.1,-k/2+M*.2).lineTo(v/2+M*.2,-k/2-M*.1).lineTo(v/2-M*.1,k/2+M*.3).lineTo(-v/2+M*.3,k/2-M*.2).closePath().fill(m).stroke({width:M*.2,color:w,alignment:.5}),f.moveTo(-v/2+M*.4,-k/2+M*.5).lineTo(v/2-M*.3,-k/2+M*.2).lineTo(v/2-M*.4,k/2-M*.1).lineTo(-v/2+M*.2,k/2-M*.4).closePath().fill(y),f.circle(v*.15,k*.1,M*1.2).fill(S),f.circle(-v*.3,-k*.25,M*.5).fill(S),p.position.set(M*.3,-M*.2);const E=[M*1.1,-M*.7,M*.2,-M*1,-M*.6,-M*.9,-M*1.3,-M*.2,-M*1.1,M*.6,-M*.2,M*1,M*.7,M*.8,M*1.3,M*.1];p.poly(E).fill(x).stroke({width:M*.15,color:w,alignment:0});const A=[M*.8,-M*.25,M*1.5,-M*.4,M*1.4,M*.15,M*.7,M*.05];p.poly(A).fill(x).stroke({width:M*.1,color:w,alignment:0}),p.circle(M*.1,-M*.2,M*.4).fill(S);const C=d.getBounds(),R=t.generateTexture({target:d,frame:new ht(C.x,C.y,C.width,C.height)});d.destroy({children:!0});const X=new W().rect(C.x,C.y,C.width,C.height).fill(ie),z=t.generateTexture({target:X,frame:new ht(C.x,C.y,C.width,C.height)});return X.destroy(!0),{texture:R,normal:z}};s.liveTeamId1=c(e.teamId1),s.liveTeamId2=c(e.teamId2);const _=u();return s.destroyed=_.texture,s.destroyedNormal=_.normal,s}const lt=2;function xl(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 fi(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 wl(i,t,e=Mt){const{colors:s}=i,n=(o,r=!1)=>{const a=new W;fs(a,o);const l=a.getBounds();a.destroy(!0);const h=Math.ceil(l.width),c=Math.ceil(l.height),u={x:lt,y:lt,w:ge.width,h:ge.height,originX:lt+ge.width/2,originY:lt+ge.height/2},_={x:u.x+u.w+lt,y:lt,w:h,h:c,originX:u.x+u.w+lt-l.x,originY:lt-l.y},d=lt+Math.max(u.h,_.h)+lt,f={x:lt,y:d,w:ge.width,h:e.trackHeight},p={x:f.x+f.w+lt,y:d,w:22,h:e.barrelRadius*2},m={x:p.x+p.w+lt,y:d,w:8,h:e.brakeRadius*2},y={x:m.x+m.w+lt,y:d,w:4,h:4},x=Math.max(_.x+_.w,y.x+y.w)+lt,S=d+Math.max(f.h,p.h,m.h,y.h)+lt,w=new K,v=new W,k=new W,M=new W;if(qi(v),v.position.set(u.originX,u.originY),fs(k,o),k.position.set(_.originX,_.originY),xl(M,f),fi(M,p,o),fi(M,m,jt(o,.7)),M.rect(y.x,y.y,y.w,y.h).fill(1710618),w.addChild(v,k,M),r){const A=new W;for(const C of[u,_,f,p,m])A.rect(C.x,C.y,C.w,C.h).fill({color:789e3,alpha:.62});A.circle(u.originX+4,u.originY+2,6).fill({color:0,alpha:.5}),A.circle(u.originX-9,u.originY-4,3).fill({color:0,alpha:.5}),A.circle(_.originX-2,_.originY+1,4).fill({color:0,alpha:.5}),w.addChild(A)}const E=t.generateTexture({target:w,frame:new ht(0,0,x,S)});return w.destroy({children:!0}),{texture:E,width:x,height:S,regions:{body:u,gun:_,trackSide:f,barrelSide:p,brakeSide:m,bottom:y}}};return{liveTeamId1:n(s.teamId1),liveTeamId2:n(s.teamId2),destroyed:n(3815994,!0)}}function vl(i,t){const{radius:e,borderWidth:s,crossSize:n,crossThickness:o,colors:r}=i,a={},l=(e+s)*2,h=l/2,c=15658734,u=3355443,_=f=>{const p=new W;p.circle(h,h,e).fill(c),p.circle(h,h,e-s).fill(f);const m=t.generateTexture({target:p,frame:new ht(0,0,l,l)});return p.destroy(!0),m},d=()=>{const f=new W,p=n/2;f.moveTo(h-p,h-p).lineTo(h+p,h+p).moveTo(h-p,h+p).lineTo(h+p,h-p).stroke({width:o,color:u});const m=t.generateTexture({target:f,frame:new ht(0,0,l,l)});return f.destroy(!0),m};return a.liveTeamId1=_(r.teamId1),a.liveTeamId2=_(r.teamId2),a.destroyed=d(),a}function Ml(i,t){const{colorOuter:e,colorInner:s}=i,n=new W,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 ht(0,0,o,o)});return n.destroy(!0),a}function Sl(i,t){const{width:e,length:s,color:n}=i,o=new W;o.rect(0,0,s,e).fill(n);const r=t.generateTexture({target:o,frame:new ht(0,0,s,e)});return o.destroy(!0),r}function bl(i,t){const{width:e,height:s,radius:n,blur:o,color:r,quality:a=20}=i,l=new W,h=St(o),c=e+h*2,u=s+h*2;return l.roundRect(h,h,e,s,n),l.fill(r),{texture:Xt(t,l,{blur:o,quality:a,width:c,height:u}),contentSize:e}}function kl(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,c=Math.max(1,Math.floor(h)||1),u=(e+s)*2,_=u+St(n)*2,d=_/2,f=[],p=(m,y)=>{const x=[];for(let S=0;S<o;S+=1){const w=S/o*Math.PI*2,v=m+O(-y,y);x.push(d+v*Math.cos(w),d+v*Math.sin(w))}return x};for(let m=0;m<c;m+=1){const y=new W;y.poly(p(e,s)).fill(r).poly(p(e*l,s*l)).fill(a),f.push(Xt(t,y,{blur:n,width:_,height:_}))}return{textures:f,contentSize:u}}function Tl(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 c=new W,u=O(s*.3,s)/2,_=O(s*.1,s*.6)/2;c.poly([0,a-_,e,a-u,e,a+u,0,a+_]).fill(n),l.push(t.generateTexture({target:c,frame:new ht(0,0,e,e)})),c.destroy(!0)}return{textures:l,contentSize:e}}function ji(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 Al(i,t){const{radius:e,rings:s=32,blur:n=2,quality:o=10}=i,r=new W,a=St(n),l=(e+a)*2,h=l/2;return ji(r,h,e,s,Ci),{texture:Xt(t,r,{blur:n,quality:o,width:l,height:l}),contentSize:e*2}}function Ll(i,t){const{length:e,halfWidth:s,strips:n=24,blur:o=4,quality:r=10}=i,a=new W,l=St(o),h=e+l*2,c=(s+l)*2,u=l,_=c/2;for(let f=0;f<n;f+=1){const p=e*f/n,m=e*(f+1)/n,y=s*f/n,x=s*(f+1)/n,S=(f+.5)/n,w=Ei(S);a.poly([u+p,_-y,u+m,_-x,u+m,_+x,u+p,_+y]),a.fill({color:16777215,alpha:w})}return{texture:Xt(t,a,{blur:o,quality:r,width:h,height:c}),length:e,halfWidth:s,margin:l}}function Pl(i,t){const{core:e,halo:s,rings:n=12,blur:o=1,quality:r=10}=i,a=new W,l=St(o),h=(s+l)*2,c=h/2,u=e/s;return ji(a,c,s,n,d=>d<=u?1:.6*(1-(d-u)/(1-u))**2),{texture:Xt(t,a,{blur:o,quality:r,width:h,height:h}),contentSize:s*2}}function Cl(i,t){const{radius:e,strips:s=16,blur:n=2,quality:o=10}=i,r=new W,a=St(n),l=(e+a)*2,h=l/2;for(let u=0;u<s;u+=1){const _=e*u/s,d=e*(u+1)/s,f=(u+.5)/s;r.rect(h+_,h-e,d-_,e*2),r.fill({color:16777215,alpha:f*f})}return{texture:Xt(t,r,{blur:n,quality:o,width:l,height:l}),contentSize:e*2}}function El(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 Il(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 W,c=St(a),u=(e+c)*2,_=u/2,d=El(r);for(let p=0;p<s;p+=1){const m=(p+(d()-.5)*.8)/s*Math.PI*2,y=e*(.55+.45*d()),x=.35+.65*d(),S=n*(.5+d()),w=Math.cos(m-S),v=Math.sin(m-S),k=Math.cos(m+S),M=Math.sin(m+S);for(let E=0;E<o;E+=1){const A=y*E/o,C=y*(E+1)/o,R=(E+.5)/o;h.poly([_+w*A,_+v*A,_+w*C,_+v*C,_+k*C,_+M*C,_+k*A,_+M*A]),h.fill({color:16777215,alpha:x*(1-R)})}}return{texture:Xt(t,h,{blur:a,quality:l,width:u,height:u}),contentSize:e*2}}const zl={explosionTexture:ke,smokeTexture:ke,impactParticleTexture:ke,dustTexture:ke,tankShadowTexture:bl,funnelTexture:_l,tankTexture:yl,tankModelTexture:wl,tankRadarTexture:vl,bombTexture:Ml,trackMarkTexture:Sl,scorchTexture:kl,debrisTexture:Tl,lightRadialTexture:Al,headlightConeTexture:Ll,lampHeadTexture:Pl,glintTexture:Cl,lightShaftTexture:Il},Rl=i=>(i??"").split(/[?#]/)[0].endsWith(".js"),Fl=i=>import(i);function Dl(i=Mn,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,c=e.key;return(e.camera===null||c===null||c.x!==o.x||c.y!==o.y||c.scaleX!==r.x||c.scaleY!==r.y||c.width!==l||c.height!==h)&&(e.key={x:o.x,y:o.y,scaleX:r.x,scaleY:r.y,width:l,height:h},e.camera=dt(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(),c=_t(e.x,e.y,h,e.z*N.shear),u=_t(r,a,h,l*N.shear);return En({viewLevel:e.level,viewX:c.x,viewY:c.y,level:o,x:u.x,y:u.y,cfg:i})},tintFor(o){return In(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}}}const Te=16777215;class di{constructor({level:t,ambient:e,resolution:s,area:n,roof:o=!1}){this.level=t,this.ambient=e,this.roof=o,this.overlay=new K,this.overlay.label=o?`lighting-roof-${t}`:`lighting-${t}`,this.overlay.zIndex=Z(no,t),this.overlay.eventMode="none",this.base=new Q(oe.WHITE),this.base.tint=t===0?e:Te,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 W:null,this.mask&&this.overlay.addChild(this.mask),this.lights=new K,this.overlay.addChild(this.lights),this.rampLights=new K,this.overlay.addChild(this.rampLights),this.rampMask=null,this.lightsMask=null,this.ramps=[],this.rampLightPool=[],this.shafts=new K,this.overlay.addChild(this.shafts),this.shaftPool=[],this.tops=new K,this.overlay.addChild(this.tops),this.topGroups=[],this.pool=[],this.fanPool=[],this.washPool=[],this.filter=new mi({alpha:1}),this.filter.resolution=s,this.filter.blendMode="multiply",this.overlay.filters=[this.filter],this.overlay.filterArea=new ht(n.x,n.y,n.width,n.height),this.resolution=s,this.hole=os(),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 W;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 W,this.lightsMask=new W,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&&pt(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=yo(r,s,n,t,e,o);this.rampMask.poly(a),this.lightsMask.poly(a)}this.rampMask.fill(Te),this.lightsMask.fill(Te)}for(const{graphics:s,volume:n}of this.topGroups)pt(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){Xl(this.pool,this.lights,t.filter(e=>!e.fan)),Yl(this.fanPool,this.lights,t.filter(e=>e.fan))}layoutWashes(t,e,s){for(;this.washPool.length<t.length;){const n=new is({positions:new Float32Array(8),uvs:new Float32Array(8),indices:new Uint32Array(6)}),o=new Re({geometry:n,texture:oe.EMPTY});o.blendMode="add",o.wash=null,o.facing=null,this.washPool.push(o),this.lights.addChild(o)}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,{base:c,heights:u,normals:_,mids:d}=a;for(let m=0;m<u.length;m+=1){const y=c[m*2],x=c[m*2+1],S=e?(r.level+u[m])*s:0;h[m*2]=e?y+(y-e.x)*S:y,h[m*2+1]=e?x+(x-e.y)*S:x}l.positions=h;const f=l.indices;let p=!1;for(let m=0;m<o.facing.length;m+=1){const y=e&&_[m*2]*(e.x-d[m*2])+_[m*2+1]*(e.y-d[m*2+1])>0?1:0;if(o.facing[m]!==y){o.facing[m]=y,p=!0;for(let x=0;x<6;x+=1)f[m*6+x]=y?a.indices[m*6+x]:m*4}}p&&(l.indices=f),o.visible=!0,o.texture=r.texture,o.tint=r.color,o.alpha=r.alpha}}layoutRampLights(t,e,s){for(;this.rampLightPool.length<t.length;){const n=new is({positions:new Float32Array(6),uvs:new Float32Array(6),indices:new Uint32Array(3)}),o=new Re({geometry:n,texture:oe.EMPTY});o.blendMode="add",o.ramp=null,this.rampLightPool.push(o),this.rampLights.addChild(o)}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,{base:c,heights:u}=a;for(let _=0;_<u.length;_+=1){const d=c[_*2],f=c[_*2+1],p=e?u[_]*s:0;h[_*2]=e?d+(d-e.x)*p:d,h[_*2+1]=e?f+(f-e.y)*p:f}l.positions=h,o.visible=!0,o.texture=r.texture,o.tint=r.color,o.alpha=r.alpha}}layoutShafts(t){for(;this.shaftPool.length<t.length;){const e=new K,s=new Q,n=new W;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 c of l)a.poly(c);l.length&&a.fill(Te);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),rs(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=oe.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 Xl(i,t,e){for(;i.length<e.length;){const s=new Q;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 Yl(i,t,e){for(;i.length<e.length;){const s=new is({positions:new Float32Array(6),uvs:new Float32Array(6),indices:ls(2)}),n=new Re({geometry:s,texture:oe.EMPTY});n.blendMode="add",n.shape=null,n.topology=null,i.push(n),t.addChild(n)}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,c=`${h}:${!!a.closed}`;n.topology!==c&&(l.indices=ls(h,a.closed),n.topology=c),l.positions=a.points,l.uvs=a.uvs,n.shape=a}n.visible=!0,n.texture=o.texture,n.position.set(r.x,r.y),n.scale.set(r.scale),n.tint=o.color,n.alpha=o.alpha}}const Vl=.6;function Qi(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 Ol({getMap:i,cfg:t}){const e=new WeakMap;let s=0;const n=(d,f)=>{const p=i();p.blockers=new Map,p.rampCells=new Map,s+=1;const{cols:m,rows:y}=p;if(!(m>0&&y>0))return;const x=(S,w)=>S>=0&&S<m&&w>=0&&w<y;for(const[S,w]of d){let v=null;for(const{cells:k,volume:M}of w.values())for(const[E,A]of k)x(E,A)&&(v||=new Float32Array(m*y),v[A*m+E]=Math.max(v[A*m+E],M));v&&p.blockers.set(S,v)}for(const[S,w]of f){const v=[...w.values()].flat();if(!v.length)continue;const k=new Int32Array(m*y);v.forEach((M,E)=>{for(let A=M.row0;A<M.row1;A+=1)for(let C=M.col0;C<M.col1;C+=1)x(C,A)&&(k[A*m+C]=E+1)}),p.rampCells.set(S,{cells:k,lanes:v})}},o=d=>{const f=i(),p=d.level??0,m=f.blockers.get(p)||null,{cols:y,rows:x}=f,S=f.step*f.scale.x,w=f.step*f.scale.y,v=(A,C)=>A>=0&&A<y&&C>=0&&C<x?C*y+A:-1,k=f.rampCells.get(p)||null;if(!m&&!k)return null;const M=A=>k&&A>=0&&k.cells[A]>0?k.lanes[k.cells[A]-1]:null,E=M(v(Math.floor(d.x/S),Math.floor(d.y/w)));return(A,C,R,X,z,F)=>{const Y=v(A,C);if(m&&Y>=0&&m[Y]>0)return!0;if(!k||R===null||R===void 0)return!1;const B=M(Y),V=M(v(R,X));return E&&(B===E||V===E)?!1:wo({lane:B,prevLane:V,col:A,row:C,prevCol:R,prevRow:X,x:z,y:F,z:d.z??p,cellW:S,cellH:w})}},r=(d,f,p,m,y)=>{const x=i(),S=d.level??0,{cols:w,rows:v}=x,k=x.step*x.scale.x,M=x.step*x.scale.y,E=Math.cos(f),A=Math.sin(f);let C=1/0,R=1/0,X=-1/0,z=-1/0;for(const G of[-m,p])for(const j of[-y,y]){const U=d.x+G*E-j*A,gt=d.y+G*A+j*E;C=Math.min(C,U),R=Math.min(R,gt),X=Math.max(X,U),z=Math.max(z,gt)}const F=Math.floor(C/k)-1,Y=Math.floor(R/M)-1,B=Math.floor(X/k)+1,V=Math.floor(z/M)+1;return zs(x.blockers.get(S),w,v,F,Y,B,V)||zs(x.rampCells.get(S)?.cells,w,v,F,Y,B,V)},a=()=>t.headlights?.occlusion,l=(d,f,p)=>{const m=i(),y=m.blockers.get(d),x=Math.floor(f/(m.step*m.scale.x)),S=Math.floor(p/(m.step*m.scale.y));return!y||x<0||x>=m.cols||S<0||S>=m.rows?0:y[S*m.cols+x]},h=(d,f,p)=>{const m=i(),y=m.rampCells.get(d),x=m.step*m.scale.x,S=m.step*m.scale.y,w=Math.floor(f/x),v=Math.floor(p/S);if(!y||w<0||w>=m.cols||v<0||v>=m.rows)return 0;const k=y.cells[v*m.cols+w];return k>0?vs(y.lanes[k-1],f,p,x,S)-d:0};return{sync:n,occlusionOf:(d,f)=>{const p=a();if(!p?.enabled||!f||!(d.radius>0))return null;const m=d.level??0,y=d.rotation||0,x=d.spread??.5,S=`${d.x},${d.y},${d.z},${y},${m},${d.radius},${x},${s},${p.rays}`,w=e.get(d);if(w&&w.key===S&&w.texture===f.texture)return w;const v=o(d);if(!v)return null;const k=i(),M=k.step*k.scale.x,E=k.step*k.scale.y,A=Qi(d,f),C=(A.width-A.margin)*A.sx,R=A.margin*A.sx,X=A.height/2*A.sy;if(!r(d,y,C,R,X)){const U={key:S,texture:f.texture,shape:null,hit:null,wash:null,fan:null};return e.set(d,U),U}const{points:z,clipped:F,closed:Y,reaches:B,forward:V}=Mo({x:d.x,y:d.y,rotation:y,alongMax:C,alongBack:R,acrossMax:X,rays:p.rays},v,M,E),G=t.headlights?.wash,j={key:S,texture:f.texture,shape:F?{points:z,closed:Y,uvs:So(z,A)}:null,hit:vo(d.x,d.y,Math.cos(y),Math.sin(y),d.radius,v,M,E),fan:{points:z,closed:Y,frame:A},wash:G?.intensity>0?ko({x:d.x,y:d.y,points:z,reaches:B,forward:V,uvOf:(U,gt)=>Ms(U,gt,A),wallAt:(U,gt)=>Math.max(l(m,U,gt),h(m,U,gt)),cellW:M,cellH:E,height:G.height}):null};return e.set(d,j),j},reachesPoint:(d,f,p)=>{if(d.kind!=="cone"||!a()?.enabled)return!0;const m=o(d);if(!m)return!0;const y=Math.hypot(f-d.x,p-d.y);if(y<1e-6)return!0;const x=i();return ws(d.x,d.y,(f-d.x)/y,(p-d.y)/y,y,m,x.step*x.scale.x,x.step*x.scale.y)>=y},bounceOf:(d,f)=>{const p=t.headlights?.bounce;if(!p||!(p.intensity>0)||!(p.radius>0)||f.distance>(p.maxDistance??d.radius))return null;const m=d.rotation||0,y=p.radius*Vl;return{kind:"radial",level:d.level,levels:d.levels,x:f.x-Math.cos(m)*y,y:f.y-Math.sin(m)*y,z:d.z,radius:p.radius,color:d.color,intensity:(d.intensity??1)*p.intensity*(1-f.distance/d.radius)}}}}function Bl({getMap:i,lights:t,flashes:e,cfg:s,reachesPoint:n}){let o=null,r=0;const a=(h,c,u,_,d)=>{const f=i(),p=[],m=y=>(y.levels??[y.level??0]).includes(u);for(const y of po(f.lampGrid,h,c))y.level===u&&p.push({light:y,factor:De(y.seed,d,y.flicker)});for(const y of t)y.kind==="cone"&&!_?.includes(y)&&m(y)&&Ii(y,h,c)>0&&n(y,h,c)&&p.push({light:y,factor:1});for(const y of e){const x=Pi(d-y.start,y.duration);x>0&&m(y)&&p.push({light:y,factor:x})}return p};return{lightsAt:(h,c,u,_=1,d=null)=>{if(!(_>0))return[];const f=st.shared.lastTime;if(o!==f&&(o=f,r=0),r>=s.maxLights)return[];const p=fo(a(h,c,u,d,f),h,c,_);return p.length&&(r+=1),p},candidatesAt:a}}const Nl=.08;function Wl({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 c of o.values()){const u=Math.hypot(c.x-i.x,c.y-i.y);c.level===i.level&&u<a&&l.push({caster:c,distance:u})}l.sort((c,u)=>c.distance-u.distance);const h=[];for(const{caster:c}of l.slice(0,n.maxShadowCasters)){const u=(c.z??c.level)*r,_=_t(c.x,c.y,s,u),d=mo(t.x,t.y,_.x,_.y,c.radius*(1+u),e);d&&h.push(d)}return h}function Ul({map:i,casters:t,cfg:e,asset:s,camera:n,screen:o,now:r,stage:a,shear:l}){const h=new Map,c=e.shafts;if(!c?.enabled||!s)return h;let u=0;for(const _ of i.lamps){if(!_.head||!(i.levels.has(_.level)||i.roofLevels.has(_.level)))continue;if(u>=e.maxLights)break;const d=Ce(_.x,_.y,_.level,n,a,l),f=_.radius*c.length*d.scale;!(f>0)||!as(d.screenX,d.screenY,f*a.scale.x,o.width,o.height)||(h.has(_.level)||h.set(_.level,[]),h.get(_.level).push({texture:s.texture,x:d.x,y:d.y,scale:f*2/s.contentSize,rotation:go(_.seed,r,Nl),color:_.color,alpha:c.intensity*_.intensity*De(_.seed,r,_.flicker),shadows:Wl({lamp:_,view:d,reach:f,camera:n,shaftsCfg:c,casters:t,shear:l})}),u+=1)}return h}const Hl=3818080,Gl=["radial","cone","head","glint","shaft"];function $l(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 Kl(i=Qt,t={}){const e=!!i.enabled,s=t.levelView||null,n=t.shear??N.shear;let o=null,r=null;const a={},l=new Set,h=new Map,c=[],u=new Map;let _=null;const d=new Map;let f=null;const p=new Map,m=new Map,y=new Map,x=new Map;let S=!1,w=null;const v=Ol({getMap:()=>f,cfg:i}),k=Bl({getMap:()=>f,lights:l,flashes:c,cfg:i,reachesPoint:v.reachesPoint}),M=new WeakMap,E=new WeakMap,A=()=>s?.cfg||null,C=(g,b,L,T)=>{let P=g.get(T);return P||(P=new K,P.label=`${L}-${T}`,P.zIndex=Z(b,T),P.eventMode="none",g.set(T,P)),P},R=g=>C(f.emissive,Li,"emissive",g),X=g=>C(f.lampHeads,oo,"lamp-heads",g),z=()=>{if(!(!f?.night||!a.head||f.headsReady)){f.headsReady=!0;for(const g of f.lamps){if(!g.head)continue;const b=new Q(a.head.texture);b.anchor.set(.5),b.blendMode="add",b.tint=g.color,g.headSprite=b,X(g.level).addChild(b)}}},F=(g,b,L,T)=>{const P=g||{},$=!!P.night,q=Me(L??1);if(f={night:$,ambient:P.ambient??Hl,step:b,scale:q,area:$l(T,b,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},!!$){(P.lamps||[]).forEach((H,it)=>{const[ut,ot]=H.cell||[0,0],yt=H.level||0,D=lo(ut,ot,b,q);f.lamps.push({kind:"radial",level:yt,x:D.x,y:D.y,z:yt,radius:H.radius??0,rotation:0,color:H.color??16777215,intensity:H.intensity??1,flicker:H.flicker||0,seed:it+1,head:!!H.head,headSprite:null})});for(const[H,it]of h)R(it).addChild(H);f.lampGrid=_o(f.lamps,Math.max(1,...f.lamps.map(H=>H.radius))),z(),S=!0,w=null}},Y=()=>{if(f){for(const g of[...f.emissive.values(),...f.lampHeads.values()])g.parent?.removeChild(g);for(const g of V())g.overlay.parent?.removeChild(g.overlay);for(const g of f.emissive.values())for(const b of h.keys())b.parent===g&&g.removeChild(b);for(const g of f.lamps)g.headSprite&&(g.headSprite.destroy({texture:!1,textureSource:!1}),g.headSprite=null);for(const g of[...f.emissive.values(),...f.lampHeads.values()])g.destroy({children:!0});for(const g of V())g.destroy();f=null,w=null}},B=()=>{Y(),p.clear(),m.clear(),y.clear(),x.clear(),S=!1,_=null},V=()=>[...f.levels.values(),...f.roofLevels.values()],G=g=>f.levels.has(g)||f.roofLevels.has(g),j=(g,b=null)=>{const L=[],T=new Set;for(const P of g?.values()||[])for(const $ of P){const q=`${$[0]},${$[1]}`;!T.has(q)&&!b?.has(q)&&(T.add(q),L.push($))}return[L,T]},U=(g,b,L,T)=>{let P=g.get(b);if(L.length===0){P&&(P.destroy(),g.delete(b));return}P||(P=new di({level:b,ambient:f.ambient,resolution:i.resolution,area:f.area,roof:T}),g.set(b,P)),P.setMask(Is(L),f.step,f.scale)},gt=g=>{const b=new Map;for(const{cells:L,volume:T}of y.get(g)?.values()||[])b.has(T)||b.set(T,[]),b.get(T).push(...L);return[...b].map(([L,T])=>({volume:L,runs:Is(T)}))},Et=()=>{const g=S;if(S){S=!1;const b=new Set([...p.keys(),...m.keys(),...f.levels.keys(),...f.roofLevels.keys()]);for(const L of b){if(L<1)continue;const[T,P]=j(m.get(L)),[$,q]=j(p.get(L),P);f.maskCells.set(L,q),f.roofCells.set(L,P),U(f.levels,L,$,!1),U(f.roofLevels,L,T,!0)}}if(f.levels.has(0)||f.levels.set(0,new di({level:0,ambient:f.ambient,resolution:i.resolution,area:f.area})),g){v.sync(y,x);for(const b of f.levels.values())b.setTops(gt(b.level),f.step,f.scale),b.setRamps([...x.get(b.level)?.values()||[]].flat(),f.step,f.scale,Ft.rampSegments)}},Nt=()=>{for(const g of V())g.overlay.parent!==o&&o.addChild(g.overlay);for(const g of[...f.emissive.values(),...f.lampHeads.values()])g.parent!==o&&o.addChild(g)},Wt=(g,b,L)=>{const T=g.kind==="cone"?a.cone:a.radial;if(!T||!(g.intensity*L>0))return null;const P=Ce(g.x,g.y,g.z??g.level,b,o,n);if(g.kind==="cone"){const q=g.radius*P.scale,H=q*(g.spread??.5);return{reach:q*o.scale.x,view:P,fan:null,hit:null,texture:T.texture,anchorX:T.margin/T.texture.width,anchorY:.5,scaleX:q/T.length,scaleY:H/T.halfWidth,rotation:g.rotation||0,color:g.color,alpha:g.intensity*L}}const $=g.radius*P.scale;return{reach:$*o.scale.x,view:P,texture:T.texture,anchorX:.5,anchorY:.5,scaleX:$*2/T.contentSize,scaleY:$*2/T.contentSize,rotation:0,color:g.color,alpha:g.intensity*L}},Ut=(g,b)=>{if(b.kind!=="cone")return;const L=v.occlusionOf(b,a.cone);if(!L)return;const{view:T}=g;L.shape&&(g.fan={shape:L.shape,x:T.x-b.x*T.scale,y:T.y-b.y*T.scale,scale:T.scale}),g.hit=L.hit,g.wash=L.wash,g.rampFan=L.fan},Ht=(g,b)=>{const L=`${g.kind},${g.x},${g.y},${g.rotation},${g.radius},${g.spread}`,T=M.get(g);if(T&&T.key===L&&T.texture===b.texture)return T.fan;const P=Qi(g,b),$=Math.cos(P.rotation),q=Math.sin(P.rotation),H=-P.margin*P.sx,it=(P.width-P.margin)*P.sx,ut=P.height/2*P.sy,ot=new Float32Array(10);ot[0]=P.x,ot[1]=P.y,[[H,-ut],[it,-ut],[it,ut],[H,ut]].forEach(([D,ct],bt)=>{ot[(bt+1)*2]=P.x+D*$-ct*q,ot[(bt+1)*2+1]=P.y+D*q+ct*$});const yt={points:ot,closed:!0,frame:P};return M.set(g,{key:L,texture:b.texture,fan:yt}),yt},rt=(g,b,L,T,P,$)=>{if(!L?.length)return!1;const q=T.kind==="cone"?a.cone:a.radial,H=P.rampFan??Ht(T,q);let it=E.get(H.points);it||(it=new Map,E.set(H.points,it));let ut=!1;for(const ot of L){it.has(ot)||it.set(ot,To({points:H.points,closed:H.closed,lane:ot,frame:H.frame,cellW:f.step*f.scale.x,cellH:f.step*f.scale.y,segmentsPerCell:Ft.rampSegments}));const yt=it.get(ot);yt&&(g.has(b)||g.set(b,[]),g.get(b).push({ramp:yt,texture:P.texture,color:P.color,alpha:$}),ut=!0)}return ut},Gt=(g,b,L)=>{const T=new Map,P=new Map,$=new Map;let q=0;const H=new Map;for(const D of f.levels.values())for(const ct of D.rampLevels())H.has(ct)||H.set(ct,[]),H.get(ct).push(D.level);const it=i.rampSpill??1,ut=[],ot=(D,ct)=>{const bt=D.levels??[D.level],bs=bt.filter(G),ks=it>0?bt.flatMap(xt=>H.get(xt)||[]).filter(xt=>!bt.includes(xt)):[];if(q>=i.maxLights||bs.length===0&&ks.length===0)return;const tt=Wt(D,g,ct);if(!tt||!as(tt.view.screenX,tt.view.screenY,tt.reach,b.width,b.height))return;tt.x=tt.view.x,tt.y=tt.view.y,Ut(tt,D);const ue=D.level??0;tt.wash&&f.levels.has(ue)&&($.has(ue)||$.set(ue,[]),$.get(ue).push({wash:tt.wash,level:ue,texture:tt.texture,color:tt.color,alpha:tt.alpha*i.headlights.wash.intensity}));for(const xt of bs){if(q>=i.maxLights)return;T.has(xt)||T.set(xt,[]),T.get(xt).push(tt),q+=1,rt(P,xt,f.levels.get(xt)?.ramps,D,tt,tt.alpha)}for(const xt of new Set(ks)){if(q>=i.maxLights)return;const en=f.levels.get(xt)?.ramps.filter(sn=>bt.includes(sn.to));rt(P,xt,en,D,tt,tt.alpha*it)&&(q+=1)}const Ts=tt.hit?v.bounceOf(D,tt.hit):null;Ts&&ut.push({light:Ts,factor:ct})};for(let D=c.length-1;D>=0;D-=1){const ct=c[D],bt=Pi(L-ct.start,ct.duration);bt<=0?c.splice(D,1):ot(ct,bt)}for(const D of l)ot(D,1);for(const D of f.lamps)ot(D,De(D.seed,L,D.flicker));for(const{light:D,factor:ct}of ut)ot(D,ct);const yt=Ul({map:f,casters:u,cfg:i,asset:a.shaft,camera:g,screen:b,now:L,stage:o,shear:n});for(const D of V())D.place(g,n),D.layout(T.get(D.level)||[]),D.roof||D.layoutWashes($.get(D.level)||[],g,n),D.layoutRampLights(D.roof?[]:P.get(D.level)||[],g,n),D.layoutShafts(yt.get(D.level)||[])},$t=g=>{const b=A();if(!b)return;const L=_t(s.x,s.y,g,s.z*n);for(const T of V()){if(T.level<1)continue;const P=s.level<T.level,$=T.roof&&P&&Pn(f.roofCells.get(T.level),f.step,f.scale,L,g,[T.level*n],b.roofMargin??0),q=T.overlay,H=vi(T.hole,b.fadeRate);if(s.mode==="layer"){let it=$;if(!T.roof){const ot=ae(s.x,f.scale.x,f.step),yt=ae(s.y,f.scale.y,f.step);it=P&&!!f.maskCells.get(T.level)?.has(`${ot},${yt}`)}const ut=it?b.layerAlpha:1;q.alpha+=(ut-q.alpha)*H;continue}ms(T.hole,T.roof?$:P,H),gs(q,T.hole,b,s,o,g),T.syncFilters()}},It=(g,b)=>{for(const L of f.lamps){const T=L.headSprite;if(!T)continue;const P=Ce(L.x,L.y,L.level,g,o,n);T.position.set(P.x,P.y),T.scale.set(P.scale),T.alpha=(s?s.alphaFor(L.level,P.x,P.y,0):1)*De(L.seed,b,L.flicker)}},zt=()=>e&&f?.night===!0;return{get enabled(){return e},attachStage(g,b){!e||o||!g||!b||(o=g,r=b,w=null,s?.attachStage(g,b))},acquireMap(g,b,L,T,P){e&&(d.set(g,(d.get(g)||0)+1),g!==_&&(Y(),_=g,F(b,L,T,P)))},releaseMap(g,b){if(!e)return;if(b!==void 0)for(const T of[p,m,y,x])for(const P of T.values())P.delete(b)&&(S=!0);const L=d.get(g);if(L!==void 0){if(L>1){d.set(g,L-1);return}d.delete(g),g===_&&B()}},setLevelMask(g,b,L,{roof:T=!1}={}){if(!e||!(g>=1))return;const P=T?m:p;P.has(g)||P.set(g,new Map),b&&b.length>0?P.get(g).set(L,b):P.get(g).delete(L),S=!0},setVolumeTops(g,b,L,T){!e||!(g>=0)||(y.has(g)||y.set(g,new Map),b&&b.length>0&&L>0?y.get(g).set(T,{cells:b,volume:L}):y.get(g).delete(T),S=!0)},setRampWedges(g,b,L){if(!e||!(g>=0))return;x.has(g)||x.set(g,new Map);const T=(b||[]).filter(P=>P.from===g&&P.to>P.from);T.length>0?x.get(g).set(L,T):x.get(g).delete(L),S=!0},registerTextures(g){if(!(!e||!g)){for(const b of Gl){const L=g[b];if(!L)continue;const T=a[b];if(a[b]=L,b==="head"&&T&&T!==L){for(const P of h.keys())P.texture===T.texture&&(P.texture=L.texture);for(const P of f?.lamps||[])P.headSprite&&(P.headSprite.texture=L.texture)}}a.head&&z()}},texture(g){return a[g]||null},addLight(g){if(!e)return null;const b={kind:"radial",level:0,x:0,y:0,radius:0,rotation:0,color:16777215,intensity:1,...g};return l.add(b),b},updateLight(g,b){g&&l.has(g)&&Object.assign(g,b)},removeLight(g){l.delete(g)},flash(g){!zt()||!a.radial||c.push({kind:"radial",level:0,color:16777215,intensity:1,...g,start:st.shared.lastTime})},addEmissive(g,b){return!zt()||!g?!1:(h.get(g)!==void 0&&g.parent&&g.parent.removeChild(g),h.set(g,b||0),R(b||0).addChild(g),!0)},removeEmissive(g){if(h.has(g)){h.delete(g);for(const b of f?.emissive.values()||[])g.parent===b&&b.removeChild(g)}},isNight:zt,lightsAt(g,b,L,T=1,P=null){return zt()?k.lightsAt(g,b,L,T,P):[]},onScreen(g,b,L,T){if(!o||!r?.screen)return!1;const P=s?s.camera():dt(o,r);if(!P)return!1;const $=Ce(g,b,L,P,o,n);return as($.screenX,$.screenY,T*$.scale*o.scale.x,r.screen.width,r.screen.height)},setCaster(g,b){e&&(b?u.set(g,b):u.delete(g))},castsShadows(){const g=i.shafts;return zt()&&!!(g?.enabled&&g.shadows&&g.maxShadowCasters>0)},render(){if(!zt()||!o||!r)return;const g=s?s.camera():dt(o,r),b=r.screen;if(!g||!b)return;const L=st.shared.lastTime,T=w;T!==null&&T.tick===L&&T.x===o.position.x&&T.y===o.position.y&&T.scaleX===o.scale.x&&T.scaleY===o.scale.y&&T.width===b.width&&T.height===b.height&&!S||(w={tick:L,x:o.position.x,y:o.position.y,scaleX:o.scale.x,scaleY:o.scale.y,width:b.width,height:b.height},Et(),z(),Nt(),Gt(g,b,L),s&&$t(g),It(g,L))},clear:B}}function Zl({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 c=0;c+2<(l?.length??0);c+=3)h.push({t0:l[c],t1:l[c+1],level:l[c+2]});return h.length?h:null}}}function ql(){const i=new Set;return{subscribe(t){return i.add(t),()=>{i.delete(t)}},exploded(t){for(const e of i)e(t)}}}function jl(){const i=new Map;let t=0,e=0,s=null;const n=()=>{s=new Map;for(const{level:o,cells:r,volume:a}of i.values()){s.has(o)||s.set(o,new Map);const l=s.get(o);for(const[h,c]of r){const u=`${h},${c}`;l.set(u,Math.max(l.get(u)||0,a))}}return s};return{setLayerVolume(o,r,a,l,{step:h,scale:c}){const{x:u,y:_}=Me(c??1);t=h*u,e=h*_,i.set(l,{level:o||0,cells:r,volume:a}),s=null},release(o){i.delete(o)&&(s=null)},heightAt(o,r,a){if(!(t>0&&e>0))return 0;const l=(s||n()).get(o||0);return l&&l.get(`${Math.floor(r/t)},${Math.floor(a/e)}`)||0},cellSize(){return{cellW:t,cellH:e}}}}const Ql=(i,t)=>t>=Math.min(i.from,i.to)&&t<=Math.max(i.from,i.to),Ss=(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},Ji=(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 Jl(i,t,e,s){const n=tn(i,t,e,s);return n?Ss(n,n.axis===0?e:s):null}function tn(i,t,e,s){return Array.isArray(i)?i.find(n=>Ql(n,t)&&Ji(n,e,s))??null:null}function th(i,t,e,s){const n=tn(i,t,e,s);return n?{height:Ss(n,n.axis===0?e:s),axis:n.axis}:null}function eh(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 c of i){if(Math.min(c.from,c.to)!==t||!Ji(c,l,h))continue;const u=c.axis===0,_=u?e:s,d=u?s:e,f=u?n:o,p=u?o:n,m=[{coord:c.min,dist:Math.abs(_-c.min),end:!0,d:f},{coord:c.max,dist:Math.abs(_-c.max),end:!0,d:f},{coord:c.crossMin,dist:Math.abs(d-c.crossMin),end:!1,d:p},{coord:c.crossMax,dist:Math.abs(d-c.crossMax),end:!1,d:p}].filter(w=>w.dist<=r&&Math.abs(w.d)>1e-9);if(m.length===0)continue;const y=m.reduce((w,v)=>v.dist<w.dist?v:w),x=y.end===u?"x":"y",S=y.d>0?-1:1;return{face:{axis:x,coord:y.coord,nx:x==="x"?S:0,ny:x==="y"?S:0},volume:Ss(c,u?l:h)-t}}return null}const sh=[[0,-1],[0,1],[-1,0],[1,0]],oh={id:"tanks",engineApi:fn,requires:["map.layers","map.levelsN","map.gameData","map.bodyState"],async createClientCore(i,{wasmUrl:t}){if(Rl(t)){const s=await Fl(t);return{core:new s.ClientCore(i),memory:null}}const e=await wn({module_or_path:t});return{core:new ns(i),memory:e.memory}},parts:dl,bakers:zl,styles:vn,serviceNames:["levelView","mapDynamics","rampRuns","surfaces","volumes","lighting","shots","blasts"],hooks:{services(i){const t=Dl(),e=Kl(void 0,{levelView:t});let s=[],n=null;const o=()=>{const l=i.map_generation();return l!==n&&(n=l,s=JSON.parse(i.ramp_runs())),s};let r=[],a=null;return{levelView:t,lighting:e,shots:Zl({segments:(l,h,c,u,_,d)=>i.shot_segments(l,h,c,u,_,d)}),blasts:ql(),volumes:jl(),mapDynamics:{toWorld(l,h,c){const u=i.map_dynamics_to_world(l,h,c);return u.length===0?null:{x:u[0],y:u[1]}}},rampRuns:{forLevel(l){return o().filter(h=>h.from===l)},heightAt(l,h,c){return Jl(o(),l,h,c)},slopeAt(l,h,c){return th(o(),l,h,c)},faceAt(l,h,c,u,_,d){return eh(o(),l,h,c,u,_,d)},floorAt(l,h,c){return i.floor_level(l,h,c)}},surfaces:{kindAt(l,h,c){const u=i.surface_at(l,h,c);if(u<0)return null;const _=i.map_generation();return _!==a&&(a=_,r=JSON.parse(i.surface_types())),r[u]??null},dirAt(l,h,c){return sh[i.surface_dir_at(l,h,c)]??null}}}},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{oh as default};