From 39e648ff874acc0818813c8d26c051508f1a57b5 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 30 Nov 2020 03:41:26 -0600 Subject: [PATCH] Try to fix movers --- Room.Phase1.js | 2 +- bodypartbuilder.js | 31 ++++++++++++++++++++++++++++++- role.mover.js | 30 +++++++++++++++++++++++++----- role.phase1worker.js | 14 ++++++++++---- 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/Room.Phase1.js b/Room.Phase1.js index 55ef954..c7bda4c 100644 --- a/Room.Phase1.js +++ b/Room.Phase1.js @@ -34,7 +34,7 @@ let Phase1 = { console.log('Spawning sourceminer in ' + room) require('proc.spawning').spawnsourceminer(room) } - if((((creepcounts[workerrolename]< (Game.rooms[room].memory.minablepositions) || creepcounts[workerrolename]==undefined) && Game.rooms[room].energyAvailable >= Game.rooms[room].energyCapacityAvailable) ) || ((creepcounts[workerrolename]==0 || creepcounts[workerrolename]==undefined ) && Game.rooms[room].energyAvailable>100)) { + if((((creepcounts[workerrolename]< (Game.rooms[room].memory.minablepositions+1) || creepcounts[workerrolename]==undefined) && Game.rooms[room].energyAvailable >= Game.rooms[room].energyCapacityAvailable) ) || ((creepcounts[workerrolename]==0 || creepcounts[workerrolename]==undefined ) && Game.rooms[room].energyAvailable>100)) { console.log('Spawning worker in ' + room) require('proc.spawning').spawnworker(room) } diff --git a/bodypartbuilder.js b/bodypartbuilder.js index 3b71f95..8934d7b 100644 --- a/bodypartbuilder.js +++ b/bodypartbuilder.js @@ -302,6 +302,35 @@ let buildparts = { } - } + }, + designCreep: function(availableCost,arrParts) + { + var bodyPartArray = []; + var arrCosts = []; + for(var i = 0;i {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER) && _.sum(s.store) >= 500) ;}}); - if(creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) { - creep.say('Getting Energy') - creep.travelTo(storagetarget); - } + let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>200)}}); + let tombstone = creep.pos.findClosestByRange(FIND_TOMBSTONES, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}}); + if((droppedenergy == undefined) && (tombstone==undefined)){ + if(creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) { + creep.say('Getting Energy') + creep.travelTo(storagetarget); + } + } else { + if(droppedenergy){ + if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) { + if(global.verbosity>0){ + creep.say("MTDE"); + } + creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps}) + } + } else { + if(creep.withdraw(tombstone,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { + if(global.verbosity>0){ + creep.say("MTTS"); + } + creep.moveTo(tombstone.pos,{ignoreCreeps:ignorecreeps}) + } + } + } } } creep.memory.lastpos=creep.pos -} + } } module.exports = mover; \ No newline at end of file diff --git a/role.phase1worker.js b/role.phase1worker.js index 8f3c9fa..623d2df 100644 --- a/role.phase1worker.js +++ b/role.phase1worker.js @@ -69,7 +69,6 @@ let Phase1Worker = { } } } else if ((creep.ticksToLive < 300 || creep.ticksToLive <= creep.memory.renewto) && (Game.rooms[creep.room.name].find(FIND_MY_SPAWNS, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>1)}})) ) { - if(creep.memory.renewto == undefined){ creep.memory.renewto = 1200 } else { @@ -80,9 +79,16 @@ let Phase1Worker = { creep.say('renewing') console.log(creep.name + ": " + creep.ticksToLive + " " + creep.memory.renewto) let spawn = creep.pos.findClosestByRange(FIND_MY_SPAWNS) - if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE) - { - creep.moveTo(spawn); + if(creep.room.memory.NeedsRecharge==1 && creep.carry.energy>0){ + if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) { + creep.say('!MTRC!') + creep.say(creep.room.controller.ticksToDowngrade) + creep.moveTo(creep.room.controller) + } + } else { + if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE){ + creep.moveTo(spawn); + } } } else { let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>200)}});