Changes to use recharge

This commit is contained in:
dan 2020-11-17 10:30:13 -06:00
parent f2ed90049b
commit c8d3293dde
8 changed files with 69 additions and 17 deletions

View File

@ -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)){
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)
}

View File

@ -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){

View File

@ -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 +'----')
}

View File

@ -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'})
}}
}

View File

@ -16,8 +16,23 @@ let roleMiner = {
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) {
creep.travelTo(mysource);
}
} 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 {
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) ;}});
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})

View File

@ -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,6 +36,21 @@ 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) ;}});

View File

@ -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)}});

1
todos.js Normal file
View File

@ -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.