-
Notifications
You must be signed in to change notification settings - Fork 0
/
prototype.pos.js
34 lines (27 loc) · 1.09 KB
/
prototype.pos.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
let cardinal_dirs = [[1,0],[-1,0],[0,1],[0,-1]];
let diagonal_dirs = [[1,1],[1,-1],[-1,1],[-1,-1]];
RoomPosition.prototype.diagonals = function() {
let positions = [];
for(let d of diagonal_dirs){
positions.push(new RoomPosition(this.x+d[0], this.y+d[1], this.roomName));
}
return positions;
};
RoomPosition.prototype.cardinals = function() {
let positions = [];
for(let d of cardinal_dirs){
positions.push(new RoomPosition(this.x+d[0], this.y+d[1], this.roomName));
}
return positions;
};
RoomPosition.prototype.adjacent = function() {
return this.diagonals().concat(this.cardinals());
};
RoomPosition.prototype.occupied = function() {
return this.findInRange(FIND_CREEPS, 0).length > 0 || !this.canBuild()
};
RoomPosition.prototype.canBuild = function() {
let isWall = this.lookFor(LOOK_TERRAIN)[0] == 'wall';
let hasBlockingStruct = this.lookFor(LOOK_STRUCTURES).filter(s => OBSTACLE_OBJECT_TYPES.includes(s.structureType)).length > 0;
return !(isWall || hasBlockingStruct);
};