-
Notifications
You must be signed in to change notification settings - Fork 0
/
nomad.js
47 lines (46 loc) · 1.49 KB
/
nomad.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 = function (creep) {
if(creep.fatigue > 0)return;
if(creep.energy == 0 || creep.memory.task == "harvest") {
creep.memory.task = "harvest";
if(creep.room != Game.flags.nomad.room) {
creep.moveTo(Game.flags.nomad);
return;
}
else {
if(creep.memory.target == undefined) {
creep.memory.target = Game.flags.nomad.pos.findClosest(FIND_SOURCES);
if(target == null) {
flag = Game.flags.nomadSource;
target = flag.room.lookForAt('source', flag.pos);
}
}
var target = creep.memory.target;
target = Game.getObjectById(target.id);
creep.moveTo(target);
creep.harvest(target);
}
if(creep.energy == creep.energyCapacity) {
creep.memory.task = "work";
}
}
else {
var sites = creep.room.find(FIND_CONSTRUCTION_SITES);
if(sites.length > 0) {
creep.moveTo(sites[0]);
creep.build(sites[0]);
}
else {
var ctrl = Game.flags.nomad.room.controller;
creep.moveTo(ctrl);
if(Game.flags.nomad.color == COLOR_RED){
creep.unclaimController(ctrl);
}
else if(ctrl.my == false) {
creep.claimController(ctrl);
}
else {
creep.upgradeController(ctrl);
}
}
}
};