<commit_before>/**Harvester role designed to gather source and return it.
 */

//Tell jshint (atom package) to stop showing certain irrelevent warnings.
/*jshint esversion: 6 */

//Begin module.
var roleHarvester = {

  /**Run function that executes the logic for this role.
   * @param {Creep} creep The creep that uses this role.
   */
  run: function(creep) {
      if (creep.carry.energy < creep.carryCapacity) {
        //If this harvester is not full of energy, go gather source.

        //let sources = creep.room.find(FIND_SOURCES);
        let closestSource = creep.pos.findClosestByPath(FIND_SOURCES);
        if (creep.harvest(closestSource) == ERR_NOT_IN_RANGE) {
          creep.moveTo(closestSource);
        }
      } else {
        //Find the closest structure that needs energy.
        let target = creep.pos.findClosestByPath(FIND_MY_STRUCTURES, {
          filter: (structure) => {
            return structure.structureType == STRUCTURE_EXTENSION ||
              structure.structureType == STRUCTURE_SPAWN ||
              structure.structureType == STRUCTURE_TOWER &&
              structure.energy < structure.energyCapacity;
          }
        });

        //Move to the target and return energy to it.
        if (target !== undefined && target !== null) {
          if (creep.transfer(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
            creep.moveTo(target);
          }
        }
      }
    } //End run function.
}; //End module.

//Make this module available to other modules.<commit_msg>Fixed issue where harvesters try to drop off energy at full structures.<commit_after>/**Harvester role designed to gather source and return it.
 */

//Tell jshint (atom package) to stop showing certain irrelevent warnings.
/*jshint esversion: 6 */

//Begin module.
var roleHarvester = {

  /**Run function that executes the logic for this role.
   * @param {Creep} creep The creep that uses this role.
   */
  run: function(creep) {
      if (creep.carry.energy < creep.carryCapacity) {
        //If this harvester is not full of energy, go gather source.

        //let sources = creep.room.find(FIND_SOURCES);
        let closestSource = creep.pos.findClosestByPath(FIND_SOURCES);
        if (creep.harvest(closestSource) == ERR_NOT_IN_RANGE) {
          creep.moveTo(closestSource);
        }
      } else {
        //Find the closest structure that needs energy.
        let target = creep.pos.findClosestByPath(FIND_MY_STRUCTURES, {
          filter: (structure) => {
            return (structure.structureType == STRUCTURE_EXTENSION ||
                structure.structureType == STRUCTURE_SPAWN ||
                structure.structureType == STRUCTURE_TOWER) &&
              structure.energy < structure.energyCapacity;
          }
        });

        //Move to the target and return energy to it.
        if (target !== undefined && target !== null) {
          if (creep.transfer(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
            creep.moveTo(target);
          }
        }
      }
    } //End run function.
}; //End module.

//Make this module available to other modules.
{'fraction_non_alphanumeric': 0.10288461538461538, 'fraction_numerical': 0.000641025641025641, 'mean_word_length': 2.345123258306538, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5868419', 'n_tokens_mistral': 919, 'n_tokens_neox': 892, 'n_words': 256}