Advertisement
Guest User

screeps_main.js

a guest
Jan 17th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. module.exports.loop = function () {
  4.     for (let name in Game.creeps) {
  5.         let creep = Game.creeps[name];
  6.  
  7.         if (!creep.memory.sourceId) {
  8.  
  9.             var source = creep.pos.findClosestByPath(FIND_SOURCES_ACTIVE, {
  10.                 filter: (s) => s.pos.findInRange(FIND_MY_CREEPS, 1).length == 0
  11.             });
  12.  
  13.             if (source) {
  14.                 creep.memory.sourceId = source.id;
  15.             }
  16.         }
  17.        
  18.         if (creep.memory.sourceId) {
  19.             creepHarvestBehavior(creep, Game.getObjectById(creep.memory.sourceId), Game.spawns.Spawn1);
  20.         }
  21.     }
  22.    
  23.     if (!Game.spawns.Spawn1.spawning && Game.spawns.Spawn1.energy == 300) {
  24.         Game.spawns.Spawn1.createCreep([WORK, CARRY, MOVE, MOVE]);
  25.     }
  26. }
  27.  
  28. function creepHarvestBehavior(creep, source, returnStructure) {
  29.     if (_.sum(creep.carry) == creep.carryCapacity) {
  30.         if (creep.transfer(returnStructure, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
  31.             creep.moveTo(returnStructure);
  32.         }
  33.     }
  34.     else {
  35.         if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
  36.             creep.moveTo(source);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement