Skip to content

Instantly share code, notes, and snippets.

@Hernanduer
Last active October 14, 2015 04:49
Show Gist options
  • Save Hernanduer/389203a6ff1bfd730d99 to your computer and use it in GitHub Desktop.
Save Hernanduer/389203a6ff1bfd730d99 to your computer and use it in GitHub Desktop.
"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