From e08f49adfc17de12aca1490fe71c01beb49050cf Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Tue, 26 Jun 2018 03:13:58 +0100 Subject: Initial commit --- src/main.js | 7 +++++++ src/role.harvester.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/main.js create mode 100644 src/role.harvester.js (limited to 'src') diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..e466974 --- /dev/null +++ b/src/main.js @@ -0,0 +1,7 @@ +const harvester = require('role.harvester'); + +module.exports.loop = () => { + for (const name in Game.creeps) { + harvester.run(Game.creeps[name]); + } +} 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); + } + } + } +}; -- cgit v1.2.1