From 2a94fffaaec0d475760bd7ad877bc190edf74a2f Mon Sep 17 00:00:00 2001 From: Dan Hamik Date: Wed, 11 May 2022 08:40:08 -0500 Subject: [PATCH] adding ability to pass roomnames or not as appropriate --- Empire.js | 79 ++++++++++++++++++++++++++++++------------ proc.creepfunctions.js | 5 +++ proc.spawning.js | 6 +++- 3 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 proc.creepfunctions.js diff --git a/Empire.js b/Empire.js index 6daa2aa..671e2fd 100644 --- a/Empire.js +++ b/Empire.js @@ -39,58 +39,93 @@ module.exports = { } return 'Spawning initiated' }, - spawnnrworker: function(){ - for(let myroom of _.filter(Game.rooms, 'controller.my')) { - let name = myroom.name + spawnnrworker: function(name){ + if(name==null || name== undefined){ + for(let myroom of _.filter(Game.rooms, 'controller.my')) { + let name = myroom.name + require('proc.spawning').spawnnrworker(name) + } + } else { require('proc.spawning').spawnnrworker(name) } return 'Spawning initiated' }, - spawnworker: function(){ - for(let myroom of _.filter(Game.rooms, 'controller.my')) { - let name = myroom.name + spawnworker: function(name){ + if(name!=null && name!= undefined){ + for(let myroom of _.filter(Game.rooms, 'controller.my')) { + let name = myroom.name + require('proc.spawning').spawnworker(name) + } + } else { require('proc.spawning').spawnworker(name) } return 'Spawning initiated' }, - spawnminer: function(){ - for(let myroom of _.filter(Game.rooms, 'controller.my')) { - let name = myroom.name + spawnminer: function(name){ + if(name!=null && name!= undefined){ + for(let myroom of _.filter(Game.rooms, 'controller.my')) { + let name = myroom.name + require('proc.spawning').spawnsourceminer(name) + } + } else { require('proc.spawning').spawnsourceminer(name) } return 'Spawning initiated' }, - spawnmover: function(){ - for(let myroom of _.filter(Game.rooms, 'controller.my')) { - let name = myroom.name + spawnmover: function(name){ + if(name!=null && name!= undefined){ + for(let myroom of _.filter(Game.rooms, 'controller.my')) { + let name = myroom.name + require('proc.spawning').spawnmover(name) + } + } else { require('proc.spawning').spawnmover(name) } return 'Spawning initiated' }, - spawnclaimer: function(){ - for(let myroom of _.filter(Game.rooms, 'controller.my')) { - let name = myroom.name + spawnclaimer: function(name){ + if(name!=null && name!= undefined){ + for(let myroom of _.filter(Game.rooms, 'controller.my')) { + let name = myroom.name + require('proc.spawning').spawnclaimer(name) + } + } else { require('proc.spawning').spawnclaimer(name) } return 'Spawning initiated' }, - removeConstruction: function(roomname){ - _.invoke(Game.rooms[roomname].find(FIND_MY_CONSTRUCTION_SITES), 'remove') + removeConstruction: function(name){ + if(name==null || name== undefined){ + for(let myroom of _.filter(Game.rooms, 'controller.my')) { + let name = myroom.name + _.invoke(Game.rooms[name].find(FIND_MY_CONSTRUCTION_SITES), 'remove') + } + } else { + _.invoke(Game.rooms[name].find(FIND_MY_CONSTRUCTION_SITES), 'remove') + } }, removeAllConstruction: function(){ _.invoke(_.map(Game.constructionSites, (x)=>x), 'remove') }, - removeWalls: function(roomname){ - Game.rooms[roomname].find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_WALL}).forEach(s => s.destroy()) + removeWalls: function(name){ + if(name==null || name== undefined){ + for(let myroom of _.filter(Game.rooms, 'controller.my')) { + let name = myroom.name + Game.rooms[name].find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_WALL}).forEach(s => s.destroy()) + } + } else { + Game.rooms[name].find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_WALL}).forEach(s => s.destroy()) + } }, - removeRoads: function(roomname,hitsleft){ - Game.rooms[roomname].find(FIND_STRUCTURES, {filter: s => (s.structureType === STRUCTURE_ROAD && s.hits < hitsleft)}).forEach(s => s.destroy()) + removeRoads: function(name,hitsleft){ + Game.rooms[name].find(FIND_STRUCTURES, {filter: s => (s.structureType === STRUCTURE_ROAD && s.hits < hitsleft)}).forEach(s => s.destroy()) return "done" }, - sellEnergy: function(roomname){ + sellEnergy: function(name){ let myorders = Game.market.getAllOrders(order=>order.resourceType == RESOURCE_ENERGY && order.type == ORDER_SELL) }, computeSourceAccess: function(){ + for(let myroom of _.filter(Game.rooms, 'controller.my')) { let name = myroom.name let minablepositions = 0 diff --git a/proc.creepfunctions.js b/proc.creepfunctions.js new file mode 100644 index 0000000..a5463e6 --- /dev/null +++ b/proc.creepfunctions.js @@ -0,0 +1,5 @@ +module.exports = { + spawnwarrior: function(){ + + } +} \ No newline at end of file diff --git a/proc.spawning.js b/proc.spawning.js index 1c4a50f..e7bb31f 100644 --- a/proc.spawning.js +++ b/proc.spawning.js @@ -94,7 +94,11 @@ let buildparts = { break; } } - let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time,role:"phase" + Game.rooms[roomname].memory.phase +"worker"}) + if(tobuild != null && tobuild != undefined){ + let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time,role:"phase" + Game.rooms[roomname].memory.phase +"worker"}) + } else { + console.log("not enough e in " + roomname + " to spawn") + } }} },