<commit_before>var roleArchitect = require('role.architect');
var bodyObj = require('module.bodyTypes');
var modCommon = require('module.common');
var modConstants = require('module.constants');
var modMemory = require('module.memory');

var modSpawning = {

  //These return booleans
  needHarvester:function(roomName){
    var roles = Memory.rooms[roomName].roles;

    var LTMin = roles.numHarvesters < roles.maxHarvesters;
    var tier = this.calcTier(roomName);

    return LTMin && tier<=3;
  },

  needUpgrader:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var LTMin = roles.numUpgraders < roles.maxUpgraders;
      return LTMin;
    }
  },

  needBuilder:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var tier = this.calcTier(roomName);
      var construct = Game.rooms[roomName].find(FIND_MY_CONSTRUCTION_SITES).length;
      var LTMin = roles.numBuilders < roles.maxBuilders;
      var noArch = roles.numArchitects === 0;
      return (tier > 1) && construct && LTMin && noArch;
    }
  },

  needRepair:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var numTowers = Memory.rooms[roomName].towers.length;
      var LTMin = roles.numRepair < (roles.maxRepair - numTowers);
      return LTMin;
    }
  },

  needArchitect:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var flags = _.filter(Game.rooms[roomName].find(FIND_FLAGS), (flag) => roleArchitect.ableToBuild(Game.rooms[roomName].controller.level, flag.name));

      return flags.length && roles.numArchitects < 1;
    }
  },

  needMiner:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var tier = this.calcTier(roomName);
      var sources = Memory.rooms[roomName].sourceIDs.length;
      var LTMin = roles.numMiners < sources;
      return (tier >= 4) && LTMin;
    }
  },
  needHauler:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var tier = this.calcTier(roomName);
      var LTMin = roles.numHaulers < roles.maxHaulers;
      return (tier >= 4) && LTMin;
    }
  },

  needFeeder:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var storage = Game.rooms[roomName].storage !== undefined;
      var LTMin = roles.numFeeders < roles.maxFeeders;
      return storage && LTMin;
    }
  },

  needGeoMiner:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var tier = this.calcTier(roomName);
      var LTMin = roles.numGeo < 1;

      var extractor = _.filter(Game.rooms[roomName].find(FIND_STRUCTURES), (structure) => structure.structureType === STRUCTURE_EXTRACTOR);
      var minerals = (_.filter(Game.rooms[roomName].find(FIND_MINERALS), (mineral) => mineral.mineralAmount > 0).length) > 0;

      return (tier >=4) && LTMin && extractor && minerals;
    }
  },

  needMerchant:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var tier = this.calcTier(roomName);
      var LTMin = roles.numMerchant < 1;

      var minerals = (_.filter(Game.rooms[roomName].find(FIND_MINERALS), (mineral) => mineral.mineralAmount > 0).length) > 0;
      var toSell = modCommon.whatStore(Game.rooms[roomName].storage) != RESOURCE_ENERGY;

      return !minerals && toSell && (tier >= 4) && LTMin;
    }
  },

  /* Add type to queue, full parameter list object
      Example:
      var memoryObj = {
        role:'harvester',
        selfHarvest:true,
        source:""
      };

      var harvesterObj = {
        description:"",
        body: null,
        name: undefined,
        memory:memoryObj
      };
  */
  enqueueHarvester:function(roomName){
    var tier = this.calcTier(roomName);
    var memoryObj = modMemory.getInitalCreepMem("harvester");

    var harvesterObj = {<commit_msg>null check in need Merchant<commit_after>var roleArchitect = require('role.architect');
var bodyObj = require('module.bodyTypes');
var modCommon = require('module.common');
var modConstants = require('module.constants');
var modMemory = require('module.memory');

var modSpawning = {

  //These return booleans
  needHarvester:function(roomName){
    var roles = Memory.rooms[roomName].roles;

    var LTMin = roles.numHarvesters < roles.maxHarvesters;
    var tier = this.calcTier(roomName);

    return LTMin && tier<=3;
  },

  needUpgrader:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var LTMin = roles.numUpgraders < roles.maxUpgraders;
      return LTMin;
    }
  },

  needBuilder:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var tier = this.calcTier(roomName);
      var construct = Game.rooms[roomName].find(FIND_MY_CONSTRUCTION_SITES).length;
      var LTMin = roles.numBuilders < roles.maxBuilders;
      var noArch = roles.numArchitects === 0;
      return (tier > 1) && construct && LTMin && noArch;
    }
  },

  needRepair:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var numTowers = Memory.rooms[roomName].towers.length;
      var LTMin = roles.numRepair < (roles.maxRepair - numTowers);
      return LTMin;
    }
  },

  needArchitect:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var flags = _.filter(Game.rooms[roomName].find(FIND_FLAGS), (flag) => roleArchitect.ableToBuild(Game.rooms[roomName].controller.level, flag.name));

      return flags.length && roles.numArchitects < 1;
    }
  },

  needMiner:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var tier = this.calcTier(roomName);
      var sources = Memory.rooms[roomName].sourceIDs.length;
      var LTMin = roles.numMiners < sources;
      return (tier >= 4) && LTMin;
    }
  },
  needHauler:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var tier = this.calcTier(roomName);
      var LTMin = roles.numHaulers < roles.maxHaulers;
      return (tier >= 4) && LTMin;
    }
  },

  needFeeder:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var storage = Game.rooms[roomName].storage !== undefined;
      var LTMin = roles.numFeeders < roles.maxFeeders;
      return storage && LTMin;
    }
  },

  needGeoMiner:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var tier = this.calcTier(roomName);
      var LTMin = roles.numGeo < 1;

      var extractor = _.filter(Game.rooms[roomName].find(FIND_STRUCTURES), (structure) => structure.structureType === STRUCTURE_EXTRACTOR);
      var minerals = (_.filter(Game.rooms[roomName].find(FIND_MINERALS), (mineral) => mineral.mineralAmount > 0).length) > 0;

      return (tier >=4) && LTMin && extractor && minerals;
    }
  },

  needMerchant:function(roomName){
    var roles = Memory.rooms[roomName].roles;
    var notEnoughHarvest = (roles.numHarvesters <= 0) && (roles.numMiners <= 0);

    if(notEnoughHarvest){
      return false;
    }else{
      var tier = this.calcTier(roomName);
      var LTMin = roles.numMerchant < 1;

      var minerals = (_.filter(Game.rooms[roomName].find(FIND_MINERALS), (mineral) => mineral.mineralAmount > 0).length) > 0;
      var toSell = Game.rooms[roomName].storage && modCommon.whatStore(Game.rooms[roomName].storage) != RESOURCE_ENERGY;

      return !minerals && toSell && (tier >= 4) && LTMin;
    }
  },

  /* Add type to queue, full parameter list object
      Example:
      var memoryObj = {
        role:'harvester',
        selfHarvest:true,
        source:""
      };

      var harvesterObj = {
        description:"",
        body: null,
        name: undefined,
        memory:memoryObj
      };
  */
  enqueueHarvester:function(roomName){
    var tier = this.calcTier(roomName);
    var memoryObj = modMemory.getInitalCreepMem("harvester");

    var harvesterObj = {
{'fraction_non_alphanumeric': 0.1352263701350278, 'fraction_numerical': 0.006354249404289118, 'mean_word_length': 3.1848774407976737, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 29, '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': '67142', 'n_tokens_mistral': 3557, 'n_tokens_neox': 3358, 'n_words': 651}