mining/mover fixes

This commit is contained in:
Dan Hamik 2022-05-23 15:59:00 -05:00
parent 36c253fa36
commit 5c5b9003ad
8 changed files with 312 additions and 245 deletions

View File

@ -164,5 +164,37 @@ module.exports = {
} }
} }
return accessPoints; return accessPoints;
},
computeSpawnLevels: function(room){
myroom=Game.rooms[room]
creepcounts=myroom.memory.creepcounts
let workerrolename = 'phase' + myroom.memory.phase +'worker'
if((myroom.memory.minablepositions >= 3 ||myroom.memory.minablepositions==undefined) && (creepcounts["mover"] == 0 || creepcounts["mover"]==undefined) ){
if((((creepcounts[workerrolename]< (myroom.memory.minablepositions + 1) || creepcounts[workerrolename]==undefined) && myroom.energyAvailable >= myroom.energyCapacityAvailable) ) || ((creepcounts[workerrolename]==0 || creepcounts[workerrolename]==undefined ) && myroom.energyAvailable>100)) {
console.log('Spawning worker in ' + room)
}
} else {
if((((creepcounts['sourceminer']< myroom.find(FIND_SOURCES).length) || creepcounts['sourceminer']==undefined) ) || ((creepcounts['sourceminer']==0 || creepcounts['sourceminer']==undefined ) && myroom.energyAvailable>100)) {
console.log('Spawning sourceminer in ' + room)
}
if((((creepcounts[workerrolename]< (myroom.memory.minablepositions+1) || creepcounts[workerrolename]==undefined) && myroom.energyAvailable >= myroom.energyCapacityAvailable) ) || ((creepcounts[workerrolename]==0 || creepcounts[workerrolename]==undefined ) && myroom.energyAvailable>100)) {
console.log('Spawning worker in ' + room)
}
}
if((myroom.storage!=undefined || myroom.terminal!=undefined) && (creepcounts["mover"] < 2 || creepcounts["mover"]==undefined)){
console.log("Spawning Mover in " + room)
}
if(((myroom.storage || myroom.terminal) && myroom.StructureExtractor) && (creepcounts["mineralmover"] < 1 || creepcounts["mineralmover"]==undefined)){
console.log("Spawning MineralMover in " + room)
}
if((myroom.find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_EXTRACTOR}}).length > 0)&&(creepcounts["miner"] < myroom.memory.mineralminablepositions || creepcounts["miner"]==undefined)&&(myroom.energyAvailable >= myroom.energyCapacityAvailable)){
if(myroom.find(FIND_MINERALS)[0].ticksToRegeneration == undefined || myroom.find(FIND_MINERALS)[0].ticksToRegeneration < 1000 ){
console.log("Spawning Miner in " + room)
} else {
if(Game.flags.debug && Game.flags.debug.room == myroom){
console.log("Not spawning miner in " + room + ", waiting for regen")
}
}
}
} }
}; };

View File

