var ROT={isSupported:function(){return!(!document.createElement("canvas").getContext||!Function.prototype.bind)},DEFAULT_WIDTH:80,DEFAULT_HEIGHT:25,DIRS:{4:[[0,-1],[1,0],[0,1],[-1,0]],8:[[0,-1],[1,-1],[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1]],6:[[-1,-1],[1,-1],[2,0],[1,1],[-1,1],[-2,0]]},VK_CANCEL:3,VK_HELP:6,VK_BACK_SPACE:8,VK_TAB:9,VK_CLEAR:12,VK_RETURN:13,VK_ENTER:14,VK_SHIFT:16,VK_CONTROL:17,VK_ALT:18,VK_PAUSE:19,VK_CAPS_LOCK:20,VK_ESCAPE:27,VK_SPACE:32,VK_PAGE_UP:33,VK_PAGE_DOWN:34,VK_END:35, VK_HOME:36,VK_LEFT:37,VK_UP:38,VK_RIGHT:39,VK_DOWN:40,VK_PRINTSCREEN:44,VK_INSERT:45,VK_DELETE:46,VK_0:48,VK_1:49,VK_2:50,VK_3:51,VK_4:52,VK_5:53,VK_6:54,VK_7:55,VK_8:56,VK_9:57,VK_COLON:58,VK_SEMICOLON:59,VK_LESS_THAN:60,VK_EQUALS:61,VK_GREATER_THAN:62,VK_QUESTION_MARK:63,VK_AT:64,VK_A:65,VK_B:66,VK_C:67,VK_D:68,VK_E:69,VK_F:70,VK_G:71,VK_H:72,VK_I:73,VK_J:74,VK_K:75,VK_L:76,VK_M:77,VK_N:78,VK_O:79,VK_P:80,VK_Q:81,VK_R:82,VK_S:83,VK_T:84,VK_U:85,VK_V:86,VK_W:87,VK_X:88,VK_Y:89,VK_Z:90,VK_CONTEXT_MENU:93, VK_NUMPAD0:96,VK_NUMPAD1:97,VK_NUMPAD2:98,VK_NUMPAD3:99,VK_NUMPAD4:100,VK_NUMPAD5:101,VK_NUMPAD6:102,VK_NUMPAD7:103,VK_NUMPAD8:104,VK_NUMPAD9:105,VK_MULTIPLY:106,VK_ADD:107,VK_SEPARATOR:108,VK_SUBTRACT:109,VK_DECIMAL:110,VK_DIVIDE:111,VK_F1:112,VK_F2:113,VK_F3:114,VK_F4:115,VK_F5:116,VK_F6:117,VK_F7:118,VK_F8:119,VK_F9:120,VK_F10:121,VK_F11:122,VK_F12:123,VK_F13:124,VK_F14:125,VK_F15:126,VK_F16:127,VK_F17:128,VK_F18:129,VK_F19:130,VK_F20:131,VK_F21:132,VK_F22:133,VK_F23:134,VK_F24:135,VK_NUM_LOCK:144, VK_SCROLL_LOCK:145,VK_CIRCUMFLEX:160,VK_EXCLAMATION:161,VK_DOUBLE_QUOTE:162,VK_HASH:163,VK_DOLLAR:164,VK_PERCENT:165,VK_AMPERSAND:166,VK_UNDERSCORE:167,VK_OPEN_PAREN:168,VK_CLOSE_PAREN:169,VK_ASTERISK:170,VK_PLUS:171,VK_PIPE:172,VK_HYPHEN_MINUS:173,VK_OPEN_CURLY_BRACKET:174,VK_CLOSE_CURLY_BRACKET:175,VK_TILDE:176,VK_COMMA:188,VK_PERIOD:190,VK_SLASH:191,VK_BACK_QUOTE:192,VK_OPEN_BRACKET:219,VK_BACK_SLASH:220,VK_CLOSE_BRACKET:221,VK_QUOTE:222,VK_META:224,VK_ALTGR:225,VK_WIN:91,VK_KANA:21,VK_HANGUL:21, VK_EISU:22,VK_JUNJA:23,VK_FINAL:24,VK_HANJA:25,VK_KANJI:25,VK_CONVERT:28,VK_NONCONVERT:29,VK_ACCEPT:30,VK_MODECHANGE:31,VK_SELECT:41,VK_PRINT:42,VK_EXECUTE:43,VK_SLEEP:95,Text:{RE_COLORS:/%([bc]){([^}]*)}/g,TYPE_TEXT:0,TYPE_NEWLINE:1,TYPE_FG:2,TYPE_BG:3,measure:function(a,b){for(var c={width:0,height:1},d=this.tokenize(a,b),e=0,f=0;fb){for(g=-1;;){var h=f.value.indexOf(" ",g+1);if(-1==h)break;if(d+h>b)break;g=h}-1!=g?f.value=this._breakInsideToken(a,c,g,!0):-1!=e?(f=a[e],c=f.value.lastIndexOf(" "),f.value=this._breakInsideToken(a,e,c,!0),c=e):f.value= this._breakInsideToken(a,c,b-d,!1)}else d+=f.value.length,-1!=f.value.indexOf(" ")&&(e=c);c++}else a.splice(c,1)}}a.push({type:ROT.Text.TYPE_NEWLINE});d=null;for(c=0;cb||0>a||b>=this._context.canvas.width||a>=this._context.canvas.height?[-1,-1]:this._backend.eventToPosition(b,a)}; ROT.Display.prototype.draw=function(a,b,c,d,e){d||(d=this._options.fg);e||(e=this._options.bg);this._data[a+","+b]=[a,b,c,d,e];!0!==this._dirty&&(this._dirty||(this._dirty={}),this._dirty[a+","+b]=!0)}; ROT.Display.prototype.drawText=function(a,b,c,d){var e=null,f=null,g=a,h=1;d||(d=this._options.width-a);for(c=ROT.Text.tokenize(c,d);c.length;)switch(d=c.shift(),d.type){case ROT.Text.TYPE_TEXT:for(var k=0;ka?1/a:a;this._s0=(a>>>0)*this._frac;a=69069*a+1>>>0;this._s1=a*this._frac;this._s2=(69069*a+1>>>0)*this._frac;this._c=1;return this},getUniform:function(){var a=2091639*this._s0+this._c*this._frac;this._s0=this._s1;this._s1=this._s2;this._c=a|0;return this._s2=a-this._c},getNormal:function(a,b){do var c=2*this.getUniform()-1,d=2*this.getUniform()-1,d=c*c+d*d;while(1this._options.order?a=a.slice(-this._options.order):a.lengthb){c=d;break}this._events.splice(c,0,a);this._eventTimes.splice(c,0,b)}; ROT.EventQueue.prototype.get=function(){if(!this._events.length)return null;var a=this._eventTimes.splice(0,1)[0];if(0p;p++)if(g=e+2*m[p][0],h=f+2*m[p][1],this._isFree(d,g,h,b,c)){d[g][h]=0;d[e+m[p][0]][f+ m[p][1]]=0;e=g;f=h;l=!1;k++;break}}while(!l)}while(k+1b;b++)a[b][0]=0,a[b][1]=0;switch(Math.floor(4*ROT.RNG.getUniform())){case 0:a[0][0]=-1;a[1][0]=1;a[2][1]=-1;a[3][1]=1;break;case 1:a[3][0]=-1;a[2][0]=1;a[1][1]=-1;a[0][1]=1;break;case 2:a[2][0]=-1;a[3][0]=1;a[0][1]=-1;a[1][1]=1;break;case 3:a[1][0]=-1,a[0][0]=1,a[3][1]=-1,a[2][1]=1}};ROT.Map.IceyMaze.prototype._isFree=function(a,b,c,d,e){return 1>b||1>c||b>=d||c>=e?!1:a[b][c]};ROT.Map.EllerMaze=function(a,b){ROT.Map.call(this,a,b)};ROT.Map.EllerMaze.extend(ROT.Map); ROT.Map.EllerMaze.prototype.create=function(a){for(var b=this._fillMap(1),c=Math.ceil((this._width-2)/2),d=[],e=[],f=0;ff||(f>=this._width||0>f||e>=this._width)||(c+=1==this._map[f][e]?1:0)}return c};ROT.Map.Dungeon=function(a,b){ROT.Map.call(this,a,b);this._rooms=[];this._corridors=[]};ROT.Map.Dungeon.extend(ROT.Map);ROT.Map.Dungeon.prototype.getRooms=function(){return this._rooms};ROT.Map.Dungeon.prototype.getCorridors=function(){return this._corridors}; ROT.Map.Digger=function(a,b,c){ROT.Map.Dungeon.call(this,a,b);this._options={roomWidth:[3,9],roomHeight:[3,5],corridorLength:[3,10],dugPercentage:0.2,timeLimit:1E3};for(var d in c)this._options[d]=c[d];this._features={Room:4,Corridor:4};this._featureAttempts=20;this._walls={};this._digCallback=this._digCallback.bind(this);this._canBeDugCallback=this._canBeDugCallback.bind(this);this._isWallCallback=this._isWallCallback.bind(this);this._priorityWallCallback=this._priorityWallCallback.bind(this)};ROT.Map.Digger.extend(ROT.Map.Dungeon); ROT.Map.Digger.prototype.create=function(a){this._rooms=[];this._corridors=[];this._map=this._fillMap(1);this._walls={};this._dug=0;var b=(this._width-2)*(this._height-2);this._firstRoom();var c=Date.now();do{if(Date.now()-c>this._options.timeLimit)break;var d=this._findWall();if(!d)break;var e=d.split(","),d=parseInt(e[0]),e=parseInt(e[1]),f=this._getDiggingDirection(d,e);if(f){var g=0;do if(g++,this._tryFeature(d,e,f[0],f[1])){this._removeSurroundingWalls(d,e);this._removeSurroundingWalls(d-f[0], e-f[1]);break}while(ga||0>b||a>=this._width||b>=this._height?!1:1==this._map[a][b]};ROT.Map.Digger.prototype._canBeDugCallback=function(a,b){return 1>a||1>b||a+1>=this._width||b+1>=this._height?!1:1==this._map[a][b]};ROT.Map.Digger.prototype._priorityWallCallback=function(a,b){this._walls[a+","+b]=2}; ROT.Map.Digger.prototype._firstRoom=function(){var a=ROT.Map.Feature.Room.createRandomCenter(Math.floor(this._width/2),Math.floor(this._height/2),this._options);this._rooms.push(a);a.create(this._digCallback)};ROT.Map.Digger.prototype._findWall=function(){var a=[],b=[],c;for(c in this._walls)2==this._walls[c]?b.push(c):a.push(c);a=b.length?b:a;if(!a.length)return null;c=a.random();delete this._walls[c];return c}; ROT.Map.Digger.prototype._tryFeature=function(a,b,c,d){var e=ROT.RNG.getWeightedValue(this._features),e=ROT.Map.Feature[e].createRandomAt(a,b,c,d,this._options);if(!e.isValid(this._isWallCallback,this._canBeDugCallback))return!1;e.create(this._digCallback);e instanceof ROT.Map.Feature.Room&&this._rooms.push(e);e instanceof ROT.Map.Feature.Corridor&&(e.createPriorityWalls(this._priorityWallCallback),this._corridors.push(e));return!0}; ROT.Map.Digger.prototype._removeSurroundingWalls=function(a,b){for(var c=ROT.DIRS[4],d=0;dg||0>h||g>=this._width||h>=this._width)return null;if(!this._map[g][h]){if(c)return null;c=f}}return c?[-c[0],-c[1]]:null}; ROT.Map.Digger.prototype._addDoors=function(){for(var a=this._map,b=function(b,c){return 1==a[b][c]},c=0;cthis._options.timeLimit)return null;this._map=this._fillMap(1);this._dug=0;this._rooms=[];this._unconnected=[];this._generateRooms();if(this._generateCorridors())break}if(a)for(b=0;bthis._options.roomDugPercentage)break}while(c)}; ROT.Map.Uniform.prototype._generateRoom=function(){for(var a=0;a=g&&c[e]<=h){var k=c.slice(),d=null;switch(f){case 0:d=b.getTop()-1;break;case 1:d=b.getRight()+1;break;case 2:d=b.getBottom()+1;break;case 3:d=b.getLeft()-1}k[(e+1)%2]=d;this._digLine([c,k])}else if(c[e]< g-1||c[e]>h+1){d=c[e]-d[e];switch(f){case 0:case 1:k=0>d?3:1;break;case 2:case 3:k=0>d?1:3}k=this._placeInWall(b,(f+k)%4);if(!k)return!1;f=[0,0];f[e]=c[e];d=(e+1)%2;f[d]=k[d];this._digLine([c,f,k])}else{d=(e+1)%2;k=this._placeInWall(b,f);if(!k)return;f=Math.round((k[d]+c[d])/2);g=[0,0];h=[0,0];g[e]=c[e];g[d]=f;h[e]=k[e];h[d]=f;this._digLine([c,g,h,k])}a.addDoor(c[0],c[1]);b.addDoor(k[0],k[1]);e=this._unconnected.indexOf(a);-1!=e&&(this._unconnected.splice(e,1),this._connected.push(a));e=this._unconnected.indexOf(b); -1!=e&&(this._unconnected.splice(e,1),this._connected.push(b));return!0}; ROT.Map.Uniform.prototype._placeInWall=function(a,b){var c=[0,0],d=[0,0],e=0;switch(b){case 0:d=[1,0];c=[a.getLeft(),a.getTop()-1];e=a.getRight()-a.getLeft()+1;break;case 1:d=[0,1];c=[a.getRight()+1,a.getTop()];e=a.getBottom()-a.getTop()+1;break;case 2:d=[1,0];c=[a.getLeft(),a.getBottom()+1];e=a.getRight()-a.getLeft()+1;break;case 3:d=[0,1],c=[a.getLeft()-1,a.getTop()],e=a.getBottom()-a.getTop()+1}for(var f=[],g=-2,h=0;ha||0>b||a>=this._width||b>=this._height?!1:1==this._map[a][b]};ROT.Map.Uniform.prototype._canBeDugCallback=function(a,b){return 1>a||1>b||a+1>=this._width||b+1>=this._height?!1:1==this._map[a][b]}; ROT.Map.Rogue=function(a,b,c){ROT.Map.call(this,a,b);this._options={cellWidth:3,cellHeight:3};for(var d in c)this._options[d]=c[d];this._options.hasOwnProperty("roomWidth")||(this._options.roomWidth=this._calculateRoomSize(a,this._options.cellWidth));this._options.hasOwnProperty.roomHeight||(this._options.roomHeight=this._calculateRoomSize(b,this._options.cellHeight))};ROT.Map.Rogue.extend(ROT.Map); ROT.Map.Rogue.prototype.create=function(a){this.map=this._fillMap(1);this.rooms=[];this.connectedCells=[];this._initRooms();this._connectRooms();this._connectUnconnectedRooms();this._createRandomRoomConnections();this._createRooms();this._createCorridors();if(a)for(var b=0;bd&&(d=2);2>c&&(c=2);return[d,c]};ROT.Map.Rogue.prototype._initRooms=function(){for(var a=0;ad||d>=this._options.cellWidth||0>c||c>=this._options.cellHeight)){f=this.rooms[a][b];if(0l||l>=a||0>k||k>=b)){d=this.rooms[l][k];e=!0;if(0==d.connections.length)break;for(l=0;lp-(n.y+n.height);)p++;if(0m-(n.x+n.width);)m++; n=Math.round(this._getRandomInt(0,e-g)/2);for(var s=Math.round(this._getRandomInt(0,f-h)/2);m+n+g>=a;)n?n--:g--;for(;p+s+h>=b;)s?s--:h--;m+=n;p+=s;this.rooms[q][r].x=m;this.rooms[q][r].y=p;this.rooms[q][r].width=g;this.rooms[q][r].height=h;for(n=m;nc.cellx?(e=2,f=4):d.cellxc.celly?(e=3,f=1):d.cellyq?(r=1,s=0):(r=0,s=1);var u=n-r+f,v=q-s+f,m=n-1+2*f,f=q-1+2*f,p=p.mod(e),e=l.mod(e),t=0.5-n*n-q*q;0<=t&&(t*=t,l=d[p+c[e]],l=this._gradients[l],g=t*t*(l[0]*n+l[1]*q));n=0.5-u*u-v*v;0<=n&&(n*=n,l=d[p+r+c[e+s]],l=this._gradients[l],h=n*n*(l[0]*u+l[1]*v));n=0.5-m*m-f*f;0<=n&&(n*=n,l=d[p+1+c[e+ 1]],l=this._gradients[l],k=n*n*(l[0]*m+l[1]*f));return 70*(g+h+k)};ROT.FOV=function(a,b){this._lightPasses=a;this._options={topology:8};for(var c in b)this._options[c]=b[c]};ROT.FOV.prototype.compute=function(a,b,c,d){}; ROT.FOV.prototype._getCircle=function(a,b,c){var d=[],e,f,g;switch(this._options.topology){case 4:f=1;g=[0,1];e=[ROT.DIRS[8][7],ROT.DIRS[8][1],ROT.DIRS[8][3],ROT.DIRS[8][5]];break;case 6:e=ROT.DIRS[6];f=1;g=[-1,1];break;case 8:e=ROT.DIRS[4],f=2,g=[-1,1]}a+=g[0]*c;b+=g[1]*c;for(g=0;ga){var e=arguments.callee(0,b,c,d),f=arguments.callee(360+a,360,c,d);return e||f}for(e=0;eb[0])return a=this._checkVisibility(a,[a[1],a[1]],c,d),b=this._checkVisibility([0,1],b,c,d),(a+b)/2;for(var e=0,f=!1;eh&&e%2&&(g=!1);if(!g)return 0;f=h-e+1;if(f%2)e%2?(h=d[e],h=(b[0]*h[1]-h[0]*b[1])/ (h[1]*b[1]),c&&d.splice(e,f,b)):(h=d[h],h=(h[0]*a[1]-a[0]*h[1])/(a[1]*h[1]),c&&d.splice(e,f,a));else if(e%2)k=d[e],h=d[h],h=(h[0]*k[1]-k[0]*h[1])/(k[1]*h[1]),c&&d.splice(e,f);else return c&&d.splice(e,f,a,b),1;return h/((b[0]*a[1]-a[0]*b[1])/(a[1]*b[1]))}; ROT.Color={fromString:function(a){var b,c;if(a in this._cache)b=this._cache[a];else{if("#"==a.charAt(0))if(b=a.match(/[0-9a-f]/gi).map(function(a){return parseInt(a,16)}),3==b.length)b=b.map(function(a){return 17*a});else for(c=0;3>c;c++)b[c+1]+=16*b[c],b.splice(c,1);else b=(c=a.match(/rgb\(([0-9, ]+)\)/i))?c[1].split(/\s*,\s*/).map(function(a){return parseInt(a)}):[0,0,0];this._cache[a]=b}return b.slice()},add:function(a,b){for(var c=a.slice(),d=0;3>d;d++)for(var e=1;ec;c++)for(var d=1;dd;d++){for(var e=1;ec;c++){for(var d=1;darguments.length&&(c=0.5);for(var d=a.slice(),e=0;3> e;e++)d[e]=Math.round(d[e]+c*(b[e]-a[e]));return d},interpolateHSL:function(a,b,c){3>arguments.length&&(c=0.5);for(var d=this.rgb2hsl(a),e=this.rgb2hsl(b),f=0;3>f;f++)d[f]+=c*(e[f]-d[f]);return this.hsl2rgb(d)},randomize:function(a,b){b instanceof Array||(b=ROT.RNG.getNormal(0,b));for(var c=a.slice(),d=0;3>d;d++)c[d]+=b instanceof Array?Math.round(ROT.RNG.getNormal(0,b[d])):b;return c},rgb2hsl:function(a){var b=a[0]/255,c=a[1]/255;a=a[2]/255;var d=Math.max(b,c,a),e=Math.min(b,c,a),f,g=(d+e)/2;if(d== e)f=e=0;else{var h=d-e,e=0.5c&&(c+=1);1c?b:c<2/3?a+6*(b-a)*(2/3-c):a},d=a[1],d=0.5>b?b*(1+d):b+d-b*d,e=2*b-d,b=c(e,d,a[0]+1/3),f=c(e,d,a[0]);a=c(e,d,a[0]-1/3);return[Math.round(255*b),Math.round(255*f),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 b=[],c=0;3>c;c++)b.push(this._clamp(a[c]).toString(16).lpad("0",2));return"#"+b.join("")},_clamp:function(a){return 0>a?0:255k;k++){var l=Math.round(e[k]*f);g[k]=l;h+=l}h>this._options.emissionThreshold&&(c[d]=g)}}return c}; ROT.Lighting.prototype._emitLightFromCell=function(a,b,c,d){var e=a+","+b;a=e in this._fovCache?this._fovCache[e]:this._updateFOV(a,b);for(var f in a){b=a[f];f in d?e=d[f]:(e=[0,0,0],d[f]=e);for(var g=0;3>g;g++)e[g]+=Math.round(c[g]*b)}return this};ROT.Lighting.prototype._updateFOV=function(a,b){var c={};this._fovCache[a+","+b]=c;var d=this._options.range;this._fov.compute(a,b,d,function(a,b,g,h){g=h*(1-g/d);0!=g&&(c[a+","+b]=g)}.bind(this));return c}; ROT.Path=function(a,b,c,d){this._toX=a;this._toY=b;this._fromY=this._fromX=null;this._passableCallback=c;this._options={topology:8};for(var e in d)this._options[e]=d[e];this._dirs=ROT.DIRS[this._options.topology]};ROT.Path.prototype.compute=function(a,b,c){};ROT.Path.prototype._getNeighbors=function(a,b){for(var c=[],d=0;d