Added progress checking, and automatic source delegation for creeps, when there is more than 1 source
This commit is contained in:
parent
97bf5fe399
commit
d5956ede22
|
@ -15,7 +15,7 @@ const roleMap = {
|
|||
|
||||
var creepCounts = {
|
||||
"harvester" : 3,
|
||||
"builder" : 1,
|
||||
"builder" : 2,
|
||||
"upgrader" : 2,
|
||||
"repairer" : 1,
|
||||
"streltsy" : 2
|
||||
|
|
|
@ -4,9 +4,11 @@ var name = 'harvester';
|
|||
|
||||
function run(creep) {
|
||||
if(creep.store.getFreeCapacity() > 0) {
|
||||
var sources = creep.room.find(FIND_SOURCES);
|
||||
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
|
||||
if(typeof creep.memory.assignedSource === 'undefined') energyUtils.sourceDelegate(creep);
|
||||
var source = Game.getObjectById(creep.memory.assignedSource);
|
||||
|
||||
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(source, {visualizePathStyle: {stroke: '#ffaa00'}});
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1,25 +1,61 @@
|
|||
var energyUtils = {
|
||||
gatherEnergy : function(creep) {
|
||||
var storage = creep.room.find(FIND_STRUCTURES, {
|
||||
let storage;
|
||||
if(creep.room.memory.hasContainer){
|
||||
storage = creep.room.find(FIND_STRUCTURES, {
|
||||
filter: (structure) => {
|
||||
return (structure.structureType == STRUCTURE_CONTAINER) &&
|
||||
structure.store.getUsedCapacity(RESOURCE_ENERGY) > 0;
|
||||
}
|
||||
});
|
||||
/**
|
||||
if(storage.length == 0){
|
||||
storage = creep.room.find(FIND_STRUCTURES, {
|
||||
filter: (structure) => {
|
||||
return (structure.structureType == STRUCTURE_SPAWN) &&
|
||||
structure.store.getUsedCapacity(RESOURCE_ENERGY) > 0;
|
||||
}
|
||||
});
|
||||
else{
|
||||
if(typeof creep.memory.assignedSource === 'undefined') energyUtils.sourceDelegate(creep);
|
||||
let source = Game.getObjectById(creep.memory.assignedSource);
|
||||
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(source, {visualizePathStyle: {stroke: '#ffaa00'}});
|
||||
}
|
||||
**/
|
||||
return;
|
||||
}
|
||||
|
||||
if(storage.length == 0) return;
|
||||
|
||||
if(creep.withdraw(storage[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(storage[0], {visualizePathStyle: {stroke: '#ffaa00'}});
|
||||
}
|
||||
},
|
||||
sourceDelegate : function(creep){
|
||||
const room = creep.room;
|
||||
|
||||
const sources = creep.room.find(FIND_SOURCES);
|
||||
|
||||
let minSource = sources[0].id;
|
||||
let minSourceCount = 0;
|
||||
|
||||
if(typeof room.memory[sources[0].id] !== 'undefined')
|
||||
minSourceCount = room.memory[sources[0].id].length;
|
||||
|
||||
sources.forEach(function(source){
|
||||
if(typeof room.memory[source.id] === 'undefined')
|
||||
room.memory[source.id] = [];
|
||||
|
||||
room.memory[source.id].forEach(function(assignedCreep, index){
|
||||
if(!Game.creeps[assignedCreep]){
|
||||
room.memory[source.id].splice(index, 1);
|
||||
}
|
||||
});
|
||||
|
||||
if(room.memory[source.id].length < minSourceCount){
|
||||
minSource = source.id;
|
||||
minSourceCount = room.memory[source.id].length;
|
||||
}
|
||||
});
|
||||
|
||||
room.memory[minSource].push(creep.name);
|
||||
creep.memory.assignedSource = minSource;
|
||||
|
||||
}
|
||||
,
|
||||
depositEnergy : function(creep) {
|
||||
var targets = creep.room.find(FIND_STRUCTURES, {
|
||||
filter: (structure) => {
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
var progressUtils = {
|
||||
checkProgress : function() {
|
||||
|
||||
for(var room in Game.rooms){
|
||||
const structures = Game.rooms[room].find(FIND_MY_STRUCTURES);
|
||||
for(var roomName in Game.rooms){
|
||||
const room = Game.rooms[roomName];
|
||||
const structures = room.find(FIND_MY_STRUCTURES);
|
||||
room.memory.hasContainer = false;
|
||||
room.memory.hasSpawn = false;
|
||||
room.memory.extensions = 0;
|
||||
|
||||
for(var structure in structures){
|
||||
structures.forEach(function (structure){
|
||||
if(structure.structureType == STRUCTURE_CONTAINER) room.memory.hasContainer = true;
|
||||
if(structure.structureType == STRUCTURE_SPAWN) room.memory.hasSpawn = true;
|
||||
|
||||
if(structure.structureType == STRUCTURE_EXTENSION) room.memory.extensions++;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue