Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. var hauler = [CARRY, CARRY, MOVE, MOVE];
  2. var hauler_cost = body_cost(hauler);
  3. var harvester = [WORK, WORK, MOVE, MOVE];
  4. var harvester_cost = body_cost(harvester);
  5. var upgrader = [WORK, CARRY, MOVE];
  6. var upgrader_cost = body_cost(upgrader);
  7.  
  8. //indexes into starting body types array
  9. var BodyType = { //itd be nice to unify this with Actions
  10. hauler: {body: hauler, cost: hauler_cost},
  11. harvester: {body: harvester, cost: harvester_cost},
  12. upgrader: {body: upgrader, cost: upgrader_cost},
  13. };
  14.  
  15. function body_cost(body) {
  16. return body.reduce(function (accumulator, part) {
  17. return accumulator + BODYPART_COST[part];
  18. }, 0);
  19. }
  20.  
  21. //this is here so the AI knows what "types" of creep it should spawn
  22. //the AI will these arrays in room memory as the rooms production capabilities increase
  23.  
  24. //creep spawning in the context of a room
  25. //this saves the counts of all the types of creep spawn
  26. function smart_spawn(room) {
  27. var spawns = room.find(FIND_STRUCTURES, {
  28. filter: (structure) => {
  29. return (structure.structureType == STRUCTURE_SPAWN)
  30. }
  31. });
  32.  
  33. //room info
  34. var room_energy = room.energyAvailable;
  35. //if creep counter exists, room must have already been initialized
  36. if(room.memory.creep_counter) {
  37. if(spawns) {
  38. for(var name in spawns) {
  39. var spawn = spawns[name];
  40. if(room.memory.spawn_sequence.length != 0) {
  41. var spawn_info = room.memory.spawn_sequence.shift();
  42. if(spawn_info.cost <= spawn.energy) {
  43. spawn.createCreep(spawn_info.body, null);
  44. }
  45. }
  46. else {
  47. console.log('initial spawn sequence ended!');
  48. }
  49. }
  50. }
  51. }
  52. else {
  53. //initialization stuff
  54. room.memory.spawn_sequence = [
  55. BodyType.hauler,
  56. BodyType.hauler,
  57. BodyType.harvester,
  58. BodyType.hauler,
  59. BodyType.hauler,
  60. BodyType.harvester,
  61. BodyType.hauler,
  62. BodyType.upgrader,
  63. BodyType.upgrader,
  64. BodyType.upgrader,
  65. ];
  66.  
  67.  
  68. var new_spawn = spawns[0].createCreep(BodyType.harvester.body, null);
  69. if(new_spawn != ERR_NOT_ENOUGH_ENERGY) {
  70. room.memory.creep_counter = {
  71. haulers: 0,
  72. harvesters: 0,
  73. upgraders: 0,
  74. };
  75.  
  76. room.memory.creep_counter.harvesters += 1;
  77. }
  78. }
  79. }
  80.  
  81. module.exports = {
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement