Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @param {Creep} creep **/
- global.deposit = function(creep) {
- //Find Things that need energy
- var structuresNeedingEnergy = creep.room.find(FIND_STRUCTURES, {
- filter: (structure) => {
- return ((structure.structureType == STRUCTURE_SPAWN ||
- structure.structureType == STRUCTURE_EXTENSION) && structure.energy < structure.energyCapacity);
- }
- });
- var towersNeedingEnergy = creep.room.find(FIND_STRUCTURES, {
- filter: (structure) => {
- return structure.structureType == STRUCTURE_TOWER && structure.energy < structure.energyCapacity - 100 && creep.pos.getRangeTo(structure) < 6;
- }
- });
- var structuresWantingEnergy = creep.room.find(FIND_STRUCTURES, {
- filter: (structure) => {
- return (structure.structureType == STRUCTURE_CONTAINER && structure.pos.getRangeTo(structure.pos.findClosestByRange(FIND_SOURCES)) > 3 && structure.store[RESOURCE_ENERGY] < structure.storeCapacity - 100);
- }
- });
- var storageBox = creep.room.find(FIND_STRUCTURES, {
- filter: (structure) => {
- return (structure.structureType == STRUCTURE_STORAGE && structure.store[RESOURCE_ENERGY] < structure.storeCapacity - 100);
- }
- });
- if(structuresNeedingEnergy.length > 0) {
- var dropOff = creep.pos.findClosestByPath(structuresNeedingEnergy);
- if(creep.transfer(dropOff, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
- creep.moveTo(dropOff);
- }
- }else if(towersNeedingEnergy.length > 0){
- var dropOff = creep.pos.findClosestByPath(towersNeedingEnergy);
- if(creep.transfer(dropOff, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
- creep.moveTo(dropOff);
- }
- }else if(structuresWantingEnergy.length > 0){
- var dropOff = creep.pos.findClosestByPath(structuresWantingEnergy);
- if(creep.transfer(dropOff, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
- creep.moveTo(dropOff);
- }
- }else if(storageBox.length > 0){
- var dropOff = creep.pos.findClosestByPath(storageBox);
- if(creep.transfer(dropOff, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
- creep.moveTo(dropOff);
- }
- }else{
- //Do Nothing
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement