forked from zfmarkham/screeps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.harvest.js
28 lines (22 loc) · 849 Bytes
/
task.harvest.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
/**
* Created by zmark_000 on 29/12/2016.
*/
let utils = require('utils');
let harvest = {
harvest: function(creep) {
if (!creep.memory.harvestPointId)
{
let occupiedHarvestPoints = _.filter(Game.creeps, (creep) => creep.memory.role == 'harvester').map((el) => el.memory.harvestPointId);
let closestSource = creep.pos.findClosestByRange(FIND_SOURCES, (source) => occupiedHarvestPoints.indexOf(source.id) == -1);
creep.memory.harvestPointId = closestSource.id;
}
let source = Game.getObjectById(creep.memory.harvestPointId);
if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
if (creep.moveTo(source, {noPathFinding: true}) == ERR_NOT_FOUND)
{
creep.moveTo(source);
}
}
}
};
module.exports = harvest;