animation loop for cpu phase, cpu can build structures and units now
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE----- iQJDBAABCAAtFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAl0K4NkPHG5pbGl4QG5p bGZtLmNjAAoJEDt/vCIUTmOYYrAQAI+k8V12Sf3VQmMUqLdDQw64OEL0tQG0Kqxs YB8fiHmw3OJymobx/vx7mGG5V6OagjKPC0LpV3a3hLle9LClqzfoDqRfW29OY5ug 1MJDEjYOjpWIxAqzp2yeaReSBJ2V47jlTeOJWXJ5siaDHTOdeuEaW/LyEfhKRaQv IJwt10phoUjC7zez+iPkMtVfbYjTTOWAbevkhWxel6q/y8M9KfdblRGz1LRWeCwv XWC9rBu6DZOjrlOLc+gFz7tO5ihpErqDc+sNwuPsNGOt47CAxC2ioVr+idHzEqD6 vWtfHaKtFUgz1Ya0MeEGjRLhExgosJZkNjs1vo3J+IVQKzDKfotW+Y6e6E2zwLbC IjdeAsaINgSKSYaj/2QJp18jDu8i2EKM7WE0Rnle58m0hjSkJrs/guulNk7Q8Jl7 PA9fjFSN62HIRfNJLL/a4E14PFtd9asgCvvZNs7ZlwkL9lQIrMbY9hgfNy0qiIiM kHjso+6pJTBOj6YiKc+fptz1YzHUH+u/e5Trru96yk8mZy1g+ecYdoegwhzJRXg5 k44GHxAFKYRYXAem7cv5FkmtNit6eyExwS1HvYi++kfjvaGqJBYdSWbJjQok7iTP Hoxsm9u0u7SjjK1MVphgZlrJdvWC7tZDv7QCk07DmWaIblHrbGa4DpZi+LRvJOXf OHxfvMtp =3sQ3 -----END PGP SIGNATURE-----
M
AI.js
→
AI.js
@@ -109,7 +109,7 @@ }
AI.buildStruct = function() { - var cell = this.findNewStruct(); + var cell = AI.findNewStruct(); mapCursor.x = cell.x; mapCursor.y = cell.y; switch (cell.type)@@ -122,7 +122,7 @@ if (teams.cpu.energy >= 40)
{ if (AI.rand(4) < 2) { - if (AI.rand(4) < 2) + if (AI.rand(4) < 3) { buildFactory(); }@@ -151,9 +151,116 @@ break;
} } +AI.cycleThruFactories = function() +{ + var l = teams.cpu.structs.length; + var i, s; + for (i = 0; i < l; i++) + { + s = teams.cpu.structs[i]; + if (s.name == "cpu factory") + { + mapCursor.x = s.x; + mapCursor.y = s.y; + AI.buildUnits(); + } + } +} + +AI.buildUnits = function() +{ + if (AI.rand(5) < 3) + { + return; + } + if (teams.cpu.energy >= 300) + { + if (AI.rand(4) < 1) + { + buildBlitzWalker(); + } + else if (AI.rand(4) < 1) + { + buildBattleAngel(); + } + else return; + } + if (teams.cpu.energy >= 180) + { + if (AI.rand(4) < 1) + { + buildBattleAngel(); + } + else if (AI.rand(4) < 1) + { + buildAce(); + } + else return; + } + if (teams.cpu.energy >= 90) + { + if (AI.rand(4) < 1) + { + buildAce(); + } + else if (AI.rand(4) < 1) + { + buildKnight(); + } + else return; + } + if (teams.cpu.energy >= 60) + { + if (AI.rand(4) < 1) + { + buildKnight(); + } + else if (AI.rand(4) < 1) + { + buildRanger(); + } + else return; + } + if (teams.cpu.energy >= 30) + { + if (AI.rand(4) < 2) + { + buildRanger(); + } + } +} + +AI.animCounter = 0; +AI.fCounter = 0; +AI.actions = [ AI.cycleThruFactories, AI.buildStruct, AI.cycleThruFactories ]; +AI.Q = {} + +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.main = function() { -// this.deliberatePriority(); - this.buildStruct(); - endPhase(); + AI.Q = AI.actions; + AI.animLoop(); }
M
Unit.js
→
Unit.js
@@ -71,7 +71,7 @@ teams.p1.energy -= teams.p1.units[teams.p1.units.length - 1].cost;
resetFlow(); break; case "cpu": - teams.cpu.structs.push(mkRanger("cpu", mapCursor.x, mapCursor.y)); + teams.cpu.units.push(mkRanger("cpu", mapCursor.x, mapCursor.y)); teams.cpu.energy -= teams.cpu.units[teams.cpu.units.length - 1].cost; break; }@@ -105,7 +105,7 @@ teams.p1.energy -= teams.p1.units[teams.p1.units.length - 1].cost;
resetFlow(); break; case "cpu": - teams.cpu.structs.push(mkKnight("cpu", mapCursor.x, mapCursor.y)); + teams.cpu.units.push(mkKnight("cpu", mapCursor.x, mapCursor.y)); teams.cpu.energy -= teams.cpu.units[teams.cpu.units.length - 1].cost; break; }@@ -139,7 +139,7 @@ teams.p1.energy -= teams.p1.units[teams.p1.units.length - 1].cost;
resetFlow(); break; case "cpu": - teams.cpu.structs.push(mkBattleAngel("cpu", mapCursor.x, mapCursor.y)); + teams.cpu.units.push(mkBattleAngel("cpu", mapCursor.x, mapCursor.y)); teams.cpu.energy -= teams.cpu.units[teams.cpu.units.length - 1].cost; break; }@@ -173,7 +173,7 @@ teams.p1.energy -= teams.p1.units[teams.p1.units.length - 1].cost;
resetFlow(); break; case "cpu": - teams.cpu.structs.push(mkBlitzWalker("cpu", mapCursor.x, mapCursor.y)); + teams.cpu.units.push(mkBlitzWalker("cpu", mapCursor.x, mapCursor.y)); teams.cpu.energy -= teams.cpu.units[teams.cpu.units.length - 1].cost; break; }