From d482d39d160940bdf5d1fe4b455cf836459340d5 Mon Sep 17 00:00:00 2001 From: paradizelost Date: Thu, 15 Sep 2016 01:40:56 -0500 Subject: [PATCH] fixed errors in state tracking and removed excess logging --- role.builder.js | 2 -- role.hauler.js | 19 ++++++++++++++++--- role.hauler2.js | 11 +++++++++++ role.repairbot.js | 1 - tower.js | 2 -- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/role.builder.js b/role.builder.js index e7c2129..013ec2e 100644 --- a/role.builder.js +++ b/role.builder.js @@ -13,8 +13,6 @@ var roleBuilder = { usedstorage+=_.sum(allcontainers[i].store) mycapacity+=allcontainers[i].storeCapacity } - console.log(usedstorage + " " + mycapacity) - var storagepercent = usedstorage/mycapacity var ttl = creep.ticksToLive diff --git a/role.hauler.js b/role.hauler.js index 151a224..5ccf8bb 100644 --- a/role.hauler.js +++ b/role.hauler.js @@ -1,9 +1,21 @@ var roleHauler = { run: function(creep) { - var sources = creep.room.find(FIND_DROPPED_ENERGY ); - if(creep.pickup(sources[0]) == ERR_NOT_IN_RANGE && creep.carryCapacity/2 > creep.carry.energy) { + if(creep.memory.hauling == undefined){creep.memory.hauling=false} + if(creep.memory.hauling && creep.carry.energy == 0) { + creep.memory.hauling = false; + creep.say('gathering'); + } + if(!creep.memory.hauling && creep.carry.energy == creep.carryCapacity) { + creep.memory.hauling = true; + creep.say('hauling'); + } + var sources = creep.room.find(FIND_DROPPED_ENERGY ); + if(creep.memory.hauling==false){ + if(creep.pickup(sources[0]) == ERR_NOT_IN_RANGE && creep.carryCapacity/2 > creep.carry.energy) { creep.moveTo(sources[0]); - } else if(sources != undefined ) + } + }else { + if(sources != undefined ) { var spawntargets = creep.room.find(FIND_STRUCTURES, { filter: (structure) => { return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) &&structure.energy < structure.energyCapacity) @@ -31,6 +43,7 @@ var roleHauler = { creep.say("NS,NT") creep.moveTo(Game.flags.Flag1); } + } }, spawn: function(){ var myrole='hauler'; diff --git a/role.hauler2.js b/role.hauler2.js index a69d59d..f6a0d1b 100644 --- a/role.hauler2.js +++ b/role.hauler2.js @@ -2,6 +2,16 @@ /** @param {Creep} creep **/ run: function(creep) { + if(creep.memory.hauling == undefined){creep.memory.hauling=false} + if(creep.memory.hauling && creep.carry.energy == 0) { + creep.memory.hauling = false; + creep.say('gathering'); + } + if(!creep.memory.hauling && creep.carry.energy == creep.carryCapacity) { + creep.memory.hauling = true; + creep.say('hauling'); + } + if(creep.memory.hauling==false){ if(creep.carryCapacity > creep.carry.energy){ var container = creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (structure) => { @@ -27,6 +37,7 @@ creep.moveTo(Game.flags.Flag1); } } + } }, spawn: function(){ var myrole='hauler2'; diff --git a/role.repairbot.js b/role.repairbot.js index 594cc73..71bb730 100644 --- a/role.repairbot.js +++ b/role.repairbot.js @@ -11,7 +11,6 @@ var roleRepairbot = { creep.memory.repairing = true; creep.say('repairing'); } - console.log(creep.name) if(creep.memory.repairing==false){ var container = creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (structure) => { diff --git a/tower.js b/tower.js index 61df122..4871a14 100644 --- a/tower.js +++ b/tower.js @@ -25,8 +25,6 @@ var towers = { usedstorage+=_.sum(allcontainers[i].store) mycapacity+=allcontainers[i].storeCapacity } - console.log(usedstorage + " " + mycapacity) - var storagepercent = usedstorage/mycapacity var importantstructures = tower.room.find(FIND_STRUCTURES, { filter: (structure) => {