mirror of
https://github.com/paradizelost/screeps.git
synced 2024-11-25 02:14:44 -06:00
Rewrite Catchup
This commit is contained in:
parent
2f45d9b69e
commit
2199b449bb
70
Empire.js
Normal file
70
Empire.js
Normal file
@ -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())
|
||||
}
|
||||
};
|
26
MinedMineralProc.js
Normal file
26
MinedMineralProc.js
Normal file
@ -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;
|
4
NOTES.js
4
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;
|
||||
},
|
||||
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
93
main.js
93
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---')
|
||||
}
|
22
mineralprocessing.js
Normal file
22
mineralprocessing.js
Normal file
@ -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;
|
@ -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;
|
21
role.claimer.js
Normal file
21
role.claimer.js
Normal file
@ -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;
|
@ -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);
|
||||
@ -54,20 +52,12 @@ let roleHauler = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
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);
|
||||
if(creep.carry.RESOURCE_ZYNTHIUM > 0){
|
||||
if(creep.transfer(storagetargets, RESOURCE_ZYNTHIUM) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(storagetargets);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
module.exports = roleHauler;
|
@ -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;
|
@ -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;
|
13
role.miner2.js
Normal file
13
role.miner2.js
Normal file
@ -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;
|
33
role.mineralhauler.js
Normal file
33
role.mineralhauler.js
Normal file
@ -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;
|
60
role.nrbuilder.js
Normal file
60
role.nrbuilder.js
Normal file
@ -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;
|
25
role.nrminer.js
Normal file
25
role.nrminer.js
Normal file
@ -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;
|
@ -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;
|
@ -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;
|
@ -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){
|
||||
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);
|
||||
}
|
||||
}else{
|
||||
let droppedenergy = creep.room.find(FIND_DROPPED_ENERGY );
|
||||
if(creep.pickup(droppedenergy[0]) == ERR_NOT_IN_RANGE) {
|
||||
creep.say("MTDE");
|
||||
creep.moveTo(droppedenergy[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='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;
|
25
role.warrior.js
Normal file
25
role.warrior.js
Normal file
@ -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;
|
@ -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' );
|
||||
|
99
spawnprocessing.js
Normal file
99
spawnprocessing.js
Normal file
@ -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;
|
2
sproc.js
2
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'));
|
||||
|
13
tower.js
13
tower.js
@ -7,8 +7,6 @@ var towers = {
|
||||
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
|
||||
});
|
||||
@ -19,7 +17,12 @@ var towers = {
|
||||
return ( s.structureType == STRUCTURE_CONTAINER)
|
||||
}
|
||||
});
|
||||
if(tower.energy > tower.energyCapacity * .7 ){
|
||||
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) ;
|
||||
@ -36,9 +39,7 @@ var towers = {
|
||||
} 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);
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user