var roleHarvester = require('role.harvester'); var roleUpgrader = require('role.upgrader'); var roleBuilder = require('role.builder'); module.exports.loop = function(){ // Cleanup Creeps for (var name in Memory.creeps){ if (!Game.creeps[name]){ delete Memory.creeps[name]; console.log("Clearning non-existing creep memory: ", name); } } // Refactor some similar behavior for all roles var roleNames = ["harvester", "builder", "upgrader"]; roleNames.forEach(function(roleName){ var creepsOfKind = _.filter(Game.creeps, (creep) => creep.memory.role == roleName); if (creepsOfKind.length < 2){ var newName = Game.spawns.Spawn1.createCreep([WORK, CARRY, MOVE], undefined, {role: roleName}); console.log("Spawning new ", roleName, ": ", newName); } }); // Run stuff for each creep for (var name in Game.creeps){ var creep = Game.creeps[name]; if (creep.memory.role == 'harvester'){ roleHarvester.run(creep); } if (creep.memory.role == 'upgrader'){ roleUpgrader.run(creep); } if (creep.memory.role == 'builder'){ roleBuilder.run(creep); } } }