2017-06-06 13:17:26 -05:00
|
|
|
let buildparts=require('bodypartbuilder')
|
|
|
|
let processSpawns = {
|
|
|
|
tick: function(roomname) {
|
|
|
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
|
|
|
for(let spawn of myspawns){
|
|
|
|
if(spawn.spawning){spawn.memory.spawnqueued=true}else {spawn.memory.spawnqueued=false}
|
|
|
|
}
|
|
|
|
let energyready = Game.rooms[roomname].energyAvailable
|
|
|
|
let energymax = Game.rooms[roomname].energyCapacityAvailable
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log(Game.rooms[roomname].memory.tickssincespawn)
|
|
|
|
console.log(energyready / energymax)
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
if(energyready==energymax || energyready / energymax > .5 ||Game.rooms[roomname].memory.tickssincespawn>50){
|
|
|
|
Game.rooms[roomname].memory.tickssincespawn=0
|
|
|
|
let allcreeps = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS));
|
|
|
|
let allbuilders = _.filter(allcreeps,(creep) => (creep.memory.role=='builder'))
|
|
|
|
let allminers = _.filter(allcreeps,(creep) => (creep.memory.role=='miner'))
|
|
|
|
let allminer2s = _.filter(allcreeps,(creep) => (creep.memory.role=='miner2'))
|
|
|
|
let allhaulers = _.filter(allcreeps,(creep) => (creep.memory.role=='hauler'))
|
|
|
|
let allhauler2s = _.filter(allcreeps,(creep) => (creep.memory.role=='hauler2'))
|
|
|
|
let allhauler3s = _.filter(allcreeps,(creep) => (creep.memory.role=='hauler3'))
|
|
|
|
let alltowerrechargers = _.filter(allcreeps,(creep) => (creep.memory.role=='towerrecharger'))
|
|
|
|
let allrepairbots = _.filter(allcreeps,(creep) => (creep.memory.role=='repairbot'))
|
|
|
|
let allupgraders = _.filter(allcreeps,(creep) => (creep.memory.role=='upgrader'))
|
|
|
|
let allwarriors = _.filter(allcreeps,(creep) => (creep.memory.role=='warrior'))
|
|
|
|
let allclaimers = _.filter(allcreeps,(creep) => (creep.memory.role=='claimer'))
|
|
|
|
let allnrbuilders = _.filter(allcreeps,(creep) => (creep.memory.role=='nrbuilder'))
|
|
|
|
let allnrminers = _.filter(allcreeps,(creep) => (creep.memory.role=='nrminer'))
|
|
|
|
|
|
|
|
//console.log(allcreeps.length + " " + allbuilders.length + " " + allminers.length + " " + allhaulers.length + " " + allhauler2s.length + " " + alltowerrechargers.length + " " + allrepairbots.length + " " + allupgraders.length + " " + allwarriors.length)
|
|
|
|
for(let spawn of myspawns){
|
|
|
|
if(!spawn.spawning && !spawn.memory.spawnqueued){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('WOULD SPAWN AT '+ spawn.name)
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
//spawn.memory.spawnqueued=true
|
|
|
|
|
|
|
|
if(Game.rooms[roomname].memory.maxminers > allminers.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn miner')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'miner')
|
|
|
|
spawn.memory.spawnqueued=true
|
|
|
|
} else if(Game.rooms[roomname].memory.maxminer2s > allminer2s.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn miner2s')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'miner2')
|
|
|
|
spawn.memory.spawnqueued=true
|
|
|
|
} else if(Game.rooms[roomname].memory.maxhaulers > allhaulers.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn hauler')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'hauler')
|
|
|
|
spawn.memory.spawnqueued=true
|
|
|
|
}else if(Game.rooms[roomname].memory.maxhauler3s > allhauler3s.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn hauler3')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'hauler3')
|
|
|
|
spawn.memory.spawnqueued=true
|
|
|
|
}else if(Game.rooms[roomname].memory.maxupgraders > allupgraders.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn upgrader')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'upgrader')
|
|
|
|
spawn.memory.spawnqueued=true
|
|
|
|
} else if(Game.rooms[roomname].memory.maxhauler2s > allhauler2s.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn hauler2')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'hauler2')
|
|
|
|
spawn.memory.spawnqueued=true
|
|
|
|
} else if(Game.rooms[roomname].memory.maxtowerrechargers > alltowerrechargers.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn towerrecharger')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'towerrecharger')
|
|
|
|
spawn.memory.spawnqueued=true
|
|
|
|
} else if(Game.rooms[roomname].memory.maxrepairbots > allrepairbots.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn repairbot')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'repairbot')
|
|
|
|
spawn.memory.spawnqueued=true
|
|
|
|
}else if(Game.rooms[roomname].memory.maxbuilders > allbuilders.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn builder')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'builder')
|
|
|
|
spawn.memory.spawnqueued=true
|
|
|
|
} else if (Game.rooms[roomname].memory.maxwarriors > allwarriors.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn warrior')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'warrior')
|
|
|
|
} else if(Game.rooms[roomname].memory.maxclaimers > allclaimers.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn claimer')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'claimer')
|
|
|
|
} else if(Game.rooms[roomname].memory.maxnrbuilders > allnrbuilders.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn nrbuilder')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'nrbuilder')
|
|
|
|
} else if(Game.rooms[roomname].memory.maxnrminers > allnrminers.length){
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('spawn nrminer')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
buildparts.tick(roomname,'nrminer')
|
|
|
|
} else {}
|
|
|
|
|
|
|
|
} else if (!spawn.spawning && spawn.memory.spawnqueued) {
|
|
|
|
spawn.memory.spawnqueued=false
|
2017-07-13 23:24:42 -05:00
|
|
|
if(global.verbosity>0){
|
2017-06-06 13:17:26 -05:00
|
|
|
console.log('clearing spawn queue')
|
2017-07-13 23:24:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
} else if (spawn.spawning && !spawn.memory.spawnqueued){
|
|
|
|
spawn.memory.spawnqueued=true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(Game.rooms[roomname].memory.tickssincespawn==undefined){Game.rooms[roomname].memory.tickssincespawn=1} else{
|
|
|
|
Game.rooms[roomname].memory.tickssincespawn++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
module.exports = processSpawns;
|