@korial29/tiny-fps 0.113.0 → 0.114.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/local.js CHANGED
@@ -1 +1 @@
1
- var e=.4,t=1.8,n=.9,r=7.5,i=.5,a=5.5,o=2.5,s=[`#ff3d4f`,`#2f80ff`],c=.12,l=[{ticks:28,strike:10,reach:2.65,arc:.3,hp:2,hold:8},{ticks:34,strike:13,reach:2.15,arc:1.2,hp:2,hold:4},{ticks:34,strike:13,reach:2.15,arc:1.2,hp:2,hold:4},{ticks:40,strike:16,reach:2.15,arc:.45,hp:3,hold:11},{ticks:36,strike:12,reach:3.2,arc:.3,hp:3,hold:-1},{ticks:46,strike:20,reach:2.15,arc:.6,hp:3,hold:-1},{ticks:46,strike:20,reach:2.15,arc:.6,hp:3,hold:-1},{ticks:58,strike:40,reach:2.4,arc:.6,hp:4,hold:-1}],[u,d,f]=[1.8,15,60],[p,m,h]=[2,.5,1.4],[g,_,v]=[24,15,.6],[y,b]=[63,7],x=7.5,[ee,S,C]=[.82,.45,.12],te=.012,ne={maxPlayers:16,scoreLimit:3,timeLimit:480,map:`highline`},w={HOME:0,CARRIED:1,DROPPED:2},T={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128,FIRE:256,BLADE:512,SPECIAL:1024,RAIL:2048,RELOAD:4096,RIFLE:8192,USE:16384},E={THRUST:0,LEFT:1,RIGHT:2,SLASH:3,LUNGE:4,ARC_L:5,ARC_R:6,LEAP:7},D={NONE:0,HEAD:1,ARM_L:2,ARM_R:3,LEG_L:4,LEG_R:5},O={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6,RIDE:7},k={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},A={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512,RESPAWN:1024},j={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7,CONCRETE:8,GLASS:9,STEEL:10,PAINT:11,ROCK:12},re=[`x`,`y`,`z`,`vx`,`vy`,`vz`,`yaw`,`pitch`,`roll`,`wy`,`wp`,`wr`,`steer`],ie=127,ae=16,oe=32,se=128/Math.PI,ce=254/Math.PI,le=65536/(2*Math.PI),ue=e=>Math.round(e*le)&65535,de=e=>Math.max(-32768,Math.min(32767,Math.round(e))),fe=e=>de(e*1e4),pe=e=>e/1e4,me=e=>e/le,he=e=>{if(e.byteLength!==12)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint16(3)&32767,yaw:me(t.getUint16(5)),pitch:pe(t.getInt16(7)),view:(t.getUint16(9)*256+t.getUint8(11))/256}:null},ge=e=>e===w.CARRIED?2:e===w.DROPPED?8:1,_e=e=>{let t=(e.rovers??[]).slice(0,7),n=4+62*e.players.length,r=n+54*t.length,i=e.balls??[],a=r+10+e.flags.reduce((e,t)=>e+ge(t.state),0),o=new DataView(new ArrayBuffer(a+(i.length&&1+11*i.length)));o.setUint8(0,2),o.setUint16(1,e.tick&65535),o.setUint8(3,e.players.length|t.length<<5),e.players.forEach((e,t)=>{let n=4+t*62;o.setUint8(n,e.id),o.setFloat32(n+1,e.x),o.setFloat32(n+5,e.y),o.setFloat32(n+9,e.z),o.setFloat32(n+13,e.vx),o.setFloat32(n+17,e.vy),o.setFloat32(n+21,e.vz),o.setFloat32(n+25,e.edge),o.setUint16(n+29,ue(e.yaw)),o.setInt16(n+31,fe(e.pitch)),o.setUint16(n+33,e.ack&65535),o.setUint8(n+35,e.mode&7|(e.wall&7)<<3|(e.jumps&1)<<6|e.dashes<<7),o.setUint8(n+36,e.t),o.setUint8(n+37,e.dash|(e.by>>2&3)<<6),o.setUint8(n+38,e.coyote&7|(e.buffer&7)<<3|(e.held&T.JUMP?64:0)|(e.held&T.DASH?128:0)),o.setUint8(n+39,e.stun|(e.by&3)<<6);let r=e.hp|e.cool<<3|(e.ammo<0?ie:e.ammo)<<6|e.down<<13|!!e.rack<<20|!!e.blade<<21|!!e.wield<<22|!!e.zap<<23;o.setUint8(n+40,r>>16),o.setUint16(n+41,r&65535),o.setUint8(n+43,e.shots),o.setUint8(n+44,e.hits),o.setUint8(n+45,(e.swing??0)&63|((e.cut??0)&3)<<6),o.setUint8(n+46,(e.lost??0)&7|((e.cut??0)&4)<<1|(e.fried?16:0)|(e.heavy?32:0)),o.setUint8(n+47,e.charge??0),o.setUint8(n+48,e.lock??0),o.setUint8(n+49,(e.foe??0)&15|(e.pressed?128:0)),o.setUint8(n+50,e.pushes??0),o.setUint8(n+51,e.away??0),o.setUint8(n+52,(e.rail??-1)+1),o.setUint8(n+53,+!!e.railed|!!e.inRail<<1|!!e.zapping<<2|!!e.rifled<<3|!!e.inRifle<<4|!!e.hot<<5|(e.held&T.USE?64:0)),o.setUint8(n+54,e.slow??0),o.setUint8(n+55,e.mag??0),o.setUint8(n+56,e.cap??0),o.setUint8(n+57,e.reload??0),o.setUint8(n+58,(e.rifle??-1)+1),o.setUint8(n+59,e.clip??0),o.setUint8(n+60,e.heat??0),o.setUint8(n+61,(e.nades??0)<<6|(e.lob??0))}),t.forEach((e,t)=>{let r=n+t*54;re.forEach((t,n)=>o.setFloat32(r+4*n,e[t])),o.setUint8(r+52,e.driver),o.setUint8(r+53,e.rider)}),o.setUint8(r,e.score[0]),o.setUint8(r+1,e.score[1]),o.setUint16(r+2,e.clock&32767|(e.over?32768:0));let s=e.packs??0;o.setUint16(r+4,Math.floor(s/2**32)),o.setUint32(r+6,s%2**32);let c=r+10;for(let t of e.flags)o.setUint8(c,t.state),t.state===w.CARRIED?o.setUint8(c+1,t.by):t.state===w.DROPPED&&(o.setInt16(c+1,de(t.x*ae)),o.setInt16(c+3,de(t.y*ae)),o.setInt16(c+5,de(t.z*ae)),o.setUint8(c+7,Math.min(255,t.left))),c+=ge(t.state);i.length&&o.setUint8(c++,i.length);for(let e of i)o.setUint8(c,e.id),o.setUint8(c+1,e.by&127|(e.burst?128:0)),[e.x,e.y,e.z].forEach((e,t)=>o.setInt16(c+2+2*t,de(e*oe))),o.setUint8(c+8,Math.round(Math.atan2(-e.dx,-e.dz)*se)&255),o.setInt8(c+9,Math.round(Math.asin(Math.max(-1,Math.min(1,e.dy)))*ce)),o.setUint8(c+10,e.arc?128|e.arc:e.power===7?64|Math.min(63,Math.round(e.v)):e.power??1),c+=11;return o.buffer},ve=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},ye=(e,t,n)=>{let r=Math.imul(e,374761393)+Math.imul(t,668265263)+Math.imul(n,144665)|0;return r=Math.imul(r^r>>>13,1274126177),((r^r>>>16)>>>0)/4294967296},M=(e,t,n)=>{let[r,i]=[Math.floor(e),Math.floor(t)],[a,o]=[e-r,t-i].map(e=>e*e*(3-2*e)),s=(e,t)=>ye(r+e,i+t,n);return(s(0,0)*(1-a)+s(1,0)*a)*(1-o)+(s(0,1)*(1-a)+s(1,1)*a)*o},be=/* @__PURE__ */ new WeakMap,xe=e=>{let t=be.get(e);if(t)return t;let{hole:n,bound:r,cell:i,at:a,pits:o=[]}=e,s=o.reduce((e,t)=>[Math.min(e[0],t[0]),Math.min(e[1],t[1]),Math.max(e[2],t[2]),Math.max(e[3],t[3])],[1/0,1/0,-1/0,-1/0]),[c,l,u,d]=r,f=Math.floor((c-u)/i)*i,p=Math.floor((l-d)/i)*i,m=Math.ceil((c+u-f)/i)+1,h=Math.ceil((l+d-p)/i)+1,g=new Float32Array(m*h),_=-1/0;for(let e=0;e<h;e++)for(let t=0;t<m;t++)g[t+e*m]=a(f+t*i,p+e*i),_=Math.max(_,g[t+e*m]);let v=new Uint8Array(m*h);for(let[e,t,n,r]of o)for(let a=Math.floor((t-p)/i)-1;a<=Math.floor((r-p)/i)+1;a++)for(let t=Math.floor((e-f)/i)-1;t<=Math.floor((n-f)/i)+1;t++)t>=0&&a>=0&&t<m&&a<h&&(v[t+a*m]=1);let y={x0:f,z0:p,cell:i,nx:m,nz:h,h:g,hole:n,pits:o,pitted:v,box:s,bound:r,top:_};return be.set(e,y),y},Se=(e,t,n)=>{let r=e.relief;if(!r||t>r.hole[0]&&t<r.hole[2]&&n>r.hole[1]&&n<r.hole[3])return-1/0;let i=Math.min(Math.max((t-r.x0)/r.cell,0),r.nx-1),a=Math.min(Math.max((n-r.z0)/r.cell,0),r.nz-1),o=Math.min(Math.floor(i),r.nx-2),s=Math.min(Math.floor(a),r.nz-2);if(r.pitted[o+s*r.nx]&&r.pits.some(e=>t>=e[0]&&t<=e[2]&&n>=e[1]&&n<=e[3]))return-1/0;let[c,l]=[i-o,a-s],u=o+s*r.nx,[d,f,p,m]=[r.h[u],r.h[u+1],r.h[u+r.nx],r.h[u+r.nx+1]];return c>=l?d+(f-d)*c+(m-f)*l:d+(p-d)*l+(m-p)*c},Ce=(e,t)=>{if(!t.relief)return;let[n,r,i,a]=t.relief.bound,[o,s]=[(e.x-n)/i,(e.z-r)/a],c=o*o+s*s;if(c<=1)return;let l=1/Math.sqrt(c);e.x=n+o*l*i,e.z=r+s*l*a;let[u,d]=[o*l/i,s*l/a],f=(e.vx*u+e.vz*d)/(u*u+d*d);f>0&&(e.vx-=f*u,e.vz-=f*d)},we=1,Te=6,Ee=(e,t,n,r,i=0)=>{let a=e.relief;if(!a||Math.min(t[1],t[1]+n[1]*r)-i>a.top)return r;let[o,s]=[0,r];for(let e of[0,1]){let[r,i,c,l]=[t[e*2],n[e*2],a.hole[e],a.hole[e+2]];if(i){let[e,t]=[(c-r)/i,(l-r)/i];o=Math.max(o,Math.min(e,t)),s=Math.min(s,Math.max(e,t))}else(r<=c||r>=l)&&(s=-1)}let c=r=>t[1]+n[1]*r-i-Se(e,t[0]+n[0]*r,t[2]+n[2]*r);if(!n[0]&&!n[2]){let e=c(0);return e<0?0:n[1]<0?Math.min(r,e/-n[1]):r}for(let[e,t]of o<s?[[0,o],[s,r]]:[[0,r]]){if(e<t&&c(e)<0)return e;for(let n=e;n<t;n+=we){let e=Math.min(n+we,t);if(c(e)<0){let[t,r]=[n,e];for(let e=0;e<Te;e++){let e=(t+r)/2;c(e)<0?r=e:t=e}return t}}}return r},De=4,Oe=1024,ke=(e,t)=>(e+Oe)*(2*Oe)+t+Oe,Ae=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),je=(e,t=De)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=Ae(e[0],t);a<=Ae(r[0],t);a++)for(let o=Ae(e[2],t);o<=Ae(r[2],t);o++){let e=ke(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),e.relief?{def:e,cell:t,grid:n,relief:xe(e.relief)}:{def:e,cell:t,grid:n}},Me=(e,t,n,r)=>{let i=[];for(let a=Ae(t-r,e.cell);a<=Ae(t+r,e.cell);a++)for(let t=Ae(n-r,e.cell);t<=Ae(n+r,e.cell);t++)for(let n of e.grid.get(ke(a,t))??[])i.includes(n)||i.push(n);return i},Ne=(e,t,n,r,i=0)=>{let a=Pe(e,t,n,r,i);return e.relief?Ee(e,t,n,a,i):a},Pe=(e,t,n,r,i)=>{let{cell:a,def:o}=e,s=r,c=Ae(t[0],a),l=Ae(t[2],a),u=Math.sign(n[0]),d=Math.sign(n[2]),f=u?((c+ +(u>0))*a-t[0])/n[0]:1/0,p=d?((l+ +(d>0))*a-t[2])/n[2]:1/0,m=f,h=p,g=u?a/Math.abs(n[0]):1/0,_=d?a/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(ke(c,l))??[]){let e=o.brushes[r],[a,c]=[0,s];for(let r=0;r<3&&a<=c;r++){if(!n[r]){(t[r]<e.min[r]-i||t[r]>e.max[r]+i)&&(c=-1);continue}let o=(e.min[r]-i-t[r])/n[r],s=(e.max[r]+i-t[r])/n[r];a=Math.max(a,Math.min(o,s)),c=Math.min(c,Math.max(o,s))}a<=c&&c>0&&a<s&&(s=a)}if(Math.min(m,h)>=s||Math.abs(c)>Oe||Math.abs(l)>Oe)return s;m<h?(c+=u,m+=g):(l+=d,h+=_)}},Fe=(e,t,n)=>{let[r,i,a]=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],o=Math.hypot(r,i,a);return o>0&&Ne(e,t,[r/o,i/o,a/o],o)<o-1e-4},N=1/60,Ie=Math.PI*2,Le=1e-6,P=.01,Re=.001,ze=e=>(e%Ie+Ie)%Ie,F=e=>[-Math.sin(e),-Math.cos(e)],I=Math.fround,Be=Math.sqrt,Ve=(e,t,n)=>Math.min(Math.max(e,t),n),L=(e,t)=>Be(e*e+t*t),He=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],Ue={vx:0,vz:0,mode:O.GROUND,t:0,wall:k.NONE,edge:0,jumps:1,dashes:1,dash:0,stun:0,coyote:6,buffer:0,held:0,hp:5,ammo:-1,cool:0,mag:0,cap:0,reload:0,rack:!1,down:0,shots:0,hits:0,blade:!1,wield:!1,swing:0,cut:0,zap:!1,lost:D.NONE,rail:-1,railed:!1,rifle:-1,clip:0,rifled:!1,nades:0,lob:0,inRifle:!1,inRail:!1,zapping:!1,slow:0,fried:!1,heavy:!1,ev:0,fall:0},We=(e,t,n,r=0)=>{let{spawns:i}=t.def.teams[r],[a,o,s,c]=i[(n%i.length+i.length)%i.length];return{id:e,x:I(a),y:I(o),z:I(s),vy:0,yaw:ze(c),pitch:0,ground:!0,...Ue}},Ge=(e,t,n)=>{let{yaw:r,pitch:i,id:a,shots:o,hits:s}=e;Object.assign(e,We(a,t,a,n),{yaw:r,pitch:i,shots:o,hits:s,ev:e.ev|A.RESPAWN})},Ke=e=>e===O.GROUND||e===O.SLIDE||e===O.CROUCH,R=e=>e.mode===O.SLIDE||e.mode===O.CROUCH?n:t,qe=e=>e.mode===O.SLIDE||e.mode===O.CROUCH?.7:1.6,Je=e=>L(e.vx,e.vz),Ye=(e,t,n)=>e.max[1]>t+.5+P&&e.min[1]<t+n-P,Xe=(e,t,n)=>[t-Ve(t,e.min[0],e.max[0]),n-Ve(n,e.min[2],e.max[2])],Ze=(t,n,r)=>Qe(t,n,r,e),Qe=(e,t,n,r)=>{let{brushes:i}=t.def,a=Me(t,e.x,e.z,2*r),o=(r-Le)**2,[s,c]=[0,0];for(let t=0;t<4;t++){let t=0,l=0,u=0;for(let s of a){let a=i[s];if(!Ye(a,e.y,n))continue;let[c,d]=Xe(a,e.x,e.z),f=c*c+d*d;if(f>=o)continue;if(f){let e=Be(f);r-e>t&&(t=r-e,l=c/e*t,u=d/e*t);continue}let[p,m,h]=[[e.x-a.min[0],-1,0],[a.max[0]-e.x,1,0],[e.z-a.min[2],0,-1],[a.max[2]-e.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);p+r>t&&(t=p+r,[l,u]=[m*t,h*t])}if(!t)break;e.x+=l,e.z+=u,s+=l,c+=u}return[s,c]},$e=(e,t,n)=>{let[[r,i,a],[o,s,c]]=[e.a,e.b],[l,u]=[o-r,c-a],d=l*l+u*u,f=d?Ve(((t-r)*l+(n-a)*u)/d,0,1):0;return[t-r-f*l,n-a-f*u,i+f*(s-i)]},et=(t,n,r)=>{let[i,a]=[0,0];for(let o of n){let[n,s,c]=$e(o,t.x,t.z),l=o.r+e,u=n*n+s*s;if(u>=(l-Le)**2||c+o.h<=t.y+.5+P||c>=t.y+r-P)continue;let d=Be(u),[f,p]=[o.b[0]-o.a[0],o.b[2]-o.a[2]],m=L(f,p),[h,g]=d?[n/d,s/d]:m?[p/m,-f/m]:[1,0];t.x+=h*(l-d),t.z+=g*(l-d),i+=h*(l-d),a+=g*(l-d)}return[i,a]},tt=(t,n,r,i=[])=>{let{brushes:a}=n.def,o=(e-Le)**2,s=Se(n,t.x,t.z),c=1/0;for(let i of Me(n,t.x,t.z,e)){let e=a[i],[n,l]=Xe(e,t.x,t.z);n*n+l*l>=o||(e.max[1]<=t.y+.5+P?s=Math.max(s,e.max[1]):e.min[1]>=t.y+r-P&&(c=Math.min(c,e.min[1])))}for(let e of i){let[n,i,a]=$e(e,t.x,t.z);n*n+i*i>=(e.r+.4-Le)**2||(a+e.h<=t.y+.5+P?s=Math.max(s,a+e.h):a>=t.y+r-P&&(c=Math.min(c,a)))}return[s,c]},nt=(e,t,n,r)=>{let i=Se(e,t,n);for(let a of Me(e,t,n,0)){let{min:o,max:s}=e.def.brushes[a];t>=o[0]&&t<=s[0]&&n>=o[2]&&n<=s[2]&&s[1]<=r&&(i=Math.max(i,s[1]))}return i},rt=(t,n)=>{let r=(e-Le)**2;return Me(n,t.x,t.z,e).every(e=>{let i=n.def.brushes[e],[a,o]=Xe(i,t.x,t.z);return a*a+o*o>=r||!Ye(i,t.y,1.8)})},it=(t,n,r,i,a)=>{let o=(e-Le)**2;return Me(t,n,r,e).every(e=>{let s=t.def.brushes[e],[c,l]=Xe(s,n,r);return c*c+l*l>=o||s.max[1]<=i||s.min[1]>=a})},at=(e,t)=>{let[n,r]=He[t],i=n?0:2;return{a:i,o:2-i,sign:n||r,c:n?e.x:e.z,co:n?e.z:e.x}},ot=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=at(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-Re&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},st=(t,n,r)=>{let a;for(let o of Me(n,t.x,t.z,e+i)){let s=n.def.brushes[o],c=ot(s,t,r,i);c!==void 0&&s.min[1]<t.y+.5&&s.max[1]>t.y+1.8&&(a=Math.min(a??1/0,Math.max(0,c-e)))}return a},ct=(t,n)=>{let[r,i]=F(t.yaw),a;for(let o=1;o<=4;o++){let[s,c]=He[o];if(o===t.wall||r*s+i*c<.5)continue;let{a:l,sign:u}=at(t,o);for(let r of Me(n,t.x,t.z,e+.2)){let i=n.def.brushes[r],s=i.max[1],c=s-t.y;if(ot(i,t,o,.2)===void 0||c<1.2||c>2.4||i.min[1]>s-.25||a&&a.top>=s)continue;let d=u>0?i.min[l]:i.max[l],f=d-u*(e+.03),p=d+u*.2,[m,h]=l===0?[f,t.z]:[t.x,f],[g,_]=l===0?[p,t.z]:[t.x,p];it(n,m,h,Math.min(t.y,s-2)+P,s+1.8)&&it(n,g,_,s+P,s+1.8)&&(a={side:o,top:s,hang:f})}}return a},lt=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=at(e,e.wall);return Me(t,e.x,e.z,0).some(s=>{let c=t.def.brushes[s],l=i>0?a-c.min[n]:c.max[n]-a;return I(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},ut=e=>20*(e.def.gravity??1),dt=(e,n)=>{if(e.vy>=0)return!1;let[r]=tt(e,n,t),i=6*N;return e.y-r<=-e.vy*i+.5*ut(n)*i*i},z=(e,t)=>{e.mode=t,e.t=0},ft=e=>!!e.zap&&e.stun>24,pt=(e,t,n,r=48,i=6)=>{e.stun=r,e.vx=I(t*i),e.vz=I(n*i),e.dash=Math.min(e.dash,50),e.coyote=0,e.buffer=0,(e.mode===O.HANG||e.mode===O.CLIMB)&&(e.vy=0),(e.mode===O.HANG||e.mode===O.CLIMB||e.mode===O.WALLRUN||e.mode===O.RIDE)&&(z(e,O.AIR),e.edge=0)},mt=(e,t)=>{let n=L(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},ht=(t,n,r,i)=>{let[a,o]=[r.wx,r.wz];for(let r of Me(n,t.x,t.z,e+Re)){let e=n.def.brushes[r],[s,c]=Xe(e,t.x,t.z),l=L(s,c);if(l>0&&l<=.4+Re&&Ye(e,t.y,i)){let e=(-a*s-o*c)/l;e>0&&(a+=e*s/l,o+=e*c/l)}}return[a,o]},gt=(e,t,n)=>{let r=L(t[0],t[1]);if(r<Le){let t=L(e.vx,e.vz),n=t?Math.max(0,t-45*N)/t:0;e.vx*=n,e.vz*=n;return}let[i,a]=[t[0]/r,t[1]/r],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a],l=L(s,c);if(l){let e=Math.max(0,l-45*N)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*N):Math.max(n,o-12*N),e.vx=s+o*i,e.vz=c+o*a},_t=(e,t,n,r,i,a)=>{let o=e.y;e.x+=e.vx*N,e.z+=e.vz*N;let[s,c]=Ze(e,t,n),[l,u]=et(e,a,n);if(l||u){let[r,i]=Ze(e,t,n);s+=l+r,c+=u+i}let d=L(s,c);if(d){let t=(e.vx*s+e.vz*c)/d;t<0&&(e.vx-=t*s/d,e.vz-=t*c/d)}Ce(e,t);let[f,p]=tt(e,t,n,a),m=e.vy-r*ut(t)*N;if(e.y+=(e.vy+m)/2*N,e.vy=m,e.y+n>p&&(e.y=p-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=f+P:e.y<f){if(e.y=f,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&f>=o-.5)return e.y=f,e.vy=0,0;return-1},vt=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=A.JUMP},yt=(e,n,r)=>{let[i,a]=He[e.wall],o=t=>{z(e,t),e.edge=0};if(r.keys&(T.BACK|T.CROUCH))o(O.AIR),e.coyote=0;else if(r.jump&&r.fx*i+r.fz*a<0)o(O.AIR),e.vx=-i*4,e.vz=-a*4,vt(e,6);else if(r.jump||r.fwd&&e.t>=6)z(e,O.CLIMB);else if(e.t>=30)o(O.AIR),e.coyote=0;else{let r=Math.max(e.edge-2,tt(e,n,t)[0]);e.y+=Ve(r-e.y,-8*N,8*N)}},bt=(e,t)=>{let[n,r]=He[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*N):(e.x+=n*a*N,e.z+=r*a*N),e.y>=e.edge&&lt(e,t)?(z(e,O.GROUND),e.vx=n*3,e.vz=r*3,e.vy=0,e.edge=0,e.wall=k.NONE,e.coyote=6,e.ev|=A.CLIMB):e.t>=40&&(z(e,e.y>=e.edge?O.GROUND:O.AIR),e.edge=0,e.wall=k.NONE)},xt=(e,t,n)=>{let[r,i]=He[e.wall],a=e.vx*r+e.vz*i,[o,s]=[e.vx-a*r,e.vz-a*i],c=L(o,s);if(n.jump)z(e,O.AIR),e.vx=o-r*5,e.vz=s-i*5,vt(e,6.5),e.jumps=1,e.dashes=1,e.ev|=A.WALLRUN_END;else{let a=st(e,t,e.wall);if(a===void 0||!n.fwd||c<3.5||e.t>=60){z(e,O.AIR),e.ev|=A.WALLRUN_END;return}let l=Math.max(0,c-1.5*N)/c;e.vx=o*l,e.vz=s*l;let u=Math.min(a,4*N);e.x+=r*u,e.z+=i*u}},St=(e,t,n)=>{if(!n.fwd)return;let r=L(e.vx,e.vz);if(!(r<4.5))for(let n=1;n<=4;n++){let[i,a]=He[n],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a];if(n!==e.wall&&o<=.75*r&&o>=-.2*r&&st(e,t,n)!==void 0){let t=L(s,c),i=Math.max(t,.9*r)/t;z(e,O.WALLRUN),e.wall=n,[e.vx,e.vz]=[s*i,c*i],e.vy=Ve(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=A.WALLRUN_START;return}}},Ct=(e,t)=>{z(e,O.HANG),e.wall=t.side,e.edge=I(t.top),t.side<=k.WEST?e.x=t.hang:e.z=t.hang,e.vx=e.vy=e.vz=0,e.jumps=1,e.dashes=1,e.coyote=0,e.buffer=0,e.ev|=A.GRAB},wt=(e,t,n)=>{let i=e.mode===O.GROUND;if(n.dash&&e.dash===0&&(i||(e.mode===O.AIR||e.mode===O.WALLRUN)&&e.dashes>0)){let[t,r]=n.wx||n.wz?[n.wx,n.wz]:[n.fx,n.fz];i||(e.dashes--,e.vy=0,e.mode===O.WALLRUN&&(z(e,O.AIR),e.ev|=A.WALLRUN_END)),e.vx=t*16,e.vz=r*16,e.dash=60,e.ev|=A.DASH}let a=e.dash>50;e.mode===O.WALLRUN&&xt(e,t,n),Ke(e.mode)&&Tt(e,t,n,a),e.mode===O.AIR&&Et(e,t,n,a);let o=a&&e.vy<=0?0:e.mode===O.WALLRUN?.15:1,s=e.mode,c=_t(e,t,R(e),o,Ke(s),n.bodies);if(c>=0){if(!Ke(e.mode)){if(e.ev|=A.LAND|(e.mode===O.WALLRUN?A.WALLRUN_END:0),e.fall=c,e.jumps=1,e.dashes=1,e.wall=k.NONE,n.keys&T.CROUCH){let t=L(e.vx,e.vz)>=r;z(e,t?O.SLIDE:O.CROUCH),e.ev|=t?A.SLIDE_START:0}else z(e,O.GROUND)}e.coyote=6}else Ke(e.mode)&&(e.ev|=e.mode===O.SLIDE?A.SLIDE_END:0,z(e,O.AIR));if(e.mode===O.AIR){let r=ct(e,t);r?Ct(e,r):St(e,t,n)}},Tt=(e,i,a,s)=>{let c=(a.keys&T.CROUCH)!==0;if(e.buffer>0&&(e.mode===O.GROUND||rt(e,i))){e.ev|=e.mode===O.SLIDE?A.SLIDE_END:0,z(e,O.AIR),vt(e,7);return}let l=L(e.vx,e.vz);if(e.mode===O.GROUND&&c){let t=l>=r;z(e,t?O.SLIDE:O.CROUCH),e.ev|=t?A.SLIDE_START:0}else e.mode===O.SLIDE&&(e.t>=60||l<4.5||a.stumble)?(e.ev|=A.SLIDE_END,z(e,!c&&rt(e,i)?O.GROUND:O.CROUCH)):e.mode===O.SLIDE&&!c&&rt(e,i)?(e.ev|=A.SLIDE_END,z(e,O.GROUND)):e.mode===O.CROUCH&&!c&&rt(e,i)&&z(e,O.GROUND);if(!s){if(a.stumble){if(l>2.5){let t=Math.max(o,l-12*N)/l;e.vx*=t,e.vz*=t}else gt(e,ht(e,i,a,R(e)),o)}else if(e.mode===O.SLIDE){let t=Math.max(0,l-4*N)/l;e.vx*=t,e.vz*=t}else if(e.mode===O.CROUCH)gt(e,ht(e,i,a,n),3);else{let n=(a.keys&T.SPRINT)!==0&&a.fwd;gt(e,ht(e,i,a,t),n?9:6)}}},Et=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?vt(e,7):e.jumps>0&&!dt(e,t)&&(e.jumps--,vt(e,6),e.ev=e.ev&~A.JUMP|A.DOUBLE)),r||!n.wx&&!n.wz)return;let i=L(e.vx,e.vz);e.vx+=n.wx*14*N,e.vz+=n.wz*14*N,mt(e,Math.max(i,6))},Dt=(e,t,n,r=0,i=[])=>{e.yaw=ze(t.yaw),e.pitch=Math.max(-1.55,Math.min(1.55,t.pitch));let a=(t.keys&T.FORWARD?1:0)-(t.keys&T.BACK?1:0),o=(t.keys&T.RIGHT?1:0)-(t.keys&T.LEFT?1:0),s=ft(e)?1/0:L(a,o)||1,[c,l]=F(e.yaw),u=n=>(t.keys&n)!==0&&(e.held&n)===0,d=e.stun>0,f=e.mode===O.RIDE,p={keys:t.keys,stumble:d,jump:!d&&!f&&u(T.JUMP),dash:!d&&!f&&u(T.DASH),fwd:a>0,wx:(c*a-l*o)/s,wz:(l*a+c*o)/s,fx:c,fz:l,bodies:i},m=e.mode;e.ev=0,e.fall=0,p.jump&&(e.buffer=7),d&&e.stun--,e.dash>0&&(e.dash--,e.dash===50&&mt(e,10)),e.mode===O.HANG&&yt(e,n,p),e.mode===O.CLIMB?bt(e,n):e.mode!==O.HANG&&!f&&wt(e,n,p),e.slow&&(e.slow--,mt(e,3)),e.y<n.def.floor&&Ge(e,n,r),e.t=e.mode===m?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===O.AIR&&m===O.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=t.keys&(T.JUMP|T.DASH|T.USE),e.ground=Ke(e.mode),e.x=I(e.x),e.y=I(e.y),e.z=I(e.z),e.vx=I(e.vx),e.vy=I(e.vy),e.vz=I(e.vz),e.edge=I(e.edge)},Ot=.7,kt=e=>{let[t,n]=[e&T.LEFT,e&T.RIGHT];return t&&!n?E.LEFT:n&&!t?E.RIGHT:e&T.FORWARD?E.THRUST:E.SLASH},At=e=>{let t=l[e.cut??0];return e.heavy?{...t,ticks:Math.round((t.ticks-t.hold)*u),strike:Math.round((t.strike-t.hold)*u),reach:t.reach+m,arc:t.arc*h,hp:t.hp+p}:t},jt=(t,n,r)=>{let{reach:i,arc:a}=At(n),[o,s]=F(n.yaw),c=[n.x,n.y+Ot*R(n),n.z];return r.filter(r=>{let[l,u]=[r.x-n.x,r.z-n.z],d=Math.hypot(l,u);if(d-.4>i||n.y>=r.y+R(r)||r.y>=n.y+R(n))return!1;let f=d>.4?Math.abs(Math.atan2(o*u-s*l,o*l+s*u)):0,p=d>.4?Math.asin(e/d):Math.PI;return f<=a+p&&!Fe(t,c,[r.x,r.y+.7*R(r),r.z])})},Mt=(e,t)=>{if(!t.wield||!t.swing||e.lock||t.lock)return!1;let n=At(t);if(Math.abs(n.strike-(n.ticks-t.swing))>9)return!1;let[r,i]=[t.x-e.x,t.z-e.z],a=Math.hypot(r,i),o=(e,t,n)=>{let[r,i]=F(e.yaw);return a<1e-6||(r*t+i*n)/a>=Math.cos(.9)};return a-.4<=Math.min(n.reach,At(e).reach)&&o(e,r,i)&&o(t,-r,-i)},Nt=e=>{let[t,n]=F(e.yaw),r=e.cut??0;return r===E.LEFT?[-n,t]:r===E.RIGHT?[n,-t]:[t,n]},Pt=(t,n)=>{let[r,i]=F(t.yaw),[a,o]=F(n.yaw),[s,c]=[n.x-t.x,n.z-t.z],l=-i*s+r*c,u=Math.sqrt(Math.max(e*e-l*l,0)),[d,f]=[i*l-r*u,-r*l-i*u],p=-o*d+a*f,m=(t.cut??0)%4;if(m===E.SLASH)return Math.abs(p)<=C?D.HEAD:p>0?D.ARM_R:D.ARM_L;let h=(t.y+Ot*R(t)+Math.tan(t.pitch)*Math.hypot(s,c)-n.y)/R(n);if(h>ee)return D.HEAD;let g=m===E.THRUST?p>0:(m===E.LEFT?1:-1)*(r*a+i*o)<0;return h<S?g?D.LEG_R:D.LEG_L:m===E.THRUST&&Math.abs(p)<=C?D.NONE:g?D.ARM_R:D.ARM_L},Ft=()=>({state:w.HOME,by:0,x:0,y:0,z:0,left:0}),It=60,Lt=class{score=[0,0];over=!1;flags=[Ft(),Ft()];world;rules;mates=/* @__PURE__ */ new Map;clock;back=[0,0];lock=[{id:-1,left:0},{id:-1,left:0}];hold=[0,0];constructor(e,t){this.world=e,this.rules=t,this.clock=t.timeLimit*60}join(e,t,n){this.mates.set(e,{team:t,caps:0,returns:0,ground:[n.x,n.y,n.z]})}leave(e){let t=this.carrying(e),n=this.mates.get(e);t>=0&&n&&this.dropAt(t,n.ground),this.mates.delete(e)}place(e,t){let n=this.mates.get(e);n&&(n.ground=[t.x,t.y,t.z])}moved(e){let t=this.mates.get(e.id);if(!t)return;let n=this.carrying(e.id);e.ev&A.RESPAWN&&n>=0&&this.dropAt(n,t.ground),e.ground&&(t.ground=[e.x,e.y,e.z])}drop(e){let t=this.carrying(e.id),n=this.mates.get(e.id);if(t<0||!n||this.over)return!1;let r=n.ground;if(e.ground)r=[e.x,e.y,e.z];else{let t=Ne(this.world,[e.x,e.y+.05,e.z],[0,-1,0],It);t<It&&(r=[e.x,e.y+.05-t,e.z])}return this.dropAt(t,r),this.lock[t]={id:e.id,left:120},this.hold[t]=120,!0}carrying(e){return this.flags.findIndex(t=>t.state===w.CARRIED&&t.by===e)}winner(){let[e,t]=this.score;return e>t?0:t>e?1:-1}tally(){return[...this.mates].map(([e,t])=>({id:e,caps:t.caps,returns:t.returns}))}reset(){this.over=!1,this.score=[0,0],this.flags=[Ft(),Ft()],this.back=[0,0],this.lock.forEach(e=>e.left=0),this.hold=[0,0],this.clock=this.rules.timeLimit*60;for(let e of this.mates.values())e.caps=e.returns=0}wire(){return{score:[...this.score],clock:Math.ceil(this.clock/60),over:this.over,flags:this.flags.map(e=>({...e}))}}tick(e){if(this.over)return--this.clock<=0?(this.reset(),`start`):void 0;for(let e of[0,1]){let t=this.flags[e];this.lock[e].left--,this.hold[e]--,t.state===w.DROPPED&&(t.left=Math.ceil(--this.back[e]/60),this.back[e]<=0&&(this.flags[e]=Ft()))}for(let t of[0,1]){let n=this.flags[t];if(n.state===w.CARRIED)continue;let r=n.state===w.HOME?this.world.def.teams[t].base:[n.x,n.y,n.z],i=e.filter(e=>Rt(e.state,r)),a=n.state===w.DROPPED&&this.hold[t]<=0?i.find(e=>e.team===t):void 0,o=i.find(e=>e.team!==t&&(e.id!==this.lock[t].id||this.lock[t].left<=0));if(a){let e=this.mates.get(a.id);e&&e.returns++,this.flags[t]=Ft()}else o&&(this.flags[t]={...Ft(),state:w.CARRIED,by:o.id})}for(let t of e){let e=this.carrying(t.id);if(e>=0&&this.flags[t.team].state===w.HOME&&Rt(t.state,this.world.def.teams[t.team].base)){this.score[t.team]++;let n=this.mates.get(t.id);n&&n.caps++,this.flags[e]=Ft()}}if(this.score.some(e=>e>=this.rules.scoreLimit)||--this.clock<=0)return this.over=!0,this.clock=600,`end`}dropAt(e,[t,n,r]){this.flags[e]={state:w.DROPPED,by:0,x:t,y:n,z:r,left:10},this.back[e]=600}},Rt=(e,t)=>Math.hypot(e.x-t[0],e.z-t[2])<1.5&&e.y<t[1]+2.2&&e.y+1.8>t[1],zt=(e,t,n)=>{let[r,i]=[e.x-t[0],e.z-t[2]];return r*r+i*i<n*n&&Math.abs(e.y-t[1])<1},Bt=e=>{if(e.mode===O.GROUND){if(e.cut===E.LUNGE){let[t,n]=F(e.yaw);e.vx=t*13,e.vz=n*13,e.dash=60,e.ev|=A.DASH}else e.cut===E.LEAP&&(e.vy=x,e.ev|=A.JUMP)}},B={NONE:0,SHOT:1,CUT:2,RAIL:3,LASER:4,NADE:5},Vt=(e,t,n,r,i=!0,a=[])=>{let o=e.down>0,s=!o&&(e.lock??0)>0;if(Dt(e,o||s?{...t,keys:0}:t,n,r,a),e.heat=Math.max(0,(e.heat??0)-(e.zapping?0:e.hot?1:2)),e.hot=!!e.hot&&e.heat>0,e.zapping=!1,e.zap=!!e.stun&&!!e.zap,o)return e.down>0&&!--e.down&&Ge(e,n,r),B.NONE;if(s)return Ht(e,t);let{rack:c,blade:u,rail:p,rifle:m}=n.def.teams[r],h=!!c&&zt(e,c,1.2);i&&h&&!e.rack&&([e.ammo,e.mag]=[60,15]),e.rack=h,e.blade=!!e.blade||i&&!!u&&zt(e,u,1.2);let g=!!p&&zt(e,p,1.2);i&&g&&!e.inRail&&([e.rail,e.cap]=[240,80]),e.inRail=g;let _=!!m&&zt(e,m,1.2);i&&_&&!e.inRifle&&([e.rifle,e.clip,e.nades]=[240,60,3]),e.inRifle=_,e.cool=Math.max(0,e.cool-1),e.lob=Math.max(0,(e.lob??0)-1);let v=e.mode===O.HANG||e.mode===O.CLIMB,{ticks:y,hold:b}=l[e.cut??0],x=!!e.swing&&!e.heavy&&y-(e.swing??0)===b;x&&e.wield&&i&&!v&&t.keys&T.FIRE?e.charge=Math.min((e.charge??0)+1,f):x&&i&&!v&&(e.charge??0)>=d?([e.heavy,e.charge]=[!0,0],e.swing=At(e).ticks):(e.charge=x?0:e.charge,e.swing=Math.max(0,(e.swing??0)-1),e.heavy=!!e.swing&&!!e.heavy),e.mag=Math.min(e.mag??0,Math.max(e.ammo,0));let ee=[e.ammo>=0,!!e.blade,(e.rail??-1)>=0,(e.rifle??-1)>=0],S=t.keys&T.BLADE?1:t.keys&T.RAIL?2:t.keys&T.RIFLE?3:0,C=e.swing&&e.blade?1:ee[S]?S:ee.indexOf(!0);if(C!=(e.rifled?3:e.railed?2:+!!e.wield)&&(e.reload=0),[e.wield,e.railed,e.rifled]=[C==1,C==2,C==3],!i)return[e.charge,e.reload]=[0,0],B.NONE;let[te,ne,w,E]=C==3?[`clip`,60,e.rifle,96]:C==2?[`cap`,80,e.rail,90]:[`mag`,15,e.ammo,78],[D,k]=[e[te]??0,Math.min(ne,w)];e.reload?--e.reload||(e[te]=k):C!=1&&w>=0&&!v&&D<k&&(!D||t.keys&T.RELOAD)&&([e.reload,e.charge]=[E,0]);let A=At(e);if(e.swing&&A.ticks-e.swing===A.strike)return B.CUT;if((e.wield&&!x||e.railed||e.rifled||v||e.reload||!e.wield&&!e.mag)&&(e.charge=0),e.rifled&&t.keys&T.SPECIAL&&!v&&e.nades&&!e.lob)return e.nades--,[e.lob,e.cool]=[60,7],e.shots=e.shots+1&255,B.NADE;if(t.keys&T.FIRE&&!v){let n=l[e.cut??0].ticks-(e.swing??0),r=!!(t.keys&T.SPECIAL)&&(!e.swing||!e.heavy&&(e.cut??0)<4&&n<=18);if(e.wield&&(!e.swing||r))e.cut=kt(t.keys)+(r?4:0),[e.swing,e.charge]=[l[e.cut].ticks,0],Bt(e);else if(e.rifled){if(!e.cool&&e.clip&&!e.reload)return e.rifle--,e.clip--,e.cool=3,e.shots=e.shots+1&255,B.LASER}else if(e.railed){if(e.cap&&!e.reload&&!e.hot)return e.heat=(e.heat??0)+1,e.hot=e.heat>=120,e.cool||=(e.rail--,e.cap--,2),e.zapping=!0,B.RAIL}else!e.wield&&!e.cool&&e.mag&&!e.reload&&(e.charge=Math.min((e.charge??0)+1,60))}else if(e.charge)return e.power=Math.min(Ut(e.charge),e.mag),e.charge=0,e.ammo-=e.power,e.mag-=e.power,e.shots=e.shots+1&255,e.cool=7,B.SHOT;return B.NONE},Ht=(e,t)=>{let n=!!(t.keys&T.FIRE);return e.pushes=(e.pushes??0)+ +(n&&!e.pressed)&255,e.pressed=n,e.away=t.keys&(T.LEFT|T.RIGHT|T.BACK)?Math.min((e.away??0)+1,24):0,e.lock=Math.max(1,e.lock-1),[e.wield,e.swing,e.charge]=[!0,0,0],B.NONE},Ut=e=>e<10?1:1+Math.floor(4*(e-10)/50),Wt=-30,V=(e,t,n,r,i,a=j.CONCRETE)=>({min:[e,Wt,t],max:[n,i,r],top:j.CONCRETE,side:a}),H=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c});[V(4,57.7,24,76,10),V(4,36,24,53.5,10,j.GLASS),V(4,20,24,36,12.4),V(4,-5,24,7,12.4,j.GLASS),V(27,20,47,50,8),V(27,60,47,76,8,j.BRICK),H([9,12.2,39],[19,12.6,47],j.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>H([12,t,e-n],[14,t+.4*n,e-n+1],j.CONCRETE)))(53,10),H([5,10,42],[5.5,14,42.5],j.STEEL),H([5,10,50],[5.5,14,50.5],j.STEEL),H([8,12.4,24],[20,12.85,24.45],j.STEEL),H([36,8,22],[37,14.5,48],j.PAINT,j.PAINT,[.15,.72,.62]),H([30,8,28],[34,10,32],j.CONCRETE),H([40,8,30],[44,10.2,34],j.PAINT,j.PAINT,[1,.3,.06]),H([28,9.2,44],[35,12,46],j.STEEL,j.PAINT,[.2,.42,1]),H([41.5,7.6,50],[42,8,60],j.STEEL),H([30,8,64],[34,9.6,68],j.PAINT,j.PAINT,[.2,.8,.3])];var Gt=240,U=[1,.22,.26],Kt=[.2,.46,1],qt=[U,Kt],Jt=[1,.42,.08],Yt=[.12,.7,.62],Xt=(e,t,n,r,i,a,o)=>H([e,t,n],[r,i,a],j.PAINT,j.PAINT,o),Zt=(e,t,n,r,i,a,o,s=Wt)=>{let c=Math.ceil((o-a)/.46);return Array.from({length:c},(l,u)=>{let[d,f]=[t+(n-t)*u/c,t+(n-t)*(u+1)/c].sort((e,t)=>e-t),p=a+(o-a)*(u+1)/c;return e===0?H([d,s,r],[f,p,i],j.CONCRETE):H([r,s,d],[i,p,f],j.CONCRETE)})},Qt=(e,t,n,r,i,a,o)=>o.map((o,s)=>H([e+s*n,a,t+s*r],[e+s*n+4,o,t+s*r+i],j.STEEL,j.CONCRETE)),$t=[V(12,212,52,240,26,j.GLASS),Xt(12,26,212,52,26.12,212.5,U),Xt(12,26,239.5,52,26.12,240,U),Xt(12,26,212.5,12.5,26.12,239.5,U),Xt(51.5,26,212.5,52,26.12,239.5,U),Xt(11.6,12,222,12,25.8,232,U),Xt(28,12,211.4,31,25.5,212,U),H([19,26,222],[22,27.4,225],j.STEEL),H([42,26,222],[45,27.4,225],j.STEEL),H([29,26,229],[35,27.1,229.6],j.CONCRETE),H([24.5,26,215],[35,27.5,219],j.STEEL,j.PAINT,U),V(6,164,26,201,26,j.GLASS),V(6,134,26,147,26,j.GLASS),V(6,201,26,212,19),V(15,147,26,164,19),H([14,26,164],[15,32,196],j.PAINT,j.PAINT,Yt),H([14,18,147],[15,32,164],j.PAINT,j.PAINT,Yt),H([14,26,134],[15,32,147],j.PAINT,j.PAINT,Yt),...Qt(6,201,7,0,4,19,[21.2,23.4,25]),...[[18,152,22,156,21.2],[18,158,22,162,23.4],[23,160,26,164,25]].map(([e,t,n,r,i])=>H([e,19,t],[n,i,r],j.STEEL,j.CONCRETE)),H([20,26,178],[23,27.3,181],j.STEEL),H([8,26,176],[11,27.2,179],j.STEEL),H([8,26,190],[11,27.3,193],j.STEEL),H([20,26,140],[23,27.3,143],j.STEEL),V(32,186,76,209,19),Xt(32,19,207.5,76,19.1,209,U),...Qt(33,209,7,0,3,19,[21.2,23.4,25]),...[[28,196,32,200,21.2],[28,190,32,194,23.4],[26,184,30,188,25]].map(([e,t,n,r,i])=>H([e,Wt,t],[n,i,r],j.STEEL,j.CONCRETE)),V(32,166,64,182,21.2,j.GLASS),V(32,140,64,161,19),H([40,21.2,172],[44,22.6,176],j.STEEL),H([52,19,148],[57,20.3,151],j.STEEL),H([38,19,196],[41,20.4,199],j.STEEL),H([60,19,200],[63,20.4,203],j.STEEL),H([52,19,190],[58,20.6,194],j.STEEL),H([66,19,204],[72,20.2,207],j.STEEL),H([56,21.2,170],[60,22.4,174],j.STEEL),H([34,19,152],[37,20.3,156],j.STEEL),...Qt(36,135,18,0,3,15,[17.2,17.2]),...Qt(6.5,129,6,0,4,15,[17.2,19.4,21.6,23.8]),V(76,213,100,240,14.5,j.STEEL),Xt(76,14.5,238.5,100,14.6,240,U),V(76,185,100,209,14.5),V(76,138,100,181,14.5,j.GLASS),H([80,15.7,158],[96,17.7,162],j.STEEL,j.PAINT,Jt),H([82,14.5,234],[85,15.9,237],j.STEEL),H([91,14.5,190],[94,15.9,193],j.STEEL),H([80,14.5,204],[83,15.6,207],j.STEEL),H([78,14.5,170],[81,15.9,173],j.STEEL),H([92,14.5,146],[95,15.7,149],j.STEEL),H([92,14.5,222],[96,15.8,226],j.STEEL),...Zt(0,76,52,226,232,14.5,26),...Zt(0,85,76,196,202,14.5,19,14.5)],en=[V(6,106,62,134,15),V(62,106,100,134,14.5),H([34,15,112],[54,17.2,128],j.CONCRETE),Xt(38,17.2,116,50,17.3,124,Jt),...[[35,113],[35,126.2],[51,113],[51,126.2]].map(([e,t])=>H([e,17.2,t],[e+.8,21.5,t+.8],j.STEEL)),H([34.6,21.5,112.6],[52.2,21.9,127.4],j.GLASS),H([14,15,114],[17,16.5,117],j.STEEL),H([14,15,123],[17,16.5,126],j.STEEL),H([56,15,114],[59,16.5,117],j.STEEL),H([56,15,123],[59,16.5,126],j.STEEL),H([15.35,25.5,106],[15.85,26,134],j.STEEL),H([70,14.5,108],[70.8,38,108.8],j.STEEL),H([70,14.5,131.2],[70.8,38,132],j.STEEL),H([66,14.5,110],[69,15.9,113],j.STEEL),H([66,14.5,127],[69,15.9,130],j.STEEL)],tn=e=>({...e,min:[e.min[0],e.min[1],Gt-e.max[2]],max:[e.max[0],e.max[1],Gt-e.min[2]],tint:e.tint===U?Kt:e.tint}),nn=(e,t,n)=>[...[16,22,28,34,40].map(n=>[n,26,t,e]),...[19,31,43].map(t=>[t,26,n,e])],rn=[[20,26,190],[48,21.2,172],[48,19,200],[88,14.5,198]],an=[[21,26,168],[16,26,140],[46,19,144],[36,21.2,178],[58,19,156],[64,19,196],[88,14.5,216],[88,14.5,172],[90,14.5,150]],on=[[19.5,26,179],[46,19,152],[39.5,21.2,172],[88,14.5,186],[88,14.5,207]],sn={armor:!0,name:`Highline`,brushes:[...$t,...$t.map(tn),...en],teams:[{base:[32,26,224],spawns:nn(0,236,231),rack:[30.75,27.5,217],blade:[33.25,27.5,217],rail:[28.25,27.5,217],rifle:[25.75,27.5,217]},{base:[32,26,16],spawns:nn(Math.PI,4,9),rack:[30.75,27.5,23],blade:[33.25,27.5,23],rail:[28.25,27.5,23],rifle:[25.75,27.5,23]}],packs:[...rn,...rn.map(([e,t,n])=>[e,t,Gt-n]),[24,15,112],[24,15,128]],ammo:[...an,...an.map(([e,t,n])=>[e,t,Gt-n]),[12,15,116],[12,15,124]],cells:[...on,...on.map(([e,t,n])=>[e,t,Gt-n]),[28,15,Gt/2]],floor:-25,sun:{dir:[.8,.6,0],color:[2.6,2.3,1.8]},sky:[[.04,.2,.72],[.72,.86,.98]],fog:[.72,.86,.98,.0035]},{CONCRETE:cn,METAL:ln,STEEL:W,PAINT:un}=j,G=(e,t,n,r,i,a,o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c}),dn=({min:e,max:t},n,r=n)=>({min:e,max:t,top:n,side:r}),fn=(e,t,n,r,i,a)=>({min:[e,t,n],max:[r,i,a]}),pn=22.4,mn=e=>e<5?pn:pn*Math.sqrt(1-((e-5)/12)**2),hn=e=>Math.round(e*10)/10,gn=[0,10.5,13.5,15.5,17],_n=e=>[[1,.39],[.93,.71],[.71,.93],[.39,1]].map(([t,n])=>[hn(t*e),hn(n*e)]),[[vn,yn],[bn,xn]]=_n(22.599999999999998),[K,Sn]=[.4,2.48],q=[80,236],Cn=[fn(111,0,222,125,5,230),fn(96,0,196,110,5,204)],wn=[fn(102,0,223.2,111,3.5,227.2),fn(98,0,204,102,3.5,227.2)],[[Tn,,En],[Dn,On,kn],[An,,jn],[Mn]]=wn.flatMap(e=>[e.min,e.max]),[[Nn,Pn],[Fn,In]]=[[19.8,6.7],[16,13.5]],Ln=[[0,-Nn,2,3,2.8],[Fn,-10.8,2,3.5,2]],Rn=e=>[...new Map(e.flatMap(([e,t,n,r])=>[1,-1].flatMap(i=>[1,-1].flatMap(a=>[[e,n,t,r],[t,r,e,n]].map(([e,t,n,r])=>[Math.min(i*e,i*t),Math.min(a*n,a*r),Math.max(i*e,i*t),Math.max(a*n,a*r)])))).map(e=>[`${e}`,e])).values()],zn=([e,t,n,r],i,a,o=cn,s=o)=>({...G(q[0]+e,i,q[1]+t,q[0]+n,a,q[1]+r,o,s),ghost:!0}),Bn=(e,t,n,r,i,a,o)=>{let s=Math.ceil((o-a)/.46);return Array.from({length:s},(c,l)=>{let[u,d]=[t+(n-t)*l/s,t+(n-t)*(l+1)/s].sort((e,t)=>e-t),f=a+(o-a)*(l+1)/s;return e?G(r,a,u,i,f,d,cn):G(u,a,r,d,f,i,cn)})},Vn=[...Rn([[12,-In,Fn,In],[Fn,-Pn,Nn,Pn]]).filter(e=>e[1]>-Nn).map(e=>zn(e,3.1,3.5,ln,W)),...Bn(2,q[1]+5.6,q[1]+12,q[0]-1.5,q[0]+1.5,0,3.5).map(e=>({...e,ghost:!0})),zn([-3,19,3,Nn],3.5,4.6,W,ln),zn([-9,12,-2.5,12.5],3.5,4.6,W,un),zn([2.5,12,9,12.5],3.5,4.6,W,un),zn([-9.5,-10,-7.5,-8],0,1.4,W),zn([7.5,-10,9.5,-8],0,1.4,W),zn([7.5,3,10,5.5],0,2.4,W)],{BENCH:Hn,SAMPLES:Un,RACKS:Wn,SCOPE:Gn,ANALYSER:Kn,PLANTS:qn,LOCKERS:Jn,SUIT:Yn}={BENCH:0,SAMPLES:1,RACKS:2,SCOPE:3,ANALYSER:4,PLANTS:5,LOCKERS:6,SUIT:7},Xn=[[Hn,60.2,230.5,61.2,241.5,0,.95,0],[Un,65,233.5,66.5,238.5,0,.9,0],[Wn,98.8,229.3,99.8,234.3,0,3.1,2],[Wn,98.8,237.7,99.8,242.7,0,3.1,2],[Gn,68.9,250.8,70.1,252,3.5,4.5,3],[Kn,89.4,250.8,91.4,252,3.5,4.8,3],[qn,115,222.4,121,223.2,0,2,1],[qn,123.8,226.4,124.6,229.6,0,2,2],[Jn,96.4,200.4,97,203.6,0,2.1,0],[Yn,108.6,197.4,109.6,198.4,0,2,2]],Zn=(e,t,n,r,i,a,o=[])=>{let s=(t,n,o)=>e?G(r,o,t,i,a,n,cn):G(t,o,r,n,a,i,cn);return[...o,[n,n]].flatMap(([e,n],r,i)=>[s(r?i[r-1][1]:t,e,0),...n>e?[s(e,n,Sn)]:[]])},Qn=({min:[e,,t],max:[n,r,i]},a,o)=>[G(e,4,t,n,r,i,ln,cn),...Zn(0,e,n,t,t+K,4,a[0]),...Zn(0,e,n,i-K,i,4,a[1]),...Zn(2,t+K,i-K,e,e+K,4,a[2]),...Zn(2,t+K,i-K,n-K,n,4),o],$n=[1,.42,.08],er=[...gn.slice(2).flatMap((e,t)=>_n(mn(gn[t+1])+.2).map(([n,r])=>zn([-n,-r,n,r],gn[t+1],e))),...Rn([[Nn,-yn,vn,yn],[Fn,Pn,bn,xn],[In,In,Fn,Fn]]).map(e=>zn(e,Ln.find(([t,n])=>e[0]<=t&&t<=e[2]&&e[1]<=n&&n<=e[3])?.[3]??0,gn[1])),...[[-yn,-vn,-Ln[0][2],-Nn],[Ln[0][2],-vn,yn,-Nn],[Fn,kn-q[1],bn,-Pn],[Fn,-xn,An-q[0],En-q[1]]].map(e=>zn(e,0,gn[1])),...Vn,...Xn.map(([,e,t,n,r,i,a])=>({...G(e,i,t,n,a,r,W),ghost:!0})),...Qn(Cn[0],[[[118,118]],[[116.8,119.2]],[[En+K,kn-K]]],G(121.5,0,223.5,123.5,1.2,225.5,un,un,$n)),...Qn(Cn[1],[[[101.8,104.2]],[[An+K,Mn-K],[105.8,105.8]]],G(106,0,200.6,108,1.2,202.6,un,un,$n)),G(Tn,Sn,En,Dn,On,kn,W,ln),G(An,Sn,jn,Mn,On,kn,W,ln),G(An,0,kn-K,Dn,Sn,kn,ln),G(Mn-K,0,En,Dn,Sn,En+K,ln),G(An,0,jn,An+K,Sn,En,ln),G(Mn-K,0,jn,Mn,Sn,En,ln),...Bn(2,214,En,105,109,0,3.5),...Bn(0,108,Mn,206,210,0,3.5)],[tr,nr]=qt,{STONE:J,CONCRETE:rr,METAL:ir,STEEL:ar,PAINT:or}=j,sr=({min:e,max:t})=>fn(e[0],e[1],280-t[2],t[0],t[1],280-e[2]),cr=[40,220,13],lr=fn(33,.25,218,47,3.25,222),ur=[[27.3,207.3],[52.7,207.3],[27.3,232.7],[52.7,232.7],[106.2,230.4],[103.2,212.4]],dr=q[1]-2,Y=e=>Math.min(Math.max(e,0),1),fr=e=>Y(e)*Y(e)*(3-2*Y(e)),pr=(e,t)=>Math.sqrt(e*e+t*t),mr=[[-100,0,46,.13,.52],[-4,224,36,.12,.67],[110,236,16],[-112,108,14],[236,170,13],[-52,230,10],[80,184,14],[150,250,13],[-36,168,10],[200,152,12],[262,134,14],[240,150,9],[-140,60,12],[-66,60,9],[40,262,10],[118,200,11]],hr=[[-20,0,-1,0],[192,124,0,-1],[64,236,1,0],[-60,100,0,1]],[gr,_r]=[[248,64],[180,200]],vr=[[12,24],[36,60],[72,88],[124,156]],yr=(()=>{let e=Array.from({length:160},(e,t)=>vr.some(([e,n])=>t>=e-1&&t<=n)?0:Math.min(Math.round(Math.max(26*M(t/17,0,33)+8*M(t/5,0,35)-11,0))/2,6.5));for(let t of[1,-1])for(let n=t>0?1:158;n>=0&&n<160;n+=t)e[n]=Math.min(e[n],e[n-t]+.5);return e.map((e,t)=>{let n=Math.min(t,159-t);return n<4?-6:n<8?-3:e})})(),br=e=>e.reduce((e,t,n)=>(e.at(-1)?.[2]===t?e.at(-1)[1]++:e.push([n,1,t]),e),[]),xr=br(yr),X=[114,176,2],Sr=[48,144],[Cr,wr]=[3,8],Tr=[[27,67,53,93],[56,74,104,133],[96,56,125,90],[98,36,102,40],[28,113,32,117],[30,45,30,45],[135,50,135,50],[50,106,50,106],[35,104,35,104],[115,22,115,22],[45,20,51,62],[114,36,114,36],[141,20,147,66]],Er=[[0,0,4.5],[-14,6,3],[10,-12,3.5],[16,10,2.5],[-8,-16,2.2],[-20,-8,3.8],[6,18,3],[22,-4,2],[-12,20,2.4]].map(([e,t,n])=>[e-50,t+330,n]),Dr=[[126,143,131,147,1.2],[130,138.5,135,141.5,2.4],[126,133,131,137,1.2]],Or=[[180,340],[173,346],[186,347]],kr=[mr[0][0]-4.5,140],Ar=[[4,172,4,4,2.2],[30,154,5,5,3],[66,158,3,3,1.6],[95,164,5,4,2.6],[125,175,6,5,3.2],[92,186,4,4,2.4]],jr=.85,Mr=Array.from({length:36},(e,t)=>{let n=e=>ye(t,e,41),r=Math.floor(n(1)*3),[i,a]=r<2?[(r?151:0)+n(2)*9,150+n(3)*122]:[5+n(2)*150,273+n(3)*7];return[i,a+(r===0&&Math.abs(a-174)<8?16:0),.6+2.4*n(4)*n(4)]}).filter(([e,t,n],r,i)=>!i.slice(0,r).some(([r,i,a])=>{let o=Math.max(Math.abs(e-r),Math.abs(t-i))-jr*(n+a);return o>0&&o<1})),Nr=(e,t)=>{let[n,r]=[0,0];for(let[i,a,o,s=.17,c=0]of mr){let l=pr(e-i,t-a),[u,d]=l?[(e-i)/l,(t-a)/l]:[1,0],f=l/o*(.9+.2*M(2.5*u+.37*i,2.5*d+.21*a,9)),p=.03+.045*M(4*u-.1*a,4*d+.1*i,10),m=1-Y((f-1-4/o)/.6),h=c?(s+p)*Y((f-c)/(1-c))-s:(s+p)*f*f-s;n+=o*(f<1?h:p*m*m),r=Math.max(r,c?Y((1.6-f)/(1.5-c)):0)}return[n,r]},Pr=(e,t)=>{let n=t=>Y((12-Math.abs(t-e))/8)*Y((152-t)/4),r=4*Math.floor(t/4);return n(r)+(n(r+4)-n(r))*(t-r)/4},Fr=(e,t)=>{t=Math.abs(t-140);let n=pr((e-80)/300,t/360),r=Math.max((n-.78)/.22,0),i=Nr(e,t),a=Math.max(Math.abs(e-80)-80,t-140),o=fr((a-12)/48)*(1-.7*fr(r))*(16*M(e/96,t/96,1)+6*M(e/52,t/52,4)+5*M(e/36,t/36,2)+1.4*M(e/22,t/22,3)-14.2);if(a<0){let n=fr((t-16-10*M(e/19,.5,37))/8)*fr(-a/10);for(let[r,i,a,o]of Tr)n*=fr((pr(Math.max(r-e,e-a,0),Math.max(i-t,t-o,0))-6)/6);o=n*Math.min(Math.max(4.8*M(e/15,t/15,21)-.9,0)+Math.max(3*M(e/31,t/31,23)-.6,0),2.6);let r=fr((10-pr(e-X[0],t-(X[1]-140)))/8);o=o*(1-r)-X[2]*r;for(let n of Sr)o+=Cr*Y((8+wr-t)/wr)*Pr(n,e);o=t<8?0:o}o=(a<0?o:o*(1-i[1]))+i[0];for(let[n,r,i,a]of hr){let[s,c]=[e-n,t-r],l=s*i+c*a;o+=5.6*Y(Math.min(l/16,(32-l)/12))*Y((18-Math.abs(s*a-c*i))/12)}let s=Y(pr(e-gr[0],Math.max(t-gr[1],0))/36);o+=12*(1-s*s)*(1-s*s)+8*fr((36-pr(e-_r[0],t-_r[1]))/24);let c=10*r*(1+r);return n>1&&(c=(c+(n-1)*60*(Math.abs(2*M(e/45,t/45,5)-1)-.5))*(1+(n-1)*(1.2*M(e/90,t/90,7)-.6))*(1-fr((n-1.25)/.4))),Math.max(o,-14.5)+c},Ir=[[1,0],[.309,.951],[-.809,.588],[-.809,-.588],[.309,-.951]],Lr=(e,t,n)=>{let r=t=>ye(e,t,131),i=e=>{let[t,n]=[2*r(e)-1,2*r(e+1)-1],i=Math.sqrt(t*t+n*n)||1;return[t/i,n/i]},a=[0,1,2].slice(0,t<1.3?1:t<3.2?2:3).map(e=>{let[a,o]=i(20*e+1),[s,c]=[[.1,.45,.42][e]*t,[.8,.75,.65][e]*t],l=[a*s,o*s],u=[n,(.5+.15*r(20*e+3))*n,.34*n][e]-.25*n,d=Math.min(.06,.06/c),[f,p]=[(2*r(20*e+4)-1)*d,(2*r(20*e+5)-1)*d],m=Math.sqrt(f*f+1+p*p);return{o:l,rad:c,top:u,planes:[[f/m,1/m,p/m,(f*l[0]+u+p*l[1])/m],...Ir.map(([t,n],i)=>{let[a,o]=[t+r(20*e+6+i)-.5,n+r(20*e+11+i)-.5],s=Math.sqrt(a*a+o*o),u=-.15+.5*r(20*e+16+i),d=Math.sqrt(1-u*u),[f,p]=[d*a/s,d*o/s];return[f,u,p,f*l[0]+p*l[1]+c*(.72+.22*r(20*e+21+i))]})]}}),[o,s]=i(91),c=[.866*o,-.5,.866*s,.72*t];return{reach:t=>{let r=0;for(let{o:e,rad:i,planes:o}of a){let[a,s]=[1.2*i,1.15*n],l=(t[0]*t[0]+t[2]*t[2])/(a*a)+t[1]*t[1]/(s*s),u=-2*(t[0]*e[0]+t[2]*e[1])/(a*a),d=(e[0]*e[0]+e[1]*e[1])/(a*a)-1,f=(-u+Math.sqrt(u*u-4*l*d))/(2*l);for(let[e,n,r,i]of[...o,c]){let a=t[0]*e+t[1]*n+t[2]*r;f=a>1e-9?Math.min(f,i/a):f}r=Math.max(r,f)}return r*(.94+.12*M(1.5*t[0]+e,1.5*t[2]+2*t[1],e))},tops:a.map(({o:e,top:t})=>[e[0],e[1],t])}},Rr=({reach:e,tops:t},n,r)=>{let i=(t,n,r,i=.09)=>{let a=Math.sqrt(t*t+n*n+r*r);return a<1e-6||a<=e([t/a,n/a,r/a])+i},a=[-1,0,1],o=(e,t,n,o,s)=>[r+.05,(r+s)/2,s].every(r=>a.every(s=>a.every(a=>i(e+s*n,r,t+a*o))))&&a.every(r=>a.every(a=>!i(e+r*n,s+.2,t+a*o,0)));return t.flatMap(([e,t,i],a)=>{let s=[0,0,0,0,0,0],c=Math.sqrt(e*e+t*t)||1;for(let l of a?[.1,.3,.5]:[-.15,0,.15])for(let u of[-.15,0,.15]){let[d,f]=a?[e+(l*e-u*t)*(n/c),t+(l*t+u*e)*(n/c)]:[e+l*n,t+u*n],p=0;for(let e=i+.1;!p&&e>r+.3;e-=.1)p=o(d,f,.08*n,.08*n,e)?e:0;let[m,h]=[.08*n,.08*n];for(let[e,t]of p?[[1,1],[1,0],[0,1]]:[])for(let r=.5*n;r>.03;r/=2)[m,h]=o(d,f,m+e*r,h+t*r,p)?[m+e*r,h+t*r]:[m,h];p&&m*h*(p-r)>s[0]&&(s=[m*h*(p-r),d,f,m,h,p])}let[,l,u,d,f,p]=s;return Math.min(d,f)<(a?.25:0)?[]:[[l-d,r,u-f,l+d,p,u+f]]})},zr=(e,t,n,r,i,a=0)=>{let o=Fr(e,t),s=o+.25*r;return{at:[e,o,t],R:n,H:r,s:i,parts:Rr(Lr(i,n,r),n,-.25*r).filter((e,t,n)=>{let r=Math.max(e[0]-n[0][3],n[0][0]-e[3],e[2]-n[0][5],n[0][2]-e[5]);return!t||r<=0||r>1.2}).map(([n,,r,i,o,c])=>[e+n,a,t+r,e+i,s+o,t+c])}},Br={arena:[...Ar.map(([e,t,n,r,i],a)=>zr(e+n/2,t+r/2,.31*(n+r),1.15*i,a+61)),...Mr.map(([e,t,n],r)=>zr(e,t,n,.8*n,r))],field:Er.map(([e,t,n],r)=>zr(e,t,n,.75*n,r+100,Fr(e,t)-6))},Vr=e=>e.flatMap(e=>e.parts).map(([e,t,n,r,i,a])=>({...G(e,t,n,r,i,a,J),ghost:!0})),[Z,Hr,Ur,Wr]=[9,12,-19,7],Gr=mr.filter(e=>e[4]).map(([e,t],n)=>{let r=140+t,i=Array.from({length:2*Z},(e,t)=>{let i=Math.abs(t+.5-Z),a=Math.sqrt(Z*Z-i*i),o=e=>Math.ceil(2*a*(.88+.24*M(i/4,e+.5,60+n)))/2;return[r-Z+t,r-Z+t+1,o(0),o(1)]});return{x:e,z:r,level:Fr(e,r),rows:i}}),Kr=({x:e,z:t,level:n,rows:r})=>{let i=r.reduce((e,[t,n,r,i])=>{let a=e.at(-1);return a&&a[2]===r&&a[3]===i?a[1]=n:e.push([t,n,r,i]),e},[]),a=r[Z][3],o=(n-Ur)/Wr;return[G(e-Hr,-30,t-Hr,e+Hr,n,t-Z,J),G(e-Hr,-30,t+Z,e+Hr,n,t+Hr,J),...i.flatMap(([t,r,i,a])=>[G(e-Hr,-30,t,e-i,n,r,J),G(e+a,-30,t,e+Hr,n,r,J)]),G(e-Z-1.5,-30,t-Z,e+Z+1.5,Ur,t+Z,J),...Array.from({length:Wr-1},(n,r)=>G(e+a-1.3*(Wr-1-r),Ur,t-1,e+a-1.3*(Wr-2-r),Ur+o*(r+1),t+1,J))].map(e=>({...e,ghost:!0}))},qr=(e,t,n,r)=>({...G(e-n,Fr(e,t)-6,t-n,e+n,Fr(e,t)+r,t+n,J),ghost:!0}),Jr={rocks:[...Er,...Er.map(([e,t,n])=>[e,280-t,n])],dishes:[...Or,...Or.map(([e,t])=>[e,280-t])],ramps:hr.flatMap(([e,t,n,r])=>(t?[1,-1]:[1]).map(i=>[e+16*n,140+i*(t+16*r),n,i*r+0])),wreck:kr,pits:Gr.flatMap(e=>e.z===140?[e]:[e,{...e,z:280-e.z,rows:e.rows.map(([e,t,n,r])=>[280-t,280-e,n,r]).reverse()}]),bowls:mr.flatMap(([e,t,n,r=.17])=>(t?[1,-1]:[1]).map(i=>[e,140+i*t,n,r])),boulders:Mr,crags:Br,stones:Ar,pillars:Dr,domes:[q,[q[0],280-q[1]]],pads:[cr,[cr[0],280-cr[1],cr[2]]],shuttles:[lr,sr(lr)],modules:[...Cn,...Cn.map(sr)],tubes:[...wn,...wn.map(sr)],masts:[...ur,...ur.map(([e,t])=>[e,280-t])]},Yr=e=>({...e,min:[e.min[0],e.min[1],280-e.max[2]],max:[e.max[0],e.max[1],280-e.min[2]],tint:e.tint===tr?nr:e.tint}),Xr=([e,t,n])=>[e,t,280-n],Zr=(e,...t)=>[...e,...e.map(Xr),...t],Qr=[...[G(0,-30,160,160,0,X[1]-12,J),G(0,-30,X[1]-12,X[0]-12,0,X[1]+12,J),G(X[0]+12,-30,X[1]-12,160,0,X[1]+12,J),G(0,-30,X[1]+12,160,0,280,J),G(X[0]-12,-30,X[1]-12,X[0]+12,-3,X[1]+12,J),...xr.filter(e=>e[2]<0).map(([e,t,n])=>G(e,-30,148+n,e+t,0,160,J)),...Array.from({length:14},(e,t)=>br(yr.map(e=>e<0?2:+(e>t/2))).filter(e=>!e[2]).map(([e,n])=>G(e,-30,148+t/2,e+n,0,t<13?148.5+t/2:160,J))).flat(),...Sr.flatMap(e=>[-12,-10,-8,-6,-4,4,6,8,10].map(e=>[e,e+(e===-4?8:2)]).map(([t,n])=>[e+t,e+n,Cr*Math.min(Pr(e,e+t),Pr(e,e+n))*(1-.5/wr)-.12]).filter(e=>e[2]>.3).map(([e,t,n])=>G(e,0,148,t,n,148.5,J)))].map(e=>({...e,ghost:!0})),...er,{...G(75.25,0,dr-4.75,84.75,.5,dr+4.75,or,rr,tr),ghost:!0},{...G(75.75,.5,dr-4.25,84.25,1,dr+4.25,or,rr,tr),ghost:!0},G(60,0,259,70,1.5,265,ar,or,tr),G(27,0,207,53,.25,233,ir),{...dn(lr,or),tint:[.82,.84,.88]},{...G(42,1,222,45.8,1.25,225.5,ir),ghost:!0},{...G(42,1,214.5,45.8,1.25,218,ir),ghost:!0},{...G(43,3.25,219.9,46.8,5.4,220.1,or),ghost:!0},...ur.map(([e,t])=>G(e-.2,e<60?.25:0,t-.2,e+.2,e<60?10.25:10,t+.2,ar)),G(12,-30,148-2.5/2,24,0,148,or,J,[1,.42,.08]),...Gr.filter(e=>e.z!==140).flatMap(Kr),...Vr(Br.arena),...Vr(Br.field),...Or.map(([e,t])=>qr(e,t,.4,6))],$r=[G(74,-1.5,132,86,0,148,ir,ar),G(74,0,132,74.4,1.1,148,rr),G(85.6,0,132,86,1.1,148,rr),...Dr.map(([e,t,n,r,i])=>({...G(e,-30,t,n,i,r,J),ghost:!0})),{...G(-10,-30,132,0,0,148,J),ghost:!0},{...G(160,-30,132,170,0,148,J),ghost:!0},{...G(kr[0]-3.6,-30,kr[1]-3.6,kr[0]+3.6,Ur+3.5,kr[1]+3.6,J),ghost:!0},...Gr.filter(e=>e.z===140).flatMap(Kr),...Jr.ramps.flatMap(([e,t,n,r])=>[-8,8].map(i=>qr(e+i*r,t-i*n,.2,2.2)))],ei=[...[56,68,80,92,104].map(e=>[e,0,271,0]),...[62,80,98].map(e=>[e,0,267,0])],ti=e=>Object.fromEntries([`rifle`,`rail`,`rack`,`blade`].map((t,n)=>[t,[61.25+2.5*n,1.5,e]])),ni=(e,t)=>({base:[80,1,e],spawns:t,...ti(e+(e>140?28:-28))}),ri={highline:sn,tranquility:{name:`Tranquility`,brushes:[...Qr,...Qr.map(Yr),...$r],teams:[ni(dr,ei),ni(280-dr,ei.map(([e,t,n])=>[e,t,280-n,Math.PI]))],packs:Zr([[90,0,210],[118,5,226],[30,0,185],[80,3.5,253.5]],[45,0,162],[45,0,118]),ammo:Zr([[50,0,246],[103,5,200],[135,0,190]],[115,0,162],[115,0,118]),cells:Zr([[106.5,3.5,226],[35,0,244]],[80,0,140]),floor:-26,relief:{hole:[0,132,160,148],pits:[...xr.flatMap(([e,t,n])=>n>0?[[e,148,e+t,148+n],[e,132-n,e+t,132]]:[]),...Jr.pits.flatMap(({x:e,rows:t})=>t.map(([t,n,r,i])=>[e-r,t,e+i,n]))],bound:[80,140,300,360],cell:4,at:Fr},sun:{dir:[.87996,.40998,.23999],color:[3,2.95,2.85]},sky:[[.002,.002,.006],[.02,.02,.035]],gravity:.5,rovers:[[100,0,178,0],[30,0,255,0],[100,0,102,Math.PI],[30,0,25,Math.PI]],scenery:`moon`,helmets:!0,armor:!0}},ii=e=>e!==void 0&&ri[e]||sn,ai=e=>e!==void 0&&Object.hasOwn(ri,e)?e:`highline`,oi=40/60,si=g/60,ci=e=>[te*Math.sin(e*2.4),te*Math.cos(e*1.7)],li=(e,t=0)=>{let[n,r]=e.rifled?ci(e.shots):[0,0],[i,a]=[e.yaw+n,e.pitch+r],[o,s,c,l]=[Math.sin(i),Math.cos(i),Math.sin(a),Math.cos(a)];return{id:e.shots,by:e.id,team:t,x:e.x,y:e.y+qe(e),z:e.z,dx:-o*l,dy:c,dz:-s*l,left:e.rifled?60:80,burst:!1,power:e.rifled?0:e.power??1}},ui=(e,t=0)=>({...li(e,t),id:e.shots^128,left:_,power:1,arc:e.cut}),di=e=>e.arc?si:e.power===6?2:oi,fi=(e,t,n,r,i)=>{let[a,o]=[e[0]-n.x,e[2]-n.z],s=t[0]*t[0]+t[2]*t[2],c=a*t[0]+o*t[2],l=c*c-s*(a*a+o*o-r*r),[u,d]=[0,1/0];if(s>1e-12){if(l<0)return 1/0;[u,d]=[(-c-Math.sqrt(l))/s,(-c+Math.sqrt(l))/s]}else if(a*a+o*o>r*r)return 1/0;let[f,p]=[n.y-e[1],n.y+i-e[1]];if(t[1])[u,d]=[Math.max(u,Math.min(f/t[1],p/t[1])),Math.min(d,Math.max(f/t[1],p/t[1]))];else if(f>0||p<0)return 1/0;return u<=d&&d>=0?Math.max(u,0):1/0},pi=(t,n,r,i)=>{let a=[n.x,n.y,n.z],o=[n.dx,n.dy,n.dz],s=Math.min(r,n.left),l=Ne(t,a,o,s,c),u;for(let t of i){let r=fi(a,o,t,e+(n.arc?v:c),R(t));r<l&&([l,u]=[r,t])}return n.burst=l<s,n.left-=l,[n.x,n.y,n.z]=[a[0]+o[0]*l,a[1]+o[1]*l,a[2]+o[2]*l],u},mi=(e,t=0)=>({...li({...e,rifled:!1},t),left:150,power:7,v:36}),hi=(e,t,n)=>{let r=Math.fround,[i,a,o]=[t.dx*t.v,t.dy*t.v-ut(e)/60,t.dz*t.v],s=Math.sqrt(i*i+a*a+o*o)||1;[t.dx,t.dy,t.dz,t.v]=[r(i/s),r(a/s),r(o/s),r(s)];let c=pi(e,t,t.v/60,n);return[t.x,t.y,t.z,t.left]=[r(t.x),r(t.y),r(t.z),r(t.left)],t.burst||=t.left<=0,c},gi=(e,t,n)=>{let r=R(n),i=[n.x,Math.max(n.y,Math.min(n.y+r,t[1])),n.z],[a,o,s]=[i[0]-t[0],i[1]-t[1],i[2]-t[2]],c=Math.sqrt(a*a+o*o+s*s);return c>=5||Fe(e,t,i)&&Fe(e,t,[n.x,n.y+.7*r,n.z])?0:Math.ceil(5*(1-c/5))},_i=(t,n,r=[],i=30,[a,o]=[0,0])=>{let s=[n.x,n.y+qe(n),n.z],[c,l]=[n.yaw+a,n.pitch+o],u=Math.cos(l),d=[-Math.sin(c)*u,Math.sin(l),-Math.cos(c)*u],f=Ne(t,s,d,i),p;for(let t of r){let n=fi(s,d,t,e,R(t));n<f&&([f,p]=[n,t])}return{o:s,d,t:f,hit:p}},Q={A:1.25,B:1,WR:.5,L0:.6,CMAX:.5,K:30,D:2,KP2:1.2,KR2:.7,HC:.7,ENGINE:12,VMAX:23.2,VREV:8,BRAKE:14,ROLL:.6,HB:6,MU:1.1,MUL:1.2,HBG:.35,HBY:1.5,SK:2.5,SV:10,SMAX:.55,SRATE:3.5,YMAX:2.4,YRESP:10,AK:5,AC:3,AD:.5,TILT:.9,RB:1.05,BODY:[1.15,0,-1.15],BODY_H:1.5,WHEEL_STEP:.6,BOUNCE:.3,ENTER_R:3,SPLAT_MIN:6,SPLAT_KILL:12,GUN_COOL:8,GUN_RANGE:90,GUN_AIM:50},vi=[[-1.05,.18,.6],[1.05,.18,.6]],yi=[[-.45,-.35,.1],[.45,-.35,.1]],bi=[1,1,-1,-1].map(e=>e*Q.A),xi=[-1,1,-1,1].map(e=>e*Q.B),Si=Q.L0+Q.WR,Ci=Q.RB+e+.15,wi=1,Ti=`x y z vx vy vz yaw pitch roll wy wp wr steer`.split(` `),$=1/60,Ei=Math.fround,{sin:Di,cos:Oi,min:ki,max:Ai,abs:ji,sqrt:Mi}=Math,Ni=(e,t,n)=>ki(Ai(e,t),n),Pi=(e,t,n,r=0)=>{let[i,a]=F(e.yaw),[o,s]=[t*Oi(e.pitch),n*Oi(e.roll)];return[e.x+i*o-a*s,e.y+r+t*Di(e.pitch)-n*Di(e.roll),e.z+a*o+i*s]},Fi=(e,t)=>bi.map((n,r)=>{let[i,a,o]=Pi(e,n,xi[r]);return[i,a,o,Si+nt(t,i,o,a-Q.L0+Q.WHEEL_STEP)-a]}),Ii=e=>Q.BODY.map(t=>Pi(e,t,0,-Si)),Li=e=>{let[t,,n]=Ii(e);return{a:t,b:n,r:Q.RB,h:Q.BODY_H}},Ri=e=>(e.def.rovers??[]).map(([e,t,n,r])=>({x:Ei(e),y:Ei(t+Si),z:Ei(n),vx:0,vy:0,vz:0,yaw:Ei(ze(r)),pitch:0,roll:0,wy:0,wp:0,wr:0,steer:0,driver:255,rider:255})),zi=(e,t,n,r=[])=>{let{A:i,B:a,CMAX:o,K:s,D:c,KP2:l,KR2:u,HC:d,MU:f,MUL:p,TILT:m}=Q,h=ut(n),g=t?t.keys:0,_=(g&T.FORWARD?1:0)-(g&T.BACK?1:0),v=g&T.JUMP,[y,b]=F(e.yaw),[x,ee]=[Oi(e.pitch),Oi(e.roll)],S=Fi(e,n),[C,te,ne,w]=S.map(([,e,,t])=>t+e-Si),E=S.some(e=>e[3]<-o),D=E?0:(C+te-ne-w)/(4*i*x),O=E?0:(te+w-C-ne)/(4*a*ee),k=1/Mi(D*D+O*O+1),A=-(D*y-O*b)*k,j=-(D*b+O*y)*k,re=()=>e.vx*A+e.vy*k+e.vz*j,ie=Ai(0,...S.map(e=>e[3]-o));if(ie){e.y+=ie;let t=ki(0,re());e.vx-=t*A,e.vy-=t*k,e.vz-=t*j}let ae=re(),[oe,se,ce]=[0,0,0];S.forEach(([,,,t],n)=>{if(t>ie){let r=Ai(0,s*(t-ie)-c*(ae+(bi[n]*x*e.wp-xi[n]*ee*e.wr)*k));oe+=r,se+=r*bi[n],ce+=r*xi[n]}}),e.vx+=oe*A*$,e.vy+=(oe*k-h)*$,e.vz+=oe*j*$,e.wp+=se/l*$,e.wr-=ce/u*$;let le=ki(oe/h,2);if(le>0){let n=e.vx*y+e.vz*b,r=e.vz*y-e.vx*b,a=t?ze(t.yaw-e.yaw+Math.PI)-Math.PI:0,o=Ni(Q.SK*a/(1+ji(n)/Q.SV),-Q.SMAX,Q.SMAX),s=Q.SRATE*$;e.steer+=Ni((n+_<0?-o:o)-e.steer,-s,s);let c=Ni(n*e.steer/(2*i),-Q.YMAX,Q.YMAX)*(v?Q.HBY:1);e.wy+=(c-e.wy)*Q.YRESP*$*ki(1,le);let m=h*le*$,g=Ni((_*n<0?_*Q.BRAKE:_*Q.ENGINE*Ai(0,1-ji(n)/(_>0?Q.VMAX:Q.VREV)))*$,-p*m,p*m),x=(Q.ROLL+(v||!t?Q.HB:0))*le*$;g-=Ni(n+g,-x,x);let ee=f*m*(v?Q.HBG:1),S=-Ni(r,-ee,ee);e.vx+=g*y-S*b,e.vz+=g*b+S*y,e.wp+=g*d/l,e.wr-=S*d/u}else e.wp-=(Q.AK*e.pitch+Q.AC*e.wp)*$,e.wr-=(Q.AK*e.roll+Q.AC*e.wr)*$;e.wp*=1-Q.AD*$,e.wr*=1-Q.AD*$,e.x+=e.vx*$,e.y+=e.vy*$,e.z+=e.vz*$,e.yaw=ze(e.yaw+e.wy*$),e.pitch=Ni(e.pitch+e.wp*$,-m,m),e.roll=Ni(e.roll+e.wr*$,-m,m),ji(e.pitch)===m&&e.pitch*e.wp>0&&(e.wp=0),ji(e.roll)===m&&e.roll*e.wr>0&&(e.wr=0);for(let t of Q.BODY){let[r,i,a]=Pi(e,t,0,-Si),[o,s]=Qe({x:r,y:Ai(i,C,te,ne,w),z:a},n,Q.BODY_H,Q.RB),c=o*o+s*s;if(c){e.x+=o,e.z+=s;let t=ki(0,e.vx*o+e.vz*s)/c;e.vx-=t*o,e.vz-=t*s}}for(let t of r){if(t===e)continue;let n=Li(t);for(let r of Q.BODY){let[i,a,o]=Pi(e,r,0,-Si),[s,c,l]=$e(n,i,o),u=2*Q.RB,d=Mi(s*s+c*c);if(d>=u-1e-4||l>=a+Q.BODY_H||l+Q.BODY_H<=a)continue;let[f,p]=F(t.yaw),[m,h]=d?[s/d,c/d]:[-p,f];e.x+=m*(u-d),e.z+=h*(u-d);let g=ki(0,e.vx*m+e.vz*h)*(1+Q.BOUNCE);e.vx-=g*m,e.vz-=g*h}}Ce(e,n);for(let t of Ti)e[t]=Ei(e[t]);return e.y<n.def.floor},Bi=(e,t,n)=>{let[r,i,a]=yi[n];[e.x,e.y,e.z]=Pi(t,a,r,i).map(Ei),e.vx=t.vx,e.vy=t.vy,e.vz=t.vz},Vi=(e,t,n)=>{t[n?`rider`:`driver`]=e.id,e.mode=O.RIDE,e.t=0,e.edge=0,e.ground=!1,e.dash=ki(e.dash,50),e.coyote=0,e.buffer=0,Bi(e,t,n)},Hi=(n,r,i,a)=>{r[i?`rider`:`driver`]=255,n.mode=O.AIR,n.t=0,n.coyote=0,[n.vx,n.vy,n.vz]=[r.vx,r.vy,r.vz];let o=i?Ci:-Ci;for(let[s,c]of[[o,-Si],[-o,-Si],[0,Q.BODY_H-Si]]){let[o,l,u]=Pi(r,yi[i][2],s,c);Object.assign(n,{x:o,y:l,z:u}),Ce(n,a);let d=nt(a,n.x,n.z,r.y);n.y=Ai(l,d);let[f,p]=Qe(n,a,t,e);if(!s||d>l-wi&&!f&&!p)break}[n.x,n.y,n.z,n.vx,n.vz]=[n.x,n.y,n.z,n.vx,n.vz].map(Ei)},Ui=(e,t,n,r,i,a=[])=>{let o=(n.keys&T.USE)!==0&&(e.held&T.USE)===0,s=zi(t,n,r,a);return Vt(e,n,r,i,!1),e.mode===O.RIDE?(Bi(e,t,0),o&&Hi(e,t,0,r)):t.driver=255,s},Wi=(e,t,n)=>{let[r,i,a,o]=[Math.sin(t),Math.cos(t),Math.sin(n),Math.cos(n)];return[e.x-r*o*Q.GUN_AIM,e.y+a*Q.GUN_AIM,e.z-i*o*Q.GUN_AIM]},Gi=(e,t,n,r,i,a)=>{let[o,s]=F(e.yaw),c=Wi(e,r,i);return vi.map(([r,i,l],u)=>{let d=[e.x+o*l-s*r,e.y+i,e.z+s*l+o*r],f=c.map((e,t)=>e-d[t]),p=Math.sqrt(f[0]*f[0]+f[1]*f[1]+f[2]*f[2]);return{id:a+u&255,by:t,team:n,x:d[0],y:d[1],z:d[2],dx:f[0]/p,dy:f[1]/p,dz:f[2]/p,left:Q.GUN_RANGE,burst:!1,power:6}})},Ki=e=>e.mode===O.SLIDE||e.dash>50,qi=(e,t)=>Math.hypot(e.x-t.x,e.z-t.z)<1.1&&e.y<t.y+R(t)&&t.y<e.y+R(e),Ji=20,Yi=2,Xi=30,Zi=[`driver`,`rider`],Qi=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),$i=e=>Qi((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),ea=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${Qi(e,15-`${r}`.length)} ${r}`;return n},ta=(e,t)=>Math.sqrt(e*e+t*t),na=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},ra={lock:0,foe:0,pushes:0,pressed:!1,away:0},ia=({x:e,y:t,z:n,yaw:r})=>({x:e,y:t,z:n,yaw:r}),aa=({x:e,y:t,z:n})=>({x:e,y:t,z:n}),oa=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;ctf;halt;rules;rr=[0,0];gone;balls=[];rovers;mapName;next;joins=0;constructor(e={},t){this.rules={...ne,...e},this.mapName=ai(this.rules.map),this.world=je(t??ii(this.mapName)),this.ctf=new Lt(this.world,this.rules),this.gone=this.spots(),this.rovers=Ri(this.world)}spots(){let{packs:e=[],ammo:t=[],cells:n=[]}=this.world.def;return[...e,...t,...n].map(()=>0)}host(){return this.players().reduce((e,t)=>e&&e.since<t.since?e:t,void 0)}load(){if(this.next!==void 0){this.mapName=this.next,this.next=void 0,this.world=je(ii(this.mapName)),this.ctf=new Lt(this.world,this.rules),this.gone=this.spots(),this.rovers=Ri(this.world),this.history=[],this.balls=[];for(let e of this.players())this.ctf.join(e.info.id,e.info.team,e.state);this.roster()}}get size(){return this.players().length}connect(e){this.peers.set(e,null)}receive(e,t){let n=this.peers.get(e);if(typeof t==`string`){let r=ve(t);n===null&&r?.t===`join`?this.join(e,r.name):n&&r?.t===`map`&&n===this.host()&&Object.hasOwn(ri,r.map)&&(this.next=r.map===this.mapName?void 0:r.map,this.roster());return}let r=n&&he(t);if(r&&n.bank>0){n.bank--;let e=n.state.slow??0,t=(r.keys&T.USE)!==0&&(n.state.held&T.USE)===0,[i,a]=this.seatOf(n);if(i&&!a){let e=Ui(n.state,i,r,this.world,n.info.team,this.rovers);this.ctf.moved(n.state),e?this.sink(i):(this.carry(i),this.splat(n,i,r.view),this.lase(n,i,r))}else{let e=Vt(n.state,r,this.world,n.info.team,!this.ctf.over,this.rovers.map(Li));this.ctf.moved(n.state),this.tackle(n,r.view);let a=aa(n.state),o=i&&e?this.past(r.view).find(e=>e.id===n.info.id):void 0;Object.assign(n.state,o&&aa(o)),e===B.SHOT?this.shoot(n,r.view):e===B.CUT?this.cut(n,r.view):e===B.RAIL?this.rail(n,r.view):e===B.LASER?this.shoot(n,r.view):e===B.NADE&&this.shoot(n,r.view,mi(n.state,n.info.team)),Object.assign(n.state,a),t&&i&&n.state.mode===O.RIDE?Hi(n.state,i,1,this.world):t&&this.enter(n)}n.burn=e?(n.burn??0)+1:0,e&&!(n.burn%60)&&this.fry(n),this.duel(n),n.ack=r.seq,this.seats()}}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&(this.ctf.leave(t.info.id),this.size||(this.ctf.reset(),this.gone.fill(0),this.rovers=Ri(this.world),this.load()),this.seats(),this.roster())}drop(e){let t=this.players().find(t=>t.info.id===e);return!!t&&this.ctf.drop(t.state)}tick(){let e=this.players();if(!e.length){this.balls=[];return}let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);for(let e of this.balls)!e.burst&&e.left>0&&this.fly(e,di(e));this.heal(e);let n=this.ctf.tick(e.filter(e=>!e.state.down&&!this.rovers.some(t=>t.driver===e.info.id)).map(e=>({id:e.info.id,team:e.info.team,state:e.state})));n===`end`?this.end(e):n===`start`&&(this.load(),this.restart(e)),this.seats();for(let e of this.rovers)e.driver===255&&zi(e,void 0,this.world,this.rovers)?this.sink(e):this.carry(e);if(this.seats(),t%2==0){for(this.history.push({tick:t,players:e.map(e=>({...e.state}))});this.history[0].tick<t-30;)this.history.shift();let n=_e({tick:t,players:e.map(e=>({...e.state,ack:e.ack,by:e.state.stun?e.by:0})),...this.ctf.wire(),packs:this.gone.reduce((e,t,n)=>t?e:e+2**n,0),balls:this.balls,rovers:this.rovers});e.forEach(e=>e.conn.send(n)),this.balls=this.balls.filter(e=>!e.burst&&e.left>0)}}start(e=na){if(this.halt)return;let t=1e3/60,n=performance.now(),r=0;this.halt=e(()=>{let e=performance.now();r+=e-n,n=e;for(let e=0;r>=t&&e<Ji;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){return this.past(t).filter(t=>t.id!==e)}past(e=0){let t=this.players().map(e=>e.state),[n,r]=[this.history[0],this.history.at(-1)];if(!n||!r)return t;let i=((this.ticks-e+32768)%65536+65536)%65536-32768,a=Math.min(Math.max(this.ticks-i,n.tick),r.tick),o=0;for(;o+1<this.history.length&&this.history[o+1].tick<=a;)o++;let[s,c]=[this.history[o],this.history[o+1]??this.history[o]],l=c.tick>s.tick?(a-s.tick)/(c.tick-s.tick):0,u=(e,t)=>e+(t-e)*l;return t.map(e=>{let t=s.players.find(t=>t.id===e.id),n=c.players.find(t=>t.id===e.id);return t&&n?{...n,x:u(t.x,n.x),y:u(t.y,n.y),z:u(t.z,n.z)}:n??t??e})}tackle(e,t){let n=e.state;if(n.down||!Ki(n)||this.ticks-e.tackled<30)return;let r=this.players().filter(t=>t.info.team!==e.info.team),i=this.rewind(e.info.id,t).find(e=>qi(n,e)&&r.some(t=>t.info.id===e.id&&this.ctf.carrying(t.info.id)>=0)),a=r.find(e=>e.info.id===i?.id);if(!a||!this.drop(a.info.id))return;let o=Je(n),[s,c]=o>.001?[n.vx/o,n.vz/o]:F(n.yaw);pt(a.state,s,c),a.state.zap=!1,a.by=e.info.id,e.tackled=this.ticks}enemies(e,t){let n=this.players();return this.rewind(e.info.id,t).filter(t=>{let r=n.find(e=>e.info.id===t.id);return r&&r.info.team!==e.info.team&&!r.state.down&&!t.down})}harm(e,t){return(e.state.hp-=t)>0?!1:(e.graze=0,e.state.mode===O.RIDE&&this.unseat(e),Object.assign(e.state,{hp:0,down:120,ammo:-1,cool:0,charge:0,mag:0,cap:0,reload:0,blade:!1,wield:!1,swing:0,lost:D.NONE,rail:-1,railed:!1,rifle:-1,clip:0,rifled:!1,nades:0,lob:0,zapping:!1,slow:0}),this.ctf.drop(e.state),!0)}shoot(e,t=0,n=li(e.state,e.info.team)){let r=(this.ticks-t+65536)%65536;this.balls.push(n);let i=Math.min(r<32768?r:0,12);if(n.power===7)for(let e=0;e<i&&!n.burst;e++)this.fly(n,0);else this.fly(n,i*di(n));let a=this.balls.filter(e=>!e.burst);a.length>64&&(a[0].burst=!0)}fly(e,t){let n=this.players(),r=n.filter(t=>t.info.team!==e.team&&!t.state.down);if(e.power===7){hi(this.world,e,r.map(e=>e.state));let t=!1;for(let r of e.burst?n:[]){let n=r.info.id===e.by,i=!r.state.down&&(n||r.info.team!==e.team)?gi(this.world,[e.x,e.y,e.z],r.state):0;i&&(this.harm(r,i),t||=!n)}let i=n.find(t=>t.info.id===e.by);t&&i&&(i.state.hits=i.state.hits+1&255);return}let i=pi(this.world,e,t,r.map(e=>e.state)),a=r.find(e=>e.state===i);if(!a)return;let o=n.find(t=>t.info.id===e.by);if(o&&(o.state.hits=o.state.hits+1&255),e.power===0||e.power===6)a.graze=((a.graze??0)+1)%2,a.graze||this.harm(a,1);else if(!e.arc)this.harm(a,e.power??1);else if(this.harm(a,l[e.arc].hp)){let t=o&&{...o.state,cut:e.arc,yaw:Math.atan2(-e.dx,-e.dz)};a.state.lost=t?Pt(Object.assign(t,{x:e.x-e.dx,y:e.y-e.dy-Ot*R(t),z:e.z-e.dz,pitch:Math.asin(e.dy)}),a.state):D.NONE}else{let t=Math.hypot(e.dx,e.dz)||1;pt(a.state,e.dx/t,e.dz/t,y,b),a.state.zap=!0,a.by=e.by,this.ctf.drop(a.state)}}cut(e,t){if(e.state.cut===E.ARC_L||e.state.cut===E.ARC_R){this.shoot(e,t,ui(e.state,e.info.team));return}let n=jt(this.world,e.state,this.enemies(e,t)),r=this.players().filter(e=>n.some(t=>t.id===e.info.id)),i=r.find(t=>Mt(e.state,{...t.state,...ia(n.find(e=>e.id===t.info.id))}));if(i){for(let[t,n]of[[e,i],[i,e]])Object.assign(t.state,{...ra,lock:240,foe:n.info.id,pressed:!0}),Object.assign(t.state,{swing:0,charge:0,stun:0,zap:!1,vx:0,vz:0});r=r.filter(e=>e!==i)}if(r.length){e.state.hits=e.state.hits+1&255;for(let t of r){let r=n.find(e=>e.id===t.info.id);if(this.harm(t,At(e.state).hp))t.state.lost=Pt(e.state,r);else{let[n,r]=Nt(e.state);pt(t.state,n,r,24,4*(e.state.heavy?u:1)),t.state.zap=!0,t.by=e.info.id}}}}rail(e,t){let{hit:n}=_i(this.world,e.state,this.enemies(e,t)),r=this.players().find(e=>e.info.id===n?.id);if(r){let t=!r.state.slow;r.state.slow=180,t&&(e.state.hits=e.state.hits+1&255,r.burn=0,this.fry(r))}}fry(e){e.state.fried=this.harm(e,1)}duel(e){let t=e.state;if(!t.lock)return;let n=this.players().find(e=>e.info.id===t.foe);if(!n||n.state.foe!==e.info.id||!n.state.lock||n.state.down||t.down){Object.assign(t,ra);return}let r=(t.pushes??0)-(n.state.pushes??0),i=(t.away??0)>=24||(n.state.away??0)>=24;if(!(Math.abs(r)<8&&!i&&t.lock>1)){if(Object.assign(t,ra),Object.assign(n.state,ra),Math.abs(r)>=8){let[t,i]=r>0?[e,n]:[n,e];if(t.state.hits=t.state.hits+1&255,!this.harm(i,3)){let[e,n]=F(t.state.yaw);pt(i.state,e,n,24,4),i.state.zap=!0,i.by=t.info.id}}else if(!i){let[e,r]=[n.state.x-t.x,n.state.z-t.z],i=Math.hypot(e,r)||1;pt(t,-e/i,-r/i),pt(n.state,e/i,r/i)}}}heal(e){let{packs:t=[],ammo:n=[],cells:r=[]}=this.world.def;[...t,...n,...r].forEach((r,i)=>{if(this.gone[i]>0){this.gone[i]--;return}let a=+(i>=t.length)+ +(i>=t.length+n.length),o=e=>[e.hp<5,e.ammo>=0&&e.ammo<60||(e.rifle??-1)>=0&&e.rifle<240,(e.rail??-1)>=0&&e.rail<240][a],s=e.find(({state:e})=>!e.down&&o(e)&&zt(e,r,.9));if(s){let e=s.state;a==0?e.hp=Math.min(5,e.hp+2):a==1?(e.ammo=e.ammo<0?-1:Math.min(60,e.ammo+20),e.rifle=(e.rifle??-1)<0?-1:Math.min(240,e.rifle+60)):e.rail=Math.min(240,e.rail+80),this.gone[i]=(a==1?10:20)*60}})}seatOf(e){if(e.state.mode===O.RIDE)for(let t of this.rovers){let n=Zi.findIndex(n=>t[n]===e.info.id);if(n>=0)return[t,n]}return[]}unseat(e){for(let t of this.rovers)Zi.forEach(n=>t[n]=t[n]===e.info.id?255:t[n]);Object.assign(e.state,{mode:O.AIR,t:0,coyote:0})}seats(){let e=this.players();for(let t of this.rovers)for(let n of Zi)e.some(e=>e.info.id===t[n]&&e.state.mode===O.RIDE)||(t[n]=255);for(let t of e)t.state.mode===O.RIDE&&!this.seatOf(t).length&&this.unseat(t)}enter(e){let t=e.state;if(t.down||t.stun||t.lock||t.mode===O.RIDE)return;let n=this.ctf.carrying(e.info.id)>=0,r=e=>Math.abs(e.y-t.y)>Q.ENTER_R?1/0:(e.x-t.x)**2+(e.z-t.z)**2,i=e=>e.driver===255&&!n?0:e.rider===255?1:-1,a=this.rovers.filter(e=>r(e)<=Q.ENTER_R**2&&i(e)>=0).sort((e,t)=>r(e)-r(t))[0];a&&Vi(t,a,i(a))}carry(e){let t=this.players().find(t=>t.info.id===e.rider);if(t?.state.mode===O.RIDE){Bi(t.state,e,1);let n=nt(this.world,e.x,e.z,e.y);n>this.world.def.floor&&this.ctf.place(t.info.id,{...t.state,y:n})}}sink(e){for(let t of this.players())this.seatOf(t)[0]===e&&(Ge(t.state,this.world,t.info.team),this.ctf.moved(t.state));let t=this.rovers.indexOf(e);Object.assign(e,Ri(this.world)[t])}lase(e,t,n){if(e.gun=Math.max(0,(e.gun??0)-1),!(!(n.keys&T.FIRE)||e.gun||this.ctf.over||e.state.mode!==O.RIDE)){e.gun=Q.GUN_COOL,e.bolt=(e.bolt??0)+2&255;for(let r of Gi(t,e.info.id,e.info.team,n.yaw,n.pitch,e.bolt))this.shoot(e,n.view,r)}}splat(e,t,n){if(ta(t.vx,t.vz)<Q.SPLAT_MIN)return;let r=Ii(t);for(let i of this.enemies(e,n)){let n=this.players().find(e=>e.info.id===i.id);if(!n||n.state.mode===O.RIDE||this.ticks-n.run<Xi||!r.find(([e,t,n])=>ta(i.x-e,i.z-n)<Q.RB+.4&&i.y<t+Q.BODY_H&&i.y+R(i)>t))continue;let[a,o]=[i.x-t.x,i.z-t.z],s=ta(a,o)||1,c=((t.vx-i.vx)*a+(t.vz-i.vz)*o)/s;if(!(c<Q.SPLAT_MIN)&&(n.run=this.ticks,e.state.hits=e.state.hits+1&255,!this.harm(n,c<Q.SPLAT_KILL?1:n.state.hp))){let r=ta(t.vx,t.vz);pt(n.state,t.vx/r,t.vz/r),n.state.zap=!1,n.by=e.info.id}}}place(e,t,n){let r=this.world.def.teams[t].spawns.findIndex((r,i)=>{let{x:a,z:o}=We(e,this.world,i,t);return!n.some(e=>Math.hypot(e.x-a,e.z-o)<Yi)});return We(e,this.world,r<0?this.rr[t]++:r,t)}end(e){let t=this.ctf.tally().flatMap(t=>{let n=e.find(e=>e.info.id===t.id)?.info;return n?[{...t,name:n.name,team:n.team}]:[]}),n=JSON.stringify({t:`end`,score:this.ctf.score,players:t});e.forEach(e=>e.conn.send(n))}restart(e){let t=[];this.rr=[0,0],this.gone.fill(0),this.rovers=Ri(this.world);for(let n of e){let{shots:e,hits:r}=n.state;n.state={...this.place(n.info.id,n.info.team,t),shots:e,hits:r},t.push(n.state),this.ctf.place(n.info.id,n.state)}}players(){return[...this.peers.values()].filter(e=>e!==null)}join(e,t){let n=this.players();if(n.length>=this.rules.maxPlayers){e.send(JSON.stringify({t:`full`}));return}let r=0;for(;n.some(e=>e.info.id===r);)r++;let i=n.filter(e=>e.info.team===0).length,a=+(i>n.length-i),o={conn:e,info:{id:r,name:ea($i(t)||`Player ${r}`,n.map(e=>e.info.name)),team:a,color:s[a]},state:this.place(r,a,n.map(e=>e.state)),since:this.joins++,bank:10,ack:65535,by:0,tackled:-30,run:-Xi};this.peers.set(e,o),this.ctf.join(r,a,o.state),this.roster()}roster(){let e=this.players(),t=e.map(e=>e.info).sort((e,t)=>e.id-t.id);e.forEach(e=>e.conn.send(JSON.stringify({t:`roster`,you:e.info.id,players:t,map:this.mapName,host:this.host()?.info.id,next:this.next})))}},sa=(e,t)=>{let n=()=>{},r=()=>{n();let r=setInterval(e,t);n=()=>clearInterval(r)};try{let i=URL.createObjectURL(new Blob([`setInterval(()=>postMessage(0),${t})`])),a=new Worker(i);a.onmessage=e,a.onerror=r,n=()=>{a.terminate(),URL.revokeObjectURL(i)}}catch{r()}return()=>n()},ca=(e,t)=>{let n=`tiny-fps:`+e,r=Math.random().toString(36).slice(2),i=new BroadcastChannel(n),a=new AbortController,o=globalThis.navigator?.locks,s,c,l,u,d=[],f,p=!1,m=e=>i.postMessage({from:r,...e}),h=e=>!p&&x.onmessage?.({data:e}),g={send:e=>queueMicrotask(()=>h(e))},_=()=>{let e=d.length?d:f?[f]:[];return d=[],e},v=e=>{if(p)return e();l=e,u=r,c=/* @__PURE__ */ new Map,s=new oa(t),s.start(sa),s.connect(g),_().forEach(e=>s.receive(g,e)),m({kind:`h`})};i.onmessage=({data:e})=>{if(!p){if(s&&c){let{from:t,kind:n}=e,r=c.get(t);n===`q`?m({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!p&&m({to:t,kind:`m`,data:e})},c.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(c.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?h(e.data):e.kind===`h`&&e.from!==u&&(u=e.from,_().forEach(e=>m({kind:`m`,data:e}))))}};let y=e=>{p||(typeof e==`string`&&ve(e)?.t===`join`&&(f=e),s?s.receive(g,e):u?m({kind:`m`,data:e}):d.push(e))},b=()=>{p||(p=!0,globalThis.removeEventListener?.(`pagehide`,b),s?(s.stop(),l()):(m({kind:`b`}),a.abort()),i.close(),setTimeout(()=>x.onclose?.()))},x={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:y,close:b};return o?o.request(n,{signal:a.signal},()=>new Promise(v)).catch(()=>{}):v(()=>{}),m({kind:`q`}),globalThis.addEventListener?.(`pagehide`,b),setTimeout(()=>!p&&x.onopen?.()),x};export{ca as localSocket};
1
+ var e=.4,t=1.8,n=.9,r=7.5,i=.5,a=5.5,o=2.5,s=[`#ff3d4f`,`#2f80ff`],c={ticks:20,strike:6,reach:1.4,arc:.6,hp:0,hold:-1},[l,u,d]=[2,3,180],f=.12,p=[{ticks:28,strike:10,reach:2.65,arc:.3,hp:2,hold:8},{ticks:34,strike:13,reach:2.15,arc:1.2,hp:2,hold:4},{ticks:34,strike:13,reach:2.15,arc:1.2,hp:2,hold:4},{ticks:40,strike:16,reach:2.15,arc:.45,hp:3,hold:11},{ticks:36,strike:12,reach:3.2,arc:.3,hp:3,hold:-1},{ticks:46,strike:20,reach:2.15,arc:.6,hp:3,hold:-1},{ticks:46,strike:20,reach:2.15,arc:.6,hp:3,hold:-1},{ticks:58,strike:40,reach:2.4,arc:.6,hp:4,hold:-1}],[m,h,g]=[1.8,15,60],[_,v,y]=[2,.5,1.4],[b,x,ee]=[24,15,.6],[S,te]=[63,7],C=7.5,[ne,re,ie]=[.82,.45,.12],ae=.012,oe={maxPlayers:16,scoreLimit:3,timeLimit:480,map:`highline`},w={HOME:0,CARRIED:1,DROPPED:2},T={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128,FIRE:256,BLADE:512,SPECIAL:1024,RAIL:2048,RELOAD:4096,RIFLE:8192,USE:16384},E={THRUST:0,LEFT:1,RIGHT:2,SLASH:3,LUNGE:4,ARC_L:5,ARC_R:6,LEAP:7},D={NONE:0,HEAD:1,ARM_L:2,ARM_R:3,LEG_L:4,LEG_R:5},O={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6,RIDE:7},se={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},k={JUMP:1,DOUBLE:2,DASH:4,LAND:8,GRAB:16,CLIMB:32,WALLRUN_START:64,WALLRUN_END:128,SLIDE_START:256,SLIDE_END:512,RESPAWN:1024},A={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7,CONCRETE:8,GLASS:9,STEEL:10,PAINT:11,ROCK:12},ce=[`x`,`y`,`z`,`vx`,`vy`,`vz`,`yaw`,`pitch`,`roll`,`wy`,`wp`,`wr`,`steer`],le=127,ue=16,de=32,fe=128/Math.PI,pe=254/Math.PI,me=65536/(2*Math.PI),he=e=>Math.round(e*me)&65535,ge=e=>Math.max(-32768,Math.min(32767,Math.round(e))),_e=e=>ge(e*1e4),ve=e=>e/1e4,ye=e=>e/me,be=e=>{if(e.byteLength!==12)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint16(3)&32767,yaw:ye(t.getUint16(5)),pitch:ve(t.getInt16(7)),view:(t.getUint16(9)*256+t.getUint8(11))/256}:null},xe=e=>e===w.CARRIED?2:e===w.DROPPED?8:1,Se=e=>{let t=(e.rovers??[]).slice(0,7),n=4+62*e.players.length,r=n+54*t.length,i=e.balls??[],a=r+10+e.flags.reduce((e,t)=>e+xe(t.state),0),o=new DataView(new ArrayBuffer(a+(i.length&&1+11*i.length)));o.setUint8(0,2),o.setUint16(1,e.tick&65535),o.setUint8(3,e.players.length|t.length<<5),e.players.forEach((e,t)=>{let n=4+t*62;o.setUint8(n,e.id),o.setFloat32(n+1,e.x),o.setFloat32(n+5,e.y),o.setFloat32(n+9,e.z),o.setFloat32(n+13,e.vx),o.setFloat32(n+17,e.vy),o.setFloat32(n+21,e.vz),o.setFloat32(n+25,e.edge),o.setUint16(n+29,he(e.yaw)),o.setInt16(n+31,_e(e.pitch)),o.setUint16(n+33,e.ack&65535),o.setUint8(n+35,e.mode&7|(e.wall&7)<<3|(e.jumps&1)<<6|e.dashes<<7),o.setUint8(n+36,e.t),o.setUint8(n+37,e.dash|(e.by>>2&3)<<6),o.setUint8(n+38,e.coyote&7|(e.buffer&7)<<3|(e.held&T.JUMP?64:0)|(e.held&T.DASH?128:0)),o.setUint8(n+39,e.stun|(e.by&3)<<6);let r=e.hp|e.cool<<3|(e.ammo<0?le:e.ammo)<<6|e.down<<13|!!e.rack<<20|!!e.blade<<21|!!e.wield<<22|!!e.zap<<23;o.setUint8(n+40,r>>16),o.setUint16(n+41,r&65535),o.setUint8(n+43,e.shots),o.setUint8(n+44,e.hits),o.setUint8(n+45,(e.swing??0)&63|((e.cut??0)&3)<<6),o.setUint8(n+46,(e.lost??0)&7|((e.cut??0)&4)<<1|(e.fried?16:0)|(e.heavy?32:0)),o.setUint8(n+47,e.charge??0),o.setUint8(n+48,e.lock??0),o.setUint8(n+49,(e.foe??0)&15|(e.pressed?128:0)),o.setUint8(n+50,e.pushes??0),o.setUint8(n+51,e.away??0),o.setUint8(n+52,(e.rail??-1)+1),o.setUint8(n+53,+!!e.railed|!!e.inRail<<1|!!e.zapping<<2|!!e.rifled<<3|!!e.inRifle<<4|!!e.hot<<5|(e.held&T.USE?64:0)),o.setUint8(n+54,e.slow??0),o.setUint8(n+55,e.mag??0),o.setUint8(n+56,e.cap??0),o.setUint8(n+57,e.reload??0),o.setUint8(n+58,(e.rifle??-1)+1),o.setUint8(n+59,e.clip??0),o.setUint8(n+60,e.heat??0),o.setUint8(n+61,(e.nades??0)<<6|(e.lob??0))}),t.forEach((e,t)=>{let r=n+t*54;ce.forEach((t,n)=>o.setFloat32(r+4*n,e[t])),o.setUint8(r+52,e.driver),o.setUint8(r+53,e.rider)}),o.setUint8(r,e.score[0]),o.setUint8(r+1,e.score[1]),o.setUint16(r+2,e.clock&32767|(e.over?32768:0));let s=e.packs??0;o.setUint16(r+4,Math.floor(s/2**32)),o.setUint32(r+6,s%2**32);let c=r+10;for(let t of e.flags)o.setUint8(c,t.state),t.state===w.CARRIED?o.setUint8(c+1,t.by):t.state===w.DROPPED&&(o.setInt16(c+1,ge(t.x*ue)),o.setInt16(c+3,ge(t.y*ue)),o.setInt16(c+5,ge(t.z*ue)),o.setUint8(c+7,Math.min(255,t.left))),c+=xe(t.state);i.length&&o.setUint8(c++,i.length);for(let e of i)o.setUint8(c,e.id),o.setUint8(c+1,e.by&127|(e.burst?128:0)),[e.x,e.y,e.z].forEach((e,t)=>o.setInt16(c+2+2*t,ge(e*de))),o.setUint8(c+8,Math.round(Math.atan2(-e.dx,-e.dz)*fe)&255),o.setInt8(c+9,Math.round(Math.asin(Math.max(-1,Math.min(1,e.dy)))*pe)),o.setUint8(c+10,e.arc?128|e.arc:e.power===7?64|Math.min(63,Math.round(e.v)):e.power??1),c+=11;return o.buffer},Ce=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},we=(e,t,n)=>{let r=Math.imul(e,374761393)+Math.imul(t,668265263)+Math.imul(n,144665)|0;return r=Math.imul(r^r>>>13,1274126177),((r^r>>>16)>>>0)/4294967296},j=(e,t,n)=>{let[r,i]=[Math.floor(e),Math.floor(t)],[a,o]=[e-r,t-i].map(e=>e*e*(3-2*e)),s=(e,t)=>we(r+e,i+t,n);return(s(0,0)*(1-a)+s(1,0)*a)*(1-o)+(s(0,1)*(1-a)+s(1,1)*a)*o},Te=/* @__PURE__ */ new WeakMap,Ee=e=>{let t=Te.get(e);if(t)return t;let{hole:n,bound:r,cell:i,at:a,pits:o=[]}=e,s=o.reduce((e,t)=>[Math.min(e[0],t[0]),Math.min(e[1],t[1]),Math.max(e[2],t[2]),Math.max(e[3],t[3])],[1/0,1/0,-1/0,-1/0]),[c,l,u,d]=r,f=Math.floor((c-u)/i)*i,p=Math.floor((l-d)/i)*i,m=Math.ceil((c+u-f)/i)+1,h=Math.ceil((l+d-p)/i)+1,g=new Float32Array(m*h),_=-1/0;for(let e=0;e<h;e++)for(let t=0;t<m;t++)g[t+e*m]=a(f+t*i,p+e*i),_=Math.max(_,g[t+e*m]);let v=new Uint8Array(m*h);for(let[e,t,n,r]of o)for(let a=Math.floor((t-p)/i)-1;a<=Math.floor((r-p)/i)+1;a++)for(let t=Math.floor((e-f)/i)-1;t<=Math.floor((n-f)/i)+1;t++)t>=0&&a>=0&&t<m&&a<h&&(v[t+a*m]=1);let y={x0:f,z0:p,cell:i,nx:m,nz:h,h:g,hole:n,pits:o,pitted:v,box:s,bound:r,top:_};return Te.set(e,y),y},De=(e,t,n)=>{let r=e.relief;if(!r||t>r.hole[0]&&t<r.hole[2]&&n>r.hole[1]&&n<r.hole[3])return-1/0;let i=Math.min(Math.max((t-r.x0)/r.cell,0),r.nx-1),a=Math.min(Math.max((n-r.z0)/r.cell,0),r.nz-1),o=Math.min(Math.floor(i),r.nx-2),s=Math.min(Math.floor(a),r.nz-2);if(r.pitted[o+s*r.nx]&&r.pits.some(e=>t>=e[0]&&t<=e[2]&&n>=e[1]&&n<=e[3]))return-1/0;let[c,l]=[i-o,a-s],u=o+s*r.nx,[d,f,p,m]=[r.h[u],r.h[u+1],r.h[u+r.nx],r.h[u+r.nx+1]];return c>=l?d+(f-d)*c+(m-f)*l:d+(p-d)*l+(m-p)*c},Oe=(e,t)=>{if(!t.relief)return;let[n,r,i,a]=t.relief.bound,[o,s]=[(e.x-n)/i,(e.z-r)/a],c=o*o+s*s;if(c<=1)return;let l=1/Math.sqrt(c);e.x=n+o*l*i,e.z=r+s*l*a;let[u,d]=[o*l/i,s*l/a],f=(e.vx*u+e.vz*d)/(u*u+d*d);f>0&&(e.vx-=f*u,e.vz-=f*d)},ke=1,Ae=6,je=(e,t,n,r,i=0)=>{let a=e.relief;if(!a||Math.min(t[1],t[1]+n[1]*r)-i>a.top)return r;let[o,s]=[0,r];for(let e of[0,1]){let[r,i,c,l]=[t[e*2],n[e*2],a.hole[e],a.hole[e+2]];if(i){let[e,t]=[(c-r)/i,(l-r)/i];o=Math.max(o,Math.min(e,t)),s=Math.min(s,Math.max(e,t))}else(r<=c||r>=l)&&(s=-1)}let c=r=>t[1]+n[1]*r-i-De(e,t[0]+n[0]*r,t[2]+n[2]*r);if(!n[0]&&!n[2]){let e=c(0);return e<0?0:n[1]<0?Math.min(r,e/-n[1]):r}for(let[e,t]of o<s?[[0,o],[s,r]]:[[0,r]]){if(e<t&&c(e)<0)return e;for(let n=e;n<t;n+=ke){let e=Math.min(n+ke,t);if(c(e)<0){let[t,r]=[n,e];for(let e=0;e<Ae;e++){let e=(t+r)/2;c(e)<0?r=e:t=e}return t}}}return r},Me=4,Ne=1024,Pe=(e,t)=>(e+Ne)*(2*Ne)+t+Ne,Fe=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),Ie=(e,t=Me)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=Fe(e[0],t);a<=Fe(r[0],t);a++)for(let o=Fe(e[2],t);o<=Fe(r[2],t);o++){let e=Pe(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),e.relief?{def:e,cell:t,grid:n,relief:Ee(e.relief)}:{def:e,cell:t,grid:n}},Le=(e,t,n,r)=>{let i=[];for(let a=Fe(t-r,e.cell);a<=Fe(t+r,e.cell);a++)for(let t=Fe(n-r,e.cell);t<=Fe(n+r,e.cell);t++)for(let n of e.grid.get(Pe(a,t))??[])i.includes(n)||i.push(n);return i},Re=(e,t,n,r,i=0)=>{let a=ze(e,t,n,r,i);return e.relief?je(e,t,n,a,i):a},ze=(e,t,n,r,i)=>{let{cell:a,def:o}=e,s=r,c=Fe(t[0],a),l=Fe(t[2],a),u=Math.sign(n[0]),d=Math.sign(n[2]),f=u?((c+ +(u>0))*a-t[0])/n[0]:1/0,p=d?((l+ +(d>0))*a-t[2])/n[2]:1/0,m=f,h=p,g=u?a/Math.abs(n[0]):1/0,_=d?a/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(Pe(c,l))??[]){let e=o.brushes[r],[a,c]=[0,s];for(let r=0;r<3&&a<=c;r++){if(!n[r]){(t[r]<e.min[r]-i||t[r]>e.max[r]+i)&&(c=-1);continue}let o=(e.min[r]-i-t[r])/n[r],s=(e.max[r]+i-t[r])/n[r];a=Math.max(a,Math.min(o,s)),c=Math.min(c,Math.max(o,s))}a<=c&&c>0&&a<s&&(s=a)}if(Math.min(m,h)>=s||Math.abs(c)>Ne||Math.abs(l)>Ne)return s;m<h?(c+=u,m+=g):(l+=d,h+=_)}},Be=(e,t,n)=>{let[r,i,a]=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],o=Math.hypot(r,i,a);return o>0&&Re(e,t,[r/o,i/o,a/o],o)<o-1e-4},M=1/60,Ve=Math.PI*2,He=1e-6,N=.01,Ue=.001,We=e=>(e%Ve+Ve)%Ve,P=e=>[-Math.sin(e),-Math.cos(e)],F=Math.fround,Ge=Math.sqrt,Ke=(e,t,n)=>Math.min(Math.max(e,t),n),I=(e,t)=>Ge(e*e+t*t),qe=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],Je={vx:0,vz:0,mode:O.GROUND,t:0,wall:se.NONE,edge:0,jumps:1,dashes:1,dash:0,stun:0,coyote:6,buffer:0,held:0,hp:5,ammo:-1,cool:0,mag:0,cap:0,reload:0,rack:!1,down:0,shots:0,hits:0,blade:!1,wield:!1,swing:0,cut:0,zap:!1,lost:D.NONE,rail:-1,railed:!1,rifle:-1,clip:0,rifled:!1,nades:0,lob:0,inRifle:!1,inRail:!1,zapping:!1,slow:0,fried:!1,heavy:!1,ev:0,fall:0},Ye=(e,t,n,r=0)=>{let{spawns:i}=t.def.teams[r],[a,o,s,c]=i[(n%i.length+i.length)%i.length];return{id:e,x:F(a),y:F(o),z:F(s),vy:0,yaw:We(c),pitch:0,ground:!0,...Je}},Xe=(e,t,n)=>{let{yaw:r,pitch:i,id:a,shots:o,hits:s}=e;Object.assign(e,Ye(a,t,a,n),{yaw:r,pitch:i,shots:o,hits:s,ev:e.ev|k.RESPAWN})},Ze=e=>e===O.GROUND||e===O.SLIDE||e===O.CROUCH,L=e=>e.mode===O.SLIDE||e.mode===O.CROUCH?n:t,Qe=e=>e.mode===O.SLIDE||e.mode===O.CROUCH?.7:1.6,$e=e=>I(e.vx,e.vz),et=(e,t,n)=>e.max[1]>t+.5+N&&e.min[1]<t+n-N,tt=(e,t,n)=>[t-Ke(t,e.min[0],e.max[0]),n-Ke(n,e.min[2],e.max[2])],nt=(t,n,r)=>rt(t,n,r,e),rt=(e,t,n,r)=>{let{brushes:i}=t.def,a=Le(t,e.x,e.z,2*r),o=(r-He)**2,[s,c]=[0,0];for(let t=0;t<4;t++){let t=0,l=0,u=0;for(let s of a){let a=i[s];if(!et(a,e.y,n))continue;let[c,d]=tt(a,e.x,e.z),f=c*c+d*d;if(f>=o)continue;if(f){let e=Ge(f);r-e>t&&(t=r-e,l=c/e*t,u=d/e*t);continue}let[p,m,h]=[[e.x-a.min[0],-1,0],[a.max[0]-e.x,1,0],[e.z-a.min[2],0,-1],[a.max[2]-e.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);p+r>t&&(t=p+r,[l,u]=[m*t,h*t])}if(!t)break;e.x+=l,e.z+=u,s+=l,c+=u}return[s,c]},it=(e,t,n)=>{let[[r,i,a],[o,s,c]]=[e.a,e.b],[l,u]=[o-r,c-a],d=l*l+u*u,f=d?Ke(((t-r)*l+(n-a)*u)/d,0,1):0;return[t-r-f*l,n-a-f*u,i+f*(s-i)]},at=(t,n,r)=>{let[i,a]=[0,0];for(let o of n){let[n,s,c]=it(o,t.x,t.z),l=o.r+e,u=n*n+s*s;if(u>=(l-He)**2||c+o.h<=t.y+.5+N||c>=t.y+r-N)continue;let d=Ge(u),[f,p]=[o.b[0]-o.a[0],o.b[2]-o.a[2]],m=I(f,p),[h,g]=d?[n/d,s/d]:m?[p/m,-f/m]:[1,0];t.x+=h*(l-d),t.z+=g*(l-d),i+=h*(l-d),a+=g*(l-d)}return[i,a]},ot=(t,n,r,i=[])=>{let{brushes:a}=n.def,o=(e-He)**2,s=De(n,t.x,t.z),c=1/0;for(let i of Le(n,t.x,t.z,e)){let e=a[i],[n,l]=tt(e,t.x,t.z);n*n+l*l>=o||(e.max[1]<=t.y+.5+N?s=Math.max(s,e.max[1]):e.min[1]>=t.y+r-N&&(c=Math.min(c,e.min[1])))}for(let e of i){let[n,i,a]=it(e,t.x,t.z);n*n+i*i>=(e.r+.4-He)**2||(a+e.h<=t.y+.5+N?s=Math.max(s,a+e.h):a>=t.y+r-N&&(c=Math.min(c,a)))}return[s,c]},st=(e,t,n,r)=>{let i=De(e,t,n);for(let a of Le(e,t,n,0)){let{min:o,max:s}=e.def.brushes[a];t>=o[0]&&t<=s[0]&&n>=o[2]&&n<=s[2]&&s[1]<=r&&(i=Math.max(i,s[1]))}return i},ct=(t,n)=>{let r=(e-He)**2;return Le(n,t.x,t.z,e).every(e=>{let i=n.def.brushes[e],[a,o]=tt(i,t.x,t.z);return a*a+o*o>=r||!et(i,t.y,1.8)})},lt=(t,n,r,i,a)=>{let o=(e-He)**2;return Le(t,n,r,e).every(e=>{let s=t.def.brushes[e],[c,l]=tt(s,n,r);return c*c+l*l>=o||s.max[1]<=i||s.min[1]>=a})},ut=(e,t)=>{let[n,r]=qe[t],i=n?0:2;return{a:i,o:2-i,sign:n||r,c:n?e.x:e.z,co:n?e.z:e.x}},dt=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=ut(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-Ue&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},ft=(t,n,r)=>{let a;for(let o of Le(n,t.x,t.z,e+i)){let s=n.def.brushes[o],c=dt(s,t,r,i);c!==void 0&&s.min[1]<t.y+.5&&s.max[1]>t.y+1.8&&(a=Math.min(a??1/0,Math.max(0,c-e)))}return a},pt=(t,n)=>{let[r,i]=P(t.yaw),a;for(let o=1;o<=4;o++){let[s,c]=qe[o];if(o===t.wall||r*s+i*c<.5)continue;let{a:l,sign:u}=ut(t,o);for(let r of Le(n,t.x,t.z,e+.2)){let i=n.def.brushes[r],s=i.max[1],c=s-t.y;if(dt(i,t,o,.2)===void 0||c<1.2||c>2.4||i.min[1]>s-.25||a&&a.top>=s)continue;let d=u>0?i.min[l]:i.max[l],f=d-u*(e+.03),p=d+u*.2,[m,h]=l===0?[f,t.z]:[t.x,f],[g,_]=l===0?[p,t.z]:[t.x,p];lt(n,m,h,Math.min(t.y,s-2)+N,s+1.8)&&lt(n,g,_,s+N,s+1.8)&&(a={side:o,top:s,hang:f})}}return a},mt=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=ut(e,e.wall);return Le(t,e.x,e.z,0).some(s=>{let c=t.def.brushes[s],l=i>0?a-c.min[n]:c.max[n]-a;return F(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},ht=e=>20*(e.def.gravity??1),gt=(e,n)=>{if(e.vy>=0)return!1;let[r]=ot(e,n,t),i=6*M;return e.y-r<=-e.vy*i+.5*ht(n)*i*i},R=(e,t)=>{e.mode=t,e.t=0},_t=e=>!!e.zap&&e.stun>24,vt=(e,t,n,r=48,i=6)=>{e.stun=r,e.vx=F(t*i),e.vz=F(n*i),e.dash=Math.min(e.dash,50),e.coyote=0,e.buffer=0,(e.mode===O.HANG||e.mode===O.CLIMB)&&(e.vy=0),(e.mode===O.HANG||e.mode===O.CLIMB||e.mode===O.WALLRUN||e.mode===O.RIDE)&&(R(e,O.AIR),e.edge=0)},yt=(e,t)=>{let n=I(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},bt=(t,n,r,i)=>{let[a,o]=[r.wx,r.wz];for(let r of Le(n,t.x,t.z,e+Ue)){let e=n.def.brushes[r],[s,c]=tt(e,t.x,t.z),l=I(s,c);if(l>0&&l<=.4+Ue&&et(e,t.y,i)){let e=(-a*s-o*c)/l;e>0&&(a+=e*s/l,o+=e*c/l)}}return[a,o]},xt=(e,t,n)=>{let r=I(t[0],t[1]);if(r<He){let t=I(e.vx,e.vz),n=t?Math.max(0,t-45*M)/t:0;e.vx*=n,e.vz*=n;return}let[i,a]=[t[0]/r,t[1]/r],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a],l=I(s,c);if(l){let e=Math.max(0,l-45*M)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*M):Math.max(n,o-12*M),e.vx=s+o*i,e.vz=c+o*a},St=(e,t,n,r,i,a)=>{let o=e.y;e.x+=e.vx*M,e.z+=e.vz*M;let[s,c]=nt(e,t,n),[l,u]=at(e,a,n);if(l||u){let[r,i]=nt(e,t,n);s+=l+r,c+=u+i}let d=I(s,c);if(d){let t=(e.vx*s+e.vz*c)/d;t<0&&(e.vx-=t*s/d,e.vz-=t*c/d)}Oe(e,t);let[f,p]=ot(e,t,n,a),m=e.vy-r*ht(t)*M;if(e.y+=(e.vy+m)/2*M,e.vy=m,e.y+n>p&&(e.y=p-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=f+N:e.y<f){if(e.y=f,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&f>=o-.5)return e.y=f,e.vy=0,0;return-1},Ct=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=k.JUMP},wt=(e,n,r)=>{let[i,a]=qe[e.wall],o=t=>{R(e,t),e.edge=0};if(r.keys&(T.BACK|T.CROUCH))o(O.AIR),e.coyote=0;else if(r.jump&&r.fx*i+r.fz*a<0)o(O.AIR),e.vx=-i*4,e.vz=-a*4,Ct(e,6);else if(r.jump||r.fwd&&e.t>=6)R(e,O.CLIMB);else if(e.t>=30)o(O.AIR),e.coyote=0;else{let r=Math.max(e.edge-2,ot(e,n,t)[0]);e.y+=Ke(r-e.y,-8*M,8*M)}},Tt=(e,t)=>{let[n,r]=qe[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*M):(e.x+=n*a*M,e.z+=r*a*M),e.y>=e.edge&&mt(e,t)?(R(e,O.GROUND),e.vx=n*3,e.vz=r*3,e.vy=0,e.edge=0,e.wall=se.NONE,e.coyote=6,e.ev|=k.CLIMB):e.t>=40&&(R(e,e.y>=e.edge?O.GROUND:O.AIR),e.edge=0,e.wall=se.NONE)},Et=(e,t,n)=>{let[r,i]=qe[e.wall],a=e.vx*r+e.vz*i,[o,s]=[e.vx-a*r,e.vz-a*i],c=I(o,s);if(n.jump)R(e,O.AIR),e.vx=o-r*5,e.vz=s-i*5,Ct(e,6.5),e.jumps=1,e.dashes=1,e.ev|=k.WALLRUN_END;else{let a=ft(e,t,e.wall);if(a===void 0||!n.fwd||c<3.5||e.t>=60){R(e,O.AIR),e.ev|=k.WALLRUN_END;return}let l=Math.max(0,c-1.5*M)/c;e.vx=o*l,e.vz=s*l;let u=Math.min(a,4*M);e.x+=r*u,e.z+=i*u}},Dt=(e,t,n)=>{if(!n.fwd)return;let r=I(e.vx,e.vz);if(!(r<4.5))for(let n=1;n<=4;n++){let[i,a]=qe[n],o=e.vx*i+e.vz*a,[s,c]=[e.vx-o*i,e.vz-o*a];if(n!==e.wall&&o<=.75*r&&o>=-.2*r&&ft(e,t,n)!==void 0){let t=I(s,c),i=Math.max(t,.9*r)/t;R(e,O.WALLRUN),e.wall=n,[e.vx,e.vz]=[s*i,c*i],e.vy=Ke(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=k.WALLRUN_START;return}}},Ot=(e,t)=>{R(e,O.HANG),e.wall=t.side,e.edge=F(t.top),t.side<=se.WEST?e.x=t.hang:e.z=t.hang,e.vx=e.vy=e.vz=0,e.jumps=1,e.dashes=1,e.coyote=0,e.buffer=0,e.ev|=k.GRAB},kt=(e,t,n)=>{let i=e.mode===O.GROUND;if(n.dash&&e.dash===0&&(i||(e.mode===O.AIR||e.mode===O.WALLRUN)&&e.dashes>0)){let[t,r]=n.wx||n.wz?[n.wx,n.wz]:[n.fx,n.fz];i||(e.dashes--,e.vy=0,e.mode===O.WALLRUN&&(R(e,O.AIR),e.ev|=k.WALLRUN_END)),e.vx=t*16,e.vz=r*16,e.dash=60,e.ev|=k.DASH}let a=e.dash>50;e.mode===O.WALLRUN&&Et(e,t,n),Ze(e.mode)&&At(e,t,n,a),e.mode===O.AIR&&jt(e,t,n,a);let o=a&&e.vy<=0?0:e.mode===O.WALLRUN?.15:1,s=e.mode,c=St(e,t,L(e),o,Ze(s),n.bodies);if(c>=0){if(!Ze(e.mode)){if(e.ev|=k.LAND|(e.mode===O.WALLRUN?k.WALLRUN_END:0),e.fall=c,e.jumps=1,e.dashes=1,e.wall=se.NONE,n.keys&T.CROUCH){let t=I(e.vx,e.vz)>=r;R(e,t?O.SLIDE:O.CROUCH),e.ev|=t?k.SLIDE_START:0}else R(e,O.GROUND)}e.coyote=6}else Ze(e.mode)&&(e.ev|=e.mode===O.SLIDE?k.SLIDE_END:0,R(e,O.AIR));if(e.mode===O.AIR){let r=pt(e,t);r?Ot(e,r):Dt(e,t,n)}},At=(e,i,a,s)=>{let c=(a.keys&T.CROUCH)!==0;if(e.buffer>0&&(e.mode===O.GROUND||ct(e,i))){e.ev|=e.mode===O.SLIDE?k.SLIDE_END:0,R(e,O.AIR),Ct(e,7);return}let l=I(e.vx,e.vz);if(e.mode===O.GROUND&&c){let t=l>=r;R(e,t?O.SLIDE:O.CROUCH),e.ev|=t?k.SLIDE_START:0}else e.mode===O.SLIDE&&(e.t>=60||l<4.5||a.stumble)?(e.ev|=k.SLIDE_END,R(e,!c&&ct(e,i)?O.GROUND:O.CROUCH)):e.mode===O.SLIDE&&!c&&ct(e,i)?(e.ev|=k.SLIDE_END,R(e,O.GROUND)):e.mode===O.CROUCH&&!c&&ct(e,i)&&R(e,O.GROUND);if(!s){if(a.stumble){if(l>2.5){let t=Math.max(o,l-12*M)/l;e.vx*=t,e.vz*=t}else xt(e,bt(e,i,a,L(e)),o)}else if(e.mode===O.SLIDE){let t=Math.max(0,l-4*M)/l;e.vx*=t,e.vz*=t}else if(e.mode===O.CROUCH)xt(e,bt(e,i,a,n),3);else{let n=(a.keys&T.SPRINT)!==0&&a.fwd;xt(e,bt(e,i,a,t),n?9:6)}}},jt=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?Ct(e,7):e.jumps>0&&!gt(e,t)&&(e.jumps--,Ct(e,6),e.ev=e.ev&~k.JUMP|k.DOUBLE)),r||!n.wx&&!n.wz)return;let i=I(e.vx,e.vz);e.vx+=n.wx*14*M,e.vz+=n.wz*14*M,yt(e,Math.max(i,6))},Mt=(e,t,n,r=0,i=[])=>{e.yaw=We(t.yaw),e.pitch=Math.max(-1.55,Math.min(1.55,t.pitch));let a=(t.keys&T.FORWARD?1:0)-(t.keys&T.BACK?1:0),o=(t.keys&T.RIGHT?1:0)-(t.keys&T.LEFT?1:0),s=_t(e)?1/0:I(a,o)||1,[c,l]=P(e.yaw),u=n=>(t.keys&n)!==0&&(e.held&n)===0,d=e.stun>0,f=e.mode===O.RIDE,p={keys:t.keys,stumble:d,jump:!d&&!f&&u(T.JUMP),dash:!d&&!f&&u(T.DASH),fwd:a>0,wx:(c*a-l*o)/s,wz:(l*a+c*o)/s,fx:c,fz:l,bodies:i},m=e.mode;e.ev=0,e.fall=0,p.jump&&(e.buffer=7),d&&e.stun--,e.dash>0&&(e.dash--,e.dash===50&&yt(e,10)),e.mode===O.HANG&&wt(e,n,p),e.mode===O.CLIMB?Tt(e,n):e.mode!==O.HANG&&!f&&kt(e,n,p),e.slow&&(e.slow--,yt(e,3)),e.y<n.def.floor&&Xe(e,n,r),e.t=e.mode===m?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===O.AIR&&m===O.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=t.keys&(T.JUMP|T.DASH|T.USE),e.ground=Ze(e.mode),e.x=F(e.x),e.y=F(e.y),e.z=F(e.z),e.vx=F(e.vx),e.vy=F(e.vy),e.vz=F(e.vz),e.edge=F(e.edge)},Nt=.7,Pt=e=>{let[t,n]=[e&T.LEFT,e&T.RIGHT];return t&&!n?E.LEFT:n&&!t?E.RIGHT:e&T.FORWARD?E.THRUST:E.SLASH},Ft=e=>{let t=p[e.cut??0];return e.heavy?{...t,ticks:Math.round((t.ticks-t.hold)*m),strike:Math.round((t.strike-t.hold)*m),reach:t.reach+v,arc:t.arc*y,hp:t.hp+_}:t},It=(e,t,n,{reach:r,arc:i}=Ft(t))=>{let[a,o]=P(t.yaw),s=[t.x,t.y+Nt*L(t),t.z];return n.filter(n=>{let[c,l]=[n.x-t.x,n.z-t.z],u=Math.hypot(c,l);return u-.4>r||t.y>=n.y+L(n)||n.y>=t.y+L(t)?!1:(u>.4?Math.abs(Math.atan2(a*l-o*c,a*c+o*l)):0)<=i+(u>.4?Math.asin(.4/u):Math.PI)&&!Be(e,s,[n.x,n.y+.7*L(n),n.z])})},Lt=(e,t)=>{if(!t.wield||!t.swing||e.lock||t.lock)return!1;let n=Ft(t);if(Math.abs(n.strike-(n.ticks-t.swing))>9)return!1;let[r,i]=[t.x-e.x,t.z-e.z],a=Math.hypot(r,i),o=(e,t,n)=>{let[r,i]=P(e.yaw);return a<1e-6||(r*t+i*n)/a>=Math.cos(.9)};return a-.4<=Math.min(n.reach,Ft(e).reach)&&o(e,r,i)&&o(t,-r,-i)},Rt=e=>{let[t,n]=P(e.yaw),r=e.cut??0;return r===E.LEFT?[-n,t]:r===E.RIGHT?[n,-t]:[t,n]},zt=(t,n)=>{let[r,i]=P(t.yaw),[a,o]=P(n.yaw),[s,c]=[n.x-t.x,n.z-t.z],l=-i*s+r*c,u=Math.sqrt(Math.max(e*e-l*l,0)),[d,f]=[i*l-r*u,-r*l-i*u],p=-o*d+a*f,m=(t.cut??0)%4;if(m===E.SLASH)return Math.abs(p)<=ie?D.HEAD:p>0?D.ARM_R:D.ARM_L;let h=(t.y+Nt*L(t)+Math.tan(t.pitch)*Math.hypot(s,c)-n.y)/L(n);if(h>ne)return D.HEAD;let g=m===E.THRUST?p>0:(m===E.LEFT?1:-1)*(r*a+i*o)<0;return h<re?g?D.LEG_R:D.LEG_L:m===E.THRUST&&Math.abs(p)<=ie?D.NONE:g?D.ARM_R:D.ARM_L},Bt=()=>({state:w.HOME,by:0,x:0,y:0,z:0,left:0}),Vt=60,Ht=class{score=[0,0];over=!1;flags=[Bt(),Bt()];world;rules;mates=/* @__PURE__ */ new Map;clock;back=[0,0];lock=[{id:-1,left:0},{id:-1,left:0}];hold=[0,0];constructor(e,t){this.world=e,this.rules=t,this.clock=t.timeLimit*60}join(e,t,n){this.mates.set(e,{team:t,caps:0,returns:0,ground:[n.x,n.y,n.z]})}leave(e){let t=this.carrying(e),n=this.mates.get(e);t>=0&&n&&this.dropAt(t,n.ground),this.mates.delete(e)}place(e,t){let n=this.mates.get(e);n&&(n.ground=[t.x,t.y,t.z])}moved(e){let t=this.mates.get(e.id);if(!t)return;let n=this.carrying(e.id);e.ev&k.RESPAWN&&n>=0&&this.dropAt(n,t.ground),e.ground&&(t.ground=[e.x,e.y,e.z])}drop(e){let t=this.carrying(e.id),n=this.mates.get(e.id);if(t<0||!n||this.over)return!1;let r=n.ground;if(e.ground)r=[e.x,e.y,e.z];else{let t=Re(this.world,[e.x,e.y+.05,e.z],[0,-1,0],Vt);t<Vt&&(r=[e.x,e.y+.05-t,e.z])}return this.dropAt(t,r),this.lock[t]={id:e.id,left:120},this.hold[t]=120,!0}carrying(e){return this.flags.findIndex(t=>t.state===w.CARRIED&&t.by===e)}winner(){let[e,t]=this.score;return e>t?0:t>e?1:-1}tally(){return[...this.mates].map(([e,t])=>({id:e,caps:t.caps,returns:t.returns}))}reset(){this.over=!1,this.score=[0,0],this.flags=[Bt(),Bt()],this.back=[0,0],this.lock.forEach(e=>e.left=0),this.hold=[0,0],this.clock=this.rules.timeLimit*60;for(let e of this.mates.values())e.caps=e.returns=0}wire(){return{score:[...this.score],clock:Math.ceil(this.clock/60),over:this.over,flags:this.flags.map(e=>({...e}))}}tick(e){if(this.over)return--this.clock<=0?(this.reset(),`start`):void 0;for(let e of[0,1]){let t=this.flags[e];this.lock[e].left--,this.hold[e]--,t.state===w.DROPPED&&(t.left=Math.ceil(--this.back[e]/60),this.back[e]<=0&&(this.flags[e]=Bt()))}for(let t of[0,1]){let n=this.flags[t];if(n.state===w.CARRIED)continue;let r=n.state===w.HOME?this.world.def.teams[t].base:[n.x,n.y,n.z],i=e.filter(e=>Ut(e.state,r)),a=n.state===w.DROPPED&&this.hold[t]<=0?i.find(e=>e.team===t):void 0,o=i.find(e=>e.team!==t&&(e.id!==this.lock[t].id||this.lock[t].left<=0));if(a){let e=this.mates.get(a.id);e&&e.returns++,this.flags[t]=Bt()}else o&&(this.flags[t]={...Bt(),state:w.CARRIED,by:o.id})}for(let t of e){let e=this.carrying(t.id);if(e>=0&&this.flags[t.team].state===w.HOME&&Ut(t.state,this.world.def.teams[t.team].base)){this.score[t.team]++;let n=this.mates.get(t.id);n&&n.caps++,this.flags[e]=Bt()}}if(this.score.some(e=>e>=this.rules.scoreLimit)||--this.clock<=0)return this.over=!0,this.clock=600,`end`}dropAt(e,[t,n,r]){this.flags[e]={state:w.DROPPED,by:0,x:t,y:n,z:r,left:10},this.back[e]=600}},Ut=(e,t)=>Math.hypot(e.x-t[0],e.z-t[2])<1.5&&e.y<t[1]+2.2&&e.y+1.8>t[1],Wt=(e,t,n)=>{let[r,i]=[e.x-t[0],e.z-t[2]];return r*r+i*i<n*n&&Math.abs(e.y-t[1])<1},Gt=e=>{if(e.mode===O.GROUND){if(e.cut===E.LUNGE){let[t,n]=P(e.yaw);e.vx=t*13,e.vz=n*13,e.dash=60,e.ev|=k.DASH}else e.cut===E.LEAP&&(e.vy=C,e.ev|=k.JUMP)}},z={NONE:0,SHOT:1,CUT:2,RAIL:3,LASER:4,NADE:5},Kt=(e,t,n,r,i=!0,a=[])=>{let o=e.down>0,s=!o&&(e.lock??0)>0;if(Mt(e,o||s?{...t,keys:0}:t,n,r,a),e.heat=Math.max(0,(e.heat??0)-(e.zapping?0:e.hot?1:2)),e.hot=!!e.hot&&e.heat>0,e.zapping=!1,e.zap=!!e.stun&&!!e.zap,o)return e.down>0&&!--e.down&&Xe(e,n,r),z.NONE;if(s)return qt(e,t);let{rack:l,blade:u,rail:d,rifle:f}=n.def.teams[r],m=!!l&&Wt(e,l,1.2);i&&m&&!e.rack&&([e.ammo,e.mag]=[60,15]),e.rack=m,e.blade=!!e.blade||i&&!!u&&Wt(e,u,1.2);let _=!!d&&Wt(e,d,1.2);i&&_&&!e.inRail&&([e.rail,e.cap]=[240,80]),e.inRail=_;let v=!!f&&Wt(e,f,1.2);i&&v&&!e.inRifle&&([e.rifle,e.clip,e.nades]=[240,60,3]),e.inRifle=v,e.cool=Math.max(0,e.cool-1),e.lob=Math.max(0,(e.lob??0)-1);let y=e.mode===O.HANG||e.mode===O.CLIMB,{ticks:b,hold:x}=p[e.cut??0],ee=!!e.swing&&!e.heavy&&b-(e.swing??0)===x;ee&&e.wield&&i&&!y&&t.keys&T.FIRE?e.charge=Math.min((e.charge??0)+1,g):ee&&i&&!y&&(e.charge??0)>=h?([e.heavy,e.charge]=[!0,0],e.swing=Ft(e).ticks):(e.charge=ee?0:e.charge,e.swing=Math.max(0,(e.swing??0)-1),e.heavy=!!e.swing&&!!e.heavy),e.mag=Math.min(e.mag??0,Math.max(e.ammo,0));let S=[e.ammo>=0,!!e.blade,(e.rail??-1)>=0,(e.rifle??-1)>=0],te=t.keys&T.BLADE?1:t.keys&T.RAIL?2:t.keys&T.RIFLE?3:0,C=e.swing&&e.blade?1:S[te]?te:S.indexOf(!0);if(C!=(e.rifled?3:e.railed?2:+!!e.wield)&&(e.reload=0),[e.wield,e.railed,e.rifled]=[C==1,C==2,C==3],e.swing&&C>=0&&!e.blade&&(e.swing=0),!i)return[e.charge,e.reload]=[0,0],z.NONE;let[ne,re,ie,ae]=C==3?[`clip`,60,e.rifle,96]:C==2?[`cap`,80,e.rail,90]:[`mag`,15,e.ammo,78],[oe,w]=[e[ne]??0,Math.min(re,ie)];e.reload?--e.reload||(e[ne]=w):C!=1&&ie>=0&&!y&&oe<w&&(!oe||t.keys&T.RELOAD)&&([e.reload,e.charge]=[ae,0]);let E=C<0,D=E?c:Ft(e);if(e.swing&&D.ticks-e.swing===D.strike)return z.CUT;if((e.wield&&!ee||e.railed||e.rifled||y||e.reload||!e.wield&&!e.mag)&&(e.charge=0),e.rifled&&t.keys&T.SPECIAL&&!y&&e.nades&&!e.lob)return e.nades--,[e.lob,e.cool]=[60,7],e.shots=e.shots+1&255,z.NADE;if(t.keys&T.FIRE&&!y){let n=p[e.cut??0].ticks-(e.swing??0),r=!!(t.keys&T.SPECIAL)&&(!e.swing||!e.heavy&&(e.cut??0)<4&&n<=18);if(E)e.swing||([e.cut,e.heavy,e.swing]=[0,!1,c.ticks]);else if(e.wield&&(!e.swing||r))e.cut=Pt(t.keys)+(r?4:0),[e.swing,e.charge]=[p[e.cut].ticks,0],Gt(e);else if(e.rifled){if(!e.cool&&e.clip&&!e.reload)return e.rifle--,e.clip--,e.cool=3,e.shots=e.shots+1&255,z.LASER}else if(e.railed){if(e.cap&&!e.reload&&!e.hot)return e.heat=(e.heat??0)+1,e.hot=e.heat>=120,e.cool||=(e.rail--,e.cap--,2),e.zapping=!0,z.RAIL}else!e.wield&&!e.cool&&e.mag&&!e.reload&&(e.charge=Math.min((e.charge??0)+1,60))}else if(e.charge)return e.power=Math.min(Jt(e.charge),e.mag),e.charge=0,e.ammo-=e.power,e.mag-=e.power,e.shots=e.shots+1&255,e.cool=7,z.SHOT;return z.NONE},qt=(e,t)=>{let n=!!(t.keys&T.FIRE);return e.pushes=(e.pushes??0)+ +(n&&!e.pressed)&255,e.pressed=n,e.away=t.keys&(T.LEFT|T.RIGHT|T.BACK)?Math.min((e.away??0)+1,24):0,e.lock=Math.max(1,e.lock-1),[e.wield,e.swing,e.charge]=[!0,0,0],z.NONE},Jt=e=>e<10?1:1+Math.floor(4*(e-10)/50),Yt=-30,B=(e,t,n,r,i,a=A.CONCRETE)=>({min:[e,Yt,t],max:[n,i,r],top:A.CONCRETE,side:a}),V=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c});[B(4,57.7,24,76,10),B(4,36,24,53.5,10,A.GLASS),B(4,20,24,36,12.4),B(4,-5,24,7,12.4,A.GLASS),B(27,20,47,50,8),B(27,60,47,76,8,A.BRICK),V([9,12.2,39],[19,12.6,47],A.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>V([12,t,e-n],[14,t+.4*n,e-n+1],A.CONCRETE)))(53,10),V([5,10,42],[5.5,14,42.5],A.STEEL),V([5,10,50],[5.5,14,50.5],A.STEEL),V([8,12.4,24],[20,12.85,24.45],A.STEEL),V([36,8,22],[37,14.5,48],A.PAINT,A.PAINT,[.15,.72,.62]),V([30,8,28],[34,10,32],A.CONCRETE),V([40,8,30],[44,10.2,34],A.PAINT,A.PAINT,[1,.3,.06]),V([28,9.2,44],[35,12,46],A.STEEL,A.PAINT,[.2,.42,1]),V([41.5,7.6,50],[42,8,60],A.STEEL),V([30,8,64],[34,9.6,68],A.PAINT,A.PAINT,[.2,.8,.3])];var Xt=240,H=[1,.22,.26],Zt=[.2,.46,1],Qt=[H,Zt],$t=[1,.42,.08],en=[.12,.7,.62],tn=(e,t,n,r,i,a,o)=>V([e,t,n],[r,i,a],A.PAINT,A.PAINT,o),nn=(e,t,n,r,i,a,o,s=Yt)=>{let c=Math.ceil((o-a)/.46);return Array.from({length:c},(l,u)=>{let[d,f]=[t+(n-t)*u/c,t+(n-t)*(u+1)/c].sort((e,t)=>e-t),p=a+(o-a)*(u+1)/c;return e===0?V([d,s,r],[f,p,i],A.CONCRETE):V([r,s,d],[i,p,f],A.CONCRETE)})},rn=(e,t,n,r,i,a,o)=>o.map((o,s)=>V([e+s*n,a,t+s*r],[e+s*n+4,o,t+s*r+i],A.STEEL,A.CONCRETE)),an=[B(12,212,52,240,26,A.GLASS),tn(12,26,212,52,26.12,212.5,H),tn(12,26,239.5,52,26.12,240,H),tn(12,26,212.5,12.5,26.12,239.5,H),tn(51.5,26,212.5,52,26.12,239.5,H),tn(11.6,12,222,12,25.8,232,H),tn(28,12,211.4,31,25.5,212,H),V([19,26,222],[22,27.4,225],A.STEEL),V([42,26,222],[45,27.4,225],A.STEEL),V([29,26,229],[35,27.1,229.6],A.CONCRETE),V([24.5,26,215],[35,27.5,219],A.STEEL,A.PAINT,H),B(6,164,26,201,26,A.GLASS),B(6,134,26,147,26,A.GLASS),B(6,201,26,212,19),B(15,147,26,164,19),V([14,26,164],[15,32,196],A.PAINT,A.PAINT,en),V([14,18,147],[15,32,164],A.PAINT,A.PAINT,en),V([14,26,134],[15,32,147],A.PAINT,A.PAINT,en),...rn(6,201,7,0,4,19,[21.2,23.4,25]),...[[18,152,22,156,21.2],[18,158,22,162,23.4],[23,160,26,164,25]].map(([e,t,n,r,i])=>V([e,19,t],[n,i,r],A.STEEL,A.CONCRETE)),V([20,26,178],[23,27.3,181],A.STEEL),V([8,26,176],[11,27.2,179],A.STEEL),V([8,26,190],[11,27.3,193],A.STEEL),V([20,26,140],[23,27.3,143],A.STEEL),B(32,186,76,209,19),tn(32,19,207.5,76,19.1,209,H),...rn(33,209,7,0,3,19,[21.2,23.4,25]),...[[28,196,32,200,21.2],[28,190,32,194,23.4],[26,184,30,188,25]].map(([e,t,n,r,i])=>V([e,Yt,t],[n,i,r],A.STEEL,A.CONCRETE)),B(32,166,64,182,21.2,A.GLASS),B(32,140,64,161,19),V([40,21.2,172],[44,22.6,176],A.STEEL),V([52,19,148],[57,20.3,151],A.STEEL),V([38,19,196],[41,20.4,199],A.STEEL),V([60,19,200],[63,20.4,203],A.STEEL),V([52,19,190],[58,20.6,194],A.STEEL),V([66,19,204],[72,20.2,207],A.STEEL),V([56,21.2,170],[60,22.4,174],A.STEEL),V([34,19,152],[37,20.3,156],A.STEEL),...rn(36,135,18,0,3,15,[17.2,17.2]),...rn(6.5,129,6,0,4,15,[17.2,19.4,21.6,23.8]),B(76,213,100,240,14.5,A.STEEL),tn(76,14.5,238.5,100,14.6,240,H),B(76,185,100,209,14.5),B(76,138,100,181,14.5,A.GLASS),V([80,15.7,158],[96,17.7,162],A.STEEL,A.PAINT,$t),V([82,14.5,234],[85,15.9,237],A.STEEL),V([91,14.5,190],[94,15.9,193],A.STEEL),V([80,14.5,204],[83,15.6,207],A.STEEL),V([78,14.5,170],[81,15.9,173],A.STEEL),V([92,14.5,146],[95,15.7,149],A.STEEL),V([92,14.5,222],[96,15.8,226],A.STEEL),...nn(0,76,52,226,232,14.5,26),...nn(0,85,76,196,202,14.5,19,14.5)],on=[B(6,106,62,134,15),B(62,106,100,134,14.5),V([34,15,112],[54,17.2,128],A.CONCRETE),tn(38,17.2,116,50,17.3,124,$t),...[[35,113],[35,126.2],[51,113],[51,126.2]].map(([e,t])=>V([e,17.2,t],[e+.8,21.5,t+.8],A.STEEL)),V([34.6,21.5,112.6],[52.2,21.9,127.4],A.GLASS),V([14,15,114],[17,16.5,117],A.STEEL),V([14,15,123],[17,16.5,126],A.STEEL),V([56,15,114],[59,16.5,117],A.STEEL),V([56,15,123],[59,16.5,126],A.STEEL),V([15.35,25.5,106],[15.85,26,134],A.STEEL),V([70,14.5,108],[70.8,38,108.8],A.STEEL),V([70,14.5,131.2],[70.8,38,132],A.STEEL),V([66,14.5,110],[69,15.9,113],A.STEEL),V([66,14.5,127],[69,15.9,130],A.STEEL)],sn=e=>({...e,min:[e.min[0],e.min[1],Xt-e.max[2]],max:[e.max[0],e.max[1],Xt-e.min[2]],tint:e.tint===H?Zt:e.tint}),cn=(e,t,n)=>[...[16,22,28,34,40].map(n=>[n,26,t,e]),...[19,31,43].map(t=>[t,26,n,e])],ln=[[20,26,190],[48,21.2,172],[48,19,200],[88,14.5,198]],un=[[21,26,168],[16,26,140],[46,19,144],[36,21.2,178],[58,19,156],[64,19,196],[88,14.5,216],[88,14.5,172],[90,14.5,150]],dn=[[19.5,26,179],[46,19,152],[39.5,21.2,172],[88,14.5,186],[88,14.5,207]],fn={armor:!0,name:`Highline`,brushes:[...an,...an.map(sn),...on],teams:[{base:[32,26,224],spawns:cn(0,236,231),rack:[30.75,27.5,217],blade:[33.25,27.5,217],rail:[28.25,27.5,217],rifle:[25.75,27.5,217]},{base:[32,26,16],spawns:cn(Math.PI,4,9),rack:[30.75,27.5,23],blade:[33.25,27.5,23],rail:[28.25,27.5,23],rifle:[25.75,27.5,23]}],packs:[...ln,...ln.map(([e,t,n])=>[e,t,Xt-n]),[24,15,112],[24,15,128]],ammo:[...un,...un.map(([e,t,n])=>[e,t,Xt-n]),[12,15,116],[12,15,124]],cells:[...dn,...dn.map(([e,t,n])=>[e,t,Xt-n]),[28,15,Xt/2]],floor:-25,sun:{dir:[.8,.6,0],color:[2.6,2.3,1.8]},sky:[[.04,.2,.72],[.72,.86,.98]],fog:[.72,.86,.98,.0035]},{CONCRETE:pn,METAL:mn,STEEL:U,PAINT:hn}=A,W=(e,t,n,r,i,a,o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c}),gn=({min:e,max:t},n,r=n)=>({min:e,max:t,top:n,side:r}),_n=(e,t,n,r,i,a)=>({min:[e,t,n],max:[r,i,a]}),vn=22.4,yn=e=>e<5?vn:vn*Math.sqrt(1-((e-5)/12)**2),bn=e=>Math.round(e*10)/10,xn=[0,10.5,13.5,15.5,17],Sn=e=>[[1,.39],[.93,.71],[.71,.93],[.39,1]].map(([t,n])=>[bn(t*e),bn(n*e)]),[[Cn,wn],[Tn,En]]=Sn(22.599999999999998),[G,Dn]=[.4,2.48],K=[80,236],On=[_n(111,0,222,125,5,230),_n(96,0,196,110,5,204)],kn=[_n(102,0,223.2,111,3.5,227.2),_n(98,0,204,102,3.5,227.2)],[[An,,jn],[Mn,Nn,Pn],[Fn,,In],[Ln]]=kn.flatMap(e=>[e.min,e.max]),[[Rn,zn],[Bn,Vn]]=[[19.8,6.7],[16,13.5]],Hn=[[0,-Rn,2,3,2.8],[Bn,-10.8,2,3.5,2]],Un=e=>[...new Map(e.flatMap(([e,t,n,r])=>[1,-1].flatMap(i=>[1,-1].flatMap(a=>[[e,n,t,r],[t,r,e,n]].map(([e,t,n,r])=>[Math.min(i*e,i*t),Math.min(a*n,a*r),Math.max(i*e,i*t),Math.max(a*n,a*r)])))).map(e=>[`${e}`,e])).values()],q=([e,t,n,r],i,a,o=pn,s=o)=>({...W(K[0]+e,i,K[1]+t,K[0]+n,a,K[1]+r,o,s),ghost:!0}),Wn=(e,t,n,r,i,a,o)=>{let s=Math.ceil((o-a)/.46);return Array.from({length:s},(c,l)=>{let[u,d]=[t+(n-t)*l/s,t+(n-t)*(l+1)/s].sort((e,t)=>e-t),f=a+(o-a)*(l+1)/s;return e?W(r,a,u,i,f,d,pn):W(u,a,r,d,f,i,pn)})},Gn=[...Un([[12,-Vn,Bn,Vn],[Bn,-zn,Rn,zn]]).filter(e=>e[1]>-Rn).map(e=>q(e,3.1,3.5,mn,U)),...Wn(2,K[1]+5.6,K[1]+12,K[0]-1.5,K[0]+1.5,0,3.5).map(e=>({...e,ghost:!0})),q([-3,19,3,Rn],3.5,4.6,U,mn),q([-9,12,-2.5,12.5],3.5,4.6,U,hn),q([2.5,12,9,12.5],3.5,4.6,U,hn),q([-9.5,-10,-7.5,-8],0,1.4,U),q([7.5,-10,9.5,-8],0,1.4,U),q([7.5,3,10,5.5],0,2.4,U)],{BENCH:Kn,SAMPLES:qn,RACKS:Jn,SCOPE:Yn,ANALYSER:Xn,PLANTS:Zn,LOCKERS:Qn,SUIT:$n}={BENCH:0,SAMPLES:1,RACKS:2,SCOPE:3,ANALYSER:4,PLANTS:5,LOCKERS:6,SUIT:7},er=[[Kn,60.2,230.5,61.2,241.5,0,.95,0],[qn,65,233.5,66.5,238.5,0,.9,0],[Jn,98.8,229.3,99.8,234.3,0,3.1,2],[Jn,98.8,237.7,99.8,242.7,0,3.1,2],[Yn,68.9,250.8,70.1,252,3.5,4.5,3],[Xn,89.4,250.8,91.4,252,3.5,4.8,3],[Zn,115,222.4,121,223.2,0,2,1],[Zn,123.8,226.4,124.6,229.6,0,2,2],[Qn,96.4,200.4,97,203.6,0,2.1,0],[$n,108.6,197.4,109.6,198.4,0,2,2]],tr=(e,t,n,r,i,a,o=[])=>{let s=(t,n,o)=>e?W(r,o,t,i,a,n,pn):W(t,o,r,n,a,i,pn);return[...o,[n,n]].flatMap(([e,n],r,i)=>[s(r?i[r-1][1]:t,e,0),...n>e?[s(e,n,Dn)]:[]])},nr=({min:[e,,t],max:[n,r,i]},a,o)=>[W(e,4,t,n,r,i,mn,pn),...tr(0,e,n,t,t+G,4,a[0]),...tr(0,e,n,i-G,i,4,a[1]),...tr(2,t+G,i-G,e,e+G,4,a[2]),...tr(2,t+G,i-G,n-G,n,4),o],rr=[1,.42,.08],ir=[...xn.slice(2).flatMap((e,t)=>Sn(yn(xn[t+1])+.2).map(([n,r])=>q([-n,-r,n,r],xn[t+1],e))),...Un([[Rn,-wn,Cn,wn],[Bn,zn,Tn,En],[Vn,Vn,Bn,Bn]]).map(e=>q(e,Hn.find(([t,n])=>e[0]<=t&&t<=e[2]&&e[1]<=n&&n<=e[3])?.[3]??0,xn[1])),...[[-wn,-Cn,-Hn[0][2],-Rn],[Hn[0][2],-Cn,wn,-Rn],[Bn,Pn-K[1],Tn,-zn],[Bn,-En,Fn-K[0],jn-K[1]]].map(e=>q(e,0,xn[1])),...Gn,...er.map(([,e,t,n,r,i,a])=>({...W(e,i,t,n,a,r,U),ghost:!0})),...nr(On[0],[[[118,118]],[[116.8,119.2]],[[jn+G,Pn-G]]],W(121.5,0,223.5,123.5,1.2,225.5,hn,hn,rr)),...nr(On[1],[[[101.8,104.2]],[[Fn+G,Ln-G],[105.8,105.8]]],W(106,0,200.6,108,1.2,202.6,hn,hn,rr)),W(An,Dn,jn,Mn,Nn,Pn,U,mn),W(Fn,Dn,In,Ln,Nn,Pn,U,mn),W(Fn,0,Pn-G,Mn,Dn,Pn,mn),W(Ln-G,0,jn,Mn,Dn,jn+G,mn),W(Fn,0,In,Fn+G,Dn,jn,mn),W(Ln-G,0,In,Ln,Dn,jn,mn),...Wn(2,214,jn,105,109,0,3.5),...Wn(0,108,Ln,206,210,0,3.5)],[ar,or]=Qt,{STONE:J,CONCRETE:sr,METAL:cr,STEEL:lr,PAINT:ur}=A,dr=({min:e,max:t})=>_n(e[0],e[1],280-t[2],t[0],t[1],280-e[2]),fr=[40,220,13],pr=_n(33,.25,218,47,3.25,222),mr=[[27.3,207.3],[52.7,207.3],[27.3,232.7],[52.7,232.7],[106.2,230.4],[103.2,212.4]],hr=K[1]-2,Y=e=>Math.min(Math.max(e,0),1),gr=e=>Y(e)*Y(e)*(3-2*Y(e)),_r=(e,t)=>Math.sqrt(e*e+t*t),vr=[[-100,0,46,.13,.52],[-4,224,36,.12,.67],[110,236,16],[-112,108,14],[236,170,13],[-52,230,10],[80,184,14],[150,250,13],[-36,168,10],[200,152,12],[262,134,14],[240,150,9],[-140,60,12],[-66,60,9],[40,262,10],[118,200,11]],yr=[[-20,0,-1,0],[192,124,0,-1],[64,236,1,0],[-60,100,0,1]],[br,xr]=[[248,64],[180,200]],Sr=[[12,24],[36,60],[72,88],[124,156]],Cr=(()=>{let e=Array.from({length:160},(e,t)=>Sr.some(([e,n])=>t>=e-1&&t<=n)?0:Math.min(Math.round(Math.max(26*j(t/17,0,33)+8*j(t/5,0,35)-11,0))/2,6.5));for(let t of[1,-1])for(let n=t>0?1:158;n>=0&&n<160;n+=t)e[n]=Math.min(e[n],e[n-t]+.5);return e.map((e,t)=>{let n=Math.min(t,159-t);return n<4?-6:n<8?-3:e})})(),wr=e=>e.reduce((e,t,n)=>(e.at(-1)?.[2]===t?e.at(-1)[1]++:e.push([n,1,t]),e),[]),Tr=wr(Cr),X=[114,176,2],Er=[48,144],[Dr,Or]=[3,8],kr=[[27,67,53,93],[56,74,104,133],[96,56,125,90],[98,36,102,40],[28,113,32,117],[30,45,30,45],[135,50,135,50],[50,106,50,106],[35,104,35,104],[115,22,115,22],[45,20,51,62],[114,36,114,36],[141,20,147,66]],Ar=[[0,0,4.5],[-14,6,3],[10,-12,3.5],[16,10,2.5],[-8,-16,2.2],[-20,-8,3.8],[6,18,3],[22,-4,2],[-12,20,2.4]].map(([e,t,n])=>[e-50,t+330,n]),jr=[[126,143,131,147,1.2],[130,138.5,135,141.5,2.4],[126,133,131,137,1.2]],Mr=[[180,340],[173,346],[186,347]],Nr=[vr[0][0]-4.5,140],Pr=[[4,172,4,4,2.2],[30,154,5,5,3],[66,158,3,3,1.6],[95,164,5,4,2.6],[125,175,6,5,3.2],[92,186,4,4,2.4]],Fr=.85,Ir=Array.from({length:36},(e,t)=>{let n=e=>we(t,e,41),r=Math.floor(n(1)*3),[i,a]=r<2?[(r?151:0)+n(2)*9,150+n(3)*122]:[5+n(2)*150,273+n(3)*7];return[i,a+(r===0&&Math.abs(a-174)<8?16:0),.6+2.4*n(4)*n(4)]}).filter(([e,t,n],r,i)=>!i.slice(0,r).some(([r,i,a])=>{let o=Math.max(Math.abs(e-r),Math.abs(t-i))-Fr*(n+a);return o>0&&o<1})),Lr=(e,t)=>{let[n,r]=[0,0];for(let[i,a,o,s=.17,c=0]of vr){let l=_r(e-i,t-a),[u,d]=l?[(e-i)/l,(t-a)/l]:[1,0],f=l/o*(.9+.2*j(2.5*u+.37*i,2.5*d+.21*a,9)),p=.03+.045*j(4*u-.1*a,4*d+.1*i,10),m=1-Y((f-1-4/o)/.6),h=c?(s+p)*Y((f-c)/(1-c))-s:(s+p)*f*f-s;n+=o*(f<1?h:p*m*m),r=Math.max(r,c?Y((1.6-f)/(1.5-c)):0)}return[n,r]},Rr=(e,t)=>{let n=t=>Y((12-Math.abs(t-e))/8)*Y((152-t)/4),r=4*Math.floor(t/4);return n(r)+(n(r+4)-n(r))*(t-r)/4},zr=(e,t)=>{t=Math.abs(t-140);let n=_r((e-80)/300,t/360),r=Math.max((n-.78)/.22,0),i=Lr(e,t),a=Math.max(Math.abs(e-80)-80,t-140),o=gr((a-12)/48)*(1-.7*gr(r))*(16*j(e/96,t/96,1)+6*j(e/52,t/52,4)+5*j(e/36,t/36,2)+1.4*j(e/22,t/22,3)-14.2);if(a<0){let n=gr((t-16-10*j(e/19,.5,37))/8)*gr(-a/10);for(let[r,i,a,o]of kr)n*=gr((_r(Math.max(r-e,e-a,0),Math.max(i-t,t-o,0))-6)/6);o=n*Math.min(Math.max(4.8*j(e/15,t/15,21)-.9,0)+Math.max(3*j(e/31,t/31,23)-.6,0),2.6);let r=gr((10-_r(e-X[0],t-(X[1]-140)))/8);o=o*(1-r)-X[2]*r;for(let n of Er)o+=Dr*Y((8+Or-t)/Or)*Rr(n,e);o=t<8?0:o}o=(a<0?o:o*(1-i[1]))+i[0];for(let[n,r,i,a]of yr){let[s,c]=[e-n,t-r],l=s*i+c*a;o+=5.6*Y(Math.min(l/16,(32-l)/12))*Y((18-Math.abs(s*a-c*i))/12)}let s=Y(_r(e-br[0],Math.max(t-br[1],0))/36);o+=12*(1-s*s)*(1-s*s)+8*gr((36-_r(e-xr[0],t-xr[1]))/24);let c=10*r*(1+r);return n>1&&(c=(c+(n-1)*60*(Math.abs(2*j(e/45,t/45,5)-1)-.5))*(1+(n-1)*(1.2*j(e/90,t/90,7)-.6))*(1-gr((n-1.25)/.4))),Math.max(o,-14.5)+c},Br=[[1,0],[.309,.951],[-.809,.588],[-.809,-.588],[.309,-.951]],Vr=(e,t,n)=>{let r=t=>we(e,t,131),i=e=>{let[t,n]=[2*r(e)-1,2*r(e+1)-1],i=Math.sqrt(t*t+n*n)||1;return[t/i,n/i]},a=[0,1,2].slice(0,t<1.3?1:t<3.2?2:3).map(e=>{let[a,o]=i(20*e+1),[s,c]=[[.1,.45,.42][e]*t,[.8,.75,.65][e]*t],l=[a*s,o*s],u=[n,(.5+.15*r(20*e+3))*n,.34*n][e]-.25*n,d=Math.min(.06,.06/c),[f,p]=[(2*r(20*e+4)-1)*d,(2*r(20*e+5)-1)*d],m=Math.sqrt(f*f+1+p*p);return{o:l,rad:c,top:u,planes:[[f/m,1/m,p/m,(f*l[0]+u+p*l[1])/m],...Br.map(([t,n],i)=>{let[a,o]=[t+r(20*e+6+i)-.5,n+r(20*e+11+i)-.5],s=Math.sqrt(a*a+o*o),u=-.15+.5*r(20*e+16+i),d=Math.sqrt(1-u*u),[f,p]=[d*a/s,d*o/s];return[f,u,p,f*l[0]+p*l[1]+c*(.72+.22*r(20*e+21+i))]})]}}),[o,s]=i(91),c=[.866*o,-.5,.866*s,.72*t];return{reach:t=>{let r=0;for(let{o:e,rad:i,planes:o}of a){let[a,s]=[1.2*i,1.15*n],l=(t[0]*t[0]+t[2]*t[2])/(a*a)+t[1]*t[1]/(s*s),u=-2*(t[0]*e[0]+t[2]*e[1])/(a*a),d=(e[0]*e[0]+e[1]*e[1])/(a*a)-1,f=(-u+Math.sqrt(u*u-4*l*d))/(2*l);for(let[e,n,r,i]of[...o,c]){let a=t[0]*e+t[1]*n+t[2]*r;f=a>1e-9?Math.min(f,i/a):f}r=Math.max(r,f)}return r*(.94+.12*j(1.5*t[0]+e,1.5*t[2]+2*t[1],e))},tops:a.map(({o:e,top:t})=>[e[0],e[1],t])}},Hr=({reach:e,tops:t},n,r)=>{let i=(t,n,r,i=.09)=>{let a=Math.sqrt(t*t+n*n+r*r);return a<1e-6||a<=e([t/a,n/a,r/a])+i},a=[-1,0,1],o=(e,t,n,o,s)=>[r+.05,(r+s)/2,s].every(r=>a.every(s=>a.every(a=>i(e+s*n,r,t+a*o))))&&a.every(r=>a.every(a=>!i(e+r*n,s+.2,t+a*o,0)));return t.flatMap(([e,t,i],a)=>{let s=[0,0,0,0,0,0],c=Math.sqrt(e*e+t*t)||1;for(let l of a?[.1,.3,.5]:[-.15,0,.15])for(let u of[-.15,0,.15]){let[d,f]=a?[e+(l*e-u*t)*(n/c),t+(l*t+u*e)*(n/c)]:[e+l*n,t+u*n],p=0;for(let e=i+.1;!p&&e>r+.3;e-=.1)p=o(d,f,.08*n,.08*n,e)?e:0;let[m,h]=[.08*n,.08*n];for(let[e,t]of p?[[1,1],[1,0],[0,1]]:[])for(let r=.5*n;r>.03;r/=2)[m,h]=o(d,f,m+e*r,h+t*r,p)?[m+e*r,h+t*r]:[m,h];p&&m*h*(p-r)>s[0]&&(s=[m*h*(p-r),d,f,m,h,p])}let[,l,u,d,f,p]=s;return Math.min(d,f)<(a?.25:0)?[]:[[l-d,r,u-f,l+d,p,u+f]]})},Ur=(e,t,n,r,i,a=0)=>{let o=zr(e,t),s=o+.25*r;return{at:[e,o,t],R:n,H:r,s:i,parts:Hr(Vr(i,n,r),n,-.25*r).filter((e,t,n)=>{let r=Math.max(e[0]-n[0][3],n[0][0]-e[3],e[2]-n[0][5],n[0][2]-e[5]);return!t||r<=0||r>1.2}).map(([n,,r,i,o,c])=>[e+n,a,t+r,e+i,s+o,t+c])}},Wr={arena:[...Pr.map(([e,t,n,r,i],a)=>Ur(e+n/2,t+r/2,.31*(n+r),1.15*i,a+61)),...Ir.map(([e,t,n],r)=>Ur(e,t,n,.8*n,r))],field:Ar.map(([e,t,n],r)=>Ur(e,t,n,.75*n,r+100,zr(e,t)-6))},Gr=e=>e.flatMap(e=>e.parts).map(([e,t,n,r,i,a])=>({...W(e,t,n,r,i,a,J),ghost:!0})),[Z,Kr,qr,Jr]=[9,12,-19,7],Yr=vr.filter(e=>e[4]).map(([e,t],n)=>{let r=140+t,i=Array.from({length:2*Z},(e,t)=>{let i=Math.abs(t+.5-Z),a=Math.sqrt(Z*Z-i*i),o=e=>Math.ceil(2*a*(.88+.24*j(i/4,e+.5,60+n)))/2;return[r-Z+t,r-Z+t+1,o(0),o(1)]});return{x:e,z:r,level:zr(e,r),rows:i}}),Xr=({x:e,z:t,level:n,rows:r})=>{let i=r.reduce((e,[t,n,r,i])=>{let a=e.at(-1);return a&&a[2]===r&&a[3]===i?a[1]=n:e.push([t,n,r,i]),e},[]),a=r[Z][3],o=(n-qr)/Jr;return[W(e-Kr,-30,t-Kr,e+Kr,n,t-Z,J),W(e-Kr,-30,t+Z,e+Kr,n,t+Kr,J),...i.flatMap(([t,r,i,a])=>[W(e-Kr,-30,t,e-i,n,r,J),W(e+a,-30,t,e+Kr,n,r,J)]),W(e-Z-1.5,-30,t-Z,e+Z+1.5,qr,t+Z,J),...Array.from({length:Jr-1},(n,r)=>W(e+a-1.3*(Jr-1-r),qr,t-1,e+a-1.3*(Jr-2-r),qr+o*(r+1),t+1,J))].map(e=>({...e,ghost:!0}))},Zr=(e,t,n,r)=>({...W(e-n,zr(e,t)-6,t-n,e+n,zr(e,t)+r,t+n,J),ghost:!0}),Qr={rocks:[...Ar,...Ar.map(([e,t,n])=>[e,280-t,n])],dishes:[...Mr,...Mr.map(([e,t])=>[e,280-t])],ramps:yr.flatMap(([e,t,n,r])=>(t?[1,-1]:[1]).map(i=>[e+16*n,140+i*(t+16*r),n,i*r+0])),wreck:Nr,pits:Yr.flatMap(e=>e.z===140?[e]:[e,{...e,z:280-e.z,rows:e.rows.map(([e,t,n,r])=>[280-t,280-e,n,r]).reverse()}]),bowls:vr.flatMap(([e,t,n,r=.17])=>(t?[1,-1]:[1]).map(i=>[e,140+i*t,n,r])),boulders:Ir,crags:Wr,stones:Pr,pillars:jr,domes:[K,[K[0],280-K[1]]],pads:[fr,[fr[0],280-fr[1],fr[2]]],shuttles:[pr,dr(pr)],modules:[...On,...On.map(dr)],tubes:[...kn,...kn.map(dr)],masts:[...mr,...mr.map(([e,t])=>[e,280-t])]},$r=e=>({...e,min:[e.min[0],e.min[1],280-e.max[2]],max:[e.max[0],e.max[1],280-e.min[2]],tint:e.tint===ar?or:e.tint}),ei=([e,t,n])=>[e,t,280-n],ti=(e,...t)=>[...e,...e.map(ei),...t],ni=[...[W(0,-30,160,160,0,X[1]-12,J),W(0,-30,X[1]-12,X[0]-12,0,X[1]+12,J),W(X[0]+12,-30,X[1]-12,160,0,X[1]+12,J),W(0,-30,X[1]+12,160,0,280,J),W(X[0]-12,-30,X[1]-12,X[0]+12,-3,X[1]+12,J),...Tr.filter(e=>e[2]<0).map(([e,t,n])=>W(e,-30,148+n,e+t,0,160,J)),...Array.from({length:14},(e,t)=>wr(Cr.map(e=>e<0?2:+(e>t/2))).filter(e=>!e[2]).map(([e,n])=>W(e,-30,148+t/2,e+n,0,t<13?148.5+t/2:160,J))).flat(),...Er.flatMap(e=>[-12,-10,-8,-6,-4,4,6,8,10].map(e=>[e,e+(e===-4?8:2)]).map(([t,n])=>[e+t,e+n,Dr*Math.min(Rr(e,e+t),Rr(e,e+n))*(1-.5/Or)-.12]).filter(e=>e[2]>.3).map(([e,t,n])=>W(e,0,148,t,n,148.5,J)))].map(e=>({...e,ghost:!0})),...ir,{...W(75.25,0,hr-4.75,84.75,.5,hr+4.75,ur,sr,ar),ghost:!0},{...W(75.75,.5,hr-4.25,84.25,1,hr+4.25,ur,sr,ar),ghost:!0},W(60,0,259,70,1.5,265,lr,ur,ar),W(27,0,207,53,.25,233,cr),{...gn(pr,ur),tint:[.82,.84,.88]},{...W(42,1,222,45.8,1.25,225.5,cr),ghost:!0},{...W(42,1,214.5,45.8,1.25,218,cr),ghost:!0},{...W(43,3.25,219.9,46.8,5.4,220.1,ur),ghost:!0},...mr.map(([e,t])=>W(e-.2,e<60?.25:0,t-.2,e+.2,e<60?10.25:10,t+.2,lr)),W(12,-30,148-2.5/2,24,0,148,ur,J,[1,.42,.08]),...Yr.filter(e=>e.z!==140).flatMap(Xr),...Gr(Wr.arena),...Gr(Wr.field),...Mr.map(([e,t])=>Zr(e,t,.4,6))],ri=[W(74,-1.5,132,86,0,148,cr,lr),W(74,0,132,74.4,1.1,148,sr),W(85.6,0,132,86,1.1,148,sr),...jr.map(([e,t,n,r,i])=>({...W(e,-30,t,n,i,r,J),ghost:!0})),{...W(-10,-30,132,0,0,148,J),ghost:!0},{...W(160,-30,132,170,0,148,J),ghost:!0},{...W(Nr[0]-3.6,-30,Nr[1]-3.6,Nr[0]+3.6,qr+3.5,Nr[1]+3.6,J),ghost:!0},...Yr.filter(e=>e.z===140).flatMap(Xr),...Qr.ramps.flatMap(([e,t,n,r])=>[-8,8].map(i=>Zr(e+i*r,t-i*n,.2,2.2)))],ii=[...[56,68,80,92,104].map(e=>[e,0,271,0]),...[62,80,98].map(e=>[e,0,267,0])],ai=e=>Object.fromEntries([`rifle`,`rail`,`rack`,`blade`].map((t,n)=>[t,[61.25+2.5*n,1.5,e]])),oi=(e,t)=>({base:[80,1,e],spawns:t,...ai(e+(e>140?28:-28))}),si={highline:fn,tranquility:{name:`Tranquility`,brushes:[...ni,...ni.map($r),...ri],teams:[oi(hr,ii),oi(280-hr,ii.map(([e,t,n])=>[e,t,280-n,Math.PI]))],packs:ti([[90,0,210],[118,5,226],[30,0,185],[80,3.5,253.5]],[45,0,162],[45,0,118]),ammo:ti([[50,0,246],[103,5,200],[135,0,190]],[115,0,162],[115,0,118]),cells:ti([[106.5,3.5,226],[35,0,244]],[80,0,140]),floor:-26,relief:{hole:[0,132,160,148],pits:[...Tr.flatMap(([e,t,n])=>n>0?[[e,148,e+t,148+n],[e,132-n,e+t,132]]:[]),...Qr.pits.flatMap(({x:e,rows:t})=>t.map(([t,n,r,i])=>[e-r,t,e+i,n]))],bound:[80,140,300,360],cell:4,at:zr},sun:{dir:[.87996,.40998,.23999],color:[3,2.95,2.85]},sky:[[.002,.002,.006],[.02,.02,.035]],gravity:.5,rovers:[[100,0,178,0],[30,0,255,0],[100,0,102,Math.PI],[30,0,25,Math.PI]],scenery:`moon`,helmets:!0,armor:!0}},ci=e=>e!==void 0&&si[e]||fn,li=e=>e!==void 0&&Object.hasOwn(si,e)?e:`highline`,ui=40/60,di=b/60,fi=e=>[ae*Math.sin(e*2.4),ae*Math.cos(e*1.7)],pi=(e,t=0)=>{let[n,r]=e.rifled?fi(e.shots):[0,0],[i,a]=[e.yaw+n,e.pitch+r],[o,s,c,l]=[Math.sin(i),Math.cos(i),Math.sin(a),Math.cos(a)];return{id:e.shots,by:e.id,team:t,x:e.x,y:e.y+Qe(e),z:e.z,dx:-o*l,dy:c,dz:-s*l,left:e.rifled?60:80,burst:!1,power:e.rifled?0:e.power??1}},mi=(e,t=0)=>({...pi(e,t),id:e.shots^128,left:x,power:1,arc:e.cut}),hi=e=>e.arc?di:e.power===6?2:ui,gi=(e,t,n,r,i)=>{let[a,o]=[e[0]-n.x,e[2]-n.z],s=t[0]*t[0]+t[2]*t[2],c=a*t[0]+o*t[2],l=c*c-s*(a*a+o*o-r*r),[u,d]=[0,1/0];if(s>1e-12){if(l<0)return 1/0;[u,d]=[(-c-Math.sqrt(l))/s,(-c+Math.sqrt(l))/s]}else if(a*a+o*o>r*r)return 1/0;let[f,p]=[n.y-e[1],n.y+i-e[1]];if(t[1])[u,d]=[Math.max(u,Math.min(f/t[1],p/t[1])),Math.min(d,Math.max(f/t[1],p/t[1]))];else if(f>0||p<0)return 1/0;return u<=d&&d>=0?Math.max(u,0):1/0},_i=(t,n,r,i)=>{let a=[n.x,n.y,n.z],o=[n.dx,n.dy,n.dz],s=Math.min(r,n.left),c=Re(t,a,o,s,f),l;for(let t of i){let r=gi(a,o,t,e+(n.arc?ee:f),L(t));r<c&&([c,l]=[r,t])}return n.burst=c<s,n.left-=c,[n.x,n.y,n.z]=[a[0]+o[0]*c,a[1]+o[1]*c,a[2]+o[2]*c],l},vi=(e,t=0)=>({...pi({...e,rifled:!1},t),left:150,power:7,v:36}),yi=(e,t,n)=>{let r=Math.fround,[i,a,o]=[t.dx*t.v,t.dy*t.v-ht(e)/60,t.dz*t.v],s=Math.sqrt(i*i+a*a+o*o)||1;[t.dx,t.dy,t.dz,t.v]=[r(i/s),r(a/s),r(o/s),r(s)];let c=_i(e,t,t.v/60,n);return[t.x,t.y,t.z,t.left]=[r(t.x),r(t.y),r(t.z),r(t.left)],t.burst||=t.left<=0,c},bi=(e,t,n)=>{let r=L(n),i=[n.x,Math.max(n.y,Math.min(n.y+r,t[1])),n.z],[a,o,s]=[i[0]-t[0],i[1]-t[1],i[2]-t[2]],c=Math.sqrt(a*a+o*o+s*s);return c>=5||Be(e,t,i)&&Be(e,t,[n.x,n.y+.7*r,n.z])?0:Math.ceil(5*(1-c/5))},xi=(t,n,r=[],i=30,[a,o]=[0,0])=>{let s=[n.x,n.y+Qe(n),n.z],[c,l]=[n.yaw+a,n.pitch+o],u=Math.cos(l),d=[-Math.sin(c)*u,Math.sin(l),-Math.cos(c)*u],f=Re(t,s,d,i),p;for(let t of r){let n=gi(s,d,t,e,L(t));n<f&&([f,p]=[n,t])}return{o:s,d,t:f,hit:p}},Q={A:1.25,B:1,WR:.5,L0:.6,CMAX:.5,K:30,D:2,KP2:1.2,KR2:.7,HC:.7,ENGINE:12,VMAX:23.2,VREV:8,BRAKE:14,ROLL:.6,HB:6,MU:1.1,MUL:1.2,HBG:.35,HBY:1.5,SK:2.5,SV:10,SMAX:.55,SRATE:3.5,YMAX:2.4,YRESP:10,AK:5,AC:3,AD:.5,TILT:.9,RB:1.05,BODY:[1.15,0,-1.15],BODY_H:1.5,WHEEL_STEP:.6,BOUNCE:.3,ENTER_R:3,SPLAT_MIN:6,SPLAT_KILL:12,GUN_COOL:8,GUN_RANGE:90,GUN_AIM:50},Si=[[-1.05,.18,.6],[1.05,.18,.6]],Ci=[[-.45,-.35,.1],[.45,-.35,.1]],wi=[1,1,-1,-1].map(e=>e*Q.A),Ti=[-1,1,-1,1].map(e=>e*Q.B),Ei=Q.L0+Q.WR,Di=Q.RB+e+.15,Oi=1,ki=`x y z vx vy vz yaw pitch roll wy wp wr steer`.split(` `),$=1/60,Ai=Math.fround,{sin:ji,cos:Mi,min:Ni,max:Pi,abs:Fi,sqrt:Ii}=Math,Li=(e,t,n)=>Ni(Pi(e,t),n),Ri=(e,t,n,r=0)=>{let[i,a]=P(e.yaw),[o,s]=[t*Mi(e.pitch),n*Mi(e.roll)];return[e.x+i*o-a*s,e.y+r+t*ji(e.pitch)-n*ji(e.roll),e.z+a*o+i*s]},zi=(e,t)=>wi.map((n,r)=>{let[i,a,o]=Ri(e,n,Ti[r]);return[i,a,o,Ei+st(t,i,o,a-Q.L0+Q.WHEEL_STEP)-a]}),Bi=e=>Q.BODY.map(t=>Ri(e,t,0,-Ei)),Vi=e=>{let[t,,n]=Bi(e);return{a:t,b:n,r:Q.RB,h:Q.BODY_H}},Hi=e=>(e.def.rovers??[]).map(([e,t,n,r])=>({x:Ai(e),y:Ai(t+Ei),z:Ai(n),vx:0,vy:0,vz:0,yaw:Ai(We(r)),pitch:0,roll:0,wy:0,wp:0,wr:0,steer:0,driver:255,rider:255})),Ui=(e,t,n,r=[])=>{let{A:i,B:a,CMAX:o,K:s,D:c,KP2:l,KR2:u,HC:d,MU:f,MUL:p,TILT:m}=Q,h=ht(n),g=t?t.keys:0,_=(g&T.FORWARD?1:0)-(g&T.BACK?1:0),v=g&T.JUMP,[y,b]=P(e.yaw),[x,ee]=[Mi(e.pitch),Mi(e.roll)],S=zi(e,n),[te,C,ne,re]=S.map(([,e,,t])=>t+e-Ei),ie=S.some(e=>e[3]<-o),ae=ie?0:(te+C-ne-re)/(4*i*x),oe=ie?0:(C+re-te-ne)/(4*a*ee),w=1/Ii(ae*ae+oe*oe+1),E=-(ae*y-oe*b)*w,D=-(ae*b+oe*y)*w,O=()=>e.vx*E+e.vy*w+e.vz*D,se=Pi(0,...S.map(e=>e[3]-o));if(se){e.y+=se;let t=Ni(0,O());e.vx-=t*E,e.vy-=t*w,e.vz-=t*D}let k=O(),[A,ce,le]=[0,0,0];S.forEach(([,,,t],n)=>{if(t>se){let r=Pi(0,s*(t-se)-c*(k+(wi[n]*x*e.wp-Ti[n]*ee*e.wr)*w));A+=r,ce+=r*wi[n],le+=r*Ti[n]}}),e.vx+=A*E*$,e.vy+=(A*w-h)*$,e.vz+=A*D*$,e.wp+=ce/l*$,e.wr-=le/u*$;let ue=Ni(A/h,2);if(ue>0){let n=e.vx*y+e.vz*b,r=e.vz*y-e.vx*b,a=t?We(t.yaw-e.yaw+Math.PI)-Math.PI:0,o=Li(Q.SK*a/(1+Fi(n)/Q.SV),-Q.SMAX,Q.SMAX),s=Q.SRATE*$;e.steer+=Li((n+_<0?-o:o)-e.steer,-s,s);let c=Li(n*e.steer/(2*i),-Q.YMAX,Q.YMAX)*(v?Q.HBY:1);e.wy+=(c-e.wy)*Q.YRESP*$*Ni(1,ue);let m=h*ue*$,g=Li((_*n<0?_*Q.BRAKE:_*Q.ENGINE*Pi(0,1-Fi(n)/(_>0?Q.VMAX:Q.VREV)))*$,-p*m,p*m),x=(Q.ROLL+(v||!t?Q.HB:0))*ue*$;g-=Li(n+g,-x,x);let ee=f*m*(v?Q.HBG:1),S=-Li(r,-ee,ee);e.vx+=g*y-S*b,e.vz+=g*b+S*y,e.wp+=g*d/l,e.wr-=S*d/u}else e.wp-=(Q.AK*e.pitch+Q.AC*e.wp)*$,e.wr-=(Q.AK*e.roll+Q.AC*e.wr)*$;e.wp*=1-Q.AD*$,e.wr*=1-Q.AD*$,e.x+=e.vx*$,e.y+=e.vy*$,e.z+=e.vz*$,e.yaw=We(e.yaw+e.wy*$),e.pitch=Li(e.pitch+e.wp*$,-m,m),e.roll=Li(e.roll+e.wr*$,-m,m),Fi(e.pitch)===m&&e.pitch*e.wp>0&&(e.wp=0),Fi(e.roll)===m&&e.roll*e.wr>0&&(e.wr=0);for(let t of Q.BODY){let[r,i,a]=Ri(e,t,0,-Ei),[o,s]=rt({x:r,y:Pi(i,te,C,ne,re),z:a},n,Q.BODY_H,Q.RB),c=o*o+s*s;if(c){e.x+=o,e.z+=s;let t=Ni(0,e.vx*o+e.vz*s)/c;e.vx-=t*o,e.vz-=t*s}}for(let t of r){if(t===e)continue;let n=Vi(t);for(let r of Q.BODY){let[i,a,o]=Ri(e,r,0,-Ei),[s,c,l]=it(n,i,o),u=2*Q.RB,d=Ii(s*s+c*c);if(d>=u-1e-4||l>=a+Q.BODY_H||l+Q.BODY_H<=a)continue;let[f,p]=P(t.yaw),[m,h]=d?[s/d,c/d]:[-p,f];e.x+=m*(u-d),e.z+=h*(u-d);let g=Ni(0,e.vx*m+e.vz*h)*(1+Q.BOUNCE);e.vx-=g*m,e.vz-=g*h}}Oe(e,n);for(let t of ki)e[t]=Ai(e[t]);return e.y<n.def.floor},Wi=(e,t,n)=>{let[r,i,a]=Ci[n];[e.x,e.y,e.z]=Ri(t,a,r,i).map(Ai),e.vx=t.vx,e.vy=t.vy,e.vz=t.vz},Gi=(e,t,n)=>{t[n?`rider`:`driver`]=e.id,e.mode=O.RIDE,e.t=0,e.edge=0,e.ground=!1,e.dash=Ni(e.dash,50),e.coyote=0,e.buffer=0,Wi(e,t,n)},Ki=(n,r,i,a)=>{r[i?`rider`:`driver`]=255,n.mode=O.AIR,n.t=0,n.coyote=0,[n.vx,n.vy,n.vz]=[r.vx,r.vy,r.vz];let o=i?Di:-Di;for(let[s,c]of[[o,-Ei],[-o,-Ei],[0,Q.BODY_H-Ei]]){let[o,l,u]=Ri(r,Ci[i][2],s,c);Object.assign(n,{x:o,y:l,z:u}),Oe(n,a);let d=st(a,n.x,n.z,r.y);n.y=Pi(l,d);let[f,p]=rt(n,a,t,e);if(!s||d>l-Oi&&!f&&!p)break}[n.x,n.y,n.z,n.vx,n.vz]=[n.x,n.y,n.z,n.vx,n.vz].map(Ai)},qi=(e,t,n,r,i,a=[])=>{let o=(n.keys&T.USE)!==0&&(e.held&T.USE)===0,s=Ui(t,n,r,a);return Kt(e,n,r,i,!1),e.mode===O.RIDE?(Wi(e,t,0),o&&Ki(e,t,0,r)):t.driver=255,s},Ji=(e,t,n)=>{let[r,i,a,o]=[Math.sin(t),Math.cos(t),Math.sin(n),Math.cos(n)];return[e.x-r*o*Q.GUN_AIM,e.y+a*Q.GUN_AIM,e.z-i*o*Q.GUN_AIM]},Yi=(e,t,n,r,i,a)=>{let[o,s]=P(e.yaw),c=Ji(e,r,i);return Si.map(([r,i,l],u)=>{let d=[e.x+o*l-s*r,e.y+i,e.z+s*l+o*r],f=c.map((e,t)=>e-d[t]),p=Math.sqrt(f[0]*f[0]+f[1]*f[1]+f[2]*f[2]);return{id:a+u&255,by:t,team:n,x:d[0],y:d[1],z:d[2],dx:f[0]/p,dy:f[1]/p,dz:f[2]/p,left:Q.GUN_RANGE,burst:!1,power:6}})},Xi=e=>e.mode===O.SLIDE||e.dash>50,Zi=(e,t)=>Math.hypot(e.x-t.x,e.z-t.z)<1.1&&e.y<t.y+L(t)&&t.y<e.y+L(e),Qi=20,$i=2,ea=30,ta=[`driver`,`rider`],na=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),ra=e=>na((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),ia=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${na(e,15-`${r}`.length)} ${r}`;return n},aa=(e,t)=>Math.sqrt(e*e+t*t),oa=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},sa={lock:0,foe:0,pushes:0,pressed:!1,away:0},ca=({x:e,y:t,z:n,yaw:r})=>({x:e,y:t,z:n,yaw:r}),la=({x:e,y:t,z:n})=>({x:e,y:t,z:n}),ua=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;ctf;halt;rules;rr=[0,0];gone;balls=[];rovers;mapName;next;joins=0;constructor(e={},t){this.rules={...oe,...e},this.mapName=li(this.rules.map),this.world=Ie(t??ci(this.mapName)),this.ctf=new Ht(this.world,this.rules),this.gone=this.spots(),this.rovers=Hi(this.world)}spots(){let{packs:e=[],ammo:t=[],cells:n=[]}=this.world.def;return[...e,...t,...n].map(()=>0)}host(){return this.players().reduce((e,t)=>e&&e.since<t.since?e:t,void 0)}load(){if(this.next!==void 0){this.mapName=this.next,this.next=void 0,this.world=Ie(ci(this.mapName)),this.ctf=new Ht(this.world,this.rules),this.gone=this.spots(),this.rovers=Hi(this.world),this.history=[],this.balls=[];for(let e of this.players())this.ctf.join(e.info.id,e.info.team,e.state);this.roster()}}get size(){return this.players().length}connect(e){this.peers.set(e,null)}receive(e,t){let n=this.peers.get(e);if(typeof t==`string`){let r=Ce(t);n===null&&r?.t===`join`?this.join(e,r.name):n&&r?.t===`map`&&n===this.host()&&Object.hasOwn(si,r.map)&&(this.next=r.map===this.mapName?void 0:r.map,this.roster());return}let r=n&&be(t);if(r&&n.bank>0){n.bank--;let e=n.state.slow??0,t=(r.keys&T.USE)!==0&&(n.state.held&T.USE)===0,[i,a]=this.seatOf(n);if(i&&!a){let e=qi(n.state,i,r,this.world,n.info.team,this.rovers);this.ctf.moved(n.state),e?this.sink(i):(this.carry(i),this.splat(n,i,r.view),this.lase(n,i,r))}else{let e=Kt(n.state,r,this.world,n.info.team,!this.ctf.over,this.rovers.map(Vi));this.ctf.moved(n.state),this.tackle(n,r.view);let a=la(n.state),o=i&&e?this.past(r.view).find(e=>e.id===n.info.id):void 0;Object.assign(n.state,o&&la(o)),e===z.SHOT?this.shoot(n,r.view):e===z.CUT?this.cut(n,r.view):e===z.RAIL?this.rail(n,r.view):e===z.LASER?this.shoot(n,r.view):e===z.NADE&&this.shoot(n,r.view,vi(n.state,n.info.team)),Object.assign(n.state,a),t&&i&&n.state.mode===O.RIDE?Ki(n.state,i,1,this.world):t&&this.enter(n)}n.burn=e?(n.burn??0)+1:0,e&&!(n.burn%60)&&this.fry(n),this.duel(n),n.ack=r.seq,this.seats()}}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&(this.ctf.leave(t.info.id),this.size||(this.ctf.reset(),this.gone.fill(0),this.rovers=Hi(this.world),this.load()),this.seats(),this.roster())}drop(e){let t=this.players().find(t=>t.info.id===e);return!!t&&this.ctf.drop(t.state)}tick(){let e=this.players();if(!e.length){this.balls=[];return}let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);for(let e of this.balls)!e.burst&&e.left>0&&this.fly(e,hi(e));this.heal(e);let n=this.ctf.tick(e.filter(e=>!e.state.down&&!this.rovers.some(t=>t.driver===e.info.id)).map(e=>({id:e.info.id,team:e.info.team,state:e.state})));n===`end`?this.end(e):n===`start`&&(this.load(),this.restart(e)),this.seats();for(let e of this.rovers)e.driver===255&&Ui(e,void 0,this.world,this.rovers)?this.sink(e):this.carry(e);if(this.seats(),t%2==0){for(this.history.push({tick:t,players:e.map(e=>({...e.state}))});this.history[0].tick<t-30;)this.history.shift();let n=Se({tick:t,players:e.map(e=>({...e.state,ack:e.ack,by:e.state.stun?e.by:0})),...this.ctf.wire(),packs:this.gone.reduce((e,t,n)=>t?e:e+2**n,0),balls:this.balls,rovers:this.rovers});e.forEach(e=>e.conn.send(n)),this.balls=this.balls.filter(e=>!e.burst&&e.left>0)}}start(e=oa){if(this.halt)return;let t=1e3/60,n=performance.now(),r=0;this.halt=e(()=>{let e=performance.now();r+=e-n,n=e;for(let e=0;r>=t&&e<Qi;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){return this.past(t).filter(t=>t.id!==e)}past(e=0){let t=this.players().map(e=>e.state),[n,r]=[this.history[0],this.history.at(-1)];if(!n||!r)return t;let i=((this.ticks-e+32768)%65536+65536)%65536-32768,a=Math.min(Math.max(this.ticks-i,n.tick),r.tick),o=0;for(;o+1<this.history.length&&this.history[o+1].tick<=a;)o++;let[s,c]=[this.history[o],this.history[o+1]??this.history[o]],l=c.tick>s.tick?(a-s.tick)/(c.tick-s.tick):0,u=(e,t)=>e+(t-e)*l;return t.map(e=>{let t=s.players.find(t=>t.id===e.id),n=c.players.find(t=>t.id===e.id);return t&&n?{...n,x:u(t.x,n.x),y:u(t.y,n.y),z:u(t.z,n.z)}:n??t??e})}tackle(e,t){let n=e.state;if(n.down||!Xi(n)||this.ticks-e.tackled<30)return;let r=this.players().filter(t=>t.info.team!==e.info.team),i=this.rewind(e.info.id,t).find(e=>Zi(n,e)&&r.some(t=>t.info.id===e.id&&this.ctf.carrying(t.info.id)>=0)),a=r.find(e=>e.info.id===i?.id);if(!a||!this.drop(a.info.id))return;let o=$e(n),[s,c]=o>.001?[n.vx/o,n.vz/o]:P(n.yaw);vt(a.state,s,c),a.state.zap=!1,a.by=e.info.id,e.tackled=this.ticks}enemies(e,t){let n=this.players();return this.rewind(e.info.id,t).filter(t=>{let r=n.find(e=>e.info.id===t.id);return r&&r.info.team!==e.info.team&&!r.state.down&&!t.down})}harm(e,t){return(e.state.hp-=t)>0?!1:([e.graze,e.bruise,e.blows]=[0,0,0],e.state.mode===O.RIDE&&this.unseat(e),Object.assign(e.state,{hp:0,down:120,ammo:-1,cool:0,charge:0,mag:0,cap:0,reload:0,blade:!1,wield:!1,swing:0,lost:D.NONE,rail:-1,railed:!1,rifle:-1,clip:0,rifled:!1,nades:0,lob:0,zapping:!1,slow:0}),this.ctf.drop(e.state),!0)}shoot(e,t=0,n=pi(e.state,e.info.team)){let r=(this.ticks-t+65536)%65536;this.balls.push(n);let i=Math.min(r<32768?r:0,12);if(n.power===7)for(let e=0;e<i&&!n.burst;e++)this.fly(n,0);else this.fly(n,i*hi(n));let a=this.balls.filter(e=>!e.burst);a.length>64&&(a[0].burst=!0)}fly(e,t){let n=this.players(),r=n.filter(t=>t.info.team!==e.team&&!t.state.down);if(e.power===7){yi(this.world,e,r.map(e=>e.state));let t=!1;for(let r of e.burst?n:[]){let n=r.info.id===e.by,i=!r.state.down&&(n||r.info.team!==e.team)?bi(this.world,[e.x,e.y,e.z],r.state):0;i&&(this.harm(r,i),t||=!n)}let i=n.find(t=>t.info.id===e.by);t&&i&&(i.state.hits=i.state.hits+1&255);return}let i=_i(this.world,e,t,r.map(e=>e.state)),a=r.find(e=>e.state===i);if(!a)return;let o=n.find(t=>t.info.id===e.by);if(o&&(o.state.hits=o.state.hits+1&255),e.power===0||e.power===6)a.graze=((a.graze??0)+1)%2,a.graze||this.harm(a,1);else if(!e.arc)this.harm(a,e.power??1);else if(this.harm(a,p[e.arc].hp)){let t=o&&{...o.state,cut:e.arc,yaw:Math.atan2(-e.dx,-e.dz)};a.state.lost=t?zt(Object.assign(t,{x:e.x-e.dx,y:e.y-e.dy-Nt*L(t),z:e.z-e.dz,pitch:Math.asin(e.dy)}),a.state):D.NONE}else{let t=Math.hypot(e.dx,e.dz)||1;vt(a.state,e.dx/t,e.dz/t,S,te),a.state.zap=!0,a.by=e.by,this.ctf.drop(a.state)}}cut(e,t){if(!e.state.blade){this.punch(e,t);return}if(e.state.cut===E.ARC_L||e.state.cut===E.ARC_R){this.shoot(e,t,mi(e.state,e.info.team));return}let n=It(this.world,e.state,this.enemies(e,t)),r=this.players().filter(e=>n.some(t=>t.id===e.info.id)),i=r.find(t=>Lt(e.state,{...t.state,...ca(n.find(e=>e.id===t.info.id))}));if(i){for(let[t,n]of[[e,i],[i,e]])Object.assign(t.state,{...sa,lock:240,foe:n.info.id,pressed:!0}),Object.assign(t.state,{swing:0,charge:0,stun:0,zap:!1,vx:0,vz:0});r=r.filter(e=>e!==i)}if(r.length){e.state.hits=e.state.hits+1&255;for(let t of r){let r=n.find(e=>e.id===t.info.id);if(this.harm(t,Ft(e.state).hp))t.state.lost=zt(e.state,r);else{let[n,r]=Rt(e.state);vt(t.state,n,r,24,4*(e.state.heavy?m:1)),t.state.zap=!0,t.by=e.info.id}}}}punch(e,t){let n=It(this.world,e.state,this.enemies(e,t),c),r=this.players().filter(e=>n.some(t=>t.id===e.info.id));if(r.length){e.state.hits=e.state.hits+1&255;for(let t of r)if(t.blows=(this.ticks-(t.punched??-1/0)<=d?t.blows??0:0)+1,t.punched=this.ticks,t.bruise=((t.bruise??0)+1)%l,(t.bruise||!this.harm(t,1))&&t.blows>=u){t.blows=0,this.drop(t.info.id);let[n,r]=P(e.state.yaw);vt(t.state,n,r),t.state.zap=!1,t.by=e.info.id}}}rail(e,t){let{hit:n}=xi(this.world,e.state,this.enemies(e,t)),r=this.players().find(e=>e.info.id===n?.id);if(r){let t=!r.state.slow;r.state.slow=180,t&&(e.state.hits=e.state.hits+1&255,r.burn=0,this.fry(r))}}fry(e){e.state.fried=this.harm(e,1)}duel(e){let t=e.state;if(!t.lock)return;let n=this.players().find(e=>e.info.id===t.foe);if(!n||n.state.foe!==e.info.id||!n.state.lock||n.state.down||t.down){Object.assign(t,sa);return}let r=(t.pushes??0)-(n.state.pushes??0),i=(t.away??0)>=24||(n.state.away??0)>=24;if(!(Math.abs(r)<8&&!i&&t.lock>1)){if(Object.assign(t,sa),Object.assign(n.state,sa),Math.abs(r)>=8){let[t,i]=r>0?[e,n]:[n,e];if(t.state.hits=t.state.hits+1&255,!this.harm(i,3)){let[e,n]=P(t.state.yaw);vt(i.state,e,n,24,4),i.state.zap=!0,i.by=t.info.id}}else if(!i){let[e,r]=[n.state.x-t.x,n.state.z-t.z],i=Math.hypot(e,r)||1;vt(t,-e/i,-r/i),vt(n.state,e/i,r/i)}}}heal(e){let{packs:t=[],ammo:n=[],cells:r=[]}=this.world.def;[...t,...n,...r].forEach((r,i)=>{if(this.gone[i]>0){this.gone[i]--;return}let a=+(i>=t.length)+ +(i>=t.length+n.length),o=e=>[e.hp<5,e.ammo>=0&&e.ammo<60||(e.rifle??-1)>=0&&e.rifle<240,(e.rail??-1)>=0&&e.rail<240][a],s=e.find(({state:e})=>!e.down&&o(e)&&Wt(e,r,.9));if(s){let e=s.state;a==0?e.hp=Math.min(5,e.hp+2):a==1?(e.ammo=e.ammo<0?-1:Math.min(60,e.ammo+20),e.rifle=(e.rifle??-1)<0?-1:Math.min(240,e.rifle+60)):e.rail=Math.min(240,e.rail+80),this.gone[i]=(a==1?10:20)*60}})}seatOf(e){if(e.state.mode===O.RIDE)for(let t of this.rovers){let n=ta.findIndex(n=>t[n]===e.info.id);if(n>=0)return[t,n]}return[]}unseat(e){for(let t of this.rovers)ta.forEach(n=>t[n]=t[n]===e.info.id?255:t[n]);Object.assign(e.state,{mode:O.AIR,t:0,coyote:0})}seats(){let e=this.players();for(let t of this.rovers)for(let n of ta)e.some(e=>e.info.id===t[n]&&e.state.mode===O.RIDE)||(t[n]=255);for(let t of e)t.state.mode===O.RIDE&&!this.seatOf(t).length&&this.unseat(t)}enter(e){let t=e.state;if(t.down||t.stun||t.lock||t.mode===O.RIDE)return;let n=this.ctf.carrying(e.info.id)>=0,r=e=>Math.abs(e.y-t.y)>Q.ENTER_R?1/0:(e.x-t.x)**2+(e.z-t.z)**2,i=e=>e.driver===255&&!n?0:e.rider===255?1:-1,a=this.rovers.filter(e=>r(e)<=Q.ENTER_R**2&&i(e)>=0).sort((e,t)=>r(e)-r(t))[0];a&&Gi(t,a,i(a))}carry(e){let t=this.players().find(t=>t.info.id===e.rider);if(t?.state.mode===O.RIDE){Wi(t.state,e,1);let n=st(this.world,e.x,e.z,e.y);n>this.world.def.floor&&this.ctf.place(t.info.id,{...t.state,y:n})}}sink(e){for(let t of this.players())this.seatOf(t)[0]===e&&(Xe(t.state,this.world,t.info.team),this.ctf.moved(t.state));let t=this.rovers.indexOf(e);Object.assign(e,Hi(this.world)[t])}lase(e,t,n){if(e.gun=Math.max(0,(e.gun??0)-1),!(!(n.keys&T.FIRE)||e.gun||this.ctf.over||e.state.mode!==O.RIDE)){e.gun=Q.GUN_COOL,e.bolt=(e.bolt??0)+2&255;for(let r of Yi(t,e.info.id,e.info.team,n.yaw,n.pitch,e.bolt))this.shoot(e,n.view,r)}}splat(e,t,n){if(aa(t.vx,t.vz)<Q.SPLAT_MIN)return;let r=Bi(t);for(let i of this.enemies(e,n)){let n=this.players().find(e=>e.info.id===i.id);if(!n||n.state.mode===O.RIDE||this.ticks-n.run<ea||!r.find(([e,t,n])=>aa(i.x-e,i.z-n)<Q.RB+.4&&i.y<t+Q.BODY_H&&i.y+L(i)>t))continue;let[a,o]=[i.x-t.x,i.z-t.z],s=aa(a,o)||1,c=((t.vx-i.vx)*a+(t.vz-i.vz)*o)/s;if(!(c<Q.SPLAT_MIN)&&(n.run=this.ticks,e.state.hits=e.state.hits+1&255,!this.harm(n,c<Q.SPLAT_KILL?1:n.state.hp))){let r=aa(t.vx,t.vz);vt(n.state,t.vx/r,t.vz/r),n.state.zap=!1,n.by=e.info.id}}}place(e,t,n){let r=this.world.def.teams[t].spawns.findIndex((r,i)=>{let{x:a,z:o}=Ye(e,this.world,i,t);return!n.some(e=>Math.hypot(e.x-a,e.z-o)<$i)});return Ye(e,this.world,r<0?this.rr[t]++:r,t)}end(e){let t=this.ctf.tally().flatMap(t=>{let n=e.find(e=>e.info.id===t.id)?.info;return n?[{...t,name:n.name,team:n.team}]:[]}),n=JSON.stringify({t:`end`,score:this.ctf.score,players:t});e.forEach(e=>e.conn.send(n))}restart(e){let t=[];this.rr=[0,0],this.gone.fill(0),this.rovers=Hi(this.world);for(let n of e){let{shots:e,hits:r}=n.state;n.state={...this.place(n.info.id,n.info.team,t),shots:e,hits:r},t.push(n.state),this.ctf.place(n.info.id,n.state)}}players(){return[...this.peers.values()].filter(e=>e!==null)}join(e,t){let n=this.players();if(n.length>=this.rules.maxPlayers){e.send(JSON.stringify({t:`full`}));return}let r=0;for(;n.some(e=>e.info.id===r);)r++;let i=n.filter(e=>e.info.team===0).length,a=+(i>n.length-i),o={conn:e,info:{id:r,name:ia(ra(t)||`Player ${r}`,n.map(e=>e.info.name)),team:a,color:s[a]},state:this.place(r,a,n.map(e=>e.state)),since:this.joins++,bank:10,ack:65535,by:0,tackled:-30,run:-ea};this.peers.set(e,o),this.ctf.join(r,a,o.state),this.roster()}roster(){let e=this.players(),t=e.map(e=>e.info).sort((e,t)=>e.id-t.id);e.forEach(e=>e.conn.send(JSON.stringify({t:`roster`,you:e.info.id,players:t,map:this.mapName,host:this.host()?.info.id,next:this.next})))}},da=(e,t)=>{let n=()=>{},r=()=>{n();let r=setInterval(e,t);n=()=>clearInterval(r)};try{let i=URL.createObjectURL(new Blob([`setInterval(()=>postMessage(0),${t})`])),a=new Worker(i);a.onmessage=e,a.onerror=r,n=()=>{a.terminate(),URL.revokeObjectURL(i)}}catch{r()}return()=>n()},fa=(e,t)=>{let n=`tiny-fps:`+e,r=Math.random().toString(36).slice(2),i=new BroadcastChannel(n),a=new AbortController,o=globalThis.navigator?.locks,s,c,l,u,d=[],f,p=!1,m=e=>i.postMessage({from:r,...e}),h=e=>!p&&x.onmessage?.({data:e}),g={send:e=>queueMicrotask(()=>h(e))},_=()=>{let e=d.length?d:f?[f]:[];return d=[],e},v=e=>{if(p)return e();l=e,u=r,c=/* @__PURE__ */ new Map,s=new ua(t),s.start(da),s.connect(g),_().forEach(e=>s.receive(g,e)),m({kind:`h`})};i.onmessage=({data:e})=>{if(!p){if(s&&c){let{from:t,kind:n}=e,r=c.get(t);n===`q`?m({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!p&&m({to:t,kind:`m`,data:e})},c.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(c.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?h(e.data):e.kind===`h`&&e.from!==u&&(u=e.from,_().forEach(e=>m({kind:`m`,data:e}))))}};let y=e=>{p||(typeof e==`string`&&Ce(e)?.t===`join`&&(f=e),s?s.receive(g,e):u?m({kind:`m`,data:e}):d.push(e))},b=()=>{p||(p=!0,globalThis.removeEventListener?.(`pagehide`,b),s?(s.stop(),l()):(m({kind:`b`}),a.abort()),i.close(),setTimeout(()=>x.onclose?.()))},x={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:y,close:b};return o?o.request(n,{signal:a.signal},()=>new Promise(v)).catch(()=>{}):v(()=>{}),m({kind:`q`}),globalThis.addEventListener?.(`pagehide`,b),setTimeout(()=>!p&&x.onopen?.()),x};export{fa as localSocket};
package/dist/server.js CHANGED
@@ -30,6 +30,27 @@ var CLIMB_INSET = .2;
30
30
  var CLIMB_FWD_SPEED = 5.5;
31
31
  var STUMBLE_SPEED = 2.5;
32
32
  var TEAM_COLOR = ["#ff3d4f", "#2f80ff"];
33
+ /**
34
+ * A punch (the user, 2026-11-11): FIRE with no weapon at all. A swing of `ticks` that strikes at
35
+ * `strike` whoever is within `reach` of his centre less PLAYER_R, inside `arc` round his look (the
36
+ * katana's strike test, blade.ts). It takes half a point of health: every PUNCH_HITS punches a
37
+ * player takes cost him 1 hp (the host counts; the wire's health is whole). The PUNCH_STUN-th he
38
+ * takes within PUNCH_MEMORY ticks of the one before stuns him: a stumble as a tackle's, thrown the
39
+ * way the puncher faces, and he drops the flag he carries.
40
+ */
41
+ var PUNCH = {
42
+ ticks: 20,
43
+ strike: 6,
44
+ reach: 1.4,
45
+ arc: .6,
46
+ hp: 0,
47
+ hold: -1
48
+ };
49
+ var [PUNCH_HITS, PUNCH_STUN, PUNCH_MEMORY] = [
50
+ 2,
51
+ 3,
52
+ 180
53
+ ];
33
54
  var PLASMA_R = .12;
34
55
  /**
35
56
  * The cuts, by CUT. A swing lasts `ticks`, during which no other starts, and strikes once, `strike`
@@ -1408,8 +1429,7 @@ var swingOf = (p) => {
1408
1429
  * the arc round his look (the foe's own angular radius counts: his edge in the arc is a hit), with
1409
1430
  * the heights of the two bodies overlapping and no brush between the chests.
1410
1431
  */
1411
- var strike = (w, p, foes) => {
1412
- const { reach, arc } = swingOf(p);
1432
+ var strike = (w, p, foes, { reach, arc } = swingOf(p)) => {
1413
1433
  const [fx, fz] = forward(p.yaw);
1414
1434
  const o = [
1415
1435
  p.x,
@@ -1420,9 +1440,7 @@ var strike = (w, p, foes) => {
1420
1440
  const [dx, dz] = [f.x - p.x, f.z - p.z];
1421
1441
  const d = Math.hypot(dx, dz);
1422
1442
  if (d - .4 > reach || p.y >= f.y + heightOf(f) || f.y >= p.y + heightOf(p)) return false;
1423
- const off = d > .4 ? Math.abs(Math.atan2(fx * dz - fz * dx, fx * dx + fz * dz)) : 0;
1424
- const wide = d > .4 ? Math.asin(PLAYER_R / d) : Math.PI;
1425
- return off <= arc + wide && !hidden(w, o, [
1443
+ return (d > .4 ? Math.abs(Math.atan2(fx * dz - fz * dx, fx * dx + fz * dz)) : 0) <= arc + (d > .4 ? Math.asin(.4 / d) : Math.PI) && !hidden(w, o, [
1426
1444
  f.x,
1427
1445
  f.y + .7 * heightOf(f),
1428
1446
  f.z
@@ -1838,6 +1856,7 @@ var step = (p, i, w, team, armed = true, bodies = []) => {
1838
1856
  hand == 2,
1839
1857
  hand == 3
1840
1858
  ];
1859
+ if (p.swing && hand >= 0 && !p.blade) p.swing = 0;
1841
1860
  if (!armed) {
1842
1861
  [p.charge, p.reload] = [0, 0];
1843
1862
  return STRIKE.NONE;
@@ -1862,7 +1881,8 @@ var step = (p, i, w, team, armed = true, bodies = []) => {
1862
1881
  if (p.reload) {
1863
1882
  if (!--p.reload) p[key] = full;
1864
1883
  } else if (hand != 1 && carried >= 0 && !busy && load < full && (!load || i.keys & KEY.RELOAD)) [p.reload, p.charge] = [ticks2, 0];
1865
- const c = swingOf(p);
1884
+ const bare = hand < 0;
1885
+ const c = bare ? PUNCH : swingOf(p);
1866
1886
  if (p.swing && c.ticks - p.swing === c.strike) return STRIKE.CUT;
1867
1887
  if (p.wield && !top || p.railed || p.rifled || busy || p.reload || !p.wield && !p.mag) p.charge = 0;
1868
1888
  if (p.rifled && i.keys & KEY.SPECIAL && !busy && p.nades && !p.lob) {
@@ -1874,7 +1894,13 @@ var step = (p, i, w, team, armed = true, bodies = []) => {
1874
1894
  if (i.keys & KEY.FIRE && !busy) {
1875
1895
  const late = CUTS[p.cut ?? 0].ticks - (p.swing ?? 0);
1876
1896
  const special = !!(i.keys & KEY.SPECIAL) && (!p.swing || !p.heavy && (p.cut ?? 0) < 4 && late <= 18);
1877
- if (p.wield && (!p.swing || special)) {
1897
+ if (bare) {
1898
+ if (!p.swing) [p.cut, p.heavy, p.swing] = [
1899
+ 0,
1900
+ false,
1901
+ PUNCH.ticks
1902
+ ];
1903
+ } else if (p.wield && (!p.swing || special)) {
1878
1904
  p.cut = cutOf(i.keys) + (special ? 4 : 0);
1879
1905
  [p.swing, p.charge] = [CUTS[p.cut].ticks, 0];
1880
1906
  launch$1(p);
@@ -5603,7 +5629,11 @@ var Room = class {
5603
5629
  */
5604
5630
  harm(foe, hp) {
5605
5631
  if ((foe.state.hp -= hp) > 0) return false;
5606
- foe.graze = 0;
5632
+ [foe.graze, foe.bruise, foe.blows] = [
5633
+ 0,
5634
+ 0,
5635
+ 0
5636
+ ];
5607
5637
  if (foe.state.mode === MODE.RIDE) this.unseat(foe);
5608
5638
  Object.assign(foe.state, {
5609
5639
  hp: 0,
@@ -5713,6 +5743,10 @@ var Room = class {
5713
5743
  * crosses where `p` drew him (`limbOf`).
5714
5744
  */
5715
5745
  cut(p, view) {
5746
+ if (!p.state.blade) {
5747
+ this.punch(p, view);
5748
+ return;
5749
+ }
5716
5750
  if (p.state.cut === CUT.ARC_L || p.state.cut === CUT.ARC_R) {
5717
5751
  this.shoot(p, view, wave(p.state, p.info.team));
5718
5752
  return;
@@ -5756,6 +5790,33 @@ var Room = class {
5756
5790
  }
5757
5791
  }
5758
5792
  /**
5793
+ * A punch of `p` struck at the view tick `view`: every enemy it reaches as `p` drew him (the
5794
+ * strike test, with PUNCH's reach and arc) takes half a point, 1 hp every PUNCH_HITS punches; the
5795
+ * `hits` count goes up once. The PUNCH_STUN-th he takes with no more than PUNCH_MEMORY ticks
5796
+ * between two stuns him as a tackle does: a stumble thrown the way `p` faces, the flag dropped,
5797
+ * `by` the puncher.
5798
+ */
5799
+ punch(p, view) {
5800
+ const seen = strike(this.world, p.state, this.enemies(p, view), PUNCH);
5801
+ const foes = this.players().filter((q) => seen.some((s) => s.id === q.info.id));
5802
+ if (!foes.length) return;
5803
+ p.state.hits = p.state.hits + 1 & 255;
5804
+ for (const foe of foes) {
5805
+ foe.blows = (this.ticks - (foe.punched ?? -Infinity) <= PUNCH_MEMORY ? foe.blows ?? 0 : 0) + 1;
5806
+ foe.punched = this.ticks;
5807
+ foe.bruise = ((foe.bruise ?? 0) + 1) % PUNCH_HITS;
5808
+ if (!foe.bruise && this.harm(foe, 1)) continue;
5809
+ if (foe.blows >= PUNCH_STUN) {
5810
+ foe.blows = 0;
5811
+ this.drop(foe.info.id);
5812
+ const [dx, dz] = forward(p.state.yaw);
5813
+ stumble(foe.state, dx, dz);
5814
+ foe.state.zap = false;
5815
+ foe.by = p.info.id;
5816
+ }
5817
+ }
5818
+ }
5819
+ /**
5759
5820
  * The rail gun's bolt of `p` at the view tick `view`: the first enemy it enters as `p` drew him is
5760
5821
  * drained for RAIL_TICKS more (`slow`). A first touch, when he was not drained, takes 1 hp at once
5761
5822
  * and counts a hit.
@@ -69,5 +69,25 @@ export declare const SIT: {
69
69
  * trunk and the legs follow the knock.
70
70
  */
71
71
  export declare const MOVES: number[][];
72
+ /**
73
+ * An arm's pose, the upper arm then the forearm, as the gait builds them: `s` 1 the right, -1 the
74
+ * left; the upper arm's lift forward, out to the side and turn inward, and the elbow's bend.
75
+ */
76
+ export declare const armOf: (s: number, [lift, out, inward, bend]: number[]) => [Quat, Quat];
77
+ /**
78
+ * A punch from the guard (the user, 2026-11-11), a karate reverse punch: the rear hand (the left)
79
+ * driven straight out at the chest's height, the lead one drawn back to the hip, the chest turned
80
+ * behind the blow (radians, the left shoulder forward).
81
+ */
82
+ export declare const JAB: {
83
+ out: number[];
84
+ back: number[];
85
+ twist: number;
86
+ };
87
+ /**
88
+ * How far out the fist of a punch is, 0 to 1, by the swing of a player with no weapon at all: out
89
+ * at the strike, back by the swing's end.
90
+ */
91
+ export declare const thrown: (p: PlayerState) => number;
72
92
  /** `bow` is the guard's lean forward: none for the eye's own body, whose arms hold to the view and which stands in no sword guard. */
73
93
  export declare const createGait: (bow?: number) => Gait;
@@ -28,6 +28,8 @@ export interface Runner {
28
28
  /** Seconds left of the grimace a hit puts on his face, and of the grin of a capture or of a foe put down. */
29
29
  hurt: number;
30
30
  grin: number;
31
+ /** How far out the fist of a punch is, 0 to 1, eased. */
32
+ jab: number;
31
33
  /** His face (expression.ts), and the seconds it has yet to live through: soldier() moves it once drawn, where the head's turn is known. */
32
34
  face: Face;
33
35
  dt: number;
@@ -26,7 +26,10 @@ export declare const swingOf: (p: Pick<PlayerState, "cut" | "heavy">) => {
26
26
  * the arc round his look (the foe's own angular radius counts: his edge in the arc is a hit), with
27
27
  * the heights of the two bodies overlapping and no brush between the chests.
28
28
  */
29
- export declare const strike: (w: World, p: PlayerState, foes: PlayerState[]) => PlayerState[];
29
+ export declare const strike: (w: World, p: PlayerState, foes: PlayerState[], { reach, arc }?: {
30
+ reach: number;
31
+ arc: number;
32
+ }) => PlayerState[];
30
33
  /**
31
34
  * Whether the cut of `p`, striking now, meets the cut of the foe `f` (where `p` drew him) and the
32
35
  * two lock blades: `f` swings the katana and strikes within LOCK_WINDOW ticks of now, before or
@@ -167,6 +167,23 @@ export declare const FLAG_H = 2.2;
167
167
  export declare const FLAG_RETURN = 10;
168
168
  /** Health of a player; a hit takes 1, so HP_MAX hits put him down. */
169
169
  export declare const HP_MAX = 5;
170
+ /**
171
+ * A punch (the user, 2026-11-11): FIRE with no weapon at all. A swing of `ticks` that strikes at
172
+ * `strike` whoever is within `reach` of his centre less PLAYER_R, inside `arc` round his look (the
173
+ * katana's strike test, blade.ts). It takes half a point of health: every PUNCH_HITS punches a
174
+ * player takes cost him 1 hp (the host counts; the wire's health is whole). The PUNCH_STUN-th he
175
+ * takes within PUNCH_MEMORY ticks of the one before stuns him: a stumble as a tackle's, thrown the
176
+ * way the puncher faces, and he drops the flag he carries.
177
+ */
178
+ export declare const PUNCH: {
179
+ ticks: number;
180
+ strike: number;
181
+ reach: number;
182
+ arc: number;
183
+ hp: number;
184
+ hold: number;
185
+ };
186
+ export declare const PUNCH_HITS: number, PUNCH_STUN: number, PUNCH_MEMORY: number;
170
187
  /** Shots the rack loads. */
171
188
  export declare const AMMO_MAX = 60;
172
189
  /**
@@ -107,6 +107,14 @@ export declare class Room {
107
107
  * crosses where `p` drew him (`limbOf`).
108
108
  */
109
109
  private cut;
110
+ /**
111
+ * A punch of `p` struck at the view tick `view`: every enemy it reaches as `p` drew him (the
112
+ * strike test, with PUNCH's reach and arc) takes half a point, 1 hp every PUNCH_HITS punches; the
113
+ * `hits` count goes up once. The PUNCH_STUN-th he takes with no more than PUNCH_MEMORY ticks
114
+ * between two stuns him as a tackle does: a stumble thrown the way `p` faces, the flag dropped,
115
+ * `by` the puncher.
116
+ */
117
+ private punch;
110
118
  /**
111
119
  * The rail gun's bolt of `p` at the view tick `view`: the first enemy it enters as `p` drew him is
112
120
  * drained for RAIL_TICKS more (`slow`). A first touch, when he was not drained, takes 1 hp at once
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@korial29/tiny-fps",
3
3
  "description": "Tiny multiplayer first-person rooftop game for the browser: raw WebGL, zero runtime dependencies, WebSocket or same-browser multi-tab play.",
4
4
  "license": "Apache-2.0",
5
- "version": "0.113.0",
5
+ "version": "0.114.0",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"