Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var roleHarvesterRoom = {
- /** @param {Creep} creep **/
- run: function(creep) {
- var room_spawn = "[remove]";
- var room_dest;
- if(creep.memory.room_dest != 0) {
- room_dest = creep.memory.room_dest;
- } else {
- Game.notify('Harvester for other rooms has no destination');
- }
- var flag = Game.flags.F_Roombot;
- var flag_spawn = Game.flags.Flag1;
- if(creep.room.name == room_spawn) {
- if(creep.carry.energy == 0) {
- creep.moveTo(flag);
- } else {
- var targets = creep.room.find(FIND_STRUCTURES, {
- filter: (structure) => {
- return (structure.structureType == STRUCTURE_TOWER || structure.structureType == STRUCTURE_SPAWN ||
- structure.structureType == STRUCTURE_EXTENSION ||
- structure.structureType == STRUCTURE_CONTAINER) &&
- structure.energy < structure.energyCapacity;
- }
- });
- if(targets.length > 0) {
- if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
- creep.moveTo(targets[0]);
- }
- }
- }
- } else if(creep.room.name == room_dest) {
- 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 {
- creep.moveTo(flag_spawn);
- }
- }
- }
- };
- module.exports = roleHarvesterRoom;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement