forked from Garethp/Screeps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roles_transporter.js
68 lines (56 loc) · 1.26 KB
/
roles_transporter.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
65
66
67
68
var transporter = {
parts: [
[Game.CARRY, Game.CARRY, Game.MOVE, Game.MOVE]
],
action: function()
{
var creep = this.creep;
//@TODO: Balance Spawns here
if(creep.energy == 0)
{
var closestSpawn = creep.pos.findNearest(Game.MY_SPAWNS, {
filter: function(spawn)
{
return spawn.energy > 0;
}
});
creep.moveTo(closestSpawn);
closestSpawn.transferEnergy(creep);
return;
}
var target = null;
//Transfer to builder
if (!target) {
var builderToHelp = creep.pos.findNearest(Game.MY_CREEPS, {
filter: function (builder) {
return builder.memory.role == "builder"
&& builder.energy < ( builder.energyCapacity - 10);
}
});
if (builderToHelp)
target = builderToHelp;
}
if(!target)
{
var extension = creep.pos.findNearest(Game.MY_STRUCTURES, {
filter: function(structure)
{
return structure.structureType == Game.STRUCTURE_EXTENSION &&
structure.energy < structure.energyCapacity;
}
});
if(extension)
target = extension;
}
//Go to target and give it energy
if (creep.pos.isNearTo(target)) {
if (target.energy < target.energyCapacity) {
creep.transferEnergy(target);
}
}
else {
creep.moveTo(target);
}
}
};
module.exports = transporter;