Advertisement
Guest User

Untitled

a guest
May 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. /** @param {Creep} creep **/
  2. global.deposit = function(creep) {
  3.  
  4. //Find Things that need energy
  5. var structuresNeedingEnergy = creep.room.find(FIND_STRUCTURES, {
  6. filter: (structure) => {
  7. return ((structure.structureType == STRUCTURE_SPAWN ||
  8. structure.structureType == STRUCTURE_EXTENSION) && structure.energy < structure.energyCapacity);
  9. }
  10. });
  11. var towersNeedingEnergy = creep.room.find(FIND_STRUCTURES, {
  12. filter: (structure) => {
  13. return structure.structureType == STRUCTURE_TOWER && structure.energy < structure.energyCapacity - 100 && creep.pos.getRangeTo(structure) < 6;
  14. }
  15. });
  16.  
  17. var structuresWantingEnergy = creep.room.find(FIND_STRUCTURES, {
  18. filter: (structure) => {
  19. return (structure.structureType == STRUCTURE_CONTAINER && structure.pos.getRangeTo(structure.pos.findClosestByRange(FIND_SOURCES)) > 3 && structure.store[RESOURCE_ENERGY] < structure.storeCapacity - 100);
  20. }
  21. });
  22.  
  23. var storageBox = creep.room.find(FIND_STRUCTURES, {
  24. filter: (structure) => {
  25. return (structure.structureType == STRUCTURE_STORAGE && structure.store[RESOURCE_ENERGY] < structure.storeCapacity - 100);
  26. }
  27. });
  28.  
  29. if(structuresNeedingEnergy.length > 0) {
  30. var dropOff = creep.pos.findClosestByPath(structuresNeedingEnergy);
  31. if(creep.transfer(dropOff, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
  32. creep.moveTo(dropOff);
  33. }
  34. }else if(towersNeedingEnergy.length > 0){
  35. var dropOff = creep.pos.findClosestByPath(towersNeedingEnergy);
  36. if(creep.transfer(dropOff, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
  37. creep.moveTo(dropOff);
  38. }
  39. }else if(structuresWantingEnergy.length > 0){
  40. var dropOff = creep.pos.findClosestByPath(structuresWantingEnergy);
  41. if(creep.transfer(dropOff, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
  42. creep.moveTo(dropOff);
  43. }
  44. }else if(storageBox.length > 0){
  45. var dropOff = creep.pos.findClosestByPath(storageBox);
  46. if(creep.transfer(dropOff, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
  47. creep.moveTo(dropOff);
  48. }
  49. }else{
  50. //Do Nothing
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement