@vimp-games/tanks 0.22.22 → 0.22.24

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.
Files changed (89) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/vimp_tanks_core_bg-CI0QeU9I.wasm +0 -0
  3. package/dist/client-CsTbNQIQ.js +136 -0
  4. package/dist/client-CsTbNQIQ.js.map +1 -0
  5. package/dist/core-node/vimp_tanks_core.d.ts +32 -7
  6. package/dist/core-node/vimp_tanks_core.js +63 -10
  7. package/dist/core-node/vimp_tanks_core_bg.wasm +0 -0
  8. package/dist/core-node/vimp_tanks_core_bg.wasm.d.ts +5 -1
  9. package/dist/host-BTwPEd7Q.js +1 -0
  10. package/dist/host-BTwPEd7Q.js.map +1 -0
  11. package/dist/manifest.json +14 -10
  12. package/dist/maps/canopy.json +1 -1
  13. package/dist/maps/downtown.json +1 -1
  14. package/dist/maps/overpass.json +1 -1
  15. package/dist/sounds/bomb-has-been-planted.mp3 +0 -0
  16. package/dist/sounds/bomb-has-been-planted.webm +0 -0
  17. package/dist/sounds/bomb-has-been-planted2.mp3 +0 -0
  18. package/dist/sounds/bomb-has-been-planted2.webm +0 -0
  19. package/dist/sounds/bottle-break.mp3 +0 -0
  20. package/dist/sounds/bottle-break.webm +0 -0
  21. package/dist/sounds/buy.mp3 +0 -0
  22. package/dist/sounds/buy.webm +0 -0
  23. package/dist/sounds/defeat.mp3 +0 -0
  24. package/dist/sounds/defeat.webm +0 -0
  25. package/dist/sounds/empty-bullet.mp3 +0 -0
  26. package/dist/sounds/empty-bullet.webm +0 -0
  27. package/dist/sounds/explosion.mp3 +0 -0
  28. package/dist/sounds/explosion.webm +0 -0
  29. package/dist/sounds/flamethrower.mp3 +0 -0
  30. package/dist/sounds/flamethrower.webm +0 -0
  31. package/dist/sounds/frag.mp3 +0 -0
  32. package/dist/sounds/frag.webm +0 -0
  33. package/dist/sounds/game-over.mp3 +0 -0
  34. package/dist/sounds/game-over.webm +0 -0
  35. package/dist/sounds/hit.mp3 +0 -0
  36. package/dist/sounds/hit.webm +0 -0
  37. package/dist/sounds/machinegun.mp3 +0 -0
  38. package/dist/sounds/machinegun.webm +0 -0
  39. package/dist/sounds/missile-beep.mp3 +0 -0
  40. package/dist/sounds/missile-beep.webm +0 -0
  41. package/dist/sounds/missile-flight.mp3 +0 -0
  42. package/dist/sounds/missile-flight.webm +0 -0
  43. package/dist/sounds/missile-launch.mp3 +0 -0
  44. package/dist/sounds/missile-launch.webm +0 -0
  45. package/dist/sounds/own-hit.mp3 +0 -0
  46. package/dist/sounds/own-hit.webm +0 -0
  47. package/dist/sounds/reload.mp3 +0 -0
  48. package/dist/sounds/reload.webm +0 -0
  49. package/dist/sounds/ricochet-1.mp3 +0 -0
  50. package/dist/sounds/ricochet-1.webm +0 -0
  51. package/dist/sounds/ricochet-2.mp3 +0 -0
  52. package/dist/sounds/ricochet-2.webm +0 -0
  53. package/dist/sounds/ricochet-3.mp3 +0 -0
  54. package/dist/sounds/ricochet-3.webm +0 -0
  55. package/dist/sounds/ricochet-4.mp3 +0 -0
  56. package/dist/sounds/ricochet-4.webm +0 -0
  57. package/dist/sounds/round-start.mp3 +0 -0
  58. package/dist/sounds/round-start.webm +0 -0
  59. package/dist/sounds/shot.mp3 +0 -0
  60. package/dist/sounds/shot.webm +0 -0
  61. package/dist/sounds/shotgun.mp3 +0 -0
  62. package/dist/sounds/shotgun.webm +0 -0
  63. package/dist/sounds/tank-blast.mp3 +0 -0
  64. package/dist/sounds/tank-blast.webm +0 -0
  65. package/dist/sounds/tank-burning.mp3 +0 -0
  66. package/dist/sounds/tank-burning.webm +0 -0
  67. package/dist/sounds/tank-crash.mp3 +0 -0
  68. package/dist/sounds/tank-crash.webm +0 -0
  69. package/dist/sounds/tank-engine.mp3 +0 -0
  70. package/dist/sounds/tank-engine.webm +0 -0
  71. package/dist/sounds/tank-landing.mp3 +0 -0
  72. package/dist/sounds/tank-landing.webm +0 -0
  73. package/dist/sounds/tank-scream.mp3 +0 -0
  74. package/dist/sounds/tank-scream.webm +0 -0
  75. package/dist/sounds/tank-water.mp3 +0 -0
  76. package/dist/sounds/tank-water.webm +0 -0
  77. package/dist/sounds/victory.mp3 +0 -0
  78. package/dist/sounds/victory.webm +0 -0
  79. package/dist/sounds/weapon-switch.mp3 +0 -0
  80. package/dist/sounds/weapon-switch.webm +0 -0
  81. package/package.json +2 -2
  82. package/dist/assets/vimp_tanks_core_bg-6RnMvtoz.wasm +0 -0
  83. package/dist/client-se-N9EV5.js +0 -210
  84. package/dist/client-se-N9EV5.js.map +0 -1
  85. package/dist/host-Cq_deDqg.js +0 -1
  86. package/dist/host-Cq_deDqg.js.map +0 -1
  87. package/dist/maps/garden.json +0 -1
  88. package/dist/maps/pool mini.json +0 -1
  89. package/dist/maps/terraces.json +0 -1
@@ -0,0 +1,136 @@
1
+ import{UniformGroup as Ri,Filter as Ta,GpuProgram as za,GlProgram as cr,defaultFilterVert as Pa,Ticker as ot,Container as rt,Sprite as nt,Rectangle as Vt,Spritesheet as Ia,MeshSimple as Ea,Text as en,BlurFilter as sn,Assets as Fi,Texture as Js,Graphics as ft,Shader as Ca,Geometry as Ra,Mesh as ur,AlphaFilter as Oi,Particle as Fa,ParticleContainer as ri,MeshGeometry as Oa,Matrix as Xa}from"pixi.js";const Da=4;class Xi{__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,En.unregister(this),t}free(){const t=this.__destroy_into_raw();O.__wbg_clientcore_free(t,0)}abi_describe(){let t,e;try{const s=O.clientcore_abi_describe(this.__wbg_ptr);return t=s[0],e=s[1],xe(s[0],s[1])}finally{O.__wbindgen_free(t,e,1)}}apply_aim(t,e,s,i){O.clientcore_apply_aim(this.__wbg_ptr,t,e,s,i)}apply_input(t,e,s){const i=Ce(t,O.__wbindgen_malloc,O.__wbindgen_realloc),o=Jt,r=Ce(e,O.__wbindgen_malloc,O.__wbindgen_realloc),a=Jt;O.clientcore_apply_input(this.__wbg_ptr,i,o,r,a,s)}debug_json(){let t,e;try{const s=O.clientcore_debug_json(this.__wbg_ptr);return t=s[0],e=s[1],xe(s[0],s[1])}finally{O.__wbindgen_free(t,e,1)}}decode_frame(t){let e,s;try{const i=pi(t,O.__wbindgen_malloc),o=Jt,r=O.clientcore_decode_frame(this.__wbg_ptr,i,o);return e=r[0],s=r[1],xe(r[0],r[1])}finally{O.__wbindgen_free(e,s,1)}}dispatch(t,e){const s=Ce(t,O.__wbindgen_malloc,O.__wbindgen_realloc),i=Jt,o=pi(e,O.__wbindgen_malloc),r=Jt,a=O.clientcore_dispatch(this.__wbg_ptr,s,i,o,r);var l=Ha(a[0],a[1]).slice();return O.__wbindgen_free(a[0],a[1]*1,1),l}empty_fire(t){return O.clientcore_empty_fire(this.__wbg_ptr,t)!==0}floor_level(t,e,s){return O.clientcore_floor_level(this.__wbg_ptr,t,e,s)}hot_ptr(){return O.clientcore_hot_ptr(this.__wbg_ptr)>>>0}hot_values(){const t=O.clientcore_hot_values(this.__wbg_ptr);var e=os(t[0],t[1]).slice();return O.__wbindgen_free(t[0],t[1]*4,4),e}map_dynamics_to_world(t,e,s){const i=Ce(t,O.__wbindgen_malloc,O.__wbindgen_realloc),o=Jt,r=O.clientcore_map_dynamics_to_world(this.__wbg_ptr,i,o,e,s);var a=os(r[0],r[1]).slice();return O.__wbindgen_free(r[0],r[1]*4,4),a}map_generation(){return O.clientcore_map_generation(this.__wbg_ptr)>>>0}my_game_id(){return O.clientcore_my_game_id(this.__wbg_ptr)}constructor(t){const e=Ce(t,O.__wbindgen_malloc,O.__wbindgen_realloc),s=Jt,i=O.clientcore_new(e,s);if(i[2])throw Cn(i[1]);return this.__wbg_ptr=i[0],En.register(this,this.__wbg_ptr,this),this}offset(){return O.clientcore_offset(this.__wbg_ptr)}push_frame(t,e){const s=pi(t,O.__wbindgen_malloc),i=Jt;return O.clientcore_push_frame(this.__wbg_ptr,s,i,e)!==0}ramp_runs(){let t,e;try{const s=O.clientcore_ramp_runs(this.__wbg_ptr);return t=s[0],e=s[1],xe(s[0],s[1])}finally{O.__wbindgen_free(t,e,1)}}reset(){O.clientcore_reset(this.__wbg_ptr)}reset_generation(){return O.clientcore_reset_generation(this.__wbg_ptr)>>>0}resync(){O.clientcore_resync(this.__wbg_ptr)}sample(t){return O.clientcore_sample(this.__wbg_ptr,t)>>>0}set_active(t){O.clientcore_set_active(this.__wbg_ptr,t)}set_map(t){const e=Ce(t,O.__wbindgen_malloc,O.__wbindgen_realloc),s=Jt,i=O.clientcore_set_map(this.__wbg_ptr,e,s);if(i[1])throw Cn(i[0])}set_model(t){const e=Ce(t,O.__wbindgen_malloc,O.__wbindgen_realloc),s=Jt;O.clientcore_set_model(this.__wbg_ptr,e,s)}shot_segments(t,e,s,i,o,r){const a=O.clientcore_shot_segments(this.__wbg_ptr,t,e,s,i,o,r);var l=os(a[0],a[1]).slice();return O.__wbindgen_free(a[0],a[1]*4,4),l}slot_switches(){return O.clientcore_slot_switches(this.__wbg_ptr)>>>0}surface_at(t,e,s){return O.clientcore_surface_at(this.__wbg_ptr,t,e,s)}surface_dir_at(t,e,s){return O.clientcore_surface_dir_at(this.__wbg_ptr,t,e,s)}surface_types(){let t,e;try{const s=O.clientcore_surface_types(this.__wbg_ptr);return t=s[0],e=s[1],xe(s[0],s[1])}finally{O.__wbindgen_free(t,e,1)}}sync_panel(t){const e=Ce(t,O.__wbindgen_malloc,O.__wbindgen_realloc),s=Jt;O.clientcore_sync_panel(this.__wbg_ptr,e,s)}take_divergence(){let t,e;try{const s=O.clientcore_take_divergence(this.__wbg_ptr);return t=s[0],e=s[1],xe(s[0],s[1])}finally{O.__wbindgen_free(t,e,1)}}take_frames(){let t,e;try{const s=O.clientcore_take_frames(this.__wbg_ptr);return t=s[0],e=s[1],xe(s[0],s[1])}finally{O.__wbindgen_free(t,e,1)}}throw_aim(){const t=O.clientcore_throw_aim(this.__wbg_ptr);var e=os(t[0],t[1]).slice();return O.__wbindgen_free(t[0],t[1]*4,4),e}throw_wall(t,e,s,i,o,r){const a=O.clientcore_throw_wall(this.__wbg_ptr,t,e,s,i,o,r);var l=os(a[0],a[1]).slice();return O.__wbindgen_free(a[0],a[1]*4,4),l}try_fire(t){const e=O.clientcore_try_fire(this.__wbg_ptr,t);let s;return e[0]!==0&&(s=xe(e[0],e[1]).slice(),O.__wbindgen_free(e[0],e[1]*1,1)),s}}Symbol.dispose&&(Xi.prototype[Symbol.dispose]=Xi.prototype.free);function Ya(){return{__proto__:null,"./vimp_tanks_core_bg.js":{__proto__:null,__wbg_Error_92b29b0548f8b746:function(t,e){return Error(xe(t,e))},__wbg___wbindgen_throw_344f42d3211c4765:function(t,e){throw new Error(xe(t,e))},__wbindgen_init_externref_table:function(){const t=O.__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 En=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>O.__wbg_clientcore_free(n,1));typeof FinalizationRegistry>"u"||new FinalizationRegistry(n=>O.__wbg_gamecore_free(n,1));function os(n,t){return n=n>>>0,Ba().subarray(n/4,n/4+t)}function Ha(n,t){return n=n>>>0,qe().subarray(n/1,n/1+t)}let _s=null;function Ba(){return(_s===null||_s.byteLength===0)&&(_s=new Float32Array(O.memory.buffer)),_s}function xe(n,t){return Va(n>>>0,t)}let ps=null;function qe(){return(ps===null||ps.byteLength===0)&&(ps=new Uint8Array(O.memory.buffer)),ps}function pi(n,t){const e=t(n.length*1,1)>>>0;return qe().set(n,e/1),Jt=n.length,e}function Ce(n,t,e){if(e===void 0){const a=ms.encode(n),l=t(a.length,1)>>>0;return qe().subarray(l,l+a.length).set(a),Jt=a.length,l}let s=n.length,i=t(s,1)>>>0;const o=qe();let r=0;for(;r<s;r++){const a=n.charCodeAt(r);if(a>127)break;o[i+r]=a}if(r!==s){r!==0&&(n=n.slice(r)),i=e(i,s,s=r+n.length*3,1)>>>0;const a=qe().subarray(i+r,i+s),l=ms.encodeInto(n,a);r+=l.written,i=e(i,s,r,1)>>>0}return Jt=r,i}function Cn(n){const t=O.__wbindgen_externrefs.get(n);return O.__externref_table_dealloc(n),t}let Us=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});Us.decode();const Wa=2146435072;let mi=0;function Va(n,t){return mi+=t,mi>=Wa&&(Us=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),Us.decode(),mi=t),Us.decode(qe().subarray(n,n+t))}const ms=new TextEncoder;"encodeInto"in ms||(ms.encodeInto=function(n,t){const e=ms.encode(n);return t.set(e),{read:n.length,written:e.length}});let Jt=0,O;function Na(n,t){return O=n.exports,_s=null,ps=null,O.__wbindgen_start(),O}async function Ua(n,t){if(typeof Response=="function"&&n instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(n,t)}catch(i){if(n.ok&&e(n.type)&&n.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",i);else throw i}const s=await n.arrayBuffer();return await WebAssembly.instantiate(s,t)}else{const s=await WebAssembly.instantiate(n,t);return s instanceof WebAssembly.Instance?{instance:s,module:n}:s}function e(s){switch(s){case"basic":case"cors":case"default":return!0}return!1}}async function Ga(n){if(O!==void 0)return O;n!==void 0&&(Object.getPrototypeOf(n)===Object.prototype?{module_or_path:n}=n:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),n===void 0&&(n=new URL("/assets/vimp_tanks_core_bg-CI0QeU9I.wasm",import.meta.url));const t=Ya();(typeof n=="string"||typeof Request=="function"&&n instanceof Request||typeof URL=="function"&&n instanceof URL)&&(n=fetch(n));const{instance:e,module:s}=await Ua(await n,t);return Na(e)}const Ka='@charset "UTF-8";#panel table td#panel-health{width:28%}#panel table td#panel-primary-ammo,#panel table td#panel-secondary-amount,#panel table td#panel-grenade-amount{width:16%;opacity:.65;transition:opacity .12s}#panel table td#panel-money{width:12%}#panel table td#panel-time{width:8%}#panel table td#panel-time:before{content:"time: "}#panel table td.active,#panel table td#panel-primary-ammo.active,#panel table td#panel-secondary-amount.active,#panel table td#panel-grenade-amount.active{opacity:1;color:#fff;font-weight:700;box-shadow:inset 0 -2px #fa0}#panel table td.is-empty,#panel table td#panel-secondary-amount.is-empty,#panel table td#panel-grenade-amount.is-empty{opacity:.35}#panel table td.is-empty .panel-value{display:none}#panel table td div.panel-gauge{background-color:#f80}#panel table td#panel-money.is-up{color:#6f6}#panel table td#panel-money.is-down{color:#f66}@media(max-width:900px){#panel{height:48px}#panel table,#panel table tbody,#panel table tr{display:flex;flex-wrap:wrap;align-content:flex-start}#panel table td{height:24px;box-sizing:border-box;font-size:12px;text-overflow:ellipsis}#panel table td#panel-health{width:100%}#panel table td#panel-primary-ammo,#panel table td#panel-secondary-amount,#panel table td#panel-grenade-amount{width:25%}#panel table td#panel-money,#panel table td#panel-time{width:12.5%;min-width:60px}}@media(max-width:560px){#panel table td .panel-label{display:none}#panel table td#panel-primary-ammo:before{content:"1 "}#panel table td#panel-secondary-amount:before{content:"2 "}#panel table td#panel-grenade-amount:before{content:"3 "}#panel table td#panel-time:before{content:""}}@media(prefers-reduced-motion:reduce){#panel table td#panel-primary-ammo,#panel table td#panel-secondary-amount,#panel table td#panel-grenade-amount{transition:none}}#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}:root{--vimp-team-color-1: #ff6b5e;--vimp-team-color-2: #7fb2ff;--tanks-team-flag-1: #cd0000;--tanks-team-flag-2: #0a3161}#team1{color:var(--vimp-team-color-1)}#team2{color:var(--vimp-team-color-2)}#team1 tHead td:first-child{box-shadow:inset 4px 0 0 var(--tanks-team-flag-1);padding-left:calc(1% + 4px)}#team2 tHead td:first-child{box-shadow:inset 4px 0 0 var(--tanks-team-flag-2);padding-left:calc(1% + 4px)}#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}#vote.vote-style-shop{background:#0f7d4b99}#vote.vote-style-shop .vote-list li.disabled{opacity:.4}#menu-hints .menu-hint[data-name=shop]{color:#7f7;filter:drop-shadow(0 0 4px rgba(90,255,120,.7));animation:shop-hint-pulse 1.6s ease-in-out infinite}#menu-hints .menu-hint[data-name=shop]:after{content:"B";display:block;font-size:11px;font-weight:700;text-align:center;text-shadow:0 0 2px #000}@keyframes shop-hint-pulse{50%{opacity:.6}}@media(prefers-reduced-motion:reduce){#menu-hints .menu-hint[data-name=shop]{animation:none}}',$t=3.4,$a=n=>Math.round(n*1e3)/1e3,se=n=>$a(n*$t),gi=([n,t])=>[se(n),se(t)],W={hull:{length:6.1,width:3,lower:{bottom:{u:[-2.7,2.45],v:.975,w:.4},top:{u:[-2.9,2.75],v:.975,w:.9}},upper:{bottom:{u:[-2.95,2.78],v:1.38,w:.9,nose:.92,corner:[-2.45,2.15]},top:{u:[-1.6,1.45],v:.98,w:1.5}},fender:{mid:{u:[-2.45,2.15],v:[1.38,1.5]},front:{u:[2.15,3.05],v:[.92,1.5]},rear:{u:[-3.05,-2.45],v:[.92,1.5]},w:[.9,.95]}},track:{v:[.975,1.475],profile:[[2.35,0],[2.95,.4],[2.95,.7],[2.65,.88],[-2.65,.88],[-2.95,.7],[-2.95,.4],[-2.35,0]],pitch:.172,wheels:{u:[-1.86,-.93,0,.93,1.86],radius:.415,center:.46},idler:{u:2.62,radius:.3,center:.56},sprocket:{u:-2.62,radius:.32,center:.56}},fittings:{bowMg:{u:2,v:.55,radius:.15,barrel:2.45},headlight:{u:[1.5,1.72],v:-1.17,radius:.08},driverHatch:{u:[2.2,2.6],v:[-.5,-.12]},engineHatch:{u:[-1.8,-1.22],v:[-.3,.3],h:.03},louvers:{u:[-1.85,-1.15],v:[.84,.94],slats:6},innerLouvers:{u:[-1.8,-1.22],v:[.35,.5],slats:5},grille:{u:[-2.35,-1.9],v:[-.74,.74]},transmissionHatch:{u:-2.65,v:0,radius:[.18,.22]},exhausts:{u:[-2.85,-2.45],v:.55,radius:.14},smokeDrums:{u:-2.62,v:[.66,1.13],radius:.2},fuelTanks:[{u:[-1.37,-.45],v:1.25,w:1.2,radius:.17},{u:[-2.31,-1.42],v:1.25,w:1.2,radius:.17,rear:!0},{u:[-2.31,-1.42],v:-1.25,w:1.2,radius:.17,rear:!0}],zipBox:{u:[.66,1.8],v:[-1.5,-1.3],w:[.95,1.13]},handrails:{v:1.08,u:[[.85,1.35],[.15,.7],[-.4,.05],[-.98,-.52],[-1.55,-1.05]]},cable:{u:[-.4,2.05],v:[1.3,1.44]}},turret:{axisU:.6,base:{w:1.5,outline:[[1.22,.45],[1.18,.74],[1,.9],[.3,1.02],[-.3,1.02],[-1.1,.92],[-1.55,.74],[-1.72,.5]]},roof:{w:2.45,outline:[[.55,.36],[.55,.7],[.42,.82],[.2,.9],[-.3,.9],[-1.05,.8],[-1.42,.64],[-1.58,.42]]},mantlet:{u:.87,back:.62,w:1.95,radius:.35,v:.4},sleeve:[[1.12,.11],[1.3,.15],[1.47,.1]],cupola:{u:-.62,v:-.48,radius:.38,w:[2.45,2.64],lid:{radius:.31,h:.08}},loaderHatch:{u:-.55,v:.4,radius:.28,h:.04},vents:[{u:-1.3,v:-.5},{u:-1.3,v:-.12}],vent:{radius:.18,topRadius:.15,h:.05,domeRadius:.06,domeH:.1},periscopes:[{u:.25,v:.5},{u:.05,v:-.6}],periscope:{radius:.11,h:.1}},gunAxisW:1.95,guns:{cannon:{barrel:{u:[1.47,4.2],radius:.085},reach:4.2},shotgun:{barrel:{u:[1.22,2.7],radius:.12},flare:{u:[2.7,2.85],radius:[.12,.15]},muzzle:{u:[2.85,2.9],radius:.15},reach:2.9},machinegun:{barrels:{v:.12,u:[1.22,3.65],radius:.055},clamps:[2.25,3.1],clamp:{du:.1,v:.2,h:.08},brake:{u:[3.65,4],v:.24,h:.1},magazine:{u:[.8,1.2],v:[-.72,-.46],w:[1.8,2.12]},reach:4}}},ns={flame:{tank:{u:-1.98,v:[-.45,.45],w:2,radius:.2},brackets:[{u:[-1.78,-1.7],v:[-.33,-.27],w:[1.85,2.05]},{u:[-1.78,-1.7],v:[.27,.33],w:[1.85,2.05]}],hose:{radius:.05,points:[[-1.88,.45,2],[-1.6,.92,2],[-1.05,1.14,2],[.35,1.16,2],[.5,1.12,2.05]]},nozzle:{u:[.5,1.25],v:1.12,w:2.05,radius:.09},nozzleBracket:{u:[.62,.78],v:[.86,1.06],w:[2,2.08]},igniter:{u:[1.25,1.33],v:[1.08,1.16],w:[2.03,2.11]},glow:{radius:.25,color:16752704,alpha:.6,flicker:.3,hz:9},origin:[1.33,1.12]},missile:{body:{u:[-.45,.8],radius:.16},nose:{u:[.8,1.1],radius:.16,tipRadius:.04},fins:{u:[-.45,-.22],span:.26,thickness:.04},rail:{u:[-.5,.85],halfWidth:.05,below:[.21,.16]},rails:[{name:"roof",u:-1.08,v:0,w:2.95,pylon:{u:[-1.57,-1.5],v:[-.12,.12],w:[2.45,2.74]}},{name:"right",u:0,v:1.24,w:2.08,bracket:{u:[-.1,.2],v:[.78,1.2],w:[1.84,1.94]}},{name:"left",u:0,v:-1.24,w:2.08,bracket:{u:[-.1,.2],v:[-1.2,-.78],w:[1.84,1.94]}}]}},dr={rack:{u:[-2.31,-1.42],v:[1.03,1.47],w:[.95,1.4]},places:[{u:-1.645,side:1},{u:-1.645,side:-1},{u:-2.065,side:1}],sideV:1.25,mine:{radius:.2,w:[1.4,1.52],fuze:{radius:.06,h:.03}},molotov:{crate:{top:1.45,wall:.04,divider:.03},bottle:{body:{u:[-.2,.04],radius:.1},neck:{u:[.04,.14],radius:.04},w:1.51},wick:{u:[.14,.18],halfWidth:.035,w:[1.48,1.54]}}},Za=[W.turret.loaderHatch.u,W.turret.loaderHatch.v],Ss={bend:{u:2.4,pitch:-.1,yaw:.12},trackCut:-1.8,trackPiece:{u:-3.8,v:-1.3,angle:.45,size:[1.3,.5,.06]},turretPose:{du:[-.55,-.2],dv:[-.6,.6],yaw:[.35,.75],roll:[.1,.25],pitch:[.05,.2]},lidAngle:1.75},fr=[{region:"hull",u:[-2.2,1.6],v:[-.9,.9],w:W.hull.upper.top.w},{region:"hull",u:[-2.45,2.15],v:[1.38,1.5],w:.95},{region:"hull",u:[-2.45,2.15],v:[-1.5,-1.38],w:.95},{region:"turret",u:[-1,.8],v:[-.8,.8],w:W.turret.roof.w}],nn=[(W.fittings.louvers.u[0]+W.fittings.louvers.u[1])/2,(W.fittings.louvers.v[0]+W.fittings.louvers.v[1])/2],{missile:Rn}=ns,Se={w1:{type:"hitscan",slot:"primary",code:1,title:"Pistol",price:0,magazine:12,reload:2.2,auto:!1,impulseMagnitude:175e4,damage:40,range:1500,fireRate:.3,spread:0,pellets:1,muzzle:{reach:se(W.guns.cannon.reach)},cameraShake:{intensity:20,duration:200}},w2:{type:"explosive",slot:"grenade",code:2,title:"Bomb",price:250,unit:"count",pack:1,maxCharge:3,auto:!1,constructor:"Bomb",time:1e3,shotOutcomeId:"w2e",size:8,fireRate:.1,damage:110,radius:70,impulseMagnitude:25e5,cameraShake:{intensity:40,duration:500}},w3:{type:"hitscan",slot:"primary",code:3,title:"Shotgun",price:1200,magazine:6,reload:2.8,auto:!1,fireRate:.9,pellets:8,spread:.07,spreadHeight:se(.9),muzzle:{reach:se(W.guns.shotgun.reach)},damage:18,range:450,falloff:{start:.35,minFactor:.4},impulseMagnitude:175e4,cameraShake:{intensity:25,duration:220}},w4:{type:"hitscan",slot:"primary",code:4,title:"Machine gun",price:1800,magazine:40,reload:2.6,auto:!0,fireRate:.08,pellets:1,spread:.05,spreadHeight:se(.5),spreadGrowth:{max:.14,time:1.5,maxHeight:se(1.4)},muzzle:{reach:se(W.guns.machinegun.reach)},damage:12,range:1100,impulseMagnitude:6e5,cameraShake:{intensity:8,duration:80}},w5:{type:"beam",slot:"secondary",code:5,title:"Flamethrower",price:400,unit:"seconds",pack:5,maxCharge:20,auto:!0,beam:{range:96,width:10,dps:{base:25,max:60},rampTime:2,dwellGrace:.25,ignite:{time:4,dps:8},propFactor:1},impulseMagnitude:0,origin:gi(ns.flame.origin)},w6:{type:"molotov",slot:"grenade",code:6,title:"Molotov",price:300,unit:"count",pack:1,maxCharge:3,auto:!1,constructor:"Molotov",time:600,size:6,fireRate:.8,shotOutcomeId:"w6e",molotov:{range:130,minRange:40,chargeTime:1.2,radius:40,duration:6,ignite:{time:4,dps:8},misfire:.1,dudHitRadius:3,spin:14,roll:{share:.15,time:.8}},origin:gi(Za)},w7:{type:"missile",slot:"secondary",code:7,title:"Guided missile",price:500,unit:"count",pack:1,maxCharge:3,auto:!1,fireRate:1,missile:{speed:200,turnRate:2.2,lifetime:10,hp:100,hitRadius:5,hitCapPerShot:35,sourceFactor:{bullet:1,pellet:.5,beam:.5,blast:1},ignoreOwnerTime:.35,cameraHang:.6},damage:90,radius:60,impulseMagnitude:2e6,time:0,rails:Rn.rails.map(n=>gi([n.u+Rn.nose.u[1],n.v])),shotOutcomeId:"w2e",cameraShake:{intensity:35,duration:450}}},ja={mode:"hole",radius:260,softness:.45,minAlpha:.12,layerAlpha:.4,fadeRate:6,roofMargin:0,lowerTint:11579584},Q={shear:.22,levelZStride:100},Te={faceTilesPerLevel:3,faceSegments:4,faceBleedPx:2,rampSegments:4,sideTint:10133674},xi={baseAlpha:.4,alphaFalloff:.12,groundAlpha:.3},on={lightDir:[-.7,-.7]},gs={ambient:.55,diffuse:.6,lightZ:1},de={duration:80,attack:.15,gunKick:1.8,bodyKick:.3,rock:.13,machinegunKick:.12},Cs={cannon:{pull:.9,pullUntil:.08,closeAt:.86},shotgun:{pull:.75,pullUntil:.08,closeAt:.86},machinegun:{pull:.35,magazine:{out:[0,.15],hideAt:.2,showAt:.65,in:[.65,.85],travel:.7,drop:.5}},release:{travel:.6,time:.14},cancelTime:.12,rock:{amount:.04,decay:250},box:{life:1.6,size:[.6,.39,.48],color:6119782}},Zt={levelHeight:12.8,leanGain:.3,maxLean:.6,shadowBlur:1,texelsPerMeter:64,outline:{width:.25}},rs={rock:.22,wobbleHz:5,decay:180,duration:700,hop:.3,hopDuration:420,underShare:.5,shake:1.2,shakeDuration:220},wt={referenceLength:12,maxFire:64,maxSmoke:80,wind:{x:5,y:-3},joltRadius:18,sound:"tankExplosion",deathSounds:{1:"tankScream",2:"tankCrash",3:"tankBlast"},flash:{duration:180,startSize:12,endSize:40,alpha:1,color:16773576},fireball:{count:14,speed:{min:15,max:50},drag:4,size:{min:4,max:7},grow:2.2,lifetime:{min:450,max:850},rise:.5,alpha:.95},sparks:{count:12,speed:{min:70,max:160},drag:3,length:2.4,width:.5,lifetime:{min:300,max:700},colors:[16770728,16738842]},fire:{duration:9e3,fadeOut:5e3,rate:36,points:[[-.25,0],[.1,0]],spread:.4,size:{min:2.5,max:4.5},grow:1.6,lifetime:{min:300,max:650},jitter:4,rise:.35,alpha:.85,ramp:[[0,16774344],[.2,16761418],[.5,15885850],[.8,9184266],[1,2361348]]},glow:{size:28,alpha:.3,color:16747056,flicker:.35},smoke:{rate:12,tailRate:7,tail:15e3,burst:{count:12,speed:{min:12,max:30},alpha:.55},size:{min:3,max:5},grow:3.8,lifetime:{min:2600,max:4200},speed:6,drag:1.5,rise:1.4,alpha:.42,tailAlpha:.2,burning:[1315344,2762274],cooling:[4867908,6446682]},scorch:{size:26,alpha:.55,fadeIn:400}},rn={color:16751178,coreColor:16774368},_r=[{scale:1.35,alpha:.18},{scale:1,alpha:.45},{scale:.55,alpha:.95,core:!0}],pr=.3,Be={speed:19e3,minDuration:45,maxDuration:80,trailLength:55,trailShare:.4,...rn,coreWidth:.4,glowWidth:1.3,glowAlpha:.2,taper:.3,alphaStart:1,alphaEnd:.6,height:.52,fadeSteps:8},mr={duration:80,spikes:7,length:13,width:3.6,spread:.28,jitter:.35,sideLength:6,sideWidth:2.4,ball:{radius:2.8},ring:null,layers:_r,shrink:pr,...rn},qa={3:{sound:"shotgun",tracer:{color:16742938,coreColor:16767392,coreWidth:1.1,glowWidth:2.6,glowAlpha:.28,trailLength:22,trailShare:.25,taper:.5},muzzleFlash:{duration:110,spikes:9,length:22,width:6,spread:.42,sideLength:9,sideWidth:3.4,ball:{radius:4.6}}},4:{sound:"machinegun",soundBurst:{step:.06,min:.4,resetGap:250},tracer:{color:16765498,coreColor:16777215,coreWidth:.25,glowWidth:.8,glowAlpha:.15,speed:26e3,trailLength:40},muzzleFlash:{duration:55,spikes:4,length:7,width:2.2,spread:.18,sideLength:0,ball:{radius:1.6}}}},Qa=250,Ja={duration:110,spikes:6,length:8,width:3,spread:1.1,jitter:.5,sideLength:0,ball:{radius:3.4},ring:{radius:10,width:.8,alpha:.3,duration:150,color:16769712},layers:_r,shrink:pr,...rn},gr={count:5,speed:{min:8,max:26},spread:1.2,drag:3,size:{min:3,max:5},grow:2.5,lifetime:{min:600,max:1e3},alpha:.5,colors:[6249045,8025196,9340798]},ye={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"]}},He={fullImpact:6,squash:.14,duration:260,minImpact:1.5},tl={maxFps:30},ie={enabled:!0,resolution:.5,maxLights:96,headlights:{length:90,spread:.55,intensity:.9,color:16773572,offset:.5,occlusion:{enabled:!0,rays:64},bounce:{intensity:.35,radius:30,maxDistance:80},wash:{height:.6,intensity:1}},rampSpill:1,tankGlow:{radius:26,intensity:.35,color:12570879},flash:{explosion:{radius:140,intensity:1,duration:260,color:16756832},shot:{radius:90,intensity:.9,duration:120,color:16773280},hit:{radius:60,intensity:.8,duration:110,color:16760944},wreck:{radius:150,intensity:1.1,duration:320,color:16752720}},wreckFire:{radius:70,intensity:.75,color:16748608,flicker:.45},glints:{enabled:!0,intensity:.8,size:1.2},shafts:{enabled:!0,rays:14,length:1.3,intensity:.35,shadows:!0,maxShadowCasters:4}},xr={size:7,offsetY:11,arcs:3,period:900,popIn:120,color:3854699},as={period:900,maxScale:3.2,alpha:.9,color:3854699},xt={holdMs:150,range:Se.w5.beam.range,reach:1,startOffset:0,coneAngle:8,nozzleWidth:.5,wobble:1.2,wobbleSpeed:.012,splash:{spread:1.1,run:16,size:16,wallZone:8},maxParticles:800,rate:{min:900,max:1500},life:{min:300,max:520},speed:{min:1.6,max:2.4},size:{start:4,end:6.5},ramp:[[0,16766282],[.3,16747024],[.65,14690824],[1,3804680]],alpha:.85,fade:.7,coreShare:.12,sound:"flamethrower",light:{radius:70,color:16742944,intensity:.55}},Re={rate:60,maxParticles:64,life:{min:450,max:950},rise:{min:6,max:18},size:{start:13,end:4},sizeScale:{min:.7,max:1.4},colors:{start:16771216,end:14688256},alpha:{start:.75,end:0},glow:{size:1.1,color:16734736,alpha:.5,flicker:.25},light:{radius:69,color:16742944,intensity:.45,flicker:.3},char:{rate:.15,max:.45,color:1709072}},Ne={referenceLength:12,rate:10,maxParticles:16,life:{min:250,max:500},size:{start:1.2,end:3},rise:{x:4,y:-9},spread:.3,colors:{start:16765024,end:16727048},alpha:{start:.55,end:0},light:{radius:52,color:16742944,intensity:.3,flicker:.4}},Ot={length:14,width:5,focusHoldMs:150,timerShowDistance:20,timerFontSize:8,timerColor:16777215,timerWarnSeconds:3,timerWarnColor:16728128,cameraHang:Se.w7.missile.cameraHang,trail:{rate:70,life:{min:350,max:650},size:5,tint:13619151,alpha:.55,maxParticles:80},sound:"missileFlight",launchSound:"missileLaunch",launchFreshSeconds:.5,liftBlend:.3,beep:{sound:"missileBeep",fromSeconds:3,everySeconds:1},light:{radius:55,color:16754784,intensity:.6}},Je={lift:.45,maxLift:.98,shadow:{alpha:.35,falloff:.25,size:1},maxTickMs:100},Et={sound:"bottleBreak",spreadMs:600,flash:{size:1.3,color:16752688,alpha:.9,ms:450},glow:{size:1.1,color:16734736,alpha:.5,flicker:.25,speed:9},rate:.09,spreadBoost:3,life:{min:450,max:950},size:{start:13,end:4},rise:{min:6,max:18},splash:70,colors:{start:16771216,end:14688256},alpha:{start:.75,end:0},scorch:{size:1,color:1182214,alpha:.5},fadeInMs:400,fadeOutMs:1200,maxParticles:400,maxTickMs:100,wall:{height:.5,share:.6,climb:1.2},light:{radius:1,color:16742944,intensity:.5,flicker:.35}},Ue={dash:6,gap:4,width:1.4,alpha:.9,ringWidth:1.2,ringFill:.12,cross:3,colors:{start:16769136,end:16722437},baseZ:5.5},We={fade:.2,hole:{life:3e4,limit:250,size:2.2,jitter:.08},blast:{reach:.6,size:8,maxFaces:4,strength:1},soot:{life:6e4,limit:80,size:10,merge:4,maxStrength:1,step:.15,everyMs:150}},yr=Q.levelZStride,it=(n,t)=>n+yr*(t||0),ai=5,bs=(n,t)=>Math.min(n||0,Math.round(t)),el=yr*9;function At(n,t){const e=t?.screen;return!n||n.destroyed||!e||!n.scale.x||!n.scale.y?null:{x:(e.width/2-n.position.x)/n.scale.x,y:(e.height/2-n.position.y)/n.scale.y,scaleX:n.scale.x,scaleY:n.scale.y}}function Lt(n,t,e,s){return!e||!s?{x:n,y:t}:{x:n+(n-e.x)*s,y:t+(t-e.y)*s}}function te(n,t,e,s=1){const i=typeof s=="number"?s:s.x,o=typeof s=="number"?s:s.y;if(!t||!e){n.scale.set(i,o),n.position.set(0,0);return}n.scale.set(i*(1+e),o*(1+e)),n.position.set(-t.x*e,-t.y*e)}function xs(n,t,e,s,i){if(!e)return{x:n,y:t,scale:1};const o=(1+(i||0))/(1+(s||0));return{x:e.x+(n-e.x)*o,y:e.y+(t-e.y)*o,scale:o}}function As(n){const t=typeof n=="number"?n:n.x,e=typeof n=="number"?n:n.y;return{x:t,y:e}}function ts(n,t,e){return Math.floor(n/t/e)}function sl(n,t,e){return Math.round(n/t/e)}function il(n,t,e){return{map:n,scale:t,step:e}}function wr(n,t,e,s){const i=ts(t,n.scale.x,n.step),o=ts(e,n.scale.y,n.step),r=n.map?.[o]?.[i];return r!==void 0&&s.has(r)}function vr(n,t,e,s,i){if(!e||!t)return!1;const o=i>0?[[0,0],[i,0],[-i,0],[0,i],[0,-i]]:[[0,0]];for(const r of s){const a=1+r;for(const[l,h]of o)if(n((t.x+l+e.x*r)/a,(t.y+h+e.y*r)/a))return!0}return!1}function nl(n,t,e,s,i,o){return n?.map?vr((r,a)=>wr(n,r,a,t),e,s,i,o):!1}function ol(n,t,e,s,i,o,r){return!n||n.size===0?!1:vr((a,l)=>n.has(`${ts(a,e.x,t)},${ts(l,e.y,t)}`),s,i,o,r)}const Mr=n=>n.radius*(1-n.softness),rl=(n,t,e)=>{if(t<=n)return e<t?0:1;const s=Math.min(1,Math.max(0,(e-n)/(t-n)));return s*s*(3-2*s)};function al({viewLevel:n,viewX:t,viewY:e,level:s,x:i,y:o,cfg:r}){if((s||0)<=(n||0))return 1;if(r.mode==="layer")return r.layerAlpha;const a=i-t,l=o-e,h=Math.sqrt(a*a+l*l),c=rl(Mr(r),r.radius,h);return r.minAlpha+(1-r.minAlpha)*c}function ll(n,t,e){return(t||0)<(n||0)?e.lowerTint:16777215}const hl=`
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
+ `,Fn=`
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 cl(n){const t=new Ri({uHoleCenter:{value:new Float32Array([0,0]),type:"vec2<f32>"},uHoleParams:{value:new Float32Array([n.radius,Mr(n),n.minAlpha]),type:"vec3<f32>"}});return new Ta({glProgram:cr.from({vertex:Pa,fragment:hl,name:"see-through-hole-filter"}),gpuProgram:za.from({vertex:{source:Fn,entryPoint:"mainVertex"},fragment:{source:Fn,entryPoint:"mainFragment"}}),resources:{holeUniforms:t}})}function ul(n,{centerX:t,centerY:e,radius:s,softness:i,minAlpha:o}){const r=n.resources.holeUniforms.uniforms;r.uHoleCenter[0]=t,r.uHoleCenter[1]=e,r.uHoleParams[0]=s,r.uHoleParams[1]=s*(1-i),r.uHoleParams[2]=o}const dl=.01;function Di(){return{strength:0,filter:null,attached:!1,tick:null}}function Sr(n,t){const e=ot.shared.lastTime;return n.tick===e?0:(n.tick=e,Math.min(1,t*(ot.shared.deltaMS/1e3)))}function an(n,t,e){return n.strength+=((t?1:0)-n.strength)*e,n.strength}function br(n,t){return 1+(t.minAlpha-1)*n.strength}function ln(n,t,e,s,i,o){if(t.strength<dl||!i){t.attached&&(n.filters=[],t.attached=!1);return}t.filter||(t.filter=cl(e)),t.attached||(n.filters=[t.filter],t.attached=!0);const r=Lt(s.x,s.y,o,s.z*Q.shear);ul(t.filter,{centerX:r.x*i.scale.x+i.position.x,centerY:r.y*i.scale.y+i.position.y,radius:e.radius*i.scale.x,softness:e.softness,minAlpha:br(t,e)})}function Yi(n,t){if(!n.filter){n.attached=!1;return}t.filters=[],n.attached=!1,n.filter.destroy(),n.filter=null}async function kr(n,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"}},i=new Ia(n,s);return await i.parse(),i}async function hn({baseTexture:n,spriteSheetData:t,map:e,tiles:s,step:i,renderer:o,exclude:r=[]}){const a=await kr(n,t),l=new Set(r),h=s.filter(p=>!l.has(p)),c=e[0].length*i,u=e.length*i,d=new rt;for(let p=0,_=e.length;p<_;p+=1)for(let m=0,g=e[p].length;m<g;m+=1){const w=e[p][m];if(h.includes(w)){const M=`frame${w}`,S=a.textures[M];if(S){const b=new nt(S);b.x=m*i,b.y=p*i,d.addChild(b)}else console.warn(`Texture not found. Tile: ${w}, sprite: ${M}`)}}const f=o.generateTexture({target:d,frame:new Vt(0,0,c,u)});return d.destroy({children:!0}),a.destroy(),f}function fl(n,t){const e=[];if(!Array.isArray(n))return e;for(const s of n){const i=s.axis===0?0:1,o=i===0?1:0,r=t(s.min,i),a=t(s.max,i),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,i):null,rail1:c?t(s.railMax,i):null,col0:i===0?r:l,col1:i===0?a:h,row0:i===0?l:r,row1:i===0?h:a})}return _l(e)}function _l(n){const t=new Map;for(const s of n){const i=t.get(s.block);i?i.push(s):t.set(s.block,[s])}const e=[];for(const s of t.values()){const i=a=>a.axis===1?a.col0:a.row0,o=a=>a.axis===1?a.col1:a.row1;s.sort((a,l)=>i(a)-i(l));let r=null;for(const a of s){if(r&&i(a)===o(r)){r.axis===1?r.col1=a.col1:r.row1=a.row1;continue}r={...a},e.push(r)}}return e}function cn(n){const t=new Ea(n);return t.geometry.batchMode="batch",t}const pl=1e-6,ml=1e3,Ar=[0,1,3,0,3,2];function gl(n,t){const e=[],s=n.length,i=n.reduce((r,a)=>Math.max(r,a.length),0),o=(r,a)=>{const l=n[a]?.[r];return l!==void 0&&t.has(l)};for(let r=0;r<s;r+=1)for(let a=0;a<i;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:n[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:n[r][a],col:a,row:r,nx:l,ny:0,x0:h,y0:r,x1:h,y1:r+1})}}return e}function Lr(n,t){return Math.max(1,Math.ceil(n*t-1e-9))}function xl({map:n,tiles:t,step:e,baseScale:s,level:i,volume:o,shear:r,sideTint:a,textures:l,tilesPerLevel:h=1,segments:c=1}){const u=gl(n,new Set(t)),d=i*r,f=(i+o)*r,p=f-pl,_=Math.max(1,Math.ceil(o*c-1e-9)),m=Lr(o,h),g=o*h/m,w=(_+1)*2,M=Math.max(1,Math.floor(ml/_)),S=[],b=new Map;for(const y of u)b.has(y.tile)||b.set(y.tile,[]),b.get(y.tile).push(y);for(const[y,v]of b){const z=l?.get(y);if(!z){console.warn(`buildVolumeWalls: no side texture for tile ${y}`);continue}for(let L=0;L<v.length;L+=M){const T=v.slice(L,L+M),E=T.length,G=E*w,H=new Float32Array(G*2),K=new Float32Array(G),J=new Float32Array(G*2),$=new Uint32Array(E*_*6),B=new Float32Array(E*2),I=new Float32Array(E*2);for(let N=0;N<E;N+=1){const{nx:It,ny:Ht,x0:lt,y0:ut,x1:ht,y1:ct}=T[N],tt=lt*e,bt=ut*e,et=ht*e,st=ct*e,k=N*w;for(let P=0;P<=_;P+=1)for(let C=0;C<2;C+=1){const R=k+P*2+C;H[R*2]=(C===1?et:tt)*s.x,H[R*2+1]=(C===1?st:bt)*s.y,K[R]=f-(f-d)*P/_,J[R*2]=C,J[R*2+1]=g*P/_}for(let P=0;P<_;P+=1){const C=k+P*2,R=(N*_+P)*6;for(let Y=0;Y<6;Y+=1)$[R+Y]=C+Ar[Y]}B[N*2]=It,B[N*2+1]=Ht,I[N*2]=(tt+et)/2*s.x,I[N*2+1]=(bt+st)/2*s.y}const at=cn({texture:z,vertices:H.slice(),uvs:J,indices:$});at.tint=a,S.push({target:at,k:p,base:H,heights:K,rows:_,k0:d,k1:f,occluder:!0,walls:!0,normals:B,centers:I,facing:new Uint8Array(E).fill(2)})}}return S}function Tr(n,t,e){return n.cameraX===t.x&&n.cameraY===t.y&&n.cameraScale===t.scaleX&&n.cameraBleed===e?!0:(n.cameraX=t.x,n.cameraY=t.y,n.cameraScale=t.scaleX,n.cameraBleed=e,!1)}function yl(n,t,e=0){if(Tr(n,t,e))return;const{target:s,base:i,heights:o,rows:r}=n,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 d=i[c*2],f=i[c*2+1],p=d-t.x,_=f-t.y,m=c%l<2,g=Math.sqrt(p*p+_*_)||1e-6,w=o[c]+(m?h/g:0);a[c*2]=d+p*w,a[c*2+1]=f+_*w}s.vertices=a}function wl(n,t){if(n.orderX===t.x&&n.orderY===t.y)return!1;n.orderX=t.x,n.orderY=t.y;const{target:e,normals:s,centers:i,facing:o,rows:r}=n,a=o.length,l=(r+1)*2;let h=!1;for(let d=0;d<a;d+=1){const p=s[d*2]*(t.x-i[d*2])+s[d*2+1]*(t.y-i[d*2+1])>0?1:0;o[d]!==p&&(o[d]=p,h=!0)}if(!h)return!1;const c=e.geometry.indices;let u=0;for(let d=0;d<2;d+=1)for(let f=0;f<a;f+=1)if(o[f]===d)for(let p=0;p<r;p+=1){const _=f*l+p*2;for(let m=0;m<6;m+=1)c[u]=_+Ar[m],u+=1}return e.geometry.indices=c,!0}function vl({runs:n,texture:t,step:e,shear:s,baseScale:i,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 n){const d=u.axis===0,f=d?u.col1-u.col0:u.row1-u.row0,p=Math.max(1,f*c),_=d?u.col0:u.row0,m=typeof u.rail0=="number"&&typeof u.rail1=="number"?{first:(u.rail0-_)*c,last:(u.rail1-_)*c}:null,g=u.col0*e,w=u.col1*e,M=u.row0*e,S=u.row1*e,b=p+1,y=Math.min(u.from,u.to),v=Math.max(u.from,u.to),z=y*s,L=new Float32Array(b*4),T=new Float32Array(b*4),E=new Float32Array(b*4),G=new Float32Array(b*2),H=new Uint32Array(p*6),K=1;for(let $=0;$<b;$+=1){const B=$/p,I=u.sign>0?B:1-B,at=(u.from+(u.to-u.from)*I)*s,N=d?g:M,Ht=N+((d?w:S)-N)*B,lt=d?Ht:g,ut=d?M:Ht,ht=d?Ht:w,ct=d?S:Ht,tt=$*4;L[tt]=lt*i.x,L[tt+1]=ut*i.y,L[tt+2]=ht*i.x,L[tt+3]=ct*i.y,T[tt]=lt/l,T[tt+1]=ut/h,T[tt+2]=ht/l,T[tt+3]=ct/h;const bt=d?ut+K:lt+K,et=d?ct-K:ht-K,st=Math.min(Math.max(Ht,(d?g:M)+K),(d?w:S)-K);E[tt]=(d?st:bt)/l,E[tt+1]=(d?bt:st)/h,E[tt+2]=(d?st:et)/l,E[tt+3]=(d?et:st)/h,G[$*2]=at,G[$*2+1]=at}for(let $=0;$<p;$+=1){const B=$*2,I=$*6;H[I]=B,H[I+1]=B+1,H[I+2]=B+3,H[I+3]=B,H[I+4]=B+3,H[I+5]=B+2}const J=cn({texture:t,vertices:L.slice(),uvs:T,indices:H});a.push(Ml({base:L,uvs:E,heights:G,points:b,texture:t,kBase:z,sideTint:r,endIndex:u.sign>0?b-1:0,rails:m})),a.push({target:J,k:v*s,base:L,heights:G})}return a}function Ml(n){const{base:t,uvs:e,heights:s,points:i,texture:o,kBase:r,endIndex:a,sideTint:l,rails:h}=n,c=h?Math.max(0,Math.min(h.first,i-1)):0,u=h?Math.max(c,Math.min(h.last,i-1)):-1,d=h?u-c+1:0,f=d*2+2,p=new Float32Array(f*4),_=new Float32Array(f*4),m=new Float32Array(f*2),g=Math.max(0,d-1)*2+1,w=new Uint32Array(g*6),M=y=>y<d?(c+y)*2:y<d*2?(c+y-d)*2+1:a*2+(y-d*2);for(let y=0;y<f;y+=1){const v=M(y),z=y*4,L=t[v*2],T=t[v*2+1];p[z]=L,p[z+1]=T,p[z+2]=L,p[z+3]=T,_[z]=e[v*2],_[z+1]=e[v*2+1],_[z+2]=e[v*2],_[z+3]=e[v*2+1],m[y*2]=s[v],m[y*2+1]=r}let S=0;for(let y=0;y<3;y+=1){const v=y===2?d*2:y*d,z=y===2?d*2+1:v+d-1;for(let L=v;L<z;L+=1){const T=L*2,E=S*6;w[E]=T,w[E+1]=T+1,w[E+2]=T+3,w[E+3]=T,w[E+4]=T+3,w[E+5]=T+2,S+=1}}const b=cn({texture:o,vertices:p.slice(),uvs:_,indices:w});return b.tint=l,{target:b,k:r,base:p,heights:m}}function Sl(n,t){if(Tr(n,t,0))return;const{target:e,base:s,heights:i}=n,o=e.vertices;for(let r=0,a=i.length;r<a;r+=1){const l=s[r*2],h=s[r*2+1],c=i[r];o[r*2]=l+(l-t.x)*c,o[r*2+1]=h+(h-t.y)*c}e.vertices=o}const ls={mapSprite:null,occluder:null,slices:[],rampTexture:null,wallTextures:[]};function bl({mapSprite:n,bakedTexture:t,occluder:e,slices:s,rampTexture:i,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}),i&&i.destroy(!0);for(const r of o??[])r.destroy(!0);n&&(n.parent?.removeChild(n),n.destroy({texture:!1,textureSource:!1})),t?.destroy(!0)}async function kl(n){try{const t=await n.baseTexture;if(n.isAborted())return ls;const e=await hn({baseTexture:t,spriteSheetData:n.spriteSheetData,map:n.map,tiles:n.tiles,step:n.step,renderer:n.renderer,exclude:n.exclude});if(n.isAborted())return e.destroy(!0),ls;const s=new nt(e);if(n.layerRoot.addChildAt(s,0),!n.extruding)return{...ls,mapSprite:s};const i=await Al(n,t,e),o={mapSprite:s,...i};return n.isAborted()?(bl({...o,bakedTexture:e}),ls):o}catch(t){return console.error(`Failed to create static map with asset ${n.assetUrl}:`,t),ls}}async function Al(n,t,e){const s=Q.shear,i=[],o=[];let r=null,a=null;if(n.volume>0){r=new rt,r.zIndex=it(Math.max(n.layer,ai),n.level);{const h=await Ll(n,t,o);if(n.isAborted())return{occluder:r,slices:i,rampTexture:a,wallTextures:o};i.push(...xl({map:n.map,tiles:n.tiles,step:n.step,baseScale:n.baseScale,level:n.level,volume:n.volume,shear:s,sideTint:Te.sideTint,textures:h,tilesPerLevel:Te.faceTilesPerLevel,segments:Te.faceSegments}));const c=new nt(e);c.tint=16777215,i.push({target:c,k:(n.level+n.volume)*s,occluder:!0})}}const l=zr(n);if(l.length){if(a=await hn({baseTexture:t,spriteSheetData:n.spriteSheetData,map:n.map,tiles:n.ramps.map(h=>h.tile),step:n.step,renderer:n.renderer}),n.isAborted())return{occluder:r,slices:i,rampTexture:a,wallTextures:o};i.push(...vl({runs:l,texture:a,step:n.step,shear:s,baseScale:n.baseScale,segments:Te.rampSegments,sideTint:Te.sideTint}))}if(n.isAborted())return{occluder:r,slices:i,rampTexture:a,wallTextures:o};i.sort((h,c)=>h.k-c.k);for(const h of i)h.base||te(h.target,null,h.k,n.baseScale),(h.occluder?r:n.container).addChild(h.target);return{occluder:r,slices:i,rampTexture:a,wallTextures:o}}async function Ll(n,t,e){const s=new Map,i=Lr(n.volume,Te.faceTilesPerLevel);for(const o of n.tiles){const r=await hn({baseTexture:t,spriteSheetData:n.spriteSheetData,map:Array.from({length:i},()=>[o]),tiles:[o],step:n.step,renderer:n.renderer});e.push(r),s.set(o,r)}return s}function zr(n){if(!n.ramps?.length||!n.rampRuns)return[];const t=new Set(n.ramps.map(i=>`${i.from}:${i.to}`)),e=n.rampRuns.forLevel(n.level).filter(i=>t.has(`${i.from}:${i.to}`));return fl(e,(i,o)=>sl(i,o===0?n.baseScale.x:n.baseScale.y,n.step))}function Tl(n,t){if(!n.levelView)return;const e=n.levelView.cfg,s=Sr(n.hole,e.fadeRate);n.hasSprite&&zl(n,e,s,t),n.occluder&&Pl(n,e,s,t)}function zl(n,t,e,s){const{levelView:i,container:o}=n,r=n.roof?i.level<n.level&&El(n,t,s):null;if(i.mode==="layer"){const h=(n.roof?r:i.level<n.level&&wr(n.grid,i.x,i.y,n.floorSet))?t.layerAlpha:1;o.alpha+=(h-o.alpha)*e;return}const a=n.roof?r:i.level<n.level;an(n.hole,a,e),ln(o,n.hole,t,i,n.stage,s)}function Pl(n,t,e,s){const{levelView:i,occluder:o}=n,r=n.level>i.level;if(i.mode==="layer"){const a=r?t.layerAlpha:1;o.alpha+=(a-o.alpha)*e;return}an(n.occluderHole,r,e),ln(o,n.occluderHole,t,i,n.stage,s)}function Il(n,t){const e=n.levelView;return Lt(e.x,e.y,t,e.z*Q.shear)}function El(n,t,e){return e?nl(n.grid,n.tileSet,Il(n,e),e,[n.level*Q.shear],t.roofMargin??0):!1}const Cl=40,Pr=45,Rl=1.5;function Fl(n){let t=2166136261;for(let e=0;e<n.length;e+=1)t^=n.charCodeAt(e),t=Math.imul(t,16777619)>>>0;return t>>>0}function Ol(n){const t=n?.map?.length||0,e=n?.map?.[0]?.length||0,s=Fl(JSON.stringify(n?.game?.lighting??null));return`${e}x${t}:${s.toString(16)}`}function Xl(n,t,e,s){const{x:i,y:o}=As(s);return{x:(n+.5)*e*i,y:(t+.5)*e*o}}function On(n,t){const e=new Set(t||[]),s=[];if(!n||e.size===0)return s;for(let i=0;i<n.length;i+=1){const o=n[i]||[];for(let r=0;r<o.length;r+=1)e.has(o[r])&&s.push([r,i])}return s}function Xn(n){const t=new Map;for(const[s,i]of n)t.has(i)||t.set(i,new Set),t.get(i).add(s);const e=[];for(const s of[...t.keys()].sort((i,o)=>i-o)){const i=[...t.get(s)].sort((a,l)=>a-l);let o=i[0],r=i[0];for(let a=1;a<=i.length;a+=1){const l=i[a];l===r+1||(e.push({col:o,row:s,length:r-o+1}),o=l),r=l}}return e}function Gs(n,t,e,s,i,o){const r=e*o,a=Lt(n,t,s,r);return{x:a.x,y:a.y,scale:1+r,screenX:a.x*i.scale.x+i.position.x,screenY:a.y*i.scale.y+i.position.y}}function li(n,t,e){return!e&&Math.abs(t-Math.round(t))>.001?[Math.floor(t),Math.ceil(t)]:[bs(n,t)]}function Hi(n,t,e,s,i){return n+e>=0&&n-e<=s&&t+e>=0&&t-e<=i}function ze(n,t,e){if(!e)return 1;const s=t/1e3,i=Math.sin(s*7.3+n*12.9898)*.5+Math.sin(s*13.1+n*78.233)*.3+Math.sin(s*23.7+n*3.7)*.2;return 1-e*((i+1)/2)}function Ir(n,t){if(!(t>0)||n>=t)return 0;const e=1-Math.max(0,n)/t;return e*e}function Er(n){return(1-n)*(1-n)}const Dl=.35;function Cr(n){return(1-n)*(1-n*Dl)}function Yl(n,t){return!(t>0)||n>=t?0:Er(Math.max(0,n)/t)}function Rr(n,t,e){const s=t-n.x,i=e-n.y,o=n.intensity??1;if(n.kind!=="cone")return o*Yl(Math.hypot(s,i),n.radius);const r=Math.cos(n.rotation||0),a=Math.sin(n.rotation||0),l=s*r+i*a,h=Math.abs(i*r-s*a);if(!(n.radius>0)||l<=0||l>=n.radius)return 0;const c=l*(n.spread??.5);if(h>=c)return 0;const u=l/n.radius;return o*Cr(u)*(1-h/c)}function Hl(n,t,e,s){const i=[];for(const{light:o,factor:r}of n){const a=Rr(o,t,e)*r;a>0&&i.push({light:o,strength:a,angle:Math.atan2(o.y-e,o.x-t),color:o.color??16777215})}return i.sort((o,r)=>r.strength-o.strength),i.slice(0,Math.max(0,s))}const Fr=(n,t)=>`${n},${t}`;function Bl(n,t){const e=t>0?t:1,s=new Map;for(const i of n){const o=i.radius||0,r=Math.floor((i.x-o)/e),a=Math.floor((i.x+o)/e),l=Math.floor((i.y-o)/e),h=Math.floor((i.y+o)/e);for(let c=l;c<=h;c+=1)for(let u=r;u<=a;u+=1){const d=Fr(u,c);s.has(d)||s.set(d,[]),s.get(d).push(i)}}return{cellSize:e,cells:s}}function Wl(n,t,e){if(!n)return[];const s=Math.floor(t/n.cellSize),i=Math.floor(e/n.cellSize);return n.cells.get(Fr(s,i))||[]}function Vl(n,t,e,s,i,o){const r=Math.hypot(e-n,s-t);if(!(i>0)||r<=i)return null;const a=Math.sqrt(r*r-i*i);if(a>=o)return null;const l=Math.atan2(s-t,e-n),h=Math.asin(i/r),c=l-h,u=l+h;return[n+Math.cos(c)*a,t+Math.sin(c)*a,n+Math.cos(c)*o,t+Math.sin(c)*o,n+Math.cos(u)*o,t+Math.sin(u)*o,n+Math.cos(u)*a,t+Math.sin(u)*a]}function Nl(n,t,e){const s=t/1e3;return e*(Math.sin(s*.37+n*1.7)*.6+Math.sin(s*.61+n*4.1)*.4)}function Ul(n=ot.shared){let t=null,e=0;return{now(){const s=n.lastTime;return s!==t&&(t!==null&&(e+=Math.max(0,s-t)/1e3),t=s),e}}}const Gl=Ul();function Kl(n,t){return Math.floor(n*t)/t}function $l(n){return new Set(Object.keys(n||{}).map(Number))}function Zl(n,t,e=1){if(n.speed!==void 0){const s=n.frames?.length||0,i=t*(typeof e=="number"?e:e.x);return i>0?n.speed*s/i:0}return n.fps||0}function Or(n,t,e){return!(e>0)||!(t>0)?0:Math.floor(n*t)%e}function jl(n,t,e){const s=new rt,i=[];if(s.label="animatedTiles",!e)return{container:s,groups:i};const o=new Set(n.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:Zl(a,n.step,n.scale),textures:h,sprites:[],container:new rt,frame:0};c.container.label=`animatedTile-${l}`;for(let u=0;u<n.map.length;u+=1){const d=n.map[u];for(let f=0;f<d.length;f+=1){if(d[f]!==l)continue;const p=new nt(h[0]);p.x=f*n.step,p.y=u*n.step,p.cullable=!0,c.sprites.push(p),c.container.addChild(p)}}if(c.sprites.length===0){c.container.destroy();continue}s.addChild(c.container),i.push(c)}return{container:s,groups:i}}function ql(n,t,e=()=>!0){for(let s=0;s<n.length;s+=1){const i=n[s];if(!e(i.container))continue;const o=Or(t,i.fps,i.textures.length);if(o===i.frame)continue;i.frame=o;const r=i.textures[o];for(let a=0;a<i.sprites.length;a+=1)i.sprites[a].texture=r}}function Ql(n){n.container.parent?.removeChild(n.container),n.container.destroy({children:!0,texture:!1,textureSource:!1}),n.groups.length=0}function Dn(n,t,e){return(n||[]).filter(s=>(s.level||0)===t&&Number(s.layer)===e)}function Jl(n,t,e,s){const i=[];for(const o of n){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 nt(h[0]);c.anchor.set(.5),c.position.set((r+.5)*e,(a+.5)*e),s.addChild(c),i.push({item:o,sprite:c,textures:h,frame:0})}return i}function th(n,t){for(let e=0;e<n.length;e+=1){const s=n[e];if(s.item.kind==="rotate"){s.sprite.rotation=(s.item.rps||0)*2*Math.PI*t;continue}if(s.item.kind==="frames"){const i=Or(t,s.item.fps,s.textures.length);i!==s.frame&&(s.frame=i,s.sprite.texture=s.textures[i])}}}function eh(n){for(const t of n)t.sprite.parent?.removeChild(t.sprite),t.sprite.destroy({texture:!1,textureSource:!1});n.length=0}const sh=.8,yi=.6,Yn=.09,ih=.12,nh=.55;function Xr(n){let t=n+2654435769>>>0;return t=Math.imul(t^t>>>16,2246822507)>>>0,t=Math.imul(t^t>>>13,3266489909)>>>0,(t^t>>>16)>>>0}function oh(n,t,e=0){return Xr((Math.imul(n,73856093)^Math.imul(t,19349663)^Math.imul(e,83492791))>>>0)}function Hn(n,t,e){return Xr((n^Math.imul(t+e,668265261))>>>0)/4294967296}const hs=n=>Math.min(1,Math.max(0,n));function rh(n,t,e){if(!(e>0))return!1;const s=Math.floor(n/yi);if(Hn(t,s,0)>=e)return!1;const i=s*yi+Hn(t,s,1)*(yi-Yn);return n>=i&&n<i+Yn}function ah(n,t,e){const s=hs(e?.pulse||0),i=t%1e3/1e3,o=1-s*(.5+.5*Math.sin(2*Math.PI*(sh*n+i)));return rh(n,t,e?.dropouts||0)?{core:hs(o*ih),glow:hs(o*nh)}:{core:hs(o),glow:hs(o)}}const lh=4;function le(n){return Math.ceil(n*lh)}function Dr(n){return le(n)*2}const Bi=new WeakMap;function Yr({text:n,size:t}){return`${t}|${n}`}function hh(n){return Math.max(2,Math.round(n/4))}function ch(n,{text:t,size:e}){const s=hh(e),i=le(s),o=new rt,r=new en({text:String(t),style:{fontFamily:"monospace",fontWeight:"bold",fontSize:e,fill:16777215}});r.position.set(i,i),o.addChild(r);const a=new Vt(0,0,Math.ceil(r.width)+i*2,Math.ceil(r.height)+i*2),l=n.generateTexture({target:o,frame:a}),h=new sn({strength:s,quality:6});h.padding=Dr(s),r.filters=[h];const c=n.generateTexture({target:o,frame:a});return r.filters=[],h.destroy(),o.destroy({children:!0}),{core:l,glow:c}}function uh(n,t){let e=Bi.get(n);e||(e=new Map,Bi.set(n,e));const s=Yr(t);let i=e.get(s);return i||(i={...ch(n,t),count:0},e.set(s,i)),i.count+=1,{core:i.core,glow:i.glow}}function dh(n,t){const e=Bi.get(n),s=Yr(t),i=e?.get(s);i&&(i.count-=1,!(i.count>0)&&(e.delete(s),i.core.destroy(!0),i.glow.destroy(!0)))}class fh{constructor({sign:t,renderer:e,lighting:s,animated:i,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=oh(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=uh(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),i.addChild(this.glow,this.core))}_sprite(t){const e=new nt(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,i=null){const o=t===null?{core:1,glow:1}:ah(t,this._seed,this._sign.flicker);if(!this.emissive){this.glow.alpha=o.glow,this.core.alpha=o.core;return}const r=this._level*Q.shear,a=Lt(this._worldX,this._worldY,e,r);let l=1;i!==null?l=i: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,()=>dh(t,e)}}function _h(n,t,e,s){const i=$l(n?.animatedTiles),o=new Set(t);return{exclude:[...i],hasTiles:[...i].some(r=>o.has(r)),signs:Dn(n?.signs,e,s),decals:Dn(n?.decals,e,s)}}function Bn(n){return n.hasTiles||n.signs.length>0||n.decals.length>0}async function ph({spec:n,game:t,baseTexture:e,spriteSheetData:s,map:i,tiles:o,step:r,scale:a,level:l,animated:h,renderer:c,lighting:u,isAborted:d}){let f=null;if((n.hasTiles||n.decals.length>0)&&(f=await kr(e,s),d()))return f.destroy(),null;const p={sheet:f,tiles:null,decals:[],signs:[],tick:null};return n.hasTiles&&(p.tiles=jl({map:i,tiles:o,step:r,scale:a},f,t.animatedTiles),h.addChild(p.tiles.container)),f&&(p.decals=Jl(n.decals,f,r,h)),p.signs=n.signs.map(_=>new fh({sign:_,renderer:c,lighting:u,animated:h,step:r,scale:a,level:l})),p}function mh(n){return n?t=>{const e=t.getBounds();return e.maxX>=0&&e.minX<=n.width&&e.maxY>=0&&e.minY<=n.height}:()=>!0}function gh(n,{camera:t,levelView:e,screen:s,roofAlpha:i=null}){const o=Kl(Gl.now(),tl.maxFps),r=ot.shared.lastTime;n.tick!==r&&(n.tick=r,n.tiles&&ql(n.tiles.groups,o,mh(s)),th(n.decals,o));for(let a=0;a<n.signs.length;a+=1)n.signs[a].update(o,t,e,i)}function xh(n){if(!n)return()=>{};n.tiles&&(Ql(n.tiles),n.tiles=null),eh(n.decals);const t=n.signs.map(s=>s.destroy()),e=n.sheet;return n.signs=[],n.sheet=null,()=>{t.forEach(s=>s()),e?.destroy()}}class yh{constructor(t,e,s,i,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=Di(),this._occluderHole=Di(),this._occluder=null,this._baseScale=As(e.scale),this._slices=[],this._rampTexture=null,this._wallTextures=[],this.mapSprite=null,this._assetUrl=`${i}${e.spriteSheet.img}`,this._baseTexturePromise=Fi.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=wh(e.game,this._level,this._tiles),this._spriteSheetData=e.spriteSheet,this._step=e.step,this._layer=Number(e.layer)||1,t.zIndex=it(this._layer,this._level),this._parallaxK=this._level*Q.shear,this._layerRoot=new rt,this._layerRoot.label="layerRoot",this._animated=new rt,this._animated.label="animated",this._layerRoot.addChild(this._animated),te(this._layerRoot,null,this._parallaxK,this._baseScale),t.addChild(this._layerRoot),this._animationSpec=_h(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=il(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=Ol(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,On(this._map,this._roof?this._tiles:this._floor),this,{roof:this._roof}),this._ramps.length&&this._lighting.setRampWedges(this._level,zr({ramps:this._ramps,rampRuns:this._rampRuns,level:this._level,baseScale:this._baseScale,step:this._step}),this)),this._volumes=s.volumes||null,this._volume>0&&this._volumes?.setLayerVolume(this._level,On(this._map,this._tiles),this._volume,this,{step:this._step,scale:e.scale}),this.needsRender=this._level>=1||this._extruding||!!this._lighting?.isNight()||Bn(this._animationSpec),this._build(e)}async _build(t){const e=await kl({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||!Bn(this._animationSpec))&&(this._animations=await ph({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:br(this._hole,this._levelView.cfg)}render(){this._attachOccluder(),this._levelView&&this._levelView.attachStage(this._container.parent,this._renderer);const t=this._levelView?this._levelView.camera():At(this._container.parent,this._renderer);if(this._lighting&&(this._lighting.attachStage(this._container.parent,this._renderer),this._lighting.render()),(this._level>=1||this._occluder)&&Tl(this._seeThroughView(),t),this._animations&&gh(this._animations,{camera:t,levelView:this._levelView,screen:this._renderer?.screen,roofAlpha:this._roofAlpha()}),!(!this._parallaxK&&!this._slices.length)&&t){te(this._layerRoot,t,this._parallaxK,this._baseScale);for(let e=0;e<this._slices.length;e+=1){const s=this._slices[e];s.walls?(yl(s,t,Te.faceBleedPx),wl(s,t)):s.base?Sl(s,t):te(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=xh(this._animations);if(this._animations=null,this._lighting&&(this._lighting.releaseMap(this._mapKey,this),this._lighting=null),this._volumes?.release(this),this._volumes=null,Yi(this._hole,t),this._occluder){const a=this._occluder;this._occluder=null,a.filters=[],Yi(this._occluderHole,a),a.parent?.removeChild(a),a.destroy({children:!0,texture:!1,textureSource:!1})}const s=this.mapSprite,i=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=Js.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(),i&&i.destroy(!0);for(const a of o)a.destroy(!0);s&&s.destroy({children:!0,texture:!0,textureSource:!0})}}}function wh(n,t,e){const s=n?.roofs?.[t]??n?.roofs?.[String(t)];if(!Array.isArray(s)||s.length===0||!e?.length)return!1;const i=new Set(s),o=e.filter(r=>i.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 Pt=(n,t,e)=>n+(t-n)*e,oe=(n,t,e)=>Math.min(e,Math.max(t,n)),vh=n=>n*(Math.PI/180),Mh=n=>{for(;n>Math.PI;)n-=Math.PI*2;for(;n<-Math.PI;)n+=Math.PI*2;return n},V=(n,t)=>Math.random()*(t-n)+n;class Xe extends rt{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),ot.shared.add(this._tickListener),this._onEffectStart(),this.isComplete||this._update(0))}_onEffectStart(){}_update(){}_completeEffect(){this.isComplete||(this.isComplete=!0,this._tickListener&&(ot.shared.remove(this._tickListener),this._tickListener=null),typeof this.onComplete=="function"&&this.onComplete())}destroy(t){this.isComplete=!0,this._tickListener&&(ot.shared.remove(this._tickListener),this._tickListener=null),this.parent&&this.parent.removeChild(this),super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}class Sh extends Xe{constructor(t,e,s,i,o){super(i),this.x=t,this.y=e,this._textures=o.textures,this._contentSize=o.contentSize,this.config={particleCount:Math.round(V(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 i=Math.random()*Math.PI*2,o=V(e.minInitialSpeed,e.maxInitialSpeed),r=this._textures[Math.floor(Math.random()*this._textures.length)],a=new nt(r),l=V(0,t);a.anchor.set(.5),a.tint=e.color[Math.floor(Math.random()*e.color.length)],a.scale.set(V(e.particleMinSize,e.particleMaxSize)/this._contentSize),this.particlesData.push({sprite:a,x:Math.cos(i)*l,y:Math.sin(i)*l,vx:Math.cos(i)*o,vy:Math.sin(i)*o,rotation:Math.random()*Math.PI*2,spin:V(-e.maxSpin,e.maxSpin),lifetime:V(e.minLifetime,e.maxLifetime),age:0}),this.addChild(a)}}_update(t){if(this.isComplete)return;const{config:e}=this,s=t/1e3,i=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*=i,r.vy*=i,r.spin*=i,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:Pt(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 Hr(n,{x:t,y:e,z:s,level:i,reach:o,exclude:r=null}){const a=n?.texture("glint");return!ie.glints?.enabled||!a||!n.isNight()||!n.onScreen(t,e,s,o)?null:n.lightsAt(t,e,i,1,r)[0]||null}function Br(n,t,e,s=new nt){if(n)return n;const i=new nt(e);return i.anchor.set(.5),i.blendMode="add",i.mask=s,t.addChild(s,i),{sprite:i,mask:s}}function Wr(n){n&&(n.sprite.visible=!1)}function Vr(n,{hit:t,asset:e,x:s,y:i,rotation:o,size:r}){const{sprite:a}=n,l=ie.glints;a.texture=e.texture,a.visible=!0,a.position.set(s,i),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 re=0,ae=1,Me=2,Wi=3,es=4,ss=5,Fe=6,Kt=7,ti=8,Oe=10,jt=11,is=12,Wn=13,Vn=14,Nn=15,Vi=16,Ni=17,Ui=18,bh=19,kh=20,Ah=21,Lh=22,Th=0,zh=1,Ph=2,Ih=3,Eh=4,Ch=5,Rh=6,cs=7,Fh=8,Oh=9,Xh=10,Un=11,Gn=12,Dh=13,Yh=1,Hh=2,Gi=2,Nr=3,Ur=4,Bh=0,Wh=1,Vh=2,Nh=3,Uh=4,Gh=5,Kh=6,Kn=0,$n=1,Zn=2,$h=3,Zh=4,jh=6,qh=0,Qh=1,Jh=2,tc=3,ec=0,sc=1,ic=3,nc=4,oc=6,rc=7,ac=8,lc=0,hc=1,jn=2,cc=3,uc=0,dc=1,fc=2,_c=3,pc=4,qn=0,Qn=1,Jn=2,mc=3,gc=4,xc=5,yc=0,wc=1,vc=2,Mc=3,Sc=4,bc=5,kc=6,Ac=7,Lc=8,to=0,Tc=1,us=2,zc=1,Pc=2,Ic=1.4;class Ec{constructor(t,e,s,i,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=As(e.scale),t.scale=e.scale,this._assetUrl=`${i}${e.img}`,this._baseTexturePromise=Fi.load(this._assetUrl),this._damagedUrl=e.game?.imgDamaged?`${i}${e.game.imgDamaged}`:null,this._destroyedUrl=e.game?.imgDestroyed?`${i}${e.game.imgDestroyed}`:null,this._z=e.level||0,this._level=e.level||0,this._layer=Number(e.layer)||2,t.zIndex=it(this._layer,this._level),this._rotation=vh(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 nt(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!==to&&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)&&te(t,this._levelView.camera()??At(t.parent,this._renderer),this._z*Q.shear,this._baseScale)}update(t){this.sprite&&(this.sprite.x=t[qn]/this._baseScale.x,this.sprite.y=t[Qn]/this._baseScale.y,this.sprite.rotation=t[Jn]),this._worldX=t[qn],this._worldY=t[Qn],this._rotation=t[Jn],this._z=t[mc]||0;const e=bs(t[gc],this._z);e!==this._level&&(this._level=e,this._container.zIndex=it(this._drawLayer(),e),!e&&!this._z&&te(this._container,null,0,this._baseScale));const s=t[xc]||to;if(s!==this._state){const i=this._state===null;this._state=s,this._showState(s),s===us&&!i&&this._burst()}this._placeScorch()}_drawLayer(){return this._state===us?zc:this._layer}_standing(){return this._state!==us||!!this._destroyedUrl}_updateGlint(){const t=this._localCenter(),e=this.sprite.visible&&this._standing()?Hr(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){Wr(this._glint);return}const s=this._lighting.texture("glint");this._glint=Br(this._glint,this._container,s.texture);const{mask:i}=this._glint,o=this.sprite;i.texture=o.texture,i.position.copyFrom(o.position),i.scale.copyFrom(o.scale),i.rotation=o.rotation,Vr(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=it(this._drawLayer(),this._level),!this.sprite)return;if(t===us&&!this._destroyedUrl){this.sprite.visible=!1,this._showScorch();return}this._scorch&&(this._scorch.visible=!1),this.sprite.visible=!0;let e=null;t===Tc?e=this._damagedUrl:t===us&&(e=this._destroyedUrl),this._setTexture(e?Fi.load(e):this._baseTexturePromise,t,e??this._assetUrl)}async _setTexture(t,e,s){try{const i=await t;if(this._container.destroyed||!this.sprite||this._state!==e)return;this.sprite.texture=i,this.sprite.width=this._width,this.sprite.height=this._height}catch(i){console.error(`Failed to load map object state asset ${s}:`,i)}}_showScorch(){const t=this._assets.scorchTexture;if(t){if(!this._scorch){const{textures:e,contentSize:s}=t,i=new nt(e[Math.floor(Math.random()*e.length)]);i.anchor.set(.5),i.rotation=Math.random()*Math.PI*2,i.scale.set(Math.max(this._width,this._height)*Ic/s),this._scorch=i,this._container.addChild(i)}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,i=this._height/2;return{x:this._worldX/this._baseScale.x+t*s-e*i,y:this._worldY/this._baseScale.y+e*s+t*i}}_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 i=this._container.parent,o=this._assets.debrisTexture;if(!i||!o)return;const r=Math.max(this._width*this._baseScale.x,this._height*this._baseScale.y),a=new Sh(e,s,r,()=>{this._effects.delete(a),a.destroy()},o);a.zIndex=it(Pc,this._level),i.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 Cc=class extends rt{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 i=`${s.assetsBase}img/`;this._mode=t.type==="dynamic"?new Ec(this,t,s,i,e):new yh(this,t,s,i,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 eo=[16777215,9418751,10477760,15783820,14721232,10541296,15773836,12632280],Gr=n=>eo[n]??eo[0],Rc=2,Fc=.35;class Oc extends rt{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=it(Rc,this._level),this.scale=t.scale,this._draws=this._tiles.some(i=>this._solid.includes(i)),this.radarGraphics=new ft,this.addChild(this.radarGraphics),this._levelView=s.levelView||null,this._levelView&&this._draws&&(this.onRender=()=>{this.alpha=this._levelView.level===this._level?1:Fc}),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 i=0;i<s.length;i+=1){const o=s[i];this._solid.includes(o)&&t.rect(i*this._step,e*this._step,this._step/2,this._step/2)}}t.fill(Gr(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 so=2,Xc=9,Dc=1.5;class Yc extends rt{constructor(t,e,s,i){super(),this._level=t[jt]||0,this.zIndex=it(so,this._level),this._textures=e.tankRadarTexture,this.body=new nt,this.body.anchor.set(.5),this.levelRing=new ft,this.addChild(this.levelRing,this.body),this._voice=s?.voice??null,this._partId=i?.id,this.ping=null,this._voice&&e.radarPingTexture&&(this.ping=new nt(e.radarPingTexture.ring),this.ping.anchor.set(.5),this.ping.tint=as.color,this.ping.visible=!1,this.addChildAt(this.ping,0),this.onRender=()=>this._updatePing()),this._drawLevelRing(),this.x=t[re]||0,this.y=t[ae]||0,this._condition=t[Kt],this._teamId=t[ti],this.scale.set(5,5),this.create()}_drawLevelRing(){this.levelRing.clear(),this._level>0&&this.levelRing.circle(0,0,Xc).stroke({width:Dc,color:Gr(this._level)})}_updatePing(){const t=this._condition!==0&&this._voice.isTalking(this._partId)===!0;if(this.ping.visible=t,!t)return;const e=this._voice.talkingSince(this._partId)??0,s=(performance.now()-e)%as.period/as.period;this.ping.scale.set(1+(as.maxScale-1)*s),this.ping.alpha=as.alpha*(1-s)}create(){this._condition===0?this.body.texture=this._textures.destroyed:this._teamId===1?this.body.texture=this._textures.liveTeamId1:this._teamId===2&&(this.body.texture=this._textures.liveTeamId2)}update(t){this.x=t[re],this.y=t[ae];const e=t[jt]||0;e!==this._level&&(this._level=e,this.zIndex=it(so,e),this._drawLevelRing());const s=t[Kt],i=t[ti];let o=!1;s!==void 0&&s!==this._condition&&(this._condition=s,o=!0),i!==void 0&&i!==this._teamId&&(this._teamId=i,o=!0),o&&this.create()}destroy(t){super.destroy({children:!0,texture:!1,textureSource:!1,...t}),this.body=null,this.levelRing=null,this.ping=null,this._voice=null,this._textures=null}}function Kr(n,t,{minImpact:e,fullImpact:s}){return!(n<-e)||t!==0?0:Math.min(1,-n/s)}function io(n,t,e){if(n<0||n>=t)return 0;const s=n/t;if(s<e)return s/e;const i=(s-e)/(1-e);return(1-i)*(1-i)}function Hc({amount:n,gunRotation:t,config:e}){const s=Math.cos(t),i=Math.sin(t),o=e.gunKick*n,r=e.bodyKick*n,a=e.rock*n;return{gun:{x:-s*o,y:-i*o},body:{x:-s*r,y:-i*r},pitch:a*s,roll:a*i}}const Bc=n=>{const t=Math.min(1,Math.max(0,n));return t*t*(3-2*t)},Rs=(n,t,e)=>e>t?Bc((n-t)/(e-t)):+(n>=e),Wc=.001,$r=(n,t)=>n==="shotgun"?t.shotgun:t.cannon;function Vc(n,t,e){return n==="machinegun"?e.machinegun.magazine.in[0]*t:$r(n,e).closeAt*t}function wi(n,t,e,s){const i=e>0?t/e:1,o={gunPull:0,magazineOffset:[0,0,0],magazineHidden:!1};if(n==="machinegun"){const a=s.machinegun,{out:l,hideAt:h,showAt:c,travel:u,drop:d}=a.magazine,f=a.magazine.in,p=i<c?Rs(i,l[0],l[1]):1-Rs(i,f[0],f[1]);return o.gunPull=a.pull*Rs(i,0,l[1]),o.magazineOffset=[0,-u*p,-d*p],o.magazineHidden=i>=h&&i<c,o}const r=$r(n,s);return o.gunPull=r.pull*Rs(i,0,r.pullUntil),o}function Nc(n,t,e){const s=[{type:"kick",at:Wc}];return n==="machinegun"&&s.push({type:"box",at:e.machinegun.magazine.hideAt*t}),s}function Uc({primary:n,elapsed:t,previous:e,duration:s,endedAt:i=null,config:o}){const r=i!==null&&t>=i,a=r&&i<Vc(n,s,o),l=r?i:t,h=[];if(e!==void 0){for(const{type:_,at:m}of Nc(n,s,o))m>e&&m<=l&&h.push(_);r&&!a&&e<=i&&t>i&&h.push("kickForward")}const c={gunPull:0,magazineOffset:[0,0,0],magazineHidden:!1,events:h};if(!(t>0))return{...c,done:i!==null};if(!r)return{...wi(n,t,s,o),events:h,done:!1};const u=t-i;if(a){const _=1-u/o.cancelTime;if(_<=0)return{...c,done:!0};const m=wi(n,i,s,o);return{gunPull:m.gunPull*_,magazineOffset:(m.magazineHidden?wi(n,o.machinegun.magazine.out[1]*s,s,o).magazineOffset:m.magazineOffset).map(g=>g*_),magazineHidden:!1,events:h,done:!1}}const{travel:d,time:f}=o.release;if(!(u<f))return{...c,done:!0};const p=1-u/f;return{...c,gunPull:-d*p*p,done:!1}}function Gc(n){return n?.magazineHidden?new Set(["magazine"]):new Set}const Kc=.4,$c=1.5;function Zc(n,t,e,s){const i=Kc*t,o=Math.min(1,Math.max(0,n/i)),r=t-i;return{along:o,height:Math.max(0,e*(1-o)+s*4*o*(1-o)),alpha:n<=i?1:Math.max(0,1-(n-i)/r)}}class jc{constructor(){this._items=[]}get count(){return this._items.length}spawn({stage:t,x:e,y:s,baseZ:i,height:o,dx:r,dy:a,rise:l,angle:h,size:c,color:u,life:d,zIndex:f}){const p=new ft().rect(-c[0]/2,-c[1]/2,c[0],c[1]).fill(u);p.zIndex=f,p.rotation=h,t.addChild(p),this._items.push({graphics:p,x:e,y:s,baseZ:i,height:o,dx:r,dy:a,rise:l,angle:h,life:d,t:0})}step(t,e,{shear:s,levelHeight:i,alpha:o=1}){this._items=this._items.filter(r=>{if(r.t+=t,r.t>=r.life)return r.graphics.destroy(),!1;const{along:a,height:l,alpha:h}=Zc(r.t,r.life,r.height,r.rise),c=Lt(r.x+r.dx*a,r.y+r.dy*a,e,(r.baseZ+l/i)*s);return r.graphics.position.set(c.x,c.y),r.graphics.rotation=r.angle+$c*2*Math.PI*a,r.graphics.alpha=h*o,!0})}destroy(){for(const t of this._items)t.graphics.destroy();this._items=[]}}const Ks=Math.PI*2,qc=.09,Qc=.113;function Jc(n,t){return!(t>0)||n>=t?0:1-n/t}function tu({x:n,y:t,level:e,heading:s,hullLength:i,blast:o,config:r,rng:a=Math.random}){if((o.level||0)!==(e||0))return null;const l=o.x-n,h=o.y-t,c=Math.hypot(l,h),u=Jc(c,o.radius);if(!u)return null;const d=c<r.underShare*i,f=d?a()*Ks:Math.atan2(h,l)-s;return{strength:u,dirU:Math.cos(f),dirV:Math.sin(f),hop:d,phaseX:a()*Ks,phaseY:a()*Ks}}function no({elapsed:n,kick:t,config:e}){const s=t.strength,i=e.decay>0?Math.exp(-n/e.decay):0,o=i*Math.cos(Ks*e.wobbleHz*(n/1e3)),r=e.rock*s*o,a=t.hop&&n<e.hopDuration,l=a?e.hop*s*Math.sin(Math.PI*n/e.hopDuration):0,c=n<e.shakeDuration?e.shake*s*(1-n/e.shakeDuration):0;return{pitch:r*t.dirU,roll:r*t.dirV,lift:l,shakeX:c*Math.sin(n*qc+t.phaseX),shakeY:c*Math.sin(n*Qc+t.phaseY),envelope:s*i,done:n>=e.duration&&!a}}const eu={paintHull:{mode:"planarHull",region:"hullTop"},paintTurret:{mode:"planarTurret",region:"turretTop"},paintGun:{mode:"strip",region:"gunSide"},track:{mode:"planarSide",region:"trackSide"},steel:{mode:"swatch",region:"steelSwatch"},smoke:{mode:"swatch",region:"smokeSwatch"},darkSteel:{mode:"swatch",region:"darkSteelSwatch"},headlight:{mode:"swatch",region:"headlightSwatch"},chrome:{mode:"swatch",region:"chromeSwatch"},flameTank:{mode:"strip",region:"flameTankSide"},hose:{mode:"swatch",region:"hoseSwatch"},igniter:{mode:"swatch",region:"igniterSwatch"},missile:{mode:"strip",region:"missileSide"},warhead:{mode:"swatch",region:"warheadSwatch"},mine:{mode:"local",region:"mineTop",side:"mineSwatch"},fuze:{mode:"swatch",region:"fuzeSwatch"},bottle:{mode:"strip",region:"bottleSide"},wick:{mode:"swatch",region:"wickSwatch"}};function su(n,t){const e=eu[n];return n==="track"&&Math.abs(t[1])<.9?{mode:"strip",region:"trackTop"}:e.mode==="local"?t[2]>.35?{mode:"local",region:e.region}:{mode:"swatch",region:e.side}:{mode:e.mode,region:e.region}}const oo=(n,t,e)=>Math.min(e,Math.max(t,n));function iu(n,t){const e=t.indices.map(i=>n.vertices[i][0]),s=t.indices.map(i=>n.vertices[i][1]);return{u0:Math.min(...e),u1:Math.max(...e),v0:Math.min(...s),v1:Math.max(...s)}}function nu(n,t){return n.faces.map(e=>ou(n,e,t))}function ou(n,t,e){const{regions:s,texelsPerMeter:i}=e,[o,r]=n.turretAxis??[0,0],a=s[t.uvRegion],l=([c,u])=>[c/e.width,u/e.height];if(t.uvMode==="swatch"||t.kind==="bottom"){const c=t.uvMode==="swatch"?a:s.darkSteelSwatch;return t.indices.map(()=>l([c.x+c.w/2,c.y+c.h/2]))}const h=t.uvMode==="local"?iu(n,t):null;return t.indices.map(c=>{const[u,d,f]=n.vertices[c];let p,_;if(h)p=a.x+(u-h.u0)/(h.u1-h.u0||1)*a.w,_=a.y+(d-h.v0)/(h.v1-h.v0||1)*a.h;else if(t.uvMode==="planarHull")p=a.originX+u*i,_=a.originY+d*i;else if(t.uvMode==="planarTurret")p=a.originX+(u-o)*i,_=a.originY+(d-r)*i;else if(t.uvMode==="planarSide")p=a.originX+u*i,_=a.y+a.h-f*i;else{const m=t.strip||{v:0,half:1},g=m.axis==="v",w=g?d:u,M=g?u-m.u:d-m.v;p=a.originX+(w-(m.start??0))*i,_=a.y+(.5+.5*M/m.half)*a.h}return l([oo(p,a.x,a.x+a.w),oo(_,a.y,a.y+a.h)])})}function ru(n){let t=0;for(let e=0;e<n.length;e+=1){const[s,i]=n[e],[o,r]=n[(e+1)%n.length];t+=s*r-o*i}return t}function Zr(n){let t=0,e=0,s=0;for(let o=0;o<n.length;o+=1){const[r,a,l]=n[o],[h,c,u]=n[(o+1)%n.length];t+=(a-c)*(l+u),e+=(l-u)*(r+h),s+=(r-h)*(a+c)}const i=Math.hypot(t,e,s)||1;return[t/i,e/i,s/i]}const ro=(n,t)=>[n[0]-t[0],n[1]-t[1],n[2]-t[2]],au=(n,t)=>n[0]*t[0]+n[1]*t[1]+n[2]*t[2],ao=(n,t)=>[n[1]*t[2]-n[2]*t[1],n[2]*t[0]-n[0]*t[2],n[0]*t[1]-n[1]*t[0]],lo=n=>{const t=Math.hypot(n[0],n[1],n[2])||1;return[n[0]/t,n[1]/t,n[2]/t]},ei=(n,t,e,s)=>[[n,e],[t,e],[t,s],[n,s]];function lu(){const n=[],t=[],e=[],s=(l,h,c)=>{const{part:u,group:d,material:f,outline:p,shadow:_,strip:m}=l,g=e.length,w=n.length,M=[0,0,0];for(const S of h)M[0]+=S[0]/h.length,M[1]+=S[1]/h.length,M[2]+=S[2]/h.length;e.push({part:u,group:d,outline:p===!0,shadow:_!==!1,first:w,count:h.length}),n.push(...h);for(const S of c){let b=S,y=Zr(b.map(E=>h[E]));const v=[0,0,0];for(const E of b)v[0]+=h[E][0]/b.length,v[1]+=h[E][1]/b.length,v[2]+=h[E][2]/b.length;au(y,ro(v,M))<0&&(b=[...b].reverse(),y=y.map(E=>-E));const{mode:z,region:L}=su(f,y),T={indices:b.map(E=>w+E),piece:g,part:u,group:d,material:f,kind:y[2]>.35?"top":y[2]<-.35?"bottom":"side",uvMode:z,uvRegion:L};m&&(T.strip=m),t.push(T)}},i=({bottom:l,top:h,w0:c,w1:u,...d})=>{const f=l.length,p=[...l.map(([m,g])=>[m,g,c]),...h.map(([m,g])=>[m,g,u])],_=[l.map((m,g)=>g),h.map((m,g)=>f+g)];for(let m=0;m<f;m+=1){const g=(m+1)%f;_.push([m,g,f+g,f+m])}s(d,p,_)};return{vertices:n,faces:t,pieces:e,prism:i,extrude:({section:l,axis:h,from:c,to:u,...d})=>{const f=l.length,p=(g,w,M)=>h==="v"?[g,M,w]:[M,g,w],_=[...l.map(([g,w])=>p(g,w,c)),...l.map(([g,w])=>p(g,w,u))],m=[l.map((g,w)=>w),l.map((g,w)=>f+w)];for(let g=0;g<f;g+=1){const w=(g+1)%f;m.push([g,w,f+w,f+g])}s(d,_,m)},cylinder:({from:l,to:h,radius:c,radiusTo:u=c,sides:d,...f})=>{const p=lo(ro(h,l)),_=Math.abs(p[2])<.9?[0,0,1]:[1,0,0],m=lo(ao(p,_)),g=ao(p,m),w=(y,v)=>Array.from({length:d},(z,L)=>{const T=L/d*Math.PI*2,E=Math.cos(T)*v,G=Math.sin(T)*v;return[y[0]+m[0]*E+g[0]*G,y[1]+m[1]*E+g[1]*G,y[2]+m[2]*E+g[2]*G]}),M=[...w(l,c),...w(h,u)],S=[Array.from({length:d},(y,v)=>v),Array.from({length:d},(y,v)=>d+v)];for(let y=0;y<d;y+=1){const v=(y+1)%d;S.push([y,v,d+v,d+y])}const b=f.strip||{v:(l[1]+h[1])/2,half:Math.max(c,u)};s({...f,strip:b},M,S)},box:(l,h,[c,u],[d,f],[p,_],m={})=>{const g=ei(c,u,d,f);i({bottom:g,top:g,w0:p,w1:_,part:l,material:h,...m})}}}const ho={w1:"cannon",w3:"shotgun",w4:"machinegun",w5:"flame",w7:"missile",w2:"mines",w6:"molotov"},jr=["cannon","shotgun","machinegun"],hu=["flame","missile"],cu=["mines","molotov"],uu=3,ys=n=>Math.min(uu,Math.max(0,Math.round(Number(n)||0))),co=new WeakMap;function du(n){let t=co.get(n);if(!t){t={};for(const[e,s]of Object.entries(n))ho[e]&&(t[s.code]=ho[e]);co.set(n,t)}return t}function fu(n,t){const e=du(t),s=(h,c)=>c.includes(e[h])?e[h]:null,i=s(n.primaryCode,jr)??"cannon";let o=s(n.secondaryCode,hu)??"none",r=s(n.grenadeCode,cu)??"none";const a=o==="missile"?ys(n.secondaryAmount):0,l=r==="none"?0:ys(n.grenadeAmount);return o==="missile"&&a===0&&(o="none"),l===0&&(r="none"),{primary:i,secondary:o,missiles:a,grenade:r,grenades:l}}function Ki({primary:n,secondary:t,missiles:e,grenade:s,grenades:i}){const o=t==="missile"?`missile${e}`:t,r=s==="none"?"none":`${s}${i}`;return`${n}|${o}|${r}`}const _u=jr.map((n,t)=>({primary:n,label:`P${t+1}`})),pu=[{secondary:"none",missiles:0,label:"S0"},{secondary:"flame",missiles:0,label:"S1"},...[1,2,3].map(n=>({secondary:"missile",missiles:n,label:`S2-${n}`}))],mu=[{grenade:"none",grenades:0,label:"G0"},...[1,2,3].map(n=>({grenade:"mines",grenades:n,label:`G1-${n}`})),...[1,2,3].map(n=>({grenade:"molotov",grenades:n,label:`G2-${n}`}))];_u.flatMap((n,t)=>pu.flatMap((e,s)=>mu.map((i,o)=>({number:t*35+s*7+o+1,label:`${n.label}+${e.label}+${i.label}`,primary:n.primary,secondary:e.secondary,missiles:e.missiles,grenade:i.grenade,grenades:i.grenades}))));const gu={ground:0,track:1,hullLow:2,fender:3,hull:4,hullFit:5,sideRack:6,turret:7,turretFit:8,mantlet:9,gun:10,mount:11,roofMount:12},{hull:Ls,track:Fs,fittings:De,turret:Mt,guns:$s}=W,Z=Mt.axisU,Dt=W.gunAxisW,uo=n=>[...n.map(([t,e])=>[t+Z,e]),...[...n].reverse().map(([t,e])=>[t+Z,-e])],xu=n=>{const{bottom:t,top:e}=Ls.upper,s=(t.u[1]-n)/(t.u[1]-e.u[1]);return t.w+s*(e.w-t.w)},yu=n=>{const{bottom:t,top:e}=Ls.upper,s=(n-t.u[0])/(e.u[0]-t.u[0]);return t.w+Math.min(1,Math.max(0,s))*(e.w-t.w)},wu=n=>{const{bottom:t,top:e}=Ls.upper,s=(t.v-Math.abs(n))/(t.v-e.v);return t.w+Math.min(1,Math.max(0,s))*(e.w-t.w)},vu=()=>{const{bottom:n,top:t}=Ls.upper,[e,s]=n.u,[i,o]=n.corner,r=(u,d)=>u.map(([f,p])=>[f,d*p]),a=[[s,n.nose],[o,n.v],[i,n.v],[e,n.nose]],l=.05,h=[[t.u[1],t.v-l],[t.u[1]-l,t.v],[t.u[0]+l,t.v],[t.u[0],t.v-l]],c=u=>[...r(u,1),...[...r(u,-1)].reverse()];return{bottom:c(a),top:c(h)}},Mu=()=>{const{u:n,back:t,w:e,radius:s}=Mt.mantlet,i=[[Z+t,e-s]];for(let o=0;o<=6;o+=1){const r=-Math.PI/2+o/6*Math.PI;i.push([Z+n+Math.cos(r)*s,e+Math.sin(r)*s])}return i.push([Z+t,e+s]),i},Su={lid:{u:Z+Mt.loaderHatch.u-Mt.loaderHatch.radius,w:Mt.roof.w+Mt.loaderHatch.h},cupolaLid:{u:Z+Mt.cupola.u-Mt.cupola.lid.radius,w:Mt.cupola.w[1]+Mt.cupola.lid.h}},bu=(n,t)=>{const e=Math.max(...n.map(([,s])=>s));return[...n.filter(([s])=>s>t),[t,e],[t,0]]};function qr(n={},t={}){const e=lu(),s=t.wreck===!0;s&&(n={});const i=$s[n.primary]?n.primary:"cannon",o={group:"hull",material:"paintHull"},r={group:"turret",material:"paintTurret"};for(const[T,E]of[[Fs.v[0],Fs.v[1]],[-1.475,-.975]])e.extrude({section:s&&E<0?bu(Fs.profile,Ss.trackCut):Fs.profile,axis:"v",from:T,to:E,part:"track",group:"hull",material:"track",outline:!0,strip:{v:(T+E)/2,half:(E-T)/2}});s&&zu(e);const{lower:a,upper:l,fender:h}=Ls;e.prism({bottom:ei(a.bottom.u[0],a.bottom.u[1],-.975,a.bottom.v),top:ei(a.top.u[0],a.top.u[1],-.975,a.top.v),w0:a.bottom.w,w1:a.top.w,part:"hullLow",...o});const c=vu();e.prism({bottom:c.bottom,top:c.top,w0:l.bottom.w,w1:l.top.w,part:"hull",outline:!0,...o});for(const T of[1,-1])for(const E of["mid","front","rear"]){const[G,H]=h[E].v;e.box("fender","paintHull",h[E].u,T>0?[G,H]:[-H,-G],h.w,{group:"hull",outline:!0})}const u=De.bowMg,d=xu(u.u);e.cylinder({from:[u.u,u.v,d-.02],to:[u.u,u.v,d+.1],radius:u.radius,radiusTo:u.radius*.8,sides:8,part:"hullFit",group:"hull",material:"darkSteel",shadow:!1}),e.cylinder({from:[u.u,u.v,d+.06],to:[u.barrel,u.v,d+.06],radius:.03,sides:6,part:"hullFit",group:"hull",material:"darkSteel",shadow:!1});const f=De.headlight,p=wu(f.v)+.1;e.cylinder({from:[f.u[0],f.v,p],to:[f.u[1],f.v,p],radius:f.radius,sides:6,part:"hullFit",group:"hull",material:"headlight",shadow:!1});const _=De.engineHatch;e.box("hullFit","paintHull",_.u,_.v,[l.top.w,l.top.w+_.h],{group:"hull",shadow:!1});const m=De.exhausts,g=yu((m.u[0]+m.u[1])/2)+m.radius*.6;for(const T of[1,-1])e.cylinder({from:[m.u[0],T*m.v,g],to:[m.u[1],T*m.v,g],radius:m.radius,sides:8,part:"hullFit",shadow:!1,...o});const w=De.smokeDrums;for(const T of[1,-1])e.cylinder({from:[w.u,T*w.v[0],h.w[1]+w.radius],to:[w.u,T*w.v[1],h.w[1]+w.radius],radius:w.radius,sides:6,part:"hullFit",group:"hull",material:"smoke",outline:!0});const M=["mines","molotov"].includes(n.grenade)&&ys(n.grenades)>0;for(const T of De.fuelTanks)T.rear&&M||e.cylinder({from:[T.u[0],T.v,T.w],to:[T.u[1],T.v,T.w],radius:T.radius,sides:8,part:"hullFit",outline:!0,...o});const S=De.zipBox;e.box("hullFit","paintHull",S.u,S.v,S.w,{group:"hull",outline:!0}),e.prism({bottom:uo(Mt.base.outline),top:uo(Mt.roof.outline),w0:Mt.base.w,w1:Mt.roof.w,part:"turret",outline:!0,...r}),e.extrude({section:Mu(),axis:"v",from:-.4,to:Mt.mantlet.v,part:"mantlet",outline:!0,...r});const b=Mt.cupola;e.cylinder({from:[Z+b.u,b.v,b.w[0]],to:[Z+b.u,b.v,b.w[1]],radius:b.radius,sides:10,part:"turretFit",outline:!0,...r}),e.cylinder({from:[Z+b.u,b.v,b.w[1]],to:[Z+b.u,b.v,b.w[1]+b.lid.h],radius:b.lid.radius,sides:8,part:"turretFit",group:"cupolaLid",material:"paintTurret",shadow:!1});const y=Mt.loaderHatch;e.cylinder({from:[Z+y.u,y.v,Mt.roof.w],to:[Z+y.u,y.v,Mt.roof.w+y.h],radius:y.radius,sides:8,part:"turretFit",group:"lid",material:"paintTurret",shadow:!1});const v=Mt.vent;for(const T of Mt.vents){const E=Mt.roof.w;e.cylinder({from:[Z+T.u,T.v,E],to:[Z+T.u,T.v,E+v.h],radius:v.radius,radiusTo:v.topRadius,sides:8,part:"turretFit",shadow:!1,...r}),e.cylinder({from:[Z+T.u,T.v,E+v.h],to:[Z+T.u,T.v,E+v.h+v.domeH],radius:v.topRadius,radiusTo:v.domeRadius,sides:8,part:"turretFit",shadow:!1,...r})}const z=Mt.periscope;for(const T of Mt.periscopes)e.cylinder({from:[Z+T.u,T.v,Mt.roof.w],to:[Z+T.u,T.v,Mt.roof.w+z.h],radius:z.radius,sides:6,part:"turretFit",shadow:!1,...r});Pu(e,i,s?t.bendSign??1:0);let L=null;return n.secondary==="flame"?L=ku(e):n.secondary==="missile"&&Au(e,ys(n.missiles)),M&&Lu(e,n.grenade,ys(n.grenades)),{vertices:e.vertices,faces:e.faces,pieces:e.pieces,partOrder:gu,turretAxis:[Z,0],turretRingW:Mt.base.w,hinges:Su,igniter:L}}function ku(n){const{tank:t,brackets:e,hose:s,nozzle:i,nozzleBracket:o,igniter:r}=ns.flame,a={part:"mount",group:"turret"},l=([c,u,d])=>[Z+c,u,d];n.cylinder({from:[Z+t.u,t.v[0],t.w],to:[Z+t.u,t.v[1],t.w],radius:t.radius,sides:10,material:"flameTank",outline:!0,strip:{axis:"v",u:Z+t.u,half:t.radius,start:t.v[0]},...a});for(const c of e)n.box("mount","chrome",ws(c.u),c.v,c.w,{group:"turret",shadow:!1});for(let c=0;c<s.points.length-1;c+=1)n.cylinder({from:l(s.points[c]),to:l(s.points[c+1]),radius:s.radius,sides:6,material:"hose",...a});n.cylinder({from:[Z+i.u[0],i.v,i.w],to:[Z+i.u[1],i.v,i.w],radius:i.radius,sides:8,material:"chrome",outline:!0,...a}),n.box("mount","chrome",ws(o.u),o.v,o.w,{group:"turret"});const h=n.pieces.length;return n.box("mount","igniter",ws(r.u),r.v,r.w,{group:"turret",shadow:!1}),h}const ws=([n,t],e=0)=>[Z+n+e,Z+t+e];function Au(n,t){const{body:e,nose:s,fins:i,rail:o,rails:r}=ns.missile;for(const a of r.slice(r.length-t)){const l=a.name==="roof"?"roofMount":"mount",h={part:l,group:"turret"},{v:c,w:u}=a,d=S=>ws(S,a.u),[f,p]=d(e.u);n.cylinder({from:[f,c,u],to:[p,c,u],radius:e.radius,sides:8,material:"missile",outline:!0,strip:{v:c,half:e.radius,start:f},...h});const[_,m]=d(s.u);n.cylinder({from:[_,c,u],to:[m,c,u],radius:s.radius,radiusTo:s.tipRadius,sides:8,material:"warhead",...h});const g=d(i.u),w=i.thickness/2;n.box(l,"chrome",g,[c-i.span,c+i.span],[u-w,u+w],{group:"turret",shadow:!1}),n.box(l,"chrome",g,[c-w,c+w],[u-o.below[1],u+i.span],{group:"turret",shadow:!1}),n.box(l,"chrome",d(o.u),[c-o.halfWidth,c+o.halfWidth],[u-o.below[0],u-o.below[1]],{group:"turret"});const M=a.pylon??a.bracket;n.box(l,"chrome",ws(M.u),M.v,M.w,{group:"turret"})}}function Lu(n,t,e){const{rack:s,places:i,sideV:o,mine:r,molotov:a}=dr,l={part:"sideRack",group:"hull"},h=([u,d],f)=>f>0?[u,d]:[-d,-u],c=i.slice(0,e);for(const u of[1,-1].filter(d=>c.some(f=>f.side===d))){const d=h(s.v,u);n.box("sideRack","darkSteel",s.u,d,s.w,{group:"hull",outline:!0}),t==="molotov"&&Tu(n,s,d,a.crate)}for(const{u,side:d}of c){const f=d*o;if(t==="mines"){n.cylinder({from:[u,f,r.w[0]],to:[u,f,r.w[1]],radius:r.radius,sides:12,material:"mine",outline:!0,...l}),n.cylinder({from:[u,f,r.w[1]],to:[u,f,r.w[1]+r.fuze.h],radius:r.fuze.radius,sides:8,material:"fuze",shadow:!1,...l});continue}const{bottle:p,wick:_}=a,m=u+p.body.u[0],g={v:f,half:p.body.radius,start:m};for(const[w,M]of[[p.body,8],[p.neck,6]])n.cylinder({from:[u+w.u[0],f,p.w],to:[u+w.u[1],f,p.w],radius:w.radius,sides:M,material:"bottle",strip:g,...l});n.box("sideRack","wick",[u+_.u[0],u+_.u[1]],[f-_.halfWidth,f+_.halfWidth],_.w,{group:"hull",shadow:!1})}}function Tu(n,t,[e,s],i){const[o,r]=t.u,{wall:a,divider:l}=i,h=[t.w[1],i.top],c=(o+r)/2,u={group:"hull",outline:!0};for(const[d,f]of[[[o,o+a],[e,s]],[[r-a,r],[e,s]],[[o+a,r-a],[e,e+a]],[[o+a,r-a],[s-a,s]]])n.box("sideRack","darkSteel",d,f,h,u);n.box("sideRack","darkSteel",[c-l/2,c+l/2],[e+a,s-a],h,{group:"hull"})}function zu(n){const{u:t,v:e,angle:s,size:i}=Ss.trackPiece,[o,r,a]=i,l=Math.cos(s),h=Math.sin(s),c=ei(-o/2,o/2,-r/2,r/2).map(([u,d])=>[t+u*l-d*h,e+u*h+d*l]);n.prism({bottom:c,top:c,w0:0,w1:a,part:"ground",group:"hull",material:"track",outline:!0})}function Pu(n,t,e=0){const s={part:"gun",group:"gun"};if(t==="shotgun"){const{barrel:u,flare:d,muzzle:f}=$s.shotgun;n.cylinder({from:[Z+u.u[0],0,Dt],to:[Z+u.u[1],0,Dt],radius:u.radius,sides:10,material:"paintGun",outline:!0,...s}),n.cylinder({from:[Z+d.u[0],0,Dt],to:[Z+d.u[1],0,Dt],radius:d.radius[0],radiusTo:d.radius[1],sides:10,material:"paintGun",outline:!0,...s}),n.cylinder({from:[Z+f.u[0],0,Dt],to:[Z+f.u[1],0,Dt],radius:f.radius,sides:10,material:"darkSteel",shadow:!1,...s});return}if(t==="machinegun"){const{barrels:u,clamps:d,clamp:f,brake:p,magazine:_}=$s.machinegun;for(const[m,g]of[[-1,"gunLeft"],[1,"gunRight"]])n.cylinder({from:[Z+u.u[0],m*u.v,Dt],to:[Z+u.u[1],m*u.v,Dt],radius:u.radius,sides:6,material:"paintGun",outline:!0,part:"gun",group:g});for(const m of d)n.box("gun","darkSteel",[Z+m-f.du/2,Z+m+f.du/2],[-.2,f.v],[Dt-f.h/2,Dt+f.h/2],{group:"gun",shadow:!1});n.box("gun","darkSteel",[Z+p.u[0],Z+p.u[1]],[-.24,p.v],[Dt-p.h/2,Dt+p.h/2],{group:"gun",outline:!0}),n.box("turretFit","steel",[Z+_.u[0],Z+_.u[1]],_.v,_.w,{group:"magazine"});return}const i=Mt.sleeve;for(let u=0;u<i.length-1;u+=1)n.cylinder({from:[Z+i[u][0],0,Dt],to:[Z+i[u+1][0],0,Dt],radius:i[u][1],radiusTo:i[u+1][1],sides:8,part:"mantlet",group:"turret",material:"paintGun",outline:!0,shadow:!1});const{barrel:o}=$s.cannon;if(!e){n.cylinder({from:[Z+o.u[0],0,Dt],to:[Z+o.u[1],0,Dt],radius:o.radius,sides:10,material:"paintGun",outline:!0,...s});return}const r=Ss.bend,a=o.u[1]-r.u,l=Math.sign(e)*r.yaw,h=[Z+r.u,0,Dt],c=[h[0]+a*Math.cos(r.pitch)*Math.cos(l),a*Math.cos(r.pitch)*Math.sin(l),Dt+a*Math.sin(r.pitch)];for(const[u,d]of[[[Z+o.u[0],0,Dt],h],[h,c]])n.cylinder({from:u,to:d,radius:o.radius,sides:10,material:"paintGun",outline:!0,...s})}function Iu(...n){let t=2166136261;const e=s=>{t^=s&4294967295,t=Math.imul(t,16777619)};for(const s of n){if(typeof s=="string")for(let i=0;i<s.length;i+=1)e(s.charCodeAt(i));else e(Math.round(Number(s)||0));e(2654435769)}return t>>>0}function Qr(n){let t=n>>>0;return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}function Eu(n,t,e){const s=Iu(String(n??""),Math.round(t),Math.round(e)),i=Qr(s),o=([l,h])=>l+i()*(h-l),r=()=>i()<.5?-1:1,a=Ss.turretPose;return{seed:s,bendSign:r(),turretPose:{du:o(a.du),dv:o(a.dv),yaw:r()*o(a.yaw),roll:r()*o(a.roll),pitch:o(a.pitch)},lidAngle:Ss.lidAngle}}function Jr(n){const t=[...n].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=[],i=[];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(;i.length>=2&&e(i[i.length-2],i[i.length-1],r)<=0;)i.pop();i.push(r)}return s.pop(),i.pop(),s.concat(i)}function ta(n,t,e){if(!n)return{x:0,y:0};const s=Math.hypot(n[0],n[1])||1,i=-n[0]/s/t,o=-n[1]/s/t,r=Math.cos(e),a=Math.sin(e);return{x:i*r+o*a,y:-i*a+o*r}}function Cu({model:n,points:t,lift:e=0,drift:s,hidden:i}){const o=new Map;for(const a of n.faces)if(!(n.pieces[a.piece].shadow===!1||i?.has(a.group))){o.has(a.piece)||o.set(a.piece,new Set);for(const l of a.indices)o.get(a.piece).add(l)}const r=[];for(const a of o.values()){const l=[...a].map(h=>{const[c,u,d]=t[h],f=Math.max(0,d+e);return[c+s.x*f,u+s.y*f]});r.push(Jr(l))}return r}function Ru({model:n,projected:t}){const e=new Map;for(const s of n.faces)if(n.pieces[s.piece].outline){e.has(s.piece)||e.set(s.piece,new Set);for(const i of s.indices)e.get(s.piece).add(i)}return[...e.values()].map(s=>Jr([...s].map(i=>t[i])))}const Fu=[[1,.25],[.7,.35],[.45,.5],[.22,.8]];function Ou(n){const t=new ft;let e=null;t.blendMode="add";const s=o=>{t.clear();for(const[r,a]of Fu)t.circle(0,0,o*r).fill({color:n.color,alpha:a});e=o};return{graphics:t,update:({model:o,projected:r,unitScale:a,time:l})=>{if(o.igniter===null||o.igniter===void 0){t.visible=!1;return}const{first:h,count:c}=o.pieces[o.igniter];let u=0,d=0;for(let m=h;m<h+c;m+=1)u+=r[m][0]/c,d+=r[m][1]/c;const f=n.radius*a;f!==e&&s(f);const p=l/1e3*n.hz*Math.PI*2,_=.5+.25*Math.sin(p)+.25*Math.sin(p*.37+1);t.visible=!0,t.position.set(u,d),t.alpha=n.alpha*(1-n.flicker*_)},destroy:()=>t.destroy()}}const fo=new Set(["turret","gun","gunLeft","gunRight","magazine","lid","cupolaLid"]),Xu=new Set(["gun","gunLeft","gunRight"]);function Du({model:n,gunRotation:t=0,pitch:e=0,roll:s=0,gunKick:i={x:0,y:0},unitScale:o,turretAxis:r=n.turretAxis??[0,0],gunLeftKick:a=0,gunRightKick:l=0,lidAngle:h=0,cupolaLidAngle:c=0,magazineOffset:u=[0,0,0],shift:d={x:0,y:0},squash:f=0,turretPose:p=null}){const _=o,m=Math.cos(t),g=Math.sin(t),w=Math.cos(e),M=Math.sin(e),S=Math.cos(s),b=Math.sin(s),y=1-f,v=new Array(n.vertices.length);for(const lt of n.faces)for(const ut of lt.indices)v[ut]=lt.group;const z=n.hinges??{},L=(lt,ut,[ht,ct,tt])=>{if(!ut||!z[lt])return[ht,ct,tt];const{u:bt,w:et}=z[lt],st=Math.cos(ut),k=Math.sin(ut),P=ht-bt,C=tt-et;return[bt+P*st-C*k,ct,et+P*k+C*st]},T=lt=>lt==="lid"?h:lt==="cupolaLid"?c:0,E=r[0]*_,G=r[1]*_,H=([lt,ut,ht])=>{const ct=ut*S-ht*b,tt=ut*b+ht*S;return[lt*w-tt*M,ct,lt*M+tt*w]},K=([lt,ut,ht])=>[lt*m-ut*g,lt*g+ut*m,ht],J=([lt,ut,ht])=>{const[ct,tt]=K([lt-E,ut-G,ht]);return[ct+E,tt+G,ht]},$=p?Yu(p):null,B=(n.turretRingW??0)*_*y,I=([lt,ut,ht])=>{const[ct,tt,bt]=$.rotate([lt-E,ut-G,ht-B]);return[ct+E+p.du*_,tt+G+p.dv*_,bt+B]},at=lt=>lt==="gunLeft"?a:lt==="gunRight"?l:0,N=n.vertices.map(([lt,ut,ht],ct)=>{const tt=v[ct];let bt=L(tt,T(tt),[lt,ut,ht]);tt==="magazine"&&(bt=bt.map((st,k)=>st+u[k]));let et=[bt[0]*_,bt[1]*_,bt[2]*_*y];if(fo.has(tt)&&(et=J(et),$&&(et=I(et))),Xu.has(tt)){const st=at(tt);et=[et[0]+i.x+m*st,et[1]+i.y+g*st,et[2]]}return et=H(et),[et[0]+d.x,et[1]+d.y,et[2]]}),It=n.faces.map(lt=>{const{group:ut}=lt;let ht=Hu(n,lt,y);return ht=Ht(ut,T(ut),ht),fo.has(ut)&&(ht=K(ht),$&&(ht=$.rotate(ht))),H(ht)});return{points:N,normals:It};function Ht(lt,ut,[ht,ct,tt]){if(!ut||!z[lt])return[ht,ct,tt];const bt=Math.cos(ut),et=Math.sin(ut);return[ht*bt-tt*et,ct,ht*et+tt*bt]}}function Yu({yaw:n=0,pitch:t=0,roll:e=0}){const s=Math.cos(n),i=Math.sin(n),o=Math.cos(t),r=Math.sin(t),a=Math.cos(e),l=Math.sin(e);return{rotate([h,c,u]){const d=h*s-c*i,f=h*i+c*s,p=f*a-u*l,_=f*l+u*a;return[d*o-_*r,p,d*r+_*o]}}}function Hu(n,t,e){return Zr(t.indices.map(s=>{const[i,o,r]=n.vertices[s];return[i,o,r*e]}))}function Bu({x:n,y:t,camera:e,heading:s,shear:i,levelHeight:o,maxLean:r,topHeight:a,gain:l=1}){if(!e)return{x:0,y:0};let h=(n-e.x)*i*l/o,c=(t-e.y)*i*l/o;const u=Math.hypot(h,c)*a;if(u>0&&r>0){const p=r*Math.tanh(u/r)/u;h*=p,c*=p}const d=Math.cos(s),f=Math.sin(s);return{x:h*d+c*f,y:-h*f+c*d}}function Wu({points:n,lean:t,zScale:e=1}){return n.map(([s,i,o])=>[(s+t.x*o)*e,(i+t.y*o)*e])}function Vu({model:n,points:t,projected:e,hidden:s}){const i=[];n.faces.forEach((r,a)=>{if(s?.has(r.group))return;const l=r.indices.map(h=>e[h]);if(ru(l)>1e-9){let h=0;for(const c of r.indices)h+=t[c][2];i.push({index:a,height:h/r.indices.length,face:r})}});const o=n.partOrder;return i.sort((r,a)=>o[r.face.part]-o[a.face.part]||r.height-a.height||r.index-a.index),i.map(r=>r.index)}function Nu(n,t,e){const s=Math.cos(t),i=Math.sin(t),o=n[0]*s-n[1]*i,r=n[0]*i+n[1]*s,a=o*e.uLight[0]+r*e.uLight[1]+n[2]*e.uLight[2];return(e.uAmbient+e.uDiffuse*Math.max(a,0))*e.uNorm}const vs=(n,t)=>n>>t&255,Uu=n=>[vs(n,16)/255,vs(n,8)/255,vs(n,0)/255];function we(n,t,e){const s=Math.min(Math.max(e,0),1),i=o=>{const r=vs(n,o);return Math.round(r+(vs(t,o)-r)*s)};return i(16)<<16|i(8)<<8|i(0)}function ea(n,t){const[e,s]=n[0];if(t<=e)return s;for(let i=1;i<n.length;i+=1){const[o,r]=n[i];if(t<=o){const[a,l]=n[i-1];return we(l,r,(t-a)/(o-a))}}return n[n.length-1][1]}const Gu=`#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
+ `,Ku=`#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
+ uniform float uChar;
128
+ uniform vec3 uCharColor;
129
+
130
+ void main(void) {
131
+ vec4 color = texture(uTexture, vUV);
132
+
133
+ color.rgb = mix(color.rgb, uCharColor * color.a, uChar);
134
+ finalColor = vec4(color.rgb * vShade, color.a) * vColor;
135
+ }
136
+ `;let _o=null;function $u(n){return _o||=cr.from({vertex:Gu,fragment:Ku,name:"tank-model"}),new Ca({glProgram:_o,resources:{uTexture:n.source,textureUniforms:new Ri({uTextureMatrix:{value:n.textureMatrix.mapCoord,type:"mat3x3<f32>"}}),charUniforms:new Ri({uChar:{value:0,type:"f32"},uCharColor:{value:new Float32Array(3),type:"vec3<f32>"}})}})}function Zu(n,t,e){const{uniforms:s}=n.resources.charUniforms;s.uChar=t,s.uCharColor.set(Uu(e))}function ju(n,t){n.resources.uTexture=t.source,n.resources.textureUniforms.uniforms.uTextureMatrix=t.textureMatrix.mapCoord}function qu(n,t){const e=[];let s=0,i=0;for(const f of n.faces)e.push(s),s+=f.indices.length,i+=f.indices.length-2;const o=new Float32Array(s*2),r=new Float32Array(s*2),a=new Float32Array(s).fill(1),l=new Uint32Array(i*3),h=f=>{nu(n,f).forEach((p,_)=>{p.forEach(([m,g],w)=>{r[(e[_]+w)*2]=m,r[(e[_]+w)*2+1]=g})})};h(t);const c=new Ra({attributes:{aPosition:{buffer:o,format:"float32x2"},aUv:{buffer:r,format:"float32x2"},aShade:{buffer:a,format:"float32"}},indexBuffer:l}),u=$u(t.texture),d=new ur({geometry:c,shader:u,texture:t.texture});return{mesh:d,setAtlas(f){h(f),c.getBuffer("aUv").update(),ju(u,f.texture),d.texture=f.texture},setChar(f,p){Zu(u,f,p)},update(f,p,_){n.faces.forEach((g,w)=>{const M=e[w];g.indices.forEach((S,b)=>{o[(M+b)*2]=f[S][0],o[(M+b)*2+1]=f[S][1],a[M+b]=p[w]})});let m=0;for(const g of _){const w=e[g],M=n.faces[g].indices.length;for(let S=1;S<M-1;S+=1)l[m]=w,l[m+1]=w+S,l[m+2]=w+S+1,m+=3}l.fill(0,m),c.getBuffer("aPosition").update(),c.getBuffer("aShade").update(),c.indexBuffer.update()},destroy(){d.destroy(),u.destroy(),c.destroy()}}}const Qu=se(W.hull.length),Ju=se(W.hull.width),Ts={m1:{length:Qu,width:Ju,turretAxis:se(W.turret.axisU),barrelHeight:se(W.gunAxisW),turretTop:se(W.turret.roof.w)}},td=Ts.m1.turretTop;function un({x:n,y:t,camera:e,heading:s=0}){return Bu({x:n,y:t,camera:e,heading:s,shear:Q.shear,levelHeight:Zt.levelHeight,maxLean:Zt.maxLean,gain:Zt.leanGain,topHeight:td})}function sa({x:n,y:t,camera:e,level:s,height:i,weight:o}){const r=s*Q.shear,a=r+i/Zt.levelHeight*Q.shear,l=Lt(n,t,e,a);if(o>=1)return{x:l.x,y:l.y,k:a};const h=Lt(n,t,e,r),c=un({x:n,y:t,camera:e}),u=i*(1+r);return{x:Pt(h.x+c.x*u,l.x,o),y:Pt(h.y+c.y*u,l.y,o),k:a}}function dn({x:n,y:t,camera:e,level:s,height:i=Be.height}){const o=s*Q.shear,r=e?Math.hypot(n-e.x,t-e.y):0;if(r===0)return o;const a=un({x:n,y:t,camera:e}),l=i*Zt.levelHeight;return o+Math.hypot(a.x,a.y)/r*l*(1+o)}function ed({lightDir:n,lightZ:t,ambient:e,diffuse:s}){const[i,o]=n||[0,0],r=Math.hypot(i,o,t)||1,a=[i/r,o/r,t/r],l=e+s*Math.max(a[2],0);return{uLight:a,uAmbient:e,uDiffuse:s,uNorm:l?1/l:1}}const sd=.55;function id(n,t=0){if(n.muzzle)return[n.muzzle.reach,0];if(n.origin)return n.origin;const e=n.rails?.length??0;if(e===0)return null;const s=Math.min(Math.max(Math.ceil(t),1),e);return n.rails[e-s]}function nd({x:n,y:t,heading:e,gunRotation:s,model:i,weapon:o,charge:r=0}){const a={x:n+Math.cos(e)*i.turretAxis,y:t+Math.sin(e)*i.turretAxis},l=e+s,h=Math.cos(l),c=Math.sin(l),u=id(o,r);if(!u){const p=i.length*sd;return{axis:a,point:{x:n+h*p,y:t+c*p}}}const[d,f]=u;return{axis:a,point:{x:a.x+d*h-f*c,y:a.y+d*c+f*h}}}const od=-Math.PI/4,rd=.35,ad=.35,ld=.6,hd=.6,cd=n=>1-Math.pow(1-n,3);class ud{constructor(t,e=xr){this._config=e;const s=new nt(t.icon),i=e.size/t.icon.width;s.anchor.set(.5),s.scale.set(i),this._arcs=[],this._view=new rt,this._view.zIndex=el,this._view.visible=!1,this._view.addChild(s);for(let o=0;o<e.arcs;o+=1){const r=new nt(t.arc);r.anchor.set(.5),r.rotation=od,r.tint=e.color,this._arcs.push({sprite:r,baseScale:e.size/t.arc.width}),this._view.addChild(r)}}get view(){return this._view}update({active:t,x:e,y:s,nowMs:i,sinceMs:o}){const r=this._view;if(!r||(r.visible=t,!t))return;const a=this._config,l=Math.max(0,i-o);r.position.set(e,s-a.offsetY),r.scale.set(cd(Math.min(1,l/a.popIn))),this._arcs.forEach(({sprite:h,baseScale:c},u)=>{const d=(l/a.period+u/a.arcs)%1,f=a.size*(rd+ad*d);h.position.set(f,-f),h.alpha=1-d,h.scale.set(c*(ld+hd*d))})}destroy(){this._view?.destroy({children:!0,texture:!1,textureSource:!1}),this._view=null,this._arcs=[]}}class dd extends ft{constructor(){super(),this.visible=!1}update(t,e){if(this.clear(),!t){this.visible=!1;return}const s=t.level*Q.shear,i=Lt(t.startX,t.startY,e,s),o=Lt(t.endX,t.endY,e,s),r=we(Ue.colors.start,Ue.colors.end,t.fraction),a=o.x-i.x,l=o.y-i.y,h=Math.hypot(a,l),{dash:c,gap:u,width:d,alpha:f,cross:p}=Ue;if(this.visible=!0,this.zIndex=it(Ue.baseZ,t.level),h>0){const m=a/h,g=l/h;for(let w=0;w<h;w+=c+u){const M=Math.min(w+c,h);this.moveTo(i.x+m*w,i.y+g*w).lineTo(i.x+m*M,i.y+g*M)}this.stroke({width:d,color:r,alpha:f})}const _=t.radius*(1+s);this.circle(o.x,o.y,_).fill({color:r,alpha:Ue.ringFill}).stroke({width:Ue.ringWidth,color:r,alpha:f}),this.moveTo(o.x-p,o.y).lineTo(o.x+p,o.y).moveTo(o.x,o.y-p).lineTo(o.x,o.y+p).stroke({width:d,color:r,alpha:f})}}const fd=n=>({length:n.length,width:n.width}),pe=fd(Ts.m1),Ms={offset:(W.track.v[0]+W.track.v[1])/2*$t,width:(W.track.v[1]-W.track.v[0])*$t,back:-W.track.profile.at(-1)[0]*$t},po=724759,vi=3,_d=1,Qe=new Map,pd=n=>{const t=Ki(n);return Qe.has(t)||Qe.set(t,qr(n)),Qe.get(t)},md=n=>{const t=`wreck:${n}`;return Qe.has(t)||Qe.set(t,qr({},{wreck:!0,bendSign:n})),Qe.get(t)},gd=ed({lightDir:on.lightDir,lightZ:gs.lightZ,ambient:gs.ambient,diffuse:gs.diffuse}),xd=new Map(Object.values(Se).map(n=>[n.code,n])),yd=Se.w1,mo=Se.w5,wd=Se.w6,go=n=>fu({primaryCode:n[Ni],secondaryCode:n[Ui],secondaryAmount:n[bh],grenadeCode:n[kh],grenadeAmount:n[Ah]},Se),vd=7,Md=1,xo=1.15,Sd=1.25,bd=.6,kd=1,Ad=.015,Ld=2.5;function Td(n,t=0){const e=Number.isFinite(n)?n:0,s=oe(e,0,1),i=Math.max(0,e-1),o=Pt(Md,xo,s)+(Sd-xo)*i,r=Pt(bd,kd,s),a=1+Ad*(1-s)*Math.sin(2*Math.PI*Ld*(t/1e3));return{rate:o*a,volumeFactor:r}}class zd extends rt{constructor(t,e,s,i){super(),this._modelAtlases=e.tankModelTexture,this._outline=new ft,this._levelAlpha=1,this._levelAlphaFilter=new Oi({alpha:1}),this._silhouettePolygons=[],this._igniter=Ou(ns.flame.glow),this.addChild(this._outline,this._igniter.graphics),this._model=null,this._modelAtlasShown=null,this._projected=null,this._loadout=go(t),this._primaryCode=t[Ni],this._secondaryCode=t[Ui],this._modelShadow=null,this._wreck=null,this._renderer=s.renderer||null,this._voice=s.voice??null,this._radioTextures=e.radioBadgeTexture??null,this._radioBadge=null,this._partId=i?.id,this._muzzles=s.muzzles??null,this._shopSounds=s.shopSounds??null,this._throwAimService=s.throwAim??null,this._throwAim=null,this._worldX=t[re]||0,this._worldY=t[ae]||0,this.x=this._worldX,this.y=this._worldY,this.rotation=t[Me]||0,this._gunRotation=t[Wi]||0,this._engineLoad=t[Fe]||0,this._condition=t[Kt],this._length=pe.length,this._width=pe.width,this._teamId=t[ti],this._z=t[Oe]||0,this._physLevel=t[jt]||0,this._vz=t[is]||0,this._prevVz=this._vz,this._pitch=t[Wn]||0,this._roll=t[Vn]||0,this._burning=(t[Vi]||0)>0,this._char=0,this._reloading=(t[Nn]||0)===1,this._reloadAnim=!1,this._reloadElapsed=0,this._reloadPrevious=0,this._reloadEndedAt=null,this._reloadDuration=0,this._reloadState=null,this._debris=new jc,this._reloadRock={elapsed:1/0,sign:1},this._reloadTilt={pitch:0,roll:0},this._mgBarrel=0,this._barrelElapsed=[1/0,1/0],this._reloadSoundTimer=null,this._reloadSoundId=null,this._switchSoundId=null,this._hitSoundId=null,this._burnSoundId=null,this._landImpact=0,this._landTimer=0,this._squash=0,this._level=bs(t[jt],this._z),this.zIndex=it(vi,this._level),this._isLocal=()=>s.localPlayer?.is(i?.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(a=>this._onBlast(a)):null,this._unsubscribeShots=s.shots&&i?.id!==void 0?s.shots.subscribe(i.id,{fired:()=>this._onFired(),muzzle:()=>this._weaponWorld(this._primaryWeapon())}):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(),this._soundManager=s.soundManager,this._soundId=null;const o=this._soundManager.getSoundConfig("tankEngine");this._baseEngineVolume=o?.volume||0,this._hasEngineSound=!!o,this._surfaces=s.surfaces||null,this._waterSoundId=null,this._speed=Math.hypot(t[es]||0,t[ss]||0);const r=this._soundManager.getSoundConfig("tankWater");this._baseWaterVolume=r?.volume||0,this._hasWaterSound=!!r,this.create()}_initSounds(){this._soundId||this._condition===0||!this._hasEngineSound||(this._soundId=this._soundManager.registerSound("tankEngine",this._getSoundData()))}_getSoundData(){const{rate:t,volumeFactor:e}=Td(this._engineLoad,performance.now());return{position:{x:this._worldX,y:this._worldY},rate:t,volume:this._baseEngineVolume*e,spatial:!this._isLocal()}}create(){this._condition===0?(this._wreck??=Eu(this._partId,this._worldX,this._worldY),this._char=0,this._showModel(this._modelAtlases.destroyed),this._gunRotation=0,this._resetRecoil(),this.destroySounds(),this._removeLights()):(this._wreck=null,this._showModel(this._liveAtlas()),this._initSounds(),this._addLights())}update(t){this._worldX=t[re],this._worldY=t[ae],this.rotation=t[Me],this._gunRotation=t[Wi],this._engineLoad=t[Fe]||0,this._speed=Math.hypot(t[es]||0,t[ss]||0),this._z=t[Oe]||0,this._physLevel=t[jt]||0,this._vz=t[is]||0,this._pitch=t[Wn]||0,this._roll=t[Vn]||0,this._burning=(t[Vi]||0)>0,this._primaryCode=t[Ni],this._secondaryCode=t[Ui],this._setLoadout(go(t));const e=(t[Nn]||0)===1;e&&!this._reloading&&(t[Kt]??this._condition)>0&&this._playReloadSound(),(!e||(t[Kt]??this._condition)===0)&&this._stopReloadSound(),e&&!this._reloading?(this._reloadAnim=!0,this._reloadElapsed=0,this._reloadPrevious=0,this._reloadEndedAt=null,this._reloadDuration=this._primaryWeapon().reload??0):!e&&this._reloading&&this._reloadAnim&&(t[Kt]??this._condition)>0&&(this._reloadEndedAt=this._reloadElapsed),this._reloading=e;const s=Kr(this._prevVz,this._vz,He);s>0&&(this._landImpact=s,this._landTimer=He.duration),this._prevVz=this._vz;const i=bs(t[jt],this._z);i!==this._level&&(this._level=i,this.zIndex=it(vi,i)),this._levelView&&this._isLocal()&&this._levelView.set(i,this._worldX,this._worldY,this._z),this._condition>0&&(this._soundId===null?this._initSounds():this._soundManager.updateSoundData(this._soundId,this._getSoundData()));const o=t[Kt],r=t[ti];let a=!1;o!==void 0&&o!==this._condition&&(o>this._condition&&(this._char=0),this._condition=o,a=!0),r!==void 0&&r!==this._teamId&&(this._teamId=r,a=!0),a&&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}=ye.water.sound,i=oe(this._speed/e,0,1);return{position:{x:this._worldX,y:this._worldY},rate:Pt(s.min,s.max,i),volume:this._baseWaterVolume*(t+(1-t)*i),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._length/2,i=this._width/2*ie.headlights.offset,o=this._worldX+t*s,r=this._worldY+e*s;return[{x:o+e*i,y:r-t*i},{x:o-e*i,y:r+t*i}]}_addLights(){if(!this._lighting||this._headlights)return;const{headlights:t,tankGlow:e}=ie,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=li(this._physLevel,e,this._vz!==0),i=this._headlightPoints();for(let o=0;o<2;o+=1)this._lighting.updateLight(this._headlights.cones[o],{x:i[o].x,y:i[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=de.attack*de.duration;this._recoilElapsed=this._recoilElapsed<de.duration?Math.min(this._recoilElapsed,t):0,this._loadout.primary==="machinegun"&&(this._barrelElapsed[this._mgBarrel]=0,this._mgBarrel=1-this._mgBarrel)}_primaryWeapon(){return xd.get(this._primaryCode)??yd}_beamWeapon(){return this._secondaryCode===mo.code?mo:this._primaryWeapon()}_weaponWorld(t){return this._condition===0||this.destroyed?null:nd({x:this._worldX,y:this._worldY,heading:this.rotation,gunRotation:this._gunRotation,model:Ts.m1,weapon:t}).point}_playShopSound(){if(!this._isLocal()||!this._shopSounds)return;this._shopSounds.takeHit()&&(this._stopHitSound(),this._hitSoundId=this._soundManager.registerSound("ownHit",{position:{x:this._worldX,y:this._worldY},spatial:!1})),this._shopSounds.takeSwitch()&&(this._stopSwitchSound(),this._switchSoundId=this._soundManager.registerSound("weaponSwitch",{position:{x:this._worldX,y:this._worldY},spatial:!1}));const t=[["buy",this._shopSounds.take()],["emptyClick",this._shopSounds.takeEmpty()]];for(const[e,s]of t)s&&this._soundManager.registerSound(e,{position:{x:this._worldX,y:this._worldY},spatial:!1})}_updateThrowAim(){if(!this._throwAimService||!this._isLocal()||!this.parent)return;const t=this._throwAimService.get(),e=t?this._weaponWorld(wd):null,s=t&&e?this._throwAimLine(t,e):null;if(!s&&!this._throwAim)return;this._throwAim||(this._throwAim=new dd,this.parent.addChild(this._throwAim));const i=this._levelView?this._levelView.camera():At(this.parent,this._renderer);this._throwAim.update(s,i)}_throwAimLine(t,e){const s=this.rotation+this._gunRotation,i=Math.cos(s),o=Math.sin(s),r=this._throwAimService.wallAt?.(e.x,e.y,i,o,t.range,this._physLevel)??null,a=r===null?t.range:Math.min(t.range,r);return{startX:e.x,startY:e.y,endX:e.x+i*a,endY:e.y+o*a,radius:t.radius,fraction:t.fraction,level:this._physLevel}}_publishMuzzle(){if(!this._muzzles||this._partId===void 0)return;const t=this._weaponWorld(this._beamWeapon());t?this._muzzles.set(this._partId,t.x,t.y,this.rotation+this._gunRotation,this._physLevel):this._muzzles.delete(this._partId)}_resetRecoil(){this._recoilElapsed=1/0,this._barrelElapsed[0]=1/0,this._barrelElapsed[1]=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(){for(let s=0;s<2;s+=1)this._barrelElapsed[s]!==1/0&&(this._barrelElapsed[s]+=ot.shared.deltaMS,this._barrelElapsed[s]>=de.duration&&(this._barrelElapsed[s]=1/0));if(this._recoilElapsed===1/0)return;this._recoilElapsed+=ot.shared.deltaMS;const t=io(this._recoilElapsed,de.duration,de.attack);if(t===0&&this._recoilElapsed>=de.duration){this._resetRecoil();return}const e=Hc({amount:t,gunRotation:this._gunRotation,config:de});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=tu({x:this._worldX,y:this._worldY,level:this._physLevel,heading:this.rotation,hullLength:this._length,blast:t,config:rs});if(!e)return;const s=this._blastKick?no({elapsed:this._blastElapsed,kick:this._blastKick,config:rs}).envelope:0;e.strength>=s&&(this._blastKick=e,this._blastElapsed=0)}_stepBlast(){if(!this._blastKick)return;const t=this._blastKick.hop&&this._blastElapsed<rs.hopDuration;this._blastElapsed+=ot.shared.deltaMS;const e=no({elapsed:this._blastElapsed,kick:this._blastKick,config:rs});if(t&&this._blastElapsed>=rs.hopDuration&&He.duration>0&&(this._landImpact=this._blastKick.strength,this._landTimer=He.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}_groundZ(){return this._vz!==0?this._physLevel:this._z}_updateView(){this._publishMuzzle(),this._playShopSound(),this._updateBurnSound(),this._updateThrowAim(),this._levelView&&this._levelView.attachStage(this.parent,this._renderer);const t=this._levelView?this._levelView.camera():At(this.parent,this._renderer);this._lighting&&(this._lighting.attachStage(this.parent,this._renderer),this._lighting.render()),this._levelView&&(this._setLevelAlpha(this._levelView.alphaFor(this._level,this._worldX,this._worldY,this._z)),this.tint=this._levelView.tintFor(this._level)),this._stepBlast();const e=Lt(this._worldX,this._worldY,t,this._viewZ()*Q.shear);if(this.position.set(e.x,e.y),this._landTimer>0){this._landTimer=Math.max(0,this._landTimer-ot.shared.deltaMS);const s=this._landTimer/He.duration;this._squash=Math.sin(s*Math.PI)*He.squash*this._landImpact}else this._squash=0;this._stepRecoil(),this._stepReload(),this._stepReloadRock(),this._stepChar(),this._debris.step(ot.shared.deltaMS/1e3,t,{shear:Q.shear,levelHeight:Zt.levelHeight,alpha:this._levelAlpha}),this._applyModel(t),this._updateShadow(t),this._updateGlint(),this._updateCaster(),this._updateRadioBadge(e)}_setLevelAlpha(t){this._levelAlpha=t,this._levelAlphaFilter.alpha=t;const e=t<1;e!==this.filters?.length>0&&(this.filters=e?[this._levelAlphaFilter]:null)}_updateRadioBadge(t){const e=this._condition!==0&&this._voice?.isTalking(this._partId)===!0;if(!(!e&&!this._radioBadge)){if(!this._radioBadge){if(!this._radioTextures||!this.parent)return;this._radioBadge=new ud(this._radioTextures,xr),this.parent.addChild(this._radioBadge.view)}this._radioBadge.update({active:e,x:t.x,y:t.y,nowMs:performance.now(),sinceMs:this._voice?.talkingSince(this._partId)??0})}}_updateGlint(){const t=1+this._viewZ()*Q.shear,e=this._projected?Hr(this._lighting,{x:this._worldX,y:this._worldY,z:this._viewZ(),level:this._level,reach:this._length/2*t,exclude:this._ownLights}):null;if(!e){Wr(this._glint);return}const s=this._lighting.texture("glint");this._glint||(this._glint=Br(null,this,s.texture,new ft));const{sprite:i,mask:o}=this._glint;this.children.at(-1)!==i&&this.addChild(i),o.clear();for(const r of this._silhouettePolygons)o.poly(r.flat()).fill(16777215);Vr(this._glint,{hit:e,asset:s,x:0,y:0,rotation:e.angle-this.rotation,size:this._length*t})}_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._length/2}}_liveAtlas(){const t=this._teamId===2?"TeamId2":"TeamId1",e=this._condition===2?"damaged1":this._condition===1?"damaged2":"live";return this._modelAtlases[e+t]??this._modelAtlases[`live${t}`]}_geometry(){return this._wreck?md(this._wreck.bendSign):pd(this._loadout)}_showModel(t){this._modelAtlasShown=t;const e=this._geometry();this._model&&this._modelGeometry!==e&&(this._model.destroy(),this._model=null),this._model?this._model.setAtlas(t):(this._model=qu(e,t),this._modelGeometry=e,this.addChildAt(this._model.mesh,1))}_setLoadout(t){Ki(t)!==Ki(this._loadout)&&(this._loadout=t,this._model&&this._showModel(this._modelAtlasShown))}_stepReload(){const t=ot.shared.deltaMS/1e3;if(this._condition===0){this._stopReloadAnim();return}if(!this._reloadAnim)return;this._reloadPrevious=this._reloadElapsed,this._reloadElapsed+=t;const e=Uc({primary:this._loadout.primary,elapsed:this._reloadElapsed,previous:this._reloadPrevious,duration:this._reloadDuration,endedAt:this._reloadEndedAt,config:Cs});for(const s of e.events)s==="box"?this._spawnBox():(s==="kick"||s==="kickForward")&&(this._reloadRock.elapsed=0,this._reloadRock.sign=s==="kick"?1:-1);e.done?this._stopReloadAnim():this._reloadState=e}_stepChar(){if(this._burning&&this._condition!==0){const{rate:t,max:e}=Re.char;this._char=Math.min(e,this._char+t*ot.shared.deltaMS/1e3)}this._model?.setChar(this._char,Re.char.color)}_stepReloadRock(){const t=this._reloadRock,{amount:e,decay:s}=Cs.rock;t.elapsed!==1/0&&(t.elapsed+=ot.shared.deltaMS);const i=t.elapsed<s&&this._condition!==0?1-t.elapsed/s:0,o=e*t.sign*i*i;i===0&&(t.elapsed=1/0),this._reloadTilt.pitch=o*Math.cos(this._gunRotation),this._reloadTilt.roll=o*Math.sin(this._gunRotation)}_turretPoint(t,e){const s=$t,i=this.rotation+this._gunRotation,o=Math.cos(i),r=Math.sin(i),a=W.turret.axisU*s;return{x:this._worldX+Math.cos(this.rotation)*a+(o*t-r*e)*s,y:this._worldY+Math.sin(this.rotation)*a+(r*t+o*e)*s,turn:i}}_stopReloadAnim(){this._reloadAnim=!1,this._reloadEndedAt=null,this._reloadState=null}_spawnBox(){if(!this.parent)return;const t=$t,e=Cs.box,{magazine:s}=W.guns.machinegun,{travel:i,drop:o}=Cs.machinegun.magazine,{x:r,y:a,turn:l}=this._turretPoint((s.u[0]+s.u[1])/2,(s.v[0]+s.v[1])/2-i),h=e.size[1]*2*t;this._debris.spawn({stage:this.parent,x:r,y:a,baseZ:this._groundZ(),height:((s.w[0]+s.w[1])/2-o)*t,dx:Math.sin(l)*h,dy:-Math.cos(l)*h,rise:0,angle:l,size:[e.size[0]*t,e.size[1]*t],color:e.color,life:e.life,zIndex:it(_d,this._level)})}_applyModel(t){const e=this._geometry(),s=this._wreck,i=this._reloadState,o=(i?.gunPull??0)*$t,r=this._loadout.primary==="machinegun",a=r?{x:0,y:0}:this._recoilOffsets.gun,l=_=>-io(this._barrelElapsed[_],de.duration,de.attack)*de.machinegunKick*$t,h=Gc(i),c=Du({model:e,unitScale:$t,gunRotation:s?0:this._gunRotation,turretPose:s?.turretPose,pitch:this._pitch+this._recoilTilt.pitch+this._blastTilt.pitch+this._reloadTilt.pitch,roll:this._roll+this._recoilTilt.roll+this._blastTilt.roll+this._reloadTilt.roll,gunKick:{x:a.x-Math.cos(this._gunRotation)*o,y:a.y-Math.sin(this._gunRotation)*o},gunLeftKick:r?l(0):0,gunRightKick:r?l(1):0,lidAngle:s?s.lidAngle:0,cupolaLidAngle:s?s.lidAngle:0,magazineOffset:i?.magazineOffset,shift:{x:this._recoilOffsets.body.x+this._blastShake.x,y:this._recoilOffsets.body.y+this._blastShake.y},squash:this._squash}),u=un({x:this._worldX,y:this._worldY,camera:t,heading:this.rotation}),d=Wu({points:c.points,lean:u,zScale:1+this._viewZ()*Q.shear});this._modelPose=c,this._modelHidden=h,this._projected=d,this._silhouettePolygons=Ru({model:e,projected:d});const f=Vu({model:e,points:c.points,projected:d,hidden:h}),p=c.normals.map(_=>Nu(_,this.rotation,gd));this._model.update(d,p,f),this._drawOutline(),this._updateIgniter(e,d)}_drawOutline(){const t=this._outline;t.clear();for(const e of this._silhouettePolygons)t.poly(e.flat()).fill(po).stroke({width:2*Zt.outline.width,color:po,join:"round"})}_updateIgniter(t,e){if(this._condition===0||this._loadout.secondary!=="flame"){this._igniter.graphics.visible=!1;return}this._igniter.update({model:t,projected:e,unitScale:$t,time:ot.shared.lastTime})}_modelShadowActive(){return this._modelPose!==void 0&&this.parent!==null}_updateModelShadow(t){if(!this._modelShadow){const h=new ft;this._modelShadowAlpha=new Oi({alpha:1}),h.filters=[new sn({strength:Zt.shadowBlur,quality:2}),this._modelShadowAlpha],this.parent.addChild(h),this._modelShadow=h}const e=this._modelShadow,s=this._groundZ(),i=Lt(this._worldX,this._worldY,t,s*Q.shear),o=Math.max(0,this._viewZ()-s);e.visible=!0,e.position.set(i.x,i.y),e.rotation=this.rotation,e.scale.set(1+s*Q.shear),e.zIndex=it(vi-1,Math.min(vd,Math.floor(s)));const r=Cu({model:this._geometry(),points:this._modelPose.points,lift:o*Zt.levelHeight,hidden:this._modelHidden,drift:ta(on.lightDir,gs.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,xi.baseAlpha-o*xi.alphaFalloff):xi.groundAlpha;this._modelShadowAlpha.alpha=l*this._levelAlpha}_updateShadow(t){this._modelShadowActive()?this._updateModelShadow(t):this._modelShadow&&(this._modelShadow.visible=!1)}_playReloadSound(){const t=this._isLocal();this._stopReloadSound();const e=()=>{this._reloadSoundTimer=null,this._reloadSoundId=this._soundManager.registerSound("reload",{position:{x:this._worldX,y:this._worldY},spatial:!t})};t?e():this._reloadSoundTimer=setTimeout(e,Qa)}_stopReloadSound(){this._reloadSoundTimer!==null&&(clearTimeout(this._reloadSoundTimer),this._reloadSoundTimer=null),this._reloadSoundId&&(this._soundManager.unregisterSound(this._reloadSoundId),this._reloadSoundId=null)}_updateBurnSound(){const t=this._isLocal()&&this._condition>0&&this._burning;t&&!this._burnSoundId?this._burnSoundId=this._soundManager.registerSound("tankBurning",{position:{x:this._worldX,y:this._worldY},spatial:!1}):t||this._stopBurnSound()}_stopBurnSound(){this._burnSoundId&&(this._soundManager.unregisterSound(this._burnSoundId),this._burnSoundId=null)}_stopHitSound(){this._hitSoundId&&(this._soundManager.unregisterSound(this._hitSoundId),this._hitSoundId=null)}_stopSwitchSound(){this._switchSoundId&&(this._soundManager.unregisterSound(this._switchSoundId),this._switchSoundId=null)}destroySounds(){this._stopReloadSound(),this._stopSwitchSound(),this._stopBurnSound(),this._stopHitSound(),this._soundId&&(this._soundManager.unregisterSound(this._soundId),this._soundId=null),this._removeWaterSound()}destroy(t){this.destroySounds(),this._partId!==void 0&&this._muzzles?.delete(this._partId),this._removeLights(),this._lighting?.setCaster(this,null),this._glint=null,this._throwAim&&(this._throwAim.destroy(),this._throwAim=null),this._radioBadge?.destroy(),this._radioBadge=null,this._debris.destroy(),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),this._igniter.destroy(),this.filters=null,this._levelAlphaFilter.destroy(),super.destroy({children:!0,texture:!1,textureSource:!1,...t})}}const Pd=2;class Id extends rt{constructor(t,e,s){super(),this._level=t[jh]||0,this.zIndex=it(Pd,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 nt(e.bombTexture),this.body.anchor.set(.5),this._worldX=t[Kn],this._worldY=t[$n],this.x=this._worldX,this.y=this._worldY,this.rotation=t[Zn],this._size=t[$h],this._totalDurationMs=t[Zh],this._soundManager=s.soundManager,this._soundId=null;const i=e.bombTexture.width,o=this._size/i;this.body.scale.set(o);const r=64,a=this._size/1.2/r;this.text=new en({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),ot.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[Kn],this._worldY=t[$n],this.x=this._worldX,this.y=this._worldY,this.rotation=t[Zn],this._soundId&&(this._soundManager.updateSoundData(this._soundId,{position:{x:this._worldX,y:this._worldY}})||(this._soundId=null))}_applyHeight(){const t=this._level*Q.shear,e=At(this.parent,this._renderer),s=Lt(this._worldX,this._worldY,e,t);this.position.set(s.x,s.y),this.scale.set(1+t)}_stopTimer(){this._tickListener&&(ot.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}}const Ed=ai+.75,Cd=Ts.m1.barrelHeight,yo=Object.values(Se).find(n=>n.type==="missile")?.missile?.lifetime??0,Rd=100;class Fd extends rt{constructor(t,e,s={},i){super(),this._id=i?.id,this._texture=e.missileTexture,this._smokeTexture=e.smokeTexture||null,this._renderer=s.renderer??null,this._levelView=s.levelView??null,this._localPlayer=s.localPlayer??null,this._soundManager=s.soundManager??null,this._soundId=null,this._beepedSecond=null,this._lighting=s.lighting?.enabled?s.lighting:null,this._light=null,this._particles=[],this._emitAcc=0,this._focused=!1,this.sortableChildren=!1,this.body=new nt(this._texture),this.body.anchor.set(.5),this.body.width=Ot.length,this.body.height=Ot.width,this.timer=new en({text:"",style:{fontFamily:"Arial",fontSize:Ot.timerFontSize*8,fill:Ot.timerColor,align:"center"}}),this.timer.anchor.set(.5),this.timer.scale.set(1/8),this.timer.y=-12,this.timer.visible=!1,this.addChild(this.body,this.timer),this._applyRow(t),this.onRender=()=>this._place(),this._tickListener=o=>this._tick(o.deltaMS),ot.shared.add(this._tickListener)}update(t){this._applyRow(t)}_applyRow(t){this._worldX=t[Bh],this._worldY=t[Wh],this._angle=t[Vh],this._ownerId=t[Nh],this._controlled=t[Uh]===1;const e=(t[Gh]??0)/10;(this._ageMs===void 0||e>this._timeLeft)&&(this._ageMs=Math.max(0,yo-e)*1e3),this._timeLeft=e,this._level=t[Kh]||0,this.zIndex=it(Ed,this._level),this.body.rotation=this._angle}_isCameraOn(){if(!this._controlled)return!1;if(this._localPlayer?.is(this._ownerId)===!0)return!0;const t=At(this.parent,this._renderer);return t!==null&&Math.hypot(t.x-this._worldX,t.y-this._worldY)<Ot.timerShowDistance}_tick(t){const e=Math.min(t,Rd);this._ageMs+=e,this._emit(e),this._age(e),this._updateFocus(),this._updateTimer(),this._updateLight(),this._updateSound(),this._updateBeep()}_updateBeep(){const t=Ot.beep;if(!this._soundManager||!this._controlled||this._localPlayer?.is(this._ownerId)!==!0||this._timeLeft>t.fromSeconds||this._timeLeft<=0)return;const e=Math.ceil(this._timeLeft/t.everySeconds);e!==this._beepedSecond&&(this._beepedSecond=e,this._soundManager.registerSound(t.sound,{position:{x:this._worldX,y:this._worldY},spatial:!1}))}_updateSound(){if(!this._soundManager)return;const t={position:{x:this._worldX,y:this._worldY},spatial:this._localPlayer?.is(this._ownerId)!==!0};this._soundId===null?(this._timeLeft>=yo-Ot.launchFreshSeconds&&this._soundManager.registerSound(Ot.launchSound,t),this._soundId=this._soundManager.registerSound(Ot.sound,t)):this._soundManager.updateSoundData(this._soundId,t)}_updateFocus(){if(!this._levelView)return;this._isCameraOn()?(this._levelView.focus(this._level,this._worldX,this._worldY,this._level,Ot.focusHoldMs),this._focused=!0):this._focused&&(this._levelView.releaseFocus(),this._focused=!1)}_updateTimer(){const t=this._isCameraOn();this.timer.visible=t,t&&(this.timer.text=this._timeLeft.toFixed(1),this.timer.style.fill=this._timeLeft<Ot.timerWarnSeconds?Ot.timerWarnColor:Ot.timerColor,this.timer.rotation=0)}_emit(t){const e=Ot.trail;if(!(!this._smokeTexture||this._particles.length>=e.maxParticles))for(this._emitAcc+=e.rate*t/1e3;this._emitAcc>=1&&this._particles.length<e.maxParticles;){this._emitAcc-=1;const s=new nt(this._smokeTexture);s.anchor.set(.5),s.tint=e.tint,s.width=e.size,s.height=e.size,this.addChildAt(s,0);const i=e.life.min+Math.random()*(e.life.max-e.life.min);this._particles.push({sprite:s,x:this._worldX-Math.cos(this._angle)*(Ot.length/2),y:this._worldY-Math.sin(this._angle)*(Ot.length/2),age:0,life:i})}}_age(t){const e=Ot.trail;for(let s=this._particles.length-1;s>=0;s-=1){const i=this._particles[s];i.age+=t,i.age>=i.life?(i.sprite.destroy(),this._particles.splice(s,1)):i.sprite.alpha=e.alpha*(1-i.age/i.life)}}_place(){const t=sa({x:this._worldX,y:this._worldY,camera:At(this.parent,this._renderer),level:this._level,height:Cd,weight:Math.min(1,this._ageMs/(Ot.liftBlend*1e3))});this.position.set(t.x,t.y),this.scale.set(1+t.k),this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._worldX,this._worldY),this.tint=this._levelView.tintFor(this._level));for(const e of this._particles)e.sprite.position.set(e.x-this._worldX,e.y-this._worldY)}_updateLight(){if(!this._lighting)return;const t=Ot.light;this._light||(this._light=this._lighting.addLight({kind:"radial",radius:t.radius,color:t.color,intensity:0})),this._lighting.updateLight(this._light,{x:this._worldX,y:this._worldY,z:this._level,level:this._level,levels:[this._level],intensity:t.intensity})}_removeLight(){this._light&&(this._lighting.removeLight(this._light),this._light=null)}destroy(t){this._tickListener&&(ot.shared.remove(this._tickListener),this._tickListener=null),this._removeLight(),this._soundId!==null&&(this._soundManager.unregisterSound(this._soundId),this._soundId=null),this._focused&&this._levelView&&(this._levelView.focus(this._level,this._worldX,this._worldY,this._level,Ot.cameraHang*1e3),this._focused=!1),this._particles=[],super.destroy({children:!0,texture:!1,textureSource:!1,...t}),this.body=null,this.timer=null}}class Od extends Xe{constructor(t,e,s,i,o){super(i);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 nt(r),this._mainBody.anchor.set(.5),this._mainBody.tint=11393254,this._mainBody.scale.set(this._baseScale),this._core=new nt(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=i=>i*i;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 Mi=[],ne={get(n){if(Mi.length>0){const t=Mi.pop();return t.texture=n,t.alpha=1,t.scaleX=1,t.scaleY=1,t.rotation=0,t.tint=16777215,t.anchorX=.5,t.anchorY=.5,t}return new Fa({texture:n,anchorX:.5,anchorY:.5})},release(n){n&&Mi.push(n)}},$i=50,Xd=400,Dd=800;class Yd extends Xe{constructor(t,e=$i){super();const s=e/$i;this._blastScale=s;const{texture:i,contentSize:o}=t.explosionTexture;this.explosionTexture=i,this._unitScale=1/o;const r=Xd*s,a=Dd*s;this._particleContainer=new ri({texture:this.explosionTexture,boundsArea:new Vt(-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=ne.get(this.explosionTexture),e=.2+Math.random()*.4,s=Math.floor(e*255);t.tint=s<<16|s<<8|s;const i=(this._minStartSize+Math.random()*(this._maxStartSize-this._minStartSize))*this._unitScale,o=.6+Math.random()*.8,r=.6+Math.random()*.8;t.scaleX=i*o,t.scaleY=i*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:i};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],i=s.view;if(s.life+=t,s.life>=s.maxLife)this._particleContainer.removeParticle(i),ne.release(i),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;i.x+=(s.vx+r)*(t/16),i.y+=s.vy*(t/16),i.rotation+=s.rotationSpeed*(t/16);const a=1-Math.pow(1-o,3),l=s.startScale+(s.targetScale-s.startScale)*a;if(i.scaleX=l*s.aspectRatioX,i.scaleY=l*s.aspectRatioY,o<.1)i.alpha=o/.1*this._startAlpha;else if(o>.4){const h=(o-.4)/.6;i.alpha=this._startAlpha*(1-h)}else i.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)ne.release(this._particles[e].view);this._particles=[],super.destroy(t)}}const Hd=.168,Bd=.225,wo=.15,Wd=2e4,Vd=50,Nd=4e3,Ud=4e3;class Gd extends Xe{constructor(t,e,s,i,o){super(i),this._assets=o,this._radius=s,this.x=t,this.y=e,this._funnelDurationMs=Wd,this._funnelFadeInDurationMs=Vd,this._funnelFadeDurationMs=Nd,this._elapsedMs=0,this._smokeDurationMs=Ud,this._smokeSpawningStopped=!1,this._funnel=this._createFunnelSprite(),this._smoke=new Yd(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)],i=new nt(s);i.anchor.set(.5),i.alpha=0,i.rotation=Math.random()*Math.PI*2;const o=this._radius*Hd*V(1-wo,1+wo);return i.scale.set(o/e),i}_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,i=e/this._funnelFadeDurationMs;this._funnel.alpha=Bd*oe(Math.min(s,i),0,1),e<=0&&this._completeEffect()}destroy(t){this._smoke&&(this._smoke.destroy(),this._smoke=null),this._funnel=null,super.destroy(t)}}const Os=["soot","hole"],Kd=(n,t)=>n.axis===t.axis&&n.coord===t.coord&&n.nx===t.nx&&n.ny===t.ny;function $d(n,t=We.fade){const e=1-n.age/n.life;return e<=0?0:t>0?Math.min(1,e/t):1}function hi(n,t=Math.random){const e=n?.textures;if(!e?.length||!(n.contentSize>0))return null;const s=Math.min(e.length-1,Math.floor(t()*e.length));return{texture:e[s],contentSize:n.contentSize}}function Zd(n=We){const t=Object.fromEntries(Os.map(i=>[i,[]]));let e=null;const s=()=>{for(const i of Os)t[i]=[]};return{add(i){const o=n[i.kind],r=t[i.kind];if(!o||!r)return null;if(i.kind==="soot"){const l=r.find(h=>h.level===i.level&&Kd(h.face,i.face)&&Math.hypot(h.x-i.x,h.y-i.y)<=o.merge);if(l)return l.strength=Math.min(o.maxStrength,l.strength+(i.strength??o.step)),l.age=0,l}const a={...i,strength:i.kind==="soot"?Math.min(o.maxStrength,i.strength??o.step):1,age:0,life:o.life};return r.push(a),r.length>o.limit&&r.splice(0,r.length-o.limit),a},marks(){return Os.flatMap(i=>t[i])},step(i){for(const o of Os){const r=t[o];for(const a of r)a.age+=i;t[o]=r.filter(a=>a.age<a.life)}},clear:s,syncGeneration(i,o){if(e&&e.reset===i&&e.map===o)return!1;const r=e!==null;return e={reset:i,map:o},r&&s(),r}}}function ia(n,t,e,s,i,o){const{cellW:r,cellH:a}=n?.cellSize?.()??{};if(!(r>0&&a>0&&i>0&&o>0))return[];const l=(c,u)=>n.heightAt(t,(c+.5)*r,(u+.5)*a)>0,h=new Map;for(let c=Math.floor((e-i)/r);c*r<=e+i;c+=1)for(let u=Math.floor((s-i)/a);u*a<=s+i;u+=1){if(!l(c,u))continue;const d=c*r,f=u*a,p=[{axis:"x",coord:d,nx:-1,ny:0,next:[c-1,u]},{axis:"x",coord:d+r,nx:1,ny:0,next:[c+1,u]},{axis:"y",coord:f,nx:0,ny:-1,next:[c,u-1]},{axis:"y",coord:f+a,nx:0,ny:1,next:[c,u+1]}];for(const{next:_,...m}of p){if(l(..._))continue;const g=m.axis==="x"?m.coord:Math.min(d+r,Math.max(d,e)),w=m.axis==="y"?m.coord:Math.min(f+a,Math.max(f,s)),M=m.nx*(e-g)+m.ny*(s-w)>-1,S=Math.hypot(e-g,s-w);if(!M||S>i)continue;const b=`${m.axis}:${m.coord}:${m.nx}:${m.ny}`;(!h.has(b)||h.get(b).distance>S)&&h.set(b,{face:m,x:g,y:w,distance:S})}}return[...h.values()].sort((c,u)=>c.distance-u.distance).slice(0,o)}const jd=4,qd=2;class Qd extends rt{constructor(t,e,s){super(),this.originX=t[qh],this.originY=t[Qh],this.radius=t[Jh]??$i,this._level=t[tc]||0,this._assets=e,this._soundManager=s.soundManager,this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._lighting=s.lighting||null,this._volumes=s.volumes||null,this._wallMarks=s.wallMarks||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*Q.shear,e=At(this.parent,this._renderer),s=Lt(this.originX,this.originY,e,t);for(const i of[this.explosion,this.funnel])i&&(i.position.set(s.x,s.y),i.scale.set(1+t))}run(){if(!(this._isDestroyed||this._isStarted)){if(this._isStarted=!0,!this.parent){this.destroy();return}this._markWalls(),this._lighting?.flash({...ie.flash.explosion,level:this._level,x:this.originX,y:this.originY,z:this._level}),this.explosion=new Od(this.originX,this.originY,this.radius,this._onExplosionComplete.bind(this),this._assets),this.explosion.zIndex=it(jd,this._level),this.funnel=new Gd(this.originX,this.originY,this.radius,this._onFunnelComplete.bind(this),this._assets),this.funnel.zIndex=it(qd,this._level),this.parent.addChild(this.explosion,this.funnel),this.parent.sortChildren(),this.explosion.run(),this.funnel.run()}}_markWalls(){if(!this._wallMarks||!this._volumes)return;const{blast:t}=We,e=t.reach*this.radius,s=ia(this._volumes,this._level,this.originX,this.originY,e,t.maxFaces);for(const{face:i,x:o,y:r,distance:a}of s){const l=hi(this._assets?.wallSootTexture);if(!l)return;this._wallMarks.add({kind:"soot",x:o,y:r,level:this._level,face:i,height:Be.height,size:t.size*(1-a/e),angle:0,strength:t.strength,...l},{parent:this.parent,renderer:this._renderer})}}_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 vo=4,Ge=400,Jd=0,tf=0,Si=8,Yt={particleLifetime:{min:800,max:1800},particleStartSizeFactor:{1:2,2:1},particleEndSizeFactor:{1:3,2:2},particleStartAlpha:.08,particleEndAlpha:0,particleColor:{1:1710618,2:6052956},referenceLength:12,particleSpawnRate:{1:60,2:50},particleInitialVelocity:{away:{min:-10,max:100},side:{min:-30,max:30}},airResistance:.92,particleVelocityVariance:10,burstParticleCount:3,exhaust:{minLoad:.05,idle:{rate:2.5,color:[9672345,11645878],alpha:.1,size:[1.7,5],speed:[10,25],life:[700,1100]},run:{rate:16,color:[8224643,10724777],alpha:.22,size:[2,7],speed:[20,45],life:[800,1400]},burst:{jump:.3,follow:.5,time:.6,rate:40,color:[6645868,9869468],alpha:.45,size:[2.5,10],speed:[55,100],life:[900,1600]}}},Mo=2.85*$t,So=W.fittings.exhausts.v*$t,bo=nn[1]*$t;class ef extends rt{constructor(t,e,s={}){super(),this._level=t[jt]||0,this.zIndex=it(vo,this._level);const{texture:i,contentSize:o}=e.smokeTexture;this._smokeTexture=i,this._textureScale=Si/o,this._emitterX=t[re],this._emitterY=t[ae],this._emitterRotation=t[Me],this._emitterVX=t[es],this._emitterVY=t[ss],this._engineLoad=t[Fe],this._condition=t[Kt],this._z=t[Oe]||0,this._width=pe.length,this._height=pe.width,this._exhaustPipe=0,this._louver=0,this._particleScaleMultiplier=Math.max(.5,Math.sqrt(this._width*this._height*.001)),this._damageScale=this._width/Yt.referenceLength,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)),te(this,At(this.parent,this._renderer),this._z*Q.shear,1)}),this._particleContainer=new ri({texture:this._smokeTexture,boundsArea:new Vt(this._emitterX-Ge,this._emitterY-Ge,Ge*2,Ge*2),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.addChild(this._particleContainer),this._timeSinceLastSpawn=0,this._timeSinceExhaust=0,this._gasFollow=Math.min(this._engineLoad||0,1),this._burstLeft=0,this._tickListener=r=>this._updateParticles(r.deltaMS),ot.shared.add(this._tickListener)}update(t){const e=this._condition,s=t[jt]||0;s!==this._level&&(this._level=s,this.zIndex=it(vo,s)),this._emitterX=t[re],this._emitterY=t[ae],this._emitterRotation=t[Me],this._emitterVX=t[es],this._emitterVY=t[ss],this._engineLoad=t[Fe],this._condition=t[Kt],this._z=t[Oe]||0,this._particleContainer.boundsArea.x=this._emitterX-Ge,this._particleContainer.boundsArea.y=this._emitterY-Ge,this._condition!==e&&(this._condition===1||this._condition===2)&&this._triggerSmokeBurst()}_triggerSmokeBurst(){let t=0;if(this._condition===1?t=2:this._condition===2&&(t=1),t>0){const e=Yt.burstParticleCount,s=Math.ceil(e/t);for(let i=0;i<s;i+=1)for(let o=0;o<t;o+=1)this.spawnParticle(o,t,"burst")}}_updateParticles(t){if(t<=0)return;const e=t/1e3;this._timeSinceLastSpawn+=t,this._timeSinceExhaust+=t;let s=0;this._condition===3?s=0:this._condition===1?s=2:this._condition===2&&(s=1);const i=Yt.particleSpawnRate[this._condition]||0,o=i>0?1e3/i:1/0;if(s>0&&i>0)for(;this._timeSinceLastSpawn>=o;){for(let l=0;l<s;l+=1)this.spawnParticle(l,s);this._timeSinceLastSpawn-=o}else this._timeSinceLastSpawn=0;this._stepExhaust(t);const a=1-Math.pow(Yt.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),ne.release(h.view),this._particles.splice(l,1);continue}h.vx=h.vx+(Jd-h.vx)*a,h.vy=h.vy+(tf-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),d=Pt(h.startSizeFactor,h.endSizeFactor,u),f=Pt(h.startAlpha,h.endAlpha,c),p=h.absolute?d*this._textureScale/Si:d*this._particleScaleMultiplier*this._textureScale;h.colors&&(h.view.tint=we(h.colors[0],h.colors[1],c));const _=h.view;_.x=h.x,_.y=h.y,_.scaleX=p,_.scaleY=p,_.alpha=f,_.rotation+=h.rotSpeed*e}}_stepExhaust(t){const e=Yt.exhaust,s=t/1e3,i=Math.min(this._engineLoad||0,1),o=this._condition>0;this._gasFollow+=(i-this._gasFollow)*Math.min(1,s/e.burst.follow),this._burstLeft=Math.max(0,this._burstLeft-s),o&&i-this._gasFollow>=e.burst.jump&&(this._burstLeft=e.burst.time);const r=this._exhaustMode(i),a=o&&i>=e.minLoad?r.rate:0;if(a<=0){this._timeSinceExhaust=0;return}const l=1e3/a;for(;this._timeSinceExhaust>=l;)this.spawnExhaust(r),this._timeSinceExhaust-=l}_exhaustMode(t){const{idle:e,run:s,burst:i}=Yt.exhaust;if(this._burstLeft>0)return i;const o=(r,a)=>Array.isArray(r)?r.map((l,h)=>o(l,a[h])):Pt(r,a,t);return{rate:o(e.rate,s.rate),color:t<.5?e.color:s.color,alpha:o(e.alpha,s.alpha),size:o(e.size,s.size),speed:o(e.speed,s.speed),life:o(e.life,s.life)}}spawnExhaust(t){this._exhaustPipe=1-this._exhaustPipe;const e=this._emitterRotation,s=-Math.cos(e),i=-Math.sin(e),o=-Math.sin(e),r=Math.cos(e),a=this._exhaustPipe===0?-So:So,l=this._emitterX+s*Mo+o*a,h=this._emitterY+i*Mo+r*a,c=V(t.speed[0],t.speed[1]),u=V(-.25,.25)*c,d=ne.get(this._smokeTexture);d.tint=t.color[0],d.x=l,d.y=h,d.alpha=t.alpha,d.rotation=V(0,Math.PI*2);const f=t.size[0]*this._textureScale/Si;d.scaleX=f,d.scaleY=f,this._particleContainer.addParticle(d),this._particles.push({view:d,x:l,y:h,vx:s*c+o*u+(this._emitterVX||0),vy:i*c+r*u+(this._emitterVY||0),age:0,lifetime:V(t.life[0],t.life[1]),startSizeFactor:t.size[0],endSizeFactor:t.size[1],startAlpha:t.alpha,endAlpha:0,rotSpeed:V(-1,1),absolute:!0,colors:t.color,kind:"exhaust"})}spawnParticle(t,e,s="damage"){const i=s==="burst",o=V(Yt.particleLifetime.min,Yt.particleLifetime.max);let r=(Yt.particleStartSizeFactor[this._condition]||.3)*this._damageScale,a=(Yt.particleEndSizeFactor[this._condition]||1)*this._damageScale,l=Yt.particleStartAlpha,h=1;i&&(r*=2,a*=2.5,l=.8,h=2);const c=this._emitterRotation,u=c+Math.PI,d=Math.cos(u),f=Math.sin(u),p=c+Math.PI/2,_=Math.cos(p),m=Math.sin(p);let g=t;e===1&&(this._louver=1-this._louver,g=this._louver);const w=g===0?-bo:bo,M=5.1,S=this._emitterX+d*M+_*w,b=this._emitterY+f*M+m*w;let y=V(Yt.particleInitialVelocity.away.min,Yt.particleInitialVelocity.away.max),v=V(Yt.particleInitialVelocity.side.min,Yt.particleInitialVelocity.side.max);y*=h,v*=h;let z=d*y+_*v,L=f*y+m*v;const T=Yt.particleVelocityVariance;z+=V(-T,T),L+=V(-T,T),z+=this._emitterVX,L+=this._emitterVY;const E=ne.get(this._smokeTexture);E.tint=Yt.particleColor[this._condition]??Yt.particleColor[2],E.x=S,E.y=b,E.alpha=l;const G=r*this._particleScaleMultiplier*this._textureScale;E.scaleX=G,E.scaleY=G,E.rotation=V(0,Math.PI*2);const H={view:E,x:S,y:b,vx:z,vy:L,age:0,lifetime:o,startSizeFactor:r,endSizeFactor:a,startAlpha:l,endAlpha:Yt.particleEndAlpha,rotSpeed:V(-1,1)};this._particleContainer.addParticle(E),this._particles.push(H)}_stopTimer(){this._tickListener&&(ot.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer();for(let e=0;e<this._particles.length;e+=1)ne.release(this._particles[e].view);this._particles=[],super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}const Zi=3,ko=ai+.75,sf=Ts.m1.turretTop,na=sf/Zt.levelHeight,nf=.5,of=Object.values(Se).find(n=>n.type==="molotov")?.molotov?.spin??0,si=ta(on.lightDir,gs.lightZ,0);function rf(n){return n>=1?0:Math.min(Je.maxLift,na*(1-n)+Je.lift*Math.sin(Math.PI*n))}class af extends rt{constructor(t,e,s={}){super(),this._level=t[oc]||0,this.zIndex=it(ko,this._level),this._startX=t[rc],this._startY=t[ac],this._endX=t[ec],this._endY=t[sc],this._flightMs=Math.max(1,t[nc]),this._elapsedMs=0,this._worldX=this._startX,this._worldY=this._startY,this._z=na,this._heading=Math.atan2(this._endY-this._startY,this._endX-this._startX),this._tickListener=null,this._shadow=null,this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._texture=e.bottleTexture,this.body=new nt(this._texture),this.body.anchor.set(.5),this._baseScale=t[ic]/this._texture.width,this.body.scale.set(this._baseScale),this.addChild(this.body),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._place(),this._tickListener=i=>this._update(i.deltaMS),ot.shared.add(this._tickListener)}_place(){const t=Math.min(1,this._elapsedMs/this._flightMs);this._worldX=this._startX+(this._endX-this._startX)*t,this._worldY=this._startY+(this._endY-this._startY)*t,this._p=t,this._z=rf(t),this.zIndex=it(t<1?ko:Zi,this._level),this.body.rotation=this._heading+Math.min(this._elapsedMs,this._flightMs)/1e3*of}_update(t){this._elapsedMs+=Math.min(t,Je.maxTickMs),this._place(),this._p>=1&&this._stopTicker()}_applyHeight(){const t=At(this.parent,this._renderer),e=sa({x:this._worldX,y:this._worldY,camera:t,level:this._level,height:this._z*Zt.levelHeight,weight:Math.min(1,this._p/nf)});this.position.set(e.x,e.y),this.scale.set(1+e.k),this._applyShadow(t)}_applyShadow(t){if(!this.parent)return;this._shadow||(this._shadow=new nt(this._texture),this._shadow.anchor.set(.5),this._shadow.tint=0,this._shadow.zIndex=it(Zi-.5,this._level),this.parent.addChild(this._shadow));const{shadow:e}=Je,s=this._level*Q.shear,i=this._z*Zt.levelHeight,o=Lt(this._worldX+si.x*i,this._worldY+si.y*i,t,s);this._shadow.position.set(o.x,o.y),this._shadow.rotation=this.body.rotation,this._shadow.scale.set(this._baseScale*e.size*(1+s)),this._shadow.alpha=Math.max(0,e.alpha-this._z*e.falloff)*this.alpha}update(){}_stopTicker(){this._tickListener&&(ot.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTicker(),this._shadow&&(this._shadow.destroy(),this._shadow=null),super.destroy({children:!0,texture:!1,textureSource:!1,...t}),this.body=null}}const oa=Object.values(Se).find(n=>n.type==="molotov")?.size??6,Ao=oa*.4;class lf extends rt{constructor(t,e,s={}){super(),this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._texture=e.bottleTexture,this._baseScale=oa/this._texture.width,this.shadow=new nt(this._texture),this.shadow.anchor.set(.5),this.shadow.tint=0,this.shadow.alpha=Je.shadow.alpha,this.shadow.scale.set(this._baseScale*Je.shadow.size),this.shadow.position.set(si.x*Ao,si.y*Ao),this.body=new nt(this._texture),this.body.anchor.set(.5),this.body.scale.set(this._baseScale),this.addChild(this.shadow,this.body),this._applyRow(t),this.onRender=()=>this._place()}_applyRow(t){this._worldX=t[lc],this._worldY=t[hc],this._level=t[cc]||0,this.zIndex=it(Zi,this._level),this.body.rotation=t[jn],this.shadow.rotation=t[jn]}update(t){this._applyRow(t)}_place(){const t=this._level*Q.shear,e=At(this.parent,this._renderer),s=Lt(this._worldX,this._worldY,e,t);this.position.set(s.x,s.y),this.scale.set(1+t),this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._worldX,this._worldY),this.tint=this._levelView.tintFor(this._level))}destroy(t){super.destroy({children:!0,texture:!1,textureSource:!1,...t}),this.body=null,this.shadow=null}}class ji{constructor({texture:t,max:e,blendMode:s="normal",padding:i}){this.texture=t,this.max=e,this.items=[],this._padding=i,this.container=new ri({texture:t,boundsArea:new Vt(-i,-i,i*2,i*2),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.container.blendMode=s}get size(){return this.items.length}follow(t,e){this.container.boundsArea.x=t-this._padding,this.container.boundsArea.y=e-this._padding}spawn(t){if(this.items.length>=this.max)return null;const e=ne.get(this.texture);return t.view=e,this.container.addParticle(e),this.items.push(t),t}removeAt(t){const[e]=this.items.splice(t,1);e&&(this.container.removeParticle(e.view),ne.release(e.view))}clear(){this.container.removeParticles();for(let t=0;t<this.items.length;t+=1)ne.release(this.items[t].view);this.items.length=0}}const fn=ai+.5;function _n(n,t){const e=new rt;return e.zIndex=it(fn,t),n.addChild(e),e}const Lo=(n,t)=>Math.round(n/t)*t;function ra(n,t,e,s,i,o,r){const a=Lo(n,i),l=Lo(t,o),h=Math.abs(e)>1e-9&&Math.abs(n-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 qi(n,t,e,s,i,o,r){const{cellW:a,cellH:l}=n.cellSize();if(!(a>0&&l>0))return null;const h=ra(t,e,s,i,a,l,r);if(!h)return null;const c=.01*Math.min(a,l),u=t+s*c,d=e+i*c,f=o(u,d),p=n.heightAt(f,u,d);return p>0?{face:h,volume:p,base:f}:null}function ks(n,t,e,s){return n.nx*(s.x-t)+n.ny*(s.y-e)>0}function aa({x0:n,y0:t,dx:e,dy:s,face:i,camera:o,kBase:r,kLine:a}){const l=i.axis==="x",h=l?n:t,c=l?e:s,u=l?o.x:o.y;return Math.abs(c)<1e-9?null:(i.coord+(i.coord-u)*a+u*r-h*(1+r))/(c*(1+r))}function la(n,t,e,s){const{cellW:i,cellH:o}=n.cellSize();if(!(i>0&&o>0)||!(n.heightAt(t,e,s)>0))return null;const r=Math.floor(e/i),a=Math.floor(s/o);return{x0:r*i,y0:a*o,x1:(r+1)*i,y1:(a+1)*o}}function hf(n,t,e,s,i,o){const r=(e.x0+e.x1)/2,a=(e.y0+e.y1)/2,{cellW:l,cellH:h}=n.cellSize(),c=[{axis:"x",coord:e.x0,nx:-1,ny:0},{axis:"x",coord:e.x1,nx:1,ny:0},{axis:"y",coord:e.y0,nx:0,ny:-1},{axis:"y",coord:e.y1,nx:0,ny:1}];let u=null,d=1/0;for(const f of c){const p=r+f.nx*l,_=a+f.ny*h;if(n.heightAt(t,p,_)>0)continue;const m=f.axis==="x"?f.coord:s,g=f.axis==="y"?f.coord:i,w=Math.hypot(o.x-m,o.y-g);w<d&&(d=w,u={...f,x:m,y:g})}return u}const cf=(n,t,e)=>Math.hypot(Math.max(e.x0-n,0,n-e.x1),Math.max(e.y0-t,0,t-e.y1));function uf(n,t,e,s,i,o,r=9){let a=0,l=0,h=0;const c=[];for(let p=0;p<r;p+=1)for(let _=0;_<r;_+=1){const m=e+(2*(p+.5)/r-1)*i,g=s+(2*(_+.5)/r-1)*i;if(Math.hypot(m-e,g-s)>i)continue;const w=la(n,t,m,g);w?c.push(w):(a+=m,l+=g,h+=1)}if(c.length===0||h===0)return{x:e,y:s,radius:o};const u=a/h,d=l/h,f=Math.min(...c.map(p=>cf(u,d,p)));return{x:u,y:d,radius:Math.min(o,f)}}const df=4.5,fe=(n,t,e)=>n+(t-n)*e;class ff extends rt{constructor(t,e,s={}){super(),this._worldX=t[uc],this._worldY=t[dc],this._radius=t[fc],this._level=t[_c]||0,this._durationMs=t[pc],this._elapsedMs=0,this._emitCarry=0,this._tickListener=null,this._isDestroyed=!1,this._levelView=s.levelView||null,this._renderer=s.renderer||null,s.soundManager?.registerSound(Et.sound,{position:{x:this._worldX,y:this._worldY}}),this._volumes=s.volumes??null,this._lighting=s.lighting?.enabled?s.lighting:null,this._light=null,this._lightPlace=null,this._seed=Math.random()*100,this._wallFlames=[],this._wallLayer=null,this._sootAsset=e.wallSootTexture||null,this._wallMarks=s.wallMarks??null,this._sootFaces=null,this._sootAt=new Map,this.zIndex=it(df,this._level);const{texture:i,contentSize:o}=e.smokeTexture;this._wallTexture=i,this._unitScale=1/o,this._scorch=new nt(i),this._scorch.anchor.set(.5),this._scorch.tint=Et.scorch.color,this._scorch.scale.set(this._radius*2*Et.scorch.size*this._unitScale),this._scorch.alpha=0,this._glow=new nt(i),this._glow.anchor.set(.5),this._glow.tint=Et.glow.color,this._glow.blendMode="add",this._glow.alpha=0,this._flash=new nt(i),this._flash.anchor.set(.5),this._flash.tint=Et.flash.color,this._flash.blendMode="add",this._flash.scale.set(this._radius*2*Et.flash.size*this._unitScale),this._flash.alpha=Et.flash.alpha,this._flames=new ji({texture:i,max:Et.maxParticles,blendMode:"add",padding:this._radius*2}),this.addChild(this._scorch,this._glow,this._flames.container,this._flash),this.onRender=()=>{this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._worldX,this._worldY),this.tint=this._levelView.tintFor(this._level),this._wallLayer&&(this._wallLayer.alpha=this.alpha,this._wallLayer.tint=this.tint)),this._applyHeight()}}_spread(){return 1-(1-Math.min(1,this._elapsedMs/Et.spreadMs))**3}_scorchFade(){const t=Math.min(1,this._elapsedMs/Et.fadeInMs),e=this._durationMs-this._elapsedMs,s=Math.min(1,Math.max(0,e/Et.fadeOutMs));return Math.min(t,s)}_flameFade(){const t=this._durationMs-this._elapsedMs;return Math.min(1,Math.max(0,t/Et.fadeOutMs))}_spawnFlame(t){const e=Math.random()*Math.PI*2,s=t*(.85+Math.random()*.25),i=Math.sqrt(Math.random())*s,{life:o,size:r,rise:a,splash:l}=Et;let h=Math.cos(e)*i,c=Math.sin(e)*i,u=(1-this._spread())*l*(i/this._radius);const d=this._volumes?la(this._volumes,this._level,this._worldX+h,this._worldY+c):null;if(d){const f=this._spawnAtWall(d,h,c);if(!f)return;h=f.x-this._worldX,c=f.y-this._worldY,u=0}this._flames.spawn({x:h,y:c,vx:Math.cos(e)*u,vy:Math.sin(e)*u,age:0,life:fe(o.min,o.max,Math.random()),rise:fe(a.min,a.max,Math.random()),sizeScale:fe(.7,1.4,Math.random()),size:r})}_spawnAtWall(t,e,s){const i=hf(this._volumes,this._level,t,this._worldX+e,this._worldY+s,{x:this._worldX,y:this._worldY});if(!i||Math.random()>Et.wall.share)return null;this._markSoot(i);const o=this._levelView?.camera?.()??At(this.parent,this._renderer);return!o||!ks(i,i.x,i.y,o)?i:(this._spawnWallFlame(i),null)}_markSoot(t){const{soot:e}=We;if(!this._wallMarks||!this._volumes)return;this._sootFaces??=ia(this._volumes,this._level,this._worldX,this._worldY,this._radius,1/0);const s=`${t.axis}:${t.coord}:${t.nx}:${t.ny}`,i=this._sootFaces.find(({face:a})=>`${a.axis}:${a.coord}:${a.nx}:${a.ny}`===s),o=performance.now();if(!i||o-(this._sootAt.get(s)??-1/0)<e.everyMs)return;const r=hi(this._sootAsset);r&&(this._sootAt.set(s,o),this._wallMarks.add({kind:"soot",x:i.x,y:i.y,level:this._level,face:i.face,height:Be.height,size:e.size,angle:0,...r},{parent:this.parent,renderer:this._renderer}))}_spawnWallFlame(t){if(!this._wallLayer){if(!this.parent)return;this._wallLayer=_n(this.parent,this._level)}const{life:e,wall:s}=Et,i=new nt(this._wallTexture);i.anchor.set(.5),i.blendMode="add",this._wallLayer.addChild(i),this._wallFlames.push({sprite:i,x:t.x,y:t.y,height:0,top:s.height*fe(.5,1,Math.random()),age:0,life:fe(e.min,e.max,Math.random()),sizeScale:fe(.7,1.4,Math.random())})}_updateWallFlames(t){if(this._wallFlames.length===0)return;const{size:e,colors:s,alpha:i,wall:o}=Et,r=this._levelView?.camera?.()??At(this.parent,this._renderer),a=[];for(const l of this._wallFlames){if(l.age+=t,l.age>=l.life){l.sprite.destroy();continue}const h=l.age/l.life;l.height=Math.min(l.top,l.height+o.climb*t/1e3);const c=(this._level+l.height)*Q.shear,u=Lt(l.x,l.y,r,c),d=l.sprite;d.position.set(u.x,u.y),d.scale.set(fe(e.start,e.end,h)*l.sizeScale*this._unitScale*(1+c)),d.tint=we(s.start,s.end,h),d.alpha=fe(i.start,i.end,h),a.push(l)}this._wallFlames=a}_stepLight(){if(!this._lighting)return;const t=Et.light,e=this._flameFade()*Math.min(1,this._spread()+.2);if(e<=0){this._removeLight();return}let s=this._lightPlace;if(!s){const i=this._radius*t.radius,o=this._volumes?.cellSize().cellW>0;s=o?uf(this._volumes,this._level,this._worldX,this._worldY,this._radius,i):{x:this._worldX,y:this._worldY,radius:i},o&&(this._lightPlace=s)}this._light??=this._lighting.addLight({kind:"radial",radius:s.radius,color:t.color,intensity:0}),this._lighting.updateLight(this._light,{x:s.x,y:s.y,radius:s.radius,z:this._level,level:this._level,levels:li(this._level,this._level,!1),intensity:t.intensity*e*ze(this._seed,this._elapsedMs,t.flicker)})}_removeLight(){this._light&&(this._lighting.removeLight(this._light),this._light=null)}_updateFlames(t){const{size:e,colors:s,alpha:i}=Et,o=this._flames.items;for(let r=o.length-1;r>=0;r-=1){const a=o[r];if(a.age+=t,a.age>=a.life){this._flames.removeAt(r);continue}const l=a.age/a.life,h=a.view;a.x+=a.vx*(t/1e3),a.y+=a.vy*(t/1e3)-a.rise*(t/1e3),a.vx*=.94,a.vy*=.94,h.x=a.x,h.y=a.y,h.scaleX=fe(e.start,e.end,l)*a.sizeScale*this._unitScale,h.scaleY=h.scaleX,h.tint=we(s.start,s.end,l),h.alpha=fe(i.start,i.end,l)}}_applyHeight(){const t=this._level*Q.shear,e=At(this.parent,this._renderer),s=Lt(this._worldX,this._worldY,e,t);this.position.set(s.x,s.y),this.scale.set(1+t)}run(){this._isDestroyed||this._tickListener||(this._tickListener=t=>this._update(t.deltaMS),ot.shared.add(this._tickListener))}_update(t){if(this._isDestroyed)return;const e=Math.min(t,Et.maxTickMs);this._elapsedMs+=e;const s=this._spread(),i=this._radius*s;if(this._elapsedMs<this._durationMs){const c=fe(Et.spreadBoost,1,s);for(this._emitCarry+=Et.rate*c*Math.PI*i*i*this._flameFade()*(e/1e3);this._emitCarry>=1;)this._emitCarry-=1,this._spawnFlame(i)}this._updateFlames(e),this._updateWallFlames(e),this._stepLight();const o=this._scorchFade(),{scorch:r,glow:a,flash:l}=Et,h=this._radius*2*this._unitScale;this._scorch.scale.set(h*r.size*Math.max(.05,s)),this._scorch.alpha=r.alpha*o,this._glow.scale.set(h*a.size*Math.max(.05,s)),this._glow.alpha=a.alpha*this._flameFade()*Math.min(1,this._elapsedMs/Et.fadeInMs)*(1-a.flicker+a.flicker*Math.sin(this._elapsedMs*a.speed*.001*6.283)),this._flash.alpha=l.alpha*Math.max(0,1-this._elapsedMs/l.ms),this._elapsedMs>=this._durationMs&&this._flames.items.length===0&&this._wallFlames.length===0&&this.destroy()}_stopTicker(){this._tickListener&&(ot.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._isDestroyed||(this._isDestroyed=!0,this._stopTicker(),this._flames.clear(),this._removeLight(),this._wallLayer?.destroy({children:!0}),this._wallLayer=null,this._wallFlames=[],this.parent&&this.parent.removeChild(this),super.destroy({children:!0,texture:!1,...t}))}}class _f extends nt{constructor(t,e,s,i,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=i,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 bi=1;class pf extends rt{constructor(t,e,s={}){super(),this._levelView=s.levelView||null,this._renderer=s.renderer||null,this._surfaces=s.surfaces||null,this._level=t[jt]||0,this._markLayers=new Map,this.zIndex=it(bi,this._level),this._currentX=t[re]||0,this._currentY=t[ae]||0,this._currentRotation=t[Me]||0,this._engineLoad=t[Fe]||0,this._condition=t[Kt],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=Ms.width,this._trackLength=pe.length/8,this._trackOffset=Ms.offset,this._backwardOffset=Ms.back,this._trackInitialAlpha=.4,this._trailKind=null,this._trailLeft=0,this._tickListener=i=>this._internalUpdate(i.deltaMS),ot.shared.add(this._tickListener),this._levelView&&(this.onRender=()=>this._updateLayers())}update(t){this._currentX=t[re],this._currentY=t[ae],this._currentRotation=t[Me],this._engineLoad=t[Fe],this._condition=t[Kt];const e=t[jt]||0;e!==this._level&&(this._level=e,this.zIndex=it(bi,e))}_markLayer(t){let e=this._markLayers.get(t);if(e)return e;e=new rt,e.zIndex=it(bi,t),this._markLayers.set(t,e);const s=this.parent||this;return s.addChild(e),s.sortChildren(),e}_internalUpdate(t){if(t<=0)return;for(const f of this._markLayers.values())for(let p=f.children.length-1;p>=0;p-=1){const _=f.children[p];_.update(t)&&_.destroy()}this._stepTrail(t/1e3);const e=this._currentX-this._prevX,s=this._currentY-this._prevY,i=Math.sqrt(e*e+s*s),o=Mh(this._currentRotation-this._prevRotation),r=Math.abs(o),a=i-this._prevSpeed,l=Math.abs(a),h=r-this._prevAngularSpeed,c=Math.abs(h),u=performance.now();let d=!1;this._condition!==0&&u-this._lastTrackMarkTime>this._trackMarkCooldown&&(l>this._minAbsAccelerationForMark&&(d=!0),i>this._minSpeedForRotationMarks&&(r>this._minAngularSpeedForMark||c>this._minRotationAccelerationForMark)&&(d=!0)),this._engineLoad>1&&(d=!0),d&&(this.createTrackMarksAtPreviousPosition(),this._lastTrackMarkTime=u),this._prevX=this._currentX,this._prevY=this._currentY,this._prevRotation=this._currentRotation,this._prevSpeed=i,this._prevAngularSpeed=r}_stepTrail(t){if(!this._surfaces)return;const e=this._surfaces.kindAt(this._currentX,this._currentY,this._level),s=e&&ye.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&&ye.tracks.noMarks.includes(t))return;let e=t&&ye.tracks[t]||null,s=1;!e&&this._trailLeft>0&&(e=ye.tracks[this._trailKind],s=this._trailLeft/e.trail);const i=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,d=new _f(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&&(d.tint=e.tint),i.addChild(d)}}_updateLayers(){if(!this._markLayers.size)return;const t=At(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&&te(s,t,e*Q.shear)}_stopTimer(){this._tickListener&&(ot.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 To=2,Ke=300,mf=6,Rt={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},gf={color:Rt.color,alpha:Rt.startAlpha,lifetime:Rt.lifetime},xf=["sand","mud","water"],zo=.35,yf=(n,t)=>n.kind==="boost"&&n.dir!==null&&n.dir[0]===t[0]&&n.dir[1]===t[1];class wf extends rt{constructor(t,e,s={}){super(),this._level=t[jt]||0,this.zIndex=it(To,this._level);const{texture:i,contentSize:o}=e.dustTexture;this._dustTexture=i,this._textureScale=mf/o,this._x=t[re],this._y=t[ae],this._rotation=t[Me],this._vx=t[es]||0,this._vy=t[ss]||0,this._engineLoad=t[Fe]||0,this._condition=t[Kt],this._z=t[Oe]||0,this._vz=t[is]||0,this._prevVz=this._vz;const{length:r,width:a}=pe;this._trackOffset=Ms.offset,this._backwardOffset=Ms.back,this._particleScaleMultiplier=Math.max(.5,Math.sqrt(r*a*.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 l=this._soundManager?.getSoundConfig("tankLanding");this._landingVolume=l?.volume||0,this._hasLandingSound=!!l,(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)),te(this,At(this.parent,this._renderer),this._z*Q.shear,1)}),this._particleContainer=new ri({texture:this._dustTexture,boundsArea:new Vt(this._x-Ke,this._y-Ke,Ke*2,Ke*2),dynamicProperties:{position:!0,vertex:!0,rotation:!0,color:!0}}),this.addChild(this._particleContainer),this._tickListener=h=>this._updateParticles(h.deltaMS),ot.shared.add(this._tickListener)}update(t){const e=this._x,s=this._y,i=this._condition>0,o=t[jt]||0;o!==this._level&&(this._level=o,this.zIndex=it(To,o)),this._x=t[re],this._y=t[ae],this._rotation=t[Me],this._vx=t[es]||0,this._vy=t[ss]||0,this._engineLoad=t[Fe]||0,this._condition=t[Kt],this._z=t[Oe]||0,this._vz=t[is]||0,this._particleContainer.boundsArea.x=this._x-Ke,this._particleContainer.boundsArea.y=this._y-Ke;const r=Kr(this._prevVz,this._vz,He);r>0&&(this._triggerLandingBurst(r),this._playLandingSound(r)),this._prevVz=this._vz,this._updateSurface(e,s,i)}_updateSurface(t,e,s){if(!this._surfaces)return;const i=this._surfaces.kindAt(this._x,this._y,this._level),o=i==="boost"?this._surfaces.dirAt(this._x,this._y,this._level):null,r=this._surfaceCell,a=Math.hypot(this._x-t,this._y-e)>ye.boost.resetDistance,l=!s&&this._condition>0;this._surfaceKind=i,this._surfaceCell={kind:i,dir:o},!(r===null||l||a||this._condition<=0||this._vz!==0)&&(i==="water"&&r.kind!=="water"&&this._triggerWaterEntry(),o&&!yf(r,o)&&this._vx*o[0]+this._vy*o[1]>=ye.boost.boostMinSpeed&&this._triggerBoostFlash(o))}_triggerWaterEntry(){const t=ye.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 i=0;i<t.entryBurst;i+=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=ye.boost,s=Math.atan2(-t[1],-t[0]);for(let i=0;i<e.burst;i+=1){const o=s+V(-zo,zo),r=V(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,i=this._rotation+Math.PI,o=V(e.sideSpeed.min,e.sideSpeed.max)*t,r=V(0,e.sideSpeed.min);return[Math.cos(s)*o+Math.cos(i)*r,Math.sin(s)*o+Math.sin(i)*r]}_spawnSurfaceDust(t,e){for(let s=-1;s<=1;s+=2){const i=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=V(Rt.spinVelocity.back.min,Rt.spinVelocity.back.max),c=V(Rt.spinVelocity.side.min,Rt.spinVelocity.side.max);o=Math.cos(a)*h+Math.cos(l)*c,r=Math.sin(a)*h+Math.sin(l)*c}this._spawnParticle(i.x,i.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(Rt.landingBurst*t);if(!(e<=0))for(let s=-1;s<=1;s+=2){const i=this._contactPoint(s);for(let o=0;o<e;o+=1){const r=V(0,Math.PI*2),a=V(Rt.landingVelocity.min,Rt.landingVelocity.max)*t;this._spawnParticle(i.x,i.y,Math.cos(r)*a,Math.sin(r)*a,Rt.landingSizeFactor*t)}}}_spawnSpinDust(){const t=this._rotation+Math.PI,e=this._rotation+Math.PI/2;for(let s=-1;s<=1;s+=2){const i=this._contactPoint(s),o=V(Rt.spinVelocity.back.min,Rt.spinVelocity.back.max),r=V(Rt.spinVelocity.side.min,Rt.spinVelocity.side.max);this._spawnParticle(i.x,i.y,Math.cos(t)*o+Math.cos(e)*r,Math.sin(t)*o+Math.sin(e)*r,1)}}_spawnParticle(t,e,s,i,o,r=gf){const a=Rt.startSizeFactor*o,l=Rt.endSizeFactor*o,h=ne.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=V(0,Math.PI*2),this._particles.push({view:h,x:t,y:e,vx:s,vy:i,age:0,lifetime:V(r.lifetime.min,r.lifetime.max),startAlpha:r.alpha,startSizeFactor:a,endSizeFactor:l,rotSpeed:V(-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),i=Math.hypot(this._vx,this._vy),r=this._condition>0&&s>0&&i<Rt.maxSpinSpeed&&this._surfaceKind!=="oil"?Rt.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,i);const a=Math.pow(Rt.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),ne.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),d=(h.startSizeFactor+(h.endSizeFactor-h.startSizeFactor)*u)*this._particleScaleMultiplier*this._textureScale,f=h.view;f.x=h.x,f.y=h.y,f.scaleX=d,f.scaleY=d,f.alpha=h.startAlpha+(Rt.endAlpha-h.startAlpha)*c,f.rotation+=h.rotSpeed*e}}_emitSurface(t,e){const s=this._surfaceKind,i=xf.includes(s)?ye[s]:null;if(!i||this._condition<=0||this._vz!==0||e<i.minSpeed){this._timeSinceSurfaceSpawn=0;return}const o=1e3/(i.rate*Math.min(e/i.fullSpeed,1));for(this._timeSinceSurfaceSpawn+=t;this._timeSinceSurfaceSpawn>=o;)this._spawnSurfaceDust(s,i),this._timeSinceSurfaceSpawn-=o}_stopTimer(){this._tickListener&&(ot.shared.remove(this._tickListener),this._tickListener=null)}destroy(t){this._stopTimer();for(let e=0;e<this._particles.length;e+=1)ne.release(this._particles[e].view);this._particles=[],super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}function vf({progress:n,totalDist:t,trailLength:e,trailShare:s=0}){const i=t*oe(n,0,1),o=Math.max(e,t*s),r=Pt(o,0,oe(n,0,1));return{tail:Math.max(0,i-r),head:i}}const Mf=2,Sf=.9;class bf extends Xe{constructor(t,e,s,i,o,r=Be,a={}){super(o),this.startPositionX=t,this.startPositionY=e,this.endPositionX=s,this.endPositionY=i,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 ft;h.blendMode="add",(this._layerFor?.(l)||this).addChild(h),this._graphics.set(l,h)}this.elapsedTime=0,this.progress=0,this._shownFrames=0,this._aim(),this.animationDuration=oe(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 i=e?this.startPositionX:this.startPositionY,o=(t.coord-i)/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}=vf({progress:this.progress,totalDist:this.totalDist,trailLength:this.config.trailLength,trailShare:this.config.trailShare}),s=e-t>.001;return s&&this._drawTrail(t,e,Pt(this.config.alphaStart,this.config.alphaEnd,this.progress)),s}_update(t){if(!this.isComplete){if(this.elapsedTime+=t,this.progress=Math.min(this.elapsedTime/this.animationDuration,1),this.progress>=1){if(this._shownFrames>=Mf||this.totalDist===0){this._clear(),this._completeEffect();return}this.progress=Sf}this._draw()&&(this._shownFrames+=1)}}_drawTrail(t,e,s){const{color:i,coreColor:o,coreWidth:r,glowWidth:a,glowAlpha:l}=this.config,h=this.config.taper??1,c=Math.max(1,this.config.fadeSteps),u=[];for(let f=0;f<c;f+=1){const p=Pt(t,e,f/c),_=Pt(t,e,(f+1)/c),m=(f+1)/c;u.push({from:p,to:_,fade:m*m,thin:Pt(h,1,m)})}const d=this._split(u);for(const{graphics:f,from:p,to:_,fade:m,thin:g}of d)f.moveTo(p[0],p[1]).lineTo(_[0],_[1]).stroke({width:a*g,color:i,alpha:s*l*m,cap:"round"});for(const{graphics:f,from:p,to:_,fade:m,thin:g}of d)f.moveTo(p[0],p[1]).lineTo(_[0],_[1]).stroke({width:r*g,color:o,alpha:s*m,cap:"round"})}_split(t){const e=i=>[this.startPositionX+this.nx*i,this.startPositionY+this.ny*i],s=[];for(const{from:i,to:o,fade:r,thin:a}of t)for(const l of this.pieces){const h=Math.max(i,l.from),c=Math.min(o,l.to);c-h>1e-6&&s.push({graphics:this._graphics.get(l.level),from:e(h),to:e(c),fade:r,thin:a})}return s}destroy(t){for(const e of this._graphics.values())e.destroyed||(e.clear(),e.parent!==this&&e.destroy());this._graphics.clear(),super.destroy(t)}}function kf(n,t,e){const s=e||0;if(!(t>0))return[{from:0,to:0,level:s}];const i=(n||[]).filter(u=>u.t1>u.t0&&u.t0<t);if(i.length===0)return[{from:0,to:t,level:s}];const o=u=>Math.min(t,Math.max(0,u)),r=[...new Set([0,t,...i.flatMap(u=>[o(u.t0),o(u.t1)])])].sort((u,d)=>u-d),a=[];for(let u=0;u+1<r.length;u+=1){const d=r[u],f=r[u+1];if(f-d<1e-6)continue;const p=(d+f)/2;let _=null;for(const g of i)g.t0<=p&&p<g.t1&&(_===null||g.t0<_.t0)&&(_=g);const m=_?_.level:a.at(-1)?.level??s;ki(a,d,f,m)}if(a.at(-1).level===s)return a;const l=i.filter(u=>u.level===s&&u.t0<t&&u.t1>=t-.001).sort((u,d)=>d.t0-u.t0)[0],h=l?o(l.t0):a.at(-1).from,c=[];for(const u of a)u.from<h&&ki(c,u.from,Math.min(u.to,h),u.level);return ki(c,h,t,s),c}function ki(n,t,e,s){if(e-t<1e-6)return;const i=n.at(-1);i&&i.level===s&&Math.abs(i.to-t)<1e-6?i.to=e:n.push({from:t,to:e,level:s})}class Af extends Xe{constructor(t,e,s,i,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:V(5,9),particleMinSize:.8,particleMaxSize:2.8,minInitialSpeed:10,maxInitialSpeed:380,minLifetime:8e3,maxLifetime:15e3,color:[3355443,2236962,4473924],fadeOutStart:.8,impactDirectionX:s,impactDirectionY:i,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 i=0,o=this.config.particleCount;i<o;i+=1){let r;this.useOmnidirectionalSpread?r=Math.random()*Math.PI*2:r=t+V(-s,s);const a=V(this.config.minInitialSpeed,this.config.maxInitialSpeed),l=new nt(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:V(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:V(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 i=0,o=this.particlesData.length;i<o;i+=1){const r=this.particlesData[i];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 f=u*this.config.dragCoefficient*e,p=Math.max(0,1-f/u);r.vx*=p,r.vy*=p}r.x+=r.vx*e,r.y+=r.vy*e,r.k=this._kAt(r),Math.hypot(r.vx,r.vy)<this.config.minSpeedThreshold&&(r.isMoving=!1,r.vx=0,r.vy=0)}else r.timeSinceStopped+=t;const l=r.age/r.lifetime;if(!r.isMoving&&r.timeSinceStopped>=this.config.lingerDuration){const u=r.timeSinceStopped-this.config.lingerDuration,d=Math.min(500,r.lifetime*(1-this.config.fadeOutStart));r.alpha=Pt(1,0,Math.min(u/d,1))}else if(l>=this.config.fadeOutStart){const u=r.age-r.lifetime*this.config.fadeOutStart,d=r.lifetime*(1-this.config.fadeOutStart);r.alpha=d>0?Pt(1,0,Math.min(u/d,1)):0}(r.age>=r.lifetime||r.alpha<.01)&&(r.active=!1,r.alpha=0);const h=r.sprite;h.position.set(r.x,r.y),h.alpha=r.alpha,h.visible=r.active;const 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 i=s.k??e,o=this._startK===null?i:i+(this._startK-i)*s.lift,r=xs(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 Lf(n,t=Math.random){const e=[],s=Math.max(1,n.spikes);for(let o=0;o<s;o+=1){const r=s===1?.5:(o+t())/s;e.push({angle:(r*2-1)*n.spread,length:1-t()*n.jitter})}const i=n.sideLength?[1-t()*n.jitter,1-t()*n.jitter]:[];return{forward:e,sides:i}}const Po=12,Tf=Array.from({length:Po},(n,t)=>{const e=t/Po*Math.PI*2;return[Math.cos(e),Math.sin(e)]}),Io=(n,t)=>n.core?t.coreColor:t.color;function zf(n){return Math.max(n.duration||0,n.ring?.duration||0)}function Pf(n,t){const e=t.ring;if(!e||!(e.duration>0)||n>=e.duration)return null;const s=oe(n/e.duration,0,1),i=1-(1-s)*(1-s),o=1-s;return{radius:e.radius*i,width:e.width,alpha:e.alpha*o*o,color:e.color??t.coreColor}}function If({dirX:n,dirY:t,t:e,roll:s,config:i}){const o=1-oe(e,0,1),r=o*o,a=1-i.shrink*(1-o),l=Math.atan2(t,n),h=[],c=(u,d,f)=>{const p=Math.cos(u),_=Math.sin(u),m=f/2;return[-_*m,p*m,p*d,_*d,_*m,-p*m]};for(const u of i.layers){const d=u.scale*a,f=Io(u,i),p=u.alpha*r;if(!(p<=0)){for(const{angle:_,length:m}of s.forward)h.push({points:c(l+_,i.length*m*d,i.width*d),color:f,alpha:p});s.sides.forEach((_,m)=>{h.push({points:c(l+(m===0?Math.PI/2:-Math.PI/2),i.sideLength*_*d,i.sideWidth*d),color:f,alpha:p})})}}if(i.ball?.radius>0)for(const u of i.layers){const d=u.alpha*r;if(d<=0)continue;const f=i.ball.radius*u.scale*a,p=[];for(const[_,m]of Tf)p.push(_*f,m*f);h.push({points:p,color:Io(u,i),alpha:d})}return h}class Eo extends Xe{constructor(t,e,s,i,o,r=mr,a=Math.random){super(o),this.position.set(t,e),this.dirX=s,this.dirY=i,this.config=r,this.roll=Lf(r,a),this.elapsedTime=0,this.graphics=new ft,this.graphics.blendMode="add",this.addChild(this.graphics)}_update(t){if(this.isComplete)return;if(this.elapsedTime+=t,this.graphics.clear(),this.elapsedTime>=zf(this.config)){this._completeEffect();return}const e=this.config.duration?this.elapsedTime/this.config.duration:1;if(e<1){const i=If({dirX:this.dirX,dirY:this.dirY,t:e,roll:this.roll,config:this.config});for(const{points:o,color:r,alpha:a}of i)this.graphics.poly(o).fill({color:r,alpha:a})}const s=Pf(this.elapsedTime,this.config);s&&s.radius>0&&s.alpha>0&&this.graphics.circle(0,0,s.radius).stroke({width:s.width,color:s.color,alpha:s.alpha})}destroy(t){this.graphics&&this.graphics.clear(),super.destroy(t)}}function Ef(n,t,e,s=Math.random){const i=[],o=Math.max(0,Math.round(n.count)),r=Math.atan2(e,t),a=(l,h)=>l.min+(l.max-l.min)*h;for(let l=0;l<o;l+=1){const h=t===0&&e===0?s()*Math.PI*2:r+(s()*2-1)*n.spread,c=a(n.speed,s());i.push({vx:Math.cos(h)*c,vy:Math.sin(h)*c,size:a(n.size,s()),lifetime:a(n.lifetime,s()),color:n.colors[Math.floor(s()*n.colors.length)],rotation:s()*Math.PI*2})}return i}function Cf(n,t,e){if(t>=n.lifetime)return null;const s=oe(t/n.lifetime,0,1),i=t/1e3,o=e.drag>0?(1-Math.exp(-e.drag*i))/e.drag:i,r=1-(1-s)*(1-s),a=1-s;return{x:n.vx*o,y:n.vy*o,size:n.size*(1+(e.grow-1)*r),alpha:e.alpha*a*a}}class Rf extends Xe{constructor(t,e,s,i,o,r,a=gr,l=Math.random){super(o),this.position.set(t,e),this.config=a,this.elapsedTime=0;const{texture:h,contentSize:c}=r.smokeTexture;this._unitScale=1/c,this.puffs=Ef(a,s,i,l),this.sprites=this.puffs.map(u=>{const d=new nt(h);return d.anchor.set(.5),d.tint=u.color,d.rotation=u.rotation,this.addChild(d),d})}_update(t){if(this.isComplete)return;this.elapsedTime+=t;let e=0;this.puffs.forEach((s,i)=>{const o=Cf(s,this.elapsedTime,this.config),r=this.sprites[i];r.visible=o!==null,o&&(e+=1,r.position.set(o.x,o.y),r.scale.set(o.size*this._unitScale),r.alpha=o.alpha)}),e===0&&this._completeEffect()}destroy(t){this.puffs=[],this.sprites=[],super.destroy(t)}}const Ff="shot",Co=new Map;function Of(n){let t=Co.get(n);if(!t){const e=qa[n]||{};t={sound:e.sound||Ff,soundBurst:e.soundBurst||null,tracer:{...Be,...e.tracer},muzzleFlash:{...mr,...e.muzzleFlash}},Co.set(n,t)}return t}const Xs=new Map;function Xf(n,t,e){if(!t)return 1;for(const[o,r]of Xs)e-r.time>t.resetGap&&Xs.delete(o);const s=Xs.get(n),i=s&&e-s.time<=t.resetGap?s.index:0;return Xs.set(n,{time:e,index:i+1}),Math.max(t.min,1-t.step*i)}const Df=["ricochet1","ricochet2","ricochet3","ricochet4"];function Yf({sounds:n=Df,volleyMs:t=100,random:e=Math.random}={}){let s=-1;const i=new Map,o=r=>{for(const[a,l]of i)r-l.at>=t&&i.delete(a)};return{pick(r,a,l){o(l);const h=i.get(r);if(i.set(r,{pellet:a,at:l}),h&&a>h.pellet)return null;let c;return s<0?c=Math.floor(e()*n.length):(c=Math.floor(e()*(n.length-1)),c>=s&&(c+=1)),c=Math.min(c,n.length-1),s=c,n[c]}}}const Hf=Yf(),Ai=2,Ro=fn,Li=.15,Bf=new Set([Ur,Gi,Nr]);class Wf extends rt{constructor(t,e,s){super(),this.startPositionX=t[Th],this.startPositionY=t[zh],this.endPositionX=t[Ph],this.endPositionY=t[Ih],this.soundPositionX=t[Eh],this.soundPositionY=t[Ch],this.hitCode=t[Rh]||0,this.hit=this.hitCode!==0;const i=this.endPositionX-this.startPositionX,o=this.endPositionY-this.startPositionY;this._blocked=!(Math.hypot(i,o)>.001);const[r,a]=this._blocked?[this.endPositionX-this.soundPositionX,this.endPositionY-this.soundPositionY]:[i,o],l=Math.hypot(r,a);this._rayDirX=l>.001?r/l:0,this._rayDirY=l>.001?a/l:0,this.endLevel=t[Oh]||0,this.startLevel=t[Fh]||0,this.zIndex=it(Ai,this.endLevel),this._style=Of(t[Xh]||1);const h=t[Dh]||0;this._flashOnly=(h&Yh)!==0,this._muzzle=(t[Un]||0)===0&&(h&Hh)===0,this.anchorKey=null,this.anchorLocalX=0,this.anchorLocalY=0,Array.isArray(t[Gn])&&([this.anchorKey,this.anchorLocalX,this.anchorLocalY]=t[Gn]),this._assets=e,this._soundManager=s.soundManager,this._isLocalShot=s.localPlayer?.is(t[cs])===!0,this._ricochetSound=!this._flashOnly&&Bf.has(this.hitCode)?Hf.pick(t[cs],t[Un]||0,performance.now()):null,this._muzzle&&s.shots?.fired(t[cs]),this._mapDynamics=s.mapDynamics||null,this._shots=s.shots||null,this._shooterId=t[cs],this._levelView=s.levelView||null,this._lighting=s.lighting||null,this._volumes=s.volumes||null,this._rampRuns=s.rampRuns||null,this._wall=null,this._wallMarks=s.wallMarks||null,this._wallK=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 c=At(this.parent,this._renderer);te(this,c,this.endLevel*Q.shear,1);for(const[u,d]of this.layers)this._levelView&&(d.alpha=this._levelView.alphaFor(u,d.refX,d.refY),d.tint=this._levelView.tintFor(u)),te(d,c,u*Q.shear,1);this._followMuzzle(),this._placeFlash(c),this._placeDebris(c),this._placeImpactZ(c)}),this.tracer=null,this.layers=new Map,this.impact=null,this.flash=null,this._flashComplete=!0,this.hitFlash=null,this.hitSmoke=null,this._burstPending=0,this._visibleEnd=null,this._isDestroyed=!1,this._visualsComplete=!1,this._soundComplete=!1,this._soundId=this._muzzle?this._registerShotSound(t):null,this._soundId||(this._soundComplete=!0)}_registerShotSound(t){const{sound:e,soundBurst:s}=this._style,i=Xf(t[cs],s,performance.now()),o=this._soundManager.getSoundConfig?.(e)?.volume??.5;return this._soundManager.registerSound(e,{position:{x:this.soundPositionX,y:this.soundPositionY},spatial:!this._isLocalShot,...i<1?{volume:o*i}:{}},()=>{this._soundComplete=!0,this._soundId=null,this._tryDestroy()})}run(){if(this._isDestroyed)return;const t=this.endPositionX-this.startPositionX,e=this.endPositionY-this.startPositionY,s=Math.hypot(t,e),i=this.startPositionX-this.soundPositionX,o=this.startPositionY-this.soundPositionY,r=Math.hypot(i,o),[a,l,h]=r>.001?[i,o,r]:[t,e,s];if(this._muzzle&&this._lighting?.flash({...ie.flash.shot,level:this.startLevel,x:this.startPositionX,y:this.startPositionY,z:this.startLevel}),this._muzzle&&h>.001&&(this._flashComplete=!1,this.flash=new Eo(this.startPositionX,this.startPositionY,a/h,l/h,()=>{this._flashComplete=!0,this._tryDestroy()},this._style.muzzleFlash),this.addChild(this.flash),this.flash.run()),this._flashOnly){this._visualsComplete=!0,this._tryDestroy();return}const c=this._slopeEnd(s)??this._wallEnd(s);if(this._visibleEnd=c,this._markWall(),this._blocked){this._onTracerComplete();return}const u=kf(this._shots?.path?.(this.startPositionX,this.startPositionY,c.x,c.y,this.startLevel),c.dist,this.endLevel);this.tracer=new bf(this.startPositionX,this.startPositionY,c.x,c.y,this._onTracerComplete.bind(this),this._style.tracer,{pieces:u,layerFor:d=>this._layerFor(d,u),stopLine:c.stopLine}),this.addChild(this.tracer),this.tracer.run()}_wallAt(t,e){if(!this.hit)return null;if(this.hitCode===Nr){const s=2*Li,i=this._floorAt(this.endPositionX+t*s,this.endPositionY+e*s),o=this._rampRuns?.faceAt?.(i,this.endPositionX,this.endPositionY,t,e,Li);return o?{...o,base:i}:null}return this._volumes?qi(this._volumes,this.endPositionX,this.endPositionY,t,e,(s,i)=>this._floorAt(s,i),Li):null}_floorAt(t,e){const s=this._rampRuns?.floorAt?.(this.endLevel,t,e);return Number.isInteger(s)?s:this.endLevel}_wallEnd(t){const e={x:this.endPositionX,y:this.endPositionY,dist:t,stopLine:null},s=this._rayDirX,i=this._rayDirY;if(s===0&&i===0)return e;if(this._wall=this._wallAt(s,i),!this._wall)return this._wallK=null,e;const o=this._levelView?.camera()??At(this.parent,this._renderer);if(this._wallK=dn({x:this.endPositionX,y:this.endPositionY,camera:o,level:this.endLevel}),!o)return e;const{face:r,volume:a,base:l}=this._wall,{shear:h}=Q,c=this.endLevel*h;let u,d;if(ks(r,this.endPositionX,this.endPositionY,o))({x:u,y:d}=xs(this.endPositionX,this.endPositionY,o,c,this._wallK)),this.zIndex=it(Ro,this.endLevel);else{const f=aa({x0:this.startPositionX,y0:this.startPositionY,dx:s,dy:i,face:r,camera:o,kBase:c,kLine:(l+a)*h}),p=f===null?t:Math.min(t,Math.max(0,f));u=this.startPositionX+s*p,d=this.startPositionY+i*p}return{x:u,y:d,dist:Math.hypot(u-this.startPositionX,d-this.startPositionY),stopLine:{axis:r.axis,coord:r.axis==="x"?u:d}}}_markWall(){if(this.hitCode!==Ur||!this._wall||!this._wallMarks)return;const t=hi(this._assets?.bulletHoleTexture);if(!t)return;const{hole:e}=We;this._wallMarks.add({kind:"hole",x:this.endPositionX,y:this.endPositionY,level:this.endLevel,face:this._wall.face,height:Be.height+(Math.random()*2-1)*e.jitter,size:e.size,angle:Math.random()*Math.PI*2,...t},{parent:this.parent,renderer:this._renderer})}_slopeEnd(t){const e=this.hitCode===Gi&&t>.001?this._rampRuns?.slopeAt?.(this.endLevel,this.endPositionX,this.endPositionY):null;if(!e)return null;const s=this._levelView?.camera()??At(this.parent,this._renderer),{shear:i}=Q,{x:o,y:r}=xs(this.endPositionX,this.endPositionY,s,this.endLevel*i,e.height*i);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}=Q;return(i,o)=>{const r=this._floorAt(i,o),a=t.heightAt(r,i,o);return a!==null?a*s:r<e?r*s:null}}_debrisStartK(){const{shear:t}=Q;return this._wall?this._wallK:this.hitCode===Gi?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*Q.shear)}_placeImpactZ(t){const e=this.impact;if(!this._wall||!e||e.destroyed)return;const s=!!(t&&ks(this._wall.face,this.endPositionX,this.endPositionY,t));this.zIndex=it(s&&(e.isFalling()||this._burstPending>0)?Ro:Ai,this.endLevel)}_layerFor(t,e){const s=!!this._lighting?.isNight?.();if(!s&&t===this.endLevel||!this.parent)return this;let i=this.layers.get(t);if(!i){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;i=new rt,i.label=`shot-tracer-${t}`,i.eventMode="none",i.zIndex=it(s?Pr:Ai,t),i.refX=this.startPositionX+a/h*r,i.refY=this.startPositionY+l/h*r,this.parent.addChild(i),this.layers.set(t,i)}return i}_followMuzzle(){if(!this._shots||this.impact&&!this._blocked)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}=Q,s=xs(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._ricochetSound&&this._soundManager?.registerSound(this._ricochetSound,{position:{x:this.endPositionX,y:this.endPositionY}}),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,i=e-this.startPositionY,o=Math.hypot(s,i);let r=this._blocked?-this._rayDirX:0,a=this._blocked?-this._rayDirY:0;!this._blocked&&o>.001&&(r=-(s/o),a=-(i/o)),this.impact=new Af(t,e,r,a,this._onImpactComplete.bind(this),this._assets,{surfaceK:this._debrisSurface(),startK:this._debrisStartK()}),this.addChild(this.impact),this.impact.run(),this._burst(t,e,r,a)}else this._visualsComplete=!0,this._tryDestroy()}_burst(t,e,s,i){const o=this._visibleEnd,r=t!==this.endPositionX||e!==this.endPositionY,a=o&&!r?o.x:t,l=o&&!r?o.y:e,h=()=>{this._burstPending-=1,this._tryDestroy()};ie.flash.hit&&this._lighting?.flash({...ie.flash.hit,level:this.endLevel,x:t,y:e,z:this.endLevel}),this._assets?.smokeTexture&&gr.count>0&&(this._burstPending+=1,this.hitSmoke=new Rf(a,l,s,i,h,this._assets),this.addChild(this.hitSmoke),this.hitSmoke.run()),this._burstPending+=1,this.hitFlash=new Eo(a,l,s,i,h,Ja),this.addChild(this.hitFlash),this.hitFlash.run()}_onImpactComplete(){this._isDestroyed||(this._visualsComplete=!0,this._tryDestroy())}_tryDestroy(){this._visualsComplete&&this._soundComplete&&this._flashComplete&&this._burstPending===0&&this.destroy()}destroy(){if(!this._isDestroyed){this._isDestroyed=!0,this._soundId&&(this._soundManager.unregisterSound(this._soundId),this._soundId=null),this.tracer&&(this.tracer.destroy(),this.tracer=null);for(const t of this.layers.values())t.destroy({children:!0});this.layers.clear(),this.impact&&(this.impact.destroy(),this.impact=null),this.flash&&(this.flash.destroy(),this.flash=null),this.hitFlash&&(this.hitFlash.destroy(),this.hitFlash=null),this.hitSmoke&&(this.hitSmoke.destroy(),this.hitSmoke=null),this.parent&&this.parent.removeChild(this),super.destroy({children:!0})}}}const Vf=2,Nf=Math.PI*2;class Uf{constructor(t,e,{x:s,y:i,z:o,level:r,sizeScale:a}){const{textures:l}=e,h=new nt(l[Math.floor(Math.random()*l.length)]);h.anchor.set(.5),h.rotation=Math.random()*Nf,h.alpha=0,h.zIndex=it(Vf,r),this.sprite=h,this.x=s,this.y=i,this.z=o,this.level=r,this.scale=wt.scorch.size*a/e.contentSize,this.age=0,this.alpha=0,t.addChild(h),t.sortChildren()}get settled(){return this.age>=wt.scorch.fadeIn}step(t){const{alpha:e,fadeIn:s}=wt.scorch;this.age+=t,this.alpha=e*oe(this.age/s,0,1)}render(t,e){const s=this.z*Q.shear,i=Lt(this.x,this.y,t,s);this.sprite.position.set(i.x,i.y),this.sprite.scale.set(this.scale*(1+s));const o=e?e.alphaFor(this.level,this.x,this.y,this.z):1;this.sprite.alpha=this.alpha*o,e&&(this.sprite.tint=e.tintFor(this.level))}destroy(){this.sprite.destroy({texture:!1,textureSource:!1})}}function ha(n,t){return n<=t.duration?1:t.fadeOut>0?Math.max(0,1-(n-t.duration)/t.fadeOut):0}function ca(n){return n.duration+n.fadeOut}function Gf(n,t,e){const s=ca(t);if(n<s){const i=ha(n,t);return e.tailRate+(e.rate-e.tailRate)*i}return e.tailRate*Math.max(0,1-(n-s)/e.tail)}function Kf(n,t){return ca(n)+t.tail}function $f(n,t){return n<=0||n>=1?0:n<.12?t*(n/.12):n<=.45?t:t*(1-(n-.45)/.55)}const Fo=4,Oo=400,Zf=100,$e=Math.PI*2,Ds={min:.8,max:1.2},Ys=1,Xo={min:.7,max:1.3},Do=.3,jf=.6,Yo=.5,qf=.8,Qf=[[0,0]],Jf=.8,t_=1.3,e_=.5,Gt=n=>V(n.min,n.max),Hs=n=>({kind:"flame",x:0,y:0,vx:0,vy:0,windX:0,windY:0,drag:0,h:0,rise:0,age:0,life:1,size0:0,width:0,grow:1,aspectX:1,aspectY:1,spin:0,alpha:1,scaleX:0,scaleY:0,...n});class s_ extends rt{constructor(t,e,s={}){super(),this._readRow(t),this._condition=t[Kt],this.zIndex=it(Fo,this._level),this.visible=!1;const i=e.wreckFireTexture,o=e.wreckSmokeTexture;this._fireAsset=i||null,this._smokeAsset=o||null,this._scorchAsset=e.wreckScorchTexture||null,this._fireUnit=i?1/i.contentSize:0,this._smokeUnit=o?1/o.contentSize:0,this._enabled=!!i&&!!o,this._renderer=s.renderer||null,this._levelView=s.levelView||null,this._soundManager=s.soundManager||null,this._blasts=s.blasts||null,this._lighting=s.lighting?.enabled?s.lighting:null,this._active=!1,this._elapsed=0,this._flameAcc=0,this._smokeAcc=0,this._seed=0,this._tickListener=null,this._light=null,this._soundId=null,this._scorch=null,this._scorchPending=!1,this._fire=null,this._smoke=null,this._glow=null,this._flash=null,this._flashAge=0}_readRow(t){this._x=t[re],this._y=t[ae],this._heading=t[Me],this._z=t[Oe]||0,this._physLevel=t[jt]||0,this._vz=t[is]||0,this._deathCause=t[Lh]||0,this._level=bs(t[jt],this._z),this._length=pe.length,this._width=pe.width,this._sizeScale=pe.length/wt.referenceLength}update(t){const e=this._condition,s=this._level;this._readRow(t),this._level!==s&&(this.zIndex=it(Fo,this._level)),this._active&&(this._fire.follow(this._x,this._y),this._smoke.follow(this._x,this._y));const i=t[Kt];i!==void 0&&i!==e&&(this._condition=i,i===0&&e>0?this._ignite():i>0&&e===0&&this._reset()),this._scorchPending&&this._vz===0&&this._addScorch()}_ensureViews(){if(this._fire)return;const t=this._fireAsset.texture;this._smoke=new ji({texture:this._smokeAsset.texture,max:wt.maxSmoke,padding:Oo}),this._fire=new ji({texture:t,max:wt.maxFire,blendMode:"add",padding:Oo});const e=()=>{const s=new nt(t);return s.anchor.set(.5),s.blendMode="add",s.visible=!1,s};this._glow=e(),this._flash=e(),this.addChild(this._glow,this._smoke.container,this._fire.container,this._flash)}_ignite(){this._enabled&&(this._reset(),this._ensureViews(),this._elapsed=0,this._flameAcc=0,this._smokeAcc=0,this._seed=Math.random()*1e3,this._active=!0,this.visible=!0,this._fire.follow(this._x,this._y),this._smoke.follow(this._x,this._y),this._explode(),this._notify(),this._addLight(),this._addScorch(),this._tickListener=t=>this._tick(t.deltaMS),ot.shared.add(this._tickListener),this.onRender=()=>this._render())}_explode(){const t=this._flash;this._flashAge=0,t.position.set(this._x,this._y),t.tint=wt.flash.color,t.visible=!0,this._stepFlash(0);for(let e=0;e<wt.fireball.count;e+=1)this._spawnFireball();for(let e=0;e<wt.sparks.count;e+=1)this._spawnSpark();for(let e=0;e<wt.smoke.burst.count;e+=1)this._spawnBurstSmoke()}_notify(){const t=wt.deathSounds?.[this._deathCause]??wt.sound;t&&this._soundManager&&(this._soundId=this._soundManager.registerSound(t,{position:{x:this._x,y:this._y}})),this._lighting?.flash({...ie.flash.wreck,level:this._level,x:this._x,y:this._y,z:this._z}),this._blasts?.exploded({x:this._x,y:this._y,radius:wt.joltRadius*this._sizeScale,level:this._physLevel})}_addLight(){this._lighting&&(this._light=this._lighting.addLight({kind:"radial",radius:ie.wreckFire.radius*this._sizeScale,color:ie.wreckFire.color,intensity:0}))}_addScorch(){const t=this._scorchAsset;if(!(!t||!this.parent)){if(this._vz!==0){this._scorchPending=!0;return}this._scorchPending=!1,this._scorch=new Uf(this.parent,t,{x:this._x,y:this._y,z:this._z,level:this._level,sizeScale:this._sizeScale})}}_hullPoint(t,e){const[s,i]=t[Math.floor(Math.random()*t.length)],o=(s+V(-e,e)/2)*this._length,r=(i+V(-e,e)/2)*this._width,a=Math.cos(this._heading),l=Math.sin(this._heading);return{x:this._x+a*o-l*r,y:this._y+l*o+a*r}}_spawnFlame(t){const{fire:e,wind:s}=wt,i=this._hullPoint(e.points,e.spread),o=this._fire.spawn(Hs({kind:"flame",x:i.x,y:i.y,vx:s.x*Yo+V(-4,e.jitter)*this._sizeScale,vy:s.y*Yo+V(-4,e.jitter)*this._sizeScale,windX:s.x,windY:s.y,rise:e.rise,life:Gt(e.lifetime),size0:Gt(e.size)*this._sizeScale*Pt(jf,1,t)*this._fireUnit,grow:e.grow,aspectX:Gt(Ds),aspectY:Gt(Ds),spin:V(-Ys,Ys),alpha:e.alpha}));o&&(o.view.rotation=Math.random()*$e,this._applyFire(o,0))}_spawnFireball(){const{fireball:t,wind:e}=wt,s=this._hullPoint(Qf,qf),i=Math.random()*$e,o=Gt(t.speed)*this._sizeScale,r=this._fire.spawn(Hs({kind:"fireball",x:s.x,y:s.y,vx:Math.cos(i)*o,vy:Math.sin(i)*o,windX:e.x,windY:e.y,drag:t.drag,rise:t.rise,life:Gt(t.lifetime),size0:Gt(t.size)*this._sizeScale*this._fireUnit,grow:t.grow,aspectX:Gt(Ds),aspectY:Gt(Ds),spin:V(-Ys,Ys),alpha:t.alpha}));r&&(r.view.rotation=Math.random()*$e,this._applyFire(r,0))}_spawnSpark(){const{sparks:t}=wt,e=Math.random()*$e,s=Gt(t.speed)*this._sizeScale,i=this._fire.spawn(Hs({kind:"spark",x:this._x,y:this._y,vx:Math.cos(e)*s,vy:Math.sin(e)*s,drag:t.drag,life:Gt(t.lifetime),size0:t.length*this._sizeScale*this._fireUnit,width:t.width*this._sizeScale*this._fireUnit}));i&&(i.view.rotation=e,this._applyFire(i,0))}_spawnSmoke(t){const{smoke:e}=wt;this._emitSmoke({heat:t,speed:V(0,e.speed),lifeFactor:1,sizeFactor:1,alpha:Pt(e.tailAlpha,e.alpha,t)})}_spawnBurstSmoke(){const{smoke:t}=wt;this._emitSmoke({heat:1,speed:Gt(t.burst.speed),lifeFactor:Jf,sizeFactor:t_,alpha:t.burst.alpha})}_emitSmoke({heat:t,speed:e,lifeFactor:s,sizeFactor:i,alpha:o}){const{fire:r,smoke:a,wind:l}=wt,h=this._hullPoint(r.points,r.spread),c=Math.random()*$e,u=e*this._sizeScale,d=Math.random(),f=we(we(a.cooling[0],a.cooling[1],d),we(a.burning[0],a.burning[1],d),t),p=this._smoke.spawn(Hs({kind:"smoke",x:h.x,y:h.y,vx:Math.cos(c)*u+l.x,vy:Math.sin(c)*u+l.y,windX:l.x,windY:l.y,drag:a.drag,rise:a.rise,life:Gt(a.lifetime)*s,size0:Gt(a.size)*this._sizeScale*i*this._smokeUnit,grow:a.grow,aspectX:Gt(Xo),aspectY:Gt(Xo),spin:V(-Do,Do),alpha:o}));p&&(p.view.tint=f,p.view.rotation=Math.random()*$e,this._applySmoke(p,0))}_tick(t){if(!this._active)return;const e=oe(t,0,Zf);this._elapsed+=e;const s=ha(this._elapsed,wt.fire);for(this._flameAcc+=wt.fire.rate*s*e/1e3;this._flameAcc>=1;)this._flameAcc-=1,this._spawnFlame(s);for(this._smokeAcc+=Gf(this._elapsed,wt.fire,wt.smoke)*e/1e3;this._smokeAcc>=1;)this._smokeAcc-=1,this._spawnSmoke(s);this._stepChannel(this._fire,e,i=>this._applyFire(i,e)),this._stepChannel(this._smoke,e,i=>this._applySmoke(i,e)),this._stepFlash(e),this._stepGlow(s),this._stepLight(s),this._stepScorch(e),this._elapsed>=Kf(wt.fire,wt.smoke)&&this._fire.size===0&&this._smoke.size===0&&!this._flash.visible&&this._scorchSettled()&&this._finish()}_stepChannel(t,e,s){const{items:i}=t;for(let o=i.length-1;o>=0;o-=1){const r=i[o];r.age+=e,r.age>=r.life?t.removeAt(o):s(r)}}_move(t,e){const s=Math.exp(-t.drag*e);return t.vx=t.windX+(t.vx-t.windX)*s,t.vy=t.windY+(t.vy-t.windY)*s,t.x+=t.vx*e,t.y+=t.vy*e,t.age/t.life}_applyFire(t,e){const s=e/1e3,i=this._move(t,s),o=t.view;if(t.kind==="spark"){const{colors:r}=wt.sparks;t.scaleX=t.size0*(1-e_*i),t.scaleY=t.width,o.rotation=Math.atan2(t.vy,t.vx),o.tint=we(r[0],r[1],i),o.alpha=1-i}else{const r=1-(1-i)*(1-i),a=t.size0*(1+(t.grow-1)*r);t.scaleX=a*t.aspectX,t.scaleY=a*t.aspectY,t.h=t.rise*r,o.rotation+=t.spin*s,o.tint=ea(wt.fire.ramp,i),o.alpha=t.alpha*(1-i*i)}}_applySmoke(t,e){const s=e/1e3,i=this._move(t,s),o=t.view,r=t.size0*(1+(t.grow-1)*(1-(1-i)**3));t.scaleX=r*t.aspectX,t.scaleY=r*t.aspectY,t.h=t.rise*(1-(1-i)*(1-i)),o.rotation+=t.spin*s,o.alpha=$f(i,t.alpha)}_stepFlash(t){const e=this._flash;if(!e.visible)return;const{duration:s,startSize:i,endSize:o,alpha:r}=wt.flash;this._flashAge+=t;const a=this._flashAge/s;if(a>=1){e.visible=!1;return}const l=Pt(i,o,1-(1-a)*(1-a))*this._sizeScale;e.scale.set(l*this._fireUnit),e.alpha=r*(1-a)*(1-a)}_stepGlow(t){const e=this._glow,s=wt.glow;e.visible=t>0,e.visible&&(e.position.set(this._x,this._y),e.scale.set(s.size*this._sizeScale*this._fireUnit),e.tint=s.color,e.alpha=s.alpha*t*ze(this._seed,this._elapsed,s.flicker))}_stepLight(t){if(!this._light)return;if(t<=0){this._removeLight();return}const e=ie.wreckFire;this._lighting.updateLight(this._light,{x:this._x,y:this._y,z:this._z,level:this._level,levels:li(this._physLevel,this._z,this._vz!==0),intensity:e.intensity*t*ze(this._seed+1,this._elapsed,e.flicker)})}_stepScorch(t){this._scorch?.step(t)}_scorchSettled(){return!this._scorchPending&&(!this._scorch||this._scorch.settled)}_render(){const t=At(this.parent,this._renderer),e=Q.shear;if(this._active){const s=this._z*e;te(this,t,s,1),this._levelView&&(this.alpha=this._levelView.alphaFor(this._level,this._x,this._y,this._z),this.tint=this._levelView.tintFor(this._level));for(const i of[this._fire,this._smoke])for(const o of i.items){const r=xs(o.x,o.y,t,s,s+o.h*e);o.view.x=r.x,o.view.y=r.y,o.view.scaleX=o.scaleX*r.scale,o.view.scaleY=o.scaleY*r.scale}}this._scorch?.render(t,this._levelView)}_finish(){this._stopTicker(),this._active=!1,this._flash.visible=!1,this._glow.visible=!1,this._removeLight(),this.visible=!1,this._scorch||(this.onRender=null)}_reset(){this._stopTicker(),this._fire&&(this._fire.clear(),this._smoke.clear(),this._flash.visible=!1,this._glow.visible=!1),this._removeLight(),this._soundId!==null&&(this._soundManager?.releaseSound(this._soundId),this._soundId=null),this._scorch?.destroy(),this._scorch=null,this._scorchPending=!1,this._active=!1,this.visible=!1,this.onRender=null}_stopTicker(){this._tickListener&&(ot.shared.remove(this._tickListener),this._tickListener=null)}_removeLight(){this._light&&(this._lighting.removeLight(this._light),this._light=null)}destroy(t){this._reset(),super.destroy({texture:!1,textureSource:!1,...t,children:!0})}}const i_=4,n_=100,Zs=fr.map(({u:n,v:t})=>(n[1]-n[0])*(t[1]-t[0])),o_=Zs.reduce((n,t)=>n+t,0),[r_,a_]=nn,Ho=W.hull.upper.top.w;function l_(n,t,e,s){const i=n.u[0]+t*(n.u[1]-n.u[0]),o=n.v[0]+e*(n.v[1]-n.v[0]);if(n.region!=="turret")return[i,o,n.w];const r=Math.cos(s),a=Math.sin(s);return[W.turret.axisU+i*r-o*a,i*a+o*r,n.w]}const h_=()=>{let n=Math.random()*o_,t=0;for(;t<Zs.length-1&&n>Zs[t];)n-=Zs[t],t+=1;return fr[t]};class c_ extends rt{constructor(t,e,s={}){super();const i=e.flameTexture||null;this._renderer=s.renderer??null,this._lighting=s.lighting?.enabled?s.lighting:null,this._burnLight=null,this._engineLight=null,this._seed=Math.random()*100,this._elapsed=0,this._acc={burn:0,engine:0},this._texture=i?i.texture??i:null,this._unit=i?1/i.contentSize:0,this._engineScale=pe.length/Ne.referenceLength,this._burnParticles=[],this._engineParticles=[],this._burnLayer=new rt,this._engineLayer=new rt,this._glow=this._texture?new nt(this._texture):null,this._glow&&(this._glow.anchor.set(.5),this._glow.blendMode="add",this._glow.tint=Re.glow.color,this._glow.visible=!1,this.addChild(this._glow)),this.addChild(this._burnLayer,this._engineLayer),this._applyRow(t),this._tickListener=o=>this._tick(o.deltaMS),ot.shared.add(this._tickListener)}update(t){this._applyRow(t)}_applyRow(t){this._x=t[re],this._y=t[ae],this._heading=t[Me]||0,this._gunRotation=t[Wi]||0,this._z=t[Oe]||0,this._level=t[jt]||0,this._vz=t[is]||0,this._condition=t[Kt]??3,this._burn=this._condition===0?0:(t[Vi]||0)/255,this._engine=this._condition===1,this.zIndex=it(i_,this._level)}_tick(t){const e=Math.min(t,n_);this._elapsed+=e,this._burn>0&&this._emit("burn",Re.rate*this._burn,e,()=>this._spawnBurnFlame()),this._engine&&this._emit("engine",Ne.rate,e,()=>this._spawnEngineFlame()),this._advance(e),this._stepLights()}_emit(t,e,s,i){for(this._acc[t]+=e*s/1e3;this._acc[t]>=1;)this._acc[t]-=1,i()||(this._acc[t]=0)}_louverPoint(){const t=Ne.spread,e=Math.random()<.5?-1:1;return[r_+V(-t,t),e*a_+V(-t,t),Ho]}_world([t,e,s]){const i=Math.cos(this._heading),o=Math.sin(this._heading),r=$t;return[this._x+(t*i-e*o)*r,this._y+(t*o+e*i)*r,s*r]}_project(t,e,s,i){const o=(this._level+this._z+s/Zt.levelHeight)*Q.shear,r=Lt(t,e,i,o);return{x:r.x,y:r.y,scale:1+o}}_spawnSprite(t,e,s,[i,o,r],a){if(!this._texture||t.length>=s)return!1;const l=new nt(this._texture);return l.anchor.set(.5),l.blendMode="add",l.visible=!1,e.addChild(l),t.push({sprite:l,x:i,y:o,height:r,age:0,...a}),!0}_spawnBurnFlame(){const{life:t,rise:e,size:s,sizeScale:i,colors:o,alpha:r}=Re,a=V(i.min,i.max);return this._spawnSprite(this._burnParticles,this._burnLayer,Re.maxParticles,[0,0,0],{anchor:{area:h_(),a:Math.random(),b:Math.random()},life:V(t.min,t.max),vx:0,vy:-V(e.min,e.max),sizeFrom:s.start*a,sizeTo:s.end*a,colors:o,alpha:r,scaled:!0})}_spawnEngineFlame(){const{life:t,rise:e,size:s,colors:i,alpha:o}=Ne,r=2*this._engineScale;return this._spawnSprite(this._engineParticles,this._engineLayer,Ne.maxParticles,this._world(this._louverPoint()),{life:V(t.min,t.max),vx:e.x,vy:e.y,sizeFrom:s.start*r,sizeTo:s.end*r,colors:i,alpha:o,anchor:null,scaled:!1})}_stepSprites(t,e,s){return t.filter(i=>{i.age+=e;const o=i.age/i.life;if(o>=1)return i.sprite.destroy(),!1;i.x+=i.vx*e/1e3,i.y+=i.vy*e/1e3;const r=this._placeSprite(i,s),a=i.sprite,{colors:l,alpha:h}=i;return a.visible=!0,a.position.set(r.x,r.y),a.scale.set(Pt(i.sizeFrom,i.sizeTo,o)*(i.scaled?r.scale:1)*this._unit),a.tint=we(l.start,l.end,o),a.alpha=Pt(h.start,h.end,o),!0})}_placeSprite(t,e){const{anchor:s}=t;if(!s)return this._project(t.x,t.y,t.height,e);const[i,o,r]=this._world(l_(s.area,s.a,s.b,this._gunRotation));return this._project(i+t.x,o+t.y,r,e)}_stepGlow(t){const e=this._glow;if(!e||(e.visible=this._burn>0,!e.visible))return;const s=Re.glow,i=this._project(this._x,this._y,Ho*$t,t);e.position.set(i.x,i.y),e.scale.set(s.size*pe.length*i.scale*this._unit),e.alpha=s.alpha*this._burn*ze(this._seed+2,this._elapsed,s.flicker)}_advance(t){const e=At(this.parent,this._renderer);this._burnParticles=this._stepSprites(this._burnParticles,t,e),this._engineParticles=this._stepSprites(this._engineParticles,t,e),this._stepGlow(e)}_stepLights(){this._lighting&&(this._burnLight=this._stepLight(this._burnLight,this._burn>0,Re.light,this._burn,0),this._engineLight=this._stepLight(this._engineLight,this._engine,Ne.light,1,1))}_stepLight(t,e,s,i,o){if(!e)return t&&this._lighting.removeLight(t),null;const r=t??this._lighting.addLight({kind:"radial",radius:s.radius,color:s.color,intensity:0});return this._lighting.updateLight(r,{x:this._x,y:this._y,z:this._z,level:this._level,levels:li(this._level,this._z,this._vz!==0),intensity:s.intensity*i*ze(this._seed+o,this._elapsed,s.flicker)}),r}_removeLights(){this._burnLight&&(this._lighting.removeLight(this._burnLight),this._burnLight=null),this._engineLight&&(this._lighting.removeLight(this._engineLight),this._engineLight=null)}destroy(t){this._tickListener&&(ot.shared.remove(this._tickListener),this._tickListener=null),this._removeLights(),super.destroy({children:!0,texture:!1,textureSource:!1,...t})}}const Ti=255,u_=4,d_=100,Bo=.15;class f_ extends rt{constructor(t,e,s={},i){super(),this._ownerId=t[Lc]??i?.id,this._texture=e.flameTexture||null,this._unit=this._texture?1/this._texture.contentSize:0,this._muzzles=s.muzzles??null,this._renderer=s.renderer??null,this._volumes=s.volumes??null,this._soundManager=s.soundManager??null,this._localPlayer=s.localPlayer??null,this._lighting=s.lighting?.enabled?s.lighting:null,this._particles=[],this._emitAcc=0,this._lastUpdate=performance.now(),this._soundId=null,this._light=null,this._wallLayer=null,this._sootAsset=e.wallSootTexture||null,this._wallMarks=s.wallMarks??null,this._lastSootAt=-1/0,this.sortableChildren=!1,this._applyRow(t),this.onRender=()=>this._place(),this._tickListener=o=>this._tick(o.deltaMS),ot.shared.add(this._tickListener)}update(t){this._lastUpdate=performance.now(),this._applyRow(t)}_applyRow(t){this._fallbackX=t[yc],this._fallbackY=t[wc],this._fallbackAngle=t[vc],this._length=t[Mc],this._weapon=t[Sc],this._level=t[bc]||0,this._power=(t[kc]||0)/255;const e=t[Ac]??Ti;this._normal=e===Ti?null:e/Ti*Math.PI*2,this.zIndex=it(u_,this._level)}_active(){return performance.now()-this._lastUpdate<=xt.holdMs}_muzzleNow(){const t=this._muzzles?.get(this._ownerId);return t?{x:t.x,y:t.y,angle:t.angle}:{x:this._fallbackX,y:this._fallbackY,angle:this._fallbackAngle}}_tick(t){const e=Math.min(t,d_),s=this._active(),i=this._muzzleNow();s&&(this._emit(e),this._markSoot()),this._age(e),this._place(),this._updateSound(s,i),this._updateLight(s,i)}_visualReach(){return this._blocked()?this._length:this._length*xt.reach}_blocked(){return this._length<xt.range-.5}_emit(t){if(!this._texture||this._particles.length>=xt.maxParticles)return;const e=Pt(xt.rate.min,xt.rate.max,this._power),s=xt.range*xt.reach;for(this._emitAcc+=e*t/1e3;this._emitAcc>=1&&this._particles.length<xt.maxParticles;){this._emitAcc-=1;const i=new nt(this._texture);i.anchor.set(.5),i.rotation=Math.random()*Math.PI*2,this.addChild(i),this._particles.push({sprite:i,dist:xt.startOffset,lateral:(Math.random()*2-1)*.5,fan:Math.random(),onWall:!1,wobble:Math.random()*Math.PI*2,speed:s*V(xt.speed.min,xt.speed.max),age:0,life:V(xt.life.min,xt.life.max)})}}_age(t){const e=this._visualReach()+(this._blocked()?xt.splash.run:0),s=[];for(const i of this._particles){if(i.age+=t,i.dist+=i.speed*t/1e3,i.age>=i.life||i.dist>e){i.sprite.destroy();continue}s.push(i)}this._particles=s}_place(){const t=this._muzzleNow(),e=At(this.parent,this._renderer),s=this._level*Q.shear,i=this._visualReach(),o=Math.cos(t.angle),r=Math.sin(t.angle),a=this._wallFlow(o,r),l=a.nx!==0||a.ny!==0,h=l?a.nx:-o,c=l?a.ny:-r,u=this._wallView(t,o,r,e),{splash:d}=xt,f=u&&u.lift>0?this._ensureWallLayer():null;f&&(f.visible=this.visible,f.alpha=this.alpha,f.tint=this.tint);const p=Math.tan(xt.coneAngle*Math.PI/360);for(const _ of this._particles){const m=_.age/_.life,g=Math.max(0,_.dist-i),w=_.dist-g,M=i>0?Math.min(1,w/i):1,S=xt.nozzleWidth+2*w*p,b=Math.min(Pt(xt.size.start,xt.size.end,m)*2,S),y=Math.min(1,g/d.run),v=1-(1-y)*(1-y),z=g>0?Pt(b,d.size,v):b,L=(S-b)/2,T=oe(_.lateral*2*L+Math.sin(_.wobble+_.age*xt.wobbleSpeed)*xt.wobble*M,-L,L),E=_.lateral+.5<a.flow?1:-1,G=Math.PI/2*_.fan*_.fan,H=d.spread*d.run*v,K=(a.tx*E*Math.cos(G)+h*Math.sin(G))*H,J=(a.ty*E*Math.cos(G)+c*Math.sin(G))*H,$=_.sprite;_.onWall||=g>0||i-w<d.wallZone;const B=f&&_.onWall?f:this;$.parent!==B&&B.addChild($);const I=u?u.lift*M:0,at=Lt(t.x+o*w-r*T+K,t.y+r*w+o*T+J,e,s+I*Q.shear);$.visible=!u||_.dist<=u.cut,$.position.set(at.x,at.y),$.scale.set(z*this._unit),$.blendMode=m<xt.coreShare?"add":"normal",$.tint=ea(xt.ramp,m),$.alpha=xt.alpha*(1-m)**xt.fade}}_ensureWallLayer(){if(!this._wallLayer){if(!this.parent)return null;this._wallLayer=_n(this.parent,this._level),this._wallLayer.sortableChildren=!1}return this._wallLayer.zIndex=it(fn,this._level),this._wallLayer}_markSoot(){if(!this._wallMarks||!this._volumes||!this._blocked())return;const{soot:t}=We,e=performance.now();if(e-this._lastSootAt<t.everyMs)return;const s=Math.cos(this._fallbackAngle),i=Math.sin(this._fallbackAngle),o=this._fallbackX+s*this._length,r=this._fallbackY+i*this._length,a=qi(this._volumes,o,r,s,i,()=>this._level,Bo),l=a&&hi(this._sootAsset);l&&(this._lastSootAt=e,this._wallMarks.add({kind:"soot",x:o,y:r,level:this._level,face:a.face,height:Be.height,size:t.size,angle:0,...l},{parent:this.parent,renderer:this._renderer}))}_wallView(t,e,s,i){if(!this._blocked()||!this._volumes||!i)return null;const o=Math.cos(this._fallbackAngle),r=Math.sin(this._fallbackAngle),a=this._fallbackX+o*this._length,l=this._fallbackY+r*this._length,h=qi(this._volumes,a,l,o,r,()=>this._level,Bo);if(!h)return null;const{face:c,volume:u}=h,{shear:d}=Q;if(ks(c,a,l,i)){const p=this._level*d,_=dn({x:a,y:l,camera:i,level:this._level});return{lift:oe((_-p)/d,0,u),cut:1/0}}const f=aa({x0:t.x,y0:t.y,dx:e,dy:s,face:c,camera:i,kBase:this._level*d,kLine:(this._level+u)*d});return{lift:0,cut:f===null?1/0:Math.max(0,f)}}_wallFlow(t,e){if(this._normal===null)return{tx:-e,ty:t,nx:0,ny:0,flow:.5};const s=Math.cos(this._normal),i=Math.sin(this._normal),o=t*s+e*i,r=t-o*s,a=e-o*i,l=Math.hypot(r,a);return l<.001?{tx:-i,ty:s,nx:s,ny:i,flow:.5}:{tx:r/l,ty:a/l,nx:s,ny:i,flow:.5+.5*Math.min(1,l)}}_updateSound(t,e){if(!this._soundManager)return;if(!t){this._stopSound();return}const s={position:{x:e.x,y:e.y},spatial:this._localPlayer?.is(this._ownerId)!==!0};this._soundId===null?this._soundId=this._soundManager.registerSound(xt.sound,s):this._soundManager.updateSoundData(this._soundId,s)}_stopSound(){this._soundId!==null&&(this._soundManager.unregisterSound(this._soundId),this._soundId=null)}_updateLight(t,e){if(this._lighting){if(!t){this._removeLight();return}this._light||(this._light=this._lighting.addLight({kind:"radial",radius:xt.light.radius,color:xt.light.color,intensity:0})),this._lighting.updateLight(this._light,{x:e.x,y:e.y,z:this._level,level:this._level,levels:[this._level],intensity:xt.light.intensity*(.5+.5*this._power)})}}_removeLight(){this._light&&(this._lighting.removeLight(this._light),this._light=null)}destroy(t){this._tickListener&&(ot.shared.remove(this._tickListener),this._tickListener=null),this._stopSound(),this._removeLight(),this._wallLayer?.destroy({children:!0}),this._wallLayer=null,super.destroy({children:!0,texture:!1,textureSource:!1,...t})}}const __={Map:Cc,MapRadar:Oc,TankRadar:Yc,Tank:zd,Bomb:Id,Missile:Fd,ExplosionEffect:Qd,Smoke:ef,Molotov:af,DudBottle:lf,FirePool:ff,Tracks:pf,Dust:wf,ShotEffect:Wf,WreckFire:s_,TankFire:c_,BeamEffect:f_};function be(n,t,{blur:e,quality:s=10,width:i,height:o}){const r=new sn({strength:e,quality:s});r.padding=Dr(e),t.filters=[r];const a=n.generateTexture({target:t,frame:new Vt(0,0,i,o)});return t.destroy(!0),r.destroy(),a}function ds(n,t){const{radius:e,blur:s,color:i,quality:o=40}=n,r=new ft,a=(e+le(s))*2,l=a/2;return r.circle(l,l,e),r.fill(i),{texture:be(t,r,{blur:s,quality:o,width:a,height:a}),contentSize:e*2}}function p_(n,t){const{baseRadius:e,irregularity:s=0,blur:i=0,numPoints:o=20,colorFill:r,colorRim:a=r,rimWidth:l=0,variants:h=1}=n,c=Math.max(1,Math.floor(h)||1),u=(e+s+l)*2,d=u+le(i)*2,f=d/2,p=[];for(let _=0;_<c;_+=1){const m=new ft,g=[];for(let w=0;w<o;w+=1){const M=w/o*Math.PI*2,S=e+V(-s,s);g.push(f+S*Math.cos(M),f+S*Math.sin(M))}m.poly(g).fill(r).stroke({width:l,color:a,alignment:1}),p.push(be(t,m,{blur:i,width:d,height:d}))}return{textures:p,contentSize:u}}function Wo(n,t){const e=s=>{const i=Math.round((n>>s&255)*t);return Math.min(255,Math.max(0,i))};return e(16)<<16|e(8)<<8|e(0)}const{fittings:m_}=W,{upper:Vo}=W.hull,{turret:Ye}=W,g_=10988979,ua=1315086,x_=3811874,js=328965,qs=2761760,y_=2762532,w_=5913128,v_=7236198,M_={damaged1:71,damaged2:72,destroyed:73},S_={paint:y_,light:4012341,shade:1710102},Wt=(n,[t,e])=>t+n()*(e-t),[da,fa]=nn,ii=[{region:"hull",u:[Vo.top.u[0],Vo.top.u[1]],v:[-.9,.9]},{region:"turret",u:[-1,.8],v:[-.8,.8]}];function _a(n){const t=[],e=8+Math.floor(n()*3);for(let s=0;s<e;s+=1){const i=ii[s%2];t.push({kind:"scratch",region:i.region,u:Wt(n,i.u),v:Wt(n,i.v),length:Wt(n,[.15,.4]),angle:Wt(n,[-.6,.6]),color:g_,alpha:.8})}for(let s=0;s<3;s+=1){const i=ii[s===2?1:0];t.push({kind:"dent",region:i.region,u:Wt(n,i.u),v:Wt(n,i.v),r:Wt(n,[.08,.12]),color:"shade",alpha:.35})}return[...t,...pa(.35)]}const pa=n=>[1,-1].map(t=>({kind:"spot",region:"hull",u:da-.45,v:t*fa,rx:.55,ry:.12,angle:0,color:ua,alpha:n}));function b_(n){const t=[{region:"hull",u:-1.45,v:.35,rx:.32,ry:.24},{region:"hull",u:-2.15,v:-.4,rx:.3,ry:.22},{region:"hull",u:-1.9,v:.6,rx:.22,ry:.16},{region:"turret",u:-1.25,v:.3,rx:.26,ry:.2},{region:"turret",u:-1.1,v:-.35,rx:.2,ry:.16}].map(e=>({kind:"spot",...e,angle:Wt(n,[-.5,.5]),color:x_,alpha:.85}));return[..._a(n),...t,...pa(.55),{kind:"hole",region:"turret",u:.95,v:-.78,r:.09,color:js,rim:qs}]}function k_(n){const t=[];for(let e=0;e<7;e+=1){const s=ii[e%2];t.push({kind:"spot",region:s.region,u:Wt(n,s.u),v:Wt(n,s.v),rx:Wt(n,[.18,.4]),ry:Wt(n,[.12,.28]),angle:Wt(n,[-1,1]),color:w_,alpha:.7})}for(let e=0;e<6;e+=1){const s=ii[e%2];t.push({kind:"spot",region:s.region,u:Wt(n,s.u),v:Wt(n,s.v),rx:Wt(n,[.3,.6]),ry:Wt(n,[.04,.08]),angle:Wt(n,[-.4,.4]),color:v_,alpha:.45})}for(const e of[1,-1]){const{u:s,v:i}=m_.louvers;t.push({kind:"spot",region:"hull",u:da,v:e*fa,rx:(s[1]-s[0])/2+.05,ry:(i[1]-i[0])/2+.05,angle:0,color:ua,alpha:.9})}return t.push({kind:"hole",region:"turret",u:Ye.loaderHatch.u,v:Ye.loaderHatch.v,r:Ye.loaderHatch.radius*.9,color:js,rim:qs},{kind:"hole",region:"turret",u:Ye.cupola.u,v:Ye.cupola.v,r:Ye.cupola.lid.radius*.9,color:js,rim:qs},{kind:"hole",region:"hull",u:Ye.axisU,v:0,r:.8,color:js,rim:qs,ragged:!0}),t}const A_={damaged1:_a,damaged2:b_,destroyed:k_};function L_(n){const t=A_[n];return t?t(Qr(M_[n])):[]}const Ae=2,T_=640,vt={chrome:13028564,chromeLight:16054266,chromeShade:7107453,steel:11120825,clamp:3817286,hazard:14721072,hazardDark:1908513,missileBand:2764340,warhead:14263610,mine:4054090,mineRing:2062890,mineLight:10286500,fuze:15901974,igniter:16756782,glass:16765466,liquid:16742912,wick:15921126},No={steelSwatch:6119782,darkSteelSwatch:2829873,headlightSwatch:16773824,smokeSwatch:5913384,chromeSwatch:vt.chrome,hoseSwatch:vt.steel,igniterSwatch:vt.igniter,warheadSwatch:vt.warhead,mineSwatch:vt.mine,fuzeSwatch:vt.fuze,wickSwatch:vt.wick},{flame:ni,missile:Uo}=ns,{bottle:oi}=dr.molotov,z_=ni.tank.v[1]-ni.tank.v[0],Go=Uo.body.u[1]-Uo.body.u[0],P_=oi.neck.u[1]-oi.body.u[0],_e=2303530,zi=7309984,Le=4869973,Ko=1842462;function $o(n,t,e){let s=n*374761393+t*668265263+e*2147483647|0;return s=Math.imul(s^s>>>13,1274126177),s^=s>>>16,(s>>>0)/4294967295}const Zo={veil:789e3,veilAlpha:.62};function I_(n){let t=n*2654435761;return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}function E_(n,t,{texelsPerMeter:e=Zt.texelsPerMeter}={}){const{palette:s}=n,i=a=>Math.round(a*e),o=()=>{const a={hullTop:[Math.ceil(W.hull.length*e),Math.ceil(W.hull.width*e)],turretTop:[Math.ceil(3.4*e),Math.ceil(2.2*e)],trackSide:[Math.ceil(W.hull.length*e),Math.ceil(.95*e)],trackTop:[Math.ceil(W.hull.length*e),Math.ceil(.5*e)],gunSide:[Math.ceil(4.6*e),Math.ceil(.4*e)],flameTankSide:[Math.ceil(z_*e),Math.ceil(.4*e)],missileSide:[Math.ceil(Go*e),Math.ceil(.32*e)],bottleSide:[Math.ceil(P_*e),Math.ceil(.2*e)],mineTop:[Math.ceil(.48*e),Math.ceil(.48*e)],...Object.fromEntries(Object.keys(No).map(g=>[g,[4,4]]))},l={};let h=Ae,c=Ae,u=0;for(const[g,[w,M]]of Object.entries(a))h+w+Ae>T_&&h>Ae&&(h=Ae,c+=u+Ae,u=0),l[g]={x:h,y:c,w,h:M},h+=w+Ae,u=Math.max(u,M);const{hullTop:d,turretTop:f,trackSide:p,trackTop:_,gunSide:m}=l;d.originX=d.x+d.w/2,d.originY=d.y+d.h/2,f.originX=f.x+i(1.8),f.originY=f.y+f.h/2,p.originX=p.x+p.w/2,_.originX=_.x+_.w/2,m.originX=m.x-i(W.turret.axisU);for(const g of["flameTankSide","missileSide","bottleSide"])l[g].originX=l[g].x;return{regions:l,width:Math.max(...Object.values(l).map(g=>g.x+g.w))+Ae,height:Math.max(...Object.values(l).map(g=>g.y+g.h))+Ae}},r=({paint:a,light:l,shade:h},c,u="live")=>{const{regions:d,width:f,height:p}=o(),_=new ft,{hullTop:m,turretTop:g,trackSide:w,trackTop:M,gunSide:S}=d,b=I_(c),y=x=>m.originX+x*e,v=x=>m.originY+x*e,z=x=>g.originX+x*e,L=x=>g.originY+x*e,T=x=>Wo(a,x),E=(x,A,F=1)=>{const X=Wo(a,F),D=U=>Math.round((X>>U&255)*(1-A)+(x>>U&255)*A);return D(16)<<16|D(8)<<8|D(0)},G=E(3815988,.5,.78),H=E(5917240,.55,.9),K=E(3027254,.3,.85),J=E(16777215,.06,1.15),$=.4,B=(x,A,F,X,D,U=1,mt=1)=>{_.moveTo(x,A).lineTo(F,X).stroke({width:U,color:D,alpha:mt*$})},I=(x,A,F,X,D,U=1)=>{_.rect(x,A,F,X).fill({color:D,alpha:U})},at=(x,A,F,X,D,U=1)=>{_.rect(x,A,F,X).stroke({width:1,color:D,alpha:U*$})},N=(x,A,F,X,D=1)=>{_.circle(x,A,F).fill({color:X,alpha:D})},It=(x,A,F,X,D=1,U=1)=>{_.circle(x,A,F).stroke({width:D,color:X,alpha:U*.6})},Ht=(x,A,F,X,D,U)=>{const mt=Math.max(1,Math.floor(Math.hypot(F-x,X-A)/D));for(let gt=0;gt<=mt;gt+=1){const kt=gt/mt;N(x+(F-x)*kt,A+(X-A)*kt,1,U)}},lt=(x,A,F,X)=>{for(const[D,U,mt]of[[.15,A*.6,11],[.04,F,29]]){const gt=Math.max(2,Math.round(e*D));for(let kt=0;kt*gt<x.h;kt+=1)for(let Ut=0;Ut*gt<x.w;Ut+=1){const Ee=$o(Ut,kt,c+X+mt)*2-1;_.rect(x.x+Ut*gt,x.y+kt*gt,Math.min(gt,x.w-Ut*gt),Math.min(gt,x.h-kt*gt)).fill({color:Ee>0?l:h,alpha:Math.abs(Ee)*U})}}},ut=(x,A)=>{for(let F=0;F<A;F+=1){const X=x.x+b()*x.w,D=x.y+b()*x.h,U=(.04+b()*.14)*e,mt=(.02+b()*.06)*e,gt=b();gt<.45?I(X,D,U,mt,l,.26):gt<.85?I(X,D,U*1.3,mt,2826520,.2):I(X,D,Math.max(1,mt*.6),Math.max(1,mt*.6),7028514,.5)}for(let F=0;F<A/6;F+=1){const X=x.x+b()*x.w,D=x.y+b()*x.h;B(X,D,X+(.2+b()*.5)*e,D,2826520,1,.12)}},ht=(x,A,F,X,D,U,mt=5)=>{for(let kt=0;kt<8;kt+=1){const Ut=mt*(7-kt)/7-mt/2;I(x-Ut,A-Ut,F+2*Ut,X+2*Ut,D,U)}},ct=(x,A,F,X,D)=>{for(let U=D;U>0;U-=1)I(x-U,A-U,F+2*U,X+2*U,0,.07)},{upper:tt,fender:bt}=W.hull,et=W.fittings,st=tt.top,k=tt.bottom.v,P=tt.bottom.nose,[C,R]=tt.bottom.u,[Y,yt]=tt.bottom.corner;I(m.x,m.y,m.w,m.h,G),lt(m,.14,.08,1);for(const x of[1,-1]){const A=v(x>0?st.v:-k);ht(y(-3.05),A,i(6.1),i(k-st.v),h,.07,6)}ht(y(st.u[1]),v(-P),i(R-st.u[1]),i(2*P),K,.3,6),ht(y(C),v(-P),i(st.u[0]-C),i(2*P),K,.3,6);for(const x of[1,-1])for(const A of["mid","front","rear"]){const[F,X]=bt[A].v,D=v(x>0?F:-X),U=y(bt[A].u[0]),mt=i(bt[A].u[1]-bt[A].u[0]),gt=i(X-F);if(ht(U,D,mt,gt,H,.3,4),at(U,D,mt,gt,h,.7),A!=="mid"){for(let kt=1;kt<6;kt+=1)B(U+2,D+gt*kt/6,U+mt-2,D+gt*kt/6,h,1,.25);Ht(U+3,D+3,U+mt-3,D+3,7,h)}}at(y(st.u[0]),v(-.98),i(st.u[1]-st.u[0]),i(2*st.v),l,.9);for(const x of[1,-1]){for(const[A,F,X,D]of[[st.u[1],st.v-.05,R,P],[st.u[1]-.05,st.v,yt,k],[st.u[0],st.v-.05,C,P],[st.u[0]+.05,st.v,Y,k]])B(y(A),v(x*F),y(X),v(x*D),h,1,.8),B(y(A),v(x*F)+1,y(X),v(x*D)+1,l,1,.35);Ht(y(Y),v(x*(k-.04)),y(yt),v(x*(k-.04)),8,h),Ht(y(-2.4),v(x*1.46),y(2.1),v(x*1.46),9,l)}B(y(-.95),v(-.98),y(-.95),v(st.v),h,1,.55),Ht(y(2.15),v(-P+.04),y(2.15),v(P-.04),7,h);for(const x of[1,-1]){const A=x*et.handrails.v;for(const[F,X]of et.handrails.u)_.roundRect(y(F),v(A-.035),i(X-F),i(.07),3).stroke({width:2,color:Le,alpha:.85}),B(y(F)+2,v(A-.035)-1,y(X)-2,v(A-.035)-1,l,1,.6)}const j=et.driverHatch;ct(y(j.u[0]),v(j.v[0]),i(j.u[1]-j.u[0]),i(j.v[1]-j.v[0]),2),I(y(j.u[0]),v(j.v[0]),i(j.u[1]-j.u[0]),i(j.v[1]-j.v[0]),h,.35),at(y(j.u[0]),v(j.v[0]),i(j.u[1]-j.u[0]),i(j.v[1]-j.v[0]),l,.7);for(const x of[-.42,-.22])I(y(j.u[1])-i(.12),v(x),i(.08),i(.06),_e),I(y(j.u[1])-i(.12),v(x),i(.08),1,zi);const dt=et.bowMg;ct(y(dt.u)-i(dt.radius),v(dt.v)-i(dt.radius),i(2*dt.radius),i(2*dt.radius),3),N(y(dt.u),v(dt.v),i(dt.radius),T(.85)),It(y(dt.u),v(dt.v),i(dt.radius),_e,2),N(y(dt.u)-2,v(dt.v)-2,i(dt.radius*.45),l,.35),B(y(dt.u),v(dt.v),y(dt.barrel),v(dt.v),_e,2);for(const x of[1,-1])B(y(2.38),v(x*.55),y(2.6),v(x*.55),Le,3,.9),I(y(2.6),v(x*.55)-3,i(.06),6,_e),I(y(2.62),v(x*.84)-2,i(.06),i(.06),Le);const Bt=et.headlight;ct(y(Bt.u[0]),v(Bt.v)-i(Bt.radius),i(Bt.u[1]-Bt.u[0]),i(2*Bt.radius),3),I(y(Bt.u[0]-.2),v(Bt.v)-2,i(.12),4,Le);const pt=et.engineHatch;ct(y(pt.u[0]),v(pt.v[0]),i(pt.u[1]-pt.u[0]),i(pt.v[1]-pt.v[0]),3),I(y(pt.u[0]),v(pt.v[0]),i(pt.u[1]-pt.u[0]),i(pt.v[1]-pt.v[0]),l,.08),at(y(pt.u[0]),v(pt.v[0]),i(pt.u[1]-pt.u[0]),i(pt.v[1]-pt.v[0]),h),at(y(pt.u[0])+3,v(pt.v[0])+3,i(pt.u[1]-pt.u[0])-6,i(pt.v[1]-pt.v[0])-6,l,.5),I(y(pt.u[1])-i(.1),v(-.08),i(.05),i(.16),_e);const he=({u:x,v:A,slats:F},X)=>{const D=v(X>0?A[0]:-A[1]),U=i(A[1]-A[0]);I(y(x[0])-2,D-2,i(x[1]-x[0])+4,U+4,1382170);for(let mt=0;mt<F;mt+=1){const gt=y(x[0]+(x[1]-x[0])*(mt+.5)/F);I(gt-2,D,4,U,2830131),I(gt-2,D,4,1,Le)}};for(const x of[1,-1])he(et.louvers,x),he(et.innerLouvers,x);const Nt=et.grille,q=y(Nt.u[0]),Ft=v(Nt.v[0]),qt=i(Nt.u[1]-Nt.u[0]),ce=i(Nt.v[1]-Nt.v[0]);ct(q,Ft,qt,ce,3),I(q,Ft,qt,ce,1382170);for(let x=q+2;x<q+qt-2;x+=3)for(let A=Ft+2;A<Ft+ce-2;A+=3)I(x,A,1,1,3883335);for(let x=0;x<=5;x+=1){const A=Ft+ce*x/5;I(q,A-1,qt,2,T(.8)),B(q,A-1,q+qt,A-1,l,1,.3)}I(q-1,Ft,2,ce,T(.8)),I(q+qt-1,Ft,2,ce,T(.8)),B(y(Nt.u[0]-.08),Ft,y(Nt.u[0]-.08),Ft+ce,h,2,.8),B(y(Nt.u[0]-.08)+2,Ft,y(Nt.u[0]-.08)+2,Ft+ce,l,1,.4);const Qt=et.transmissionHatch,[St,me]=Qt.radius;ct(y(Qt.u-St),v(Qt.v-me),i(2*St),i(2*me),3),_.ellipse(y(Qt.u),v(Qt.v),i(St),i(me)).fill(T(.9)),_.ellipse(y(Qt.u),v(Qt.v),i(St),i(me)).stroke({width:2,color:h,alpha:.8});for(let x=0;x<10;x+=1){const A=x/10*Math.PI*2;I(y(Qt.u)+Math.cos(A)*i(St*.82)-1,v(Qt.v)+Math.sin(A)*i(me*.82)-1,2,2,_e)}I(y(Qt.u)-i(.06),v(Qt.v)-i(.04),i(.12),i(.08),h,.7),Ht(y(C+.04),v(-P+.04),y(C+.04),v(P-.04),7,h);for(const x of[1,-1])Ht(y(st.u[0]-.05),v(x*(st.v-.08)),y(C+.08),v(x*(P-.06)),7,h);const ge=et.exhausts;for(const x of[1,-1]){const A=y(ge.u[0]),F=i(ge.u[1]-ge.u[0]),X=v(x*ge.v-ge.radius),D=i(2*ge.radius);ct(A,X,F,D,4),I(A,X,F,D,T(.75)),I(A,X+D*.2,F,D*.6,T(.95)),I(A,X+D*.38,F,D*.18,l,.4),I(A+F-3,X,3,D,h,.6),I(y(C),v(x*ge.v)-3,A-y(C),6,1776928)}const Ct=et.smokeDrums;for(const x of[1,-1]){const A=v(x>0?Ct.v[0]:-1.13);ct(y(Ct.u)-i(Ct.radius),A,i(2*Ct.radius),i(Ct.v[1]-Ct.v[0]),5)}for(const x of et.fuelTanks){const A=y(x.u[0]),F=i(x.u[1]-x.u[0]),X=v(x.v-x.radius),D=i(2*x.radius);ct(A,X,F,D,5),I(A,X,F,D,T(.78)),I(A,X+D*.18,F,D*.64,T(.98)),I(A,X+D*.36,F,D*.2,l,.4),I(A,X+D*.8,F,D*.2,h,.35);for(const U of[.1,.5,.9])I(A+F*U-2,X,4,D,2961459),I(A+F*U-2,X,1,D,Le);I(A+F*.7-2,X+D*.5-2,4,4,_e),at(A,X,F,D,h,.8)}const Tt=et.zipBox;ct(y(Tt.u[0]),v(Tt.v[0]),i(Tt.u[1]-Tt.u[0]),i(Tt.v[1]-Tt.v[0]),4),I(y(Tt.u[0]),v(Tt.v[0]),i(Tt.u[1]-Tt.u[0]),i(Tt.v[1]-Tt.v[0]),T(.85)),at(y(Tt.u[0]),v(Tt.v[0]),i(Tt.u[1]-Tt.u[0]),i(Tt.v[1]-Tt.v[0]),l,.7);for(const x of[.2,.5,.8])I(y(Tt.u[0]+(Tt.u[1]-Tt.u[0])*x)-2,v(Tt.v[1])-4,4,4,_e);const ue=et.cable;for(const x of ue.v){B(y(ue.u[0]),v(x),y(ue.u[1]),v(x),3816768,3);for(let A=ue.u[0];A<ue.u[1];A+=.06)B(y(A),v(x)-1,y(A)+2,v(x)+1,9080467,1)}_.roundRect(y(ue.u[1]-.1),v(ue.v[0]),i(.14),i(ue.v[1]-ue.v[0]),i(.07)).stroke({width:3,color:3816768}),ut(m,90),I(g.x,g.y,g.w,g.h,J),lt(g,.16,.1,2);const Mn=W.turret.roof.outline,Sn=[...Mn,...[...Mn].reverse().map(([x,A])=>[x,-A])],bn=[...W.turret.base.outline,...[...W.turret.base.outline].reverse().map(([x,A])=>[x,-A])];_.poly(bn.flatMap(([x,A])=>[z(x),L(A)])).fill({color:h,alpha:.35}),_.poly(Sn.flatMap(([x,A])=>[z(x),L(A)])).fill({color:J}),_.poly(Sn.flatMap(([x,A])=>[z(x),L(A)])).stroke({width:2,color:l,alpha:.85}),_.poly(bn.flatMap(([x,A])=>[z(x),L(A)])).stroke({width:1,color:h});for(let x=0;x<40;x+=1){const A=g.x+b()*g.w,F=g.y+b()*g.h;I(A,F,(.05+b()*.15)*e,(.03+b()*.08)*e,b()>.5?l:h,.07)}const Xt=W.turret.mantlet,ui=Xt.u+Xt.radius;ct(z(Xt.back),L(-.4),i(ui-Xt.back),i(2*Xt.v),4),I(z(Xt.back),L(-.4),i(ui-Xt.back),i(2*Xt.v),T(.98));for(let x=0;x<4;x+=1)I(z(Xt.u+Xt.radius*x/4),L(-.4),i(Xt.radius/4)+1,i(2*Xt.v),h,.08*(x+1));at(z(Xt.back),L(-.4),i(ui-Xt.back),i(2*Xt.v),l,.8);for(const x of[Xt.back+.2,Xt.back+.31])B(z(x),L(-.4+.02),z(x),L(Xt.v-.02),h,2,.8),B(z(x)+2,L(-.4+.02),z(x)+2,L(Xt.v-.02),l,1,.6);const zt=W.turret.loaderHatch;ct(z(zt.u)-i(zt.radius),L(zt.v)-i(zt.radius),i(2*zt.radius),i(2*zt.radius),3),N(z(zt.u),L(zt.v),i(zt.radius),T(1)),It(z(zt.u),L(zt.v),i(zt.radius),h,2),It(z(zt.u),L(zt.v),i(zt.radius*.88),l,1,.7),I(z(zt.u+zt.radius)-2,L(zt.v)-4,i(.08),8,Le),I(z(zt.u+zt.radius)-2,L(zt.v)-4,i(.08),1,l),I(z(zt.u-zt.radius)-2,L(zt.v-.1),5,i(.2),Le);const _t=W.turret.cupola;ct(z(_t.u)-i(_t.radius),L(_t.v)-i(_t.radius),i(2*_t.radius),i(2*_t.radius),4),N(z(_t.u),L(_t.v),i(_t.radius),T(.95)),It(z(_t.u),L(_t.v),i(_t.radius),h,2),N(z(_t.u),L(_t.v),i(_t.lid.radius),T(1.05)),It(z(_t.u),L(_t.v),i(_t.lid.radius),l,1,.7),B(z(_t.u),L(_t.v-_t.lid.radius),z(_t.u),L(_t.v+_t.lid.radius),h,2,.9),B(z(_t.u)+2,L(_t.v-_t.lid.radius),z(_t.u)+2,L(_t.v+_t.lid.radius),l,1,.5);for(let x=0;x<5;x+=1){const A=(x-2)/4*Math.PI*.8,F=z(_t.u)+Math.cos(A)*i(_t.radius*.9),X=L(_t.v)+Math.sin(A)*i(_t.radius*.9);I(F-2,X-2,4,4,_e),I(F-2,X-2,4,1,zi)}for(const x of W.turret.vents){const A=i(W.turret.vent.radius);ct(z(x.u)-A,L(x.v)-A,2*A,2*A,4),N(z(x.u),L(x.v),A,T(.82)),N(z(x.u)-2,L(x.v)-2,A*.8,T(.98)),N(z(x.u)-3,L(x.v)-3,A*.45,l,.45),It(z(x.u),L(x.v),A,h,1,.9)}for(const x of W.turret.periscopes){const A=i(W.turret.periscope.radius);ct(z(x.u)-A,L(x.v)-A,2*A,2*A,3),N(z(x.u),L(x.v),A,T(.9)),It(z(x.u),L(x.v),A,h,1,.9),I(z(x.u)-A*.5,L(x.v)-A*.4,A,A*.8,_e),I(z(x.u)+A*.3,L(x.v)-A*.4,2,A*.8,zi)}for(const x of[1,-1]){const A=[[.9,.62],[-.26,.86],[-1.1,.67]].map(([F,X])=>[z(F),L(x*X)]);_.moveTo(...A[0]).lineTo(...A[1]).lineTo(...A[2]).stroke({width:3,color:Le,alpha:.9}),_.moveTo(A[0][0],A[0][1]-1).lineTo(A[1][0],A[1][1]-1).lineTo(A[2][0],A[2][1]-1).stroke({width:1,color:10133670,alpha:.7});for(const[F,X]of A)I(F-2,X-2,4,4,_e)}ut(g,50);const di=S.y;I(S.x,di,S.w,S.h,T(.7)),I(S.x,di+S.h*.2,S.w,S.h*.6,T(.95)),I(S.x,di+S.h*.35,S.w,S.h*.3,l,.5),I(w.x,w.y,w.w,w.h,2829358);const Ve=x=>w.originX+x*e,Ps=x=>w.y+w.h-x*e;for(let x=-2.95;x<2.95;x+=W.track.pitch)B(Ve(x),w.y,Ve(x),w.y+w.h,3947839);const fi=(x,A,F,X)=>{N(Ve(x),Ps(A),i(F),X),N(Ve(x),Ps(A),i(F*.72),5593438),N(Ve(x),Ps(A),i(F*.3),2764080);for(let D=0;D<6;D+=1){const U=D/6*Math.PI*2;N(Ve(x)+Math.cos(U)*i(F*.5),Ps(A)+Math.sin(U)*i(F*.5),2,1842462)}};for(const x of W.track.wheels.u)fi(x,W.track.wheels.center,W.track.wheels.radius,Ko);fi(W.track.idler.u,W.track.idler.center,W.track.idler.radius,Ko),fi(W.track.sprocket.u,W.track.sprocket.center,W.track.sprocket.radius,2829358),I(M.x,M.y,M.w,M.h,2829358);for(let x=0;x*W.track.pitch*e<M.w;x+=1){const A=M.x+x*W.track.pitch*e;x%2===0&&I(A,M.y,Math.max(1,W.track.pitch*e*.5),M.h,3947839)}const kn=x=>{I(x.x,x.y,x.w,x.h,vt.chromeShade),I(x.x,x.y+x.h*.15,x.w,x.h*.7,vt.chrome),I(x.x,x.y+x.h*.3,x.w,x.h*.18,vt.chromeLight),I(x.x,x.y+x.h*.68,x.w,x.h*.08,vt.chromeShade)},An=(x,A,F,X,D=1)=>{I(x.x+i(A-F/2),x.y,Math.max(1,i(F)),x.h,X,D)},Pe=d.flameTankSide,Ln=ni.tank.v[0];kn(Pe);for(const x of ni.brackets)An(Pe,(x.v[0]+x.v[1])/2-Ln,.05,vt.clamp);const Tn=Pe.x+i(-Ln-.04),zn=Math.max(2,i(.08));I(Tn,Pe.y,zn,Pe.h,vt.hazard);for(let x=Pe.y;x<Pe.y+Pe.h;x+=4)I(Tn,x,zn,2,vt.hazardDark);const Pn=d.missileSide;kn(Pn);for(const x of[.1,.55])An(Pn,x*Go,.05,vt.missileBand);const ee=d.bottleSide,Aa=oi.body.u[1]-oi.body.u[0];I(ee.x,ee.y,ee.w,ee.h,vt.glass),I(ee.x,ee.y+ee.h*.15,i(Aa*.7),ee.h*.7,vt.liquid),I(ee.x+1,ee.y+ee.h*.3,ee.w-2,Math.max(1,ee.h*.12),vt.chromeLight,.8);const ke=d.mineTop,Is=ke.x+ke.w/2,Es=ke.y+ke.h/2,Ie=ke.w/2;I(ke.x,ke.y,ke.w,ke.h,vt.mine),N(Is-Ie*.3,Es-Ie*.3,Ie*.35,vt.mineLight),N(Is,Es,Ie*.55,vt.mineRing),N(Is,Es,Ie*.42,vt.mine);for(let x=0;x<4;x+=1){const A=Math.PI/4+x/4*Math.PI*2;N(Is+Math.cos(A)*Ie*.78,Es+Math.sin(A)*Ie*.78,Math.max(1,Ie*.07),vt.mineRing)}for(const[x,A]of Object.entries(No)){const F=d[x];I(F.x,F.y,F.w,F.h,A)}if(u==="destroyed")for(const x of Object.values(d))I(x.x,x.y,x.w,x.h,Zo.veil,Zo.veilAlpha);for(const x of L_(u)){const A=x.region==="turret",F=A?z(x.u):y(x.u),X=A?L(x.v):v(x.v),D=x.color==="shade"?h:x.color;if(x.kind==="scratch"){const U=Math.cos(x.angle)*x.length*e/2,mt=Math.sin(x.angle)*x.length*e/2;_.moveTo(F-U,X-mt).lineTo(F+U,X+mt).stroke({width:1,color:D,alpha:x.alpha})}else if(x.kind==="dent")N(F,X,x.r*e,D,x.alpha),_.arc(F,X,x.r*e,Math.PI*.1,Math.PI*.9).stroke({width:1,color:l,alpha:x.alpha});else if(x.kind==="hole"){const U=x.r*e;if(x.ragged){const gt=[];for(let kt=0;kt<18;kt+=1){const Ut=kt/18*Math.PI*2,Ee=1+($o(kt,7,c)-.5)*.3;gt.push(F+Math.cos(Ut)*U*Ee,X+Math.sin(Ut)*U*Ee)}_.poly(gt).fill(x.rim),N(F,X,U*.85,D)}else N(F,X,U+Math.max(1,U*.35),x.rim),N(F,X,U,D)}else{const U=Math.cos(x.angle),mt=Math.sin(x.angle),gt=[];for(let kt=0;kt<24;kt+=1){const Ut=kt/24*Math.PI*2,Ee=Math.cos(Ut)*x.rx*e,In=Math.sin(Ut)*x.ry*e;gt.push(F+Ee*U-In*mt,X+Ee*mt+In*U)}_.poly(gt).fill({color:D,alpha:x.alpha})}}const _i=new rt;_i.addChild(_);const La=t.generateTexture({target:_i,frame:new Vt(0,0,f,p)});return _i.destroy({children:!0}),{texture:La,width:f,height:p,regions:d,texelsPerMeter:e}};return{liveTeamId1:r(s[1],1),liveTeamId2:r(s[2],2),damaged1TeamId1:r(s[1],1,"damaged1"),damaged1TeamId2:r(s[2],2,"damaged1"),damaged2TeamId1:r(s[1],1,"damaged2"),damaged2TeamId2:r(s[2],2,"damaged2"),destroyed:r(S_,3,"destroyed")}}function C_(n,t){const{radius:e,borderWidth:s,crossSize:i,crossThickness:o,colors:r}=n,a={},l=(e+s)*2,h=l/2,c=15658734,u=3355443,d=p=>{const _=new ft;_.circle(h,h,e).fill(c),_.circle(h,h,e-s).fill(p);const m=t.generateTexture({target:_,frame:new Vt(0,0,l,l)});return _.destroy(!0),m},f=()=>{const p=new ft,_=i/2;p.moveTo(h-_,h-_).lineTo(h+_,h+_).moveTo(h-_,h+_).lineTo(h+_,h-_).stroke({width:o,color:u});const m=t.generateTexture({target:p,frame:new Vt(0,0,l,l)});return p.destroy(!0),m};return a.liveTeamId1=d(r.teamId1),a.liveTeamId2=d(r.teamId2),a.destroyed=f(),a}function R_(n,t){const{colorOuter:e,colorInner:s}=n,i=new ft,o=20,r=1;i.rect(0,0,o,o).fill(e),i.rect(r,r,o-r*2,o-r*2).fill(s);const a=t.generateTexture({target:i,frame:new Vt(0,0,o,o)});return i.destroy(!0),a}function F_(n,t){const{length:e,width:s,colorBody:i,colorNose:o,colorFin:r}=n,a=new ft,l=s/2,h=e*.3,c=e-h;a.poly([0,0,e*.25,l,e*.25,s,0,s-l*.4]).fill(r),a.poly([0,s,e*.25,l,e*.25,0,0,l*.4]).fill(r),a.rect(0,l*.35,c,s-l*.7).fill(i),a.poly([c,l*.35,e,l,c,s-l*.35]).fill(o);const u=t.generateTexture({target:a,frame:new Vt(0,0,e,s)});return a.destroy(!0),u}function O_(n,t){const{length:e}=n,s=e*.4,i=s/2,o=e*.62,r=o-i*.4,a=s*.4,l=e*.86,h=s*.3,c=s*.14,u=new ft;u.roundRect(0,0,o,s,i).fill(vt.glass),u.roundRect(s*.1,s*.15,o*.7,s*.7,s*.35).fill(vt.liquid),u.rect(r,i-a/2,l-r,a).fill(vt.glass),u.rect(l,i-h/2,e-l,h).fill(vt.wick),u.circle(e-c,i,c).fill(vt.igniter),u.rect(i*.5,s*.2,o-i,s*.1).fill({color:vt.chromeLight,alpha:.8});const d=t.generateTexture({target:u,frame:new Vt(0,0,e,s)});return u.destroy(!0),d}function X_(n,t){const{width:e,length:s,color:i}=n,o=new ft;o.rect(0,0,s,e).fill(i);const r=t.generateTexture({target:o,frame:new Vt(0,0,s,e)});return o.destroy(!0),r}function jo(n,t){const{baseRadius:e,irregularity:s=0,blur:i=0,numPoints:o=16,color:r,coreColor:a=r,coreRatio:l=.5,variants:h=1}=n,c=Math.max(1,Math.floor(h)||1),u=(e+s)*2,d=u+le(i)*2,f=d/2,p=[],_=(m,g)=>{const w=[];for(let M=0;M<o;M+=1){const S=M/o*Math.PI*2,b=m+V(-g,g);w.push(f+b*Math.cos(S),f+b*Math.sin(S))}return w};for(let m=0;m<c;m+=1){const g=new ft;g.poly(_(e,s)).fill(r).poly(_(e*l,s*l)).fill(a),p.push(be(t,g,{blur:i,width:d,height:d}))}return{textures:p,contentSize:u}}function Qs(n,t,e,s,i=14,o=1){const r=[];for(let a=0;a<i;a+=1){const l=a/i*Math.PI*2,h=e+V(-s,s);r.push(n+h*Math.cos(l),t+h*o*Math.sin(l))}return r}function D_(n,t){const{radius:e,irregularity:s=0,haloRatio:i=2,color:o,coreColor:r=o,haloColor:a,haloAlpha:l=.5,blur:h=0,variants:c=1}=n,u=Math.max(1,Math.floor(c)||1),d=e*i,f=(d+s)*2,p=f+le(h)*2,_=p/2,m=[];for(let g=0;g<u;g+=1){const w=new ft;w.poly(Qs(_,_,d,s,12)).fill({color:a,alpha:l}).poly(Qs(_,_,e,s,10)).fill(o).poly(Qs(_,_,e*.5,s*.5,8)).fill(r),m.push(be(t,w,{blur:h,width:p,height:p}))}return{textures:m,contentSize:f}}function Y_(n,t){const{radius:e,rise:s=2,irregularity:i=0,color:o,alpha:r=.6,layers:a=4,blur:l=0,variants:h=1}=n,c=Math.max(1,Math.floor(h)||1),u=Math.max(1,Math.floor(a)||1),d=e*s+i*2,f=d+le(l)*2,p=f/2,_=p+d/2-e,m=p-d/2+e,g=[];for(let w=0;w<c;w+=1){const M=new ft;for(let S=0;S<u;S+=1){const b=u===1?0:S/(u-1),y=_+(m-_)*b,v=e*(1-.45*b);M.poly(Qs(p,y,v,i,12,1.2)).fill({color:o,alpha:r*(1-.7*b)})}g.push(be(t,M,{blur:l,width:f,height:f}))}return{textures:g,contentSize:d}}function H_(n,t){const{length:e,width:s,color:i,variants:o=1}=n,r=Math.max(1,Math.floor(o)||1),a=e/2,l=[];for(let h=0;h<r;h+=1){const c=new ft,u=V(s*.3,s)/2,d=V(s*.1,s*.6)/2;c.poly([0,a-d,e,a-u,e,a+u,0,a+d]).fill(i),l.push(t.generateTexture({target:c,frame:new Vt(0,0,e,e)})),c.destroy(!0)}return{textures:l,contentSize:e}}function ma(n,t,e,s,i){for(let o=0;o<s;o+=1){const r=e*o/s,a=e*(o+1)/s,l=i((o+.5)/s);l<=0||(n.circle(t,t,a),n.fill({color:16777215,alpha:l}),r>0&&(n.circle(t,t,r),n.cut()))}}function Pi(n,t){const{radius:e,rings:s=32,blur:i=2,quality:o=10}=n,r=new ft,a=le(i),l=(e+a)*2,h=l/2;return ma(r,h,e,s,Er),{texture:be(t,r,{blur:i,quality:o,width:l,height:l}),contentSize:e*2}}function B_(n,t){const{length:e,halfWidth:s,strips:i=24,blur:o=4,quality:r=10}=n,a=new ft,l=le(o),h=e+l*2,c=(s+l)*2,u=l,d=c/2;for(let p=0;p<i;p+=1){const _=e*p/i,m=e*(p+1)/i,g=s*p/i,w=s*(p+1)/i,M=(p+.5)/i,S=Cr(M);a.poly([u+_,d-g,u+m,d-w,u+m,d+w,u+_,d+g]),a.fill({color:16777215,alpha:S})}return{texture:be(t,a,{blur:o,quality:r,width:h,height:c}),length:e,halfWidth:s,margin:l}}function W_(n,t){const{core:e,halo:s,rings:i=12,blur:o=1,quality:r=10}=n,a=new ft,l=le(o),h=(s+l)*2,c=h/2,u=e/s;return ma(a,c,s,i,f=>f<=u?1:.6*(1-(f-u)/(1-u))**2),{texture:be(t,a,{blur:o,quality:r,width:h,height:h}),contentSize:s*2}}function V_(n,t){const{radius:e,strips:s=16,blur:i=2,quality:o=10}=n,r=new ft,a=le(i),l=(e+a)*2,h=l/2;for(let u=0;u<s;u+=1){const d=e*u/s,f=e*(u+1)/s,p=(u+.5)/s;r.rect(h+d,h-e,f-d,e*2),r.fill({color:16777215,alpha:p*p})}return{texture:be(t,r,{blur:i,quality:o,width:l,height:l}),contentSize:e*2}}function N_(n){let t=n>>>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 U_(n,t){const{radius:e,rays:s=14,width:i=.05,strips:o=8,seed:r=1,blur:a=3,quality:l=10}=n,h=new ft,c=le(a),u=(e+c)*2,d=u/2,f=N_(r);for(let _=0;_<s;_+=1){const m=(_+(f()-.5)*.8)/s*Math.PI*2,g=e*(.55+.45*f()),w=.35+.65*f(),M=i*(.5+f()),S=Math.cos(m-M),b=Math.sin(m-M),y=Math.cos(m+M),v=Math.sin(m+M);for(let z=0;z<o;z+=1){const L=g*z/o,T=g*(z+1)/o,E=(z+.5)/o;h.poly([d+S*L,d+b*L,d+S*T,d+b*T,d+y*T,d+v*T,d+y*L,d+v*L]),h.fill({color:16777215,alpha:w*(1-E)})}}return{texture:be(t,h,{blur:a,quality:l,width:u,height:u}),contentSize:e*2}}const G_=64,Bs=1053978,qo=50*Math.PI/180;function K_(n,t){const e=n.pixelSize??G_,s=new Vt(0,0,e,e),i=f=>{const p=t.generateTexture({target:f,frame:s});return f.destroy(!0),p},o=new ft,r=e*.42,a=e*.62,l=(e-r)/2,h=e*.3,c=e/16;o.roundRect(e*.58,e*.06,e*.08,e*.28,e*.03).fill(n.color).stroke({width:c,color:Bs}),o.roundRect(l,h,r,a,e*.08).fill(n.color).stroke({width:c,color:Bs}),o.rect(l+r*.18,h+a*.12,r*.64,a*.24).fill(Bs);const u=new ft,d=e*.38;for(const[f,p]of[[d/3+e/24,Bs],[d/3,16777215]])u.arc(e/2,e/2,d,-qo,qo).stroke({width:f,color:p,cap:"round"});return{icon:i(o),arc:i(u)}}function $_(n,t){const{radius:e,width:s}=n,i=(e+s)*2,o=i/2,r=new ft;r.circle(o,o,e).stroke({width:s,color:16777215});const a=t.generateTexture({target:r,frame:new Vt(0,0,i,i)});return r.destroy(!0),{ring:a}}const Z_={explosionTexture:ds,smokeTexture:ds,impactParticleTexture:ds,dustTexture:ds,wreckSmokeTexture:ds,wreckFireTexture:Pi,flameTexture:Pi,wreckScorchTexture:jo,funnelTexture:p_,tankModelTexture:E_,tankRadarTexture:C_,bombTexture:R_,missileTexture:F_,bottleTexture:O_,trackMarkTexture:X_,scorchTexture:jo,bulletHoleTexture:D_,wallSootTexture:Y_,debrisTexture:H_,lightRadialTexture:Pi,headlightConeTexture:B_,lampHeadTexture:W_,glintTexture:V_,lightShaftTexture:U_,radioBadgeTexture:K_,radarPingTexture:$_},j_=n=>(n??"").split(/[?#]/)[0].endsWith(".js"),q_=n=>import(n);function Q_(n=ja,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,focus:null},s=t.now||(()=>performance.now()),i=()=>{const a=e.focus;return a&&s()<a.until?a:e},o=()=>{if(e.warned)return;e.warned=!0;const a=e.stage,l=e.renderer?.screen,h={destroyed:a?a.destroyed:null,position:a?{x:a.position?.x,y:a.position?.y}:null,scale:a?{x:a.scale?.x,y:a.scale?.y}:null,screen:l?{width:l.width,height:l.height}:null};console.warn("[tanks] levelView: центра камеры нет — кадр без трансформа сцены",h),e.diagnostics?.warn("tanks.camera.missing",h)},r=()=>{if(!e.stage)return null;if(e.stage.destroyed)return o(),null;const{position:a,scale:l}=e.stage,h=e.renderer?.screen,c=h?h.width:0,u=h?h.height:0,d=e.key;return(e.camera===null||d===null||d.x!==a.x||d.y!==a.y||d.scaleX!==l.x||d.scaleY!==l.y||d.width!==c||d.height!==u)&&(e.key={x:a.x,y:a.y,scaleX:l.x,scaleY:l.y,width:c,height:u},e.camera=At(e.stage,e.renderer),e.camera===null&&o()),e.camera};return{attachStage(a,l){!a||!l||e.stage&&!e.stage.destroyed||(e.stage=a,e.renderer=l,e.key=null,e.camera=null)},setDiagnostics(a){!e.diagnostics&&a&&(e.diagnostics=a)},camera(){return r()},set(a,l,h,c=0){e.level=a,e.x=l,e.y=h,e.z=c},focus(a,l,h,c,u){e.focus={level:a,x:l,y:h,z:c,until:s()+u}},releaseFocus(){e.focus=null},alphaFor(a,l,h,c=a){const u=r(),d=i(),f=Lt(d.x,d.y,u,d.z*Q.shear),p=Lt(l,h,u,c*Q.shear);return al({viewLevel:d.level,viewX:f.x,viewY:f.y,level:a,x:p.x,y:p.y,cfg:n})},tintFor(a){return ll(i().level,a,n)},get cfg(){return n},get mode(){return n.mode},get level(){return i().level},get x(){return i().x},get y(){return i().y},get z(){return i().z}}}function pn(n,t,e){const s=n.axis===0;return{alongX:s,a0:s?n.col0*t:n.row0*e,a1:s?n.col1*t:n.row1*e,b0:s?n.row0*e:n.col0*t,b1:s?n.row1*e:n.col1*t}}function ga(n,t){const e=n.sign>0?t:1-t;return n.from+(n.to-n.from)*e}function J_(n,t,e,s,i,o){const{alongX:r,a0:a,a1:l,b0:h,b1:c}=pn(n,t*e.x,t*e.y),u=(g,w)=>r?[g,w]:[w,g],d=r?n.col1-n.col0:n.row1-n.row0,f=Math.max(1,d*Math.max(1,Math.round(o)||1)),p=(g,w,M)=>[g+(g-s.x)*M,w+(w-s.y)*M],_=[],m=[];for(let g=0;g<=f;g+=1){const w=g/f,M=ga(n,w)*i,S=a+(l-a)*w;_.push(p(...u(S,h),M)),m.push(p(...u(S,c),M))}return[..._,...m.reverse()].flat()}function mn(n,t,e,s,i,o,r,a){let l=Math.floor(n/r),h=Math.floor(t/a);if(o(l,h,null,null,n,t))return 0;const c=e>0?1:-1,u=s>0?1:-1,d=e!==0?Math.abs(r/e):1/0,f=s!==0?Math.abs(a/s):1/0;let p=1/0,_=1/0;for(e!==0&&(p=((e>0?l+1:l)*r-n)/e),s!==0&&(_=((s>0?h+1:h)*a-t)/s);;){const m=l,g=h;let w;if(p<_?(w=p,l+=c,p+=d):(w=_,h+=u,_+=f),!(w<i))return i;if(o(l,h,m,g,n+e*w,t+s*w))return Math.max(0,w)}}const t0=.2;function gn(n,t,e,s,i){const{alongX:o,a0:r,a1:a}=pn(n,s,i),l=o?t:e,h=a-r||1,c=Math.min(1,Math.max(0,(l-r)/h));return ga(n,c)}function e0({lane:n,prevLane:t,col:e,row:s,prevCol:i,prevRow:o,x:r,y:a,z:l,cellW:h,cellH:c,clearance:u=t0}){if(t&&t!==n){const p=t.axis===0?s!==o:e!==i;return!!n||!p}return!n||t===n||i===null||i===void 0||(n.axis===0?e-i:s-o)===n.sign?!1:gn(n,r,a,h,c)-(l||0)>u}function Qo(n,t,e,s,i,o,r){if(!n)return!1;const a=Math.max(0,s),l=Math.min(t-1,o),h=Math.max(0,i),c=Math.min(e-1,r);for(let u=h;u<=c;u+=1){const d=u*t;for(let f=a;f<=l;f+=1)if(n[d+f]!==0)return!0}return!1}function s0(n,t,e,s,i,o,r,a){const l=mn(n,t,e,s,i,o,r,a);return l>=i?null:{distance:l,x:n+e*l,y:t+s*l}}function i0({x:n,y:t,rotation:e,alongMax:s,alongBack:i=0,acrossMax:o,rays:r},a,l,h){const c=Math.max(2,Math.round(r)||2),u=i>0,d=u?Math.max(3,Math.round(c/8)):0,f=[];for(let g=0;g<c;g+=1)f.push(-Math.PI/2+Math.PI*g/(c-1));for(let g=0;g<d;g+=1)f.push(Math.PI/2+Math.PI*(g+1)/(d+1));const p=new Float32Array((f.length+1)*2),_=new Float32Array(f.length);let m=!1;return p[0]=n,p[1]=t,f.forEach((g,w)=>{const M=e+g,S=Math.cos(M),b=Math.sin(M),y=Math.cos(g),v=Math.abs(Math.sin(g));let z=v>1e-9?o/v:1/0;y>1e-9?z=Math.min(z,s/y):y<-1e-9&&(z=Math.min(z,i/-y));const L=mn(n,t,S,b,z,a,l,h);_[w]=z,L<z-1e-6&&(m=!0),p[(w+1)*2]=n+S*L,p[(w+1)*2+1]=t+b*L}),{points:p,clipped:m,closed:u,reaches:_,forward:c}}function xn(n,t){const{width:e,height:s}=t.texture;if(n.kind==="cone")return{x:n.x,y:n.y,rotation:n.rotation||0,sx:n.radius/t.length,sy:n.radius*(n.spread??.5)/t.halfWidth,margin:t.margin,width:e,height:s};const i=n.radius*2/t.contentSize;return{x:n.x,y:n.y,rotation:0,sx:i,sy:i,margin:e/2,width:e,height:s}}function yn(n,t,{x:e,y:s,rotation:i,sx:o,sy:r,margin:a,width:l,height:h},c=Math.cos(i),u=Math.sin(i)){const d=n-e,f=t-s,p=d*c+f*u,_=f*c-d*u;return[(a+p/o)/l,(h/2+_/r)/h]}function n0(n,t){const e=Math.cos(t.rotation),s=Math.sin(t.rotation),i=new Float32Array(n.length);for(let o=0;o<n.length;o+=2){const[r,a]=yn(n[o],n[o+1],t,e,s);i[o]=r,i[o+1]=a}return i}const o0=[0,1,3,0,3,2];function r0({x:n,y:t,points:e,reaches:s,forward:i,uvOf:o,wallAt:r,cellW:a,cellH:l,height:h,level:c=0}){const u=.01*Math.min(a,l),d=b=>{const y=e[b*2],v=e[b*2+1],z=Math.hypot(y-n,v-t),L=s[b-1];if(!(z>1e-9)||!(z<L-1e-6))return null;const T=(y-n)/z,E=(v-t)/z,G=ra(y,v,T,E,a,l,.001);if(!G)return null;const H=r(y+T*u,v+E*u);return H>0?{face:G,x:y,y:v,endX:y+T*(L-z),endY:v+E*(L-z),height:Math.min(h,H)}:null},f=[];for(let b=1;b<=i;b+=1)f.push(d(b));const p=[];for(let b=0;b+1<f.length;b+=1){const y=f[b],v=f[b+1];y&&v&&y.face.axis===v.face.axis&&Math.abs(y.face.coord-v.face.coord)<1e-6&&p.push([y,v])}if(!p.length)return null;const _=new Float32Array(p.length*8),m=new Float32Array(p.length*4),g=new Float32Array(p.length*8),w=new Uint32Array(p.length*6),M=new Float32Array(p.length*2),S=new Float32Array(p.length*2);return p.forEach(([b,y],v)=>{[[b.x,b.y,b.height,b.endX,b.endY],[y.x,y.y,y.height,y.endX,y.endY],[b.x,b.y,0,b.x,b.y],[y.x,y.y,0,y.x,y.y]].forEach(([L,T,E,G,H],K)=>{const J=v*4+K,[$,B]=o(G,H);_[J*2]=L,_[J*2+1]=T,m[J]=c+E,g[J*2]=$,g[J*2+1]=B});for(let L=0;L<6;L+=1)w[v*6+L]=v*4+o0[L];M[v*2]=b.face.nx,M[v*2+1]=b.face.ny,S[v*2]=(b.x+y.x)/2,S[v*2+1]=(b.y+y.y)/2}),{base:_,heights:m,uvs:g,indices:w,normals:M,mids:S}}function xa(n,t=!1){const e=Math.max(0,n-1),s=new Uint32Array((e+(t&&n>2?1:0))*3);for(let i=0;i<e;i+=1)s[i*3]=0,s[i*3+1]=i+1,s[i*3+2]=i+2;return t&&n>2&&(s[e*3]=0,s[e*3+1]=n,s[e*3+2]=1),s}function Ze(n,t,e,s){const i=[];for(let o=0;o<n.length;o+=1){const r=n[o],a=n[(o+1)%n.length],l=s?r[t]>=e:r[t]<=e,h=s?a[t]>=e:a[t]<=e;if(l&&i.push(r),l!==h){const c=(e-r[t])/(a[t]-r[t]);i.push([r[0]+(a[0]-r[0])*c,r[1]+(a[1]-r[1])*c])}}return i}function a0({points:n,closed:t,lane:e,frame:s,cellW:i,cellH:o,segmentsPerCell:r}){const{alongX:a,a0:l,a1:h,b0:c,b1:u}=pn(e,i,o),d=H=>a?[n[H*2],n[H*2+1]]:[n[H*2+1],n[H*2]],f=n.length/2;let p=1/0,_=-1/0,m=1/0,g=-1/0;for(let H=0;H<f;H+=1){const[K,J]=d(H);p=Math.min(p,K),_=Math.max(_,K),m=Math.min(m,J),g=Math.max(g,J)}if(!(_>l&&p<h&&g>c&&m<u))return null;const w=a?e.col1-e.col0:e.row1-e.row0,M=Math.max(1,w*Math.max(1,Math.round(r)||1)),S=(h-l)/M,b=Math.cos(s.rotation),y=Math.sin(s.rotation),v=[],z=[],L=[],T=[],E=H=>{const K=z.length;for(const[J,$]of H){const B=a?J:$,I=a?$:J,[at,N]=yn(B,I,s,b,y);v.push(B,I),z.push(gn(e,B,I,i,o)),L.push(at,N)}for(let J=1;J+1<H.length;J+=1)T.push(K,K+J,K+J+1)},G=xa(f-1,t);for(let H=0;H<G.length;H+=3){let K=[d(G[H]),d(G[H+1]),d(G[H+2])];if(K=Ze(K,1,c,!0),K=Ze(K,1,u,!1),K=Ze(K,0,l,!0),K=Ze(K,0,h,!1),K.length<3)continue;const J=Math.min(...K.map(([at])=>at)),$=Math.max(...K.map(([at])=>at)),B=Math.max(0,Math.floor((J-l)/S)),I=Math.min(M-1,Math.ceil(($-l)/S)-1);for(let at=B;at<=I;at+=1){const N=Ze(Ze(K,0,l+at*S,!0),0,l+(at+1)*S,!1);N.length>=3&&E(N)}}return T.length?{base:new Float32Array(v),heights:new Float32Array(z),uvs:new Float32Array(L),indices:new Uint32Array(T)}:null}const Ws=16777215;class Jo{constructor({level:t,ambient:e,resolution:s,area:i,roof:o=!1}){this.level=t,this.ambient=e,this.roof=o,this.overlay=new rt,this.overlay.label=o?`lighting-roof-${t}`:`lighting-${t}`,this.overlay.zIndex=it(Cl,t),this.overlay.eventMode="none",this.base=new nt(Js.WHITE),this.base.tint=t===0?e:Ws,this.base.position.set(i.x,i.y),this.base.width=i.width,this.base.height=i.height,this.overlay.addChild(this.base),this.mask=t>=1?new ft:null,this.mask&&this.overlay.addChild(this.mask),this.lights=new rt,this.overlay.addChild(this.lights),this.rampLights=new rt,this.overlay.addChild(this.rampLights),this.rampMask=null,this.lightsMask=null,this.ramps=[],this.rampLightPool=[],this.shafts=new rt,this.overlay.addChild(this.shafts),this.shaftPool=[],this.tops=new rt,this.overlay.addChild(this.tops),this.topGroups=[],this.pool=[],this.fanPool=[],this.washPool=[],this.filter=new Oi({alpha:1}),this.filter.resolution=s,this.filter.blendMode="multiply",this.overlay.filters=[this.filter],this.overlay.filterArea=new Vt(i.x,i.y,i.width,i.height),this.resolution=s,this.hole=Di(),this.hasMask=!1}setMask(t,e,s){if(this.mask){this.mask.clear(),this.hasMask=t.length>0;for(const i of t)this.mask.rect(i.col*e*s.x,i.row*e*s.y,i.length*e*s.x,e*s.y);this.hasMask&&this.mask.fill(this.ambient)}}setTops(t,e,s){for(const i of this.topGroups)i.graphics.destroy();this.topGroups=[];for(const{volume:i,runs:o}of t){if(!o.length)continue;const r=new ft;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:i})}}setRamps(t,e,s,i){this.ramps=t,this.rampGeometry={step:e,scale:s,segments:i},t.length&&!this.rampMask?(this.rampMask=new ft,this.lightsMask=new ft,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&&te(this.mask,t,this.level*e,1),this.rampMask){const{step:s,scale:i,segments:o}=this.rampGeometry;this.rampMask.clear(),this.lightsMask.clear();for(const r of this.ramps){const a=J_(r,s,i,t,e,o);this.rampMask.poly(a),this.lightsMask.poly(a)}this.rampMask.fill(Ws),this.lightsMask.fill(Ws)}for(const{graphics:s,volume:i}of this.topGroups)te(s,t,(this.level+i)*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){l0(this.pool,this.lights,t.filter(e=>!e.fan)),h0(this.fanPool,this.lights,t.filter(e=>e.fan))}layoutWashes(t,e,s){Qi(this.washPool,this.lights,t.length);for(let i=0;i<this.washPool.length;i+=1){const o=this.washPool[i],r=t[i];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;tr(h,a.base,a.heights,e,s),l.positions=h;const{normals:c,mids:u}=a,d=l.indices;let f=!1;for(let p=0;p<o.facing.length;p+=1){const _=e&&c[p*2]*(e.x-u[p*2])+c[p*2+1]*(e.y-u[p*2+1])>0?1:0;if(o.facing[p]!==_){o.facing[p]=_,f=!0;for(let m=0;m<6;m+=1)d[p*6+m]=_?a.indices[p*6+m]:p*4}}f&&(l.indices=d),Ji(o,r)}}layoutRampLights(t,e,s){Qi(this.rampLightPool,this.rampLights,t.length);for(let i=0;i<this.rampLightPool.length;i+=1){const o=this.rampLightPool[i],r=t[i];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;tr(h,a.base,a.heights,e,s),l.positions=h,Ji(o,r)}}layoutShafts(t){for(;this.shaftPool.length<t.length;){const e=new rt,s=new nt,i=new ft;s.anchor.set(.5),s.blendMode="add",e.addChild(s,i),this.shafts.addChild(e),this.shaftPool.push({container:e,sprite:s,shadow:i,masked:!1})}for(let e=0;e<this.shaftPool.length;e+=1){const s=this.shaftPool[e],i=t[e];if(!i){s.container.visible=!1;continue}const{container:o,sprite:r,shadow:a}=s,l=i.shadows||[];o.visible=!0,r.texture=i.texture,r.position.set(i.x,i.y),r.scale.set(i.scale),r.rotation=i.rotation,r.tint=i.color,r.alpha=i.alpha,a.clear();for(const c of l)a.poly(c);l.length&&a.fill(Ws);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),Yi(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=Js.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 ya(n,t){return n.levels.has(t)||n.roofLevels.has(t)}function Qi(n,t,e){for(;n.length<e;){const s=new Oa({positions:new Float32Array(6),uvs:new Float32Array(6),indices:new Uint32Array(3)}),i=new ur({geometry:s,texture:Js.EMPTY});i.blendMode="add",n.push(i),t.addChild(i)}}function Ji(n,t){n.visible=!0,n.texture=t.texture,n.tint=t.color,n.alpha=t.alpha}function tr(n,t,e,s,i){for(let o=0;o<e.length;o+=1){const r=t[o*2],a=t[o*2+1],l=s?e[o]*i:0;n[o*2]=s?r+(r-s.x)*l:r,n[o*2+1]=s?a+(a-s.y)*l:a}}function l0(n,t,e){for(;n.length<e.length;){const s=new nt;s.blendMode="add",n.push(s),t.addChild(s)}for(let s=0;s<n.length;s+=1){const i=n[s],o=e[s];if(!o){i.visible=!1;continue}i.visible=!0,i.texture=o.texture,i.anchor.set(o.anchorX,o.anchorY),i.position.set(o.x,o.y),i.scale.set(o.scaleX,o.scaleY),i.rotation=o.rotation,i.tint=o.color,i.alpha=o.alpha}}function h0(n,t,e){Qi(n,t,e.length);for(let s=0;s<n.length;s+=1){const i=n[s],o=e[s];if(!o){i.visible=!1;continue}const{fan:r}=o,{shape:a}=r;if(i.shape!==a){const l=i.geometry,h=a.points.length/2-1,c=`${h}:${!!a.closed}`;i.topology!==c&&(l.indices=xa(h,a.closed),i.topology=c),l.positions=a.points,l.uvs=a.uvs,i.shape=a}Ji(i,o),i.position.set(r.x,r.y),i.scale.set(r.scale)}}const c0=.6;function u0({getMap:n,cfg:t}){const e=new WeakMap;let s=0;const i=(f,p)=>{const _=n();_.blockers=new Map,_.rampCells=new Map,s+=1;const{cols:m,rows:g}=_;if(!(m>0&&g>0))return;const w=(M,S)=>M>=0&&M<m&&S>=0&&S<g;for(const[M,S]of f){let b=null;for(const{cells:y,volume:v}of S)for(const[z,L]of y)w(z,L)&&(b||=new Float32Array(m*g),b[L*m+z]=Math.max(b[L*m+z],v));b&&_.blockers.set(M,b)}for(const[M,S]of p){const b=[...S.values()].flat();if(!b.length)continue;const y=new Int32Array(m*g);b.forEach((v,z)=>{for(let L=v.row0;L<v.row1;L+=1)for(let T=v.col0;T<v.col1;T+=1)w(T,L)&&(y[L*m+T]=z+1)}),_.rampCells.set(M,{cells:y,lanes:b})}},o=f=>{const p=n(),_=f.level??0,m=p.blockers.get(_)||null,{cols:g,rows:w}=p,{cellW:M,cellH:S}=p,b=(L,T)=>L>=0&&L<g&&T>=0&&T<w?T*g+L:-1,y=p.rampCells.get(_)||null;if(!m&&!y)return null;const v=L=>y&&L>=0&&y.cells[L]>0?y.lanes[y.cells[L]-1]:null,z=v(b(Math.floor(f.x/M),Math.floor(f.y/S)));return(L,T,E,G,H,K)=>{const J=b(L,T);if(m&&J>=0&&m[J]>0)return!0;if(!y||E===null||E===void 0)return!1;const $=v(J),B=v(b(E,G));return z&&($===z||B===z)?!1:e0({lane:$,prevLane:B,col:L,row:T,prevCol:E,prevRow:G,x:H,y:K,z:f.z??_,cellW:M,cellH:S})}},r=(f,p,_,m,g)=>{const w=n(),M=f.level??0,{cols:S,rows:b}=w,{cellW:y,cellH:v}=w,z=Math.cos(p),L=Math.sin(p);let T=1/0,E=1/0,G=-1/0,H=-1/0;for(const I of[-m,_])for(const at of[-g,g]){const N=f.x+I*z-at*L,It=f.y+I*L+at*z;T=Math.min(T,N),E=Math.min(E,It),G=Math.max(G,N),H=Math.max(H,It)}const K=Math.floor(T/y)-1,J=Math.floor(E/v)-1,$=Math.floor(G/y)+1,B=Math.floor(H/v)+1;return Qo(w.blockers.get(M),S,b,K,J,$,B)||Qo(w.rampCells.get(M)?.cells,S,b,K,J,$,B)},a=()=>t.headlights?.occlusion,l=(f,p,_)=>{const m=n(),g=m.blockers.get(f),w=Math.floor(p/m.cellW),M=Math.floor(_/m.cellH);return!g||w<0||w>=m.cols||M<0||M>=m.rows?0:g[M*m.cols+w]},h=(f,p,_)=>{const m=n(),g=m.rampCells.get(f),{cellW:w,cellH:M}=m,S=Math.floor(p/w),b=Math.floor(_/M);if(!g||S<0||S>=m.cols||b<0||b>=m.rows)return 0;const y=g.cells[b*m.cols+S];return y>0?gn(g.lanes[y-1],p,_,w,M)-f:0};return{sync:i,occlusionOf:(f,p)=>{const _=a();if(!_?.enabled||!p||!(f.radius>0))return null;const m=f.level??0,g=f.rotation||0,w=f.spread??.5,M=`${f.x},${f.y},${f.z},${g},${m},${f.radius},${w},${s},${_.rays}`,S=e.get(f);if(S&&S.key===M&&S.texture===p.texture)return S;const b=o(f);if(!b)return null;const y=n(),{cellW:v,cellH:z}=y,L=xn(f,p),T=(L.width-L.margin)*L.sx,E=L.margin*L.sx,G=L.height/2*L.sy;if(!r(f,g,T,E,G)){const N={key:M,texture:p.texture,shape:null,hit:null,wash:null,fan:null};return e.set(f,N),N}const{points:H,clipped:K,closed:J,reaches:$,forward:B}=i0({x:f.x,y:f.y,rotation:g,alongMax:T,alongBack:E,acrossMax:G,rays:_.rays},b,v,z),I=t.headlights?.wash,at={key:M,texture:p.texture,shape:K?{points:H,closed:J,uvs:n0(H,L)}:null,hit:s0(f.x,f.y,Math.cos(g),Math.sin(g),f.radius,b,v,z),fan:{points:H,closed:J,frame:L},wash:I?.intensity>0?r0({x:f.x,y:f.y,points:H,reaches:$,forward:B,uvOf:(N,It)=>yn(N,It,L),wallAt:(N,It)=>Math.max(l(m,N,It),h(m,N,It)),cellW:v,cellH:z,height:I.height,level:m}):null};return e.set(f,at),at},reachesPoint:(f,p,_)=>{if(f.kind!=="cone"||!a()?.enabled)return!0;const m=o(f);if(!m)return!0;const g=Math.hypot(p-f.x,_-f.y);if(g<1e-6)return!0;const w=n();return mn(f.x,f.y,(p-f.x)/g,(_-f.y)/g,g,m,w.cellW,w.cellH)>=g},bounceOf:(f,p)=>{const _=t.headlights?.bounce;if(!_||!(_.intensity>0)||!(_.radius>0)||p.distance>(_.maxDistance??f.radius))return null;const m=f.rotation||0,g=_.radius*c0;return{kind:"radial",level:f.level,levels:f.levels,x:p.x-Math.cos(m)*g,y:p.y-Math.sin(m)*g,z:f.z,radius:_.radius,color:f.color,intensity:(f.intensity??1)*_.intensity*(1-p.distance/f.radius)}}}}function d0({getMap:n,textures:t}){const e=new WeakMap,s=new WeakMap,i=(a,l)=>{const h=`${a.kind},${a.x},${a.y},${a.rotation},${a.radius},${a.spread}`,c=e.get(a);if(c&&c.key===h&&c.texture===l.texture)return c.fan;const u=xn(a,l),d=Math.cos(u.rotation),f=Math.sin(u.rotation),p=-u.margin*u.sx,_=(u.width-u.margin)*u.sx,m=u.height/2*u.sy,g=new Float32Array(10);g[0]=u.x,g[1]=u.y,[[p,-m],[_,-m],[_,m],[p,m]].forEach(([M,S],b)=>{g[(b+1)*2]=u.x+M*d-S*f,g[(b+1)*2+1]=u.y+M*f+S*d});const w={points:g,closed:!0,frame:u};return e.set(a,{key:h,texture:l.texture,fan:w}),w};return{push:(a,l,h,c,u,d)=>{if(!h?.length)return!1;const f=n(),p=c.kind==="cone"?t.cone:t.radial,_=u.rampFan??i(c,p);let m=s.get(_.points);m||(m=new Map,s.set(_.points,m));let g=!1;for(const w of h){m.has(w)||m.set(w,a0({points:_.points,closed:_.closed,lane:w,frame:_.frame,cellW:f.cellW,cellH:f.cellH,segmentsPerCell:Te.rampSegments}));const M=m.get(w);M&&(a.has(l)||a.set(l,[]),a.get(l).push({ramp:M,texture:u.texture,color:u.color,alpha:d}),g=!0)}return g},targets:()=>{const a=new Map;for(const l of n().levels.values())for(const h of l.rampLevels())a.has(h)||a.set(h,[]),a.get(h).push(l.level);return a}}}function f0({getMap:n,lights:t,flashes:e,cfg:s,reachesPoint:i}){let o=null,r=0;const a=(h,c,u,d,f)=>{const p=n(),_=[],m=g=>(g.levels??[g.level??0]).includes(u);for(const g of Wl(p.lampGrid,h,c))g.level===u&&_.push({light:g,factor:ze(g.seed,f,g.flicker)});for(const g of t)g.kind==="cone"&&!d?.includes(g)&&m(g)&&Rr(g,h,c)>0&&i(g,h,c)&&_.push({light:g,factor:1});for(const g of e){const w=Ir(f-g.start,g.duration);w>0&&m(g)&&_.push({light:g,factor:w})}return _};return{lightsAt:(h,c,u,d=1,f=null)=>{if(!(d>0))return[];const p=ot.shared.lastTime;if(o!==p&&(o=p,r=0),r>=s.maxLights)return[];const _=Hl(a(h,c,u,f,p),h,c,d);return _.length&&(r+=1),_},candidatesAt:a}}const _0=.08;function p0({lamp:n,view:t,reach:e,camera:s,shaftsCfg:i,casters:o,shear:r}){if(!i.shadows||!(i.maxShadowCasters>0))return[];const a=n.radius*i.length,l=[];for(const c of o.values()){const u=Math.hypot(c.x-n.x,c.y-n.y);c.level===n.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,i.maxShadowCasters)){const u=(c.z??c.level)*r,d=Lt(c.x,c.y,s,u),f=Vl(t.x,t.y,d.x,d.y,c.radius*(1+u),e);f&&h.push(f)}return h}function m0({map:n,casters:t,cfg:e,asset:s,camera:i,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 d of n.lamps){if(!d.head||!ya(n,d.level))continue;if(u>=e.maxLights)break;const f=Gs(d.x,d.y,d.level,i,a,l),p=d.radius*c.length*f.scale;!(p>0)||!Hi(f.screenX,f.screenY,p*a.scale.x,o.width,o.height)||(h.has(d.level)||h.set(d.level,[]),h.get(d.level).push({texture:s.texture,x:f.x,y:f.y,scale:p*2/s.contentSize,rotation:Nl(d.seed,r,_0),color:d.color,alpha:c.intensity*d.intensity*ze(d.seed,r,d.flicker),shadows:p0({lamp:d,view:f,reach:p,camera:i,shaftsCfg:c,casters:t,shear:l})}),u+=1)}return h}const g0=3818080,x0=["radial","cone","head","glint","shaft"];function y0(n,t,e){const s=(n?.cols??0)*t*e.x,i=(n?.rows??0)*t*e.y,o=Math.max(s,i);return{x:-o,y:-o,width:s+o*2,height:i+o*2}}function w0(n=ie,t={}){const e=!!n.enabled,s=t.levelView||null,i=t.volumes||null,o=t.shear??Q.shear;let r=null,a=null;const l={},h=new Set,c=new Map,u=[],d=new Map;let f=null;const p=new Map;let _=null;const m=new Map,g=new Map;let w=null;const M=new Map;let S=!1,b=null;const y=u0({getMap:()=>_,cfg:n}),v=f0({getMap:()=>_,lights:h,flashes:u,cfg:n,reachesPoint:y.reachesPoint}),z=d0({getMap:()=>_,textures:l}),L=()=>s?.cfg||null,T=(k,P,C,R)=>{let Y=k.get(R);return Y||(Y=new rt,Y.label=`${C}-${R}`,Y.zIndex=it(P,R),Y.eventMode="none",k.set(R,Y)),Y},E=k=>T(_.emissive,Pr,"emissive",k),G=k=>T(_.lampHeads,Rl,"lamp-heads",k),H=()=>{if(!(!_?.night||!l.head||_.headsReady)){_.headsReady=!0;for(const k of _.lamps){if(!k.head)continue;const P=new nt(l.head.texture);P.anchor.set(.5),P.blendMode="add",P.tint=k.color,k.headSprite=P,G(k.level).addChild(P)}}},K=(k,P,C,R)=>{const Y=k||{},yt=!!Y.night,j=As(C??1);if(_={night:yt,ambient:Y.ambient??g0,step:P,scale:j,cellW:P*j.x,cellH:P*j.y,area:y0(R,P,j),cols:R?.cols??0,rows:R?.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},!!yt){(Y.lamps||[]).forEach((dt,Bt)=>{const[pt,he]=dt.cell||[0,0],Nt=dt.level||0,q=Xl(pt,he,P,j);_.lamps.push({kind:"radial",level:Nt,x:q.x,y:q.y,z:Nt,radius:dt.radius??0,rotation:0,color:dt.color??16777215,intensity:dt.intensity??1,flicker:dt.flicker||0,seed:Bt+1,head:!!dt.head,headSprite:null})});for(const[dt,Bt]of c)E(Bt).addChild(dt);_.lampGrid=Bl(_.lamps,Math.max(1,..._.lamps.map(dt=>dt.radius))),H(),S=!0,b=null}},J=()=>{if(_){for(const k of[..._.emissive.values(),..._.lampHeads.values()])k.parent?.removeChild(k);for(const k of B())k.overlay.parent?.removeChild(k.overlay);for(const k of _.emissive.values())for(const P of c.keys())P.parent===k&&k.removeChild(P);for(const k of _.lamps)k.headSprite&&(k.headSprite.destroy({texture:!1,textureSource:!1}),k.headSprite=null);for(const k of[..._.emissive.values(),..._.lampHeads.values()])k.destroy({children:!0});for(const k of B())k.destroy();_=null,b=null}},$=()=>{J(),m.clear(),g.clear(),M.clear(),S=!1,w=null,f=null},B=()=>[..._.levels.values(),..._.roofLevels.values()],I=()=>i?.levels()??new Map,at=()=>i!==null&&i.version!==w,N=(k,P=null)=>{const C=[],R=new Set;for(const Y of k?.values()||[])for(const yt of Y){const j=`${yt[0]},${yt[1]}`;!R.has(j)&&!P?.has(j)&&(R.add(j),C.push(yt))}return[C,R]},It=(k,P,C,R)=>{let Y=k.get(P);if(C.length===0){Y&&(Y.destroy(),k.delete(P));return}Y||(Y=new Jo({level:P,ambient:_.ambient,resolution:n.resolution,area:_.area,roof:R}),k.set(P,Y)),Y.setMask(Xn(C),_.step,_.scale)},Ht=k=>{const P=new Map;for(const{cells:C,volume:R}of I().get(k)||[])P.has(R)||P.set(R,[]),P.get(R).push(...C);return[...P].map(([C,R])=>({volume:C,runs:Xn(R)}))},lt=()=>{at()&&(w=i.version,S=!0);const k=S;if(S){S=!1;const P=new Set([...m.keys(),...g.keys(),..._.levels.keys(),..._.roofLevels.keys()]);for(const C of P){if(C<1)continue;const[R,Y]=N(g.get(C)),[yt,j]=N(m.get(C),Y);_.maskCells.set(C,j),_.roofCells.set(C,Y),It(_.levels,C,yt,!1),It(_.roofLevels,C,R,!0)}}if(_.levels.has(0)||_.levels.set(0,new Jo({level:0,ambient:_.ambient,resolution:n.resolution,area:_.area})),k){y.sync(I(),M);for(const P of _.levels.values())P.setTops(Ht(P.level),_.step,_.scale),P.setRamps([...M.get(P.level)?.values()||[]].flat(),_.step,_.scale,Te.rampSegments)}},ut=()=>{for(const k of B())k.overlay.parent!==r&&r.addChild(k.overlay);for(const k of[..._.emissive.values(),..._.lampHeads.values()])k.parent!==r&&r.addChild(k)},ht=(k,P,C)=>{const R=k.kind==="cone"?l.cone:l.radial;if(!R||!(k.intensity*C>0))return null;const Y=Gs(k.x,k.y,k.z??k.level,P,r,o),yt=xn(k,R),j={reach:k.radius*Y.scale*r.scale.x,view:Y,texture:R.texture,anchorX:yt.margin/yt.width,anchorY:.5,scaleX:yt.sx*Y.scale,scaleY:yt.sy*Y.scale,rotation:yt.rotation,color:k.color,alpha:k.intensity*C};return k.kind==="cone"&&(j.fan=null,j.hit=null),j},ct=(k,P)=>{if(P.kind!=="cone")return;const C=y.occlusionOf(P,l.cone);if(!C)return;const{view:R}=k;C.shape&&(k.fan={shape:C.shape,x:R.x-P.x*R.scale,y:R.y-P.y*R.scale,scale:R.scale}),k.hit=C.hit,k.wash=C.wash,k.rampFan=C.fan},tt=(k,P,C)=>{const R=new Map,Y=new Map,yt=new Map;let j=0;const dt=z.targets(),Bt=n.rampSpill??1,pt=[],he=(q,Ft)=>{const qt=q.levels??[q.level],ce=qt.filter(Ct=>ya(_,Ct)),Qt=Bt>0?qt.flatMap(Ct=>dt.get(Ct)||[]).filter(Ct=>!qt.includes(Ct)):[];if(j>=n.maxLights||ce.length===0&&Qt.length===0)return;const St=ht(q,k,Ft);if(!St||!Hi(St.view.screenX,St.view.screenY,St.reach,P.width,P.height))return;St.x=St.view.x,St.y=St.view.y,ct(St,q);const me=q.level??0;St.wash&&_.levels.has(me)&&(yt.has(me)||yt.set(me,[]),yt.get(me).push({wash:St.wash,texture:St.texture,color:St.color,alpha:St.alpha*n.headlights.wash.intensity}));for(const Ct of ce){if(j>=n.maxLights)return;R.has(Ct)||R.set(Ct,[]),R.get(Ct).push(St),j+=1,z.push(Y,Ct,_.levels.get(Ct)?.ramps,q,St,St.alpha)}for(const Ct of new Set(Qt)){if(j>=n.maxLights)return;const Tt=_.levels.get(Ct)?.ramps.filter(ue=>qt.includes(ue.to));z.push(Y,Ct,Tt,q,St,St.alpha*Bt)&&(j+=1)}const ge=St.hit?y.bounceOf(q,St.hit):null;ge&&pt.push({light:ge,factor:Ft})};for(let q=u.length-1;q>=0;q-=1){const Ft=u[q],qt=Ir(C-Ft.start,Ft.duration);qt<=0?u.splice(q,1):he(Ft,qt)}for(const q of h)he(q,1);for(const q of _.lamps)he(q,ze(q.seed,C,q.flicker));for(const{light:q,factor:Ft}of pt)he(q,Ft);const Nt=m0({map:_,casters:d,cfg:n,asset:l.shaft,camera:k,screen:P,now:C,stage:r,shear:o});for(const q of B())q.place(k,o),q.layout(R.get(q.level)||[]),q.roof||q.layoutWashes(yt.get(q.level)||[],k,o),q.layoutRampLights(q.roof?[]:Y.get(q.level)||[],k,o),q.layoutShafts(Nt.get(q.level)||[])},bt=k=>{const P=L();if(!P)return;const C=Lt(s.x,s.y,k,s.z*o);for(const R of B()){if(R.level<1)continue;const Y=s.level<R.level,yt=R.roof&&Y&&ol(_.roofCells.get(R.level),_.step,_.scale,C,k,[R.level*o],P.roofMargin??0),j=R.overlay,dt=Sr(R.hole,P.fadeRate);if(s.mode==="layer"){let Bt=yt;if(!R.roof){const he=ts(s.x,_.scale.x,_.step),Nt=ts(s.y,_.scale.y,_.step);Bt=Y&&!!_.maskCells.get(R.level)?.has(`${he},${Nt}`)}const pt=Bt?P.layerAlpha:1;j.alpha+=(pt-j.alpha)*dt;continue}an(R.hole,R.roof?yt:Y,dt),ln(j,R.hole,P,s,r,k),R.syncFilters()}},et=(k,P)=>{for(const C of _.lamps){const R=C.headSprite;if(!R)continue;const Y=Gs(C.x,C.y,C.level,k,r,o);R.position.set(Y.x,Y.y),R.scale.set(Y.scale),R.alpha=(s?s.alphaFor(C.level,Y.x,Y.y,0):1)*ze(C.seed,P,C.flicker)}},st=()=>e&&_?.night===!0;return{get enabled(){return e},attachStage(k,P){!e||r||!k||!P||(r=k,a=P,b=null,s?.attachStage(k,P))},acquireMap(k,P,C,R,Y){e&&(p.set(k,(p.get(k)||0)+1),k!==f&&(J(),f=k,K(P,C,R,Y)))},releaseMap(k,P){if(!e)return;if(P!==void 0)for(const R of[m,g,M])for(const Y of R.values())Y.delete(P)&&(S=!0);const C=p.get(k);if(C!==void 0){if(C>1){p.set(k,C-1);return}p.delete(k),k===f&&$()}},setLevelMask(k,P,C,{roof:R=!1}={}){if(!e||!(k>=1))return;const Y=R?g:m;Y.has(k)||Y.set(k,new Map),P&&P.length>0?Y.get(k).set(C,P):Y.get(k).delete(C),S=!0},setRampWedges(k,P,C){if(!e||!(k>=0))return;M.has(k)||M.set(k,new Map);const R=(P||[]).filter(Y=>Y.from===k&&Y.to>Y.from);R.length>0?M.get(k).set(C,R):M.get(k).delete(C),S=!0},registerTextures(k){if(!(!e||!k)){for(const P of x0){const C=k[P];if(!C)continue;const R=l[P];if(l[P]=C,P==="head"&&R&&R!==C){for(const Y of c.keys())Y.texture===R.texture&&(Y.texture=C.texture);for(const Y of _?.lamps||[])Y.headSprite&&(Y.headSprite.texture=C.texture)}}l.head&&H()}},texture(k){return l[k]||null},addLight(k){if(!e)return null;const P={kind:"radial",level:0,x:0,y:0,radius:0,rotation:0,color:16777215,intensity:1,...k};return h.add(P),P},updateLight(k,P){k&&h.has(k)&&Object.assign(k,P)},removeLight(k){h.delete(k)},flash(k){!st()||!l.radial||u.push({kind:"radial",level:0,color:16777215,intensity:1,...k,start:ot.shared.lastTime})},addEmissive(k,P){return!st()||!k?!1:(c.get(k)!==void 0&&k.parent&&k.parent.removeChild(k),c.set(k,P||0),E(P||0).addChild(k),!0)},removeEmissive(k){if(c.has(k)){c.delete(k);for(const P of _?.emissive.values()||[])k.parent===P&&P.removeChild(k)}},isNight:st,lightsAt(k,P,C,R=1,Y=null){return st()?v.lightsAt(k,P,C,R,Y):[]},onScreen(k,P,C,R){if(!r||!a?.screen)return!1;const Y=s?s.camera():At(r,a);if(!Y)return!1;const yt=Gs(k,P,C,Y,r,o);return Hi(yt.screenX,yt.screenY,R*yt.scale*r.scale.x,a.screen.width,a.screen.height)},setCaster(k,P){e&&(P?d.set(k,P):d.delete(k))},castsShadows(){const k=n.shafts;return st()&&!!(k?.enabled&&k.shadows&&k.maxShadowCasters>0)},render(){if(!st()||!r||!a)return;const k=s?s.camera():At(r,a),P=a.screen;if(!k||!P)return;const C=ot.shared.lastTime,R=b;R!==null&&R.tick===C&&R.x===r.position.x&&R.y===r.position.y&&R.scaleX===r.scale.x&&R.scaleY===r.scale.y&&R.width===P.width&&R.height===P.height&&!S&&!at()||(b={tick:C,x:r.position.x,y:r.position.y,scaleX:r.scale.x,scaleY:r.scale.y,width:P.width,height:P.height},lt(),H(),ut(),tt(k,P,C),s&&bt(k),et(k,C))},clear:$}}function v0({segments:n=null}={}){const t=new Map;return{subscribe(e,s){const i=String(e);return t.has(i)||t.set(i,new Set),t.get(i).add(s),()=>{const o=t.get(i);o&&(o.delete(s),o.size===0&&t.delete(i))}},fired(e){const s=t.get(String(e));if(s)for(const i of s)i.fired?.()},muzzle(e){const s=t.get(String(e));if(s)for(const i of s){const o=i.muzzle?.();if(o)return o}return null},path(e,s,i,o,r){const a=Math.hypot(i-e,o-s);if(!n||!(a>.001))return null;const l=n(e,s,(i-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}}}const ci={click:12,squelch:120,deny:120,static:2e3},er=1200,M0=1200,S0=1800,b0=28,k0=[7,9,42,68,111],A0=16,L0=.45,T0=4,z0=1.5,P0=2e3,I0=3,E0=150,C0=4,Ii={noise:.5,high:.3,low:.6},R0=.7,F0=7,O0=400,X0=5e3,D0=3,Y0=20,H0=.01,B0=.35,W0=250,V0=[1,3,5,7],N0=160,U0=90,G0=5,wa=.35,K0=1800,$0=.5,Z0=.04,j0=20;function wn(n){let t=n>>>0;return()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}const ve=(n,t)=>Math.round(n*t/1e3);function zs(n,t){let e=0;for(let s=0;s<n.length;s+=1)e=Math.max(e,Math.abs(n[s]));if(e>0){const s=t/e;for(let i=0;i<n.length;i+=1)n[i]*=s}return n}function va(n,t,e){return e<=0?1:Math.min(1,n/e,(t-1-n)/e)}function Ma(n,t){return new Float32Array(ve(n,t))}function tn(...n){const t=n.reduce((i,o)=>i+o.length,0),e=new Float32Array(t);let s=0;for(const i of n)e.set(i,s),s+=i.length;return e}function q0(n){let t=65535;for(const e of n){t^=e<<8;for(let s=0;s<8;s+=1)t=t&32768?(t<<1^4129)&65535:t<<1&65535}return t}function sr(n){const t=[];for(let e=0;e<n;e+=1)t.push(e%2===0?1:0);return t}function ir(n){const t=[];for(const e of n)for(let s=7;s>=0;s-=1)t.push(e>>s&1);return t}function Q0(n){const t=n&65535,e=[1,128,t>>8,t&255],s=q0(e),i=ir([...e,s>>8,s&255]);return[...sr(b0),...ir(k0),...i,...i.map(o=>1-o),...sr(A0)]}function J0(n,t){const e=Q0(t),s=Math.round(n*e.length/er),i=ve(n,T0),o=new Float32Array(s);let r=0;for(let a=0;a<s;a+=1){const l=Math.min(e.length-1,Math.floor(a*er/n)),h=e[l]===1?M0:S0;r+=2*Math.PI*h/n,o[a]=Math.sin(r)*L0*va(a,s,i)}return o}function nr(n){const t=ve(n,ci.click),e=wn(F0),s=new Float32Array(t);for(let i=0;i<t;i+=1){const o=i/n,r=o*1e3,a=(e()*2-1)*Math.exp(-r/z0),l=Math.sin(2*Math.PI*P0*o)*Math.exp(-r/I0),h=Math.sin(2*Math.PI*E0*o)*Math.exp(-r/C0);s[i]=a*Ii.noise+l*Ii.high+h*Ii.low}return zs(s,R0)}function or(n,t){const e=ve(n,ci.squelch),s=wn(t),i=new Float32Array(e),o=ve(n,D0),r=o+ve(n,Y0),a=Math.exp(-2*Math.PI*O0/n),l=Math.exp(-2*Math.PI*X0/n);let h=0,c=0,u=0;for(let d=0;d<e;d+=1){const f=s()*2-1;c=a*(c+f-h),h=f,u=(1-l)*c+l*u;let p;d<o?p=d/o:d<r?p=1:p=Math.pow(H0,(d-r)/(e-r)),i[d]=u*p}return zs(i,B0)}function Sa(n,t){const e=ve(n,t),s=ve(n,G0),i=new Float32Array(e);for(let o=0;o<e;o+=1){const r=o/n;let a=0;for(const l of V0)a+=Math.sin(2*Math.PI*W0*l*r)/l;i[o]=a*va(o,e,s)}return i}function tp(n){const t=Sa(n,N0);return zs(tn(t,Ma(n,U0),t),wa)}function ep(n){return zs(Sa(n,ci.deny),wa)}function sp(n,t,e,s){const i=2*Math.PI*e/t,o=Math.sin(i)/(2*s),r=1+o,a=o/r,l=-o/r,h=-2*Math.cos(i)/r,c=(1-o)/r,u=new Float32Array(n.length);let d=0,f=0,p=0,_=0;for(let m=0;m<n.length;m+=1){const g=n[m],w=a*g+l*f-h*p-c*_;f=d,d=g,_=p,p=w,u[m]=w}return u}function ip(n,t){const e=ve(n,ci.static),s=ve(n,j0),i=wn(t),o=new Float32Array(e+s);let r=0,a=0,l=0,h=0,c=0,u=0,d=0;for(let _=0;_<o.length;_+=1){const m=i()*2-1;r=.99886*r+m*.0555179,a=.99332*a+m*.0750759,l=.969*l+m*.153852,h=.8665*h+m*.3104856,c=.55*c+m*.5329522,u=-.7616*u-m*.016898,o[_]=r+a+l+h+c+u+d+m*.5362,d=m*.115926}const f=sp(o,n,K0,$0),p=f.slice(0,e);for(let _=0;_<s;_+=1){const m=_/s;p[_]=f[_]*m+f[e+_]*(1-m)}return zs(p,Z0)}const np=256,op=15,rp=.6,ap=1,lp=2,hp=3;function je(n){for(let t=0;t<n.length;t+=1)n[t]*=rp;return n}function cp({sampleRate:n}){const t=e=>je(tn(nr(n),Ma(n,op),J0(n,np+(e??0))));return{talkStart:t,incomingStart:t,talkEnd:()=>je(tn(nr(n),or(n,ap))),incomingEnd:()=>je(or(n,lp)),busy:()=>je(tp(n)),deny:()=>je(ep(n)),bed:()=>je(ip(n,hp))}}const rr=300,ar=3400,Vs=.707,fs={threshold:-30,knee:6,ratio:6,attack:.003,release:.12},up=.7,dp=1800,fp=4,_p=1,pp=2,mp=1;function gp(n=2,t=2048){const e=new Float32Array(t),s=Math.tanh(n);for(let i=0;i<t;i+=1){const o=i/(t-1)*2-1;e[i]=Math.tanh(n*o)/s}return e}function xp(n){const t=n.createGain(),e=n.createGain(),s=(f,p,_)=>{const m=n.createBiquadFilter();return m.type=f,m.frequency.value=p,m.Q.value=_,m},i=s("highpass",rr,Vs),o=s("highpass",rr,Vs),r=s("lowpass",ar,Vs),a=s("lowpass",ar,Vs),l=n.createDynamicsCompressor();l.threshold.value=fs.threshold,l.knee.value=fs.knee,l.ratio.value=fs.ratio,l.attack.value=fs.attack,l.release.value=fs.release;const h=n.createGain();h.gain.value=up;const c=s("peaking",dp,_p);c.gain.value=fp;const u=n.createWaveShaper();u.curve=gp(pp),u.oversample="4x",e.gain.value=mp;const d=[t,i,o,r,a,l,h,c,u,e];for(let f=0;f<d.length-1;f+=1)d[f].connect(d[f+1]);return{input:t,output:e,dispose(){for(const f of d)f.disconnect()}}}function yp(){const n=new Set;return{subscribe(t){return n.add(t),()=>{n.delete(t)}},exploded(t){for(const e of n)e(t)}}}function wp(){const n=new Map;let t=0,e=0,s=null,i=null,o=0;const r=()=>{s=null,i=null,o+=1},a=()=>{s=new Map;for(const{level:l,cells:h,volume:c}of n.values()){s.has(l)||s.set(l,new Map);const u=s.get(l);for(const[d,f]of h){const p=`${d},${f}`;u.set(p,Math.max(u.get(p)||0,c))}}return s};return{setLayerVolume(l,h,c,u,{step:d,scale:f}){const{x:p,y:_}=As(f??1);t=d*p,e=d*_,n.set(u,{level:l||0,cells:h,volume:c}),r()},release(l){n.delete(l)&&r()},get version(){return o},levels(){if(!i){i=new Map;for(const{level:l,cells:h,volume:c}of n.values())i.has(l)||i.set(l,[]),i.get(l).push({cells:h,volume:c})}return i},heightAt(l,h,c){if(!(t>0&&e>0))return 0;const u=(s||a()).get(l||0);return u&&u.get(`${Math.floor(h/t)},${Math.floor(c/e)}`)||0},cellSize(){return{cellW:t,cellH:e}}}}const lr=.5,Ei=(n,t,e)=>Math.min(e,Math.max(t,n)),hr=(n,t,e,s,i)=>(1+e+n*s)*t/i;function vp(n,t,e=n.contentSize){const{shear:s}=Q,i=n.level*s,o=n.top>0?n.top:1,r=n.kind==="soot",a=Math.min(n.size/Zt.levelHeight,o),l=Number.isFinite(n.faceHeight),h=l?n.faceHeight:(dn({x:n.x,y:n.y,camera:t,level:n.level,height:n.height})-i)/s,c=(n.x-t.x)*s,u=(n.y-t.y)*s,d=Math.hypot(c,u);if(d*a<lr)return null;let f,p;if(r)p=l?h:Ei(h,0,o-a),f=Math.min(a,o-p);else if(l)p=h,f=Math.min(a,hr(p,n.size,i,s,d),2*Math.min(p,o-p));else{f=a,p=Ei(h,f/2,o-f/2);for(let T=0;T<3;T+=1)f=Math.min(a,hr(p,n.size,i,s,d)),p=Ei(h,f/2,o-f/2)}if(d*f<lr)return null;const _=i+p*s,m=Lt(n.x,n.y,t,_),g=(1+_)*n.size/n.contentSize,w=f/n.contentSize,M=n.face.axis==="x"?0:g,S=n.face.axis==="x"?g:0,b=-c*w,y=-u*w,v=r?0:n.angle||0,z=Math.cos(v),L=Math.sin(v);return{a:M*z+b*L,b:S*z+y*L,c:-M*L+b*z,d:-S*L+y*z,tx:m.x,ty:m.y,anchorY:r&&e>0?Math.min(1,.5+n.contentSize/2/e):.5,height:p}}function Mp({levelView:n=null,volumes:t=null,generations:e=()=>[0,0],cfg:s=We}={}){const i=Zd(s),o=new Map;let r=null,a=null,l=null,h=null;const c=new Xa,u=()=>{const[M,S]=e();i.syncGeneration(M,S)},d=()=>{h&&!h.destroyed&&h.destroy(),h=null;for(const{layer:M}of o.values())M.destroyed||M.destroy({children:!0});o.clear()},f=M=>{let S=o.get(M);return S?.layer.destroyed&&(o.delete(M),S=null),S?S.layer.parent!==r&&r.addChild(S.layer):(S={layer:_n(r,M),sprites:[],used:0},o.set(M,S)),S},p=(M,S,b)=>{const y=vp(S,b,S.texture.height);if(!y)return;Number.isFinite(S.faceHeight)||(S.faceHeight=y.height);let v=M.sprites[M.used];v||(v=new nt(S.texture),M.layer.addChild(v),M.sprites.push(v)),M.used+=1;const{a:z,b:L,c:T,d:E,tx:G,ty:H,anchorY:K}=y;v.texture=S.texture,v.visible=!0,v.anchor.set(.5,K),v.setFromMatrix(c.set(z,L,T,E,G,H)),v.alpha=(n?.alphaFor?.(S.level,S.x,S.y)??1)*$d(S,s.fade)*S.strength,v.tint=n?.tintFor?.(S.level)??16777215},_=()=>{if(!r||r.destroyed){r=null,o.clear();return}for(const S of o.values())S.used=0;const M=n?.camera?.()??At(r,a);if(M)for(const S of i.marks())ks(S.face,S.x,S.y,M)&&p(f(S.level),S,M);for(const S of o.values())for(let b=S.used;b<S.sprites.length;b+=1)S.sprites[b].visible=!1},m=M=>{u(),i.step(M)},g=M=>{m(M),_()},w=(M,S)=>{!M||M.destroyed||(M!==r&&(d(),r=M),h?.parent!==r&&(h&&!h.destroyed&&h.destroy(),h=new rt,h.onRender=_,r.addChild(h)),S&&(a=S),l||(l=b=>m(b.deltaMS),ot.shared.add(l)))};return{add(M,{parent:S=null,renderer:b=null}={}){if(!M?.texture)return null;u(),w(S,b);const y=t?.heightAt?.(M.level,M.x-(M.face?.nx??0)*.5,M.y-(M.face?.ny??0)*.5);return i.add({...M,top:y>0?y:1})},marks:()=>i.marks(),frame:g,destroy(){l&&(ot.shared.remove(l),l=null),d(),i.clear(),r=null}}}function Sp(){const n=new Map;return{set(t,e,s,i,o){n.set(String(t),{x:e,y:s,angle:i,level:o})},get(t){return n.get(String(t))},delete(t){n.delete(String(t))}}}const bp="bu",kp="h",Ap=5;function Lp(){let n=null,t=0,e=0,s=0,i=0,o=null,r=0;return{note(a){n!==null&&a>n&&(t+=1),n=a},take(){return t===0?!1:(t=0,!0)},markEmpty(){e+=1},takeEmpty(){return e===0?!1:(e=0,!0)},noteSwitches(a){a!==s&&(i+=1),s=a},noteHealth(a){if(a===null){o=null,r=0;return}o!==null&&o-a>=Ap&&(r+=1),o=a},takeHit(){return r===0?!1:(r=0,!0)},takeSwitch(){return i===0?!1:(i=0,!0)}}}function Tp(n,t){for(const e of t??[]){if(typeof e!="string")continue;const[s,i]=e.split(":");if(s===bp)n.note(Number(i)||0);else if(s===kp){const o=i===void 0||i===""?NaN:Number(i);n.noteHealth(Number.isFinite(o)?o:null)}}}const zp=(n,t)=>t>=Math.min(n.from,n.to)&&t<=Math.max(n.from,n.to),vn=(n,t)=>{const e=n.max-n.min,s=e>0?(t-n.min)/e:0,i=n.sign>0?s:1-s;return n.from+(n.to-n.from)*i},ba=(n,t,e)=>{const s=n.axis===0?t:e,i=n.axis===0?e:t;return s>=n.min&&s<=n.max&&i>=n.crossMin&&i<=n.crossMax};function Pp(n,t,e,s){const i=ka(n,t,e,s);return i?vn(i,i.axis===0?e:s):null}function ka(n,t,e,s){return Array.isArray(n)?n.find(i=>zp(i,t)&&ba(i,e,s))??null:null}function Ip(n,t,e,s){const i=ka(n,t,e,s);return i?{height:vn(i,i.axis===0?e:s),axis:i.axis}:null}function Ep(n,t,e,s,i,o,r){if(!Array.isArray(n))return null;const a=2*r,l=e+i*a,h=s+o*a;for(const c of n){if(Math.min(c.from,c.to)!==t||!ba(c,l,h))continue;const u=c.axis===0,d=u?e:s,f=u?s:e,p=u?i:o,_=u?o:i,m=[{coord:c.min,dist:Math.abs(d-c.min),end:!0,d:p},{coord:c.max,dist:Math.abs(d-c.max),end:!0,d:p},{coord:c.crossMin,dist:Math.abs(f-c.crossMin),end:!1,d:_},{coord:c.crossMax,dist:Math.abs(f-c.crossMax),end:!1,d:_}].filter(S=>S.dist<=r&&Math.abs(S.d)>1e-9);if(m.length===0)continue;const g=m.reduce((S,b)=>b.dist<S.dist?b:S),w=g.end===u?"x":"y",M=g.d>0?-1:1;return{face:{axis:w,coord:g.coord,nx:w==="x"?M:0,ny:w==="y"?M:0},volume:vn(c,u?l:h)-t}}return null}const Cp=[[0,-1],[0,1],[-1,0],[1,0]],Ci=new WeakMap;function Ns(n){return Ci.has(n)||Ci.set(n,Lp()),Ci.get(n)}const Op={id:"tanks",engineApi:Da,requires:["map.layers","map.levelsN","map.levelHeight","map.gameData","map.bodyState","menu.personal","actor.forget","match.reset","state.persist","vote.hold","panel.cells"],async createClientCore(n,{wasmUrl:t}){if(j_(t)){const s=await q_(t);return{core:new s.ClientCore(n),memory:null}}const e=await Ga({module_or_path:t});return{core:new Xi(n),memory:e.memory}},parts:__,bakers:Z_,styles:Ka,serviceNames:["levelView","mapDynamics","rampRuns","surfaces","volumes","lighting","shots","blasts","muzzles","shopSounds","throwAim","wallMarks"],hooks:{services(n){const t=Q_(),e=wp(),s=w0(void 0,{levelView:t,volumes:e});let i=[],o=null;const r=()=>{const h=n.map_generation();return h!==o&&(o=h,i=JSON.parse(n.ramp_runs())),i};let a=[],l=null;return{levelView:t,lighting:s,shots:v0({segments:(h,c,u,d,f,p)=>n.shot_segments(h,c,u,d,f,p)}),blasts:yp(),wallMarks:Mp({levelView:t,volumes:e,generations:()=>[n.reset_generation(),n.map_generation()]}),muzzles:Sp(),shopSounds:Ns(n),throwAim:{get(){const h=n.throw_aim();return h.length===0?null:{range:h[0],radius:h[1],fraction:h[2]}},wallAt(h,c,u,d,f,p){const _=n.throw_wall(h,c,u,d,f,p);return _.length===0?null:_[0]}},volumes:e,mapDynamics:{toWorld(h,c,u){const d=n.map_dynamics_to_world(h,c,u);return d.length===0?null:{x:d[0],y:d[1]}}},rampRuns:{forLevel(h){return r().filter(c=>c.from===h)},heightAt(h,c,u){return Pp(r(),h,c,u)},slopeAt(h,c,u){return Ip(r(),h,c,u)},faceAt(h,c,u,d,f,p){return Ep(r(),h,c,u,d,f,p)},floorAt(h,c,u){return n.floor_level(h,c,u)}},surfaces:{kindAt(h,c,u){const d=n.surface_at(h,c,u);if(d<0)return null;const f=n.map_generation();return f!==l&&(l=f,a=JSON.parse(n.surface_types())),a[d]??null},dirAt(h,c,u){return Cp[n.surface_dir_at(h,c,u)]??null}}}},voiceSounds:n=>cp(n),voiceFilter:n=>xp(n),onAuth(n,t){n.set_model(t.model)},onPanel(n,t){n.sync_panel(JSON.stringify(t)),Tp(Ns(n),t)},onLocalAction(n,t,e,s){if(t!=="down")return null;if(e==="slot1"||e==="slot2"||e==="slot3")return Ns(n).noteSwitches(n.slot_switches()),null;if(e==="fire"){const i=n.try_fire(s)||null;return!i&&n.empty_fire(s)&&Ns(n).markEmpty(),i}return null}}};export{Op as default};