Advertisement
Guest User

code

a guest
Jun 28th, 2016
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var roleHarvesterRoom = {
  2.  
  3.     /** @param {Creep} creep **/
  4.     run: function(creep) {
  5.        
  6.         var room_spawn = "[remove]";
  7.         var room_dest;
  8.        
  9.         if(creep.memory.room_dest != 0) {
  10.             room_dest = creep.memory.room_dest;
  11.         } else {
  12.             Game.notify('Harvester for other rooms has no destination');
  13.         }
  14.        
  15.         var flag = Game.flags.F_Roombot;
  16.         var flag_spawn = Game.flags.Flag1;
  17.         if(creep.room.name == room_spawn) {
  18.             if(creep.carry.energy == 0) {
  19.                 creep.moveTo(flag);
  20.             } else {
  21.                 var targets = creep.room.find(FIND_STRUCTURES, {
  22.                 filter: (structure) => {
  23.                         return (structure.structureType == STRUCTURE_TOWER || structure.structureType == STRUCTURE_SPAWN ||
  24.                                 structure.structureType == STRUCTURE_EXTENSION ||
  25.                                 structure.structureType == STRUCTURE_CONTAINER) &&
  26.                             structure.energy < structure.energyCapacity;
  27.                     }
  28.                 });
  29.                 if(targets.length > 0) {
  30.                     if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
  31.                     creep.moveTo(targets[0]);
  32.                     }
  33.                 }
  34.             }
  35.         } else if(creep.room.name == room_dest) {
  36.             if(creep.carry.energy < creep.carryCapacity) {
  37.                 var sources = creep.room.find(FIND_SOURCES);
  38.                 if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
  39.                 creep.moveTo(sources[0]);
  40.                 }
  41.             } else {
  42.                 creep.moveTo(flag_spawn);
  43.             }
  44.         }
  45.     }
  46. };
  47.  
  48. module.exports = roleHarvesterRoom;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement