Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. roleHarvester = function(creep) {
  2.  
  3. if(creep.carry.energy < creep.carryCapacity) {
  4. let sources = creep.room.find(FIND_SOURCES)
  5. if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
  6. creep.moveTo(sources[0]);
  7. }
  8. }
  9. else {
  10. let targets = creep.pos.findClosestByPath(FIND_STRUCTURES, {
  11. filter: (structure) =>
  12. (structure.structureType == STRUCTURE_SPAWN && structure.energy < structure.energyCapacity ) ||
  13. (structure.structureType == STRUCTURE_EXTENSION && structure.energy < structure.energyCapacity ) ||
  14. (structure.structureType == STRUCTURE_CONTAINER && structure.store.energy < structure.storeCapacity )
  15.  
  16. })
  17. if(targets) {
  18. if(creep.transfer(targets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
  19. creep.moveTo(targets);
  20. }
  21. }
  22.  
  23. else {
  24. if(creep.memory.building) {
  25. let targets = creep.room.find(FIND_CONSTRUCTION_SITES);
  26. let rtargets = creep.room.find(FIND_STRUCTURES, {
  27. filter: (structure) => structure.hits < structure.hitsMax && structure.hits < 100000
  28. });
  29.  
  30. if(targets.length) {
  31. if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
  32. creep.moveTo(targets[0]);
  33. }
  34. }
  35. else if(rtargets.length) {
  36. if(creep.repair(rtargets[0]) == ERR_NOT_IN_RANGE) {
  37. creep.moveTo(rtargets[0]);
  38. }
  39. }
  40. }
  41.  
  42. }
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement