Worker/Mover/Miner changes

This commit is contained in:
dan 2020-11-14 01:18:05 -06:00
parent ab136d8201
commit e7f66d8918
7 changed files with 107 additions and 33 deletions

View File

@ -53,6 +53,13 @@ module.exports = {
} }
return 'Spawning initiated' return 'Spawning initiated'
}, },
spawnminer: function(){
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
let name = myroom.name
require('proc.spawning').spawnminer(name)
}
return 'Spawning initiated'
},
spawnclaimer: function(){ spawnclaimer: function(){
for(let myroom of _.filter(Game.rooms, 'controller.my')) { for(let myroom of _.filter(Game.rooms, 'controller.my')) {
let name = myroom.name let name = myroom.name

View File

@ -8,6 +8,7 @@ let Phase1 = {
let myspawn = myspawns[0] let myspawn = myspawns[0]
let creepcount = Game.rooms[room].find(FIND_MY_CREEPS).length let creepcount = Game.rooms[room].find(FIND_MY_CREEPS).length
creepcounts = _.countBy(Game.rooms[room].find(FIND_MY_CREEPS), c => c.memory.role) creepcounts = _.countBy(Game.rooms[room].find(FIND_MY_CREEPS), c => c.memory.role)
Game.rooms[room].memory.movercount=creepcounts["mover"]
let workerrolename = 'phase' + Game.rooms[room].memory.phase +'worker' let workerrolename = 'phase' + Game.rooms[room].memory.phase +'worker'
let sources = Game.rooms[room].find(FIND_SOURCES ) let sources = Game.rooms[room].find(FIND_SOURCES )
if(Game.rooms[room].controller.ticksToDowngrade < CONTROLLER_DOWNGRADE[Game.rooms[room].controller.level] * .2 ){ if(Game.rooms[room].controller.ticksToDowngrade < CONTROLLER_DOWNGRADE[Game.rooms[room].controller.level] * .2 ){
@ -24,14 +25,18 @@ let Phase1 = {
console.log(creepcounts[workerrolename]) console.log(creepcounts[workerrolename])
console.log(Game.rooms[room].energyAvailable + " of " + Game.rooms[room].energyCapacityAvailable) 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)) { 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) require('proc.spawning').spawnworker(room)
} }
if(Game.rooms[room].storage && Game.rooms[room].terminal && (creepcounts["mover"] < 1 || creepcounts["mover"]==undefined) && Game.rooms[room].energyAvailable >= Game.rooms[room].energyCapacityAvailable){ if((Game.rooms[room].storage || Game.rooms[room].terminal) && (creepcounts["mover"] < 2 || creepcounts["mover"]==undefined)){
console.log("Spawning Mover") console.log("Spawning Mover in " + room)
require('proc.spawning').spawnmover(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)
}
//require('proc.market').sellEnergy(room) //require('proc.market').sellEnergy(room)
} }
} }

View File

@ -9,6 +9,23 @@ let initroom = {
Game.rooms[name].memory.hasbeeninited=1 Game.rooms[name].memory.hasbeeninited=1
Game.rooms[name].memory.tickssofar=0 Game.rooms[name].memory.tickssofar=0
Game.rooms[name].memory.maphits={} Game.rooms[name].memory.maphits={}
//Game.rooms[name].memory.minablepositions= this.checkminablepositions(name)
},
checkminablepositions: function(name){
Source.prototype.analyzeFreeSpaces = function() {
let x = this.pos.x;
let y = this.pos.y;
let walkable = this.room.lookForAtArea(
LOOK_TERRAIN,
y - 1, // top
x - 1, // left
y + 1, // bottom
x + 1, // right
true // asArray
).filter(o => o[LOOK_TERRAIN] !== 'wall');
return walkable.length;
};
} }
} }
module.exports = initroom module.exports = initroom

View File

