screeps/Room.Phase1.js

72 lines
4.7 KiB
JavaScript
Raw Normal View History

2020-11-09 19:31:39 -06:00
let Phase1 = {
run: function(room) {
let myroom=Game.rooms[room]
2020-11-09 19:31:39 -06:00
require('assignsources').tick(room)
if(Game.time % 1 === 0){
2020-11-09 19:31:39 -06:00
//console.log('processing spawn')
let myspawns = myroom.find(FIND_MY_SPAWNS)
2020-11-09 19:31:39 -06:00
if(myspawns.length>0){
let myspawn = myspawns[0]
let creepcount = myroom.find(FIND_MY_CREEPS).length
creepcounts = _.countBy(myroom.find(FIND_MY_CREEPS), c => c.memory.role)
myroom.memory.movercount=creepcounts["mover"]
let workerrolename = 'phase' + myroom.memory.phase +'worker'
let sources = myroom.find(FIND_SOURCES )
if(myroom.controller.ticksToDowngrade < CONTROLLER_DOWNGRADE[myroom.controller.level] * .2 ){
myroom.memory.NeedsRecharge=1
console.log(room + " needs Recharge " + myroom.memory.NeedsRecharge)
2020-11-09 19:31:39 -06:00
}
if(myroom.controller.ticksToDowngrade > CONTROLLER_DOWNGRADE[myroom.controller.level]*.8){
myroom.memory.NeedsRecharge=0
2020-11-09 19:31:39 -06:00
}
if(Game.flags.debug && Game.flags.debug.room == myroom){
2020-11-09 19:31:39 -06:00
console.log(room)
console.log(workerrolename)
console.log(creepcounts[workerrolename])
console.log(myroom.energyAvailable + " of " + myroom.energyCapacityAvailable)
2020-11-09 19:31:39 -06:00
}
if(myroom.memory.minablepositions >= 3 ||myroom.memory.minablepositions==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)
require('proc.spawning').spawnworker(room)
}
} else {
if((((creepcounts['sourceminer']< myroom.memory.minablepositions) || creepcounts['sourceminer']==undefined) && myroom.energyAvailable >= myroom.energyCapacityAvailable) || ((creepcounts['sourceminer']==0 || creepcounts['sourceminer']==undefined ) && myroom.energyAvailable>100)) {
console.log('Spawning sourceminer in ' + room)
require('proc.spawning').spawnsourceminer(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)
require('proc.spawning').spawnworker(room)
}
2020-11-09 19:31:39 -06:00
}
if((myroom.storage || myroom.terminal) && (creepcounts["mover"] < 2 || creepcounts["mover"]==undefined)){
2020-11-14 01:18:05 -06:00
console.log("Spawning Mover in " + room)
2020-11-09 19:31:39 -06:00
require('proc.spawning').spawnmover(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 ){
2020-11-17 10:30:13 -06:00
console.log("Spawning Miner in " + room)
require('proc.spawning').spawnminer(room)
} else { if(Game.flags.debug && Game.flags.debug.room == myroom){console.log("Not spawning miner in " + room + ", waiting for regen")}}
2020-11-14 01:18:05 -06:00
}
if(myroom.find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_TERMINAL}}).length > 0){
console.log("starting market check for room " + room)
2022-04-27 00:12:54 -05:00
try{
let availtosell = myroom.terminal.store.getUsedCapacity([RESOURCE_ENERGY]) - 200000
2022-04-27 00:12:54 -05:00
if(availtosell > 1000){
require('proc.market').sellEnergy(room)
}
}catch{
console.log("Myroom" + myroom)
console.log("Room" + room)
2022-04-27 00:02:31 -05:00
}
2022-04-26 23:51:44 -05:00
}
2020-11-09 19:31:39 -06:00
//require('proc.market').sellEnergy(room)
}
}
if(myroom.controller.level>2){ }
2020-11-09 19:31:39 -06:00
}
};
module.exports = Phase1;