47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
var energyUtils = require('util_energy');
|
|
var _ = require('lodash');
|
|
|
|
var name = 'desatilnik';
|
|
|
|
function run(creep) {
|
|
if(creep.room.memory.containers == 0) return;
|
|
|
|
if(creep.store.getFreeCapacity() > 0 ){
|
|
var containers = creep.room.find(FIND_STRUCTURES, {
|
|
filter : { structureType: STRUCTURE_CONTAINER}
|
|
});
|
|
|
|
var maxContainer = containers[0];
|
|
|
|
containers.forEach((container, index) => {
|
|
if(container.store[RESOURCE_ENERGY] > maxContainer.store[RESOURCE_ENERGY]){
|
|
maxContainer = container;
|
|
}
|
|
});
|
|
|
|
if(creep.withdraw(maxContainer, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
creep.moveTo(maxContainer);
|
|
}
|
|
}
|
|
else{
|
|
var containers = creep.room.find(FIND_STRUCTURES, {
|
|
filter : { structureType: STRUCTURE_CONTAINER}
|
|
});
|
|
|
|
var minContainer = containers[0];
|
|
|
|
containers.forEach((container, index) => {
|
|
if(container.store[RESOURCE_ENERGY] < minContainer.store[RESOURCE_ENERGY]){
|
|
minContainer = container;
|
|
}
|
|
});
|
|
|
|
if(creep.transfer(minContainer, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
creep.moveTo(minContainer);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = {name,run};
|
|
|