p-(q.x+
84 | q.width);)p++;q=Math.round(b.RNG.getUniformInt(0,f-h)/2);for(var v=Math.round(b.RNG.getUniformInt(0,g-l)/2);p+q+h>=a;)q?q--:h--;for(;r+v+l>=c;)v?v--:l--;p+=q;r+=v;this.rooms[t][u].x=p;this.rooms[t][u].y=r;this.rooms[t][u].width=h;this.rooms[t][u].height=l;for(q=p;qd.cellx?(b=2,g=4):e.cellxd.celly?(b=3,g=1):e.cellyt){var u=1;var v=0}else u=0,v=1;var x=q-u+g,y=t-v+g;n=q-1+2*g;g=t-1+2*g;p=p.mod(b);b=r.mod(b);var w=.5-q*q-t*t;0<=w&&(w*=w,r=e[p+d[b]],r=this._gradients[r],h=w*w*(r[0]*q+r[1]*t));q=.5-x*x-y*y;0<=q&&(q*=q,r=e[p+u+d[b+v]],r=this._gradients[r],l=q*q*(r[0]*x+r[1]*y));q=.5-n*n-g*g;0<=q&&(q*=q,r=e[p+1+d[b+1]],r=this._gradients[r],m=q*q*(r[0]*n+r[1]*g));return 70*(h+l+m)};b.FOV=function(a,c){this._lightPasses=
98 | a;this._options={topology:8};for(var d in c)this._options[d]=c[d]};b.FOV.prototype.compute=function(a,c,d,b){};b.FOV.prototype._getCircle=function(a,c,d){var e=[];switch(this._options.topology){case 4:var f=1;var g=[0,1];var h=[b.DIRS[8][7],b.DIRS[8][1],b.DIRS[8][3],b.DIRS[8][5]];break;case 6:h=b.DIRS[6];f=1;g=[-1,1];break;case 8:h=b.DIRS[4],f=2,g=[-1,1]}a+=g[0]*d;c+=g[1]*d;for(g=0;ga)return c=this._visibleCoords(0,c,d,b),a=this._visibleCoords(360+a,360,d,b),c||a;for(var e=0;ec[0])return a=this._checkVisibility(a,[a[1],a[1]],
102 | d,b),c=this._checkVisibility([0,1],c,d,b),(a+c)/2;for(var e=0,g=!1;el&&e%2&&(h=!1);if(!h)return 0;g=l-e+1;if(g%2)e%2?(l=b[e],l=(c[0]*l[1]-l[0]*c[1])/(l[1]*c[1]),d&&b.splice(e,g,c)):(l=b[l],l=(l[0]*a[1]-a[0]*l[1])/(a[1]*l[1]),d&&b.splice(e,g,a));else if(e%2)m=b[e],l=b[l],l=(l[0]*m[1]-
103 | m[0]*l[1])/(m[1]*l[1]),d&&b.splice(e,g);else return d&&b.splice(e,g,a,c),1;return l/((c[0]*a[1]-a[0]*c[1])/(a[1]*c[1]))};b.FOV.RecursiveShadowcasting=function(a,c){b.FOV.call(this,a,c)};b.FOV.RecursiveShadowcasting.extend(b.FOV);b.FOV.RecursiveShadowcasting.OCTANTS=[[-1,0,0,1],[0,-1,1,0],[0,-1,-1,0],[-1,0,0,-1],[1,0,0,-1],[0,1,-1,0],[0,1,1,0],[1,0,0,1]];b.FOV.RecursiveShadowcasting.prototype.compute=function(a,c,d,e){e(a,c,0,1);for(var f=0;f=e;){e+=1;var v=a+e*h+q*l,x=c+e*m+q*n,y=(e-.5)/(q+.5),w=(e+
106 | .5)/(q-.5);if(!(w>b)){if(yc;c++)d[c+1]+=16*d[c],d.splice(c,1);else d=(c=a.match(/rgb\(([0-9, ]+)\)/i))?
107 | c[1].split(/\s*,\s*/).map(function(a){return parseInt(a)}):[0,0,0];this._cache[a]=d}return d.slice()},add:function(a,c){for(var d=a.slice(),b=0;3>b;b++)for(var f=1;fd;d++)for(var b=1;bb;b++){for(var f=1;fd;d++){for(var b=1;barguments.length&&(d=.5);for(var b=a.slice(),f=0;3>f;f++)b[f]=Math.round(b[f]+d*(c[f]-a[f]));return b},interpolateHSL:function(a,c,b){3>arguments.length&&(b=.5);for(var d=this.rgb2hsl(a),f=this.rgb2hsl(c),g=0;3>g;g++)d[g]+=b*(f[g]-d[g]);return this.hsl2rgb(d)},randomize:function(a,c){c instanceof Array||(c=Math.round(b.RNG.getNormal(0,c)));for(var d=a.slice(),e=0;3>
109 | e;e++)d[e]+=c instanceof Array?Math.round(b.RNG.getNormal(0,c[e])):c;return d},rgb2hsl:function(a){var c=a[0]/255,b=a[1]/255;a=a[2]/255;var e=Math.max(c,b,a),f=Math.min(c,b,a),g=(e+f)/2;if(e==f)var h=f=0;else{var l=e-f;f=.5b&&(b+=1);1b?
110 | c:b<2/3?a+(c-a)*(2/3-b)*6:a},e=a[1];e=.5>c?c*(1+e):c+e-c*e;var f=2*c-e;c=b(f,e,a[0]+1/3);var g=b(f,e,a[0]);a=b(f,e,a[0]-1/3);return[Math.round(255*c),Math.round(255*g),Math.round(255*a)]},toRGB:function(a){return"rgb("+this._clamp(a[0])+","+this._clamp(a[1])+","+this._clamp(a[2])+")"},toHex:function(a){for(var c=[],b=0;3>b;b++)c.push(this._clamp(a[b]).toString(16).lpad("0",2));return"#"+c.join("")},_clamp:function(a){return 0>a?0:255m;m++){var n=Math.round(f[m]*g);h[m]=n;l+=n}l>this._options.emissionThreshold&&(b[e]=h)}}return b};b.Lighting.prototype._emitLightFromCell=function(a,c,b,e){var d=a+","+c;a=d in this._fovCache?this._fovCache[d]:this._updateFOV(a,
121 | c);for(var g in a){c=a[g];g in e?d=e[g]:(d=[0,0,0],e[g]=d);for(var h=0;3>h;h++)d[h]+=Math.round(b[h]*c)}return this};b.Lighting.prototype._updateFOV=function(a,c){var b={};this._fovCache[a+","+c]=b;var e=this._options.range;this._fov.compute(a,c,e,function(a,c,d,l){d=l*(1-d/e);0!=d&&(b[a+","+c]=d)}.bind(this));return b};b.Path=function(a,c,d,e){this._toX=a;this._toY=c;this._fromY=this._fromX=null;this._passableCallback=d;this._options={topology:8};for(var f in e)this._options[f]=e[f];this._dirs=b.DIRS[this._options.topology];
122 | 8==this._options.topology&&(this._dirs=[this._dirs[0],this._dirs[2],this._dirs[4],this._dirs[6],this._dirs[1],this._dirs[3],this._dirs[5],this._dirs[7]])};b.Path.prototype.compute=function(a,b,d){};b.Path.prototype._getNeighbors=function(a,b){for(var c=[],e=0;e