diff --git a/main.js b/main.js index 3ccd08f..4fb7e17 100644 --- a/main.js +++ b/main.js @@ -13,7 +13,7 @@ var creepsConfig = { }, builder: { bodyParts: [WORK, CARRY, MOVE, MOVE], - minimumCreeps: 1, + minimumCreeps: 2, role: roleBuilder }, upgrader: { diff --git a/role.guard.js b/role.guard.js index 37fa6b3..c9b7841 100644 --- a/role.guard.js +++ b/role.guard.js @@ -8,10 +8,14 @@ var roleGuard = { let flagNumbers = _.map(patrolFlags, function(flag){ return parseInt(flag.name.substring("patrol_".length, flag.name.length)); }); - let max = Math.max.apply(Math, flagNumbers); - return max; + return Math.max.apply(Math, flagNumbers); + }, + getDestinationFlag: function(){ + return Game.flags['patrol_' + this.creep.memory.patrolDestination]; }, run: function(creep){ + this.creep = creep; + console.log(creep, 'running Guard') // Reset creep to 1 creep.memory.patrolDestination = creep.memory.patrolDestination || 1; @@ -22,18 +26,15 @@ var roleGuard = { creep.moveTo(target); creep.attack(target); } else { - var destinationFlag = Game.flags['patrol_' + creep.memory.patrolDestination]; - - if (creep.pos.isEqualTo(destinationFlag)){ + if (creep.pos.isEqualTo(this.getDestinationFlag())){ creep.memory.patrolDestination += 1; } if (creep.memory.patrolDestination > this.getLastFlag()){ creep.memory.patrolDestination = 1; } - destinationFlag = Game.flags['patrol_' + creep.memory.patrolDestination]; console.log('\tMoving to Patrol leg:', creep.memory.patrolDestination); - creep.moveTo(destinationFlag); + creep.moveTo(this.getDestinationFlag()); } }