@ -12,7 +12,7 @@ let Phase0 = {
let newworkerrolename = 'phase' + Game.rooms[room].memory.phase + 'worker' let newworkerrolename = 'phase' + Game.rooms[room].memory.phase + 'worker'
for(let mycreep in creeps){ for(let mycreep in creeps){
creep=creeps[mycreep] creep=creeps[mycreep]
if(creep.memory.role == workerrolename){ if(creep.memory.role != newworkerrolename){
creep.memory.role=newworkerrolename creep.memory.role=newworkerrolename
} }
} }
@ -30,7 +30,7 @@ let Phase0 = {
require('proc.spawning').spawnworker(room) require('proc.spawning').spawnworker(room)
} }
} else { } } else { }
if(Game.rooms[room].controller.level>1){ if(Game.rooms[room].controller.level>1 && Game.rooms[room].spawn){
Game.rooms[room].memory.phase++ Game.rooms[room].memory.phase++
let creeps=Game.rooms[room].find(FIND_MY_CREEPS) let creeps=Game.rooms[room].find(FIND_MY_CREEPS)

View File

@ -6,11 +6,25 @@ let Phase1 = {
myroom.memory.creepcounts=creepcounts myroom.memory.creepcounts=creepcounts
myroom.memory.movercount=creepcounts["mover"] myroom.memory.movercount=creepcounts["mover"]
let links=myroom.find(FIND_STRUCTURES, {filter: (s) =>{return ( s.structureType==STRUCTURE_LINK)}}) let links=myroom.find(FIND_STRUCTURES, {filter: (s) =>{return ( s.structureType==STRUCTURE_LINK)}})
let constructionSites=myroom.find(FIND_CONSTRUCTION_SITES)
if(constructionSites.length > 0){
if(myroom.memory.currentconstruction!=undefined && myroom.memory.currentconstruction!=null){
if(Game.getObjectById(myroom.memory.currentconstruction.id)){
} else {
myroom.memory.currentconstruction=constructionSites[0]
}
} else {
myroom.memory.currentconstruction=constructionSites[0]
}
} else {
console.log(myroom.name+" No constructions")
delete myroom.memory.currentconstruction
}
if(Game.time % 10 === 0){ if(Game.time % 10 === 0){
//console.log('processing spawn') //console.log('processing spawn')
let myspawns = myroom.find(FIND_MY_SPAWNS) let myspawns = myroom.find(FIND_MY_SPAWNS)
if(myspawns.length>0){ if(myspawns.length>0){
let myspawn = myspawns[0] let myspawn = myspawns[0]
let creepcount = myroom.find(FIND_MY_CREEPS).length let creepcount = myroom.find(FIND_MY_CREEPS).length
@ -45,7 +59,7 @@ let Phase1 = {
require('proc.spawning').spawnworker(room) require('proc.spawning').spawnworker(room)
} }
} }
if((myroom.storage || myroom.terminal) && (creepcounts["mover"] < 2 || creepcounts["mover"]==undefined)){ if((myroom.storage!=undefined || myroom.terminal!=undefined) && (creepcounts["mover"] < 2 || creepcounts["mover"]==undefined)){
console.log("Spawning Mover in " + room) console.log("Spawning Mover in " + room)
require('proc.spawning').spawnmover(room) require('proc.spawning').spawnmover(room)
} }
@ -62,6 +76,7 @@ let Phase1 = {
} }
} }
if(Game.time % 4 === 0){ if(Game.time % 4 === 0){
/*
if(myroom.find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_TERMINAL}}).length > 0){ if(myroom.find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_TERMINAL}}).length > 0){
//console.log("starting market check for room " + room) //console.log("starting market check for room " + room)
try{ try{
@ -106,7 +121,7 @@ let Phase1 = {
console.log("Myroom" + myroom) console.log("Myroom" + myroom)
console.log(e) console.log(e)
} }
} }*/
} }
/* /*
if(links!=null && links!=undefined){ if(links!=null && links!=undefined){

View File

@ -22,7 +22,11 @@ module.exports.loop = function () {
} }
if(myroom.controller!==undefined){ if(myroom.controller!==undefined){
myroom.memory.tickssofar++ myroom.memory.tickssofar++
try{
require('Room.Phase' + myroom.memory.phase).run(name) require('Room.Phase' + myroom.memory.phase).run(name)
} catch(e){
console.log(e)
}
} }
for(let pos in myroom.memory.maphits){ for(let pos in myroom.memory.maphits){

View File

@ -31,11 +31,7 @@ let buildparts = {
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,WORK,MOVE]
[WORK,WORK,WORK,WORK,MOVE],
[WORK,WORK,WORK,MOVE],
[WORK,WORK,MOVE],
[WORK,MOVE]
]){ ]){
let ispossible = spawn.canCreateCreep(totry) let ispossible = spawn.canCreateCreep(totry)
if(ispossible==OK){ if(ispossible==OK){

View File

@ -8,6 +8,9 @@ let mover={
if(creep.memory.working==undefined){ if(creep.memory.working==undefined){
creep.memory.working=false creep.memory.working=false
} }
if(creep.memory.assignedroom==undefined){
creep.memory.assignedroom=creep.room.name
}
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
@ -25,100 +28,108 @@ let mover={
creep.memory.working = true; creep.memory.working = true;
creep.say('working'); creep.say('working');
} }
if(creep.memory.working){ if(creep.room.name != creep.memory.assignedroom){
//let terminaltarget = creep.room.terminal creep.moveTo(Game.rooms[creep.memory.assignedroom].controller)
let spawntarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER, STRUCTURE_LAB].includes(s.structureType)) && s.energy < s.energyCapacity ))}}) Game.notify(creep.name + " Not in assigned room")
if(spawntarget){
creep.say('ref sp')
if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(spawntarget,{ignoreCreeps:ignorecreeps})
}
} else {
try{
creep.say('finding storage')
let mystorage = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER) && s.store.getFreeCapacity()>0 ) ;}});
creep.say('got storage')
if(creep.transfer(mystorage, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.say('MvStor')
creep.moveTo(mystorage,{ignoreCreeps:ignorecreeps})
} else {
creep.say("Dumped")
}
} catch(e){
console.log(e)
}
}
/*else if(terminaltarget != creep.memory.pulledenergyfrom){
if(creep.transfer(terminaltarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE ) {
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]>200)}})) ) {
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 { } else {
if(filllevel < creep.carryCapacity){ if(creep.memory.working){
let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_CONTAINER) && s.store.getUsedCapacity('energy') >= 1000) ;}}); //let terminaltarget = creep.room.terminal
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>10)}}); let spawntarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER, STRUCTURE_LAB].includes(s.structureType)) && s.energy < s.energyCapacity ))}})
let tombstone = creep.pos.findClosestByRange(FIND_TOMBSTONES, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}}); if(spawntarget){
let ruins=creep.pos.findClosestByRange(FIND_RUINS, {filter: ruin => ruin.store.getUsedCapacity(RESOURCE_ENERGY) > 0}); creep.say('ref sp')
console.log(creep.room.name + " " + creep.name + " " + creep.room.energyAvailable+":"+ creep.room.energyCapacityAvailable ) if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
if(creep.room.energyAvailable < creep.room.energyCapacityAvailable || ((droppedenergy == undefined) && (tombstone==undefined) && (ruins==undefined))){ creep.moveTo(spawntarget,{ignoreCreeps:ignorecreeps})
if(storagetarget===undefined||storagetarget==null){
creep.say('finding storage')
storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE) && s.store.getUsedCapacity('energy') >= 10) ;}});
if((storagetarget==undefined ||storagetarget==null) && creep.room.terminal){
storagetarget=creep.room.terminal
}
}
if(creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
creep.say('GEST')
creep.travelTo(storagetarget);
} }
} else { } else {
if(ruins){ try{
if(creep.withdraw(ruins,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.say('finding storage')
if(global.verbosity>0){ let mystorage = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER) && s.store.getFreeCapacity()>0 ) ;}});
creep.say("MTRU"); creep.say('got storage')
} if(creep.transfer(mystorage, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(ruins,{ignoreCreeps:ignorecreeps}) creep.say('MvStor')
} creep.moveTo(mystorage,{ignoreCreeps:ignorecreeps})
}else if(droppedenergy){ } else {
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) { creep.say("Dumped")
if(global.verbosity>0){
creep.say("MTDE");
}
creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps})
}
} else {
if(creep.withdraw(tombstone,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){
creep.say("MTTS");
}
creep.moveTo(tombstone.pos,{ignoreCreeps:ignorecreeps})
} }
} catch(e){
console.log(e)
} }
} }
if(!storagetarget && (creep.carry > 0)){ /*else if(terminaltarget != creep.memory.pulledenergyfrom){
creep.memory.working=true if(creep.transfer(terminaltarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE ) {
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]>200)}})) ) {
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(creep.store.getUsedCapacity('energy') > 0){
creep.transfer(spawn,RESOURCE_ENERGY)
}
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_CONTAINER) && s.store.getUsedCapacity('energy') >= 200) ;}});
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>10)}});
let tombstone = creep.pos.findClosestByRange(FIND_TOMBSTONES, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}});
let ruins=creep.pos.findClosestByRange(FIND_RUINS, {filter: ruin => ruin.store.getUsedCapacity(RESOURCE_ENERGY) > 0});
console.log(creep.room.name + " " + creep.name + " " + creep.room.energyAvailable+":"+ creep.room.energyCapacityAvailable )
if(creep.room.energyAvailable < creep.room.energyCapacityAvailable || ((droppedenergy == undefined) && (tombstone==undefined) && (ruins==undefined))){
if(storagetarget===undefined||storagetarget==null){
creep.say('finding storage')
storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE) && s.store.getUsedCapacity('energy') >= 10) ;}});
if((storagetarget==undefined ||storagetarget==null) && creep.room.terminal){
storagetarget=creep.room.terminal
}
}
if(creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
creep.say('GEST')
creep.travelTo(storagetarget);
}
} else {
if(ruins){
if(creep.withdraw(ruins,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){
creep.say("MTRU");
}
creep.moveTo(ruins,{ignoreCreeps:ignorecreeps})
}
}else if(droppedenergy){
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){
creep.say("MTDE");
}
creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps})
}
} else {
if(creep.withdraw(tombstone,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){
creep.say("MTTS");
}
creep.moveTo(tombstone.pos,{ignoreCreeps:ignorecreeps})
}
}
}
if(!storagetarget && (creep.carry > 0)){
creep.memory.working=true
}
} }
} }
creep.memory.lastpos=creep.pos
} }
creep.memory.lastpos=creep.pos
} }
} }
module.exports = mover; module.exports = mover;

View File

@ -21,162 +21,171 @@ let Phase1Worker = {
let road = creep.pos.lookFor(LOOK_STRUCTURES); let road = creep.pos.lookFor(LOOK_STRUCTURES);
let filllevel = _.sum(creep.carry) let filllevel = _.sum(creep.carry)
if(creep.memory.working && filllevel == 0) { if(creep.room.name == creep.memory.assignedroom){
creep.memory.working = false; if(creep.memory.working && filllevel == 0) {
creep.say('Gathering'); creep.memory.working = false;
} creep.say('Gathering');
if(!creep.memory.working && creep.carry.energy == creep.carryCapacity) {
creep.memory.working = true;
creep.say('working');
}
if(creep.memory.working){
let look=creep.pos.lookFor(LOOK_STRUCTURES)
let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_TERMINAL ) && _.sum(s.store) < s.store.getCapacity()) ;}});
if(creep.room.memory.NeedsRecharge==1){
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
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,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})
}
} else if(creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_RAMPART].includes(s.structureType)) && s.hits < 20000))}})){
let ramparttarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return (((s.structureType == STRUCTURE_RAMPART) && s.hits < s.hitsMax))}});
if(creep.repair(ramparttarget) == ERR_NOT_IN_RANGE) {
creep.moveTo(ramparttarget,{ignoreCreeps:ignorecreeps})
}
} else if(creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES)){
target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES)
if(creep.build(target) == ERR_NOT_IN_RANGE) {
if (road.length > 0) {creep.repair(road);}
creep.moveTo(target,{ignoreCreeps:ignorecreeps})
}
} 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})
}
}else {
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.say('MTRC')
if (road.length > 0) {creep.repair(road);}
creep.moveTo(Game.rooms[creep.memory.assignedroom].controller,{ignoreCreeps:ignorecreeps})
}
} }
} else if (creep.pos.findClosestByRange(FIND_MY_SPAWNS) && (creep.ticksToLive < 300 || creep.ticksToLive <= creep.memory.renewto) && (Game.rooms[creep.room.name].find(FIND_MY_SPAWNS, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}})) ) { if(!creep.memory.working && creep.carry.energy == creep.carryCapacity) {
if(creep.memory.renewto == undefined){ creep.memory.working = true;
creep.memory.renewto = 1200 creep.say('working');
} else {
if(creep.ticksToLive >= creep.memory.renewto){
delete creep.memory.renewto
}
} }
creep.say('renewing') if(creep.memory.working){
console.log(creep.name + ": " + creep.ticksToLive + " " + creep.memory.renewto) let look=creep.pos.lookFor(LOOK_STRUCTURES)
let spawn = creep.pos.findClosestByRange(FIND_MY_SPAWNS) let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_TERMINAL ) && _.sum(s.store) < s.store.getCapacity()) ;}});
if(spawn != undefined && spawn!= null){ if(creep.room.memory.NeedsRecharge==1){
if(creep.room.memory.NeedsRecharge==1 && creep.carry.energy>0){
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) { if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.say(creep.room.controller.ticksToDowngrade + " of " + (CONTROLLER_DOWNGRADE[creep.room.controller.level] * .2)) creep.say(creep.room.controller.ticksToDowngrade + " of " + CONTROLLER_DOWNGRADE[creep.room.controller.level] * .2)
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,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})
}
} else if(creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_RAMPART].includes(s.structureType)) && s.hits < 20000))}})){
let ramparttarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return (((s.structureType == STRUCTURE_RAMPART) && s.hits < s.hitsMax))}});
if(creep.repair(ramparttarget) == ERR_NOT_IN_RANGE) {
creep.moveTo(ramparttarget,{ignoreCreeps:ignorecreeps})
}
} else if(creep.room.memory.currentconstruction){
target = Game.getObjectById(creep.room.memory.currentconstruction.id)
creep.moveTo(target,{ignoreCreeps:ignorecreeps})
if(creep.build(target) == ERR_NOT_IN_RANGE) {
if (road.length > 0) {creep.repair(road);}
creep.moveTo(target,{ignoreCreeps:ignorecreeps})
}
} 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})
}
}else {
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.say('MTRC')
if (road.length > 0) {creep.repair(road);}
creep.moveTo(Game.rooms[creep.memory.assignedroom].controller,{ignoreCreeps:ignorecreeps})
}
}
} else if (creep.pos.findClosestByRange(FIND_MY_SPAWNS) && (creep.ticksToLive < 300 || creep.ticksToLive <= creep.memory.renewto) && (Game.rooms[creep.room.name].find(FIND_MY_SPAWNS, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}})) ) {
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 != undefined && spawn!= null){
if(creep.room.memory.NeedsRecharge==1 && creep.carry.energy>0){
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.say(creep.room.controller.ticksToDowngrade + " of " + (CONTROLLER_DOWNGRADE[creep.room.controller.level] * .2))
creep.moveTo(creep.room.controller)
}
} else {
creep.transfer(spawn, RESOURCE_ENERGY)
if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE){
creep.say('MVSP')
creep.moveTo(spawn);
}
} }
} else { } else {
creep.memory.renewto=1
if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE){
creep.say('MVSP')
creep.moveTo(spawn);
}
} }
} else { } else {
creep.memory.renewto=1 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)}});
} else { let ruins=creep.pos.findClosestByRange(FIND_RUINS, {filter: ruin => ruin.store.getUsedCapacity(RESOURCE_ENERGY) > 0});
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>200)}}); let spawn= creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_SPAWN)}});
let tombstone = creep.pos.findClosestByRange(FIND_TOMBSTONES, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}}); //console.log(tombstone)
let ruins=creep.pos.findClosestByRange(FIND_RUINS, {filter: ruin => ruin.store.getUsedCapacity(RESOURCE_ENERGY) > 0}); if((droppedenergy == undefined || droppedenergy==null) && (tombstone==undefined || tombstone==null) && (spawn!=undefined || spawn!=null) && (ruins==undefined || ruins==null)){
let spawn= creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_SPAWN)}}); creep.say("1")
//console.log(tombstone) if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
if((droppedenergy == undefined || droppedenergy==null) && (tombstone==undefined || tombstone==null) && (spawn!=undefined || spawn!=null) && (ruins==undefined || ruins==null)){ let mysource=Game.getObjectById(creep.memory.destsource.id)
creep.say("1") try{
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined} //console.log(creep.room.memory.creepcounts)
let mysource=Game.getObjectById(creep.memory.destsource.id) if((mysource.energy==0 || ((creep.room.memory.creepcounts.sourceminer!=null ||creep.room.memory.creepcounts.sourceminer!=undefined )))){
try{ creep.say("2.1")
//console.log(creep.room.memory.creepcounts) //creep.say("No Energy Left to get")
if((mysource.energy==0 || ((creep.room.memory.creepcounts.sourceminer!=null ||creep.room.memory.creepcounts.sourceminer!=undefined )))){ let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_LINK) && s.store.getUsedCapacity('energy') >= 100) ;}});
creep.say("2.1") if(storagetarget===undefined || storagetarget==null){
//creep.say("No Energy Left to get") creep.say('2.2')
let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_LINK) && s.store.getUsedCapacity('energy') >= 100) ;}}); storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE) && s.store.getUsedCapacity('energy') >= creep.room.controller.level * 125000) ;}});
if(storagetarget===undefined || storagetarget==null){ if((storagetarget===undefined || storagetarget==null) && creep.room.terminal && creep.room.terminal.store.getUsedCapacity('energy') > 100000){
creep.say('2.2') creep.say('2.3')
storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE) && s.store.getUsedCapacity('energy') >= creep.room.controller.level * 125000) ;}}); storagetarget=creep.room.terminal
if((storagetarget===undefined || storagetarget==null) && creep.room.terminal && creep.room.terminal.store.getUsedCapacity('energy') > 100000){ }
creep.say('2.3')
storagetarget=creep.room.terminal
} }
} //console.log(Game.getObjectById(storagetarget.id))
//console.log(Game.getObjectById(storagetarget.id)) if((storagetarget != undefined || storagetarget != null)){
if((storagetarget != undefined || storagetarget != null)){ if( creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE){
if( creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE){ creep.say('3')
creep.say('3') //creep.say('Getting Energy')
//creep.say('Getting Energy') creep.travelTo(storagetarget);
creep.travelTo(storagetarget); }
} else {
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
creep.moveTo(mysource,{ignoreCreeps:ignorecreeps})
}
creep.say("NSE-Ming")
} }
} else { }else {
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})
} }
creep.say("NSE-Ming")
}
}else {
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
creep.moveTo(mysource,{ignoreCreeps:ignorecreeps})
} }
} catch(e){
console.log(e)
} }
} catch(e){ } else {
console.log(e) if(droppedenergy){
} if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
} else { if(global.verbosity>0){
if(droppedenergy){ creep.say("MTDE");
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) { }
if(global.verbosity>0){ creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps})
creep.say("MTDE");
} }
creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps}) } else if (tombstone) {
} if(creep.withdraw(tombstone,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
} else if (tombstone) {
if(creep.withdraw(tombstone,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){
creep.say("MTTS");
}
creep.moveTo(tombstone.pos,{ignoreCreeps:ignorecreeps})
}
} else if (ruins){
if(creep.withdraw(ruins,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){
creep.say("MTTS");
}
creep.moveTo(ruins,{ignoreCreeps:ignorecreeps})
}
} else if(spawn==null || spawn==undefined){
storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE)) ;}});
if(storagetarget){
if(creep.withdraw(storagetarget,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){ if(global.verbosity>0){
creep.say("MTTS"); creep.say("MTTS");
} }
creep.moveTo(storagetarget,{ignoreCreeps:ignorecreeps}) creep.moveTo(tombstone.pos,{ignoreCreeps:ignorecreeps})
} }
} else if (ruins){
if(creep.withdraw(ruins,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){
creep.say("MTTS");
}
creep.moveTo(ruins,{ignoreCreeps:ignorecreeps})
}
} else if(spawn==null || spawn==undefined){
storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE)) ;}});
if(storagetarget){
if(creep.withdraw(storagetarget,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){
creep.say("MTTS");
}
creep.moveTo(storagetarget,{ignoreCreeps:ignorecreeps})
}
} else {
let mysource=Game.getObjectById(creep.memory.destsource.id)
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
creep.moveTo(mysource,{ignoreCreeps:ignorecreeps})
}
}
} else {
creep.say("IDK")
} }
} else {
creep.say("IDK")
} }
} }
creep.memory.lastpos=creep.pos
} else {
creep.moveTo(Game.rooms[creep.memory.assignedroom].controller)
} }
creep.memory.lastpos=creep.pos }
}
}; };
module.exports = Phase1Worker; module.exports = Phase1Worker;

View File

@ -29,23 +29,23 @@ let rolesourceMiner = {
} else{ } else{
try{ try{
creep.say('1') creep.say('1')
destcontainer=Game.getObjectById(creep.memory.destsource.id).pos.findInRange(FIND_STRUCTURES,1,{filter: (s) => {return (s.structureType == STRUCTURE_CONTAINER && s.store.getFreeCapacity() > 0) ;}}) let destcontainer=Game.getObjectById(creep.memory.destsource.id).pos.findInRange(FIND_STRUCTURES,1,{filter: (s) => {return (s.structureType == STRUCTURE_CONTAINER && s.store.getFreeCapacity() > 0) ;}})
//console.log(creep.room.name + " " + destcontainer)
if(destcontainer == undefined || destcontainer == null){ if(destcontainer != undefined || destcontainer != null){
creep.say('2') creep.say('2')
console.log(creep.name + " " + destcontainer[0].id) console.log(creep.name + " " + destcontainer[0].id)
creep.travelTo(destcontainer[0]) creep.travelTo(destcontainer[0])
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) { if(creep.harvest(mysource) == ERR_NOT_IN_RANGE || creep.harvest(mysource)==ERR_NOT_ENOUGH_RESOURCES) {
//let mycontainer = creep.find(FIND_STRUCTURES, {filter: (s) => {return (s.structureType == STRUCTURE_CONTAINER) ;}}); //let mycontainer = creep.find(FIND_STRUCTURES, {filter: (s) => {return (s.structureType == STRUCTURE_CONTAINER) ;}});
creep.travelTo(destcontainer[0],{ignoreCreeps:ignorecreeps}); creep.travelTo(destcontainer[0],{ignoreCreeps:ignorecreeps});
}
} else {
creep.say('3')
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE|| creep.harvest(mysource)==ERR_NOT_ENOUGH_RESOURCES) {
//let mycontainer = creep.find(FIND_STRUCTURES, {filter: (s) => {return (s.structureType == STRUCTURE_CONTAINER) ;}});
creep.travelTo(mysource,{ignoreCreeps:ignorecreeps});
}
} }
} else {
creep.say('3')
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) {
//let mycontainer = creep.find(FIND_STRUCTURES, {filter: (s) => {return (s.structureType == STRUCTURE_CONTAINER) ;}});
creep.travelTo(mysource,{ignoreCreeps:ignorecreeps});
}
}
} catch(e){ } catch(e){
console.log(e) console.log(e)
} }