forked from Garethp/Screeps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constructionPlanner.js
64 lines (57 loc) · 1.56 KB
/
constructionPlanner.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
61
62
63
64
module.exports = {
buildRoads: function(from, to)
{
var path = Game.getRoom('1-1').findPath(from, to, { ignoreCreeps: true });
for(var i in path)
{
var result = Game.getRoom('1-1').createConstructionSite(path[i].x, path[i].y, Game.STRUCTURE_ROAD);
}
},
buildRoadToAllSources: function()
{
var sources = Game.spawns.Spawn1.room.find(Game.SOURCES);
for(var i in sources)
{
this.buildRoads(Game.spawns.Spawn1.pos, sources[i].pos);
}
},
expandRampartsOutwards: function()
{
var ramparts = Game.getRoom('1-1').find(Game.MY_STRUCTURES, {
filter: function(struct)
{
return struct.structureType == Game.STRUCTURE_RAMPART
}
});
for(var i in ramparts)
{
var rampart = ramparts[i];
var positions = [
[rampart.pos.x - 1, rampart.pos.y],
[rampart.pos.x, rampart.pos.y - 1],
[rampart.pos.x, rampart.pos.y - 1],
[rampart.pos.x, rampart.pos.y + 1],
[rampart.pos.x - 1, rampart.pos.y - 1],
[rampart.pos.x + 1, rampart.pos.y - 1],
[rampart.pos.x - 1, rampart.pos.y + 1],
[rampart.pos.x - 1, rampart.pos.y - 1]
];
for(var i in positions)
{
var pos = positions[i];
var tile = Game.getRoom('1-1').lookAt(pos[0], pos[1]);
var build = true;
for(var tilei in tile)
{
var thing = tile[tilei];
if(thing.type == 'structure' && thing.structure.structureType == Game.STRUCTURE_RAMPART)
build = false;
if(thing.type == 'constructionSite')
build = false;
}
if(build)
Game.getRoom('1-1').createConstructionSite(pos[0], pos[1], Game.STRUCTURE_RAMPART);
}
}
}
};