From c525c49b7426bbff07b4c25cf5a3dac174d529dc Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 18 Nov 2020 08:30:01 -0600 Subject: [PATCH 1/2] try catch blocks in main.js to keep things running smoothly. --- main.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index bb09b63..9581a02 100644 --- a/main.js +++ b/main.js @@ -5,6 +5,7 @@ global.verbosity=0 module.exports.loop = function () { console.log("----Start loop for "+ Game.time + '----') let decrementcounter = Game.time % 30 + try{ for(let name in Game.rooms){ let myroom=Game.rooms[name] @@ -32,15 +33,16 @@ module.exports.loop = function () { delete myroom.memory.maphits[pos] } } - } + }} catch(e) {console.log("Error processing rooms: "+ e + " " + e.stack)} + try{ for(let name in Memory.creeps) { if(!Game.creeps[name]) { delete Memory.creeps[name]; if(global.verbosity>0){ } } else { + let creep = Game.creeps[name] try{ - let creep = Game.creeps[name] if(creep.spawning) return; if(creep.fatigue>0){ if(creep.room.memory.maphits==undefined){ @@ -64,17 +66,20 @@ module.exports.loop = function () { require('role.' + creep.memory.role).run(creep) //creep.say("TRYING") } catch (e) { - console.log("creep error " + Game.creeps[name]) + creep.say('🦄') + console.log("creep error " + creep.name) console.log(e) + console.log(e.stack) } } //console.log('done running creeps') - } + }} catch(e) {console.log("Error processing creeps: "+ e.stack)} + try{ let flags = Game.flags for(let flag in flags){ //console.log('running flags') require('flag.' + flag ).run() - } + }} catch(e) {console.log("Error processing flags: "+ e.stack)} for(let name in Memory.rooms) { // console.log('cleaning up old rooms') let myroom = Game.rooms[name] From e4831aa8e8fd758dfdb3df8ca7442762b7a7a227 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 18 Nov 2020 09:04:06 -0600 Subject: [PATCH 2/2] Fix miner spawn bug and add check for how many positions are usable when mining. increase miner spawns to match this number, add Empire function to init all rooms with this data. --- Empire.js | 14 ++++++++++++++ Room.Phase1.js | 4 ++-- RoomInit.js | 9 +++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Empire.js b/Empire.js index b593bd2..fcc5e78 100644 --- a/Empire.js +++ b/Empire.js @@ -96,6 +96,20 @@ module.exports = { Game.rooms[name].memory.minablepositions = minablepositions } }, + computeMineralAccess: function(){ + for(let myroom of _.filter(Game.rooms, 'controller.my')) { + let name = myroom.name + let mineralminablepositions = 0 + let minerals = Game.rooms[name].find(FIND_MINERALS); + for(let i = 0;i 0)&&(creepcounts["miner"] < 1 || creepcounts["miner"]==undefined)&&(Game.rooms[room].energyAvailable >= Game.rooms[room].energyCapacityAvailable)){ - if(Game.rooms[room].find(FIND_MINERALS)[0].ticksToRegeneration < 1000){ + 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(Game.rooms[room].find(FIND_MINERALS)[0].ticksToRegeneration == undefined || Game.rooms[room].find(FIND_MINERALS)[0].ticksToRegeneration < 1000 ){ console.log("Spawning Miner in " + 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")}} diff --git a/RoomInit.js b/RoomInit.js index bcd5aa6..1a983a2 100644 --- a/RoomInit.js +++ b/RoomInit.js @@ -10,6 +10,15 @@ let initroom = { Game.rooms[name].memory.tickssofar=0 Game.rooms[name].memory.maphits={} //Game.rooms[name].memory.minablepositions= this.checkminablepositions(name) + let mineralminablepositions = 0 + let minerals = Game.rooms[name].find(FIND_MINERALS); + for(let i = 0;i