SHARE
TWEET

main,js

maxxchildress Sep 22nd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////////Main/////////////////////
  2. // To expand to another room set expand = 1
  3. //  
  4. // To Set Desired Populations Use The Below Function In The Console
  5. // Game.spawns['Spawn1'].memory.harvesters_1 = 4;
  6. // with builders,upgraders,defenders,harvesters_0,harvesters_eR1_0 and repairers being other options
  7.  
  8. // Import all requires and modules //    
  9. var init = require('init');
  10. var pop = require('pop');    
  11.  
  12. var roleClaimer = require('role.claimer');
  13. var roleHarvester = require('role.harvester');    
  14. var roleUpgrader = require('role.upgrader');
  15. var roleBuilder = require('role.builder');
  16. var roleRepairer = require('role.repairer');
  17. var roleDefender = require('role.defender');
  18. var roleLinker = require('role.linker');
  19. var roleTower = require('role.tower');
  20. var rolesatHarvester = require('role.satharvester');
  21. var visuals = require('visuals');
  22. var architect = require('architect');
  23.  
  24. ///////////////////////////////////////////////////////
  25. ///////////////////////////////////////////////////////
  26. ///////////////////////////////////////////////////////
  27.  
  28. // Define Variables //
  29.  
  30. var spawn1 = Game.spawns['Spawn1'];
  31. var room1 = spawn1.room;
  32. var energyAvailable1 = room1.energyAvailable;
  33. var sources = room1.find(FIND_SOURCES);
  34.  
  35. // Structures //
  36. var storage1 = room1.storage;
  37. var links = room1.find(FIND_STRUCTURES, { filter: (s) => s.structureType == STRUCTURE_LINK});
  38. var sourceLink = links[0];
  39. var targetLink = links[1];
  40. var towers1 = room1.find(FIND_STRUCTURES, { filter: (s) => s.structureType == STRUCTURE_TOWER});
  41. var needsSomeRepair = room1.find(FIND_STRUCTURES, { filter: object => object.hits < object.hitsMax });
  42.  
  43. // For introducing second spawns and expansions //
  44. var spawn2 = Game.spawns['Spawn2'];
  45.     if(spawn2){var room2 = spawn2.room;}
  46.     if(Game.flags['expand1']) {var expansionFlag1 = Game.flags['expand1'];}
  47.     if(Game.flags['expand2']) {var expansionFlag2 = Game.flags['expand2'];}
  48.     if(Game.flags['expand3']) {var expansionFlag3 = Game.flags['expand3'];}
  49.  
  50. // For Automatic Populations  //
  51. var constructSites = spawn1.room.find(FIND_CONSTRUCTION_SITES);
  52. var upgraders = _.filter(Game.creeps, (creep) => creep.memory.role == 'upgrader');
  53.  
  54. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  55. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  56. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  57.  
  58. console.log('THIS IS A GLOBAL TICK');
  59.  
  60. // This is the primary loop for the AI //
  61. module.exports.loop = function () {
  62.     console.log('##################################################');
  63.     init.run();
  64.     console.log('Expansion Flag 1: ' + expansionFlag1);
  65.  
  66.     // Clear Memory of Dead Creeps //
  67.     for(var name in Memory.creeps) {
  68.         if(!Game.creeps[name]) {
  69.             delete Memory.creeps[name];
  70.             // console.log('Clearing non-existing creep memory:', name);  
  71.         }
  72.     }
  73.    
  74.    
  75.  
  76.     /////////////////////////////////////////////////////////////////////////////////////////
  77.     // Set some automatic populations.                                                     //
  78.     // If there is a contruction site build a builder. If there are five or more build 2   //
  79.     if(constructSites.length >= 1) { spawn1.memory.builders = 1; }
  80.     if(constructSites.length >= 5) { spawn1.memory.builders = 2; }  
  81.     if(constructSites.length < 1) { spawn1.memory.builders = 0; }
  82.     // If there are towers set repairers to zero                                           //
  83.     if(towers1.length) { spawn1.memory.repairers = 0; }
  84.     else if(spawn1.memory.repairers <= 0 && needsSomeRepair.length > 0) { spawn1.memory.repairers = 1; }
  85.     // Always keep two upgraders for now.                                                  //
  86.     if(spawn1.memory.upgraders <= 1) { spawn1.memory.upgraders = 2; }
  87.     // always have atleast two harvester going.                                            //
  88.     if(spawn1.memory.harvesters_0 <= 0 && sources[0].energy >= 0) { spawn1.memory.harvesters_0 = 2; }
  89.     if(spawn1.memory.harvesters_1 <= 0 && sources[1].energy >= 0) { spawn1.memory.harvesters_1 = 2; }
  90.     /////////////////////////////////////////////////////////////////////////////////////////
  91.     /////////////////////////////////////////////////////////////////////////////////////////
  92.  
  93.     // Refresh availableEnergy //
  94.     energyAvailable1 = room1.energyAvailable;
  95.  
  96.     // Run Creep Population Control
  97.     if(spawn2){var energyAvailable2 = room2.energyAvailable;}
  98.     if(spawn2){pop.run(spawn2, room2);console.log('Running Room 2');}
  99.     pop.run(spawn1, room1, energyAvailable1);
  100.  
  101.     /////////////////////////////////////////////////////////////////////////////////////////
  102.     // Execute the Architect                                                               //
  103.     //                                                                                     //
  104.     architect.run(spawn1, room1, energyAvailable1);
  105.  
  106.     // Run Creep modules
  107.     for(var name in Game.creeps) {
  108.         var creep = Game.creeps[name];
  109.  
  110.         if(creep.memory.role == 'harvester_0' || creep.memory.role == 'harvester_1' || creep.memory.role == 'harvester_2' || creep.memory.role == 'harvester_3') {
  111.             roleHarvester.run(creep, expansionFlag1);
  112.             visuals.run(creep, "🚚");
  113.         }
  114.         if(creep.memory.role == "harvester_eR1_0") {
  115.             rolesatHarvester.run(creep, expansionFlag1);
  116.             visuals.run(creep, "🚚+1");
  117.         }
  118.         if(creep.memory.role == "harvester_eR2_0") {
  119.             rolesatHarvester.run(creep, expansionFlag2);
  120.             visuals.run(creep, "🚚+2");
  121.         }
  122.         if(creep.memory.role == "harvester_eR3_0") {
  123.             rolesatHarvester.run(creep, expansionFlag3);
  124.             visuals.run(creep, "🚚+3");
  125.         }
  126.         if(creep.memory.role == 'upgrader') {
  127.             roleUpgrader.run(creep);
  128.             visuals.run(creep, "🔅");
  129.         }
  130.         if(creep.memory.role == 'builder') {
  131.             roleBuilder.run(creep);
  132.             visuals.run(creep, "🔨");
  133.         }
  134.         if(creep.memory.role == 'expansionBuilder') {
  135.             roleBuilder.run(creep, expansionFlag1);
  136.             visuals.run(creep, "🔨+");
  137.         }
  138.         if(creep.memory.role == 'repairer') {
  139.             roleRepairer.run(creep);
  140.             visuals.run(creep, "🔧");
  141.         }
  142.         if(creep.memory.role == 'defender') {
  143.             roleDefender.run(creep);
  144.             visuals.run(creep, "🚀");
  145.         }
  146.         if(creep.memory.role == 'claimer') {
  147.             roleClaimer.run(creep, expansionFlag1);
  148.             visuals.run(creep, "Cl");
  149.         }
  150.         if(creep.memory.role == 'linker') {
  151.             roleLinker.run(creep);
  152.             visuals.run(creep, "Lr");
  153.         }
  154.  
  155.     }
  156.     // Run Tower Code
  157.     if(towers1.length) {
  158.         roleTower.run();
  159.         // console.log(towers1);
  160.     }
  161. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top