-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreepGenerator.js
97 lines (88 loc) · 2.72 KB
/
creepGenerator.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
let creepGenerator = {
run: function () {
let maxUpgrader = 1;
let maxHarvester = 3;
let maxBuilder = 3;
let maxWarrior = 3;
let maxTransfer = 0;
let amountUpgrader = 0;
let amountHarvester = 0;
let amountBuilder = 0;
let amountWarrior = 0;
let amountTransfer = 0;
for (let name in Game.creeps) {
let creep = Game.creeps[name];
if (creep.memory.role == "upgrader") {
amountUpgrader += 1;
} else if (creep.memory.role == "harvester") {
amountHarvester += 1;
} else if (creep.memory.role == "builder") {
amountBuilder += 1;
} else if (creep.memory.role == "warrior") {
amountWarrior += 1;
} else if (creep.memory.role == "transfer") {
amountTransfer += 1;
}
// TODO: Creating an "Heal" Creep
// IDEA: Maybe give creeps an Level, so an living creep can be killed for an updated one.
}
let creepName = "Creep" + Game.time;
if (amountHarvester < maxHarvester) {
if (Game.spawns["Spawn1"].room.energyCapacityAvailable < 400) {
Game.spawns["Spawn1"].spawnCreep([WORK, MOVE, CARRY], creepName, {
memory: { role: "harvester", upgrading: false },
});
} else if (Game.spawns["Spawn1"].room.energyCapacityAvailable >= 400) {
Game.spawns["Spawn1"].spawnCreep(
[WORK, WORK, MOVE, MOVE, CARRY, CARRY],
creepName,
{
memory: { role: "harvester", upgrading: false },
}
);
}
}
if (amountUpgrader < maxUpgrader) {
if (Game.spawns["Spawn1"].room.energyCapacityAvailable < 400) {
Game.spawns["Spawn1"].spawnCreep([WORK, MOVE, CARRY], creepName, {
memory: { role: "upgrader", upgrading: false },
});
} else if (Game.spawns["Spawn1"].room.energyCapacityAvailable >= 400) {
Game.spawns["Spawn1"].spawnCreep(
[WORK, WORK, MOVE, MOVE, CARRY, CARRY],
creepName,
{
memory: { role: "upgrader", upgrading: false },
}
);
}
}
if (amountBuilder < maxBuilder) {
if (Game.spawns["Spawn1"].room.energyCapacityAvailable < 400) {
Game.spawns["Spawn1"].spawnCreep([WORK, MOVE, CARRY], creepName, {
memory: { role: "builder", building: false },
});
} else if (Game.spawns["Spawn1"].room.energyCapacityAvailable >= 400) {
Game.spawns["Spawn1"].spawnCreep(
[WORK, WORK, MOVE, MOVE, CARRY, CARRY],
creepName,
{
memory: { role: "builder", building: false },
}
);
}
}
// TODO: Warrior is still very weak, has to be updated
if (amountWarrior < maxWarrior) {
Game.spawns["Spawn1"].spawnCreep([MOVE, ATTACK, ATTACK], creepName, {
memory: { role: "warrior" },
});
}
if (amountTransfer < maxTransfer) {
Game.spawns["Spawn1"].spawnCreep([MOVE, CARRY, CARRY], creepName, {
memory: { role: "transfer" },
});
}
},
};
module.exports = creepGenerator;