diff --git a/Room.Phase1.js b/Room.Phase1.js index a418ad8..312dee3 100644 --- a/Room.Phase1.js +++ b/Room.Phase1.js @@ -25,15 +25,22 @@ let Phase1 = { console.log(creepcounts[workerrolename]) console.log(Game.rooms[room].energyAvailable + " of " + Game.rooms[room].energyCapacityAvailable) } - if((((creepcounts[workerrolename]< (sources.length * 3) || 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) + if(Game.rooms[room].minablepositions>=3){ + if((((creepcounts[workerrolename]< (sources.length * 3) || 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) + } + } else { + if((((creepcounts['sourceminer']< Game.rooms[room].memory.minablepositions) || creepcounts['sourceminer']==undefined) && Game.rooms[room].energyAvailable >= Game.rooms[room].energyCapacityAvailable) || ((creepcounts['sourceminer']==0 || creepcounts['sourceminer']==undefined ) && Game.rooms[room].energyAvailable>100)) { + console.log('Spawning sourceminer in ' + room) + require('proc.spawning').spawnsourceminer(room) + } } if((Game.rooms[room].storage || Game.rooms[room].terminal) && (creepcounts["mover"] < 2 || creepcounts["mover"]==undefined)){ 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}}))&&(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) } diff --git a/assignsources.js b/assignsources.js index 1edfd43..4698eb5 100644 --- a/assignsources.js +++ b/assignsources.js @@ -2,7 +2,7 @@ let assignMiners = { tick: function(roomname) { let sources = Game.rooms[roomname].find(FIND_SOURCES ); for(let source of sources){ - let allminers = Game.rooms[roomname].find(FIND_MY_CREEPS, {filter: (creep) =>{return ( creep.memory.role=='miner'|| creep.memory.role == ("phase" + Game.rooms[roomname].memory.phase + "worker") )}}); + let allminers = Game.rooms[roomname].find(FIND_MY_CREEPS, {filter: (creep) =>{return ( creep.memory.role=='sourceminer'|| creep.memory.role == ("phase" + Game.rooms[roomname].memory.phase + "worker") )}}); //let allstorage = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE)}}) let unassignedminers = _.filter(allminers, (creep) => (creep.memory.destsource == undefined )); let sourcecount = sources.length diff --git a/proc.spawning.js b/proc.spawning.js index 72a5539..0f19158 100644 --- a/proc.spawning.js +++ b/proc.spawning.js @@ -22,6 +22,30 @@ let buildparts = { let newcreep = spawn.createCreep(tobuild,CreepName,{role:'miner'}) }} + }, + spawnsourceminer: function(roomname) { + let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) + Game.rooms[roomname].memory.CreepNum++ + let CreepName = 'sourceminer_' + roomname + "_" + (Game.rooms[roomname].memory.CreepNum) + for(let spawn of myspawns){ + if(!spawn.spawning){ + let tobuild=[] + for(let totry of [ + [WORK,WORK,WORK,WORK,WORK,MOVE], + [WORK,WORK,WORK,WORK,MOVE], + [WORK,WORK,WORK,MOVE], + [WORK,WORK,MOVE], + [WORK,MOVE] + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + let newcreep = spawn.createCreep(tobuild,CreepName,{role:'sourceminer'}) + }} + }, spawnwarrior: function(roomname) { let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) diff --git a/role.sourceminer.js b/role.sourceminer.js new file mode 100644 index 0000000..70e21bb --- /dev/null +++ b/role.sourceminer.js @@ -0,0 +1,12 @@ +let rolesourceMiner = { + run: function(creep) { + //if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined} + let ignorecreeps=true + //console.log('running sourceminer') + let mysource=Game.getObjectById(creep.memory.destsource.id) + if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) { + creep.travelTo(mysource); + } + } +}; +module.exports = rolesourceMiner; \ No newline at end of file