Team.js (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
// Team.js & uStrat (c) Derek Stevens <nilix@nilfm.cc> // this file contains data structures and basic functions // relating to the Teams (ie P1 and CPU) function defTeams() { this.p1 = {}; this.cpu = {}; this.data = new Array(2); this.data[0] = this.p1; this.data[1] = this.cpu; let i; for (i = 0; i < 2; i++) { this.data[i].units = new Array(); this.data[i].structs = new Array(); this.data[i].energy = 35; switch (i) { case 0: this.data[i].structs.push(mkHQ("p1")); break; case 1: this.data[i].structs.push(mkHQ("cpu")); break; } } } function subtractCost(player, item) { switch (player) { case "p1": teams.p1.energy -= item.cost; break; case "cpu": teams.cpu.energy -= item.cost; break; } } function getIndex(player, type, obj) { let x, y, z, i; switch (player) { case "p1": x = teams.p1; break; case "cpu": x = teams.cpu; break; } switch (type) { case "struct": y = x.structs; break; case "unit": y = x.units; break; } i = 0; for (z in y) { if (obj.x == z.x && obj.y == z.y) { return i; } i++; } // assuming you passed in valid arguments and a real object into this // function, you should never return -1. return -1; } |