var battle = require('battle') var roleGuard = { getLastFlag: function(){ return 4; // TODO. calculate me. }, run: function(creep){ console.log(creep, 'running Guard') // Reset creep to 1 creep.memory.patrolDestination = creep.memory.patrolDestination || 1; var target = battle.findEnemy(creep); if(target != creep.room.controller && creep.hits > creep.hitsMax - 500 /* no more attack */) { console.log('\t', creep, 'attacking:',target) creep.moveTo(target); creep.attack(target); } else { 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 = 1; } destinationFlag = Game.flags['patrol_' + creep.memory.patrolDestination]; console.log('\tMoving to Patrol leg:', creep.memory.patrolDestination); creep.moveTo(destinationFlag); } } } module.exports = roleGuard;