-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsourcefinder.js
32 lines (31 loc) · 1.13 KB
/
sourcefinder.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
let sourceFinder = {
findAvailableSource: (creep) => {
let room = creep.room;
let activeSources = room.find(FIND_SOURCES_ACTIVE);
let availableSources = [];
activeSources.forEach((item, index) => {
let available = false;
let sourceLocation = item.pos;
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
let location = room.lookAt(sourceLocation.x - 1 + i, sourceLocation.y - 1 + j);
let microAvailable = true;
location.forEach((item, index) => {
if ((item.type === 'terrain' && item.terrain !== 'plain') || item.type === 'creep') {
microAvailable = false;
}
});
if (microAvailable) {
available = true;
break;
}
}
}
if (available) {
availableSources.push(item)
}
});
return availableSources;
}
};
module.exports = sourceFinder;