CursedFlames

Untitled

Apr 19th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Room.prototype.getUnclaimedSources = function() {
  2.     let arr = [], sources = this.find(FIND_SOURCES);
  3.     if (Memory.rooms[this.name].sourceMinerIds === undefined) {Memory.rooms[this.name].sourceMinerIds = {};}
  4.     for (let i in sources) {
  5.         if (Memory.rooms[this.name].sourceMinerIds[sources[i].id] === undefined || Game.getObjectById(Memory.rooms[this.name].sourceMinerIds[sources[i].id]) === null) {
  6.             arr.push(sources[i]);
  7.         }
  8.     }
  9.     return arr;
  10. };
  11. switch(creep.memory.role) {
  12.             case "harvester":
  13.                 let source = creep.pos.findClosestByRange(creep.room.getUnclaimedSources());
  14.                 if (source !== null) {
  15.                     creep.memory.sourceId = source.id;
  16.                     creep.room.memory.sourceMinerIds[source.id] = creep.id;
  17.                 }
  18.                 break;
  19.             default:
  20.                 console.log(creep + " has no role");
  21.                 break;
  22.         }
Advertisement
Add Comment
Please, Sign In to add comment