summaryrefslogtreecommitdiff
path: root/src/role.harvester.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/role.harvester.js')
-rw-r--r--src/role.harvester.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/role.harvester.js b/src/role.harvester.js
new file mode 100644
index 0000000..aae5a2c
--- /dev/null
+++ b/src/role.harvester.js
@@ -0,0 +1,16 @@
+module.exports = {
+ run: (creep) => {
+ if (creep.carry.energy < creep.carryCapacity) {
+ // just use the first sourrce for now
+ const source = creep.room.find(FIND_SOURCES)[0];
+ if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
+ creep.moveTo(source);
+ }
+ } else {
+ const spawn = Game.spawns['Initial'];
+ if (creep.transfer(spawn), RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
+ creep.moveTo(spawn);
+ }
+ }
+ }
+};