diff --git a/Room.Phase1.js b/Room.Phase1.js index d549bfb..55cc258 100644 --- a/Room.Phase1.js +++ b/Room.Phase1.js @@ -25,7 +25,7 @@ let Phase1 = { console.log(Game.rooms[room].energyAvailable + " of " + Game.rooms[room].energyCapacityAvailable) } if(Game.rooms[room].memory.minablepositions >= 3 ||Game.rooms[room].memory.minablepositions==undefined ){ - 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) } @@ -43,9 +43,11 @@ let Phase1 = { console.log("Spawning Mover in " + room) require('proc.spawning').spawnmover(room) } - if((Game.rooms[room].find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_EXTRACTOR}}))&&(creepcounts["miner"] < 1 || creepcounts["miner"]==undefined)&&(Game.rooms[room].energyAvailable >= Game.rooms[room].energyCapacityAvailable)){ - console.log("Spawning Miner in " + room) - require('proc.spawning').spawnminer(room) + if((Game.rooms[room].find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_EXTRACTOR}}).length > 0)&&(creepcounts["miner"] < 1 || creepcounts["miner"]==undefined)&&(Game.rooms[room].energyAvailable >= Game.rooms[room].energyCapacityAvailable)){ + if(Game.rooms[room].find(FIND_MINERALS)[0].ticksToRegeneration < 1000){ + console.log("Spawning Miner in " + room) + require('proc.spawning').spawnminer(room) + } else { if(Game.flags.debug && Game.flags.debug.room == Game.rooms[room]){console.log("Not spawning miner in " + room + ", waiting for regen")}} } //require('proc.market').sellEnergy(room) } diff --git a/RoomInit.js b/RoomInit.js index 82f1e7b..bcd5aa6 100644 --- a/RoomInit.js +++ b/RoomInit.js @@ -17,6 +17,7 @@ let initroom = { minablepositions = minablepositions + this.computeSourceAccessPoints(Game.rooms[name],srcs[i]) //minablepositions = minablepositions + this.checkminablepositions(srcs[i]) } + //todo - create array of minable positions in the room and assign a screep to them, rather than having them constantly try to find the nearest one. Game.rooms[name].memory.minablepositions = minablepositions }, computeSourceAccessPoints: function(room, source){ diff --git a/main.js b/main.js index ed4d0d9..682e0cb 100644 --- a/main.js +++ b/main.js @@ -3,6 +3,7 @@ global.Empire = require("Empire") let Traveler = require("Traveler") global.verbosity=0 module.exports.loop = function () { + console.log("----Start loop for "+ Game.time + '----') let decrementcounter = Game.time % 30 for(let name in Game.rooms){ let myroom=Game.rooms[name] @@ -76,5 +77,6 @@ module.exports.loop = function () { let myroom = Game.rooms[name] if(!Game.rooms[name]){delete Memory.rooms[name]} } - + console.log("----End loop for "+ Game.time +'----') } + \ No newline at end of file diff --git a/proc.spawning.js b/proc.spawning.js index 0f19158..846bb2a 100644 --- a/proc.spawning.js +++ b/proc.spawning.js @@ -19,7 +19,7 @@ let buildparts = { break; } } - let newcreep = spawn.createCreep(tobuild,CreepName,{role:'miner'}) + let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time, role:'miner'}) }} }, @@ -43,7 +43,7 @@ let buildparts = { break; } } - let newcreep = spawn.createCreep(tobuild,CreepName,{role:'sourceminer'}) + let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time,role:'sourceminer'}) }} }, @@ -67,7 +67,7 @@ let buildparts = { break; } } - let newcreep = spawn.createCreep(tobuild,CreepName,{role:'warrior'}) + let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time,role:'warrior'}) }} }, @@ -94,7 +94,7 @@ let buildparts = { break; } } - let newcreep = spawn.createCreep(tobuild,CreepName,{role:"phase" + Game.rooms[roomname].memory.phase +"worker"}) + let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time,role:"phase" + Game.rooms[roomname].memory.phase +"worker"}) }} }, @@ -121,7 +121,7 @@ let buildparts = { break; } } - let newcreep = spawn.createCreep(tobuild,CreepName,{role:"mover"}) + let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time,role:"mover"}) }} }, @@ -149,7 +149,7 @@ let buildparts = { break; } } - let newcreep = spawn.createCreep(tobuild,CreepName,{role:"nrworker"}) + let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time,role:"nrworker"}) }} }, @@ -171,7 +171,7 @@ let buildparts = { } } console.log(roomname + ' ' + tobuild) - let newcreep = spawn.createCreep(tobuild,CreepName,{role:'claimer'}) + let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time,role:'claimer'}) }} } diff --git a/role.miner.js b/role.miner.js index ecd7fc7..5882fed 100644 --- a/role.miner.js +++ b/role.miner.js @@ -16,8 +16,23 @@ let roleMiner = { if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) { creep.travelTo(mysource); } - } else { - 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) ;}}); + } 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 { + if(creep.ticksToLive >= creep.memory.renewto){ + delete creep.memory.renewto + } + } + //console.log(creep.name + ": " + creep.ticksToLive + " " + creep.memory.renewto) + creep.say('renewing') + let spawn = creep.pos.findClosestByRange(FIND_MY_SPAWNS) + if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE) + { + creep.moveTo(spawn); + } + } else { + let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_TERMINAL || s.structureType == STRUCTURE_FACTORY ) && _.sum(s.store) < s.storeCapacity) ;}}); if(storagetargets){ if(this.transferAll(creep,storagetargets) == ERR_NOT_IN_RANGE) { creep.moveTo(storagetargets,{ignoreCreeps:ignorecreeps}) diff --git a/role.mover.js b/role.mover.js index 617526e..bfc8179 100644 --- a/role.mover.js +++ b/role.mover.js @@ -27,8 +27,8 @@ let mover={ } if(creep.memory.working){ let terminaltarget = creep.room.terminal - if(creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER].includes(s.structureType)) && s.energy < s.energyCapacity))}})){ - 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.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER, STRUCTURE_LAB].includes(s.structureType)) && s.energy < s.energyCapacity))}})){ + let spawntarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return (((s.structureType == STRUCTURE_EXTENSION || s.structureType == STRUCTURE_SPAWN || s.structureType == STRUCTURE_TOWER|| s.structureType == STRUCTURE_LAB) && s.energy < s.energyCapacity))}}); if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(spawntarget,{ignoreCreeps:ignorecreeps}) } @@ -36,9 +36,24 @@ let mover={ creep.say('Putting Energy') creep.travelTo(terminaltarget); } + } 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 { + if(creep.ticksToLive >= creep.memory.renewto){ + delete creep.memory.renewto + } + } + //console.log(creep.name + ": " + creep.ticksToLive + " " + creep.memory.renewto) + creep.say('renewing') + let spawn = creep.pos.findClosestByRange(FIND_MY_SPAWNS) + if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE) + { + creep.moveTo(spawn); + } } else { if(filllevel < creep.carryCapacity){ - let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER ) && _.sum(s.store) >= 500) ;}}); + let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {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); diff --git a/role.phase1worker.js b/role.phase1worker.js index c947ce2..8f3c9fa 100644 --- a/role.phase1worker.js +++ b/role.phase1worker.js @@ -68,6 +68,22 @@ let Phase1Worker = { creep.moveTo(Game.rooms[creep.memory.assignedroom].controller,{ignoreCreeps:ignorecreeps}) } } + } 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 { + if(creep.ticksToLive >= creep.memory.renewto){ + delete creep.memory.renewto + } + } + 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); + } } else { 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)}}); diff --git a/todos.js b/todos.js new file mode 100644 index 0000000..92d0be1 --- /dev/null +++ b/todos.js @@ -0,0 +1 @@ +//todo - create array of minable positions in the room and assign a screep to them, rather than having them constantly try to find the nearest one.