screeps/Room.Phase0.js

55 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2020-11-09 19:31:39 -06:00
let Phase0 = {
run: function(room) {
require('assignsources').tick(room)
2022-06-01 09:39:13 -05:00
let creepcounts = _.countBy(Game.rooms[room].find(FIND_MY_CREEPS), c => c.memory.role)
if(creepcounts===undefined){creepcounts['phase' + Game.rooms[room].memory.phase +'worker']=0}
Game.rooms[room].memory.creepcounts=creepcounts
2020-11-09 19:31:39 -06:00
let myspawns = Game.rooms[room].find(FIND_MY_SPAWNS)
let sources = Game.rooms[room].find(FIND_SOURCES )
if(myspawns.length<1){
if(Game.rooms[room].controller.level>1){
Game.rooms[room].memory.phase++
let creeps=Game.rooms[room].find(FIND_MY_CREEPS)
let newworkerrolename = 'phase' + Game.rooms[room].memory.phase + 'worker'
for(let mycreep in creeps){
creep=creeps[mycreep]
2022-05-23 15:59:00 -05:00
if(creep.memory.role != newworkerrolename){
2020-11-09 19:31:39 -06:00
creep.memory.role=newworkerrolename
}
}
Game.rooms[room].memory['tickstophase' + Game.rooms[room].memory.phase]=Game.rooms[room].memory.tickssofar
console.log(Game.rooms[room].memory['tickstophase' + Game.rooms[room].memory.phase])
}
} else {
let workerrolename = 'phase' + Game.rooms[room].memory.phase +'worker'
console.log(room)
2022-06-01 09:39:13 -05:00
console.log("room.phase0.js "+workerrolename + " : " + creepcounts[workerrolename])
if(( creepcounts[workerrolename] == undefined ||(creepcounts[workerrolename]< (sources.length * 1) || creepcounts[workerrolename]==undefined) && !myspawns[0].spawning && Game.rooms[room].energyAvailable == Game.rooms[room].energyCapacityAvailable) || (creepcounts[workerrolename] ==0 && Game.rooms[room].energyAvailable==300) ){
2020-11-09 19:31:39 -06:00
if(Game.rooms[room].energyAvailable == Game.rooms[room].energyCapacityAvailable){
require('proc.spawning').spawnworker(room)
}
} else { }
2022-05-23 15:59:00 -05:00
if(Game.rooms[room].controller.level>1 && Game.rooms[room].spawn){
2020-11-09 19:31:39 -06:00
Game.rooms[room].memory.phase++
let creeps=Game.rooms[room].find(FIND_MY_CREEPS)
let newworkerrolename = 'phase' + Game.rooms[room].memory.phase + 'worker'
for(let mycreep in creeps){
creep=creeps[mycreep]
if(creep.memory.role == workerrolename){
creep.memory.role=newworkerrolename
}
}
Game.rooms[room].memory['tickstophase' + Game.rooms[room].memory.phase]=Game.rooms[room].memory.tickssofar
console.log(Game.rooms[room].memory['tickstophase' + Game.rooms[room].memory.phase])
}
}
}
};
module.exports = Phase0;