From c0ec265a2d2ee551bcb28a85097c2f2121774c80 Mon Sep 17 00:00:00 2001 From: Dan Hamik Date: Mon, 9 May 2022 17:03:22 -0500 Subject: [PATCH] . --- Room.Phase1.js | 38 ++++++++++++++++++++++++++++++++++++++ role.phase0worker.js | 30 ++++++++++++++++++++++++++++-- role.phase1worker.js | 6 +++--- 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/Room.Phase1.js b/Room.Phase1.js index 5d25049..ff38867 100644 --- a/Room.Phase1.js +++ b/Room.Phase1.js @@ -5,6 +5,7 @@ let Phase1 = { creepcounts = _.countBy(myroom.find(FIND_MY_CREEPS), c => c.memory.role) myroom.memory.creepcounts=creepcounts myroom.memory.movercount=creepcounts["mover"] + let links=myroom.find(FIND_STRUCTURES, {filter: (s) =>{return ( s.structureType==STRUCTURE_LINK)}}) if(Game.time % 10 === 0){ //console.log('processing spawn') @@ -107,6 +108,43 @@ let Phase1 = { } } } + /* + if(links!=null && links!=undefined){ + if(links.length>1){ + console.log('1') + let sourcelink=links[0] + let destlinks + try{ + for(let idx in links.length){ + link = links[idx] + console.log('2') + console.log(link.id) + console.log(sourcelink.id) + link.store.getUsedCapacity('energy') + sourcelink.store.getUsedCapacity('energy') + if(link.store.getUsedCapacity('energy') > sourcelink.store.getUsedCapacity('energy')){ + console.log("2.1") + destlinks += sourcelink + sourcelink=link + } else if (link.store.getUsedCapacity('energy') == sourcelink.store.getUsedCapacity('energy')){ + console.log('2.2') + } + idx++ + } + for(let destlink in destlinks){ + if(destlink != undefined && destlink != null){ + if(destlink.store.getUsedCapacity() < destlink.store.getCapacity()){ + console.log('3') + sourcelink.transferEnergy(destlink) + } + } + } + } catch(e){ + console.log(e) + } + } + } + */ if(myroom.controller.level>2){ } } }; diff --git a/role.phase0worker.js b/role.phase0worker.js index 519ae3b..266309a 100644 --- a/role.phase0worker.js +++ b/role.phase0worker.js @@ -1,6 +1,23 @@ //'use strict'; let Phase0Worker = { run: function(creep) { + let ignorecreeps=true + if(creep.memory.lastpos==undefined || creep.memory.timeatpos==undefined){ + creep.memory.lastpos = creep.pos + creep.memory.timeatpos = 0 + } + if(creep.memory.assignedroom==undefined){ + creep.memory.assignedroom=creep.room.name + } + let lastpos = _.create(RoomPosition.prototype, creep.memory.lastpos) + if(creep.pos.isEqualTo(lastpos)){ + + creep.memory.timeatpos = creep.memory.timeatpos+1 + if(creep.memory.timeatpos>2){ + //console.log(creep.name + " " + creep.memory.timeatpos) + ignorecreeps=false + } else { } + } else { creep.memory.timeatpos=0} let filllevel = _.sum(creep.carry) //creep.say(creep.room.memory.maphits[creep.pos.x + '-' + creep.pos.y].hits) if(creep.memory.working && filllevel == 0) { @@ -30,7 +47,8 @@ let Phase0Worker = { } } else { let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: {resourceType: RESOURCE_ENERGY}}); - if(droppedenergy == undefined){ + let ruins=creep.pos.findClosestByRange(FIND_RUINS, {filter: ruin => ruin.store.getUsedCapacity(RESOURCE_ENERGY) > 0}); + if(droppedenergy == undefined && ruins==undefined){ if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined} let mysource=Game.getObjectById(creep.memory.destsource.id) //mysource=creep.pos.findClosestByRange( FIND_SOURCES ) @@ -38,12 +56,20 @@ let Phase0Worker = { creep.travelTo(mysource); } } else { + if(droppedenergy){ if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) { if(global.verbosity>0){ creep.say("MTDE"); } creep.travelTo(droppedenergy); - } + } } else { + if(creep.withdraw(ruins,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { + if(global.verbosity>0){ + creep.say("MTRU"); + } + creep.moveTo(ruins,{ignoreCreeps:ignorecreeps}) + } + } } } } diff --git a/role.phase1worker.js b/role.phase1worker.js index ca3191c..ceeed54 100644 --- a/role.phase1worker.js +++ b/role.phase1worker.js @@ -39,7 +39,7 @@ let Phase1Worker = { creep.say(creep.room.controller.ticksToDowngrade + " of " + CONTROLLER_DOWNGRADE[creep.room.controller.level] * .2) creep.moveTo(creep.room.controller) } - } else if((creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER].includes(s.structureType)) && s.energy < s.energyCapacity))}}))&& (creep.room.memory.movercount<1||creep.room.memory.movercount==undefined)){ + } else if((creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER,STRUCTURE_LINK].includes(s.structureType)) && s.energy < s.energyCapacity))}}))&& (creep.room.memory.movercount<1||creep.room.memory.movercount==undefined)){ let spawntarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return (((s.structureType == STRUCTURE_EXTENSION || s.structureType == STRUCTURE_SPAWN || s.structureType == STRUCTURE_TOWER) && s.energy < s.energyCapacity))}}); if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(spawntarget,{ignoreCreeps:ignorecreeps}) @@ -55,7 +55,7 @@ let Phase1Worker = { if (road.length > 0) {creep.repair(road);} creep.moveTo(target,{ignoreCreeps:ignorecreeps}) } - } else if(storagetargets && creep.room.controller.level*125000> creep.room.storage.store.getUsedCapacity('energy')){ + } else if(storagetargets && creep.room.storage&& creep.room.controller.level*125000> creep.room.storage.store.getUsedCapacity('energy')){ if(creep.transfer(storagetargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { if (road.length > 0) {creep.repair(road);} creep.moveTo(storagetargets,{ignoreCreeps:ignorecreeps}) @@ -107,7 +107,7 @@ let Phase1Worker = { if((mysource.energy==0 || ((creep.room.memory.creepcounts.sourceminer!=null ||creep.room.memory.creepcounts.sourceminer!=undefined )))){ creep.say("2.1") //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') >= 100) ;}}); + let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_LINK) && s.store.getUsedCapacity('energy') >= 100) ;}}); if(storagetarget===undefined || storagetarget==null){ creep.say('2.2') storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE) && s.store.getUsedCapacity('energy') >= creep.room.controller.level * 125000) ;}});