@korial29/tiny-fps 0.26.0 → 0.27.1

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/index.js CHANGED
@@ -1,10 +1,10 @@
1
- var e=.4,t=1.8,n=1.55,r=.5,i=.9,a=7.5,o=2.4,s=5.5,c=2.5,l=[`Red`,`Blue`],u=[`#ff3d4f`,`#2f80ff`],d=1.5,f=.012,p=1.2,m={HOME:0,CARRIED:1,DROPPED:2},h={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128,FIRE:256},g={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},_={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},v={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},y={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7,CONCRETE:8,GLASS:9,STEEL:10,PAINT:11},b=-30,x=(e,t,n,r,i,a=y.CONCRETE)=>({min:[e,b,t],max:[n,i,r],top:y.CONCRETE,side:a}),S=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c});[x(4,57.7,24,76,10),x(4,36,24,53.5,10,y.GLASS),x(4,20,24,36,12.4),x(4,-5,24,7,12.4,y.GLASS),x(27,20,47,50,8),x(27,60,47,76,8,y.BRICK),S([9,12.2,39],[19,12.6,47],y.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>S([12,t,e-n],[14,t+.4*n,e-n+1],y.CONCRETE)))(53,10),S([5,10,42],[5.5,14,42.5],y.STEEL),S([5,10,50],[5.5,14,50.5],y.STEEL),S([8,12.4,24],[20,12.85,24.45],y.STEEL),S([36,8,22],[37,14.5,48],y.PAINT,y.PAINT,[.15,.72,.62]),S([30,8,28],[34,10,32],y.CONCRETE),S([40,8,30],[44,10.2,34],y.PAINT,y.PAINT,[1,.3,.06]),S([28,9.2,44],[35,12,46],y.STEEL,y.PAINT,[.2,.42,1]),S([41.5,7.6,50],[42,8,60],y.STEEL),S([30,8,64],[34,9.6,68],y.PAINT,y.PAINT,[.2,.8,.3])];var C=240,w=[1,.22,.26],T=[.2,.46,1],E=[1,.42,.08],D=[.12,.7,.62],O=(e,t,n,r,i,a,o)=>S([e,t,n],[r,i,a],y.PAINT,y.PAINT,o),k=(e,t,n,r,i,a,o,s=b)=>{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?S([d,s,r],[f,p,i],y.CONCRETE):S([r,s,d],[i,p,f],y.CONCRETE)})},A=(e,t,n,r,i,a,o)=>o.map((o,s)=>S([e+s*n,a,t+s*r],[e+s*n+4,o,t+s*r+i],y.STEEL,y.CONCRETE)),j=[x(12,212,52,240,26,y.GLASS),O(12,26,212,52,26.12,212.5,w),O(12,26,239.5,52,26.12,240,w),O(12,26,212.5,12.5,26.12,239.5,w),O(51.5,26,212.5,52,26.12,239.5,w),O(11.6,12,222,12,25.8,232,w),O(28,12,211.4,31,25.5,212,w),S([19,26,222],[22,27.4,225],y.STEEL),S([42,26,222],[45,27.4,225],y.STEEL),S([29,26,229],[35,27.1,229.6],y.CONCRETE),x(6,164,26,201,26,y.GLASS),x(6,134,26,147,26,y.GLASS),x(6,201,26,212,19),x(15,147,26,164,19),S([14,26,164],[15,32,196],y.PAINT,y.PAINT,D),S([14,18,147],[15,32,164],y.PAINT,y.PAINT,D),S([14,26,134],[15,32,147],y.PAINT,y.PAINT,D),...A(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])=>S([e,19,t],[n,i,r],y.STEEL,y.CONCRETE)),S([20,26,178],[23,27.3,181],y.STEEL),S([8,26,176],[11,27.2,179],y.STEEL),S([8,26,190],[11,27.3,193],y.STEEL),S([20,26,140],[23,27.3,143],y.STEEL),x(32,186,76,209,19),O(32,19,207.5,76,19.1,209,w),...A(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])=>S([e,b,t],[n,i,r],y.STEEL,y.CONCRETE)),x(32,166,64,182,21.2,y.GLASS),x(32,140,64,161,19),S([40,21.2,172],[44,22.6,176],y.STEEL),S([52,19,148],[57,20.3,151],y.STEEL),S([38,19,196],[41,20.4,199],y.STEEL),S([60,19,200],[63,20.4,203],y.STEEL),S([52,19,190],[58,20.6,194],y.STEEL),S([66,19,204],[72,20.2,207],y.STEEL),S([56,21.2,170],[60,22.4,174],y.STEEL),S([34,19,152],[37,20.3,156],y.STEEL),...A(36,135,18,0,3,15,[17.2,17.2]),...A(6.5,129,6,0,4,15,[17.2,19.4,21.6,23.8]),x(76,213,100,240,14.5,y.STEEL),O(76,14.5,238.5,100,14.6,240,w),x(76,185,100,209,14.5),x(76,138,100,181,14.5,y.GLASS),S([80,15.7,158],[96,17.7,162],y.STEEL,y.PAINT,E),S([82,14.5,234],[85,15.9,237],y.STEEL),S([91,14.5,190],[94,15.9,193],y.STEEL),S([80,14.5,204],[83,15.6,207],y.STEEL),S([78,14.5,170],[81,15.9,173],y.STEEL),S([92,14.5,146],[95,15.7,149],y.STEEL),S([92,14.5,222],[96,15.8,226],y.STEEL),...k(0,76,52,226,232,14.5,26),...k(0,85,76,196,202,14.5,19,14.5)],M=[x(6,106,62,134,15),x(62,106,100,134,14.5),S([34,15,112],[54,17.2,128],y.CONCRETE),O(38,17.2,116,50,17.3,124,E),...[[35,113],[35,126.2],[51,113],[51,126.2]].map(([e,t])=>S([e,17.2,t],[e+.8,21.5,t+.8],y.STEEL)),S([34.6,21.5,112.6],[52.2,21.9,127.4],y.GLASS),S([14,15,114],[17,16.5,117],y.STEEL),S([14,15,123],[17,16.5,126],y.STEEL),S([56,15,114],[59,16.5,117],y.STEEL),S([56,15,123],[59,16.5,126],y.STEEL),S([15.35,25.5,106],[15.85,26,134],y.STEEL),S([70,14.5,108],[70.8,38,108.8],y.STEEL),S([70,14.5,131.2],[70.8,38,132],y.STEEL),S([66,14.5,110],[69,15.9,113],y.STEEL),S([66,14.5,127],[69,15.9,130],y.STEEL)],ee=e=>({...e,min:[e.min[0],e.min[1],C-e.max[2]],max:[e.max[0],e.max[1],C-e.min[2]],tint:e.tint===w?T:e.tint}),N=(e,t,n)=>[...[16,22,28,34,40].map(n=>[n,26,t,e]),...[19,31,43].map(t=>[t,26,n,e])],P=[[20,26,190],[48,21.2,172],[48,19,200],[88,14.5,198]],F={name:`Highline`,brushes:[...j,...j.map(ee),...M],teams:[{base:[32,26,224],spawns:N(0,236,231),rack:[47,26,234]},{base:[32,26,16],spawns:N(Math.PI,4,9),rack:[47,26,6]}],packs:[...P,...P.map(([e,t,n])=>[e,t,C-n]),[24,15,112],[24,15,128]],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]},I=4,L=1024,R=(e,t)=>(e+L)*(2*L)+t+L,z=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),te=(e,t=I)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=z(e[0],t);a<=z(r[0],t);a++)for(let o=z(e[2],t);o<=z(r[2],t);o++){let e=R(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},ne=(e,t,n,r)=>{let i=[];for(let a=z(t-r,e.cell);a<=z(t+r,e.cell);a++)for(let t=z(n-r,e.cell);t<=z(n+r,e.cell);t++)for(let n of e.grid.get(R(a,t))??[])i.includes(n)||i.push(n);return i},re=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=z(t[0],i),c=z(t[2],i),l=Math.sign(n[0]),u=Math.sign(n[2]),d=l?((s+ +(l>0))*i-t[0])/n[0]:1/0,f=u?((c+ +(u>0))*i-t[2])/n[2]:1/0,p=d,m=f,h=l?i/Math.abs(n[0]):1/0,g=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(R(s,c))??[]){let e=a.brushes[r],[i,s]=[0,o];for(let r=0;r<3&&i<=s;r++){if(!n[r]){(t[r]<e.min[r]||t[r]>e.max[r])&&(s=-1);continue}let a=(e.min[r]-t[r])/n[r],o=(e.max[r]-t[r])/n[r];i=Math.max(i,Math.min(a,o)),s=Math.min(s,Math.max(a,o))}i<=s&&s>0&&i<o&&(o=i)}if(Math.min(p,m)>=o||Math.abs(s)>L||Math.abs(c)>L)return o;p<m?(s+=l,p+=h):(c+=u,m+=g)}},ie=(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},B=1/60,V=Math.PI*2,ae=1e-6,oe=.01,se=.001,ce=e=>(e%V+V)%V,le=e=>[-Math.sin(e),-Math.cos(e)],H=Math.fround,ue=Math.sqrt,de=(e,t,n)=>Math.min(Math.max(e,t),n),U=(e,t)=>ue(e*e+t*t),fe=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],pe={vx:0,vz:0,mode:g.GROUND,t:0,wall:_.NONE,edge:0,jumps:1,dashes:1,dash:0,stun:0,coyote:6,buffer:0,held:0,hp:5,ammo:-1,cool:0,rack:!1,down:0,shots:0,hits:0,ev:0,fall:0},me=(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:H(a),y:H(o),z:H(s),vy:0,yaw:ce(c),pitch:0,ground:!0,...pe}},he=(e,t,n)=>{let{yaw:r,pitch:i,id:a,shots:o,hits:s}=e;Object.assign(e,me(a,t,a,n),{yaw:r,pitch:i,shots:o,hits:s,ev:e.ev|v.RESPAWN})},ge=e=>e===g.GROUND||e===g.SLIDE||e===g.CROUCH,_e=e=>e.mode===g.SLIDE||e.mode===g.CROUCH?i:t,ve=e=>e.mode===g.SLIDE||e.mode===g.CROUCH?.7:1.6,ye=e=>U(e.vx,e.vz),be=e=>e.mode===g.GROUND&&U(e.vx,e.vz)>6.5,xe=(e,t,n)=>e.max[1]>t+.5+oe&&e.min[1]<t+n-oe,Se=(e,t,n)=>[t-de(t,e.min[0],e.max[0]),n-de(n,e.min[2],e.max[2])],Ce=(t,n,r)=>{let{brushes:i}=n.def,a=ne(n,t.x,t.z,2*e),o=(e-ae)**2,[s,c]=[0,0];for(let n=0;n<4;n++){let n=0,l=0,u=0;for(let s of a){let a=i[s];if(!xe(a,t.y,r))continue;let[c,d]=Se(a,t.x,t.z),f=c*c+d*d;if(f>=o)continue;if(f){let t=ue(f);.4-t>n&&(n=e-t,l=c/t*n,u=d/t*n);continue}let[p,m,h]=[[t.x-a.min[0],-1,0],[a.max[0]-t.x,1,0],[t.z-a.min[2],0,-1],[a.max[2]-t.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);p+.4>n&&(n=p+e,[l,u]=[m*n,h*n])}if(!n)break;t.x+=l,t.z+=u,s+=l,c+=u}return[s,c]},we=(t,n,r)=>{let{brushes:i}=n.def,a=(e-ae)**2,o=-1/0,s=1/0;for(let c of ne(n,t.x,t.z,e)){let e=i[c],[n,l]=Se(e,t.x,t.z);n*n+l*l>=a||(e.max[1]<=t.y+.5+oe?o=Math.max(o,e.max[1]):e.min[1]>=t.y+r-oe&&(s=Math.min(s,e.min[1])))}return[o,s]},Te=(t,n)=>{let r=(e-ae)**2;return ne(n,t.x,t.z,e).every(e=>{let i=n.def.brushes[e],[a,o]=Se(i,t.x,t.z);return a*a+o*o>=r||!xe(i,t.y,1.8)})},Ee=(t,n,r,i,a)=>{let o=(e-ae)**2;return ne(t,n,r,e).every(e=>{let s=t.def.brushes[e],[c,l]=Se(s,n,r);return c*c+l*l>=o||s.max[1]<=i||s.min[1]>=a})},De=(e,t)=>{let[n,r]=fe[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}},Oe=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=De(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-se&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},ke=(t,n,r)=>{let i;for(let a of ne(n,t.x,t.z,.9)){let o=n.def.brushes[a],s=Oe(o,t,r,.5);s!==void 0&&o.min[1]<t.y+.5&&o.max[1]>t.y+1.8&&(i=Math.min(i??1/0,Math.max(0,s-e)))}return i},Ae=(e,t)=>{let[n,r]=le(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=fe[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=De(e,a);for(let n of ne(t,e.x,e.z,.6000000000000001)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(Oe(r,e,a,.2)===void 0||s<1.2||s>2.4||r.min[1]>o-.25||i&&i.top>=o)continue;let u=l>0?r.min[c]:r.max[c],d=u-l*.43000000000000005,f=u+l*.2,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];Ee(t,p,m,Math.min(e.y,o-2)+oe,o+1.8)&&Ee(t,h,g,o+oe,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},je=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=De(e,e.wall);return ne(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 H(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},Me=(e,n)=>{if(e.vy>=0)return!1;let[r]=we(e,n,t),i=6*B;return e.y-r<=-e.vy*i+10*i*i},W=(e,t)=>{e.mode=t,e.t=0},Ne=(e,t)=>{let n=U(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},Pe=(t,n,r,i)=>{let[a,o]=[r.wx,r.wz];for(let r of ne(n,t.x,t.z,e+se)){let e=n.def.brushes[r],[s,c]=Se(e,t.x,t.z),l=U(s,c);if(l>0&&l<=.4+se&&xe(e,t.y,i)){let e=(-a*s-o*c)/l;e>0&&(a+=e*s/l,o+=e*c/l)}}return[a,o]},Fe=(e,t,n)=>{let r=U(t[0],t[1]);if(r<ae){let t=U(e.vx,e.vz),n=t?Math.max(0,t-45*B)/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=U(s,c);if(l){let e=Math.max(0,l-45*B)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*B):Math.max(n,o-12*B),e.vx=s+o*i,e.vz=c+o*a},Ie=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*B,e.z+=e.vz*B;let[o,s]=Ce(e,t,n),c=U(o,s);if(c){let t=(e.vx*o+e.vz*s)/c;t<0&&(e.vx-=t*o/c,e.vz-=t*s/c)}let[l,u]=we(e,t,n),d=e.vy-r*20*B;if(e.y+=(e.vy+d)/2*B,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+oe:e.y<l){if(e.y=l,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&l>=a-.5)return e.y=l,e.vy=0,0;return-1},Le=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=v.JUMP},Re=(e,n,r)=>{let[i,a]=fe[e.wall],o=t=>{W(e,t),e.edge=0};if(r.keys&(h.BACK|h.CROUCH))o(g.AIR),e.coyote=0;else if(r.jump&&r.fx*i+r.fz*a<0)o(g.AIR),e.vx=-i*4,e.vz=-a*4,Le(e,6);else if(r.jump||r.fwd&&e.t>=6)W(e,g.CLIMB);else if(e.t>=30)o(g.AIR),e.coyote=0;else{let r=Math.max(e.edge-2,we(e,n,t)[0]);e.y+=de(r-e.y,-8*B,8*B)}},ze=(e,t)=>{let[n,r]=fe[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*B):(e.x+=n*s*B,e.z+=r*s*B),e.y>=e.edge&&je(e,t)?(W(e,g.GROUND),e.vx=n*3,e.vz=r*3,e.vy=0,e.edge=0,e.wall=_.NONE,e.coyote=6,e.ev|=v.CLIMB):e.t>=40&&(W(e,e.y>=e.edge?g.GROUND:g.AIR),e.edge=0,e.wall=_.NONE)},Be=(e,t,n)=>{let[r,i]=fe[e.wall],a=e.vx*r+e.vz*i,[o,s]=[e.vx-a*r,e.vz-a*i],c=U(o,s);if(n.jump)W(e,g.AIR),e.vx=o-r*5,e.vz=s-i*5,Le(e,6.5),e.jumps=1,e.dashes=1,e.ev|=v.WALLRUN_END;else{let a=ke(e,t,e.wall);if(a===void 0||!n.fwd||c<3.5||e.t>=60){W(e,g.AIR),e.ev|=v.WALLRUN_END;return}let l=Math.max(0,c-1.5*B)/c;e.vx=o*l,e.vz=s*l;let u=Math.min(a,4*B);e.x+=r*u,e.z+=i*u}},Ve=(e,t,n)=>{if(!n.fwd)return;let r=U(e.vx,e.vz);if(!(r<4.5))for(let n=1;n<=4;n++){let[i,a]=fe[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&&ke(e,t,n)!==void 0){let t=U(s,c),i=Math.max(t,.9*r)/t;W(e,g.WALLRUN),e.wall=n,[e.vx,e.vz]=[s*i,c*i],e.vy=de(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=v.WALLRUN_START;return}}},He=(e,t)=>{W(e,g.HANG),e.wall=t.side,e.edge=H(t.top),t.side<=_.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|=v.GRAB},Ue=(e,t,n)=>{let r=e.mode===g.GROUND;if(n.dash&&e.dash===0&&(r||(e.mode===g.AIR||e.mode===g.WALLRUN)&&e.dashes>0)){let[t,i]=n.wx||n.wz?[n.wx,n.wz]:[n.fx,n.fz];r||(e.dashes--,e.vy=0,e.mode===g.WALLRUN&&(W(e,g.AIR),e.ev|=v.WALLRUN_END)),e.vx=t*16,e.vz=i*16,e.dash=60,e.ev|=v.DASH}let i=e.dash>50;e.mode===g.WALLRUN&&Be(e,t,n),ge(e.mode)&&We(e,t,n,i),e.mode===g.AIR&&Ge(e,t,n,i);let o=i&&e.vy<=0?0:e.mode===g.WALLRUN?.15:1,s=e.mode,c=Ie(e,t,_e(e),o,ge(s));if(c>=0){if(!ge(e.mode)){if(e.ev|=v.LAND|(e.mode===g.WALLRUN?v.WALLRUN_END:0),e.fall=c,e.jumps=1,e.dashes=1,e.wall=_.NONE,n.keys&h.CROUCH){let t=U(e.vx,e.vz)>=a;W(e,t?g.SLIDE:g.CROUCH),e.ev|=t?v.SLIDE_START:0}else W(e,g.GROUND)}e.coyote=6}else ge(e.mode)&&(e.ev|=e.mode===g.SLIDE?v.SLIDE_END:0,W(e,g.AIR));if(e.mode===g.AIR){let r=Ae(e,t);r?He(e,r):Ve(e,t,n)}},We=(e,n,r,o)=>{let s=(r.keys&h.CROUCH)!==0;if(e.buffer>0&&(e.mode===g.GROUND||Te(e,n))){e.ev|=e.mode===g.SLIDE?v.SLIDE_END:0,W(e,g.AIR),Le(e,7);return}let l=U(e.vx,e.vz);if(e.mode===g.GROUND&&s){let t=l>=a;W(e,t?g.SLIDE:g.CROUCH),e.ev|=t?v.SLIDE_START:0}else e.mode===g.SLIDE&&(e.t>=60||l<4.5||r.stumble)?(e.ev|=v.SLIDE_END,W(e,!s&&Te(e,n)?g.GROUND:g.CROUCH)):e.mode===g.SLIDE&&!s&&Te(e,n)?(e.ev|=v.SLIDE_END,W(e,g.GROUND)):e.mode===g.CROUCH&&!s&&Te(e,n)&&W(e,g.GROUND);if(!o){if(r.stumble){if(l>2.5){let t=Math.max(c,l-12*B)/l;e.vx*=t,e.vz*=t}else Fe(e,Pe(e,n,r,_e(e)),c)}else if(e.mode===g.SLIDE){let t=Math.max(0,l-4*B)/l;e.vx*=t,e.vz*=t}else if(e.mode===g.CROUCH)Fe(e,Pe(e,n,r,i),3);else{let i=(r.keys&h.SPRINT)!==0&&r.fwd;Fe(e,Pe(e,n,r,t),i?9:6)}}},Ge=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?Le(e,7):e.jumps>0&&!Me(e,t)&&(e.jumps--,Le(e,6),e.ev=e.ev&~v.JUMP|v.DOUBLE)),r||!n.wx&&!n.wz)return;let i=U(e.vx,e.vz);e.vx+=n.wx*14*B,e.vz+=n.wz*14*B,Ne(e,Math.max(i,6))},Ke=(e,t,r,i=0)=>{e.yaw=ce(t.yaw),e.pitch=Math.max(-1.55,Math.min(n,t.pitch));let a=(t.keys&h.FORWARD?1:0)-(t.keys&h.BACK?1:0),o=(t.keys&h.RIGHT?1:0)-(t.keys&h.LEFT?1:0),s=U(a,o)||1,[c,l]=le(e.yaw),u=n=>(t.keys&n)!==0&&(e.held&n)===0,d=e.stun>0,f={keys:t.keys,stumble:d,jump:!d&&u(h.JUMP),dash:!d&&u(h.DASH),fwd:a>0,wx:(c*a-l*o)/s,wz:(l*a+c*o)/s,fx:c,fz:l},p=e.mode;e.ev=0,e.fall=0,f.jump&&(e.buffer=7),d&&e.stun--,e.dash>0&&(e.dash--,e.dash===50&&Ne(e,10)),e.mode===g.HANG&&Re(e,r,f),e.mode===g.CLIMB?ze(e,r):e.mode!==g.HANG&&Ue(e,r,f),e.y<r.def.floor&&he(e,r,i),e.t=e.mode===p?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===g.AIR&&p===g.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=t.keys&(h.JUMP|h.DASH),e.ground=ge(e.mode),e.x=H(e.x),e.y=H(e.y),e.z=H(e.z),e.vx=H(e.vx),e.vy=H(e.vy),e.vz=H(e.vz),e.edge=H(e.edge)},qe=127,Je=16,Ye=65536/(2*Math.PI),Xe=e=>Math.round(e*Ye)&65535,Ze=e=>Math.max(-32768,Math.min(32767,Math.round(e))),Qe=e=>Ze(e*1e4),$e=e=>e/1e4,et=e=>e/Ye,tt=(e=0)=>Math.round(e*256)&16777215,nt=e=>({...e,yaw:et(Xe(e.yaw)),pitch:$e(Qe(e.pitch)),...e.view!==void 0&&{view:tt(e.view)/256}}),rt=e=>{let t=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(12));t.setUint8(0,1),t.setUint16(1,e.seq&65535),t.setUint16(3,e.keys&511),t.setUint16(5,Xe(e.yaw)),t.setInt16(7,Qe(e.pitch));let n=tt(e.view);return t.setUint16(9,n>>8),t.setUint8(11,n&255),t.buffer},it=e=>e===m.CARRIED?2:e===m.DROPPED?8:1,at=e=>{if(e.byteLength<4)return null;let t=new DataView(e),n=t.getUint8(3),r=4+45*n;if(t.getUint8(0)!==2||e.byteLength<r+8+2)return null;let i=[];for(let e=0;e<n;e++){let n=4+e*45,r=t.getUint8(n+35),a=t.getUint8(n+38),[o,s]=[t.getUint8(n+37),t.getUint8(n+39)],c=r&7,l=t.getUint8(n+40)<<16|t.getUint16(n+41);i.push({id:t.getUint8(n),x:t.getFloat32(n+1),y:t.getFloat32(n+5),z:t.getFloat32(n+9),vx:t.getFloat32(n+13),vy:t.getFloat32(n+17),vz:t.getFloat32(n+21),edge:t.getFloat32(n+25),yaw:et(t.getUint16(n+29)),pitch:$e(t.getInt16(n+31)),ack:t.getUint16(n+33),ground:c===g.GROUND||c===g.SLIDE||c===g.CROUCH,mode:c,wall:r>>3&7,jumps:r>>6&1,dashes:r>>7,t:t.getUint8(n+36),dash:o&63,stun:s&63,by:o>>6<<2|s>>6,coyote:a&7,buffer:a>>3&7,held:(a&64?h.JUMP:0)|(a&128?h.DASH:0),ev:0,fall:0,hp:l&7,cool:l>>3&7,ammo:(l>>6&127)===qe?-1:l>>6&127,down:l>>13&127,rack:(l>>20&1)==1,shots:t.getUint8(n+43),hits:t.getUint8(n+44)})}let a=t.getUint16(r+2),o=r+8,s=[];for(let n=0;n<2;n++){let n=o<e.byteLength?t.getUint8(o):-1;if(n<0||n>m.DROPPED||o+it(n)>e.byteLength)return null;let r={state:n,by:0,x:0,y:0,z:0,left:0};n===m.CARRIED?r.by=t.getUint8(o+1):n===m.DROPPED&&([r.x,r.y,r.z]=[1,3,5].map(e=>t.getInt16(o+e)/Je),r.left=t.getUint8(o+7)),s.push(r),o+=it(n)}return o===e.byteLength?{tick:t.getUint16(1),players:i,score:[t.getUint8(r),t.getUint8(r+1)],clock:a&32767,over:!!(a&32768),flags:s,packs:t.getUint32(r+4)}:null},ot=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},st=44100,ct=([e,t,n,r,i,a,o,s,c,l,u],d)=>{let f=new Float32Array(Math.ceil((r+i+a)*st)),p=0,m=0,h=0,g=()=>{d=d+1831565813|0;let e=Math.imul(d^d>>>15,1|d);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/2**31-1};for(let d=0;d<f.length;d++){let _=d/st;p+=t*2**(n*_)*(_>c?l:1)*(1+o*Math.sin(_*44))/st,p>=1&&(p%=1,h=g());let v=e==3?h:e==2?Math.sin(p*2*Math.PI):e?1-2*p:p<.5?1:-1;m+=(v-m)*s;let y=_<r?_/r:_<r+i?1:((r+i+a-_)/a)**2;f[d]=m*y*u}return f},G={STEP:0,WALLSTEP:1,JUMP:2,DOUBLE:3,DASH:4,LAND:5,GRAB:6,SCUFF:7,WIND:8,SCRAPE:9,TAKE:10,DROP:11,RETURN:12,CAPTURE:13,TACKLE:14,GRUNT:15,LASER:16,HIT:17,HURT:18,DOWN:19,GUN:20,PACK:21,DRY:22},lt=[[[2,130,-3,.001,.005,.06,0,1,0,1,.7],[3,8e3,-1,.001,0,.035,0,.4,0,1,.45]],[[3,12e3,0,.001,0,.03,0,.5,0,1,.4],[2,190,-3,.001,0,.04,0,1,0,1,.3]],[[3,14e3,0,.015,.02,.09,.3,.18,0,1,.5],[2,70,-2,.003,0,.07,0,1,0,1,.3]],[[3,4e3,3.5,.03,.03,.2,0,.25,0,1,.5],[2,350,1.2,.03,.02,.18,.02,1,0,1,.12]],[[3,14e3,-2.5,.008,.07,.2,.25,.3,0,1,.8],[3,3500,.5,.01,.06,.2,0,.12,0,1,.5]],[[2,70,-2.5,.001,.01,.2,0,1,0,1,.9],[3,7e3,-1,.001,0,.09,0,.25,0,1,.5]],[[3,6e3,-1,.001,0,.05,0,.5,0,1,.7],[2,160,-4,.001,0,.07,0,1,0,1,.5]],[[3,5e3,0,.01,.04,.14,.5,.3,0,1,.5],[3,2500,0,.03,0,.1,.4,.2,0,1,.3,.08]],[[3,2e4,0,.001,2.1,.001,.25,.06,0,1,1.2],[3,2e4,0,.001,2.1,.001,.35,.3,0,1,.3]],[[3,9e3,0,.001,2.1,.001,.5,.4,0,1,.5],[3,3e3,0,.001,2.1,.001,.4,.2,0,1,.5]],[[0,392,0,.003,.05,.08,0,.35,.07,1.5,.5],[2,784,0,.003,.03,.1,.01,1,0,1,.3,.05]],[[1,330,-2.2,.003,.04,.22,.04,.25,0,1,.45],[3,2500,-1,.001,0,.12,0,.3,0,1,.4]],[[2,659,0,.003,.06,.25,.015,1,.09,1.5,.5],[2,1318,0,.003,.03,.2,0,1,0,1,.2,.09]],[[0,523,0,.004,.07,.1,0,.3,0,1,.4],[0,659,0,.004,.07,.1,0,.3,0,1,.4,.11],[0,784,0,.004,.07,.1,0,.3,0,1,.4,.22],[0,1047,0,.004,.2,.35,.008,.3,0,1,.5,.33],[2,262,0,.004,.25,.3,0,1,0,1,.35,.33]],[[2,120,-3,.001,.01,.24,0,1,0,1,1],[3,5e3,-1.5,.001,0,.09,0,.35,0,1,.7],[3,2200,0,.01,.03,.16,.3,.15,0,1,.4,.03]],[[1,170,-.9,.012,.05,.17,.06,.2,0,1,.5],[3,3e3,0,.01,.04,.14,.4,.12,0,1,.5]],[[1,3600,-10,.001,.01,.09,0,.5,0,1,.4],[0,1900,-8,.001,0,.06,0,.3,0,1,.25],[3,9e3,0,.001,0,.03,0,.4,0,1,.25]],[[2,1700,0,.001,0,.13,0,1,0,1,.6],[2,4700,0,.001,0,.05,0,1,0,1,.3],[2,1790,0,.001,0,.09,0,1,0,1,.3]],[[2,110,-2.5,.002,.01,.2,0,1,0,1,.9],[3,2500,0,.02,.03,.17,.3,.12,0,1,.5,.04]],[[2,90,-1.2,.002,.04,.45,0,1,0,1,.9],[1,180,-1.5,.01,.06,.4,.05,.2,0,1,.45],[3,3e3,0,.02,0,.35,.3,.1,0,1,.4,.12]],[[3,5e3,0,.001,0,.02,0,.5,0,1,.5],[0,260,1.5,.005,.06,.12,0,.25,0,1,.4,.02],[2,1040,.5,.003,.03,.18,.01,1,0,1,.25,.1]],[[2,523,0,.003,.03,.1,0,1,0,1,.4],[2,659,0,.003,.03,.1,0,1,0,1,.4,.07],[2,880,0,.003,.05,.2,.01,1,0,1,.45,.14]],[[0,190,-3,.001,0,.04,0,.6,0,1,.6],[3,6e3,0,.001,0,.02,0,.5,0,1,.5]]],ut=[G.WIND,G.SCRAPE],dt=(e,t=lt)=>{let n=t[e].map((t,n)=>[ct(t,e*9+n),Math.round((t[11]??0)*st)]);return Float32Array.from({length:Math.max(...n.map(([e,t])=>t+e.length))},(e,t)=>Math.tanh(n.reduce((e,[n,r])=>e+(n[t-r]??0),0)))},ft=(e,t=st/10)=>{let n=e.length-t;return Float32Array.from({length:n},(r,i)=>i<t?e[i]*Math.sqrt(i/t)+e[n+i]*Math.sqrt(1-i/t):e[i])},pt=st*60/108,mt=pt/4,ht=4,gt=[2,150,-6,.002,0,.25,0,1,0,1,1],_t=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],vt=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],yt=()=>{let e=new Float32Array(pt*4*ht),t={},n=(n,r)=>(t[String(r)]??=ct(r,1)).forEach((t,r)=>e[(n*mt+r)%e.length]+=t),r=e=>55*2**(e/12),i=[0,0,-4,-5],a=[0,0,12,0,0,7,12,7];for(let e=0;e<64;e++){let t=e%16;if(`x.......x.x.....`[t]==`x`&&n(e,gt),`....x.......x...`[t]==`x`&&n(e,_t),t%2==0){n(e,vt);let o=i[e>>4]+a[t>>1];n(e,[1,r(o),0,.005,.08,.18,0,.15,0,1,.6])}}[15,12,10,19,17,15].forEach((e,t)=>n([18,24,28,50,54,60][t],[2,r(e+24),0,.02,.1,.6,.01,1,0,1,.5]));let o=e.reduce((e,t)=>Math.max(e,Math.abs(t)),0);return e.map(e=>e/o*.35)},bt=40,xt=24,St=.5,Ct=`tiny-fps:muted`,wt=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},loop:()=>({set:()=>{}}),mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},Tt=(e=lt)=>{let t;try{t=new AudioContext}catch{return wt()}let n=(e,n=1)=>{let r=t.createGain();return r.gain.value=n,r.connect(e),r},r=n(t.destination),i=n(r,St),a=[],o=!1,s=/* @__PURE__ */ new Set,c=[0,0,0],l=0,u=!1,d=e=>{let n=t.createBuffer(1,e.length,st);return n.getChannelData(0).set(e),n},f=e=>{let n=t.createBufferSource();return n.buffer=e,n};return{unlock(){if(t.resume().catch(()=>{}),!o){o=!0,e.forEach((t,n)=>{let r=dt(n,e);a[n]=d(ut.includes(n)?ft(r):r)});let t=f(d(yt()));t.loop=!0,t.connect(i),t.start()}},listen(e,t){[c,l]=[e,t]},play(e,i,o=1,u=1){let d=0,p=o;if(i){let[e,t,n]=i.map((e,t)=>e-c[t]),r=Math.hypot(e,t,n);p=Math.max(0,1-r/bt)**2*o,d=(e*Math.cos(l)-n*Math.sin(l))/Math.max(r,1)}let m=a[e];if(!m||!p)return;if(s.size>=xt){let e=[...s].reduce((e,t)=>t.vol<e.vol?t:e);if(e.vol>=p)return;e.src.stop(),s.delete(e)}let h=f(m);h.playbackRate.value=u;let g=t.createStereoPanner();g.pan.value=d,h.connect(g).connect(n(r,p));let _={vol:p,src:h};s.add(_),h.onended=()=>s.delete(_),h.start()},loop(e){let i,o;return{set(s,c){!i&&a[e]&&(i=f(a[e]),i.loop=!0,i.connect(o=n(r,0)),i.start()),i&&(o.gain.setTargetAtTime(s,t.currentTime,.08),i.playbackRate.setTargetAtTime(c,t.currentTime,.08))}}},mute(e){u=e,r.gain.setTargetAtTime(+!e,t.currentTime,.05)},get muted(){return u},destroy:()=>void t.close().catch(()=>{})}},Et=()=>{try{return localStorage.getItem(Ct)==`1`}catch{return!1}},Dt=e=>{e.mute(!e.muted);try{localStorage.setItem(Ct,e.muted?`1`:`0`)}catch{}return e.muted},Ot=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],kt=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],At=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],jt=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n],Mt=e=>{let t=Math.hypot(...e)||1;return[e[0]/t,e[1]/t,e[2]/t]},Nt=(e,t,n=0)=>{let[r,i,a,o,s,c]=[e,t,n].flatMap(e=>[Math.sin(e),Math.cos(e)]),l=[i,0,-r],u=[r*a,o,i*a];return[l.map((e,t)=>e*c-u[t]*s),u.map((e,t)=>e*c+l[t]*s),[-r*o,a,-i*o]]},Pt=(e,t,n=[0,0,0])=>{let r=[],i=e.filter((t,n)=>!n||Math.hypot(t[0]-e[n-1][0],t[1]-e[n-1][1])>1e-9),a=i.slice(1).map(([e,t],n)=>{let[r,a]=i[n],o=Math.hypot(e-r,t-a);return[(t-a)/o,-(e-r)/o]}),o=i.map(([e],t)=>{let[n,r]=[0,1].map(e=>(a[t-1]?.[e]??0)+(a[t]?.[e]??0)),i=Math.hypot(n,r);return e?[n/i,r/i]:[0,Math.sign(r)]}),s=(e,a)=>{let[s,c]=i[a],[l,u]=[Math.cos(e*V/t),Math.sin(e*V/t)];r.push(n[0]+s*l,n[1]+s*u,n[2]-c,o[a][0]*l,o[a][0]*u,-o[a][1])};for(let e=1;e<i.length;e++)for(let n=0;n<t;n++)[...i[e-1][0]?[[n,e-1],[n+1,e-1],[n+1,e]]:[],...i[e][0]?[[n,e-1],[n+1,e],[n,e]]:[]].forEach(([e,t])=>s(e,t));return r},Ft=(e,t,n,[r,i],a)=>{let o=(e,t,n,r)=>Array.from({length:t},(i,a)=>{let o=a*V/t/4;return[e*Math.sin(o),n-r*e*Math.cos(o)]});return Pt([...r?o(t[0],r,0,1):[[0,0]],...t.map((n,r)=>[n,e*r/(t.length-1)]),...i?o(t[t.length-1],i,e,-1).reverse():[[0,e]]],n,a)},It=(e,[t,n,r])=>Array.from({length:e.length*(10/6)},(i,a)=>{let[o,s]=[Math.floor(a/10),a%10];return s<6?e[o*6+s]:[t,n,-1,r][s-6]}),Lt=[[5,1],[7,2],[10,3]],Rt=/* @__PURE__ */ new Map,zt=(e,t,n,r=[1,1])=>{let[i,a]=Lt[e];!e&&n.length>3&&(n=[n[0],n[n.length>>1],n[n.length-1]]);let o=`${e} ${t} ${n} ${r}`,s=Rt.get(o);return s||(s=It(Ft(t,n,i,r.map(e=>Math.ceil(a*e))),[1,1,1]),Rt.set(o,s)),s},Bt=(e,t,n,[r,i,a],o,s,c=[1,1,1])=>{let[l,u,d]=typeof s==`number`?[s,s,s]:s,f=l==u&&u==d,[p,m,h,g,_,v,y,b,x]=[...r,...i,...a],S=n[0]+p*o[0]+g*o[1]+y*o[2],C=n[1]+m*o[0]+_*o[1]+b*o[2],w=n[2]+h*o[0]+v*o[1]+x*o[2];for(let n=0;n<t.length;n+=10){let[r,i,a]=[t[n]*l,t[n+1]*u,t[n+2]*d],[o,s,T]=[t[n+3],t[n+4],t[n+5]];if(!f){[o,s,T]=[o/l,s/u,T/d];let e=Math.sqrt(o*o+s*s+T*T)||1;[o,s,T]=[o/e,s/e,T/e]}e.push(S+p*r+g*i-y*a,C+m*r+_*i-b*a,w+h*r+v*i-x*a,p*o+g*s-y*T,m*o+_*s-b*T,h*o+v*s-x*T,t[n+6]*c[0],t[n+7]*c[1],t[n+8],t[n+9]*c[2])}},Vt=(e,t)=>{let n=e[0]*t[0]+e[1]*t[1]+e[2]*t[2],r=t.map((t,r)=>t-e[r]*n),i=Math.hypot(...r)||1,[a,o,s]=r.map(e=>e/i);return[[a,o,s],[o*e[2]-s*e[1],s*e[0]-a*e[2],a*e[1]-o*e[0]],e]},Ht=(e,t,n,r,i,a,o=1,s)=>{let c=[r[0]-n[0],r[1]-n[1],r[2]-n[2]],l=Math.hypot(...c)||1,[u,d]=typeof o==`number`?[o,o]:o;Bt(e,t,n,Vt([c[0]/l,c[1]/l,c[2]/l],i),[0,0,0],[u,d,l/a],s)},Ut=2.4,Wt=[1,.62],Gt=8,Kt=28,qt=2.2,Jt=.04,Yt=.045,Xt=e=>{let t=parseInt(u[e].slice(1),16);return[t>>16,t>>8&255,t&255].map(e=>e/255)},Zt=(e,t,n)=>e.flatMap((e,r)=>{if(e.state===m.DROPPED)return[{team:r,at:[e.x,e.y,e.z],dropped:!0}];if(e.state===m.CARRIED){let t=n(e.by);return t?[{team:r,at:[t.x,t.y,t.z],by:{yaw:t.yaw,vx:t.vx,vz:t.vz}}]:[]}return[{team:r,at:t[r]}]}),Qt=[[1,0,0],[0,1,0],[0,0,1]],$t=(e,t,n)=>{for(let r=t;r<e.length;r+=10)e[r+6]*=n,e[r+7]*=n,e[r+9]*=n,e[r+8]=-2},en=(e,t,n,r,[i,a,o])=>{let[s,c,l]=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],[u,d,f]=[r[0]-t[0],r[1]-t[1],r[2]-t[2]],p=[c*f-l*d,l*u-s*f,s*d-c*u],m=Math.hypot(...p)||1;for(let s of[t,n,r])e.push(...s,p[0]/m,p[1]/m,p[2]/m,i,a,-1,o)},tn=(e,t,n,r,i)=>{for(let a=0;a<Kt;a++){let[o,s]=[a,a+1].map(e=>e*2*Math.PI/Kt),c=(e,n)=>[t[0]+e*Math.cos(n),t[1],t[2]+e*Math.sin(n)];en(e,c(n,o),c(r,s),c(r,o),i),en(e,c(n,o),c(n,s),c(r,s),i)}},nn=(e,t,n,r)=>{for(let i=0;i<Kt;i++){let[a,o]=[i,i+1].map(e=>e*2*Math.PI/Kt);en(e,t,[t[0]+n*Math.cos(o),t[1],t[2]+n*Math.sin(o)],[t[0]+n*Math.cos(a),t[1],t[2]+n*Math.sin(a)],r)}},rn=(e,t,n,r)=>{nn(e,[t[0],t[1]+Jt,t[2]],d,n.map(e=>e*.4));let i=e.length;tn(e,[t[0],t[1]+Yt,t[2]],d-.16,d,n),$t(e,i,qt*(.75+.25*Math.sin(r*3)))},an=(e,t,n,[r,i],a,o,s)=>{let c=[-n[2],0,n[0]],l=(e,s)=>{let l=a*e*Math.sin(o*7-e*5),u=i*s*(1-e);return[t[0]+n[0]*r*e+c[0]*l,t[1]-u+.12*r*e*Math.sin(o*5-e*4)*a,t[2]+n[2]*r*e+c[2]*l]};for(let t=0;t<Gt;t++){let[n,r]=[t/Gt,(t+1)/Gt],[i,a,o,c]=[l(n,0),l(r,0),l(r,1),l(n,1)],u=[(a[1]-i[1])*(c[2]-i[2])-(a[2]-i[2])*(c[1]-i[1]),(a[2]-i[2])*(c[0]-i[0])-(a[0]-i[0])*(c[2]-i[2]),(a[0]-i[0])*(c[1]-i[1])-(a[1]-i[1])*(c[0]-i[0])],d=Math.hypot(...u)||1,f=(e,t)=>[e[0]+u[0]/d*.004*t,e[1]+u[1]/d*.004*t,e[2]+u[2]/d*.004*t];for(let t of[1,-1]){let n=[i,a,o,c].map(e=>f(e,t)),[r,l,u,d]=t>0?n:[n[0],n[3],n[2],n[1]];en(e,r,l,u,s),en(e,r,u,d,s)}}},on=(e,t,n,r)=>{Ht(e,zt(1,1,[1,1],[0,0]),t,n,[.6,0,.8],1,.045,[.82,.84,.9]);let i=e.length;Bt(e,zt(1,0,[1,1]),n,Qt,[0,0,0],.09,r),$t(e,i,qt)},sn=(e,t,n,r)=>{let[i,a,o]=t.at,s=r+t.team*1.7;if(t.by){let{yaw:r,vx:c,vz:l}=t.by,u=-Math.sin(r),d=-Math.cos(r),f=Math.hypot(c,l),p=[i-u*.28,a+.55,o-d*.28],m=[i-u*.38,a+.55+Ut-.2,o-d*.38],[h,g]=f>1?[-c/f,-l/f]:[-u,-d];on(e,p,m,n);let _=Math.min(1,f/8);an(e,m,[h,0,g],[Wt[0]*(.7+.5*_),Wt[1]],.1+.16*_,s,n);return}if(t.dropped){let t=i*12.9898+o*78.233,[c,l]=[Math.cos(t),Math.sin(t)],u=[i+c*2.3,a+.6,o+l*2.3];on(e,[i,a+.06,o],u,n),an(e,u,[c,0,l],[Wt[0]*.8,Wt[1]*.8],.04,s,n);let f=e.length;tn(e,[i,a+Yt,o],d-.1,d,n),$t(e,f,qt*(.5+.5*Math.abs(Math.sin(r*5))));return}let c=[i,a+Ut,o];on(e,[i,a,o],c,n);let l=.6+t.team*Math.PI;an(e,c,[Math.cos(l),0,Math.sin(l)],Wt,.18,s,n)},cn={SPOT:0,POINT:1},ln=9,un=6,dn=e=>{let{ctf:t,t:n}=e;if(!t)return[];let r=([e,t,n],r,i,a)=>({kind:cn.POINT,p:[e,t,n],d:[0,-1,0],cone:0,range:i,color:Xt(r).map(e=>e*a),shadow:!1});return[...t.bases.map(([e,t,i],a)=>r([e,t+1.2,i],a,ln,1.1+.3*Math.sin(n*3))),...t.flags.filter(e=>e.dropped).map(e=>r([e.at[0],e.at[1]+.8,e.at[2]],e.team,un,.9))]},fn=.08,pn=.06,mn=.22,hn=7,gn=[[.022,[.4,.15,1.3],0],[.007,[.7,1.7,2.2],.02]],_n=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],vn=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],yn=e=>{let t=Math.hypot(...e)||1;return[e[0]/t,e[1]/t,e[2]/t]},bn=(e,t,[n,r,i])=>e.push(...t,0,1,0,n,r,-2,i),xn=(e,t,n,r,i,a,o)=>{let s=_n(n,t),c=vn(s,_n(t,a));Math.hypot(...c)<1e-6*Math.hypot(...s)&&(c=vn(s,[0,1,0])),c=yn(c);let[l,u,d,f]=[[t,1],[t,-1],[n,-1],[n,1]].map(([e,t])=>{let n=yn(_n(a,e)),i=r*Math.min(Math.max(Math.hypot(..._n(a,e))/5,1),2.5);return e.map((e,r)=>e+c[r]*i*t+n[r]*o)});for(let t of[l,u,d,l,d,f])bn(e,t,i)},Sn=()=>{let e=[],t=[],n=7,r=()=>(n=n*16807%2147483647)/2147483647*2-1;return{mount(t){e.forEach(e=>e.own&&(e.a=t))},shoot(n,i,a,o=!1){if(e.push({a:n,b:i,age:0,hit:a,own:o}),e=e.slice(-16),a){let e=yn(_n(n,i));for(let n=0;n<hn;n++)t.push({p:i,v:[0,1,2].map(t=>e[t]*3+r()*3+(t==1?2:0)),age:0});t=t.slice(-112)}},update(n){for(let r of[...e,...t])r.age+=n;e=e.filter(e=>e.age<fn),t=t.filter(e=>e.age<mn);for(let e of t)e.v[1]-=9*n,e.p=e.p.map((t,r)=>t+e.v[r]*n)},draw(n,r){for(let{a:t,b:i,age:a}of e){let e=1-a/fn;gn.forEach(([a,o,s])=>xn(n,t,i,a*e**.7,o.map(t=>t*(.6+.4*e)),r,s))}for(let{p:e,age:i}of t){let t=1-i/mn,a=yn(vn(_n(e,r),[0,1,0])),o=yn(vn(a,_n(e,r))),[s,c]=[.022*t,.022*t],l=(t,n)=>[e[0]+a[0]*t+o[0]*n,e[1]+a[1]*t+o[1]*n,e[2]+a[2]*t+o[2]*n];for(let e of[l(-s,0),l(0,c),l(s,0),l(-s,0),l(s,0),l(0,-c)])bn(n,e,[1.4*t+.4,2.2*t+.3,3])}},lights(){let t=(e,t,n,r)=>({kind:cn.POINT,p:e,d:[0,-1,0],cone:0,range:t,color:r.map(e=>e*n),shadow:!1});return e.filter(e=>e.age<pn).slice(-3).flatMap(e=>{let n=1-e.age/pn;return[t(e.a,6,1.3*n,[.35,.8,1.5]),...e.hit?[t(e.b,3.5,.9*n,[.3,.7,1.3])]:[]]})},get count(){return e.length}}},Cn=(e,t)=>{if(!e)return[];if(e.over||t.over)return e.over&&!t.over?[{kind:`start`}]:[];let n=[];for(let r of[0,1])t.score[r]>e.score[r]&&n.push({kind:`capture`,team:r});let r=n.length>0;t.flags.forEach((t,i)=>{let a=e.flags[i];t.state===m.CARRIED&&(a.state!==m.CARRIED||a.by!==t.by)?n.push({kind:`take`,flag:i,by:t.by}):t.state===m.DROPPED&&a.state===m.CARRIED?n.push({kind:`drop`,flag:i}):t.state===m.HOME&&(a.state===m.DROPPED||a.state===m.CARRIED&&!r)&&n.push({kind:`return`,flag:i})});for(let r of t.players)r.stun>(e.players.find(e=>e.id===r.id)?.stun??1/0)&&n.push({kind:`tackle`,who:r.id,by:r.by,at:[r.x,r.y+1,r.z]});return n},wn=(e,t,n)=>{let r=e=>l[e].toLowerCase();switch(e.kind){case`take`:{let i=1-e.flag;return{team:i,text:e.flag===t.team?`${l[i]} took your flag`:e.by===t.id?`You took the ${r(e.flag)} flag`:`${n(e.by)} took the ${r(e.flag)} flag`}}case`drop`:return{team:e.flag,text:e.flag===t.team?`Your flag was dropped`:`${l[e.flag]} flag dropped`};case`return`:return{team:e.flag,text:e.flag===t.team?`Your flag returned`:`${l[e.flag]} flag returned`};case`capture`:return{team:e.team,text:`${l[e.team]} scored`};case`tackle`:return e.by===t.id?{team:t.team,text:`Tackled ${n(e.who)}!`}:void 0;default:return{text:`New match`}}},Tn=(e,t)=>{let{team:n}=t;switch(e.kind){case`take`:return[{id:G.TAKE,rate:e.flag===n?.8:1}];case`drop`:return[{id:G.DROP,rate:e.flag===n?1:.85}];case`return`:return[{id:G.RETURN,rate:e.flag===n?1:.85}];case`capture`:return[{id:G.CAPTURE,rate:e.team===n?1:.8}];case`tackle`:return e.who===t.id?[{id:G.TACKLE},{id:G.GRUNT}]:e.by===t.id?[{id:G.TACKLE,gain:.8,rate:1.1}]:[{id:G.TACKLE,at:e.at}];default:return[]}},K={PELVIS:0,SPINE:1,CHEST:2,NECK:3,HEAD:4,CLAVICLE_L:5,ARM_L:6,FOREARM_L:7,HAND_L:8,CLAVICLE_R:9,ARM_R:10,FOREARM_R:11,HAND_R:12,THIGH_L:13,SHIN_L:14,FOOT_L:15,TOE_L:16,THIGH_R:17,SHIN_R:18,FOOT_R:19,TOE_R:20},En=Object.keys(K).length,Dn=[-1,0,1,2,3,2,5,6,7,2,9,10,11,0,13,14,15,0,17,18,19],On=[[0,.98,0],[0,.12,0],[0,.2,0],[0,.22,0],[0,.1,0],[-.04,.17,0],[-.15,0,0],[-.03,-.29,0],[0,-.26,0],[.04,.17,0],[.15,0,0],[.03,-.29,0],[0,-.26,0],[-.1,-.05,0],[0,-.44,0],[0,-.43,0],[0,-.04,-.13],[.1,-.05,0],[0,-.44,0],[0,-.43,0],[0,-.04,-.13]],kn=[0,0,0,1],An=(e=[0,0,0],t=0)=>({at:e,yaw:t,hips:[0,0,0],rot:Array.from({length:En},()=>[...kn])}),q=([e,t,n,r],[i,a,o,s])=>[r*i+e*s+t*o-n*a,r*a-e*o+t*s+n*i,r*o+e*a-t*i+n*s,r*s-e*i-t*a-n*o],J=([e,t,n],r)=>{let i=Math.sin(r/2);return[e*i,t*i,n*i,Math.cos(r/2)]},jn=(e,[t,n,r])=>{let[i,a,o,s]=e,[c,l,u]=[2*(a*r-o*n),2*(o*t-i*r),2*(i*n-a*t)];return[t+s*c+a*u-o*l,n+s*l+o*c-i*u,r+s*u+i*l-a*c]},Mn=(e,t,n)=>{let r=e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],i=r<0?-1:1;if(r*=i,r>.9995){let r=e.map((e,r)=>e+(i*t[r]-e)*n),a=Math.hypot(...r);return r.map(e=>e/a)}let a=Math.acos(r),[o,s]=[Math.sin((1-n)*a),Math.sin(n*a)*i],c=1/Math.sin(a);return e.map((e,n)=>(e*o+t[n]*s)*c)},Nn=e=>{let t=[],n=[],r=J([0,1,0],e.yaw);for(let i=0;i<En;i++){let a=Dn[i],o=a<0?r:n[a];n[i]=q(o,e.rot[i]);let s=jn(o,i===0?On[0].map((t,n)=>t+e.hips[n]):On[i]),c=a<0?e.at:t[a];t[i]=[c[0]+s[0],c[1]+s[1],c[2]+s[2]]}return{pos:t,rot:n}},Pn=(e,t,n,r,i)=>{let a=e[t]-n,o=e[t+1]+r*a,s=Math.exp(-r*i);return e[t]=n+(a+o*i)*s,e[t+1]=(e[t+1]-r*o*i)*s,e[t]},Fn=Math.PI*2,[Y,In,Ln]=[[1,0,0],[0,1,0],[0,0,1]],[Rn,zn,Bn]=[.44,.43,.06],[Vn,Hn]=[.2915,.26],Un=Rn+zn,X=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Wn=e=>(e=X(e))*e*(3-2*e),Gn=(e,t)=>Math.atan2(Math.sin(t-e),Math.cos(t-e)),Kn=e=>[-e[0],-e[1],-e[2],e[3]],qn=(e,t)=>{let n=Math.sin(e*78.233+t*37.719)*43758.5453;return n-Math.floor(n)},Jn=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],Yn=(e,t,n,r=0)=>e.map((e,i)=>e*t+n[i]*r),Xn=e=>Yn(e,1/(Math.hypot(...e)||1),e),Zn=(e,t)=>Yn(e,1,t,-(e[0]*t[0]+e[1]*t[1]+e[2]*t[2])),Qn=(e,t,n)=>{let r=Math.max(n-Math.abs(e-t),0)/n;return Math.min(e,t)-r*r*n/4},$n=(e,t)=>{let n=[-t[0],-t[1],-t[2]],r=Jn(e,n),i=[e[0]+n[1]+r[2],e[0]-n[1]-r[2],n[1]-e[0]-r[2],r[2]-e[0]-n[1]],a=i.indexOf(Math.max(...i)),[o,s,c,l]=[1+i[a],n[2]-r[1],r[0]-e[2],e[1]-n[0]],[u,d,f]=[n[0]+e[1],r[0]+e[2],r[1]+n[2]],p=[[s,c,l,o],[o,u,d,s],[u,o,f,c],[d,f,o,l]][a],m=Math.hypot(...p);return p.map(e=>e/m)},er=(e,t,n,r=Rn,i=zn,a=1)=>{let o=Yn(t,1,e,-1),s=Math.hypot(...o)||1e-6,c=X(s,.2,(r+i)*.999),l=Yn(o,1/s,o),u=Xn(Zn(n,l)),d=X((r*r+c*c-i*i)/(2*r*c),-1,1),f=Yn(l,d,u,Math.sqrt(1-d*d)),p=Xn(Yn(l,c,f,-r)),m=Yn(Jn(l,u),a,l);return[$n(m,f),$n(m,p)]},tr=e=>{let[t,n]=[Math.abs(e),e>0?.07:.13],[r,i]=[Math.sin(t),Math.cos(t)];return[(e>0?-1:1)*(n*(1-i)+Bn*r),Bn*(i-1)+n*r]},nr=[1.4,5,9],rr={f:[.95,1.4,1.8],s:[.88,.95,1],k:[.45,.42,.4],lat:[.11,.09,.07],lift:[.09,.3,.4],d0:[.002,.01,.01],d1:[.008,.075,.05],td:[.12,.1,-.12],to:[-.45,-.6,-.8],pr:[.07,.1,.14],po:[.06,.06,.05],pt:[.04,.1,.16],pa:[.02,.05,.06],cc:[.1,.16,.22],aa:[.35,.8,1],am:[-.05,.12,.25],em:[.3,1.4,1.75],ea:[.12,.25,.3],ab:[.1,.12,.1],sw:[.025,.012,.008],hop:[0,.02,.025]},Z={AIR:0,RISE:1,DASH:2,WALL_L:3,WALL_R:4,HANG:5,CLIMB:6,SLIDE:7,STUN:8,TUCK:9,DOWN:10},ir=[[-.05,.12,0,.35,.5,.15,.7,.25,.5,.25,.5,1.15,0,0],[0,.1,0,1.2,1.5,-.35,.3,2.4,.3,2.2,.3,.35,0,0],[-.35,1.25,0,1.1,1.3,-.6,.25,-1,.3,-1,.3,.25,0,0],[],[-.02,.2,.4,.9,1.2,.6,1.3,.8,1,.3,.5,.6,0,.1],[.07,.05,0,.2,.3,.1,.2,3,.2,3,.2,.2,-.22,0],[0,.5,0,.2,.4,1.4,1.7,1,1.4,1,1.4,.15,-.1,0],[-.78,-1.1,0,1.1,1.8,1.4,.1,.5,.8,.4,.5,.8,0,0],[0,0,0,0,0,0,0,.8,1.6,.8,1.6,.2,0,0],[-.05,.9,0,1.7,2,1.7,2,.8,1.6,.8,1.6,.2,0,0],[-.5,.35,0,1.3,.3,1.1,.2,.4,.4,.2,.3,.6,0,0]],ar=ir[Z.WALL_R];ir[Z.WALL_L]=[ar[0],ar[1],-ar[2],ar[5],ar[6],ar[3],ar[4],ar[9],ar[10],ar[7],ar[8],ar[11],ar[12],-ar[13]];var or=[K.PELVIS,K.SPINE,K.CHEST,K.ARM_L,K.FOREARM_L,K.ARM_R,K.FOREARM_R,K.THIGH_L,K.SHIN_L,K.FOOT_L,K.TOE_L,K.THIGH_R,K.SHIN_R,K.FOOT_R,K.TOE_R],sr=e=>{let t=[],[n,r,i]=[e[1],e[2],e[11]];return t[K.PELVIS]=q(J(Ln,r*.4),J(Y,-.3*n)),t[K.SPINE]=q(J(Ln,r*.3),J(Y,-.35*n)),t[K.CHEST]=t[K.SPINE],t[K.ARM_L]=q(J(Ln,-i),J(Y,e[7])),t[K.FOREARM_L]=J(Y,e[8]),t[K.ARM_R]=q(J(Ln,i),J(Y,e[9])),t[K.FOREARM_R]=J(Y,e[10]),[K.THIGH_L,K.THIGH_R].forEach((r,i)=>{t[r]=J(Y,e[3+2*i]+.3*n),t[r+1]=J(Y,-e[4+2*i]),t[r+2]=J(Y,-.35),t[r+3]=cr}),t},cr=[0,0,0,1],lr=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],[ur,dr,fr,pr,mr,hr,gr,_r,vr,yr,br,xr]=[0,2,4,6,8,10,12,14,16,18,20,22],Sr=5,Cr=.1,wr=()=>{let e=An(),t={},n=Array(xr+2*ir.length).fill(0),r=[0,1].map(()=>({x:0,y:0,z:0,px:0,pz:0,gy:0,lx:0,ly:0,lz:0,dl:0,tg:0,u:0,x0:0,w:0,th:0,tw:1,on:!0})),i={},a=!1,[o,s,c,l,u,d,f]=[0,0,0,0,0,0,0],[p,m,h,_,v]=[0,0,0,.6,0],[y,b,x,S]=[!1,!0,!0,-1],C=[1,1,1,0,.06,0],[w,T,E]=[0,0,[0,0,0]],[D,O,k,A]=[1,[1,0],[0,0,0,-1,0],!1],j=(e,j,M)=>{j=X(j,0,.1),b=!a||Math.hypot(e.x-i.x,e.y-i.y,e.z-i.z)>Sr;let ee=e.mode==g.GROUND||e.mode==g.CROUCH,N=e.mode==g.AIR,P=(e,t,r)=>{b?[n[e],n[e+1]]=[t,0]:Pn(n,e,t,r,j)};P(hr,e.vx,12),P(gr,e.vz,12);let[F,I]=[n[hr],n[gr]];l=Math.sqrt(F*F+I*I);let L=l>1?Math.atan2(-F,-I):e.yaw;if(b){let t=e.id;C=[1+.08*(qn(t,0)-.5),1+.16*(qn(t,1)-.5),1+.16*(qn(t,2)-.5),.03*(qn(t,3)-.5),.05+.04*qn(t,4),qn(t,6)],o=l>.25?qn(t,5):qn(t,5)<.5?.05:.55,[s,c,h,p,m,y,S]=[0,0,0,0,0,!1,-1],f=L,d=e.yaw}else N&&i.mode==g.AIR&&e.jumps<i.jumps&&e.vy>i.vy&&(h=.001),N?m=Math.min(m,e.vy):(i.mode==g.AIR&&(ee||e.mode==g.SLIDE)&&m<-3&&(p=X(-m/12,.3)),m=0),h&&=(h+=j*(N?2.2:8),h>=1?0:h);c+=j,p*=Math.exp(-j*7);let R=lr[e.wall],z=e.mode==g.WALLRUN,te=e.mode==g.HANG||e.mode==g.CLIMB;z&&([D,O]=[R[0]*Math.cos(L)-R[1]*Math.sin(L)<0?-1:1,R]),te&&e.wall&&(d=Math.atan2(-R[0],-R[1]),e.mode!=g.HANG&&A||(k=[e.x,e.z,R[0],R[1],0]),k[4]=e.edge),A=te,[N,N&&e.vy>.5,e.dash>50,z&&D<0,z&&D>0,e.mode==g.HANG,e.mode==g.CLIMB,e.mode==g.SLIDE,e.stun>0,h&&Math.sqrt(Math.sin(Math.PI*h))].forEach((e,t)=>P(xr+2*t,+e,12)),P(xr+2*Z.DOWN,+(e.down>0),5),P(mr,+(e.mode==g.CROUCH),12),P(vr,te?X((1.7-k[4]+e.y)/1.2):0,14),P(pr,p,26);let ne=b||l<2?0:Gn(f,L)/Math.max(j,.001);f=L;let re=b?0:-((e.vx-i.vx)*Math.sin(u)+(e.vz-i.vz)*Math.cos(u))/Math.max(j,.001),ie=-(F*Math.sin(u)+I*Math.cos(u)),B=Math.sign(ie)*X((Math.abs(ie)-1.5)*.028,0,.22);P(ur,(ie>0?B:B/2)+X(re*.012,-.3,.3),7),P(dr,X(.3*Math.atan(l*ne/9.8),-.4,.4),8),P(fr,.5*Math.sin(Gn(e.yaw,L))*X(l/2),10);let V=e=>n[xr+2*e],ae=X(V(Z.DASH)+V(Z.WALL_L)+V(Z.WALL_R)+V(Z.SLIDE)),oe=e.yaw+Gn(e.yaw,L)*ae;u=oe+Gn(oe,d)*X(V(Z.HANG)+V(Z.CLIMB)),u+=n[fr]*(1-ae);let[se,ce]=[Math.cos(u),Math.sin(u)];P(yr,e.stun>0?X(-(e.vx*ce+e.vz*se)/4.2,-1,1):0,18),P(br,e.stun>0?X((e.vx*se-e.vz*ce)/4.2,-1,1):0,18),[w,T,E]=[e.yaw,e.pitch,[e.x,e.y,e.z]];let le=l<nr[1]?0:1,H=X((l-nr[le])/(nr[le+1]-nr[le]));for(let e in rr){let n=rr[e];t[e]=n[le]+(n[le+1]-n[le])*H}v=Wn((l-.2)/1.2);let ue=t.f*C[0]*(.35+.65*X(l/1.4))*(1+.5*V(Z.STUN));_=X(t.s*ue/Math.max(l,.1),.2,.62);let[de,U]=[Math.cos(u),-Math.sin(u)],fe=(t,n)=>{let r=M?M(t,n):e.y;return Math.abs(r-e.y)<.6?r:e.y},pe=l<=.25,me=ee&&(!pe||!r[0].on||!r[1].on);(me||z)&&(o=(o+(pe&&!z?.9:ue)*j)%1),r.forEach((n,a)=>{let c=a?1:-1,l=(o+a/2)%1,[d,f]=[e.x+de*c*Cr,e.z+U*c*Cr],p=u-c*C[4],[m,h]=[-Math.sin(p),-Math.cos(p)];if(ee){if(y||([n.px,n.pz,n.gy,n.on]=[d,f,fe(d,f),!0],b&&([n.x,n.y,n.z,n.th,n.tw]=[d,n.gy+Bn,f,0,1])),n.on&&me&&(l>=_||Math.hypot(n.x-d,n.z-f)>.56))[n.on,n.lx,n.ly,n.lz,n.dl]=[!1,n.x-e.x,n.y,n.z-e.z,l];else if(!n.on&&l<n.u){let[e]=tr(t.td*v);[n.on,n.px,n.pz,n.gy]=[!0,n.x-m*e,n.z-h*e,n.tg],s++}if(n.u=l,n.on){if(pe&&r[0].on&&r[1].on){let e=1-Math.exp(-8*j);n.px+=(d-n.px)*e,n.pz+=(f-n.pz)*e,n.gy+=(fe(d,f)-n.gy)*e}n.x0=X(l/_),n.th=v*(t.td*(1-Wn(n.x0/.25))+t.to*Wn((n.x0-.55)/.45));let[e,i]=tr(n.th);[n.x,n.y,n.z]=[n.px+m*e,n.gy+Bn+i,n.pz+h*e],n.w=1-v*(1-Wn(Math.min(n.x0,1-n.x0)/.12)),n.tw=Wn(n.x0*10)}else{let r=X((l-n.dl)/(1-n.dl+1e-6)),[i,a]=[t.k*_/ue,(1-l)/ue+t.k*_/ue],[o,s]=[F*i+de*c*t.lat,I*i+U*c*t.lat];n.tg=fe(e.x+F*a+de*c*t.lat,e.z+I*a+U*c*t.lat);let[u,d]=[t.td*v,t.to*v],f=Wn((r-.12)/.78);n.x=e.x+n.lx+(o-n.lx)*f,n.z=e.z+n.lz+(s-n.lz)*f,n.y=n.ly+(n.tg+Bn+tr(u)[1]-n.ly)*Wn(r*1.5)+t.lift*Math.sin(Math.PI*r**.6),n.th=d+(u-d)*Wn(r)+.15*Math.sin(Math.PI*r),n.tw=1-Wn(r*4),n.w=0}}else{let t=b?0:Math.exp(-10*j),r=b?[0,0,0]:[n.x-i.x,n.y-i.y,n.z-i.z];n.x=e.x+r[0]*t+(d-e.x)*(1-t),n.y=e.y+r[1]*t+Bn*(1-t),n.z=e.z+r[2]*t+(f-e.z)*(1-t),[n.th,n.tw,n.w,n.on,n.u]=[n.th*t,n.tw*t,0,!1,l]}}),y=ee,x=!0,Object.assign(i,e),a=!0},M=()=>{let t=e=>n[xr+2*e],{rot:r}=e,[i,a]=[Math.cos(u),Math.sin(u)],s=(e,t,n,r=E)=>[r[0]+e*i+n*a,t,r[2]+n*i-e*a],c=(e,t,n)=>s(e,t,n,[0,0,0]),l=[],{pos:d,rot:f}=Nn(e),p=d[K.PELVIS],m=e=>e<0?K.HAND_L:K.HAND_R,h=e=>e<0?K.FOOT_L:K.FOOT_R,g=q(J(In,u),J(Y,-.2)),_=X(t(Z.HANG)+t(Z.CLIMB));if(_>.002){let[r,i,a,o,s]=k,u=.4+.14*n[vr],f=[-1,1].map(e=>{let t=d[m(e)-2],n=Math.max(u,(t[0]-r)*a+(t[2]-i)*o),c=[r+a*n-o*e*.21,s+.03,i+o*n+a*e*.21],l=(t[0]-c[0])**2+(t[2]-c[2])**2;return[c,t[1]-c[1]-Math.sqrt(Math.max(((Vn+Hn)*.97)**2-l,0))]}),g=_**4*X(Math.max(...f.map(e=>e[1])));e.at[1]-=g,d.forEach(e=>e[1]-=g),[-1,1].forEach((e,t)=>l.push([m(e),_,f[t][0],c(e*.8,0,.6),$n([0,e,0],[a,0,o])]));let v=(p[0]-r)*a+(p[2]-i)*o,y=Math.max(.58,v+.45);[-1,1].forEach(e=>l.push([h(e),t(Z.CLIMB)*X(e<0?(v-.25)*4:n[vr]*2-.4),[r+a*y-o*e*.1,s+Bn,i+o*y+a*e*.1],[a,.5,o],$n([-o,0,a],[0,-1,0])]))}[-1,1].forEach(e=>{let n=t(e<0?Z.WALL_L:Z.WALL_R);if(n>.002){let[t,r]=O;[e,-e].forEach((i,a)=>{let d=(o+.5*a)%1,f=d<.55,_=f?d/.55:(d-.55)/.45,v=f?0:Math.sin(Math.PI*_),y=(f?2*_-1:1-2*Wn(_))*(a?.4:.3);l.push([h(i),n,a?s(-e*.12,p[1]-.7+.4*v,y):s(e*(.34-.2*v),p[1]-.52+.3*v,y),c(-e*.7,1,-1),a?q(J(In,u),J(Y,-.5)):Mn(g,$n(Jn([t,0,r],c(0,0,-1)),[t,0,r]),1-v)]);let b=Math.cos(Fn*(o+.5*(1-a)));l.push([m(i),n,a?s(-e*.5,p[1]+.3+.12*b,.2*b):s(e*.37,p[1]+.3+.05*b,.1*b),c(a?-e*.7:0,a?0:-.5,.7),$n(a?[0,i,0]:[-i*t,0,-i*r],c(0,0,-1))])})}});let v=t(Z.SLIDE);if(v>.002){let e=E[1];l.push([K.FOOT_R,v,s(.12,e+Bn+.14,-.85,p),c(.1,1,-.3),g],[K.FOOT_L,v,s(-.2,e+Bn,-.3,p),c(-.4,1,-.1),g],[K.HAND_L,v,s(-.4,e+.03,.4,p),c(-.7,0,.7),$n([0,-1,0],c(-1,0,0))])}l.forEach(([e,t,n,i,a])=>{let[o,s,c]=[e-2,e<K.THIGH_L,t*t],l=Yn(Yn(d[o+1],1,d[o],-1),1,jn(f[o],[0,0,s?1:-1]),.05),[u,p]=[Yn(d[e],1-c,n,c),e=>Xn(Yn(e,1,d[o],-1))],m=Yn(Xn(Zn(l,p(d[e]))),1-c,Xn(Zn(i,p(n))),c),[h,g]=s?er(d[o],u,m,Vn,Hn,-1):er(d[o],u,m),_=s?q(h,J(Ln,o==K.ARM_L?.1:-.1)):h;r[o]=q(Kn(f[Dn[o]]),_),r[o+1]=q(Kn(_),g),r[e]=Mn(r[e],q(Kn(g),a),c)})},ee=()=>{let{rot:i}=e,a=v,s=e=>n[xr+2*e],[l,d,f,p,m]=[n[ur],n[dr],n[fr],n[pr],n[mr]],[g,y]=[Math.cos(Fn*o),Math.cos(2*Fn*o)],b=Math.cos(Fn*(o-(1+_)/2)),D=t.po*a*b,O=t.pt+C[3]+t.pa*a*y,k=(t.cc+t.pr)*a*g,A=1-a,j=A*.012*Math.sin(Fn*.28*c),ee=A*.012*Math.sin(Fn*.17*c+C[1]*9),N=t.sw*a*b+ee;e.at[0]=E[0],e.at[1]=E[1],e.at[2]=E[2],e.yaw=u,i[K.PELVIS]=q(q(J(In,-t.pr*a*g),J(Ln,D+.4*d)),J(Y,-(O+.25*l+.3*m+.5*p)));let P=O+.25*l-l-.7*m-.8*p;i[K.SPINE]=q(q(J(In,.4*k-.25*f),J(Ln,.25*d-.8*D+.5*ee)),J(Y,.45*P+j*.5)),i[K.CHEST]=q(q(J(In,.6*k-.25*f),J(Ln,.25*d-.8*D-.5*ee)),J(Y,.55*P+j)),[-1,1].forEach(e=>{let n=Math.cos(Fn*(o-(e<0?.5:0))),r=C[e<0?1:2];i[e<0?K.ARM_L:K.ARM_R]=q(J(Ln,e*(.06+t.ab*a+.5*p)),J(Y,(t.am+t.aa*r*n)*a+.05*A*e*Math.sin(c*1.3)+p+.5*m)),i[e<0?K.FOREARM_L:K.FOREARM_R]=J(Y,.15*A+a*(t.em+t.ea*n)+p+.5*m)});let F=J(In,u),I=q(F,i[K.PELVIS]),[L,R]=[Math.cos(u),-Math.sin(u)],z=[E[0]+L*N,0,E[2]+R*N],te=[K.THIGH_L,K.THIGH_R].map(e=>jn(I,On[e])),ne=1-.25*m-.7*p,re=E[1]+.05+Bn+Un*(ne-t.d0-.6*t.d1*a)+t.hop*a*(.5-.5*Math.cos(2*Fn*o-2*Fn*_/2)),ie=r.map((e,n)=>{let[r,i]=[e.x-z[0]-te[n][0],e.z-z[2]-te[n][2]],o=t.d0+t.d1*a*Math.sin(Math.PI*e.x0)+1-ne,s=Math.min(Un*(1-o),Un*.99),c=e.y+Math.sqrt(Math.max(s*s-r*r-i*i,.04));return re+(c-te[n][1]-re)*e.w}),B=Qn(ie[0],ie[1],.05),V=c-S;S=c,V>.1?[n[_r],n[_r+1]]=[B,0]:Pn(n,_r,B,30,V),z[1]=Math.min(B,n[_r]),e.hips=[N,z[1]-E[1]-On[0][1],0],r.forEach((e,t)=>{let n=t?1:-1,r=[z[0]+te[t][0],z[1]+te[t][1],z[2]+te[t][2]],a=u-n*C[4],[o,s]=er(r,[e.x,e.y,e.z],[-Math.sin(a),0,-Math.cos(a)]),c=t?K.THIGH_R:K.THIGH_L;i[c]=q(Kn(I),o),i[c+1]=q(Kn(o),s),i[c+2]=q(Kn(s),q(J(In,a),J(Y,e.th))),i[c+3]=J(Y,e.th<0?-e.th*e.tw:0)}),ir.forEach((t,n)=>{let r=s(n);if(r>.002){let a=sr(t),o=n==Z.STUN;or.slice(o?3:0,o?7:15).forEach(e=>i[e]=Mn(i[e],a[e],r)),o||[t[13],t[0],t[12]].forEach((t,n)=>e.hips[n]+=(t-e.hips[n])*r)}}),h&&(i[K.PELVIS]=q(J(Y,-Fn*(3-2*h)*h*h),i[K.PELVIS]));let ae=s(Z.HANG);if(ae>.002){let[t,n]=[.01*Math.sin(Fn*(.3*c+C[5])),.006*Math.sin(Fn*(.2*c+3*C[5]))].map(e=>e*ae);i[K.PELVIS]=q(q(J(Ln,n),J(Y,t)),i[K.PELVIS]),[K.THIGH_L,K.THIGH_R].forEach(e=>i[e]=q(i[e],J(Y,t))),e.hips[0]+=n,e.hips[2]-=t}let oe=s(Z.STUN);if(oe){[K.SPINE,K.CHEST].forEach((e,t)=>{let r=.3+.1*t;i[e]=q(i[e],q(J(Ln,-r*n[br]),J(Y,-r*n[yr])))});let e=Math.sin(c*13);[K.ARM_L,K.ARM_R].forEach((t,n)=>i[t]=q(i[t],J(Y,oe*(n?e:-e)))),i[K.CHEST]=q(i[K.CHEST],J(In,.3*oe*Math.sin(c*8)))}M();let se=Wn((s(Z.DOWN)-.35)/.65);se&&(i[K.PELVIS]=q(J(Y,-1.45*se),i[K.PELVIS]),e.hips[1]+=(.17-On[0][1]-e.hips[1])*se,[K.THIGH_L,K.THIGH_R].forEach(e=>i[e]=q(i[e],J(Y,-1.25*se))),[K.ARM_L,K.ARM_R].forEach(e=>i[e]=q(i[e],J(Y,-.5*se))));let ce=q(q(F,i[K.PELVIS]),q(i[K.SPINE],i[K.CHEST])),le=q(J(In,w),J(Y,X(T,-1,1)*.9)),H=q(Kn(ce),Mn(ce,le,.85*(1-s(Z.TUCK))*(1-.5*oe)*(1-s(Z.DOWN))));return i[K.NECK]=Mn([0,0,0,1],H,.4),i[K.HEAD]=q(Kn(i[K.NECK]),H),x=!1,e};return{update:j,pose:()=>x?ee():e,get phase(){return o},get steps(){return s}}},Tr=e=>Math.sign(e)*Math.abs(e)**.8,Er=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),Dr=e=>Math.min(Math.max(e,0),1),Or=(e,t,n,r)=>{let i=[],a=[],o=[],s=t.map(([e,r,o,s,c=0],l)=>{let[u,d]=[t[Math.max(l-1,0)],t[Math.min(l+1,t.length-1)]],f=Math.hypot(d[0]-u[0],d[1]-u[1])||1,[p,m]=[(d[0]-u[0])/f,(d[1]-u[1])/f];return Array.from({length:o?n:1},(t,l)=>{let[u,d]=[Tr(Math.cos(l*V/n)),Tr(Math.sin(l*V/n))];return i.push([c+o*u,r+s*d*p,-(e-s*d*m)]),a.push([0,0,0]),i.length-1})});s.slice(1).forEach((e,r)=>{let c=s[r],l=[(t[r][4]??0)+(t[r+1][4]??0),t[r][1]+t[r+1][1],-t[r][0]-t[r+1][0]];for(let t=0;t<n;t++){let[n,r,s,u]=[c[t%c.length],c[(t+1)%c.length],e[(t+1)%e.length],e[t%e.length]];for(let e of[[n,r,s],[n,s,u]]){if(new Set(e).size<3)continue;let[t,n]=[1,2].map(t=>[0,1,2].map(n=>i[e[t]][n]-i[e[0]][n])),r=[t[1]*n[2]-t[2]*n[1],t[2]*n[0]-t[0]*n[2],t[0]*n[1]-t[1]*n[0]],s=[0,1,2].reduce((t,n)=>t+r[n]*(i[e[0]][n]*2-l[n]),0)<0;o.push(...s?[e[0],e[2],e[1]]:e);for(let t of e)[0,1,2].forEach(e=>a[t][e]+=s?-r[e]:r[e])}}});for(let t of o){let n=Math.hypot(...a[t])||1,o=a[t].map(e=>e/n);e.push(...i[t],...o,...r(i[t],o))}},kr=[.34,.12,.62],Ar=[.72,.46,1],jr=[.1,.38,.72],Mr=[.16,.06,.34],Nr=[.5,1.9,2.3],Pr=(e=0)=>(t,n)=>{let r=Er(Er(kr,jr,Dr(-t[2]*5-.3)*.8),Ar,Math.max(n[1],0)**1.5*.7),[i,a,,o]=Er([...r.slice(0,2),0,r[2]],[...Mr.slice(0,2),0,Mr[2]],Dr(-n[1]*.5+e));return[i,a,-1,o]},Fr=()=>[Nr[0],Nr[1],-2,Nr[2]],Ir=[0,.04,-.225],Lr=[Math.sin(.4),Math.cos(.4)],Rr=[[-.06,.095,0,0],[-.055,.098,.022,.022],[-.035,.103,.042,.036],[-.005,.104,.048,.04],[.035,.098,.044,.038],[.08,.088,.036,.034],[.12,.074,.028,.028],[.135,.066,0,0]],zr=[[-.05,-.02,0,0],[-.045,-.025,.018,.012],[-.025,-.052,.032,.018],[.01,-.066,.036,.02],[.06,-.06,.034,.02],[.11,-.042,.028,.018],[.16,-.012,.02,.014],[.2,.018,.012,.01],[.222,.032,0,0]],Br=[],Vr=e=>{if(Br[e])return Br[e];let t=e?8:5,n=[];Or(n,Rr,t,Pr()),Or(n,zr,t,Pr(.25)),Or(n,[[.03,.06,0,0],[.02,.046,.021,.022],[0,0,.021,.023],[-.02,-.046,.021,.022],[-.03,-.06,0,0]],t,Pr(.1)),Or(n,[[-.045,.136,0,0],[-.035,.139,.006,.007],[-.005,.144,.008,.009],[.035,.137,.008,.008],[.08,.123,.006,.007],[.1,.115,0,0]],e?6:4,Pr(-.3)),Or(n,[[-.03,.14,0,0],[-.04,.148,.005,.012],[-.062,.162,.004,.01],[-.085,.176,0,0]],4,Pr(.05)),Or(n,[[-.08,.173,0,0],[-.085,.175,.005,.005],[-.092,.18,0,0]],4,Fr);for(let r of[-1,1])Or(n,[[.06,.092,.018,.03,.026*r],[.1,.084,.017,.028,.027*r],[.15,.07,.015,.024,.024*r],[.19,.052,.012,.018,.019*r],[.222,.036,.008,.012,.015*r],[.232,.032,0,0,.014*r]],t,Pr(.05)),Or(n,Rr.slice(1,6).map(([e,t,n,i])=>[e,t-.1*i,.0035,.006,r*n*.93]),e?5:3,Fr),Or(n,zr.slice(1,7).map(([e,t,n,i])=>[e,t+.3*i,.0035,.005,r*n*.92]),e?5:3,Fr),Or(n,Rr.slice(1,5).map(([e,t,n,i])=>[e,t+.55*i,.007,.011,r*n*.86]),e?5:3,Pr(-.25));return Or(n,[[.09,.082,0,0],[.1,.082,.009,.009],[.15,.068,.009,.009],[.2,.05,.007,.007],[.21,.047,0,0]],t,Fr),Br[e]=n},Hr=e=>{let[t,n,r]=[jn(e,[0,0,-1]),jn(e,[1,0,0]),jn(e,[0,-1,0])],[i,a]=Lr;return[n,t.map((e,t)=>a*e-i*r[t]),t.map((e,t)=>i*e+a*r[t])]},Ur=(e,t)=>{let[n,r]=[jn(t,[0,-1,0]),jn(t,[1,0,0])];return e.map((e,t)=>e+n[t]*.078-r[t]*.022)},Wr=(e,t,n,r,i=1)=>Bt(e,Vr(r),Ur(t,n),Hr(n),[0,0,0],i),Gr=(e,[,t,n])=>[0,1,2].map(r=>e[r]+t[r]*Ir[1]-n[r]*Ir[2]),Kr=e=>{let t=Nt(e.yaw,e.pitch),n=[e.x,e.y+ve(e),e.z];return[[0,1,2].map(e=>n[e]+t[0][e]*.2-t[1][e]*.17+t[2][e]*.42),t]},qr=[.66,.45,.35],[Jr,Yr,Xr,Zr,Qr,$r,ei,ti,ni]=[0,1,2,3,4,5,6,7,8],ri=e=>[e,e.map(e=>e*.5),[.12,.13,.17],qr,[.09,.07,.06],[.74,.74,.77],[.93,.93,.94],[.26,.26,.3],[.03,.03,.04]],ii={chain:[K.PELVIS,K.SPINE,K.CHEST,K.NECK,K.HEAD],n:[8,8],e:2.3,far:[0,2,4,6,8,10,13],rings:[[.84,0,0,0,0,0,Xr],[.88,0,.005,.13,.09,0,Xr],[.94,0,.01,.187,.108,0,Xr],[.99,0,.005,.18,.106,.25,Yr],[1.03,0,0,.17,.102,.5,Jr],[1.12,0,0,.155,.097,1,Jr],[1.24,0,-.003,.176,.112,1.7,Jr],[1.35,0,-.005,.19,.126,2,Jr],[1.44,0,-.004,.2,.116,2,Jr],[1.485,0,0,.2,.098,2.05,Jr],[1.512,0,0,.125,.08,2.1,Jr],[1.532,0,0,.07,.068,2.25,Yr],[1.555,0,0,.06,.062,2.6,Zr],[1.6,0,0,.057,.059,3.5,Zr]]},ai={chain:[K.PELVIS,K.THIGH_R,K.SHIN_R,K.FOOT_R],n:[6,8],m:!0,far:[0,2,4,6,7,9],rings:[[1,.1,.01,0,0,0,Xr],[.9,.1,.006,.093,.098,.5,Xr],[.72,.1,-.002,.088,.09,1,Xr],[.55,.1,-.003,.066,.07,1.25,Xr],[.49,.1,-.004,.058,.064,1.5,Xr],[.42,.1,.002,.056,.064,1.8,Xr],[.33,.1,.012,.055,.068,2,Xr],[.19,.1,.003,.04,.047,2.05,Xr],[.09,.1,0,.036,.04,2.6,Xr],[.06,.1,0,0,0,3,Xr]]},oi={chain:[K.ARM_R,K.FOREARM_R,K.HAND_R],n:[5,7],m:!0,far:[0,2,4,6,7,9,11],rings:[[1.5,.19,0,0,0,0,Jr],[1.465,.192,0,.052,.056,0,Jr],[1.38,.198,0,.056,.058,.1,Jr],[1.27,.21,0,.049,.051,.3,Jr],[1.18,.22,0,.043,.046,.5,Jr],[1.09,.222,-.002,.046,.048,.8,Jr],[.975,.222,0,.034,.034,1.2,Yr],[.935,.222,0,.03,.03,1.8,ti],[.885,.222,-.004,.027,.037,2,ti],[.84,.222,-.008,.029,.042,2,ti],[.795,.222,-.012,.025,.034,2,ti],[.772,.222,-.014,0,0,2,ti]]},si={chain:[K.FOOT_R,K.TOE_R],n:[5,6],e:2.6,z:!0,m:!0,far:[0,1,3,5,7],rings:[[.095,.1,.05,0,0,0,$r],[.08,.1,.048,.032,.042,0,$r,130,ei],[.03,.1,.052,.042,.052,.05,$r,130,ei],[-.05,.1,.04,.045,.044,.3,$r,130,ei],[-.12,.1,.033,.047,.034,.6,$r,130,ei],[-.17,.1,.028,.042,.028,1,$r,130,ei],[-.205,.1,.024,.028,.02,1,$r,130,ei],[-.215,.1,.022,0,0,1,$r]]},ci={chain:[K.HEAD],n:[7,10],far:[0,1,3,5,6,7],rings:[[1.575,0,-.0075,.034,.0425,0,Zr],[1.6,0,-.0165,.058,.0665,0,Zr],[1.635,0,-.0085,.072,.0785,0,Zr,150,Qr],[1.675,0,-.001,.08,.089,0,Zr,-36,ni,110,Qr],[1.71,0,.0035,.083,.0935,0,Zr,72,Qr],[1.75,0,.0065,.08,.0885,0,Qr],[1.785,0,.011,.056,.061,0,Qr],[1.8,0,.015,0,0,0,Qr]]},li={chain:[K.HEAD],n:[0,5],z:!0,far:[],rings:[[-.075,0,1.675,.014,.034,0,Zr],[-.1,0,1.66,.012,.024,0,Zr],[-.115,0,1.649,0,0,0,Zr]]},ui=[ii,ai,oi,si,ci,li],di=(e,t)=>Math.sign(e)*Math.abs(e)**(2/t),fi=e=>{let[t,n,r,i,a]=[[],[],[],[],[]];for(let o of ui){let s=o.n[Math.min(e,1)];if(!s||e>1&&(o===ci||o===li))continue;let c=e>1&&o===ii?[...o.rings.slice(0,9),[1.455,0,0,0,0,2,Jr]]:e>1&&o===oi?[...o.rings.slice(0,7),[.95,.222,0,.037,.037,1.6,ti],[.925,.222,0,.027,.027,2,ti],[.91,.222,0,0,0,2,ti]]:e?o.rings:o.far.map(e=>o.rings[e]),l=c[c.length-1][0]>c[0][0];for(let e of o.m?[1,-1]:[1]){let u=t=>e<0&&t>K.HEAD?t-4:t,d=c.map(([i,a,c,l,d,f])=>{let p=Math.min(Math.floor(f),o.chain.length-2),m=[];for(let h=0;h<(l?s:1);h++){let g=h*2*Math.PI/s,[_,v]=[a+l*di(Math.sin(g),o.e??2),c+d*di(Math.cos(g),o.e??2)];t.push(e*_,...o.z?[v,i]:[i,-v],0,0,0),n.push(u(o.chain[Math.max(p,0)]),u(o.chain[p+1]??o.chain[0])),r.push(p<0||o.chain[p+1]===void 0?0:f-p),m.push(r.length-1)}return m});d.slice(1).forEach((t,n)=>{let r=d[n],[,,,,,,o,...u]=c[n];for(let n=0;n<s;n++){let[c,d,f,p]=[r[n%r.length],r[(n+1)%r.length],t[(n+1)%t.length],t[n%t.length]],m=Math.abs(((n+.5)/s*360+180)%360-180),h=u.findIndex((e,t)=>!(t%2)&&(e>0?m>e:m<-e));for(let t of[[c,d,f],[c,f,p]])new Set(t).size>2&&(i.push(...l===e<0?t:[t[0],t[2],t[1]]),a.push(h<0?o:u[h+1]))}})}}for(let e=0;e<i.length;e+=3){let[n,r,a]=[i[e],i[e+1],i[e+2]].map(e=>e*6),o=[0,1,2].map(e=>[t[r+e]-t[n+e],t[a+e]-t[n+e]]),s=[o[1][0]*o[2][1]-o[2][0]*o[1][1],o[2][0]*o[0][1]-o[0][0]*o[2][1],o[0][0]*o[1][1]-o[1][0]*o[0][1]];for(let e of[n,r,a])for(let n=0;n<3;n++)t[e+3+n]+=s[n]}for(let e=0;e<t.length;e+=6){let n=Math.hypot(t[e+3],t[e+4],t[e+5])||1;for(let r=3;r<6;r++)t[e+r]/=n}return{v:new Float32Array(t),j:new Uint8Array(n),w:new Float32Array(r),t:new Uint16Array(i),c:new Uint8Array(a)}},pi=[],mi=e=>pi[e]??=fi(e),hi=Nn(An()).pos,gi=new Float64Array(En*12),Q=/* @__PURE__ */ new Float32Array,_i=(e,t,{pos:n,rot:r},i)=>{for(let e=0;e<En;e++){let[t,i,a,o]=r[e],s=[1-2*(i*i+a*a),2*(t*i-a*o),2*(t*a+i*o),2*(t*i+a*o),1-2*(t*t+a*a),2*(i*a-t*o),2*(t*a-i*o),2*(i*a+t*o),1-2*(t*t+i*i)];for(let t=0;t<3;t++)gi.set(s.slice(t*3,t*3+3),e*12+t*3),gi[e*12+9+t]=n[e][t]-(s[t*3]*hi[e][0]+s[t*3+1]*hi[e][1]+s[t*3+2]*hi[e][2])}let a=t.w.length;Q.length<a*6&&(Q=new Float32Array(a*6));for(let e=0;e<a;e++){let[n,r,i,a]=[t.j[e*2]*12,t.j[e*2+1]*12,t.w[e],e*6];for(let e=0;e<6;e++){let[o,s]=[e%3*3,e<3?a:a+3],[c,l,u,d]=[t.v[s],t.v[s+1],t.v[s+2],+(e<3)];Q[a+e]=(1-i)*(gi[n+o]*c+gi[n+o+1]*l+gi[n+o+2]*u+d*gi[n+9+e%3])+i*(gi[r+o]*c+gi[r+o+1]*l+gi[r+o+2]*u+d*gi[r+9+e%3])}let o=Math.sqrt(Q[a+3]**2+Q[a+4]**2+Q[a+5]**2)||1;Q[a+3]/=o,Q[a+4]/=o,Q[a+5]/=o}for(let n=0;n<t.t.length;n+=3){let[r,a,o]=i[t.c[n/3]];for(let i=n;i<n+3;i++){let n=t.t[i]*6;e.push(Q[n],Q[n+1],Q[n+2],Q[n+3],Q[n+4],Q[n+5],r,a,-1,o)}}},vi=1,[yi,bi]=[.12,.03],[xi,Si]=[[1,0,0],[0,1,0]],Ci=[.7,-1,-.5],wi=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Ti=([e,t,n,r])=>[-e,-t,-n,r],Ei=(e,t)=>Math.hypot(...Ot(e,t)),Di=(e,t,n)=>kt(e,jt([0,0,0],t,n)),Oi=(e,t)=>{let[n,r]=[Mt(e),Mt(t)],i=[n[1]*r[2]-n[2]*r[1],n[2]*r[0]-n[0]*r[2],n[0]*r[1]-n[1]*r[0],1+At(n,r)],a=Math.hypot(...i)||1;return i.map(e=>e/a)},ki=(e,t,n,r,i)=>{let a=Ot(t,e),o=Mt(a),s=Math.max(Math.min(Math.hypot(...a),(r+i)*.99),.15),c=(r*r-i*i+s*s)/(2*s),l=Math.sqrt(Math.max(r*r-c*c,0)),u=Mt(Ot(n,jt([0,0,0],o,At(n,o))));return[Di(Di(e,o,c),u,l),Di(e,o,s)]},Ai=(e,t,n,r,i,a=!1)=>{let[o,s,c]=[t.pos[n],t.pos[n+1],t.pos[n+2]],[l,u]=ki(o,r,i,Ei(o,s),Ei(s,c)),d=q(Oi(Ot(s,o),Ot(l,o)),t.rot[n]),f=q(Oi(Ot(c,s),Ot(u,l)),t.rot[n+1]);e.rot[n]=q(Ti(t.rot[Dn[n]]),d),e.rot[n+1]=q(Ti(d),f),a&&(e.rot[n+2]=q(Ti(f),t.rot[n+2]))},ji=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],Mi=()=>zt(0,.04,[.0105,.0095],[1,2]),Ni=[1,1.1,1,.82],Pi=[[[.55,-.2,.8],[.2,-.75,.6]],[[.4,-.1,.9],[-.55,-.5,.65]]],Fi=(e,t,n,r,i,a,o)=>{let s=([e,a,o])=>[t[0]+i[0]*e+r[0]*a+n[0]*o,t[1]+i[1]*e+r[1]*a+n[1]*o,t[2]+i[2]*e+r[2]*a+n[2]*o],c=(t,n,r,a)=>n.reduce((t,n,c)=>{let l=[t[0]+n[0]*r,t[1]+n[1]*r,t[2]+n[2]*r];return Ht(e,Mi(),s(t),s(l),i,.04,a*.88**c,o),l},t);Bt(e,zt(1,0,[1,1]),t,[i,r,n],[0,0,.045],[.0425,.02,.058],o);for(let e=0;e<4;e++){let[t,n]=[.1+1.3*a,.2+3*a],r=-(e-1.5)*.08*(1-a),i=[t,n].map(e=>Mt([r,-Math.sin(e),Math.cos(e)]));c([.0315-.021*e,-.004,.092],i,.04*Ni[e],1)}c([.034,-.012,.025],Pi.map(([e,t])=>Mt(jt(e,t,a))),.037,1.25)},Ii=(e,t)=>(n,i)=>{let a=re(e,[n,t+r,i],[0,-1,0],2*r);return a>0&&a<1?t+r-a:t},Li={amp:8,sprint:6,air:12,rise:10,dash:14,plant:16,wall:10,slide:10,stun:14,gun:10},Ri=e=>{let t=wr(),n,r={amp:0,sprint:0,air:0,rise:0,dash:0,plant:0,wall:0,slide:0,stun:0,gun:0},[i,a,o]=[0,0,1.6],s=0,c=0,l,u=[0,0],d=(a,u,d=0,f=1.6)=>{if(i=d,o=f,!a){n=void 0;return}t.update(a,u,e&&Ii(e,a.y)),n={...a},s+=u;let p=a.mode==g.GROUND||a.mode==g.CROUCH||a.mode==g.WALLRUN,m=a.dash>50,h=a.mode==g.AIR&&!m,_={amp:p?wi(ye(a)/9):0,sprint:+be(a),air:+h,rise:+(h&&a.vy>.5),dash:+m,plant:+(a.mode==g.HANG||a.mode==g.CLIMB),wall:+(a.mode==g.WALLRUN),slide:+(a.mode==g.SLIDE),stun:+(a.stun>0),gun:+(a.ammo>=0&&!a.down)};for(let e of Object.keys(Li))r[e]+=(_[e]-r[e])*(1-Math.exp(-u*Li[e]));let[v,y]=ji[a.wall];c+=(wi(v*Math.cos(a.yaw)-y*Math.sin(a.yaw),-1,1)-c)*(1-Math.exp(-u*10)),_.plant&&a.edge&&(l={x:a.x,y:a.edge,z:a.z,dx:v,dz:y})},f=()=>{let e=r.amp*(1+.5*r.sprint),[n,a]=[Math.sin(V*t.phase),Math.cos(V*t.phase)],s=[Math.min(.27,.21*o)+.012*e*n,-.2+.018*e*a-.3*(1-r.gun),.5-.05*i];return[s,Vt(Mt([-s[0],.1*i-s[1],2.5-s[2]]),xi)]},p=(e,i,o,d=0)=>{if(!n||n.down||Ei(e,[n.x,n.y+ve(n),n.z])>vi)return;let p=t.pose(),m={at:[...p.at],yaw:p.yaw,hips:[...p.hips],rot:p.rot.map(e=>[...e])},[h,g,_]=Nt(i,o,d),v=([e,t,n])=>[h[0]*e+g[0]*t+_[0]*n,h[1]*e+g[1]*t+_[1]*n,h[2]*e+g[2]*t+_[2]*n],y=e=>[At(e,h),At(e,g),At(e,_)];for(let e of[K.SPINE,K.CHEST])m.rot[e]=q(m.rot[e],J(xi,.12*wi(o,-1.3,1.3)));let b=Nn(m),x=[-Math.sin(i),0,-Math.cos(i)],S=kt(b.pos[K.HEAD],jn(b.rot[K.HEAD],[0,.02,-.08]));m.at=kt(m.at,Ot(e,Di(S,[-x[0]*yi,-bi,-x[2]*yi],r.plant)));let C=Nn(m),w=[-Math.sin(m.yaw),0,-Math.cos(m.yaw)];for(let e of[K.THIGH_L,K.THIGH_R])Ai(m,C,e,b.pos[e+2],w,!0);let[T,E]=f(),D=[0,1,2].map(e=>Lr[1]*E[2][e]-Lr[0]*E[1][e]),O=[0,1,2].map(e=>T[e]-.078*D[e]+.022*E[0][e]);for(let n of[-1,1]){let i=Math.cos(V*t.phase)*n,o=r.amp*(1+.5*r.sprint),d=jt([.25,-.17,.36],[.2,-.14,.42],r.sprint);d=[d[0],d[1]+.07*o*i,d[2]+.12*o*i],n<0&&(d=jt(d,[-.2,-.65,.2],r.gun*(1-wi(r.amp*2.5)))),d=jt(d,[.38,-.2,.34],r.air),d=jt(d,[.3,.02,.45],r.rise),d=jt(d,[.14,-.1,.5],r.dash);let f=r.wall*wi(c*n);d=jt(d,[.42,-.16,.42],f),d=jt(d,n>0?[.36,-.26,.38]:[.28,-.1,.42],r.slide);let p=Math.sin(s*12+(n>0?Math.PI:0));if(d=jt(d,[.46,.05+.2*p,.4+.1*p],r.stun),l){let[t,i]=[-l.dz,l.dx];At([t,0,i],h)<0&&([t,i]=[-t,-i]);let a=.35000000000000003,[o,s,c]=y(Ot([l.x+l.dx*a+t*.12*n,l.y+.03,l.z+l.dz*a+i*.12*n],e));d=jt(d,[o*n,Math.max(s,-.28),Math.max(c,.4)],r.plant)}n>0&&(a=r.gun*(1-wi(r.plant+f+r.stun)),d=jt(d,O,a));let g=.75+.25*r.sprint;for(let[e,t]of[[.25,r.air],[.1,r.rise],[1,r.dash],[.1,f],[.1,r.slide],[.1,r.plant],[.2,r.stun]])g+=(e-g)*t;u[(n+1)/2]=n>0?g+(.9-g)*a:g;let _=kt(e,v([d[0]*n,d[1],d[2]])),b=n<0?K.ARM_L:K.ARM_R;if(Ai(m,C,b,_,v([Ci[0]*n,Ci[1],Ci[2]])),m.rot[b+2]=J(Si,n*(1+.5*(r.plant+r.slide))),n>0&&a>.002){let e=$n(v(E[0]),v(D));m.rot[b+2]=Mn(m.rot[b+2],q(Ti(Nn(m).rot[K.FOREARM_R]),e),a)}}return Nn(m)};return{get id(){return n?.id??-1},update:d,pose:p,draw(e,t,n,r,i=0,o=[.7,.7,.7]){let s=p(t,n,r,i);if(s){let t=ri(o);_i(e,mi(2),s,t),[K.HAND_L,K.HAND_R].forEach((n,r)=>{let i=s.rot[n];Fi(e,s.pos[n],jn(i,[0,-1,0]),jn(i,[r*2-1,0,0]),jn(i,[0,0,-1]),u[r],t[7])}),a>.2&&Wr(e,s.pos[K.HAND_R],s.rot[K.HAND_R],1,wi(a*1.5-.5))}},muzzle:()=>Gr(...f())}},zi=(e,t)=>e&&t?t.shots-e.shots&255:0,Bi=3,Vi=(e,t,r,i,a,o)=>{let s=0,c,l=!1,u=0,d=/* @__PURE__ */ new Map,p=()=>.94+.12*(u++*.618%1),m=e=>t.play(G.LASER,e,e?.7:.5,p());return{step(e,t){let r=zi(e,t);s+=r;for(let e=0;e<r;e++)o.pitch=Math.min(n,o.pitch+f),i.fire()},frame(n,o,u,f,p){if(a.update(p),o){let e=c;e&&o.hits!=e.hits&&(t.play(G.HIT),r.hit()),e&&o.hp<e.hp?(t.play(o.down&&!e.down?G.DOWN:G.HURT),i.wound()):e&&o.hp>e.hp&&!e.down&&t.play(G.PACK),e&&(e.ammo<0||o.ammo>e.ammo)&&o.ammo>=0&&t.play(G.GUN);let n=!!(f&h.FIRE);n&&!l&&o.ammo==0&&!o.down&&t.play(G.DRY),l=n,r.vitals(o.hp,o.ammo),r.down(i.lie,o.down/60),c={...o}}else c=void 0;if(n){let[t,r,i]=Nt(n.yaw,n.drawn),o=n.muzzle,c=[0,1,2].map(e=>n.cam[e]+t[e]*o[0]+r[e]*o[1]+i[e]*o[2]),l=Nt(n.yaw,n.pitch)[2],u=re(e,n.eye,l,80);for(a.mount(c);s>0;s--)a.shoot(c,[0,1,2].map(e=>n.eye[e]+l[e]*u),u<80,!0),m()}s=0;for(let t of u){let n=d.get(t.id),r=Math.min(n===void 0?0:t.shots-n&255,Bi),[i,o]=Kr(t),s=[t.x,t.y+ve(t),t.z];for(let t=0;t<r;t++){let t=re(e,s,o[2],80);a.shoot(Gr(i,o),[0,1,2].map(e=>s[e]+o[2][e]*t),t<80),m(s)}d.set(t.id,t.shots)}for(let e of d.keys())u.some(t=>t.id==e)||d.delete(e)}}},Hi=e=>.6+.2*e,Ui=e=>e?.mode===g.GROUND||e?.mode===g.CROUCH,Wi=e=>Ui(e)||e?.mode===g.WALLRUN,Gi=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],Ki=e=>.02+.0025*e,qi=.006,Ji=.03,Yi=.14,Xi=.05,Zi=5,Qi=9,$i=6.5,ea=.25,ta=.22,na=.9,ra=4,ia=1,aa=.12,oa=24,sa=15.7,ca=.45,la=[-8,4,5],ua=3,da=[-1,1.2],fa=4,pa=[-.25,.4,.5],ma=[-1.5,.8,1.5],ha=[.9,.3],ga=[.1,.05,11],_a=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),va=(e,t)=>{let n=Math.ceil(t*120);for(let r=0;r<n;r++)e[1]+=(-15.7*sa*e[0]-2*ca*sa*e[1])*(t/n),e[0]+=e[1]*(t/n)},ya=()=>{let e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0,c,l,u=[0,0],d=[0,0],f=[0,0],p={dy:0,pitch:0,roll:0,fov:0,lines:0,stride:0,hurt:0,kick:0,lie:0,fire(){s++,u[1]+=pa[0],d[1]+=pa[1],f[1]+=pa[2]*Math.sin(s*2.4),p.kick=1},wound(){u[1]+=ma[0],d[1]+=ma[1],f[1]+=ma[2]*Math.sin(s++),p.hurt=1},jolt(){u[1]+=la[0],d[1]+=la[1],f[1]+=la[2],p.hurt=1},punch(){u[1]+=da[0],d[1]+=da[1],a=1},update(s,m,_,y={ev:0,fall:0}){let b=e=>Math.min(1,_*e),x=s?ye(s):0,S=s&&l&&Wi(s)&&Wi(l)?Math.hypot(s.x-l.x,s.z-l.z):0;S<1&&(p.stride+=S/Hi(x)),e+=((Ui(s)&&S>.5*_&&S<1?1:0)-e)*b(10),l=s,y.ev&v.LAND&&(u[1]-=ta*Math.min(y.fall,20)),y.ev&v.CLIMB&&(u[1]-=ta*ra),y.ev&(v.JUMP|v.DOUBLE)&&(u[1]+=na),y.ev&v.GRAB&&(d[1]-=ia),va(u,_),va(d,_),va(f,_),p.hurt*=Math.exp(-_*ua),a*=Math.exp(-_*10),p.kick*=Math.exp(-_*22),p.lie+=(+!!s?.down-p.lie)*b(5),o+=_*ga[2];let C=s?Math.min(1,s.stun/48):0,w=s?ve(s):0;c=s?c===void 0?w:c+(w-c)*b(14):void 0,p.dy=(c??0)-w+u[0]-Math.cos(p.stride*2*Math.PI)*Ki(x)*e-p.lie*(w-ha[1]),i+=((s?.mode===g.CLIMB?aa*Math.sin(Math.PI*_a(s.t/oa)):0)-i)*b(10),p.pitch=d[0]+i+Math.sin(o*.8)*ga[1]*C;let T=s?.mode===g.WALLRUN?Gi[s.wall]:[0,0],E=s?T[0]*Math.cos(s.yaw)-T[1]*Math.sin(s.yaw):0,D=+!!(m&h.RIGHT)-!!(m&h.LEFT);t+=(D*Ji+E*Yi+(s?.mode===g.SLIDE?Xi:0)-t)*b(8),p.roll=t+Math.sin(p.stride*Math.PI)*qi*e+f[0]+Math.sin(o)*ga[0]*C+p.lie*ha[0];let O=!!s&&s.dash>50;n+=(+O-n)*b(O?40:6),r+=(_a((x-6)/3)-r)*b(4),p.fov=r*Zi+n*Qi+a*fa,p.lines+=(_a((x-$i)/(9-$i))*ea+n*.75-p.lines)*b(8)}};return p},ba=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),xa=e=>{let t=e.loop(G.WIND),n=e.loop(G.SCRAPE),r=0,i=/* @__PURE__ */ new Map,a=(t,n,r)=>{let i=be(t);e.play(t.mode===g.WALLRUN?G.WALLSTEP:G.STEP,r,i||t.mode===g.WALLRUN?1:t.mode===g.CROUCH?.35:.6,(i?.92:1)*(n&1?1.06:.94))},o=(t,n)=>e.play(G.LAND,n,ba(t/14,.2),1.25-.5*ba(t/20));return{me(i,s,c){let l=Math.floor(c),u=l>r;if(r=l,!i||e.muted)return;u&&a(i,l);for(let[t,n]of[[v.JUMP,G.JUMP],[v.DOUBLE,G.DOUBLE],[v.DASH,G.DASH],[v.GRAB,G.GRAB],[v.CLIMB,G.SCUFF]])s.ev&t&&e.play(n);s.ev&v.LAND&&o(s.fall);let d=ba((Math.hypot(i.vx,i.vy,i.vz)-4)/12);t.set(.55*d**1.5,.6+.9*d);let f=ba(ye(i)/9);n.set(i.mode===g.SLIDE?.2+.5*f:0,.8+.4*f)},others(t){for(let n of t){let t=i.get(n.id);if(t&&!e.muted){let e=[n.x,n.y+.1,n.z],r=Math.hypot(n.x-t.p.x,n.z-t.p.z);if(Wi(n)&&Wi(t.p)&&r<1){let i=Math.floor(t.stride);t.stride+=r/Hi(ye(n)),Math.floor(t.stride)>i&&a(n,i,e)}n.ground&&!t.p.ground&&t.p.vy<-3&&o(-t.p.vy,e)}i.set(n.id,{p:n,stride:t?.stride??0})}for(let e of i.keys())t.some(t=>t.id===e)||i.delete(e)}}},Sa=`h5,aside,nav,output,section,em,u,ul,dl,s,mark{position:absolute;margin:0;padding:0;pointer-events:none;user-select:none;white-space:pre-line}h5{top:8px;right:12px;font-size:12px}u{inset:0;opacity:0;background:radial-gradient(ellipse at center,#0000 35%,#d10000dd 120%)}nav{top:8px;left:50%;transform:translateX(-50%);display:grid;grid-template-columns:1fr auto 1fr;gap:2px 16px;align-items:center;text-align:center;font-size:13px}nav span,nav time{font:900 clamp(16px,4.6vw,24px)/1 system-ui,sans-serif;letter-spacing:.03em;white-space:nowrap}nav time{min-width:4.2ch;font-variant-numeric:tabular-nums;font-size:clamp(14px,3.8vw,20px)}nav small{font-size:clamp(10px,2.6vw,12px);white-space:nowrap;opacity:.95}nav small:first-of-type{text-align:right}nav small:last-of-type{text-align:left}output{top:20%;left:50%;transform:translateX(-50%);padding:6px 18px;font:900 clamp(18px,3.4vw,30px)/1.1 system-ui,sans-serif;letter-spacing:.06em;text-transform:uppercase;white-space:nowrap;background:#000a;border-bottom:3px solid currentColor}em{font-style:normal;font-size:13px;font-weight:800;line-height:1.1;text-align:center;transform:translate(-50%,-50%)}em span{display:block;font-size:20px;line-height:1}section{inset:0;z-index:2;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:0 12px;text-align:center;background:#000c}section h6{font:900 clamp(30px,9vw,72px)/1 system-ui,sans-serif;letter-spacing:.04em}section strong{font-size:34px}section td:first-child{text-align:left;opacity:1}section td+td{text-align:center}section th{padding:2px 10px;font-size:12px;opacity:.7;font-weight:600}aside{inset:0;z-index:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;padding:0 12px;text-align:center;background:#000b}h6{margin:0;font-size:inherit;text-shadow:none}aside h6{font:900 clamp(36px,13vw,84px)/1 system-ui,sans-serif;letter-spacing:.04em;transform:skewX(-8deg);background:linear-gradient(#fe6,#f92 45%,#d21);-webkit-background-clip:text;background-clip:text;color:transparent;filter:drop-shadow(0 3px 0 #500) drop-shadow(0 0 14px #f604)}ul{left:12px;bottom:30px;display:flex;gap:4px;list-style:none}li{width:16px;height:6px;background:#fff;box-shadow:0 0 0 1px #0008}li.e{background:#0000;box-shadow:inset 0 0 0 1px #fffb,0 0 0 1px #0008}ul.low li{background:#f55}ul.low li.e{background:#0000}dl{left:50%;bottom:10px;transform:translateX(-50%);display:flex;align-items:center;gap:10px}dl svg{width:38px;fill:#fff;filter:drop-shadow(0 1px 1px #000)}@media(max-width:520px){dl{left:auto;right:12px;bottom:46px;transform:none}}dl data{font:900 clamp(30px,5vw,46px)/1 system-ui,sans-serif;font-variant-numeric:tabular-nums}dl.e data{color:#f66}s{left:50%;top:50%;width:28px;height:28px;margin:-14px 0 0 -14px;background:linear-gradient(45deg,#0000 44%,#fff 44% 56%,#0000 56%),linear-gradient(-45deg,#0000 44%,#fff 44% 56%,#0000 56%);-webkit-mask:radial-gradient(#0000 6px,#000 7px);mask:radial-gradient(#0000 6px,#000 7px)}mark{inset:0;z-index:1;padding-top:30vh;text-align:center;color:#ddd;background:radial-gradient(ellipse at center,#6668 0%,#4a0c0ce8 130%);backdrop-filter:grayscale(1)}mark::first-line{font:900 clamp(30px,8vw,64px)/1 system-ui,sans-serif;letter-spacing:.24em}strong{font-size:22px}table{border-collapse:collapse;font-size:16px}td{padding:2px 10px}td+td{text-align:left}td:first-child{text-align:right;opacity:.7}`,Ca=2800,wa=e=>`${Math.floor(e/60)}:${`${e%60}`.padStart(2,`0`)}`,Ta=e=>{e.insertAdjacentHTML(`beforeend`,`<aside hidden><h6>TINY FPS</h6><span></span><table><tr><td>Mouse<td>look<tr><td>WASD / ZQSD<td>move<tr><td>Shift<td>sprint<tr><td>Space<td>jump, again in the air<tr><td>Move key twice<td>dash that way<tr><td>C<td>crouch, slide when fast<tr><td>Left click<td>fire the gun<tr><td>M<td>mute</table><span>Take the enemy flag to your own base while yours is home. Take the gun at your rack.</span><strong></strong></aside><u></u><h5 hidden>Muted (M)</h5><ul>${`<li></li>`.repeat(5)}</ul><dl hidden><svg viewBox="0 0 38 22"><path d="M1 7c3-5 13-7 22-4l7 3 3 1v4l-6 1-4 2-1 1-3 6h-5l2-7-5-1c-6-1-12-3-10-6z"/></svg><data></data></dl><s hidden></s><mark hidden></mark><nav hidden><span></span><time></time><span></span><small></small><small></small></nav><output hidden></output><section hidden><h6></h6><strong></strong><table></table><span></span></section>`);let t=t=>e.querySelector(t),[n,r]=[`h5`,`aside`].map(e=>t(e)),[i,a]=[`aside span`,`aside strong`].map(e=>t(e)),o=(e,t)=>e.textContent!=t&&(e.textContent=t),s=t(`nav`),[c,d,f]=[...s.querySelectorAll(`span, time`)],[p,h]=[...s.querySelectorAll(`small`)],g=[...e.querySelectorAll(`li`)],[_,v,y,b]=[t(`ul`),t(`dl`),t(`s`),t(`mark`)],x,S=t(`output`),C=t(`u`),w=t(`section`),[T,E,D]=[`h6`,`strong`,`span`].map(e=>w.querySelector(e)),O=w.querySelector(`table`),k=[],A,j,M=(e,t)=>e.style.color=u[t];return[c,p].forEach(e=>M(e,0)),[f,h].forEach(e=>M(e,1)),{title(e,t){r.hidden=!e,o(i,t),o(a,e)},mute:e=>n.hidden=!e,match(e,t){s.hidden=!1,o(c,`${l[0].toUpperCase()} ${e.score[0]}`),o(f,`${e.score[1]} ${l[1].toUpperCase()}`),o(d,e.over?`END`:wa(e.clock)),e.flags.forEach((e,n)=>{let r=e.state===m.CARRIED?`taken by ${t(e.by)}`:e.state===m.DROPPED?`dropped ${e.left}s`:`home`;o(n?h:p,`${l[n]} flag: ${r}`)})},marks(t){for(;k.length<t.length;){let t=document.createElement(`em`);t.innerHTML=`<span></span><small></small>`,k.push(t),e.append(t)}k.splice(t.length).forEach(e=>e.remove()),t.forEach((e,t)=>{let n=k[t];n.style.left=`${e.x*100}%`,n.style.top=`${e.y*100}%`,M(n,e.team);let[r,i]=[n.children[0],n.children[1]];r.style.transform=e.arrow===void 0?``:`rotate(${e.arrow}rad)`,o(r,e.arrow===void 0?`▼`:`▲`),o(i,`${e.kind===`base`?`Base `:``}${e.text}`)})},hurt(e){let t=e<.01?``:`${Math.min(1,e)}`;C.style.opacity!=t&&(C.style.opacity=t)},vitals(e,t){g.forEach((t,n)=>t.classList.toggle(`e`,n>=e)),_.classList.toggle(`low`,e<=1),v.hidden=t<0,v.classList.toggle(`e`,!t),o(v.lastElementChild,`${Math.max(t,0)}`)},hit(){y.hidden=!1,clearTimeout(x),x=setTimeout(()=>y.hidden=!0,140)},down(e,t){b.hidden=e<.02,b.style.opacity=`${Math.min(e,1)}`,o(b,b.hidden?``:`DOWN\nBack in ${t.toFixed(1)}`)},banner(e,t){S.hidden=!1,o(S,e),S.style.color=t===void 0?`#fff`:u[t],clearTimeout(A),A=setTimeout(()=>S.hidden=!0,Ca)},end(e,t){if(w.hidden=!e,!e)j=void 0;else{if(j!==e){j=e;let[t,n]=e.score,r=t>n?0:n>t?1:-1;o(T,r<0?`DRAW`:`${l[r].toUpperCase()} WINS`),T.style.color=r<0?`#fff`:u[r],o(E,`${t} – ${n}`);let i=[...e.players].sort((e,t)=>t.caps-e.caps||t.returns-e.returns||e.id-t.id);O.replaceChildren(),O.insertAdjacentHTML(`beforeend`,`<tr><th>Player<th>Captures<th>Returns</tr>`);for(let e of i){let t=O.insertRow();[e.name,e.caps,e.returns].forEach(e=>t.insertCell().textContent=`${e}`),t.style.color=u[e.team]}}o(D,`Next match in ${t}`)}}}},Ea=.0025,Da=Math.PI*2,Oa={KeyW:h.FORWARD,ArrowUp:h.FORWARD,KeyS:h.BACK,ArrowDown:h.BACK,KeyA:h.LEFT,ArrowLeft:h.LEFT,KeyD:h.RIGHT,ArrowRight:h.RIGHT,Space:h.JUMP,ShiftLeft:h.SPRINT,ShiftRight:h.SPRINT,KeyC:h.CROUCH},ka=h.FORWARD|h.BACK|h.LEFT|h.RIGHT,Aa=(e,t)=>e&~ka|t|h.DASH,ja=e=>Oa[e]??0,Ma=(e,t=()=>{})=>{let r=new AbortController,i=(e,t,n)=>e.addEventListener(t,n,{signal:r.signal}),a=/* @__PURE__ */ new Set,o=/* @__PURE__ */ new Map,s=0,c={yaw:0,pitch:0,keys:0,take(){let e=s?Aa(c.keys,s):c.keys;return s=0,e},locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>r.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{c.locked()&&(c.yaw=((c.yaw-e.movementX*Ea)%Da+Da)%Da,c.pitch=Math.max(-1.55,Math.min(n,c.pitch-e.movementY*Ea)))}),i(document,`mousedown`,e=>{c.locked()&&!e.button&&(c.keys|=h.FIRE)}),i(document,`mouseup`,e=>{e.button||(c.keys&=~h.FIRE)}),i(document,`keydown`,e=>{let n=ja(e.code);if(e.code==`KeyM`&&!e.repeat&&c.locked()&&t(),n&&c.locked()){if(n&ka&&!e.repeat&&!a.has(e.code)){let t=performance.now(),r=o.get(e.code);r!==void 0&&t-r<=250?(s=n,o.delete(e.code)):o.set(e.code,t)}a.add(e.code),c.keys|=n,e.preventDefault()}}),i(document,`keyup`,e=>{a.delete(e.code),c.keys&=~ja(e.code)});let l=()=>{c.keys=s=0,a.clear(),o.clear()};return i(window,`blur`,l),i(document,`pointerlockchange`,()=>c.locked()||l()),c},Na=(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},Pa=(e,t,n,r,i=!0)=>{let a=e.down>0;if(Ke(e,a?{...t,keys:0}:t,n,r),a)return e.down>0&&!--e.down&&he(e,n,r),!1;let o=n.def.teams[r].rack,s=!!o&&Na(e,o,1.2);return i&&s&&!e.rack&&(e.ammo=60),e.rack=s,e.cool=Math.max(0,e.cool-1),i&&t.keys&h.FIRE&&!e.cool&&e.ammo>0&&e.mode!==g.HANG&&e.mode!==g.CLIMB?(e.ammo--,e.shots=e.shots+1&255,e.cool=7,!0):!1},Fa=120,Ia=16,La=e=>{let t={...e};return delete t.ack,delete t.by,t},Ra=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,z:e.z+(t.z-e.z)*n}),za=(e,t,n)=>ce(e+(((t-e+Math.PI)%V+V)%V-Math.PI)*n),Ba=(e,t)=>(t-e&65535)<32768,Va=(e,t,n)=>({...t,...Ra(e,t,n),yaw:za(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),Ha=e=>{let t,n=0,r=0,i=[],a,o,s=[],c=0,l=0,u=!0,d=e=>{let t=e-100,n=0;for(;n+1<s.length&&s[n+1].t<=t;)n++;let r=s[n],i=s[n+1]??r;return{a:r,b:i,u:i.t>r.t?Math.max(0,Math.min(1,(t-r.t)/(i.t-r.t))):0}},f=e=>{if(!s.length)return;let{a:t,b:n,u:r}=d(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536};return{you:(e,r=0)=>{[t,n]=[e,r]},step:(t,s)=>{let d=nt({...t,seq:r,view:s===void 0?void 0:f(s)});return r=r+1&65535,i.push(d),i.length>Fa&&i.shift(),a&&(o=La(a),Pa(a,d,e,n,u),c|=a.ev,l=Math.max(l,a.fall)),d},snapshot:(r,c)=>{s.push({t:c,s:r}),s.length>Ia&&s.shift();let l=r.players.find(e=>e.id===t);l&&(u=!r.over,i=i.filter(e=>!Ba(e.seq,l.ack)),a=La(l),o=La(a),i.forEach((t,r)=>{r===i.length-1&&(o=La(a)),Pa(a,t,e,n,u)}))},events:()=>{let e={ev:c,fall:l};return c=l=0,e},me:e=>a&&o?Va(o,a,Math.max(0,Math.min(1,e))):void 0,others:e=>{let n=s.at(-1);if(!n)return[];let{a:r,b:i,u:a}=d(e);return n.s.players.filter(e=>e.id!==t).map(e=>{let t=r.s.players.find(t=>t.id===e.id),n=i.s.players.find(t=>t.id===e.id);return t&&n?Va(La(t),La(n),a):La(n??t??e)})}}},Ua={x0:.05,x1:.95,y0:.15,y1:.92},Wa=(e,t,n,r,i)=>{let[a,o]=[r-e,i-t];return Math.atan2(a*Math.cos(n)-o*Math.sin(n),-a*Math.sin(n)-o*Math.cos(n))},Ga=e=>{let[t,n]=[Math.sin(e),-Math.cos(e)],[r,i]=[(Ua.x0+Ua.x1)/2,(Ua.y0+Ua.y1)/2],[a,o]=[(Ua.x1-Ua.x0)/2,(Ua.y1-Ua.y0)/2],s=Math.min(a/(Math.abs(t)||1e-9),o/(Math.abs(n)||1e-9));return[r+t*s,i+n*s]},Ka=2.6,qa=e=>{let t=[],n=(n,r,[i,a,o])=>{let s=Math.round(Math.hypot(i-e.eye[0],a+Ka-e.eye[1],o-e.eye[2])),c=e.project(i,a+Ka,o),l=c&&c[0]>=Ua.x0&&c[0]<=Ua.x1&&c[1]>=Ua.y0&&c[1]<=Ua.y1,u=`${s} m`;if(l)t.push({team:n,kind:r,x:c[0],y:c[1],text:u});else{let a=Wa(e.eye[0],e.eye[2],e.yaw,i,o),[s,c]=Ga(a);t.push({team:n,kind:r,x:s,y:c,arrow:a,text:u})}},r=e.flags.some(t=>t.state===m.CARRIED&&t.by===e.id);return e.flags.forEach((t,i)=>{if(t.state===m.CARRIED&&t.by===e.id){n(e.team,`base`,e.bases[e.team]);return}if(r&&i===e.team&&t.state===m.HOME)return;let a=t.state===m.HOME?e.bases[i]:t.state===m.DROPPED?[t.x,t.y,t.z]:e.where(t.by);a&&n(i,`flag`,a)}),t},Ja=(e=[],t=0)=>e.filter((e,n)=>t>>>n&1),Ya=(e,t,n,r)=>{let i=n.map(e=>e*.45);Ht(e,zt(1,1,[1,1],[0,0]),t,[t[0],t[1]+.72,t[2]],[1,0,0],1,.06,i);let[a,o,s]=t;Bt(e,zt(1,0,[1,1]),[a,o+.74,s],Nt(0,0),[0,0,0],[.3,.035,.3],n);let c=e.length;tn(e,[a,o+.045,s],p-.07,p,n),$t(e,c,1.2*qt*(.7+.3*Math.sin(r*2.5))),Bt(e,Vr(0),[a,o+1.05+.04*Math.sin(r*2),s],Nt(r*.8,0),[0,0,0],1.5)},Xa=[[[1,0,0],[0,1,0],[0,0,1]],[[-1,0,0],[0,0,1],[0,1,0]],[[0,1,0],[0,0,1],[1,0,0]],[[0,-1,0],[1,0,0],[0,0,1]],[[0,0,1],[1,0,0],[0,1,0]],[[0,0,-1],[0,1,0],[1,0,0]]],Za=(e,t,n)=>{let[r,i]=[.17,.13],[a,,o]=Nt(n*.9,0),s=[t[0],t[1]+.45+.07*Math.sin(n*2.2+t[0]),t[2]],c=([e,t,n])=>[a[0]*e-o[0]*n,t,a[2]*e-o[2]*n];for(let[t,n,a]of Xa){let o=(e,i,o=1)=>{let l=[0,1,2].map(s=>t[s]*r*o+n[s]*e+a[s]*i),[u,d,f]=c(l);return[s[0]+u,s[1]+d,s[2]+f]};c(t);for(let[t,n,a,s,c,l]of[[-r,-r,r,r,[.86,.9,.88],1],[-i,-.04,i,.04,[.1,1.2,.4],1.01],[-.04,-i,.04,i,[.1,1.2,.4],1.01]]){let r=e.length,[i,u,d,f]=[o(t,n,l),o(a,n,l),o(a,s,l),o(t,s,l)];if(en(e,i,u,d,c),en(e,i,d,f,c),l>1)for(let t=r;t<e.length;t+=10)e[t+8]=-2}}},Qa=14,$a=.5,eo=e=>e.dash>50,to=e=>{let t=wr();return t.update(e,0),{p:{...e},gait:t,dash:+eo(e),since:1e3,aim:0}},no=(e,t)=>(n,i)=>{let a=re(e,[n,t+r,i],[0,-1,0],2*r);return a>0&&a<1?t+r-a:t},ro=(e,t,n,r)=>{for(let n of e.keys())t.some(e=>e.id==n)||e.delete(n);for(let i of t){let t=e.get(i.id);t?(t.gait.update(i,n,r&&no(r,i.y)),t.dash+=(+eo(i)-t.dash)*(1-Math.exp(-n*Qa)),t.since=i.shots==t.p.shots?t.since+n:0,t.aim+=(+(t.since<$a)-t.aim)*(1-Math.exp(-n*12)),t.p={...i}):e.set(i.id,to(i))}},io=(e,t,n,r)=>{let[i,a]=Kr(n),o=e.rot.slice(),s={...e,rot:o},[c,l]=[a[0],a[2].map((e,t)=>e*.92-a[1][t]*.38)],u=i.map((e,t)=>e-.078*l[t]+.022*c[t]),d=[c[0]*.7,-1,c[2]*.7];return Ai(s,t,K.ARM_R,u.map((e,n)=>t.pos[K.HAND_R][n]+(e-t.pos[K.HAND_R][n])*r),d),o[K.HAND_R]=Mn(o[K.HAND_R],q(Ti(Nn(s).rot[K.FOREARM_R]),$n(c,l)),r),s},ao=(e,t,n,r)=>{let i=Mt([-t.p.vx,0,-t.p.vz]),[a,o,s]=n.map(e=>.6+.6*e);[[.5,.12,1.3],[.9,-.16,1.7],[1.25,.14,1.2]].forEach(([n,c,l],u)=>{let d=r([c,n,-.2-.1*u]),f=d.map((e,n)=>e+i[n]*l*t.dash);for(let t of[[-i[2]*.03,0,i[0]*.03],[0,.03,0]])for(let n of[d.map((e,n)=>e+t[n]),d.map((e,n)=>e-t[n]),f])e.push(...n,0,1,0,a,o,-2,s)})},oo=(e,t,n,r=1)=>{let i=t.gait.pose(),{p:a}=t;a.down&&(i={...i,at:[i.at[0],i.at[1]-.5*Math.min(Math.max(1-a.down/30,0),1),i.at[2]]});let o=Nn(i);if(t.aim>.01&&a.ammo>=0&&(i=io(i,o,a,t.aim),o=Nn(i)),_i(e,mi(r),o,ri(n)),a.ammo>=0&&!a.down&&Wr(e,o.pos[K.HAND_R],o.rot[K.HAND_R],r),t.dash>.15){let[r,a]=[Math.sin(i.yaw),Math.cos(i.yaw)],{x:o,y:s,z:c}=t.p;ao(e,t,n,([e,t,n])=>[o+e*a-n*r,s+t,c-e*r-n*a])}},so=Object.keys(y).length,co=(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},lo=(e,t,n,r)=>{let[i,a]=[Math.floor(e),Math.floor(t)],[o,s]=[e-i,t-a].map(e=>e*e*(3-2*e)),c=(e,t)=>co((i+e)%n,(a+t)%n,r);return(c(0,0)*(1-o)+c(1,0)*o)*(1-s)+(c(0,1)*(1-o)+c(1,1)*o)*s},uo=(e,t,n,r,i)=>{let[a,o]=[0,.5];for(let s=0;s<r;s++,o/=2)a+=o*lo(e*(1<<s),t*(1<<s),n<<s,i+s);return a/(1-o*2)},fo=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),$=(e,t)=>e.map(e=>e*t),po=e=>Math.min(Math.max(e,0),1),mo=Math.PI*2,ho=[];ho[y.BRICK]=(e,t)=>{let n=Math.floor(t*8),r=e*4+(n&1)*.5,[i,a,o]=[Math.floor(r)%4,r%1,t*8%1],s=lo(e*16,t*16,16,5),c=.8+.4*s;return a<.05||o<.1?[$([165,160,150],.7+.3*c),.1+.1*s]:[$([170,78,56],(.8+.4*co(i,n,1))*c*(.85+.15*o)),.7+.2*s+.1*po(Math.min(a-.05,o-.1)*12)]},ho[y.TILE]=(e,t)=>{let[n,r]=[Math.floor(e*4),Math.floor(t*4)],[i,a]=[e*4%1,t*4%1],o=lo(e*16,t*16,16,7),s=.9+.2*o;return i<.05||a<.05?[$([85,85,80],s),.1]:[$([196,190,172],s*(.88+.08*(n+r&1)+.1*co(n,r,2))),.8+.1*o+.1*po((Math.min(i,a)-.05)*14)]},ho[y.LAVA]=(e,t)=>{let n=uo(e*4,t*4,4,4,11),r=Math.max(0,1-Math.abs(n-.5)*7)**2;return[fo(fo([55,8,4],[230,70,8],n),[255,215,90],r),.5]},ho[y.STONE]=(e,t)=>{let n=uo(e*8,t*8,8,4,3);return[$([128,124,120],.45+.7*(n*1.3+.1*co(Math.floor(e*128),Math.floor(t*128),4))),po(n*1.4-.2)]},ho[y.METAL]=(e,t)=>{let[n,r,i,a]=[Math.floor(e*2),Math.floor(t*2),e*2%1,t*2%1],o=po((lo(e*8,t*8,8,13)-.68)*6),s=e=>Math.min(Math.max(Math.round((e-.1)/.4),0),2)*.4+.1,[c,l]=[s(i),s(a)],u=c==l&&c==.5?1:Math.hypot(i-c,a-l),d=po(1-u/.07),f=$([98,108,124],(.9+.2*lo(e*32,t*32,32,9)+.12*co(n,r,6))*(1+.3*d)*(.65+.35*po((u-.06)/.04)));return Math.min(i,a,1-i,1-a)<.03?[$([40,44,50],1+o),.05]:[fo(f,[105,68,45],o*.7),.5+.1*(1-o)+.4*d]},ho[y.WOOD]=(e,t)=>{let n=Math.floor(t*8),r=e*2+co(n,0,8)*2,[i,a,o]=[Math.floor(r)%2,r%1,t*8%1],s=co(n,i,3),c=.5+.5*Math.sin(mo*(t*40+2.5*lo(e*4,t*4,4,21)+s*7));return o<.08||a<.015?[[28,18,10],.05]:[fo([92,58,32],[158,106,62],c*.6+s*.35),.7+.15*c+.15*po((o-.08)*15)]},ho[y.MOSS]=(e,t)=>{let n=Math.floor(t*4),r=e*2+(n&1)*.5,[i,a,o]=[Math.floor(r)%2,r%1,t*4%1],s=Math.min(a,1-a,(o<.5?o:1-o)*.5),c=a<.04||o<.06,l=po((.3*uo(e*12,t*12,12,3,17)-.03-s)*12),u=lo(e*64,t*64,64,19),d=$([128,126,118],(.7+.4*co(i,n,5))*(.7+.5*lo(e*16,t*16,16,15)));return[fo(c?$(d,.45):d,fo([52,100,34],[96,148,56],u),l),c?.1+.6*l*u:.6+.2*po(s*30)+.2*l*u]},ho[y.GRATE]=(e,t)=>{let[n,r]=[e*8%1,t*8%1],i=Math.max(Math.abs(n-.5),Math.abs(r-.5)),a=Math.min(Math.abs(n-.5),Math.abs(r-.5))>.43,o=lo(e*16,t*16,16,23);return i<.36?[[9,9,12],0]:[$(fo([104,108,116],[96,80,68],po((o-.55)*4)),(a?1.25:1)-(.5-i)*2.2+.2*o),a?1:.6+.4*po((i-.36)*12)]},ho[y.CONCRETE]=(e,t)=>{let[n,r]=[e*2%1,t*2%1],i=uo(e*4,t*4,4,3,41),a=co(Math.floor(e*128),Math.floor(t*128),43)>.992,o=Math.hypot(n%.5-.25,r%.5-.25)<.02,s=(.94+.1*i+.03*co(Math.floor(e*2),Math.floor(t*2),44))*(a||o?.9:1);return n<.015||r<.015?[$([160,164,172],s),.3]:[$([206,209,214],s),o?.5:.8+.2*i-(a?.15:0)]},ho[y.GLASS]=(e,t)=>{let n=e*2%1,r=((n+t*.7)%1-.5)/.12,i=Math.exp(-r*r);return n<.03||t<.03?[$([150,158,170],1-.3*n),.9]:[fo(fo([7,20,44],[48,88,136],t**2),[120,160,200],i*.18),.4]},ho[y.STEEL]=(e,t)=>{let n=Math.floor(t*128),r=.5*co(n,3,31)+.5*lo(e*8,0,8,n+7),i=e*4%1;return i<.03?[[60,66,76],.1]:[$([176,184,196],.8+.35*r+(i>.97?.15:0)),.6+.2*r]},ho[y.PAINT]=(e,t)=>{let[n,r]=[e*2%1,t*2%1],i=co(Math.floor(e*128),Math.floor(t*128),47);return n<.02||r<.02?[[200,200,206],.3]:[$([246,246,248],.96+.06*i),.85+.04*i]};var go=()=>{let e=new Uint8ClampedArray(so*128*128*4);return ho.forEach((t,n)=>{for(let r=0;r<16384;r++){let[i,a]=t(r%128/128,Math.floor(r/128)/128);e.set([...i,a*255],(n*128*128+r)*4)}}),e},_o=[18,26],vo=8,yo=40,bo=55,xo=-60,So=[[1,.45,.12],[.2,.6,1],[.9,.15,.2],[.25,.85,.55]],Co=({brushes:e})=>{let[t,n,r,i]=[0,2].flatMap(t=>[Math.min(...e.map(e=>e.min[t])),Math.max(...e.map(e=>e.max[t]))]),[a,o,s]=[(t+n)/2,(r+i)/2,Math.hypot(n-t,i-r)/2];return _o.flatMap((e,t)=>Array.from({length:e},(n,r)=>{let i=e=>co(r,t,vo+e),c=(r+i(1)*.8)/e*2*Math.PI,l=s+yo+t*bo+i(2)*30,[u,d]=[a+l*Math.cos(c),o+l*Math.sin(c)],[f,p]=[5+i(3)*8,5+i(4)*8],m=t?-5+i(5)**2*90:-20+i(5)*30,h=[y.GLASS,y.STEEL,y.CONCRETE][+(i(6)>.7)+ +(i(6)>.85)],g={min:[u-f,xo,d-p],max:[u+f,m,d+p],top:y.CONCRETE,side:h};return i(7)<.35?[g,{min:[u-f/2,m,d-p/2],max:[u+f/2,m+3+i(8)*3,d+p/2],top:y.PAINT,side:y.PAINT,tint:So[Math.floor(i(9)*So.length)]}]:[g]}).flat())},wo=r,To=o+.05,Eo=1.5,Do=.6,Oo=8,ko=2.5,Ao=3,jo=.4,Mo=.012,No=.2,Po=[1.2,1.45],Fo=[1.6,.12,.08],Io=[.9,.07,.05],Lo=[.85,.07,.05],Ro=(e,t,n,r)=>{let i=-1/0;for(let a of e)if(a!=t&&a.min[0]<=n&&n<=a.max[0]&&a.min[2]<=r&&r<=a.max[2]){if(a.max[1]>t.max[1]+.001){if(a.min[1]<t.max[1])return 1/0}else i=Math.max(i,a.max[1])}return t.max[1]-i},zo=({brushes:e,floor:t},n)=>{let r=n.max.map((e,t)=>e-n.min[t]),i=[...r].sort((e,t)=>e-t),a={beam:i[1]<=Do&&i[2]>=2*Do,lips:[],stripes:[]};if(a.beam)return a;for(let i of[0,2]){let o=2-i;for(let t of[0,1]){let s=[n.min[0],0,n.min[2]];s[i]=(t?n.max:n.min)[i]+(t?jo:-.4),s[o]=(n.min[o]+n.max[o])/2;let c=Ro(e,n,s[0],s[2]);c>wo&&c<=To&&r[o]>=Eo&&a.lips.push([i,t])}n.min[1]>t&&r[1]>=ko&&r[o]>=Oo&&r[i]<=Ao&&a.stripes.push([i,0],[i,1])}return a},Bo=(e,t,n,r,i,a,o)=>{let[s,c]=[(r+1)%3,(r+2)%3],l=[0,0,0];l[r]=i?1:-1;for(let[u,d]of[[0,0],[1,0],[1,1],[0,0],[1,1],[0,1]]){let f=[0,0,0];[f[r],f[s],f[c]]=[(i?n:t)[r],(u?n:t)[s],(d?n:t)[c]],e.push(...f,...l,o[0],o[1],a,o[2])}},Vo=e=>{let t=[];for(let n of e.brushes){let{beam:r,lips:i,stripes:a}=zo(e,n),[o,s]=[n.min.map(e=>e-Mo),n.max.map(e=>e+Mo)];if(r)for(let e=0;e<3;e++)for(let n of[0,1])(e!=1||n)&&Bo(t,o,s,e,n,-1,Lo);for(let[e,r]of i){let i=r?1:-1,a=(r?n.max:n.min)[e],o=[n.min[0],n.max[1]+Mo,n.min[2]],s=[n.max[0],n.max[1]+Mo,n.max[2]];[o[e],s[e]]=r?[a-No,a]:[a,a+No],Bo(t,o,s,1,1,-2,Fo);let[c,l]=[o.slice(),s.slice()];[c[1],l[1]]=[n.max[1]-No,n.max[1]],[c[e],l[e]]=[a+i*Mo,a+i*Mo],Bo(t,c,l,e,r,-2,Fo)}for(let[e,r]of a){let i=2-e,[a,o]=[[...n.min],[...n.max]];[a[1],o[1]]=[n.min[1]+Po[0],n.min[1]+Po[1]],[a[i],o[i]]=[n.min[i]+.3,n.max[i]-.3],a[e]=o[e]=(r?n.max:n.min)[e]+(r?Mo:-.012),Bo(t,a,o,e,r,-2,Io)}}return t},Ho=4.2,Uo=({teams:e})=>{let t=[];return e.forEach(({base:[e,n,r]},i)=>{let a=Xt(i),o=a.map(e=>.25+.45*e),s=(i,a,o,s,c,l)=>Bo(t,[e+i,n+l,r+a],[e+o,n+l,r+s],1,1,-1,c);s(-4.2,-4.2,Ho,Ho,o,.02);for(let[e,t,n,r]of[[-4.2,-4.2,Ho,-3.85],[-4.2,3.85,Ho,Ho],[-4.2,-4.2,-3.85,Ho],[3.85,-4.2,Ho,Ho]])s(e,t,n,r,a.map(e=>e*.8),.03)}),t},Wo=1<<18,Go=2,Ko=1024,qo=.6,Jo=Math.tan(70*Math.PI/360),Yo=10,Xo=4,Zo=`#version 300 es
1
+ var e=.4,t=1.8,n=1.55,r=.5,i=.9,a=7.5,o=2.4,s=5.5,c=2.5,l=[`Red`,`Blue`],u=[`#ff3d4f`,`#2f80ff`],d=1.5,f=.012,p=1.2,m={HOME:0,CARRIED:1,DROPPED:2},h={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,SPRINT:32,DASH:64,CROUCH:128,FIRE:256},g={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},_={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},v={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},y={BRICK:0,TILE:1,LAVA:2,STONE:3,METAL:4,WOOD:5,MOSS:6,GRATE:7,CONCRETE:8,GLASS:9,STEEL:10,PAINT:11},b=-30,x=(e,t,n,r,i,a=y.CONCRETE)=>({min:[e,b,t],max:[n,i,r],top:y.CONCRETE,side:a}),S=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c});[x(4,57.7,24,76,10),x(4,36,24,53.5,10,y.GLASS),x(4,20,24,36,12.4),x(4,-5,24,7,12.4,y.GLASS),x(27,20,47,50,8),x(27,60,47,76,8,y.BRICK),S([9,12.2,39],[19,12.6,47],y.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>S([12,t,e-n],[14,t+.4*n,e-n+1],y.CONCRETE)))(53,10),S([5,10,42],[5.5,14,42.5],y.STEEL),S([5,10,50],[5.5,14,50.5],y.STEEL),S([8,12.4,24],[20,12.85,24.45],y.STEEL),S([36,8,22],[37,14.5,48],y.PAINT,y.PAINT,[.15,.72,.62]),S([30,8,28],[34,10,32],y.CONCRETE),S([40,8,30],[44,10.2,34],y.PAINT,y.PAINT,[1,.3,.06]),S([28,9.2,44],[35,12,46],y.STEEL,y.PAINT,[.2,.42,1]),S([41.5,7.6,50],[42,8,60],y.STEEL),S([30,8,64],[34,9.6,68],y.PAINT,y.PAINT,[.2,.8,.3])];var C=240,w=[1,.22,.26],T=[.2,.46,1],E=[1,.42,.08],D=[.12,.7,.62],O=(e,t,n,r,i,a,o)=>S([e,t,n],[r,i,a],y.PAINT,y.PAINT,o),k=(e,t,n,r,i,a,o,s=b)=>{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?S([d,s,r],[f,p,i],y.CONCRETE):S([r,s,d],[i,p,f],y.CONCRETE)})},A=(e,t,n,r,i,a,o)=>o.map((o,s)=>S([e+s*n,a,t+s*r],[e+s*n+4,o,t+s*r+i],y.STEEL,y.CONCRETE)),j=[x(12,212,52,240,26,y.GLASS),O(12,26,212,52,26.12,212.5,w),O(12,26,239.5,52,26.12,240,w),O(12,26,212.5,12.5,26.12,239.5,w),O(51.5,26,212.5,52,26.12,239.5,w),O(11.6,12,222,12,25.8,232,w),O(28,12,211.4,31,25.5,212,w),S([19,26,222],[22,27.4,225],y.STEEL),S([42,26,222],[45,27.4,225],y.STEEL),S([29,26,229],[35,27.1,229.6],y.CONCRETE),x(6,164,26,201,26,y.GLASS),x(6,134,26,147,26,y.GLASS),x(6,201,26,212,19),x(15,147,26,164,19),S([14,26,164],[15,32,196],y.PAINT,y.PAINT,D),S([14,18,147],[15,32,164],y.PAINT,y.PAINT,D),S([14,26,134],[15,32,147],y.PAINT,y.PAINT,D),...A(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])=>S([e,19,t],[n,i,r],y.STEEL,y.CONCRETE)),S([20,26,178],[23,27.3,181],y.STEEL),S([8,26,176],[11,27.2,179],y.STEEL),S([8,26,190],[11,27.3,193],y.STEEL),S([20,26,140],[23,27.3,143],y.STEEL),x(32,186,76,209,19),O(32,19,207.5,76,19.1,209,w),...A(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])=>S([e,b,t],[n,i,r],y.STEEL,y.CONCRETE)),x(32,166,64,182,21.2,y.GLASS),x(32,140,64,161,19),S([40,21.2,172],[44,22.6,176],y.STEEL),S([52,19,148],[57,20.3,151],y.STEEL),S([38,19,196],[41,20.4,199],y.STEEL),S([60,19,200],[63,20.4,203],y.STEEL),S([52,19,190],[58,20.6,194],y.STEEL),S([66,19,204],[72,20.2,207],y.STEEL),S([56,21.2,170],[60,22.4,174],y.STEEL),S([34,19,152],[37,20.3,156],y.STEEL),...A(36,135,18,0,3,15,[17.2,17.2]),...A(6.5,129,6,0,4,15,[17.2,19.4,21.6,23.8]),x(76,213,100,240,14.5,y.STEEL),O(76,14.5,238.5,100,14.6,240,w),x(76,185,100,209,14.5),x(76,138,100,181,14.5,y.GLASS),S([80,15.7,158],[96,17.7,162],y.STEEL,y.PAINT,E),S([82,14.5,234],[85,15.9,237],y.STEEL),S([91,14.5,190],[94,15.9,193],y.STEEL),S([80,14.5,204],[83,15.6,207],y.STEEL),S([78,14.5,170],[81,15.9,173],y.STEEL),S([92,14.5,146],[95,15.7,149],y.STEEL),S([92,14.5,222],[96,15.8,226],y.STEEL),...k(0,76,52,226,232,14.5,26),...k(0,85,76,196,202,14.5,19,14.5)],M=[x(6,106,62,134,15),x(62,106,100,134,14.5),S([34,15,112],[54,17.2,128],y.CONCRETE),O(38,17.2,116,50,17.3,124,E),...[[35,113],[35,126.2],[51,113],[51,126.2]].map(([e,t])=>S([e,17.2,t],[e+.8,21.5,t+.8],y.STEEL)),S([34.6,21.5,112.6],[52.2,21.9,127.4],y.GLASS),S([14,15,114],[17,16.5,117],y.STEEL),S([14,15,123],[17,16.5,126],y.STEEL),S([56,15,114],[59,16.5,117],y.STEEL),S([56,15,123],[59,16.5,126],y.STEEL),S([15.35,25.5,106],[15.85,26,134],y.STEEL),S([70,14.5,108],[70.8,38,108.8],y.STEEL),S([70,14.5,131.2],[70.8,38,132],y.STEEL),S([66,14.5,110],[69,15.9,113],y.STEEL),S([66,14.5,127],[69,15.9,130],y.STEEL)],ee=e=>({...e,min:[e.min[0],e.min[1],C-e.max[2]],max:[e.max[0],e.max[1],C-e.min[2]],tint:e.tint===w?T:e.tint}),N=(e,t,n)=>[...[16,22,28,34,40].map(n=>[n,26,t,e]),...[19,31,43].map(t=>[t,26,n,e])],P=[[20,26,190],[48,21.2,172],[48,19,200],[88,14.5,198]],F=[[21,26,168],[46,19,144],[36,21.2,178],[88,14.5,216],[88,14.5,172]],I={name:`Highline`,brushes:[...j,...j.map(ee),...M],teams:[{base:[32,26,224],spawns:N(0,236,231),rack:[47,26,234]},{base:[32,26,16],spawns:N(Math.PI,4,9),rack:[47,26,6]}],packs:[...P,...P.map(([e,t,n])=>[e,t,C-n]),[24,15,112],[24,15,128]],ammo:[...F,...F.map(([e,t,n])=>[e,t,C-n])],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]},L=4,R=1024,z=(e,t)=>(e+R)*(2*R)+t+R,B=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),te=(e,t=L)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=B(e[0],t);a<=B(r[0],t);a++)for(let o=B(e[2],t);o<=B(r[2],t);o++){let e=z(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},ne=(e,t,n,r)=>{let i=[];for(let a=B(t-r,e.cell);a<=B(t+r,e.cell);a++)for(let t=B(n-r,e.cell);t<=B(n+r,e.cell);t++)for(let n of e.grid.get(z(a,t))??[])i.includes(n)||i.push(n);return i},V=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=B(t[0],i),c=B(t[2],i),l=Math.sign(n[0]),u=Math.sign(n[2]),d=l?((s+ +(l>0))*i-t[0])/n[0]:1/0,f=u?((c+ +(u>0))*i-t[2])/n[2]:1/0,p=d,m=f,h=l?i/Math.abs(n[0]):1/0,g=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(z(s,c))??[]){let e=a.brushes[r],[i,s]=[0,o];for(let r=0;r<3&&i<=s;r++){if(!n[r]){(t[r]<e.min[r]||t[r]>e.max[r])&&(s=-1);continue}let a=(e.min[r]-t[r])/n[r],o=(e.max[r]-t[r])/n[r];i=Math.max(i,Math.min(a,o)),s=Math.min(s,Math.max(a,o))}i<=s&&s>0&&i<o&&(o=i)}if(Math.min(p,m)>=o||Math.abs(s)>R||Math.abs(c)>R)return o;p<m?(s+=l,p+=h):(c+=u,m+=g)}},re=(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&&V(e,t,[r/o,i/o,a/o],o)<o-1e-4},H=1/60,U=Math.PI*2,ie=1e-6,ae=.01,oe=.001,se=e=>(e%U+U)%U,ce=e=>[-Math.sin(e),-Math.cos(e)],le=Math.fround,ue=Math.sqrt,de=(e,t,n)=>Math.min(Math.max(e,t),n),W=(e,t)=>ue(e*e+t*t),fe=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],pe={vx:0,vz:0,mode:g.GROUND,t:0,wall:_.NONE,edge:0,jumps:1,dashes:1,dash:0,stun:0,coyote:6,buffer:0,held:0,hp:5,ammo:-1,cool:0,rack:!1,down:0,shots:0,hits:0,ev:0,fall:0},me=(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:le(a),y:le(o),z:le(s),vy:0,yaw:se(c),pitch:0,ground:!0,...pe}},he=(e,t,n)=>{let{yaw:r,pitch:i,id:a,shots:o,hits:s}=e;Object.assign(e,me(a,t,a,n),{yaw:r,pitch:i,shots:o,hits:s,ev:e.ev|v.RESPAWN})},ge=e=>e===g.GROUND||e===g.SLIDE||e===g.CROUCH,_e=e=>e.mode===g.SLIDE||e.mode===g.CROUCH?i:t,ve=e=>e.mode===g.SLIDE||e.mode===g.CROUCH?.7:1.6,ye=e=>W(e.vx,e.vz),be=e=>e.mode===g.GROUND&&W(e.vx,e.vz)>6.5,xe=(e,t,n)=>e.max[1]>t+.5+ae&&e.min[1]<t+n-ae,Se=(e,t,n)=>[t-de(t,e.min[0],e.max[0]),n-de(n,e.min[2],e.max[2])],Ce=(t,n,r)=>{let{brushes:i}=n.def,a=ne(n,t.x,t.z,2*e),o=(e-ie)**2,[s,c]=[0,0];for(let n=0;n<4;n++){let n=0,l=0,u=0;for(let s of a){let a=i[s];if(!xe(a,t.y,r))continue;let[c,d]=Se(a,t.x,t.z),f=c*c+d*d;if(f>=o)continue;if(f){let t=ue(f);.4-t>n&&(n=e-t,l=c/t*n,u=d/t*n);continue}let[p,m,h]=[[t.x-a.min[0],-1,0],[a.max[0]-t.x,1,0],[t.z-a.min[2],0,-1],[a.max[2]-t.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);p+.4>n&&(n=p+e,[l,u]=[m*n,h*n])}if(!n)break;t.x+=l,t.z+=u,s+=l,c+=u}return[s,c]},we=(t,n,r)=>{let{brushes:i}=n.def,a=(e-ie)**2,o=-1/0,s=1/0;for(let c of ne(n,t.x,t.z,e)){let e=i[c],[n,l]=Se(e,t.x,t.z);n*n+l*l>=a||(e.max[1]<=t.y+.5+ae?o=Math.max(o,e.max[1]):e.min[1]>=t.y+r-ae&&(s=Math.min(s,e.min[1])))}return[o,s]},Te=(t,n)=>{let r=(e-ie)**2;return ne(n,t.x,t.z,e).every(e=>{let i=n.def.brushes[e],[a,o]=Se(i,t.x,t.z);return a*a+o*o>=r||!xe(i,t.y,1.8)})},Ee=(t,n,r,i,a)=>{let o=(e-ie)**2;return ne(t,n,r,e).every(e=>{let s=t.def.brushes[e],[c,l]=Se(s,n,r);return c*c+l*l>=o||s.max[1]<=i||s.min[1]>=a})},De=(e,t)=>{let[n,r]=fe[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}},Oe=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=De(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-oe&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},ke=(t,n,r)=>{let i;for(let a of ne(n,t.x,t.z,.9)){let o=n.def.brushes[a],s=Oe(o,t,r,.5);s!==void 0&&o.min[1]<t.y+.5&&o.max[1]>t.y+1.8&&(i=Math.min(i??1/0,Math.max(0,s-e)))}return i},Ae=(e,t)=>{let[n,r]=ce(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=fe[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=De(e,a);for(let n of ne(t,e.x,e.z,.6000000000000001)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(Oe(r,e,a,.2)===void 0||s<1.2||s>2.4||r.min[1]>o-.25||i&&i.top>=o)continue;let u=l>0?r.min[c]:r.max[c],d=u-l*.43000000000000005,f=u+l*.2,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];Ee(t,p,m,Math.min(e.y,o-2)+ae,o+1.8)&&Ee(t,h,g,o+ae,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},je=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=De(e,e.wall);return ne(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 le(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},Me=(e,n)=>{if(e.vy>=0)return!1;let[r]=we(e,n,t),i=6*H;return e.y-r<=-e.vy*i+10*i*i},G=(e,t)=>{e.mode=t,e.t=0},Ne=(e,t)=>{let n=W(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},Pe=(t,n,r,i)=>{let[a,o]=[r.wx,r.wz];for(let r of ne(n,t.x,t.z,e+oe)){let e=n.def.brushes[r],[s,c]=Se(e,t.x,t.z),l=W(s,c);if(l>0&&l<=.4+oe&&xe(e,t.y,i)){let e=(-a*s-o*c)/l;e>0&&(a+=e*s/l,o+=e*c/l)}}return[a,o]},Fe=(e,t,n)=>{let r=W(t[0],t[1]);if(r<ie){let t=W(e.vx,e.vz),n=t?Math.max(0,t-45*H)/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=W(s,c);if(l){let e=Math.max(0,l-45*H)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*H):Math.max(n,o-12*H),e.vx=s+o*i,e.vz=c+o*a},Ie=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*H,e.z+=e.vz*H;let[o,s]=Ce(e,t,n),c=W(o,s);if(c){let t=(e.vx*o+e.vz*s)/c;t<0&&(e.vx-=t*o/c,e.vz-=t*s/c)}let[l,u]=we(e,t,n),d=e.vy-r*20*H;if(e.y+=(e.vy+d)/2*H,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+ae:e.y<l){if(e.y=l,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&l>=a-.5)return e.y=l,e.vy=0,0;return-1},Le=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=v.JUMP},Re=(e,n,r)=>{let[i,a]=fe[e.wall],o=t=>{G(e,t),e.edge=0};if(r.keys&(h.BACK|h.CROUCH))o(g.AIR),e.coyote=0;else if(r.jump&&r.fx*i+r.fz*a<0)o(g.AIR),e.vx=-i*4,e.vz=-a*4,Le(e,6);else if(r.jump||r.fwd&&e.t>=6)G(e,g.CLIMB);else if(e.t>=30)o(g.AIR),e.coyote=0;else{let r=Math.max(e.edge-2,we(e,n,t)[0]);e.y+=de(r-e.y,-8*H,8*H)}},ze=(e,t)=>{let[n,r]=fe[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*H):(e.x+=n*s*H,e.z+=r*s*H),e.y>=e.edge&&je(e,t)?(G(e,g.GROUND),e.vx=n*3,e.vz=r*3,e.vy=0,e.edge=0,e.wall=_.NONE,e.coyote=6,e.ev|=v.CLIMB):e.t>=40&&(G(e,e.y>=e.edge?g.GROUND:g.AIR),e.edge=0,e.wall=_.NONE)},Be=(e,t,n)=>{let[r,i]=fe[e.wall],a=e.vx*r+e.vz*i,[o,s]=[e.vx-a*r,e.vz-a*i],c=W(o,s);if(n.jump)G(e,g.AIR),e.vx=o-r*5,e.vz=s-i*5,Le(e,6.5),e.jumps=1,e.dashes=1,e.ev|=v.WALLRUN_END;else{let a=ke(e,t,e.wall);if(a===void 0||!n.fwd||c<3.5||e.t>=60){G(e,g.AIR),e.ev|=v.WALLRUN_END;return}let l=Math.max(0,c-1.5*H)/c;e.vx=o*l,e.vz=s*l;let u=Math.min(a,4*H);e.x+=r*u,e.z+=i*u}},Ve=(e,t,n)=>{if(!n.fwd)return;let r=W(e.vx,e.vz);if(!(r<4.5))for(let n=1;n<=4;n++){let[i,a]=fe[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&&ke(e,t,n)!==void 0){let t=W(s,c),i=Math.max(t,.9*r)/t;G(e,g.WALLRUN),e.wall=n,[e.vx,e.vz]=[s*i,c*i],e.vy=de(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=v.WALLRUN_START;return}}},He=(e,t)=>{G(e,g.HANG),e.wall=t.side,e.edge=le(t.top),t.side<=_.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|=v.GRAB},Ue=(e,t,n)=>{let r=e.mode===g.GROUND;if(n.dash&&e.dash===0&&(r||(e.mode===g.AIR||e.mode===g.WALLRUN)&&e.dashes>0)){let[t,i]=n.wx||n.wz?[n.wx,n.wz]:[n.fx,n.fz];r||(e.dashes--,e.vy=0,e.mode===g.WALLRUN&&(G(e,g.AIR),e.ev|=v.WALLRUN_END)),e.vx=t*16,e.vz=i*16,e.dash=60,e.ev|=v.DASH}let i=e.dash>50;e.mode===g.WALLRUN&&Be(e,t,n),ge(e.mode)&&We(e,t,n,i),e.mode===g.AIR&&Ge(e,t,n,i);let o=i&&e.vy<=0?0:e.mode===g.WALLRUN?.15:1,s=e.mode,c=Ie(e,t,_e(e),o,ge(s));if(c>=0){if(!ge(e.mode)){if(e.ev|=v.LAND|(e.mode===g.WALLRUN?v.WALLRUN_END:0),e.fall=c,e.jumps=1,e.dashes=1,e.wall=_.NONE,n.keys&h.CROUCH){let t=W(e.vx,e.vz)>=a;G(e,t?g.SLIDE:g.CROUCH),e.ev|=t?v.SLIDE_START:0}else G(e,g.GROUND)}e.coyote=6}else ge(e.mode)&&(e.ev|=e.mode===g.SLIDE?v.SLIDE_END:0,G(e,g.AIR));if(e.mode===g.AIR){let r=Ae(e,t);r?He(e,r):Ve(e,t,n)}},We=(e,n,r,o)=>{let s=(r.keys&h.CROUCH)!==0;if(e.buffer>0&&(e.mode===g.GROUND||Te(e,n))){e.ev|=e.mode===g.SLIDE?v.SLIDE_END:0,G(e,g.AIR),Le(e,7);return}let l=W(e.vx,e.vz);if(e.mode===g.GROUND&&s){let t=l>=a;G(e,t?g.SLIDE:g.CROUCH),e.ev|=t?v.SLIDE_START:0}else e.mode===g.SLIDE&&(e.t>=60||l<4.5||r.stumble)?(e.ev|=v.SLIDE_END,G(e,!s&&Te(e,n)?g.GROUND:g.CROUCH)):e.mode===g.SLIDE&&!s&&Te(e,n)?(e.ev|=v.SLIDE_END,G(e,g.GROUND)):e.mode===g.CROUCH&&!s&&Te(e,n)&&G(e,g.GROUND);if(!o){if(r.stumble){if(l>2.5){let t=Math.max(c,l-12*H)/l;e.vx*=t,e.vz*=t}else Fe(e,Pe(e,n,r,_e(e)),c)}else if(e.mode===g.SLIDE){let t=Math.max(0,l-4*H)/l;e.vx*=t,e.vz*=t}else if(e.mode===g.CROUCH)Fe(e,Pe(e,n,r,i),3);else{let i=(r.keys&h.SPRINT)!==0&&r.fwd;Fe(e,Pe(e,n,r,t),i?9:6)}}},Ge=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?Le(e,7):e.jumps>0&&!Me(e,t)&&(e.jumps--,Le(e,6),e.ev=e.ev&~v.JUMP|v.DOUBLE)),r||!n.wx&&!n.wz)return;let i=W(e.vx,e.vz);e.vx+=n.wx*14*H,e.vz+=n.wz*14*H,Ne(e,Math.max(i,6))},Ke=(e,t,r,i=0)=>{e.yaw=se(t.yaw),e.pitch=Math.max(-1.55,Math.min(n,t.pitch));let a=(t.keys&h.FORWARD?1:0)-(t.keys&h.BACK?1:0),o=(t.keys&h.RIGHT?1:0)-(t.keys&h.LEFT?1:0),s=W(a,o)||1,[c,l]=ce(e.yaw),u=n=>(t.keys&n)!==0&&(e.held&n)===0,d=e.stun>0,f={keys:t.keys,stumble:d,jump:!d&&u(h.JUMP),dash:!d&&u(h.DASH),fwd:a>0,wx:(c*a-l*o)/s,wz:(l*a+c*o)/s,fx:c,fz:l},p=e.mode;e.ev=0,e.fall=0,f.jump&&(e.buffer=7),d&&e.stun--,e.dash>0&&(e.dash--,e.dash===50&&Ne(e,10)),e.mode===g.HANG&&Re(e,r,f),e.mode===g.CLIMB?ze(e,r):e.mode!==g.HANG&&Ue(e,r,f),e.y<r.def.floor&&he(e,r,i),e.t=e.mode===p?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===g.AIR&&p===g.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=t.keys&(h.JUMP|h.DASH),e.ground=ge(e.mode),e.x=le(e.x),e.y=le(e.y),e.z=le(e.z),e.vx=le(e.vx),e.vy=le(e.vy),e.vz=le(e.vz),e.edge=le(e.edge)},qe=127,Je=16,Ye=65536/(2*Math.PI),Xe=e=>Math.round(e*Ye)&65535,Ze=e=>Math.max(-32768,Math.min(32767,Math.round(e))),Qe=e=>Ze(e*1e4),$e=e=>e/1e4,et=e=>e/Ye,tt=(e=0)=>Math.round(e*256)&16777215,nt=e=>({...e,yaw:et(Xe(e.yaw)),pitch:$e(Qe(e.pitch)),...e.view!==void 0&&{view:tt(e.view)/256}}),rt=e=>{let t=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(12));t.setUint8(0,1),t.setUint16(1,e.seq&65535),t.setUint16(3,e.keys&511),t.setUint16(5,Xe(e.yaw)),t.setInt16(7,Qe(e.pitch));let n=tt(e.view);return t.setUint16(9,n>>8),t.setUint8(11,n&255),t.buffer},it=e=>e===m.CARRIED?2:e===m.DROPPED?8:1,at=e=>{if(e.byteLength<4)return null;let t=new DataView(e),n=t.getUint8(3),r=4+45*n;if(t.getUint8(0)!==2||e.byteLength<r+8+2)return null;let i=[];for(let e=0;e<n;e++){let n=4+e*45,r=t.getUint8(n+35),a=t.getUint8(n+38),[o,s]=[t.getUint8(n+37),t.getUint8(n+39)],c=r&7,l=t.getUint8(n+40)<<16|t.getUint16(n+41);i.push({id:t.getUint8(n),x:t.getFloat32(n+1),y:t.getFloat32(n+5),z:t.getFloat32(n+9),vx:t.getFloat32(n+13),vy:t.getFloat32(n+17),vz:t.getFloat32(n+21),edge:t.getFloat32(n+25),yaw:et(t.getUint16(n+29)),pitch:$e(t.getInt16(n+31)),ack:t.getUint16(n+33),ground:c===g.GROUND||c===g.SLIDE||c===g.CROUCH,mode:c,wall:r>>3&7,jumps:r>>6&1,dashes:r>>7,t:t.getUint8(n+36),dash:o&63,stun:s&63,by:o>>6<<2|s>>6,coyote:a&7,buffer:a>>3&7,held:(a&64?h.JUMP:0)|(a&128?h.DASH:0),ev:0,fall:0,hp:l&7,cool:l>>3&7,ammo:(l>>6&127)===qe?-1:l>>6&127,down:l>>13&127,rack:(l>>20&1)==1,shots:t.getUint8(n+43),hits:t.getUint8(n+44)})}let a=t.getUint16(r+2),o=r+8,s=[];for(let n=0;n<2;n++){let n=o<e.byteLength?t.getUint8(o):-1;if(n<0||n>m.DROPPED||o+it(n)>e.byteLength)return null;let r={state:n,by:0,x:0,y:0,z:0,left:0};n===m.CARRIED?r.by=t.getUint8(o+1):n===m.DROPPED&&([r.x,r.y,r.z]=[1,3,5].map(e=>t.getInt16(o+e)/Je),r.left=t.getUint8(o+7)),s.push(r),o+=it(n)}return o===e.byteLength?{tick:t.getUint16(1),players:i,score:[t.getUint8(r),t.getUint8(r+1)],clock:a&32767,over:!!(a&32768),flags:s,packs:t.getUint32(r+4)}:null},ot=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},st=44100,ct=([e,t,n,r,i,a,o,s,c,l,u],d)=>{let f=new Float32Array(Math.ceil((r+i+a)*st)),p=0,m=0,h=0,g=()=>{d=d+1831565813|0;let e=Math.imul(d^d>>>15,1|d);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/2**31-1};for(let d=0;d<f.length;d++){let _=d/st;p+=t*2**(n*_)*(_>c?l:1)*(1+o*Math.sin(_*44))/st,p>=1&&(p%=1,h=g());let v=e==3?h:e==2?Math.sin(p*2*Math.PI):e?1-2*p:p<.5?1:-1;m+=(v-m)*s;let y=_<r?_/r:_<r+i?1:((r+i+a-_)/a)**2;f[d]=m*y*u}return f},K={STEP:0,WALLSTEP:1,JUMP:2,DOUBLE:3,DASH:4,LAND:5,GRAB:6,SCUFF:7,WIND:8,SCRAPE:9,TAKE:10,DROP:11,RETURN:12,CAPTURE:13,TACKLE:14,GRUNT:15,LASER:16,HIT:17,HURT:18,DOWN:19,GUN:20,PACK:21,DRY:22},lt=[[[2,130,-3,.001,.005,.06,0,1,0,1,.7],[3,8e3,-1,.001,0,.035,0,.4,0,1,.45]],[[3,12e3,0,.001,0,.03,0,.5,0,1,.4],[2,190,-3,.001,0,.04,0,1,0,1,.3]],[[3,14e3,0,.015,.02,.09,.3,.18,0,1,.5],[2,70,-2,.003,0,.07,0,1,0,1,.3]],[[3,4e3,3.5,.03,.03,.2,0,.25,0,1,.5],[2,350,1.2,.03,.02,.18,.02,1,0,1,.12]],[[3,14e3,-2.5,.008,.07,.2,.25,.3,0,1,.8],[3,3500,.5,.01,.06,.2,0,.12,0,1,.5]],[[2,70,-2.5,.001,.01,.2,0,1,0,1,.9],[3,7e3,-1,.001,0,.09,0,.25,0,1,.5]],[[3,6e3,-1,.001,0,.05,0,.5,0,1,.7],[2,160,-4,.001,0,.07,0,1,0,1,.5]],[[3,5e3,0,.01,.04,.14,.5,.3,0,1,.5],[3,2500,0,.03,0,.1,.4,.2,0,1,.3,.08]],[[3,2e4,0,.001,2.1,.001,.25,.06,0,1,1.2],[3,2e4,0,.001,2.1,.001,.35,.3,0,1,.3]],[[3,9e3,0,.001,2.1,.001,.5,.4,0,1,.5],[3,3e3,0,.001,2.1,.001,.4,.2,0,1,.5]],[[0,392,0,.003,.05,.08,0,.35,.07,1.5,.5],[2,784,0,.003,.03,.1,.01,1,0,1,.3,.05]],[[1,330,-2.2,.003,.04,.22,.04,.25,0,1,.45],[3,2500,-1,.001,0,.12,0,.3,0,1,.4]],[[2,659,0,.003,.06,.25,.015,1,.09,1.5,.5],[2,1318,0,.003,.03,.2,0,1,0,1,.2,.09]],[[0,523,0,.004,.07,.1,0,.3,0,1,.4],[0,659,0,.004,.07,.1,0,.3,0,1,.4,.11],[0,784,0,.004,.07,.1,0,.3,0,1,.4,.22],[0,1047,0,.004,.2,.35,.008,.3,0,1,.5,.33],[2,262,0,.004,.25,.3,0,1,0,1,.35,.33]],[[2,120,-3,.001,.01,.24,0,1,0,1,1],[3,5e3,-1.5,.001,0,.09,0,.35,0,1,.7],[3,2200,0,.01,.03,.16,.3,.15,0,1,.4,.03]],[[1,170,-.9,.012,.05,.17,.06,.2,0,1,.5],[3,3e3,0,.01,.04,.14,.4,.12,0,1,.5]],[[1,3600,-10,.001,.01,.09,0,.5,0,1,.4],[0,1900,-8,.001,0,.06,0,.3,0,1,.25],[3,9e3,0,.001,0,.03,0,.4,0,1,.25]],[[2,1700,0,.001,0,.13,0,1,0,1,.6],[2,4700,0,.001,0,.05,0,1,0,1,.3],[2,1790,0,.001,0,.09,0,1,0,1,.3]],[[2,110,-2.5,.002,.01,.2,0,1,0,1,.9],[3,2500,0,.02,.03,.17,.3,.12,0,1,.5,.04]],[[2,90,-1.2,.002,.04,.45,0,1,0,1,.9],[1,180,-1.5,.01,.06,.4,.05,.2,0,1,.45],[3,3e3,0,.02,0,.35,.3,.1,0,1,.4,.12]],[[3,5e3,0,.001,0,.02,0,.5,0,1,.5],[0,260,1.5,.005,.06,.12,0,.25,0,1,.4,.02],[2,1040,.5,.003,.03,.18,.01,1,0,1,.25,.1]],[[2,523,0,.003,.03,.1,0,1,0,1,.4],[2,659,0,.003,.03,.1,0,1,0,1,.4,.07],[2,880,0,.003,.05,.2,.01,1,0,1,.45,.14]],[[0,190,-3,.001,0,.04,0,.6,0,1,.6],[3,6e3,0,.001,0,.02,0,.5,0,1,.5]]],ut=[K.WIND,K.SCRAPE],dt=(e,t=lt)=>{let n=t[e].map((t,n)=>[ct(t,e*9+n),Math.round((t[11]??0)*st)]);return Float32Array.from({length:Math.max(...n.map(([e,t])=>t+e.length))},(e,t)=>Math.tanh(n.reduce((e,[n,r])=>e+(n[t-r]??0),0)))},ft=(e,t=st/10)=>{let n=e.length-t;return Float32Array.from({length:n},(r,i)=>i<t?e[i]*Math.sqrt(i/t)+e[n+i]*Math.sqrt(1-i/t):e[i])},pt=st*60/108,mt=pt/4,ht=4,gt=[2,150,-6,.002,0,.25,0,1,0,1,1],_t=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],vt=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],yt=()=>{let e=new Float32Array(pt*4*ht),t={},n=(n,r)=>(t[String(r)]??=ct(r,1)).forEach((t,r)=>e[(n*mt+r)%e.length]+=t),r=e=>55*2**(e/12),i=[0,0,-4,-5],a=[0,0,12,0,0,7,12,7];for(let e=0;e<64;e++){let t=e%16;if(`x.......x.x.....`[t]==`x`&&n(e,gt),`....x.......x...`[t]==`x`&&n(e,_t),t%2==0){n(e,vt);let o=i[e>>4]+a[t>>1];n(e,[1,r(o),0,.005,.08,.18,0,.15,0,1,.6])}}[15,12,10,19,17,15].forEach((e,t)=>n([18,24,28,50,54,60][t],[2,r(e+24),0,.02,.1,.6,.01,1,0,1,.5]));let o=e.reduce((e,t)=>Math.max(e,Math.abs(t)),0);return e.map(e=>e/o*.35)},bt=40,xt=24,St=.5,Ct=`tiny-fps:muted`,wt=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},loop:()=>({set:()=>{}}),mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},Tt=(e=lt)=>{let t;try{t=new AudioContext}catch{return wt()}let n=(e,n=1)=>{let r=t.createGain();return r.gain.value=n,r.connect(e),r},r=n(t.destination),i=n(r,St),a=[],o=!1,s=/* @__PURE__ */ new Set,c=[0,0,0],l=0,u=!1,d=e=>{let n=t.createBuffer(1,e.length,st);return n.getChannelData(0).set(e),n},f=e=>{let n=t.createBufferSource();return n.buffer=e,n};return{unlock(){if(t.resume().catch(()=>{}),!o){o=!0,e.forEach((t,n)=>{let r=dt(n,e);a[n]=d(ut.includes(n)?ft(r):r)});let t=f(d(yt()));t.loop=!0,t.connect(i),t.start()}},listen(e,t){[c,l]=[e,t]},play(e,i,o=1,u=1){let d=0,p=o;if(i){let[e,t,n]=i.map((e,t)=>e-c[t]),r=Math.hypot(e,t,n);p=Math.max(0,1-r/bt)**2*o,d=(e*Math.cos(l)-n*Math.sin(l))/Math.max(r,1)}let m=a[e];if(!m||!p)return;if(s.size>=xt){let e=[...s].reduce((e,t)=>t.vol<e.vol?t:e);if(e.vol>=p)return;e.src.stop(),s.delete(e)}let h=f(m);h.playbackRate.value=u;let g=t.createStereoPanner();g.pan.value=d,h.connect(g).connect(n(r,p));let _={vol:p,src:h};s.add(_),h.onended=()=>s.delete(_),h.start()},loop(e){let i,o;return{set(s,c){!i&&a[e]&&(i=f(a[e]),i.loop=!0,i.connect(o=n(r,0)),i.start()),i&&(o.gain.setTargetAtTime(s,t.currentTime,.08),i.playbackRate.setTargetAtTime(c,t.currentTime,.08))}}},mute(e){u=e,r.gain.setTargetAtTime(+!e,t.currentTime,.05)},get muted(){return u},destroy:()=>void t.close().catch(()=>{})}},Et=()=>{try{return localStorage.getItem(Ct)==`1`}catch{return!1}},Dt=e=>{e.mute(!e.muted);try{localStorage.setItem(Ct,e.muted?`1`:`0`)}catch{}return e.muted},q=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Ot=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],kt=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],At=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n],jt=e=>{let t=Math.hypot(...e)||1;return[e[0]/t,e[1]/t,e[2]/t]},Mt=(e,t,n=0)=>{let[r,i,a,o,s,c]=[e,t,n].flatMap(e=>[Math.sin(e),Math.cos(e)]),l=[i,0,-r],u=[r*a,o,i*a];return[l.map((e,t)=>e*c-u[t]*s),u.map((e,t)=>e*c+l[t]*s),[-r*o,a,-i*o]]},Nt=(e,t,n=[0,0,0])=>{let r=[],i=e.filter((t,n)=>!n||Math.hypot(t[0]-e[n-1][0],t[1]-e[n-1][1])>1e-9),a=i.slice(1).map(([e,t],n)=>{let[r,a]=i[n],o=Math.hypot(e-r,t-a);return[(t-a)/o,-(e-r)/o]}),o=i.map(([e],t)=>{let[n,r]=[0,1].map(e=>(a[t-1]?.[e]??0)+(a[t]?.[e]??0)),i=Math.hypot(n,r);return e?[n/i,r/i]:[0,Math.sign(r)]}),s=(e,a)=>{let[s,c]=i[a],[l,u]=[Math.cos(e*U/t),Math.sin(e*U/t)];r.push(n[0]+s*l,n[1]+s*u,n[2]-c,o[a][0]*l,o[a][0]*u,-o[a][1])};for(let e=1;e<i.length;e++)for(let n=0;n<t;n++)[...i[e-1][0]?[[n,e-1],[n+1,e-1],[n+1,e]]:[],...i[e][0]?[[n,e-1],[n+1,e],[n,e]]:[]].forEach(([e,t])=>s(e,t));return r},Pt=(e,t,n,[r,i],a)=>{let o=(e,t,n,r)=>Array.from({length:t},(i,a)=>{let o=a*U/t/4;return[e*Math.sin(o),n-r*e*Math.cos(o)]});return Nt([...r?o(t[0],r,0,1):[[0,0]],...t.map((n,r)=>[n,e*r/(t.length-1)]),...i?o(t[t.length-1],i,e,-1).reverse():[[0,e]]],n,a)},Ft=(e,[t,n,r])=>Array.from({length:e.length*(10/6)},(i,a)=>{let[o,s]=[Math.floor(a/10),a%10];return s<6?e[o*6+s]:[t,n,-1,r][s-6]}),It=[[5,1],[7,2],[10,3]],Lt=/* @__PURE__ */ new Map,Rt=(e,t,n,r=[1,1])=>{let[i,a]=It[e];!e&&n.length>3&&(n=[n[0],n[n.length>>1],n[n.length-1]]);let o=`${e} ${t} ${n} ${r}`,s=Lt.get(o);return s||(s=Ft(Pt(t,n,i,r.map(e=>Math.ceil(a*e))),[1,1,1]),Lt.set(o,s)),s},zt=(e,t,n,[r,i,a],o,s,c=[1,1,1])=>{let[l,u,d]=typeof s==`number`?[s,s,s]:s,f=l==u&&u==d,[p,m,h,g,_,v,y,b,x]=[...r,...i,...a],S=n[0]+p*o[0]+g*o[1]+y*o[2],C=n[1]+m*o[0]+_*o[1]+b*o[2],w=n[2]+h*o[0]+v*o[1]+x*o[2];for(let n=0;n<t.length;n+=10){let[r,i,a]=[t[n]*l,t[n+1]*u,t[n+2]*d],[o,s,T]=[t[n+3],t[n+4],t[n+5]];if(!f){[o,s,T]=[o/l,s/u,T/d];let e=Math.sqrt(o*o+s*s+T*T)||1;[o,s,T]=[o/e,s/e,T/e]}e.push(S+p*r+g*i-y*a,C+m*r+_*i-b*a,w+h*r+v*i-x*a,p*o+g*s-y*T,m*o+_*s-b*T,h*o+v*s-x*T,t[n+6]*c[0],t[n+7]*c[1],t[n+8],t[n+9]*c[2])}},Bt=(e,t)=>{let n=e[0]*t[0]+e[1]*t[1]+e[2]*t[2],r=t.map((t,r)=>t-e[r]*n),i=Math.hypot(...r)||1,[a,o,s]=r.map(e=>e/i);return[[a,o,s],[o*e[2]-s*e[1],s*e[0]-a*e[2],a*e[1]-o*e[0]],e]},Vt=(e,t,n,r,i,a,o=1,s)=>{let c=[r[0]-n[0],r[1]-n[1],r[2]-n[2]],l=Math.hypot(...c)||1,[u,d]=typeof o==`number`?[o,o]:o;zt(e,t,n,Bt([c[0]/l,c[1]/l,c[2]/l],i),[0,0,0],[u,d,l/a],s)},Ht=2.4,Ut=[1,.62],Wt=8,Gt=28,Kt=2.2,qt=.04,Jt=.045,Yt=e=>{let t=parseInt(u[e].slice(1),16);return[t>>16,t>>8&255,t&255].map(e=>e/255)},Xt=(e,t,n)=>e.flatMap((e,r)=>{if(e.state===m.DROPPED)return[{team:r,at:[e.x,e.y,e.z],dropped:!0}];if(e.state===m.CARRIED){let t=n(e.by);return t?[{team:r,at:[t.x,t.y,t.z],by:{yaw:t.yaw,vx:t.vx,vz:t.vz}}]:[]}return[{team:r,at:t[r]}]}),Zt=[[1,0,0],[0,1,0],[0,0,1]],Qt=(e,t,n)=>{for(let r=t;r<e.length;r+=10)e[r+6]*=n,e[r+7]*=n,e[r+9]*=n,e[r+8]=-2},$t=(e,t,n,r,[i,a,o])=>{let[s,c,l]=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],[u,d,f]=[r[0]-t[0],r[1]-t[1],r[2]-t[2]],p=[c*f-l*d,l*u-s*f,s*d-c*u],m=Math.hypot(...p)||1;for(let s of[t,n,r])e.push(...s,p[0]/m,p[1]/m,p[2]/m,i,a,-1,o)},en=(e,t,n,r,i)=>{for(let a=0;a<Gt;a++){let[o,s]=[a,a+1].map(e=>e*2*Math.PI/Gt),c=(e,n)=>[t[0]+e*Math.cos(n),t[1],t[2]+e*Math.sin(n)];$t(e,c(n,o),c(r,s),c(r,o),i),$t(e,c(n,o),c(n,s),c(r,s),i)}},tn=(e,t,n,r)=>{for(let i=0;i<Gt;i++){let[a,o]=[i,i+1].map(e=>e*2*Math.PI/Gt);$t(e,t,[t[0]+n*Math.cos(o),t[1],t[2]+n*Math.sin(o)],[t[0]+n*Math.cos(a),t[1],t[2]+n*Math.sin(a)],r)}},nn=(e,t,n,r)=>{tn(e,[t[0],t[1]+qt,t[2]],d,n.map(e=>e*.4));let i=e.length;en(e,[t[0],t[1]+Jt,t[2]],d-.16,d,n),Qt(e,i,Kt*(.75+.25*Math.sin(r*3)))},rn=(e,t,n,[r,i],a,o,s)=>{let c=[-n[2],0,n[0]],l=(e,s)=>{let l=a*e*Math.sin(o*7-e*5),u=i*s*(1-e);return[t[0]+n[0]*r*e+c[0]*l,t[1]-u+.12*r*e*Math.sin(o*5-e*4)*a,t[2]+n[2]*r*e+c[2]*l]};for(let t=0;t<Wt;t++){let[n,r]=[t/Wt,(t+1)/Wt],[i,a,o,c]=[l(n,0),l(r,0),l(r,1),l(n,1)],u=[(a[1]-i[1])*(c[2]-i[2])-(a[2]-i[2])*(c[1]-i[1]),(a[2]-i[2])*(c[0]-i[0])-(a[0]-i[0])*(c[2]-i[2]),(a[0]-i[0])*(c[1]-i[1])-(a[1]-i[1])*(c[0]-i[0])],d=Math.hypot(...u)||1,f=(e,t)=>[e[0]+u[0]/d*.004*t,e[1]+u[1]/d*.004*t,e[2]+u[2]/d*.004*t];for(let t of[1,-1]){let n=[i,a,o,c].map(e=>f(e,t)),[r,l,u,d]=t>0?n:[n[0],n[3],n[2],n[1]];$t(e,r,l,u,s),$t(e,r,u,d,s)}}},an=(e,t,n,r)=>{Vt(e,Rt(1,1,[1,1],[0,0]),t,n,[.6,0,.8],1,.045,[.82,.84,.9]);let i=e.length;zt(e,Rt(1,0,[1,1]),n,Zt,[0,0,0],.09,r),Qt(e,i,Kt)},on=(e,t,n,r)=>{let[i,a,o]=t.at,s=r+t.team*1.7;if(t.by){let{yaw:r,vx:c,vz:l}=t.by,u=-Math.sin(r),d=-Math.cos(r),f=Math.hypot(c,l),p=[i-u*.28,a+.55,o-d*.28],m=[i-u*.38,a+.55+Ht-.2,o-d*.38],[h,g]=f>1?[-c/f,-l/f]:[-u,-d];an(e,p,m,n);let _=Math.min(1,f/8);rn(e,m,[h,0,g],[Ut[0]*(.7+.5*_),Ut[1]],.1+.16*_,s,n);return}if(t.dropped){let t=i*12.9898+o*78.233,[c,l]=[Math.cos(t),Math.sin(t)],u=[i+c*2.3,a+.6,o+l*2.3];an(e,[i,a+.06,o],u,n),rn(e,u,[c,0,l],[Ut[0]*.8,Ut[1]*.8],.04,s,n);let f=e.length;en(e,[i,a+Jt,o],d-.1,d,n),Qt(e,f,Kt*(.5+.5*Math.abs(Math.sin(r*5))));return}let c=[i,a+Ht,o];an(e,[i,a,o],c,n);let l=.6+t.team*Math.PI;rn(e,c,[Math.cos(l),0,Math.sin(l)],Ut,.18,s,n)},sn={SPOT:0,POINT:1},cn=9,ln=6,un=e=>{let{ctf:t,t:n}=e;if(!t)return[];let r=([e,t,n],r,i,a)=>({kind:sn.POINT,p:[e,t,n],d:[0,-1,0],cone:0,range:i,color:Yt(r).map(e=>e*a),shadow:!1});return[...t.bases.map(([e,t,i],a)=>r([e,t+1.2,i],a,cn,1.1+.3*Math.sin(n*3))),...t.flags.filter(e=>e.dropped).map(e=>r([e.at[0],e.at[1]+.8,e.at[2]],e.team,ln,.9))]},dn=.08,fn=.06,pn=.22,mn=7,hn=[[.022,[.4,.15,1.3],0],[.007,[.7,1.7,2.2],.02]],gn=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],_n=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],vn=e=>{let t=Math.hypot(...e)||1;return[e[0]/t,e[1]/t,e[2]/t]},yn=(e,t,[n,r,i])=>e.push(...t,0,1,0,n,r,-2,i),bn=(e,t,n,r,i,a,o)=>{let s=gn(n,t),c=_n(s,gn(t,a));Math.hypot(...c)<1e-6*Math.hypot(...s)&&(c=_n(s,[0,1,0])),c=vn(c);let[l,u,d,f]=[[t,1],[t,-1],[n,-1],[n,1]].map(([e,t])=>{let n=vn(gn(a,e)),i=r*Math.min(Math.max(Math.hypot(...gn(a,e))/5,1),2.5);return e.map((e,r)=>e+c[r]*i*t+n[r]*o)});for(let t of[l,u,d,l,d,f])yn(e,t,i)},xn=()=>{let e=[],t=[],n=7,r=()=>(n=n*16807%2147483647)/2147483647*2-1;return{mount(t){e.forEach(e=>e.own&&(e.a=t))},shoot(n,i,a,o=!1){if(e.push({a:n,b:i,age:0,hit:a,own:o}),e=e.slice(-16),a){let e=vn(gn(n,i));for(let n=0;n<mn;n++)t.push({p:i,v:[0,1,2].map(t=>e[t]*3+r()*3+(t==1?2:0)),age:0});t=t.slice(-112)}},update(n){for(let r of[...e,...t])r.age+=n;e=e.filter(e=>e.age<dn),t=t.filter(e=>e.age<pn);for(let e of t)e.v[1]-=9*n,e.p=e.p.map((t,r)=>t+e.v[r]*n)},draw(n,r){for(let{a:t,b:i,age:a}of e){let e=1-a/dn;hn.forEach(([a,o,s])=>bn(n,t,i,a*e**.7,o.map(t=>t*(.6+.4*e)),r,s))}for(let{p:e,age:i}of t){let t=1-i/pn,a=vn(_n(gn(e,r),[0,1,0])),o=vn(_n(a,gn(e,r))),[s,c]=[.022*t,.022*t],l=(t,n)=>[e[0]+a[0]*t+o[0]*n,e[1]+a[1]*t+o[1]*n,e[2]+a[2]*t+o[2]*n];for(let e of[l(-s,0),l(0,c),l(s,0),l(-s,0),l(s,0),l(0,-c)])yn(n,e,[1.4*t+.4,2.2*t+.3,3])}},lights(){let t=(e,t,n,r)=>({kind:sn.POINT,p:e,d:[0,-1,0],cone:0,range:t,color:r.map(e=>e*n),shadow:!1});return e.filter(e=>e.age<fn).slice(-3).flatMap(e=>{let n=1-e.age/fn;return[t(e.a,6,1.3*n,[.35,.8,1.5]),...e.hit?[t(e.b,3.5,.9*n,[.3,.7,1.3])]:[]]})},get count(){return e.length}}},Sn=(e,t)=>{if(!e)return[];if(e.over||t.over)return e.over&&!t.over?[{kind:`start`}]:[];let n=[];for(let r of[0,1])t.score[r]>e.score[r]&&n.push({kind:`capture`,team:r});let r=n.length>0;t.flags.forEach((t,i)=>{let a=e.flags[i];t.state===m.CARRIED&&(a.state!==m.CARRIED||a.by!==t.by)?n.push({kind:`take`,flag:i,by:t.by}):t.state===m.DROPPED&&a.state===m.CARRIED?n.push({kind:`drop`,flag:i}):t.state===m.HOME&&(a.state===m.DROPPED||a.state===m.CARRIED&&!r)&&n.push({kind:`return`,flag:i})});for(let r of t.players)r.stun>(e.players.find(e=>e.id===r.id)?.stun??1/0)&&n.push({kind:`tackle`,who:r.id,by:r.by,at:[r.x,r.y+1,r.z]});return n},Cn=(e,t,n)=>{let r=e=>l[e].toLowerCase();switch(e.kind){case`take`:{let i=1-e.flag;return{team:i,text:e.flag===t.team?`${l[i]} took your flag`:e.by===t.id?`You took the ${r(e.flag)} flag`:`${n(e.by)} took the ${r(e.flag)} flag`}}case`drop`:return{team:e.flag,text:e.flag===t.team?`Your flag was dropped`:`${l[e.flag]} flag dropped`};case`return`:return{team:e.flag,text:e.flag===t.team?`Your flag returned`:`${l[e.flag]} flag returned`};case`capture`:return{team:e.team,text:`${l[e.team]} scored`};case`tackle`:return e.by===t.id?{team:t.team,text:`Tackled ${n(e.who)}!`}:void 0;default:return{text:`New match`}}},wn=(e,t)=>{let{team:n}=t;switch(e.kind){case`take`:return[{id:K.TAKE,rate:e.flag===n?.8:1}];case`drop`:return[{id:K.DROP,rate:e.flag===n?1:.85}];case`return`:return[{id:K.RETURN,rate:e.flag===n?1:.85}];case`capture`:return[{id:K.CAPTURE,rate:e.team===n?1:.8}];case`tackle`:return e.who===t.id?[{id:K.TACKLE},{id:K.GRUNT}]:e.by===t.id?[{id:K.TACKLE,gain:.8,rate:1.1}]:[{id:K.TACKLE,at:e.at}];default:return[]}},J={PELVIS:0,SPINE:1,CHEST:2,NECK:3,HEAD:4,CLAVICLE_L:5,ARM_L:6,FOREARM_L:7,HAND_L:8,CLAVICLE_R:9,ARM_R:10,FOREARM_R:11,HAND_R:12,THIGH_L:13,SHIN_L:14,FOOT_L:15,TOE_L:16,THIGH_R:17,SHIN_R:18,FOOT_R:19,TOE_R:20},Tn=Object.keys(J).length,En=[-1,0,1,2,3,2,5,6,7,2,9,10,11,0,13,14,15,0,17,18,19],Dn=[[0,.98,0],[0,.12,0],[0,.2,0],[0,.22,0],[0,.1,0],[-.04,.17,0],[-.15,0,0],[-.03,-.29,0],[0,-.26,0],[.04,.17,0],[.15,0,0],[.03,-.29,0],[0,-.26,0],[-.1,-.05,0],[0,-.44,0],[0,-.43,0],[0,-.04,-.13],[.1,-.05,0],[0,-.44,0],[0,-.43,0],[0,-.04,-.13]],On=[0,0,0,1],kn=(e=[0,0,0],t=0)=>({at:e,yaw:t,hips:[0,0,0],rot:Array.from({length:Tn},()=>[...On])}),Y=([e,t,n,r],[i,a,o,s])=>[r*i+e*s+t*o-n*a,r*a-e*o+t*s+n*i,r*o+e*a-t*i+n*s,r*s-e*i-t*a-n*o],X=([e,t,n],r)=>{let i=Math.sin(r/2);return[e*i,t*i,n*i,Math.cos(r/2)]},An=(e,[t,n,r])=>{let[i,a,o,s]=e,[c,l,u]=[2*(a*r-o*n),2*(o*t-i*r),2*(i*n-a*t)];return[t+s*c+a*u-o*l,n+s*l+o*c-i*u,r+s*u+i*l-a*c]},jn=(e,t,n)=>{let r=e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],i=r<0?-1:1;if(r*=i,r>.9995){let r=e.map((e,r)=>e+(i*t[r]-e)*n),a=Math.hypot(...r);return r.map(e=>e/a)}let a=Math.acos(r),[o,s]=[Math.sin((1-n)*a),Math.sin(n*a)*i],c=1/Math.sin(a);return e.map((e,n)=>(e*o+t[n]*s)*c)},Mn=e=>{let t=[],n=[],r=X([0,1,0],e.yaw);for(let i=0;i<Tn;i++){let a=En[i],o=a<0?r:n[a];n[i]=Y(o,e.rot[i]);let s=An(o,i===0?Dn[0].map((t,n)=>t+e.hips[n]):Dn[i]),c=a<0?e.at:t[a];t[i]=[c[0]+s[0],c[1]+s[1],c[2]+s[2]]}return{pos:t,rot:n}},Nn=(e,t,n,r,i)=>{let a=e[t]-n,o=e[t+1]+r*a,s=Math.exp(-r*i);return e[t]=n+(a+o*i)*s,e[t+1]=(e[t+1]-r*o*i)*s,e[t]},Pn=Math.PI*2,[Z,Fn,In]=[[1,0,0],[0,1,0],[0,0,1]],[Ln,Rn,zn]=[.44,.43,.06],[Bn,Vn]=[.2915,.26],Hn=Ln+Rn,Q=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Un=e=>(e=Q(e))*e*(3-2*e),Wn=(e,t)=>Math.atan2(Math.sin(t-e),Math.cos(t-e)),Gn=e=>[-e[0],-e[1],-e[2],e[3]],Kn=(e,t)=>{let n=Math.sin(e*78.233+t*37.719)*43758.5453;return n-Math.floor(n)},qn=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],Jn=(e,t,n,r=0)=>e.map((e,i)=>e*t+n[i]*r),Yn=e=>Jn(e,1/(Math.hypot(...e)||1),e),Xn=(e,t)=>Jn(e,1,t,-(e[0]*t[0]+e[1]*t[1]+e[2]*t[2])),Zn=(e,t,n)=>{let r=Math.max(n-Math.abs(e-t),0)/n;return Math.min(e,t)-r*r*n/4},Qn=(e,t)=>{let n=[-t[0],-t[1],-t[2]],r=qn(e,n),i=[e[0]+n[1]+r[2],e[0]-n[1]-r[2],n[1]-e[0]-r[2],r[2]-e[0]-n[1]],a=i.indexOf(Math.max(...i)),[o,s,c,l]=[1+i[a],n[2]-r[1],r[0]-e[2],e[1]-n[0]],[u,d,f]=[n[0]+e[1],r[0]+e[2],r[1]+n[2]],p=[[s,c,l,o],[o,u,d,s],[u,o,f,c],[d,f,o,l]][a],m=Math.hypot(...p);return p.map(e=>e/m)},$n=(e,t,n,r=Ln,i=Rn,a=1)=>{let o=Jn(t,1,e,-1),s=Math.hypot(...o)||1e-6,c=Q(s,.2,(r+i)*.999),l=Jn(o,1/s,o),u=Yn(Xn(n,l)),d=Q((r*r+c*c-i*i)/(2*r*c),-1,1),f=Jn(l,d,u,Math.sqrt(1-d*d)),p=Yn(Jn(l,c,f,-r)),m=Jn(qn(l,u),a,l);return[Qn(m,f),Qn(m,p)]},er=e=>{let[t,n]=[Math.abs(e),e>0?.07:.13],[r,i]=[Math.sin(t),Math.cos(t)];return[(e>0?-1:1)*(n*(1-i)+zn*r),zn*(i-1)+n*r]},tr=[1.4,5,9],nr={f:[.95,1.4,1.8],s:[.88,.95,1],k:[.45,.42,.4],lat:[.11,.09,.07],lift:[.09,.3,.4],d0:[.002,.01,.01],d1:[.008,.075,.05],td:[.12,.1,-.12],to:[-.45,-.6,-.8],pr:[.07,.1,.14],po:[.06,.06,.05],pt:[.04,.1,.16],pa:[.02,.05,.06],cc:[.1,.16,.22],aa:[.35,.8,1],am:[-.05,.12,.25],em:[.3,1.4,1.75],ea:[.12,.25,.3],ab:[.1,.12,.1],sw:[.025,.012,.008],hop:[0,.02,.025]},$={AIR:0,RISE:1,DASH:2,WALL_L:3,WALL_R:4,HANG:5,CLIMB:6,SLIDE:7,STUN:8,TUCK:9,DOWN:10},rr=[[-.05,.12,0,.35,.5,.15,.7,.25,.5,.25,.5,1.15,0,0],[0,.1,0,1.2,1.5,-.35,.3,2.4,.3,2.2,.3,.35,0,0],[-.35,1.25,0,1.1,1.3,-.6,.25,-1,.3,-1,.3,.25,0,0],[],[-.02,.2,.4,.9,1.2,.6,1.3,.8,1,.3,.5,.6,0,.1],[.07,.05,0,.2,.3,.1,.2,3,.2,3,.2,.2,-.22,0],[0,.5,0,.2,.4,1.4,1.7,1,1.4,1,1.4,.15,-.1,0],[-.78,-1.1,0,1.1,1.8,1.4,.1,.5,.8,.4,.5,.8,0,0],[0,0,0,0,0,0,0,.8,1.6,.8,1.6,.2,0,0],[-.05,.9,0,1.7,2,1.7,2,.8,1.6,.8,1.6,.2,0,0],[-.5,.35,0,1.3,.3,1.1,.2,.4,.4,.2,.3,.6,0,0]],ir=rr[$.WALL_R];rr[$.WALL_L]=[ir[0],ir[1],-ir[2],ir[5],ir[6],ir[3],ir[4],ir[9],ir[10],ir[7],ir[8],ir[11],ir[12],-ir[13]];var ar=[J.PELVIS,J.SPINE,J.CHEST,J.ARM_L,J.FOREARM_L,J.ARM_R,J.FOREARM_R,J.THIGH_L,J.SHIN_L,J.FOOT_L,J.TOE_L,J.THIGH_R,J.SHIN_R,J.FOOT_R,J.TOE_R],or=e=>{let t=[],[n,r,i]=[e[1],e[2],e[11]];return t[J.PELVIS]=Y(X(In,r*.4),X(Z,-.3*n)),t[J.SPINE]=Y(X(In,r*.3),X(Z,-.35*n)),t[J.CHEST]=t[J.SPINE],t[J.ARM_L]=Y(X(In,-i),X(Z,e[7])),t[J.FOREARM_L]=X(Z,e[8]),t[J.ARM_R]=Y(X(In,i),X(Z,e[9])),t[J.FOREARM_R]=X(Z,e[10]),[J.THIGH_L,J.THIGH_R].forEach((r,i)=>{t[r]=X(Z,e[3+2*i]+.3*n),t[r+1]=X(Z,-e[4+2*i]),t[r+2]=X(Z,-.35),t[r+3]=sr}),t},sr=[0,0,0,1],cr=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],[lr,ur,dr,fr,pr,mr,hr,gr,_r,vr,yr,br]=[0,2,4,6,8,10,12,14,16,18,20,22],xr=5,Sr=.1,Cr=()=>{let e=kn(),t={},n=Array(br+2*rr.length).fill(0),r=[0,1].map(()=>({x:0,y:0,z:0,px:0,pz:0,gy:0,lx:0,ly:0,lz:0,dl:0,tg:0,u:0,x0:0,w:0,th:0,tw:1,on:!0})),i={},a=!1,[o,s,c,l,u,d,f]=[0,0,0,0,0,0,0],[p,m,h,_,v]=[0,0,0,.6,0],[y,b,x,S]=[!1,!0,!0,-1],C=[1,1,1,0,.06,0],[w,T,E]=[0,0,[0,0,0]],[D,O,k,A]=[1,[1,0],[0,0,0,-1,0],!1],j=(e,j,M)=>{j=Q(j,0,.1),b=!a||Math.hypot(e.x-i.x,e.y-i.y,e.z-i.z)>xr;let ee=e.mode==g.GROUND||e.mode==g.CROUCH,N=e.mode==g.AIR,P=(e,t,r)=>{b?[n[e],n[e+1]]=[t,0]:Nn(n,e,t,r,j)};P(mr,e.vx,12),P(hr,e.vz,12);let[F,I]=[n[mr],n[hr]];l=Math.sqrt(F*F+I*I);let L=l>1?Math.atan2(-F,-I):e.yaw;if(b){let t=e.id;C=[1+.08*(Kn(t,0)-.5),1+.16*(Kn(t,1)-.5),1+.16*(Kn(t,2)-.5),.03*(Kn(t,3)-.5),.05+.04*Kn(t,4),Kn(t,6)],o=l>.25?Kn(t,5):Kn(t,5)<.5?.05:.55,[s,c,h,p,m,y,S]=[0,0,0,0,0,!1,-1],f=L,d=e.yaw}else N&&i.mode==g.AIR&&e.jumps<i.jumps&&e.vy>i.vy&&(h=.001),N?m=Math.min(m,e.vy):(i.mode==g.AIR&&(ee||e.mode==g.SLIDE)&&m<-3&&(p=Q(-m/12,.3)),m=0),h&&=(h+=j*(N?2.2:8),h>=1?0:h);c+=j,p*=Math.exp(-j*7);let R=cr[e.wall],z=e.mode==g.WALLRUN,B=e.mode==g.HANG||e.mode==g.CLIMB;z&&([D,O]=[R[0]*Math.cos(L)-R[1]*Math.sin(L)<0?-1:1,R]),B&&e.wall&&(d=Math.atan2(-R[0],-R[1]),e.mode!=g.HANG&&A||(k=[e.x,e.z,R[0],R[1],0]),k[4]=e.edge),A=B,[N,N&&e.vy>.5,e.dash>50,z&&D<0,z&&D>0,e.mode==g.HANG,e.mode==g.CLIMB,e.mode==g.SLIDE,e.stun>0,h&&Math.sqrt(Math.sin(Math.PI*h))].forEach((e,t)=>P(br+2*t,+e,12)),P(br+2*$.DOWN,+(e.down>0),5),P(pr,+(e.mode==g.CROUCH),12),P(_r,B?Q((1.7-k[4]+e.y)/1.2):0,14),P(fr,p,26);let te=b||l<2?0:Wn(f,L)/Math.max(j,.001);f=L;let ne=b?0:-((e.vx-i.vx)*Math.sin(u)+(e.vz-i.vz)*Math.cos(u))/Math.max(j,.001),V=-(F*Math.sin(u)+I*Math.cos(u)),re=Math.sign(V)*Q((Math.abs(V)-1.5)*.028,0,.22);P(lr,(V>0?re:re/2)+Q(ne*.012,-.3,.3),7),P(ur,Q(.3*Math.atan(l*te/9.8),-.4,.4),8),P(dr,.5*Math.sin(Wn(e.yaw,L))*Q(l/2),10);let H=e=>n[br+2*e],U=Q(H($.DASH)+H($.WALL_L)+H($.WALL_R)+H($.SLIDE)),ie=e.yaw+Wn(e.yaw,L)*U;u=ie+Wn(ie,d)*Q(H($.HANG)+H($.CLIMB)),u+=n[dr]*(1-U);let[ae,oe]=[Math.cos(u),Math.sin(u)];P(vr,e.stun>0?Q(-(e.vx*oe+e.vz*ae)/4.2,-1,1):0,18),P(yr,e.stun>0?Q((e.vx*ae-e.vz*oe)/4.2,-1,1):0,18),[w,T,E]=[e.yaw,e.pitch,[e.x,e.y,e.z]];let se=l<tr[1]?0:1,ce=Q((l-tr[se])/(tr[se+1]-tr[se]));for(let e in nr){let n=nr[e];t[e]=n[se]+(n[se+1]-n[se])*ce}v=Un((l-.2)/1.2);let le=t.f*C[0]*(.35+.65*Q(l/1.4))*(1+.5*H($.STUN));_=Q(t.s*le/Math.max(l,.1),.2,.62);let[ue,de]=[Math.cos(u),-Math.sin(u)],W=(t,n)=>{let r=M?M(t,n):e.y;return Math.abs(r-e.y)<.6?r:e.y},fe=l<=.25,pe=ee&&(!fe||!r[0].on||!r[1].on);(pe||z)&&(o=(o+(fe&&!z?.9:le)*j)%1),r.forEach((n,a)=>{let c=a?1:-1,l=(o+a/2)%1,[d,f]=[e.x+ue*c*Sr,e.z+de*c*Sr],p=u-c*C[4],[m,h]=[-Math.sin(p),-Math.cos(p)];if(ee){if(y||([n.px,n.pz,n.gy,n.on]=[d,f,W(d,f),!0],b&&([n.x,n.y,n.z,n.th,n.tw]=[d,n.gy+zn,f,0,1])),n.on&&pe&&(l>=_||Math.hypot(n.x-d,n.z-f)>.56))[n.on,n.lx,n.ly,n.lz,n.dl]=[!1,n.x-e.x,n.y,n.z-e.z,l];else if(!n.on&&l<n.u){let[e]=er(t.td*v);[n.on,n.px,n.pz,n.gy]=[!0,n.x-m*e,n.z-h*e,n.tg],s++}if(n.u=l,n.on){if(fe&&r[0].on&&r[1].on){let e=1-Math.exp(-8*j);n.px+=(d-n.px)*e,n.pz+=(f-n.pz)*e,n.gy+=(W(d,f)-n.gy)*e}n.x0=Q(l/_),n.th=v*(t.td*(1-Un(n.x0/.25))+t.to*Un((n.x0-.55)/.45));let[e,i]=er(n.th);[n.x,n.y,n.z]=[n.px+m*e,n.gy+zn+i,n.pz+h*e],n.w=1-v*(1-Un(Math.min(n.x0,1-n.x0)/.12)),n.tw=Un(n.x0*10)}else{let r=Q((l-n.dl)/(1-n.dl+1e-6)),[i,a]=[t.k*_/le,(1-l)/le+t.k*_/le],[o,s]=[F*i+ue*c*t.lat,I*i+de*c*t.lat];n.tg=W(e.x+F*a+ue*c*t.lat,e.z+I*a+de*c*t.lat);let[u,d]=[t.td*v,t.to*v],f=Un((r-.12)/.78);n.x=e.x+n.lx+(o-n.lx)*f,n.z=e.z+n.lz+(s-n.lz)*f,n.y=n.ly+(n.tg+zn+er(u)[1]-n.ly)*Un(r*1.5)+t.lift*Math.sin(Math.PI*r**.6),n.th=d+(u-d)*Un(r)+.15*Math.sin(Math.PI*r),n.tw=1-Un(r*4),n.w=0}}else{let t=b?0:Math.exp(-10*j),r=b?[0,0,0]:[n.x-i.x,n.y-i.y,n.z-i.z];n.x=e.x+r[0]*t+(d-e.x)*(1-t),n.y=e.y+r[1]*t+zn*(1-t),n.z=e.z+r[2]*t+(f-e.z)*(1-t),[n.th,n.tw,n.w,n.on,n.u]=[n.th*t,n.tw*t,0,!1,l]}}),y=ee,x=!0,Object.assign(i,e),a=!0},M=()=>{let t=e=>n[br+2*e],{rot:r}=e,[i,a]=[Math.cos(u),Math.sin(u)],s=(e,t,n,r=E)=>[r[0]+e*i+n*a,t,r[2]+n*i-e*a],c=(e,t,n)=>s(e,t,n,[0,0,0]),l=[],{pos:d,rot:f}=Mn(e),p=d[J.PELVIS],m=e=>e<0?J.HAND_L:J.HAND_R,h=e=>e<0?J.FOOT_L:J.FOOT_R,g=Y(X(Fn,u),X(Z,-.2)),_=Q(t($.HANG)+t($.CLIMB));if(_>.002){let[r,i,a,o,s]=k,u=.4+.14*n[_r],f=[-1,1].map(e=>{let t=d[m(e)-2],n=Math.max(u,(t[0]-r)*a+(t[2]-i)*o),c=[r+a*n-o*e*.21,s+.03,i+o*n+a*e*.21],l=(t[0]-c[0])**2+(t[2]-c[2])**2;return[c,t[1]-c[1]-Math.sqrt(Math.max(((Bn+Vn)*.97)**2-l,0))]}),g=_**4*Q(Math.max(...f.map(e=>e[1])));e.at[1]-=g,d.forEach(e=>e[1]-=g),[-1,1].forEach((e,t)=>l.push([m(e),_,f[t][0],c(e*.8,0,.6),Qn([0,e,0],[a,0,o])]));let v=(p[0]-r)*a+(p[2]-i)*o,y=Math.max(.58,v+.45);[-1,1].forEach(e=>l.push([h(e),t($.CLIMB)*Q(e<0?(v-.25)*4:n[_r]*2-.4),[r+a*y-o*e*.1,s+zn,i+o*y+a*e*.1],[a,.5,o],Qn([-o,0,a],[0,-1,0])]))}[-1,1].forEach(e=>{let n=t(e<0?$.WALL_L:$.WALL_R);if(n>.002){let[t,r]=O;[e,-e].forEach((i,a)=>{let d=(o+.5*a)%1,f=d<.55,_=f?d/.55:(d-.55)/.45,v=f?0:Math.sin(Math.PI*_),y=(f?2*_-1:1-2*Un(_))*(a?.4:.3);l.push([h(i),n,a?s(-e*.12,p[1]-.7+.4*v,y):s(e*(.34-.2*v),p[1]-.52+.3*v,y),c(-e*.7,1,-1),a?Y(X(Fn,u),X(Z,-.5)):jn(g,Qn(qn([t,0,r],c(0,0,-1)),[t,0,r]),1-v)]);let b=Math.cos(Pn*(o+.5*(1-a)));l.push([m(i),n,a?s(-e*.5,p[1]+.3+.12*b,.2*b):s(e*.37,p[1]+.3+.05*b,.1*b),c(a?-e*.7:0,a?0:-.5,.7),Qn(a?[0,i,0]:[-i*t,0,-i*r],c(0,0,-1))])})}});let v=t($.SLIDE);if(v>.002){let e=E[1];l.push([J.FOOT_R,v,s(.12,e+zn+.14,-.85,p),c(.1,1,-.3),g],[J.FOOT_L,v,s(-.2,e+zn,-.3,p),c(-.4,1,-.1),g],[J.HAND_L,v,s(-.4,e+.03,.4,p),c(-.7,0,.7),Qn([0,-1,0],c(-1,0,0))])}l.forEach(([e,t,n,i,a])=>{let[o,s,c]=[e-2,e<J.THIGH_L,t*t],l=Jn(Jn(d[o+1],1,d[o],-1),1,An(f[o],[0,0,s?1:-1]),.05),[u,p]=[Jn(d[e],1-c,n,c),e=>Yn(Jn(e,1,d[o],-1))],m=Jn(Yn(Xn(l,p(d[e]))),1-c,Yn(Xn(i,p(n))),c),[h,g]=s?$n(d[o],u,m,Bn,Vn,-1):$n(d[o],u,m),_=s?Y(h,X(In,o==J.ARM_L?.1:-.1)):h;r[o]=Y(Gn(f[En[o]]),_),r[o+1]=Y(Gn(_),g),r[e]=jn(r[e],Y(Gn(g),a),c)})},ee=()=>{let{rot:i}=e,a=v,s=e=>n[br+2*e],[l,d,f,p,m]=[n[lr],n[ur],n[dr],n[fr],n[pr]],[g,y]=[Math.cos(Pn*o),Math.cos(2*Pn*o)],b=Math.cos(Pn*(o-(1+_)/2)),D=t.po*a*b,O=t.pt+C[3]+t.pa*a*y,k=(t.cc+t.pr)*a*g,A=1-a,j=A*.012*Math.sin(Pn*.28*c),ee=A*.012*Math.sin(Pn*.17*c+C[1]*9),N=t.sw*a*b+ee;e.at[0]=E[0],e.at[1]=E[1],e.at[2]=E[2],e.yaw=u,i[J.PELVIS]=Y(Y(X(Fn,-t.pr*a*g),X(In,D+.4*d)),X(Z,-(O+.25*l+.3*m+.5*p)));let P=O+.25*l-l-.7*m-.8*p;i[J.SPINE]=Y(Y(X(Fn,.4*k-.25*f),X(In,.25*d-.8*D+.5*ee)),X(Z,.45*P+j*.5)),i[J.CHEST]=Y(Y(X(Fn,.6*k-.25*f),X(In,.25*d-.8*D-.5*ee)),X(Z,.55*P+j)),[-1,1].forEach(e=>{let n=Math.cos(Pn*(o-(e<0?.5:0))),r=C[e<0?1:2];i[e<0?J.ARM_L:J.ARM_R]=Y(X(In,e*(.06+t.ab*a+.5*p)),X(Z,(t.am+t.aa*r*n)*a+.05*A*e*Math.sin(c*1.3)+p+.5*m)),i[e<0?J.FOREARM_L:J.FOREARM_R]=X(Z,.15*A+a*(t.em+t.ea*n)+p+.5*m)});let F=X(Fn,u),I=Y(F,i[J.PELVIS]),[L,R]=[Math.cos(u),-Math.sin(u)],z=[E[0]+L*N,0,E[2]+R*N],B=[J.THIGH_L,J.THIGH_R].map(e=>An(I,Dn[e])),te=1-.25*m-.7*p,ne=E[1]+.05+zn+Hn*(te-t.d0-.6*t.d1*a)+t.hop*a*(.5-.5*Math.cos(2*Pn*o-2*Pn*_/2)),V=r.map((e,n)=>{let[r,i]=[e.x-z[0]-B[n][0],e.z-z[2]-B[n][2]],o=t.d0+t.d1*a*Math.sin(Math.PI*e.x0)+1-te,s=Math.min(Hn*(1-o),Hn*.99),c=e.y+Math.sqrt(Math.max(s*s-r*r-i*i,.04));return ne+(c-B[n][1]-ne)*e.w}),re=Zn(V[0],V[1],.05),H=c-S;S=c,H>.1?[n[gr],n[gr+1]]=[re,0]:Nn(n,gr,re,30,H),z[1]=Math.min(re,n[gr]),e.hips=[N,z[1]-E[1]-Dn[0][1],0],r.forEach((e,t)=>{let n=t?1:-1,r=[z[0]+B[t][0],z[1]+B[t][1],z[2]+B[t][2]],a=u-n*C[4],[o,s]=$n(r,[e.x,e.y,e.z],[-Math.sin(a),0,-Math.cos(a)]),c=t?J.THIGH_R:J.THIGH_L;i[c]=Y(Gn(I),o),i[c+1]=Y(Gn(o),s),i[c+2]=Y(Gn(s),Y(X(Fn,a),X(Z,e.th))),i[c+3]=X(Z,e.th<0?-e.th*e.tw:0)}),rr.forEach((t,n)=>{let r=s(n);if(r>.002){let a=or(t),o=n==$.STUN;ar.slice(o?3:0,o?7:15).forEach(e=>i[e]=jn(i[e],a[e],r)),o||[t[13],t[0],t[12]].forEach((t,n)=>e.hips[n]+=(t-e.hips[n])*r)}}),h&&(i[J.PELVIS]=Y(X(Z,-Pn*(3-2*h)*h*h),i[J.PELVIS]));let U=s($.HANG);if(U>.002){let[t,n]=[.01*Math.sin(Pn*(.3*c+C[5])),.006*Math.sin(Pn*(.2*c+3*C[5]))].map(e=>e*U);i[J.PELVIS]=Y(Y(X(In,n),X(Z,t)),i[J.PELVIS]),[J.THIGH_L,J.THIGH_R].forEach(e=>i[e]=Y(i[e],X(Z,t))),e.hips[0]+=n,e.hips[2]-=t}let ie=s($.STUN);if(ie){[J.SPINE,J.CHEST].forEach((e,t)=>{let r=.3+.1*t;i[e]=Y(i[e],Y(X(In,-r*n[yr]),X(Z,-r*n[vr])))});let e=Math.sin(c*13);[J.ARM_L,J.ARM_R].forEach((t,n)=>i[t]=Y(i[t],X(Z,ie*(n?e:-e)))),i[J.CHEST]=Y(i[J.CHEST],X(Fn,.3*ie*Math.sin(c*8)))}M();let ae=Un((s($.DOWN)-.35)/.65);ae&&(i[J.PELVIS]=Y(X(Z,-1.45*ae),i[J.PELVIS]),e.hips[1]+=(.17-Dn[0][1]-e.hips[1])*ae,[J.THIGH_L,J.THIGH_R].forEach(e=>i[e]=Y(i[e],X(Z,-1.25*ae))),[J.ARM_L,J.ARM_R].forEach(e=>i[e]=Y(i[e],X(Z,-.5*ae))));let oe=Y(Y(F,i[J.PELVIS]),Y(i[J.SPINE],i[J.CHEST])),se=Y(X(Fn,w),X(Z,Q(T,-1,1)*.9)),ce=Y(Gn(oe),jn(oe,se,.85*(1-s($.TUCK))*(1-.5*ie)*(1-s($.DOWN))));return i[J.NECK]=jn([0,0,0,1],ce,.4),i[J.HEAD]=Y(Gn(i[J.NECK]),ce),x=!1,e};return{update:j,pose:()=>x?ee():e,get phase(){return o},get steps(){return s}}},wr=e=>Math.sign(e)*Math.abs(e)**.8,Tr=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),Er=e=>Math.min(Math.max(e,0),1),Dr=(e,t,n,r)=>{let i=[],a=[],o=[],s=t.map(([e,r,o,s,c=0],l)=>{let[u,d]=[t[Math.max(l-1,0)],t[Math.min(l+1,t.length-1)]],f=Math.hypot(d[0]-u[0],d[1]-u[1])||1,[p,m]=[(d[0]-u[0])/f,(d[1]-u[1])/f];return Array.from({length:o?n:1},(t,l)=>{let[u,d]=[wr(Math.cos(l*U/n)),wr(Math.sin(l*U/n))];return i.push([c+o*u,r+s*d*p,-(e-s*d*m)]),a.push([0,0,0]),i.length-1})});s.slice(1).forEach((e,r)=>{let c=s[r],l=[(t[r][4]??0)+(t[r+1][4]??0),t[r][1]+t[r+1][1],-t[r][0]-t[r+1][0]];for(let t=0;t<n;t++){let[n,r,s,u]=[c[t%c.length],c[(t+1)%c.length],e[(t+1)%e.length],e[t%e.length]];for(let e of[[n,r,s],[n,s,u]]){if(new Set(e).size<3)continue;let[t,n]=[1,2].map(t=>[0,1,2].map(n=>i[e[t]][n]-i[e[0]][n])),r=[t[1]*n[2]-t[2]*n[1],t[2]*n[0]-t[0]*n[2],t[0]*n[1]-t[1]*n[0]],s=[0,1,2].reduce((t,n)=>t+r[n]*(i[e[0]][n]*2-l[n]),0)<0;o.push(...s?[e[0],e[2],e[1]]:e);for(let t of e)[0,1,2].forEach(e=>a[t][e]+=s?-r[e]:r[e])}}});for(let t of o){let n=Math.hypot(...a[t])||1,o=a[t].map(e=>e/n);e.push(...i[t],...o,...r(i[t],o))}},Or=[.34,.12,.62],kr=[.72,.46,1],Ar=[.1,.38,.72],jr=[.16,.06,.34],Mr=[.5,1.9,2.3],Nr=(e=0)=>(t,n)=>{let r=Tr(Tr(Or,Ar,Er(-t[2]*5-.3)*.8),kr,Math.max(n[1],0)**1.5*.7),[i,a,,o]=Tr([...r.slice(0,2),0,r[2]],[...jr.slice(0,2),0,jr[2]],Er(-n[1]*.5+e));return[i,a,-1,o]},Pr=[.035,.025,.08],Fr=()=>[Mr[0],Mr[1],-2,Mr[2]],Ir=[0,.095,.06],Lr=[0,.075,-.21],Rr=[Math.sin(.4),Math.cos(.4)],zr=[[-.06,.095,0,0],[-.055,.098,.022,.022],[-.035,.103,.042,.036],[-.005,.104,.048,.04],[.035,.1,.044,.038],[.08,.094,.036,.034],[.12,.088,.028,.028],[.135,.084,0,0]],Br=[[-.05,-.02,0,0],[-.045,-.025,.018,.012],[-.025,-.052,.032,.018],[.01,-.066,.036,.02],[.06,-.06,.034,.02],[.11,-.04,.028,.018],[.16,0,.02,.014],[.2,.04,.012,.01],[.222,.065,0,0]],Vr=[],Hr=e=>{if(Vr[e])return Vr[e];let[t,n]=e?[12,8]:[8,5],r=[];Dr(r,zr,t,Nr()),Dr(r,Br,t,Nr(.25)),Dr(r,[[.03,.06,0,0],[.02,.046,.021,.022],[0,0,.021,.023],[-.02,-.046,.021,.022],[-.03,-.06,0,0]],n,Nr(.1));for(let t of[-1,1])Dr(r,[[.06,.095,.018,.03,.026*t],[.1,.093,.017,.028,.027*t],[.15,.088,.015,.024,.024*t],[.19,.081,.012,.018,.019*t],[.222,.074,.008,.012,.015*t],[.232,.07,0,0,.014*t]],n,Nr(.05)),Dr(r,zr.slice(1,6).map(([e,n,r,i])=>[e,n-.1*i,.0035,.006,t*r*.93]),e?5:3,Fr),Dr(r,Br.slice(1,7).map(([e,n,r,i])=>[e,n+.3*i,.0035,.005,t*r*.92]),e?5:3,Fr);return Dr(r,[[.09,.088,0,0],[.1,.088,.009,.009],[.15,.084,.009,.009],[.2,.078,.007,.007],[-Lr[2],Lr[1],0,0]],n,Fr),Vr[e]=r},Ur=e=>{let[t,n,r]=[An(e,[0,0,-1]),An(e,[1,0,0]),An(e,[0,-1,0])],[i,a]=Rr;return[n,t.map((e,t)=>a*e-i*r[t]),t.map((e,t)=>i*e+a*r[t])]},Wr=(e,t)=>{let[n,r]=[An(t,[0,-1,0]),An(t,[1,0,0])];return e.map((e,t)=>e+n[t]*.078-r[t]*.022)},Gr=[`abcdef`,`bc`,`abdeg`,`abcdg`,`bcfg`,`acdfg`,`acdefg`,`abc`,`abcdefg`,`abcdfg`],[Kr,qr,Jr,Yr]=[.019,.026,.0055,.004],Xr={a:[0,qr-Jr,Kr,qr],b:[Kr-Jr,qr/2,Kr,qr],c:[Kr-Jr,0,Kr,qr/2],d:[0,0,Kr,Jr],e:[0,0,Jr,qr/2],f:[0,qr/2,Jr,qr],g:[0,(qr-Jr)/2,Kr,(qr+Jr)/2]},Zr=[[.036,.112,.056],[.036,.112,.012]],Qr=[[.028,.156,.036],[.028,.152,.02]],$r=[.2,.075,.36],[ei,ti,ni]=[.023,.0175,.0455],ri=/* @__PURE__ */ new Map,ii=e=>{let t=Math.min(Math.max(Math.floor(e),0),99),n=ri.get(t);if(!n){let e=n=[],r=e=>[-e[0],e[1],e[2]],[i,a,o,s]=[Zr[0],Zr[1],Qr[0],Qr[1]],c=[i,a,o,s].flatMap(e=>[e,r(e)]),l=[0,1,2].map(e=>c.reduce((t,n)=>t+n[e],0)/c.length),u=(t,n)=>{let[r,i]=[q(t[1],t[0]),q(t[2],t[0])],a=kt([r[1]*i[2]-r[2]*i[1],r[2]*i[0]-r[0]*i[2],r[0]*i[1]-r[1]*i[0]],q(t[0],l))<0?[t[0],t[3],t[2],t[1]]:t;$t(e,a[0],a[1],a[2],n),$t(e,a[0],a[2],a[3],n)};u([i,r(i),r(o),o],$r),u([a,r(a),r(s),s],$r),u([i,a,s,o],$r),u([r(i),r(a),r(s),r(o)],$r),u([o,r(o),r(s),s],$r);let d=jt(q(o,i)),[f,p]=[[0,i[1],i[2]],[0,-d[2],d[1]]],m=(e,t,n)=>[f[0]+e,f[1]+d[1]*t+p[1]*n,f[2]+d[2]*t+p[2]*n];u([m(-ei,ti,.0012),m(ei,ti,.0012),m(ei,ni,.0012),m(-ei,ni,.0012)],Pr);let h=e.length;[...`${t}`.padStart(2,`0`)].forEach((n,r)=>{let i=-Kr-Yr/2+r*(Kr+Yr);for(let r of Gr[+n]){let[n,a,o,s]=Xr[r],c=(e,t)=>m(i+e,(ti+ni-qr)/2+t,.0027),l=t>10?[.25,.9,1]:[1,.18,.12];$t(e,c(n,a),c(o,a),c(o,s),l),$t(e,c(n,a),c(o,s),c(n,s),l)}}),Qt(e,h,1),ri.set(t,n)}return n},ai=(e,t,n,r,i=1,a)=>{let[o,s]=[Wr(t,n),Ur(n)];zt(e,Hr(r),o,s,[0,0,0],i),a!==void 0&&zt(e,ii(a),o,s,[0,0,0],i)},oi=(e,[,t,n])=>[0,1,2].map(r=>e[r]+t[r]*Lr[1]-n[r]*Lr[2]),si=Math.atan2(Ir[1]-Lr[1],Ir[2]-Lr[2]),ci=(e,t,n,r)=>{let i=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],a=[n,r,jt(q(t,e))];for(let o=0;o<3;o++){let s=jt(q(t,o?oi(e,a):e)),c=jt(q(n,i(s,kt(n,s)))),l=jt(q(q(r,i(s,kt(r,s))),i(c,kt(r,c)))),[u,d]=[Math.sin(si),Math.cos(si)];a=[c,Ot(i(l,d),i(s,-u)),Ot(i(s,d),i(l,u))]}return a},li=(e,t)=>{let n=[e.x,e.y+ve(e),e.z],r=Mt(e.yaw,e.pitch)[2],i=V(t,n,r,80);return[[0,1,2].map(e=>n[e]+r[e]*i),i<80]},ui=(e,t)=>{let[n,r,i]=Mt(e.yaw,e.pitch),a=[e.x,e.y+ve(e),e.z],o=[0,1,2].map(e=>a[e]+n[e]*.2-r[e]*.17+i[e]*.42);return[o,ci(o,t,n,r)]},di=[.66,.45,.35],[fi,pi,mi,hi,gi,_i,vi,yi,bi]=[0,1,2,3,4,5,6,7,8],xi=e=>[e,e.map(e=>e*.5),[.12,.13,.17],di,[.09,.07,.06],[.74,.74,.77],[.93,.93,.94],[.26,.26,.3],[.03,.03,.04]],Si={chain:[J.PELVIS,J.SPINE,J.CHEST,J.NECK,J.HEAD],n:[8,8],e:2.3,far:[0,2,4,6,8,10,13],rings:[[.84,0,0,0,0,0,mi],[.88,0,.005,.13,.09,0,mi],[.94,0,.01,.187,.108,0,mi],[.99,0,.005,.18,.106,.25,pi],[1.03,0,0,.17,.102,.5,fi],[1.12,0,0,.155,.097,1,fi],[1.24,0,-.003,.176,.112,1.7,fi],[1.35,0,-.005,.19,.126,2,fi],[1.44,0,-.004,.2,.116,2,fi],[1.485,0,0,.2,.098,2.05,fi],[1.512,0,0,.125,.08,2.1,fi],[1.532,0,0,.07,.068,2.25,pi],[1.555,0,0,.06,.062,2.6,hi],[1.6,0,0,.057,.059,3.5,hi]]},Ci={chain:[J.PELVIS,J.THIGH_R,J.SHIN_R,J.FOOT_R],n:[6,8],m:!0,far:[0,2,4,6,7,9],rings:[[1,.1,.01,0,0,0,mi],[.9,.1,.006,.093,.098,.5,mi],[.72,.1,-.002,.088,.09,1,mi],[.55,.1,-.003,.066,.07,1.25,mi],[.49,.1,-.004,.058,.064,1.5,mi],[.42,.1,.002,.056,.064,1.8,mi],[.33,.1,.012,.055,.068,2,mi],[.19,.1,.003,.04,.047,2.05,mi],[.09,.1,0,.036,.04,2.6,mi],[.06,.1,0,0,0,3,mi]]},wi={chain:[J.ARM_R,J.FOREARM_R,J.HAND_R],n:[5,7],m:!0,far:[0,2,4,6,7,9,11],rings:[[1.5,.19,0,0,0,0,fi],[1.465,.192,0,.052,.056,0,fi],[1.38,.198,0,.056,.058,.1,fi],[1.27,.21,0,.049,.051,.3,fi],[1.18,.22,0,.043,.046,.5,fi],[1.09,.222,-.002,.046,.048,.8,fi],[.975,.222,0,.034,.034,1.2,pi],[.935,.222,0,.03,.03,1.8,yi],[.885,.222,-.004,.027,.037,2,yi],[.84,.222,-.008,.029,.042,2,yi],[.795,.222,-.012,.025,.034,2,yi],[.772,.222,-.014,0,0,2,yi]]},Ti={chain:[J.FOOT_R,J.TOE_R],n:[5,6],e:2.6,z:!0,m:!0,far:[0,1,3,5,7],rings:[[.095,.1,.05,0,0,0,_i],[.08,.1,.048,.032,.042,0,_i,130,vi],[.03,.1,.052,.042,.052,.05,_i,130,vi],[-.05,.1,.04,.045,.044,.3,_i,130,vi],[-.12,.1,.033,.047,.034,.6,_i,130,vi],[-.17,.1,.028,.042,.028,1,_i,130,vi],[-.205,.1,.024,.028,.02,1,_i,130,vi],[-.215,.1,.022,0,0,1,_i]]},Ei={chain:[J.HEAD],n:[7,10],far:[0,1,3,5,6,7],rings:[[1.575,0,-.0075,.034,.0425,0,hi],[1.6,0,-.0165,.058,.0665,0,hi],[1.635,0,-.0085,.072,.0785,0,hi,150,gi],[1.675,0,-.001,.08,.089,0,hi,-36,bi,110,gi],[1.71,0,.0035,.083,.0935,0,hi,72,gi],[1.75,0,.0065,.08,.0885,0,gi],[1.785,0,.011,.056,.061,0,gi],[1.8,0,.015,0,0,0,gi]]},Di={chain:[J.HEAD],n:[0,5],z:!0,far:[],rings:[[-.075,0,1.675,.014,.034,0,hi],[-.1,0,1.66,.012,.024,0,hi],[-.115,0,1.649,0,0,0,hi]]},Oi=[Si,Ci,wi,Ti,Ei,Di],ki=(e,t)=>Math.sign(e)*Math.abs(e)**(2/t),Ai=e=>{let[t,n,r,i,a]=[[],[],[],[],[]];for(let o of Oi){let s=o.n[Math.min(e,1)];if(!s||e>1&&(o===Ei||o===Di))continue;let c=e>1&&o===Si?[...o.rings.slice(0,9),[1.455,0,0,0,0,2,fi]]:e>1&&o===wi?[...o.rings.slice(0,7),[.95,.222,0,.037,.037,1.6,yi],[.925,.222,0,.027,.027,2,yi],[.91,.222,0,0,0,2,yi]]:e?o.rings:o.far.map(e=>o.rings[e]),l=c[c.length-1][0]>c[0][0];for(let e of o.m?[1,-1]:[1]){let u=t=>e<0&&t>J.HEAD?t-4:t,d=c.map(([i,a,c,l,d,f])=>{let p=Math.min(Math.floor(f),o.chain.length-2),m=[];for(let h=0;h<(l?s:1);h++){let g=h*2*Math.PI/s,[_,v]=[a+l*ki(Math.sin(g),o.e??2),c+d*ki(Math.cos(g),o.e??2)];t.push(e*_,...o.z?[v,i]:[i,-v],0,0,0),n.push(u(o.chain[Math.max(p,0)]),u(o.chain[p+1]??o.chain[0])),r.push(p<0||o.chain[p+1]===void 0?0:f-p),m.push(r.length-1)}return m});d.slice(1).forEach((t,n)=>{let r=d[n],[,,,,,,o,...u]=c[n];for(let n=0;n<s;n++){let[c,d,f,p]=[r[n%r.length],r[(n+1)%r.length],t[(n+1)%t.length],t[n%t.length]],m=Math.abs(((n+.5)/s*360+180)%360-180),h=u.findIndex((e,t)=>!(t%2)&&(e>0?m>e:m<-e));for(let t of[[c,d,f],[c,f,p]])new Set(t).size>2&&(i.push(...l===e<0?t:[t[0],t[2],t[1]]),a.push(h<0?o:u[h+1]))}})}}for(let e=0;e<i.length;e+=3){let[n,r,a]=[i[e],i[e+1],i[e+2]].map(e=>e*6),o=[0,1,2].map(e=>[t[r+e]-t[n+e],t[a+e]-t[n+e]]),s=[o[1][0]*o[2][1]-o[2][0]*o[1][1],o[2][0]*o[0][1]-o[0][0]*o[2][1],o[0][0]*o[1][1]-o[1][0]*o[0][1]];for(let e of[n,r,a])for(let n=0;n<3;n++)t[e+3+n]+=s[n]}for(let e=0;e<t.length;e+=6){let n=Math.hypot(t[e+3],t[e+4],t[e+5])||1;for(let r=3;r<6;r++)t[e+r]/=n}return{v:new Float32Array(t),j:new Uint8Array(n),w:new Float32Array(r),t:new Uint16Array(i),c:new Uint8Array(a)}},ji=[],Mi=e=>ji[e]??=Ai(e),Ni=Mn(kn()).pos,Pi=new Float64Array(Tn*12),Fi=/* @__PURE__ */ new Float32Array,Ii=(e,t,{pos:n,rot:r},i)=>{for(let e=0;e<Tn;e++){let[t,i,a,o]=r[e],s=[1-2*(i*i+a*a),2*(t*i-a*o),2*(t*a+i*o),2*(t*i+a*o),1-2*(t*t+a*a),2*(i*a-t*o),2*(t*a-i*o),2*(i*a+t*o),1-2*(t*t+i*i)];for(let t=0;t<3;t++)Pi.set(s.slice(t*3,t*3+3),e*12+t*3),Pi[e*12+9+t]=n[e][t]-(s[t*3]*Ni[e][0]+s[t*3+1]*Ni[e][1]+s[t*3+2]*Ni[e][2])}let a=t.w.length;Fi.length<a*6&&(Fi=new Float32Array(a*6));for(let e=0;e<a;e++){let[n,r,i,a]=[t.j[e*2]*12,t.j[e*2+1]*12,t.w[e],e*6];for(let e=0;e<6;e++){let[o,s]=[e%3*3,e<3?a:a+3],[c,l,u,d]=[t.v[s],t.v[s+1],t.v[s+2],+(e<3)];Fi[a+e]=(1-i)*(Pi[n+o]*c+Pi[n+o+1]*l+Pi[n+o+2]*u+d*Pi[n+9+e%3])+i*(Pi[r+o]*c+Pi[r+o+1]*l+Pi[r+o+2]*u+d*Pi[r+9+e%3])}let o=Math.sqrt(Fi[a+3]**2+Fi[a+4]**2+Fi[a+5]**2)||1;Fi[a+3]/=o,Fi[a+4]/=o,Fi[a+5]/=o}for(let n=0;n<t.t.length;n+=3){let[r,a,o]=i[t.c[n/3]];for(let i=n;i<n+3;i++){let n=t.t[i]*6;e.push(Fi[n],Fi[n+1],Fi[n+2],Fi[n+3],Fi[n+4],Fi[n+5],r,a,-1,o)}}},Li=1,[Ri,zi]=[.12,.03],[Bi,Vi]=[[1,0,0],[0,1,0]],Hi=[.7,-1,-.5],Ui=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Wi=([e,t,n,r])=>[-e,-t,-n,r],Gi=(e,t)=>Math.hypot(...q(e,t)),Ki=(e,t,n)=>Ot(e,At([0,0,0],t,n)),qi=(e,t)=>{let[n,r]=[jt(e),jt(t)],i=[n[1]*r[2]-n[2]*r[1],n[2]*r[0]-n[0]*r[2],n[0]*r[1]-n[1]*r[0],1+kt(n,r)],a=Math.hypot(...i)||1;return i.map(e=>e/a)},Ji=(e,t,n,r,i)=>{let a=q(t,e),o=jt(a),s=Math.max(Math.min(Math.hypot(...a),(r+i)*.99),.15),c=(r*r-i*i+s*s)/(2*s),l=Math.sqrt(Math.max(r*r-c*c,0)),u=jt(q(n,At([0,0,0],o,kt(n,o))));return[Ki(Ki(e,o,c),u,l),Ki(e,o,s)]},Yi=(e,t,n,r,i,a=!1)=>{let[o,s,c]=[t.pos[n],t.pos[n+1],t.pos[n+2]],[l,u]=Ji(o,r,i,Gi(o,s),Gi(s,c)),d=Y(qi(q(s,o),q(l,o)),t.rot[n]),f=Y(qi(q(c,s),q(u,l)),t.rot[n+1]);e.rot[n]=Y(Wi(t.rot[En[n]]),d),e.rot[n+1]=Y(Wi(d),f),a&&(e.rot[n+2]=Y(Wi(f),t.rot[n+2]))},Xi=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],Zi=()=>Rt(0,.04,[.0105,.0095],[1,2]),Qi=[1,1.1,1,.82],$i=[[[.55,-.2,.8],[.2,-.75,.6]],[[.4,-.1,.9],[-.55,-.5,.65]]],ea=(e,t,n,r,i,a,o)=>{let s=([e,a,o])=>[t[0]+i[0]*e+r[0]*a+n[0]*o,t[1]+i[1]*e+r[1]*a+n[1]*o,t[2]+i[2]*e+r[2]*a+n[2]*o],c=(t,n,r,a)=>n.reduce((t,n,c)=>{let l=[t[0]+n[0]*r,t[1]+n[1]*r,t[2]+n[2]*r];return Vt(e,Zi(),s(t),s(l),i,.04,a*.88**c,o),l},t);zt(e,Rt(1,0,[1,1]),t,[i,r,n],[0,0,.045],[.0425,.02,.058],o);for(let e=0;e<4;e++){let[t,n]=[.1+1.3*a,.2+3*a],r=-(e-1.5)*.08*(1-a),i=[t,n].map(e=>jt([r,-Math.sin(e),Math.cos(e)]));c([.0315-.021*e,-.004,.092],i,.04*Qi[e],1)}c([.034,-.012,.025],$i.map(([e,t])=>jt(At(e,t,a))),.037,1.25)},ta=(e,t)=>(n,i)=>{let a=V(e,[n,t+r,i],[0,-1,0],2*r);return a>0&&a<1?t+r-a:t},na={amp:8,sprint:6,air:12,rise:10,dash:14,plant:16,wall:10,slide:10,stun:14,gun:10},ra=e=>{let t=Cr(),n,r={amp:0,sprint:0,air:0,rise:0,dash:0,plant:0,wall:0,slide:0,stun:0,gun:0},[i,a,o]=[0,0,1.6],s=[0,0,8],c=0,l=0,u,d=[0,0],f=(a,s,d=0,f=1.6)=>{if(i=d,o=f,!a){n=void 0;return}t.update(a,s,e&&ta(e,a.y)),n={...a},c+=s;let p=a.mode==g.GROUND||a.mode==g.CROUCH||a.mode==g.WALLRUN,m=a.dash>50,h=a.mode==g.AIR&&!m,_={amp:p?Ui(ye(a)/9):0,sprint:+be(a),air:+h,rise:+(h&&a.vy>.5),dash:+m,plant:+(a.mode==g.HANG||a.mode==g.CLIMB),wall:+(a.mode==g.WALLRUN),slide:+(a.mode==g.SLIDE),stun:+(a.stun>0),gun:+(a.ammo>=0&&!a.down)};for(let e of Object.keys(na))r[e]+=(_[e]-r[e])*(1-Math.exp(-s*na[e]));let[v,y]=Xi[a.wall];l+=(Ui(v*Math.cos(a.yaw)-y*Math.sin(a.yaw),-1,1)-l)*(1-Math.exp(-s*10)),_.plant&&a.edge&&(u={x:a.x,y:a.edge,z:a.z,dx:v,dz:y})},p=()=>{let e=r.amp*(1+.5*r.sprint),[n,a]=[Math.sin(U*t.phase),Math.cos(U*t.phase)],c=[Math.min(.22,.18*o)+.012*e*n,-.25+.018*e*a-.3*(1-r.gun),.4-.05*i];return[c,ci(c,[s[0],s[1]+.1*i*Math.hypot(...s),s[2]],Bi,Vi)]},m=(e,i,o,s=0)=>{if(!n||n.down||Gi(e,[n.x,n.y+ve(n),n.z])>Li)return;let f=t.pose(),m={at:[...f.at],yaw:f.yaw,hips:[...f.hips],rot:f.rot.map(e=>[...e])},[h,g,_]=Mt(i,o,s),v=([e,t,n])=>[h[0]*e+g[0]*t+_[0]*n,h[1]*e+g[1]*t+_[1]*n,h[2]*e+g[2]*t+_[2]*n],y=e=>[kt(e,h),kt(e,g),kt(e,_)];for(let e of[J.SPINE,J.CHEST])m.rot[e]=Y(m.rot[e],X(Bi,.12*Ui(o,-1.3,1.3)));let b=Mn(m),x=[-Math.sin(i),0,-Math.cos(i)],S=Ot(b.pos[J.HEAD],An(b.rot[J.HEAD],[0,.02,-.08]));m.at=Ot(m.at,q(e,Ki(S,[-x[0]*Ri,-zi,-x[2]*Ri],r.plant)));let C=Mn(m),w=[-Math.sin(m.yaw),0,-Math.cos(m.yaw)];for(let e of[J.THIGH_L,J.THIGH_R])Yi(m,C,e,b.pos[e+2],w,!0);let[T,E]=p(),D=[0,1,2].map(e=>Rr[1]*E[2][e]-Rr[0]*E[1][e]),O=[0,1,2].map(e=>T[e]-.078*D[e]+.022*E[0][e]);for(let n of[-1,1]){let i=Math.cos(U*t.phase)*n,o=r.amp*(1+.5*r.sprint),s=At([.25,-.17,.36],[.2,-.14,.42],r.sprint);s=[s[0],s[1]+.07*o*i,s[2]+.12*o*i],n<0&&(s=At(s,[-.2,-.65,.2],r.gun*(1-Ui(r.amp*2.5)))),s=At(s,[.38,-.2,.34],r.air),s=At(s,[.3,.02,.45],r.rise),s=At(s,[.14,-.1,.5],r.dash);let f=r.wall*Ui(l*n);s=At(s,[.42,-.16,.42],f),s=At(s,n>0?[.36,-.26,.38]:[.28,-.1,.42],r.slide);let p=Math.sin(c*12+(n>0?Math.PI:0));if(s=At(s,[.46,.05+.2*p,.4+.1*p],r.stun),u){let[t,i]=[-u.dz,u.dx];kt([t,0,i],h)<0&&([t,i]=[-t,-i]);let a=.35000000000000003,[o,c,l]=y(q([u.x+u.dx*a+t*.12*n,u.y+.03,u.z+u.dz*a+i*.12*n],e));s=At(s,[o*n,Math.max(c,-.28),Math.max(l,.4)],r.plant)}n>0&&(a=r.gun*(1-Ui(r.plant+f+r.stun)),s=At(s,O,a));let g=.75+.25*r.sprint;for(let[e,t]of[[.25,r.air],[.1,r.rise],[1,r.dash],[.1,f],[.1,r.slide],[.1,r.plant],[.2,r.stun]])g+=(e-g)*t;d[(n+1)/2]=n>0?g+(.9-g)*a:g;let _=Ot(e,v([s[0]*n,s[1],s[2]])),b=n<0?J.ARM_L:J.ARM_R;if(Yi(m,C,b,_,v([Hi[0]*n,Hi[1],Hi[2]])),m.rot[b+2]=X(Vi,n*(1+.5*(r.plant+r.slide))),n>0&&a>.002){let e=Qn(v(E[0]),v(D));m.rot[b+2]=jn(m.rot[b+2],Y(Wi(Mn(m).rot[J.FOREARM_R]),e),a)}}return Mn(m)};return{get id(){return n?.id??-1},update:f,pose:m,draw(e,t,r,i,o=0,s=[.7,.7,.7]){let c=m(t,r,i,o);if(c){let t=xi(s);Ii(e,Mi(2),c,t),[J.HAND_L,J.HAND_R].forEach((n,r)=>{let i=c.rot[n];ea(e,c.pos[n],An(i,[0,-1,0]),An(i,[r*2-1,0,0]),An(i,[0,0,-1]),d[r],t[7])}),a>.2&&ai(e,c.pos[J.HAND_R],c.rot[J.HAND_R],1,Ui(a*1.5-.5),n?.ammo)}},aim(e){let t=Math.hypot(...e);s=t<3?t?e.map(e=>e*3/t):[0,0,3]:e},muzzle:()=>oi(...p())}},ia=(e,t,n,r,i,a)=>{let o=Mt(r,i)[2],s=V(e,t,o,80),c=[0,1,2].map(e=>t[e]+o[e]*s);return{end:c,hit:s<80,local:Mt(r,a).map(e=>(c[0]-n[0])*e[0]+(c[1]-n[1])*e[1]+(c[2]-n[2])*e[2])}},aa=(e,t)=>e&&t?t.shots-e.shots&255:0,oa=3,sa=(e,t,r,i,a,o)=>{let s=0,c,l=!1,u=0,d=/* @__PURE__ */ new Map,p=()=>.94+.12*(u++*.618%1),m=e=>t.play(K.LASER,e,e?.7:.5,p());return{step(e,t){let r=aa(e,t);s+=r;for(let e=0;e<r;e++)o.pitch=Math.min(n,o.pitch+f),i.fire()},frame(n,o,u,f,p){if(a.update(p),o){let e=c;e&&o.hits!=e.hits&&(t.play(K.HIT),r.hit()),e&&o.hp<e.hp?(t.play(o.down&&!e.down?K.DOWN:K.HURT),i.wound()):e&&o.hp>e.hp&&!e.down&&t.play(K.PACK),e&&(e.ammo<0||o.ammo>e.ammo)&&o.ammo>=0&&t.play(K.GUN);let n=!!(f&h.FIRE);n&&!l&&o.ammo==0&&!o.down&&t.play(K.DRY),l=n,r.vitals(o.hp,o.ammo),r.down(i.lie,o.down/60),c={...o}}else c=void 0;if(n){let[e,t,r]=Mt(n.yaw,n.drawn),i=n.muzzle,o=[0,1,2].map(a=>n.cam[a]+e[a]*i[0]+t[a]*i[1]+r[a]*i[2]);for(a.mount(o);s>0;s--)a.shoot(o,n.end,n.hit,!0),m()}s=0;for(let t of u){let n=d.get(t.id),r=Math.min(n===void 0?0:t.shots-n&255,oa),[i,o]=li(t,e),[s,c]=ui(t,i);for(let e=0;e<r;e++)a.shoot(oi(s,c),i,o),m([t.x,t.y+ve(t),t.z]);d.set(t.id,t.shots)}for(let e of d.keys())u.some(t=>t.id==e)||d.delete(e)}}},ca=e=>.6+.2*e,la=e=>e?.mode===g.GROUND||e?.mode===g.CROUCH,ua=e=>la(e)||e?.mode===g.WALLRUN,da=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],fa=e=>.02+.0025*e,pa=.006,ma=.03,ha=.14,ga=.05,_a=5,va=9,ya=6.5,ba=.25,xa=.22,Sa=.9,Ca=4,wa=1,Ta=.12,Ea=24,Da=15.7,Oa=.45,ka=[-8,4,5],Aa=3,ja=[-1,1.2],Ma=4,Na=[-.25,.4,.5],Pa=[-1.5,.8,1.5],Fa=[.9,.3],Ia=[.1,.05,11],La=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Ra=(e,t)=>{let n=Math.ceil(t*120);for(let r=0;r<n;r++)e[1]+=(-15.7*Da*e[0]-2*Oa*Da*e[1])*(t/n),e[0]+=e[1]*(t/n)},za=()=>{let e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0,c,l,u=[0,0],d=[0,0],f=[0,0],p={dy:0,pitch:0,roll:0,fov:0,lines:0,stride:0,hurt:0,kick:0,lie:0,fire(){s++,u[1]+=Na[0],d[1]+=Na[1],f[1]+=Na[2]*Math.sin(s*2.4),p.kick=1},wound(){u[1]+=Pa[0],d[1]+=Pa[1],f[1]+=Pa[2]*Math.sin(s++),p.hurt=1},jolt(){u[1]+=ka[0],d[1]+=ka[1],f[1]+=ka[2],p.hurt=1},punch(){u[1]+=ja[0],d[1]+=ja[1],a=1},update(s,m,_,y={ev:0,fall:0}){let b=e=>Math.min(1,_*e),x=s?ye(s):0,S=s&&l&&ua(s)&&ua(l)?Math.hypot(s.x-l.x,s.z-l.z):0;S<1&&(p.stride+=S/ca(x)),e+=((la(s)&&S>.5*_&&S<1?1:0)-e)*b(10),l=s,y.ev&v.LAND&&(u[1]-=xa*Math.min(y.fall,20)),y.ev&v.CLIMB&&(u[1]-=xa*Ca),y.ev&(v.JUMP|v.DOUBLE)&&(u[1]+=Sa),y.ev&v.GRAB&&(d[1]-=wa),Ra(u,_),Ra(d,_),Ra(f,_),p.hurt*=Math.exp(-_*Aa),a*=Math.exp(-_*10),p.kick*=Math.exp(-_*22),p.lie+=(+!!s?.down-p.lie)*b(5),o+=_*Ia[2];let C=s?Math.min(1,s.stun/48):0,w=s?ve(s):0;c=s?c===void 0?w:c+(w-c)*b(14):void 0,p.dy=(c??0)-w+u[0]-Math.cos(p.stride*2*Math.PI)*fa(x)*e-p.lie*(w-Fa[1]),i+=((s?.mode===g.CLIMB?Ta*Math.sin(Math.PI*La(s.t/Ea)):0)-i)*b(10),p.pitch=d[0]+i+Math.sin(o*.8)*Ia[1]*C;let T=s?.mode===g.WALLRUN?da[s.wall]:[0,0],E=s?T[0]*Math.cos(s.yaw)-T[1]*Math.sin(s.yaw):0,D=+!!(m&h.RIGHT)-!!(m&h.LEFT);t+=(D*ma+E*ha+(s?.mode===g.SLIDE?ga:0)-t)*b(8),p.roll=t+Math.sin(p.stride*Math.PI)*pa*e+f[0]+Math.sin(o)*Ia[0]*C+p.lie*Fa[0];let O=!!s&&s.dash>50;n+=(+O-n)*b(O?40:6),r+=(La((x-6)/3)-r)*b(4),p.fov=r*_a+n*va+a*Ma,p.lines+=(La((x-ya)/(9-ya))*ba+n*.75-p.lines)*b(8)}};return p},Ba=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Va=e=>{let t=e.loop(K.WIND),n=e.loop(K.SCRAPE),r=0,i=/* @__PURE__ */ new Map,a=(t,n,r)=>{let i=be(t);e.play(t.mode===g.WALLRUN?K.WALLSTEP:K.STEP,r,i||t.mode===g.WALLRUN?1:t.mode===g.CROUCH?.35:.6,(i?.92:1)*(n&1?1.06:.94))},o=(t,n)=>e.play(K.LAND,n,Ba(t/14,.2),1.25-.5*Ba(t/20));return{me(i,s,c){let l=Math.floor(c),u=l>r;if(r=l,!i||e.muted)return;u&&a(i,l);for(let[t,n]of[[v.JUMP,K.JUMP],[v.DOUBLE,K.DOUBLE],[v.DASH,K.DASH],[v.GRAB,K.GRAB],[v.CLIMB,K.SCUFF]])s.ev&t&&e.play(n);s.ev&v.LAND&&o(s.fall);let d=Ba((Math.hypot(i.vx,i.vy,i.vz)-4)/12);t.set(.55*d**1.5,.6+.9*d);let f=Ba(ye(i)/9);n.set(i.mode===g.SLIDE?.2+.5*f:0,.8+.4*f)},others(t){for(let n of t){let t=i.get(n.id);if(t&&!e.muted){let e=[n.x,n.y+.1,n.z],r=Math.hypot(n.x-t.p.x,n.z-t.p.z);if(ua(n)&&ua(t.p)&&r<1){let i=Math.floor(t.stride);t.stride+=r/ca(ye(n)),Math.floor(t.stride)>i&&a(n,i,e)}n.ground&&!t.p.ground&&t.p.vy<-3&&o(-t.p.vy,e)}i.set(n.id,{p:n,stride:t?.stride??0})}for(let e of i.keys())t.some(t=>t.id===e)||i.delete(e)}}},Ha=`h5,aside,nav,output,section,em,u,ul,dl,s,mark{position:absolute;margin:0;padding:0;pointer-events:none;user-select:none;white-space:pre-line}h5{top:8px;right:12px;font-size:12px}u{inset:0;opacity:0;background:radial-gradient(ellipse at center,#0000 35%,#d10000dd 120%)}nav{top:8px;left:50%;transform:translateX(-50%);display:grid;grid-template-columns:1fr auto 1fr;gap:2px 16px;align-items:center;text-align:center;font-size:13px}nav span,nav time{font:900 clamp(16px,4.6vw,24px)/1 system-ui,sans-serif;letter-spacing:.03em;white-space:nowrap}nav time{min-width:4.2ch;font-variant-numeric:tabular-nums;font-size:clamp(14px,3.8vw,20px)}nav small{font-size:clamp(10px,2.6vw,12px);white-space:nowrap;opacity:.95}nav small:first-of-type{text-align:right}nav small:last-of-type{text-align:left}output{top:20%;left:50%;transform:translateX(-50%);padding:6px 18px;font:900 clamp(18px,3.4vw,30px)/1.1 system-ui,sans-serif;letter-spacing:.06em;text-transform:uppercase;white-space:nowrap;background:#000a;border-bottom:3px solid currentColor}em{font-style:normal;font-size:13px;font-weight:800;line-height:1.1;text-align:center;transform:translate(-50%,-50%)}em span{display:block;font-size:20px;line-height:1}section{inset:0;z-index:2;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:0 12px;text-align:center;background:#000c}section h6{font:900 clamp(30px,9vw,72px)/1 system-ui,sans-serif;letter-spacing:.04em}section strong{font-size:34px}section td:first-child{text-align:left;opacity:1}section td+td{text-align:center}section th{padding:2px 10px;font-size:12px;opacity:.7;font-weight:600}aside{inset:0;z-index:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;padding:0 12px;text-align:center;background:#000b}h6{margin:0;font-size:inherit;text-shadow:none}aside h6{font:900 clamp(36px,13vw,84px)/1 system-ui,sans-serif;letter-spacing:.04em;transform:skewX(-8deg);background:linear-gradient(#fe6,#f92 45%,#d21);-webkit-background-clip:text;background-clip:text;color:transparent;filter:drop-shadow(0 3px 0 #500) drop-shadow(0 0 14px #f604)}ul{left:12px;bottom:30px;display:flex;gap:4px;list-style:none}li{width:16px;height:6px;background:#fff;box-shadow:0 0 0 1px #0008}li.e{background:#0000;box-shadow:inset 0 0 0 1px #fffb,0 0 0 1px #0008}ul.low li{background:#f55}ul.low li.e{background:#0000}dl{left:50%;bottom:10px;transform:translateX(-50%);display:flex;align-items:center;gap:10px}dl svg{width:38px;fill:#fff;filter:drop-shadow(0 1px 1px #000)}@media(max-width:520px){dl{left:auto;right:12px;bottom:46px;transform:none}}dl data{font:900 clamp(30px,5vw,46px)/1 system-ui,sans-serif;font-variant-numeric:tabular-nums}dl.e data{color:#f66}s{left:50%;top:50%;width:28px;height:28px;margin:-14px 0 0 -14px;background:linear-gradient(45deg,#0000 44%,#fff 44% 56%,#0000 56%),linear-gradient(-45deg,#0000 44%,#fff 44% 56%,#0000 56%);-webkit-mask:radial-gradient(#0000 6px,#000 7px);mask:radial-gradient(#0000 6px,#000 7px)}mark{inset:0;z-index:1;padding-top:30vh;text-align:center;color:#ddd;background:radial-gradient(ellipse at center,#6668 0%,#4a0c0ce8 130%);backdrop-filter:grayscale(1)}mark::first-line{font:900 clamp(30px,8vw,64px)/1 system-ui,sans-serif;letter-spacing:.24em}strong{font-size:22px}table{border-collapse:collapse;font-size:16px}td{padding:2px 10px}td+td{text-align:left}td:first-child{text-align:right;opacity:.7}`,Ua=2800,Wa=e=>`${Math.floor(e/60)}:${`${e%60}`.padStart(2,`0`)}`,Ga=e=>{e.insertAdjacentHTML(`beforeend`,`<aside hidden><h6>TINY FPS</h6><span></span><table><tr><td>Mouse<td>look<tr><td>WASD / ZQSD<td>move<tr><td>Shift<td>sprint<tr><td>Space<td>jump, again in the air<tr><td>Move key twice<td>dash that way<tr><td>C<td>crouch, slide when fast<tr><td>Left click<td>fire the gun<tr><td>M<td>mute</table><span>Take the enemy flag to your own base while yours is home. Take the gun at your rack.</span><strong></strong></aside><u></u><h5 hidden>Muted (M)</h5><ul>${`<li></li>`.repeat(5)}</ul><dl hidden><svg viewBox="0 0 38 22"><path d="M1 7c3-5 13-7 22-4l7 3 3 1v4l-6 1-4 2-1 1-3 6h-5l2-7-5-1c-6-1-12-3-10-6z"/></svg><data></data></dl><s hidden></s><mark hidden></mark><nav hidden><span></span><time></time><span></span><small></small><small></small></nav><output hidden></output><section hidden><h6></h6><strong></strong><table></table><span></span></section>`);let t=t=>e.querySelector(t),[n,r]=[`h5`,`aside`].map(e=>t(e)),[i,a]=[`aside span`,`aside strong`].map(e=>t(e)),o=(e,t)=>e.textContent!=t&&(e.textContent=t),s=t(`nav`),[c,d,f]=[...s.querySelectorAll(`span, time`)],[p,h]=[...s.querySelectorAll(`small`)],g=[...e.querySelectorAll(`li`)],[_,v,y,b]=[t(`ul`),t(`dl`),t(`s`),t(`mark`)],x,S=t(`output`),C=t(`u`),w=t(`section`),[T,E,D]=[`h6`,`strong`,`span`].map(e=>w.querySelector(e)),O=w.querySelector(`table`),k=[],A,j,M=(e,t)=>e.style.color=u[t];return[c,p].forEach(e=>M(e,0)),[f,h].forEach(e=>M(e,1)),{title(e,t){r.hidden=!e,o(i,t),o(a,e)},mute:e=>n.hidden=!e,match(e,t){s.hidden=!1,o(c,`${l[0].toUpperCase()} ${e.score[0]}`),o(f,`${e.score[1]} ${l[1].toUpperCase()}`),o(d,e.over?`END`:Wa(e.clock)),e.flags.forEach((e,n)=>{let r=e.state===m.CARRIED?`taken by ${t(e.by)}`:e.state===m.DROPPED?`dropped ${e.left}s`:`home`;o(n?h:p,`${l[n]} flag: ${r}`)})},marks(t){for(;k.length<t.length;){let t=document.createElement(`em`);t.innerHTML=`<span></span><small></small>`,k.push(t),e.append(t)}k.splice(t.length).forEach(e=>e.remove()),t.forEach((e,t)=>{let n=k[t];n.style.left=`${e.x*100}%`,n.style.top=`${e.y*100}%`,M(n,e.team);let[r,i]=[n.children[0],n.children[1]];r.style.transform=e.arrow===void 0?``:`rotate(${e.arrow}rad)`,o(r,e.arrow===void 0?`▼`:`▲`),o(i,`${e.kind===`base`?`Base `:``}${e.text}`)})},hurt(e){let t=e<.01?``:`${Math.min(1,e)}`;C.style.opacity!=t&&(C.style.opacity=t)},vitals(e,t){g.forEach((t,n)=>t.classList.toggle(`e`,n>=e)),_.classList.toggle(`low`,e<=1),v.hidden=t<0,v.classList.toggle(`e`,!t),o(v.lastElementChild,`${Math.max(t,0)}`)},hit(){y.hidden=!1,clearTimeout(x),x=setTimeout(()=>y.hidden=!0,140)},down(e,t){b.hidden=e<.02,b.style.opacity=`${Math.min(e,1)}`,o(b,b.hidden?``:`DOWN\nBack in ${t.toFixed(1)}`)},banner(e,t){S.hidden=!1,o(S,e),S.style.color=t===void 0?`#fff`:u[t],clearTimeout(A),A=setTimeout(()=>S.hidden=!0,Ua)},end(e,t){if(w.hidden=!e,!e)j=void 0;else{if(j!==e){j=e;let[t,n]=e.score,r=t>n?0:n>t?1:-1;o(T,r<0?`DRAW`:`${l[r].toUpperCase()} WINS`),T.style.color=r<0?`#fff`:u[r],o(E,`${t} – ${n}`);let i=[...e.players].sort((e,t)=>t.caps-e.caps||t.returns-e.returns||e.id-t.id);O.replaceChildren(),O.insertAdjacentHTML(`beforeend`,`<tr><th>Player<th>Captures<th>Returns</tr>`);for(let e of i){let t=O.insertRow();[e.name,e.caps,e.returns].forEach(e=>t.insertCell().textContent=`${e}`),t.style.color=u[e.team]}}o(D,`Next match in ${t}`)}}}},Ka=.0025,qa=Math.PI*2,Ja={KeyW:h.FORWARD,ArrowUp:h.FORWARD,KeyS:h.BACK,ArrowDown:h.BACK,KeyA:h.LEFT,ArrowLeft:h.LEFT,KeyD:h.RIGHT,ArrowRight:h.RIGHT,Space:h.JUMP,ShiftLeft:h.SPRINT,ShiftRight:h.SPRINT,KeyC:h.CROUCH},Ya=h.FORWARD|h.BACK|h.LEFT|h.RIGHT,Xa=(e,t)=>e&~Ya|t|h.DASH,Za=e=>Ja[e]??0,Qa=(e,t=()=>{})=>{let r=new AbortController,i=(e,t,n)=>e.addEventListener(t,n,{signal:r.signal}),a=/* @__PURE__ */ new Set,o=/* @__PURE__ */ new Map,s=0,c={yaw:0,pitch:0,keys:0,take(){let e=s?Xa(c.keys,s):c.keys;return s=0,e},locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>r.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{c.locked()&&(c.yaw=((c.yaw-e.movementX*Ka)%qa+qa)%qa,c.pitch=Math.max(-1.55,Math.min(n,c.pitch-e.movementY*Ka)))}),i(document,`mousedown`,e=>{c.locked()&&!e.button&&(c.keys|=h.FIRE)}),i(document,`mouseup`,e=>{e.button||(c.keys&=~h.FIRE)}),i(document,`keydown`,e=>{let n=Za(e.code);if(e.code==`KeyM`&&!e.repeat&&c.locked()&&t(),n&&c.locked()){if(n&Ya&&!e.repeat&&!a.has(e.code)){let t=performance.now(),r=o.get(e.code);r!==void 0&&t-r<=250?(s=n,o.delete(e.code)):o.set(e.code,t)}a.add(e.code),c.keys|=n,e.preventDefault()}}),i(document,`keyup`,e=>{a.delete(e.code),c.keys&=~Za(e.code)});let l=()=>{c.keys=s=0,a.clear(),o.clear()};return i(window,`blur`,l),i(document,`pointerlockchange`,()=>c.locked()||l()),c},$a=(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},eo=(e,t,n,r,i=!0)=>{let a=e.down>0;if(Ke(e,a?{...t,keys:0}:t,n,r),a)return e.down>0&&!--e.down&&he(e,n,r),!1;let o=n.def.teams[r].rack,s=!!o&&$a(e,o,1.2);return i&&s&&!e.rack&&(e.ammo=60),e.rack=s,e.cool=Math.max(0,e.cool-1),i&&t.keys&h.FIRE&&!e.cool&&e.ammo>0&&e.mode!==g.HANG&&e.mode!==g.CLIMB?(e.ammo--,e.shots=e.shots+1&255,e.cool=7,!0):!1},to=120,no=16,ro=e=>{let t={...e};return delete t.ack,delete t.by,t},io=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,z:e.z+(t.z-e.z)*n}),ao=(e,t,n)=>se(e+(((t-e+Math.PI)%U+U)%U-Math.PI)*n),oo=(e,t)=>(t-e&65535)<32768,so=(e,t,n)=>({...t,...io(e,t,n),yaw:ao(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),co=e=>{let t,n=0,r=0,i=[],a,o,s=[],c=0,l=0,u=!0,d=e=>{let t=e-100,n=0;for(;n+1<s.length&&s[n+1].t<=t;)n++;let r=s[n],i=s[n+1]??r;return{a:r,b:i,u:i.t>r.t?Math.max(0,Math.min(1,(t-r.t)/(i.t-r.t))):0}},f=e=>{if(!s.length)return;let{a:t,b:n,u:r}=d(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536};return{you:(e,r=0)=>{[t,n]=[e,r]},step:(t,s)=>{let d=nt({...t,seq:r,view:s===void 0?void 0:f(s)});return r=r+1&65535,i.push(d),i.length>to&&i.shift(),a&&(o=ro(a),eo(a,d,e,n,u),c|=a.ev,l=Math.max(l,a.fall)),d},snapshot:(r,c)=>{s.push({t:c,s:r}),s.length>no&&s.shift();let l=r.players.find(e=>e.id===t);l&&(u=!r.over,i=i.filter(e=>!oo(e.seq,l.ack)),a=ro(l),o=ro(a),i.forEach((t,r)=>{r===i.length-1&&(o=ro(a)),eo(a,t,e,n,u)}))},events:()=>{let e={ev:c,fall:l};return c=l=0,e},me:e=>a&&o?so(o,a,Math.max(0,Math.min(1,e))):void 0,others:e=>{let n=s.at(-1);if(!n)return[];let{a:r,b:i,u:a}=d(e);return n.s.players.filter(e=>e.id!==t).map(e=>{let t=r.s.players.find(t=>t.id===e.id),n=i.s.players.find(t=>t.id===e.id);return t&&n?so(ro(t),ro(n),a):ro(n??t??e)})}}},lo={x0:.05,x1:.95,y0:.15,y1:.92},uo=(e,t,n,r,i)=>{let[a,o]=[r-e,i-t];return Math.atan2(a*Math.cos(n)-o*Math.sin(n),-a*Math.sin(n)-o*Math.cos(n))},fo=e=>{let[t,n]=[Math.sin(e),-Math.cos(e)],[r,i]=[(lo.x0+lo.x1)/2,(lo.y0+lo.y1)/2],[a,o]=[(lo.x1-lo.x0)/2,(lo.y1-lo.y0)/2],s=Math.min(a/(Math.abs(t)||1e-9),o/(Math.abs(n)||1e-9));return[r+t*s,i+n*s]},po=2.6,mo=e=>{let t=[],n=(n,r,[i,a,o])=>{let s=Math.round(Math.hypot(i-e.eye[0],a+po-e.eye[1],o-e.eye[2])),c=e.project(i,a+po,o),l=c&&c[0]>=lo.x0&&c[0]<=lo.x1&&c[1]>=lo.y0&&c[1]<=lo.y1,u=`${s} m`;if(l)t.push({team:n,kind:r,x:c[0],y:c[1],text:u});else{let a=uo(e.eye[0],e.eye[2],e.yaw,i,o),[s,c]=fo(a);t.push({team:n,kind:r,x:s,y:c,arrow:a,text:u})}},r=e.flags.some(t=>t.state===m.CARRIED&&t.by===e.id);return e.flags.forEach((t,i)=>{if(t.state===m.CARRIED&&t.by===e.id){n(e.team,`base`,e.bases[e.team]);return}if(r&&i===e.team&&t.state===m.HOME)return;let a=t.state===m.HOME?e.bases[i]:t.state===m.DROPPED?[t.x,t.y,t.z]:e.where(t.by);a&&n(i,`flag`,a)}),t},ho=(e=[],t=0,n=0)=>e.filter((e,r)=>n+r<32&&t>>>n+r&1),go=(e,t,n,r)=>{let i=n.map(e=>e*.45);Vt(e,Rt(1,1,[1,1],[0,0]),t,[t[0],t[1]+.72,t[2]],[1,0,0],1,.06,i);let[a,o,s]=t;zt(e,Rt(1,0,[1,1]),[a,o+.74,s],Mt(0,0),[0,0,0],[.3,.035,.3],n);let c=e.length;en(e,[a,o+.045,s],p-.07,p,n),Qt(e,c,1.2*Kt*(.7+.3*Math.sin(r*2.5))),zt(e,Hr(0),[a,o+1.05+.04*Math.sin(r*2),s],Mt(r*.8,0),[0,0,0],1.5)},_o=[[[1,0,0],[0,1,0],[0,0,1]],[[-1,0,0],[0,0,1],[0,1,0]],[[0,1,0],[0,0,1],[1,0,0]],[[0,-1,0],[1,0,0],[0,0,1]],[[0,0,1],[1,0,0],[0,1,0]],[[0,0,-1],[0,1,0],[1,0,0]]],vo=(e,t,n,r)=>[[[e,t],[n,t],[n,r]],[[e,t],[n,r],[e,r]]],yo=[...vo(-.13,-.04,.13,.04),...vo(-.04,-.13,.04,.13)],bo=[...vo(-.035,-.09,.035,.04),[[-.035,.04],[.035,.04],[0,.11]],...vo(-.05,-.12,.05,-.095)],xo=(e,t,n,r,i,a,o)=>{let[s,,c]=Mt(n*.9,0),l=[t[0],t[1]+.45+.07*Math.sin(n*2.2+t[0]),t[2]],u=([e,t,n])=>[s[0]*e-c[0]*n,t,s[2]*e-c[2]*n];for(let[t,n,s]of _o){let c=(e,i,a)=>{let[o,c,d]=u([0,1,2].map(o=>t[o]*r*a+n[o]*e+s[o]*i));return[l[0]+o,l[1]+c,l[2]+d]};$t(e,c(-r,-r,1),c(r,-r,1),c(r,r,1),i),$t(e,c(-r,-r,1),c(r,r,1),c(-r,r,1),i);let d=e.length;for(let[t,n,r]of a)$t(e,c(...t,1.01),c(...n,1.01),c(...r,1.01),o);for(let t=d;t<e.length;t+=10)e[t+8]=-2}},So=(e,t,n)=>xo(e,t,n,.17,[.86,.9,.88],yo,[.1,1.2,.4]),Co=(e,t,n)=>xo(e,t,n,.15,[.34,.14,.58],bo,[.3,1.4,1.8]),wo=14,To=e=>{let t=Mt(e.yaw,e.pitch)[2];return[e.x+t[0]*30,e.y+1.6+t[1]*30,e.z+t[2]*30]},Eo=.5,Do=e=>e.dash>50,Oo=e=>{let t=Cr();return t.update(e,0),{p:{...e},gait:t,dash:+Do(e),since:1e3,aim:0,focus:To(e)}},ko=(e,t)=>(n,i)=>{let a=V(e,[n,t+r,i],[0,-1,0],2*r);return a>0&&a<1?t+r-a:t},Ao=(e,t,n,r)=>{for(let n of e.keys())t.some(e=>e.id==n)||e.delete(n);for(let i of t){let t=e.get(i.id);t?(t.gait.update(i,n,r&&ko(r,i.y)),t.dash+=(+Do(i)-t.dash)*(1-Math.exp(-n*wo)),t.since=i.shots==t.p.shots?t.since+n:0,t.aim=t.since==0?1:t.aim+(+(t.since<Eo)-t.aim)*(1-Math.exp(-n*12)),t.focus=t.since<Eo?r?li(i,r)[0]:To(i):t.focus,t.p={...i}):e.set(i.id,Oo(i))}},jo=(e,t,n,r,i)=>{let[a,o]=ui(n,r),s=e.rot.slice(),c={...e,rot:s},[l,u]=[o[0],o[2].map((e,t)=>e*Rr[1]-o[1][t]*Rr[0])],d=a.map((e,t)=>e-.078*u[t]+.022*l[t]),f=[l[0]*.7,-1,l[2]*.7];return Yi(c,t,J.ARM_R,d.map((e,n)=>t.pos[J.HAND_R][n]+(e-t.pos[J.HAND_R][n])*i),f),s[J.HAND_R]=jn(s[J.HAND_R],Y(Wi(Mn(c).rot[J.FOREARM_R]),Qn(l,u)),i),c},Mo=(e,t,n,r)=>{let i=jt([-t.p.vx,0,-t.p.vz]),[a,o,s]=n.map(e=>.6+.6*e);[[.5,.12,1.3],[.9,-.16,1.7],[1.25,.14,1.2]].forEach(([n,c,l],u)=>{let d=r([c,n,-.2-.1*u]),f=d.map((e,n)=>e+i[n]*l*t.dash);for(let t of[[-i[2]*.03,0,i[0]*.03],[0,.03,0]])for(let n of[d.map((e,n)=>e+t[n]),d.map((e,n)=>e-t[n]),f])e.push(...n,0,1,0,a,o,-2,s)})},No=(e,t,n,r=1)=>{let i=t.gait.pose(),{p:a}=t;a.down&&(i={...i,at:[i.at[0],i.at[1]-.5*Math.min(Math.max(1-a.down/30,0),1),i.at[2]]});let o=Mn(i);if(t.aim>.01&&a.ammo>=0&&(i=jo(i,o,a,t.focus,t.aim),o=Mn(i)),Ii(e,Mi(r),o,xi(n)),a.ammo>=0&&!a.down&&ai(e,o.pos[J.HAND_R],o.rot[J.HAND_R],r),t.dash>.15){let[r,a]=[Math.sin(i.yaw),Math.cos(i.yaw)],{x:o,y:s,z:c}=t.p;Mo(e,t,n,([e,t,n])=>[o+e*a-n*r,s+t,c-e*r-n*a])}},Po=Object.keys(y).length,Fo=(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},Io=(e,t,n,r)=>{let[i,a]=[Math.floor(e),Math.floor(t)],[o,s]=[e-i,t-a].map(e=>e*e*(3-2*e)),c=(e,t)=>Fo((i+e)%n,(a+t)%n,r);return(c(0,0)*(1-o)+c(1,0)*o)*(1-s)+(c(0,1)*(1-o)+c(1,1)*o)*s},Lo=(e,t,n,r,i)=>{let[a,o]=[0,.5];for(let s=0;s<r;s++,o/=2)a+=o*Io(e*(1<<s),t*(1<<s),n<<s,i+s);return a/(1-o*2)},Ro=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),zo=(e,t)=>e.map(e=>e*t),Bo=e=>Math.min(Math.max(e,0),1),Vo=Math.PI*2,Ho=[];Ho[y.BRICK]=(e,t)=>{let n=Math.floor(t*8),r=e*4+(n&1)*.5,[i,a,o]=[Math.floor(r)%4,r%1,t*8%1],s=Io(e*16,t*16,16,5),c=.8+.4*s;return a<.05||o<.1?[zo([165,160,150],.7+.3*c),.1+.1*s]:[zo([170,78,56],(.8+.4*Fo(i,n,1))*c*(.85+.15*o)),.7+.2*s+.1*Bo(Math.min(a-.05,o-.1)*12)]},Ho[y.TILE]=(e,t)=>{let[n,r]=[Math.floor(e*4),Math.floor(t*4)],[i,a]=[e*4%1,t*4%1],o=Io(e*16,t*16,16,7),s=.9+.2*o;return i<.05||a<.05?[zo([85,85,80],s),.1]:[zo([196,190,172],s*(.88+.08*(n+r&1)+.1*Fo(n,r,2))),.8+.1*o+.1*Bo((Math.min(i,a)-.05)*14)]},Ho[y.LAVA]=(e,t)=>{let n=Lo(e*4,t*4,4,4,11),r=Math.max(0,1-Math.abs(n-.5)*7)**2;return[Ro(Ro([55,8,4],[230,70,8],n),[255,215,90],r),.5]},Ho[y.STONE]=(e,t)=>{let n=Lo(e*8,t*8,8,4,3);return[zo([128,124,120],.45+.7*(n*1.3+.1*Fo(Math.floor(e*128),Math.floor(t*128),4))),Bo(n*1.4-.2)]},Ho[y.METAL]=(e,t)=>{let[n,r,i,a]=[Math.floor(e*2),Math.floor(t*2),e*2%1,t*2%1],o=Bo((Io(e*8,t*8,8,13)-.68)*6),s=e=>Math.min(Math.max(Math.round((e-.1)/.4),0),2)*.4+.1,[c,l]=[s(i),s(a)],u=c==l&&c==.5?1:Math.hypot(i-c,a-l),d=Bo(1-u/.07),f=zo([98,108,124],(.9+.2*Io(e*32,t*32,32,9)+.12*Fo(n,r,6))*(1+.3*d)*(.65+.35*Bo((u-.06)/.04)));return Math.min(i,a,1-i,1-a)<.03?[zo([40,44,50],1+o),.05]:[Ro(f,[105,68,45],o*.7),.5+.1*(1-o)+.4*d]},Ho[y.WOOD]=(e,t)=>{let n=Math.floor(t*8),r=e*2+Fo(n,0,8)*2,[i,a,o]=[Math.floor(r)%2,r%1,t*8%1],s=Fo(n,i,3),c=.5+.5*Math.sin(Vo*(t*40+2.5*Io(e*4,t*4,4,21)+s*7));return o<.08||a<.015?[[28,18,10],.05]:[Ro([92,58,32],[158,106,62],c*.6+s*.35),.7+.15*c+.15*Bo((o-.08)*15)]},Ho[y.MOSS]=(e,t)=>{let n=Math.floor(t*4),r=e*2+(n&1)*.5,[i,a,o]=[Math.floor(r)%2,r%1,t*4%1],s=Math.min(a,1-a,(o<.5?o:1-o)*.5),c=a<.04||o<.06,l=Bo((.3*Lo(e*12,t*12,12,3,17)-.03-s)*12),u=Io(e*64,t*64,64,19),d=zo([128,126,118],(.7+.4*Fo(i,n,5))*(.7+.5*Io(e*16,t*16,16,15)));return[Ro(c?zo(d,.45):d,Ro([52,100,34],[96,148,56],u),l),c?.1+.6*l*u:.6+.2*Bo(s*30)+.2*l*u]},Ho[y.GRATE]=(e,t)=>{let[n,r]=[e*8%1,t*8%1],i=Math.max(Math.abs(n-.5),Math.abs(r-.5)),a=Math.min(Math.abs(n-.5),Math.abs(r-.5))>.43,o=Io(e*16,t*16,16,23);return i<.36?[[9,9,12],0]:[zo(Ro([104,108,116],[96,80,68],Bo((o-.55)*4)),(a?1.25:1)-(.5-i)*2.2+.2*o),a?1:.6+.4*Bo((i-.36)*12)]},Ho[y.CONCRETE]=(e,t)=>{let[n,r]=[e*2%1,t*2%1],i=Lo(e*4,t*4,4,3,41),a=Fo(Math.floor(e*128),Math.floor(t*128),43)>.992,o=Math.hypot(n%.5-.25,r%.5-.25)<.02,s=(.94+.1*i+.03*Fo(Math.floor(e*2),Math.floor(t*2),44))*(a||o?.9:1);return n<.015||r<.015?[zo([160,164,172],s),.3]:[zo([206,209,214],s),o?.5:.8+.2*i-(a?.15:0)]},Ho[y.GLASS]=(e,t)=>{let n=e*2%1,r=((n+t*.7)%1-.5)/.12,i=Math.exp(-r*r);return n<.03||t<.03?[zo([150,158,170],1-.3*n),.9]:[Ro(Ro([7,20,44],[48,88,136],t**2),[120,160,200],i*.18),.4]},Ho[y.STEEL]=(e,t)=>{let n=Math.floor(t*128),r=.5*Fo(n,3,31)+.5*Io(e*8,0,8,n+7),i=e*4%1;return i<.03?[[60,66,76],.1]:[zo([176,184,196],.8+.35*r+(i>.97?.15:0)),.6+.2*r]},Ho[y.PAINT]=(e,t)=>{let[n,r]=[e*2%1,t*2%1],i=Fo(Math.floor(e*128),Math.floor(t*128),47);return n<.02||r<.02?[[200,200,206],.3]:[zo([246,246,248],.96+.06*i),.85+.04*i]};var Uo=()=>{let e=new Uint8ClampedArray(Po*128*128*4);return Ho.forEach((t,n)=>{for(let r=0;r<16384;r++){let[i,a]=t(r%128/128,Math.floor(r/128)/128);e.set([...i,a*255],(n*128*128+r)*4)}}),e},Wo=[18,26],Go=8,Ko=40,qo=55,Jo=-60,Yo=[[1,.45,.12],[.2,.6,1],[.9,.15,.2],[.25,.85,.55]],Xo=({brushes:e})=>{let[t,n,r,i]=[0,2].flatMap(t=>[Math.min(...e.map(e=>e.min[t])),Math.max(...e.map(e=>e.max[t]))]),[a,o,s]=[(t+n)/2,(r+i)/2,Math.hypot(n-t,i-r)/2];return Wo.flatMap((e,t)=>Array.from({length:e},(n,r)=>{let i=e=>Fo(r,t,Go+e),c=(r+i(1)*.8)/e*2*Math.PI,l=s+Ko+t*qo+i(2)*30,[u,d]=[a+l*Math.cos(c),o+l*Math.sin(c)],[f,p]=[5+i(3)*8,5+i(4)*8],m=t?-5+i(5)**2*90:-20+i(5)*30,h=[y.GLASS,y.STEEL,y.CONCRETE][+(i(6)>.7)+ +(i(6)>.85)],g={min:[u-f,Jo,d-p],max:[u+f,m,d+p],top:y.CONCRETE,side:h};return i(7)<.35?[g,{min:[u-f/2,m,d-p/2],max:[u+f/2,m+3+i(8)*3,d+p/2],top:y.PAINT,side:y.PAINT,tint:Yo[Math.floor(i(9)*Yo.length)]}]:[g]}).flat())},Zo=r,Qo=o+.05,$o=1.5,es=.6,ts=8,ns=2.5,rs=3,is=.4,as=.012,os=.2,ss=[1.2,1.45],cs=[1.6,.12,.08],ls=[.9,.07,.05],us=[.85,.07,.05],ds=(e,t,n,r)=>{let i=-1/0;for(let a of e)if(a!=t&&a.min[0]<=n&&n<=a.max[0]&&a.min[2]<=r&&r<=a.max[2]){if(a.max[1]>t.max[1]+.001){if(a.min[1]<t.max[1])return 1/0}else i=Math.max(i,a.max[1])}return t.max[1]-i},fs=({brushes:e,floor:t},n)=>{let r=n.max.map((e,t)=>e-n.min[t]),i=[...r].sort((e,t)=>e-t),a={beam:i[1]<=es&&i[2]>=2*es,lips:[],stripes:[]};if(a.beam)return a;for(let i of[0,2]){let o=2-i;for(let t of[0,1]){let s=[n.min[0],0,n.min[2]];s[i]=(t?n.max:n.min)[i]+(t?is:-.4),s[o]=(n.min[o]+n.max[o])/2;let c=ds(e,n,s[0],s[2]);c>Zo&&c<=Qo&&r[o]>=$o&&a.lips.push([i,t])}n.min[1]>t&&r[1]>=ns&&r[o]>=ts&&r[i]<=rs&&a.stripes.push([i,0],[i,1])}return a},ps=(e,t,n,r,i,a,o)=>{let[s,c]=[(r+1)%3,(r+2)%3],l=[0,0,0];l[r]=i?1:-1;for(let[u,d]of[[0,0],[1,0],[1,1],[0,0],[1,1],[0,1]]){let f=[0,0,0];[f[r],f[s],f[c]]=[(i?n:t)[r],(u?n:t)[s],(d?n:t)[c]],e.push(...f,...l,o[0],o[1],a,o[2])}},ms=e=>{let t=[];for(let n of e.brushes){let{beam:r,lips:i,stripes:a}=fs(e,n),[o,s]=[n.min.map(e=>e-as),n.max.map(e=>e+as)];if(r)for(let e=0;e<3;e++)for(let n of[0,1])(e!=1||n)&&ps(t,o,s,e,n,-1,us);for(let[e,r]of i){let i=r?1:-1,a=(r?n.max:n.min)[e],o=[n.min[0],n.max[1]+as,n.min[2]],s=[n.max[0],n.max[1]+as,n.max[2]];[o[e],s[e]]=r?[a-os,a]:[a,a+os],ps(t,o,s,1,1,-2,cs);let[c,l]=[o.slice(),s.slice()];[c[1],l[1]]=[n.max[1]-os,n.max[1]],[c[e],l[e]]=[a+i*as,a+i*as],ps(t,c,l,e,r,-2,cs)}for(let[e,r]of a){let i=2-e,[a,o]=[[...n.min],[...n.max]];[a[1],o[1]]=[n.min[1]+ss[0],n.min[1]+ss[1]],[a[i],o[i]]=[n.min[i]+.3,n.max[i]-.3],a[e]=o[e]=(r?n.max:n.min)[e]+(r?as:-.012),ps(t,a,o,e,r,-2,ls)}}return t},hs=4.2,gs=({teams:e})=>{let t=[];return e.forEach(({base:[e,n,r]},i)=>{let a=Yt(i),o=a.map(e=>.25+.45*e),s=(i,a,o,s,c,l)=>ps(t,[e+i,n+l,r+a],[e+o,n+l,r+s],1,1,-1,c);s(-4.2,-4.2,hs,hs,o,.02);for(let[e,t,n,r]of[[-4.2,-4.2,hs,-3.85],[-4.2,3.85,hs,hs],[-4.2,-4.2,-3.85,hs],[3.85,-4.2,hs,hs]])s(e,t,n,r,a.map(e=>e*.8),.03)}),t},_s=1<<18,vs=2,ys=1024,bs=.6,xs=Math.tan(70*Math.PI/360),Ss=10,Cs=4,ws=`#version 300 es
2
2
  layout(location=0)in vec3 p;layout(location=1)in vec3 n;layout(location=2)in vec4 c;
3
3
  uniform mat4 m;uniform float Y;uniform vec3 J[3];out vec3 P,N;out vec4 C;
4
4
  void main(){
5
5
  if(Y>.5){vec2 q=vec2(gl_VertexID&1,gl_VertexID>>1)*4.-1.;gl_Position=vec4(q,1,1);P=J[0]*q.x+J[1]*q.y+J[2];N=vec3(0);C=vec4(0);return;}
6
- P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,Qo=`#version 300 es
7
- out vec2 U;void main(){U=vec2(gl_VertexID&1,gl_VertexID>>1)*2.;gl_Position=vec4(U*2.-1.,0,1);}`,$o=`#version 300 es
6
+ P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,Ts=`#version 300 es
7
+ out vec2 U;void main(){U=vec2(gl_VertexID&1,gl_VertexID>>1)*2.;gl_Position=vec4(U*2.-1.,0,1);}`,Es=`#version 300 es
8
8
  precision highp float;uniform sampler2D S[4];uniform vec4 Y;uniform float L;in vec2 U;out vec4 o;
9
9
  vec3 b(vec2 x){vec3 c=texture(S[0],x).rgb;return c*smoothstep(.9,2.,max(c.r,max(c.g,c.b)));}
10
10
  #define T(k)texture(S[0],U+Y.xy*(k)).rgb
@@ -20,12 +20,12 @@ float a=atan(q.y,q.x)*24.,h=fract(sin(floor(a)*12.9898)*43758.5453);
20
20
  c+=L*step(.85-.5*L,h)*sin(fract(a)*3.1416)*smoothstep(.2,.6,length(q))*fract(length(q)*3.-Y.w*.002+h*9.)*.22;
21
21
  c*=1.-(.7+.3*L)*dot(q,q);
22
22
  c=pow(c*vec3(.97,1.,1.03),vec3(.92))+(fract(sin(dot(gl_FragCoord.xy+Y.w,vec2(12.9898,78.233)))*43758.5453)-.5)*.03;}
23
- o=vec4(c,1);}`,es=[[.04,8],[.25,30],[0,1],[.08,10],[.8,48],[.06,12],[.3,20],[.7,40],[.06,14],[1.5,110],[.9,60],[.25,30],[.1,24]],ts=`#version 300 es
23
+ o=vec4(c,1);}`,Ds=[[.04,8],[.25,30],[0,1],[.08,10],[.8,48],[.06,12],[.3,20],[.7,40],[.06,14],[1.5,110],[.9,60],[.25,30],[.1,24]],Os=`#version 300 es
24
24
  precision highp float;precision highp sampler2DArray;precision highp sampler2DArrayShadow;
25
25
  in vec3 P,N;in vec4 C;uniform vec3 E;uniform float T,Z,Y;uniform int Q;
26
26
  uniform vec4 A[16],B[16],K[16],F;uniform vec3 G[16],H[5],O,X;uniform mat4 M[4],W;
27
27
  uniform sampler2DArray S;uniform sampler2DArrayShadow D;out vec4 o;
28
- const vec2 SP[${es.length}]=vec2[](${es.map(([e,t])=>`vec2(${e},${t})`)});
28
+ const vec2 SP[${Ds.length}]=vec2[](${Ds.map(([e,t])=>`vec2(${e},${t})`)});
29
29
  vec3 e(vec3 x){return 2.*(1.-exp(-.5*x));}
30
30
  vec3 K0(vec3 d){
31
31
  float h=d.y,k=max(dot(d,O),0.);
@@ -36,19 +36,19 @@ void main(){
36
36
  if(Z<0.)return;
37
37
  if(Y>.5){o=vec4(K0(normalize(P)),1);return;}
38
38
  float L=C.z,s=step(0.,L),I=floor(C.w*.5),g=step(abs(L-${y.LAVA}.),.5)+step(L,-1.5);
39
- vec4 t=texture(S,vec3(C.xy/${Go}.+vec2(g*T*.01,0),max(L,0.)));
39
+ vec4 t=texture(S,vec3(C.xy/${vs}.+vec2(g*T*.01,0),max(L,0.)));
40
40
  vec3 c=mix(vec3(C.xy,C.w),t.rgb,s);
41
41
  vec3 n=normalize(N),dx=dFdx(P),dy=dFdy(P),a=cross(dy,n),b=cross(n,dx);
42
42
  float h=t.a*s*0.06,det=dot(dx,a);
43
- float f=1.-smoothstep(.6,2.5,${128/Go}.*max(length(dFdx(C.xy)),length(dFdy(C.xy))));
43
+ float f=1.-smoothstep(.6,2.5,${128/vs}.*max(length(dFdx(C.xy)),length(dFdy(C.xy))));
44
44
  vec3 m=normalize(abs(det)*n-sign(det)*f*(dFdx(h)*a+dFdy(h)*b)+n*1e-9);
45
- vec2 R=SP[int(s>0.?L+.5:${so}.)];
45
+ vec2 R=SP[int(s>0.?L+.5:${Po}.)];
46
46
  vec3 y=mix(vec3(1),G[int(min(I,15.))]*(C.w-2.*I),s),V=normalize(E-P),w=normalize(n+m);
47
47
  float sd=max(dot(m,O),0.)*smoothstep(0.,.1,dot(n,O)),sv=1.;
48
48
  if(sd>0.&&g<1.){
49
49
  vec4 q=W*vec4(P+n*.08,1);q.xyz=q.xyz*.5+.5;
50
50
  float v=0.;
51
- for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/Ko},0,q.z-.0004));
51
+ for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/ys},0,q.z-.0004));
52
52
  sv=mix(v/4.,1.,smoothstep(.8,1.,max(abs(q.x-.5),abs(q.y-.5))*2.));}
53
53
  vec3 l=y*(mix(mix(H[1],H[0],max(w.y,0.)),H[2],max(-w.y,0.))+X*sd*sv),sp=X*sv*sd*pow(max(dot(m,normalize(O+V)),0.),R.y);
54
54
  for(int i=0;i<16;i++){
@@ -60,10 +60,10 @@ w*=w*smoothstep(u,u+(1.-u)*.4,-dot(d,B[i].xyz))*max(dot(m,d),0.);
60
60
  if(w>0.&&k>=0.){
61
61
  vec4 q=M[int(k)]*vec4(P+n*.03,1);q.xyz=q.xyz/q.w*.5+.5;
62
62
  float v=0.;
63
- for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/Ko},k+1.,q.z-.0005));
63
+ for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/ys},k+1.,q.z-.0005));
64
64
  w*=v/4.;}
65
65
  l+=K[i].rgb*w;
66
66
  sp+=K[i].rgb*w*pow(max(dot(m,normalize(d+V)),0.),R.y);}
67
67
  c=c*mix(e(l),vec3(1.4),g)+e(sp*R.x*(.4+.6*mix(1.,t.a,s)));
68
68
  c+=step(abs(L-${y.GLASS}.),.5)*K0(reflect(-V,m))*(.1+.9*pow(1.-max(dot(m,V),0.),4.));
69
- o=vec4(mix(c,F.rgb,1.-exp(-F.a*length(P-E))),1.);}`,ns=(e,t,n,r,i=0,a=Jo,[o,s]=[.1,400])=>{let[c,l,u]=Nt(t,n,i),d=(s+o)/(s-o),f=[c.map(e=>e/(a*r)),l.map(e=>e/a),u.map(e=>e*d),u].map(t=>[...t,-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]);return f[2][3]-=2*s*o/(s-o),Float32Array.from({length:16},(e,t)=>f[t&3][t>>2])},rs=(e,t,n,r)=>{let i=e[3]*t+e[7]*n+e[11]*r+e[15];if(i<=0)return;let a=e[0]*t+e[4]*n+e[8]*r+e[12],o=e[1]*t+e[5]*n+e[9]*r+e[13];return[.5+a/(2*i),.5-o/(2*i)]},is=({p:e,d:t,cone:n,range:r})=>ns(e,Math.atan2(-t[0],-t[2]),Math.atan2(t[1],Math.hypot(t[0],t[2])),1,0,Math.min(Math.tan(Math.acos(n)),5.7),[.3,r]),as=e=>{let[t,n,r]=[0,0,0].map(()=>/* @__PURE__ */ new Float32Array(64)),i=/* @__PURE__ */ new Float32Array(64),a=0,o=e.slice(0,16);return o.forEach((e,o)=>{let s=e.shadow&&e.kind==cn.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==cn.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(is(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},os=(e,t,n=64,r=100)=>{let i=e.map(e=>-e),a=Math.hypot(i[0],i[2]),o=a>.001?[-i[2]/a,0,i[0]/a]:[1,0,0],s=[o[1]*i[2]-o[2]*i[1],o[2]*i[0]-o[0]*i[2],o[0]*i[1]-o[1]*i[0]],c=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],[l,u]=[n/2,n/Ko],d=[o,s].map(e=>[...e.map(e=>e/l),-(Math.round(c(e,t)/u)*u)/l]);return d.push([...i.map(e=>e/r),-c(i,t)/r],[0,0,0,1]),Float32Array.from({length:16},(e,t)=>d[t&3][t>>2])},ss=({def:e})=>[...new Map([[`1,1,1`,[1,1,1]],...e.brushes.flatMap(({tint:e})=>e?[[`${e}`,e]]:[])]).values()].slice(0,16),cs=[[0,0],[1,0],[1,1],[0,0],[1,1],[0,1]],ls=e=>{let{brushes:t,floor:n}=e.def,r=[],i=ss(e).map(String);return t.forEach((e,a)=>{let o=1+2*Math.max(0,i.indexOf(`${e.tint}`));for(let i=0;i<3;i++){let[s,c]=[(i+1)%3,(i+2)%3],[l,u]=i==0?[2,1]:i==1?[0,2]:[0,1];for(let d of[0,1]){let f=d?e.max[i]:e.min[i];if(t.some((t,n)=>n!=a&&(d?t.min[i]:t.max[i])==f&&t.min[s]<=e.min[s]&&t.max[s]>=e.max[s]&&t.min[c]<=e.min[c]&&t.max[c]>=e.max[c])||i==1&&!d&&e.min[1]<=n)continue;let p=[0,0,0];p[i]=d?1:-1;for(let[t,n]of cs){let a=[0,0,0];[a[i],a[s],a[c]]=[f,(t?e.max:e.min)[s],(n?e.max:e.min)[c]],r.push(...a,...p,a[l],a[u],i==1&&d?e.top:e.side,o)}}}}),r},us=({sky:[e,t]})=>[e.map(e=>(e*.45+.55)*.74),t.map(e=>(e*.7+.3)*.58),t.map((e,t)=>e*[1,.92,.8][t]*.34),e,t],ds=e=>({...e,def:{...e.def,brushes:[...e.def.brushes,...Co(e.def)]}}),fs=({fog:e,sky:t})=>e?[...[0,1,2].map(n=>e[n]+(t[1][n]-e[n])*qo),e[3]]:[...t[1],0],ps=2073600,ms=(e,t,n)=>{let r=Math.min(n,2,Math.sqrt(ps/(e*t||1)));return[Math.round(e*r),Math.round(t*r)]},hs=(e,t)=>{let n=/* @__PURE__ */ new Map,r=performance.now()/1e3,i=e.getContext(`webgl2`,{antialias:!1,depth:!1});if(!i)throw Error(`WebGL2 is not available`);let a=document.createElement(`canvas`).getContext(`2d`),o=/* @__PURE__ */ new Map,s=e=>{let t=o.get(e);if(!t){a.fillStyle=`#888`,a.fillStyle=e;let n=parseInt(a.fillStyle.slice(1),16),r=n>=0?n:8947848;o.set(e,t=[r>>16,r>>8&255,r&255].map(e=>e/255))}return t},c=()=>ms(e.clientWidth,e.clientHeight,devicePixelRatio),l=[...ls({...t,def:{...t.def,brushes:[...t.def.brushes,...Co(t.def)]}}),...Vo(t.def),...Uo(t.def)],{sun:u,sky:d}=t.def,f=u.dir.map(e=>e/Math.hypot(...u.dir)),p=go(),m=l.length*4,h=m+Wo,g={},_,v,y,b,x={},S,C,w,T,E=[0,0],D=[],O=!1,k=/* @__PURE__ */ new Float32Array(16),A=()=>{i.bufferData(i.ARRAY_BUFFER,h,i.DYNAMIC_DRAW),i.bufferSubData(i.ARRAY_BUFFER,0,new Float32Array(l))},j=(e,t,n)=>{let r=i.createProgram();for(let[n,a]of[[i.VERTEX_SHADER,e],[i.FRAGMENT_SHADER,t]]){let e=i.createShader(n);i.shaderSource(e,a),i.compileShader(e),i.attachShader(r,e)}return i.linkProgram(r),i.useProgram(r),[r,Object.fromEntries(n.map(e=>[e,i.getUniformLocation(r,e)]))]},M=(e,t)=>{let n=i.createTexture();i.bindTexture(i.TEXTURE_2D,n),i.texStorage2D(i.TEXTURE_2D,1,S,e,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);let r=i.createFramebuffer();return i.bindFramebuffer(i.FRAMEBUFFER,r),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,n,0),D.push(()=>i.deleteTexture(n),()=>i.deleteFramebuffer(r)),{t:n,f:r,w:e,h:t}},ee=(e,t)=>{D.splice(0).forEach(e=>e()),E=[e,t],w=M(e,t),T=[1,2,3].map(n=>[0,1].map(()=>M(e>>n||1,t>>n||1)));let n=n=>{let r=i.createRenderbuffer();return i.bindRenderbuffer(i.RENDERBUFFER,r),i.renderbufferStorageMultisample(i.RENDERBUFFER,Xo,n,e,t),D.push(()=>i.deleteRenderbuffer(r)),r};i.bindFramebuffer(i.FRAMEBUFFER,C=i.createFramebuffer()),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,n(S)),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,n(i.DEPTH_COMPONENT24)),D.push(()=>i.deleteFramebuffer(C))},N=(e,t,n,r,...a)=>{i.bindFramebuffer(i.FRAMEBUFFER,e?.f??null),i.viewport(0,0,e?.w??E[0],e?.h??E[1]),a.forEach((e,t)=>{i.activeTexture(i.TEXTURE0+t),i.bindTexture(i.TEXTURE_2D,e.t)}),i.uniform4f(x.Y,n,r,t,performance.now()%1e4),i.drawArrays(i.TRIANGLES,0,3)},P=()=>{S=i.getExtension(`EXT_color_buffer_float`)?i.RGBA16F:i.RGBA8,D.length=0,E=[0,0],[b,x]=j(Qo,$o,[`S`,`Y`,`L`]),i.uniform1iv(x.S,[0,1,2,3]),[y,g]=j(Zo,ts,[`m`,`E`,`T`,`Z`,`Q`,`A`,`B`,`K`,`M`,`D`,`F`,`G`,`W`,`H`,`O`,`X`,`Y`,`J`]),i.uniform1i(g.D,1),i.bindBuffer(i.ARRAY_BUFFER,i.createBuffer()),A(),[3,3,4].reduce((e,t,n)=>(i.enableVertexAttribArray(n),i.vertexAttribPointer(n,t,i.FLOAT,!1,40,e*4),e+t),0),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D_ARRAY,_=i.createTexture()),i.texStorage3D(i.TEXTURE_2D_ARRAY,1,i.DEPTH_COMPONENT24,Ko,Ko,5);for(let[e,t]of[[i.TEXTURE_MIN_FILTER,i.LINEAR],[i.TEXTURE_MAG_FILTER,i.LINEAR],[i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE],[i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE],[i.TEXTURE_COMPARE_MODE,i.COMPARE_REF_TO_TEXTURE]])i.texParameteri(i.TEXTURE_2D_ARRAY,e,t);i.bindFramebuffer(i.FRAMEBUFFER,v=i.createFramebuffer()),i.drawBuffers([i.NONE]),i.bindFramebuffer(i.FRAMEBUFFER,null),i.polygonOffset(2,4),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D_ARRAY,i.createTexture()),i.texImage3D(i.TEXTURE_2D_ARRAY,0,i.RGBA8,128,128,so,0,i.RGBA,i.UNSIGNED_BYTE,p),i.generateMipmap(i.TEXTURE_2D_ARRAY),i.texParameteri(i.TEXTURE_2D_ARRAY,i.TEXTURE_MIN_FILTER,i.LINEAR_MIPMAP_LINEAR);let e=i.getExtension(`EXT_texture_filter_anisotropic`);e&&i.texParameterf(i.TEXTURE_2D_ARRAY,e.TEXTURE_MAX_ANISOTROPY_EXT,8),i.enable(i.DEPTH_TEST),i.depthFunc(i.LEQUAL),F();let[t,n]=c();t&&n&&ee(t,n)},F=()=>{let e=ss(ds(t));i.uniform4fv(g.F,fs(t.def)),i.uniform3fv(g.H,us(t.def).flat()),i.uniform3fv(g.O,f),i.uniform3fv(g.X,u.color),i.uniform3fv(g.G,Float32Array.from({length:48},(t,n)=>e[n/3|0]?.[n%3]??1)),i.clearColor(...d[1],1)};P();let I=e=>{e.preventDefault(),O=!0},L=()=>{P(),O=!1};return e.addEventListener(`webglcontextlost`,I),e.addEventListener(`webglcontextrestored`,L),{frame(a,o,u,d,p,S,D,j,M,P){let[F,I]=c();if(O||!F||!I)return;(e.width!=F||e.height!=I)&&(e.width=F,e.height=I),(E[0]!=F||E[1]!=I)&&ee(F,I);let L=Math.tan((70+S.fov)*Math.PI/360);k=ns(a,o,u,F/I,S.roll,L);let R=[],z=performance.now()/1e3,te=Math.min(.1,z-r);r=z,ro(n,d,te,t),M?.bases.forEach((e,t)=>rn(R,e,Xt(t),z)),M?.flags.forEach(e=>sn(R,e,Xt(e.team),z)),M?.racks?.forEach((e,t)=>e&&Ya(R,e,Xt(t),z)),M?.packs?.forEach(e=>Za(R,e,z));for(let e of d)oo(R,n.get(e.id),s(p.get(e.id)??`#888`),+(Math.hypot(e.x-a[0],e.z-a[2])<Yo));let ne=R.length;P?.draw(R,a);let re=R.length;j?.draw(R,a,o,u,S.roll,s(p.get(j.id)??`#888`)),m+R.length*4>h&&(h=m+R.length*8,A()),i.bufferSubData(i.ARRAY_BUFFER,m,new Float32Array(R));let ie=as(D),B=l.length/10,V=os(f,a);i.uniform1f(g.Z,-1),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D_ARRAY,null),i.bindFramebuffer(i.FRAMEBUFFER,v),i.viewport(0,0,Ko,Ko),i.enable(i.POLYGON_OFFSET_FILL);for(let e=0;e<=ie.maps;e++)i.framebufferTextureLayer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,_,0,e),i.uniformMatrix4fv(g.m,!1,e?ie.m.subarray(e*16-16,e*16):V),i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,0,B+ne/10);i.disable(i.POLYGON_OFFSET_FILL),i.bindTexture(i.TEXTURE_2D_ARRAY,_),i.activeTexture(i.TEXTURE0),i.bindFramebuffer(i.FRAMEBUFFER,C),i.viewport(0,0,F,I),i.uniformMatrix4fv(g.m,!1,k),i.uniformMatrix4fv(g.W,!1,V),i.uniform3fv(g.E,a),i.uniform1f(g.T,performance.now()/1e3),i.uniform1f(g.Z,1),i.uniform1i(g.Q,ie.n),i.uniform4fv(g.A,ie.a),i.uniform4fv(g.B,ie.b),i.uniform4fv(g.K,ie.k),i.uniformMatrix4fv(g.M,!1,ie.m),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT);let[ae,oe,se]=Nt(o,u,S.roll);i.uniform3fv(g.J,[ae.map(e=>e*L*(F/I)),oe.map(e=>e*L),se].flat()),i.uniform1f(g.Y,1),i.drawArrays(i.TRIANGLES,0,3),i.uniform1f(g.Y,0),i.drawArrays(i.TRIANGLES,0,B+re/10),R.length>re&&(i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,B+re/10,(R.length-re)/10)),i.bindFramebuffer(i.READ_FRAMEBUFFER,C),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,w.f),i.blitFramebuffer(0,0,F,I,0,0,F,I,i.COLOR_BUFFER_BIT,i.NEAREST),i.useProgram(b),N(T[0][0],0,1/F,1/I,w),T.forEach(([e,t],n)=>{N(t,1,1/t.w,0,T[n&&n-1][0]),N(e,1,0,1/e.h,t)}),i.uniform1f(x.L,S.lines),N(void 0,2,0,0,w,...T.map(e=>e[0]));for(let e=3;e>0;e--)i.activeTexture(i.TEXTURE0+e),i.bindTexture(i.TEXTURE_2D,null);i.activeTexture(i.TEXTURE0),i.useProgram(y)},project:(e,t,n)=>rs(k,e,t,n),destroy(){e.removeEventListener(`webglcontextlost`,I),e.removeEventListener(`webglcontextrestored`,L),i.getExtension(`WEBGL_lose_context`)?.loseContext()}}},gs=1/60,_s=5,vs=(e,n)=>{let r=document.createElement(`div`),i=r.attachShadow({mode:`open`});i.innerHTML=`<style>:host{display:block;width:100%;height:100%}div{position:relative;width:100%;height:100%;overflow:hidden;background:#000;font:600 14px system-ui,sans-serif;color:#fff;text-shadow:0 1px 2px #000}canvas{display:block;width:100%;height:100%;cursor:pointer}i,p,b{position:absolute;pointer-events:none;user-select:none;margin:0}`+Sa+`i{left:50%;top:50%;width:6px;height:6px;margin:-3px;border-radius:50%;background:#fff;box-shadow:0 0 0 1px #0008}p{bottom:8px;left:12px}b{transform:translate(-50%,-100%);font-size:12px;white-space:nowrap}[hidden]{display:none}</style><div><canvas></canvas><i></i><p></p></div>`,e.append(r);let a=i.querySelector(`canvas`),o=i.querySelector(`p`),s=i.querySelector(`div`),c=Ta(s),l={roster:[],open:[],close:[]},u=e=>l[e].forEach(e=>e()),d=te(F),f=Ha(d),p=Tt();p.mute(Et()),c.mute(p.muted);let m=Ma(a,()=>c.mute(Dt(p)));a.addEventListener(`click`,()=>p.unlock());let h=ya(),g=xa(p),_=Ri(d),v=Sn(),y=Vi(d,p,c,h,v,m),b;try{b=hs(a,d)}catch{}let x=d.def.teams.map(e=>e.base),S=d.def.teams.map(e=>e.rack),C=[],w={id:-1,team:0},T,E,D=/* @__PURE__ */ new Map,O=/* @__PURE__ */ new Map,k=/* @__PURE__ */ new Map,A=!1,j=b?``:`WebGL2 is not available`,M=!1,ee=performance.now(),N=0,P=0,I=!1,L=n.socket??new WebSocket(n.url);L.binaryType=`arraybuffer`,L.onopen=()=>{A=!0,L.send(JSON.stringify({t:`join`,name:n.name})),u(`open`)},L.onclose=()=>{A=!1,j||=`Connection closed`,u(`close`)},L.onmessage=({data:e})=>{if(typeof e!=`string`){let t=at(e);if(t){f.snapshot(t,performance.now());for(let e of Cn(T,t)){let t=wn(e,w,e=>O.get(e)??`Someone`);t&&c.banner(t.text,t.team),e.kind==`start`&&([m.yaw,m.pitch]=[d.def.teams[w.team].spawns[0][3],0]);for(let t of Tn(e,w))p.play(t.id,t.at,t.gain,t.rate);e.kind==`tackle`&&(e.who==w.id?h.jolt():e.by==w.id&&h.punch())}T=t}return}let t=ot(e);t?.t==`roster`?(C=t.players,D=new Map(C.map(e=>[e.id,e.color])),O=new Map(C.map(e=>[e.id,e.name])),w={id:t.you,team:C.find(e=>e.id==t.you)?.team??0},f.you(w.id,w.team),o.textContent=`Players: ${C.length}`,u(`roster`)):t?.t==`end`?E={score:t.score,players:t.players}:t?.t==`full`&&(j=`Room is full`)};let R=e=>{let t=k.get(e);return t||(k.set(e,t=document.createElement(`b`)),s.append(t)),t},z=()=>{P=requestAnimationFrame(z);let e=performance.now(),n=ee;if(N=Math.min(N+(e-ee)/1e3,_s*gs),ee=e,!M){let e=f.me(0);e&&([m.yaw,m.pitch,M]=[e.yaw,e.pitch,!0]),N=0}for(;M&&N>=gs;N-=gs){let t=f.me(1),n=f.step({keys:m.take(),yaw:m.yaw,pitch:m.pitch},e);y.step(t,f.me(1)),A&&L.send(rt(n))}let r=f.me(N/gs),i=f.others(e),o=r?[r.x,r.y+ve(r),r.z]:[0,0,0];p.listen(o,m.yaw);let s=Math.min((e-n)/1e3,.1),l=e=>e==w.id?r:i.find(t=>t.id==e),u=T&&{bases:x,flags:Zt(T.flags,x,l),racks:S,packs:Ja(d.def.packs,T.packs)},C=f.events();h.update(r,m.keys,s,C),c.hurt(h.hurt),g.me(r,C,h.stride),g.others(i),_.update(r,s,h.kick,a.clientWidth/(a.clientHeight||1));let F=[o[0],o[1]+h.dy,o[2]],I=m.pitch+h.pitch;y.frame(r&&{eye:o,cam:F,yaw:m.yaw,pitch:m.pitch,drawn:I,muzzle:_.muzzle()},r,i,m.keys,s),r&&b&&b.frame(F,m.yaw,I,i,D,h,[...dn({eye:F,yaw:m.yaw,pitch:I,others:i,t:e/1e3,ctf:u}),...v.lights()],_,u,v),T&&(c.match(T,e=>O.get(e)??`?`),c.marks(r&&b?qa({eye:o,id:w.id,team:w.team,yaw:m.yaw,flags:T.flags,bases:x,where:e=>{let t=l(e);return t&&[t.x,t.y,t.z]},project:b.project}):[]),c.end(T.over?E:void 0,T.clock));let te=/* @__PURE__ */ new Set;for(let e of i){let n=[e.x,e.y+t+.3,e.z],i=r&&!ie(d,o,n)?b?.project(...n):void 0,a=R(e.id);te.add(e.id),a.hidden=!i,i&&(a.style.left=i[0]*100+`%`,a.style.top=i[1]*100+`%`);let s=O.get(e.id)??``;a.textContent!=s&&(a.textContent=s),a.style.color=D.get(e.id)??``}for(let[e,t]of k)te.has(e)||(t.remove(),k.delete(e));c.title(j||(A?M?m.locked()?``:`Click to play`:`Joining…`:`Connecting…`),d.def.name??``)};return P=requestAnimationFrame(z),{on:(e,t)=>void l[e].push(t),players:()=>C,destroy(){I||(I=!0,cancelAnimationFrame(P),m.destroy(),p.destroy(),b?.destroy(),L.onopen=L.onclose=L.onmessage=null,L.close(),document.exitPointerLock(),r.remove())}}};export{vs as tinyFps};
69
+ o=vec4(mix(c,F.rgb,1.-exp(-F.a*length(P-E))),1.);}`,ks=(e,t,n,r,i=0,a=xs,[o,s]=[.1,400])=>{let[c,l,u]=Mt(t,n,i),d=(s+o)/(s-o),f=[c.map(e=>e/(a*r)),l.map(e=>e/a),u.map(e=>e*d),u].map(t=>[...t,-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]);return f[2][3]-=2*s*o/(s-o),Float32Array.from({length:16},(e,t)=>f[t&3][t>>2])},As=(e,t,n,r)=>{let i=e[3]*t+e[7]*n+e[11]*r+e[15];if(i<=0)return;let a=e[0]*t+e[4]*n+e[8]*r+e[12],o=e[1]*t+e[5]*n+e[9]*r+e[13];return[.5+a/(2*i),.5-o/(2*i)]},js=({p:e,d:t,cone:n,range:r})=>ks(e,Math.atan2(-t[0],-t[2]),Math.atan2(t[1],Math.hypot(t[0],t[2])),1,0,Math.min(Math.tan(Math.acos(n)),5.7),[.3,r]),Ms=e=>{let[t,n,r]=[0,0,0].map(()=>/* @__PURE__ */ new Float32Array(64)),i=/* @__PURE__ */ new Float32Array(64),a=0,o=e.slice(0,16);return o.forEach((e,o)=>{let s=e.shadow&&e.kind==sn.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==sn.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(js(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},Ns=(e,t,n=64,r=100)=>{let i=e.map(e=>-e),a=Math.hypot(i[0],i[2]),o=a>.001?[-i[2]/a,0,i[0]/a]:[1,0,0],s=[o[1]*i[2]-o[2]*i[1],o[2]*i[0]-o[0]*i[2],o[0]*i[1]-o[1]*i[0]],c=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],[l,u]=[n/2,n/ys],d=[o,s].map(e=>[...e.map(e=>e/l),-(Math.round(c(e,t)/u)*u)/l]);return d.push([...i.map(e=>e/r),-c(i,t)/r],[0,0,0,1]),Float32Array.from({length:16},(e,t)=>d[t&3][t>>2])},Ps=({def:e})=>[...new Map([[`1,1,1`,[1,1,1]],...e.brushes.flatMap(({tint:e})=>e?[[`${e}`,e]]:[])]).values()].slice(0,16),Fs=[[0,0],[1,0],[1,1],[0,0],[1,1],[0,1]],Is=e=>{let{brushes:t,floor:n}=e.def,r=[],i=Ps(e).map(String);return t.forEach((e,a)=>{let o=1+2*Math.max(0,i.indexOf(`${e.tint}`));for(let i=0;i<3;i++){let[s,c]=[(i+1)%3,(i+2)%3],[l,u]=i==0?[2,1]:i==1?[0,2]:[0,1];for(let d of[0,1]){let f=d?e.max[i]:e.min[i];if(t.some((t,n)=>n!=a&&(d?t.min[i]:t.max[i])==f&&t.min[s]<=e.min[s]&&t.max[s]>=e.max[s]&&t.min[c]<=e.min[c]&&t.max[c]>=e.max[c])||i==1&&!d&&e.min[1]<=n)continue;let p=[0,0,0];p[i]=d?1:-1;for(let[t,n]of Fs){let a=[0,0,0];[a[i],a[s],a[c]]=[f,(t?e.max:e.min)[s],(n?e.max:e.min)[c]],r.push(...a,...p,a[l],a[u],i==1&&d?e.top:e.side,o)}}}}),r},Ls=({sky:[e,t]})=>[e.map(e=>(e*.45+.55)*.74),t.map(e=>(e*.7+.3)*.58),t.map((e,t)=>e*[1,.92,.8][t]*.34),e,t],Rs=e=>({...e,def:{...e.def,brushes:[...e.def.brushes,...Xo(e.def)]}}),zs=({fog:e,sky:t})=>e?[...[0,1,2].map(n=>e[n]+(t[1][n]-e[n])*bs),e[3]]:[...t[1],0],Bs=2073600,Vs=(e,t,n)=>{let r=Math.min(n,2,Math.sqrt(Bs/(e*t||1)));return[Math.round(e*r),Math.round(t*r)]},Hs=(e,t)=>{let n=/* @__PURE__ */ new Map,r=performance.now()/1e3,i=e.getContext(`webgl2`,{antialias:!1,depth:!1});if(!i)throw Error(`WebGL2 is not available`);let a=document.createElement(`canvas`).getContext(`2d`),o=/* @__PURE__ */ new Map,s=e=>{let t=o.get(e);if(!t){a.fillStyle=`#888`,a.fillStyle=e;let n=parseInt(a.fillStyle.slice(1),16),r=n>=0?n:8947848;o.set(e,t=[r>>16,r>>8&255,r&255].map(e=>e/255))}return t},c=()=>Vs(e.clientWidth,e.clientHeight,devicePixelRatio),l=[...Is({...t,def:{...t.def,brushes:[...t.def.brushes,...Xo(t.def)]}}),...ms(t.def),...gs(t.def)],{sun:u,sky:d}=t.def,f=u.dir.map(e=>e/Math.hypot(...u.dir)),p=Uo(),m=l.length*4,h=m+_s,g={},_,v,y,b,x={},S,C,w,T,E=[0,0],D=[],O=!1,k=/* @__PURE__ */ new Float32Array(16),A=()=>{i.bufferData(i.ARRAY_BUFFER,h,i.DYNAMIC_DRAW),i.bufferSubData(i.ARRAY_BUFFER,0,new Float32Array(l))},j=(e,t,n)=>{let r=i.createProgram();for(let[n,a]of[[i.VERTEX_SHADER,e],[i.FRAGMENT_SHADER,t]]){let e=i.createShader(n);i.shaderSource(e,a),i.compileShader(e),i.attachShader(r,e)}return i.linkProgram(r),i.useProgram(r),[r,Object.fromEntries(n.map(e=>[e,i.getUniformLocation(r,e)]))]},M=(e,t)=>{let n=i.createTexture();i.bindTexture(i.TEXTURE_2D,n),i.texStorage2D(i.TEXTURE_2D,1,S,e,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);let r=i.createFramebuffer();return i.bindFramebuffer(i.FRAMEBUFFER,r),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,n,0),D.push(()=>i.deleteTexture(n),()=>i.deleteFramebuffer(r)),{t:n,f:r,w:e,h:t}},ee=(e,t)=>{D.splice(0).forEach(e=>e()),E=[e,t],w=M(e,t),T=[1,2,3].map(n=>[0,1].map(()=>M(e>>n||1,t>>n||1)));let n=n=>{let r=i.createRenderbuffer();return i.bindRenderbuffer(i.RENDERBUFFER,r),i.renderbufferStorageMultisample(i.RENDERBUFFER,Cs,n,e,t),D.push(()=>i.deleteRenderbuffer(r)),r};i.bindFramebuffer(i.FRAMEBUFFER,C=i.createFramebuffer()),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,n(S)),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,n(i.DEPTH_COMPONENT24)),D.push(()=>i.deleteFramebuffer(C))},N=(e,t,n,r,...a)=>{i.bindFramebuffer(i.FRAMEBUFFER,e?.f??null),i.viewport(0,0,e?.w??E[0],e?.h??E[1]),a.forEach((e,t)=>{i.activeTexture(i.TEXTURE0+t),i.bindTexture(i.TEXTURE_2D,e.t)}),i.uniform4f(x.Y,n,r,t,performance.now()%1e4),i.drawArrays(i.TRIANGLES,0,3)},P=()=>{S=i.getExtension(`EXT_color_buffer_float`)?i.RGBA16F:i.RGBA8,D.length=0,E=[0,0],[b,x]=j(Ts,Es,[`S`,`Y`,`L`]),i.uniform1iv(x.S,[0,1,2,3]),[y,g]=j(ws,Os,[`m`,`E`,`T`,`Z`,`Q`,`A`,`B`,`K`,`M`,`D`,`F`,`G`,`W`,`H`,`O`,`X`,`Y`,`J`]),i.uniform1i(g.D,1),i.bindBuffer(i.ARRAY_BUFFER,i.createBuffer()),A(),[3,3,4].reduce((e,t,n)=>(i.enableVertexAttribArray(n),i.vertexAttribPointer(n,t,i.FLOAT,!1,40,e*4),e+t),0),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D_ARRAY,_=i.createTexture()),i.texStorage3D(i.TEXTURE_2D_ARRAY,1,i.DEPTH_COMPONENT24,ys,ys,5);for(let[e,t]of[[i.TEXTURE_MIN_FILTER,i.LINEAR],[i.TEXTURE_MAG_FILTER,i.LINEAR],[i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE],[i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE],[i.TEXTURE_COMPARE_MODE,i.COMPARE_REF_TO_TEXTURE]])i.texParameteri(i.TEXTURE_2D_ARRAY,e,t);i.bindFramebuffer(i.FRAMEBUFFER,v=i.createFramebuffer()),i.drawBuffers([i.NONE]),i.bindFramebuffer(i.FRAMEBUFFER,null),i.polygonOffset(2,4),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D_ARRAY,i.createTexture()),i.texImage3D(i.TEXTURE_2D_ARRAY,0,i.RGBA8,128,128,Po,0,i.RGBA,i.UNSIGNED_BYTE,p),i.generateMipmap(i.TEXTURE_2D_ARRAY),i.texParameteri(i.TEXTURE_2D_ARRAY,i.TEXTURE_MIN_FILTER,i.LINEAR_MIPMAP_LINEAR);let e=i.getExtension(`EXT_texture_filter_anisotropic`);e&&i.texParameterf(i.TEXTURE_2D_ARRAY,e.TEXTURE_MAX_ANISOTROPY_EXT,8),i.enable(i.DEPTH_TEST),i.depthFunc(i.LEQUAL),F();let[t,n]=c();t&&n&&ee(t,n)},F=()=>{let e=Ps(Rs(t));i.uniform4fv(g.F,zs(t.def)),i.uniform3fv(g.H,Ls(t.def).flat()),i.uniform3fv(g.O,f),i.uniform3fv(g.X,u.color),i.uniform3fv(g.G,Float32Array.from({length:48},(t,n)=>e[n/3|0]?.[n%3]??1)),i.clearColor(...d[1],1)};P();let I=e=>{e.preventDefault(),O=!0},L=()=>{P(),O=!1};return e.addEventListener(`webglcontextlost`,I),e.addEventListener(`webglcontextrestored`,L),{frame(a,o,u,d,p,S,D,j,M,P){let[F,I]=c();if(O||!F||!I)return;(e.width!=F||e.height!=I)&&(e.width=F,e.height=I),(E[0]!=F||E[1]!=I)&&ee(F,I);let L=Math.tan((70+S.fov)*Math.PI/360);k=ks(a,o,u,F/I,S.roll,L);let R=[],z=performance.now()/1e3,B=Math.min(.1,z-r);r=z,Ao(n,d,B,t),M?.bases.forEach((e,t)=>nn(R,e,Yt(t),z)),M?.flags.forEach(e=>on(R,e,Yt(e.team),z)),M?.racks?.forEach((e,t)=>e&&go(R,e,Yt(t),z)),M?.packs?.forEach(e=>So(R,e,z)),M?.ammo?.forEach(e=>Co(R,e,z));for(let e of d)No(R,n.get(e.id),s(p.get(e.id)??`#888`),+(Math.hypot(e.x-a[0],e.z-a[2])<Ss));let te=R.length;P?.draw(R,a);let ne=R.length;j?.draw(R,a,o,u,S.roll,s(p.get(j.id)??`#888`)),m+R.length*4>h&&(h=m+R.length*8,A()),i.bufferSubData(i.ARRAY_BUFFER,m,new Float32Array(R));let V=Ms(D),re=l.length/10,H=Ns(f,a);i.uniform1f(g.Z,-1),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D_ARRAY,null),i.bindFramebuffer(i.FRAMEBUFFER,v),i.viewport(0,0,ys,ys),i.enable(i.POLYGON_OFFSET_FILL);for(let e=0;e<=V.maps;e++)i.framebufferTextureLayer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,_,0,e),i.uniformMatrix4fv(g.m,!1,e?V.m.subarray(e*16-16,e*16):H),i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,0,re+te/10);i.disable(i.POLYGON_OFFSET_FILL),i.bindTexture(i.TEXTURE_2D_ARRAY,_),i.activeTexture(i.TEXTURE0),i.bindFramebuffer(i.FRAMEBUFFER,C),i.viewport(0,0,F,I),i.uniformMatrix4fv(g.m,!1,k),i.uniformMatrix4fv(g.W,!1,H),i.uniform3fv(g.E,a),i.uniform1f(g.T,performance.now()/1e3),i.uniform1f(g.Z,1),i.uniform1i(g.Q,V.n),i.uniform4fv(g.A,V.a),i.uniform4fv(g.B,V.b),i.uniform4fv(g.K,V.k),i.uniformMatrix4fv(g.M,!1,V.m),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT);let[U,ie,ae]=Mt(o,u,S.roll);i.uniform3fv(g.J,[U.map(e=>e*L*(F/I)),ie.map(e=>e*L),ae].flat()),i.uniform1f(g.Y,1),i.drawArrays(i.TRIANGLES,0,3),i.uniform1f(g.Y,0),i.drawArrays(i.TRIANGLES,0,re+ne/10),R.length>ne&&(i.clear(i.DEPTH_BUFFER_BIT),i.drawArrays(i.TRIANGLES,re+ne/10,(R.length-ne)/10)),i.bindFramebuffer(i.READ_FRAMEBUFFER,C),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,w.f),i.blitFramebuffer(0,0,F,I,0,0,F,I,i.COLOR_BUFFER_BIT,i.NEAREST),i.useProgram(b),N(T[0][0],0,1/F,1/I,w),T.forEach(([e,t],n)=>{N(t,1,1/t.w,0,T[n&&n-1][0]),N(e,1,0,1/e.h,t)}),i.uniform1f(x.L,S.lines),N(void 0,2,0,0,w,...T.map(e=>e[0]));for(let e=3;e>0;e--)i.activeTexture(i.TEXTURE0+e),i.bindTexture(i.TEXTURE_2D,null);i.activeTexture(i.TEXTURE0),i.useProgram(y)},project:(e,t,n)=>As(k,e,t,n),destroy(){e.removeEventListener(`webglcontextlost`,I),e.removeEventListener(`webglcontextrestored`,L),i.getExtension(`WEBGL_lose_context`)?.loseContext()}}},Us=1/60,Ws=5,Gs=(e,n)=>{let r=document.createElement(`div`),i=r.attachShadow({mode:`open`});i.innerHTML=`<style>:host{display:block;width:100%;height:100%}div{position:relative;width:100%;height:100%;overflow:hidden;background:#000;font:600 14px system-ui,sans-serif;color:#fff;text-shadow:0 1px 2px #000}canvas{display:block;width:100%;height:100%;cursor:pointer}i,p,b{position:absolute;pointer-events:none;user-select:none;margin:0}`+Ha+`i{left:50%;top:50%;width:6px;height:6px;margin:-3px;border-radius:50%;background:#fff;box-shadow:0 0 0 1px #0008}p{bottom:8px;left:12px}b{transform:translate(-50%,-100%);font-size:12px;white-space:nowrap}[hidden]{display:none}</style><div><canvas></canvas><i></i><p></p></div>`,e.append(r);let a=i.querySelector(`canvas`),o=i.querySelector(`p`),s=i.querySelector(`div`),c=Ga(s),l={roster:[],open:[],close:[]},u=e=>l[e].forEach(e=>e()),d=te(I),f=co(d),p=Tt();p.mute(Et()),c.mute(p.muted);let m=Qa(a,()=>c.mute(Dt(p)));a.addEventListener(`click`,()=>p.unlock());let h=za(),g=Va(p),_=ra(d),v=xn(),y=sa(d,p,c,h,v,m),b;try{b=Hs(a,d)}catch{}let x=d.def.teams.map(e=>e.base),S=d.def.teams.map(e=>e.rack),C=[],w={id:-1,team:0},T,E,D=/* @__PURE__ */ new Map,O=/* @__PURE__ */ new Map,k=/* @__PURE__ */ new Map,A=!1,j=b?``:`WebGL2 is not available`,M=!1,ee=performance.now(),N=0,P=0,F=!1,L=n.socket??new WebSocket(n.url);L.binaryType=`arraybuffer`,L.onopen=()=>{A=!0,L.send(JSON.stringify({t:`join`,name:n.name})),u(`open`)},L.onclose=()=>{A=!1,j||=`Connection closed`,u(`close`)},L.onmessage=({data:e})=>{if(typeof e!=`string`){let t=at(e);if(t){f.snapshot(t,performance.now());for(let e of Sn(T,t)){let t=Cn(e,w,e=>O.get(e)??`Someone`);t&&c.banner(t.text,t.team),e.kind==`start`&&([m.yaw,m.pitch]=[d.def.teams[w.team].spawns[0][3],0]);for(let t of wn(e,w))p.play(t.id,t.at,t.gain,t.rate);e.kind==`tackle`&&(e.who==w.id?h.jolt():e.by==w.id&&h.punch())}T=t}return}let t=ot(e);t?.t==`roster`?(C=t.players,D=new Map(C.map(e=>[e.id,e.color])),O=new Map(C.map(e=>[e.id,e.name])),w={id:t.you,team:C.find(e=>e.id==t.you)?.team??0},f.you(w.id,w.team),o.textContent=`Players: ${C.length}`,u(`roster`)):t?.t==`end`?E={score:t.score,players:t.players}:t?.t==`full`&&(j=`Room is full`)};let R=e=>{let t=k.get(e);return t||(k.set(e,t=document.createElement(`b`)),s.append(t)),t},z=()=>{P=requestAnimationFrame(z);let e=performance.now(),n=ee;if(N=Math.min(N+(e-ee)/1e3,Ws*Us),ee=e,!M){let e=f.me(0);e&&([m.yaw,m.pitch,M]=[e.yaw,e.pitch,!0]),N=0}for(;M&&N>=Us;N-=Us){let t=f.me(1),n=f.step({keys:m.take(),yaw:m.yaw,pitch:m.pitch},e);y.step(t,f.me(1)),A&&L.send(rt(n))}let r=f.me(N/Us),i=f.others(e),o=r?[r.x,r.y+ve(r),r.z]:[0,0,0];p.listen(o,m.yaw);let s=Math.min((e-n)/1e3,.1),l=e=>e==w.id?r:i.find(t=>t.id==e),u=T&&{bases:x,flags:Xt(T.flags,x,l),racks:S,packs:ho(d.def.packs,T.packs),ammo:ho(d.def.ammo,T.packs,d.def.packs?.length)},C=f.events();h.update(r,m.keys,s,C),c.hurt(h.hurt),g.me(r,C,h.stride),g.others(i),_.update(r,s,h.kick,a.clientWidth/(a.clientHeight||1));let F=[o[0],o[1]+h.dy,o[2]],I=m.pitch+h.pitch,B=r&&ia(d,o,F,m.yaw,m.pitch,I);B&&_.aim(B.local),y.frame(r&&B&&{eye:o,cam:F,yaw:m.yaw,pitch:m.pitch,drawn:I,muzzle:_.muzzle(),...B},r,i,m.keys,s),r&&b&&b.frame(F,m.yaw,I,i,D,h,[...un({eye:F,yaw:m.yaw,pitch:I,others:i,t:e/1e3,ctf:u}),...v.lights()],_,u,v),T&&(c.match(T,e=>O.get(e)??`?`),c.marks(r&&b?mo({eye:o,id:w.id,team:w.team,yaw:m.yaw,flags:T.flags,bases:x,where:e=>{let t=l(e);return t&&[t.x,t.y,t.z]},project:b.project}):[]),c.end(T.over?E:void 0,T.clock));let te=/* @__PURE__ */ new Set;for(let e of i){let n=[e.x,e.y+t+.3,e.z],i=r&&!re(d,o,n)?b?.project(...n):void 0,a=R(e.id);te.add(e.id),a.hidden=!i,i&&(a.style.left=i[0]*100+`%`,a.style.top=i[1]*100+`%`);let s=O.get(e.id)??``;a.textContent!=s&&(a.textContent=s),a.style.color=D.get(e.id)??``}for(let[e,t]of k)te.has(e)||(t.remove(),k.delete(e));c.title(j||(A?M?m.locked()?``:`Click to play`:`Joining…`:`Connecting…`),d.def.name??``)};return P=requestAnimationFrame(z),{on:(e,t)=>void l[e].push(t),players:()=>C,destroy(){F||(F=!0,cancelAnimationFrame(P),m.destroy(),p.destroy(),b?.destroy(),L.onopen=L.onclose=L.onmessage=null,L.close(),document.exitPointerLock(),r.remove())}}};export{Gs as tinyFps};
package/dist/local.js CHANGED
@@ -1 +1 @@
1
- var e={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},n={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},r={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},i={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},o=127,s=16,c=65536/(2*Math.PI),l=e=>Math.round(e*c)&65535,u=e=>Math.max(-32768,Math.min(32767,Math.round(e))),d=e=>u(e*1e4),f=e=>e/1e4,p=e=>e/c,m=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)&511,yaw:p(t.getUint16(5)),pitch:f(t.getInt16(7)),view:(t.getUint16(9)*256+t.getUint8(11))/256}:null},h=t=>t===e.CARRIED?2:t===e.DROPPED?8:1,g=n=>{let r=4+45*n.players.length,i=new DataView(new ArrayBuffer(r+8+n.flags.reduce((e,t)=>e+h(t.state),0)));i.setUint8(0,2),i.setUint16(1,n.tick&65535),i.setUint8(3,n.players.length),n.players.forEach((e,n)=>{let r=4+n*45;i.setUint8(r,e.id),i.setFloat32(r+1,e.x),i.setFloat32(r+5,e.y),i.setFloat32(r+9,e.z),i.setFloat32(r+13,e.vx),i.setFloat32(r+17,e.vy),i.setFloat32(r+21,e.vz),i.setFloat32(r+25,e.edge),i.setUint16(r+29,l(e.yaw)),i.setInt16(r+31,d(e.pitch)),i.setUint16(r+33,e.ack&65535),i.setUint8(r+35,e.mode&7|(e.wall&7)<<3|(e.jumps&1)<<6|e.dashes<<7),i.setUint8(r+36,e.t),i.setUint8(r+37,e.dash|(e.by>>2&3)<<6),i.setUint8(r+38,e.coyote&7|(e.buffer&7)<<3|(e.held&t.JUMP?64:0)|(e.held&t.DASH?128:0)),i.setUint8(r+39,e.stun|(e.by&3)<<6);let a=e.hp|e.cool<<3|(e.ammo<0?o:e.ammo)<<6|e.down<<13|!!e.rack<<20;i.setUint8(r+40,a>>16),i.setUint16(r+41,a&65535),i.setUint8(r+43,e.shots),i.setUint8(r+44,e.hits)}),i.setUint8(r,n.score[0]),i.setUint8(r+1,n.score[1]),i.setUint16(r+2,n.clock&32767|(n.over?32768:0)),i.setUint32(r+4,n.packs??0);let a=r+8;for(let t of n.flags)i.setUint8(a,t.state),t.state===e.CARRIED?i.setUint8(a+1,t.by):t.state===e.DROPPED&&(i.setInt16(a+1,u(t.x*s)),i.setInt16(a+3,u(t.y*s)),i.setInt16(a+5,u(t.z*s)),i.setUint8(a+7,Math.min(255,t.left))),a+=h(t.state);return i.buffer},ee=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},_=.4,v=1.8,te=1.6,y=1.55,b=.9,ne=.7,re=7.5,ie=1.5,ae=.15,oe=.5,se=.9,ce=6.5,le=.2,ue=.03,de=.2,fe=5.5,pe=2.5,me=[`#ff3d4f`,`#2f80ff`],he={maxPlayers:16,scoreLimit:3,timeLimit:480},ge=4,x=1024,_e=(e,t)=>(e+x)*(2*x)+t+x,S=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),ve=(e,t=ge)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=S(e[0],t);a<=S(r[0],t);a++)for(let o=S(e[2],t);o<=S(r[2],t);o++){let e=_e(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},C=(e,t,n,r)=>{let i=[];for(let a=S(t-r,e.cell);a<=S(t+r,e.cell);a++)for(let t=S(n-r,e.cell);t<=S(n+r,e.cell);t++)for(let n of e.grid.get(_e(a,t))??[])i.includes(n)||i.push(n);return i},ye=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=S(t[0],i),c=S(t[2],i),l=Math.sign(n[0]),u=Math.sign(n[2]),d=l?((s+ +(l>0))*i-t[0])/n[0]:1/0,f=u?((c+ +(u>0))*i-t[2])/n[2]:1/0,p=d,m=f,h=l?i/Math.abs(n[0]):1/0,g=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(_e(s,c))??[]){let e=a.brushes[r],[i,s]=[0,o];for(let r=0;r<3&&i<=s;r++){if(!n[r]){(t[r]<e.min[r]||t[r]>e.max[r])&&(s=-1);continue}let a=(e.min[r]-t[r])/n[r],o=(e.max[r]-t[r])/n[r];i=Math.max(i,Math.min(a,o)),s=Math.min(s,Math.max(a,o))}i<=s&&s>0&&i<o&&(o=i)}if(Math.min(p,m)>=o||Math.abs(s)>x||Math.abs(c)>x)return o;p<m?(s+=l,p+=h):(c+=u,m+=g)}},w=()=>({state:e.HOME,by:0,x:0,y:0,z:0,left:0}),be=60,xe=class{score=[0,0];over=!1;flags=[w(),w()];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&i.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=ye(this.world,[e.x,e.y+.05,e.z],[0,-1,0],be);t<be&&(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(t){return this.flags.findIndex(n=>n.state===e.CARRIED&&n.by===t)}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=[w(),w()],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(t){if(this.over)return--this.clock<=0?(this.reset(),`start`):void 0;for(let t of[0,1]){let n=this.flags[t];this.lock[t].left--,this.hold[t]--,n.state===e.DROPPED&&(n.left=Math.ceil(--this.back[t]/60),this.back[t]<=0&&(this.flags[t]=w()))}for(let n of[0,1]){let r=this.flags[n];if(r.state===e.CARRIED)continue;let i=r.state===e.HOME?this.world.def.teams[n].base:[r.x,r.y,r.z],a=t.filter(e=>Se(e.state,i)),o=r.state===e.DROPPED&&this.hold[n]<=0?a.find(e=>e.team===n):void 0,s=a.find(e=>e.team!==n&&(e.id!==this.lock[n].id||this.lock[n].left<=0));if(o){let e=this.mates.get(o.id);e&&e.returns++,this.flags[n]=w()}else s&&(this.flags[n]={...w(),state:e.CARRIED,by:s.id})}for(let n of t){let t=this.carrying(n.id);if(t>=0&&this.flags[n.team].state===e.HOME&&Se(n.state,this.world.def.teams[n.team].base)){this.score[n.team]++;let e=this.mates.get(n.id);e&&e.caps++,this.flags[t]=w()}}if(this.score.some(e=>e>=this.rules.scoreLimit)||--this.clock<=0)return this.over=!0,this.clock=600,`end`}dropAt(t,[n,r,i]){this.flags[t]={state:e.DROPPED,by:0,x:n,y:r,z:i,left:10},this.back[t]=600}},Se=(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],T=1/60,E=Math.PI*2,D=1e-6,O=.01,k=.001,Ce=e=>(e%E+E)%E,A=e=>[-Math.sin(e),-Math.cos(e)],j=Math.fround,we=Math.sqrt,M=(e,t,n)=>Math.min(Math.max(e,t),n),N=(e,t)=>we(e*e+t*t),P=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],Te={vx:0,vz:0,mode:n.GROUND,t:0,wall:r.NONE,edge:0,jumps:1,dashes:1,dash:0,stun:0,coyote:6,buffer:0,held:0,hp:5,ammo:-1,cool:0,rack:!1,down:0,shots:0,hits:0,ev:0,fall:0},F=(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:j(a),y:j(o),z:j(s),vy:0,yaw:Ce(c),pitch:0,ground:!0,...Te}},Ee=(e,t,n)=>{let{yaw:r,pitch:a,id:o,shots:s,hits:c}=e;Object.assign(e,F(o,t,o,n),{yaw:r,pitch:a,shots:s,hits:c,ev:e.ev|i.RESPAWN})},I=e=>e===n.GROUND||e===n.SLIDE||e===n.CROUCH,L=e=>e.mode===n.SLIDE||e.mode===n.CROUCH?b:v,De=e=>e.mode===n.SLIDE||e.mode===n.CROUCH?ne:te,Oe=e=>N(e.vx,e.vz),R=(e,t,n)=>e.max[1]>t+.5+O&&e.min[1]<t+n-O,z=(e,t,n)=>[t-M(t,e.min[0],e.max[0]),n-M(n,e.min[2],e.max[2])],ke=(e,t,n)=>{let{brushes:r}=t.def,i=C(t,e.x,e.z,2*_),a=(_-D)**2,[o,s]=[0,0];for(let t=0;t<4;t++){let t=0,c=0,l=0;for(let o of i){let i=r[o];if(!R(i,e.y,n))continue;let[s,u]=z(i,e.x,e.z),d=s*s+u*u;if(d>=a)continue;if(d){let e=we(d);.4-e>t&&(t=_-e,c=s/e*t,l=u/e*t);continue}let[f,p,m]=[[e.x-i.min[0],-1,0],[i.max[0]-e.x,1,0],[e.z-i.min[2],0,-1],[i.max[2]-e.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);f+.4>t&&(t=f+_,[c,l]=[p*t,m*t])}if(!t)break;e.x+=c,e.z+=l,o+=c,s+=l}return[o,s]},B=(e,t,n)=>{let{brushes:r}=t.def,i=(_-D)**2,a=-1/0,o=1/0;for(let s of C(t,e.x,e.z,_)){let t=r[s],[c,l]=z(t,e.x,e.z);c*c+l*l>=i||(t.max[1]<=e.y+.5+O?a=Math.max(a,t.max[1]):t.min[1]>=e.y+n-O&&(o=Math.min(o,t.min[1])))}return[a,o]},V=(e,t)=>{let n=(_-D)**2;return C(t,e.x,e.z,_).every(r=>{let i=t.def.brushes[r],[a,o]=z(i,e.x,e.z);return a*a+o*o>=n||!R(i,e.y,1.8)})},Ae=(e,t,n,r,i)=>{let a=(_-D)**2;return C(e,t,n,_).every(o=>{let s=e.def.brushes[o],[c,l]=z(s,t,n);return c*c+l*l>=a||s.max[1]<=r||s.min[1]>=i})},H=(e,t)=>{let[n,r]=P[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}},je=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=H(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-k&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},Me=(e,t,n)=>{let r;for(let i of C(t,e.x,e.z,_+oe)){let a=t.def.brushes[i],o=je(a,e,n,oe);o!==void 0&&a.min[1]<e.y+.5&&a.max[1]>e.y+1.8&&(r=Math.min(r??1/0,Math.max(0,o-_)))}return r},Ne=(e,t)=>{let[n,r]=A(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=P[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=H(e,a);for(let n of C(t,e.x,e.z,_+le)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(je(r,e,a,.2)===void 0||s<1.2||s>2.4||r.min[1]>o-.25||i&&i.top>=o)continue;let u=l>0?r.min[c]:r.max[c],d=u-l*(_+ue),f=u+l*de,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];Ae(t,p,m,Math.min(e.y,o-2)+O,o+1.8)&&Ae(t,h,g,o+O,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},Pe=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=H(e,e.wall);return C(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 j(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},Fe=(e,t)=>{if(e.vy>=0)return!1;let[n]=B(e,t,v),r=6*T;return e.y-n<=-e.vy*r+10*r*r},U=(e,t)=>{e.mode=t,e.t=0},Ie=(e,t,r)=>{e.stun=48,e.vx=j(t*6),e.vz=j(r*6),e.dash=Math.min(e.dash,50),e.coyote=0,e.buffer=0,(e.mode===n.HANG||e.mode===n.CLIMB)&&(e.vy=0),(e.mode===n.HANG||e.mode===n.CLIMB||e.mode===n.WALLRUN)&&(U(e,n.AIR),e.edge=0)},Le=(e,t)=>{let n=N(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},W=(e,t,n,r)=>{let[i,a]=[n.wx,n.wz];for(let n of C(t,e.x,e.z,_+k)){let o=t.def.brushes[n],[s,c]=z(o,e.x,e.z),l=N(s,c);if(l>0&&l<=.4+k&&R(o,e.y,r)){let e=(-i*s-a*c)/l;e>0&&(i+=e*s/l,a+=e*c/l)}}return[i,a]},G=(e,t,n)=>{let r=N(t[0],t[1]);if(r<D){let t=N(e.vx,e.vz),n=t?Math.max(0,t-45*T)/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=N(s,c);if(l){let e=Math.max(0,l-45*T)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*T):Math.max(n,o-12*T),e.vx=s+o*i,e.vz=c+o*a},Re=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*T,e.z+=e.vz*T;let[o,s]=ke(e,t,n),c=N(o,s);if(c){let t=(e.vx*o+e.vz*s)/c;t<0&&(e.vx-=t*o/c,e.vz-=t*s/c)}let[l,u]=B(e,t,n),d=e.vy-r*20*T;if(e.y+=(e.vy+d)/2*T,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+O:e.y<l){if(e.y=l,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&l>=a-.5)return e.y=l,e.vy=0,0;return-1},K=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=i.JUMP},ze=(e,r,i)=>{let[a,o]=P[e.wall],s=t=>{U(e,t),e.edge=0};if(i.keys&(t.BACK|t.CROUCH))s(n.AIR),e.coyote=0;else if(i.jump&&i.fx*a+i.fz*o<0)s(n.AIR),e.vx=-a*4,e.vz=-o*4,K(e,6);else if(i.jump||i.fwd&&e.t>=6)U(e,n.CLIMB);else if(e.t>=30)s(n.AIR),e.coyote=0;else{let t=Math.max(e.edge-2,B(e,r,v)[0]);e.y+=M(t-e.y,-8*T,8*T)}},Be=(e,t)=>{let[a,o]=P[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*T):(e.x+=a*fe*T,e.z+=o*fe*T),e.y>=e.edge&&Pe(e,t)?(U(e,n.GROUND),e.vx=a*3,e.vz=o*3,e.vy=0,e.edge=0,e.wall=r.NONE,e.coyote=6,e.ev|=i.CLIMB):e.t>=40&&(U(e,e.y>=e.edge?n.GROUND:n.AIR),e.edge=0,e.wall=r.NONE)},Ve=(e,t,r)=>{let[a,o]=P[e.wall],s=e.vx*a+e.vz*o,[c,l]=[e.vx-s*a,e.vz-s*o],u=N(c,l);if(r.jump)U(e,n.AIR),e.vx=c-a*5,e.vz=l-o*5,K(e,ce),e.jumps=1,e.dashes=1,e.ev|=i.WALLRUN_END;else{let s=Me(e,t,e.wall);if(s===void 0||!r.fwd||u<3.5||e.t>=60){U(e,n.AIR),e.ev|=i.WALLRUN_END;return}let d=Math.max(0,u-ie*T)/u;e.vx=c*d,e.vz=l*d;let f=Math.min(s,4*T);e.x+=a*f,e.z+=o*f}},He=(e,t,r)=>{if(!r.fwd)return;let a=N(e.vx,e.vz);if(!(a<4.5))for(let r=1;r<=4;r++){let[o,s]=P[r],c=e.vx*o+e.vz*s,[l,u]=[e.vx-c*o,e.vz-c*s];if(r!==e.wall&&c<=.75*a&&c>=-.2*a&&Me(e,t,r)!==void 0){let t=N(l,u),o=Math.max(t,se*a)/t;U(e,n.WALLRUN),e.wall=r,[e.vx,e.vz]=[l*o,u*o],e.vy=M(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=i.WALLRUN_START;return}}},Ue=(e,t)=>{U(e,n.HANG),e.wall=t.side,e.edge=j(t.top),t.side<=r.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|=i.GRAB},We=(e,a,o)=>{let s=e.mode===n.GROUND;if(o.dash&&e.dash===0&&(s||(e.mode===n.AIR||e.mode===n.WALLRUN)&&e.dashes>0)){let[t,r]=o.wx||o.wz?[o.wx,o.wz]:[o.fx,o.fz];s||(e.dashes--,e.vy=0,e.mode===n.WALLRUN&&(U(e,n.AIR),e.ev|=i.WALLRUN_END)),e.vx=t*16,e.vz=r*16,e.dash=60,e.ev|=i.DASH}let c=e.dash>50;e.mode===n.WALLRUN&&Ve(e,a,o),I(e.mode)&&Ge(e,a,o,c),e.mode===n.AIR&&Ke(e,a,o,c);let l=c&&e.vy<=0?0:e.mode===n.WALLRUN?ae:1,u=e.mode,d=Re(e,a,L(e),l,I(u));if(d>=0){if(!I(e.mode)){if(e.ev|=i.LAND|(e.mode===n.WALLRUN?i.WALLRUN_END:0),e.fall=d,e.jumps=1,e.dashes=1,e.wall=r.NONE,o.keys&t.CROUCH){let t=N(e.vx,e.vz)>=re;U(e,t?n.SLIDE:n.CROUCH),e.ev|=t?i.SLIDE_START:0}else U(e,n.GROUND)}e.coyote=6}else I(e.mode)&&(e.ev|=e.mode===n.SLIDE?i.SLIDE_END:0,U(e,n.AIR));if(e.mode===n.AIR){let t=Ne(e,a);t?Ue(e,t):He(e,a,o)}},Ge=(e,r,a,o)=>{let s=(a.keys&t.CROUCH)!==0;if(e.buffer>0&&(e.mode===n.GROUND||V(e,r))){e.ev|=e.mode===n.SLIDE?i.SLIDE_END:0,U(e,n.AIR),K(e,7);return}let c=N(e.vx,e.vz);if(e.mode===n.GROUND&&s){let t=c>=re;U(e,t?n.SLIDE:n.CROUCH),e.ev|=t?i.SLIDE_START:0}else e.mode===n.SLIDE&&(e.t>=60||c<4.5||a.stumble)?(e.ev|=i.SLIDE_END,U(e,!s&&V(e,r)?n.GROUND:n.CROUCH)):e.mode===n.SLIDE&&!s&&V(e,r)?(e.ev|=i.SLIDE_END,U(e,n.GROUND)):e.mode===n.CROUCH&&!s&&V(e,r)&&U(e,n.GROUND);if(!o){if(a.stumble){if(c>2.5){let t=Math.max(pe,c-12*T)/c;e.vx*=t,e.vz*=t}else G(e,W(e,r,a,L(e)),pe)}else if(e.mode===n.SLIDE){let t=Math.max(0,c-4*T)/c;e.vx*=t,e.vz*=t}else if(e.mode===n.CROUCH)G(e,W(e,r,a,b),3);else{let n=(a.keys&t.SPRINT)!==0&&a.fwd;G(e,W(e,r,a,v),n?9:6)}}},Ke=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?K(e,7):e.jumps>0&&!Fe(e,t)&&(e.jumps--,K(e,6),e.ev=e.ev&~i.JUMP|i.DOUBLE)),r||!n.wx&&!n.wz)return;let a=N(e.vx,e.vz);e.vx+=n.wx*14*T,e.vz+=n.wz*14*T,Le(e,Math.max(a,6))},qe=(e,r,i,a=0)=>{e.yaw=Ce(r.yaw),e.pitch=Math.max(-y,Math.min(y,r.pitch));let o=(r.keys&t.FORWARD?1:0)-(r.keys&t.BACK?1:0),s=(r.keys&t.RIGHT?1:0)-(r.keys&t.LEFT?1:0),c=N(o,s)||1,[l,u]=A(e.yaw),d=t=>(r.keys&t)!==0&&(e.held&t)===0,f=e.stun>0,p={keys:r.keys,stumble:f,jump:!f&&d(t.JUMP),dash:!f&&d(t.DASH),fwd:o>0,wx:(l*o-u*s)/c,wz:(u*o+l*s)/c,fx:l,fz:u},m=e.mode;e.ev=0,e.fall=0,p.jump&&(e.buffer=7),f&&e.stun--,e.dash>0&&(e.dash--,e.dash===50&&Le(e,10)),e.mode===n.HANG&&ze(e,i,p),e.mode===n.CLIMB?Be(e,i):e.mode!==n.HANG&&We(e,i,p),e.y<i.def.floor&&Ee(e,i,a),e.t=e.mode===m?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===n.AIR&&m===n.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=r.keys&(t.JUMP|t.DASH),e.ground=I(e.mode),e.x=j(e.x),e.y=j(e.y),e.z=j(e.z),e.vx=j(e.vx),e.vy=j(e.vy),e.vz=j(e.vz),e.edge=j(e.edge)},Je=(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},Ye=(e,r,i,a,o=!0)=>{let s=e.down>0;if(qe(e,s?{...r,keys:0}:r,i,a),s)return e.down>0&&!--e.down&&Ee(e,i,a),!1;let c=i.def.teams[a].rack,l=!!c&&Je(e,c,1.2);return o&&l&&!e.rack&&(e.ammo=60),e.rack=l,e.cool=Math.max(0,e.cool-1),o&&r.keys&t.FIRE&&!e.cool&&e.ammo>0&&e.mode!==n.HANG&&e.mode!==n.CLIMB?(e.ammo--,e.shots=e.shots+1&255,e.cool=7,!0):!1},Xe=(e,t,n,r)=>{let[i,a]=[e[0]-n.x,e[2]-n.z],o=t[0]*t[0]+t[2]*t[2],s=i*t[0]+a*t[2],c=s*s-o*(i*i+a*a-_*_),[l,u]=[0,1/0];if(o>1e-12){if(c<0)return 1/0;[l,u]=[(-s-Math.sqrt(c))/o,(-s+Math.sqrt(c))/o]}else if(i*i+a*a>.4*.4)return 1/0;let[d,f]=[n.y-e[1],n.y+r-e[1]];if(t[1])[l,u]=[Math.max(l,Math.min(d/t[1],f/t[1])),Math.min(u,Math.max(d/t[1],f/t[1]))];else if(d>0||f<0)return 1/0;return l<=u&&u>=0?Math.max(l,0):1/0},Ze=(e,t,n)=>{let r=[t.x,t.y+De(t),t.z],[i,a,o,s]=[Math.sin(t.yaw),Math.cos(t.yaw),Math.sin(t.pitch),Math.cos(t.pitch)],c=[-i*s,o,-a*s],l=ye(e,r,c,80),u;for(let e of n){let t=Xe(r,c,e,L(e));t<l&&([l,u]=[t,e])}return u},q=-30,J=(e,t,n,r,i,o=a.CONCRETE)=>({min:[e,q,t],max:[n,i,r],top:a.CONCRETE,side:o}),Y=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c});[J(4,57.7,24,76,10),J(4,36,24,53.5,10,a.GLASS),J(4,20,24,36,12.4),J(4,-5,24,7,12.4,a.GLASS),J(27,20,47,50,8),J(27,60,47,76,8,a.BRICK),Y([9,12.2,39],[19,12.6,47],a.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>Y([12,t,e-n],[14,t+.4*n,e-n+1],a.CONCRETE)))(53,10),Y([5,10,42],[5.5,14,42.5],a.STEEL),Y([5,10,50],[5.5,14,50.5],a.STEEL),Y([8,12.4,24],[20,12.85,24.45],a.STEEL),Y([36,8,22],[37,14.5,48],a.PAINT,a.PAINT,[.15,.72,.62]),Y([30,8,28],[34,10,32],a.CONCRETE),Y([40,8,30],[44,10.2,34],a.PAINT,a.PAINT,[1,.3,.06]),Y([28,9.2,44],[35,12,46],a.STEEL,a.PAINT,[.2,.42,1]),Y([41.5,7.6,50],[42,8,60],a.STEEL),Y([30,8,64],[34,9.6,68],a.PAINT,a.PAINT,[.2,.8,.3])];var Qe=240,X=[1,.22,.26],$e=[.2,.46,1],et=[1,.42,.08],Z=[.12,.7,.62],Q=(e,t,n,r,i,o,s)=>Y([e,t,n],[r,i,o],a.PAINT,a.PAINT,s),tt=(e,t,n,r,i,o,s,c=q)=>{let l=Math.ceil((s-o)/.46);return Array.from({length:l},(u,d)=>{let[f,p]=[t+(n-t)*d/l,t+(n-t)*(d+1)/l].sort((e,t)=>e-t),m=o+(s-o)*(d+1)/l;return e===0?Y([f,c,r],[p,m,i],a.CONCRETE):Y([r,c,f],[i,m,p],a.CONCRETE)})},$=(e,t,n,r,i,o,s)=>s.map((s,c)=>Y([e+c*n,o,t+c*r],[e+c*n+4,s,t+c*r+i],a.STEEL,a.CONCRETE)),nt=[J(12,212,52,240,26,a.GLASS),Q(12,26,212,52,26.12,212.5,X),Q(12,26,239.5,52,26.12,240,X),Q(12,26,212.5,12.5,26.12,239.5,X),Q(51.5,26,212.5,52,26.12,239.5,X),Q(11.6,12,222,12,25.8,232,X),Q(28,12,211.4,31,25.5,212,X),Y([19,26,222],[22,27.4,225],a.STEEL),Y([42,26,222],[45,27.4,225],a.STEEL),Y([29,26,229],[35,27.1,229.6],a.CONCRETE),J(6,164,26,201,26,a.GLASS),J(6,134,26,147,26,a.GLASS),J(6,201,26,212,19),J(15,147,26,164,19),Y([14,26,164],[15,32,196],a.PAINT,a.PAINT,Z),Y([14,18,147],[15,32,164],a.PAINT,a.PAINT,Z),Y([14,26,134],[15,32,147],a.PAINT,a.PAINT,Z),...$(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])=>Y([e,19,t],[n,i,r],a.STEEL,a.CONCRETE)),Y([20,26,178],[23,27.3,181],a.STEEL),Y([8,26,176],[11,27.2,179],a.STEEL),Y([8,26,190],[11,27.3,193],a.STEEL),Y([20,26,140],[23,27.3,143],a.STEEL),J(32,186,76,209,19),Q(32,19,207.5,76,19.1,209,X),...$(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])=>Y([e,q,t],[n,i,r],a.STEEL,a.CONCRETE)),J(32,166,64,182,21.2,a.GLASS),J(32,140,64,161,19),Y([40,21.2,172],[44,22.6,176],a.STEEL),Y([52,19,148],[57,20.3,151],a.STEEL),Y([38,19,196],[41,20.4,199],a.STEEL),Y([60,19,200],[63,20.4,203],a.STEEL),Y([52,19,190],[58,20.6,194],a.STEEL),Y([66,19,204],[72,20.2,207],a.STEEL),Y([56,21.2,170],[60,22.4,174],a.STEEL),Y([34,19,152],[37,20.3,156],a.STEEL),...$(36,135,18,0,3,15,[17.2,17.2]),...$(6.5,129,6,0,4,15,[17.2,19.4,21.6,23.8]),J(76,213,100,240,14.5,a.STEEL),Q(76,14.5,238.5,100,14.6,240,X),J(76,185,100,209,14.5),J(76,138,100,181,14.5,a.GLASS),Y([80,15.7,158],[96,17.7,162],a.STEEL,a.PAINT,et),Y([82,14.5,234],[85,15.9,237],a.STEEL),Y([91,14.5,190],[94,15.9,193],a.STEEL),Y([80,14.5,204],[83,15.6,207],a.STEEL),Y([78,14.5,170],[81,15.9,173],a.STEEL),Y([92,14.5,146],[95,15.7,149],a.STEEL),Y([92,14.5,222],[96,15.8,226],a.STEEL),...tt(0,76,52,226,232,14.5,26),...tt(0,85,76,196,202,14.5,19,14.5)],rt=[J(6,106,62,134,15),J(62,106,100,134,14.5),Y([34,15,112],[54,17.2,128],a.CONCRETE),Q(38,17.2,116,50,17.3,124,et),...[[35,113],[35,126.2],[51,113],[51,126.2]].map(([e,t])=>Y([e,17.2,t],[e+.8,21.5,t+.8],a.STEEL)),Y([34.6,21.5,112.6],[52.2,21.9,127.4],a.GLASS),Y([14,15,114],[17,16.5,117],a.STEEL),Y([14,15,123],[17,16.5,126],a.STEEL),Y([56,15,114],[59,16.5,117],a.STEEL),Y([56,15,123],[59,16.5,126],a.STEEL),Y([15.35,25.5,106],[15.85,26,134],a.STEEL),Y([70,14.5,108],[70.8,38,108.8],a.STEEL),Y([70,14.5,131.2],[70.8,38,132],a.STEEL),Y([66,14.5,110],[69,15.9,113],a.STEEL),Y([66,14.5,127],[69,15.9,130],a.STEEL)],it=e=>({...e,min:[e.min[0],e.min[1],Qe-e.max[2]],max:[e.max[0],e.max[1],Qe-e.min[2]],tint:e.tint===X?$e:e.tint}),at=(e,t,n)=>[...[16,22,28,34,40].map(n=>[n,26,t,e]),...[19,31,43].map(t=>[t,26,n,e])],ot=[[20,26,190],[48,21.2,172],[48,19,200],[88,14.5,198]],st={name:`Highline`,brushes:[...nt,...nt.map(it),...rt],teams:[{base:[32,26,224],spawns:at(0,236,231),rack:[47,26,234]},{base:[32,26,16],spawns:at(Math.PI,4,9),rack:[47,26,6]}],packs:[...ot,...ot.map(([e,t,n])=>[e,t,Qe-n]),[24,15,112],[24,15,128]],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]},ct=e=>e.mode===n.SLIDE||e.dash>50,lt=(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),ut=20,dt=2,ft=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),pt=e=>ft((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),mt=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${ft(e,15-`${r}`.length)} ${r}`;return n},ht=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},gt=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;ctf;halt;rules;rr=[0,0];gone;constructor(e={},t=st){this.rules={...he,...e},this.world=ve(t),this.ctf=new xe(this.world,this.rules),this.gone=(t.packs??[]).map(()=>0)}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=ee(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&m(t);if(r&&n.bank>0){n.bank--;let e=Ye(n.state,r,this.world,n.info.team,!this.ctf.over);this.ctf.moved(n.state),this.tackle(n,r.view),e&&this.shoot(n,r.view),n.ack=r.seq}}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.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)return;let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);this.heal(e);let n=this.ctf.tick(e.filter(e=>!e.state.down).map(e=>({id:e.info.id,team:e.info.team,state:e.state})));if(n===`end`?this.end(e):n===`start`&&this.restart(e),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=g({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|1<<n,0)>>>0});e.forEach(e=>e.conn.send(n))}}start(e=ht){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<ut;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){let n=this.players().filter(t=>t.info.id!==e).map(e=>e.state),[r,i]=[this.history[0],this.history.at(-1)];if(!r||!i)return n;let a=((this.ticks-t+32768)%65536+65536)%65536-32768,o=Math.min(Math.max(this.ticks-a,r.tick),i.tick),s=0;for(;s+1<this.history.length&&this.history[s+1].tick<=o;)s++;let[c,l]=[this.history[s],this.history[s+1]??this.history[s]],u=l.tick>c.tick?(o-c.tick)/(l.tick-c.tick):0,d=(e,t)=>e+(t-e)*u;return n.map(e=>{let t=c.players.find(t=>t.id===e.id),n=l.players.find(t=>t.id===e.id);return t&&n?{...n,x:d(t.x,n.x),y:d(t.y,n.y),z:d(t.z,n.z)}:n??t??e})}tackle(e,t){let n=e.state;if(n.down||!ct(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=>lt(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=Oe(n),[s,c]=o>.001?[n.vx/o,n.vz/o]:A(n.yaw);Ie(a.state,s,c),a.by=e.info.id,e.tackled=this.ticks}shoot(e,t){let n=this.players(),r=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}),i=n.find(t=>t.info.id===Ze(this.world,e.state,r)?.id);i&&(e.state.hits=e.state.hits+1&255,--i.state.hp<=0&&(Object.assign(i.state,{hp:0,down:120,ammo:-1,cool:0}),this.ctf.drop(i.state)))}heal(e){this.world.def.packs?.forEach((t,n)=>{if(this.gone[n]>0){this.gone[n]--;return}let r=e.find(e=>e.state.hp<5&&!e.state.down&&Je(e.state,t,.9));r&&(r.state.hp=Math.min(5,r.state.hp+2),this.gone[n]=1200)})}place(e,t,n){let r=this.world.def.teams[t].spawns.findIndex((r,i)=>{let{x:a,z:o}=F(e,this.world,i,t);return!n.some(e=>Math.hypot(e.x-a,e.z-o)<dt)});return F(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);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:mt(pt(t)||`Player ${r}`,n.map(e=>e.info.name)),team:a,color:me[a]},state:this.place(r,a,n.map(e=>e.state)),bank:10,ack:65535,by:0,tackled:-30};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})))}},_t=(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()},vt=(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&&b.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 gt(t),s.start(_t),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 te=e=>{p||(typeof e==`string`&&ee(e)?.t===`join`&&(f=e),s?s.receive(g,e):u?m({kind:`m`,data:e}):d.push(e))},y=()=>{p||(p=!0,globalThis.removeEventListener?.(`pagehide`,y),s?(s.stop(),l()):(m({kind:`b`}),a.abort()),i.close(),setTimeout(()=>b.onclose?.()))},b={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:te,close:y};return o?o.request(n,{signal:a.signal},()=>new Promise(v)).catch(()=>{}):v(()=>{}),m({kind:`q`}),globalThis.addEventListener?.(`pagehide`,y),setTimeout(()=>!p&&b.onopen?.()),b};export{vt as localSocket};
1
+ var e={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},n={GROUND:0,AIR:1,WALLRUN:2,HANG:3,CLIMB:4,SLIDE:5,CROUCH:6},r={NONE:0,EAST:1,WEST:2,SOUTH:3,NORTH:4},i={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},o=127,s=16,c=65536/(2*Math.PI),l=e=>Math.round(e*c)&65535,u=e=>Math.max(-32768,Math.min(32767,Math.round(e))),d=e=>u(e*1e4),f=e=>e/1e4,p=e=>e/c,m=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)&511,yaw:p(t.getUint16(5)),pitch:f(t.getInt16(7)),view:(t.getUint16(9)*256+t.getUint8(11))/256}:null},h=t=>t===e.CARRIED?2:t===e.DROPPED?8:1,g=n=>{let r=4+45*n.players.length,i=new DataView(new ArrayBuffer(r+8+n.flags.reduce((e,t)=>e+h(t.state),0)));i.setUint8(0,2),i.setUint16(1,n.tick&65535),i.setUint8(3,n.players.length),n.players.forEach((e,n)=>{let r=4+n*45;i.setUint8(r,e.id),i.setFloat32(r+1,e.x),i.setFloat32(r+5,e.y),i.setFloat32(r+9,e.z),i.setFloat32(r+13,e.vx),i.setFloat32(r+17,e.vy),i.setFloat32(r+21,e.vz),i.setFloat32(r+25,e.edge),i.setUint16(r+29,l(e.yaw)),i.setInt16(r+31,d(e.pitch)),i.setUint16(r+33,e.ack&65535),i.setUint8(r+35,e.mode&7|(e.wall&7)<<3|(e.jumps&1)<<6|e.dashes<<7),i.setUint8(r+36,e.t),i.setUint8(r+37,e.dash|(e.by>>2&3)<<6),i.setUint8(r+38,e.coyote&7|(e.buffer&7)<<3|(e.held&t.JUMP?64:0)|(e.held&t.DASH?128:0)),i.setUint8(r+39,e.stun|(e.by&3)<<6);let a=e.hp|e.cool<<3|(e.ammo<0?o:e.ammo)<<6|e.down<<13|!!e.rack<<20;i.setUint8(r+40,a>>16),i.setUint16(r+41,a&65535),i.setUint8(r+43,e.shots),i.setUint8(r+44,e.hits)}),i.setUint8(r,n.score[0]),i.setUint8(r+1,n.score[1]),i.setUint16(r+2,n.clock&32767|(n.over?32768:0)),i.setUint32(r+4,n.packs??0);let a=r+8;for(let t of n.flags)i.setUint8(a,t.state),t.state===e.CARRIED?i.setUint8(a+1,t.by):t.state===e.DROPPED&&(i.setInt16(a+1,u(t.x*s)),i.setInt16(a+3,u(t.y*s)),i.setInt16(a+5,u(t.z*s)),i.setUint8(a+7,Math.min(255,t.left))),a+=h(t.state);return i.buffer},ee=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},_=.4,v=1.8,te=1.6,y=1.55,b=.9,ne=.7,re=7.5,ie=1.5,ae=.15,oe=.5,se=.9,ce=6.5,le=.2,ue=.03,de=.2,fe=5.5,pe=2.5,me=[`#ff3d4f`,`#2f80ff`],he={maxPlayers:16,scoreLimit:3,timeLimit:480},ge=4,x=1024,_e=(e,t)=>(e+x)*(2*x)+t+x,S=(e,t)=>Math.min(Math.max(Math.floor(e/t),-1024),1023),ve=(e,t=ge)=>{let n=/* @__PURE__ */ new Map;return e.brushes.forEach(({min:e,max:r},i)=>{for(let a=S(e[0],t);a<=S(r[0],t);a++)for(let o=S(e[2],t);o<=S(r[2],t);o++){let e=_e(a,o),t=n.get(e);t?t.push(i):n.set(e,[i])}}),{def:e,cell:t,grid:n}},C=(e,t,n,r)=>{let i=[];for(let a=S(t-r,e.cell);a<=S(t+r,e.cell);a++)for(let t=S(n-r,e.cell);t<=S(n+r,e.cell);t++)for(let n of e.grid.get(_e(a,t))??[])i.includes(n)||i.push(n);return i},ye=(e,t,n,r)=>{let{cell:i,def:a}=e,o=r,s=S(t[0],i),c=S(t[2],i),l=Math.sign(n[0]),u=Math.sign(n[2]),d=l?((s+ +(l>0))*i-t[0])/n[0]:1/0,f=u?((c+ +(u>0))*i-t[2])/n[2]:1/0,p=d,m=f,h=l?i/Math.abs(n[0]):1/0,g=u?i/Math.abs(n[2]):1/0;for(;;){for(let r of e.grid.get(_e(s,c))??[]){let e=a.brushes[r],[i,s]=[0,o];for(let r=0;r<3&&i<=s;r++){if(!n[r]){(t[r]<e.min[r]||t[r]>e.max[r])&&(s=-1);continue}let a=(e.min[r]-t[r])/n[r],o=(e.max[r]-t[r])/n[r];i=Math.max(i,Math.min(a,o)),s=Math.min(s,Math.max(a,o))}i<=s&&s>0&&i<o&&(o=i)}if(Math.min(p,m)>=o||Math.abs(s)>x||Math.abs(c)>x)return o;p<m?(s+=l,p+=h):(c+=u,m+=g)}},w=()=>({state:e.HOME,by:0,x:0,y:0,z:0,left:0}),be=60,xe=class{score=[0,0];over=!1;flags=[w(),w()];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&i.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=ye(this.world,[e.x,e.y+.05,e.z],[0,-1,0],be);t<be&&(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(t){return this.flags.findIndex(n=>n.state===e.CARRIED&&n.by===t)}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=[w(),w()],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(t){if(this.over)return--this.clock<=0?(this.reset(),`start`):void 0;for(let t of[0,1]){let n=this.flags[t];this.lock[t].left--,this.hold[t]--,n.state===e.DROPPED&&(n.left=Math.ceil(--this.back[t]/60),this.back[t]<=0&&(this.flags[t]=w()))}for(let n of[0,1]){let r=this.flags[n];if(r.state===e.CARRIED)continue;let i=r.state===e.HOME?this.world.def.teams[n].base:[r.x,r.y,r.z],a=t.filter(e=>Se(e.state,i)),o=r.state===e.DROPPED&&this.hold[n]<=0?a.find(e=>e.team===n):void 0,s=a.find(e=>e.team!==n&&(e.id!==this.lock[n].id||this.lock[n].left<=0));if(o){let e=this.mates.get(o.id);e&&e.returns++,this.flags[n]=w()}else s&&(this.flags[n]={...w(),state:e.CARRIED,by:s.id})}for(let n of t){let t=this.carrying(n.id);if(t>=0&&this.flags[n.team].state===e.HOME&&Se(n.state,this.world.def.teams[n.team].base)){this.score[n.team]++;let e=this.mates.get(n.id);e&&e.caps++,this.flags[t]=w()}}if(this.score.some(e=>e>=this.rules.scoreLimit)||--this.clock<=0)return this.over=!0,this.clock=600,`end`}dropAt(t,[n,r,i]){this.flags[t]={state:e.DROPPED,by:0,x:n,y:r,z:i,left:10},this.back[t]=600}},Se=(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],T=1/60,E=Math.PI*2,D=1e-6,O=.01,k=.001,Ce=e=>(e%E+E)%E,A=e=>[-Math.sin(e),-Math.cos(e)],j=Math.fround,we=Math.sqrt,M=(e,t,n)=>Math.min(Math.max(e,t),n),N=(e,t)=>we(e*e+t*t),P=[[0,0],[1,0],[-1,0],[0,1],[0,-1]],Te={vx:0,vz:0,mode:n.GROUND,t:0,wall:r.NONE,edge:0,jumps:1,dashes:1,dash:0,stun:0,coyote:6,buffer:0,held:0,hp:5,ammo:-1,cool:0,rack:!1,down:0,shots:0,hits:0,ev:0,fall:0},F=(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:j(a),y:j(o),z:j(s),vy:0,yaw:Ce(c),pitch:0,ground:!0,...Te}},Ee=(e,t,n)=>{let{yaw:r,pitch:a,id:o,shots:s,hits:c}=e;Object.assign(e,F(o,t,o,n),{yaw:r,pitch:a,shots:s,hits:c,ev:e.ev|i.RESPAWN})},I=e=>e===n.GROUND||e===n.SLIDE||e===n.CROUCH,L=e=>e.mode===n.SLIDE||e.mode===n.CROUCH?b:v,De=e=>e.mode===n.SLIDE||e.mode===n.CROUCH?ne:te,Oe=e=>N(e.vx,e.vz),R=(e,t,n)=>e.max[1]>t+.5+O&&e.min[1]<t+n-O,z=(e,t,n)=>[t-M(t,e.min[0],e.max[0]),n-M(n,e.min[2],e.max[2])],ke=(e,t,n)=>{let{brushes:r}=t.def,i=C(t,e.x,e.z,2*_),a=(_-D)**2,[o,s]=[0,0];for(let t=0;t<4;t++){let t=0,c=0,l=0;for(let o of i){let i=r[o];if(!R(i,e.y,n))continue;let[s,u]=z(i,e.x,e.z),d=s*s+u*u;if(d>=a)continue;if(d){let e=we(d);.4-e>t&&(t=_-e,c=s/e*t,l=u/e*t);continue}let[f,p,m]=[[e.x-i.min[0],-1,0],[i.max[0]-e.x,1,0],[e.z-i.min[2],0,-1],[i.max[2]-e.z,0,1]].reduce((e,t)=>t[0]<e[0]?t:e);f+.4>t&&(t=f+_,[c,l]=[p*t,m*t])}if(!t)break;e.x+=c,e.z+=l,o+=c,s+=l}return[o,s]},B=(e,t,n)=>{let{brushes:r}=t.def,i=(_-D)**2,a=-1/0,o=1/0;for(let s of C(t,e.x,e.z,_)){let t=r[s],[c,l]=z(t,e.x,e.z);c*c+l*l>=i||(t.max[1]<=e.y+.5+O?a=Math.max(a,t.max[1]):t.min[1]>=e.y+n-O&&(o=Math.min(o,t.min[1])))}return[a,o]},V=(e,t)=>{let n=(_-D)**2;return C(t,e.x,e.z,_).every(r=>{let i=t.def.brushes[r],[a,o]=z(i,e.x,e.z);return a*a+o*o>=n||!R(i,e.y,1.8)})},Ae=(e,t,n,r,i)=>{let a=(_-D)**2;return C(e,t,n,_).every(o=>{let s=e.def.brushes[o],[c,l]=z(s,t,n);return c*c+l*l>=a||s.max[1]<=r||s.min[1]>=i})},H=(e,t)=>{let[n,r]=P[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}},je=(e,t,n,r)=>{let{a:i,o:a,sign:o,c:s,co:c}=H(t,n),l=((o>0?e.min[i]:e.max[i])-s)*o;return l>=.4-k&&l<=.4+r&&c>=e.min[a]&&c<=e.max[a]?l:void 0},Me=(e,t,n)=>{let r;for(let i of C(t,e.x,e.z,_+oe)){let a=t.def.brushes[i],o=je(a,e,n,oe);o!==void 0&&a.min[1]<e.y+.5&&a.max[1]>e.y+1.8&&(r=Math.min(r??1/0,Math.max(0,o-_)))}return r},Ne=(e,t)=>{let[n,r]=A(e.yaw),i;for(let a=1;a<=4;a++){let[o,s]=P[a];if(a===e.wall||n*o+r*s<.5)continue;let{a:c,sign:l}=H(e,a);for(let n of C(t,e.x,e.z,_+le)){let r=t.def.brushes[n],o=r.max[1],s=o-e.y;if(je(r,e,a,.2)===void 0||s<1.2||s>2.4||r.min[1]>o-.25||i&&i.top>=o)continue;let u=l>0?r.min[c]:r.max[c],d=u-l*(_+ue),f=u+l*de,[p,m]=c===0?[d,e.z]:[e.x,d],[h,g]=c===0?[f,e.z]:[e.x,f];Ae(t,p,m,Math.min(e.y,o-2)+O,o+1.8)&&Ae(t,h,g,o+O,o+1.8)&&(i={side:a,top:o,hang:d})}}return i},Pe=(e,t)=>{let{a:n,o:r,sign:i,c:a,co:o}=H(e,e.wall);return C(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 j(c.max[1])===e.edge&&o>=c.min[r]&&o<=c.max[r]&&l>=.2})},Fe=(e,t)=>{if(e.vy>=0)return!1;let[n]=B(e,t,v),r=6*T;return e.y-n<=-e.vy*r+10*r*r},U=(e,t)=>{e.mode=t,e.t=0},Ie=(e,t,r)=>{e.stun=48,e.vx=j(t*6),e.vz=j(r*6),e.dash=Math.min(e.dash,50),e.coyote=0,e.buffer=0,(e.mode===n.HANG||e.mode===n.CLIMB)&&(e.vy=0),(e.mode===n.HANG||e.mode===n.CLIMB||e.mode===n.WALLRUN)&&(U(e,n.AIR),e.edge=0)},Le=(e,t)=>{let n=N(e.vx,e.vz);n>t&&(e.vx*=t/n,e.vz*=t/n)},W=(e,t,n,r)=>{let[i,a]=[n.wx,n.wz];for(let n of C(t,e.x,e.z,_+k)){let o=t.def.brushes[n],[s,c]=z(o,e.x,e.z),l=N(s,c);if(l>0&&l<=.4+k&&R(o,e.y,r)){let e=(-i*s-a*c)/l;e>0&&(i+=e*s/l,a+=e*c/l)}}return[i,a]},G=(e,t,n)=>{let r=N(t[0],t[1]);if(r<D){let t=N(e.vx,e.vz),n=t?Math.max(0,t-45*T)/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=N(s,c);if(l){let e=Math.max(0,l-45*T)/l;[s,c]=[s*e,c*e]}n*=r,o=o<n?Math.min(n,o+(o>=6?3:50)*T):Math.max(n,o-12*T),e.vx=s+o*i,e.vz=c+o*a},Re=(e,t,n,r,i)=>{let a=e.y;e.x+=e.vx*T,e.z+=e.vz*T;let[o,s]=ke(e,t,n),c=N(o,s);if(c){let t=(e.vx*o+e.vz*s)/c;t<0&&(e.vx-=t*o/c,e.vz-=t*s/c)}let[l,u]=B(e,t,n),d=e.vy-r*20*T;if(e.y+=(e.vy+d)/2*T,e.vy=d,e.y+n>u&&(e.y=u-n,e.vy=Math.min(e.vy,0)),e.vy<=0?e.y<=l+O:e.y<l){if(e.y=l,e.vy<=0){let t=-e.vy;return e.vy=0,t}}else if(i&&e.vy<=0&&l>=a-.5)return e.y=l,e.vy=0,0;return-1},K=(e,t)=>{e.vy=t,e.coyote=0,e.buffer=0,e.ev|=i.JUMP},ze=(e,r,i)=>{let[a,o]=P[e.wall],s=t=>{U(e,t),e.edge=0};if(i.keys&(t.BACK|t.CROUCH))s(n.AIR),e.coyote=0;else if(i.jump&&i.fx*a+i.fz*o<0)s(n.AIR),e.vx=-a*4,e.vz=-o*4,K(e,6);else if(i.jump||i.fwd&&e.t>=6)U(e,n.CLIMB);else if(e.t>=30)s(n.AIR),e.coyote=0;else{let t=Math.max(e.edge-2,B(e,r,v)[0]);e.y+=M(t-e.y,-8*T,8*T)}},Be=(e,t)=>{let[a,o]=P[e.wall];e.y<e.edge?e.y=Math.min(e.edge,e.y+8*T):(e.x+=a*fe*T,e.z+=o*fe*T),e.y>=e.edge&&Pe(e,t)?(U(e,n.GROUND),e.vx=a*3,e.vz=o*3,e.vy=0,e.edge=0,e.wall=r.NONE,e.coyote=6,e.ev|=i.CLIMB):e.t>=40&&(U(e,e.y>=e.edge?n.GROUND:n.AIR),e.edge=0,e.wall=r.NONE)},Ve=(e,t,r)=>{let[a,o]=P[e.wall],s=e.vx*a+e.vz*o,[c,l]=[e.vx-s*a,e.vz-s*o],u=N(c,l);if(r.jump)U(e,n.AIR),e.vx=c-a*5,e.vz=l-o*5,K(e,ce),e.jumps=1,e.dashes=1,e.ev|=i.WALLRUN_END;else{let s=Me(e,t,e.wall);if(s===void 0||!r.fwd||u<3.5||e.t>=60){U(e,n.AIR),e.ev|=i.WALLRUN_END;return}let d=Math.max(0,u-ie*T)/u;e.vx=c*d,e.vz=l*d;let f=Math.min(s,4*T);e.x+=a*f,e.z+=o*f}},He=(e,t,r)=>{if(!r.fwd)return;let a=N(e.vx,e.vz);if(!(a<4.5))for(let r=1;r<=4;r++){let[o,s]=P[r],c=e.vx*o+e.vz*s,[l,u]=[e.vx-c*o,e.vz-c*s];if(r!==e.wall&&c<=.75*a&&c>=-.2*a&&Me(e,t,r)!==void 0){let t=N(l,u),o=Math.max(t,se*a)/t;U(e,n.WALLRUN),e.wall=r,[e.vx,e.vz]=[l*o,u*o],e.vy=M(e.vy,2,3),e.jumps=1,e.dashes=1,e.coyote=0,e.ev|=i.WALLRUN_START;return}}},Ue=(e,t)=>{U(e,n.HANG),e.wall=t.side,e.edge=j(t.top),t.side<=r.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|=i.GRAB},We=(e,a,o)=>{let s=e.mode===n.GROUND;if(o.dash&&e.dash===0&&(s||(e.mode===n.AIR||e.mode===n.WALLRUN)&&e.dashes>0)){let[t,r]=o.wx||o.wz?[o.wx,o.wz]:[o.fx,o.fz];s||(e.dashes--,e.vy=0,e.mode===n.WALLRUN&&(U(e,n.AIR),e.ev|=i.WALLRUN_END)),e.vx=t*16,e.vz=r*16,e.dash=60,e.ev|=i.DASH}let c=e.dash>50;e.mode===n.WALLRUN&&Ve(e,a,o),I(e.mode)&&Ge(e,a,o,c),e.mode===n.AIR&&Ke(e,a,o,c);let l=c&&e.vy<=0?0:e.mode===n.WALLRUN?ae:1,u=e.mode,d=Re(e,a,L(e),l,I(u));if(d>=0){if(!I(e.mode)){if(e.ev|=i.LAND|(e.mode===n.WALLRUN?i.WALLRUN_END:0),e.fall=d,e.jumps=1,e.dashes=1,e.wall=r.NONE,o.keys&t.CROUCH){let t=N(e.vx,e.vz)>=re;U(e,t?n.SLIDE:n.CROUCH),e.ev|=t?i.SLIDE_START:0}else U(e,n.GROUND)}e.coyote=6}else I(e.mode)&&(e.ev|=e.mode===n.SLIDE?i.SLIDE_END:0,U(e,n.AIR));if(e.mode===n.AIR){let t=Ne(e,a);t?Ue(e,t):He(e,a,o)}},Ge=(e,r,a,o)=>{let s=(a.keys&t.CROUCH)!==0;if(e.buffer>0&&(e.mode===n.GROUND||V(e,r))){e.ev|=e.mode===n.SLIDE?i.SLIDE_END:0,U(e,n.AIR),K(e,7);return}let c=N(e.vx,e.vz);if(e.mode===n.GROUND&&s){let t=c>=re;U(e,t?n.SLIDE:n.CROUCH),e.ev|=t?i.SLIDE_START:0}else e.mode===n.SLIDE&&(e.t>=60||c<4.5||a.stumble)?(e.ev|=i.SLIDE_END,U(e,!s&&V(e,r)?n.GROUND:n.CROUCH)):e.mode===n.SLIDE&&!s&&V(e,r)?(e.ev|=i.SLIDE_END,U(e,n.GROUND)):e.mode===n.CROUCH&&!s&&V(e,r)&&U(e,n.GROUND);if(!o){if(a.stumble){if(c>2.5){let t=Math.max(pe,c-12*T)/c;e.vx*=t,e.vz*=t}else G(e,W(e,r,a,L(e)),pe)}else if(e.mode===n.SLIDE){let t=Math.max(0,c-4*T)/c;e.vx*=t,e.vz*=t}else if(e.mode===n.CROUCH)G(e,W(e,r,a,b),3);else{let n=(a.keys&t.SPRINT)!==0&&a.fwd;G(e,W(e,r,a,v),n?9:6)}}},Ke=(e,t,n,r)=>{if(e.buffer>0&&(e.coyote>0?K(e,7):e.jumps>0&&!Fe(e,t)&&(e.jumps--,K(e,6),e.ev=e.ev&~i.JUMP|i.DOUBLE)),r||!n.wx&&!n.wz)return;let a=N(e.vx,e.vz);e.vx+=n.wx*14*T,e.vz+=n.wz*14*T,Le(e,Math.max(a,6))},qe=(e,r,i,a=0)=>{e.yaw=Ce(r.yaw),e.pitch=Math.max(-y,Math.min(y,r.pitch));let o=(r.keys&t.FORWARD?1:0)-(r.keys&t.BACK?1:0),s=(r.keys&t.RIGHT?1:0)-(r.keys&t.LEFT?1:0),c=N(o,s)||1,[l,u]=A(e.yaw),d=t=>(r.keys&t)!==0&&(e.held&t)===0,f=e.stun>0,p={keys:r.keys,stumble:f,jump:!f&&d(t.JUMP),dash:!f&&d(t.DASH),fwd:o>0,wx:(l*o-u*s)/c,wz:(u*o+l*s)/c,fx:l,fz:u},m=e.mode;e.ev=0,e.fall=0,p.jump&&(e.buffer=7),f&&e.stun--,e.dash>0&&(e.dash--,e.dash===50&&Le(e,10)),e.mode===n.HANG&&ze(e,i,p),e.mode===n.CLIMB?Be(e,i):e.mode!==n.HANG&&We(e,i,p),e.y<i.def.floor&&Ee(e,i,a),e.t=e.mode===m?Math.min(255,e.t+1):e.t,e.buffer=Math.max(0,e.buffer-1),e.mode===n.AIR&&m===n.AIR&&(e.coyote=Math.max(0,e.coyote-1)),e.held=r.keys&(t.JUMP|t.DASH),e.ground=I(e.mode),e.x=j(e.x),e.y=j(e.y),e.z=j(e.z),e.vx=j(e.vx),e.vy=j(e.vy),e.vz=j(e.vz),e.edge=j(e.edge)},Je=(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},Ye=(e,r,i,a,o=!0)=>{let s=e.down>0;if(qe(e,s?{...r,keys:0}:r,i,a),s)return e.down>0&&!--e.down&&Ee(e,i,a),!1;let c=i.def.teams[a].rack,l=!!c&&Je(e,c,1.2);return o&&l&&!e.rack&&(e.ammo=60),e.rack=l,e.cool=Math.max(0,e.cool-1),o&&r.keys&t.FIRE&&!e.cool&&e.ammo>0&&e.mode!==n.HANG&&e.mode!==n.CLIMB?(e.ammo--,e.shots=e.shots+1&255,e.cool=7,!0):!1},Xe=(e,t,n,r)=>{let[i,a]=[e[0]-n.x,e[2]-n.z],o=t[0]*t[0]+t[2]*t[2],s=i*t[0]+a*t[2],c=s*s-o*(i*i+a*a-_*_),[l,u]=[0,1/0];if(o>1e-12){if(c<0)return 1/0;[l,u]=[(-s-Math.sqrt(c))/o,(-s+Math.sqrt(c))/o]}else if(i*i+a*a>.4*.4)return 1/0;let[d,f]=[n.y-e[1],n.y+r-e[1]];if(t[1])[l,u]=[Math.max(l,Math.min(d/t[1],f/t[1])),Math.min(u,Math.max(d/t[1],f/t[1]))];else if(d>0||f<0)return 1/0;return l<=u&&u>=0?Math.max(l,0):1/0},Ze=(e,t,n)=>{let r=[t.x,t.y+De(t),t.z],[i,a,o,s]=[Math.sin(t.yaw),Math.cos(t.yaw),Math.sin(t.pitch),Math.cos(t.pitch)],c=[-i*s,o,-a*s],l=ye(e,r,c,80),u;for(let e of n){let t=Xe(r,c,e,L(e));t<l&&([l,u]=[t,e])}return u},q=-30,J=(e,t,n,r,i,o=a.CONCRETE)=>({min:[e,q,t],max:[n,i,r],top:a.CONCRETE,side:o}),Y=([e,t,n],[r,i,a],o,s=o,c)=>({min:[e,t,n],max:[r,i,a],top:o,side:s,tint:c});[J(4,57.7,24,76,10),J(4,36,24,53.5,10,a.GLASS),J(4,20,24,36,12.4),J(4,-5,24,7,12.4,a.GLASS),J(27,20,47,50,8),J(27,60,47,76,8,a.BRICK),Y([9,12.2,39],[19,12.6,47],a.STEEL),...((e,t)=>[1,2,3,4,5,6].map(n=>Y([12,t,e-n],[14,t+.4*n,e-n+1],a.CONCRETE)))(53,10),Y([5,10,42],[5.5,14,42.5],a.STEEL),Y([5,10,50],[5.5,14,50.5],a.STEEL),Y([8,12.4,24],[20,12.85,24.45],a.STEEL),Y([36,8,22],[37,14.5,48],a.PAINT,a.PAINT,[.15,.72,.62]),Y([30,8,28],[34,10,32],a.CONCRETE),Y([40,8,30],[44,10.2,34],a.PAINT,a.PAINT,[1,.3,.06]),Y([28,9.2,44],[35,12,46],a.STEEL,a.PAINT,[.2,.42,1]),Y([41.5,7.6,50],[42,8,60],a.STEEL),Y([30,8,64],[34,9.6,68],a.PAINT,a.PAINT,[.2,.8,.3])];var X=240,Z=[1,.22,.26],Qe=[.2,.46,1],$e=[1,.42,.08],et=[.12,.7,.62],Q=(e,t,n,r,i,o,s)=>Y([e,t,n],[r,i,o],a.PAINT,a.PAINT,s),tt=(e,t,n,r,i,o,s,c=q)=>{let l=Math.ceil((s-o)/.46);return Array.from({length:l},(u,d)=>{let[f,p]=[t+(n-t)*d/l,t+(n-t)*(d+1)/l].sort((e,t)=>e-t),m=o+(s-o)*(d+1)/l;return e===0?Y([f,c,r],[p,m,i],a.CONCRETE):Y([r,c,f],[i,m,p],a.CONCRETE)})},$=(e,t,n,r,i,o,s)=>s.map((s,c)=>Y([e+c*n,o,t+c*r],[e+c*n+4,s,t+c*r+i],a.STEEL,a.CONCRETE)),nt=[J(12,212,52,240,26,a.GLASS),Q(12,26,212,52,26.12,212.5,Z),Q(12,26,239.5,52,26.12,240,Z),Q(12,26,212.5,12.5,26.12,239.5,Z),Q(51.5,26,212.5,52,26.12,239.5,Z),Q(11.6,12,222,12,25.8,232,Z),Q(28,12,211.4,31,25.5,212,Z),Y([19,26,222],[22,27.4,225],a.STEEL),Y([42,26,222],[45,27.4,225],a.STEEL),Y([29,26,229],[35,27.1,229.6],a.CONCRETE),J(6,164,26,201,26,a.GLASS),J(6,134,26,147,26,a.GLASS),J(6,201,26,212,19),J(15,147,26,164,19),Y([14,26,164],[15,32,196],a.PAINT,a.PAINT,et),Y([14,18,147],[15,32,164],a.PAINT,a.PAINT,et),Y([14,26,134],[15,32,147],a.PAINT,a.PAINT,et),...$(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])=>Y([e,19,t],[n,i,r],a.STEEL,a.CONCRETE)),Y([20,26,178],[23,27.3,181],a.STEEL),Y([8,26,176],[11,27.2,179],a.STEEL),Y([8,26,190],[11,27.3,193],a.STEEL),Y([20,26,140],[23,27.3,143],a.STEEL),J(32,186,76,209,19),Q(32,19,207.5,76,19.1,209,Z),...$(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])=>Y([e,q,t],[n,i,r],a.STEEL,a.CONCRETE)),J(32,166,64,182,21.2,a.GLASS),J(32,140,64,161,19),Y([40,21.2,172],[44,22.6,176],a.STEEL),Y([52,19,148],[57,20.3,151],a.STEEL),Y([38,19,196],[41,20.4,199],a.STEEL),Y([60,19,200],[63,20.4,203],a.STEEL),Y([52,19,190],[58,20.6,194],a.STEEL),Y([66,19,204],[72,20.2,207],a.STEEL),Y([56,21.2,170],[60,22.4,174],a.STEEL),Y([34,19,152],[37,20.3,156],a.STEEL),...$(36,135,18,0,3,15,[17.2,17.2]),...$(6.5,129,6,0,4,15,[17.2,19.4,21.6,23.8]),J(76,213,100,240,14.5,a.STEEL),Q(76,14.5,238.5,100,14.6,240,Z),J(76,185,100,209,14.5),J(76,138,100,181,14.5,a.GLASS),Y([80,15.7,158],[96,17.7,162],a.STEEL,a.PAINT,$e),Y([82,14.5,234],[85,15.9,237],a.STEEL),Y([91,14.5,190],[94,15.9,193],a.STEEL),Y([80,14.5,204],[83,15.6,207],a.STEEL),Y([78,14.5,170],[81,15.9,173],a.STEEL),Y([92,14.5,146],[95,15.7,149],a.STEEL),Y([92,14.5,222],[96,15.8,226],a.STEEL),...tt(0,76,52,226,232,14.5,26),...tt(0,85,76,196,202,14.5,19,14.5)],rt=[J(6,106,62,134,15),J(62,106,100,134,14.5),Y([34,15,112],[54,17.2,128],a.CONCRETE),Q(38,17.2,116,50,17.3,124,$e),...[[35,113],[35,126.2],[51,113],[51,126.2]].map(([e,t])=>Y([e,17.2,t],[e+.8,21.5,t+.8],a.STEEL)),Y([34.6,21.5,112.6],[52.2,21.9,127.4],a.GLASS),Y([14,15,114],[17,16.5,117],a.STEEL),Y([14,15,123],[17,16.5,126],a.STEEL),Y([56,15,114],[59,16.5,117],a.STEEL),Y([56,15,123],[59,16.5,126],a.STEEL),Y([15.35,25.5,106],[15.85,26,134],a.STEEL),Y([70,14.5,108],[70.8,38,108.8],a.STEEL),Y([70,14.5,131.2],[70.8,38,132],a.STEEL),Y([66,14.5,110],[69,15.9,113],a.STEEL),Y([66,14.5,127],[69,15.9,130],a.STEEL)],it=e=>({...e,min:[e.min[0],e.min[1],X-e.max[2]],max:[e.max[0],e.max[1],X-e.min[2]],tint:e.tint===Z?Qe:e.tint}),at=(e,t,n)=>[...[16,22,28,34,40].map(n=>[n,26,t,e]),...[19,31,43].map(t=>[t,26,n,e])],ot=[[20,26,190],[48,21.2,172],[48,19,200],[88,14.5,198]],st=[[21,26,168],[46,19,144],[36,21.2,178],[88,14.5,216],[88,14.5,172]],ct={name:`Highline`,brushes:[...nt,...nt.map(it),...rt],teams:[{base:[32,26,224],spawns:at(0,236,231),rack:[47,26,234]},{base:[32,26,16],spawns:at(Math.PI,4,9),rack:[47,26,6]}],packs:[...ot,...ot.map(([e,t,n])=>[e,t,X-n]),[24,15,112],[24,15,128]],ammo:[...st,...st.map(([e,t,n])=>[e,t,X-n])],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]},lt=e=>e.mode===n.SLIDE||e.dash>50,ut=(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),dt=20,ft=2,pt=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),mt=e=>pt((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),ht=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${pt(e,15-`${r}`.length)} ${r}`;return n},gt=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},_t=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];world;ctf;halt;rules;rr=[0,0];gone;constructor(e={},t=ct){this.rules={...he,...e},this.world=ve(t),this.ctf=new xe(this.world,this.rules),this.gone=[...t.packs??[],...t.ammo??[]].map(()=>0)}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=ee(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&m(t);if(r&&n.bank>0){n.bank--;let e=Ye(n.state,r,this.world,n.info.team,!this.ctf.over);this.ctf.moved(n.state),this.tackle(n,r.view),e&&this.shoot(n,r.view),n.ack=r.seq}}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.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)return;let t=++this.ticks;for(let t of e)t.bank=Math.min(10,t.bank+1);this.heal(e);let n=this.ctf.tick(e.filter(e=>!e.state.down).map(e=>({id:e.info.id,team:e.info.team,state:e.state})));if(n===`end`?this.end(e):n===`start`&&this.restart(e),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=g({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|1<<n,0)>>>0});e.forEach(e=>e.conn.send(n))}}start(e=gt){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<dt;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){let n=this.players().filter(t=>t.info.id!==e).map(e=>e.state),[r,i]=[this.history[0],this.history.at(-1)];if(!r||!i)return n;let a=((this.ticks-t+32768)%65536+65536)%65536-32768,o=Math.min(Math.max(this.ticks-a,r.tick),i.tick),s=0;for(;s+1<this.history.length&&this.history[s+1].tick<=o;)s++;let[c,l]=[this.history[s],this.history[s+1]??this.history[s]],u=l.tick>c.tick?(o-c.tick)/(l.tick-c.tick):0,d=(e,t)=>e+(t-e)*u;return n.map(e=>{let t=c.players.find(t=>t.id===e.id),n=l.players.find(t=>t.id===e.id);return t&&n?{...n,x:d(t.x,n.x),y:d(t.y,n.y),z:d(t.z,n.z)}:n??t??e})}tackle(e,t){let n=e.state;if(n.down||!lt(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=>ut(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=Oe(n),[s,c]=o>.001?[n.vx/o,n.vz/o]:A(n.yaw);Ie(a.state,s,c),a.by=e.info.id,e.tackled=this.ticks}shoot(e,t){let n=this.players(),r=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}),i=n.find(t=>t.info.id===Ze(this.world,e.state,r)?.id);i&&(e.state.hits=e.state.hits+1&255,--i.state.hp<=0&&(Object.assign(i.state,{hp:0,down:120,ammo:-1,cool:0}),this.ctf.drop(i.state)))}heal(e){let{packs:t=[],ammo:n=[]}=this.world.def;[...t,...n].forEach((n,r)=>{if(this.gone[r]>0){this.gone[r]--;return}let i=r<t.length,a=e.find(({state:e})=>!e.down&&(i?e.hp<5:e.ammo>=0&&e.ammo<60)&&Je(e,n,.9));if(a){let e=a.state;i?e.hp=Math.min(5,e.hp+2):e.ammo=Math.min(60,e.ammo+20),this.gone[r]=1200}})}place(e,t,n){let r=this.world.def.teams[t].spawns.findIndex((r,i)=>{let{x:a,z:o}=F(e,this.world,i,t);return!n.some(e=>Math.hypot(e.x-a,e.z-o)<ft)});return F(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);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:ht(mt(t)||`Player ${r}`,n.map(e=>e.info.name)),team:a,color:me[a]},state:this.place(r,a,n.map(e=>e.state)),bank:10,ack:65535,by:0,tackled:-30};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})))}},vt=(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()},yt=(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&&b.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 _t(t),s.start(vt),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 te=e=>{p||(typeof e==`string`&&ee(e)?.t===`join`&&(f=e),s?s.receive(g,e):u?m({kind:`m`,data:e}):d.push(e))},y=()=>{p||(p=!0,globalThis.removeEventListener?.(`pagehide`,y),s?(s.stop(),l()):(m({kind:`b`}),a.abort()),i.close(),setTimeout(()=>b.onclose?.()))},b={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:te,close:y};return o?o.request(n,{signal:a.signal},()=>new Promise(v)).catch(()=>{}):v(()=>{}),m({kind:`q`}),globalThis.addEventListener?.(`pagehide`,y),setTimeout(()=>!p&&b.onopen?.()),b};export{yt as localSocket};
package/dist/server.js CHANGED
@@ -1976,6 +1976,34 @@ var PACKS = [
1976
1976
  198
1977
1977
  ]
1978
1978
  ];
1979
+ /** Ammo packs in red's half: the Spine, two in Midtown, two on the Lowline. Their twins are across the line. */
1980
+ var AMMO = [
1981
+ [
1982
+ 21,
1983
+ 26,
1984
+ 168
1985
+ ],
1986
+ [
1987
+ 46,
1988
+ 19,
1989
+ 144
1990
+ ],
1991
+ [
1992
+ 36,
1993
+ 21.2,
1994
+ 178
1995
+ ],
1996
+ [
1997
+ 88,
1998
+ 14.5,
1999
+ 216
2000
+ ],
2001
+ [
2002
+ 88,
2003
+ 14.5,
2004
+ 172
2005
+ ]
2006
+ ];
1979
2007
  var HIGHLINE = {
1980
2008
  name: "Highline",
1981
2009
  brushes: [
@@ -2026,6 +2054,11 @@ var HIGHLINE = {
2026
2054
  128
2027
2055
  ]
2028
2056
  ],
2057
+ ammo: [...AMMO, ...AMMO.map(([x, y, z]) => [
2058
+ x,
2059
+ y,
2060
+ ZED - z
2061
+ ])],
2029
2062
  floor: -25,
2030
2063
  sun: {
2031
2064
  dir: [
@@ -2204,7 +2237,7 @@ var Room = class {
2204
2237
  };
2205
2238
  this.world = build(map);
2206
2239
  this.ctf = new Ctf(this.world, this.rules);
2207
- this.gone = (map.packs ?? []).map(() => 0);
2240
+ this.gone = [...map.packs ?? [], ...map.ammo ?? []].map(() => 0);
2208
2241
  }
2209
2242
  /** Number of joined players. */
2210
2243
  get size() {
@@ -2384,16 +2417,25 @@ var Room = class {
2384
2417
  this.ctf.drop(foe.state);
2385
2418
  }
2386
2419
  }
2387
- /** The packs: one that is gone comes back after PACK_BACK s; a hurt player standing at one takes it. */
2420
+ /**
2421
+ * The packs, health ones first, then the ammo ones: one that is gone comes back after PACK_BACK
2422
+ * s. A health pack goes to a hurt player standing at it, an ammo pack to one with the gun and
2423
+ * less than AMMO_MAX shots. Both change the state between two inputs, like a hit: the snapshot
2424
+ * carries the result and the predictor replays its unacked inputs on it.
2425
+ */
2388
2426
  heal(players) {
2389
- this.world.def.packs?.forEach((at, k) => {
2427
+ const { packs = [], ammo = [] } = this.world.def;
2428
+ [...packs, ...ammo].forEach((at, k) => {
2390
2429
  if (this.gone[k] > 0) {
2391
2430
  this.gone[k]--;
2392
2431
  return;
2393
2432
  }
2394
- const p = players.find((q) => q.state.hp < 5 && !q.state.down && within(q.state, at, .9));
2433
+ const health = k < packs.length;
2434
+ const p = players.find(({ state: q }) => !q.down && (health ? q.hp < 5 : q.ammo >= 0 && q.ammo < 60) && within(q, at, .9));
2395
2435
  if (p) {
2396
- p.state.hp = Math.min(5, p.state.hp + 2);
2436
+ const q = p.state;
2437
+ if (health) q.hp = Math.min(5, q.hp + 2);
2438
+ else q.ammo = Math.min(60, q.ammo + 20);
2397
2439
  this.gone[k] = 1200;
2398
2440
  }
2399
2441
  });
@@ -9,6 +9,11 @@ export interface Body {
9
9
  readonly id: number;
10
10
  /** Advances dt seconds: the own player, eased (undefined before the first snapshot), the kick of the gun (0 to 1) and the aspect of the screen, which keeps the gun in a narrow one. */
11
11
  update(me: PlayerState | undefined, dt: number, kick?: number, aspect?: number): void;
12
+ /**
13
+ * Where the look ray ends, in the camera's space (right, up, forward), each frame: the gun points
14
+ * at it, at least 3 m out, so that the beam leaves the emitter along its long axis.
15
+ */
16
+ aim(target: Vec3): void;
12
17
  /** The muzzle of the gun in the right hand, in the camera's space (right, up, forward), as of the last update. */
13
18
  muzzle(): Vec3;
14
19
  /** The joints for a camera at `eye`; undefined without a player, or with the camera away from the body. */
@@ -13,8 +13,22 @@ export interface View {
13
13
  pitch: number;
14
14
  /** The pitch the camera draws at: the look plus the shake. */
15
15
  drawn: number;
16
+ /** The own muzzle (the emitter) in the camera's space. */
16
17
  muzzle: Vec3;
18
+ /** Where the look ray ends, from sight(): the beam goes there. */
19
+ end: Vec3;
20
+ hit: boolean;
17
21
  }
22
+ /**
23
+ * Where the own shots end: the first wall along the look ray from the eye, or the range. `local` is
24
+ * that point in the camera's space (right, up, forward), which is turned by the drawn pitch, so
25
+ * that the gun can point at it.
26
+ */
27
+ export declare const sight: (world: World, eye: Vec3, cam: Vec3, yaw: number, pitch: number, drawn: number) => {
28
+ end: Vec3;
29
+ hit: boolean;
30
+ local: Vec3;
31
+ };
18
32
  export interface Combat {
19
33
  /** One live step of the own player, its state before and after: the recoil and the kick of each shot it fired. */
20
34
  step(a?: PlayerState, b?: PlayerState): void;
@@ -28,6 +28,8 @@ export interface CtfScene {
28
28
  /** Each team's gun rack, where it has one, and the health packs that are there to take. */
29
29
  racks?: readonly (Vec3 | undefined)[];
30
30
  packs?: readonly Vec3[];
31
+ /** The ammo packs that are there to take. */
32
+ ammo?: readonly Vec3[];
31
33
  }
32
34
  /** The flags to draw from a snapshot: each at its base, where it lies, or on the back of its carrier (none if he is not drawn). */
33
35
  export declare const flagDraws: (flags: readonly FlagState[], bases: readonly Vec3[], who: (id: number) => PlayerState | undefined) => FlagDraw[];
@@ -1,21 +1,45 @@
1
1
  import type { PlayerState } from '../shared/types';
2
+ import type { World } from '../shared/world';
2
3
  import type { Vec3 } from './mesh';
3
4
  import type { Quat } from './rig';
4
- /** Where the muzzle is, between the two jaws; and the grip's tilt: its lower end goes back by TILT[0] for each TILT[1] down. */
5
+ /**
6
+ * The back of the body and the muzzle, between the jaws, in model space (the tail and the front of
7
+ * the emitter): the line through them is the gun's long axis, the way it points and the way the
8
+ * beam leaves. The grip's tilt: its lower end goes back by TILT[0] for each TILT[1] down.
9
+ */
10
+ export declare const REAR: Vec3;
5
11
  export declare const MUZZLE: Vec3;
6
12
  export declare const TILT: number[];
7
13
  /**
8
14
  * The gun at a level of detail (0 far, 1 near), built once, in the vertex format of mesh.ts, after
9
- * the Halo plasma pistol: a bulbous upper body that splits into two jaws around a glowing
10
- * emitter, a chunky lower shell under the hand, a short thick grip between them, ridges and a fin
11
- * on the back, and cyan strips along the sides.
15
+ * the Halo plasma pistol: a smooth bulbous upper body that splits into two jaws around a glowing
16
+ * emitter, a chunky lower shell under the hand, a short thick grip between them, and cyan strips
17
+ * along the sides.
12
18
  */
13
19
  export declare const gun: (lod: number) => number[];
14
20
  /** The middle of the grip, for a wrist at `pos`: 8 cm along the fingers and 2 cm toward the palm. */
15
21
  export declare const grip: (pos: Vec3, q: Quat) => Vec3;
16
- /** Appends the gun held in the hand at `pos` with the world rotation `q`, `k` times its size about the grip. */
17
- export declare const held: (out: number[], pos: Vec3, q: Quat, lod: number, k?: number) => void;
22
+ /**
23
+ * The ammo as two glowing seven-segment digits on a dark screen set in the back of a small block
24
+ * on top of the body, in model space: cyan, red at 10 or fewer, thick segments that bloom only a
25
+ * little. The block is part of the readout, so only a gun that shows the ammo carries it. 99 at most.
26
+ */
27
+ export declare const readout: (ammo: number) => number[];
28
+ /**
29
+ * Appends the gun held in the hand at `pos` with the world rotation `q`, `k` times its size about
30
+ * the grip, with the ammo on its back when given.
31
+ */
32
+ export declare const held: (out: number[], pos: Vec3, q: Quat, lod: number, k?: number, ammo?: number) => void;
18
33
  /** The muzzle of a gun whose grip is at `at` and whose axes are [right, up, forward]. */
19
34
  export declare const tip: (at: Vec3, [, u, f]: Vec3[]) => Vec3;
20
- /** Where a runner holds the gun when it fires: the grip, a little right of and below the eye, and the gun's axes along the look. */
21
- export declare const aimed: (p: PlayerState) => [Vec3, Vec3[]];
35
+ /**
36
+ * The axes [right, up, forward] of a gun held with its grip at `at` so that its long axis, from the
37
+ * back of the body to the emitter, points at `to`: the beam leaves the emitter along it. `side` is
38
+ * where the right axis points, `up` where up is. The emitter is off the grip, so the axes are found
39
+ * in three rounds.
40
+ */
41
+ export declare const pointed: (at: Vec3, to: Vec3, side: Vec3, up: Vec3) => Vec3[];
42
+ /** Where a runner's shots end: the first wall along its look from the eye, or the range. */
43
+ export declare const focus: (p: PlayerState, world: World) => [Vec3, boolean];
44
+ /** Where a runner holds the gun when it fires at `to`: the grip, a little right of and below the eye, and the gun's axes. */
45
+ export declare const aimed: (p: PlayerState, to: Vec3) => [Vec3, Vec3[]];
@@ -1,7 +1,12 @@
1
1
  import type { Vec3 } from './mesh';
2
- /** The health packs of `all` whose bit is set in `mask`, if any: the ones that are there to take. */
3
- export declare const packsOf: (all?: readonly Vec3[], mask?: number) => Vec3[];
2
+ /**
3
+ * The packs of `all` whose bit is set in `mask`, if any: the ones that are there to take. The bits
4
+ * count from `from`: the ammo packs come after the health packs.
5
+ */
6
+ export declare const packsOf: (all?: readonly Vec3[], mask?: number, from?: number) => Vec3[];
4
7
  /** A rack at `at` (a point on a top): a post and a dish, a ring on the roof of the radius that gives the gun, the gun over it. */
5
8
  export declare const rack: (out: number[], at: Vec3, rgb: number[], t: number) => void;
6
- /** A health pack at `at` (on a top): a box turning and bobbing a little over it, a green cross glowing on each side. */
9
+ /** A health pack at `at`: a white box with a glowing green cross on each side. */
7
10
  export declare const kit: (out: number[], at: Vec3, t: number) => void;
11
+ /** An ammo pack at `at`: a violet box with a glowing cyan cartridge on each side, the gun's colours. */
12
+ export declare const cell: (out: number[], at: Vec3, t: number) => void;
@@ -1,6 +1,7 @@
1
1
  import type { PlayerState } from '../shared/types';
2
2
  import type { World } from '../shared/world';
3
3
  import type { Gait } from './gait';
4
+ import type { Vec3 } from './mesh';
4
5
  /** What a runner keeps between frames. */
5
6
  export interface Runner {
6
7
  /** The player as last seen. */
@@ -11,6 +12,8 @@ export interface Runner {
11
12
  /** Seconds since its last shot, and how far its gun arm is raised to aim, eased from 0 to 1. */
12
13
  since: number;
13
14
  aim: number;
15
+ /** Where its last shot went, which its gun points at. */
16
+ focus: Vec3;
14
17
  }
15
18
  /** A runner as first seen: in the pose its state asks for, no ease. */
16
19
  export declare const createRunner: (p: PlayerState) => Runner;
@@ -180,6 +180,8 @@ export declare const DOWN_TICKS = 120;
180
180
  /** Health a pack gives, up to HP_MAX, and seconds before a taken pack is back. */
181
181
  export declare const PACK_HP = 2;
182
182
  export declare const PACK_BACK = 20;
183
+ /** Shots an ammo pack gives, up to AMMO_MAX. */
184
+ export declare const AMMO_PACK = 20;
183
185
  /** Metres from a pack or a rack, feet to point on the floor plane, that take it. */
184
186
  export declare const PACK_R = 0.9;
185
187
  export declare const RACK_R = 1.2;
@@ -77,7 +77,12 @@ export declare class Room {
77
77
  * him down: he lies where he fell, without the gun, and a flag he carries drops with the lock.
78
78
  */
79
79
  private shoot;
80
- /** The packs: one that is gone comes back after PACK_BACK s; a hurt player standing at one takes it. */
80
+ /**
81
+ * The packs, health ones first, then the ammo ones: one that is gone comes back after PACK_BACK
82
+ * s. A health pack goes to a hurt player standing at it, an ammo pack to one with the gun and
83
+ * less than AMMO_MAX shots. Both change the state between two inputs, like a hit: the snapshot
84
+ * carries the result and the predictor replays its unacked inputs on it.
85
+ */
81
86
  private heal;
82
87
  /** The first spawn point of the team with none of `others` within SPAWN_CLEAR, else the next one round-robin. */
83
88
  private place;
@@ -205,7 +205,10 @@ export interface Snapshot {
205
205
  over: boolean;
206
206
  /** The flag of each team, red then blue. */
207
207
  flags: [FlagState, FlagState];
208
- /** Bit n set: health pack n of WorldDef.packs is there to take. Absent: none. */
208
+ /**
209
+ * Bit n set: pack n is there to take, the health packs of WorldDef.packs first, then the ammo
210
+ * packs of WorldDef.ammo (bit packs.length + n). Absent: none.
211
+ */
209
212
  packs?: number;
210
213
  }
211
214
  /** Room rules, set by the host. Defaults in constants.ts (RULES). */
@@ -31,6 +31,8 @@ export interface WorldDef {
31
31
  floor: number;
32
32
  /** Health packs, points on tops (at most 32): walking within PACK_R gives PACK_HP, then it is gone PACK_BACK seconds. */
33
33
  packs?: Vec3[];
34
+ /** Ammo packs, points on tops (health and ammo packs together at most 32): within PACK_R a player with the gun and fewer than AMMO_MAX shots takes AMMO_PACK, then it is gone PACK_BACK seconds. */
35
+ ammo?: Vec3[];
34
36
  /** Unit direction toward the sun, and its colour (linear RGB, may exceed 1). */
35
37
  sun: {
36
38
  dir: Vec3;
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.26.0",
5
+ "version": "0.27.1",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"