-
Notifications
You must be signed in to change notification settings - Fork 1
/
role.scout.js
54 lines (47 loc) · 1.89 KB
/
role.scout.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
var utility = require('utility');
var roleScout = {
/** @param {Creep} creep **/
run: function(creep) {
// Setup
if(!Memory.visitedRooms) Memory.visitedRooms = []
if(!creep.memory.target)
{
// Find exit (if there is none yet)
creep.memory.startingRoom = creep.room.name;
exits = Game.map.describeExits(creep.room.name)
for(var exit in exits)
{
console.log(exits[exit])
if(Memory.visitedRooms.filter((room) => room == exits[exit]).length == 0)
{
let targetList = creep.room.find(creep.room.findExitTo(exits[exit]));
creep.memory.target = targetList[0]; //let's just take the first one...
creep.memory.roomToVisit = exits[exit];
break;
}
}
}
else if(creep.room.name == creep.memory.roomToVisit)
{
// we made it :) let's start over
console.log("Visited new room: " + creep.room.name);
Memory.visitedRooms.push(creep.room.name);
delete creep.memory.target;
delete creep.memory.roomToVisit;
// Before we go, let's set up a few things
creep.room.createFlag(creep.room.find(FIND_STRUCTURES, {filter:
function(object)
{
return object.structureType == STRUCTURE_CONTROLLER;
}
})[0])
}
else
{
// need to recreate it because memory stringifies and thus loses classes
let target = new RoomPosition(creep.memory.target.x, creep.memory.target.y, creep.memory.target.roomName)
utility.travelTo(creep, target);
}
}
};
module.exports = roleScout;