var battleWIDTH=310; var battleHEIGHT=150; var battleGRID_WIDTH=31; //number of grid cells var battleGRID_HEIGHT=15; var battleINV_GRID_WIDTH = 1 / (battleWIDTH / battleGRID_WIDTH); var battleINV_GRID_HEIGHT = 1 / (battleHEIGHT / battleGRID_HEIGHT); var battleLEFTSHIPS=200; var battleRIGHTSHIPS=200; var battleMAXSPEED = 2; var battleDEATH_THRESHOLD = 0.5; //used to calculate battles var battleLEFTCOLOR = "#ffffff" var battleRIGHTCOLOR = "#000000" var battleEXPLODECOLOR = "#ffffff" var ships = new Array(); var numShips = 0; var grid = new Array(battleGRID_HEIGHT); var numLeftShips = 0; var numRightShips = 0; var probeCombat = 0; var probeCombatBaseRate = .15; var attackSpeed = .2; var battleSpeed = .2; var attackSpeedFlag = 0; var attackSpeedMod = .1; var battles = []; var battleID = 0; var battleName = "foo"; var battleNameFlag = 0; var maxBattles = 1; var battleClock = 0; var battleAlarm = 10; var outcomeTimer = 150; var drifterCombat = 1.75; var warTrigger = 1000000; var unitSize = 0; var driftersKilled = 0; var battleEndDelay = 0; var battleEndTimer = 100; var masterBattleClock = 0; var honorCount = 0; var threnodyTitle = "Durenstein 1"; var bonusHonor = 0; var honorReward = 0; //NON-CANVAS BATTLE LOGIC function checkForBattles(){ if (drifterCount>warTrigger && probeCount > 0 && battles.length < maxBattles){ var r = (Math.random()*100); if (r>=50){ if (battleFlag == 0){battleFlag = 1}; createBattle(); } } } var battleNames = ["Aboukir", "Abensberg", "Acre", "Alba de Tormes", "la Albuera", "Algeciras Bay", "Amstetten", "Arcis-sur-Aube", "Aspern-Essling", "Jena-Auerstedt", "Arcole", "Austerlitz", "Badajoz", "Bailen", "la Barrosa", "Bassano", "Bautzen", "Berezina", "Bergisel", "Borodino", "Burgos", "Bucaco", "Cadiz", "Caldiero", "Castiglione", "Castlebar", "Champaubert", "Chateau-Thierry", "Copenhagen", "Corunna", "Craonne", "Dego", "Dennewitz", "Dresden", "Durenstein", "Eckmuhl", "Elchingen", "Espinosa de los Monteros", "Eylau", "Cape Finisterre", "Friedland", "Fuentes de Onoro", "Gevora River", "Gerona", "Hamburg", "Haslach-Jungingen", "Heilsberg", "Hohenlinden", "Jena-Auerstedt", "Kaihona", "Kolberg", "Landshut", "Leipzig", "Ligny", "Lodi", "Lubeck", "Lutzen", "Marengo", "Maria", "Medellin", "Medina de Rioseco", "Millesimo", "Mincio River", "Mondovi", "Montebello", "Montenotte", "Montmirail", "Mount Tabor", "The Nile", "Novi", "Ocana", "Cape Ortegal", "Orthez", "Pancorbo", "Piave River", "The Pyramids", "Quatre Bras", "Raab", "Raszyn", "Rivoli", "Rolica", "La Rothiere", "Rovereto", "Saalfeld", "Schongrabern", "Salamanca", "Smolensk", "Somosierra", "Talavera", "Tamames", "Trafalgar", "Trebbia", "Tudela", "Ulm", "Valls", "Valmaseda", "Valutino", "Vauchamps", "Vimeiro", "Vitoria", "Wagram", "Waterloo", "Wavre", "Wertingen", "Zaragoza"]; var battleNumbers = []; for (i=0; i .99){ battleSpeed = .99; } } for(var i = 0; i < battles.length; i++){ r = Math.random(); if (r>=battleSpeed) { var clipCasualties = battles[i].drifterProbes * drifterCombat * (1-battleSpeed); if (clipCasualties>battles[i].clipProbes){ clipCasualties=battles[i].clipProbes; } battles[i].clipProbes = battles[i].clipProbes - clipCasualties; probeCount = probeCount - clipCasualties; probesLostCombat = probesLostCombat + clipCasualties; document.getElementById('probesLostCombatDisplay').innerHTML = numberCruncher(probesLostCombat); // document.getElementById('battle'+battles[i].id+"clipCount").innerHTML = numberCruncher(battles[i].clipProbes); } else { var drifterCasualties = battles[i].clipProbes * Math.pow(probeCombat, 1.7) * combatEffectiveness; if (drifterCasualties>battles[i].drifterProbes){ drifterCasualties=battles[i].drifterProbes; } battles[i].drifterProbes = battles[i].drifterProbes - drifterCasualties; drifterCount = drifterCount - drifterCasualties; // document.getElementById('battle'+battles[i].id+"drifterCount").innerHTML = numberCruncher(battles[i].drifterProbes); } if (battles[i].drifterProbes < 1){ battles[i].victory = true; } if (battles[i].clipProbes < 1 && battles[i].victory == false){ battles[i].loss = true; } if (battles[i].loss == true && battles[i].whiteFlag == 0){ availableMatter = availableMatter - battles[i].territory; battles[i].whiteFlag = 1; } if (battles[i].loss == true){ // document.getElementById("battleReport"+battles[i].id).style.backgroundColor = "LightGrey"; battles[i].reportCount++; if (battles[i].reportCount > outcomeTimer){ battles[i].garbageFlag = 1; } } if (battles[i].victory == true){ battles[i].reportCount++; if (battles[i].reportCount > outcomeTimer){ battles[i].garbageFlag = 1; } } } } function battleCleanUp(){ for(var i = battles.length-1; i >= 0; i--){ if (battles[i].garbageFlag == 1){ var element = document.getElementById('battleReport'+battles[i].id); element.parentNode.removeChild(element); battles.splice(i,1); } } } function updateBattleDisplay(battle){ var element = document.getElementById("battleListTop"); var newBattle = document.createElement("div"); newBattle.setAttribute("id", battle.id); element.appendChild(newBattle, element.firstChild); var span = document.createElement("span"); span.setAttribute("class", "clean"); span.style.fontWeight = "bold"; newBattle.appendChild(span); var hed = document.createTextNode("Combatants"); span.appendChild(hed); var clipsCount = document.createElement("span"); clipsCount = battle.clipProbes; element.appendChild(span); } */ //CANVAS BATTLE DISPLAY function Battle(){ var canvas; var context; var interval; var sign; battleRestart(); this.initialize = function(){ canvas = document.getElementById("canvas"); context = canvas.getContext('2d'); canvas.width = battleWIDTH; canvas.height = battleHEIGHT; var interval = setInterval(Update, 16); battleRestart(); } var Update = function(){ ClearFrame(); UpdateGrid(); MoveShips(); DoCombat(); } function checkForBattleEnd(){ if (battles.length>0){ if (numLeftShips == 0 || numRightShips == 0){ if (project121.flag == 1){ document.getElementById("victoryDiv").style.visibility = "visible"; if (numLeftShips == 0){ if (honorCount == 0){ bonusHonor = 0; honor = honor - battleLEFTSHIPS; honorCount = 1; } document.getElementById("battleResult").innerHTML = "DEFEAT"; document.getElementById("battleResultSign").innerHTML = "-"; document.getElementById("honorAmount").innerHTML = battleLEFTSHIPS; document.getElementById("honorDisplay").innerHTML = Math.round(honor).toLocaleString(); threnodyTitle = battleName; } if (numRightShips == 0){ if (honorCount == 0){ honorReward = battleRIGHTSHIPS + bonusHonor; document.getElementById("honorAmount").innerHTML = honorReward; honor = honor + honorReward; if (project134.flag == 1){ bonusHonor = bonusHonor + 10; } honorCount = 1; } document.getElementById("battleResult").innerHTML = "VICTORY"; document.getElementById("battleResultSign").innerHTML = "+"; document.getElementById("honorDisplay").innerHTML = Math.round(honor).toLocaleString(); } } battleEndDelay++; } else if (numLeftShips <= 4 || numRightShips <= 4) { battleClock = battleClock + 1; if (battleClock>2000){ endBattle(); } } if (battleEndDelay >= battleEndTimer){ endBattle(); } masterBattleClock++; if (masterBattleClock >= 8000){ endBattle(); } } } function endBattle(){ document.getElementById("victoryDiv").style.visibility = "hidden"; honorCount = 0; battleClock = 0; masterBattleClock = 0; battleEndDelay = 0; battles.splice(0,1); } function battleRestart(){ numLeftShips = 0; numRightShips = 0; numShips=0; ships = new Array(); grid = new Array(battleGRID_HEIGHT); //reset the grid var row, col; for (row = 0; row < battleGRID_HEIGHT; row++) { grid[row]= new Array(); for (col = 0; col < battleGRID_WIDTH; col++) { grid[row][col]= new Cell(); } } //create ships... alternate left team and right team so there's no advantage //for array position var leftShipTurn = false; var i=0; while ((numLeftShips battleGRID_WIDTH - 1){ p.gx = battleGRID_WIDTH - 1; } if (p.gy > battleGRID_HEIGHT - 1){ p.gy = battleGRID_HEIGHT - 1; } grid[p.gy][p.gx].add(p); //add ship to this grid cell } } var DoCombat = function(){ var pX = probeCombat * probeCombatBaseRate; // if (battleNameFlag == 1){ // pX = pX*2; // } var dX = drifterCombat; var p; var row,col,i; var numLeftTeam, numRightTeam; var diceRoll; var ooda = 0; if (attackSpeedFlag == 1){ ooda = probeSpeed * .2; } for (row = 0; row < battleGRID_HEIGHT; row++){ for (col = 0; col < battleGRID_WIDTH; col++){ //First Check if there are enough ships in this cell to do combat if (grid[row][col].numShips < 2) continue; numLeftTeam=0; numRightTeam=0; //Now count how many ships for each team in this cell; for (i=0;i=probeCount) { unitSize = probeCount/100; } else { unitSize = drifterCount/100; } if (unitSize<1) {unitSize=1}; document.getElementById('battleScale').innerHTML = numberCruncher(unitSize,0); var rr = Math.random()*drifterCount; if (rr<1){rr=1}; var ss = Math.random()*probeCount; if (ss<1){ss=1}; var tt = Math.random()*availableMatter; battleID++; var newBattle = { id: battleID, clipProbes: ss, drifterProbes: rr, victory: false, loss: false, whiteFlag: 0, territory: tt, reportCount: 0, garbageFlag: 0, } battleLEFTSHIPS = Math.ceil(ss / 1000000); if (battleLEFTSHIPS>200){ battleLEFTSHIPS=200; } if (battleLEFTSHIPS == 200){ var hinder = Math.random(); if (hinder < .50) { battleLEFTSHIPS = Math.ceil(Math.random()*175); } } battleRIGHTSHIPS = Math.ceil(rr / 1000000); if (battleRIGHTSHIPS>200){ battleRIGHTSHIPS=200; } Battle(); battleName = ("Drifter Attack "+newBattle.id); if (battleNameFlag == 1){ battleName = generateBattleName(); } document.getElementById('battleName').innerHTML = battleName; battles.push(newBattle); // battleWrite(newBattle); } var app = new Battle(); app.initialize();