diff --git a/src/prototype_creep_harvest.js b/src/prototype_creep_harvest.js index 5dda47022..07b9e8a51 100644 --- a/src/prototype_creep_harvest.js +++ b/src/prototype_creep_harvest.js @@ -14,8 +14,17 @@ Creep.prototype.handleSourcer = function() { this.buildContainer(); - if (!this.room.controller || !this.room.controller.my || this.room.controller.level >= 2) { - this.spawnCarry(); + const nearStorage = this.room.storage && this.pos.isNearTo(this.room.storage); + + if (nearStorage) { + const workParts = this.body.filter((part) => part.type === WORK).length; + if (_.sum(this.carry) > this.carryCapacity - workParts * 2) { + this.transfer(this.room.storage, RESOURCE_ENERGY); + } + } else { + if (!this.room.controller || !this.room.controller.my || this.room.controller.level >= 2) { + this.spawnCarry(); + } } if (this.inBase()) {