Advertisement
taitep

harvester.js

Jul 25th, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module.exports = {
  2.     run: function(creep) {
  3.         if(creep.store.getFreeCapacity() > 0 && creep.memory[delivering]) {
  4.             creep.memory[delivering] = false;
  5.         }
  6.         else {
  7.             if(creep.store.getFreeCapacity() = 0 && !creep.memory[delivering]) {
  8.                 creep.memory[delivering] = true;
  9.             }
  10.         }
  11.  
  12.         if(creep.memory[delivering]) {
  13.             var targets = creep.room.find(FIND_STRUCTURES, {
  14.                 filter: (structure) => {
  15.                     return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) &&
  16.                         structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
  17.                 }
  18.             });
  19.            
  20.             if(targets.length > 0) {
  21.                 if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
  22.                     creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
  23.                 }
  24.             }
  25.         } else {
  26.             var sources = creep.room.find(FIND_SOURCES);
  27.             if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
  28.                 creep.moveTo(sources[0]);
  29.             }
  30.         }
  31.     },
  32.  
  33.     spawnInfo: {
  34.         count: 2,
  35.         label: 'Harvester',
  36.         body: [WORK, CARRY, MOVE, MOVE],
  37.         startMemory: {delivering: false}
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement