forked from Garethp/Screeps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roles_scavenger.js
44 lines (38 loc) · 890 Bytes
/
roles_scavenger.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
var scavenger = {
parts: [
[Game.CARRY, Game.CARRY, Game.MOVE, Game.MOVE]
],
action: function()
{
var creep = this.creep;
var droppedEnergy = creep.pos.findNearest(Game.DROPPED_ENERGY, {
filter: function(en) {
var pickup = true;
var tile = creep.room.lookAt(en);
for(var i in tile)
{
if(tile[i].type == "creep" && tile[i].creep.memory && tile[i].creep.memory.role == "miner")
pickup = false;
}
return pickup;
}
});
if(droppedEnergy == null || creep.energy == creep.energyCapacity)
{
var nearestSpawn = creep.pos.findNearest(Game.MY_SPAWNS, {
filter: function(spawn)
{
return spawn.energy < spawn.energyCapacity;
}
});
creep.moveTo(nearestSpawn);
creep.transferEnergy(nearestSpawn);
}
else
{
creep.moveTo(droppedEnergy);
creep.pickup(droppedEnergy);
}
}
};
module.exports = scavenger;