-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
39 lines (33 loc) · 898 Bytes
/
main.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
var harvester = require('harvester');
module.exports.loop = function () {
for(var name in Game.creeps) {
var creep = Game.creeps[name];
if(creep.memory.role == 'harvester') {
harvester(creep);
}
if(creep.memory.role == 'guard') {
var targets = creep.room.find(FIND_HOSTILE_CREEPS);
if(targets.length) {
if(creep.attack(targets[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0]);
}
}
}
if(creep.memory.role == 'builder') {
if(creep.carry.energy == 0) {
if(Game.spawns.Spawn1.transferEnergy(creep) == ERR_NOT_IN_RANGE) {
creep.moveTo(Game.spawns.Spawn1);
}
}
else {
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
if(targets.length) {
if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0]);
}
}
else { harvester(creep);}
}
}
}
}