all repos — uStrat @ 3752d617f7d8ccbdd2039d27fc83ad517bbb5e0e

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

use null instead of empty object
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmDNi28ACgkQO3+8IhRO
Y5iuKBAAk8sQ1FJiLj2aRZa+w3w1JsXfCrKg1d9y8qjMmhooeEM0k1wftDDz7+dB
PGxLv4DKs7fVcgcHazLkNFXjjScbwSKz5PEgMUFRNhHbdwnHs1g7hrSwtC4EL2lY
Q8GDmazAaFJdnYJxkTxnhh7ia6axLdqJFLZderBjD5+Zx1TQBVwmIb5J7Ozmk4T4
5uPrWL6QjlJ1SP6Cnt6uVXPdK01NHdS86WRfOWg3x8ZLnXa2hHz3BP4bbZ+F7Cnc
Uw8gb0fAF+rt6NfiDc2KepYXGyvGBTC/cEVu1tnQG9lQg9oRZFuDze3d/is2p3cE
JytsOC8JRsVeuBY16aI1MUvp4OwAW5rqno1MBWbVPWfgIkuUqcEFGrAUIhZWY7eT
D7rysqc6WLv4lCOBBqqrQo8457GMzfEOn2tzNyviraCp46KsrWIbvQgBU2CvowWJ
DXmd6elSgES+MzLoVYTtO/I8F76lKHAKrDXn7rLrkwHaOro5FaXgcCqXf0H61XwF
tyIWWiYAB/qm9LhgHIwWpokL/9y5Zgcg3M/JYsHj4Ww8skefJlnZceg4q+PkyXq+
8L3tDvX4tDy3cPGpgRTIMHsUeAGGyV2F2fmAHjPZ+OY9Aj1Y3lb1QhpqyauzPIOa
lH0qegd0I0uWK4nMD6O9/Id47jMhIqH3lcfi0rdJP9X+kTE0Hlk=
=DYbZ
-----END PGP SIGNATURE-----
commit

3752d617f7d8ccbdd2039d27fc83ad517bbb5e0e

parent

ab6804a552abfab34d0ea6245329c89039c1c889

8 files changed, 56 insertions(+), 56 deletions(-)

jump to
M AI.jsAI.js

@@ -125,7 +125,7 @@ j = 0;

for (i = 0; i < teams.p1.units.length; i++) { tmp = teams.p1.units[i]; - if (isEmptyObject(tmp.equipment)) + if (tmp.equipment === null) k = tmp.hp*tmp.pow/tmp.def; else k = tmp.hp*(tmp.pow + tmp.equipment.grade)/tmp.def;

@@ -180,7 +180,7 @@ // if struct is already defense target of another AI unit, skip it!

for (x = 0; x < teams.cpu.units.length; x++) { - if ( !isEmptyObject(teams.cpu.units[x].target) && + if (teams.cpu.units[x].target !== null && teams.cpu.units[x].target.x == teams.cpu.structs[i].x && teams.cpu.units[x].target.y == teams.cpu.structs[i].y) {

@@ -263,7 +263,7 @@ j = 99999;

for (i = 0; i < teams.cpu.structs.length; i++) { if (teams.cpu.structs[i].name == "cpu armory" && - isEmptyObject(map.data[teams.cpu.structs[i].x][teams.cpu.structs[i].y].unit)) + map.data[teams.cpu.structs[i].x][teams.cpu.structs[i].y].unit === null) { k = dist(teams.cpu.structs[i], u); if (k < j)

@@ -306,33 +306,33 @@

switch (z) { case 0: - while (teams.cpu.energy >= 12 && (isEmptyObject(unit.equipment) || unit.equipment.grade < unit.equipment.limit)) + while (teams.cpu.energy >= 12 && unit.equipment === null || unit.equipment.grade < unit.equipment.limit)) { equipOrUpgradeRifleMKI(); } break; case 1: - while (teams.cpu.energy >= 15 && (isEmptyObject(unit.equipment) || unit.equipment.grade < unit.equipment.limit)) + while (teams.cpu.energy >= 15 && unit.equipment === null || unit.equipment.grade < unit.equipment.limit)) { equipOrUpgradeBeamSabreMKI(); } break; case 2: - while (teams.cpu.energy >= 45 && (isEmptyObject(unit.equipment) || unit.equipment.grade < unit.equipment.limit)) + while (teams.cpu.energy >= 45 && unit.equipment === null || unit.equipment.grade < unit.equipment.limit)) { equipOrUpgradeBeamCannon(); } break; case 3: - while (teams.cpu.energy >= 80 && (isEmptyObject(unit.equipment) || unit.equipment.grade < unit.equipment.limit)) + while (teams.cpu.energy >= 80 && unit.equipment === null || unit.equipment.grade < unit.equipment.limit)) { equipOrUpgradeHellBomb(); } break; } - if (!isEmptyObject(unit.equipment)) + if (unit.equipment !== null) { - unit.target = {}; + unit.target = null; } }

