-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstructure.link.js
41 lines (35 loc) · 1.39 KB
/
structure.link.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
var structureLink = {
run: function (room) {
var closesToStructure = ""
var spawn = room.find(FIND_STRUCTURES, {
filter: (structure) => {
return structure.structureType === STRUCTURE_SPAWN
}
});
var links = room.find(FIND_STRUCTURES, {
filter: (structure) => {
return structure.structureType === STRUCTURE_LINK;
}
});
if (links.length > 0 && spawn.length > 0) {
for (let x = 0; x < links.length; x++) {
if (closesToStructure === "") {
closesToStructure = links[x]
} else {
//console.log(spawn[0].pos + " " + links[x].pos + " " + closesToStructure.pos)
if (PathFinder.search(spawn[0].pos, links[x].pos).cost < PathFinder.search(spawn[0].pos, closesToStructure.pos).cost) {
closesToStructure = links[x]
}
}
}
for (let x = 0; x < links.length; x++) {
if (closesToStructure !== "") {
if(closesToStructure.energy + 10 <= closesToStructure.energyCapacity) {
links[x].transferEnergy(closesToStructure);
}
}
}
}
}
};
module.exports = structureLink;