-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_builder.js
37 lines (32 loc) · 1.13 KB
/
auto_builder.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
var builder = require('builder')
const body = [WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE];
module.exports = {
run: function (roomName, spawnRoomName) {
const creepName = 'auto_builder_' + roomName;
var creep = Game.creeps[creepName];
if (!creep) {
autoSpawnCreep(creepName, spawnRoomName, body);
}
else {
if(!creep.pos.inRangeTo(new RoomPosition(25, 25, roomName),24)) creep.moveTo(new RoomPosition(25, 25, roomName));
else{
builder.run(creep, 'CONTAINER');
}
}
}
}
function autoSpawnCreep(creepName, spawnRoomName, body) {
var spawn = getAvaliableSpawn(spawnRoomName);
if (spawn) {
spawn.spawnCreep(body, creepName, {memory: {role: 'outpost_builder' }});
}
}
function getAvaliableSpawn(room) {
for (var spawnname in Game.spawns) {
var spawn = Game.spawns[spawnname];
if (spawn.room.name == room && spawn.spawning == null) {
return spawn;
}
}
return null;
}