Advertisement
purplemonday

Untitled

Nov 10th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. /*
  2. * Module code goes here. Use 'module.exports' to export things:
  3. * module.exports.thing = 'a thing';
  4. *
  5. * You can import it from another modules like this:
  6. * var mod = require('base.unit.carrier');
  7. * mod.thing == 'a thing'; // true
  8. */
  9.  
  10. exports.run = function (group ,roomname,config)
  11. {
  12. // get the group of creeps we need to controle
  13. var my_group = _.filter(Game.creeps, (creep) => creep.memory.GROUP == group && creep.memory.ROOM == roomname)
  14. var my_room = Game.rooms[roomname]
  15.  
  16. var condision_ok = _.filter(my_group, (creep) => creep.ticksToLive > 30 )
  17. if (condision_ok.length < config[group])
  18. {
  19.  
  20. if (condision_ok.length < 1 || my_room.energyCapacityAvailable <301)
  21. {
  22. console.log("harvester pannic")
  23. common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname})
  24.  
  25. var newcreep = common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname})
  26. console.log(roomname+" 300-pannic "+newcreep+" "+common.functions.roomspawns(roomname)[0])
  27.  
  28. } else {
  29. console.log(my_room.energyCapacityAvailable +" "+my_room.energyAvailable )
  30. if (my_room.energyCapacityAvailable >700)
  31. {
  32. console.log("700 "+common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,WORK,WORK,WORK,MOVE,MOVE,MOVE,CARRY],{GROUP:group,ROOM : roomname}))
  33. } else if (my_room.energyCapacityAvailable > 600){
  34. console.log("600 "+common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,WORK,WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname}))
  35. } else if (my_room.energyCapacityAvailable > 500){
  36.  
  37. var newcreep = common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname})
  38. console.log(roomname+" 500 "+newcreep+" "+common.functions.roomspawns(roomname)[0])
  39.  
  40.  
  41. } else if (my_room.energyCapacityAvailable > 400){
  42.  
  43. var newcreep = common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname})
  44. console.log(roomname+" 400 "+newcreep)
  45.  
  46.  
  47.  
  48. } else if (my_room.energyCapacityAvailable > 300){
  49. common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname})
  50. } else {
  51.  
  52. }
  53. }
  54.  
  55. }
  56. for (var ind in my_group)
  57. {
  58. var this_creep = my_group[ind]
  59. if (this_creep.memory.ACTION == undefined)
  60. {
  61.  
  62.  
  63. // we are doing nothing yet lets find crip
  64. var valid_sources =[]
  65. var sources = my_room.find(FIND_SOURCES)
  66. for (var s in sources )
  67. {
  68. var on_source= _.filter(Game.creeps, (creep) => creep.memory.GROUP == group && creep.memory.ROOM == roomname && creep.memory.DEST == sources[s].id)
  69. // if this source is alrdy taken
  70. if (on_source.length < 1)
  71. {
  72. // nope this just what we where looking for
  73. valid_sources.push(sources[s])
  74. }
  75.  
  76. }
  77. console.log(">> "+on_source.length)
  78. if (valid_sources.length > 0)
  79. {
  80. target = this_creep.pos.findClosestByRange(valid_sources)
  81. //common.path.startpath(this_creep,target,{ACTION : "HARVEST", RESOURCE : RESOURCE_ENERGY})
  82.  
  83. this_creep.memory.DEST = target.id
  84. this_creep.memory.ACTION = "MOVING"
  85. } else {
  86. this_creep.say("error")
  87. delete this_creep.memory.DEST
  88. delete this_creep.memory.ACTION
  89.  
  90. }
  91.  
  92. } else {
  93. var work_destination = Game.getObjectById(this_creep.memory.DEST)
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. //console.log("move")
  101.  
  102. if (this_creep.pos.getRangeTo(work_destination.pos) > 1)
  103. {
  104. this_creep.moveTo(work_destination)
  105. } else {
  106. //this_creep.say("X")
  107. if (this_creep.memory.ACTION == "MOVING")
  108. {
  109.  
  110. this_creep.say("3")
  111. var build_containers =work_destination.pos.findInRange(FIND_CONSTRUCTION_SITES, 1);
  112. var containers = work_destination.room.find(FIND_STRUCTURES, {filter: (structure) => {return (structure.structureType == STRUCTURE_CONTAINER)}},1);
  113. containers =work_destination.pos.findInRange(containers, 1);
  114.  
  115. if (containers.length > 0)
  116. {
  117. this_creep.say("1")
  118. containers = work_destination.pos.findInRange(containers, 1);
  119. if (this_creep.pos.getRangeTo(containers[0].pos) < 1)
  120. {
  121. this_creep.memory.ACTION = "MINING"
  122. this_creep.memory.container = container.id
  123. this_creep.say("1b")
  124. } else {
  125. this_creep.moveTo(containers[0])
  126. this_creep.say("1a")
  127. }
  128.  
  129. } else if (build_containers.length >0 ) {
  130. this_creep.say("2")
  131. if (this_creep.carry.energy < 30)
  132. {
  133. this_creep.harvest(work_destination)
  134. } else {
  135. this_creep.build( this_creep.pos.findClosestByPath(build_containers ))
  136. }
  137. } else if (build_containers.length == 0) {
  138. this_creep.say("3")
  139. this_creep.pos.createConstructionSite(STRUCTURE_CONTAINER)
  140. } else {
  141. this_creep.say("4")
  142. }
  143.  
  144. } else if (this_creep.memory.ACTION == "MINING") {
  145. var containers = work_destination.room.find(FIND_STRUCTURES, {filter: (structure) => {return (structure.structureType == STRUCTURE_CONTAINER)}}, 20);
  146. var container = this_creep.pos.findClosestByPath(containers )
  147.  
  148.  
  149. var total = _.sum(container.store)
  150. this_creep.say("t"+total)
  151. if (total < 2000)this_creep.harvest(work_destination)
  152. }
  153. }
  154. }
  155.  
  156.  
  157. }
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement