From 560bec5fc8f031a23ac5a99bd00a1924c201e94c Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Wed, 29 Jun 2016 20:52:07 -0400 Subject: [PATCH] Added patrol logic to guards --- main.js | 4 ++-- role.guard.js | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index b45a9bb..03352d3 100644 --- a/main.js +++ b/main.js @@ -13,7 +13,7 @@ var creepsConfig = { }, builder: { bodyParts: [WORK, CARRY, MOVE, MOVE], - minimumCreeps: 0, + minimumCreeps: 1, role: roleBuilder }, upgrader: { @@ -24,7 +24,7 @@ var creepsConfig = { guard: { bodyParts: [TOUGH, MOVE, ATTACK, MOVE, ATTACK], minimumCreeps: 3, - role: roleGuard + role: roleGuard, } }; diff --git a/role.guard.js b/role.guard.js index 22cb9e0..8a2c26c 100644 --- a/role.guard.js +++ b/role.guard.js @@ -1,15 +1,32 @@ var battle = require("battle") var roleGuard = { + getLastFlag: function(){ + return 1; // TODO. calculate me. + }, run: function(creep){ console.log(creep, "running Guard") + if (creep.memory.patrolDestination == undefined){ + creep.memory.patrolDestination = 0 + } var target = battle.findEnemy(creep); - console.log("\t", creep, "tageting:",target) - if(target && creep.hits > creep.hitsMax - 500 /* no more attack */) { + 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 { - 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); } }