summaryrefslogtreecommitdiff
path: root/src/role.builder.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/role.builder.js')
-rw-r--r--src/role.builder.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/role.builder.js b/src/role.builder.js
new file mode 100644
index 0000000..e2649cf
--- /dev/null
+++ b/src/role.builder.js
@@ -0,0 +1,25 @@
+module.exports = {
+ run: (creep) => {
+ if (creep.memory.state === "building") {
+ if (creep.carry.energy > 0) {
+ const targets = creep.room.find(FIND_CONSTRUCTION_SITES);
+ if (targets.length) {
+ if (creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
+ creep.moveTo(targets[0]);
+ }
+ }
+ } else {
+ creep.memory.state = "collecting";
+ }
+ } else {
+ if (creep.carry.energy < creep.carryCapacity) {
+ // still filling up
+ if (creep.transfer(spawn, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
+ creep.moveTo(spawn);
+ }
+ } else {
+ creep.memory.state = "building";
+ }
+ }
+ }
+};