-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoscout.js
41 lines (35 loc) · 1.29 KB
/
autoscout.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
const body = [MOVE];
module.exports = {
run: function (roomName, spawnRoomName) {
const creepName = 'scout_' + roomName;
var creep = Game.creeps[creepName];
if (!creep) {
autoSpawnCreep(creepName, spawnRoomName);
}
else {
if(!creep.pos.inRangeTo(new RoomPosition(25, 25, roomName),20)) creep.moveTo(new RoomPosition(25, 25, roomName));
else {
var hostiles = Game.rooms[roomName].find(FIND_HOSTILE_CREEPS);
var PC_hostiles = Game.rooms[roomName].find(FIND_HOSTILE_POWER_CREEPS);
if(hostiles.length != 0 || PC_hostiles.length != 0) {
console.log('Incoming Enemies in Room: ' + roomName + ' Please Watch Out Room: ' + spawnRoomName);
}
}
}
}
}
function autoSpawnCreep(creepName, spawnRoomName) {
var spawn = getAvaliableSpawn(spawnRoomName);
if (spawn) {
spawn.spawnCreep(body, creepName, {memory: {role: 'scout' }});
}
}
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;
}