Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- roleHarvester = function(creep) {
- if(creep.carry.energy < creep.carryCapacity) {
- let sources = creep.room.find(FIND_SOURCES)
- if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
- creep.moveTo(sources[0]);
- }
- }
- else {
- let targets = creep.pos.findClosestByPath(FIND_STRUCTURES, {
- filter: (structure) =>
- (structure.structureType == STRUCTURE_SPAWN && structure.energy < structure.energyCapacity ) ||
- (structure.structureType == STRUCTURE_EXTENSION && structure.energy < structure.energyCapacity ) ||
- (structure.structureType == STRUCTURE_CONTAINER && structure.store.energy < structure.storeCapacity )
- })
- if(targets) {
- if(creep.transfer(targets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
- creep.moveTo(targets);
- }
- }
- else {
- if(creep.memory.building) {
- let targets = creep.room.find(FIND_CONSTRUCTION_SITES);
- let rtargets = creep.room.find(FIND_STRUCTURES, {
- filter: (structure) => structure.hits < structure.hitsMax && structure.hits < 100000
- });
- if(targets.length) {
- if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
- creep.moveTo(targets[0]);
- }
- }
- else if(rtargets.length) {
- if(creep.repair(rtargets[0]) == ERR_NOT_IN_RANGE) {
- creep.moveTo(rtargets[0]);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement