Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Room.prototype.getUnclaimedSources = function() {
- let arr = [], sources = this.find(FIND_SOURCES);
- if (Memory.rooms[this.name].sourceMinerIds === undefined) {Memory.rooms[this.name].sourceMinerIds = {};}
- for (let i in sources) {
- if (Memory.rooms[this.name].sourceMinerIds[sources[i].id] === undefined || Game.getObjectById(Memory.rooms[this.name].sourceMinerIds[sources[i].id]) === null) {
- arr.push(sources[i]);
- }
- }
- return arr;
- };
- switch(creep.memory.role) {
- case "harvester":
- let source = creep.pos.findClosestByRange(creep.room.getUnclaimedSources());
- if (source !== null) {
- creep.memory.sourceId = source.id;
- creep.room.memory.sourceMinerIds[source.id] = creep.id;
- }
- break;
- default:
- console.log(creep + " has no role");
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment