-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmine.js
52 lines (38 loc) · 1.76 KB
/
mine.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
let mine = {
run: function(creep) {
let sourceTarget = creep.memory.source;
if (sourceTarget == 0) {
let pos0 = new RoomPosition(
creep.room.memory.mine0x, creep.room.memory.mine0y, creep.room.name)
if (!creep.pos.isEqualTo(pos0)) {
creep.moveTo(pos0, {maxRooms:1}, {reusePath:50});
} else {
let sources = creep.room.find(FIND_SOURCES);
if (creep.harvest(sources[sourceTarget]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[sourceTarget], {maxRooms:1}, {reusePath:50});
}
}
} else {
let pos1 = new RoomPosition(
creep.room.memory.mine1x, creep.room.memory.mine1y, creep.room.name)
if (!creep.pos.isEqualTo(pos1)) {
creep.moveTo(pos1, {maxRooms:1}, {reusePath:50});
} else {
let sources = creep.room.find(FIND_SOURCES);
if (creep.harvest(sources[sourceTarget]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[sourceTarget], {maxRooms:1}, {reusePath:50});
}
}
}
if (creep.carryCapacity > 0 && creep.carry[RESOURCE_ENERGY] == creep.carryCapacity){
let thisLink = creep.pos.findClosestByRange(FIND_MY_STRUCTURES, {
filter: (thing) => thing.structureType == STRUCTURE_LINK &&
thing.energy < thing.energyCapacity
});
if (thisLink){
creep.transfer(thisLink, RESOURCE_ENERGY);
}
}
}
};
module.exports = mine;