// Setup requestAnimationFrame and cancelAnimationFrame for use in the game code
function loadItem(e){var t=this.list[e];if(t.spriteArray)return;t.spriteSheet=loader.loadImage("images/"+this.defaults.type+"/"+e+".png"),t.spriteArray=[],t.spriteCount=0;for(var n=0;n<t.spriteImages.length;n++){var r=t.spriteImages[n].count,i=t.spriteImages[n].directions;if(i)for(var s=0;s<i;s++){var o=t.spriteImages[n].name+"-"+s;t.spriteArray[o]={name:o,count:r,offset:t.spriteCount},t.spriteCount+=r}else{var o=t.spriteImages[n].name;t.spriteArray[o]={name:o,count:r,offset:t.spriteCount},t.spriteCount+=r}}t.weaponType&&bullets.load(t.weaponType)}function addItem(e){var t={},n=e.name;return $.extend(t,this.defaults),$.extend(t,this.list[n]),t.life=t.hitPoints,$.extend(t,e),t}function findAngle(e,t,n){var r=e.y-t.y,i=e.x-t.x,s=wrapDirection(n/2-Math.atan2(i,r)*n/(2*Math.PI),n);return s}function angleDiff(e,t,n){return e>=n/2&&(e-=n),t>=n/2&&(t-=n),diff=t-e,diff<-n/2&&(diff+=n),diff>n/2&&(diff-=n),diff}function wrapDirection(e,t){return e<0&&(e+=t),e>=t&&(e-=t),e}function findFiringAngle(e,t,n){var r=e.y-t.y,i=e.x-t.x;e.type=="buildings"?(r+=e.baseWidth/2/game.gridSize,i+=e.baseHeight/2/game.gridSize):e.type=="aircraft"&&(r-=e.pixelShadowHeight/game.gridSize),t.type=="buildings"?(r-=t.baseWidth/2/game.gridSize,i-=t.baseHeight/2/game.gridSize):t.type=="aircraft"&&(r+=t.pixelShadowHeight/game.gridSize);var s=wrapDirection(n/2-Math.atan2(i,r)*n/(2*Math.PI),n);return s}function isValidTarget(e){return e.team!=this.team&&(this.canAttackLand&&(e.type=="buildings"||e.type=="vehicles")||this.canAttackAir&&e.type=="aircraft")}function findTargetsInSight(e){e||(e=0);var t=[];for(var n=game.items.length-1;n>=0;n--){var r=game.items[n];this.isValidTarget(r)&&Math.pow(r.x-this.x,2)+Math.pow(r.y-this.y,2)<Math.pow(this.sight+e,2)&&t.push(r)}var i=this;return t.sort(function(e,t){return Math.pow(e.x-i.x,2)+Math.pow(e.y-i.y,2)-(Math.pow(t.x-i.x,2)+Math.pow(t.y-i.y,2))}),t}function isItemDead(e){var t=game.getItemByUid(e);return!t||t.lifeCode=="dead"}(function(){var e=0,t=["ms",";","webkit","o"];for(var n=0;n<t.length&&!window.requestAnimationFrame;++n)window.requestAnimationFrame=window[t[n]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[t[n]+"CancelAnimationFrame"]||window[t[n]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(t,n){var r=(new Date).getTime(),i=Math.max(0,16-(r-e)),s=window.setTimeout(function(){t(r+i)},i);return e=r+i,s}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){clearTimeout(e)})})();var loader={loaded:!0,loadedCount:0,totalCount:0,init:function(){var e,t,n=document.createElement("audio");n.canPlayType?(e=""!=n.canPlayType("audio/mpeg"),t=""!=n.canPlayType('audio/ogg; codecs="vorbis"')):(e=!1,t=!1),loader.soundFileExtn=t?".ogg":e?".mp3":undefined},loadImage:function(e){this.totalCount++,this.loaded=!1,$("#loadingscreen").show();var t=new Image;return t.src=e,t.onload=loader.itemLoaded,t},soundFileExtn:".ogg",loadSound:function(e){this.totalCount++,this.loaded=!1,$("#loadingscreen").show();var t=new Audio;return t.src=e+loader.soundFileExtn,t.addEventListener("canplaythrough",loader.itemLoaded,!1),t},itemLoaded:function(){loader.loadedCount++,$("#loadingmessage").html("Loaded "+loader.loadedCount+" of "+loader.totalCount),loader.loadedCount===loader.totalCount&&(loader.loaded=!0,$("#loadingscreen").hide(),loader.onload&&(loader.onload(),loader.onload=undefined))}},aircraft={list:{chopper:{name:"chopper",cost:900,pixelWidth:40,pixelHeight:40,pixelOffsetX:20,pixelOffsetY:20,weaponType:"heatseeker",radius:18,sight:6,canAttack:!0,canAttackLand:!0,canAttackAir:!0,hitPoints:50,speed:25,turnSpeed:4,pixelShadowHeight:40,spriteImages:[{name:"fly",count:4,directions:8}]},wraith:{name:"wraith",cost:600,pixelWidth:30,pixelHeight:30,canAttack:!0,canAttackLand:!1,canAttackAir:!0,weaponType:"fireball",pixelOffsetX:15,pixelOffsetY:15,radius:15,sight:8,speed:40,turnSpeed:4,hitPoints:50,pixelShadowHeight:40,spriteImages:[{name:"fly",count:1,directions:8}]}},defaults:{type:"aircraft",animationIndex:0,direction:0,directions:8,action:"fly",selected:!1,selectable:!0,orders:{type:"float"},animate:function(){if(this.life>this.hitPoints*.4)this.lifeCode="healthy";else{if(this.life<=0){this.lifeCode="dead",game.remove(this);return}this.lifeCode="damaged"}switch(this.action){case"fly":var e=wrapDirection(Math.round(this.direction),this.directions);this.imageList=this.spriteArray["fly-"+e],this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0);break;case"teleport":var e=wrapDirection(Math.round(this.direction),this.directions);this.imageList=this.spriteArray["fly-"+e],this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0),this.brightness||(this.brightness=1),this.brightness-=.05,this.brightness<=0&&(this.brightness=undefined,this.action="fly")}},drawLifeBar:function(){var e=this.drawingX,t=this.drawingY-2*game.lifeBarHeight;game.foregroundContext.fillStyle=this.lifeCode=="healthy"?game.healthBarHealthyFillColor:game.healthBarDamagedFillColor,game.foregroundContext.fillRect(e,t,this.pixelWidth*this.life/this.hitPoints,game.lifeBarHeight),game.foregroundContext.strokeStyle=game.healthBarBorderColor,game.foregroundContext.lineWidth=1,game.foregroundContext.strokeRect(e,t,this.pixelWidth,game.lifeBarHeight)},drawSelection:function(){var e=this.drawingX+this.pixelOffsetX,t=this.drawingY+this.pixelOffsetY;game.foregroundContext.strokeStyle=game.selectionBorderColor,game.foregroundContext.lineWidth=2,game.foregroundContext.beginPath(),game.foregroundContext.arc(e,t,this.radius,0,Math.PI*2,!1),game.foregroundContext.stroke(),game.foregroundContext.fillStyle=game.selectionFillColor,game.foregroundContext.fill(),game.foregroundContext.beginPath(),game.foregroundContext.arc(e,t+this.pixelShadowHeight,4,0,Math.PI*2,!1),game.foregroundContext.stroke(),game.foregroundContext.beginPath(),game.foregroundContext.moveTo(e,t),game.foregroundContext.lineTo(e,t+this.pixelShadowHeight),game.foregroundContext.stroke()},draw:function(){var e=this.x*game.gridSize-game.offsetX-this.pixelOffsetX+this.lastMovementX*game.drawingInterpolationFactor*game.gridSize,t=this.y*game.gridSize-game.offsetY-this.pixelOffsetY-this.pixelShadowHeight+this.lastMovementY*game.drawingInterpolationFactor*game.gridSize;this.drawingX=e,this.drawingY=t,this.selected&&(this.drawSelection(),this.drawLifeBar());var n=this.team=="blue"?0:1,r=n*this.pixelHeight,i=this.pixelHeight*2;game.foregroundContext.drawImage(this.spriteSheet,this.imageOffset*this.pixelWidth,r,this.pixelWidth,this.pixelHeight,e,t,this.pixelWidth,this.pixelHeight),game.foregroundContext.drawImage(this.spriteSheet,this.imageOffset*this.pixelWidth,i,this.pixelWidth,this.pixelHeight,e,t+this.pixelShadowHeight,this.pixelWidth,this.pixelHeight),this.brightness&&(game.foregroundContext.beginPath(),game.foregroundContext.arc(e+this.pixelOffsetX,t+this.pixelOffsetY,this.radius,0,Math.PI*2,!1),game.foregroundContext.fillStyle="rgba(255,255,255,"+this.brightness+")",game.foregroundContext.fill())},isValidTarget:isValidTarget,findTargetsInSight:findTargetsInSight,processOrders:function(){this.lastMovementX=0,this.lastMovementY=0,this.reloadTimeLeft&&this.reloadTimeLeft--;switch(this.orders.type){case"float":var e=this.findTargetsInSight();e.length>0&&(this.orders={type:"attack",to:e[0]});break;case"sentry":var e=this.findTargetsInSight(2);e.length>0&&(this.orders={type:"attack",to:e[0],nextOrder:this.orders});break;case"hunt":var e=this.findTargetsInSight(100);e.length>0&&(this.orders={type:"attack",to:e[0],nextOrder:this.orders});break;case"move":var t=Math.pow(this.orders.to.x-this.x,2)+Math.pow(this.orders.to.y-this.y,2);t<Math.pow(this.radius/game.gridSize,2)?this.orders={type:"float"}:this.moveTo(this.orders.to);break;case"attack":if(this.orders.to.lifeCode=="dead"||!this.isValidTarget(this.orders.to)){this.orders.nextOrder?this.orders=this.orders.nextOrder:this.orders={type:"float"};return}if(Math.pow(this.orders.to.x-this.x,2)+Math.pow(this.orders.to.y-this.y,2)<Math.pow(this.sight,2)){var n=findFiringAngle(this.orders.to,this,this.directions),r=angleDiff(this.direction,n,this.directions),i=this.turnSpeed*game.turnSpeedAdjustmentFactor;if(Math.abs(r)>i){this.direction=wrapDirection(this.direction+i*Math.abs(r)/r,this.directions);return}this.direction=n;if(!this.reloadTimeLeft){this.reloadTimeLeft=bullets.list[this.weaponType].reloadTime;var s=-(Math.round(this.direction)/this.directions)*2*Math.PI,o=this.x-this.radius*Math.sin(s)/game.gridSize,u=this.y-this.radius*Math.cos(s)/game.gridSize-this.pixelShadowHeight/game.gridSize,a=game.add({name:this.weaponType,type:"bullets",x:o,y:u,direction:n,target:this.orders.to})}}else var f=this.moveTo(this.orders.to);break;case"patrol":var e=this.findTargetsInSight(1);if(e.length>0){this.orders={type:"attack",to:e[0],nextOrder:this.orders};return}if(Math.pow(this.orders.to.x-this.x,2)+Math.pow(this.orders.to.y-this.y,2)<Math.pow(this.radius/game.gridSize,2)){var l=this.orders.to;this.orders.to=this.orders.from,this.orders.from=l}else this.moveTo(this.orders.to);break;case"guard":if(this.orders.to.lifeCode=="dead"){this.orders.nextOrder?this.orders=this.orders.nextOrder:this.orders={type:"float"};return}if(Math.pow(this.orders.to.x-this.x,2)+Math.pow(this.orders.to.y-this.y,2)<Math.pow(this.sight-2,2)){var e=this.findTargetsInSight(1);if(e.length>0){this.orders={type:"attack",to:e[0],nextOrder:this.orders};return}}else this.moveTo(this.orders.to)}},moveTo:function(e){var t=findAngle(e,this,this.directions),n=angleDiff(this.direction,t,this.directions),r=this.turnSpeed*game.turnSpeedAdjustmentFactor;if(Math.abs(n)>r)this.direction=wrapDirection(this.direction+r*Math.abs(n)/n,this.directions);else{var i=this.speed*game.speedAdjustmentFactor,s=-(Math.round(this.direction)/this.directions)*2*Math.PI;this.lastMovementX=-(i*Math.sin(s)),this.lastMovementY=-(i*Math.cos(s)),this.x=this.x+this.lastMovementX,this.y=this.y+this.lastMovementY}}},load:loadItem,add:addItem};$(window).load(function(){game.init()});var game={init:function(){loader.init(),mouse.init(),sidebar.init(),sounds.init(),$(".gamelayer").hide(),$("#gamestartscreen").show(),game.backgroundCanvas=document.getElementById("gamebackgroundcanvas"),game.backgroundContext=game.backgroundCanvas.getContext("2d"),game.foregroundCanvas=document.getElementById("gameforegroundcanvas"),game.foregroundContext=game.foregroundCanvas.getContext("2d"),game.canvasWidth=game.backgroundCanvas.width,game.canvasHeight=game.backgroundCanvas.height},start:function(){$(".gamelayer").hide(),$("#gameinterfacescreen").show(),game.running=!0,game.refreshBackground=!0,game.drawingLoop(),$("#gamemessages").html("");for(var e=game.currentLevel.triggers.length-1;e>=0;e--)game.initTrigger(game.currentLevel.triggers[e])},gridSize:20,refreshBackground:!0,animationTimeout:100,offsetX:0,offsetY:0,panningThreshold:60,panningSpeed:10,handlePanning:function(){if(!mouse.insideCanvas)return;mouse.x<=game.panningThreshold?game.offsetX>=game.panningSpeed&&(game.refreshBackground=!0,game.offsetX-=game.panningSpeed):mouse.x>=game.canvasWidth-game.panningThreshold&&game.offsetX+game.canvasWidth+game.panningSpeed<=game.currentMapImage.width&&(game.refreshBackground=!0,game.offsetX+=game.panningSpeed),mouse.y<=game.panningThreshold?game.offsetY>=game.panningSpeed&&(game.refreshBackground=!0,game.offsetY-=game.panningSpeed):mouse.y>=game.canvasHeight-game.panningThreshold&&game.offsetY+game.canvasHeight+game.panningSpeed<=game.currentMapImage.height&&(game.refreshBackground=!0,game.offsetY+=game.panningSpeed),game.refreshBackground&&mouse.calculateGameCoordinates()},animationLoop:function(){sidebar.animate();for(var e=game.items.length-1;e>=0;e--)game.items[e].processOrders&&game.items[e].processOrders();for(var e=game.items.length-1;e>=0;e--)game.items[e].animate();game.sortedItems=$.extend([],game.items),game.sortedItems.sort(function(e,t){return t.y-e.y+(t.y==e.y?e.x-t.x:0)}),fog.animate(),game.lastAnimationTime=(new Date).getTime()},drawingLoop:function(){game.handlePanning(),game.lastDrawTime=(new Date).getTime(),game.lastAnimationTime?(game.drawingInterpolationFactor=(game.lastDrawTime-game.lastAnimationTime)/game.animationTimeout-1,game.drawingInterpolationFactor>0&&(game.drawingInterpolationFactor=0)):game.drawingInterpolationFactor=-1,game.refreshBackground&&(game.backgroundContext.drawImage(game.currentMapImage,game.offsetX,game.offsetY,game.canvasWidth,game.canvasHeight,0,0,game.canvasWidth,game.canvasHeight),game.refreshBackground=!1),game.foregroundContext.clearRect(0,0,game.canvasWidth,game.canvasHeight);for(var e=game.sortedItems.length-1;e>=0;e--)game.sortedItems[e].type!="bullets"&&game.sortedItems[e].draw();for(var e=game.bullets.length-1;e>=0;e--)game.bullets[e].draw();fog.draw(),mouse.draw(),game.running&&requestAnimationFrame(game.drawingLoop)},resetArrays:function(){game.counter=1,game.items=[],game.sortedItems=[],game.buildings=[],game.vehicles=[],game.aircraft=[],game.terrain=[],game.triggeredEvents=[],game.selectedItems=[],game.sortedItems=[],game.bullets=[]},add:function(e){e.uid||(e.uid=game.counter++);var t=window[e.type].add(e);game.items.push(t),game[t.type].push(t);if(t.type=="buildings"||t.type=="terrain")game.currentMapPassableGrid=undefined;return t.type=="bullets"&&sounds.play(t.name),t},remove:function(e){e.selected=!1;for(var t=game.selectedItems.length-1;t>=0;t--)if(game.selectedItems[t].uid==e.uid){game.selectedItems.splice(t,1);break}for(var t=game.items.length-1;t>=0;t--)if(game.items[t].uid==e.uid){game.items.splice(t,1);break}for(var t=game[e.type].length-1;t>=0;t--)if(game[e.type][t].uid==e.uid){game[e.type].splice(t,1);break}if(e.type=="buildings"||e.type=="terrain")game.currentMapPassableGrid=undefined},selectionBorderColor:"rgba(255,255,0,0.5)",selectionFillColor:"rgba(255,215,0,0.2)",healthBarBorderColor:"rgba(0,0,0,0.8)",healthBarHealthyFillColor:"rgba(0,255,0,0.5)",healthBarDamagedFillColor:"rgba(255,0,0,0.5)",lifeBarHeight:5,clearSelection:function(){while(game.selectedItems.length>0)game.selectedItems.pop().selected=!1},selectItem:function(e,t){if(t&&e.selected){e.selected=!1;for(var n=game.selectedItems.length-1;n>=0;n--)if(game.selectedItems[n].uid==e.uid){game.selectedItems.splice(n,1);break}return}e.selectable&&!e.selected&&(e.selected=!0,game.selectedItems.push(e))},sendCommand:function(e,t){game.type=="singleplayer"?singleplayer.sendCommand(e,t):multiplayer.sendCommand(e,t)},getItemByUid:function(e){for(var t=game.items.length-1;t>=0;t--)if(game.items[t].uid==e)return game.items[t]},processCommand:function(e,t){var n;if(t.toUid){n=game.getItemByUid(t.toUid);if(!n||n.lifeCode=="dead")return}for(var r in e){var i=e[r],s=game.getItemByUid(i);s&&(s.orders=$.extend([],t),n&&(s.orders.to=n))}},speedAdjustmentFactor:1/64,turnSpeedAdjustmentFactor:1/8,rebuildPassableGrid:function(){game.currentMapPassableGrid=$.extend(!0,[],game.currentMapTerrainGrid);for(var e=game.items.length-1;e>=0;e--){var t=game.items[e];if(t.type=="buildings"||t.type=="terrain")for(var n=t.passableGrid.length-1;n>=0;n--)for(var r=t.passableGrid[n].length-1;r>=0;r--)t.passableGrid[n][r]&&(game.currentMapPassableGrid[t.y+n][t.x+r]=1)}},rebuildBuildableGrid:function(){game.currentMapBuildableGrid=$.extend(!0,[],game.currentMapTerrainGrid);for(var e=game.items.length-1;e>=0;e--){var t=game.items[e];if(t.type=="buildings"||t.type=="terrain")for(var n=t.buildableGrid.length-1;n>=0;n--)for(var r=t.buildableGrid[n].length-1;r>=0;r--)t.buildableGrid[n][r]&&(game.currentMapBuildableGrid[t.y+n][t.x+r]=1);else if(t.type=="vehicles"){var i=t.radius/game.gridSize,s=Math.max(Math.floor(t.x-i),0),o=Math.min(Math.floor(t.x+i),game.currentLevel.mapGridWidth-1),u=Math.max(Math.floor(t.y-i),0),a=Math.min(Math.floor(t.y+i),game.currentLevel.mapGridHeight-1);for(var r=s;r<=o;r++)for(var n=u;n<=a;n++)game.currentMapBuildableGrid[n][r]=1}}},characters:{system:{name:"System",image:"images/characters/system.png"},op:{name:"Operator",image:"images/characters/girl1.png"},pilot:{name:"Pilot",image:"images/characters/girl2.png"},driver:{name:"Driver",image:"images/characters/man1.png"}},showMessage:function(e,t){sounds.play("message-received");var n=game.characters[e];n&&(e=n.name,n.image&&($("#callerpicture").html('<img src="'+n.image+'"/>'),setTimeout(function(){$("#callerpicture").html("")},6e3)));var r=$("#gamemessages").html(),i=r+"<span>"+e+": </span>"+t+"<br>";$("#gamemessages").html(i),$("#gamemessages").animate({scrollTop:$("#gamemessages").prop("scrollHeight")})},messageBoxOkCallback:undefined,messageBoxCancelCallback:undefined,showMessageBox:function(e,t,n){$("#messageboxtext").html(e),t?game.messageBoxOkCallback=t:game.messageBoxOkCallback=undefined,n?(game.messageBoxCancelCallback=n,$("#messageboxcancel").show()):(game.messageBoxCancelCallback=undefined,$("#messageboxcancel").hide()),$("#messageboxscreen").show()},messageBoxOK:function(){$("#messageboxscreen").hide(),game.messageBoxOkCallback&&game.messageBoxOkCallback()},messageBoxCancel:function(){$("#messageboxscreen").hide(),game.messageBoxCancelCallback&&game.messageBoxCancelCallback()},initTrigger:function(e){e.type=="timed"?e.timeout=setTimeout(function(){game.runTrigger(e)},e.time):e.type=="conditional"&&(e.interval=setInterval(function(){game.runTrigger(e)},1e3))},runTrigger:function(e){e.type=="timed"?(e.repeat&&game.initTrigger(e),e.action(e)):e.type=="conditional"&&e.condition()&&(game.clearTrigger(e),e.action(e))},clearTrigger:function(e){e.type=="timed"?clearTimeout(e.timeout):e.type=="conditional"&&clearInterval(e.interval)},end:function(){if(game.currentLevel.triggers)for(var e=game.currentLevel.triggers.length-1;e>=0;e--)game.clearTrigger(game.currentLevel.triggers[e]);game.running=!1}},mouse={x:0,y:0,gameX:0,gameY:0,gridX:0,gridY:0,buttonPressed:!1,dragSelect:!1,insideCanvas:!1,click:function(e,t){var n=this.itemUnderMouse(),r=e.shiftKey;if(!t){if(game.deployBuilding){game.canDeployBuilding?sidebar.finishDeployingBuilding():game.showMessage("system","Warning! Cannot deploy building here.");return}n&&(r||game.clearSelection(),game.selectItem(n,r))}else{if(game.deployBuilding){sidebar.cancelDeployingBuilding();return}var i=[];if(n){if(n.type!="terrain")if(n.team!=game.team){for(var s=game.selectedItems.length-1;s>=0;s--){var o=game.selectedItems[s];o.team==game.team&&o.canAttack&&i.push(o.uid)}i.length>0&&(game.sendCommand(i,{type:"attack",toUid:n.uid}),sounds.play("acknowledge-attacking"))}else{for(var s=game.selectedItems.length-1;s>=0;s--){var o=game.selectedItems[s];o.team==game.team&&(o.type=="vehicles"||o.type=="aircraft")&&i.push(o.uid)}i.length>0&&(game.sendCommand(i,{type:"guard",toUid:n.uid}),sounds.play("acknowledge-moving"))}else if(n.name=="oilfield"){for(var s=game.selectedItems.length-1;s>=0;s--){var o=game.selectedItems[s];if(o.team==game.team&&o.type=="vehicles"&&o.name=="harvester"){i.push(o.uid);break}}i.length>0&&(game.sendCommand(i,{type:"deploy",toUid:n.uid}),sounds.play("acknowledge-moving"))}}else{for(var s=game.selectedItems.length-1;s>=0;s--){var o=game.selectedItems[s];o.team==game.team&&(o.type=="vehicles"||o.type=="aircraft")&&i.push(o.uid)}i.length>0&&(game.sendCommand(i,{type:"move",to:{x:mouse.gameX/game.gridSize,y:mouse.gameY/game.gridSize}}),sounds.play("acknowledge-moving"))}}},itemUnderMouse:function(){if(fog.isPointOverFog(mouse.gameX,mouse.gameY))return;for(var e=game.items.length-1;e>=0;e--){var t=game.items[e];if(t.type=="buildings"||t.type=="terrain"){if(t.lifeCode!="dead"&&t.x<=mouse.gameX/game.gridSize&&t.x>=(mouse.gameX-t.baseWidth)/game.gridSize&&t.y<=mouse.gameY/game.gridSize&&t.y>=(mouse.gameY-t.baseHeight)/game.gridSize)return t}else if(t.type=="aircraft"){if(t.lifeCode!="dead"&&Math.pow(t.x-mouse.gameX/game.gridSize,2)+Math.pow(t.y-(mouse.gameY+t.pixelShadowHeight)/game.gridSize,2)<Math.pow(t.radius/game.gridSize,2))return t}else if(t.lifeCode!="dead"&&Math.pow(t.x-mouse.gameX/game.gridSize,2)+Math.pow(t.y-mouse.gameY/game.gridSize,2)<Math.pow(t.radius/game.gridSize,2))return t}},draw:function(){if(this.dragSelect){var e=Math.min(this.gameX,this.dragX),t=Math.min(this.gameY,this.dragY),n=Math.abs(this.gameX-this.dragX),r=Math.abs(this.gameY-this.dragY);game.foregroundContext.strokeStyle="white",game.foregroundContext.strokeRect(e-game.offsetX,t-game.offsetY,n,r)}if(game.deployBuilding&&game.placementGrid){var i=buildings.list[game.deployBuilding],e=this.gridX*game.gridSize-game.offsetX,t=this.gridY*game.gridSize-game.offsetY;for(var s=game.placementGrid.length-1;s>=0;s--)for(var o=game.placementGrid[s].length-1;o>=0;o--)game.placementGrid[s][o]?game.foregroundContext.fillStyle="rgba(0,0,255,0.3)":game.foregroundContext.fillStyle="rgba(255,0,0,0.3)",game.foregroundContext.fillRect(e+o*game.gridSize,t+s*game.gridSize,game.gridSize,game.gridSize)}},calculateGameCoordinates:function(){mouse.gameX=mouse.x+game.offsetX,mouse.gameY=mouse.y+game.offsetY,mouse.gridX=Math.floor(mouse.gameX/game.gridSize),mouse.gridY=Math.floor(mouse.gameY/game.gridSize)},init:function(){var e=$("#gameforegroundcanvas");e.mousemove(function(t){var n=e.offset();mouse.x=t.pageX-n.left,mouse.y=t.pageY-n.top,mouse.calculateGameCoordinates();if(mouse.buttonPressed){if(Math.abs(mouse.dragX-mouse.gameX)>4||Math.abs(mouse.dragY-mouse.gameY)>4)mouse.dragSelect=!0}else mouse.dragSelect=!1}),e.click(function(e){return mouse.click(e,!1),mouse.dragSelect=!1,!1}),e.mousedown(function(e){return e.which==1&&(mouse.buttonPressed=!0,mouse.dragX=mouse.gameX,mouse.dragY=mouse.gameY,e.preventDefault()),!1}),e.bind("contextmenu",function(e){return mouse.click(e,!0),!1}),e.mouseup(function(e){var t=e.shiftKey;if(e.which==1){if(mouse.dragSelect){t||game.clearSelection();var n=Math.min(mouse.gameX,mouse.dragX)/game.gridSize,r=Math.min(mouse.gameY,mouse.dragY)/game.gridSize,i=Math.max(mouse.gameX,mouse.dragX)/game.gridSize,s=Math.max(mouse.gameY,mouse.dragY)/game.gridSize;for(var o=game.items.length-1;o>=0;o--){var u=game.items[o];u.type!="buildings"&&u.selectable&&u.team==game.team&&n<=u.x&&i>=u.x&&(u.type=="vehicles"&&r<=u.y&&s>=u.y||u.type=="aircraft"&&r<=u.y-u.pixelShadowHeight/game.gridSize&&s>=u.y-u.pixelShadowHeight/game.gridSize)&&game.selectItem(u,t)}}mouse.buttonPressed=!1,mouse.dragSelect=!1}return!1}),e.mouseleave(function(e){mouse.insideCanvas=!1}),e.mouseenter(function(e){mouse.buttonPressed=!1,mouse.insideCanvas=!0})}},singleplayer={start:function(){$(".gamelayer").hide(),singleplayer.currentLevel=0,game.type="singleplayer",game.team="blue",singleplayer.startCurrentLevel()},exit:function(){$(".gamelayer").hide(),$("#gamestartscreen").show()},currentLevel:0,startCurrentLevel:function(){var e=maps.singleplayer[singleplayer.currentLevel];$("#entermission").attr("disabled",!0),game.currentMapImage=loader.loadImage(e.mapImage),game.currentLevel=e,game.offsetX=e.startX*game.gridSize,game.offsetY=e.startY*game.gridSize,game.resetArrays();for(var t in e.requirements){var n=e.requirements[t];for(var r=0;r<n.length;r++){var i=n[r];window[t]?window[t].load(i):console.log("Could not load type :",t)}}for(var r=e.items.length-1;r>=0;r--){var s=e.items[r];game.add(s)}game.currentMapTerrainGrid=[];for(var o=0;o<e.mapGridHeight;o++){game.currentMapTerrainGrid[o]=[];for(var u=0;u<e.mapGridWidth;u++)game.currentMapTerrainGrid[o][u]=0}for(var r=e.mapObstructedTerrain.length-1;r>=0;r--){var a=e.mapObstructedTerrain[r];game.currentMapTerrainGrid[a[1]][a[0]]=1}game.currentMapPassableGrid=undefined,game.cash=$.extend([],e.cash),loader.loaded?$("#entermission").removeAttr("disabled"):loader.onload=function(){$("#entermission").removeAttr("disabled")},$("#missonbriefing").html(e.briefing.replace(/\n/g,"<br><br>")),$("#missionscreen").show()},play:function(){fog.initLevel(),game.animationLoop(),game.animationInterval=setInterval(game.animationLoop,game.animationTimeout),game.start()},sendCommand:function(e,t){game.processCommand(e,t)},endLevel:function(e){clearInterval(game.animationInterval),game.end();if(e){var t=singleplayer.currentLevel<maps.singleplayer.length-1;t?game.showMessageBox("Mission Accomplished.",function(){$(".gamelayer").hide(),singleplayer.currentLevel++,singleplayer.startCurrentLevel()}):game.showMessageBox("Mission Accomplished.<br><br>This was the last mission in the campaign.<br><br>Thank You for playing.",function(){$(".gamelayer").hide(),$("#gamestartscreen").show()})}else game.showMessageBox("Mission Failed.<br><br>Try again?",function(){$(".gamelayer").hide(),singleplayer.startCurrentLevel()},function(){$(".gamelayer").hide(),$("#gamestartscreen").show()})}},maps={singleplayer:[{name:"Rescue",briefing:"In the months since the great war, mankind has fallen into chaos. Billions are dead with cities in ruins.\nSmall groups of survivors band together to try and survive as best as they can.\nWe are trying to reach out to all the survivors in this sector before we join back with the main colony.",mapImage:"images/maps/level-one.png",startX:36,startY:0,mapGridWidth:60,mapGridHeight:40,mapObstructedTerrain:[[49,8],[50,8],[51,8],[51,9],[52,9],[53,9],[53,10],[53,11],[53,12],[53,13],[53,14],[53,15],[53,16],[52,16],[52,17],[52,18],[52,19],[51,19],[50,19],[50,18],[50,17],[49,17],[49,18],[48,18],[47,18],[47,17],[47,16],[48,16],[49,16],[49,15],[49,14],[48,14],[48,13],[48,12],[49,12],[49,11],[50,11],[50,10],[49,10],[49,9],[44,0],[45,0],[45,1],[45,2],[46,2],[47,2],[47,3],[48,3],[48,4],[48,5],[49,5],[49,6],[49,7],[50,7],[51,7],[51,6],[51,5],[51,4],[52,4],[53,4],[53,3],[54,3],[55,3],[55,2],[56,2],[56,1],[56,0],[55,0],[43,19],[44,19],[45,19],[46,19],[47,19],[48,19],[48,20],[48,21],[47,21],[46,21],[45,21],[44,21],[43,21],[43,20],[41,22],[42,22],[43,22],[44,22],[45,22],[46,22],[47,22],[48,22],[49,22],[50,22],[50,23],[50,24],[49,24],[48,24],[47,24],[47,25],[47,26],[47,27],[47,28],[47,29],[47,30],[46,30],[45,30],[44,30],[43,30],[43,29],[43,28],[43,27],[43,26],[43,25],[43,24],[42,24],[41,24],[41,23],[48,39],[49,39],[50,39],[51,39],[52,39],[53,39],[54,39],[55,39],[56,39],[57,39],[58,39],[59,39],[59,38],[59,37],[59,36],[59,35],[59,34],[59,33],[59,32],[59,31],[59,30],[59,29],[0,0],[1,0],[2,0],[1,1],[2,1],[10,3],[11,3],[12,3],[12,2],[13,2],[14,2],[14,3],[14,4],[15,4],[15,5],[15,6],[14,6],[13,6],[13,5],[12,5],[11,5],[10,5],[10,4],[3,9],[4,9],[5,9],[5,10],[6,10],[7,10],[8,10],[9,10],[9,11],[10,11],[11,11],[11,10],[12,10],[13,10],[13,11],[13,12],[12,12],[11,12],[10,12],[9,12],[8,12],[7,12],[7,13],[7,14],[6,14],[5,14],[5,13],[5,12],[5,11],[4,11],[3,11],[3,10],[33,33],[34,33],[35,33],[35,34],[35,35],[34,35],[33,35],[33,34],[27,39],[27,38],[27,37],[28,37],[28,36],[28,35],[28,34],[28,33],[28,32],[28,31],[28,30],[28,29],[29,29],[29,28],[29,27],[29,26],[29,25],[29,24],[29,23],[30,23],[31,23],[32,23],[32,22],[32,21],[31,21],[30,21],[30,22],[29,22],[28,22],[27,22],[26,22],[26,21],[25,21],[24,21],[24,22],[24,23],[25,23],[26,23],[26,24],[25,24],[25,25],[24,25],[24,26],[24,27],[25,27],[25,28],[25,29],[24,29],[23,29],[23,30],[23,31],[24,31],[25,31],[25,32],[25,33],[24,33],[23,33],[23,34],[23,35],[24,35],[24,36],[24,37],[23,37],[22,37],[22,38],[22,39],[23,39],[24,39],[25,39],[26,0],[26,1],[25,1],[25,2],[25,3],[26,3],[27,3],[27,2],[28,2],[29,2],[29,3],[30,3],[31,3],[31,2],[31,1],[32,1],[32,0],[33,0],[32,8],[33,8],[34,8],[34,9],[34,10],[33,10],[32,10],[32,9],[8,29],[9,29],[9,30],[17,32],[18,32],[19,32],[19,33],[18,33],[17,33],[18,34],[19,34],[3,27],[4,27],[4,26],[3,26],[2,26],[3,25],[4,25],[9,20],[10,20],[11,20],[11,21],[10,21],[10,19],[19,7],[15,7],[29,12],[30,13],[20,14],[21,14],[34,13],[35,13],[36,13],[36,14],[35,14],[34,14],[35,15],[36,15],[16,18],[17,18],[18,18],[16,19],[17,19],[18,19],[17,20],[18,20],[11,19],[58,0],[59,0],[58,1],[59,1],[59,2],[58,3],[59,3],[58,4],[59,4],[59,5],[58,6],[59,6],[58,7],[59,7],[59,8],[58,9],[59,9],[58,10],[59,10],[59,11],[52,6],[53,6],[54,6],[52,7],[53,7],[54,7],[53,8],[54,8],[44,17],[46,32],[55,32],[54,28],[26,34],[34,34],[4,10],[6,11],[6,12],[6,13],[7,11],[8,11],[12,11],[27,0],[27,1],[26,2],[28,1],[28,0],[29,0],[29,1],[30,2],[30,1],[30,0],[31,0],[33,9],[46,0],[47,0],[48,0],[49,0],[50,0],[51,0],[52,0],[53,0],[54,0],[55,1],[54,1],[53,1],[52,1],[51,1],[50,1],[49,1],[48,1],[47,1],[46,1],[48,2],[49,2],[50,2],[51,2],[52,2],[53,2],[54,2],[52,3],[51,3],[50,3],[49,3],[49,4],[50,4],[50,5],[50,6],[50,9],[51,10],[52,10],[51,11],[52,11],[50,12],[51,12],[52,12],[49,13],[50,13],[51,13],[52,13],[50,14],[51,14],[52,14],[50,15],[51,15],[52,15],[50,16],[51,16],[51,17],[48,17],[51,18],[44,20],[45,20],[46,20],[47,20],[42,23],[43,23],[44,23],[45,23],[46,23],[47,23],[48,23],[49,23],[44,24],[45,24],[46,24],[44,25],[45,25],[46,25],[44,26],[45,26],[46,26],[44,27],[45,27],[46,27],[44,28],[45,28],[46,28],[44,29],[45,29],[46,29],[11,4],[12,4],[13,4],[13,3],[14,5],[25,22],[31,22],[27,23],[28,23],[27,24],[28,24],[26,25],[27,25],[28,25],[25,26],[26,26],[27,26],[28,26],[26,27],[27,27],[28,27],[26,28],[27,28],[28,28],[26,29],[27,29],[24,30],[25,30],[26,30],[27,30],[26,31],[27,31],[26,32],[27,32],[26,33],[27,33],[24,34],[25,34],[27,34],[25,35],[26,35],[27,35],[25,36],[26,36],[27,36],[25,37],[26,37],[23,38],[24,38],[25,38],[26,38],[26,39],[2,25],[9,19],[36,31]],requirements:{buildings:["base"],vehicles:["transport","scout-tank","heavy-tank"],aircraft:[],terrain:[]},cash:{blue:0,green:0},items:[{type:"buildings",name:"base",x:55,y:6,team:"blue",life:100},{type:"vehicles",name:"heavy-tank",x:57,y:12,direction:4,team:"blue",uid:-1},{type:"vehicles",name:"transport",x:-3,y:2,direction:2,team:"blue",uid:-3,selectable:!1},{type:"vehicles",name:"transport",x:-3,y:4,direction:2,team:"blue",uid:-4,selectable:!1},{type:"vehicles",name:"scout-tank",x:40,y:20,direction:4,team:"green",uid:-2,life:20,orders:{type:"patrol",from:{x:34,y:20},to:{x:42,y:25}}},{type:"vehicles",name:"scout-tank",x:14,y:0,direction:4,team:"green",uid:-5,life:20,orders:{type:"patrol",from:{x:14,y:0},to:{x:14,y:14}}}],triggers:[{type:"timed",time:3e3,action:function(){game.showMessage("op","Commander!! We haven't heard from the last convoy in over two hours. They should have arrived by now.")}},{type:"timed",time:1e4,action:function(){game.showMessage("op","They were last seen in the North West Sector. Could you investigate?")}},{type:"conditional",condition:function(){return isItemDead(-1)||isItemDead(-3)||isItemDead(-4)},action:function(){singleplayer.endLevel(!1)}},{type:"conditional",condition:function(){return isItemDead(-2)},action:function(){game.showMessage("op","The rebels have been getting very aggressive lately. I hope the convoy is safe. Find them and escort them back to the base.")}},{type:"conditional",condition:function(){return isItemDead(-2)},action:function(){game.showMessage("op","The rebels have been getting very aggressive lately. I hope the convoy is safe. Find them and escort them back to the base.")}},{type:"conditional",condition:function(){var e=game.getItemByUid(-1);return e&&e.x<30&&e.y<30},action:function(){game.showMessage("driver","Can anyone hear us? Our convoy has been pinned down by rebel tanks. We need help.")}},{type:"conditional",condition:function(){var e=game.getItemByUid(-1);return e&&e.x<10&&e.y<10},action:function(){var e=game.getItemByUid(-1);game.showMessage("driver","Thank you. We thought we would never get out of here alive."),game.sendCommand([-3,-4],{type:"guard",to:e})}},{type:"conditional",condition:function(){var e=game.getItemByUid(-3),t=game.getItemByUid(-4);return e&&t&&e.x>52&&t.x>52&&t.y<18&&e.y<18},action:function(){singleplayer.endLevel(!0)}}]},{name:"Assault",briefing:"Thanks to the supplies from the convoy, we now have the base up and running.\n The rebels nearby are proving to be a problem. We need to take them out. \n First set up the base defences. Then find and destroy all rebels in the area.\n The colony will be sending us reinforcements to help us out.",mapImage:"images/maps/level-one.png",startX:36,startY:0,mapGridWidth:60,mapGridHeight:40,mapObstructedTerrain:[[49,8],[50,8],[51,8],[51,9],[52,9],[53,9],[53,10],[53,11],[53,12],[53,13],[53,14],[53,15],[53,16],[52,16],[52,17],[52,18],[52,19],[51,19],[50,19],[50,18],[50,17],[49,17],[49,18],[48,18],[47,18],[47,17],[47,16],[48,16],[49,16],[49,15],[49,14],[48,14],[48,13],[48,12],[49,12],[49,11],[50,11],[50,10],[49,10],[49,9],[44,0],[45,0],[45,1],[45,2],[46,2],[47,2],[47,3],[48,3],[48,4],[48,5],[49,5],[49,6],[49,7],[50,7],[51,7],[51,6],[51,5],[51,4],[52,4],[53,4],[53,3],[54,3],[55,3],[55,2],[56,2],[56,1],[56,0],[55,0],[43,19],[44,19],[45,19],[46,19],[47,19],[48,19],[48,20],[48,21],[47,21],[46,21],[45,21],[44,21],[43,21],[43,20],[41,22],[42,22],[43,22
],[44,22],[45,22],[46,22],[47,22],[48,22],[49,22],[50,22],[50,23],[50,24],[49,24],[48,24],[47,24],[47,25],[47,26],[47,27],[47,28],[47,29],[47,30],[46,30],[45,30],[44,30],[43,30],[43,29],[43,28],[43,27],[43,26],[43,25],[43,24],[42,24],[41,24],[41,23],[48,39],[49,39],[50,39],[51,39],[52,39],[53,39],[54,39],[55,39],[56,39],[57,39],[58,39],[59,39],[59,38],[59,37],[59,36],[59,35],[59,34],[59,33],[59,32],[59,31],[59,30],[59,29],[0,0],[1,0],[2,0],[1,1],[2,1],[10,3],[11,3],[12,3],[12,2],[13,2],[14,2],[14,3],[14,4],[15,4],[15,5],[15,6],[14,6],[13,6],[13,5],[12,5],[11,5],[10,5],[10,4],[3,9],[4,9],[5,9],[5,10],[6,10],[7,10],[8,10],[9,10],[9,11],[10,11],[11,11],[11,10],[12,10],[13,10],[13,11],[13,12],[12,12],[11,12],[10,12],[9,12],[8,12],[7,12],[7,13],[7,14],[6,14],[5,14],[5,13],[5,12],[5,11],[4,11],[3,11],[3,10],[33,33],[34,33],[35,33],[35,34],[35,35],[34,35],[33,35],[33,34],[27,39],[27,38],[27,37],[28,37],[28,36],[28,35],[28,34],[28,33],[28,32],[28,31],[28,30],[28,29],[29,29],[29,28],[29,27],[29,26],[29,25],[29,24],[29,23],[30,23],[31,23],[32,23],[32,22],[32,21],[31,21],[30,21],[30,22],[29,22],[28,22],[27,22],[26,22],[26,21],[25,21],[24,21],[24,22],[24,23],[25,23],[26,23],[26,24],[25,24],[25,25],[24,25],[24,26],[24,27],[25,27],[25,28],[25,29],[24,29],[23,29],[23,30],[23,31],[24,31],[25,31],[25,32],[25,33],[24,33],[23,33],[23,34],[23,35],[24,35],[24,36],[24,37],[23,37],[22,37],[22,38],[22,39],[23,39],[24,39],[25,39],[26,0],[26,1],[25,1],[25,2],[25,3],[26,3],[27,3],[27,2],[28,2],[29,2],[29,3],[30,3],[31,3],[31,2],[31,1],[32,1],[32,0],[33,0],[32,8],[33,8],[34,8],[34,9],[34,10],[33,10],[32,10],[32,9],[8,29],[9,29],[9,30],[17,32],[18,32],[19,32],[19,33],[18,33],[17,33],[18,34],[19,34],[3,27],[4,27],[4,26],[3,26],[2,26],[3,25],[4,25],[9,20],[10,20],[11,20],[11,21],[10,21],[10,19],[19,7],[15,7],[29,12],[30,13],[20,14],[21,14],[34,13],[35,13],[36,13],[36,14],[35,14],[34,14],[35,15],[36,15],[16,18],[17,18],[18,18],[16,19],[17,19],[18,19],[17,20],[18,20],[11,19],[58,0],[59,0],[58,1],[59,1],[59,2],[58,3],[59,3],[58,4],[59,4],[59,5],[58,6],[59,6],[58,7],[59,7],[59,8],[58,9],[59,9],[58,10],[59,10],[59,11],[52,6],[53,6],[54,6],[52,7],[53,7],[54,7],[53,8],[54,8],[44,17],[46,32],[55,32],[54,28],[26,34],[34,34],[4,10],[6,11],[6,12],[6,13],[7,11],[8,11],[12,11],[27,0],[27,1],[26,2],[28,1],[28,0],[29,0],[29,1],[30,2],[30,1],[30,0],[31,0],[33,9],[46,0],[47,0],[48,0],[49,0],[50,0],[51,0],[52,0],[53,0],[54,0],[55,1],[54,1],[53,1],[52,1],[51,1],[50,1],[49,1],[48,1],[47,1],[46,1],[48,2],[49,2],[50,2],[51,2],[52,2],[53,2],[54,2],[52,3],[51,3],[50,3],[49,3],[49,4],[50,4],[50,5],[50,6],[50,9],[51,10],[52,10],[51,11],[52,11],[50,12],[51,12],[52,12],[49,13],[50,13],[51,13],[52,13],[50,14],[51,14],[52,14],[50,15],[51,15],[52,15],[50,16],[51,16],[51,17],[48,17],[51,18],[44,20],[45,20],[46,20],[47,20],[42,23],[43,23],[44,23],[45,23],[46,23],[47,23],[48,23],[49,23],[44,24],[45,24],[46,24],[44,25],[45,25],[46,25],[44,26],[45,26],[46,26],[44,27],[45,27],[46,27],[44,28],[45,28],[46,28],[44,29],[45,29],[46,29],[11,4],[12,4],[13,4],[13,3],[14,5],[25,22],[31,22],[27,23],[28,23],[27,24],[28,24],[26,25],[27,25],[28,25],[25,26],[26,26],[27,26],[28,26],[26,27],[27,27],[28,27],[26,28],[27,28],[28,28],[26,29],[27,29],[24,30],[25,30],[26,30],[27,30],[26,31],[27,31],[26,32],[27,32],[26,33],[27,33],[24,34],[25,34],[27,34],[25,35],[26,35],[27,35],[25,36],[26,36],[27,36],[25,37],[26,37],[23,38],[24,38],[25,38],[26,38],[26,39],[2,25],[9,19],[36,31]],requirements:{buildings:["base","ground-turret","starport","harvester"],vehicles:["transport","scout-tank","heavy-tank"],aircraft:["chopper"],terrain:[]},cash:{blue:0,green:0},items:[{type:"buildings",name:"base",x:55,y:6,team:"blue",uid:-1},{type:"buildings",name:"ground-turret",x:53,y:17,team:"blue"},{type:"vehicles",name:"heavy-tank",x:55,y:16,direction:4,team:"blue",uid:-2,orders:{type:"sentry"}},{type:"vehicles",name:"scout-tank",x:55,y:36,direction:4,team:"green",orders:{type:"hunt"}},{type:"vehicles",name:"scout-tank",x:53,y:36,direction:4,team:"green",orders:{type:"hunt"}},{type:"vehicles",name:"scout-tank",x:5,y:5,direction:4,team:"green",orders:{type:"patrol",from:{x:5,y:5},to:{x:20,y:20}}},{type:"vehicles",name:"scout-tank",x:5,y:15,direction:4,team:"green",orders:{type:"patrol",from:{x:5,y:15},to:{x:20,y:30}}},{type:"vehicles",name:"scout-tank",x:25,y:5,direction:4,team:"green",orders:{type:"patrol",from:{x:25,y:5},to:{x:25,y:20}}},{type:"vehicles",name:"scout-tank",x:35,y:5,direction:4,team:"green",orders:{type:"patrol",from:{x:35,y:5},to:{x:35,y:30}}},{type:"buildings",name:"base",x:5,y:36,team:"green",uid:-11},{type:"buildings",name:"starport",x:1,y:30,team:"green",uid:-12},{type:"buildings",name:"starport",x:4,y:32,team:"green",uid:-13},{type:"buildings",name:"harvester",x:1,y:38,team:"green",action:"deploy"},{type:"buildings",name:"ground-turret",x:5,y:28,team:"green"},{type:"buildings",name:"ground-turret",x:7,y:33,team:"green"},{type:"buildings",name:"ground-turret",x:8,y:37,team:"green"}],triggers:[{type:"timed",time:8e3,action:function(){game.showMessage("op","Commander!! Reinforcements have arrived from the colony.");var e=game.getItemByUid(-2);game.add({type:"vehicles",name:"scout-tank",x:61,y:22,team:"blue",orders:{type:"guard",to:e}}),game.add({type:"vehicles",name:"scout-tank",x:61,y:21,team:"blue",orders:{type:"guard",to:e}})}},{type:"timed",time:25e3,action:function(){game.cash.blue=1500,game.showMessage("op","Commander!! We have enough resources for another ground turret. Set up the turret to keep the base safe from any more attacks.")}},{type:"timed",time:6e4,repeat:!0,action:function(){game.cash.green>1e3&&game.sendCommand([-12,-13],{type:"construct-unit",details:{type:"vehicles",name:"scout-tank",orders:{type:"hunt"}}})}},{type:"timed",time:18e4,repeat:!0,action:function(){game.showMessage("op","Commander!! More Reinforcments have arrived."),game.add({type:"vehicles",name:"scout-tank",x:61,y:22,team:"blue",orders:{type:"move",to:{x:55,y:21}}}),game.add({type:"vehicles",name:"heavy-tank",x:61,y:23,team:"blue",orders:{type:"move",to:{x:56,y:23}}})}},{type:"timed",time:6e5,action:function(){game.showMessage("pilot","Close Air Support en route. Will try to do what I can."),game.add({type:"aircraft",name:"chopper",x:61,y:22,selectable:!1,team:"blue",orders:{type:"hunt"}})}},{type:"conditional",condition:function(){return isItemDead(-1)},action:function(){singleplayer.endLevel(!1)}},{type:"conditional",condition:function(){var e=game.getItemByUid(-11);return!e||e.life<=e.hitPoints/2},action:function(){singleplayer.endLevel(!0)}}]},{name:"Under Siege",briefing:"Thanks to the attack led by you, we now have control of the rebel base. We can expect the rebels to try to retaliate.\n The colony is sending in aircraft to help us evacuate back to the main camp. All we need to do is hang tight until the choppers get here. \n Luckily, we have some supplies and ammunition to defend ourselves with until they get here. \n Protect the transports at all costs.",mapImage:"images/maps/level-one.png",startX:0,startY:20,mapGridWidth:60,mapGridHeight:40,mapObstructedTerrain:[[49,8],[50,8],[51,8],[51,9],[52,9],[53,9],[53,10],[53,11],[53,12],[53,13],[53,14],[53,15],[53,16],[52,16],[52,17],[52,18],[52,19],[51,19],[50,19],[50,18],[50,17],[49,17],[49,18],[48,18],[47,18],[47,17],[47,16],[48,16],[49,16],[49,15],[49,14],[48,14],[48,13],[48,12],[49,12],[49,11],[50,11],[50,10],[49,10],[49,9],[44,0],[45,0],[45,1],[45,2],[46,2],[47,2],[47,3],[48,3],[48,4],[48,5],[49,5],[49,6],[49,7],[50,7],[51,7],[51,6],[51,5],[51,4],[52,4],[53,4],[53,3],[54,3],[55,3],[55,2],[56,2],[56,1],[56,0],[55,0],[43,19],[44,19],[45,19],[46,19],[47,19],[48,19],[48,20],[48,21],[47,21],[46,21],[45,21],[44,21],[43,21],[43,20],[41,22],[42,22],[43,22],[44,22],[45,22],[46,22],[47,22],[48,22],[49,22],[50,22],[50,23],[50,24],[49,24],[48,24],[47,24],[47,25],[47,26],[47,27],[47,28],[47,29],[47,30],[46,30],[45,30],[44,30],[43,30],[43,29],[43,28],[43,27],[43,26],[43,25],[43,24],[42,24],[41,24],[41,23],[48,39],[49,39],[50,39],[51,39],[52,39],[53,39],[54,39],[55,39],[56,39],[57,39],[58,39],[59,39],[59,38],[59,37],[59,36],[59,35],[59,34],[59,33],[59,32],[59,31],[59,30],[59,29],[0,0],[1,0],[2,0],[1,1],[2,1],[10,3],[11,3],[12,3],[12,2],[13,2],[14,2],[14,3],[14,4],[15,4],[15,5],[15,6],[14,6],[13,6],[13,5],[12,5],[11,5],[10,5],[10,4],[3,9],[4,9],[5,9],[5,10],[6,10],[7,10],[8,10],[9,10],[9,11],[10,11],[11,11],[11,10],[12,10],[13,10],[13,11],[13,12],[12,12],[11,12],[10,12],[9,12],[8,12],[7,12],[7,13],[7,14],[6,14],[5,14],[5,13],[5,12],[5,11],[4,11],[3,11],[3,10],[33,33],[34,33],[35,33],[35,34],[35,35],[34,35],[33,35],[33,34],[27,39],[27,38],[27,37],[28,37],[28,36],[28,35],[28,34],[28,33],[28,32],[28,31],[28,30],[28,29],[29,29],[29,28],[29,27],[29,26],[29,25],[29,24],[29,23],[30,23],[31,23],[32,23],[32,22],[32,21],[31,21],[30,21],[30,22],[29,22],[28,22],[27,22],[26,22],[26,21],[25,21],[24,21],[24,22],[24,23],[25,23],[26,23],[26,24],[25,24],[25,25],[24,25],[24,26],[24,27],[25,27],[25,28],[25,29],[24,29],[23,29],[23,30],[23,31],[24,31],[25,31],[25,32],[25,33],[24,33],[23,33],[23,34],[23,35],[24,35],[24,36],[24,37],[23,37],[22,37],[22,38],[22,39],[23,39],[24,39],[25,39],[26,0],[26,1],[25,1],[25,2],[25,3],[26,3],[27,3],[27,2],[28,2],[29,2],[29,3],[30,3],[31,3],[31,2],[31,1],[32,1],[32,0],[33,0],[32,8],[33,8],[34,8],[34,9],[34,10],[33,10],[32,10],[32,9],[8,29],[9,29],[9,30],[17,32],[18,32],[19,32],[19,33],[18,33],[17,33],[18,34],[19,34],[3,27],[4,27],[4,26],[3,26],[2,26],[3,25],[4,25],[9,20],[10,20],[11,20],[11,21],[10,21],[10,19],[19,7],[15,7],[29,12],[30,13],[20,14],[21,14],[34,13],[35,13],[36,13],[36,14],[35,14],[34,14],[35,15],[36,15],[16,18],[17,18],[18,18],[16,19],[17,19],[18,19],[17,20],[18,20],[11,19],[58,0],[59,0],[58,1],[59,1],[59,2],[58,3],[59,3],[58,4],[59,4],[59,5],[58,6],[59,6],[58,7],[59,7],[59,8],[58,9],[59,9],[58,10],[59,10],[59,11],[52,6],[53,6],[54,6],[52,7],[53,7],[54,7],[53,8],[54,8],[44,17],[46,32],[55,32],[54,28],[26,34],[34,34],[4,10],[6,11],[6,12],[6,13],[7,11],[8,11],[12,11],[27,0],[27,1],[26,2],[28,1],[28,0],[29,0],[29,1],[30,2],[30,1],[30,0],[31,0],[33,9],[46,0],[47,0],[48,0],[49,0],[50,0],[51,0],[52,0],[53,0],[54,0],[55,1],[54,1],[53,1],[52,1],[51,1],[50,1],[49,1],[48,1],[47,1],[46,1],[48,2],[49,2],[50,2],[51,2],[52,2],[53,2],[54,2],[52,3],[51,3],[50,3],[49,3],[49,4],[50,4],[50,5],[50,6],[50,9],[51,10],[52,10],[51,11],[52,11],[50,12],[51,12],[52,12],[49,13],[50,13],[51,13],[52,13],[50,14],[51,14],[52,14],[50,15],[51,15],[52,15],[50,16],[51,16],[51,17],[48,17],[51,18],[44,20],[45,20],[46,20],[47,20],[42,23],[43,23],[44,23],[45,23],[46,23],[47,23],[48,23],[49,23],[44,24],[45,24],[46,24],[44,25],[45,25],[46,25],[44,26],[45,26],[46,26],[44,27],[45,27],[46,27],[44,28],[45,28],[46,28],[44,29],[45,29],[46,29],[11,4],[12,4],[13,4],[13,3],[14,5],[25,22],[31,22],[27,23],[28,23],[27,24],[28,24],[26,25],[27,25],[28,25],[25,26],[26,26],[27,26],[28,26],[26,27],[27,27],[28,27],[26,28],[27,28],[28,28],[26,29],[27,29],[24,30],[25,30],[26,30],[27,30],[26,31],[27,31],[26,32],[27,32],[26,33],[27,33],[24,34],[25,34],[27,34],[25,35],[26,35],[27,35],[25,36],[26,36],[27,36],[25,37],[26,37],[23,38],[24,38],[25,38],[26,38],[26,39],[2,25],[9,19],[36,31]],requirements:{buildings:["base","ground-turret","starport","harvester"],vehicles:["transport","scout-tank","heavy-tank"],aircraft:["chopper","wraith"],terrain:[]},cash:{blue:0,green:0},items:[{type:"buildings",name:"base",x:5,y:36,team:"blue",uid:-11},{type:"buildings",name:"starport",x:1,y:28,team:"blue",uid:-12},{type:"buildings",name:"starport",x:4,y:32,team:"blue",uid:-13},{type:"buildings",name:"harvester",x:1,y:38,team:"blue",action:"deploy"},{type:"buildings",name:"ground-turret",x:7,y:28,team:"blue"},{type:"buildings",name:"ground-turret",x:8,y:32,team:"blue"},{type:"buildings",name:"ground-turret",x:11,y:37,team:"blue"},{type:"vehicles",name:"transport",x:2,y:33,team:"blue",direction:2,selectable:!1,uid:-1},{type:"vehicles",name:"transport",x:1,y:34,team:"blue",direction:2,selectable:!1,uid:-2},{type:"vehicles",name:"transport",x:2,y:35,team:"blue",direction:2,selectable:!1,uid:-3},{type:"vehicles",name:"transport",x:1,y:36,team:"blue",direction:2,selectable:!1,uid:-4},{type:"aircraft",name:"chopper",x:15,y:40,team:"blue",selectable:!1,uid:-5,orders:{type:"patrol",from:{x:15,y:40},to:{x:0,y:25}}},{type:"vehicles",name:"scout-tank",x:15,y:16,direction:4,team:"green",orders:{type:"hunt"}},{type:"vehicles",name:"scout-tank",x:17,y:16,direction:4,team:"green",orders:{type:"hunt"}},{type:"buildings",name:"starport",x:35,y:37,team:"green",uid:-23},{type:"buildings",name:"starport",x:33,y:37,team:"green",uid:-24},{type:"buildings",name:"harvester",x:28,y:39,team:"green",action:"deploy"},{type:"buildings",name:"harvester",x:30,y:39,team:"green",action:"deploy"},{type:"buildings",name:"starport",x:3,y:0,team:"green",uid:-21},{type:"buildings",name:"starport",x:6,y:0,team:"green",uid:-22},{type:"buildings",name:"harvester",x:0,y:2,team:"green",action:"deploy"},{type:"buildings",name:"harvester",x:0,y:4,team:"green",action:"deploy"}],triggers:[{type:"conditional",condition:function(){return isItemDead(-1)||isItemDead(-2)||isItemDead(-3)||isItemDead(-4)},action:function(){singleplayer.endLevel(!1)}},{type:"timed",time:5e3,action:function(){game.showMessage("op","Commander!! The rebels have started attacking. We need to protect the base at any cost.")}},{type:"timed",time:2e4,action:function(){game.add({type:"vehicles",name:"transport",x:57,y:3,team:"blue",direction:4,selectable:!1,uid:-6}),game.sendCommand([-5],{type:"guard",toUid:-6}),game.showMessage("driver","Commander!! The colony has sent some extra supplies. We are coming in from the North East sector through rebel territory. We could use a little protection.")}},{type:"timed",time:28e3,action:function(){game.showMessage("pilot","I'm on my way."),game.add({type:"vehicles",name:"scout-tank",x:57,y:28,team:"green",orders:{type:"hunt"}}),game.add({type:"aircraft",name:"wraith",x:55,y:33,team:"green",orders:{type:"sentry"}}),game.add({type:"aircraft",name:"wraith",x:53,y:33,team:"green",orders:{type:"sentry"}}),game.add({type:"vehicles",name:"scout-tank",x:35,y:25,life:20,direction:4,team:"green",orders:{type:"patrol",from:{x:35,y:25},to:{x:35,y:30}}})}},{type:"timed",time:48e3,action:function(){game.showMessage("driver","Thanks! Appreciate the backup. All right. Off we go."),game.sendCommand([-6],{type:"move",to:{x:0,y:39}})}},{type:"conditional",condition:function(){var e=game.getItemByUid(-5);return e.life<e.hitPoints},action:function(){game.showMessage("pilot","We are under attack! Need assistance. This doesn't look good.")}},{type:"conditional",condition:function(){var e=game.getItemByUid(-6);return e&&e.x<2&&e.y>37},action:function(){game.showMessage("driver","The rebels came out of nowhere. There was nothing we could do. She saved our lives. Hope these supplies were worth it."),game.cash.blue+=1200}},{type:"timed",time:15e4,repeat:!0,action:function(){var e=0,t=0,n=0,r=0;for(var i=game.items.length-1;i>=0;i--){var s=game.items[i];if(s.team=="green")switch(s.name){case"chopper":t++;break;case"wraith":e++;break;case"scout-tank":n++;break;case"heavy-tank":r++}}e==0?game.sendCommand([-23,-24],{type:"construct-unit",details:{type:"aircraft",name:"wraith",orders:{type:"hunt"}}}):e==1?(game.sendCommand([-23],{type:"construct-unit",details:{type:"aircraft",name:"wraith",orders:{type:"hunt"}}}),game.sendCommand([-24],{type:"construct-unit",details:{type:"aircraft",name:"chopper",orders:{type:"hunt"}}})):game.sendCommand([-23,-24],{type:"construct-unit",details:{type:"aircraft",name:"chopper",orders:{type:"hunt"}}}),r==0?game.sendCommand([-21,-22],{type:"construct-unit",details:{type:"vehicles",name:"heavy-tank",orders:{type:"hunt"}}}):r==1?(game.sendCommand([-21],{type:"construct-unit",details:{type:"vehicles",name:"heavy-tank",orders:{type:"hunt"}}}),game.sendCommand([-22],{type:"construct-unit",details:{type:"vehicles",name:"scout-tank",orders:{type:"hunt"}}})):game.sendCommand([-21,-22],{type:"construct-unit",details:{type:"vehicles",name:"scout-tank",orders:{type:"hunt"}}});var o=[];for(var i=0;i<game.items.length;i++){var s=game.items[i];s.team=="green"&&s.canAttack&&o.push(s.uid)}game.sendCommand(o,{type:"hunt"})}},{type:"timed",time:48e4,action:function(){game.showMessage("op","Commander! The colony air fleet is just a few minutes away.")}},{type:"timed",time:6e5,action:function(){game.showMessage("op","Commander! The colony air fleet is approaching"),game.add({type:"aircraft",name:"wraith",x:-1,y:30,team:"blue",orders:{type:"hunt"}}),game.add({type:"aircraft",name:"chopper",x:-1,y:31,team:"blue",orders:{type:"hunt"}}),game.add({type:"aircraft",name:"wraith",x:-1,y:32,team:"blue",orders:{type:"hunt"}}),game.add({type:"aircraft",name:"chopper",x:-1,y:33,team:"blue",orders:{type:"hunt"}}),game.add({type:"aircraft",name:"wraith",x:-1,y:34,team:"blue",orders:{type:"hunt"}}),game.add({type:"aircraft",name:"chopper",x:-1,y:35,team:"blue",orders:{type:"hunt"}}),game.add({type:"aircraft",name:"wraith",x:-1,y:36,team:"blue",orders:{type:"hunt"}}),game.add({type:"aircraft",name:"chopper",x:-1,y:37,team:"blue",orders:{type:"hunt"}}),game.add({type:"aircraft",name:"wraith",x:-1,y:38,team:"blue",orders:{type:"hunt"}}),game.add({type:"aircraft",name:"chopper",x:-1,y:39,team:"blue",orders:{type:"hunt"}})}},{type:"timed",time:66e4,action:function(){singleplayer.endLevel(!0)}}]}],multiplayer:[{mapImage:"images/maps/level-one.png",mapGridWidth:60,mapGridHeight:40,mapObstructedTerrain:[[49,8],[50,8],[51,8],[51,9],[52,9],[53,9],[53,10],[53,11],[53,12],[53,13],[53,14],[53,15],[53,16],[52,16],[52,17],[52,18],[52,19],[51,19],[50,19],[50,18],[50,17],[49,17],[49,18],[48,18],[47,18],[47,17],[47,16],[48,16],[49,16],[49,15],[49,14],[48,14],[48,13],[48,12],[49,12],[49,11],[50,11],[50,10],[49,10],[49,9],[44,0],[45,0],[45,1],[45,2],[46,2],[47,2],[47,3],[48,3],[48,4],[48,5],[49,5],[49,6],[49,7],[50,7],[51,7],[51,6],[51,5],[51,4],[52,4],[53,4],[53,3],[54,3],[55,3],[55,2],[56,2],[56,1],[56,0],[55,0],[43,19],[44,19],[45,19],[46,19],[47,19],[48,19],[48,20],[48,21],[47,21],[46,21],[45,21],[44,21],[43,21],[43,20],[41,22],[42,22],[43,22],[44,22],[45,22],[46,22],[47,22],[48,22],[49,22],[50,22],[50,23],[50,24],[49,24],[48,24],[47,24],[47,25],[47,26],[47,27],[47,28],[47,29],[47,30],[46,30],[45,30],[44,30],[43,30],[43,29],[43,28],[43,27],[43,26],[43,25],[43,24],[42,24],[41,24],[41,23],[48,39],[49,39],[50,39],[51,39],[52,39],[53,39],[54,39],[55,39],[56,39],[57,39],[58,39],[59,39],[59,38],[59,37],[59,36],[59,35],[59,34],[59,33],[59,32],[59,31],[59,30],[59,29],[0,0],[1,0],[2,0],[1,1],[2,1],[10,3],[11,3],[12,3],[12,2],[13,2],[14,2],[14,3],[14,4],[15,4],[15,5],[15,6],[14,6],[13,6],[13,5],[12,5],[11,5],[10,5],[10,4],[3,9],[4,9],[5,9],[5,10],[6,10],[7,10],[8,10],[9,10],[9,11],[10,11],[11,11],[11,10],[12,10],[13,10],[13,11],[13,12],[12,12],[11,12],[10,12],[9,12],[8,12],[7,12],[7,13],[7,14],[6,14],[5,14],[5,13],[5,12],[5,11],[4,11],[3,11],[3,10],[33,33],[34,33],[35,33],[35,34],[35,35],[34,35],[33,35],[33,34],[27,39],[27,38],[27,37],[28,37],[28,36],[28,35],[28,34],[28,33],[28,32],[28,31],[28,30],[28,29],[29,29],[29,28],[29,27],[29,26],[29,25],[29,24],[29,23],[30,23],[31,23],[32,23],[32,22],[32,21],[31,21],[30,21],[30,22],[29,22],[28,22],[27,22],[26,22],[26,21],[25,21],[24,21],[24,22],[24,23],[25,23],[26,23],[26,24],[25,24],[25,25],[24,25],[24,26],[24,27],[25,27],[25,28],[25,29],[24,29],[23,29],[23,30],[23,31],[24,31],[25,31],[25,32],[25,33],[24,33],[23,33],[23,34],[23,35],[24,35],[24,36],[24,37],[23,37],[22,37],[22,38],[22,39],[23,39],[24,39],[25,39],[26,0],[26,1],[25,1],[25,2],[25,3],[26,3],[27,3],[27,2],[28,2],[29,2],[29,3],[30,3],[31,3],[31,2],[31,1],[32,1],[32,0],[33,0],[32,8],[33,8],[34,8],[34,9],[34,10],[33,10],[32,10],[32,9],[8,29],[9,29],[9,30],[17,32],[18,32],[19,32],[19,33],[18,33],[17,33],[18,34],[19,34],[3,27],[4,27],[4,26],[3,26],[2,26],[3,25],[4,25],[9,20],[10,20],[11,20],[11,21],[10,21],[10,19],[19,7],[15,7],[29,12],[30,13],[20,14],[21,14],[34,13],[35,13],[36,13],[36,14],[35,14],[34,14],[35,15],[36,15],[16,18],[17,18],[18,18],[16,19],[17,19],[18,19],[17,20],[18,20],[11,19],[58,0],[59,0],[58,1],[59,1],[59,2],[58,3],[59,3],[58,4],[59,4],[59,5],[58,6],[59,6],[58,7],[59,7],[59,8],[58,9],[59,9],[58,10],[59,10],[59,11],[52,6],[53,6],[54,6],[52,7],[53,7],[54,7],[53,8],[54,8],[44,17],[46,32],[55,32],[54,28],[26,34],[34,34],[4,10],[6,11],[6,12],[6,13],[7,11],[8,11],[12,11],[27,0],[27,1],[26,2],[28,1],[28,0],[29,0],[29,1],[30,2],[30,1],[30,0],[31,0],[33,9],[46,0],[47,0],[48,0],[49,0],[50,0],[51,0],[52,0],[53,0],[54,0],[55,1],[54,1],[53,1],[52,1],[51,1],[50,1],[49,1],[48,1],[47,1],[46,1],[48,2],[49,2],[50,2],[51,2],[52,2],[53,2],[54,2],[52,3],[51,3],[50,3],[49,3],[49,4],[50,4],[50,5],[50,6],[50,9],[51,10],[52,10],[51,11],[52,11],[50,12],[51,12],[52,12],[49,13],[50,13],[51,13],[52,13],[50,14],[51,14],[52,14],[50,15],[51,15],[52,15],[50,16],[51,16],[51,17],[48,17],[51,18],[44,20],[45,20],[46,20],[47,20],[42,23],[43,23],[44,23],[45,23],[46,23],[47,23],[48,23],[49,23],[44,24],[45,24],[46,24],[44,25],[45,25],[46,25],[44,26],[45,26],[46,26],[44,27],[45,27],[46,27],[44,28],[45,28],[46,28],[44,29],[45,29],[46,29],[11,4],[12,4],[13,4],[13,3],[14,5],[25,22],[31,22],[27,23],[28,23],[27,24],[28,24],[26,25],[27,25],[28,25],[25,26],[26,26],[27,26],[28,26],[26,27],[27,27],[28,27],[26,28],[27,28],[28,28],[26,29],[27,29],[24,30],[25,30],[26,30],[27,30],[26,31],[27,31],[26,32],[27,32],[26,33],[27,33],[24,34],[25,34],[27,34],[25,35],[26,35],[27,35],[25,36],[26,36],[27,36],[25,37],[26,37],[23,38],[24,38],[25,38],[26,38],[26,39],[2,25],[9,19],[36,31]],requirements:{buildings:["base","harvester","starport","ground-turret"],vehicles:["transport","scout-tank","heavy-tank","harvester"],aircraft:["wraith","chopper"],terrain:["oilfield"]},cash:{blue:1e3,green:1e3},items:[{type:"terrain",name:"oilfield",x:16,y:4,action:"hint"},{type:"terrain",name:"oilfield",x:34,y:12,action:"hint"},{type:"terrain",name:"oilfield",x:1,y:30,action:"hint"},{type:"terrain",name:"oilfield",x:38,y:38,action:"hint"}],teamStartingItems:[{type:"buildings",name:"base",x:0,y:0},{type:"vehicles",name:"harvester",x:2,y:0},{type:"vehicles",name:"heavy-tank",x:2,y:1},{type:"vehicles",name:"scout-tank",x:3,y:0},{type:"vehicles",name:"scout-tank",x:3,y:1}],spawnLocations:[{x:48,y:36,startX:36,startY:20},{x:3,y:36,startX:0,startY:20},{x:36,y:3,startX:32,startY:0},{x:3,y:3,startX:0,startY:0}],triggers:[{type:"conditional",condition:function(){for(var e=0;e<game.items.length;e++)if(game.items[e].team==game.team)return!1;return!0},action:function(){multiplayer.loseGame()}}]}]},vehicles={list:{transport:{name:"transport",pixelWidth:31,pixelHeight:30,pixelOffsetX:15,pixelOffsetY:15,radius:15,speed:15,sight:3,cost:400,hitPoints:100,turnSpeed:2,spriteImages:[{name:"stand",count:1,directions:8}]},harvester:{name:"harvester",pixelWidth:21,pixelHeight:20,pixelOffsetX:10,pixelOffsetY:10,radius:10,speed:10,sight:3,cost:1600,hitPoints:50,turnSpeed:2,spriteImages:[{name:"stand",count:1,directions:8}]},"scout-tank":{name:"scout-tank",canAttack:!0,canAttackLand:!0,canAttackAir:!1,weaponType:"bullet",pixelWidth:21,pixelHeight:21,pixelOffsetX:10,pixelOffsetY:10,radius:11,speed:20,sight:4,cost:500,hitPoints:50,turnSpeed:4,spriteImages:[{name:"stand",count:1,directions:8}]},"heavy-tank":{name:"heavy-tank",canAttack:!0,canAttackLand:!0,canAttackAir:!1,weaponType:"cannon-ball",pixelWidth:30,pixelHeight:30,pixelOffsetX:15,pixelOffsetY:15,radius:13,speed:15,sight:5,cost:1200,hitPoints:50,turnSpeed:4,spriteImages:[{name:"stand",count:1,directions:8}]}},defaults:{type:"vehicles",animationIndex:0,direction:0,action:"stand",orders:{type:"stand"},selected:!1,selectable:!0,directions:8,animate:function(){if(this.life>this.hitPoints*.4)this.lifeCode="healthy";else{if(this.life<=0){this.lifeCode="dead",game.remove(this);return}this.lifeCode="damaged"}switch(this.action){case"stand":var e=wrapDirection(Math.round(this.direction),this.directions);this.imageList=this.spriteArray["stand-"+e],this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0);break;case"teleport":var e=wrapDirection(Math.round(this.direction),this.directions);this.imageList=this.spriteArray["stand-"+e],this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0),this.brightness||(this.brightness=1),this.brightness-=.05,this.brightness<=0&&(this.brightness=undefined,this.action="stand")}},isValidTarget:isValidTarget,findTargetsInSight:findTargetsInSight,processOrders:function(){this.lastMovementX=0,this.lastMovementY=0,this.reloadTimeLeft&&this.reloadTimeLeft--;var e;switch(this.orders.type){case"move":var t=Math.pow(this.orders.to.x-this.x,2)+Math.pow(this.orders.to.y-this.y,2);if(t<Math.pow(this.radius/game.gridSize,2)){this.orders={type:"stand"};return}if(t<Math.pow(this.radius*3/game.gridSize,2)){this.orders={type:"stand"};return}if(this.colliding&&Math.pow(this.orders.to.x-this.x,2)+Math.pow(this.orders.to.y-this.y,2)<Math.pow(this.radius*5/game.gridSize,2)){this.orders.collisionCount?this.orders.collisionCount++:this.orders.collisionCount=1;if(this.orders.collisionCount>30){this.orders={type:"stand"};return}}var n=this.moveTo(this.orders.to);if(!n){this.orders={type:"stand"};return}break;case"deploy":if(this.orders.to.lifeCode=="dead"){this.orders={type:"stand"};return}var e={x:this.orders.to.x+1,y:this.orders.to.y+.5,type:"terrain"},r=Math.pow(e.x-this.x,2)+Math.pow(e.y-this.y,2);if(r<Math.pow(this.radius*2/game.gridSize,2)){var i=angleDiff(this.direction,6,this.directions),s=this.turnSpeed*game.turnSpeedAdjustmentFactor;Math.abs(i)>s?this.direction=wrapDirection(this.direction+s*Math.abs(i)/i,this.directions):(game.remove(this.orders.to),this.orders.to.lifeCode="dead",game.remove(this),this.lifeCode="dead",game.add({type:"buildings",name:"harvester",x:this.orders.to.x,y:this.orders.to.y,action:"deploy",team:this.team}))}else{var n=this.moveTo(e);n||(this.orders={type:"stand"})}break;case"stand":var o=this.findTargetsInSight();o.length>0&&(this.orders={type:"attack",to:o[0]});break;case"sentry":var o=this.findTargetsInSight(2);o.length>0&&(this.orders={type:"attack",to:o[0],nextOrder:this.orders});break;case"hunt":var o=this.findTargetsInSight(100);o.length>0&&(this.orders={type:"attack",to:o[0],nextOrder:this.orders});break;case"attack":if(this.orders.to.lifeCode=="dead"||!this.isValidTarget(this.orders.to)){this.orders.nextOrder?this.orders=this.orders.nextOrder:this.orders={type:"stand"};return}if(Math.pow(this.orders.to.x-this.x,2)+Math.pow(this.orders.to.y-this.y,2)<Math.pow(this.sight,2)){var u=findFiringAngle(this.orders.to,this,this.directions),i=angleDiff(this.direction,u,this.directions),s=this.turnSpeed*game.turnSpeedAdjustmentFactor;if(Math.abs(i)>s){this.direction=wrapDirection(this.direction+s*Math.abs(i)/i,this.directions);return}this.direction=u;if(!this.reloadTimeLeft){this.reloadTimeLeft=bullets.list[this.weaponType].reloadTime;var a=-(Math.round(this.direction)/this.directions)*2*Math.PI,f=this.x-this.radius*Math.sin(a)/game.gridSize,l=this.y-this.radius*Math.cos(a)/game.gridSize,c=game.add({name:this.weaponType,type:"bullets",x:f,y:l,direction:u,target:this.orders.to})}}else{var n=this.moveTo(this.orders.to);if(!n){this.orders={type:"stand"};return}}break;case"patrol":var o=this.findTargetsInSight(1);if(o.length>0){this.orders={type:"attack",to:o[0],nextOrder:this.orders};return}if(Math.pow(this.orders.to.x-this.x,2)+Math.pow(this.orders.to.y-this.y,2)<Math.pow(this.radius*4/game.gridSize,2)){var h=this.orders.to;this.orders.to=this.orders.from,this.orders.from=h}else this.moveTo(this.orders.to);break;case"guard":if(this.orders.to.lifeCode=="dead"){this.orders.nextOrder?this.orders=this.orders.nextOrder:this.orders={type:"stand"};return}if(Math.pow(this.orders.to.x-this.x,2)+Math.pow(this.orders.to.y-this.y,2)<Math.pow(this.sight-2,2)){var o=this.findTargetsInSight(1);if(o.length>0){this.orders={type:"attack",to:o[0],nextOrder:this.orders};return}}else this.moveTo(this.orders.to)}},checkCollisionObjects:function(e){var t=this.speed*game.speedAdjustmentFactor,n=-(Math.round(this.direction)/this.directions)*2*Math.PI,r=this.x-t*Math.sin(n),i=this.y-t*Math.cos(n),s=[],o=Math.max(0,Math.floor(r)-3),u=Math.min(game.currentLevel.mapGridWidth-1,Math.floor(r)+3),a=Math.max(0,Math.floor(i)-3),f=Math.min(game.currentLevel.mapGridHeight-1,Math.floor(i)+3);for(var l=o;l<=u;l++)for(var c=a;c<=f;c++)e[c][l]==1&&(Math.pow(l+.5-r,2)+Math.pow(c+.5-i,2)<Math.pow(this.radius/game.gridSize+.1,2)?s.push({collisionType:"hard","with":{type:"wall",x:l+.5,y:c+.5}}):Math.pow(l+.5-r,2)+Math.pow(c+.5-i,2)<Math.pow(this.radius/game.gridSize+.7,2)&&s.push({collisionType:"soft","with":{type:"wall",x:l+.5,y:c+.5}}));for(var c=game.vehicles.length-1;c>=0;c--){var h=game.vehicles[c];h!=this&&Math.abs(h.x-this.x)<3&&Math.abs(h.y-this.y)<3&&(Math.pow(h.x-r,2)+Math.pow(h.y-i,2)<Math.pow((this.radius+h.radius)/game.gridSize,2)?s.push({collisionType:"hard","with":h}):Math.pow(h.x-r,2)+Math.pow(h.y-i,2)<Math.pow((this.radius*1.5+h.radius)/game.gridSize,2)&&s.push({collisionType:"soft","with":h}))}return s},moveTo:function(e){game.currentMapPassableGrid||game.rebuildPassableGrid();var t=[Math.floor(this.x),Math.floor(this.y)],n=[Math.floor(e.x),Math.floor(e.y)],r=$.extend(!0,[],game.currentMapPassableGrid);if(e.type=="buildings"||e.type=="terrain")r[Math.floor(e.y)][Math.floor(e.x)]=0;var i;if(t[1]<0||t[1]>=game.currentLevel.mapGridHeight||t[0]<0||t[0]>=game.currentLevel.mapGridWidth)this.orders.path=[this,e],i=findAngle(e,this,this.directions);else{this.orders.path=AStar(r,t,n,"Euclidean");if(this.orders.path.length>1){var s={x:this.orders.path[1].x+.5,y:this.orders.path[1].y+.5};i=findAngle(s,this,this.directions)}else{if(t[0]!=n[0]||t[1]!=n[1])return!1;this.orders.path=[this,e],i=findAngle(e,this,this.directions)}}var o=this.checkCollisionObjects(r);this.hardCollision=!1;if(o.length>0){this.colliding=!0;var u={x:0,y:0};o.push({collisionType:"attraction","with":{x:this.orders.path[1].x+.5,y:this.orders.path[1].y+.5}});for(var a=o.length-1;a>=0;a--){var f=o[a],l=findAngle(f.with,this,this.directions),c=-(l/this.directions)*2*Math.PI,h;switch(f.collisionType){case"hard":h=2,this.hardCollision=!0;break;case"soft":h=1;break;case"attraction":h=-0.25}u.x+=h*Math.sin(c),u.y+=h*Math.cos(c)}i=findAngle(u,{x:0,y:0},this.directions)}else this.colliding=!1;var p=angleDiff(this.direction,i,this.directions),d=this.turnSpeed*game.turnSpeedAdjustmentFactor;if(this.hardCollision)Math.abs(p)>d&&(this.direction=wrapDirection(this.direction+d*Math.abs(p)/p,this.directions));else{var v=this.speed*game.speedAdjustmentFactor,m=-(Math.round(this.direction)/this.directions)*2*Math.PI;this.lastMovementX=-(v*Math.sin(m)),this.lastMovementY=-(v*Math.cos(m)),this.x=this.x+this.lastMovementX,this.y=this.y+this.lastMovementY,Math.abs(p)>d&&(this.direction=wrapDirection(this.direction+d*Math.abs(p)/p,this.directions))}return!0},drawLifeBar:function(){var e=this.drawingX,t=this.drawingY-2*game.lifeBarHeight;game.foregroundContext.fillStyle=this.lifeCode=="healthy"?game.healthBarHealthyFillColor:game.healthBarDamagedFillColor,game.foregroundContext.fillRect(e,t,this.pixelWidth*this.life/this.hitPoints,game.lifeBarHeight),game.foregroundContext.strokeStyle=game.healthBarBorderColor,game.foregroundContext.lineWidth=1,game.foregroundContext.strokeRect(e,t,this.pixelWidth,game.lifeBarHeight)},drawSelection:function(){var e=this.drawingX+this.pixelOffsetX,t=this.drawingY+this.pixelOffsetY;game.foregroundContext.strokeStyle=game.selectionBorderColor,game.foregroundContext.lineWidth=1,game.foregroundContext.beginPath(),game.foregroundContext.arc(e,t,this.radius,0,Math.PI*2,!1),game.foregroundContext.fillStyle=game.selectionFillColor,game.foregroundContext.fill(),game.foregroundContext.stroke()},draw:function(){var e=this.x*game.gridSize-game.offsetX-this.pixelOffsetX+this.lastMovementX*game.drawingInterpolationFactor*game.gridSize,t=this.y*game.gridSize-game.offsetY-this.pixelOffsetY+this.lastMovementY*game.drawingInterpolationFactor*game.gridSize;this.drawingX=e,this.drawingY=t,this.selected&&(this.drawSelection(),this.drawLifeBar());var n=this.team=="blue"?0:1,r=n*this.pixelHeight;game.foregroundContext.drawImage(this.spriteSheet,this.imageOffset*this.pixelWidth,r,this.pixelWidth,this.pixelHeight,e,t,this.pixelWidth,this.pixelHeight),this.brightness&&(game.foregroundContext.beginPath(),game.foregroundContext.arc(e+this.pixelOffsetX,t+this.pixelOffsetY,this.radius,0,Math.PI*2,!1),game.foregroundContext.fillStyle="rgba(255,255,255,"+this.brightness+")"
,game.foregroundContext.fill())}},load:loadItem,add:addItem},buildings={list:{base:{name:"base",pixelWidth:60,pixelHeight:60,baseWidth:40,baseHeight:40,pixelOffsetX:0,pixelOffsetY:20,buildableGrid:[[1,1],[1,1]],passableGrid:[[1,1],[1,1]],sight:3,hitPoints:500,cost:5e3,spriteImages:[{name:"healthy",count:4},{name:"damaged",count:1},{name:"contructing",count:3}],processOrders:function(){switch(this.orders.type){case"construct-building":this.action="construct",this.animationIndex=0;var e=this.orders.details;e.team=this.team,e.action="teleport";var t=game.add(e);game.cash[this.team]-=t.cost,this.orders={type:"stand"}}}},starport:{name:"starport",pixelWidth:40,pixelHeight:60,baseWidth:40,baseHeight:55,pixelOffsetX:1,pixelOffsetY:5,buildableGrid:[[1,1],[1,1],[1,1]],passableGrid:[[1,1],[0,0],[0,0]],sight:3,cost:2e3,hitPoints:300,spriteImages:[{name:"teleport",count:9},{name:"closing",count:18},{name:"healthy",count:4},{name:"damaged",count:1}],processOrders:function(){switch(this.orders.type){case"construct-unit":if(this.lifeCode!="healthy")return;var e=!1;for(var t=game.items.length-1;t>=0;t--){var n=game.items[t];if(n.type=="vehicles"||n.type=="aircraft")if(n.x>this.x&&n.x<this.x+2&&n.y>this.y&&n.y<this.y+3){e=!0;break}}var r=window[this.orders.details.type].list[this.orders.details.name].cost;if(e)this.team==game.team&&game.showMessage("system","Warning! Cannot teleport unit while landing bay is occupied.");else if(game.cash[this.team]<r)this.team==game.team&&game.showMessage("system","Warning! Insufficient Funds. Need "+r+" credits.");else{this.action="open",this.animationIndex=0;var i=this.orders.details;i.x=this.x+.5*this.pixelWidth/game.gridSize,i.y=this.y+.5*this.pixelHeight/game.gridSize,i.action="teleport",i.team=this.team,game.cash[this.team]-=r,this.constructUnit=$.extend(!0,[],i)}this.orders={type:"stand"}}}},harvester:{name:"harvester",pixelWidth:40,pixelHeight:60,baseWidth:40,baseHeight:20,pixelOffsetX:-2,pixelOffsetY:40,buildableGrid:[[1,1]],passableGrid:[[1,1]],sight:3,cost:5e3,hitPoints:300,spriteImages:[{name:"deploy",count:17},{name:"healthy",count:3},{name:"damaged",count:1}]},"ground-turret":{name:"ground-turret",canAttack:!0,canAttackLand:!0,canAttackAir:!1,weaponType:"cannon-ball",action:"guard",direction:0,directions:8,orders:{type:"guard"},pixelWidth:38,pixelHeight:32,baseWidth:20,baseHeight:18,cost:1500,pixelOffsetX:9,pixelOffsetY:12,buildableGrid:[[1]],passableGrid:[[1]],sight:5,hitPoints:200,spriteImages:[{name:"teleport",count:9},{name:"healthy",count:1,directions:8},{name:"damaged",count:1}],isValidTarget:isValidTarget,findTargetsInSight:findTargetsInSight,processOrders:function(){this.reloadTimeLeft&&this.reloadTimeLeft--;if(this.lifeCode!="healthy")return;switch(this.orders.type){case"guard":var e=this.findTargetsInSight();e.length>0&&(this.orders={type:"attack",to:e[0]});break;case"attack":if(!this.orders.to||this.orders.to.lifeCode=="dead"||!this.isValidTarget(this.orders.to)||Math.pow(this.orders.to.x-this.x,2)+Math.pow(this.orders.to.y-this.y,2)>Math.pow(this.sight,2)){var e=this.findTargetsInSight();e.length>0?this.orders.to=e[0]:this.orders={type:"guard"}}if(this.orders.to){var t=findFiringAngle(this.orders.to,this,this.directions),n=angleDiff(this.direction,t,this.directions),r=this.turnSpeed*game.turnSpeedAdjustmentFactor;if(Math.abs(n)>r){this.direction=wrapDirection(this.direction+r*Math.abs(n)/n,this.directions);return}this.direction=t;if(!this.reloadTimeLeft){this.reloadTimeLeft=bullets.list[this.weaponType].reloadTime;var i=-(Math.round(this.direction)/this.directions)*2*Math.PI,s=this.x+.5-1*Math.sin(i),o=this.y+.5-1*Math.cos(i),u=game.add({name:this.weaponType,type:"bullets",x:s,y:o,direction:this.direction,target:this.orders.to})}}}}}},defaults:{type:"buildings",animationIndex:0,direction:0,orders:{type:"stand"},action:"stand",selected:!1,selectable:!0,animate:function(){if(this.life>this.hitPoints*.4)this.lifeCode="healthy";else{if(this.life<=0){this.lifeCode="dead",game.remove(this);return}this.lifeCode="damaged"}switch(this.action){case"stand":this.imageList=this.spriteArray[this.lifeCode],this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0);break;case"construct":this.imageList=this.spriteArray.contructing,this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0,this.action="stand");break;case"teleport":this.imageList=this.spriteArray.teleport,this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0,this.canAttack?this.action="guard":this.action="stand");break;case"close":this.imageList=this.spriteArray.closing,this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0,this.action="stand");break;case"open":this.imageList=this.spriteArray.closing,this.imageOffset=this.imageList.offset+this.imageList.count-this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0,this.action="close",this.constructUnit&&(game.add(this.constructUnit),this.constructUnit=undefined));break;case"deploy":this.imageList=this.spriteArray.deploy,this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0,this.action="harvest");break;case"harvest":this.imageList=this.spriteArray[this.lifeCode],this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0,this.lifeCode=="healthy"&&(game.cash[this.team]+=2));break;case"guard":if(this.lifeCode=="damaged")this.imageList=this.spriteArray[this.lifeCode];else{var e=wrapDirection(Math.round(this.direction),this.directions);this.imageList=this.spriteArray[this.lifeCode+"-"+e]}this.imageOffset=this.imageList.offset}},drawLifeBar:function(){var e=this.drawingX+this.pixelOffsetX,t=this.drawingY-2*game.lifeBarHeight;game.foregroundContext.fillStyle=this.lifeCode=="healthy"?game.healthBarHealthyFillColor:game.healthBarDamagedFillColor,game.foregroundContext.fillRect(e,t,this.baseWidth*this.life/this.hitPoints,game.lifeBarHeight),game.foregroundContext.strokeStyle=game.healthBarBorderColor,game.foregroundContext.lineWidth=1,game.foregroundContext.strokeRect(e,t,this.baseWidth,game.lifeBarHeight)},drawSelection:function(){var e=this.drawingX+this.pixelOffsetX,t=this.drawingY+this.pixelOffsetY;game.foregroundContext.strokeStyle=game.selectionBorderColor,game.foregroundContext.lineWidth=1,game.foregroundContext.fillStyle=game.selectionFillColor,game.foregroundContext.fillRect(e-1,t-1,this.baseWidth+2,this.baseHeight+2),game.foregroundContext.strokeRect(e-1,t-1,this.baseWidth+2,this.baseHeight+2)},draw:function(){var e=this.x*game.gridSize-game.offsetX-this.pixelOffsetX,t=this.y*game.gridSize-game.offsetY-this.pixelOffsetY;this.drawingX=e,this.drawingY=t,this.selected&&(this.drawSelection(),this.drawLifeBar());var n=this.team=="blue"?0:1,r=n*this.pixelHeight;game.foregroundContext.drawImage(this.spriteSheet,this.imageOffset*this.pixelWidth,r,this.pixelWidth,this.pixelHeight,e,t,this.pixelWidth,this.pixelHeight)}},load:loadItem,add:addItem},terrain={list:{oilfield:{name:"oilfield",pixelWidth:40,pixelHeight:60,baseWidth:40,baseHeight:20,pixelOffsetX:0,pixelOffsetY:40,buildableGrid:[[1,1]],passableGrid:[[1,1]],spriteImages:[{name:"hint",count:1},{name:"default",count:1}]},bigrocks:{name:"bigrocks",pixelWidth:40,pixelHeight:70,baseWidth:40,baseHeight:40,pixelOffsetX:0,pixelOffsetY:30,buildableGrid:[[1,1],[0,1]],passableGrid:[[1,1],[0,1]],spriteImages:[{name:"default",count:1}]},smallrocks:{name:"smallrocks",pixelWidth:20,pixelHeight:35,baseWidth:20,baseHeight:20,pixelOffsetX:0,pixelOffsetY:15,buildableGrid:[[1]],passableGrid:[[1]],spriteImages:[{name:"default",count:1}]}},defaults:{type:"terrain",animationIndex:0,action:"default",selected:!1,selectable:!1,animate:function(){switch(this.action){case"default":this.imageList=this.spriteArray["default"],this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0);break;case"hint":this.imageList=this.spriteArray.hint,this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&(this.animationIndex=0)}},draw:function(){var e=this.x*game.gridSize-game.offsetX-this.pixelOffsetX,t=this.y*game.gridSize-game.offsetY-this.pixelOffsetY,n=0;game.foregroundContext.drawImage(this.spriteSheet,this.imageOffset*this.pixelWidth,n,this.pixelWidth,this.pixelHeight,e,t,this.pixelWidth,this.pixelHeight)}},load:loadItem,add:addItem},AStar=function(){function e(e,t,n,r,i,s,o,u,a,f,l,c,h){return e&&(n&&!a[i][o]&&(c[h++]={x:o,y:i}),r&&!a[i][u]&&(c[h++]={x:u,y:i})),t&&(n&&!a[s][o]&&(c[h++]={x:o,y:s}),r&&!a[s][u]&&(c[h++]={x:u,y:s})),c}function t(e,t,n,r,i,s,o,u,a,f,l,c,h){return e=i>-1,t=s<f,n=o<l,r=u>-1,n&&(e&&!a[i][o]&&(c[h++]={x:o,y:i}),t&&!a[s][o]&&(c[h++]={x:o,y:s})),r&&(e&&!a[i][u]&&(c[h++]={x:u,y:i}),t&&!a[s][u]&&(c[h++]={x:u,y:s})),c}function n(e,t,n,r,i,s,o,u,a,f,l,c,h){return c}function r(e,t,n,r,i,s){var o=n-1,u=n+1,a=t+1,f=t-1,l=o>-1&&!r[o][t],c=u<i&&!r[u][t],h=a<s&&!r[n][a],p=f>-1&&!r[n][f],d=[],v=0;return l&&(d[v++]={x:t,y:o}),h&&(d[v++]={x:a,y:n}),c&&(d[v++]={x:t,y:u}),p&&(d[v++]={x:f,y:n}),e(l,c,h,p,o,u,a,f,r,i,s,d,v)}function i(e,t,n,r){return r(n(e.x-t.x),n(e.y-t.y))}function s(e,t,n,r){var i=e.x-t.x,s=e.y-t.y;return r(i*i+s*s)}function o(e,t,n,r){return n(e.x-t.x)+n(e.y-t.y)}function u(u,a,f,l){var c=u[0].length,h=u.length,p=c*h,d=Math.abs,v=Math.max,m={},g=[],y=[{x:a[0],y:a[1],f:0,g:0,v:a[0]+a[1]*c}],b=1,w,E,S,x,T,N,C,k,L;f={x:f[0],y:f[1],v:f[0]+f[1]*c};switch(l){case"Diagonal":S=e;case"DiagonalFree":E=i;break;case"Euclidean":S=e;case"EuclideanFree":v=Math.sqrt,E=s;break;default:E=o,S=n}S||(S=t);do{N=p,C=0;for(x=0;x<b;++x)(l=y[x].f)<N&&(N=l,C=x);k=y.splice(C,1)[0];if(k.v!=f.v){--b,L=r(S,k.x,k.y,u,h,c);for(x=0,T=L.length;x<T;++x)(w=L[x]).p=k,w.f=w.g=0,w.v=w.x+w.y*c,w.v in m||(w.f=(w.g=k.g+E(w,k,d,v))+E(w,f,d,v),y[b++]=w,m[w.v]=1)}else{x=b=0;do g[x++]={x:k.x,y:k.y};while(k=k.p);g.reverse()}}while(b);return g}return u}(),bullets={list:{fireball:{name:"fireball",speed:60,reloadTime:30,range:8,damage:10,spriteImages:[{name:"fly",count:1,directions:8},{name:"explode",count:7}]},heatseeker:{name:"heatseeker",reloadTime:40,speed:25,range:9,damage:20,turnSpeed:2,spriteImages:[{name:"fly",count:1,directions:8},{name:"explode",count:7}]},"cannon-ball":{name:"cannon-ball",reloadTime:40,speed:25,damage:10,range:6,spriteImages:[{name:"fly",count:1,directions:8},{name:"explode",count:7}]},bullet:{name:"bullet",damage:5,speed:50,range:5,reloadTime:20,spriteImages:[{name:"fly",count:1,directions:8},{name:"explode",count:3}]}},defaults:{type:"bullets",distanceTravelled:0,animationIndex:0,direction:0,directions:8,pixelWidth:10,pixelHeight:11,pixelOffsetX:5,pixelOffsetY:5,radius:6,action:"fly",selected:!1,selectable:!1,orders:{type:"fire"},moveTo:function(e){if(this.turnSpeed){var t=findFiringAngle(e,this,this.directions),n=angleDiff(this.direction,t,this.directions),r=this.turnSpeed*game.turnSpeedAdjustmentFactor;Math.abs(n)>r&&(this.direction=wrapDirection(this.direction+r*Math.abs(n)/n,this.directions))}var i=this.speed*game.speedAdjustmentFactor;this.distanceTravelled+=i;var s=-(this.direction/this.directions)*2*Math.PI;this.lastMovementX=-(i*Math.sin(s)),this.lastMovementY=-(i*Math.cos(s)),this.x=this.x+this.lastMovementX,this.y=this.y+this.lastMovementY},reachedTarget:function(){var e=this.target;return e.type=="buildings"?e.x<=this.x&&e.x>=this.x-e.baseWidth/game.gridSize&&e.y<=this.y&&e.y>=this.y-e.baseHeight/game.gridSize:e.type=="aircraft"?Math.pow(e.x-this.x,2)+Math.pow(e.y-(this.y+e.pixelShadowHeight/game.gridSize),2)<Math.pow(e.radius/game.gridSize,2):Math.pow(e.x-this.x,2)+Math.pow(e.y-this.y,2)<Math.pow(e.radius/game.gridSize,2)},processOrders:function(){this.lastMovementX=0,this.lastMovementY=0;switch(this.orders.type){case"fire":var e=!1;this.distanceTravelled>this.range||(e=this.reachedTarget())?e?(this.target.life-=this.damage,this.orders={type:"explode"},this.action="explode",this.animationIndex=0):game.remove(this):this.moveTo(this.target)}},animate:function(){switch(this.action){case"fly":var e=wrapDirection(Math.round(this.direction),this.directions);this.imageList=this.spriteArray["fly-"+e],this.imageOffset=this.imageList.offset;break;case"explode":this.imageList=this.spriteArray.explode,this.imageOffset=this.imageList.offset+this.animationIndex,this.animationIndex++,this.animationIndex>=this.imageList.count&&game.remove(this)}},draw:function(){var e=this.x*game.gridSize-game.offsetX-this.pixelOffsetX+this.lastMovementX*game.drawingInterpolationFactor*game.gridSize,t=this.y*game.gridSize-game.offsetY-this.pixelOffsetY+this.lastMovementY*game.drawingInterpolationFactor*game.gridSize,n=0;game.foregroundContext.drawImage(this.spriteSheet,this.imageOffset*this.pixelWidth,n,this.pixelWidth,this.pixelHeight,e,t,this.pixelWidth,this.pixelHeight)}},load:loadItem,add:addItem},fog={grid:[],canvas:document.createElement("canvas"),initLevel:function(){this.canvas.width=game.currentLevel.mapGridWidth*game.gridSize,this.canvas.height=game.currentLevel.mapGridHeight*game.gridSize,this.context=this.canvas.getContext("2d"),this.defaultFogGrid=[];for(var e=0;e<game.currentLevel.mapGridHeight;e++){this.defaultFogGrid[e]=[];for(var t=0;t<game.currentLevel.mapGridWidth;t++)this.defaultFogGrid[e][t]=1}},isPointOverFog:function(e,t){return t<0||t/game.gridSize>=game.currentLevel.mapGridHeight||e<0||e/game.gridSize>=game.currentLevel.mapGridWidth?!0:this.grid[game.team][Math.floor(t/game.gridSize)][Math.floor(e/game.gridSize)]==1},animate:function(){this.context.drawImage(game.currentMapImage,0,0),this.context.fillStyle="rgba(0,0,0,0.8)",this.context.fillRect(0,0,this.canvas.width,this.canvas.height),this.grid[game.team]=$.extend(!0,[],this.defaultFogGrid),fog.context.globalCompositeOperation="destination-out";for(var e=game.items.length-1;e>=0;e--){var t=game.items[e],n=game.team;if(t.team==n&&!t.keepFogged){var r=Math.floor(t.x),i=Math.floor(t.y),s=Math.max(0,r-t.sight+1),o=Math.max(0,i-t.sight+1),u=Math.min(game.currentLevel.mapGridWidth-1,r+t.sight-1+(t.type=="buildings"?t.baseWidth/game.gridSize:0)),a=Math.min(game.currentLevel.mapGridHeight-1,i+t.sight-1+(t.type=="buildings"?t.baseHeight/game.gridSize:0));for(var f=s;f<=u;f++)for(var l=o;l<=a;l++)if(f>s&&f<u||l>o&&l<a)this.grid[n][l][f]&&(this.context.fillStyle="rgba(100,0,0,0.9)",this.context.beginPath(),this.context.arc(f*game.gridSize+12,l*game.gridSize+12,16,0,2*Math.PI,!1),this.context.fill(),this.context.fillStyle="rgba(100,0,0,0.7)",this.context.beginPath(),this.context.arc(f*game.gridSize+12,l*game.gridSize+12,18,0,2*Math.PI,!1),this.context.fill(),this.context.fillStyle="rgba(100,0,0,0.5)",this.context.beginPath(),this.context.arc(f*game.gridSize+12,l*game.gridSize+12,24,0,2*Math.PI,!1),this.context.fill()),this.grid[n][l][f]=0}}fog.context.globalCompositeOperation="source-over"},draw:function(){game.foregroundContext.drawImage(this.canvas,game.offsetX,game.offsetY,game.canvasWidth,game.canvasHeight,0,0,game.canvasWidth,game.canvasHeight)}},sidebar={enableSidebarButtons:function(){$("#gameinterfacescreen #sidebarbuttons input[type='button'] ").attr("disabled",!0);if(game.selectedItems.length==0)return;var e=!1,t=!1;for(var n=game.selectedItems.length-1;n>=0;n--){var r=game.selectedItems[n];r.type=="buildings"&&r.team==game.team&&r.lifeCode=="healthy"&&r.action=="stand"&&(r.name=="base"?e=!0:r.name=="starport"&&(t=!0))}var i=game.cash[game.team];e&&!game.deployBuilding&&(game.currentLevel.requirements.buildings.indexOf("starport")>-1&&i>=buildings.list.starport.cost&&$("#starportbutton").removeAttr("disabled"),game.currentLevel.requirements.buildings.indexOf("ground-turret")>-1&&i>=buildings.list["ground-turret"].cost&&$("#turretbutton").removeAttr("disabled")),t&&(game.currentLevel.requirements.vehicles.indexOf("scout-tank")>-1&&i>=vehicles.list["scout-tank"].cost&&$("#scouttankbutton").removeAttr("disabled"),game.currentLevel.requirements.vehicles.indexOf("heavy-tank")>-1&&i>=vehicles.list["heavy-tank"].cost&&$("#heavytankbutton").removeAttr("disabled"),game.currentLevel.requirements.vehicles.indexOf("harvester")>-1&&i>=vehicles.list.harvester.cost&&$("#harvesterbutton").removeAttr("disabled"),game.currentLevel.requirements.aircraft.indexOf("chopper")>-1&&i>=aircraft.list.chopper.cost&&$("#chopperbutton").removeAttr("disabled"),game.currentLevel.requirements.aircraft.indexOf("wraith")>-1&&i>=aircraft.list.wraith.cost&&$("#wraithbutton").removeAttr("disabled"))},animate:function(){$("#cash").html(game.cash[game.team]),this.enableSidebarButtons();if(game.deployBuilding){game.rebuildBuildableGrid();var e=buildings.list[game.deployBuilding].buildableGrid;game.placementGrid=$.extend(!0,[],e),game.canDeployBuilding=!0;for(var t=game.placementGrid.length-1;t>=0;t--)for(var n=game.placementGrid[t].length-1;n>=0;n--)game.placementGrid[t][n]&&(mouse.gridY+t>=game.currentLevel.mapGridHeight||mouse.gridX+n>=game.currentLevel.mapGridWidth||game.currentMapBuildableGrid[mouse.gridY+t][mouse.gridX+n]==1||fog.grid[game.team][mouse.gridY+t][mouse.gridX+n]==1)&&(game.canDeployBuilding=!1,game.placementGrid[t][n]=0)}},init:function(){$("#scouttankbutton").click(function(){sidebar.constructAtStarport({type:"vehicles",name:"scout-tank"})}),$("#heavytankbutton").click(function(){sidebar.constructAtStarport({type:"vehicles",name:"heavy-tank"})}),$("#harvesterbutton").click(function(){sidebar.constructAtStarport({type:"vehicles",name:"harvester"})}),$("#chopperbutton").click(function(){sidebar.constructAtStarport({type:"aircraft",name:"chopper"})}),$("#wraithbutton").click(function(){sidebar.constructAtStarport({type:"aircraft",name:"wraith"})}),$("#starportbutton").click(function(){game.deployBuilding="starport"}),$("#turretbutton").click(function(){game.deployBuilding="ground-turret"})},constructAtStarport:function(e){var t;for(var n=game.selectedItems.length-1;n>=0;n--){var r=game.selectedItems[n];if(r.type=="buildings"&&r.name=="starport"&&r.team==game.team&&r.lifeCode=="healthy"&&r.action=="stand"){t=r;break}}t&&game.sendCommand([t.uid],{type:"construct-unit",details:e})},cancelDeployingBuilding:function(){game.deployBuilding=undefined},finishDeployingBuilding:function(){var e=game.deployBuilding,t;for(var n=game.selectedItems.length-1;n>=0;n--){var r=game.selectedItems[n];if(r.type=="buildings"&&r.name=="base"&&r.team==game.team&&r.lifeCode=="healthy"&&r.action=="stand"){t=r;break}}if(t){var i={type:"buildings",name:e,x:mouse.gridX,y:mouse.gridY};game.sendCommand([t.uid],{type:"construct-building",details:i})}game.deployBuilding=undefined}},sounds={list:{bullet:["bullet1","bullet2"],heatseeker:["heatseeker1","heatseeker2"],fireball:["laser1","laser2"],"cannon-ball":["cannon1","cannon2"],"message-received":["message"],"acknowledge-attacking":["engaging"],"acknowledge-moving":["yup","roger1","roger2"]},loaded:{},init:function(){for(var e in this.list){var t={};t.audioObjects=[];for(var n=0;n<this.list[e].length;n++)t.audioObjects.push(loader.loadSound("audio/"+this.list[e][n]));this.loaded[e]=t}},play:function(e){var t=sounds.loaded[e];if(t&&t.audioObjects&&t.audioObjects.length>0){if(!t.counter||t.counter>=t.audioObjects.length)t.counter=0;var n=t.audioObjects[t.counter];t.counter++,n.play()}}};