Added patrol logic to guards

This commit is contained in:
Tyrel Souza 2016-06-29 20:52:07 -04:00
parent 02a08d2d8d
commit 560bec5fc8
2 changed files with 22 additions and 5 deletions

View File

@ -13,7 +13,7 @@ var creepsConfig = {
}, },
builder: { builder: {
bodyParts: [WORK, CARRY, MOVE, MOVE], bodyParts: [WORK, CARRY, MOVE, MOVE],
minimumCreeps: 0, minimumCreeps: 1,
role: roleBuilder role: roleBuilder
}, },
upgrader: { upgrader: {
@ -24,7 +24,7 @@ var creepsConfig = {
guard: { guard: {
bodyParts: [TOUGH, MOVE, ATTACK, MOVE, ATTACK], bodyParts: [TOUGH, MOVE, ATTACK, MOVE, ATTACK],
minimumCreeps: 3, minimumCreeps: 3,
role: roleGuard role: roleGuard,
} }
}; };

View File

@ -1,15 +1,32 @@
var battle = require("battle") var battle = require("battle")
var roleGuard = { var roleGuard = {
getLastFlag: function(){
return 1; // TODO. calculate me.
},
run: function(creep){ run: function(creep){
console.log(creep, "running Guard") console.log(creep, "running Guard")
if (creep.memory.patrolDestination == undefined){
creep.memory.patrolDestination = 0
}
var target = battle.findEnemy(creep); var target = battle.findEnemy(creep);
console.log("\t", creep, "tageting:",target) if(target != creep.room.controller && creep.hits > creep.hitsMax - 500 /* no more attack */) {
if(target && creep.hits > creep.hitsMax - 500 /* no more attack */) { console.log("\t", creep, "attacking:",target)
creep.moveTo(target); creep.moveTo(target);
creep.attack(target); creep.attack(target);
} else { } else {
creep.moveTo(Game.spawns.Spawn1); var destinationFlag = Game.flags["patrol_" + creep.memory.patrolDestination];
if (creep.pos.isEqualTo(destinationFlag)){
creep.memory.patrolDestination += 1;
}
if (creep.memory.patrolDestination > this.getLastFlag()){
creep.memory.patrolDestination = 0;
}
destinationFlag = Game.flags["patrol_" + creep.memory.patrolDestination];
console.log("\tMoving to Patrol leg:", creep.memory.patrolDestination);
creep.moveTo(destinationFlag);
} }
} }