2016-06-29 17:21:09 +00:00
|
|
|
var battle = require("battle")
|
|
|
|
|
|
|
|
var roleGuard = {
|
2016-06-30 00:52:07 +00:00
|
|
|
getLastFlag: function(){
|
|
|
|
return 1; // TODO. calculate me.
|
|
|
|
},
|
2016-06-29 17:21:09 +00:00
|
|
|
run: function(creep){
|
|
|
|
console.log(creep, "running Guard")
|
2016-06-30 00:52:07 +00:00
|
|
|
if (creep.memory.patrolDestination == undefined){
|
|
|
|
creep.memory.patrolDestination = 0
|
|
|
|
}
|
2016-06-29 17:21:09 +00:00
|
|
|
var target = battle.findEnemy(creep);
|
2016-06-30 00:52:07 +00:00
|
|
|
if(target != creep.room.controller && creep.hits > creep.hitsMax - 500 /* no more attack */) {
|
|
|
|
console.log("\t", creep, "attacking:",target)
|
2016-06-29 17:21:09 +00:00
|
|
|
creep.moveTo(target);
|
|
|
|
creep.attack(target);
|
|
|
|
} else {
|
2016-06-30 00:52:07 +00:00
|
|
|
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);
|
2016-06-29 17:21:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = roleGuard;
|