From 2199b449bb2d02f46cbfafb531254c71d45e3e50 Mon Sep 17 00:00:00 2001 From: paradizelost Date: Tue, 6 Jun 2017 13:17:26 -0500 Subject: [PATCH] Rewrite Catchup --- Empire.js | 70 ++++++++++ MinedMineralProc.js | 26 ++++ NOTES.js | 4 + bodypartbuilder.js | 290 ++++++++++++++++++++++++++++++++++++++++-- main.js | 93 ++++++++------ mineralprocessing.js | 22 ++++ role.builder.js | 38 +++--- role.claimer.js | 21 +++ role.hauler.js | 68 +++++----- role.hauler2.js | 20 +-- role.miner.js | 14 +- role.miner2.js | 13 ++ role.mineralhauler.js | 33 +++++ role.nrbuilder.js | 60 +++++++++ role.nrminer.js | 25 ++++ role.recharger.js | 18 +-- role.repairbot.js | 29 ++--- role.upgrader.js | 36 ++---- role.warrior.js | 25 ++++ sourceprocessing.js | 5 +- spawnprocessing.js | 99 ++++++++++++++ sproc.js | 2 +- tower.js | 95 +++++++------- 23 files changed, 858 insertions(+), 248 deletions(-) create mode 100644 Empire.js create mode 100644 MinedMineralProc.js create mode 100644 mineralprocessing.js create mode 100644 role.claimer.js create mode 100644 role.miner2.js create mode 100644 role.mineralhauler.js create mode 100644 role.nrbuilder.js create mode 100644 role.nrminer.js create mode 100644 role.warrior.js create mode 100644 spawnprocessing.js diff --git a/Empire.js b/Empire.js new file mode 100644 index 0000000..bf33ddd --- /dev/null +++ b/Empire.js @@ -0,0 +1,70 @@ +let buildparts=require('bodypartbuilder') +module.exports = { + get getcounts(){ + let output='' + + for(let myroom of _.filter(Game.rooms, 'controller.my')) { + let name = myroom.name + //let{builder,miner,hauler,hauler2,towerrecharger,repairbot,upgrader,warrior,claimer,nrbuilder,nrminer}=_.groupBy(Game.rooms[name].creeps, 'memory.role') + let allcreeps = _.filter(Game.rooms[name].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 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')) + output +=( + name + ': ' + + allcreeps.length + ' total creeps ' + ' ' + + allbuilders.length + ' Builders of ' + Game.rooms[name].memory.maxbuilders + " " + + allminers.length + ' Miners of ' + Game.rooms[name].memory.maxminers + " " + + allminer2s.length + ' Miner2s of ' + Game.rooms[name].memory.maxminer2s + " " + + allhaulers.length + ' Haulers of ' + Game.rooms[name].memory.maxhaulers + " " + + allhauler2s.length + ' Hauler2s of ' + Game.rooms[name].memory.maxhauler2s + " " + + alltowerrechargers.length + ' Rechargers of ' + Game.rooms[name].memory.maxtowerrechargers + " " + + allrepairbots.length + ' Repairbots of ' + Game.rooms[name].memory.maxrepairbots + " " + + allupgraders.length + ' Upgraders of ' + Game.rooms[name].memory.maxupgraders + " " + + allwarriors.length + ' Warriors of ' + Game.rooms[name].memory.maxwarriors + " " + + allclaimers.length + ' Claimers of ' + Game.rooms[name].memory.maxclaimers + " " + + allnrbuilders.length + ' nrbuilders of ' + Game.rooms[name].memory.maxnrbuilders + " " + + allnrminers.length + ' nrminers of ' + Game.rooms[name].memory.maxnrminers + " " + + '\n' + ) + } + return output + }, + decrease: function(role,roomname){ + let rolename = 'max' + role + 's' + let currentmax = Game.rooms[roomname].memory[rolename] + Game.rooms[roomname].memory[rolename]-- + let newmax = Game.rooms[roomname].memory[rolename] + return 'Old Max:'+currentmax+' New Max:'+newmax + }, + increase: function(role,roomname){ + let rolename = 'max' + role + 's' + let currentmax = Game.rooms[roomname].memory[rolename] + Game.rooms[roomname].memory[rolename]++ + let newmax = Game.rooms[roomname].memory[rolename] + return 'Old Max:'+currentmax+' New Max:'+newmax + }, + kill: function(creepname){ + let me= Game.creeps[creepname].suicide() + return me + }, + spawn: function(roomname,role){ + buildparts.tick(roomname,role) + return 'Spawning initiated' + }, + removeConstruction: function(roomname){ + _.invoke(Game.rooms[roomname].find(FIND_MY_CONSTRUCTION_SITES), 'remove') + }, + removeWalls: function(roomname){ + Game.rooms[roomname].find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_WALL}).forEach(s => s.destroy()) + } +}; \ No newline at end of file diff --git a/MinedMineralProc.js b/MinedMineralProc.js new file mode 100644 index 0000000..bb68c08 --- /dev/null +++ b/MinedMineralProc.js @@ -0,0 +1,26 @@ +let runSources = { + tick: function(roomname) { + let sources = Game.rooms[roomname].find( + FIND_DROPPED_RESOURCES, { + filter: (mineral) => (mineral.resourceType == RESOURCE_ZYNTHIUM || mineral.resourceType == RESOURCE_OXYGEN || mineral.resourceType == RESOURCE_LEMERGIUM) + }); + for(let source of sources){ + try{ + console.log(source) + let allhaulers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role=='hauler3' ); + let unassignedhauler3s = _.filter(allhaulers, (creep) => (creep.memory.destsource == undefined && creep.memory.role=='hauler3')); + let assignedhauler3s = _.filter(allhaulers, (creep) => (creep.memory.destsource != undefined && creep.memory.role=='hauler3')); + let myhauler3s = _.filter(allhaulers, (creep) => (creep.memory.destsource != undefined && creep.memory.destsource.id==source.id && creep.memory.role=='hauler3')); + let sourcecount = sources.length + let persrc = allhaulers.length / sourcecount + console.log('My Assigned Hauler3s: ' +myhauler3s.length + ' Max per source:' + persrc + ' Total Hauler3s:' + allhaulers.length + ' Total Sources:' + sourcecount + ' Unassigned Hauler3s:' + unassignedhauler3s.length) + if(unassignedhauler3s.length > 0){ + if(myhauler3s.length < persrc){ + unassignedhauler3s[0].memory.destsource = source + } else {} + } + } catch(e){console.log(e)} + } + } +}; +module.exports = runSources; \ No newline at end of file diff --git a/NOTES.js b/NOTES.js index 27e323c..9a380e3 100644 --- a/NOTES.js +++ b/NOTES.js @@ -1,3 +1,7 @@ +if(containers.count==0 && structure_extensions.count==0 && storage.count==0 && miners.count==0){spawn harvester} else { spawn miners and haulers} + +_.forEach(Game.creeps, creep => creep.suicide()) +_.forEach(Game.rooms[roomname].constructionSites, cs=>cs.remove()) serializePos: function(pos) { return pos.x + '_' + pos.y + '_' + pos.roomName; }, diff --git a/bodypartbuilder.js b/bodypartbuilder.js index 3cff0d9..f33db5a 100644 --- a/bodypartbuilder.js +++ b/bodypartbuilder.js @@ -1,18 +1,71 @@ let buildparts = { tick: function(roomname,role) { + + console.log(Game.rooms[roomname].memory.tickssincespawn) console.log(roomname + ":" + role) let energyready = Game.rooms[roomname].energyAvailable let energymax = Game.rooms[roomname].energyCapacityAvailable - if(energyready==energymax){ + + Game.rooms[roomname].memory.tickssincespawn=0 let tobuild=[] + let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) + Game.rooms[roomname].memory.CreepNum++ + let CreepName = role + "_" + roomname + "_" + (Game.rooms[roomname].memory.CreepNum) switch(role){ case 'builder': - let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) + for(let spawn of myspawns){ + if(!spawn.spawning){ for(let totry of [ - [MOVE,MOVE,MOVE,MOVE,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,WORK], - [MOVE,MOVE,MOVE,MOVE,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,MOVE], - [MOVE,MOVE,CARRY] + [MOVE,MOVE,MOVE,MOVE,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY], + [MOVE,MOVE,MOVE,WORK,WORK,WORK,CARRY,CARRY,CARRY], + [MOVE,MOVE,WORK,WORK,CARRY,CARRY], + [MOVE,WORK,CARRY] + + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + } + } + break; + case 'nrbuilder': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [ + [MOVE,MOVE,WORK,WORK,CARRY,CARRY], + [MOVE,WORK,CARRY] + + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + } + } + break; + case 'hauler': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [ + [CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], + [CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE], + [CARRY,CARRY,CARRY,CARRY,MOVE,MOVE], + [CARRY,CARRY,MOVE,MOVE], + [CARRY,MOVE] ]){ let ispossible = spawn.canCreateCreep(totry) if(ispossible==OK){ @@ -21,15 +74,232 @@ let buildparts = { } } console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + } } break; - case 'hauler': - console.log('2') - break + case 'hauler3': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [ + [CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], + [CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE], + [CARRY,CARRY,CARRY,CARRY,MOVE,MOVE], + [CARRY,CARRY,MOVE,MOVE], + [CARRY,MOVE] + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + } + } + break; + case 'miner': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [ + [WORK,WORK,WORK,WORK,WORK,MOVE], + [WORK,WORK,WORK,WORK,MOVE], + [WORK,WORK,WORK,MOVE], + [WORK,WORK,MOVE], + [WORK,MOVE] + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + }} + break; + case 'miner2': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [ + [WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE], + [WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE], + [WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE], + [WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE], + [WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE], + [WORK,WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE], + [WORK,WORK,WORK,WORK,WORK,WORK,MOVE,MOVE], + [WORK,WORK,WORK,WORK,WORK,MOVE], + [WORK,WORK,WORK,WORK,MOVE], + [WORK,WORK,WORK,MOVE], + [WORK,WORK,MOVE], + [WORK,MOVE] + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + }} + break; + case 'nrminer': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [ + [WORK,WORK,WORK,WORK,WORK,MOVE], + [WORK,WORK,WORK,WORK,MOVE], + [WORK,WORK,WORK,MOVE], + [WORK,WORK,MOVE], + [WORK,MOVE] + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + }} + break; + case 'hauler2': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [[CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], + [CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE], + [CARRY,CARRY,CARRY,CARRY,MOVE,MOVE], + [CARRY,CARRY,MOVE,MOVE], + [CARRY,MOVE] + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + }} + break; + case 'towerrecharger': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [[CARRY,CARRY,CARRY,MOVE,MOVE]]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + }} + break; + case 'repairbot': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [ + [MOVE,MOVE,MOVE,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY],//RCL3 + [WORK,CARRY,MOVE] + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + }} + break; + case 'upgrader': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [ + [WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], + [WORK,WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], + [WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], + [WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], + [WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], + [WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], + [WORK,WORK,WORK,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], + [MOVE,MOVE,WORK,WORK,WORK,CARRY,CARRY,CARRY], + [MOVE,MOVE,WORK,WORK,CARRY,CARRY], + [MOVE,WORK,CARRY] + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + }} + break; + case 'warrior': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [ + [ATTACK,ATTACK,RANGED_ATTACK,RANGED_ATTACK,MOVE,MOVE], + [ATTACK,ATTACK,RANGED_ATTACK,MOVE] + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + }} + break; + case 'claimer': + + for(let spawn of myspawns){ + if(!spawn.spawning){ + for(let totry of [ + [CLAIM,CLAIM,CLAIM,CLAIM,CLAIM,MOVE,MOVE], + [CLAIM,MOVE] + ]){ + let ispossible = spawn.canCreateCreep(totry) + if(ispossible==OK){ + tobuild=totry + break; + } + } + console.log(tobuild) + let newcreep = spawn.createCreep(tobuild,CreepName,{role:role}) + console.log('Spawning new ' + role + ': ' + newcreep ); + }} + break; default: - console.log('3') + console.log('no match') } - } + } }; diff --git a/main.js b/main.js index 2cbe69f..7391a89 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,7 @@ 'use strict'; +global.Empire = require("Empire") let roleBuilder=require('role.builder'); +let roleClaimer=require('role.claimer'); let roleMiner=require('role.miner'); let roleHauler=require('role.hauler') let roleHauler2=require('role.hauler2') @@ -9,7 +11,14 @@ let runSources=require('sourceprocessing') let roleRepairbot=require('role.repairbot') let runTower = require('tower'); let assignMiners=require('sproc') -let buildparts=require('bodypartbuilder') +let roleWarrior=require('role.warrior') +let rolenrBuilder=require('role.nrbuilder') +let rolenrMiner=require('role.nrminer') +let processSpawns=require('spawnprocessing') +let minerals=require('mineralprocessing') +let roleMiner2=require('role.miner2') +let roleHauler3=require('role.mineralhauler') +let minedproc = require('MinedMineralProc') module.exports.loop = function () { console.log('---START---') for(let name in Memory.creeps) { @@ -18,30 +27,22 @@ module.exports.loop = function () { console.log('Clearing non-existing creep memory:', name); } } - for(let myroom of _.filter(Game.rooms, 'controller.my')) { let name = myroom.name - console.log(name) - - buildparts.tick(name,'builder') console.log('---'+name+'---') runTower.tick(name); assignMiners.tick(name) runSources.tick(name) - + minedproc.tick(name) try{ let roomenergy = Game.rooms[name].energyAvailable let allstorage = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE)}}) - - let usedstorage = 0 let mycapacity=0 - for(let i=0; i < allstorage.length;i++){ - usedstorage+=_.sum(allstorage[i].store) - mycapacity+=allstorage[i].storeCapacity + for(let i of allstorage){ + usedstorage+=_.sum(i.store) + mycapacity+=i.storeCapacity } - - let allcontainers = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_CONTAINER)}}) let containerusedstorage = 0 let containercapacity=0 @@ -49,27 +50,26 @@ module.exports.loop = function () { containerusedstorage+=_.sum(allcontainers[i].store) containercapacity+=allcontainers[i].storeCapacity } - /** - var allstoragecontainers = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_STORAGE)}}) - var storagecontainerusedstorage = 0 - var storagecontainercapacity=0 - for(var i=0; i < allcontainers.length;i++){ - storagecontainerusedstorage+=_.sum(allstoragecontainers[i].store) - storagecontainercapacity+=allstoragecontainers[i].storeCapacity - } - if() - console.log(storagecontainerusedstorage + ':' + storagecontainercapacity) - **/ Game.rooms[name].memory.storagepercent = usedstorage/mycapacity Game.rooms[name].memory.containerstoragepercent = containerusedstorage/containercapacity + if(!(Game.rooms[name].memory.containerstoragepercent >-.1)){Game.rooms[name].memory.containerstoragepercent=0} console.log('-------') console.log('Room "'+name+'" has '+roomenergy+' energy : Using ' + usedstorage + ' of ' + mycapacity + ', ' + Game.rooms[name].memory.storagepercent * 100 + '% Storage, ' + containerusedstorage + ' of ' + containercapacity + ':' + Game.rooms[name].memory.containerstoragepercent *100+ '% in containers') } catch(e){} - if(Game.rooms[name].memory.maxbuilders == undefined){ Game.rooms[name].memory.maxbuilders =0 } - if(Game.rooms[name].memory.maxupgraders == undefined){ Game.rooms[name].memory.maxupgraders = 0 } - if(Game.rooms[name].memory.maxminers == undefined){ Game.rooms[name].memory.maxminers = 0 } - if(Game.rooms[name].memory.maxhaulers == undefined){ Game.rooms[name].memory.maxhaulers = 0 } - if(Game.rooms[name].memory.maxhauler2s == undefined){ Game.rooms[name].memory.maxhauler2s = 0 } + if(Game.rooms[name].memory.CreepNum == undefined){Game.rooms[name].memory.CreepNum=0} + if(Game.rooms[name].memory.minbuildpct == undefined){Game.rooms[name].memory.minbuildpct=.5} + if(Game.rooms[name].memory.minupgradepct == undefined){Game.rooms[name].memory.minupgradepct=.5} + if(Game.rooms[name].memory.minrepairpct == undefined){Game.rooms[name].memory.minrepairpct=.5} + if(Game.rooms[name].memory.maxbuilders == undefined){ Game.rooms[name].memory.maxbuilders =1 } + if(Game.rooms[name].memory.maxnrbuilders == undefined){ Game.rooms[name].memory.maxnrbuilders =0 } + if(Game.rooms[name].memory.maxclaimers == undefined){ Game.rooms[name].memory.maxclaimers =0 } + if(Game.rooms[name].memory.maxupgraders == undefined){ Game.rooms[name].memory.maxupgraders = 2 } + if(Game.rooms[name].memory.maxminers == undefined){ Game.rooms[name].memory.maxminers = 2 } + if(Game.rooms[name].memory.maxminer2s == undefined){ Game.rooms[name].memory.maxminer2s = 0 } + if(Game.rooms[name].memory.maxnrminers == undefined){ Game.rooms[name].memory.maxnrminers = 0 } + if(Game.rooms[name].memory.maxhaulers == undefined){ Game.rooms[name].memory.maxhaulers = 2 } + if(Game.rooms[name].memory.maxhauler2s == undefined){ Game.rooms[name].memory.maxhauler2s = 1 } + if(Game.rooms[name].memory.maxhauler3s == undefined){ Game.rooms[name].memory.maxhauler3s = 0 } if(Game.rooms[name].memory.maxwarriors == undefined){ Game.rooms[name].memory.maxwarriors = 0 } if(Game.rooms[name].memory.maxtowerrechargers == undefined){ Game.rooms[name].memory.maxtowerrechargers = 0 } if(Game.rooms[name].memory.maxharvesters == undefined){ Game.rooms[name].memory.maxharvesters = 0 } @@ -82,27 +82,33 @@ module.exports.loop = function () { if(Game.rooms[name].memory.hauler2parky==undefined){Game.rooms[name].memory.hauler2parky=24} if(Game.rooms[name].memory.upgraderparkx==undefined){Game.rooms[name].memory.upgraderparkx=24} if(Game.rooms[name].memory.upgraderparky==undefined){Game.rooms[name].memory.upgraderparky=24} - - roleBuilder.spawn(name) - roleMiner.spawn(name) - roleHauler.spawn(name) - roleHauler2.spawn(name) - roleUpgrader.spawn(name) - roleTowerrecharger.spawn(name) - roleRepairbot.spawn(name) - let mycreeps = Game.rooms[name].find(FIND_MY_CREEPS) + if(Game.rooms[name].memory.warriorparkx==undefined){Game.rooms[name].memory.warriorparkx=15} + if(Game.rooms[name].memory.warriorparky==undefined){Game.rooms[name].memory.warriorparky=34} + processSpawns.tick(name) + minerals.tick(name) + } + let mycreeps = Game.creeps for(let mycreep in mycreeps){ try{ let creep = mycreeps[mycreep] if(creep.memory.role == 'miner'){ roleMiner.run(creep) } + if(creep.memory.role=='miner2'){ + roleMiner2.run(creep) + } + if(creep.memory.role == 'claimer'){ + roleClaimer.run(creep) + } if(creep.memory.role == 'hauler'){ roleHauler.run(creep) } if(creep.memory.role == 'hauler2'){ roleHauler2.run(creep) } + if(creep.memory.role == 'hauler3'){ + roleHauler3.run(creep) + } if(creep.memory.role == 'builder'){ roleBuilder.run(creep) } @@ -115,12 +121,19 @@ module.exports.loop = function () { if(creep.memory.role == 'repairbot'){ roleRepairbot.run(creep) } + if(creep.memory.role=='warrior'){ + roleWarrior.run(creep) + } + if(creep.memory.role=='nrbuilder'){ + rolenrBuilder.run(creep) + } + if(creep.memory.role=='nrminer'){ + rolenrMiner.run(creep) + } } catch (e) { //console.log(e.toString) } } - - } console.log('----END---') } \ No newline at end of file diff --git a/mineralprocessing.js b/mineralprocessing.js new file mode 100644 index 0000000..2064ba9 --- /dev/null +++ b/mineralprocessing.js @@ -0,0 +1,22 @@ +let assignMiner2s = { + tick: function(roomname) { + let sources = Game.rooms[roomname].find(FIND_MINERALS); + for(let source of sources){ + let allminers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role=='miner2' ); + let unassignedminers = _.filter(allminers, (creep) => (creep.memory.destsource == undefined && creep.memory.role=='miner2')); + let assignedminers = _.filter(allminers, (creep) => (creep.memory.destsource != undefined && creep.memory.role=='miner2')); + let myminers = _.filter(allminers, (creep) => (creep.memory.destsource != undefined && creep.memory.destsource.id==source.id && creep.memory.role=='miner')); + let sourcecount = sources.length + let persrc = allminers.length / sourcecount + console.log('My Assigned miner2s: ' +myminers.length + ' Max per source:' + persrc + ' Total Miner2s:' + allminers.length + ' Total Sources:' + sourcecount + ' Unassigned Miners:' + unassignedminers.length) + if(unassignedminers.length > 0){ + if(myminers.length >= persrc){ + //break; + } else { + unassignedminers[0].memory.destsource = source + } + } + } + } +}; +module.exports = assignMiner2s; \ No newline at end of file diff --git a/role.builder.js b/role.builder.js index 532662c..6c2f885 100644 --- a/role.builder.js +++ b/role.builder.js @@ -1,3 +1,4 @@ +let buildparts=require('bodypartbuilder') let roleBuilder = { run: function(creep) { if(creep.memory.originroom === undefined){ @@ -13,35 +14,39 @@ let roleBuilder = { } if(creep.memory.building) { + if(creep.memory.buildsite==undefined|| Game.getObjectById(creep.memory.buildsite.id) == undefined){ creep.memory.buildsite = Game.rooms[creep.memory.originroom].find(FIND_CONSTRUCTION_SITES)[0]; } let target = Game.getObjectById(creep.memory.buildsite.id) - //Check next room as well if(target) { - if(Game.rooms[creep.memory.originroom].memory.containerstoragepercent > -.5 ){ + + if(creep.room.memory.containerstoragepercent > creep.room.memory.minbuildpct || creep.room.memory.containerstoragepercent === undefined ){ if(creep.build(target) == ERR_NOT_IN_RANGE) { creep.moveTo(target); if(creep.fatigue<1){ creep.say("MTCS"); } else { creep.say("Tired")} } - } + }else { + creep.say(creep.room.memory.containerstoragepercent + ' parking1') + creep.moveTo(creep.room.memory.builderparkx,creep.room.memory.builderparky,creep.room.roomName) + } } else { - creep.say('parking') - creep.moveTo(Game.rooms[creep.memory.originroom].memory.builderparkx,Game.rooms[creep.memory.originroom].memory.builderparky,creep.memory.originroom) + creep.say('parking2') + creep.moveTo(creep.room.memory.builderparkx,creep.room.memory.builderparky,creep.room.roomName) } } else { let containers =Game.rooms[creep.memory.originroom].find(FIND_STRUCTURES, { - filter: (structure) => {return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;}}); + filter: (structure) => {return ((structure.structureType == STRUCTURE_CONTAINER||structure.structureType == STRUCTURE_TERMINAL || structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;}}); let allcontainers = creep.room.find(FIND_STRUCTURES, { filter: (structure) => { - return (structure.structureType == STRUCTURE_CONTAINER ) ; + return (structure.structureType == STRUCTURE_CONTAINER || structure.structureType == STRUCTURE_STORAGE ) ; }}); - let sources = Game.rooms[creep.memory.originroom].find(FIND_SOURCES); - let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_ENERGY ); - if(containers==0){ + let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: {resourceType: RESOURCE_ENERGY}}); + //find(FIND_DROPPED_RESOURCES, {filter: r => r.resourceType === RESOURCE_ENERGY}) is another option + if(allcontainers.length==0){ if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) { creep.say("MTDE"); creep.moveTo(droppedenergy); @@ -54,19 +59,6 @@ let roleBuilder = { } } - }, - spawn: function(roomname){ - let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) - let myroom = Game.rooms[roomname] - for(let spawn of myspawns){ - let myrole='builder'; - let myroles = _.filter(Game.creeps, (creep) => { return ((creep.memory.role == myrole) && (creep.memory.originroom == roomname))}); - console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']); - if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) { - let newName = spawn.createCreep([MOVE,WORK,CARRY], undefined, {role: myrole}); - console.log('Spawning new ' + myrole + ': ' + newName); - } - } } }; module.exports = roleBuilder; \ No newline at end of file diff --git a/role.claimer.js b/role.claimer.js new file mode 100644 index 0000000..ab97272 --- /dev/null +++ b/role.claimer.js @@ -0,0 +1,21 @@ +let roleClaimer = { + run: function(creep) { + if(creep.memory.originroom === undefined){ + creep.memory.originroom = creep.room.name + } + //let mycontroller= creep.room.find(STRUCTURE_CONTROLLER) + if(!creep.room.controller.my){ + creep.say('claiming') + if(creep.claimController(creep.room.controller) == ERR_NOT_IN_RANGE) { + creep.moveTo(creep.room.controller); + } + } else if(Game.flags.claim){ + creep.say('claim') + creep.moveTo(Game.flags.claim) + } else{ + creep.say('parking') + creep.moveTo(creep.room.memory.claimerparkx,creep.room.memory.claimerparky,creep.room) + } + } +}; +module.exports = roleClaimer; \ No newline at end of file diff --git a/role.hauler.js b/role.hauler.js index 6d88347..d119c2c 100644 --- a/role.hauler.js +++ b/role.hauler.js @@ -1,45 +1,43 @@ +let buildparts=require('bodypartbuilder') let roleHauler = { run: function(creep) { + let spawntargets = creep.pos.findClosestByPath(FIND_STRUCTURES, { + filter: (structure) => { + return (((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity)) + } + }); + let containertargets = creep.pos.findClosestByRange(FIND_STRUCTURES, { + filter: (structure) => { + return ((structure.structureType == STRUCTURE_CONTAINER ) && _.sum(structure.store) < structure.storeCapacity) ; + } + }); + let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, { + filter: (structure) => { + return ((structure.structureType == STRUCTURE_STORAGE || structure.structureType == STRUCTURE_TERMINAL ) && _.sum(structure.store) < structure.storeCapacity) ; + } + }); if(creep.memory.originroom === undefined){ creep.memory.originroom = creep.room.name } if(creep.memory.hauling == undefined){creep.memory.hauling=false} - if(creep.memory.hauling && creep.carry.energy == 0) { + if(creep.memory.hauling && _.sum(creep.carry) == 0) { creep.memory.destsource=undefined creep.memory.hauling = false; creep.say('gathering'); } - if(!creep.memory.hauling && creep.carry.energy == creep.carryCapacity) { + if(!creep.memory.hauling && _.sum(creep.carry) == creep.carryCapacity) { creep.memory.hauling = true; creep.say('hauling'); } - let sources = creep.pos.findClosestByRange(FIND_DROPPED_ENERGY ); + let sources = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: {resourceType: RESOURCE_ENERGY}} || STRUCTURE_TERMINAL ); if(creep.memory.hauling==false){ if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined} let mysource=Game.getObjectById(creep.memory.destsource.id) - - if(creep.pickup(mysource) == ERR_NOT_IN_RANGE && creep.carryCapacity > creep.carry.energy) { + if(creep.pickup(mysource) == ERR_NOT_IN_RANGE && creep.carryCapacity > _.sum(creep.carry)) { creep.moveTo(mysource); - } + } } else { - if(sources != undefined ) - { let spawntargets = creep.pos.findClosestByPath(FIND_STRUCTURES, { - filter: (structure) => { - return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity) - } - }); - let containertargets = creep.pos.findClosestByRange(FIND_STRUCTURES, { - filter: (structure) => { - return ((structure.structureType == STRUCTURE_CONTAINER ) && _.sum(structure.store) < structure.storeCapacity) ; - } - - }); - let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, { - filter: (structure) => { - return ((structure.structureType == STRUCTURE_STORAGE ) && _.sum(structure.store) < structure.storeCapacity) ; - } - - }); + if(sources != undefined ) { if(spawntargets) { if(creep.transfer(spawntargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(spawntargets); @@ -48,26 +46,18 @@ let roleHauler = { if(creep.transfer(containertargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(containertargets); } - } else { + } else { if(creep.transfer(storagetargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(storagetargets); - } + } + } + } + if(creep.carry.RESOURCE_ZYNTHIUM > 0){ + if(creep.transfer(storagetargets, RESOURCE_ZYNTHIUM) == ERR_NOT_IN_RANGE) { + creep.moveTo(storagetargets); } } } - }, - spawn: function(roomname){ - let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) - let myroom = Game.rooms[roomname] - for(let spawn of myspawns){ - let myrole='hauler'; - let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname); - console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']); - if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) { - let newName = spawn.createCreep([CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], undefined, {role: myrole}); - console.log('Spawning new ' + myrole + ': ' + newName); - } - } } }; module.exports = roleHauler; \ No newline at end of file diff --git a/role.hauler2.js b/role.hauler2.js index 1a3a7d5..f4a8b72 100644 --- a/role.hauler2.js +++ b/role.hauler2.js @@ -1,6 +1,5 @@ + let buildparts=require('bodypartbuilder') let roleHauler2 = { - - /** @param {Creep} creep **/ run: function(creep) { if(creep.memory.originroom === undefined){ creep.memory.originroom = creep.room.name @@ -28,7 +27,7 @@ } else { let spawntarget = creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (structure) => { - return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) &&structure.energy < structure.energyCapacity) + return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity) } }); if(spawntarget != undefined) { @@ -41,19 +40,6 @@ creep.moveTo(creep.room.memory.hauler2parkx,creep.room.memory.hauler2parky,creep.room.roomName) } } - }, - spawn: function(roomname){ - let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) - let myroom = Game.rooms[roomname] - for(let spawn of myspawns){ - let myrole='hauler2'; - let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname); - console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']); - if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) { - let newName = spawn.createCreep([CARRY,CARRY,CARRY,MOVE,MOVE], undefined, {role: myrole}); - console.log('Spawning new ' + myrole + ': ' + newName); - } - } - } + } }; module.exports = roleHauler2; \ No newline at end of file diff --git a/role.miner.js b/role.miner.js index d3f507d..b4ea809 100644 --- a/role.miner.js +++ b/role.miner.js @@ -1,3 +1,4 @@ +let buildparts=require('bodypartbuilder') let roleMiner = { run: function(creep) { if(creep.memory.originroom === undefined){ @@ -8,19 +9,6 @@ let roleMiner = { if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) { creep.moveTo(mysource); } - }, - spawn: function(roomname){ - let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) - let myroom = Game.rooms[roomname] - for(let spawn of myspawns){ - let myrole='miner'; - let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname); - console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']); - if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) { - let newName = spawn.createCreep([WORK,WORK,WORK,WORK,WORK,MOVE], undefined, {role: myrole}); - console.log('Spawning new ' + myrole + ': ' + newName); - } - } } }; module.exports = roleMiner; \ No newline at end of file diff --git a/role.miner2.js b/role.miner2.js new file mode 100644 index 0000000..1a8aa3c --- /dev/null +++ b/role.miner2.js @@ -0,0 +1,13 @@ +let roleMiner2 = { + run: function(creep) { + if(creep.memory.originroom === undefined){ + creep.memory.originroom = creep.room.name + } + if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined} + let mysource=Game.getObjectById(creep.memory.destsource.id) + if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) { + creep.moveTo(mysource); + } + } +}; +module.exports = roleMiner2; \ No newline at end of file diff --git a/role.mineralhauler.js b/role.mineralhauler.js new file mode 100644 index 0000000..0b299fc --- /dev/null +++ b/role.mineralhauler.js @@ -0,0 +1,33 @@ +let roleHauler = { + run: function(creep) { + if(creep.memory.originroom === undefined){ + creep.memory.originroom = creep.room.name + } + if(creep.memory.hauling == undefined){creep.memory.hauling=false} + if(creep.memory.hauling && creep.carry.energy == 0) { + creep.memory.destsource=undefined + creep.memory.hauling = false; + creep.say('gathering'); + } + if(!creep.memory.hauling && _.sum(creep.carry) == creep.carryCapacity) { + creep.memory.hauling = true; + creep.say('hauling'); + } + if(creep.memory.hauling==false){ + if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined} + let mysource=Game.getObjectById(creep.memory.destsource.id) + if(creep.pickup(mysource) == ERR_NOT_IN_RANGE && creep.carryCapacity > _.sum(creep.carry)) { + creep.moveTo(mysource); + } + } else { + let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, { + filter: (structure) => {return ((structure.structureType == STRUCTURE_TERMINAL ) && _.sum(structure.store) < structure.storeCapacity);}}); + for(let resource in creep.carry){ + if(creep.transfer(storagetargets, resource) == ERR_NOT_IN_RANGE) { + creep.moveTo(storagetargets); + } + } + } + } +}; +module.exports = roleHauler; \ No newline at end of file diff --git a/role.nrbuilder.js b/role.nrbuilder.js new file mode 100644 index 0000000..cb941ef --- /dev/null +++ b/role.nrbuilder.js @@ -0,0 +1,60 @@ +let rolenrBuilder = { + run: function(creep) { + + if(creep.memory.building && creep.carry.energy == 0) { + creep.memory.building = false; + creep.say('Gathering'); + } + if(!creep.memory.building && creep.carry.energy == creep.carryCapacity) { + creep.memory.building = true; + creep.say('building'); + } + if(Game.flags.nrbuild.room == creep.room){ + if(creep.memory.originroom === undefined){ + creep.memory.originroom = creep.room.name + creep.memory.role = 'builder' + } + if(creep.memory.building) { + if(creep.memory.buildsite==undefined|| Game.getObjectById(creep.memory.buildsite.id) == undefined){ + creep.memory.buildsite = creep.room.find(FIND_CONSTRUCTION_SITES)[0]; + } + let target = Game.getObjectById(creep.memory.buildsite.id) + if(target) { + if(creep.build(target) == ERR_NOT_IN_RANGE) { + creep.moveTo(target); + if(creep.fatigue<1){ + creep.say("MTCS"); + } else { creep.say("Tired")} + } + } else { + creep.say('parking') + creep.moveTo(creep.room.memory.builderparkx,creep.room.memory.builderparky,creep.room.roomName) + } + } + else { + let containers =creep.room.find(FIND_STRUCTURES, { + filter: (structure) => {return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;}}); + let allcontainers = creep.room.find(FIND_STRUCTURES, { + filter: (structure) => { + return (structure.structureType == STRUCTURE_CONTAINER || structure.structureType == STRUCTURE_STORAGE ) ; + }}); + let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: {resourceType: RESOURCE_ENERGY}}); + if(containers.length==0){ + if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) { + creep.say("MTDE"); + creep.moveTo(droppedenergy); + } + } else { + if(creep.withdraw(containers[0],RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { + creep.say("MTSC"); + creep.moveTo(containers[0]); + } + + } + } + } else { + creep.moveTo(Game.flags.nrbuild) + } + } +}; +module.exports = rolenrBuilder; \ No newline at end of file diff --git a/role.nrminer.js b/role.nrminer.js new file mode 100644 index 0000000..7058015 --- /dev/null +++ b/role.nrminer.js @@ -0,0 +1,25 @@ +let assignMiners=require('sproc') +let rolenrMiner = { + run: function(creep) { + if(Game.flags.nrbuild.room == creep.room){ + + if(creep.memory.destsource==undefined){ + creep.memory.role='miner' + assignMiners(creep.roomName) + } + if(creep.memory.originroom === undefined){ + creep.memory.originroom = creep.room.name + creep.moveTo(Game.flags.nrbuild) + creep.memory.role='miner' + } + if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined} + let mysource=Game.getObjectById(creep.memory.destsource.id) + if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) { + creep.moveTo(mysource); + } + } else { + creep.moveTo(Game.flags.nrbuild) + } + } +}; +module.exports = rolenrMiner; \ No newline at end of file diff --git a/role.recharger.js b/role.recharger.js index e29f595..a52a479 100644 --- a/role.recharger.js +++ b/role.recharger.js @@ -1,6 +1,5 @@ + let buildparts=require('bodypartbuilder') let roleTowerrecharger = { - - /** @param {Creep} creep **/ run: function(creep) { if(creep.memory.originroom === undefined){ creep.memory.originroom = creep.room.name @@ -35,19 +34,6 @@ } } } - }, - spawn: function(roomname){ - let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) - let myroom = Game.rooms[roomname] - for(let spawn of myspawns){ - let myrole='towerrecharger'; - let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname); - console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']); - if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) { - let newName = spawn.createCreep([CARRY,CARRY,CARRY,MOVE,MOVE], undefined, {role: myrole}); - console.log('Spawning new ' + myrole + ': ' + newName); - } - } - } + } }; module.exports = roleTowerrecharger; \ No newline at end of file diff --git a/role.repairbot.js b/role.repairbot.js index efe3e9e..8638810 100644 --- a/role.repairbot.js +++ b/role.repairbot.js @@ -1,6 +1,5 @@ +let buildparts=require('bodypartbuilder') let roleRepairbot = { - - /** @param {Creep} creep **/ run: function(creep) { if(creep.memory.originroom === undefined){ creep.memory.originroom = creep.room.name @@ -24,16 +23,20 @@ let roleRepairbot = { creep.moveTo(container); } } else { + if(Game.rooms[creep.memory.originroom].memory.containerstoragepercent > .7 || !(Game.rooms[creep.memory.originroom].memory.containerstoragepercent)){ let importantstructures = creep.room.find(FIND_STRUCTURES, { filter: (structure) => { - return (structure.structureType == STRUCTURE_CONTAINER && structure.hits < structure.hitsMax) ; + return ((structure.structureType == STRUCTURE_CONTAINER || structure.structureType==STRUCTURE_RAMPART) && structure.hits < structure.hitsMax) ; }}); importantstructures = _.sortBy(importantstructures, (s)=>s.hits / s.hitsMax) if(importantstructures.length > 0){ - if(creep.repair(importantstructures[0]) == ERR_NOT_IN_RANGE){ - creep.moveTo(importantstructures[0]) + if(Game.rooms[creep.memory.originroom].memory.containerstoragepercent > .5 || !(Game.rooms[creep.memory.originroom].memory.containerstoragepercent)){ + if(creep.repair(importantstructures[0]) == ERR_NOT_IN_RANGE){ + creep.moveTo(importantstructures[0]) + } } } else { + if(Game.rooms[creep.memory.originroom].memory.containerstoragepercent > .7 || !(Game.rooms[creep.memory.originroom].memory.containerstoragepercent)){ let damagedstructures = creep.room.find(FIND_STRUCTURES,{filter: (s) => s.hits < s.hitsMax}); damagedstructures = _.sortBy(damagedstructures, (s)=>s.hits / s.hitsMax) if(damagedstructures.length>0){ @@ -41,23 +44,11 @@ let roleRepairbot = { creep.moveTo(damagedstructures[0]) } } + } } - } - }, - spawn: function(roomname){ - let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) - let myroom = Game.rooms[roomname] - for(let spawn of myspawns){ - let myrole='repairbot'; - let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname); - console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']); - if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) { - let newName = spawn.createCreep([WORK,CARRY,MOVE], undefined, {role: myrole}); - console.log('Spawning new ' + myrole + ': ' + newName); } } - } - + } }; module.exports = roleRepairbot; \ No newline at end of file diff --git a/role.upgrader.js b/role.upgrader.js index d5ceacf..a9b074c 100644 --- a/role.upgrader.js +++ b/role.upgrader.js @@ -1,3 +1,4 @@ +let buildparts=require('bodypartbuilder') let roleUpgrader = { run: function(creep) { if(creep.memory.originroom === undefined){ @@ -13,7 +14,7 @@ let roleUpgrader = { creep.say('upgrading'); } if(creep.memory.upgrading) { - if(creep.room.memory.containerstoragepercent>.6){ + if(creep.room.memory.containerstoragepercent>creep.room.memory.minupgradepct || !(creep.room.memory.containerstoragepercent) ){ if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) { creep.say('MTRC') creep.moveTo(creep.room.controller); @@ -25,33 +26,24 @@ let roleUpgrader = { filter: (structure) => { return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ; }}); - if(container){ - - if(creep.withdraw(container,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { - creep.say("MTSC"); - creep.moveTo(container); - } - }else{ - let droppedenergy = creep.room.find(FIND_DROPPED_ENERGY ); + let allcontainers = creep.room.find(FIND_STRUCTURES, { + filter: (structure) => { + return (structure.structureType == STRUCTURE_CONTAINER || structure.structureType == STRUCTURE_STORAGE ) ; + }}); + if(allcontainers.length==0){ + let droppedenergy = creep.room.find(FIND_DROPPED_RESOURCES, {filter: {resourceType: RESOURCE_ENERGY}}); if(creep.pickup(droppedenergy[0]) == ERR_NOT_IN_RANGE) { creep.say("MTDE"); creep.moveTo(droppedenergy[0]); } + }else{ + + if(creep.withdraw(container,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { + creep.say("MTSC"); + creep.moveTo(container); + } } } - }, - spawn: function(roomname){ - let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS) - let myroom = Game.rooms[roomname] - for(let spawn of myspawns){ - let myrole='upgrader'; - let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname); - console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']); - if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) { - let newName = spawn.createCreep([MOVE,MOVE,WORK,WORK,WORK,CARRY,CARRY,CARRY], undefined, {role: myrole}); - console.log('Spawning new ' + myrole + ': ' + newName); - } - } } }; module.exports = roleUpgrader; \ No newline at end of file diff --git a/role.warrior.js b/role.warrior.js new file mode 100644 index 0000000..10be42a --- /dev/null +++ b/role.warrior.js @@ -0,0 +1,25 @@ +let roleWarrior = { + run: function(creep) { + var hostile = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS); + var hostilebuilding = creep.pos.findClosestByRange(FIND_HOSTILE_STRUCTURES||FIND_HOSTILE_SPAWNS ); + if(hostile!=undefined) { + creep.say('Sorry') + creep.moveTo(hostile); + creep.attack(hostile); + + } else if(hostilebuilding!=undefined){ + creep.say('Sorry') + creep.moveTo(hostilebuilding); + creep.attack(hostilebuilding); + + }else if(Game.flags.Attack) { + creep.say('ATK') + creep.moveTo(Game.flags.Attack) + + } else{ + creep.say('parking') + creep.moveTo(creep.room.memory.warriorparkx,creep.room.memory.warriorparky,creep.room.roomName) + } + } +}; +module.exports = roleWarrior; \ No newline at end of file diff --git a/sourceprocessing.js b/sourceprocessing.js index 9b0e5dc..04865d1 100644 --- a/sourceprocessing.js +++ b/sourceprocessing.js @@ -1,6 +1,9 @@ let runSources = { tick: function(roomname) { - let sources = Game.rooms[roomname].find(FIND_DROPPED_ENERGY ); + let sources = Game.rooms[roomname].find( + FIND_DROPPED_RESOURCES, { + filter: (mineral) => mineral.resourceType === RESOURCE_ENERGY + }); for(let source of sources){ try{ let allhaulers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role=='hauler' ); diff --git a/spawnprocessing.js b/spawnprocessing.js new file mode 100644 index 0000000..9914a56 --- /dev/null +++ b/spawnprocessing.js @@ -0,0 +1,99 @@ +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 + console.log(Game.rooms[roomname].memory.tickssincespawn) + console.log(energyready / energymax) + 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){ + console.log('WOULD SPAWN AT '+ spawn.name) + //spawn.memory.spawnqueued=true + + if(Game.rooms[roomname].memory.maxminers > allminers.length){ + console.log('spawn miner') + buildparts.tick(roomname,'miner') + spawn.memory.spawnqueued=true + } else if(Game.rooms[roomname].memory.maxminer2s > allminer2s.length){ + console.log('spawn miner2s') + buildparts.tick(roomname,'miner2') + spawn.memory.spawnqueued=true + } else if(Game.rooms[roomname].memory.maxhaulers > allhaulers.length){ + console.log('spawn hauler') + buildparts.tick(roomname,'hauler') + spawn.memory.spawnqueued=true + }else if(Game.rooms[roomname].memory.maxhauler3s > allhauler3s.length){ + console.log('spawn hauler3') + buildparts.tick(roomname,'hauler3') + spawn.memory.spawnqueued=true + }else if(Game.rooms[roomname].memory.maxupgraders > allupgraders.length){ + console.log('spawn upgrader') + buildparts.tick(roomname,'upgrader') + spawn.memory.spawnqueued=true + } else if(Game.rooms[roomname].memory.maxhauler2s > allhauler2s.length){ + console.log('spawn hauler2') + buildparts.tick(roomname,'hauler2') + spawn.memory.spawnqueued=true + } else if(Game.rooms[roomname].memory.maxtowerrechargers > alltowerrechargers.length){ + console.log('spawn towerrecharger') + buildparts.tick(roomname,'towerrecharger') + spawn.memory.spawnqueued=true + } else if(Game.rooms[roomname].memory.maxrepairbots > allrepairbots.length){ + console.log('spawn repairbot') + buildparts.tick(roomname,'repairbot') + spawn.memory.spawnqueued=true + }else if(Game.rooms[roomname].memory.maxbuilders > allbuilders.length){ + console.log('spawn builder') + buildparts.tick(roomname,'builder') + spawn.memory.spawnqueued=true + } else if (Game.rooms[roomname].memory.maxwarriors > allwarriors.length){ + console.log('spawn warrior') + buildparts.tick(roomname,'warrior') + } else if(Game.rooms[roomname].memory.maxclaimers > allclaimers.length){ + console.log('spawn claimer') + buildparts.tick(roomname,'claimer') + } else if(Game.rooms[roomname].memory.maxnrbuilders > allnrbuilders.length){ + console.log('spawn nrbuilder') + buildparts.tick(roomname,'nrbuilder') + } else if(Game.rooms[roomname].memory.maxnrminers > allnrminers.length){ + console.log('spawn nrminer') + buildparts.tick(roomname,'nrminer') + } else {} + + } else if (!spawn.spawning && spawn.memory.spawnqueued) { + spawn.memory.spawnqueued=false + console.log('clearing spawn queue') + } 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; \ No newline at end of file diff --git a/sproc.js b/sproc.js index 8d8c522..d4bf202 100644 --- a/sproc.js +++ b/sproc.js @@ -1,7 +1,7 @@ let assignMiners = { tick: function(roomname) { let sources = Game.rooms[roomname].find(FIND_SOURCES ); - for(var source of sources){ + for(let source of sources){ let allminers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role=='miner' ); let unassignedminers = _.filter(allminers, (creep) => (creep.memory.destsource == undefined && creep.memory.role=='miner')); let assignedminers = _.filter(allminers, (creep) => (creep.memory.destsource != undefined && creep.memory.role=='miner')); diff --git a/tower.js b/tower.js index d77e618..454ce26 100644 --- a/tower.js +++ b/tower.js @@ -1,48 +1,49 @@ -var towers = { - - /** @param {Game} game **/ - tick: function(roomname) { - - towers = Game.rooms[roomname].find(FIND_MY_STRUCTURES, { - filter: { structureType: STRUCTURE_TOWER } - }) - _.forEach(towers, function(tower){ - - - let myclosestDamagedStructure = tower.room.find(FIND_STRUCTURES, { - filter: (structure) => structure.structureType != STRUCTURE_WALL && structure.structureType != STRUCTURE_RAMPART && structure.hits < structure.hitsMax - }); - let closestDamagedStructure = _.first(_.sortBy(myclosestDamagedStructure, (s)=>s.hits / s.hitsMax)); - - let allcontainers = tower.room.find(FIND_STRUCTURES, { - filter: (s) => { - return ( s.structureType == STRUCTURE_CONTAINER) - } - }); - if(tower.energy > tower.energyCapacity * .7 ){ - let importantstructures = tower.room.find(FIND_STRUCTURES, { - filter: (structure) => { - return (structure.structureType == STRUCTURE_CONTAINER && structure.hits < structure.hitsMax) ; - }}); - importantstructures = _.sortBy(importantstructures, (s)=>s.hits / s.hitsMax) - if(importantstructures.length > 0){ - tower.repair(importantstructures[0]); - } else - { - if(closestDamagedStructure) { - if(Game.rooms[roomname].memory.containerstoragepercent > .8){ - console.log("tower repairing. Currently at: " + Game.rooms[roomname].memory.containerstoragepercent) - tower.repair(closestDamagedStructure); - } else { console.log("tower waiting for more storage. Currently at: " + Game.rooms[roomname].memory.containerstoragepercent)} - } - } - let closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS); - if(closestHostile) { - tower.attack(closestHostile); - } - } - }) - } -}; - +var towers = { + + /** @param {Game} game **/ + tick: function(roomname) { + + towers = Game.rooms[roomname].find(FIND_MY_STRUCTURES, { + filter: { structureType: STRUCTURE_TOWER } + }) + _.forEach(towers, function(tower){ + let myclosestDamagedStructure = tower.room.find(FIND_STRUCTURES, { + filter: (structure) => structure.structureType != STRUCTURE_WALL && structure.structureType != STRUCTURE_RAMPART && structure.hits < structure.hitsMax + }); + let closestDamagedStructure = _.first(_.sortBy(myclosestDamagedStructure, (s)=>s.hits / s.hitsMax)); + + let allcontainers = tower.room.find(FIND_STRUCTURES, { + filter: (s) => { + return ( s.structureType == STRUCTURE_CONTAINER) + } + }); + let closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS); + if(closestHostile) { + tower.attack(closestHostile); + } else + { + if(tower.energy > tower.energyCapacity * .7 ){ + let importantstructures = tower.room.find(FIND_STRUCTURES, { + filter: (structure) => { + return (structure.structureType == STRUCTURE_CONTAINER && structure.hits < structure.hitsMax) ; + }}); + importantstructures = _.sortBy(importantstructures, (s)=>s.hits / s.hitsMax) + if(importantstructures.length > 0){ + tower.repair(importantstructures[0]); + } else + { + if(closestDamagedStructure) { + if(Game.rooms[roomname].memory.containerstoragepercent > .8){ + console.log("tower repairing. Currently at: " + Game.rooms[roomname].memory.containerstoragepercent) + tower.repair(closestDamagedStructure); + } else { console.log("tower waiting for more storage. Currently at: " + Game.rooms[roomname].memory.containerstoragepercent)} + } + } + + } + } + }) + } +}; + module.exports = towers; \ No newline at end of file