-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsources.js
More file actions
56 lines (47 loc) · 1.6 KB
/
Copy pathsources.js
File metadata and controls
56 lines (47 loc) · 1.6 KB
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
53
54
55
56
var sources = {
/**@param {Room} room */
init: function(room) {
var sources = room.find(FIND_SOURCES);
for (var i = 0; i < sources.length; i++) {
var source = sources[i];
console.log(source.id);
if (!room.memory.sources) room.memory.sources = {};
room.memory.sources[source.id] = this.getSourceWorkersLimitation(source);
}
},
getSourceWorkersLimitation: function (source) {
var center = source.pos;
var terrain = source.room.getTerrain();
var top = terrain.get(center.x, center.y - 1);
var right = terrain.get(center.x + 1, center.y);
var bottom = terrain.get(center.x, center.y + 1);
var left = terrain.get(center.x - 1, center.y);
var leftTop = terrain.get(center.x - 1, center.y - 1);
var rightTop = terrain.get(center.x + 1, center.y - 1);
var rightBottom = terrain.get(center.x + 1, center.y + 1);
var leftBottom = terrain.get(center.x - 1, center.y + 1);
var round = [
top,
right,
bottom,
left,
leftTop,
rightTop,
rightBottom,
leftBottom,
];
var count = 0;
for (var i = 0; i < round.length; i++) {
switch (round[i]) {
case TERRAIN_MASK_WALL:
count++;
break;
case TERRAIN_MASK_SWAMP:
count++;
break;
}
}
return 8 - count;
}
};
module.exports = sources;