mirror of
https://github.com/paradizelost/screeps.git
synced 2024-11-25 02:14:44 -06:00
mining/mover fixes
This commit is contained in:
parent
36c253fa36
commit
5c5b9003ad
32
Empire.js
32
Empire.js
@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -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)
|
||||||
|
@ -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){
|
||||||
|
4
main.js
4
main.js
@ -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){
|
||||||
|
@ -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){
|
||||||
|
@ -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,6 +28,10 @@ let mover={
|
|||||||
creep.memory.working = true;
|
creep.memory.working = true;
|
||||||
creep.say('working');
|
creep.say('working');
|
||||||
}
|
}
|
||||||
|
if(creep.room.name != creep.memory.assignedroom){
|
||||||
|
creep.moveTo(Game.rooms[creep.memory.assignedroom].controller)
|
||||||
|
Game.notify(creep.name + " Not in assigned room")
|
||||||
|
} else {
|
||||||
if(creep.memory.working){
|
if(creep.memory.working){
|
||||||
//let terminaltarget = creep.room.terminal
|
//let terminaltarget = creep.room.terminal
|
||||||
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 spawntarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER, STRUCTURE_LAB].includes(s.structureType)) && s.energy < s.energyCapacity ))}})
|
||||||
@ -65,13 +72,16 @@ let mover={
|
|||||||
//console.log(creep.name + ": " + creep.ticksToLive + " " + creep.memory.renewto)
|
//console.log(creep.name + ": " + creep.ticksToLive + " " + creep.memory.renewto)
|
||||||
creep.say('renewing')
|
creep.say('renewing')
|
||||||
let spawn = creep.pos.findClosestByRange(FIND_MY_SPAWNS)
|
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)
|
if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE)
|
||||||
{
|
{
|
||||||
creep.moveTo(spawn);
|
creep.moveTo(spawn);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(filllevel < creep.carryCapacity){
|
if(filllevel < creep.carryCapacity){
|
||||||
let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_CONTAINER) && s.store.getUsedCapacity('energy') >= 1000) ;}});
|
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 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 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});
|
let ruins=creep.pos.findClosestByRange(FIND_RUINS, {filter: ruin => ruin.store.getUsedCapacity(RESOURCE_ENERGY) > 0});
|
||||||
@ -120,5 +130,6 @@ let mover={
|
|||||||
}
|
}
|
||||||
creep.memory.lastpos=creep.pos
|
creep.memory.lastpos=creep.pos
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
module.exports = mover;
|
module.exports = mover;
|
@ -21,6 +21,7 @@ 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.room.name == creep.memory.assignedroom){
|
||||||
if(creep.memory.working && filllevel == 0) {
|
if(creep.memory.working && filllevel == 0) {
|
||||||
creep.memory.working = false;
|
creep.memory.working = false;
|
||||||
creep.say('Gathering');
|
creep.say('Gathering');
|
||||||
@ -29,8 +30,6 @@ let Phase1Worker = {
|
|||||||
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_TERMINAL ) && _.sum(s.store) < s.store.getCapacity()) ;}});
|
let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_TERMINAL ) && _.sum(s.store) < s.store.getCapacity()) ;}});
|
||||||
@ -49,8 +48,9 @@ let Phase1Worker = {
|
|||||||
if(creep.repair(ramparttarget) == ERR_NOT_IN_RANGE) {
|
if(creep.repair(ramparttarget) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(ramparttarget,{ignoreCreeps:ignorecreeps})
|
creep.moveTo(ramparttarget,{ignoreCreeps:ignorecreeps})
|
||||||
}
|
}
|
||||||
} else if(creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES)){
|
} else if(creep.room.memory.currentconstruction){
|
||||||
target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES)
|
target = Game.getObjectById(creep.room.memory.currentconstruction.id)
|
||||||
|
creep.moveTo(target,{ignoreCreeps:ignorecreeps})
|
||||||
if(creep.build(target) == ERR_NOT_IN_RANGE) {
|
if(creep.build(target) == ERR_NOT_IN_RANGE) {
|
||||||
if (road.length > 0) {creep.repair(road);}
|
if (road.length > 0) {creep.repair(road);}
|
||||||
creep.moveTo(target,{ignoreCreeps:ignorecreeps})
|
creep.moveTo(target,{ignoreCreeps:ignorecreeps})
|
||||||
@ -85,7 +85,7 @@ let Phase1Worker = {
|
|||||||
creep.moveTo(creep.room.controller)
|
creep.moveTo(creep.room.controller)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
creep.transfer(spawn, RESOURCE_ENERGY)
|
||||||
if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE){
|
if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE){
|
||||||
creep.say('MVSP')
|
creep.say('MVSP')
|
||||||
creep.moveTo(spawn);
|
creep.moveTo(spawn);
|
||||||
@ -170,13 +170,22 @@ let Phase1Worker = {
|
|||||||
}
|
}
|
||||||
creep.moveTo(storagetarget,{ignoreCreeps:ignorecreeps})
|
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 {
|
} else {
|
||||||
creep.say("IDK")
|
creep.say("IDK")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
creep.memory.lastpos=creep.pos
|
creep.memory.lastpos=creep.pos
|
||||||
|
} else {
|
||||||
|
creep.moveTo(Game.rooms[creep.memory.assignedroom].controller)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
module.exports = Phase1Worker;
|
module.exports = Phase1Worker;
|
||||||
|
@ -29,19 +29,19 @@ 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 {
|
} else {
|
||||||
creep.say('3')
|
creep.say('3')
|
||||||
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(mysource,{ignoreCreeps:ignorecreeps});
|
creep.travelTo(mysource,{ignoreCreeps:ignorecreeps});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user