mirror of
https://github.com/paradizelost/screeps.git
synced 2024-11-25 02:14:44 -06:00
Resync with system
This commit is contained in:
parent
6ede729aed
commit
e72a3f37dd
81
Empire.js
81
Empire.js
@ -1,43 +1,11 @@
|
|||||||
let buildparts=require('bodypartbuilder')
|
//let buildparts=require('bodypartbuilder')
|
||||||
module.exports = {
|
module.exports = {
|
||||||
get getcounts(){
|
get getcounts(){
|
||||||
let output=''
|
for(let room of _.filter(Game.rooms, 'controller.my')) {
|
||||||
|
roomcounts = _.countBy(room.find(FIND_MY_CREEPS), c => c.memory.role)
|
||||||
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
|
console.log(roomcounts['phase1worker'])
|
||||||
let name = myroom.name
|
console.log(roomcounts['miner'])
|
||||||
//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){
|
decrease: function(role,roomname){
|
||||||
let rolename = 'max' + role + 's'
|
let rolename = 'max' + role + 's'
|
||||||
@ -64,14 +32,49 @@ module.exports = {
|
|||||||
let me= Game.creeps[creepname].suicide()
|
let me= Game.creeps[creepname].suicide()
|
||||||
return me
|
return me
|
||||||
},
|
},
|
||||||
spawn: function(roomname,role){
|
spawnwarrior: function(){
|
||||||
buildparts.tick(roomname,role)
|
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
|
||||||
|
let name = myroom.name
|
||||||
|
require('proc.spawning').spawnwarrior(name)
|
||||||
|
}
|
||||||
|
return 'Spawning initiated'
|
||||||
|
},
|
||||||
|
spawnnrworker: function(){
|
||||||
|
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
|
||||||
|
let name = myroom.name
|
||||||
|
require('proc.spawning').spawnnrworker(name)
|
||||||
|
}
|
||||||
|
return 'Spawning initiated'
|
||||||
|
},
|
||||||
|
spawnworker: function(){
|
||||||
|
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
|
||||||
|
let name = myroom.name
|
||||||
|
require('proc.spawning').spawnworker(name)
|
||||||
|
}
|
||||||
|
return 'Spawning initiated'
|
||||||
|
},
|
||||||
|
spawnclaimer: function(){
|
||||||
|
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
|
||||||
|
let name = myroom.name
|
||||||
|
require('proc.spawning').spawnclaimer(name)
|
||||||
|
}
|
||||||
return 'Spawning initiated'
|
return 'Spawning initiated'
|
||||||
},
|
},
|
||||||
removeConstruction: function(roomname){
|
removeConstruction: function(roomname){
|
||||||
_.invoke(Game.rooms[roomname].find(FIND_MY_CONSTRUCTION_SITES), 'remove')
|
_.invoke(Game.rooms[roomname].find(FIND_MY_CONSTRUCTION_SITES), 'remove')
|
||||||
},
|
},
|
||||||
|
removeAllConstruction: function(){
|
||||||
|
_.invoke(_.map(Game.constructionSites, (x)=>x), 'remove')
|
||||||
|
},
|
||||||
removeWalls: function(roomname){
|
removeWalls: function(roomname){
|
||||||
Game.rooms[roomname].find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_WALL}).forEach(s => s.destroy())
|
Game.rooms[roomname].find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_WALL}).forEach(s => s.destroy())
|
||||||
|
},
|
||||||
|
removeRoads: function(roomname,hitsleft){
|
||||||
|
Game.rooms[roomname].find(FIND_STRUCTURES, {filter: s => (s.structureType === STRUCTURE_ROAD && s.hits < hitsleft)}).forEach(s => s.destroy())
|
||||||
|
return "done"
|
||||||
|
},
|
||||||
|
sellEnergy: function(roomname){
|
||||||
|
let myorders = Game.market.getAllOrders(order=>order.resourceType == RESOURCE_ENERGY && order.type == ORDER_SELL)
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -1,26 +0,0 @@
|
|||||||
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;
|
|
108
NOTES.js
108
NOTES.js
@ -1,64 +1,62 @@
|
|||||||
if(containers.count==0 && structure_extensions.count==0 && storage.count==0 && miners.count==0){spawn harvester} else { spawn miners and haulers}
|
/*
|
||||||
require('role.' + creep.memory.role).run(creep)
|
||Game.rooms[room].find(FIND_MY_STRUCTURES, {filter: { structureType: STRUCTURE_EXTENSION }}).length == 5
|
||||||
_.forEach(Game.creeps, creep => creep.suicide())
|
|
||||||
_.forEach(Game.rooms[roomname].constructionSites, cs=>cs.remove())
|
{ignoreCreeps:true} on moveto, need to find how to check if stuck
|
||||||
serializePos: function(pos) {
|
let pos = _.create(RoomPosition.prototype, creep.memory.pos)
|
||||||
return pos.x + '_' + pos.y + '_' + pos.roomName;
|
for(let road in look){if(road.structureType == STRUCTURE_ROAD){console.log('road at ' + creep.pos)}}
|
||||||
},
|
|
||||||
deserializePos: function(str) {
|
let road = in_creep.pos.lookFor(LOOK_STRUCTURES)[0];
|
||||||
var ar = str.split('_');
|
if (road) {in_creep.repair(road);}
|
||||||
return new RoomPosition(ar[0], ar[1], ar[2]);
|
x=Game.getObjectById("58dbc3ad8283ff5308a3df08"); console.log(`${x.progressTotal - x.progress} to go!`);
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Structure.prototype.getResourceCapacity = function(resourceType) {
|
--------- code to check for open source spots ----
|
||||||
switch (this.structureType) {
|
RoomPosition.prototype.isOpen = function(opts){
|
||||||
case STRUCTURE_CONTAINER:
|
// opts.ignoreCreeps (boolean) default false. ignores creeps if true.
|
||||||
case STRUCTURE_STORAGE:
|
// opts.ignoreSolids (boolean) default false. ignores solid structures if true.
|
||||||
case STRUCTURE_TERMINAL:
|
if ("wall" === Game.map.getTerrainAt(this)) return(false);
|
||||||
return this.storeCapacity;
|
if (null==Game.rooms[this.roomName]) return (true);
|
||||||
case STRUCTURE_SPAWN:
|
if ((null==opts || !opts.ignoreCreeps) &&
|
||||||
case STRUCTURE_EXTENSION:
|
(this.lookFor(LOOK_CREEPS).length !== 0)) return(false);
|
||||||
case STRUCTURE_LINK:
|
if (null==opts || !opts.ignoreSolids){
|
||||||
case STRUCTURE_TOWER:
|
var objectList = this.lookFor(LOOK_STRUCTURES).concat(
|
||||||
if (RESOURCE_ENERGY == resourceType) {
|
this.lookFor(LOOK_CONSTRUCTION_SITES));
|
||||||
return(this.energyCapacity);
|
for(let j=objectList.length; --j>=0; ){
|
||||||
} else {
|
let rObj = objectList[j];
|
||||||
return(-1);
|
if (rObj instanceof ConstructionSite && !rObj.my) continue;
|
||||||
|
if (rObj.structureType !== STRUCTURE_ROAD &&
|
||||||
|
rObj.structureType !== STRUCTURE_CONTAINER &&
|
||||||
|
(rObj.structureType !== STRUCTURE_RAMPART ||
|
||||||
|
!rObj.my)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
case STRUCTURE_LAB:
|
|
||||||
if (RESOURCE_ENERGY == resourceType) {
|
|
||||||
return(this.energyCapacity);
|
|
||||||
} else {
|
|
||||||
return(this.mineralCapacity);
|
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
return(-1);
|
|
||||||
}
|
}
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
Structure.prototype.getResource = function(resourceType) {
|
RoomPosition.prototype.nearOpenList = function(opts){
|
||||||
switch (this.structureType) {
|
// using .isOpen (above) this checks adjacent positions for openness. Room exits and
|
||||||
case STRUCTURE_CONTAINER:
|
// other rooms are not considered. The position itself is also not considered.
|
||||||
case STRUCTURE_STORAGE:
|
//
|
||||||
case STRUCTURE_TERMINAL:
|
// opts.ignoreCreeps (boolean) default false. ignores creeps if true.
|
||||||
return this.store[resourceType];
|
// opts.ignoreSolids (boolean) default false. ignores solid structures if true.
|
||||||
case STRUCTURE_SPAWN:
|
// return (list) list of open adjacent positions.
|
||||||
case STRUCTURE_EXTENSION:
|
var x=this.x;
|
||||||
case STRUCTURE_LINK:
|
var y=this.y;
|
||||||
case STRUCTURE_TOWER:
|
var openPosList=[];
|
||||||
if (RESOURCE_ENERGY == resourceType) {
|
var sList=[{x:x-1,y:y-1},{x:x, y:y-1},{x:x+1,y:y-1},
|
||||||
return(this.energy);
|
{x:x-1,y:y }, {x:x+1,y:y },
|
||||||
} else {
|
{x:x-1,y:y+1},{x:x, y:y+1},{x:x+1,y:y+1}];
|
||||||
return(-1);
|
for (var i=sList.length; --i>=0; ){
|
||||||
|
if (sList[i].x<49 && sList[i].x>0 &&
|
||||||
|
sList[i].y<49 && sList[i].y>0 &&
|
||||||
|
(global.myCache.getRoomPosition(
|
||||||
|
sList[i].x,sList[i].y,this.roomName)).isOpen(opts)){
|
||||||
|
openPosList.push(
|
||||||
|
global.myCache.getRoomPosition(sList[i].x,sList[i].y,this.roomName));
|
||||||
}
|
}
|
||||||
case STRUCTURE_LAB:
|
|
||||||
if (RESOURCE_ENERGY == resourceType) {
|
|
||||||
return(this.energy);
|
|
||||||
} else {
|
|
||||||
return(this.mineralAmount);
|
|
||||||
}
|
}
|
||||||
default:
|
return(openPosList);
|
||||||
return(-1);
|
};
|
||||||
}
|
--------- end open position code -----
|
||||||
}
|
|
52
Room.Phase0.js
Normal file
52
Room.Phase0.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
let Phase0 = {
|
||||||
|
run: function(room) {
|
||||||
|
require('assignsources').tick(room)
|
||||||
|
creepcounts = _.countBy(Game.rooms[room].find(FIND_MY_CREEPS), c => c.memory.role)
|
||||||
|
let myspawns = Game.rooms[room].find(FIND_MY_SPAWNS)
|
||||||
|
let sources = Game.rooms[room].find(FIND_SOURCES )
|
||||||
|
if(myspawns.length<1){
|
||||||
|
if(Game.rooms[room].controller.level>1){
|
||||||
|
|
||||||
|
Game.rooms[room].memory.phase++
|
||||||
|
let creeps=Game.rooms[room].find(FIND_MY_CREEPS)
|
||||||
|
let newworkerrolename = 'phase' + Game.rooms[room].memory.phase + 'worker'
|
||||||
|
for(let mycreep in creeps){
|
||||||
|
creep=creeps[mycreep]
|
||||||
|
if(creep.memory.role == workerrolename){
|
||||||
|
creep.memory.role=newworkerrolename
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Game.rooms[room].memory['tickstophase' + Game.rooms[room].memory.phase]=Game.rooms[room].memory.tickssofar
|
||||||
|
console.log(Game.rooms[room].memory['tickstophase' + Game.rooms[room].memory.phase])
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let workerrolename = 'phase' + Game.rooms[room].memory.phase +'worker'
|
||||||
|
console.log(room)
|
||||||
|
console.log(workerrolename + " : " + creepcounts[workerrolename])
|
||||||
|
if(((creepcounts[workerrolename]< (sources.length * 1) || creepcounts[workerrolename]==undefined) && !myspawns[0].spawning && Game.rooms[room].energyAvailable == Game.rooms[room].energyCapacityAvailable) || (creepcounts[workerrolename] ==0 && Game.rooms[room].energyAvailable==300) ){
|
||||||
|
if(Game.rooms[room].energyAvailable == Game.rooms[room].energyCapacityAvailable){
|
||||||
|
require('proc.spawning').spawnworker(room)
|
||||||
|
}
|
||||||
|
} else { }
|
||||||
|
if(Game.rooms[room].controller.level>1){
|
||||||
|
|
||||||
|
Game.rooms[room].memory.phase++
|
||||||
|
let creeps=Game.rooms[room].find(FIND_MY_CREEPS)
|
||||||
|
let newworkerrolename = 'phase' + Game.rooms[room].memory.phase + 'worker'
|
||||||
|
for(let mycreep in creeps){
|
||||||
|
creep=creeps[mycreep]
|
||||||
|
if(creep.memory.role == workerrolename){
|
||||||
|
creep.memory.role=newworkerrolename
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Game.rooms[room].memory['tickstophase' + Game.rooms[room].memory.phase]=Game.rooms[room].memory.tickssofar
|
||||||
|
console.log(Game.rooms[room].memory['tickstophase' + Game.rooms[room].memory.phase])
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = Phase0;
|
41
Room.Phase1.js
Normal file
41
Room.Phase1.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
let Phase1 = {
|
||||||
|
run: function(room) {
|
||||||
|
require('assignsources').tick(room)
|
||||||
|
if(Game.time % 10 === 0){
|
||||||
|
//console.log('processing spawn')
|
||||||
|
let myspawns = Game.rooms[room].find(FIND_MY_SPAWNS)
|
||||||
|
if(myspawns.length>0){
|
||||||
|
let myspawn = myspawns[0]
|
||||||
|
let creepcount = Game.rooms[room].find(FIND_MY_CREEPS).length
|
||||||
|
creepcounts = _.countBy(Game.rooms[room].find(FIND_MY_CREEPS), c => c.memory.role)
|
||||||
|
let workerrolename = 'phase' + Game.rooms[room].memory.phase +'worker'
|
||||||
|
let sources = Game.rooms[room].find(FIND_SOURCES )
|
||||||
|
if(Game.rooms[room].controller.ticksToDowngrade < CONTROLLER_DOWNGRADE[Game.rooms[room].controller.level] * .2 ){
|
||||||
|
Game.rooms[room].memory.NeedsRecharge=1
|
||||||
|
console.log(Game.rooms[room].memory.NeedsRecharge)
|
||||||
|
}
|
||||||
|
if(Game.rooms[room].controller.ticksToDowngrade > CONTROLLER_DOWNGRADE[Game.rooms[room].controller.level]*.8){
|
||||||
|
Game.rooms[room].memory.NeedsRecharge=0
|
||||||
|
console.log(Game.rooms[room].memory.NeedsRecharge)
|
||||||
|
}
|
||||||
|
if(Game.flags.debug && Game.flags.debug.room == Game.rooms[room]){
|
||||||
|
console.log(room)
|
||||||
|
console.log(workerrolename)
|
||||||
|
console.log(creepcounts[workerrolename])
|
||||||
|
console.log(Game.rooms[room].energyAvailable + " of " + Game.rooms[room].energyCapacityAvailable)
|
||||||
|
}
|
||||||
|
|
||||||
|
if((((creepcounts[workerrolename]< (sources.length * 3) || creepcounts[workerrolename]==undefined) && Game.rooms[room].energyAvailable >= Game.rooms[room].energyCapacityAvailable) ) || ((creepcounts[workerrolename]==0 || creepcounts[workerrolename]==undefined ) && Game.rooms[room].energyAvailable>100)) {
|
||||||
|
require('proc.spawning').spawnworker(room)
|
||||||
|
}
|
||||||
|
if(Game.rooms[room].storage && Game.rooms[room].terminal && (creepcounts["mover"] < 1 || creepcounts["mover"]==undefined) && Game.rooms[room].energyAvailable >= Game.rooms[room].energyCapacityAvailable){
|
||||||
|
console.log("Spawning Mover")
|
||||||
|
require('proc.spawning').spawnmover(room)
|
||||||
|
}
|
||||||
|
//require('proc.market').sellEnergy(room)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(Game.rooms[room].controller.level>2){ }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = Phase1;
|
13
RoomInit.js
Normal file
13
RoomInit.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
let initroom = {
|
||||||
|
run: function(name) {
|
||||||
|
console.log('Initing room ' + name)
|
||||||
|
Game.rooms[name].memory.phase=0
|
||||||
|
Game.rooms[name].memory.CreepNum=0
|
||||||
|
Game.rooms[name].memory.minbuildpct=-1
|
||||||
|
Game.rooms[name].memory.minupgradepct=.5
|
||||||
|
Game.rooms[name].memory.minrepairpct=.5
|
||||||
|
Game.rooms[name].memory.hasbeeninited=1
|
||||||
|
Game.rooms[name].memory.tickssofar=0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports = initroom
|
@ -33,7 +33,7 @@ var towers = {
|
|||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
if(closestDamagedStructure) {
|
if(closestDamagedStructure) {
|
||||||
if(Game.rooms[roomname].memory.containerstoragepercent > .8){
|
if(tower.energy > tower.energyCapacity * 1.8 ){
|
||||||
if(global.verbosity>0){
|
if(global.verbosity>0){
|
||||||
console.log("tower repairing. Currently at: " + Game.rooms[roomname].memory.containerstoragepercent)
|
console.log("tower repairing. Currently at: " + Game.rooms[roomname].memory.containerstoragepercent)
|
||||||
}
|
}
|
584
Traveler.js
Normal file
584
Traveler.js
Normal file
@ -0,0 +1,584 @@
|
|||||||
|
/**
|
||||||
|
* To start using Traveler, require it in main.js:
|
||||||
|
* Example: var Traveler = require('Traveler.js');
|
||||||
|
*/
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
class Traveler {
|
||||||
|
/**
|
||||||
|
* move creep to destination
|
||||||
|
* @param creep
|
||||||
|
* @param destination
|
||||||
|
* @param options
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static travelTo(creep, destination, options = {}) {
|
||||||
|
// uncomment if you would like to register hostile rooms entered
|
||||||
|
// this.updateRoomStatus(creep.room);
|
||||||
|
if (!destination) {
|
||||||
|
return ERR_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
if (creep.fatigue > 0) {
|
||||||
|
Traveler.circle(creep.pos, "aqua", .3);
|
||||||
|
return ERR_BUSY;
|
||||||
|
}
|
||||||
|
destination = this.normalizePos(destination);
|
||||||
|
// manage case where creep is nearby destination
|
||||||
|
let rangeToDestination = creep.pos.getRangeTo(destination);
|
||||||
|
if (options.range && rangeToDestination <= options.range) {
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
else if (rangeToDestination <= 1) {
|
||||||
|
if (rangeToDestination === 1 && !options.range) {
|
||||||
|
let direction = creep.pos.getDirectionTo(destination);
|
||||||
|
if (options.returnData) {
|
||||||
|
options.returnData.nextPos = destination;
|
||||||
|
options.returnData.path = direction.toString();
|
||||||
|
}
|
||||||
|
return creep.move(direction);
|
||||||
|
}
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
// initialize data object
|
||||||
|
if (!creep.memory._trav) {
|
||||||
|
delete creep.memory._travel;
|
||||||
|
creep.memory._trav = {};
|
||||||
|
}
|
||||||
|
let travelData = creep.memory._trav;
|
||||||
|
let state = this.deserializeState(travelData, destination);
|
||||||
|
// uncomment to visualize destination
|
||||||
|
// this.circle(destination.pos, "orange");
|
||||||
|
// check if creep is stuck
|
||||||
|
if (this.isStuck(creep, state)) {
|
||||||
|
state.stuckCount++;
|
||||||
|
Traveler.circle(creep.pos, "magenta", state.stuckCount * .2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
state.stuckCount = 0;
|
||||||
|
}
|
||||||
|
// handle case where creep is stuck
|
||||||
|
if (!options.stuckValue) {
|
||||||
|
options.stuckValue = DEFAULT_STUCK_VALUE;
|
||||||
|
}
|
||||||
|
if (state.stuckCount >= options.stuckValue && Math.random() > .5) {
|
||||||
|
options.ignoreCreeps = false;
|
||||||
|
options.freshMatrix = true;
|
||||||
|
delete travelData.path;
|
||||||
|
}
|
||||||
|
// TODO:handle case where creep moved by some other function, but destination is still the same
|
||||||
|
// delete path cache if destination is different
|
||||||
|
if (!this.samePos(state.destination, destination)) {
|
||||||
|
if (options.movingTarget && state.destination.isNearTo(destination)) {
|
||||||
|
travelData.path += state.destination.getDirectionTo(destination);
|
||||||
|
state.destination = destination;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
delete travelData.path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (options.repath && Math.random() < options.repath) {
|
||||||
|
// add some chance that you will find a new path randomly
|
||||||
|
delete travelData.path;
|
||||||
|
}
|
||||||
|
// pathfinding
|
||||||
|
let newPath = false;
|
||||||
|
if (!travelData.path) {
|
||||||
|
newPath = true;
|
||||||
|
if (creep.spawning) {
|
||||||
|
return ERR_BUSY;
|
||||||
|
}
|
||||||
|
state.destination = destination;
|
||||||
|
let cpu = Game.cpu.getUsed();
|
||||||
|
let ret = this.findTravelPath(creep.pos, destination, options);
|
||||||
|
let cpuUsed = Game.cpu.getUsed() - cpu;
|
||||||
|
state.cpu = _.round(cpuUsed + state.cpu);
|
||||||
|
if (state.cpu > REPORT_CPU_THRESHOLD) {
|
||||||
|
// see note at end of file for more info on this
|
||||||
|
console.log(`TRAVELER: heavy cpu use: ${creep.name}, cpu: ${state.cpu} origin: ${creep.pos}, dest: ${destination}`);
|
||||||
|
}
|
||||||
|
let color = "orange";
|
||||||
|
if (ret.incomplete) {
|
||||||
|
// uncommenting this is a great way to diagnose creep behavior issues
|
||||||
|
// console.log(`TRAVELER: incomplete path for ${creep.name}`);
|
||||||
|
color = "red";
|
||||||
|
}
|
||||||
|
if (options.returnData) {
|
||||||
|
options.returnData.pathfinderReturn = ret;
|
||||||
|
}
|
||||||
|
travelData.path = Traveler.serializePath(creep.pos, ret.path, color);
|
||||||
|
state.stuckCount = 0;
|
||||||
|
}
|
||||||
|
this.serializeState(creep, destination, state, travelData);
|
||||||
|
if (!travelData.path || travelData.path.length === 0) {
|
||||||
|
return ERR_NO_PATH;
|
||||||
|
}
|
||||||
|
// consume path
|
||||||
|
if (state.stuckCount === 0 && !newPath) {
|
||||||
|
travelData.path = travelData.path.substr(1);
|
||||||
|
}
|
||||||
|
let nextDirection = parseInt(travelData.path[0], 10);
|
||||||
|
if (options.returnData) {
|
||||||
|
if (nextDirection) {
|
||||||
|
let nextPos = Traveler.positionAtDirection(creep.pos, nextDirection);
|
||||||
|
if (nextPos) {
|
||||||
|
options.returnData.nextPos = nextPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options.returnData.state = state;
|
||||||
|
options.returnData.path = travelData.path;
|
||||||
|
}
|
||||||
|
return creep.move(nextDirection);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* make position objects consistent so that either can be used as an argument
|
||||||
|
* @param destination
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
|
static normalizePos(destination) {
|
||||||
|
if (!(destination instanceof RoomPosition)) {
|
||||||
|
return destination.pos;
|
||||||
|
}
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* check if room should be avoided by findRoute algorithm
|
||||||
|
* @param roomName
|
||||||
|
* @returns {RoomMemory|number}
|
||||||
|
*/
|
||||||
|
static checkAvoid(roomName) {
|
||||||
|
return Memory.rooms && Memory.rooms[roomName] && Memory.rooms[roomName].avoid;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* check if a position is an exit
|
||||||
|
* @param pos
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
static isExit(pos) {
|
||||||
|
return pos.x === 0 || pos.y === 0 || pos.x === 49 || pos.y === 49;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* check two coordinates match
|
||||||
|
* @param pos1
|
||||||
|
* @param pos2
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
static sameCoord(pos1, pos2) {
|
||||||
|
return pos1.x === pos2.x && pos1.y === pos2.y;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* check if two positions match
|
||||||
|
* @param pos1
|
||||||
|
* @param pos2
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
static samePos(pos1, pos2) {
|
||||||
|
return this.sameCoord(pos1, pos2) && pos1.roomName === pos2.roomName;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* draw a circle at position
|
||||||
|
* @param pos
|
||||||
|
* @param color
|
||||||
|
* @param opacity
|
||||||
|
*/
|
||||||
|
static circle(pos, color, opacity) {
|
||||||
|
new RoomVisual(pos.roomName).circle(pos, {
|
||||||
|
radius: .45, fill: "transparent", stroke: color, strokeWidth: .15, opacity: opacity
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* update memory on whether a room should be avoided based on controller owner
|
||||||
|
* @param room
|
||||||
|
*/
|
||||||
|
static updateRoomStatus(room) {
|
||||||
|
if (!room) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (room.controller) {
|
||||||
|
if (room.controller.owner && !room.controller.my) {
|
||||||
|
room.memory.avoid = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
delete room.memory.avoid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* find a path from origin to destination
|
||||||
|
* @param origin
|
||||||
|
* @param destination
|
||||||
|
* @param options
|
||||||
|
* @returns {PathfinderReturn}
|
||||||
|
*/
|
||||||
|
static findTravelPath(origin, destination, options = {}) {
|
||||||
|
_.defaults(options, {
|
||||||
|
ignoreCreeps: true,
|
||||||
|
maxOps: DEFAULT_MAXOPS,
|
||||||
|
range: 1,
|
||||||
|
});
|
||||||
|
if (options.movingTarget) {
|
||||||
|
options.range = 0;
|
||||||
|
}
|
||||||
|
origin = this.normalizePos(origin);
|
||||||
|
destination = this.normalizePos(destination);
|
||||||
|
let originRoomName = origin.roomName;
|
||||||
|
let destRoomName = destination.roomName;
|
||||||
|
// check to see whether findRoute should be used
|
||||||
|
let roomDistance = Game.map.getRoomLinearDistance(origin.roomName, destination.roomName);
|
||||||
|
let allowedRooms = options.route;
|
||||||
|
if (!allowedRooms && (options.useFindRoute || (options.useFindRoute === undefined && roomDistance > 2))) {
|
||||||
|
let route = this.findRoute(origin.roomName, destination.roomName, options);
|
||||||
|
if (route) {
|
||||||
|
allowedRooms = route;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let roomsSearched = 0;
|
||||||
|
let callback = (roomName) => {
|
||||||
|
if (allowedRooms) {
|
||||||
|
if (!allowedRooms[roomName]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!options.allowHostile && Traveler.checkAvoid(roomName)
|
||||||
|
&& roomName !== destRoomName && roomName !== originRoomName) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
roomsSearched++;
|
||||||
|
let matrix;
|
||||||
|
let room = Game.rooms[roomName];
|
||||||
|
if (room) {
|
||||||
|
if (options.ignoreStructures) {
|
||||||
|
matrix = new PathFinder.CostMatrix();
|
||||||
|
if (!options.ignoreCreeps) {
|
||||||
|
Traveler.addCreepsToMatrix(room, matrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (options.ignoreCreeps || roomName !== originRoomName) {
|
||||||
|
matrix = this.getStructureMatrix(room, options.freshMatrix);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
matrix = this.getCreepMatrix(room);
|
||||||
|
}
|
||||||
|
if (options.obstacles) {
|
||||||
|
matrix = matrix.clone();
|
||||||
|
for (let obstacle of options.obstacles) {
|
||||||
|
if (obstacle.pos.roomName !== roomName) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
matrix.set(obstacle.pos.x, obstacle.pos.y, 0xff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (options.roomCallback) {
|
||||||
|
if (!matrix) {
|
||||||
|
matrix = new PathFinder.CostMatrix();
|
||||||
|
}
|
||||||
|
let outcome = options.roomCallback(roomName, matrix.clone());
|
||||||
|
if (outcome !== undefined) {
|
||||||
|
return outcome;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matrix;
|
||||||
|
};
|
||||||
|
let ret = PathFinder.search(origin, { pos: destination, range: options.range }, {
|
||||||
|
maxOps: options.maxOps,
|
||||||
|
maxRooms: options.maxRooms,
|
||||||
|
plainCost: options.offRoad ? 1 : options.ignoreRoads ? 1 : 2,
|
||||||
|
swampCost: options.offRoad ? 1 : options.ignoreRoads ? 5 : 10,
|
||||||
|
roomCallback: callback,
|
||||||
|
});
|
||||||
|
if (ret.incomplete && options.ensurePath) {
|
||||||
|
if (options.useFindRoute === undefined) {
|
||||||
|
// handle case where pathfinder failed at a short distance due to not using findRoute
|
||||||
|
// can happen for situations where the creep would have to take an uncommonly indirect path
|
||||||
|
// options.allowedRooms and options.routeCallback can also be used to handle this situation
|
||||||
|
if (roomDistance <= 2) {
|
||||||
|
console.log(`TRAVELER: path failed without findroute, trying with options.useFindRoute = true`);
|
||||||
|
console.log(`from: ${origin}, destination: ${destination}`);
|
||||||
|
options.useFindRoute = true;
|
||||||
|
ret = this.findTravelPath(origin, destination, options);
|
||||||
|
console.log(`TRAVELER: second attempt was ${ret.incomplete ? "not " : ""}successful`);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
// TODO: handle case where a wall or some other obstacle is blocking the exit assumed by findRoute
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* find a viable sequence of rooms that can be used to narrow down pathfinder's search algorithm
|
||||||
|
* @param origin
|
||||||
|
* @param destination
|
||||||
|
* @param options
|
||||||
|
* @returns {{}}
|
||||||
|
*/
|
||||||
|
static findRoute(origin, destination, options = {}) {
|
||||||
|
let restrictDistance = options.restrictDistance || Game.map.getRoomLinearDistance(origin, destination) + 10;
|
||||||
|
let allowedRooms = { [origin]: true, [destination]: true };
|
||||||
|
let highwayBias = 1;
|
||||||
|
if (options.preferHighway) {
|
||||||
|
highwayBias = 2.5;
|
||||||
|
if (options.highwayBias) {
|
||||||
|
highwayBias = options.highwayBias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let ret = Game.map.findRoute(origin, destination, {
|
||||||
|
routeCallback: (roomName) => {
|
||||||
|
if (options.routeCallback) {
|
||||||
|
let outcome = options.routeCallback(roomName);
|
||||||
|
if (outcome !== undefined) {
|
||||||
|
return outcome;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let rangeToRoom = Game.map.getRoomLinearDistance(origin, roomName);
|
||||||
|
if (rangeToRoom > restrictDistance) {
|
||||||
|
// room is too far out of the way
|
||||||
|
return Number.POSITIVE_INFINITY;
|
||||||
|
}
|
||||||
|
if (!options.allowHostile && Traveler.checkAvoid(roomName) &&
|
||||||
|
roomName !== destination && roomName !== origin) {
|
||||||
|
// room is marked as "avoid" in room memory
|
||||||
|
return Number.POSITIVE_INFINITY;
|
||||||
|
}
|
||||||
|
let parsed;
|
||||||
|
if (options.preferHighway) {
|
||||||
|
parsed = /^[WE]([0-9]+)[NS]([0-9]+)$/.exec(roomName);
|
||||||
|
let isHighway = (parsed[1] % 10 === 0) || (parsed[2] % 10 === 0);
|
||||||
|
if (isHighway) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// SK rooms are avoided when there is no vision in the room, harvested-from SK rooms are allowed
|
||||||
|
if (!options.allowSK && !Game.rooms[roomName]) {
|
||||||
|
if (!parsed) {
|
||||||
|
parsed = /^[WE]([0-9]+)[NS]([0-9]+)$/.exec(roomName);
|
||||||
|
}
|
||||||
|
let fMod = parsed[1] % 10;
|
||||||
|
let sMod = parsed[2] % 10;
|
||||||
|
let isSK = !(fMod === 5 && sMod === 5) &&
|
||||||
|
((fMod >= 4) && (fMod <= 6)) &&
|
||||||
|
((sMod >= 4) && (sMod <= 6));
|
||||||
|
if (isSK) {
|
||||||
|
return 10 * highwayBias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return highwayBias;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!_.isArray(ret)) {
|
||||||
|
console.log(`couldn't findRoute to ${destination}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let value of ret) {
|
||||||
|
allowedRooms[value.room] = true;
|
||||||
|
}
|
||||||
|
return allowedRooms;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* check how many rooms were included in a route returned by findRoute
|
||||||
|
* @param origin
|
||||||
|
* @param destination
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static routeDistance(origin, destination) {
|
||||||
|
let linearDistance = Game.map.getRoomLinearDistance(origin, destination);
|
||||||
|
if (linearDistance >= 32) {
|
||||||
|
return linearDistance;
|
||||||
|
}
|
||||||
|
let allowedRooms = this.findRoute(origin, destination);
|
||||||
|
if (allowedRooms) {
|
||||||
|
return Object.keys(allowedRooms).length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* build a cost matrix based on structures in the room. Will be cached for more than one tick. Requires vision.
|
||||||
|
* @param room
|
||||||
|
* @param freshMatrix
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
|
static getStructureMatrix(room, freshMatrix) {
|
||||||
|
if (!this.structureMatrixCache[room.name] || (freshMatrix && Game.time !== this.structureMatrixTick)) {
|
||||||
|
this.structureMatrixTick = Game.time;
|
||||||
|
let matrix = new PathFinder.CostMatrix();
|
||||||
|
this.structureMatrixCache[room.name] = Traveler.addStructuresToMatrix(room, matrix, 1);
|
||||||
|
}
|
||||||
|
return this.structureMatrixCache[room.name];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* build a cost matrix based on creeps and structures in the room. Will be cached for one tick. Requires vision.
|
||||||
|
* @param room
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
|
static getCreepMatrix(room) {
|
||||||
|
if (!this.creepMatrixCache[room.name] || Game.time !== this.creepMatrixTick) {
|
||||||
|
this.creepMatrixTick = Game.time;
|
||||||
|
this.creepMatrixCache[room.name] = Traveler.addCreepsToMatrix(room, this.getStructureMatrix(room, true).clone());
|
||||||
|
}
|
||||||
|
return this.creepMatrixCache[room.name];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* add structures to matrix so that impassible structures can be avoided and roads given a lower cost
|
||||||
|
* @param room
|
||||||
|
* @param matrix
|
||||||
|
* @param roadCost
|
||||||
|
* @returns {CostMatrix}
|
||||||
|
*/
|
||||||
|
static addStructuresToMatrix(room, matrix, roadCost) {
|
||||||
|
let impassibleStructures = [];
|
||||||
|
for (let structure of room.find(FIND_STRUCTURES)) {
|
||||||
|
if (structure instanceof StructureRampart) {
|
||||||
|
if (!structure.my && !structure.isPublic) {
|
||||||
|
impassibleStructures.push(structure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (structure instanceof StructureRoad) {
|
||||||
|
matrix.set(structure.pos.x, structure.pos.y, roadCost);
|
||||||
|
}
|
||||||
|
else if (structure instanceof StructureContainer) {
|
||||||
|
matrix.set(structure.pos.x, structure.pos.y, 5);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
impassibleStructures.push(structure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let site of room.find(FIND_MY_CONSTRUCTION_SITES)) {
|
||||||
|
if (site.structureType === STRUCTURE_CONTAINER || site.structureType === STRUCTURE_ROAD
|
||||||
|
|| site.structureType === STRUCTURE_RAMPART) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
matrix.set(site.pos.x, site.pos.y, 0xff);
|
||||||
|
}
|
||||||
|
for (let structure of impassibleStructures) {
|
||||||
|
matrix.set(structure.pos.x, structure.pos.y, 0xff);
|
||||||
|
}
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* add creeps to matrix so that they will be avoided by other creeps
|
||||||
|
* @param room
|
||||||
|
* @param matrix
|
||||||
|
* @returns {CostMatrix}
|
||||||
|
*/
|
||||||
|
static addCreepsToMatrix(room, matrix) {
|
||||||
|
room.find(FIND_CREEPS).forEach((creep) => matrix.set(creep.pos.x, creep.pos.y, 0xff));
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* serialize a path, traveler style. Returns a string of directions.
|
||||||
|
* @param startPos
|
||||||
|
* @param path
|
||||||
|
* @param color
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
static serializePath(startPos, path, color = "orange") {
|
||||||
|
let serializedPath = "";
|
||||||
|
let lastPosition = startPos;
|
||||||
|
this.circle(startPos, color);
|
||||||
|
for (let position of path) {
|
||||||
|
if (position.roomName === lastPosition.roomName) {
|
||||||
|
new RoomVisual(position.roomName)
|
||||||
|
.line(position, lastPosition, { color: color, lineStyle: "dashed" });
|
||||||
|
serializedPath += lastPosition.getDirectionTo(position);
|
||||||
|
}
|
||||||
|
lastPosition = position;
|
||||||
|
}
|
||||||
|
return serializedPath;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* returns a position at a direction relative to origin
|
||||||
|
* @param origin
|
||||||
|
* @param direction
|
||||||
|
* @returns {RoomPosition}
|
||||||
|
*/
|
||||||
|
static positionAtDirection(origin, direction) {
|
||||||
|
let offsetX = [0, 0, 1, 1, 1, 0, -1, -1, -1];
|
||||||
|
let offsetY = [0, -1, -1, 0, 1, 1, 1, 0, -1];
|
||||||
|
let x = origin.x + offsetX[direction];
|
||||||
|
let y = origin.y + offsetY[direction];
|
||||||
|
if (x > 49 || x < 0 || y > 49 || y < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return new RoomPosition(x, y, origin.roomName);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* convert room avoidance memory from the old pattern to the one currently used
|
||||||
|
* @param cleanup
|
||||||
|
*/
|
||||||
|
static patchMemory(cleanup = false) {
|
||||||
|
if (!Memory.empire) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!Memory.empire.hostileRooms) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let count = 0;
|
||||||
|
for (let roomName in Memory.empire.hostileRooms) {
|
||||||
|
if (Memory.empire.hostileRooms[roomName]) {
|
||||||
|
if (!Memory.rooms[roomName]) {
|
||||||
|
Memory.rooms[roomName] = {};
|
||||||
|
}
|
||||||
|
Memory.rooms[roomName].avoid = 1;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if (cleanup) {
|
||||||
|
delete Memory.empire.hostileRooms[roomName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cleanup) {
|
||||||
|
delete Memory.empire.hostileRooms;
|
||||||
|
}
|
||||||
|
console.log(`TRAVELER: room avoidance data patched for ${count} rooms`);
|
||||||
|
}
|
||||||
|
static deserializeState(travelData, destination) {
|
||||||
|
let state = {};
|
||||||
|
if (travelData.state) {
|
||||||
|
state.lastCoord = { x: travelData.state[STATE_PREV_X], y: travelData.state[STATE_PREV_Y] };
|
||||||
|
state.cpu = travelData.state[STATE_CPU];
|
||||||
|
state.stuckCount = travelData.state[STATE_STUCK];
|
||||||
|
state.destination = new RoomPosition(travelData.state[STATE_DEST_X], travelData.state[STATE_DEST_Y], travelData.state[STATE_DEST_ROOMNAME]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
state.cpu = 0;
|
||||||
|
state.destination = destination;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
static serializeState(creep, destination, state, travelData) {
|
||||||
|
travelData.state = [creep.pos.x, creep.pos.y, state.stuckCount, state.cpu, destination.x, destination.y,
|
||||||
|
destination.roomName];
|
||||||
|
}
|
||||||
|
static isStuck(creep, state) {
|
||||||
|
let stuck = false;
|
||||||
|
if (state.lastCoord !== undefined) {
|
||||||
|
if (this.sameCoord(creep.pos, state.lastCoord)) {
|
||||||
|
// didn't move
|
||||||
|
stuck = true;
|
||||||
|
}
|
||||||
|
else if (this.isExit(creep.pos) && this.isExit(state.lastCoord)) {
|
||||||
|
// moved against exit
|
||||||
|
stuck = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stuck;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Traveler.structureMatrixCache = {};
|
||||||
|
Traveler.creepMatrixCache = {};
|
||||||
|
exports.Traveler = Traveler;
|
||||||
|
// this might be higher than you wish, setting it lower is a great way to diagnose creep behavior issues. When creeps
|
||||||
|
// need to repath to often or they aren't finding valid paths, it can sometimes point to problems elsewhere in your code
|
||||||
|
const REPORT_CPU_THRESHOLD = 1000;
|
||||||
|
const DEFAULT_MAXOPS = 20000;
|
||||||
|
const DEFAULT_STUCK_VALUE = 2;
|
||||||
|
const STATE_PREV_X = 0;
|
||||||
|
const STATE_PREV_Y = 1;
|
||||||
|
const STATE_STUCK = 2;
|
||||||
|
const STATE_CPU = 3;
|
||||||
|
const STATE_DEST_X = 4;
|
||||||
|
const STATE_DEST_Y = 5;
|
||||||
|
const STATE_DEST_ROOMNAME = 6;
|
||||||
|
// assigns a function to Creep.prototype: creep.travelTo(destination)
|
||||||
|
Creep.prototype.travelTo = function (destination, options) {
|
||||||
|
return Traveler.travelTo(this, destination, options);
|
||||||
|
};
|
21
assignsources.js
Normal file
21
assignsources.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
let assignMiners = {
|
||||||
|
tick: function(roomname) {
|
||||||
|
let sources = Game.rooms[roomname].find(FIND_SOURCES );
|
||||||
|
for(let source of sources){
|
||||||
|
let allminers = Game.rooms[roomname].find(FIND_MY_CREEPS, {filter: (creep) =>{return ( creep.memory.role=='miner'|| creep.memory.role == ("phase" + Game.rooms[roomname].memory.phase + "worker") )}});
|
||||||
|
//let allstorage = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE)}})
|
||||||
|
let unassignedminers = _.filter(allminers, (creep) => (creep.memory.destsource == undefined ));
|
||||||
|
let sourcecount = sources.length
|
||||||
|
let persrc = allminers.length / sourcecount
|
||||||
|
if(unassignedminers.length > 0){
|
||||||
|
let myminers = _.filter(allminers, (creep) => (creep.memory.destsource != undefined && creep.memory.destsource.id==source.id ));
|
||||||
|
if(myminers.length >= persrc){
|
||||||
|
//break;
|
||||||
|
} else {
|
||||||
|
unassignedminers[0].memory.destsource = source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = assignMiners;
|
@ -1,11 +1,5 @@
|
|||||||
let buildparts = {
|
let buildparts = {
|
||||||
tick: function(roomname,role) {
|
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
|
|
||||||
|
|
||||||
Game.rooms[roomname].memory.tickssincespawn=0
|
Game.rooms[roomname].memory.tickssincespawn=0
|
||||||
let tobuild=[]
|
let tobuild=[]
|
||||||
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
@ -17,10 +11,10 @@ let buildparts = {
|
|||||||
for(let spawn of myspawns){
|
for(let spawn of myspawns){
|
||||||
if(!spawn.spawning){
|
if(!spawn.spawning){
|
||||||
for(let totry of [
|
for(let totry of [
|
||||||
[MOVE,MOVE,MOVE,MOVE,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY],
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],
|
||||||
[MOVE,MOVE,MOVE,WORK,WORK,WORK,CARRY,CARRY,CARRY],
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],
|
||||||
[MOVE,MOVE,WORK,WORK,CARRY,CARRY],
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY],
|
||||||
[MOVE,WORK,CARRY]
|
[MOVE,WORK,CARRY,CARRY]
|
||||||
|
|
||||||
]){
|
]){
|
||||||
let ispossible = spawn.canCreateCreep(totry)
|
let ispossible = spawn.canCreateCreep(totry)
|
||||||
@ -40,9 +34,9 @@ let buildparts = {
|
|||||||
for(let spawn of myspawns){
|
for(let spawn of myspawns){
|
||||||
if(!spawn.spawning){
|
if(!spawn.spawning){
|
||||||
for(let totry of [
|
for(let totry of [
|
||||||
[MOVE,MOVE,MOVE,MOVE,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,CARRY],
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],
|
||||||
[MOVE,MOVE,MOVE,WORK,WORK,WORK,CARRY,CARRY,CARRY],
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],
|
||||||
[MOVE,MOVE,WORK,WORK,CARRY,CARRY],
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY],
|
||||||
[MOVE,WORK,CARRY]
|
[MOVE,WORK,CARRY]
|
||||||
|
|
||||||
]){
|
]){
|
||||||
@ -63,10 +57,12 @@ let buildparts = {
|
|||||||
for(let spawn of myspawns){
|
for(let spawn of myspawns){
|
||||||
if(!spawn.spawning){
|
if(!spawn.spawning){
|
||||||
for(let totry of [
|
for(let totry of [
|
||||||
[CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
|
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE]
|
||||||
[CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE],
|
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
|
||||||
[CARRY,CARRY,CARRY,CARRY,MOVE,MOVE],
|
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
|
||||||
[CARRY,CARRY,MOVE,MOVE],
|
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
|
||||||
|
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
|
||||||
|
[CARRY,CARRY,MOVE],
|
||||||
[CARRY,MOVE]
|
[CARRY,MOVE]
|
||||||
]){
|
]){
|
||||||
let ispossible = spawn.canCreateCreep(totry)
|
let ispossible = spawn.canCreateCreep(totry)
|
||||||
@ -181,10 +177,13 @@ let buildparts = {
|
|||||||
|
|
||||||
for(let spawn of myspawns){
|
for(let spawn of myspawns){
|
||||||
if(!spawn.spawning){
|
if(!spawn.spawning){
|
||||||
for(let totry of [[CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE],
|
for(let totry of [
|
||||||
[CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE],
|
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE]
|
||||||
[CARRY,CARRY,CARRY,CARRY,MOVE,MOVE],
|
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
|
||||||
[CARRY,CARRY,MOVE,MOVE],
|
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
|
||||||
|
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
|
||||||
|
[CARRY,CARRY,MOVE,CARRY,CARRY,MOVE],
|
||||||
|
[CARRY,CARRY,MOVE],
|
||||||
[CARRY,MOVE]
|
[CARRY,MOVE]
|
||||||
]){
|
]){
|
||||||
let ispossible = spawn.canCreateCreep(totry)
|
let ispossible = spawn.canCreateCreep(totry)
|
||||||
@ -219,7 +218,9 @@ let buildparts = {
|
|||||||
for(let spawn of myspawns){
|
for(let spawn of myspawns){
|
||||||
if(!spawn.spawning){
|
if(!spawn.spawning){
|
||||||
for(let totry of [
|
for(let totry of [
|
||||||
[MOVE,MOVE,MOVE,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY],//RCL3
|
[WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE]//RCL3
|
||||||
|
[WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE],
|
||||||
|
[WORK,CARRY,MOVE,WORK,CARRY,MOVE],
|
||||||
[WORK,CARRY,MOVE]
|
[WORK,CARRY,MOVE]
|
||||||
]){
|
]){
|
||||||
let ispossible = spawn.canCreateCreep(totry)
|
let ispossible = spawn.canCreateCreep(totry)
|
||||||
|
29
flag.claim.js
Normal file
29
flag.claim.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
let claim = {
|
||||||
|
run: function() {
|
||||||
|
if(Game.flags.claim.room==undefined){} else {
|
||||||
|
let creepcount = Game.flags.claim.room.find(FIND_MY_CREEPS).length
|
||||||
|
let totallife = _.sum(Game.flags.claim.room.find(FIND_MY_CREEPS), c => c.ticksToLive)
|
||||||
|
let avglife = totallife/creepcount
|
||||||
|
if(creepcount<3||(avglife<700 && creepcount < 4 )){
|
||||||
|
if(Game.flags.claim.memory.requesttime==undefined){
|
||||||
|
Game.flags.claim.memory.requesttime=Game.time
|
||||||
|
Game.notify('Spawning additional new room workers')
|
||||||
|
require('Empire').spawnnrworker()
|
||||||
|
} else {
|
||||||
|
if(Game.time - Game.flags.claim.memory.requesttime > 500){
|
||||||
|
console.log('ticks have passed, trying agin.')
|
||||||
|
Game.flags.claim.memory.requesttime=undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Game.flags.claim.memory.requesttime=undefined
|
||||||
|
}
|
||||||
|
if(!Game.flags.claim.room.controller.my){
|
||||||
|
//console.log('not my controller')
|
||||||
|
}
|
||||||
|
console.log("CreepCount:"+creepcount+"| Lifetime:" + avglife + "|Request Time:" + Game.flags.claim.memory.requesttime )
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = claim;
|
4
flag.debug.js
Normal file
4
flag.debug.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
let debug = {
|
||||||
|
run: function() {}
|
||||||
|
};
|
||||||
|
module.exports = debug;
|
35
flag.protect.js
Normal file
35
flag.protect.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
let protect = {
|
||||||
|
run: function() {
|
||||||
|
console.log(Game.flags.protect.room)
|
||||||
|
let creepcount=0
|
||||||
|
let totallife=0
|
||||||
|
let avglife=0
|
||||||
|
if(Game.flags.protect.room.find(FIND_MY_CREEPS).length ==undefined){
|
||||||
|
|
||||||
|
} else {
|
||||||
|
creepcount = Game.flags.protect.room.find(FIND_MY_CREEPS).length
|
||||||
|
totallife = _.sum(Game.flags.protect.room.find(FIND_MY_CREEPS), c => c.ticksToLive)
|
||||||
|
avglife = totallife/creepcount
|
||||||
|
}
|
||||||
|
//console.log(avglife)
|
||||||
|
if(creepcount<3||(avglife<500 && creepcount < 4 )){
|
||||||
|
if(Game.flags.protect.memory.requesttime==undefined){
|
||||||
|
Game.flags.protect.memory.requesttime=Game.time
|
||||||
|
Game.notify('Spawning additional new room workers')
|
||||||
|
require('Empire').spawnwarrior()
|
||||||
|
} else {
|
||||||
|
if(Game.time - Game.flags.protect.memory.requesttime > 500){
|
||||||
|
console.log('ticks have passed, trying agin.')
|
||||||
|
Game.flags.protect.memory.requesttime=undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Game.flags.protect.memory.requesttime=undefined
|
||||||
|
}
|
||||||
|
if(!Game.flags.protect.room.controller.my){
|
||||||
|
console.log('not my controller')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
module.exports = protect;
|
35
initroom.js
35
initroom.js
@ -1,35 +0,0 @@
|
|||||||
let initroom = {
|
|
||||||
run: function(name) {
|
|
||||||
console.log('Initing room ' + name)
|
|
||||||
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=-1}
|
|
||||||
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 }
|
|
||||||
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 = 1 }
|
|
||||||
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}
|
|
||||||
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}
|
|
||||||
Game.rooms[name].memory.hasbeeninited=1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
module.exports = initroom
|
|
94
main.js
94
main.js
@ -1,76 +1,54 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
global.Empire = require("Empire")
|
global.Empire = require("Empire")
|
||||||
//let runTower = require('tower');
|
let Traveler = require("Traveler")
|
||||||
//let assignMiners=require('sproc')
|
|
||||||
//let processSpawns=require('spawnprocessing')
|
|
||||||
//let minerals=require('mineralprocessing')
|
|
||||||
//let minedproc = require('MinedMineralProc')
|
|
||||||
//let runSources=require('sourceprocessing')
|
|
||||||
global.verbosity=0
|
global.verbosity=0
|
||||||
module.exports.loop = function () {
|
module.exports.loop = function () {
|
||||||
if(global.verbosity>0){
|
for(let name in Game.rooms){
|
||||||
console.log('---START---')
|
let myroom=Game.rooms[name]
|
||||||
|
|
||||||
|
let towers = Game.rooms[name].find(FIND_MY_STRUCTURES, {filter: { structureType: STRUCTURE_TOWER }})
|
||||||
|
//console.log(towers.length)
|
||||||
|
if(towers.length>0){
|
||||||
|
// console.log('running towers in ' + name)
|
||||||
|
require('Run.Tower').tick(name)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(!myroom.memory.hasbeeninited && (myroom.controller!==undefined)){
|
||||||
|
require('RoomInit').run(name)
|
||||||
|
}
|
||||||
|
if(myroom.controller!==undefined){
|
||||||
|
myroom.memory.tickssofar++
|
||||||
|
require('Room.Phase' + myroom.memory.phase).run(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(let name in Memory.creeps) {
|
for(let name in Memory.creeps) {
|
||||||
if(!Game.creeps[name]) {
|
if(!Game.creeps[name]) {
|
||||||
delete Memory.creeps[name];
|
delete Memory.creeps[name];
|
||||||
if(global.verbosity>0){
|
if(global.verbosity>0){
|
||||||
console.log('Clearing non-existing creep memory:', name);
|
console.log('Clearing non-existing creep memory:', name);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
}
|
|
||||||
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
|
|
||||||
let name = myroom.name
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('---'+name+'---')
|
|
||||||
}
|
|
||||||
if(Game.rooms[name].memory.hasbeeninited==undefined){
|
|
||||||
console.log('initing')
|
|
||||||
require('initroom').run(name)
|
|
||||||
}
|
|
||||||
require('tower').tick(name);
|
|
||||||
require('sproc').tick(name) // assignMiners
|
|
||||||
require('sourceprocessing').tick(name)
|
|
||||||
require('MinedMineralProc').tick(name)
|
|
||||||
try{
|
try{
|
||||||
let roomenergy = Game.rooms[name].energyAvailable
|
let creep = Game.creeps[name]
|
||||||
let allstorage = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE)}})
|
if(creep.spawning) return;
|
||||||
let usedstorage = 0
|
if(creep.fatigue>0){
|
||||||
let mycapacity=0
|
creep.say('fatigued')
|
||||||
for(let i of allstorage){
|
creep.room.createConstructionSite(creep.pos.x,creep.pos.y,STRUCTURE_ROAD)
|
||||||
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
|
|
||||||
for(let i=0; i < allcontainers.length;i++){
|
|
||||||
containerusedstorage+=_.sum(allcontainers[i].store)
|
|
||||||
containercapacity+=allcontainers[i].storeCapacity
|
|
||||||
}
|
|
||||||
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}
|
|
||||||
|
|
||||||
if(global.verbosity>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){}
|
|
||||||
require('spawnprocessing').tick(name)
|
|
||||||
require('mineralprocessing').tick(name)
|
|
||||||
}
|
|
||||||
let mycreeps = Game.creeps
|
|
||||||
for(let mycreep in mycreeps){
|
|
||||||
try{
|
|
||||||
let creep = mycreeps[mycreep]
|
|
||||||
require('role.' + creep.memory.role).run(creep)
|
require('role.' + creep.memory.role).run(creep)
|
||||||
} catch (e) {
|
//creep.say("TRYING")
|
||||||
//console.log(e.toString)
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let flags = Game.flags
|
||||||
|
for(let flag in flags){
|
||||||
|
require('flag.' + flag ).run()
|
||||||
|
}
|
||||||
|
for(let name in Memory.rooms) {
|
||||||
|
let myroom = Game.rooms[name]
|
||||||
|
if(!Game.rooms[name]){delete Memory.rooms[name]}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('----END---')
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
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
|
|
||||||
if(global.verbosity>0){
|
|
||||||
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;
|
|
51
proc.market.js
Normal file
51
proc.market.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Module code goes here. Use 'module.exports' to export things:
|
||||||
|
* module.exports.thing = 'a thing';
|
||||||
|
*
|
||||||
|
* You can import it from another modules like this:
|
||||||
|
* var mod = require('proc.market');
|
||||||
|
* mod.thing == 'a thing'; // true
|
||||||
|
*/
|
||||||
|
let gomarket={
|
||||||
|
sellEnergy: function(myroom) {
|
||||||
|
try{
|
||||||
|
let availtosell= Game.rooms[myroom].terminal.store[RESOURCE_ENERGY]
|
||||||
|
|
||||||
|
if(availtosell>5000){
|
||||||
|
console.log(myroom + ":" + availtosell)
|
||||||
|
//console.log(JSON.stringify(Game.market.orders))
|
||||||
|
// if(Game.market.orders.length > 9){
|
||||||
|
let myorders = Game.market.getAllOrders(order=>order.resourceType == RESOURCE_ENERGY && order.type == ORDER_BUY)
|
||||||
|
//console.log(myorders.length)
|
||||||
|
for(let i=0; i<myorders.length; i++){
|
||||||
|
let recheckavailtosell= Game.rooms[myroom].terminal.store[RESOURCE_ENERGY]
|
||||||
|
if(recheckavailtosell<1000){
|
||||||
|
console.log("too little to mess with")
|
||||||
|
} else {
|
||||||
|
//let maxTransferEnergyCost=500
|
||||||
|
//const transferEnergyCost = Game.market.calcTransactionCost(myorders[i].amount, myroom, myorders[i].roomName);
|
||||||
|
//if(transferEnergyCost < maxTransferEnergyCost) {
|
||||||
|
if(recheckavailtosell < myorders[i].amount){
|
||||||
|
amttosell = recheckavailtosell - 1000
|
||||||
|
} else {
|
||||||
|
amttosell=myorders[i].amount
|
||||||
|
}
|
||||||
|
console.log( myroom + " trying to sell " + amttosell + " Energy on order size of " + myorders[i].amount + " with " + recheckavailtosell + " left")
|
||||||
|
let mydeal = Game.market.deal(myorders[i].id, amttosell, myroom);
|
||||||
|
console.log(mydeal)
|
||||||
|
//} else {
|
||||||
|
// console.log("Too expensive")
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// } else {
|
||||||
|
// console.log("Too many orders pending")
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
module.exports = gomarket;
|
@ -1,14 +0,0 @@
|
|||||||
/*
|
|
||||||
Create order for energy and set price, store order id in room
|
|
||||||
if terminal has more than X in it, extend the sell order
|
|
||||||
if energy cost is below X buy it, and resell it at higher price
|
|
||||||
|
|
||||||
Game.market.createOrder(ORDER_SELL,RESOURCE_ENERGY,PRICE,AMOUNT,ROOM)
|
|
||||||
Game.market.createOrder(ORDER_SELL,RESOURCE_ENERGY,.03,10000,'W53N52')
|
|
||||||
Game.market.extendOrder('5953e604f605574924e58ec0',10000)
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
|
|
||||||
};
|
|
169
proc.spawning.js
Normal file
169
proc.spawning.js
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
let buildparts = {
|
||||||
|
spawnminer: function(roomname) {
|
||||||
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
|
Game.rooms[roomname].memory.CreepNum++
|
||||||
|
let CreepName = roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
|
||||||
|
for(let spawn of myspawns){
|
||||||
|
if(!spawn.spawning){
|
||||||
|
let tobuild=[]
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let newcreep = spawn.createCreep(tobuild,CreepName,{role:'miner'})
|
||||||
|
}}
|
||||||
|
|
||||||
|
},
|
||||||
|
spawnwarrior: function(roomname) {
|
||||||
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
|
Game.rooms[roomname].memory.CreepNum++
|
||||||
|
let CreepName = roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
|
||||||
|
for(let spawn of myspawns){
|
||||||
|
if(!spawn.spawning){
|
||||||
|
let tobuild=[]
|
||||||
|
for(let totry of [
|
||||||
|
[MOVE,ATTACK,MOVE,ATTACK,MOVE,ATTACK,MOVE,ATTACK,MOVE,ATTACK],
|
||||||
|
[MOVE,ATTACK,MOVE,ATTACK,MOVE,ATTACK,MOVE,ATTACK],
|
||||||
|
[MOVE,ATTACK,MOVE,ATTACK,MOVE,ATTACK],
|
||||||
|
[MOVE,ATTACK,MOVE,ATTACK],
|
||||||
|
[MOVE,ATTACK]
|
||||||
|
]){
|
||||||
|
let ispossible = spawn.canCreateCreep(totry)
|
||||||
|
if(ispossible==OK){
|
||||||
|
tobuild=totry
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let newcreep = spawn.createCreep(tobuild,CreepName,{role:'warrior'})
|
||||||
|
}}
|
||||||
|
|
||||||
|
},
|
||||||
|
spawnworker: function(roomname) {
|
||||||
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
|
Game.rooms[roomname].memory.CreepNum++
|
||||||
|
let CreepName = roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
|
||||||
|
for(let spawn of myspawns){
|
||||||
|
if(!spawn.spawning){
|
||||||
|
for(let totry of [
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,CARRY,CARRY],//MOVE*6,WORK*5,CARRY*7
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],// all * 5
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,CARRY],//move*5, work*4, carry*5
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],//move*4,work*4,carry*4
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,CARRY],//move*4, work*3, carry*4
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,CARRY], //move*3,work*2, carry*3
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY], //move*2, work*2, carry*2
|
||||||
|
[MOVE,WORK,CARRY,MOVE,CARRY],//move*2, work*1, carry*2
|
||||||
|
[MOVE,WORK,CARRY]
|
||||||
|
]){
|
||||||
|
let ispossible = spawn.canCreateCreep(totry)
|
||||||
|
if(ispossible==OK){
|
||||||
|
tobuild=totry
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let newcreep = spawn.createCreep(tobuild,CreepName,{role:"phase" + Game.rooms[roomname].memory.phase +"worker"})
|
||||||
|
}}
|
||||||
|
|
||||||
|
},
|
||||||
|
spawnmover: function(roomname) {
|
||||||
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
|
Game.rooms[roomname].memory.CreepNum++
|
||||||
|
let CreepName = roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
|
||||||
|
for(let spawn of myspawns){
|
||||||
|
if(!spawn.spawning){
|
||||||
|
for(let totry of [
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY],//MOVE*6,WORK*5,CARRY*7
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY],// all * 5
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY],//move*5, work*4, carry*5
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY],//move*4,work*4,carry*4
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY],//move*4, work*3, carry*4
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY], //move*3,work*2, carry*3
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY], //move*2, work*2, carry*2
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY],//move*2, work*1, carry*2
|
||||||
|
[MOVE,CARRY,CARRY]
|
||||||
|
]){
|
||||||
|
let ispossible = spawn.canCreateCreep(totry)
|
||||||
|
if(ispossible==OK){
|
||||||
|
tobuild=totry
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let newcreep = spawn.createCreep(tobuild,CreepName,{role:"mover"})
|
||||||
|
}}
|
||||||
|
|
||||||
|
},
|
||||||
|
spawnnrworker: function(roomname) {
|
||||||
|
console.log('1')
|
||||||
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
|
Game.rooms[roomname].memory.CreepNum++
|
||||||
|
let CreepName = "nrworker_" + roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
|
||||||
|
for(let spawn of myspawns){
|
||||||
|
if(!spawn.spawning && spawn.room.energyAvailable > 500){
|
||||||
|
for(let totry of [
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,CARRY,CARRY],//MOVE*6,WORK*5,CARRY*7
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],// all * 5
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,CARRY],//move*5, work*4, carry*5
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY],//move*4,work*4,carry*4
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,CARRY],//move*4, work*3, carry*4
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY,MOVE,CARRY], //move*3,work*2, carry*3
|
||||||
|
[MOVE,WORK,CARRY,MOVE,WORK,CARRY], //move*2, work*2, carry*2
|
||||||
|
[MOVE,WORK,CARRY,MOVE,CARRY],//move*2, work*1, carry*2
|
||||||
|
[MOVE,WORK,CARRY]
|
||||||
|
]){
|
||||||
|
let ispossible = spawn.canCreateCreep(totry)
|
||||||
|
if(ispossible==OK){
|
||||||
|
tobuild=totry
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let newcreep = spawn.createCreep(tobuild,CreepName,{role:"nrworker"})
|
||||||
|
}}
|
||||||
|
|
||||||
|
},
|
||||||
|
spawnclaimer: function(roomname) {
|
||||||
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
|
Game.rooms[roomname].memory.CreepNum++
|
||||||
|
let CreepName = "claimer" + roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
|
||||||
|
for(let spawn of myspawns){
|
||||||
|
if(!spawn.spawning){
|
||||||
|
for(let totry of [
|
||||||
|
[CLAIM,MOVE]
|
||||||
|
]){
|
||||||
|
let ispossible = spawn.canCreateCreep(totry)
|
||||||
|
if(ispossible==OK){
|
||||||
|
tobuild=totry
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
console.log("Couldn't find a size that could be made")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(roomname + ' ' + tobuild)
|
||||||
|
let newcreep = spawn.createCreep(tobuild,CreepName,{role:'claimer'})
|
||||||
|
}}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = buildparts;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch(role){
|
||||||
|
case 'builder':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log('no match')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
@ -1,64 +0,0 @@
|
|||||||
let buildparts=require('bodypartbuilder')
|
|
||||||
let roleBuilder = {
|
|
||||||
run: function(creep) {
|
|
||||||
if(creep.memory.originroom === undefined){
|
|
||||||
creep.memory.originroom = creep.room.name
|
|
||||||
}
|
|
||||||
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(creep.memory.building) {
|
|
||||||
|
|
||||||
if(creep.memory.buildsite==undefined|| Game.getObjectById(creep.memory.buildsite.id) == undefined){
|
|
||||||
creep.memory.buildsite = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
|
|
||||||
}
|
|
||||||
let target = Game.getObjectById(creep.memory.buildsite.id)
|
|
||||||
if(target) {
|
|
||||||
|
|
||||||
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('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_TERMINAL || 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}});
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(creep.withdraw(containers[0],RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.say("MTSC");
|
|
||||||
creep.moveTo(containers[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
module.exports = roleBuilder;
|
|
@ -1,20 +1,11 @@
|
|||||||
let roleClaimer = {
|
let roleClaimer = {
|
||||||
run: function(creep) {
|
run: function(creep) {
|
||||||
if(creep.memory.originroom === undefined){
|
if(Game.flags.claim.room==undefined){
|
||||||
creep.memory.originroom = creep.room.name
|
creep.travelTo(Game.flags.claim)
|
||||||
}
|
|
||||||
//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{
|
} else{
|
||||||
creep.say('parking')
|
if(creep.claimController(Game.flags.claim.room.controller) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(creep.room.memory.claimerparkx,creep.room.memory.claimerparky,creep.room)
|
creep.travelTo(Game.flags.claim.room.controller)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
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 && _.sum(creep.carry) == 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');
|
|
||||||
}
|
|
||||||
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 > _.sum(creep.carry)) {
|
|
||||||
creep.moveTo(mysource);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(sources != undefined ) {
|
|
||||||
if(spawntargets) {
|
|
||||||
if(creep.transfer(spawntargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(spawntargets);
|
|
||||||
}
|
|
||||||
} else if (containertargets) {
|
|
||||||
if(creep.transfer(containertargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(containertargets);
|
|
||||||
}
|
|
||||||
} 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
module.exports = roleHauler;
|
|
@ -1,45 +0,0 @@
|
|||||||
let buildparts=require('bodypartbuilder')
|
|
||||||
let roleHauler2 = {
|
|
||||||
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.hauling = false;
|
|
||||||
creep.say('gathering');
|
|
||||||
}
|
|
||||||
if(!creep.memory.hauling && creep.carry.energy == creep.carryCapacity) {
|
|
||||||
creep.memory.hauling = true;
|
|
||||||
creep.say('hauling');
|
|
||||||
}
|
|
||||||
if(creep.memory.hauling==false){
|
|
||||||
if(creep.carryCapacity > creep.carry.energy){
|
|
||||||
let container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
|
||||||
filter: (structure) => {
|
|
||||||
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;
|
|
||||||
}});
|
|
||||||
if(creep.withdraw(container,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.say("MTSC");
|
|
||||||
creep.moveTo(container);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let spawntarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
|
||||||
filter: (structure) => {
|
|
||||||
return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if(spawntarget != undefined) {
|
|
||||||
if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.say('refilling')
|
|
||||||
creep.moveTo(spawntarget);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
creep.say('NTD');
|
|
||||||
creep.moveTo(creep.room.memory.hauler2parkx,creep.room.memory.hauler2parky,creep.room.roomName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
module.exports = roleHauler2;
|
|
@ -1,13 +1,11 @@
|
|||||||
let buildparts=require('bodypartbuilder')
|
|
||||||
let roleMiner = {
|
let roleMiner = {
|
||||||
run: function(creep) {
|
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}
|
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
|
||||||
let mysource=Game.getObjectById(creep.memory.destsource.id)
|
let mysource=Game.getObjectById(creep.memory.destsource.id)
|
||||||
|
{
|
||||||
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) {
|
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(mysource);
|
creep.travelTo(mysource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
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;
|
|
@ -1,33 +0,0 @@
|
|||||||
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;
|
|
43
role.mover.js
Normal file
43
role.mover.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
let mover={
|
||||||
|
run: function(creep) {
|
||||||
|
let ignorecreeps=true
|
||||||
|
if(creep.memory.lastpos==undefined || creep.memory.timeatpos==undefined){
|
||||||
|
creep.memory.lastpos = creep.pos
|
||||||
|
creep.memory.timeatpos = 0
|
||||||
|
}
|
||||||
|
let lastpos = _.create(RoomPosition.prototype, creep.memory.lastpos)
|
||||||
|
if(creep.pos.isEqualTo(lastpos)){
|
||||||
|
creep.memory.timeatpos = creep.memory.timeatpos+1
|
||||||
|
if(creep.memory.timeatpos>2){
|
||||||
|
//console.log(creep.name + " " + creep.memory.timeatpos)
|
||||||
|
ignorecreeps=false
|
||||||
|
} else { }
|
||||||
|
} else { creep.memory.timeatpos=0}
|
||||||
|
let filllevel = _.sum(creep.carry)
|
||||||
|
if(creep.memory.working && filllevel == 0) {
|
||||||
|
creep.memory.working = false;
|
||||||
|
creep.say('Gathering');
|
||||||
|
}
|
||||||
|
if(!creep.memory.working && filllevel == creep.carryCapacity) {
|
||||||
|
creep.memory.working = true;
|
||||||
|
creep.say('working');
|
||||||
|
}
|
||||||
|
if(creep.memory.working){
|
||||||
|
let terminaltarget = creep.room.terminal
|
||||||
|
if(creep.transfer(terminaltarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
|
||||||
|
creep.say('Putting Energy')
|
||||||
|
creep.travelTo(terminaltarget);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(filllevel < creep.carryCapacity){
|
||||||
|
let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER ) && _.sum(s.store) > 5000) ;}});
|
||||||
|
if(creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
|
||||||
|
creep.say('Getting Energy')
|
||||||
|
creep.travelTo(storagetarget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
creep.memory.lastpos=creep.pos
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports = mover;
|
@ -1,60 +0,0 @@
|
|||||||
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.pos.isEqualTo(creep.pos) && creep.room == Game.flags.nrbuild.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;
|
|
@ -1,26 +0,0 @@
|
|||||||
let assignMiners=require('sproc')
|
|
||||||
let rolenrMiner = {
|
|
||||||
run: function(creep) {
|
|
||||||
|
|
||||||
if(Game.flags.nrbuild.pos.isEqualTo(creep.pos) && creep.room == Game.flags.nrbuild.room){
|
|
||||||
if(creep.memory.destsource===undefined){
|
|
||||||
console.log("changing role from nrminer to miner")
|
|
||||||
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;
|
|
10
role.nrworker.js
Normal file
10
role.nrworker.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
let rolenrBuilder = {
|
||||||
|
run: function(creep) {
|
||||||
|
if(Game.flags.claim.pos.isEqualTo(creep.pos) && creep.room == Game.flags.claim.room){
|
||||||
|
creep.memory.role = 'phase' + creep.room.memory.phase + 'worker'
|
||||||
|
} else {
|
||||||
|
creep.travelTo(Game.flags.claim)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = rolenrBuilder;
|
50
role.phase0worker.js
Normal file
50
role.phase0worker.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
//'use strict';
|
||||||
|
let Phase0Worker = {
|
||||||
|
run: function(creep) {
|
||||||
|
let filllevel = _.sum(creep.carry)
|
||||||
|
if(creep.memory.working && filllevel == 0) {
|
||||||
|
creep.memory.working = false;
|
||||||
|
creep.say('Gathering');
|
||||||
|
}
|
||||||
|
if(!creep.memory.working && creep.carry.energy == creep.carryCapacity) {
|
||||||
|
creep.memory.working = true;
|
||||||
|
creep.say('working');
|
||||||
|
}
|
||||||
|
if(creep.memory.working){
|
||||||
|
if(creep.room.controller.ticksToDowngrade<3100){
|
||||||
|
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.say('!MTRC!')
|
||||||
|
creep.travelTo(creep.room.controller);
|
||||||
|
}
|
||||||
|
} else if(creep.room.energyAvailable < creep.room.energyCapacityAvailable ){
|
||||||
|
let spawntarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (structure) => {return (((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity))}});
|
||||||
|
if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.travelTo(spawntarget);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.say('MTRC')
|
||||||
|
creep.travelTo(creep.room.controller);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: {resourceType: RESOURCE_ENERGY}});
|
||||||
|
if(droppedenergy == undefined){
|
||||||
|
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
|
||||||
|
let mysource=Game.getObjectById(creep.memory.destsource.id)
|
||||||
|
//mysource=creep.pos.findClosestByRange( FIND_SOURCES )
|
||||||
|
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
|
||||||
|
creep.travelTo(mysource);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
|
||||||
|
if(global.verbosity>0){
|
||||||
|
creep.say("MTDE");
|
||||||
|
}
|
||||||
|
creep.travelTo(droppedenergy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = Phase0Worker;
|
88
role.phase1worker.js
Normal file
88
role.phase1worker.js
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
//'use strict';
|
||||||
|
let Phase1Worker = {
|
||||||
|
run: function(creep) {
|
||||||
|
let ignorecreeps=true
|
||||||
|
if(creep.memory.lastpos==undefined || creep.memory.timeatpos==undefined){
|
||||||
|
creep.memory.lastpos = creep.pos
|
||||||
|
creep.memory.timeatpos = 0
|
||||||
|
}
|
||||||
|
let lastpos = _.create(RoomPosition.prototype, creep.memory.lastpos)
|
||||||
|
if(creep.pos.isEqualTo(lastpos)){
|
||||||
|
|
||||||
|
creep.memory.timeatpos = creep.memory.timeatpos+1
|
||||||
|
if(creep.memory.timeatpos>2){
|
||||||
|
//console.log(creep.name + " " + creep.memory.timeatpos)
|
||||||
|
ignorecreeps=false
|
||||||
|
} else { }
|
||||||
|
} else { creep.memory.timeatpos=0}
|
||||||
|
|
||||||
|
let road = creep.pos.lookFor(LOOK_STRUCTURES);
|
||||||
|
let filllevel = _.sum(creep.carry)
|
||||||
|
if(creep.memory.working && filllevel == 0) {
|
||||||
|
creep.memory.working = false;
|
||||||
|
creep.say('Gathering');
|
||||||
|
}
|
||||||
|
if(!creep.memory.working && creep.carry.energy == creep.carryCapacity) {
|
||||||
|
creep.memory.working = true;
|
||||||
|
creep.say('working');
|
||||||
|
}
|
||||||
|
if(creep.memory.working){
|
||||||
|
let look=creep.pos.lookFor(LOOK_STRUCTURES)
|
||||||
|
let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_TERMINAL ) && _.sum(s.store) < s.storeCapacity) ;}});
|
||||||
|
if(creep.room.memory.NeedsRecharge==1){
|
||||||
|
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.say('!MTRC!')
|
||||||
|
creep.say(creep.room.controller.ticksToDowngrade)
|
||||||
|
creep.moveTo(creep.room.controller)
|
||||||
|
}
|
||||||
|
} else if(creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER].includes(s.structureType)) && s.energy < s.energyCapacity))}})){
|
||||||
|
let spawntarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return (((s.structureType == STRUCTURE_EXTENSION || s.structureType == STRUCTURE_SPAWN || s.structureType == STRUCTURE_TOWER) && s.energy < s.energyCapacity))}});
|
||||||
|
if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.moveTo(spawntarget,{ignoreCreeps:ignorecreeps})
|
||||||
|
}
|
||||||
|
} else if(creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_RAMPART].includes(s.structureType)) && s.hits < 20000))}})){
|
||||||
|
let ramparttarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return (((s.structureType == STRUCTURE_RAMPART) && s.hits < s.hitsMax))}});
|
||||||
|
if(creep.repair(ramparttarget) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.moveTo(ramparttarget,{ignoreCreeps:ignorecreeps})
|
||||||
|
}
|
||||||
|
} else if(creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES)){
|
||||||
|
target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES)
|
||||||
|
if(creep.build(target) == ERR_NOT_IN_RANGE) {
|
||||||
|
if (road.length > 0) {creep.repair(road);}
|
||||||
|
creep.moveTo(target,{ignoreCreeps:ignorecreeps})
|
||||||
|
}
|
||||||
|
} else if(storagetargets){
|
||||||
|
if(creep.transfer(storagetargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
|
if (road.length > 0) {creep.repair(road);}
|
||||||
|
creep.moveTo(storagetargets,{ignoreCreeps:ignorecreeps})
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.say('MTRC')
|
||||||
|
if (road.length > 0) {creep.repair(road);}
|
||||||
|
creep.moveTo(creep.room.controller,{ignoreCreeps:ignorecreeps})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>200)}});
|
||||||
|
if(droppedenergy == undefined){
|
||||||
|
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,{ignoreCreeps:ignorecreeps})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
|
||||||
|
if(global.verbosity>0){
|
||||||
|
creep.say("MTDE");
|
||||||
|
}
|
||||||
|
|
||||||
|
creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps})
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
creep.memory.lastpos=creep.pos
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = Phase1Worker;
|
@ -1,39 +0,0 @@
|
|||||||
let buildparts=require('bodypartbuilder')
|
|
||||||
let roleTowerrecharger = {
|
|
||||||
run: function(creep) {
|
|
||||||
if(creep.memory.originroom === undefined){
|
|
||||||
creep.memory.originroom = creep.room.name
|
|
||||||
}
|
|
||||||
if(creep.memory.recharging && creep.carry.energy == 0) {
|
|
||||||
creep.memory.recharging = false;
|
|
||||||
creep.say('refilling');
|
|
||||||
}
|
|
||||||
if(!creep.memory.recharging && creep.carry.energy == creep.carryCapacity) {
|
|
||||||
creep.memory.recharging = true;
|
|
||||||
creep.say('building');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!creep.memory.recharging) {
|
|
||||||
let container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
|
||||||
filter: (structure) => {
|
|
||||||
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 1000) ;
|
|
||||||
}});
|
|
||||||
if(creep.withdraw(container,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.say("MTSC");
|
|
||||||
creep.moveTo(container);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let spawntarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
|
||||||
filter: (structure) => {
|
|
||||||
return (structure.structureType == STRUCTURE_TOWER && structure.energy < structure.energyCapacity)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if(spawntarget != undefined) {
|
|
||||||
if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(spawntarget);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
module.exports = roleTowerrecharger;
|
|
@ -1,54 +0,0 @@
|
|||||||
let buildparts=require('bodypartbuilder')
|
|
||||||
let roleRepairbot = {
|
|
||||||
run: function(creep) {
|
|
||||||
if(creep.memory.originroom === undefined){
|
|
||||||
creep.memory.originroom = creep.room.name
|
|
||||||
}
|
|
||||||
if(creep.memory.repairing == undefined){creep.memory.repairing=true}
|
|
||||||
if(creep.memory.repairing && creep.carry.energy == 0) {
|
|
||||||
creep.memory.repairing = false;
|
|
||||||
creep.say('gathering');
|
|
||||||
}
|
|
||||||
if(!creep.memory.repairing && creep.carry.energy == creep.carryCapacity) {
|
|
||||||
creep.memory.repairing = true;
|
|
||||||
creep.say('repairing');
|
|
||||||
}
|
|
||||||
if(creep.memory.repairing==false){
|
|
||||||
let container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
|
||||||
filter: (structure) => {
|
|
||||||
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;
|
|
||||||
}});
|
|
||||||
if(creep.withdraw(container,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.say("MTSC");
|
|
||||||
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.structureType==STRUCTURE_RAMPART) && structure.hits < structure.hitsMax) ;
|
|
||||||
}});
|
|
||||||
importantstructures = _.sortBy(importantstructures, (s)=>s.hits / s.hitsMax)
|
|
||||||
if(importantstructures.length > 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){
|
|
||||||
if(creep.repair(damagedstructures[0]) == ERR_NOT_IN_RANGE){
|
|
||||||
creep.moveTo(damagedstructures[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = roleRepairbot;
|
|
@ -1,49 +0,0 @@
|
|||||||
let buildparts=require('bodypartbuilder')
|
|
||||||
let roleUpgrader = {
|
|
||||||
run: function(creep) {
|
|
||||||
if(creep.memory.originroom === undefined){
|
|
||||||
creep.memory.originroom = creep.room.name
|
|
||||||
}
|
|
||||||
if(creep.memory.upgrading==undefined){creep.memory.upgrading=true}
|
|
||||||
if(creep.memory.upgrading && creep.carry.energy == 0) {
|
|
||||||
creep.memory.upgrading = false;
|
|
||||||
creep.say('harvesting');
|
|
||||||
}
|
|
||||||
if(!creep.memory.upgrading && creep.carry.energy == creep.carryCapacity) {
|
|
||||||
creep.memory.upgrading = true;
|
|
||||||
creep.say('upgrading');
|
|
||||||
}
|
|
||||||
if(creep.memory.upgrading) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
} else { creep.moveTo(creep.room.memory.upgraderparkx,creep.room.memory.upgraderparky,creep.room.roomName) }
|
|
||||||
} else {
|
|
||||||
|
|
||||||
let container = creep.pos.findClosestByRange(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 ) ;
|
|
||||||
}});
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
module.exports = roleUpgrader;
|
|
@ -1,25 +1,28 @@
|
|||||||
let roleWarrior = {
|
let rolewarrior = {
|
||||||
run: function(creep) {
|
run: function(creep) {
|
||||||
var hostile = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
|
var hostile = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
|
||||||
var hostilebuilding = creep.pos.findClosestByRange(FIND_HOSTILE_STRUCTURES||FIND_HOSTILE_SPAWNS );
|
var hostilebuilding = creep.pos.findClosestByRange(FIND_HOSTILE_SPAWNS );
|
||||||
if(hostile!=undefined) {
|
if(hostile!=undefined) {
|
||||||
creep.say('Sorry')
|
creep.say('Sorry')
|
||||||
creep.moveTo(hostile);
|
creep.travelTo(hostile,{ignoreCreeps:true});
|
||||||
creep.attack(hostile);
|
creep.attack(hostile);
|
||||||
|
|
||||||
} else if(hostilebuilding!=undefined){
|
} else if(hostilebuilding!=undefined){
|
||||||
creep.say('Sorry')
|
creep.say('Sorry')
|
||||||
creep.moveTo(hostilebuilding);
|
creep.travelTo(hostilebuilding,{ignoreCreeps:true});
|
||||||
creep.attack(hostilebuilding);
|
creep.attack(hostilebuilding);
|
||||||
|
|
||||||
}else if(Game.flags.Attack) {
|
}else if(Game.flags.protect,{ignoreCreeps:true}) {
|
||||||
creep.say('ATK')
|
creep.say('ATK')
|
||||||
creep.moveTo(Game.flags.Attack)
|
creep.travelTo(Game.flags.protect,{ignoreCreeps:true})
|
||||||
|
|
||||||
} else{
|
} else{
|
||||||
creep.say('parking')
|
creep.say('parking')
|
||||||
creep.moveTo(creep.room.memory.warriorparkx,creep.room.memory.warriorparky,creep.room.roomName)
|
creep.travelTo(creep.room.memory.warriorparkx,creep.room.memory.warriorparky,creep.room.roomName,{ignoreCreeps:true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
module.exports = roleWarrior;
|
module.exports = rolewarrior;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
let runSources = {
|
|
||||||
tick: function(roomname) {
|
|
||||||
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' );
|
|
||||||
let unassignedhaulers = _.filter(allhaulers, (creep) => (creep.memory.destsource == undefined && creep.memory.role=='hauler'));
|
|
||||||
let assignedhaulers = _.filter(allhaulers, (creep) => (creep.memory.destsource != undefined && creep.memory.role=='hauler'));
|
|
||||||
let myhaulers = _.filter(allhaulers, (creep) => (creep.memory.destsource != undefined && creep.memory.destsource.id==source.id && creep.memory.role=='hauler'));
|
|
||||||
let sourcecount = sources.length
|
|
||||||
let persrc = allhaulers.length / sourcecount
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('My Assigned Haulers: ' +myhaulers.length + ' Max per source:' + persrc + ' Total Haulers:' + allhaulers.length + ' Total Sources:' + sourcecount + ' Unassigned Haulers:' + unassignedhaulers.length)
|
|
||||||
}
|
|
||||||
if(unassignedhaulers.length > 0){
|
|
||||||
if(myhaulers.length < persrc){
|
|
||||||
unassignedhaulers[0].memory.destsource = source
|
|
||||||
} else {}
|
|
||||||
}
|
|
||||||
} catch(e){}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
module.exports = runSources;
|
|
@ -1,131 +0,0 @@
|
|||||||
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
|
|
||||||
if(global.verbosity>0){
|
|
||||||
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){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('WOULD SPAWN AT '+ spawn.name)
|
|
||||||
}
|
|
||||||
//spawn.memory.spawnqueued=true
|
|
||||||
|
|
||||||
if(Game.rooms[roomname].memory.maxminers > allminers.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn miner')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'miner')
|
|
||||||
spawn.memory.spawnqueued=true
|
|
||||||
} else if(Game.rooms[roomname].memory.maxminer2s > allminer2s.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn miner2s')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'miner2')
|
|
||||||
spawn.memory.spawnqueued=true
|
|
||||||
} else if(Game.rooms[roomname].memory.maxhaulers > allhaulers.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn hauler')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'hauler')
|
|
||||||
spawn.memory.spawnqueued=true
|
|
||||||
}else if(Game.rooms[roomname].memory.maxhauler3s > allhauler3s.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn hauler3')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'hauler3')
|
|
||||||
spawn.memory.spawnqueued=true
|
|
||||||
}else if(Game.rooms[roomname].memory.maxupgraders > allupgraders.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn upgrader')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'upgrader')
|
|
||||||
spawn.memory.spawnqueued=true
|
|
||||||
} else if(Game.rooms[roomname].memory.maxhauler2s > allhauler2s.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn hauler2')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'hauler2')
|
|
||||||
spawn.memory.spawnqueued=true
|
|
||||||
} else if(Game.rooms[roomname].memory.maxtowerrechargers > alltowerrechargers.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn towerrecharger')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'towerrecharger')
|
|
||||||
spawn.memory.spawnqueued=true
|
|
||||||
} else if(Game.rooms[roomname].memory.maxrepairbots > allrepairbots.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn repairbot')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'repairbot')
|
|
||||||
spawn.memory.spawnqueued=true
|
|
||||||
}else if(Game.rooms[roomname].memory.maxbuilders > allbuilders.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn builder')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'builder')
|
|
||||||
spawn.memory.spawnqueued=true
|
|
||||||
} else if (Game.rooms[roomname].memory.maxwarriors > allwarriors.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn warrior')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'warrior')
|
|
||||||
} else if(Game.rooms[roomname].memory.maxclaimers > allclaimers.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn claimer')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'claimer')
|
|
||||||
} else if(Game.rooms[roomname].memory.maxnrbuilders > allnrbuilders.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn nrbuilder')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'nrbuilder')
|
|
||||||
} else if(Game.rooms[roomname].memory.maxnrminers > allnrminers.length){
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('spawn nrminer')
|
|
||||||
}
|
|
||||||
buildparts.tick(roomname,'nrminer')
|
|
||||||
} else {}
|
|
||||||
|
|
||||||
} else if (!spawn.spawning && spawn.memory.spawnqueued) {
|
|
||||||
spawn.memory.spawnqueued=false
|
|
||||||
if(global.verbosity>0){
|
|
||||||
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;
|
|
24
sproc.js
24
sproc.js
@ -1,24 +0,0 @@
|
|||||||
let assignMiners = {
|
|
||||||
tick: function(roomname) {
|
|
||||||
let sources = Game.rooms[roomname].find(FIND_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'));
|
|
||||||
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
|
|
||||||
if(global.verbosity>0){
|
|
||||||
console.log('My Assigned Miners: ' +myminers.length + ' Max per source:' + persrc + ' Total Miners:' + 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 = assignMiners;
|
|
Loading…
Reference in New Issue
Block a user