forked from zfmarkham/screeps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.resupply.js
41 lines (34 loc) · 1.12 KB
/
task.resupply.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
/**
* Created by zmark_000 on 29/12/2016.
*/
let utils = require('utils');
let resupply = {
resupply: function(creep) {
let energyStore = utils.findNearest(creep, FIND_STRUCTURES, (struct) => struct.structureType == STRUCTURE_CONTAINER && struct.store.energy > 100);
if (energyStore)
{
if (creep.withdraw(energyStore, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE)
{
if (creep.moveTo(energyStore, {noPathFinding: true}) == ERR_NOT_FOUND)
{
creep.moveTo(energyStore);
}
}
}
else
{
energyStore = utils.findNearest(creep, FIND_DROPPED_ENERGY, (source) => source.amount >= creep.carryCapacity);
if (energyStore)
{
if (creep.pickup(energyStore) == ERR_NOT_IN_RANGE)
{
if (creep.moveTo(energyStore, {noPathFinding: true}) == ERR_NOT_FOUND)
{
creep.moveTo(energyStore);
}
}
}
}
}
};
module.exports = resupply;