@ -2,15 +2,15 @@ let buildparts = {
spawnminer: function(roomname) { spawnminer: function(roomname) {
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
Game.rooms[roomname].memory.CreepNum++ Game.rooms[roomname].memory.CreepNum++
let CreepName = roomname + "_" + (Game.rooms[roomname].memory.CreepNum) let CreepName = 'miner_' + roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
for(let spawn of myspawns){ for(let spawn of myspawns){
if(!spawn.spawning){ if(!spawn.spawning){
let tobuild=[] let tobuild=[]
for(let totry of [ for(let totry of [
[WORK,WORK,WORK,WORK,WORK,MOVE], [WORK,WORK,WORK,WORK,CARRY,MOVE],
[WORK,WORK,WORK,WORK,MOVE], [WORK,WORK,WORK,CARRY,MOVE],
[WORK,WORK,WORK,MOVE], [WORK,WORK,CARRY,MOVE],
[WORK,WORK,MOVE], [WORK,CARRY,MOVE],
[WORK,MOVE] [WORK,MOVE]
]){ ]){
let ispossible = spawn.canCreateCreep(totry) let ispossible = spawn.canCreateCreep(totry)
@ -26,7 +26,7 @@ let buildparts = {
spawnwarrior: function(roomname) { spawnwarrior: function(roomname) {
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
Game.rooms[roomname].memory.CreepNum++ Game.rooms[roomname].memory.CreepNum++
let CreepName = roomname + "_" + (Game.rooms[roomname].memory.CreepNum) let CreepName = 'warrior_' + roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
for(let spawn of myspawns){ for(let spawn of myspawns){
if(!spawn.spawning){ if(!spawn.spawning){
let tobuild=[] let tobuild=[]
@ -50,7 +50,7 @@ let buildparts = {
spawnworker: function(roomname) { spawnworker: function(roomname) {
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
Game.rooms[roomname].memory.CreepNum++ Game.rooms[roomname].memory.CreepNum++
let CreepName = roomname + "_" + (Game.rooms[roomname].memory.CreepNum) let CreepName = 'worker_' + roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
for(let spawn of myspawns){ for(let spawn of myspawns){
if(!spawn.spawning){ if(!spawn.spawning){
for(let totry of [ for(let totry of [
@ -77,7 +77,7 @@ let buildparts = {
spawnmover: function(roomname) { spawnmover: function(roomname) {
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
Game.rooms[roomname].memory.CreepNum++ Game.rooms[roomname].memory.CreepNum++
let CreepName = roomname + "_" + (Game.rooms[roomname].memory.CreepNum) let CreepName = 'Mover_' + roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
for(let spawn of myspawns){ for(let spawn of myspawns){
if(!spawn.spawning){ if(!spawn.spawning){
for(let totry of [ for(let totry of [

View File

@ -1,12 +1,38 @@
let roleMiner = { let roleMiner = {
run: function(creep) { run: function(creep) {
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined} //if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
let mysource=Game.getObjectById(creep.memory.destsource.id) let ignorecreeps=true
{ let filllevel = _.sum(creep.carry)
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) { if(creep.memory.working && filllevel == 0) {
creep.travelTo(mysource); creep.memory.working = false;
} creep.say('Gathering');
} }
} if(!creep.memory.working && _.sum(creep.carry) == creep.carryCapacity) {
creep.memory.working = true;
creep.say('working');
}
if(!creep.memory.working){
let mysource=Game.rooms[creep.room.name].find(FIND_MINERALS)[0]
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) ;}});
if(storagetargets){
if(this.transferAll(creep,storagetargets) == ERR_NOT_IN_RANGE) {
creep.moveTo(storagetargets,{ignoreCreeps:ignorecreeps})
}
}
}
},
transferAll: function(creep,targetStorage){
let result = 0;
for(mat in creep.store)
{
let tempResult = creep.transfer(targetStorage,mat);
if(tempResult !== ERR_INVALID_ARGS) {result = tempResult;}
}
return result;
}
}; };
module.exports = roleMiner; module.exports = roleMiner;

View File

@ -5,6 +5,9 @@ let mover={
creep.memory.lastpos = creep.pos creep.memory.lastpos = creep.pos
creep.memory.timeatpos = 0 creep.memory.timeatpos = 0
} }
if(creep.memory.working==undefined){
creep.memory.working=false
}
let lastpos = _.create(RoomPosition.prototype, creep.memory.lastpos) let lastpos = _.create(RoomPosition.prototype, creep.memory.lastpos)
if(creep.pos.isEqualTo(lastpos)){ if(creep.pos.isEqualTo(lastpos)){
creep.memory.timeatpos = creep.memory.timeatpos+1 creep.memory.timeatpos = creep.memory.timeatpos+1
@ -24,13 +27,18 @@ let mover={
} }
if(creep.memory.working){ if(creep.memory.working){
let terminaltarget = creep.room.terminal let terminaltarget = creep.room.terminal
if(creep.transfer(terminaltarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) { if(creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER].includes(s.structureType)) && s.energy < s.energyCapacity))}})){
creep.say('Putting Energy') 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))}});
creep.travelTo(terminaltarget); if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(spawntarget,{ignoreCreeps:ignorecreeps})
} }
}else if(creep.transfer(terminaltarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
creep.say('Putting Energy')
creep.travelTo(terminaltarget);
}
} else { } else {
if(filllevel < creep.carryCapacity){ 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) > 5000) ;}}); 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) { if(creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
creep.say('Getting Energy') creep.say('Getting Energy')
creep.travelTo(storagetarget); creep.travelTo(storagetarget);

View File

@ -28,7 +28,9 @@ let Phase1Worker = {
if(!creep.memory.working && creep.carry.energy == creep.carryCapacity) { if(!creep.memory.working && creep.carry.energy == creep.carryCapacity) {
creep.memory.working = true; creep.memory.working = true;
creep.say('working'); creep.say('working');
} }
if(creep.memory.working){ if(creep.memory.working){
let look=creep.pos.lookFor(LOOK_STRUCTURES) 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.storeCapacity) ;}});
@ -38,7 +40,7 @@ let Phase1Worker = {
creep.say(creep.room.controller.ticksToDowngrade) creep.say(creep.room.controller.ticksToDowngrade)
creep.moveTo(creep.room.controller) 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))}})){ } 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)){
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))}}); 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) { if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(spawntarget,{ignoreCreeps:ignorecreeps}) creep.moveTo(spawntarget,{ignoreCreeps:ignorecreeps})
@ -68,21 +70,30 @@ let Phase1Worker = {
} }
} else { } else {
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>200)}}); let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>200)}});
if(droppedenergy == undefined){ let tombstone = creep.pos.findClosestByRange(FIND_TOMBSTONES, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}});
//console.log(tombstones)
if((droppedenergy == undefined) && (tombstone==undefined)){
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined} if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
let mysource=Game.getObjectById(creep.memory.destsource.id) let mysource=Game.getObjectById(creep.memory.destsource.id)
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){ if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
creep.moveTo(mysource,{ignoreCreeps:ignorecreeps}) creep.moveTo(mysource,{ignoreCreeps:ignorecreeps})
} }
} else { } else {
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) { if(droppedenergy){
if(global.verbosity>0){ if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
creep.say("MTDE"); if(global.verbosity>0){
creep.say("MTDE");
}
creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps})
} }
} else {
creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps}) if(creep.withdraw(tombstone,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){
} creep.say("MTTS");
}
creep.moveTo(tombstone.pos,{ignoreCreeps:ignorecreeps})
}
}
} }
} }
creep.memory.lastpos=creep.pos creep.memory.lastpos=creep.pos