all repos — uStrat @ a630b7683012d6cb73f072f829f4171343c06e09

simple turn-based strategy game inspired by uCity, Super Robot Wars, C&C, Fire Emblem

tweak AI.generatePath() to avoid infinite loops and to push on forward if completely surrounded by high cost tiles; add win/lose conditions for destruction of HQs
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQJDBAABCAAtFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAl1Ldn8PHG5pbGl4QG5p
bGZtLmNjAAoJEDt/vCIUTmOYehMP/3OSW/c1KdtgLMEY54HGomb04qSz/5TOdn2j
GKL8OujXZAjmNb9La0UVRbHDwSRJS1Blhe3EwWJVPqLpV+ztQAuYPhBA93uQhNHY
Ms7qc+cSwcv6SxopLQAsgXROjwuNaGL+ZAGnlhwRgjT0RplP0FqrfcfynXje3CmT
eeI3UrEPPmSGxmnZhW/BQuMOTXJ56mX/IBnS9HetHl5Fvwc8fBxUeL7sp9RB7Xz0
wvHY+seSSIu7fvWn8F86l42S97CM7QSHgvMkp610tOYvCrgba9RFgKHp/LyIiUwu
KaoG8JNvsYNN6ZyXPfRjwYAgGJQZKxDJ0T0hfL2cxH++pNKiacsyRWuigQOyxyE+
zwCLiSSog/gIumAy8cTiR1miH//+p4uT7ZI4daIotxhTF8SFOyyW3r7BFu+hxm4H
0aXH6gMwCrZ8ZOI6hf3ygFey/3E0lvApfJWbM85QX1EdKqhmTnoHTZ9bfviaB0Bw
Dd5RXxSNWqpD5uSNUeSJagQ8hAi7BXkMio1jxYRDJ66d4r2rup0tfqVQfoye03Kp
7XL2blOo0gagakkowvBD6DcYdYJj1a2dFYfc3Tb+z7irC2se1xBXKp950YEaHZGt
YxdACtrsdDFQSVjwqWC9B2QK5BtUwwRF1nBQmAxvdOGk+Y1rKAyo0Vi17afB5ckJ
efWUnzKo
=UTuh
-----END PGP SIGNATURE-----
commit

a630b7683012d6cb73f072f829f4171343c06e09

parent

52186a25550d945fd5ee6e2ac79804b564d82921

4 files changed, 43 insertions(+), 57 deletions(-)

jump to
M AI.jsAI.js

@@ -40,6 +40,10 @@ else if (w/d < 0)

{ bearing += "w"; } + if (d == 0) + { + bearing += "x"; + } return bearing; }

@@ -68,6 +72,7 @@ console.log("AI movement init");

var i, j, k, b, w, x, y, z, q, last; z = "nsew"; last = ""; + i = 0; for (;;) { b = AI.getBearing(movement.chain[movement.chain.length -1], movement.unit.target);

@@ -96,12 +101,27 @@ break;

} while (w.agiMod + 1 >= Math.sqrt(dist(movement.chain[movement.chain.length - 1], movement.unit.target))/2 || !isEmptyObject(w.unit)) { + if (isEmptyObject(w.unit)) + { + // if agiMod of all panels surrounding unit are equal, just keep original path + if (w.agiMod == map.data[x - 1][y].agiMod && + w.agiMod == map.data[x + 1][y].agiMod && + w.agiMod == map.data[x][y + 1].agiMod && + w.agiMod == map.data[x][y - 1].agiMod) + { + console.log(" surrounded by high-cost cells, going straight ahead anyway"); + continue; + } + } + console.log(" going directly to target not ideal"); do { console.log(" trying to go another way"); q = z[AI.rand(4)]; - } while (q == k || q == AI.oppositeDir(last)); + i++; + } while (q == k || q == AI.oppositeDir(last) || i <= 20); + i = 0; switch (q) { case 'n':

@@ -308,6 +328,10 @@ if (teams.cpu.energy/teams.p1.energy > 2 || (teams.cpu.units.length/teams.p1.units.length <= 1.5 && AI.countStructs("cpu factory") == 0) || teams.cpu.structs.length/teams.p1.structs.length >= 1.5)

{ buildFactory() } + else if (AI.countStructs("cpu factory") >= AI.countStructs("cpu armory")) + { + buildArmory(); + } else if (AI.rand(4) < 2) { if (AI.countStructs("cpu factory") <= AI.countStructs("cpu armory"))

@@ -375,7 +399,7 @@ buildBattleAngel();

} else return; } - if (teams.cpu.energy >= 180) + else if (teams.cpu.energy >= 180) { if (AI.rand(4) < 1) {

@@ -387,7 +411,7 @@ buildAce();

} else return; } - if (teams.cpu.energy >= 90) + else if (teams.cpu.energy >= 90) { if (AI.rand(4) < 1) {

@@ -399,7 +423,7 @@ buildKnight();

} else return; } - if (teams.cpu.energy >= 60) + else if (teams.cpu.energy >= 60) { if (AI.rand(4) < 1) {

@@ -411,7 +435,7 @@ buildRanger();

} else return; } - if (teams.cpu.energy >= 30) + else if (teams.cpu.energy >= 30) { if (AI.rand(4) < 3) {

@@ -420,56 +444,6 @@ }

} } - -AI.walkPath = function() -{ - var i, j, k; - for (i = 0; i < teams.cpu.units.length ; i++) - { - AI.assignTarget(teams.cpu.units[i], map.data[16][16]); - AI.generatePath(teams.cpu.units[i]); - while (gameState.flow != "moveFinished") - { - k = new Date(); - if (k - gameState.frame >= 200) - { - gameState.frame = k; - movement.go(); - camera.centerOnCursor(); - camera.manage(); - map.draw(); - mapCursor.draw(); - } - } - gameState.flow = "cpuActions"; - } -} - -AI.actions = [ AI.buildStruct, AI.cycleThruFactories, AI.testPath ]; - -AI.animLoop = function() -{ - this.animCounter++; - if (this.animCounter == 30) - { - this.animCounter = 0; - if (this.fCounter < AI.Q.length) - { - AI.Q[this.fCounter](); - this.fCounter++; - camera.manage(); - camera.centerOnCursor(); - map.draw(); - mapCursor.draw(); - hud.draw(); - } - else - { - this.fCounter = 0; - endPhase(); - } - } -} AI.turnStart = function() {
M Movement.jsMovement.js

@@ -121,7 +121,8 @@ movement.animCounter++;

if (movement.animCounter == 10) { movement.animCounter = 0; - if (movement.chain.length > 1) + if ((!isEmptyObject(movement.unit.equipment) && dist(movement.unit.target, movement.unit) > movement.unit.equipment.range) || movement.chain.length > 1 ) + { movement.chain.shift(); }
M Struct.jsStruct.js

@@ -235,6 +235,14 @@ z = teams.p1;

} else { z = teams.cpu; } w = z.structs.indexOf(map.data[x][y].structure); + if (z.structs[w].name == "p1 HQ") + { + gameState.flow == "youLose"; + } + if (z.structs[w].name == "cpu HQ") + { + gameState.flow == "youWin"; + } z.structs.splice(w, 1); map.data[x][y].structure = {}; }
M Unit.jsUnit.js

@@ -13,7 +13,10 @@ this.cost = 30;

this.hasMoved = false; this.hasAttacked = false; this.name = ""; - this.target = {}; //only used for CPU units + + //only used for CPU units: + this.target = {}; + this.mode = ""; } function mkAce(player, x, y)