more refactoring, added miniums
This commit is contained in:
parent
490877fb9c
commit
d7223b6d60
16
main.js
16
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);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user