-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharvester.js
32 lines (30 loc) · 1.03 KB
/
harvester.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
module.exports = function (creep) {
if(creep.carry.energy < creep.carryCapacity) {
var droppedEnergy = creep.pos.findClosest(FIND_DROPPED_ENERGY);
if (droppedEnergy != null) {
creep.moveTo(droppedEnergy);
creep.pickup(droppedEnergy);
return;
}
var source = creep.pos.findClosest(FIND_SOURCES);
if (source != null) {
creep.moveTo(source);
creep.harvest(source);
return;
}
} else {
var structures = creep.room.find(FIND_MY_STRUCTURES);
for (var i in structures) {
var structure = structures[i];
if (structure.structureType == STRUCTURE_EXTENSION) {
if (structure.energy < structure.energyCapacity) {
creep.moveTo(structure);
creep.transferEnergy(structure);
return;
}
}
}
creep.moveTo(Game.spawns.Spawn1);
creep.transferEnergy(Game.spawns.Spawn1)
}
}