From d7223b6d60fc33d1cf090237eeb3f4dd46ab4e9d Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Tue, 28 Jun 2016 16:49:31 -0400 Subject: [PATCH] more refactoring, added miniums --- main.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 024b227..ba7c1e4 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,14 @@ var roleHarvester = require('role.harvester'); var roleUpgrader = require('role.upgrader'); var roleBuilder = require('role.builder'); +var _defaultBodyParts = [WORK, CARRY, MOVE]; +var _roleNames = ["harvester", "builder", "upgrader"]; +var _minimums = { + harvester: 4, + builder: 2, + upgrader: 2 +}; + module.exports.loop = function(){ // Cleanup Creeps for (var name in Memory.creeps){ @@ -12,11 +20,11 @@ module.exports.loop = function(){ } // Refactor some similar behavior for all roles - var roleNames = ["harvester", "builder", "upgrader"]; - roleNames.forEach(function(roleName){ + + _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}); + if (creepsOfKind.length < _minimums[roleName]){ + var newName = Game.spawns.Spawn1.createCreep(_defaultBodyParts, undefined, {role: roleName}); console.log("Spawning new ", roleName, ": ", newName); } });