add shortened variable for game.rooms[room]

This commit is contained in:
Dan Hamik 2022-04-27 00:51:11 -05:00
parent a70c1f3ec1
commit d314f52c66

View File

@ -1,69 +1,72 @@
let Phase1 = { let Phase1 = {
run: function(room) { run: function(room) {
let myroom=Game.rooms[room]
require('assignsources').tick(room) require('assignsources').tick(room)
if(Game.time % 10 === 0){ if(Game.time % 1 === 0){
//console.log('processing spawn') //console.log('processing spawn')
let myspawns = Game.rooms[room].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 = Game.rooms[room].find(FIND_MY_CREEPS).length let creepcount = myroom.find(FIND_MY_CREEPS).length
creepcounts = _.countBy(Game.rooms[room].find(FIND_MY_CREEPS), c => c.memory.role) creepcounts = _.countBy(myroom.find(FIND_MY_CREEPS), c => c.memory.role)
Game.rooms[room].memory.movercount=creepcounts["mover"] myroom.memory.movercount=creepcounts["mover"]
let workerrolename = 'phase' + Game.rooms[room].memory.phase +'worker' let workerrolename = 'phase' + myroom.memory.phase +'worker'
let sources = Game.rooms[room].find(FIND_SOURCES ) let sources = myroom.find(FIND_SOURCES )
if(Game.rooms[room].controller.ticksToDowngrade < CONTROLLER_DOWNGRADE[Game.rooms[room].controller.level] * .2 ){ if(myroom.controller.ticksToDowngrade < CONTROLLER_DOWNGRADE[myroom.controller.level] * .2 ){
Game.rooms[room].memory.NeedsRecharge=1 myroom.memory.NeedsRecharge=1
console.log(room + " needs Recharge " + Game.rooms[room].memory.NeedsRecharge) console.log(room + " needs Recharge " + myroom.memory.NeedsRecharge)
} }
if(Game.rooms[room].controller.ticksToDowngrade > CONTROLLER_DOWNGRADE[Game.rooms[room].controller.level]*.8){ if(myroom.controller.ticksToDowngrade > CONTROLLER_DOWNGRADE[myroom.controller.level]*.8){
Game.rooms[room].memory.NeedsRecharge=0 myroom.memory.NeedsRecharge=0
} }
if(Game.flags.debug && Game.flags.debug.room == Game.rooms[room]){ if(Game.flags.debug && Game.flags.debug.room == myroom){
console.log(room) console.log(room)
console.log(workerrolename) console.log(workerrolename)
console.log(creepcounts[workerrolename]) console.log(creepcounts[workerrolename])
console.log(Game.rooms[room].energyAvailable + " of " + Game.rooms[room].energyCapacityAvailable) console.log(myroom.energyAvailable + " of " + myroom.energyCapacityAvailable)
} }
if(Game.rooms[room].memory.minablepositions >= 3 ||Game.rooms[room].memory.minablepositions==undefined ){ if(myroom.memory.minablepositions >= 3 ||myroom.memory.minablepositions==undefined ){
if((((creepcounts[workerrolename]< (Game.rooms[room].memory.minablepositions + 1) || 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]< (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) console.log('Spawning worker in ' + room)
require('proc.spawning').spawnworker(room) require('proc.spawning').spawnworker(room)
} }
} else { } else {
if((((creepcounts['sourceminer']< Game.rooms[room].memory.minablepositions) || creepcounts['sourceminer']==undefined) && Game.rooms[room].energyAvailable >= Game.rooms[room].energyCapacityAvailable) || ((creepcounts['sourceminer']==0 || creepcounts['sourceminer']==undefined ) && Game.rooms[room].energyAvailable>100)) { 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) console.log('Spawning sourceminer in ' + room)
require('proc.spawning').spawnsourceminer(room) require('proc.spawning').spawnsourceminer(room)
} }
if((((creepcounts[workerrolename]< (Game.rooms[room].memory.minablepositions+1) || 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]< (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) 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"] < 2 || creepcounts["mover"]==undefined)){ if((myroom.storage || myroom.terminal) && (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)
} }
if((Game.rooms[room].find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_EXTRACTOR}}).length > 0)&&(creepcounts["miner"] < Game.rooms[room].memory.mineralminablepositions || creepcounts["miner"]==undefined)&&(Game.rooms[room].energyAvailable >= Game.rooms[room].energyCapacityAvailable)){ 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(Game.rooms[room].find(FIND_MINERALS)[0].ticksToRegeneration == undefined || Game.rooms[room].find(FIND_MINERALS)[0].ticksToRegeneration < 1000 ){ if(myroom.find(FIND_MINERALS)[0].ticksToRegeneration == undefined || myroom.find(FIND_MINERALS)[0].ticksToRegeneration < 1000 ){
console.log("Spawning Miner in " + room) console.log("Spawning Miner in " + room)
require('proc.spawning').spawnminer(room) require('proc.spawning').spawnminer(room)
} else { if(Game.flags.debug && Game.flags.debug.room == Game.rooms[room]){console.log("Not spawning miner in " + room + ", waiting for regen")}} } else { if(Game.flags.debug && Game.flags.debug.room == myroom){console.log("Not spawning miner in " + room + ", waiting for regen")}}
} }
if(Game.rooms[room].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 " + Game.rooms[room]) console.log("starting market check for room " + room)
try{ try{
let availtosell = Game.rooms[room].terminal.storage[RESOURCE_ENERGY] - 200000 let availtosell = myroom.terminal.store.getUsedCapacity([RESOURCE_ENERGY]) - 200000
if(availtosell > 1000){ if(availtosell > 1000){
require('proc.market').sellEnergy(room) require('proc.market').sellEnergy(room)
} }
}catch{ }catch{
console.log("Failed to get energy for terminal in room " + Game.rooms[room]) console.log("Myroom" + myroom)
console.log("Room" + room)
} }
} }
//require('proc.market').sellEnergy(room) //require('proc.market').sellEnergy(room)
} }
} }
if(Game.rooms[room].controller.level>2){ } if(myroom.controller.level>2){ }
} }
}; };
module.exports = Phase1; module.exports = Phase1;