@@ -348,7 +348,7 @@ if (movement.unit.mode == "defend" && dist(movement.unit.target, movement.unit) == 0)

{ return; } - else if (!isEmptyObject(movement.unit.equipment) && dist(movement.unit.target, movement.unit) <= movement.unit.equipment.range) + else if movement.unit.equipment !== null && dist(movement.unit.target, movement.unit) <= movement.unit.equipment.range) { return; }

@@ -418,7 +418,7 @@ if (movement.unit.mode == "defend" && dist(movement.unit.target, movement.unit) == 0)

{ return; } - else if (!isEmptyObject(movement.unit.equipment) && dist(movement.unit.target, movement.unit) <= movement.unit.equipment.range) + else if (movement.unit.equipment !== null && dist(movement.unit.target, movement.unit) <= movement.unit.equipment.range) { return; }

@@ -452,9 +452,9 @@ case 'w':

w = map.data[x - 1][y]; break; } - while ((w.agiMod + 1 >= Math.sqrt(dist(movement.chain[movement.chain.length - 1], movement.unit.target))/2 && dist(movement.chain[movement.chain.length - 1], movement.unit.target) >= 10) || !isEmptyObject(w.unit)) + while ((w.agiMod + 1 >= Math.sqrt(dist(movement.chain[movement.chain.length - 1], movement.unit.target))/2 && dist(movement.chain[movement.chain.length - 1], movement.unit.target) >= 10) || w.unit !== null) { - if (isEmptyObject(w.unit)) + if (w.unit === null) { // if agiMod of all panels surrounding unit are equal, just keep original path if (w.agiMod == map.data[x - 1][y].agiMod &&

@@ -550,7 +550,7 @@ for (i = 0; i < map.sz; i++)

{ for (j = origin.y; j < map.sz; j++) { - if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) + if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 &&map.data[i][j].structure === null) { console.log(i + ", " + j); return map.data[i][j]; }

@@ -562,7 +562,7 @@ for (i = map.sz - 1; i >= 0; i--)

{ for (j = origin.y; j >= 0; j--) { - if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) + if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && map.data[i][j].structure === null) { console.log(i + ", " + j); return map.data[i][j]; }

@@ -574,7 +574,7 @@ for (i = origin.x; i < map.sz; i++)

{ for (j = 0; j < map.sz; j++) { - if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) + if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && map.data[i][j].structure === null) { console.log(i + ", " + j); return map.data[i][j]; }

@@ -586,7 +586,7 @@ for (i = origin.x; i >= 0; i--)

{ for (j = map.sz - 1; j >= 0; j--) { - if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) + if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && map.data[i][j].structure === null) { console.log(i + ", " + j); return map.data[i][j]; }

@@ -611,7 +611,7 @@ for (i = 0; i < map.sz; i++)

{ for (j = 0; j < map.sz; j++) { - if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) + if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && map.data[i][j].structure === null) { console.log(i + ", " + j); return map.data[i][j]; }

@@ -624,7 +624,7 @@ for (i = map.sz - 1; i >= 0; i--)

{ for (j = map.sz - 1; j >= 0; j--) { - if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) + if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && map.data[i][j].structure === null) { console.log(i + ", " + j); return map.data[i][j]; }

@@ -637,7 +637,7 @@ for (i = map.sz - 1; i >= 0; i--)

{ for (j = 0; j < map.sz; j++) { - if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) + if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && map.data[i][j].structure === null) { console.log(i + ", " + j); return map.data[i][j]; }

@@ -650,7 +650,7 @@ for (i = 0; i < map.sz; i++)

{ for (j = map.sz - 1; j >= 0; j--) { - if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) + if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && map.data[i][j].structure === null) { console.log(i + ", " + j); return map.data[i][j]; }

@@ -666,7 +666,7 @@ var i, j, k;

for (i = 0; i < teams.cpu.units.length; i++) { j = map.data[teams.cpu.units[i].x][teams.cpu.units[i].y]; - if (isEmptyObject(teams.cpu.units[i].equipment) && !isEmptyObject(j.structure) && j.structure.name == "cpu armory") + if (teams.cpu.units[i].equipment === null && j.structure !== null && j.structure.name == "cpu armory") { mapCursor.x = j.x; mapCursor.y = j.y;

@@ -750,7 +750,7 @@ if (s.name == "cpu factory")

{ mapCursor.x = s.x; mapCursor.y = s.y; - if (isEmptyObject(map.data[s.x][s.y].unit)) + if (map.data[s.x][s.y].unit === null) { AI.buildUnits(); }
M Engine.jsEngine.js

@@ -192,12 +192,12 @@ if (teams.cpu.units[AI.focus].attentionSpan == 0)

{ teams.cpu.units[AI.focus].target = {}; } - if (isEmptyObject(teams.cpu.units[AI.focus].equipment)) + if (teams.cpu.units[AI.focus].equipment === null) { teams.cpu.units[AI.focus].target = AI.getClosestArmory(teams.cpu.units[AI.focus]); teams.cpu.units[AI.focus].mode = "defend"; } - else if (isEmptyObject(teams.cpu.units[AI.focus].target)) + else if (teams.cpu.units[AI.focus].target === null) { AI.setTargetType(); AI.findTarget();

@@ -237,7 +237,7 @@ if (AI.focus >= teams.cpu.units.length)

{ AI.focus = 0; AI.manageEquipment(); - if (!isEmptyObject(teams.cpu.units[AI.focus].equipment)) + if (teams.cpu.units[AI.focus].equipment !== null) { mapCursor.x = teams.cpu.units[AI.focus].x; mapCursor.y = teams.cpu.units[AI.focus].y;
M Equipment.jsEquipment.js

@@ -56,7 +56,7 @@ function equipOrUpgradeBeamSabreMKI()

{ var unit = map.data[mapCursor.x][mapCursor.y].unit; var m = false; - if (isEmptyObject(unit.equipment) || unit.equipment.name != "Beam Sabre mkI") + if (unit.equipment === null || unit.equipment.name != "Beam Sabre mkI") { unit.equipment = beamSabreMKI(); }

@@ -103,7 +103,7 @@ function equipOrUpgradeRifleMKI()

{ var unit = map.data[mapCursor.x][mapCursor.y].unit; var m = false; - if (isEmptyObject(unit.equipment) || unit.equipment.name != "Rifle mkI") + if (unit.equipment === null || unit.equipment.name != "Rifle mkI") { unit.equipment = rifleMKI(); }

@@ -148,7 +148,7 @@ function equipOrUpgradeBeamCannon()

{ var unit = map.data[mapCursor.x][mapCursor.y].unit; var m = false; - if (isEmptyObject(unit.equipment) || unit.equipment.name != "Beam Cannon") + if (unit.equipment === null || unit.equipment.name != "Beam Cannon") { unit.equipment = beamCannon(); }

@@ -193,7 +193,7 @@ function equipOrUpgradeHellBomb()

{ var unit = map.data[mapCursor.x][mapCursor.y].unit; var m = false; - if (isEmptyObject(unit.equipment) || unit.equipment.name != "Hell Bomb") + if (unit.equipment === null || unit.equipment.name != "Hell Bomb") { unit.equipment = hellBomb(); }
M Map.jsMap.js

@@ -75,7 +75,7 @@ screen.fillText("U: " + teams.p1.units.length + "/" + teams.cpu.units.length, 235, 50);

screen.drawImage(hud.gfx.cycleModes[mapCursor.cycleMode], 85, 5); - if (!isEmptyObject(currentCell.structure)) + if (currentCell.structure !== null) { screen.drawImage(hud.gfx.structWindow, 5, 135); screen.fillText(currentCell.structure.name, 10, 140);

@@ -83,7 +83,7 @@ screen.fillText("HP: " + currentCell.structure.hp + "/" + currentCell.structure.maxHP, 10, 150);

screen.fillText("E: " + currentCell.structure.energy + "@" + currentCell.structure.rate, 10, 160); } - if (!isEmptyObject(currentCell.unit)) + if (currentCell.unit !== null) { screen.drawImage(hud.gfx.unitWindow, 5, 55); screen.fillText(currentCell.unit.name, 10, 60);

@@ -92,7 +92,7 @@ screen.fillText("pow: " + currentCell.unit.pow, 10, 80);

screen.fillText("def: " + currentCell.unit.def, 10, 90); screen.fillText("agi: " + currentCell.unit.agi, 10, 100); var equipString; - if (!isEmptyObject(currentCell.unit.equipment)) + if (currentCell.unit.equipment !== null) { equipString = currentCell.unit.equipment.name; if (currentCell.unit.equipment.grade > 0)

@@ -228,13 +228,13 @@ map.cell = function(x, y)

{ this.x = x; this.y = y; - this.sprite = {}; + this.sprite = null; this.agiMod = 0; this.defMod = 0; this.flag = 0; this.type = "null"; - this.structure = {}; - this.unit = {}; + this.structure = null; + this.unit = null; } map.degradeCell = function(self)

@@ -314,11 +314,11 @@ {

if (camera.y + j < map.sz) { screen.drawImage(map.data[camera.x + i][camera.y + j].sprite, 16*i, 16*j); - if (!isEmptyObject(map.data[camera.x + i][camera.y + j].structure)) + if (map.data[camera.x + i][camera.y + j].structure !== null) { screen.drawImage(map.data[camera.x + i][camera.y + j].structure.sprite, 16*i, 16*j); } - if (!isEmptyObject(map.data[camera.x + i][camera.y + j].unit)) + if (map.data[camera.x + i][camera.y + j].unit !== null) { screen.drawImage(map.data[camera.x + i][camera.y + j].unit.sprite, 16*i, 16*j); }
M Movement.jsMovement.js

@@ -38,7 +38,7 @@ }

movement.listen = function() { - var z = {}; + var z = null; var chainEnd = this.chain[this.chain.length - 1]; this.ticker = new Date(); if (controller.z)

@@ -87,9 +87,9 @@ z = new Coords(chainEnd.x + 1, chainEnd.y);

} this.lastMove = this.ticker; } - if (!isEmptyObject(z)) + if (z !== null) { - if (map.data[z.x][z.y].agiMod <= this.pool && z.x >= 0 && z.x < 64 && z.y >= 0 && z.y < 64 && isEmptyObject(map.data[z.x][z.y].unit)) + if (map.data[z.x][z.y].agiMod <= this.pool && z.x >= 0 && z.x < map.sz && z.y >= 0 && z.y < map.sz && map.data[z.x][z.y].unit === null) { if (this.unit.name != "p1 Battle Angel") {

@@ -133,7 +133,7 @@ }

else { movement.unit.hasMoved = true; - movement.unit = {}; + movement.unit = null; movement.chain = new Array(); movement.pool = 0; if (gameState.phase == "p1")

@@ -149,7 +149,7 @@ if (movement.chain.length > 0 && movement.unit.target != undefined)

moveToTile(movement.unit, movement.chain[0]); else{ movement.unit.hasMoved = true; - movement.unit = {}; + movement.unit = null; movement.chain = new Array(); movement.pool = 0; if (gameState.phase == "p1")

@@ -168,7 +168,7 @@ function moveToTile(unit, tile)

{ var oX, oY, tmp; - tmp = {}; + tmp = null; if (dist(unit, tile) < 1) { return;

@@ -176,7 +176,7 @@ }

oX = unit.x; oY = unit.y; - if (!isEmptyObject(map.data[tile.x][tile.y].unit)) + if (map.data[tile.x][tile.y].unit !== null) { tmp = map.data[tile.x][tile.y].unit; }
M Struct.jsStruct.js

@@ -221,7 +221,7 @@ }

function damageStruct(x, y) { - if (isEmptyObject(map.data[x][y].unit) && !isEmptyObject(map.data[x][y].structure)) + if (map.data[x][y].unit === null && map.data[x][y].structure !== null) { map.data[x][y].structure.hp = map.data[x][y].structure.hp - (attack.src.pow + attack.src.equipment.grade); if (map.data[x][y].structure.hp <= 0)

@@ -251,5 +251,5 @@ {

gameState.flow = "youWin"; } z.structs.splice(w, 1); - map.data[x][y].structure = {}; + map.data[x][y].structure = null; }
M Unit.jsUnit.js

@@ -192,7 +192,7 @@ }

function damageUnit(x,y) { - if (!isEmptyObject(map.data[x][y].unit)) + if (map.data[x][y].unit !== null) { map.data[x][y].unit.hp = map.data[x][y].unit.hp - (attack.src.pow + attack.src.equipment.grade); if (map.data[x][y].unit.hp <= 0)

@@ -213,5 +213,5 @@ }

else { z = teams.cpu; } w = z.units.indexOf(map.data[x][y].unit); z.units.splice(w, 1); - map.data[x][y].unit = {}; + map.data[x][y].unit = null; }