Last active
October 14, 2015 04:49
-
-
Save Hernanduer/389203a6ff1bfd730d99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
module.exports = function(creep) { | |
if (creep.memory.state == undefined || creep.carry.energy == 0) { | |
creep.memory.state = "pickup"; | |
} else if (creep.carry.energy == creep.carryCapacity) { | |
creep.memory.state = "work"; | |
} | |
if (creep.memory.state == "pickup") { | |
let storage = creep.room.storage; | |
if (storage) { | |
creep.moveTo(storage, {reusePath: 15}); | |
storage.transferEnergy(creep); | |
} | |
} else if (creep.memory.state == "work") { | |
let target = Game.getObjectById(creep.memory.targetId); | |
if (target == null) { | |
let roadToRepair = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: function(object) { | |
return object.structureType == STRUCTURE_ROAD && (object.hits < object.hitsMax * 0.40); | |
}}); | |
if (roadToRepair == null) | |
return; | |
target = roadToRepair; | |
creep.memory.targetId = roadToRepair.id; | |
} else { | |
if (target.hits == target.hitsMax) { | |
creep.memory.targetId = undefined; | |
target = null; | |
} else { | |
creep.moveTo(target, {reusePath: 15}); | |
creep.repair(target); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment