From faeef7ee03479f889f21d9b7786a6cc9f00f104c Mon Sep 17 00:00:00 2001 From: Dan Hamik Date: Wed, 4 May 2022 08:30:12 -0500 Subject: [PATCH] Mining/Storage tweaks --- Room.Phase1.js | 4 ++-- main.js | 1 + role.mover.js | 10 +++++++--- role.phase1worker.js | 27 +++++++++++++++++++++++---- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Room.Phase1.js b/Room.Phase1.js index 1b893a8..7090dd1 100644 --- a/Room.Phase1.js +++ b/Room.Phase1.js @@ -45,7 +45,7 @@ let Phase1 = { console.log("Spawning Mover in " + room) require('proc.spawning').spawnmover(room) } - if((myroom.storage || myroom.terminal) && (creepcounts["mineralmover"] < 1 || creepcounts["mineralmover"]==undefined)){ + if(((myroom.storage || myroom.terminal) && myroom.StructureExtractor) && (creepcounts["mineralmover"] < 1 || creepcounts["mineralmover"]==undefined)){ console.log("Spawning MineralMover in " + room) require('proc.spawning').spawnmineralmover(room) } @@ -66,7 +66,7 @@ let Phase1 = { if(myroom.terminal.store.getUsedCapacity() == 0) { //console.log("terminal is empty") }else{ - if(myroom.terminal.store.getUsedCapacity('energy') > 10000){ + if(myroom.terminal.store.getUsedCapacity('energy') > 100000){ console.log("Starting market loop for "+ myroom) for(mat in myroom.terminal.store){ let availtosell=0 diff --git a/main.js b/main.js index 9581a02..6320127 100644 --- a/main.js +++ b/main.js @@ -5,6 +5,7 @@ global.verbosity=0 module.exports.loop = function () { console.log("----Start loop for "+ Game.time + '----') let decrementcounter = Game.time % 30 + ///for (let key of require('Empire')) global[key] = require('Empire')[key] try{ for(let name in Game.rooms){ let myroom=Game.rooms[name] diff --git a/role.mover.js b/role.mover.js index 488fd86..9f40794 100644 --- a/role.mover.js +++ b/role.mover.js @@ -99,10 +99,12 @@ let mover={ storagetarget=storage } }*/ + let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_CONTAINER) && s.store.getUsedCapacity('energy') >= 10) ;}}); - if(storagetarget===undefined){ + if(storagetarget===undefined||storagetarget==null){ + creep.say('finding storage') storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE) && s.store.getUsedCapacity('energy') >= 10) ;}}); - if(storagetarget==undefined && creep.room.terminal){ + if((storagetarget==undefined ||storagetarget==null) && creep.room.terminal){ storagetarget=creep.room.terminal } } @@ -119,11 +121,13 @@ let mover={ } catch(e) { console.log("oops" + e) }*/ +// creep.say('2') + //creep.say(storagetarget) if(creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) { creep.say('Getting Energy') creep.travelTo(storagetarget); } - creep.memory.pulledenergyfrom=storagetarget + //creep.memory.pulledenergyfrom=storagetarget } else { if(droppedenergy){ if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) { diff --git a/role.phase1worker.js b/role.phase1worker.js index 1199a61..050f9ec 100644 --- a/role.phase1worker.js +++ b/role.phase1worker.js @@ -33,7 +33,7 @@ let Phase1Worker = { if(creep.memory.working){ let look=creep.pos.lookFor(LOOK_STRUCTURES) - let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_TERMINAL ) && _.sum(s.store) < s.storeCapacity) ;}}); + let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_TERMINAL ) && _.sum(s.store) < s.store.getCapacity()) ;}}); if(creep.room.memory.NeedsRecharge==1){ if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) { creep.say(creep.room.controller.ticksToDowngrade + " of " + CONTROLLER_DOWNGRADE[creep.room.controller.level] * .2) @@ -55,7 +55,7 @@ let Phase1Worker = { if (road.length > 0) {creep.repair(road);} creep.moveTo(target,{ignoreCreeps:ignorecreeps}) } - } else if(storagetargets){ + } else if(storagetargets){// && creep.room.controller.level*.02 < creep.room.storage.store.getUsedCapacity('energy')/creep.room.storage.store.getCapacity()){ if(creep.transfer(storagetargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { if (road.length > 0) {creep.repair(road);} creep.moveTo(storagetargets,{ignoreCreeps:ignorecreeps}) @@ -95,8 +95,27 @@ let Phase1Worker = { if((droppedenergy == undefined) && (tombstone==undefined)){ if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined} let mysource=Game.getObjectById(creep.memory.destsource.id) - if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){ - creep.moveTo(mysource,{ignoreCreeps:ignorecreeps}) + try{ + if(mysource.energy==0){ + //creep.say("No Energy Left to get") + let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_CONTAINER) && s.store.getUsedCapacity('energy') >= 1000) ;}}); + if(storagetarget===undefined){ + storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE) && s.store.getUsedCapacity('energy') >= 100000) ;}}); + if(storagetarget==undefined && creep.room.terminal && creep.room.terminal.store.getUsedCapacity('energy') > 100000){ + storagetarget=creep.room.terminal + } + } + if(storagetarget != undefined && creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) { + //creep.say('Getting Energy') + creep.travelTo(storagetarget); + } + }else { + if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){ + creep.moveTo(mysource,{ignoreCreeps:ignorecreeps}) + } + } + } catch(e){ + console.log(e) } } else { if(droppedenergy){