more builders, and do some scoping stuff

This commit is contained in:
Tyrel Souza 2016-06-29 21:22:31 -04:00
parent 0ada42efb3
commit b4be39510a
2 changed files with 9 additions and 8 deletions

View File

@ -13,7 +13,7 @@ var creepsConfig = {
}, },
builder: { builder: {
bodyParts: [WORK, CARRY, MOVE, MOVE], bodyParts: [WORK, CARRY, MOVE, MOVE],
minimumCreeps: 1, minimumCreeps: 2,
role: roleBuilder role: roleBuilder
}, },
upgrader: { upgrader: {

View File

@ -8,10 +8,14 @@ var roleGuard = {
let flagNumbers = _.map(patrolFlags, function(flag){ let flagNumbers = _.map(patrolFlags, function(flag){
return parseInt(flag.name.substring("patrol_".length, flag.name.length)); return parseInt(flag.name.substring("patrol_".length, flag.name.length));
}); });
let max = Math.max.apply(Math, flagNumbers); return Math.max.apply(Math, flagNumbers);
return max; },
getDestinationFlag: function(){
return Game.flags['patrol_' + this.creep.memory.patrolDestination];
}, },
run: function(creep){ run: function(creep){
this.creep = creep;
console.log(creep, 'running Guard') console.log(creep, 'running Guard')
// Reset creep to 1 // Reset creep to 1
creep.memory.patrolDestination = creep.memory.patrolDestination || 1; creep.memory.patrolDestination = creep.memory.patrolDestination || 1;
@ -22,18 +26,15 @@ var roleGuard = {
creep.moveTo(target); creep.moveTo(target);
creep.attack(target); creep.attack(target);
} else { } else {
var destinationFlag = Game.flags['patrol_' + creep.memory.patrolDestination]; if (creep.pos.isEqualTo(this.getDestinationFlag())){
if (creep.pos.isEqualTo(destinationFlag)){
creep.memory.patrolDestination += 1; creep.memory.patrolDestination += 1;
} }
if (creep.memory.patrolDestination > this.getLastFlag()){ if (creep.memory.patrolDestination > this.getLastFlag()){
creep.memory.patrolDestination = 1; creep.memory.patrolDestination = 1;
} }
destinationFlag = Game.flags['patrol_' + creep.memory.patrolDestination];
console.log('\tMoving to Patrol leg:', creep.memory.patrolDestination); console.log('\tMoving to Patrol leg:', creep.memory.patrolDestination);
creep.moveTo(destinationFlag); creep.moveTo(this.getDestinationFlag());
} }
} }