<commit_before>'use strict'

// Memory.territory

Room.getCities = function () {
  // When respawning the first room has to be autodetected, after which new cities will need to added.
  if (!Memory.territory || Object.keys(Memory.territory).length <= 0) {
    Memory.territory = {}
    for (let roomName of Object.keys(Game.rooms)) {
      const room = Game.rooms[roomName]
      if (room.controller && room.controller.my) {
        Memory.territory[roomName] = {}
      }
    }
  }
  return Object.keys(Memory.territory)
}

Room.addCity = function (roomName) {
  if (!Memory.territory[roomName]) {
    Memory.territory[roomName] = {}
    Logger.log(`Adding city ${roomName}`)
    qlib.events.recordEvent('addcity')
    qlib.notify.send(`Adding city ${roomName} to empire`)
  }
}

Room.removeCity = function (roomName) {
  if (Memory.territory && Memory.territory[roomName]) {
    delete Memory.territory[roomName]
    Logger.log(`Removing city ${roomName}`)
    qlib.notify.send(`Removing city ${roomName} from empire`)
  }
}

Room.isCity = function (roomName) {
  return Boolean(Memory.territory[roomName])
}

Room.prototype.getMines = function () {
  if (!Memory.territory || !Memory.territory[this.name]) {
    return []
  }
  if (!Memory.territory[this.name].mines) {
    return []
  }
  return Memory.territory[this.name].mines
}

Room.prototype.addMine = function (mine) {
  if (!Memory.territory || !Memory.territory[this.name]) {
    return false
  }
  if (!Memory.territory[this.name].mines) {
    Memory.territory[this.name].mines = []
  }
  Memory.territory[this.name].mines.push(mine)
  Logger.log(`Adding mine from ${this.name} to ${mine}`)
  qlib.events.recordEvent('addmine')
  qlib.notify.send(`Adding mine from ${this.name} to ${mine}`)
}

Room.prototype.removeMine = function (mine) {
  const id = this.getMineId()
  if (id < 0) {
    return
  }

  Logger.log(`Removing mine ${mine} from ${this.name}`)
  qlib.events.recordEvent('removemine')
  qlib.notify.send(`Removing mine ${mine} from ${this.name}`)
  Memory.territory[this.name].mines.splice(id, 1)
}

Room.prototype.getMineId = function (mine) {
  const id = Memory.territory[this.name].mines.indexOf(mine)
  return id >= 0 ? id : false
}

Room.getMineOwner = function (mine) {
  if (!Memory.territory) {
    return false
  }
  if (!this.mineMap) {
    this.mineMap = {}
  } else if (this.mineMap[mine]) {
    return this.mineMap[mine]
  }
  const roomNames = Object.keys(Memory.territory)
  let roomName
  for (roomName of roomNames) {<commit_msg>bugfix - pass mine to `getMineId` function, check for false<commit_after>'use strict'

// Memory.territory

Room.getCities = function () {
  // When respawning the first room has to be autodetected, after which new cities will need to added.
  if (!Memory.territory || Object.keys(Memory.territory).length <= 0) {
    Memory.territory = {}
    for (let roomName of Object.keys(Game.rooms)) {
      const room = Game.rooms[roomName]
      if (room.controller && room.controller.my) {
        Memory.territory[roomName] = {}
      }
    }
  }
  return Object.keys(Memory.territory)
}

Room.addCity = function (roomName) {
  if (!Memory.territory[roomName]) {
    Memory.territory[roomName] = {}
    Logger.log(`Adding city ${roomName}`)
    qlib.events.recordEvent('addcity')
    qlib.notify.send(`Adding city ${roomName} to empire`)
  }
}

Room.removeCity = function (roomName) {
  if (Memory.territory && Memory.territory[roomName]) {
    delete Memory.territory[roomName]
    Logger.log(`Removing city ${roomName}`)
    qlib.notify.send(`Removing city ${roomName} from empire`)
  }
}

Room.isCity = function (roomName) {
  return Boolean(Memory.territory[roomName])
}

Room.prototype.getMines = function () {
  if (!Memory.territory || !Memory.territory[this.name]) {
    return []
  }
  if (!Memory.territory[this.name].mines) {
    return []
  }
  return Memory.territory[this.name].mines
}

Room.prototype.addMine = function (mine) {
  if (!Memory.territory || !Memory.territory[this.name]) {
    return false
  }
  if (!Memory.territory[this.name].mines) {
    Memory.territory[this.name].mines = []
  }
  Memory.territory[this.name].mines.push(mine)
  Logger.log(`Adding mine from ${this.name} to ${mine}`)
  qlib.events.recordEvent('addmine')
  qlib.notify.send(`Adding mine from ${this.name} to ${mine}`)
}

Room.prototype.removeMine = function (mine) {
  const id = this.getMineId(mine)
  if (!id || id < 0) {
    return
  }

  Logger.log(`Removing mine ${mine} from ${this.name}`)
  qlib.events.recordEvent('removemine')
  qlib.notify.send(`Removing mine ${mine} from ${this.name}`)
  Memory.territory[this.name].mines.splice(id, 1)
}

Room.prototype.getMineId = function (mine) {
  const id = Memory.territory[this.name].mines.indexOf(mine)
  return id >= 0 ? id : false
}

Room.getMineOwner = function (mine) {
  if (!Memory.territory) {
    return false
  }
  if (!this.mineMap) {
    this.mineMap = {}
  } else if (this.mineMap[mine]) {
    return this.mineMap[mine]
  }
  const roomNames = Object.keys(Memory.territory)
  let roomName
  for (roomName of roomNames) {
{'fraction_non_alphanumeric': 0.15377081292850148, 'fraction_numerical': 0.0015670910871694416, 'mean_word_length': 3.6801099908340973, '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': '750969', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1702, 'n_words': 351}