diff options
| author | Tom Harley | 2019-10-15 03:28:59 +0100 |
|---|---|---|
| committer | Tom Harley | 2019-10-15 03:28:59 +0100 |
| commit | 41253179b3701734a6ee65413b732b6591c7ac3a (patch) | |
| tree | 383470eb73398e05fa9bd8a3d1fa50d525686b55 /src/harvester.js | |
| parent | Forgot to rename imports (diff) | |
| download | screeps-ai-41253179b3701734a6ee65413b732b6591c7ac3a.tar.gz screeps-ai-41253179b3701734a6ee65413b732b6591c7ac3a.zip | |
Turns out screeps doesn’t like folders
Diffstat (limited to 'src/harvester.js')
| -rw-r--r-- | src/harvester.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/harvester.js b/src/harvester.js new file mode 100644 index 0000000..5c6f85c --- /dev/null +++ b/src/harvester.js @@ -0,0 +1,25 @@ +// vim: tw=80 ts=2 sw=2 et + +const util = require('creep'); + +module.exports = { + run: (creep) => { + if (creep.carry.energy < creep.carryCapacity) { + const source = creep.pos.findClosestByPath(FIND_SOURCES); + if (creep.harvest(source) == ERR_NOT_IN_RANGE) { + creep.moveTo(source); + } + } else { + const spawn = creep.pos.findClosestByPath(FIND_MY_STRUCTURES, { + filter: (structure) => { + return (structure.structureType == STRUCTURE_EXTENSION + || structure.structureType == STRUCTURE_SPAWN) + && structure.energy < structure.energyCapacity; + } + }); + if (creep.transfer(spawn, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { + creep.moveTo(spawn); + } + } + } +}; |
