Screeps Wiki
Advertisement

function (top, left, bottom, right) {

   var $__0 = this;
   var result = {};
   for (var y = top; y <= bottom; y++) {
     result[y] = {};
     for (var x = left; x <= right; x++) {
       result[y][x] = [];
     }
   }
   var checkInside = (function(i) {
     return (i.room == $__0 || i.room == $__0.name) && i.pos && i.pos.y >= top && i.pos.y <= bottom && i.pos.x >= left && i.pos.x <= right || !i.pos && i.y >= top && i.y <= bottom && i.x >= left && i.x <= right;
   });
   function lookForType(typeName, typeRegister) {
     var typeResult = _.filter(typeRegister, checkInside);
     _.forEach(typeResult, (function(obj) {
       var $__1;
       result[obj.pos.y][obj.pos.x].push(($__1 = {}, Object.defineProperty($__1, "type", {
         value: typeName,
         configurable: true,
         enumerable: true,
         writable: true
       }), Object.defineProperty($__1, typeName, {
         value: obj,
         configurable: true,
         enumerable: true,
         writable: true
       }), $__1));
     }));
   }
   lookForType('creep', register.byRoom[this.name].creeps);
   lookForType('energy', register.byRoom[this.name].energy);
   lookForType('source', register.byRoom[this.name].sources);
   lookForType('structure', register.byRoom[this.name].structures);
   lookForType('flag', register.byRoom[this.name].flags);
   lookForType('constructionSite', register.byRoom[this.name].constructionSites);
   ['objectsByRoom', 'terrainByRoom'].forEach((function(key) {
     var terrainResult = register[key][$__0.name];
     if (top > 0 || left > 0 || bottom < 49 || right < 49) {
       terrainResult = _.filter(register[key][$__0.name], (function(i) {
         return (i.type == 'wall' || i.type == 'swamp') && checkInside(i);
       }));
     }
     _.forEach(terrainResult, (function(i) {
       if ((i.type == 'wall' || i.type == 'swamp') && (result[i.y][i.x].length == 0 || result[i.y][i.x][result[i.y][i.x].length - 1].type != 'terrain')) {
         result[i.y][i.x].push({
           type: 'terrain',
           terrain: i.type
         });
       }
     }));
   }));
   for (var y = top; y <= bottom; y++) {
     for (var x = left; x <= right; x++) {
       if (result[y][x].length == 0 || result[y][x][result[y][x].length - 1].type != 'terrain') {
         result[y][x].push({
           type: 'terrain',
           terrain: 'plain'
         });
       }
     }
   }
   return result;
 }

Advertisement