-
Notifications
You must be signed in to change notification settings - Fork 0
/
spawner.default.js
47 lines (44 loc) · 1.77 KB
/
spawner.default.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
module.exports = {
/** @param {StructureSpawn} spawn **/
run: function(spawn) {
var body = null;
var role = null;
var harvesters = _.filter(Game.creeps, (creep) => creep.memory.role == 'harvester');
var transporters = _.filter(Game.creeps, (creep) => creep.memory.role == 'transporter');
var builders = _.filter(Game.creeps, (creep) => creep.memory.role == 'builder');
var upgraders = _.filter(Game.creeps, (creep) => creep.memory.role == 'upgrader');
Memory.info = {
transporters: transporters.length,
harvesters: harvesters.length,
upgraders: upgraders.length,
builders: builders.length,
};
if (harvesters.length + transporters.length < 4) {
if (harvesters.length <= transporters.length * 3) {
body = [WORK,WORK,CARRY,MOVE];
role = 'harvester';
} else {
body = [CARRY,CARRY,CARRY,MOVE,MOVE,MOVE];
role = 'transporter';
}
} else {
if (builders.length < 1) {
body = [WORK,WORK,CARRY,MOVE];
role = 'builder';
}
else if (upgraders.length < 2) {
body = [WORK,WORK,CARRY,CARRY,MOVE,MOVE];
role = 'upgrader';
}
}
if (body/*spawn.canCreateCreep(body)*/) {
var result = spawn.createCreep(body, undefined, {role:role});
if(_.isString(result)) {
console.log('Spawning new (' + role + ': ' + body.join(',') + '): ' + result);
}
else {
console.log('Spawn error: '+ result + ' (' + role + ': ' + body.join(',') + ')');
}
}
}
};