screeps/main.js

139 lines
7.2 KiB
JavaScript
Raw Normal View History

2016-09-28 08:37:28 -05:00
'use strict';
2017-06-06 13:17:26 -05:00
global.Empire = require("Empire")
2016-09-28 08:37:28 -05:00
let roleBuilder=require('role.builder');
2017-06-06 13:17:26 -05:00
let roleClaimer=require('role.claimer');
2016-09-28 08:37:28 -05:00
let roleMiner=require('role.miner');
let roleHauler=require('role.hauler')
let roleHauler2=require('role.hauler2')
let roleUpgrader=require('role.upgrader')
let roleTowerrecharger=require('role.recharger')
let runSources=require('sourceprocessing')
let roleRepairbot=require('role.repairbot')
let runTower = require('tower');
let assignMiners=require('sproc')
2017-06-06 13:17:26 -05:00
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')
2016-09-15 00:30:24 -05:00
module.exports.loop = function () {
2016-09-28 08:37:28 -05:00
console.log('---START---')
for(let name in Memory.creeps) {
2016-09-15 00:30:24 -05:00
if(!Game.creeps[name]) {
delete Memory.creeps[name];
console.log('Clearing non-existing creep memory:', name);
}
}
2016-09-28 08:37:28 -05:00
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
let name = myroom.name
console.log('---'+name+'---')
2016-09-23 00:12:42 -05:00
runTower.tick(name);
2016-09-28 08:37:28 -05:00
assignMiners.tick(name)
runSources.tick(name)
2017-06-06 13:17:26 -05:00
minedproc.tick(name)
2016-09-28 08:37:28 -05:00
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
2017-06-06 13:17:26 -05:00
for(let i of allstorage){
usedstorage+=_.sum(i.store)
mycapacity+=i.storeCapacity
2016-09-15 00:30:24 -05:00
}
2016-09-28 08:37:28 -05:00
let allcontainers = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_CONTAINER)}})
let containerusedstorage = 0
let containercapacity=0
for(let i=0; i < allcontainers.length;i++){
2016-09-23 00:12:42 -05:00
containerusedstorage+=_.sum(allcontainers[i].store)
containercapacity+=allcontainers[i].storeCapacity
2016-09-15 00:30:24 -05:00
}
2016-09-28 08:37:28 -05:00
Game.rooms[name].memory.storagepercent = usedstorage/mycapacity
2016-09-23 00:12:42 -05:00
Game.rooms[name].memory.containerstoragepercent = containerusedstorage/containercapacity
2017-06-06 13:17:26 -05:00
if(!(Game.rooms[name].memory.containerstoragepercent >-.1)){Game.rooms[name].memory.containerstoragepercent=0}
2016-09-23 00:12:42 -05:00
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')
2016-09-28 08:37:28 -05:00
} catch(e){}
2017-06-06 13:17:26 -05:00
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 }
2016-09-23 00:12:42 -05:00
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 }
if(Game.rooms[name].memory.maxharvester2s == undefined){ Game.rooms[name].memory.maxharvester2s = 0 }
if(Game.rooms[name].memory.maxrepairbots == undefined){ Game.rooms[name].memory.maxrepairbots = 0 }
if(Game.rooms[name].memory.minworkenergypct == undefined){ Game.rooms[name].memory.minworkenergypct = 0.3 }
if(Game.rooms[name].memory.builderparkx==undefined){Game.rooms[name].memory.builderparkx=24}
if(Game.rooms[name].memory.builderparky==undefined){Game.rooms[name].memory.builderparky=24}
if(Game.rooms[name].memory.hauler2parkx==undefined){Game.rooms[name].memory.hauler2parkx=24}
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}
2017-06-06 13:17:26 -05:00
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
2016-09-28 08:37:28 -05:00
for(let mycreep in mycreeps){
2016-09-23 00:12:42 -05:00
try{
2016-09-28 08:37:28 -05:00
let creep = mycreeps[mycreep]
2016-09-23 00:12:42 -05:00
if(creep.memory.role == 'miner'){
roleMiner.run(creep)
}
2017-06-06 13:17:26 -05:00
if(creep.memory.role=='miner2'){
roleMiner2.run(creep)
}
if(creep.memory.role == 'claimer'){
roleClaimer.run(creep)
}
2016-09-23 00:12:42 -05:00
if(creep.memory.role == 'hauler'){
roleHauler.run(creep)
}
if(creep.memory.role == 'hauler2'){
roleHauler2.run(creep)
}
2017-06-06 13:17:26 -05:00
if(creep.memory.role == 'hauler3'){
roleHauler3.run(creep)
}
2016-09-23 00:12:42 -05:00
if(creep.memory.role == 'builder'){
roleBuilder.run(creep)
}
if(creep.memory.role == 'upgrader'){
roleUpgrader.run(creep)
}
if(creep.memory.role=='towerrecharger'){
roleTowerrecharger.run(creep)
}
if(creep.memory.role == 'repairbot'){
roleRepairbot.run(creep)
}
2017-06-06 13:17:26 -05:00
if(creep.memory.role=='warrior'){
roleWarrior.run(creep)
}
if(creep.memory.role=='nrbuilder'){
rolenrBuilder.run(creep)
}
if(creep.memory.role=='nrminer'){
rolenrMiner.run(creep)
}
2016-09-23 00:12:42 -05:00
} catch (e) {
//console.log(e.toString)
}
2016-09-28 08:37:28 -05:00
}
2016-09-28 08:37:28 -05:00
console.log('----END---')
2016-09-15 00:30:24 -05:00
}