-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.source.js
60 lines (55 loc) · 1.65 KB
/
utils.source.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
53
54
55
56
57
58
59
60
/*
* Helper functions to do with sources.
*/
var qualifier = function(object)
{
if(object.type == "terrain")
{
if(object.terrain
&& (object.terrain == "swamp" || object.terrain == "normal" || object.terrain == "plain"))
return true;
}
else if(object.type == "structure")
{
if(object.structure)
switch(object.structure.structureType)
{
case STRUCTURE_ROAD:
return true;
case STRUCTURE_RAMPART:
if(structure.my)
return structure.my;
else if(structure.my === false)
return false;
return true;
case STRUCTURE_STORAGE:
if(structure.my)
return structure.my;
else if(structure.my === false)
return false;
return true;
default:
return false;
}
}
else
return true;
};
var adjacentEmptySpaces = function(position)
{
var areaDescription = Game.rooms[position.roomName]
.lookAtArea(position.y - 1, position.x - 1, position.y + 1, position.x + 1),
usableSpots = [];
_.forOwn(areaDescription, function(yValue, y)
{
_.forOwn(yValue, function(xValue, x)
{
if(_.filter(xValue, qualifier).length == xValue.length)
usableSpots.push([position.roomName, x, y]);
});
});
return usableSpots.length;
};
module.exports = {
adjacentEmptySpaces: adjacentEmptySpaces
};