mirror of
https://github.com/paradizelost/screeps.git
synced 2024-11-25 02:14:44 -06:00
rewrite
This commit is contained in:
parent
2ab5943444
commit
2f45d9b69e
55
NOTES.js
55
NOTES.js
@ -4,4 +4,57 @@ serializePos: function(pos) {
|
|||||||
deserializePos: function(str) {
|
deserializePos: function(str) {
|
||||||
var ar = str.split('_');
|
var ar = str.split('_');
|
||||||
return new RoomPosition(ar[0], ar[1], ar[2]);
|
return new RoomPosition(ar[0], ar[1], ar[2]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Structure.prototype.getResourceCapacity = function(resourceType) {
|
||||||
|
switch (this.structureType) {
|
||||||
|
case STRUCTURE_CONTAINER:
|
||||||
|
case STRUCTURE_STORAGE:
|
||||||
|
case STRUCTURE_TERMINAL:
|
||||||
|
return this.storeCapacity;
|
||||||
|
case STRUCTURE_SPAWN:
|
||||||
|
case STRUCTURE_EXTENSION:
|
||||||
|
case STRUCTURE_LINK:
|
||||||
|
case STRUCTURE_TOWER:
|
||||||
|
if (RESOURCE_ENERGY == resourceType) {
|
||||||
|
return(this.energyCapacity);
|
||||||
|
} else {
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
case STRUCTURE_LAB:
|
||||||
|
if (RESOURCE_ENERGY == resourceType) {
|
||||||
|
return(this.energyCapacity);
|
||||||
|
} else {
|
||||||
|
return(this.mineralCapacity);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Structure.prototype.getResource = function(resourceType) {
|
||||||
|
switch (this.structureType) {
|
||||||
|
case STRUCTURE_CONTAINER:
|
||||||
|
case STRUCTURE_STORAGE:
|
||||||
|
case STRUCTURE_TERMINAL:
|
||||||
|
return this.store[resourceType];
|
||||||
|
case STRUCTURE_SPAWN:
|
||||||
|
case STRUCTURE_EXTENSION:
|
||||||
|
case STRUCTURE_LINK:
|
||||||
|
case STRUCTURE_TOWER:
|
||||||
|
if (RESOURCE_ENERGY == resourceType) {
|
||||||
|
return(this.energy);
|
||||||
|
} else {
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
case STRUCTURE_LAB:
|
||||||
|
if (RESOURCE_ENERGY == resourceType) {
|
||||||
|
return(this.energy);
|
||||||
|
} else {
|
||||||
|
return(this.mineralAmount);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
}
|
40
Spawnloop.js
40
Spawnloop.js
@ -1,40 +0,0 @@
|
|||||||
Object.defineProperty(Room.prototype, "spawns", {
|
|
||||||
/**
|
|
||||||
* Holds array of spawns. If you do not own the room, returns ERR_NOT_OWNER
|
|
||||||
*
|
|
||||||
* @returns {number|ERR_NOT_OWNER|object}
|
|
||||||
*/
|
|
||||||
configurable: true,
|
|
||||||
get: function () {
|
|
||||||
if (!this.controller || !this.controller.my) {
|
|
||||||
return ERR_NOT_OWNER;
|
|
||||||
}
|
|
||||||
let spawnObjects = [];
|
|
||||||
if (!this.memory.spawns) {
|
|
||||||
let spawns = [];
|
|
||||||
spawnObjects = this.find(FIND_MY_STRUCTURES, {
|
|
||||||
filter: {
|
|
||||||
structureType: STRUCTURE_SPAWN
|
|
||||||
}
|
|
||||||
});
|
|
||||||
spawnObjects.forEach(
|
|
||||||
function (spawn) {
|
|
||||||
spawns.push(spawn.id)
|
|
||||||
});
|
|
||||||
this.memory.spawns = spawns;
|
|
||||||
}
|
|
||||||
if (spawnObjects.length == 0 && this.memory.spawns.length > 0) {
|
|
||||||
for (let key in this.memory.spawns) {
|
|
||||||
let spawnId = this.memory.spawns[key];
|
|
||||||
let spawn = Game.getObjectById(spawnId);
|
|
||||||
if (!spawn) {
|
|
||||||
this.log('No spawn found for ID ' + spawnId + ' despite being in cache, cleaning.', WARNING, true);
|
|
||||||
delete this.memory.spawns;
|
|
||||||
} else {
|
|
||||||
spawnObjects.push(spawn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return spawnObjects;
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,4 +1,36 @@
|
|||||||
bodyParts.forEach(function (bodyPart) {
|
let buildparts = {
|
||||||
var part = typeof bodyPart === 'string' ? bodyPart : bodyPart.type;
|
tick: function(roomname,role) {
|
||||||
cost += BODYPART_COST[part];
|
console.log(roomname + ":" + role)
|
||||||
});
|
let energyready = Game.rooms[roomname].energyAvailable
|
||||||
|
let energymax = Game.rooms[roomname].energyCapacityAvailable
|
||||||
|
if(energyready==energymax){
|
||||||
|
let tobuild=[]
|
||||||
|
switch(role){
|
||||||
|
case 'builder':
|
||||||
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
|
for(let spawn of myspawns){
|
||||||
|
for(let totry of [
|
||||||
|
[MOVE,MOVE,MOVE,MOVE,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,WORK],
|
||||||
|
[MOVE,MOVE,MOVE,MOVE,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,CARRY,MOVE],
|
||||||
|
[MOVE,MOVE,CARRY]
|
||||||
|
]){
|
||||||
|
let ispossible = spawn.canCreateCreep(totry)
|
||||||
|
if(ispossible==OK){
|
||||||
|
tobuild=totry
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(tobuild)
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'hauler':
|
||||||
|
console.log('2')
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
console.log('3')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = buildparts;
|
@ -1,69 +0,0 @@
|
|||||||
import {Util} from "../Util";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Serializable
|
|
||||||
*/
|
|
||||||
export class EnergyInformation {
|
|
||||||
|
|
||||||
energy: number;
|
|
||||||
energyCapacity: number;
|
|
||||||
availableForDistribution: boolean;
|
|
||||||
|
|
||||||
static isFull(energyInformation: EnergyInformation): boolean {
|
|
||||||
return energyInformation.energy === energyInformation.energyCapacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
static isEmpty(energyInformation: EnergyInformation): boolean {
|
|
||||||
return energyInformation.energy === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param structure
|
|
||||||
* @returns {EnergyInformation} if structure can hold energy
|
|
||||||
*/
|
|
||||||
static ofStructure(structure: Structure): EnergyInformation|undefined {
|
|
||||||
var storedEnergy = 0;
|
|
||||||
var energyCapacity = 0;
|
|
||||||
var energyAvailableForDistribution: boolean;
|
|
||||||
|
|
||||||
switch (structure.structureType) {
|
|
||||||
case STRUCTURE_EXTENSION:
|
|
||||||
energyAvailableForDistribution = false;
|
|
||||||
storedEnergy = (<Extension> structure).energy;
|
|
||||||
energyCapacity = (<Extension> structure).energyCapacity;
|
|
||||||
break;
|
|
||||||
case STRUCTURE_CONTAINER:
|
|
||||||
case STRUCTURE_STORAGE:
|
|
||||||
// both, for StructureStorage and StructureContainer use *StructureStorage*
|
|
||||||
energyAvailableForDistribution = true;
|
|
||||||
var store = (<StructureStorage> structure).store;
|
|
||||||
storedEnergy = <number> store[RESOURCE_ENERGY] || 0;
|
|
||||||
var allStorageUnits: number = _.sum(store);
|
|
||||||
energyCapacity = (<StructureStorage> structure).storeCapacity - (allStorageUnits - storedEnergy);
|
|
||||||
break;
|
|
||||||
case STRUCTURE_LINK:
|
|
||||||
energyAvailableForDistribution = true;
|
|
||||||
storedEnergy = (<Link> structure).energy;
|
|
||||||
energyCapacity = (<Extension> structure).energyCapacity;
|
|
||||||
break;
|
|
||||||
case STRUCTURE_SPAWN:
|
|
||||||
energyAvailableForDistribution = false;
|
|
||||||
storedEnergy = (<Spawn> structure).energy;
|
|
||||||
energyCapacity = (<Spawn> structure).energyCapacity;
|
|
||||||
break;
|
|
||||||
case STRUCTURE_TOWER:
|
|
||||||
energyAvailableForDistribution = false;
|
|
||||||
storedEnergy = (<Tower> structure).energy;
|
|
||||||
energyCapacity = (<Tower> structure).energyCapacity;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
var energyInformation = new EnergyInformation();
|
|
||||||
energyInformation.energy = storedEnergy;
|
|
||||||
energyInformation.energyCapacity = energyCapacity;
|
|
||||||
energyInformation.availableForDistribution = energyAvailableForDistribution;
|
|
||||||
return energyInformation;
|
|
||||||
}
|
|
||||||
}
|
|
90
main.js
90
main.js
@ -1,47 +1,73 @@
|
|||||||
var roleBuilder=require('role.builder');
|
'use strict';
|
||||||
var roleMiner=require('role.miner');
|
let roleBuilder=require('role.builder');
|
||||||
var roleMiner2=require('role.miner2');
|
let roleMiner=require('role.miner');
|
||||||
var roleHauler=require('role.hauler')
|
let roleHauler=require('role.hauler')
|
||||||
var roleHauler2=require('role.hauler2')
|
let roleHauler2=require('role.hauler2')
|
||||||
var roleUpgrader=require('role.upgrader')
|
let roleUpgrader=require('role.upgrader')
|
||||||
var roleTowerrecharger=require('role.recharger')
|
let roleTowerrecharger=require('role.recharger')
|
||||||
var runSources=require('sourceprocessing')
|
let runSources=require('sourceprocessing')
|
||||||
var roleRepairbot=require('role.repairbot')
|
let roleRepairbot=require('role.repairbot')
|
||||||
var runTower = require('tower');
|
let runTower = require('tower');
|
||||||
|
let assignMiners=require('sproc')
|
||||||
|
let buildparts=require('bodypartbuilder')
|
||||||
module.exports.loop = function () {
|
module.exports.loop = function () {
|
||||||
|
console.log('---START---')
|
||||||
for(var 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];
|
||||||
console.log('Clearing non-existing creep memory:', name);
|
console.log('Clearing non-existing creep memory:', name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(var name in Game.rooms) {
|
|
||||||
|
for(let myroom of _.filter(Game.rooms, 'controller.my')) {
|
||||||
|
let name = myroom.name
|
||||||
|
console.log(name)
|
||||||
|
|
||||||
|
buildparts.tick(name,'builder')
|
||||||
|
console.log('---'+name+'---')
|
||||||
runTower.tick(name);
|
runTower.tick(name);
|
||||||
var roomenergy = Game.rooms[name].energyAvailable
|
assignMiners.tick(name)
|
||||||
var allstorage = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE)}})
|
runSources.tick(name)
|
||||||
var allcontainers = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_CONTAINER)}})
|
|
||||||
var usedstorage = 0
|
try{
|
||||||
var mycapacity=0
|
let roomenergy = Game.rooms[name].energyAvailable
|
||||||
for(var i=0; i < allstorage.length;i++){
|
let allstorage = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE)}})
|
||||||
|
|
||||||
|
|
||||||
|
let usedstorage = 0
|
||||||
|
let mycapacity=0
|
||||||
|
for(let i=0; i < allstorage.length;i++){
|
||||||
usedstorage+=_.sum(allstorage[i].store)
|
usedstorage+=_.sum(allstorage[i].store)
|
||||||
mycapacity+=allstorage[i].storeCapacity
|
mycapacity+=allstorage[i].storeCapacity
|
||||||
}
|
}
|
||||||
Game.rooms[name].memory.storagepercent = usedstorage/mycapacity
|
|
||||||
|
|
||||||
var containerusedstorage = 0
|
|
||||||
var containercapacity=0
|
let allcontainers = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_CONTAINER)}})
|
||||||
for(var i=0; i < allcontainers.length;i++){
|
let containerusedstorage = 0
|
||||||
|
let containercapacity=0
|
||||||
|
for(let i=0; i < allcontainers.length;i++){
|
||||||
containerusedstorage+=_.sum(allcontainers[i].store)
|
containerusedstorage+=_.sum(allcontainers[i].store)
|
||||||
containercapacity+=allcontainers[i].storeCapacity
|
containercapacity+=allcontainers[i].storeCapacity
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
var allstoragecontainers = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_STORAGE)}})
|
||||||
|
var storagecontainerusedstorage = 0
|
||||||
|
var storagecontainercapacity=0
|
||||||
|
for(var i=0; i < allcontainers.length;i++){
|
||||||
|
storagecontainerusedstorage+=_.sum(allstoragecontainers[i].store)
|
||||||
|
storagecontainercapacity+=allstoragecontainers[i].storeCapacity
|
||||||
|
}
|
||||||
|
if()
|
||||||
|
console.log(storagecontainerusedstorage + ':' + storagecontainercapacity)
|
||||||
|
**/
|
||||||
|
Game.rooms[name].memory.storagepercent = usedstorage/mycapacity
|
||||||
Game.rooms[name].memory.containerstoragepercent = containerusedstorage/containercapacity
|
Game.rooms[name].memory.containerstoragepercent = containerusedstorage/containercapacity
|
||||||
console.log('-------')
|
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')
|
console.log('Room "'+name+'" has '+roomenergy+' energy : Using ' + usedstorage + ' of ' + mycapacity + ', ' + Game.rooms[name].memory.storagepercent * 100 + '% Storage, ' + containerusedstorage + ' of ' + containercapacity + ':' + Game.rooms[name].memory.containerstoragepercent *100+ '% in containers')
|
||||||
|
} catch(e){}
|
||||||
if(Game.rooms[name].memory.maxbuilders == undefined){ Game.rooms[name].memory.maxbuilders =0 }
|
if(Game.rooms[name].memory.maxbuilders == undefined){ Game.rooms[name].memory.maxbuilders =0 }
|
||||||
if(Game.rooms[name].memory.maxupgraders == undefined){ Game.rooms[name].memory.maxupgraders = 0 }
|
if(Game.rooms[name].memory.maxupgraders == undefined){ Game.rooms[name].memory.maxupgraders = 0 }
|
||||||
if(Game.rooms[name].memory.maxminers == undefined){ Game.rooms[name].memory.maxminers = 0 }
|
if(Game.rooms[name].memory.maxminers == undefined){ Game.rooms[name].memory.maxminers = 0 }
|
||||||
if(Game.rooms[name].memory.maxminer2s == undefined){ Game.rooms[name].memory.maxminer2s = 0 }
|
|
||||||
if(Game.rooms[name].memory.maxhaulers == undefined){ Game.rooms[name].memory.maxhaulers = 0 }
|
if(Game.rooms[name].memory.maxhaulers == undefined){ Game.rooms[name].memory.maxhaulers = 0 }
|
||||||
if(Game.rooms[name].memory.maxhauler2s == undefined){ Game.rooms[name].memory.maxhauler2s = 0 }
|
if(Game.rooms[name].memory.maxhauler2s == undefined){ Game.rooms[name].memory.maxhauler2s = 0 }
|
||||||
if(Game.rooms[name].memory.maxwarriors == undefined){ Game.rooms[name].memory.maxwarriors = 0 }
|
if(Game.rooms[name].memory.maxwarriors == undefined){ Game.rooms[name].memory.maxwarriors = 0 }
|
||||||
@ -56,25 +82,21 @@ module.exports.loop = function () {
|
|||||||
if(Game.rooms[name].memory.hauler2parky==undefined){Game.rooms[name].memory.hauler2parky=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.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.upgraderparky==undefined){Game.rooms[name].memory.upgraderparky=24}
|
||||||
runSources.tick(name)
|
|
||||||
roleBuilder.spawn(name)
|
roleBuilder.spawn(name)
|
||||||
roleMiner.spawn(name)
|
roleMiner.spawn(name)
|
||||||
roleHauler.spawn(name)
|
roleHauler.spawn(name)
|
||||||
roleHauler2.spawn(name)
|
roleHauler2.spawn(name)
|
||||||
roleUpgrader.spawn(name)
|
roleUpgrader.spawn(name)
|
||||||
roleMiner2.spawn(name)
|
|
||||||
roleTowerrecharger.spawn(name)
|
roleTowerrecharger.spawn(name)
|
||||||
roleRepairbot.spawn(name)
|
roleRepairbot.spawn(name)
|
||||||
var mycreeps = Game.rooms[name].find(FIND_MY_CREEPS)
|
let mycreeps = Game.rooms[name].find(FIND_MY_CREEPS)
|
||||||
for(var mycreep in mycreeps){
|
for(let mycreep in mycreeps){
|
||||||
try{
|
try{
|
||||||
var creep = mycreeps[mycreep]
|
let creep = mycreeps[mycreep]
|
||||||
if(creep.memory.role == 'miner'){
|
if(creep.memory.role == 'miner'){
|
||||||
roleMiner.run(creep)
|
roleMiner.run(creep)
|
||||||
}
|
}
|
||||||
if(creep.memory.role == 'miner2'){
|
|
||||||
roleMiner2.run(creep)
|
|
||||||
}
|
|
||||||
if(creep.memory.role == 'hauler'){
|
if(creep.memory.role == 'hauler'){
|
||||||
roleHauler.run(creep)
|
roleHauler.run(creep)
|
||||||
}
|
}
|
||||||
@ -96,7 +118,9 @@ module.exports.loop = function () {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
//console.log(e.toString)
|
//console.log(e.toString)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
console.log('-------')
|
console.log('----END---')
|
||||||
}
|
}
|
@ -1,5 +1,8 @@
|
|||||||
var roleBuilder = {
|
let roleBuilder = {
|
||||||
run: function(creep) {
|
run: function(creep) {
|
||||||
|
if(creep.memory.originroom === undefined){
|
||||||
|
creep.memory.originroom = creep.room.name
|
||||||
|
}
|
||||||
if(creep.memory.building && creep.carry.energy == 0) {
|
if(creep.memory.building && creep.carry.energy == 0) {
|
||||||
creep.memory.building = false;
|
creep.memory.building = false;
|
||||||
creep.say('Gathering');
|
creep.say('Gathering');
|
||||||
@ -10,32 +13,34 @@ var roleBuilder = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(creep.memory.building) {
|
if(creep.memory.building) {
|
||||||
var target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
|
if(creep.memory.buildsite==undefined|| Game.getObjectById(creep.memory.buildsite.id) == undefined){
|
||||||
|
creep.memory.buildsite = Game.rooms[creep.memory.originroom].find(FIND_CONSTRUCTION_SITES)[0];
|
||||||
|
}
|
||||||
|
let target = Game.getObjectById(creep.memory.buildsite.id)
|
||||||
//Check next room as well
|
//Check next room as well
|
||||||
|
if(target) {
|
||||||
if(target != undefined) {
|
if(Game.rooms[creep.memory.originroom].memory.containerstoragepercent > -.5 ){
|
||||||
|
if(creep.build(target) == ERR_NOT_IN_RANGE) {
|
||||||
if(creep.build(target) == ERR_NOT_IN_RANGE) {
|
creep.moveTo(target);
|
||||||
creep.moveTo(target);
|
if(creep.fatigue<1){
|
||||||
if(creep.fatigue<1){
|
creep.say("MTCS");
|
||||||
creep.say("MTCS");
|
} else { creep.say("Tired")}
|
||||||
} else { creep.say("Tired")}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
} else {
|
creep.say('parking')
|
||||||
//console.log(creep.room.memory.builderpark)
|
creep.moveTo(Game.rooms[creep.memory.originroom].memory.builderparkx,Game.rooms[creep.memory.originroom].memory.builderparky,creep.memory.originroom)
|
||||||
creep.moveTo(creep.room.memory.builderparkx,creep.room.memory.builderparky,creep.room.roomName)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var containers = creep.room.find(FIND_STRUCTURES, {
|
let containers =Game.rooms[creep.memory.originroom].find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;}});
|
filter: (structure) => {return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;}});
|
||||||
var allcontainers = creep.room.find(FIND_STRUCTURES, {
|
let allcontainers = creep.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return (structure.structureType == STRUCTURE_CONTAINER ) ;
|
return (structure.structureType == STRUCTURE_CONTAINER ) ;
|
||||||
}});
|
}});
|
||||||
var sources = creep.room.find(FIND_SOURCES);
|
let sources = Game.rooms[creep.memory.originroom].find(FIND_SOURCES);
|
||||||
var droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_ENERGY );
|
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_ENERGY );
|
||||||
if(containers==0){
|
if(containers==0){
|
||||||
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
|
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
|
||||||
creep.say("MTDE");
|
creep.say("MTDE");
|
||||||
@ -51,15 +56,14 @@ var roleBuilder = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
spawn: function(roomname){
|
spawn: function(roomname){
|
||||||
var myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
var myroom = Game.rooms[roomname]
|
let myroom = Game.rooms[roomname]
|
||||||
for(var thisspawn in myspawns){
|
for(let spawn of myspawns){
|
||||||
var spawn = myspawns[thisspawn]
|
let myrole='builder';
|
||||||
var myrole='builder';
|
let myroles = _.filter(Game.creeps, (creep) => { return ((creep.memory.role == myrole) && (creep.memory.originroom == roomname))});
|
||||||
var myroles = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role == myrole);
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
||||||
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
||||||
var newName = spawn.createCreep([WORK,WORK,CARRY,MOVE,MOVE], undefined, {role: myrole});
|
let newName = spawn.createCreep([MOVE,WORK,CARRY], undefined, {role: myrole});
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
console.log('Spawning new ' + myrole + ': ' + newName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
var roleHarvester = {
|
|
||||||
|
|
||||||
/** @param {Creep} creep **/
|
|
||||||
run: function(creep) {
|
|
||||||
if(creep.carry.energy < creep.carryCapacity) {
|
|
||||||
var sources = creep.room.find(FIND_SOURCES);
|
|
||||||
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(sources[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var spawntargets = creep.room.find(FIND_STRUCTURES, {
|
|
||||||
filter: (structure) => {
|
|
||||||
return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) &&structure.energy < structure.energyCapacity)
|
|
||||||
/**|| (structure.structureType == STRUCTURE_CONTAINER && structure.store[RESOURCE_ENERGY] < structure.storeCapacity) **/ ;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
var containertargets = creep.room.find(FIND_STRUCTURES, {
|
|
||||||
filter: (structure) => {
|
|
||||||
return (structure.structureType == STRUCTURE_CONTAINER && structure.store[RESOURCE_ENERGY] < structure.storeCapacity) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
if(spawntargets.length > 0) {
|
|
||||||
if(creep.transfer(spawntargets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(spawntargets[0]);
|
|
||||||
}
|
|
||||||
} else if (containertargets.length > 0) {
|
|
||||||
if(creep.transfer(containertargets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(containertargets[0]);
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
creep.moveTo(Game.flags.Flag1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
spawn: function(){
|
|
||||||
var myrole='harvester';
|
|
||||||
var nummyrole=0;
|
|
||||||
var myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole);
|
|
||||||
if(myroles.length < nummyrole) {
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + nummyrole);
|
|
||||||
var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,MOVE], undefined, {role: myrole});
|
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = roleHarvester;
|
|
@ -1,49 +0,0 @@
|
|||||||
var roleHarvester2 = {
|
|
||||||
|
|
||||||
/** @param {Creep} creep **/
|
|
||||||
run: function(creep) {
|
|
||||||
if(creep.carry.energy < creep.carryCapacity) {
|
|
||||||
var sources = creep.room.find(FIND_SOURCES);
|
|
||||||
if(creep.harvest(sources[1]) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(sources[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var spawntargets = creep.room.find(FIND_STRUCTURES, {
|
|
||||||
filter: (structure) => {
|
|
||||||
return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) &&structure.energy < structure.energyCapacity)
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
var containertargets = creep.room.find(FIND_STRUCTURES, {
|
|
||||||
filter: (structure) => {
|
|
||||||
return (structure.structureType == STRUCTURE_CONTAINER && structure.store[RESOURCE_ENERGY] < structure.storeCapacity) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
if(spawntargets.length > 0) {
|
|
||||||
if(creep.transfer(spawntargets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(spawntargets[0]);
|
|
||||||
}
|
|
||||||
} else if (containertargets.length > 0) {
|
|
||||||
if(creep.transfer(containertargets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(containertargets[0]);
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
creep.moveTo(Game.flags.Flag1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
spawn: function(){
|
|
||||||
var myrole='harvester2';
|
|
||||||
var nummyrole=0;
|
|
||||||
var myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole);
|
|
||||||
if(myroles.length < nummyrole) {
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + nummyrole);
|
|
||||||
var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,MOVE], undefined, {role: myrole});
|
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = roleHarvester2;
|
|
@ -1,5 +1,8 @@
|
|||||||
var roleHauler = {
|
let roleHauler = {
|
||||||
run: function(creep) {
|
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 == undefined){creep.memory.hauling=false}
|
||||||
if(creep.memory.hauling && creep.carry.energy == 0) {
|
if(creep.memory.hauling && creep.carry.energy == 0) {
|
||||||
creep.memory.destsource=undefined
|
creep.memory.destsource=undefined
|
||||||
@ -10,28 +13,28 @@ var roleHauler = {
|
|||||||
creep.memory.hauling = true;
|
creep.memory.hauling = true;
|
||||||
creep.say('hauling');
|
creep.say('hauling');
|
||||||
}
|
}
|
||||||
var sources = creep.pos.findClosestByRange(FIND_DROPPED_ENERGY );
|
let sources = creep.pos.findClosestByRange(FIND_DROPPED_ENERGY );
|
||||||
if(creep.memory.hauling==false){
|
if(creep.memory.hauling==false){
|
||||||
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
|
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
|
||||||
var mysource=Game.getObjectById(creep.memory.destsource.id)
|
let mysource=Game.getObjectById(creep.memory.destsource.id)
|
||||||
|
|
||||||
if(creep.pickup(mysource) == ERR_NOT_IN_RANGE && creep.carryCapacity > creep.carry.energy) {
|
if(creep.pickup(mysource) == ERR_NOT_IN_RANGE && creep.carryCapacity > creep.carry.energy) {
|
||||||
creep.moveTo(mysource);
|
creep.moveTo(mysource);
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
if(sources != undefined )
|
if(sources != undefined )
|
||||||
{ var spawntargets = creep.pos.findClosestByPath(FIND_STRUCTURES, {
|
{ let spawntargets = creep.pos.findClosestByPath(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity)
|
return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var containertargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
let containertargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return ((structure.structureType == STRUCTURE_CONTAINER ) && _.sum(structure.store) < structure.storeCapacity) ;
|
return ((structure.structureType == STRUCTURE_CONTAINER ) && _.sum(structure.store) < structure.storeCapacity) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
var storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return ((structure.structureType == STRUCTURE_STORAGE ) && _.sum(structure.store) < structure.storeCapacity) ;
|
return ((structure.structureType == STRUCTURE_STORAGE ) && _.sum(structure.store) < structure.storeCapacity) ;
|
||||||
}
|
}
|
||||||
@ -54,15 +57,14 @@ var roleHauler = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
spawn: function(roomname){
|
spawn: function(roomname){
|
||||||
var myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
var myroom = Game.rooms[roomname]
|
let myroom = Game.rooms[roomname]
|
||||||
for(var thisspawn in myspawns){
|
for(let spawn of myspawns){
|
||||||
var spawn = myspawns[thisspawn]
|
let myrole='hauler';
|
||||||
var myrole='hauler';
|
let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname);
|
||||||
var myroles = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role == myrole);
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
||||||
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
||||||
var newName = spawn.createCreep([CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], undefined, {role: myrole});
|
let newName = spawn.createCreep([CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], undefined, {role: myrole});
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
console.log('Spawning new ' + myrole + ': ' + newName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
var roleHauler2 = {
|
let roleHauler2 = {
|
||||||
|
|
||||||
/** @param {Creep} creep **/
|
/** @param {Creep} creep **/
|
||||||
run: function(creep) {
|
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 == undefined){creep.memory.hauling=false}
|
||||||
if(creep.memory.hauling && creep.carry.energy == 0) {
|
if(creep.memory.hauling && creep.carry.energy == 0) {
|
||||||
creep.memory.hauling = false;
|
creep.memory.hauling = false;
|
||||||
@ -14,7 +16,7 @@
|
|||||||
}
|
}
|
||||||
if(creep.memory.hauling==false){
|
if(creep.memory.hauling==false){
|
||||||
if(creep.carryCapacity > creep.carry.energy){
|
if(creep.carryCapacity > creep.carry.energy){
|
||||||
var container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
let container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;
|
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;
|
||||||
}});
|
}});
|
||||||
@ -24,7 +26,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var spawntarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
let spawntarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) &&structure.energy < structure.energyCapacity)
|
return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) &&structure.energy < structure.energyCapacity)
|
||||||
}
|
}
|
||||||
@ -41,15 +43,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
spawn: function(roomname){
|
spawn: function(roomname){
|
||||||
var myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
var myroom = Game.rooms[roomname]
|
let myroom = Game.rooms[roomname]
|
||||||
for(var thisspawn in myspawns){
|
for(let spawn of myspawns){
|
||||||
var spawn = myspawns[thisspawn]
|
let myrole='hauler2';
|
||||||
var myrole='hauler2';
|
let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname);
|
||||||
var myroles = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role == myrole);
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
||||||
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
||||||
var newName = spawn.createCreep([CARRY,CARRY,CARRY,MOVE,MOVE], undefined, {role: myrole});
|
let newName = spawn.createCreep([CARRY,CARRY,CARRY,MOVE,MOVE], undefined, {role: myrole});
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
console.log('Spawning new ' + myrole + ': ' + newName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
var roleMiner = {
|
let roleMiner = {
|
||||||
run: function(creep) {
|
run: function(creep) {
|
||||||
var sources = creep.room.find(FIND_SOURCES);
|
if(creep.memory.originroom === undefined){
|
||||||
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
|
creep.memory.originroom = creep.room.name
|
||||||
creep.moveTo(sources[0]);
|
}
|
||||||
}
|
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);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
spawn: function(roomname){
|
spawn: function(roomname){
|
||||||
var myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
var myroom = Game.rooms[roomname]
|
let myroom = Game.rooms[roomname]
|
||||||
for(var thisspawn in myspawns){
|
for(let spawn of myspawns){
|
||||||
var spawn = myspawns[thisspawn]
|
let myrole='miner';
|
||||||
var myrole='miner';
|
let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname);
|
||||||
var myroles = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role == myrole);
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
||||||
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
||||||
var newName = spawn.createCreep([WORK,WORK,WORK,WORK,WORK,MOVE], undefined, {role: myrole});
|
let newName = spawn.createCreep([WORK,WORK,WORK,WORK,WORK,MOVE], undefined, {role: myrole});
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
console.log('Spawning new ' + myrole + ': ' + newName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
var roleMiner2 = {
|
|
||||||
run: function(creep) {
|
|
||||||
var sources = creep.room.find(FIND_SOURCES);
|
|
||||||
if(creep.harvest(sources[1]) == ERR_NOT_IN_RANGE) {
|
|
||||||
creep.moveTo(sources[1]);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
spawn: function(roomname){
|
|
||||||
var myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
|
||||||
var myroom = Game.rooms[roomname]
|
|
||||||
for(var thisspawn in myspawns){
|
|
||||||
var spawn = myspawns[thisspawn]
|
|
||||||
var myrole='miner2';
|
|
||||||
var myroles = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role == myrole);
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
|
||||||
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
|
||||||
var newName = spawn.createCreep([WORK,WORK,WORK,WORK,WORK,MOVE], undefined, {role: myrole});
|
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
module.exports = roleMiner2;
|
|
@ -1,7 +1,10 @@
|
|||||||
var roleTowerrecharger = {
|
let roleTowerrecharger = {
|
||||||
|
|
||||||
/** @param {Creep} creep **/
|
/** @param {Creep} creep **/
|
||||||
run: function(creep) {
|
run: function(creep) {
|
||||||
|
if(creep.memory.originroom === undefined){
|
||||||
|
creep.memory.originroom = creep.room.name
|
||||||
|
}
|
||||||
if(creep.memory.recharging && creep.carry.energy == 0) {
|
if(creep.memory.recharging && creep.carry.energy == 0) {
|
||||||
creep.memory.recharging = false;
|
creep.memory.recharging = false;
|
||||||
creep.say('refilling');
|
creep.say('refilling');
|
||||||
@ -12,7 +15,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!creep.memory.recharging) {
|
if(!creep.memory.recharging) {
|
||||||
var container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
let container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 1000) ;
|
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 1000) ;
|
||||||
}});
|
}});
|
||||||
@ -21,7 +24,7 @@
|
|||||||
creep.moveTo(container);
|
creep.moveTo(container);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var spawntarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
let spawntarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return (structure.structureType == STRUCTURE_TOWER && structure.energy < structure.energyCapacity)
|
return (structure.structureType == STRUCTURE_TOWER && structure.energy < structure.energyCapacity)
|
||||||
}
|
}
|
||||||
@ -34,15 +37,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
spawn: function(roomname){
|
spawn: function(roomname){
|
||||||
var myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
var myroom = Game.rooms[roomname]
|
let myroom = Game.rooms[roomname]
|
||||||
for(var thisspawn in myspawns){
|
for(let spawn of myspawns){
|
||||||
var spawn = myspawns[thisspawn]
|
let myrole='towerrecharger';
|
||||||
var myrole='towerrecharger';
|
let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname);
|
||||||
var myroles = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role == myrole);
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
||||||
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
||||||
var newName = spawn.createCreep([CARRY,CARRY,CARRY,MOVE,MOVE], undefined, {role: myrole});
|
let newName = spawn.createCreep([CARRY,CARRY,CARRY,MOVE,MOVE], undefined, {role: myrole});
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
console.log('Spawning new ' + myrole + ': ' + newName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
var roleRepairbot = {
|
let roleRepairbot = {
|
||||||
|
|
||||||
/** @param {Creep} creep **/
|
/** @param {Creep} creep **/
|
||||||
run: function(creep) {
|
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 == undefined){creep.memory.repairing=true}
|
||||||
if(creep.memory.repairing && creep.carry.energy == 0) {
|
if(creep.memory.repairing && creep.carry.energy == 0) {
|
||||||
creep.memory.repairing = false;
|
creep.memory.repairing = false;
|
||||||
@ -12,7 +15,7 @@ var roleRepairbot = {
|
|||||||
creep.say('repairing');
|
creep.say('repairing');
|
||||||
}
|
}
|
||||||
if(creep.memory.repairing==false){
|
if(creep.memory.repairing==false){
|
||||||
var container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
let container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;
|
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;
|
||||||
}});
|
}});
|
||||||
@ -21,7 +24,7 @@ var roleRepairbot = {
|
|||||||
creep.moveTo(container);
|
creep.moveTo(container);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var importantstructures = creep.room.find(FIND_STRUCTURES, {
|
let importantstructures = creep.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return (structure.structureType == STRUCTURE_CONTAINER && structure.hits < structure.hitsMax) ;
|
return (structure.structureType == STRUCTURE_CONTAINER && structure.hits < structure.hitsMax) ;
|
||||||
}});
|
}});
|
||||||
@ -31,7 +34,7 @@ var roleRepairbot = {
|
|||||||
creep.moveTo(importantstructures[0])
|
creep.moveTo(importantstructures[0])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var damagedstructures = creep.room.find(FIND_STRUCTURES,{filter: (s) => s.hits < s.hitsMax});
|
let damagedstructures = creep.room.find(FIND_STRUCTURES,{filter: (s) => s.hits < s.hitsMax});
|
||||||
damagedstructures = _.sortBy(damagedstructures, (s)=>s.hits / s.hitsMax)
|
damagedstructures = _.sortBy(damagedstructures, (s)=>s.hits / s.hitsMax)
|
||||||
if(damagedstructures.length>0){
|
if(damagedstructures.length>0){
|
||||||
if(creep.repair(damagedstructures[0]) == ERR_NOT_IN_RANGE){
|
if(creep.repair(damagedstructures[0]) == ERR_NOT_IN_RANGE){
|
||||||
@ -42,15 +45,14 @@ var roleRepairbot = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
spawn: function(roomname){
|
spawn: function(roomname){
|
||||||
var myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
var myroom = Game.rooms[roomname]
|
let myroom = Game.rooms[roomname]
|
||||||
for(var thisspawn in myspawns){
|
for(let spawn of myspawns){
|
||||||
var spawn = myspawns[thisspawn]
|
let myrole='repairbot';
|
||||||
var myrole='repairbot';
|
let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname);
|
||||||
var myroles = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role == myrole);
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
||||||
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
||||||
var newName = spawn.createCreep([WORK,CARRY,MOVE], undefined, {role: myrole});
|
let newName = spawn.createCreep([WORK,CARRY,MOVE], undefined, {role: myrole});
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
console.log('Spawning new ' + myrole + ': ' + newName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
var roleTowerrecharger = {
|
|
||||||
|
|
||||||
/** @param {Creep} creep **/
|
|
||||||
run: function(creep) {
|
|
||||||
if(creep.carryCapacity > creep.carry.energy){
|
|
||||||
var 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 {
|
|
||||||
var 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.say('refilling')
|
|
||||||
creep.moveTo(spawntarget);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
creep.say('MTF')
|
|
||||||
creep.moveTo(Game.flags.Flag1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
spawn: function(){
|
|
||||||
var myrole='towerrecharger';
|
|
||||||
var nummyrole=2;
|
|
||||||
var myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole);
|
|
||||||
if(myroles.length < nummyrole) {
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + nummyrole);
|
|
||||||
var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,CARRY,CARRY,MOVE,MOVE], undefined, {role: myrole});
|
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
module.exports = roleTowerrecharger;
|
|
@ -1,6 +1,8 @@
|
|||||||
var roleUpgrader = {
|
let roleUpgrader = {
|
||||||
run: function(creep) {
|
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==undefined){creep.memory.upgrading=true}
|
||||||
if(creep.memory.upgrading && creep.carry.energy == 0) {
|
if(creep.memory.upgrading && creep.carry.energy == 0) {
|
||||||
creep.memory.upgrading = false;
|
creep.memory.upgrading = false;
|
||||||
@ -19,7 +21,7 @@ var roleUpgrader = {
|
|||||||
} else { creep.moveTo(creep.room.memory.upgraderparkx,creep.room.memory.upgraderparky,creep.room.roomName) }
|
} else { creep.moveTo(creep.room.memory.upgraderparkx,creep.room.memory.upgraderparky,creep.room.roomName) }
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
let container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;
|
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;
|
||||||
}});
|
}});
|
||||||
@ -30,7 +32,7 @@ var roleUpgrader = {
|
|||||||
creep.moveTo(container);
|
creep.moveTo(container);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
var droppedenergy = creep.room.find(FIND_DROPPED_ENERGY );
|
let droppedenergy = creep.room.find(FIND_DROPPED_ENERGY );
|
||||||
if(creep.pickup(droppedenergy[0]) == ERR_NOT_IN_RANGE) {
|
if(creep.pickup(droppedenergy[0]) == ERR_NOT_IN_RANGE) {
|
||||||
creep.say("MTDE");
|
creep.say("MTDE");
|
||||||
creep.moveTo(droppedenergy[0]);
|
creep.moveTo(droppedenergy[0]);
|
||||||
@ -39,15 +41,14 @@ var roleUpgrader = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
spawn: function(roomname){
|
spawn: function(roomname){
|
||||||
var myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
var myroom = Game.rooms[roomname]
|
let myroom = Game.rooms[roomname]
|
||||||
for(var thisspawn in myspawns){
|
for(let spawn of myspawns){
|
||||||
var spawn = myspawns[thisspawn]
|
let myrole='upgrader';
|
||||||
var myrole='upgrader';
|
let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname);
|
||||||
var myroles = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role == myrole);
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
|
||||||
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
|
||||||
var newName = spawn.createCreep([MOVE,MOVE,WORK,WORK,WORK,CARRY,CARRY,CARRY], undefined, {role: myrole});
|
let newName = spawn.createCreep([MOVE,MOVE,WORK,WORK,WORK,CARRY,CARRY,CARRY], undefined, {role: myrole});
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
console.log('Spawning new ' + myrole + ': ' + newName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
var roleWarrior = {
|
|
||||||
|
|
||||||
/** @param {Creep} creep **/
|
|
||||||
run: function(creep) {
|
|
||||||
var hostile = creep.pos.findClosestByRange(Game.HOSTILE_CREEPS);
|
|
||||||
|
|
||||||
if(hostile!=undefined) {
|
|
||||||
var username = hostile.owner.username;
|
|
||||||
Game.notify(`User ${username} spotted in room ${roomName}`);
|
|
||||||
creep.moveTo(hostile);
|
|
||||||
creep.attack(hostile);
|
|
||||||
|
|
||||||
} else{
|
|
||||||
creep.moveTo(Game.flags.Flag3);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
spawn: function(){
|
|
||||||
var myrole='warrior';
|
|
||||||
var nummyrole=2;
|
|
||||||
var myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole);
|
|
||||||
if(myroles.length < nummyrole) {
|
|
||||||
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + nummyrole);
|
|
||||||
var newName = Game.spawns['Spawn1'].createCreep([ATTACK,RANGED_ATTACK,MOVE], undefined, {role: myrole});
|
|
||||||
console.log('Spawning new ' + myrole + ': ' + newName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = roleWarrior;
|
|
@ -1,18 +1,21 @@
|
|||||||
var runSources = {
|
let runSources = {
|
||||||
tick: function(roomname) {
|
tick: function(roomname) {
|
||||||
var sources = Game.rooms[roomname].find(FIND_DROPPED_ENERGY );
|
let sources = Game.rooms[roomname].find(FIND_DROPPED_ENERGY );
|
||||||
for(var source of sources){
|
for(let source of sources){
|
||||||
var allhaulers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role=='hauler' );
|
try{
|
||||||
var unassignedhaulers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => (creep.memory.destsource == undefined && creep.memory.role=='hauler'));
|
let allhaulers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role=='hauler' );
|
||||||
var assignedhaulers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => (creep.memory.destsource != undefined && creep.memory.role=='hauler'));
|
let unassignedhaulers = _.filter(allhaulers, (creep) => (creep.memory.destsource == undefined && creep.memory.role=='hauler'));
|
||||||
var myhaulers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => (creep.memory.destsource != undefined && creep.memory.destsource.id==source.id && creep.memory.role=='hauler'));
|
let assignedhaulers = _.filter(allhaulers, (creep) => (creep.memory.destsource != undefined && creep.memory.role=='hauler'));
|
||||||
var sourcecount = sources.length
|
let myhaulers = _.filter(allhaulers, (creep) => (creep.memory.destsource != undefined && creep.memory.destsource.id==source.id && creep.memory.role=='hauler'));
|
||||||
var persrc = allhaulers.length / sourcecount
|
let sourcecount = sources.length
|
||||||
if(myhaulers.length >=persrc){break;} else{
|
let persrc = allhaulers.length / sourcecount
|
||||||
|
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(unassignedhaulers.length > 0){
|
||||||
unassignedhaulers[0].memory.destsource = source
|
if(myhaulers.length < persrc){
|
||||||
|
unassignedhaulers[0].memory.destsource = source
|
||||||
|
} else {}
|
||||||
}
|
}
|
||||||
}
|
} catch(e){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
22
sproc.js
Normal file
22
sproc.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
let assignMiners = {
|
||||||
|
tick: function(roomname) {
|
||||||
|
let sources = Game.rooms[roomname].find(FIND_SOURCES );
|
||||||
|
for(var 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
|
||||||
|
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;
|
270
totest.js
270
totest.js
@ -1,270 +0,0 @@
|
|||||||
let roleHarvester = require('role.harvester');
|
|
||||||
let roleBuilder = require('role.builder');
|
|
||||||
let roleRepairer = require('role.repairer');
|
|
||||||
let roleDistributor = require('role.distributor');
|
|
||||||
let roleUpgrader = require('role.upgrader');
|
|
||||||
let roleClaimer = require('role.claimer');
|
|
||||||
let roleMiner = require("role.miner");
|
|
||||||
|
|
||||||
let roleDefender = require('role.defender');
|
|
||||||
|
|
||||||
let structureTower = require('structure.tower');
|
|
||||||
let structureLink = require('structure.link');
|
|
||||||
|
|
||||||
const FLAG_PRIORITIES = { 'Flag1': 100, 'Flag2': 70, 'Flag3': 80, 'Flag4': 75, 'Flag5': 100};
|
|
||||||
const ROLE_PRIORITIES = { 'Claimers': 100, 'Harvesters': 95, 'Distributors': 94, 'Repairers': 85, 'Builders': 80, 'Upgraders': 75, 'Defenders': 90 , 'Miners' : 85 };
|
|
||||||
|
|
||||||
module.exports.loop = function () {
|
|
||||||
let spawnStack = new Array();
|
|
||||||
|
|
||||||
cleanUpCreepsFromMemory();
|
|
||||||
|
|
||||||
for(let room in Memory.myRooms){
|
|
||||||
let roomBuf = Memory.myRooms[room];
|
|
||||||
let spawnsInRoom = Game.rooms[room].find(FIND_MY_STRUCTURES, { filter: (s) => s.structureType == STRUCTURE_SPAWN });
|
|
||||||
|
|
||||||
structureLink.run();//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
|
|
||||||
for(let tower in Game.rooms[room].find(FIND_MY_STRUCTURES, {filter: s => s.structureType == STRUCTURE_TOWER}))
|
|
||||||
structureTower.run(Game.rooms[room].find(FIND_MY_STRUCTURES, {filter: s => s.structureType == STRUCTURE_TOWER})[tower]);
|
|
||||||
|
|
||||||
for(let flag in roomBuf){
|
|
||||||
let flagBuf = roomBuf[flag];
|
|
||||||
|
|
||||||
for(let role in flagBuf){
|
|
||||||
let roleBuf = flagBuf[role];
|
|
||||||
|
|
||||||
while(roleBuf.creeps.length < roleBuf.amountToSpawn){
|
|
||||||
roleBuf.creeps.push("undefined");
|
|
||||||
}
|
|
||||||
|
|
||||||
for(let i = roleBuf.creeps.length-1; i > 0; i--){
|
|
||||||
if(i >= roleBuf.amountToSpawn && !Game.creeps[roleBuf.creeps[i]]){
|
|
||||||
roleBuf.creeps.pop();
|
|
||||||
}else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(let creep in roleBuf.creeps){
|
|
||||||
let creepBuf = roleBuf.creeps[creep];
|
|
||||||
|
|
||||||
if(!Game.creeps[creepBuf]){
|
|
||||||
addToSpawnStack(spawnStack, room, flag, role, creep);
|
|
||||||
}else {
|
|
||||||
var start = Game.cpu.getUsed();
|
|
||||||
orderCreep(room, flag, role, creepBuf, creep);
|
|
||||||
var end = Game.cpu.getUsed();
|
|
||||||
//console.log(end-start + " " + flag + " " + role);
|
|
||||||
|
|
||||||
let hostileCreeps = Game.creeps[creepBuf].room.find(FIND_HOSTILE_CREEPS);
|
|
||||||
if(hostileCreeps.length > 0){
|
|
||||||
Game.flags['DD'].setPosition(hostileCreeps[0].pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spawnStack.sort(function(s1, s2){ return s1.priority > s2.priority });
|
|
||||||
for(let spawn in spawnsInRoom){
|
|
||||||
let spawnBuf = spawnsInRoom[spawn];
|
|
||||||
|
|
||||||
if(spawnBuf.isSpawning == null && spawnStack.length > 0)
|
|
||||||
spawnFromStack(spawnStack, spawnBuf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let cleanUpCreepsFromMemory = function () {
|
|
||||||
for (var name in Memory.creeps) {
|
|
||||||
if (!Game.creeps[name]) {
|
|
||||||
delete Memory.creeps[name];
|
|
||||||
console.log('Clearing non-existing creep memory:', name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let addToSpawnStack = function(spawnStack, room, flag, role, creep){
|
|
||||||
let priority = FLAG_PRIORITIES[flag] * ROLE_PRIORITIES[role];
|
|
||||||
spawnStack.push({'priority': priority,'room': room, 'flag': flag, 'role': role, 'creep': creep});
|
|
||||||
//console.log("Pushed: " + priority + " " + room + " " + flag + " " + role + " " + creep);
|
|
||||||
}
|
|
||||||
|
|
||||||
let spawnFromStack = function(spawnStack, spawn){
|
|
||||||
if(spawn.isSpawning != null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
let creepToSpawn = spawnStack.pop();
|
|
||||||
|
|
||||||
let room = creepToSpawn.room;
|
|
||||||
let flag = creepToSpawn.flag;
|
|
||||||
let role = creepToSpawn.role;
|
|
||||||
let creep = creepToSpawn.creep;
|
|
||||||
let newCreep = spawnCreep(role, spawn);
|
|
||||||
|
|
||||||
if(Game.creeps[newCreep]){
|
|
||||||
Memory.myRooms[room][flag][role].creeps[creep] = newCreep;
|
|
||||||
console.log("Spawned new Creep: " + newCreep + " " + role + " " + flag + " " + room);
|
|
||||||
}else {
|
|
||||||
spawnStack.push(creepToSpawn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let spawnCreep = function(role, spawn){
|
|
||||||
let newCreep;
|
|
||||||
if(role == 'Harvesters'){
|
|
||||||
if(spawn.name == "Spawn1")
|
|
||||||
newCreep = spawn.createCreep([WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE], undefined);
|
|
||||||
else
|
|
||||||
newCreep = spawn.createCreep([WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,WORK,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], undefined);
|
|
||||||
}else if(role == 'Distributors'){
|
|
||||||
if(spawn.name == "Spawn1")
|
|
||||||
newCreep = spawn.createCreep([CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE], undefined);
|
|
||||||
else
|
|
||||||
newCreep = spawn.createCreep([CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE], undefined);
|
|
||||||
}else if(role == 'Upgraders'){
|
|
||||||
if(spawn.name == "Spawn1")
|
|
||||||
newCreep = spawn.createCreep([WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE], undefined);
|
|
||||||
else
|
|
||||||
;
|
|
||||||
}else if(role == 'Builders'){
|
|
||||||
if(spawn.name == "Spawn1")
|
|
||||||
newCreep = spawn.createCreep([WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE], undefined);
|
|
||||||
else
|
|
||||||
newCreep = spawn.createCreep([WORK,WORK,WORK,WORK,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE], undefined);
|
|
||||||
}else if(role == 'Repairers'){
|
|
||||||
if(spawn.name == "Spawn1")
|
|
||||||
newCreep = spawn.createCreep([WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE], undefined);
|
|
||||||
else
|
|
||||||
newCreep = spawn.createCreep([WORK,WORK,WORK,WORK,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE], undefined);
|
|
||||||
}else if(role == 'Miners'){
|
|
||||||
if(spawn.name == "Spawn1")
|
|
||||||
newCreep = spawn.createCreep([WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE], undefined);
|
|
||||||
else
|
|
||||||
newCreep = spawn.createCreep([WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE], undefined);
|
|
||||||
}else if(role == 'Claimers'){
|
|
||||||
if(spawn.name == "Spawn1")
|
|
||||||
newCreep = spawn.createCreep([CLAIM, CLAIM, MOVE, MOVE], undefined);
|
|
||||||
else
|
|
||||||
newCreep = spawn.createCreep([CLAIM,CLAIM,MOVE,MOVE], undefined);
|
|
||||||
}else if(role == 'Defenders'){
|
|
||||||
if(spawn.name == "Spawn1")
|
|
||||||
newCreep = spawn.createCreep([TOUGH, TOUGH, TOUGH, TOUGH, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE ,MOVE, HEAL, HEAL, HEAL, HEAL, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK], undefined);
|
|
||||||
else
|
|
||||||
;
|
|
||||||
}
|
|
||||||
return newCreep;
|
|
||||||
}
|
|
||||||
|
|
||||||
let orderCreep = function(room, flag, role, creepName, creepIndex){
|
|
||||||
if(role == 'Harvesters'){
|
|
||||||
|
|
||||||
roleHarvester.run(room, flag, creepName, creepIndex);
|
|
||||||
|
|
||||||
}else if(role == 'Distributors'){
|
|
||||||
|
|
||||||
roleDistributor.run(room, flag, creepName, creepIndex);
|
|
||||||
|
|
||||||
}else if(role == 'Upgraders'){
|
|
||||||
|
|
||||||
roleUpgrader.run(flag, creepName);
|
|
||||||
|
|
||||||
}else if(role == 'Builders'){
|
|
||||||
|
|
||||||
roleBuilder.run(room, flag, creepName);
|
|
||||||
|
|
||||||
}else if(role == 'Repairers'){
|
|
||||||
|
|
||||||
roleRepairer.run(room, flag, creepName);
|
|
||||||
|
|
||||||
}else if(role == 'Miners'){
|
|
||||||
|
|
||||||
roleMiner.run(room, flag, creepName);
|
|
||||||
|
|
||||||
}else if(role == 'Claimers'){
|
|
||||||
|
|
||||||
roleClaimer.run(flag, creepName);
|
|
||||||
|
|
||||||
}else if(role == 'Defenders'){
|
|
||||||
|
|
||||||
roleDefender.run('DD', creepName);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let init = function(){
|
|
||||||
Memory.myRooms =
|
|
||||||
{
|
|
||||||
'E22S57':
|
|
||||||
{
|
|
||||||
'Flag1':
|
|
||||||
{
|
|
||||||
'Harvesters': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Distributors': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Repairers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Builders': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Upgraders': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Miners': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Claimers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Healers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Melees': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
},
|
|
||||||
|
|
||||||
'Flag2':
|
|
||||||
{
|
|
||||||
'Harvesters': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Distributors': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Repairers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Builders': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Upgraders': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Miners': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Claimers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Healers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Melees': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
},
|
|
||||||
|
|
||||||
'Flag3':
|
|
||||||
{
|
|
||||||
'Harvesters': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Distributors': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Repairers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Builders': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Upgraders': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Miners': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Claimers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Healers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Melees': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
},
|
|
||||||
|
|
||||||
'Flag4':
|
|
||||||
{
|
|
||||||
'Harvesters': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Distributors': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Repairers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Builders': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Upgraders': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Miners': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Claimers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Healers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Melees': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'E24S57':
|
|
||||||
{
|
|
||||||
'Flag5':
|
|
||||||
{
|
|
||||||
'Harvesters': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Distributors': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Repairers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Builders': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Upgraders': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Miners': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Claimers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Healers': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
'Melees': {'amountToSpawn': 0, 'creeps': new Array()},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
10
tower.js
10
tower.js
@ -9,18 +9,18 @@ var towers = {
|
|||||||
_.forEach(towers, function(tower){
|
_.forEach(towers, function(tower){
|
||||||
|
|
||||||
|
|
||||||
var myclosestDamagedStructure = tower.room.find(FIND_STRUCTURES, {
|
let myclosestDamagedStructure = tower.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => structure.structureType != STRUCTURE_WALL && structure.structureType != STRUCTURE_RAMPART && structure.hits < structure.hitsMax
|
filter: (structure) => structure.structureType != STRUCTURE_WALL && structure.structureType != STRUCTURE_RAMPART && structure.hits < structure.hitsMax
|
||||||
});
|
});
|
||||||
var closestDamagedStructure = _.first(_.sortBy(myclosestDamagedStructure, (s)=>s.hits / s.hitsMax));
|
let closestDamagedStructure = _.first(_.sortBy(myclosestDamagedStructure, (s)=>s.hits / s.hitsMax));
|
||||||
|
|
||||||
var allcontainers = tower.room.find(FIND_STRUCTURES, {
|
let allcontainers = tower.room.find(FIND_STRUCTURES, {
|
||||||
filter: (s) => {
|
filter: (s) => {
|
||||||
return ( s.structureType == STRUCTURE_CONTAINER)
|
return ( s.structureType == STRUCTURE_CONTAINER)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(tower.energy > tower.energyCapacity * .7 ){
|
if(tower.energy > tower.energyCapacity * .7 ){
|
||||||
var importantstructures = tower.room.find(FIND_STRUCTURES, {
|
let importantstructures = tower.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
return (structure.structureType == STRUCTURE_CONTAINER && structure.hits < structure.hitsMax) ;
|
return (structure.structureType == STRUCTURE_CONTAINER && structure.hits < structure.hitsMax) ;
|
||||||
}});
|
}});
|
||||||
@ -36,7 +36,7 @@ var towers = {
|
|||||||
} else { console.log("tower waiting for more storage. Currently at: " + Game.rooms[roomname].memory.containerstoragepercent)}
|
} else { console.log("tower waiting for more storage. Currently at: " + Game.rooms[roomname].memory.containerstoragepercent)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
|
let closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
|
||||||
if(closestHostile) {
|
if(closestHostile) {
|
||||||
tower.attack(closestHostile);
|
tower.attack(closestHostile);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user