diff --git a/.circleci/config.yml b/.circleci/config.yml index 85fdd91..b47b2a1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ jobs: build: working_directory: ~/quorum docker: - - image: circleci/node:6.11.1 + - image: circleci/node:12 steps: - checkout - restore_cache: diff --git a/gulpfile.js b/gulpfile.js index c866745..c7cb2dc 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,28 +1,27 @@ 'use strict' -let fs = require('fs') -let gulp = require('gulp') -let screeps = require('gulp-screeps') -let rename = require('gulp-rename') -let insert = require('gulp-insert') -let clean = require('gulp-clean') -let minimist = require('minimist') -let git = require('git-rev-sync') +const fs = require('fs') +const gulp = require('gulp') +const screeps = require('gulp-screeps') +const rename = require('gulp-rename') +const insert = require('gulp-insert') +const del = require('del') +const minimist = require('minimist') +const git = require('git-rev-sync') -let args = minimist(process.argv.slice(2)) -let commitdate = git.date() +const args = minimist(process.argv.slice(2)) +const commitdate = git.date() gulp.task('clean', () => { - return gulp.src('dist/', { read: false }).pipe(clean()) + return del('dist/*') }) -gulp.task('copy', ['clean'], () => { - let src - src = gulp.src('src/**/*.js') +gulp.task('copy', gulp.series('clean', () => { + const src = gulp.src('src/**/*.js') return src.pipe(rename((path) => { - let parts = path.dirname.match(/[^/\\]+/g) + const parts = path.dirname.match(/[^/\\]+/g) let name = '' - for (let i in parts) { + for (const i in parts) { if (parts[i] !== '.') { name += parts[i] + '_' } @@ -38,20 +37,20 @@ gulp.task('copy', ['clean'], () => { } return contents })).pipe(gulp.dest('dist/')) -}) +})) function deploy () { - let config = require('./.screeps.json') - let opts = config[args.server || 'main'] - let options = {} + const config = require('./.screeps.json') + const opts = config[args.server || 'main'] + const options = {} if (!opts) { - let err = new Error(`No configuration exists for server "${args.server || 'main'}`) + const err = new Error(`No configuration exists for server "${args.server || 'main'}`) err.showStack = false throw err } // allow overrides from passed arguments - for (let i in args) { // jshint ignore:line + for (const i in args) { // jshint ignore:line opts[i] = args[i] } @@ -76,11 +75,21 @@ function deploy () { return gulp.src('dist/*.js').pipe(screeps(options)) } -gulp.task('deploy', ['copy'], () => { +gulp.task('deploy', gulp.series('copy', () => { return deploy() +})) + +gulp.task('ci-version', (cb) => { + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')) + const seconds = (commitdate.getHours() * 3600) + (commitdate.getMinutes() * 60) + commitdate.getSeconds() + const year = commitdate.getFullYear() + const month = commitdate.getMonth() + 1 + const day = commitdate.getDate() + pkg.version = `${year}.${month}.${day}-${seconds}` + fs.writeFile('package.json', JSON.stringify(pkg, null, 2), cb) }) -gulp.task('ci-config', ['ci-version'], (cb) => { +gulp.task('ci-config', gulp.series('ci-version', (cb) => { fs.writeFile('.screeps.json', JSON.stringify({ main: { ptr: !!process.env.SCREEPS_PTR, @@ -91,16 +100,6 @@ gulp.task('ci-config', ['ci-version'], (cb) => { port: process.env.SCREEPS_PORT } }), cb) -}) - -gulp.task('ci-version', (cb) => { - let pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')) - let seconds = (commitdate.getHours() * 3600) + (commitdate.getMinutes() * 60) + commitdate.getSeconds() - let year = commitdate.getFullYear() - let month = commitdate.getMonth() + 1 - let day = commitdate.getDate() - pkg.version = `${year}.${month}.${day}-${seconds}` - fs.writeFile('package.json', JSON.stringify(pkg, null, 2), cb) -}) +})) -gulp.task('default', ['clean', 'copy', 'deploy']) +gulp.task('default', gulp.series('deploy')) diff --git a/package.json b/package.json index d9fc135..92ff1cf 100644 --- a/package.json +++ b/package.json @@ -14,25 +14,25 @@ "main": "dist/main.js", "repository": "ScreepsQuorum/screeps-quorum", "scripts": { - "test": "standard && ava test", - "testci": "standard && ava test --tap | tap-xunit > test-results.xml", - "watch": "ava test --watch", + "test": "standard && npx ava", + "testci": "standard && npx ava --tap | tap-xunit > test-results.xml", + "watch": "npx ava --watch", "deploy": "gulp", "ci-config": "gulp ci-config", "2npm": "npm publish" }, "dependencies": {}, "devDependencies": { - "ava": "^0.22.0", - "git-rev-sync": "^1.9.1", - "gulp": "^3.9.1", - "gulp-clean": "^0.3.2", + "ava": "^3.5.0", + "del": "^5.1.0", + "git-rev-sync": "^2.0.0", + "gulp": "^4.0.2", "gulp-insert": "^0.5.0", - "gulp-rename": "^1.2.2", - "gulp-screeps": "^1.0.6", - "minimist": "^1.2.0", - "standard": "^10.0.3", - "tap-xunit": "^1.7.0" + "gulp-rename": "^2.0.0", + "gulp-screeps": "^1.0.8", + "minimist": "^1.2.5", + "standard": "^14.3.2", + "tap-xunit": "^2.4.1" }, "screeps_bot": true, "standard": { diff --git a/src/extends/creep.js b/src/extends/creep.js index 0cb72bb..94734e1 100644 --- a/src/extends/creep.js +++ b/src/extends/creep.js @@ -1,7 +1,7 @@ 'use strict' Creep.getRole = function (roleName) { - let Role = require('roles_' + roleName) + const Role = require('roles_' + roleName) return new Role() } @@ -11,7 +11,7 @@ Creep.getRoleFromName = function (creepname) { Creep.prototype.getRole = function () { // If the creep role isn't in memory grab it based off of the name - let roleType = this.memory.role ? this.memory.role : this.name.split('_', 1)[0] + const roleType = this.memory.role ? this.memory.role : this.name.split('_', 1)[0] return Creep.getRole(roleType) } @@ -29,9 +29,9 @@ Creep.getCost = function (parts) { } Creep.buildFromTemplate = function (template, energy) { - let parts = [] + const parts = [] while (energy > 0 && parts.length < 50) { - let next = template[parts.length % template.length] + const next = template[parts.length % template.length] if (BODYPART_COST[next] > energy) { break } diff --git a/src/extends/creep/actions.js b/src/extends/creep/actions.js index e1dcc37..2368e6b 100644 --- a/src/extends/creep/actions.js +++ b/src/extends/creep/actions.js @@ -40,35 +40,37 @@ Creep.prototype.recharge = function () { return true } // Create a bigger scope for this variable ( used here and in the filter in containers ) - let carryCap = this.carryCapacity + const carryCap = this.carryCapacity // Check for qualifying dropped energy. - const resources = this.room.find(FIND_DROPPED_RESOURCES, {filter: function (resource) { - if (resource.resourceType !== RESOURCE_ENERGY || resource.amount < carryCap) { - return false - } + const resources = this.room.find(FIND_DROPPED_RESOURCES, { + filter: function (resource) { + if (resource.resourceType !== RESOURCE_ENERGY || resource.amount < carryCap) { + return false + } - // Is resource on top of container? - const structures = resource.pos.lookFor(LOOK_STRUCTURES) - for (let structure of structures) { - if (structure.structureType === STRUCTURE_CONTAINER) { + // Is resource on top of container? + const structures = resource.pos.lookFor(LOOK_STRUCTURES) + for (const structure of structures) { + if (structure.structureType === STRUCTURE_CONTAINER) { + return true + } + } + + // Is the resource near the room storage? + if (resource.room.storage && resource.room.storage.pos.getRangeTo(resource) <= 2) { return true } - } - // Is the resource near the room storage? - if (resource.room.storage && resource.room.storage.pos.getRangeTo(resource) <= 2) { - return true - } + // Is the resource on top of the suicide booth? + const suicideBooth = resource.room.getSuicideBooth() + if (suicideBooth && resource.pos.getRangeTo(suicideBooth) === 0) { + return true + } - // Is the resource on top of the suicide booth? - const suicideBooth = resource.room.getSuicideBooth() - if (suicideBooth && resource.pos.getRangeTo(suicideBooth) === 0) { - return true + return false } - - return false - }}) + }) if (resources.length > 0) { const resource = this.pos.findClosestByRange(resources) @@ -146,7 +148,7 @@ Creep.prototype.recycle = function () { if (this.pos.getRangeTo(suicideBooth) > 0) { this.travelTo(suicideBooth) } else { - let spawn = this.pos.findClosestByRange(this.room.structures[STRUCTURE_SPAWN]) + const spawn = this.pos.findClosestByRange(this.room.structures[STRUCTURE_SPAWN]) spawn.recycleCreep(this) } } diff --git a/src/extends/creep/movement.js b/src/extends/creep/movement.js index d6628b0..62f5ff1 100644 --- a/src/extends/creep/movement.js +++ b/src/extends/creep/movement.js @@ -5,12 +5,12 @@ const defaultMaxOpsPerRoom = 1500 const struckThreshold = 2 const struckRerouteThreshold = 4 const travelToDefaults = { - 'reusePath': 1500, - 'moveToOverride': true, - 'ignoreStuck': false, - 'ignoreHostileCities': true, - 'ignoreHostileReservations': false, - 'avoidHostileRooms': false + reusePath: 1500, + moveToOverride: true, + ignoreStuck: false, + ignoreHostileCities: true, + ignoreHostileReservations: false, + avoidHostileRooms: false } Creep.prototype.travelTo = function (pos, opts = {}) { @@ -40,10 +40,10 @@ Creep.prototype.travelTo = function (pos, opts = {}) { moveToOpts.avoidHostileRooms = true } else { if (moveToOpts.ignoreHostileCities) { - moveToOpts.scores['WEIGHT_HOSTILE'] = Infinity + moveToOpts.scores.WEIGHT_HOSTILE = Infinity } if (moveToOpts.ignoreHostileReservations) { - moveToOpts.scores['WEIGHT_HOSTILE_RESERVATION'] = Infinity + moveToOpts.scores.WEIGHT_HOSTILE_RESERVATION = Infinity } } } @@ -106,9 +106,9 @@ Creep.prototype.travelTo = function (pos, opts = {}) { if (Number.isInteger(worldRoute)) { return worldRoute } - for (let pathPiece of worldRoute) { - if (moveToOpts.allowedRooms.indexOf(pathPiece['room']) < 0) { - moveToOpts.allowedRooms.push(pathPiece['room']) + for (const pathPiece of worldRoute) { + if (moveToOpts.allowedRooms.indexOf(pathPiece.room) < 0) { + moveToOpts.allowedRooms.push(pathPiece.room) } } } diff --git a/src/extends/mineral.js b/src/extends/mineral.js index 0bf1fe8..c9924a7 100644 --- a/src/extends/mineral.js +++ b/src/extends/mineral.js @@ -6,9 +6,9 @@ Mineral.getEmpireRatio = function () { return this.mineralRatio } const rooms = Room.getCities() - let resources = {} + const resources = {} let max = 0 - for (let room of rooms) { + for (const room of rooms) { const roomIntel = Room.getIntel(room) if (!roomIntel[INTEL_MINERAL]) { continue @@ -26,8 +26,8 @@ Mineral.getEmpireRatio = function () { max = resources[resourceType] } } - let ratio = {} - for (let resourceType of MINERALS_EXTRACTABLE) { + const ratio = {} + for (const resourceType of MINERALS_EXTRACTABLE) { if (!resources[resourceType]) { ratio[resourceType] = 0 } else { diff --git a/src/extends/room/alchemy.js b/src/extends/room/alchemy.js index 7f8a1aa..c1fba04 100644 --- a/src/extends/room/alchemy.js +++ b/src/extends/room/alchemy.js @@ -42,7 +42,7 @@ Room.prototype.getVatLabs = function () { return false } - let vats = [] + const vats = [] for (const lab of labs) { if (feeders[0].id === lab.id || feeders[1].id === lab.id) { continue @@ -77,10 +77,10 @@ Room.prototype.getNextReaction = function () { // Has Catalyst if (this.storage.store[RESOURCE_CATALYST] && this.storage.store[RESOURCE_CATALYST] > 1000) { - if (storageByType['tier2'] && storageByType['tier2'].length > 0) { + if (storageByType.tier2 && storageByType.tier2.length > 0) { let need = 0 let resource = false - for (const option of storageByType['tier2']) { + for (const option of storageByType.tier2) { if (this.storage.store[option] < 1000) { continue } @@ -99,10 +99,10 @@ Room.prototype.getNextReaction = function () { // Has OH if (this.storage.store[RESOURCE_HYDROXIDE] && this.storage.store[RESOURCE_HYDROXIDE] > 1000) { - if (storageByType['tier1'] && storageByType['tier1'].length > 0) { + if (storageByType.tier1 && storageByType.tier1.length > 0) { let need = 0 let resource = false - for (const option of storageByType['tier1']) { + for (const option of storageByType.tier1) { if (this.storage.store[option] < 1000) { continue } diff --git a/src/extends/room/construction.js b/src/extends/room/construction.js index ac30a7e..135bc24 100644 --- a/src/extends/room/construction.js +++ b/src/extends/room/construction.js @@ -194,9 +194,9 @@ Room.prototype.getNextMissingStructureType = function () { continue } } - let currentStructures = structureCount[structureType] || 0 - let constructionStructures = constructionCount[structureType] || 0 - let totalStructures = currentStructures + constructionStructures + const currentStructures = structureCount[structureType] || 0 + const constructionStructures = constructionCount[structureType] || 0 + const totalStructures = currentStructures + constructionStructures if (totalStructures >= LEVEL_BREAKDOWN[this.controller.level][structureType]) { continue @@ -243,7 +243,7 @@ Room.prototype.getConstructionCount = function (constructionFind = FIND_MY_CONST } Room.prototype.getPracticalRoomLevel = function () { - let prl = sos.lib.cache.get(`${this.name}.prl`) + const prl = sos.lib.cache.get(`${this.name}.prl`) if (prl) { return prl } @@ -376,7 +376,7 @@ class RoomLayout { for (type of types) { for (structurePos of structures[type]) { visual.structure(structurePos.x, structurePos.y, type, { - 'opacity': 0.60 + opacity: 0.60 }) } } @@ -412,7 +412,7 @@ Room.prototype.getDefenseMap = function () { return Room.getDefenseMap(this.name) } -let defenseColors = {} +const defenseColors = {} global.RAMPART_PATHWAY = 1 defenseColors[RAMPART_PATHWAY] = '#EEEE88' @@ -465,17 +465,17 @@ class DefenseMap extends RoomLayout { const structures = layout.getAllStructures() const map = this.structureMap // Add Structure and Pathway ramparts. - let pathways = [] - for (let structureType of Object.keys(structures)) { + const pathways = [] + for (const structureType of Object.keys(structures)) { if (excludeStructures.includes(structureType)) { continue } const type = primaryStructures.includes(structureType) ? RAMPART_PRIMARY_STRUCTURES : RAMPART_SECONDARY_STRUCTURES - for (let structurePosition of structures[structureType]) { + for (const structurePosition of structures[structureType]) { map.set(structurePosition.x, structurePosition.y, type) - let distance = structureType === STRUCTURE_SPAWN ? pathwaySpawnDistance : pathwayDistance - let neighbors = structurePosition.getSteppableAdjacentInRange(distance) - for (let neighbor of neighbors) { + const distance = structureType === STRUCTURE_SPAWN ? pathwaySpawnDistance : pathwayDistance + const neighbors = structurePosition.getSteppableAdjacentInRange(distance) + for (const neighbor of neighbors) { const structure = layout.getStructureAt(neighbor.x, neighbor.y) if (!structure || excludeStructures.includes(structure)) { map.set(neighbor.x, neighbor.y, RAMPART_PATHWAY) @@ -487,7 +487,7 @@ class DefenseMap extends RoomLayout { // Add controller ramparts and pathways (if paths are enabled for controllers). const controllerRange = controllerPathway < 1 ? 1 : controllerPathway const controllerNeighbors = room.controller.pos.getSteppableAdjacentInRange(controllerRange) - for (let neighbor of controllerNeighbors) { + for (const neighbor of controllerNeighbors) { const type = room.controller.pos.getRangeTo(neighbor) > 1 ? RAMPART_PATHWAY : RAMPART_CONTROLLER if (type === RAMPART_PATHWAY) { pathways.push(neighbor) @@ -497,9 +497,9 @@ class DefenseMap extends RoomLayout { // Detect edges from existing pathways const walkableMap = this._getWalkableMap(room, map) - for (let position of pathways) { + for (const position of pathways) { const neighbors = position.getSteppableAdjacent() - for (let neighbor of neighbors) { + for (const neighbor of neighbors) { if (walkableMap.get(neighbor.x, neighbor.y) === REACHABLE_SPACE) { map.set(position.x, position.y, RAMPART_EDGE) break @@ -510,24 +510,24 @@ class DefenseMap extends RoomLayout { // plan walls around each exit, hugging them directly. // This *has* to be done after edge calculatons const exits = this.roomname === 'sim' ? ['1', '3', '5', '7'] - : Object.keys(Game.map.describeExits(this.roomname)) + : Object.keys(Game.map.describeExits(this.roomname)) // eslint-disable-line indent for (let exit of exits) { exit = parseInt(exit) const pieces = this._getExitPieces(exit) - for (let piece of pieces) { + for (const piece of pieces) { const horizontal = (exit === TOP || exit === BOTTOM) if (horizontal) { - let endpointOffset = exit === TOP ? 1 : -1 - let y = piece[0].y - let left1 = new RoomPosition(piece[0].x - 1, y, this.roomname) - let left2 = new RoomPosition(piece[0].x - 2, y, this.roomname) + const endpointOffset = exit === TOP ? 1 : -1 + const y = piece[0].y + const left1 = new RoomPosition(piece[0].x - 1, y, this.roomname) + const left2 = new RoomPosition(piece[0].x - 2, y, this.roomname) if (this.terrain.get(piece[0].x - 2, y + endpointOffset) !== TERRAIN_MASK_WALL) { map.set(piece[0].x - 2, y + endpointOffset, WALL_GATEWAY) } - let lastPiece = piece.length - 1 - let right1 = new RoomPosition(piece[lastPiece].x + 1, y, this.roomname) - let right2 = new RoomPosition(piece[lastPiece].x + 2, y, this.roomname) + const lastPiece = piece.length - 1 + const right1 = new RoomPosition(piece[lastPiece].x + 1, y, this.roomname) + const right2 = new RoomPosition(piece[lastPiece].x + 2, y, this.roomname) if (this.terrain.get(piece[lastPiece].x + 2, y + endpointOffset) !== TERRAIN_MASK_WALL) { map.set(piece[lastPiece].x + 2, y + endpointOffset, WALL_GATEWAY) } @@ -536,16 +536,16 @@ class DefenseMap extends RoomLayout { piece.push(right1) piece.push(right2) } else { - let endpointOffset = exit === LEFT ? 1 : -1 - let x = piece[0].x - let top1 = new RoomPosition(x, piece[0].y - 1, this.roomname) - let top2 = new RoomPosition(x, piece[0].y - 2, this.roomname) + const endpointOffset = exit === LEFT ? 1 : -1 + const x = piece[0].x + const top1 = new RoomPosition(x, piece[0].y - 1, this.roomname) + const top2 = new RoomPosition(x, piece[0].y - 2, this.roomname) if (this.terrain.get(x + endpointOffset, piece[0].y - 2) !== TERRAIN_MASK_WALL) { map.set(x + endpointOffset, piece[0].y - 2, WALL_GATEWAY) } - let lastPiece = piece.length - 1 - let bottom1 = new RoomPosition(x, piece[lastPiece].y + 1, this.roomname) - let bottom2 = new RoomPosition(x, piece[lastPiece].y + 2, this.roomname) + const lastPiece = piece.length - 1 + const bottom1 = new RoomPosition(x, piece[lastPiece].y + 1, this.roomname) + const bottom2 = new RoomPosition(x, piece[lastPiece].y + 2, this.roomname) if (this.terrain.get(x + endpointOffset, piece[lastPiece].y + 2) !== TERRAIN_MASK_WALL) { map.set(x + endpointOffset, piece[lastPiece].y + 2, WALL_GATEWAY) } @@ -555,7 +555,7 @@ class DefenseMap extends RoomLayout { piece.push(bottom2) } - let set = (position, type) => { + const set = (position, type) => { let x, x1, x2 let y, y1, y2 if (horizontal) { @@ -604,7 +604,7 @@ class DefenseMap extends RoomLayout { } _getExitPieces (exit) { - let vertical = exit === LEFT || exit === RIGHT + const vertical = exit === LEFT || exit === RIGHT let stationary if (vertical) { stationary = exit === LEFT ? 0 : 49 @@ -612,7 +612,7 @@ class DefenseMap extends RoomLayout { stationary = exit === TOP ? 0 : 49 } - let pieces = [] + const pieces = [] let currentPiece = [] for (var i = 0; i <= 49; i++) { const x = vertical ? stationary : i @@ -633,19 +633,19 @@ class DefenseMap extends RoomLayout { // Using a room and a rampart map (CostMatrix) this generates a list of positions reachable from an exit. _getWalkableMap (room, map) { - let tested = [] - let queue = [] - let walkableMap = new PathFinder.CostMatrix() + const tested = [] + const queue = [] + const walkableMap = new PathFinder.CostMatrix() // Add exit squares as starting points. - let exits = room.find(FIND_EXIT) - for (let exit of exits) { + const exits = room.find(FIND_EXIT) + for (const exit of exits) { walkableMap.set(exit.x, exit.y, QUEUED_SPACE) queue.push(exit) } while (queue.length > 0) { - let current = queue.pop() + const current = queue.pop() tested.push(current.serialize()) // If the value is greater than zero it has already been tested or is blocked by ramparts @@ -657,8 +657,8 @@ class DefenseMap extends RoomLayout { walkableMap.set(current.x, current.y, REACHABLE_SPACE) // Add the walkable neighbors into the queue after checking that they haven't been added or tested already - let neighbors = current.getSteppableAdjacent() - for (let neighbor of neighbors) { + const neighbors = current.getSteppableAdjacent() + for (const neighbor of neighbors) { if (walkableMap.get(neighbor.x, neighbor.y) >= QUEUED_SPACE) { continue } @@ -688,11 +688,11 @@ class DefenseMap extends RoomLayout { if (!defenseColors[type]) { continue } - let structureType = type === WALL_GATEWAY ? STRUCTURE_WALL : STRUCTURE_RAMPART + const structureType = type === WALL_GATEWAY ? STRUCTURE_WALL : STRUCTURE_RAMPART for (structurePos of structures[type]) { visual.structure(structurePos.x, structurePos.y, structureType, { - 'opacity': 0.60, - 'rampart': defenseColors[type] + opacity: 0.60, + rampart: defenseColors[type] }) } } diff --git a/src/extends/room/control.js b/src/extends/room/control.js index f9453fc..8c5a1d2 100644 --- a/src/extends/room/control.js +++ b/src/extends/room/control.js @@ -2,99 +2,99 @@ // Each key corresponds to the current practical room level and contains a separate objects containing settings enabled // at that level. Each higher level inherits the settings from the level below it. -let roomLevelOptions = { +const roomLevelOptions = { 1: { - 'UPGRADERS_QUANTITY': 5, - 'RESERVER_COUNT': 0, - 'SCOUTS': true, - 'SKIP_STRUCTURE_ROAD': true, - 'SKIP_STRUCTURE_CONTAINER': true + UPGRADERS_QUANTITY: 5, + RESERVER_COUNT: 0, + SCOUTS: true, + SKIP_STRUCTURE_ROAD: true, + SKIP_STRUCTURE_CONTAINER: true }, 2: {}, 3: { - 'PURE_CARRY_FILLERS': true, - 'ADDITIONAL_FILLERS': true, - 'SELF_SUFFICIENT': true, - 'REMOTE_MINES': 1, - 'SKIP_STRUCTURE_CONTAINER': false + PURE_CARRY_FILLERS: true, + ADDITIONAL_FILLERS: true, + SELF_SUFFICIENT: true, + REMOTE_MINES: 1, + SKIP_STRUCTURE_CONTAINER: false }, 4: { - 'DEDICATED_MINERS': true, - 'ADDITIONAL_FILLERS': false, - 'RESERVER_COUNT': 3, - 'REMOTE_MINES': 2, - 'EXPAND_FROM': true, - 'ALLOW_MINING_SCALEBACK': true, - 'SKIP_STRUCTURE_ROAD': false + DEDICATED_MINERS: true, + ADDITIONAL_FILLERS: false, + RESERVER_COUNT: 3, + REMOTE_MINES: 2, + EXPAND_FROM: true, + ALLOW_MINING_SCALEBACK: true, + SKIP_STRUCTURE_ROAD: false }, 5: {}, 6: { - 'EXTRACT_MINERALS': true, - 'RESERVER_COUNT': 2, - 'UPGRADERS_QUANTITY': 3, - 'LABS': true + EXTRACT_MINERALS: true, + RESERVER_COUNT: 2, + UPGRADERS_QUANTITY: 3, + LABS: true }, 7: { - 'RESERVER_COUNT': 1, - 'ALLOW_MINING_SCALEBACK': false, - 'ALWAYS_SAFEMODE': true + RESERVER_COUNT: 1, + ALLOW_MINING_SCALEBACK: false, + ALWAYS_SAFEMODE: true }, 8: { - 'UPGRADERS_QUANTITY': 1, - 'REMOTE_MINES': 3, - 'SHARE_ENERGY': true + UPGRADERS_QUANTITY: 1, + REMOTE_MINES: 3, + SHARE_ENERGY: true } } -roomLevelOptions[4]['RAMPART_LEVELS'] = {} -roomLevelOptions[4]['RAMPART_LEVELS'][RAMPART_PATHWAY] = 0 -roomLevelOptions[4]['RAMPART_LEVELS'][RAMPART_EDGE] = 0 -roomLevelOptions[4]['RAMPART_LEVELS'][RAMPART_PRIMARY_STRUCTURES] = 0 -roomLevelOptions[4]['RAMPART_LEVELS'][RAMPART_SECONDARY_STRUCTURES] = 0 -roomLevelOptions[4]['RAMPART_LEVELS'][RAMPART_CONTROLLER] = 0 -roomLevelOptions[4]['RAMPART_LEVELS'][RAMPART_GATEWAY] = 0 -roomLevelOptions[4]['RAMPART_LEVELS'][WALL_GATEWAY] = 0 +roomLevelOptions[4].RAMPART_LEVELS = {} +roomLevelOptions[4].RAMPART_LEVELS[RAMPART_PATHWAY] = 0 +roomLevelOptions[4].RAMPART_LEVELS[RAMPART_EDGE] = 0 +roomLevelOptions[4].RAMPART_LEVELS[RAMPART_PRIMARY_STRUCTURES] = 0 +roomLevelOptions[4].RAMPART_LEVELS[RAMPART_SECONDARY_STRUCTURES] = 0 +roomLevelOptions[4].RAMPART_LEVELS[RAMPART_CONTROLLER] = 0 +roomLevelOptions[4].RAMPART_LEVELS[RAMPART_GATEWAY] = 0 +roomLevelOptions[4].RAMPART_LEVELS[WALL_GATEWAY] = 0 -roomLevelOptions[5]['RAMPART_LEVELS'] = {} -roomLevelOptions[5]['RAMPART_LEVELS'][RAMPART_PATHWAY] = 0 -roomLevelOptions[5]['RAMPART_LEVELS'][RAMPART_EDGE] = 0 -roomLevelOptions[5]['RAMPART_LEVELS'][RAMPART_PRIMARY_STRUCTURES] = 0 -roomLevelOptions[5]['RAMPART_LEVELS'][RAMPART_SECONDARY_STRUCTURES] = 0 -roomLevelOptions[5]['RAMPART_LEVELS'][RAMPART_CONTROLLER] = 0 -roomLevelOptions[5]['RAMPART_LEVELS'][RAMPART_GATEWAY] = 0 -roomLevelOptions[5]['RAMPART_LEVELS'][WALL_GATEWAY] = 0 +roomLevelOptions[5].RAMPART_LEVELS = {} +roomLevelOptions[5].RAMPART_LEVELS[RAMPART_PATHWAY] = 0 +roomLevelOptions[5].RAMPART_LEVELS[RAMPART_EDGE] = 0 +roomLevelOptions[5].RAMPART_LEVELS[RAMPART_PRIMARY_STRUCTURES] = 0 +roomLevelOptions[5].RAMPART_LEVELS[RAMPART_SECONDARY_STRUCTURES] = 0 +roomLevelOptions[5].RAMPART_LEVELS[RAMPART_CONTROLLER] = 0 +roomLevelOptions[5].RAMPART_LEVELS[RAMPART_GATEWAY] = 0 +roomLevelOptions[5].RAMPART_LEVELS[WALL_GATEWAY] = 0 -roomLevelOptions[6]['RAMPART_LEVELS'] = {} -roomLevelOptions[6]['RAMPART_LEVELS'][RAMPART_PATHWAY] = 0 -roomLevelOptions[6]['RAMPART_LEVELS'][RAMPART_EDGE] = 0 -roomLevelOptions[6]['RAMPART_LEVELS'][RAMPART_PRIMARY_STRUCTURES] = 3000000 -roomLevelOptions[6]['RAMPART_LEVELS'][RAMPART_SECONDARY_STRUCTURES] = 0 -roomLevelOptions[6]['RAMPART_LEVELS'][RAMPART_CONTROLLER] = 0 -roomLevelOptions[6]['RAMPART_LEVELS'][RAMPART_GATEWAY] = 0 -roomLevelOptions[6]['RAMPART_LEVELS'][WALL_GATEWAY] = 0 +roomLevelOptions[6].RAMPART_LEVELS = {} +roomLevelOptions[6].RAMPART_LEVELS[RAMPART_PATHWAY] = 0 +roomLevelOptions[6].RAMPART_LEVELS[RAMPART_EDGE] = 0 +roomLevelOptions[6].RAMPART_LEVELS[RAMPART_PRIMARY_STRUCTURES] = 3000000 +roomLevelOptions[6].RAMPART_LEVELS[RAMPART_SECONDARY_STRUCTURES] = 0 +roomLevelOptions[6].RAMPART_LEVELS[RAMPART_CONTROLLER] = 0 +roomLevelOptions[6].RAMPART_LEVELS[RAMPART_GATEWAY] = 0 +roomLevelOptions[6].RAMPART_LEVELS[WALL_GATEWAY] = 0 -roomLevelOptions[7]['RAMPART_LEVELS'] = {} -roomLevelOptions[7]['RAMPART_LEVELS'][RAMPART_PATHWAY] = 0 -roomLevelOptions[7]['RAMPART_LEVELS'][RAMPART_EDGE] = 1500000 -roomLevelOptions[7]['RAMPART_LEVELS'][RAMPART_PRIMARY_STRUCTURES] = 3000000 -roomLevelOptions[7]['RAMPART_LEVELS'][RAMPART_SECONDARY_STRUCTURES] = 0 -roomLevelOptions[7]['RAMPART_LEVELS'][RAMPART_CONTROLLER] = 0 -roomLevelOptions[7]['RAMPART_LEVELS'][RAMPART_GATEWAY] = 0 -roomLevelOptions[7]['RAMPART_LEVELS'][WALL_GATEWAY] = 0 +roomLevelOptions[7].RAMPART_LEVELS = {} +roomLevelOptions[7].RAMPART_LEVELS[RAMPART_PATHWAY] = 0 +roomLevelOptions[7].RAMPART_LEVELS[RAMPART_EDGE] = 1500000 +roomLevelOptions[7].RAMPART_LEVELS[RAMPART_PRIMARY_STRUCTURES] = 3000000 +roomLevelOptions[7].RAMPART_LEVELS[RAMPART_SECONDARY_STRUCTURES] = 0 +roomLevelOptions[7].RAMPART_LEVELS[RAMPART_CONTROLLER] = 0 +roomLevelOptions[7].RAMPART_LEVELS[RAMPART_GATEWAY] = 0 +roomLevelOptions[7].RAMPART_LEVELS[WALL_GATEWAY] = 0 -roomLevelOptions[8]['RAMPART_LEVELS'] = {} -roomLevelOptions[8]['RAMPART_LEVELS'][RAMPART_PATHWAY] = 0 -roomLevelOptions[8]['RAMPART_LEVELS'][RAMPART_EDGE] = 30000000 -roomLevelOptions[8]['RAMPART_LEVELS'][RAMPART_PRIMARY_STRUCTURES] = 3000000 -roomLevelOptions[8]['RAMPART_LEVELS'][RAMPART_SECONDARY_STRUCTURES] = 0 -roomLevelOptions[8]['RAMPART_LEVELS'][RAMPART_CONTROLLER] = 30000000 -roomLevelOptions[8]['RAMPART_LEVELS'][RAMPART_GATEWAY] = 0 -roomLevelOptions[8]['RAMPART_LEVELS'][WALL_GATEWAY] = 0 +roomLevelOptions[8].RAMPART_LEVELS = {} +roomLevelOptions[8].RAMPART_LEVELS[RAMPART_PATHWAY] = 0 +roomLevelOptions[8].RAMPART_LEVELS[RAMPART_EDGE] = 30000000 +roomLevelOptions[8].RAMPART_LEVELS[RAMPART_PRIMARY_STRUCTURES] = 3000000 +roomLevelOptions[8].RAMPART_LEVELS[RAMPART_SECONDARY_STRUCTURES] = 0 +roomLevelOptions[8].RAMPART_LEVELS[RAMPART_CONTROLLER] = 30000000 +roomLevelOptions[8].RAMPART_LEVELS[RAMPART_GATEWAY] = 0 +roomLevelOptions[8].RAMPART_LEVELS[WALL_GATEWAY] = 0 // Have each level inherit the settings from the previous level unless already set. for (let level = 2; level <= 8; level++) { const keys = Object.keys(roomLevelOptions[level - 1]) - for (let key of keys) { + for (const key of keys) { if (typeof roomLevelOptions[level][key] === 'undefined') { roomLevelOptions[level][key] = roomLevelOptions[level - 1][key] } diff --git a/src/extends/room/economy.js b/src/extends/room/economy.js index d7c51b8..49425a3 100644 --- a/src/extends/room/economy.js +++ b/src/extends/room/economy.js @@ -9,40 +9,40 @@ global.ECONOMY_BURSTING = 5 // Will return true for economic levels at or above these values. const economySettings = { - 'SUPPLY_TERMINAL': ECONOMY_FALTERING, - 'MAINTAIN_STRUCTURES': ECONOMY_FALTERING, - 'REMOTE_MINES': ECONOMY_FALTERING, + SUPPLY_TERMINAL: ECONOMY_FALTERING, + MAINTAIN_STRUCTURES: ECONOMY_FALTERING, + REMOTE_MINES: ECONOMY_FALTERING, - 'EXPAND_FROM': ECONOMY_DEVELOPING, - 'BUILD_STRUCTURES': ECONOMY_DEVELOPING, + EXPAND_FROM: ECONOMY_DEVELOPING, + BUILD_STRUCTURES: ECONOMY_DEVELOPING, - 'EXTRACT_MINERALS': ECONOMY_STABLE, - 'UPGRADE_CONTROLLERS': ECONOMY_STABLE, - 'WALLBUILDERS': ECONOMY_STABLE, + EXTRACT_MINERALS: ECONOMY_STABLE, + UPGRADE_CONTROLLERS: ECONOMY_STABLE, + WALLBUILDERS: ECONOMY_STABLE, - 'EXTRA_UPGRADERS': ECONOMY_SURPLUS, - 'SHARE_ENERGY': ECONOMY_SURPLUS, + EXTRA_UPGRADERS: ECONOMY_SURPLUS, + SHARE_ENERGY: ECONOMY_SURPLUS, - 'EXTRA_WALLBUILDERS': ECONOMY_BURSTING, - 'MORE_EXTRA_UPGRADERS': ECONOMY_BURSTING, - 'DUMP_ENERGY': ECONOMY_BURSTING + EXTRA_WALLBUILDERS: ECONOMY_BURSTING, + MORE_EXTRA_UPGRADERS: ECONOMY_BURSTING, + DUMP_ENERGY: ECONOMY_BURSTING } // When the room is at RCL8 (not PRL8) use these settings. const economySettingsLevel8 = { - 'EXTRA_UPGRADERS': false, - 'MORE_EXTRA_UPGRADERS': false, + EXTRA_UPGRADERS: false, + MORE_EXTRA_UPGRADERS: false, - 'FILL_NUKER': ECONOMY_STABLE, - 'FILL_POWER_SPAWN': ECONOMY_STABLE, + FILL_NUKER: ECONOMY_STABLE, + FILL_POWER_SPAWN: ECONOMY_STABLE, - 'UPGRADE_CONTROLLERS': ECONOMY_SURPLUS, - 'EXTRA_WALLBUILDERS': ECONOMY_SURPLUS + UPGRADE_CONTROLLERS: ECONOMY_SURPLUS, + EXTRA_WALLBUILDERS: ECONOMY_SURPLUS } // Will return true for economic levels at or below these values. const economyNegativeSettings = { - 'REQUEST_ENERGY': ECONOMY_FALTERING + REQUEST_ENERGY: ECONOMY_FALTERING } Room.prototype.isEconomyCapable = function (key) { diff --git a/src/extends/room/intel.js b/src/extends/room/intel.js index baccc1c..2514c8c 100644 --- a/src/extends/room/intel.js +++ b/src/extends/room/intel.js @@ -39,7 +39,7 @@ Room.prototype.saveIntel = function (refresh = false) { if (refresh) { roominfo = {} } else { - roominfo = this.getIntel({'skipRequest': true}) + roominfo = this.getIntel({ skipRequest: true }) if (!roominfo) { roominfo = {} } @@ -66,16 +66,16 @@ Room.prototype.saveIntel = function (refresh = false) { } // Detect blocked exits in rooms where walls or ramparts are built. - let blocked = [] + const blocked = [] if (this.structures[STRUCTURE_WALL] || this.structures[STRUCTURE_RAMPART]) { - let candidates = this.find(FIND_SOURCES) + const candidates = this.find(FIND_SOURCES) candidates.push(this.controller) const centerish = this.getPositionAt(25, 25).findClosestByRange(candidates).pos const exits = _.values(Game.map.describeExits(this.name)) const name = this.name - for (let exit of exits) { + for (const exit of exits) { const targetPos = new RoomPosition(25, 25, exit) - const path = PathFinder.search(centerish, {pos: targetPos, range: 24}, + const path = PathFinder.search(centerish, { pos: targetPos, range: 24 }, { swampCost: 1, maxRooms: 2, @@ -226,7 +226,7 @@ Room.getResourcesPositions = function (roomname) { if (!roominfo[INTEL_RESOURCE_POSITIONS]) { return false } - let positions = [] + const positions = [] let serializedPosition for (serializedPosition of roominfo[INTEL_RESOURCE_POSITIONS]) { positions.push(RoomPosition.deserialize(serializedPosition)) diff --git a/src/extends/room/meta.js b/src/extends/room/meta.js index 46621eb..b1c93f6 100644 --- a/src/extends/room/meta.js +++ b/src/extends/room/meta.js @@ -51,15 +51,15 @@ Room.getCoordinates = function (name) { const coordinateRegex = /(E|W)(\d+)(N|S)(\d+)/g const match = coordinateRegex.exec(name) return { - 'x': +match[2], - 'y': +match[4], - 'x_dir': match[1], - 'y_dir': match[3] + x: +match[2], + y: +match[4], + x_dir: match[1], + y_dir: match[3] } } function getRoomRangeBounds (name, range) { - let worldsize = Game.map.getWorldSize() + const worldsize = Game.map.getWorldSize() let maxValue = worldsize // If this is the public server (or one emulating it) optimize to not look beyond edges. @@ -120,7 +120,7 @@ Room.getRoomsInRange = function (name, range) { return [] } const bounds = getRoomRangeBounds(name, range) - let rooms = [] + const rooms = [] for (var x = bounds.lowerX; x <= bounds.upperX; x++) { for (var y = bounds.lowerY; y <= bounds.upperY; y++) { rooms.push(convertToRoomname(x, y, bounds.startXdir, bounds.startYdir)) @@ -148,8 +148,8 @@ Room.isSourcekeeper = function (name) { return true } const coords = Room.getCoordinates(name) - let xMod = coords.x % 10 - let yMod = coords.y % 10 + const xMod = coords.x % 10 + const yMod = coords.y % 10 return xMod >= 4 && xMod <= 6 && yMod >= 4 && yMod <= 6 } @@ -158,8 +158,8 @@ Room.isHallway = function (name) { return false } const coords = Room.getCoordinates(name) - let xMod = coords.x % 10 - let yMod = coords.y % 10 + const xMod = coords.x % 10 + const yMod = coords.y % 10 return xMod === 0 || yMod === 0 } @@ -168,8 +168,8 @@ Room.isClaimable = function (name) { return false } const coords = Room.getCoordinates(name) - let xMod = coords.x % 10 - let yMod = coords.y % 10 + const xMod = coords.x % 10 + const yMod = coords.y % 10 if (xMod >= 4 && xMod <= 6 && yMod >= 4 && yMod <= 6) { return false } diff --git a/src/extends/room/movement.js b/src/extends/room/movement.js index a2fc83e..08b1e6c 100644 --- a/src/extends/room/movement.js +++ b/src/extends/room/movement.js @@ -11,7 +11,7 @@ Room.getCostmatrix = function (roomname, opts = {}) { if (!opts.ignoreCreeps) { const creeps = room.find(FIND_CREEPS) - for (let creep of creeps) { + for (const creep of creeps) { cm.set(creep.pos.x, creep.pos.y, 255) } } @@ -36,7 +36,7 @@ Room.getCostmatrix = function (roomname, opts = {}) { // Allow avoid ranges to be set by range if (opts.avoidRange) { - for (let avoid of opts.avoidRange) { + for (const avoid of opts.avoidRange) { const cost = avoid.value || 255 setValuesInRange(cm, avoid.pos, avoid.range, cost) } @@ -44,14 +44,14 @@ Room.getCostmatrix = function (roomname, opts = {}) { // Block all of these positions as unwalkable if (opts.avoid) { - for (let pos of opts.avoid) { + for (const pos of opts.avoid) { cm.set(pos.x, pos.y, 255) } } // Set these positions to just use terrain score if (opts.ignore) { - for (let pos of opts.ignore) { + for (const pos of opts.ignore) { cm.set(pos.x, pos.y, 0) } } @@ -81,7 +81,7 @@ Room.getStructuresCostmatrix = function (roomname, opts) { const cacheLabel = `${Room.serializeName(roomname)}_${(flags >>> 0)}` if (!opts.noCache) { - let cmSerialized = sos.lib.cache.get(cacheLabel, { + const cmSerialized = sos.lib.cache.get(cacheLabel, { ttl: Game.rooms[roomname] ? 25 : false }) if (cmSerialized) { @@ -94,7 +94,7 @@ Room.getStructuresCostmatrix = function (roomname, opts) { if (!opts.ignoreSourceKeepers && Room.isSourcekeeper(roomname)) { const resourcePoses = Room.getResourcesPositions(roomname) if (resourcePoses) { - for (let pos of resourcePoses) { + for (const pos of resourcePoses) { setValuesInRange(cm, pos, 5, 15) } } @@ -104,7 +104,7 @@ Room.getStructuresCostmatrix = function (roomname, opts) { if ((!opts.ignoreDestructibleStructures || !opts.ignoreRoads || !opts.ignorePortals) && Game.rooms[roomname]) { const room = Game.rooms[roomname] const structures = room.find(FIND_STRUCTURES) - for (let structure of structures) { + for (const structure of structures) { if (structure.structureType === STRUCTURE_ROAD) { if (opts.ignoreRoads) { continue diff --git a/src/extends/room/territory.js b/src/extends/room/territory.js index 46dfdda..219a1d5 100644 --- a/src/extends/room/territory.js +++ b/src/extends/room/territory.js @@ -6,7 +6,7 @@ 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)) { + for (const roomName of Object.keys(Game.rooms)) { const room = Game.rooms[roomName] if (room.controller && room.controller.my) { Memory.territory[roomName] = {} @@ -127,7 +127,7 @@ Room.prototype.selectNextMine = function () { if (existing.indexOf(candidate) >= 0) { continue } - let testScore = this.getMineScore(candidate) + const testScore = this.getMineScore(candidate) if (testScore === false) { continue } @@ -144,7 +144,7 @@ Room.prototype.getMineScore = function (roomName) { if (Room.isSourcekeeper(roomName)) { return false } - const route = qlib.map.findRoute(this.name, roomName, {'avoidHostileRooms': true}) + const route = qlib.map.findRoute(this.name, roomName, { avoidHostileRooms: true }) if (route === ERR_NO_PATH) { return false } @@ -342,11 +342,11 @@ function getMineralEmpireNeedsScore (mineral) { function getDefensibilityScore (room) { let score = 0 - let totalEdge = 48 * 4 - let exits = Game.map.describeExits(room) - let exitIds = Object.keys(exits) + const totalEdge = 48 * 4 + const exits = Game.map.describeExits(room) + const exitIds = Object.keys(exits) - for (let exitId of exitIds) { + for (const exitId of exitIds) { const exitRoom = exits[exitId] if (Room.isCuldesac(exitRoom)) { delete exits[exitId] @@ -417,7 +417,7 @@ function getRegionResourcesScore (centerRoomName, range) { const regionRoomCount = Math.pow((range * 2) + 1, 2) - 1 const rooms = Room.getRoomsInRange(centerRoomName, range) let sourceCount = 0 - for (let roomName of rooms) { + for (const roomName of rooms) { const intel = Room.getIntel(roomName) if (!intel || !intel[INTEL_SOURCES]) { continue @@ -439,7 +439,7 @@ function getRegionResourcesScore (centerRoomName, range) { function getNeighborSourcesScore (room) { const neighbors = _.values(Game.map.describeExits(room)) let twoSource = 0 - for (let neighbor of neighbors) { + for (const neighbor of neighbors) { const neighborIntel = Room.getIntel(neighbor) if (neighborIntel[INTEL_SOURCES] >= 2) { twoSource++ @@ -453,7 +453,7 @@ function getEmpireClutterScore (room) { const cities = Room.getCities() const maxInRange = 5 let inRange = 0 - for (let city of cities) { + for (const city of cities) { if (Room.getManhattanDistance(room, city) <= CITY_MAX_REACHABILITY_DISTANCE) { inRange++ } @@ -472,7 +472,7 @@ function getEmpireDefenseScore (room) { const cities = Room.getCities() const target = cities.length < 4 ? cities.length : 4 let closeCount = 0 - for (let city of cities) { + for (const city of cities) { if (Room.getManhattanDistance(room, city) <= CITY_MAX_REACHABILITY_DISTANCE) { closeCount++ if (closeCount >= target) { @@ -487,7 +487,7 @@ function getRegionDensityScore (room, range) { const regionRoomCount = Math.pow((range * 2) + 1, 2) - 1 const rooms = Room.getRoomsInRange(room, range) let owned = 0 - for (let room of rooms) { + for (const room of rooms) { const intel = Room.getIntel(room) if (intel[INTEL_OWNER]) { owned++ @@ -501,9 +501,9 @@ function getRegionDensityScore (room, range) { function getCityDistanceScore (room) { const cities = Room.getCities() - let max = CITY_MAX_REACHABILITY_DISTANCE - 2 + const max = CITY_MAX_REACHABILITY_DISTANCE - 2 let min = Infinity - for (let city of cities) { + for (const city of cities) { const distance = Room.getManhattanDistance(room, city) if (distance < min) { min = distance diff --git a/src/extends/roomposition.js b/src/extends/roomposition.js index 8bbf6ce..4f4354f 100644 --- a/src/extends/roomposition.js +++ b/src/extends/roomposition.js @@ -46,7 +46,7 @@ RoomPosition.prototype.getSteppableAdjacent = function (includeCreeps = false, i RoomPosition.prototype.getAdjacentInRange = function (range = 1) { const bounds = createBoundingBoxForRange(this.x, this.y, range) - let positions = [] + const positions = [] for (let x = bounds.left; x <= bounds.right; x++) { for (let y = bounds.top; y <= bounds.bottom; y++) { positions.push(new RoomPosition(x, y, this.roomName)) @@ -57,7 +57,7 @@ RoomPosition.prototype.getAdjacentInRange = function (range = 1) { RoomPosition.prototype.getSteppableAdjacentInRange = function (range = 1) { const bounds = createBoundingBoxForRange(this.x, this.y, range) - let positions = [] + const positions = [] let position for (let x = bounds.left; x <= bounds.right; x++) { for (let y = bounds.top; y <= bounds.bottom; y++) { @@ -211,8 +211,8 @@ RoomPosition.prototype.lookAround = function (range = 1) { } RoomPosition.prototype.getStructureByType = function (structureType) { - let structures = this.lookFor(LOOK_STRUCTURES) - let filteredStructures = _.filter(structures, function (structure) { + const structures = this.lookFor(LOOK_STRUCTURES) + const filteredStructures = _.filter(structures, function (structure) { return structure.structureType === structureType }) return filteredStructures.length > 0 ? filteredStructures[0] : false @@ -235,7 +235,7 @@ function createBoundingBoxForRange (x, y, range) { const right = Math.max(Math.min(x + absRange, 49), 0) const top = Math.min(Math.max(y - absRange, 0), 49) const bottom = Math.max(Math.min(y + absRange, 49), 0) - return {left, right, top, bottom} + return { left, right, top, bottom } } module.exports = { diff --git a/src/extends/storage.js b/src/extends/storage.js index be82820..ef34f3d 100644 --- a/src/extends/storage.js +++ b/src/extends/storage.js @@ -8,13 +8,13 @@ StructureStorage.prototype.getLink = function () { } const needs = { - 'base': 10000, // 8 = 80000 - 'tier1': 3000, // 10 = 30000 - 'tier2': 3000, // 10 = 30000 - 'tier3': 20000, // 10 = 200000 - 'OH': 10000, // 1 = 10000 - 'comp': 10000, // 2 = 20000 - 'G': 5000 // 1 = 5000 + base: 10000, // 8 = 80000 + tier1: 3000, // 10 = 30000 + tier2: 3000, // 10 = 30000 + tier3: 20000, // 10 = 200000 + OH: 10000, // 1 = 10000 + comp: 10000, // 2 = 20000 + G: 5000 // 1 = 5000 } // max resource storage = 375,000 // amount for energy and overflow = 625,000 diff --git a/src/extends/terminal.js b/src/extends/terminal.js index 06899f0..4dc817f 100644 --- a/src/extends/terminal.js +++ b/src/extends/terminal.js @@ -29,7 +29,7 @@ if (!StructureTerminal.prototype.__send) { } Logger.log(log, LOG_INFO) } else { - let log = `Terminal in ${this.room.name} failed to send ${amount} ${resourceType} to ${destination} due to error ${ret}` + const log = `Terminal in ${this.room.name} failed to send ${amount} ${resourceType} to ${destination} due to error ${ret}` Logger.log(log, LOG_ERROR) } return ret diff --git a/src/lib/cluster.js b/src/lib/cluster.js index 3dccd6e..33066e0 100644 --- a/src/lib/cluster.js +++ b/src/lib/cluster.js @@ -26,7 +26,7 @@ class Cluster { } if (!Memory.clusters[name]) { Memory.clusters[name] = { - 'creeps': [] + creeps: [] } } this.memory = Memory.clusters[name] @@ -76,7 +76,7 @@ class Cluster { forEach (creepAction) { const creeps = this.getCreeps() - for (let creep of creeps) { + for (const creep of creeps) { try { if (creep.spawning) { continue diff --git a/src/lib/dossier.js b/src/lib/dossier.js index ead9c4d..0b0b3a0 100644 --- a/src/lib/dossier.js +++ b/src/lib/dossier.js @@ -55,8 +55,8 @@ class Dossier { } if (intel[PLAYER_RECENT_AGGRESSION][room]) { if (Game.time - intel[PLAYER_RECENT_AGGRESSION][room].t < AGGRESSION_TIMEOUT) { - let currentScore = AGGRESSION_SCORES[type] - let existingScore = AGGRESSION_SCORES[intel[PLAYER_RECENT_AGGRESSION][room].a] + const currentScore = AGGRESSION_SCORES[type] + const existingScore = AGGRESSION_SCORES[intel[PLAYER_RECENT_AGGRESSION][room].a] if (existingScore < currentScore) { intel[PLAYER_SCORE] += currentScore - existingScore intel[PLAYER_RECENT_AGGRESSION][room].a = type diff --git a/src/lib/genome.js b/src/lib/genome.js index 3a95f8b..d951bd2 100644 --- a/src/lib/genome.js +++ b/src/lib/genome.js @@ -61,7 +61,7 @@ class Genome { } random (label) { - let seed = (this._getNumberFromString(label) + this.seed) % this.max + const seed = (this._getNumberFromString(label) + this.seed) % this.max return this._getNumberFromSeed(seed) / (this.max - 1) } @@ -104,11 +104,11 @@ if (typeof module !== 'undefined' && !module.parent) { const modifier = Math.floor(Math.random() * (100 + 1)) const seed = 'Quorum' + modifier console.log(`Testing distribution with seed ${seed} over ${iterations} iterations with max value ${max}.`) - let genome = new Genome(seed) + const genome = new Genome(seed) - let count = {} + const count = {} for (let i = 0; i < iterations; i++) { - let ret = genome.randomInt('apples' + i, 1, max) + const ret = genome.randomInt('apples' + i, 1, max) if (!count[ret]) { count[ret] = 1 } else { @@ -116,9 +116,9 @@ if (typeof module !== 'undefined' && !module.parent) { } } - let trait = {} + const trait = {} for (let i = 0; i < iterations; i++) { - let ret = genome.trait('apples' + i, 50, { + const ret = genome.trait('apples' + i, 50, { max: max, min: 1 }) @@ -129,12 +129,12 @@ if (typeof module !== 'undefined' && !module.parent) { } } - let weights = [1, 2, 3, 5, 10, 50] - let weightedResults = {} - for (let weight of weights) { + const weights = [1, 2, 3, 5, 10, 50] + const weightedResults = {} + for (const weight of weights) { weightedResults[weight] = {} for (let i = 0; i < iterations; i++) { - let ret = genome.randomCenterWeightedInt('apples' + i, 1, max, weight) + const ret = genome.randomCenterWeightedInt('apples' + i, 1, max, weight) if (!weightedResults[weight][ret]) { weightedResults[weight][ret] = 1 } else { @@ -154,7 +154,7 @@ if (typeof module !== 'undefined' && !module.parent) { header += '\tUnweighted' header += '\tTrait' - for (let weight of weights) { + for (const weight of weights) { header += `\t\t${weight}` } console.log(header) @@ -164,7 +164,7 @@ if (typeof module !== 'undefined' && !module.parent) { message += `\t${normalizeCount(count[i])}` message += `\t\t${normalizeCount(trait[i])}` - for (let weight of weights) { + for (const weight of weights) { message += `\t\t${normalizeCount(weightedResults[weight][i])}` } @@ -172,6 +172,6 @@ if (typeof module !== 'undefined' && !module.parent) { } } else { // Use the botname as the seed. - let botname = global.USERNAME ? global.USERNAME : 'Quorum' + const botname = global.USERNAME ? global.USERNAME : 'Quorum' module.exports = new Genome(botname, PUBLIC_ACCOUNT) } diff --git a/src/lib/loader.js b/src/lib/loader.js index 46331f2..c5369d0 100644 --- a/src/lib/loader.js +++ b/src/lib/loader.js @@ -1,8 +1,8 @@ 'use strict' -let target = {} // eslint-disable-line no-unused-vars +const target = {} // eslint-disable-line no-unused-vars -let loader = { +const loader = { get (target, key, receiver) { var classname = 'lib_' + key.toLowerCase() if (!target[classname]) { diff --git a/src/lib/map.js b/src/lib/map.js index 84158b1..0f34977 100644 --- a/src/lib/map.js +++ b/src/lib/map.js @@ -23,7 +23,7 @@ module.exports.findRoute = function (fromRoom, toRoom, opts = {}) { return cachedPath } const newPath = Game.map.findRoute(fromRoom, toRoom, opts) - let options = {maxttl: 150} + const options = { maxttl: 150 } if (newPath.length >= 4) { options.persist = true } @@ -48,7 +48,7 @@ module.exports.getDistanceToEmpire = function (roomname, algorithm = 'linear') { minimum = distance } } - sos.lib.cache.set(`empire_distance_${algorithm}_${roomname}`, minimum, {'maxttl': 50}) + sos.lib.cache.set(`empire_distance_${algorithm}_${roomname}`, minimum, { maxttl: 50 }) return minimum } @@ -97,10 +97,10 @@ module.exports.getRoomScore = function (toRoom, fromRoom, opts = {}) { } const scores = opts.scores ? opts.scores : {} if (Room.isSourcekeeper(toRoom)) { - return scores['WEIGHT_SOURCEKEEPER'] ? scores['WEIGHT_SOURCEKEEPER'] : PATH_WEIGHT_SOURCEKEEPER + return scores.WEIGHT_SOURCEKEEPER ? scores.WEIGHT_SOURCEKEEPER : PATH_WEIGHT_SOURCEKEEPER } if (Room.isHallway(toRoom)) { - return scores['WEIGHT_HALLWAY'] ? scores['WEIGHT_HALLWAY'] : PATH_WEIGHT_HALLWAY + return scores.WEIGHT_HALLWAY ? scores.WEIGHT_HALLWAY : PATH_WEIGHT_HALLWAY } if (fromRoom) { @@ -113,13 +113,13 @@ module.exports.getRoomScore = function (toRoom, fromRoom, opts = {}) { const roomIntel = Room.getIntel(toRoom) if (roomIntel && roomIntel[INTEL_OWNER]) { if (roomIntel[INTEL_OWNER] === USERNAME) { - return scores['WEIGHT_OWN'] ? opts.scores['WEIGHT_OWN'] : PATH_WEIGHT_OWN + return scores.WEIGHT_OWN ? opts.scores.WEIGHT_OWN : PATH_WEIGHT_OWN } if (roomIntel[INTEL_LEVEL]) { - return scores['WEIGHT_HOSTILE'] ? scores['WEIGHT_HOSTILE'] : PATH_WEIGHT_HOSTILE + return scores.WEIGHT_HOSTILE ? scores.WEIGHT_HOSTILE : PATH_WEIGHT_HOSTILE } else { - return scores['WEIGHT_HOSTILE_RESERVATION'] ? scores['WEIGHT_HOSTILE_RESERVATION'] : PATH_WEIGHT_HOSTILE_RESERVATION + return scores.WEIGHT_HOSTILE_RESERVATION ? scores.WEIGHT_HOSTILE_RESERVATION : PATH_WEIGHT_HOSTILE_RESERVATION } } - return scores['WEIGHT_NEUTRAL'] ? scores['WEIGHT_NEUTRAL'] : PATH_WEIGHT_NEUTRAL + return scores.WEIGHT_NEUTRAL ? scores.WEIGHT_NEUTRAL : PATH_WEIGHT_NEUTRAL } diff --git a/src/lib/market.js b/src/lib/market.js index 0f30d50..50acf5e 100644 --- a/src/lib/market.js +++ b/src/lib/market.js @@ -14,14 +14,14 @@ module.exports.getAveragePrice = function (resource, orderType) { module.exports.getOrdersByType = function (resource, orderType) { // Temporary wrapper to deal with broken data in game engine (bug reported to devs) try { - return Game.market.getAllOrders({type: orderType, resourceType: resource}) + return Game.market.getAllOrders({ type: orderType, resourceType: resource }) } catch (err) { return [] } } module.exports.getCurrentPrice = function (resource, orderType) { - let orders = module.exports.getOrdersByType(resource, orderType) + const orders = module.exports.getOrdersByType(resource, orderType) if (orderType === ORDER_BUY) { orders.sort((a, b) => a.price - b.price) } else { @@ -36,7 +36,7 @@ module.exports.getCurrentPrice = function (resource, orderType) { // Filter out the first few orders (by quantity) to prevent manipulation or confusion over phantom orders. let amount = 0 - for (let order of orders) { + for (const order of orders) { // Skip all new orders - manipulation orders tend to get bought out really quick. if (Game.time - order.created < 20) { continue @@ -72,13 +72,13 @@ module.exports.transactImmediately = function (resource, room, quantity, orderTy if (room.terminal.cooldown) { return ERR_BUSY } - let orders = module.exports.getOrdersByType(resource, orderType) + const orders = module.exports.getOrdersByType(resource, orderType) if (orderType === ORDER_SELL) { orders.sort((a, b) => a.price - b.price) } else { orders.sort((a, b) => b.price - a.price) } - for (let order of orders) { + for (const order of orders) { if (order.amount > TERMINAL_MIN_SEND) { if (order.amount < quantity) { quantity = order.amount diff --git a/src/main.js b/src/main.js index eee087d..45e981b 100644 --- a/src/main.js +++ b/src/main.js @@ -8,7 +8,7 @@ if (Game.cpu.bucket < 500) { /* Get Upload Version */ require('version') -require('constants') +require('./constants') /* Enable QOS Logger */ const QosLogger = require('qos_logger') @@ -24,8 +24,8 @@ require('thirdparty_roomvisual') /* Add "creep talk" library - https://github.com/screepers/creeptalk */ const language = require('thirdparty_creeptalk_emoji') require('thirdparty_creeptalk')({ - 'public': true, - 'language': language + public: true, + language: language }) /* Make the quorum library code available globally */ diff --git a/src/programs/city.js b/src/programs/city.js index da304d9..6d4eae3 100644 --- a/src/programs/city.js +++ b/src/programs/city.js @@ -1,10 +1,10 @@ 'use strict' const roomPrograms = { - 'spawns': 'spawns', - 'defense': 'city_defense', - 'reboot': 'city_reboot', - 'works': 'city_publicworks' + spawns: 'spawns', + defense: 'city_defense', + reboot: 'city_reboot', + works: 'city_publicworks' } class City extends kernel.process { @@ -66,8 +66,8 @@ class City extends kernel.process { requestAid () { if (!this.room.structures[STRUCTURE_SPAWN] || this.room.structures[STRUCTURE_SPAWN].length <= 0) { this.launchChildProcess('gethelp', 'empire_expand', { - 'colony': this.data.room, - 'recover': true + colony: this.data.room, + recover: true }) return true } @@ -78,14 +78,14 @@ class City extends kernel.process { // Launch children programs for (const label in roomPrograms) { this.launchChildProcess(label, roomPrograms[label], { - 'room': this.data.room + room: this.data.room }) } // Launch mining if all level 2 extensions are build. if (this.room.energyCapacityAvailable > 500) { this.launchChildProcess('mining', 'city_mine', { - 'room': this.data.room + room: this.data.room }) } @@ -93,17 +93,17 @@ class City extends kernel.process { const layout = this.room.getLayout() if (!layout.isPlanned()) { this.launchChildProcess('layout', 'city_layout', { - 'room': this.data.room + room: this.data.room }) } else { if (Memory.userConfig && Memory.userConfig.visualizeLayout) { layout.visualize() } this.launchChildProcess('construct', 'city_construct', { - 'room': this.data.room + room: this.data.room }) this.launchChildProcess('fortify', 'city_fortify', { - 'room': this.data.room + room: this.data.room }) } @@ -114,7 +114,7 @@ class City extends kernel.process { const mineral = this.room.find(FIND_MINERALS)[0] if (mineral.mineralAmount > 0 && !mineral.ticksToRegeneration) { this.launchChildProcess('extraction', 'city_extract', { - 'room': this.data.room + room: this.data.room }) } } @@ -123,7 +123,7 @@ class City extends kernel.process { launchCorePrograms () { if (this.room.getRoomSetting('LABS')) { this.launchChildProcess('labs', 'city_labs', { - 'room': this.data.room + room: this.data.room }) } @@ -139,7 +139,7 @@ class City extends kernel.process { let remoteMines = this.room.getMines() if (remoteMines.length < mineCount) { const cpuUsage = sos.lib.monitor.getPriorityRunStats(PRIORITIES_CREEP_DEFAULT) - if (cpuUsage && cpuUsage['long'] <= 1.25) { + if (cpuUsage && cpuUsage.long <= 1.25) { const mine = this.room.selectNextMine() if (mine) { this.room.addMine(mine) @@ -151,8 +151,8 @@ class City extends kernel.process { let mineRoomName for (mineRoomName of remoteMines) { this.launchChildProcess(`mine_${mineRoomName}`, 'city_mine', { - 'room': this.data.room, - 'mine': mineRoomName + room: this.data.room, + mine: mineRoomName }) } } @@ -160,12 +160,12 @@ class City extends kernel.process { launchCreeps () { // Launch fillers - let options = { - 'priority': 3 + const options = { + priority: 3 } if (this.room.getRoomSetting('PURE_CARRY_FILLERS')) { - options['carry_only'] = true - options['energy'] = Math.max(Math.min(1600, this.room.energyCapacityAvailable / 2), 400) + options.carry_only = true + options.energy = Math.max(Math.min(1600, this.room.energyCapacityAvailable / 2), 400) } const fillerQuantity = this.room.getRoomSetting('ADDITIONAL_FILLERS') ? 4 : 2 this.launchCreepProcess('fillers', 'filler', this.data.room, fillerQuantity, options) @@ -187,7 +187,7 @@ class City extends kernel.process { upgraderQuantity = 1 } this.launchCreepProcess('upgraders', 'upgrader', this.data.room, upgraderQuantity, { - 'priority': 5 + priority: 5 }) } @@ -201,7 +201,7 @@ class City extends kernel.process { // Launch scouts to map out neighboring rooms if (this.data.room !== 'sim' && this.room.getRoomSetting('SCOUTS')) { this.launchCreepProcess('scouts', 'spook', this.data.room, 1, { - 'priority': 4 + priority: 4 }) } } diff --git a/src/programs/city/construct.js b/src/programs/city/construct.js index d9602a0..bfafcf2 100644 --- a/src/programs/city/construct.js +++ b/src/programs/city/construct.js @@ -36,7 +36,7 @@ class CityConstruct extends kernel.process { const structures = this.room.find(FIND_STRUCTURES) const miningPositions = this.room.find(FIND_SOURCES).map(s => s.getMiningPosition()) this.data.hascleared = true - for (let structure of structures) { + for (const structure of structures) { if (structure.structureType === STRUCTURE_CONTROLLER) { continue } @@ -56,7 +56,7 @@ class CityConstruct extends kernel.process { Logger.log(`Attempting to destroy structure ${structure.structureType}: ${structure.destroy()}`) } const sites = this.room.find(FIND_HOSTILE_CONSTRUCTION_SITES) - for (let site of sites) { + for (const site of sites) { this.data.hascleared = false site.remove() } @@ -64,7 +64,7 @@ class CityConstruct extends kernel.process { } const sites = this.room.find(FIND_MY_CONSTRUCTION_SITES, { - 'filter': function (structure) { + filter: function (structure) { return !ignoreConstructionSites.includes(structure) } }) @@ -81,7 +81,7 @@ class CityConstruct extends kernel.process { return } } - let result = this.room.constructNextMissingStructure() + const result = this.room.constructNextMissingStructure() this.data.lastscan = Game.time if (result !== false && result[0] < 0) { // result is [code, type, position] diff --git a/src/programs/city/defense.js b/src/programs/city/defense.js index ce76435..5a48e45 100644 --- a/src/programs/city/defense.js +++ b/src/programs/city/defense.js @@ -66,7 +66,7 @@ class CityDefense extends kernel.process { fireTowers (towers, hostiles) { const attackFunc = (attackTarget) => { - for (let tower of towers) { + for (const tower of towers) { if (tower.energy < TOWER_ENERGY_COST) { continue } @@ -78,7 +78,7 @@ class CityDefense extends kernel.process { const healFunc = (healTarget) => { let damage = healTarget.hitsMax - healTarget.hits - for (let tower of towers) { + for (const tower of towers) { if (damage <= 0) { break } @@ -132,7 +132,7 @@ class CityDefense extends kernel.process { return false } - let safeStructures = room.find(FIND_MY_SPAWNS) + const safeStructures = room.find(FIND_MY_SPAWNS) // If there are no spawns this room isn't worth protecting with a safemode. if (safeStructures.length <= 0) { @@ -143,18 +143,18 @@ class CityDefense extends kernel.process { if (!room.getRoomSetting('ALWAYS_SAFEMODE')) { const cities = Room.getCities() let highestLevel = 0 - for (let cityName of cities) { + for (const cityName of cities) { if (!Game.rooms[cityName]) { continue } - let city = Game.rooms[cityName] + const city = Game.rooms[cityName] if (!city.controller.canSafemode()) { continue } if (city.getRoomSetting('ALWAYS_SAFEMODE')) { return false } - let level = city.getPracticalRoomLevel() + const level = city.getPracticalRoomLevel() if (highestLevel < level) { highestLevel = level } diff --git a/src/programs/city/fortify.js b/src/programs/city/fortify.js index 8e00049..b012109 100644 --- a/src/programs/city/fortify.js +++ b/src/programs/city/fortify.js @@ -56,7 +56,7 @@ class CityFortify extends kernel.process { return } - let structureType = this.defenses.getStructureAt(target.pos.x, target.pos.y) + const structureType = this.defenses.getStructureAt(target.pos.x, target.pos.y) const desiredHitpoints = this.rampartLevels[structureType] const builderCluster = this.getCluster('builders', this.room) @@ -71,7 +71,7 @@ class CityFortify extends kernel.process { } builderCluster.sizeCluster('builder', quantity, { - 'priority': 5 + priority: 5 }) builderCluster.forEach(function (builder) { @@ -99,37 +99,39 @@ class CityFortify extends kernel.process { * Structure with the lowest percentage of hit points compared to desired amount. */ getTarget () { - const sites = this.room.find(FIND_MY_CONSTRUCTION_SITES, {'filter': function (site) { - return site.structureType === STRUCTURE_RAMPART || site.structureType === STRUCTURE_WALL - }}) + const sites = this.room.find(FIND_MY_CONSTRUCTION_SITES, { + filter: function (site) { + return site.structureType === STRUCTURE_RAMPART || site.structureType === STRUCTURE_WALL + } + }) if (sites.length > 0) { return sites[0] } - let targetId = sos.lib.cache.get([this.data.room, 'rampartTarget'], { + const targetId = sos.lib.cache.get([this.data.room, 'rampartTarget'], { ttl: 50 }) if (targetId) { - let target = Game.getObjectById(targetId) + const target = Game.getObjectById(targetId) if (target) { return target } } - let structures = this.defenses.getAllStructures() - let types = Object.keys(structures) + const structures = this.defenses.getAllStructures() + const types = Object.keys(structures) // Prioritize missing sites based off of type. types.sort((a, b) => b - a) - let missing = [] - let structureMap = {} - let decaying = [] - for (let type of types) { + const missing = [] + const structureMap = {} + const decaying = [] + for (const type of types) { if (!this.rampartLevels[type]) { continue } - for (let position of structures[type]) { + for (const position of structures[type]) { // Don't build structure ramparts unless there's a structure. if (type === RAMPART_PRIMARY_STRUCTURES || type === RAMPART_SECONDARY_STRUCTURES) { if (position.lookFor(LOOK_STRUCTURES).length <= 0) { diff --git a/src/programs/city/layout.js b/src/programs/city/layout.js index d843323..dc591b2 100644 --- a/src/programs/city/layout.js +++ b/src/programs/city/layout.js @@ -389,7 +389,7 @@ class CityLayout extends kernel.process { */ planRoads (layout, corePos, flower1Pos, flower2Pos) { Logger.log(`Planning roads for room: ${this.data.room}`, LOG_INFO, 'layout') - let matrix = this.getConstructionMatrix(layout) + const matrix = this.getConstructionMatrix(layout) this.planRoad(layout, corePos, flower1Pos, matrix) this.planRoad(layout, corePos, flower2Pos, matrix) if (this.room.controller) { diff --git a/src/programs/city/mine.js b/src/programs/city/mine.js index 7318445..ddd6211 100644 --- a/src/programs/city/mine.js +++ b/src/programs/city/mine.js @@ -57,7 +57,7 @@ class CityMine extends kernel.process { // If the mine is not reachable remove it. if (!Game.rooms[this.data.mine]) { - const route = qlib.map.findRoute(this.data.room, this.data.mine, {'avoidHostileRooms': true}) + const route = qlib.map.findRoute(this.data.room, this.data.mine, { avoidHostileRooms: true }) if (route === ERR_NO_PATH) { this.room.removeMine(this.data.mine) return this.suicide() @@ -130,14 +130,14 @@ class CityMine extends kernel.process { minerQuantity = 0 } - miners.sizeCluster('miner', minerQuantity, {'priority': 2, 'remote': this.remote}) + miners.sizeCluster('miner', minerQuantity, { priority: 2, remote: this.remote }) miners.forEach(function (miner) { if (miner.pos.getRangeTo(minerPos) !== 0) { miner.travelTo(minerPos) return } - let needsRepairs = container && container.hits < container.hitsMax + const needsRepairs = container && container.hits < container.hitsMax if (construction && miner.carry[RESOURCE_ENERGY]) { miner.build(construction) @@ -200,7 +200,7 @@ class CityMine extends kernel.process { } const distance = this.data.ssp[source.id] ? this.data.ssp[source.id] : 80 if (!this.underAttack && !this.strictSpawning) { - const carryCost = BODYPART_COST['move'] + BODYPART_COST['carry'] + const carryCost = BODYPART_COST.move + BODYPART_COST.carry const multiplier = this.remote ? 1.8 : 1.3 const carryAmount = Math.ceil(((distance * multiplier) * 20) / carryCost) * carryCost const maxEnergy = Math.min(carryCost * (MAX_CREEP_SIZE / 2), this.room.energyCapacityAvailable) @@ -213,7 +213,7 @@ class CityMine extends kernel.process { const respawnTime = ((energy / carryCost) * 2) * CREEP_SPAWN_TIME const respawnAge = respawnTime + (distance * 1.2) - haulers.sizeCluster('hauler', quantity, {'energy': energy, 'respawnAge': respawnAge}) + haulers.sizeCluster('hauler', quantity, { energy: energy, respawnAge: respawnAge }) } haulers.forEach(function (hauler) { @@ -247,7 +247,7 @@ class CityMine extends kernel.process { scout () { const center = new RoomPosition(25, 25, this.data.mine) const quantity = Game.rooms[this.data.mine] ? 0 : 1 - const scouts = this.getCluster(`scout`, this.room) + const scouts = this.getCluster('scout', this.room) scouts.sizeCluster('spook', quantity) scouts.forEach(function (scout) { if (scout.room.name === center.roomName) { @@ -255,7 +255,7 @@ class CityMine extends kernel.process { return } } - scout.travelTo(center, {range: 20}) + scout.travelTo(center, { range: 20 }) }) } @@ -267,7 +267,7 @@ class CityMine extends kernel.process { quantity = Math.min(this.room.getRoomSetting('RESERVER_COUNT'), controller.pos.getSteppableAdjacent().length) } - const reservists = this.getCluster(`reservists`, this.room) + const reservists = this.getCluster('reservists', this.room) reservists.sizeCluster('reservist', quantity) reservists.forEach(function (reservist) { if (!reservist.pos.isNearTo(controller)) { diff --git a/src/programs/city/publicworks.js b/src/programs/city/publicworks.js index 1f4561b..ab73b06 100644 --- a/src/programs/city/publicworks.js +++ b/src/programs/city/publicworks.js @@ -22,9 +22,11 @@ class CityPublicWorks extends kernel.process { } this.room = Game.rooms[this.data.room] - const sites = this.room.find(FIND_MY_CONSTRUCTION_SITES, {'filter': function (structure) { - return maintainStructures.includes(structure) - }}) + const sites = this.room.find(FIND_MY_CONSTRUCTION_SITES, { + filter: function (structure) { + return maintainStructures.includes(structure) + } + }) if (sites.length > 0 && this.room.isEconomyCapable('BUILD_STRUCTURES')) { this.launchCreepProcess('builders', 'builder', this.data.room, 1) } diff --git a/src/programs/city/reboot.js b/src/programs/city/reboot.js index bf3424e..7b4fc9c 100644 --- a/src/programs/city/reboot.js +++ b/src/programs/city/reboot.js @@ -19,7 +19,7 @@ class CityReboot extends kernel.process { return this.suicide() } this.room = Game.rooms[this.data.room] - const fillers = this.room.find(FIND_MY_CREEPS, {filter: (creep) => creep.name.startsWith('filler')}) + const fillers = this.room.find(FIND_MY_CREEPS, { filter: (creep) => creep.name.startsWith('filler') }) if (fillers.length <= 0) { this.launchCreepProcess('rebooter', 'filler', this.data.room, 2, { priority: 1, diff --git a/src/programs/empire/expand.js b/src/programs/empire/expand.js index c9a9fad..0c9ca83 100644 --- a/src/programs/empire/expand.js +++ b/src/programs/empire/expand.js @@ -81,7 +81,7 @@ class EmpireExpand extends kernel.process { if (!this.data.claimedAt) { if (!this.colony.getLayout().isPlanned()) { this.launchChildProcess('layout', 'city_layout', { - 'room': this.data.colony + room: this.data.colony }) } this.data.claimedAt = Game.time @@ -100,7 +100,7 @@ class EmpireExpand extends kernel.process { this.upgrade() const sources = this.colony.find(FIND_SOURCES) - for (let source of sources) { + for (const source of sources) { this.mine(source) } @@ -114,7 +114,7 @@ class EmpireExpand extends kernel.process { // If the room layout is planned launch the construction program if (!this.data.recover && this.colony.getLayout().isPlanned()) { this.launchChildProcess('construct', 'city_construct', { - 'room': this.data.colony + room: this.data.colony }) } @@ -183,7 +183,7 @@ class EmpireExpand extends kernel.process { const cities = Room.getCities() let closest = false let distance = Infinity - for (let city of cities) { + for (const city of cities) { if (!Game.rooms[city]) { continue } @@ -201,9 +201,9 @@ class EmpireExpand extends kernel.process { getCandidateList () { const cities = Room.getCities() - let candidates = [] + const candidates = [] - for (let city of cities) { + for (const city of cities) { if (!Game.rooms[city]) { continue } @@ -212,8 +212,8 @@ class EmpireExpand extends kernel.process { continue } - let rooms = Room.getRoomsInRange(city, 10) - for (let room of rooms) { + const rooms = Room.getRoomsInRange(city, 10) + for (const room of rooms) { if (candidates.indexOf(room) >= 0 || !Room.isClaimable(room)) { continue } @@ -228,11 +228,11 @@ class EmpireExpand extends kernel.process { scout () { const closestCity = this.getClosestCity(this.data.colony) const center = new RoomPosition(25, 25, this.data.colony) - const scouts = this.getCluster(`scout`, closestCity) + const scouts = this.getCluster('scout', closestCity) if (!Game.rooms[this.data.colony] || !Game.rooms[this.data.colony].controller.my) { - let creeps = scouts.getCreeps() - let quantity = creeps.length === 1 && creeps[0].ticksToLive < 750 ? 2 : 1 - scouts.sizeCluster('spook', quantity, {'priority': 2}) + const creeps = scouts.getCreeps() + const quantity = creeps.length === 1 && creeps[0].ticksToLive < 750 ? 2 : 1 + scouts.sizeCluster('spook', quantity, { priority: 2 }) } scouts.forEach(function (scout) { if (scout.room.name === center.roomName) { @@ -240,7 +240,7 @@ class EmpireExpand extends kernel.process { return } } - scout.travelTo(center, {range: 20}) + scout.travelTo(center, { range: 20 }) }) } @@ -253,7 +253,7 @@ class EmpireExpand extends kernel.process { controller = this.colony.controller } const closestCity = this.getClosestCity(this.data.colony) - const claimer = this.getCluster(`claimers`, closestCity) + const claimer = this.getCluster('claimers', closestCity) // Give up 1000 ticks after launching the last claimer and move on to the next candidate room. @@ -261,7 +261,7 @@ class EmpireExpand extends kernel.process { if (!this.data.lastClaimAttempt || Game.time - this.data.lastClaimAttempt > 1000) { this.data.attemptedClaim++ this.data.lastClaimAttempt = Game.time - claimer.sizeCluster('claimer', 1, {'priority': 2}) + claimer.sizeCluster('claimer', 1, { priority: 2 }) } } else if (Game.time - this.data.lastClaimAttempt > 1000) { if (claimer.getCreeps().length < 1) { @@ -272,8 +272,8 @@ class EmpireExpand extends kernel.process { const colonyName = this.data.colony claimer.forEach(function (claimer) { if (!controller) { - let pos = new RoomPosition(25, 25, colonyName) - claimer.travelTo(pos, {range: 20}) + const pos = new RoomPosition(25, 25, colonyName) + claimer.travelTo(pos, { range: 20 }) return } if (!claimer.pos.isNearTo(controller)) { @@ -285,7 +285,7 @@ class EmpireExpand extends kernel.process { } mine (source) { - let spawnRoom = this.colony.energyCapacityAvailable >= 800 ? this.colony : this.getClosestCity(this.data.colony) + const spawnRoom = this.colony.energyCapacityAvailable >= 800 ? this.colony : this.getClosestCity(this.data.colony) const minerPos = source.getMiningPosition() const containers = _.filter(minerPos.lookFor(LOOK_STRUCTURES), (a) => a.structureType === STRUCTURE_CONTAINER) @@ -329,7 +329,7 @@ class EmpireExpand extends kernel.process { build () { const controller = this.colony.controller const closestCity = this.getClosestCity(this.data.colony) - const builders = this.getCluster(`builders`, closestCity) + const builders = this.getCluster('builders', closestCity) const constructionSites = this.colony.find(FIND_MY_CONSTRUCTION_SITES) const site = constructionSites.length > 0 ? constructionSites[0] : false const hostileSpawns = this.hostileSpawns @@ -357,12 +357,14 @@ class EmpireExpand extends kernel.process { } if (builder.room.energyAvailable < builder.room.energyCapacityAvailable) { - const structures = builder.room.find(FIND_MY_STRUCTURES, {filter: function (structure) { - if (structure.structureType !== STRUCTURE_EXTENSION && structure.structureType !== STRUCTURE_SPAWN) { - return false + const structures = builder.room.find(FIND_MY_STRUCTURES, { + filter: function (structure) { + if (structure.structureType !== STRUCTURE_EXTENSION && structure.structureType !== STRUCTURE_SPAWN) { + return false + } + return structure.energyCapacity && structure.energy < structure.energyCapacity } - return structure.energyCapacity && structure.energy < structure.energyCapacity - }}) + }) const structure = builder.pos.findClosestByRange(structures) if (!builder.pos.isNearTo(structure)) { @@ -399,7 +401,7 @@ class EmpireExpand extends kernel.process { upgrade () { const controller = this.colony.controller const closestCity = this.getClosestCity(this.data.colony) - const upgraders = this.getCluster(`upgraders`, closestCity) + const upgraders = this.getCluster('upgraders', closestCity) if (!this.data.deathwatch) { let quantity = 2 if (this.data.recover) { diff --git a/src/programs/empire/intel.js b/src/programs/empire/intel.js index 5b9d331..faff7ea 100644 --- a/src/programs/empire/intel.js +++ b/src/programs/empire/intel.js @@ -81,7 +81,7 @@ class EmpireIntel extends kernel.process { const targets = Object.keys(Memory.intel.targets) if (targets.length > MAX_INTEL_TARGETS) { targets.sort((a, b) => Memory.intel.targets[a] - Memory.intel.targets[b]) - for (let target of targets) { + for (const target of targets) { if (Object.keys(Memory.intel.targets).length <= MAX_INTEL_TARGETS) { break } diff --git a/src/programs/empire/market.js b/src/programs/empire/market.js index 2e7661d..283e68a 100644 --- a/src/programs/empire/market.js +++ b/src/programs/empire/market.js @@ -19,7 +19,7 @@ class EmpireMarket extends kernel.process { if (!this.data.lma || Game.time - this.data.lma > TERMINAL_COOLDOWN) { this.terminals = _.shuffle(Empire.terminals) - for (let terminal of this.terminals) { + for (const terminal of this.terminals) { this.manageTerminal(terminal) } } @@ -40,14 +40,14 @@ class EmpireMarket extends kernel.process { if (energyTarget) { // Max cost of sending 1 energy is 1, for a total of two energy. const amount = Math.min(5000, terminal.store[RESOURCE_ENERGY] / 2) - terminal.send(RESOURCE_ENERGY, amount, energyTarget, `interempire energy transfer`) + terminal.send(RESOURCE_ENERGY, amount, energyTarget, 'interempire energy transfer') return } } // Sell any resources in terminal. const carrying = Object.keys(terminal.store) - for (let resource of carrying) { + for (const resource of carrying) { if (resource === RESOURCE_ENERGY) { continue } @@ -68,7 +68,7 @@ class EmpireMarket extends kernel.process { continue } - let useableAmount = terminal.store[resource] + const useableAmount = terminal.store[resource] // Is it needed by storage? const storageNeed = terminal.room.storage.getResourceNeed(resource) @@ -83,7 +83,7 @@ class EmpireMarket extends kernel.process { this.data.sent[target] = {} } this.data.sent[target][resource] = Game.time - terminal.send(resource, Math.min(1000, useableAmount), target, `interempire resource transfer`) + terminal.send(resource, Math.min(1000, useableAmount), target, 'interempire resource transfer') return } @@ -177,7 +177,7 @@ class EmpireMarket extends kernel.process { RESOURCE_CATALYZED_GHODIUM_ACID, RESOURCE_CATALYZED_GHODIUM_ALKALIDE ] - for (let resource of resources) { + for (const resource of resources) { qlib.market.getAveragePrice(resource, ORDER_BUY) qlib.market.getAveragePrice(resource, ORDER_SELL) } diff --git a/src/programs/empire/observers.js b/src/programs/empire/observers.js index 4487c04..993bb89 100644 --- a/src/programs/empire/observers.js +++ b/src/programs/empire/observers.js @@ -7,7 +7,7 @@ class EmpireObservers extends kernel.process { } main () { - if (Game.rooms['sim']) { + if (Game.rooms.sim) { return } const cities = Room.getCities() diff --git a/src/programs/meta/maintenance.js b/src/programs/meta/maintenance.js index 0c0b3e1..655fcaa 100644 --- a/src/programs/meta/maintenance.js +++ b/src/programs/meta/maintenance.js @@ -6,6 +6,7 @@ class MetaMaintenance extends kernel.process { getPriority () { return PRIORITIES_MAINTENANCE } + main () { if (!Memory.construction) { Memory.construction = {} diff --git a/src/programs/meta/monitor.js b/src/programs/meta/monitor.js index 1aaedd0..c1934a5 100644 --- a/src/programs/meta/monitor.js +++ b/src/programs/meta/monitor.js @@ -9,9 +9,11 @@ class MetaMonitor extends kernel.process { getPriority () { return this.data.priority } + getDescriptor () { return this.data.priority } + main () { sos.lib.monitor.markRun(this.data.priority) } diff --git a/src/programs/player.js b/src/programs/player.js index 6bb6b2d..628a4ee 100644 --- a/src/programs/player.js +++ b/src/programs/player.js @@ -36,14 +36,14 @@ class Player extends kernel.process { /* Launch a "City" program for each city saved in memory. `Room.addCity` to add new rooms. */ if (Game.rooms[roomname] && Game.rooms[roomname].controller && Game.rooms[roomname].controller.my) { this.launchChildProcess(`room_${roomname}`, 'city', { - 'room': roomname + room: roomname }) } } - for (let priority of MONITOR_PRIORITIES) { + for (const priority of MONITOR_PRIORITIES) { this.launchChildProcess(`pmonitor_${priority}`, 'meta_monitor', { - 'priority': priority + priority: priority }) } @@ -54,7 +54,7 @@ class Player extends kernel.process { const lastAdd = qlib.events.getTimeSinceEvent('addcity') if (empireAge > 10000 && lastAdd > 2000) { const defaultPriorityStats = sos.lib.monitor.getPriorityRunStats(PRIORITIES_CREEP_DEFAULT) - if (defaultPriorityStats && defaultPriorityStats['long'] <= 1.25) { + if (defaultPriorityStats && defaultPriorityStats.long <= 1.25) { if (cities.length < Game.gcl.level) { if (cities.length > 1 || (Game.rooms[cities[0]] && Game.rooms[cities[0]].getRoomSetting('EXPAND_FROM'))) { this.launchChildProcess('expand', 'empire_expand') diff --git a/src/programs/respawner.js b/src/programs/respawner.js index 87d7881..87f9e7b 100644 --- a/src/programs/respawner.js +++ b/src/programs/respawner.js @@ -26,7 +26,7 @@ class Respawn extends kernel.process { } } /* Remove all construction sites */ - for (let siteId of Object.keys(Game.constructionSites)) { + for (const siteId of Object.keys(Game.constructionSites)) { Game.constructionSites[siteId].remove() } } diff --git a/src/programs/spawns.js b/src/programs/spawns.js index c2e38af..aa347a3 100644 --- a/src/programs/spawns.js +++ b/src/programs/spawns.js @@ -19,7 +19,7 @@ class Spawns extends kernel.process { } this.room = Game.rooms[this.data.room] const maxspawns = CONTROLLER_STRUCTURES[STRUCTURE_SPAWN][this.room.controller.level] - const spawns = this.room.find(FIND_MY_SPAWNS, {filter: (s, i, c) => ((c.length <= maxspawns) || (s.isActive()))}) + const spawns = this.room.find(FIND_MY_SPAWNS, { filter: (s, i, c) => ((c.length <= maxspawns) || (s.isActive())) }) let spawn for (spawn of spawns) { diff --git a/src/qos/kernel.js b/src/qos/kernel.js index 56286be..1621c0f 100644 --- a/src/qos/kernel.js +++ b/src/qos/kernel.js @@ -29,7 +29,7 @@ class QosKernel { Memory.qos = {} } this.newglobal = GLOBAL_LAST_RESET === Game.time - this.simulation = !!Game.rooms['sim'] + this.simulation = !!Game.rooms.sim this.scheduler = new Scheduler() this.performance = new Performance() this.process = Process @@ -51,14 +51,14 @@ class QosKernel { } if (this.newglobal) { - Logger.log(`New Global Detected`, LOG_INFO) + Logger.log('New Global Detected', LOG_INFO) } if (IVM && global.gc && (!Memory.qos.gc || Game.time - Memory.qos.gc >= MIN_TICKS_BETWEEN_GC)) { const heap = Game.cpu.getHeapStatistics() const heapPercent = heap.total_heap_size / heap.heap_size_limit if (heapPercent > GC_HEAP_TRIGGER) { - Logger.log(`Garbage Collection Initiated`, LOG_INFO, 'kernel') + Logger.log('Garbage Collection Initiated', LOG_INFO, 'kernel') Memory.qos.gc = Game.time global.gc() } @@ -68,7 +68,7 @@ class QosKernel { sos.lib.stormtracker.track() if (sos.lib.stormtracker.isStorming()) { - Logger.log(`Reset Storm Detected`, LOG_INFO) + Logger.log('Reset Storm Detected', LOG_INFO) } if (Game.time % 7 === 0) { @@ -122,7 +122,7 @@ class QosKernel { } catch (err) { const errorText = !!err && !!err.stack ? err.stack : err.toString() if (errorText.includes('RangeError: Array buffer allocation failed')) { - let message = 'RangeError: Array buffer allocation failed' + const message = 'RangeError: Array buffer allocation failed' Logger.log(message, LOG_ERROR, 'ivm') } else { let message = 'program error occurred\n' diff --git a/src/qos/logger.js b/src/qos/logger.js index 36df851..6c7cb34 100644 --- a/src/qos/logger.js +++ b/src/qos/logger.js @@ -9,13 +9,13 @@ global.LOG_TRACE = 0 const NOTIFY_RATELIMIT = 1500 const ERROR_COLORS = { - '5': '#ff0066', - '4': '#e65c00', - '3': '#809fff', - '2': '#999999', - '1': '#737373', - '0': '#666666', - 'highlight': '#ffff00' + 5: '#ff0066', + 4: '#e65c00', + 3: '#809fff', + 2: '#999999', + 1: '#737373', + 0: '#666666', + highlight: '#ffff00' } class Logger { @@ -75,7 +75,7 @@ class Logger { highlight (message) { return this.log(message, 'highlight', false, { - 'type': 'highlight' + type: 'highlight' }) } diff --git a/src/qos/performance.js b/src/qos/performance.js index a0774c7..59fb0c9 100644 --- a/src/qos/performance.js +++ b/src/qos/performance.js @@ -4,8 +4,8 @@ class Performance { constructor () { if (!Memory.qos.performance) { Memory.qos.performance = { - 'start': Game.time, - 'programs': {} + start: Game.time, + programs: {} } } } @@ -31,11 +31,11 @@ class Performance { const programs = Object.keys(Memory.qos.performance.programs) programs.sort((a, b) => Memory.qos.performance.programs[b].cpu - Memory.qos.performance.programs[a].cpu) let report = 'Program\tAverage\tMax Cpu\t Total Cpu \t Ticks Run\n' - for (let program of programs) { - let max = Memory.qos.performance.programs[program].max - let cpu = Memory.qos.performance.programs[program].cpu - let count = Memory.qos.performance.programs[program].count - let average = cpu / count + for (const program of programs) { + const max = Memory.qos.performance.programs[program].max + const cpu = Memory.qos.performance.programs[program].cpu + const count = Memory.qos.performance.programs[program].count + const average = cpu / count report += `${program}\t ${average.toFixed(3)}\t${max.toFixed(3)}\t${cpu.toFixed(3)}\t${count}\n` } Logger.log(report, LOG_WARN, 'performance') @@ -57,14 +57,14 @@ class Performance { report += '3000 Ticks' report += '' - for (let priority of monitoriedPriorities) { + for (const priority of monitoriedPriorities) { const stats = sos.lib.monitor.getPriorityRunStats(priority) if (stats) { report += '' report += `${priority}` - report += `${stats['short'].toFixed(3)}` - report += `${stats['medium'].toFixed(3)}` - report += `${stats['long'].toFixed(3)}` + report += `${stats.short.toFixed(3)}` + report += `${stats.medium.toFixed(3)}` + report += `${stats.long.toFixed(3)}` report += '' } } @@ -81,11 +81,11 @@ class Performance { report += 'Total CPU' report += 'Ticks Run' report += '' - for (let program of programs) { - let max = Memory.qos.performance.programs[program].max - let cpu = Memory.qos.performance.programs[program].cpu - let count = Memory.qos.performance.programs[program].count - let average = cpu / count + for (const program of programs) { + const max = Memory.qos.performance.programs[program].max + const cpu = Memory.qos.performance.programs[program].cpu + const count = Memory.qos.performance.programs[program].count + const average = cpu / count report += '' report += `${program}` report += `${average.toFixed(3)}` @@ -100,8 +100,8 @@ class Performance { clear () { Memory.qos.performance = { - 'start': Game.time, - 'programs': {} + start: Game.time, + programs: {} } } } diff --git a/src/qos/process.js b/src/qos/process.js index 3e7fc82..eec6e42 100644 --- a/src/qos/process.js +++ b/src/qos/process.js @@ -115,7 +115,7 @@ class Process { } const creepName = room.queueCreep(role, options) this.launchChildProcess(specificLabel, 'creep', { - 'creep': creepName + creep: creepName }) } } diff --git a/src/qos/scheduler.js b/src/qos/scheduler.js index 45d5fb4..90bbed8 100644 --- a/src/qos/scheduler.js +++ b/src/qos/scheduler.js @@ -15,11 +15,11 @@ class Scheduler { this.processCache = {} if (!this.memory.processes) { this.memory.processes = { - 'index': {}, - 'running': false, - 'completed': [], - 'queues': {}, - 'sleep': {} + index: {}, + running: false, + completed: [], + queues: {}, + sleep: {} } } else { // For upgrading @@ -46,7 +46,7 @@ class Scheduler { // Resume the right processes for (let pid in this.memory.processes.sleep.list) { pid = Number(pid) - let tick = this.memory.processes.sleep.list[pid] + const tick = this.memory.processes.sleep.list[pid] if (tick <= Game.time) { this.wake(pid) } else { @@ -218,7 +218,7 @@ class Scheduler { if (!self) { for (let i in this.memory.processes.queues) { i = Number(i) - let queue = this.memory.processes.queues[i] + const queue = this.memory.processes.queues[i] const index = queue.indexOf(pid) if (index > -1) { queue.splice(index, 1) diff --git a/src/roles/factotum.js b/src/roles/factotum.js index 2263d8d..44398f4 100644 --- a/src/roles/factotum.js +++ b/src/roles/factotum.js @@ -14,7 +14,7 @@ class Factotum extends MetaRole { getBuild (room, options) { this.setBuildDefaults(room, options) - let build = [MOVE, CARRY, CARRY, CARRY, CARRY] + const build = [MOVE, CARRY, CARRY, CARRY, CARRY] return Creep.buildFromTemplate(build, options.energy) } @@ -187,13 +187,13 @@ class Factotum extends MetaRole { if (creep.pos.isNearTo(feeders[0])) { creep.transfer(feeders[0], reaction[0]) } else { - creep.travelTo(feeders[0], {'ignoreCore': true}) + creep.travelTo(feeders[0], { ignoreCore: true }) } } else if (creep.carry[reaction[1]] && feeders[1].canFill()) { if (creep.pos.isNearTo(feeders[1])) { creep.transfer(feeders[1], reaction[1]) } else { - creep.travelTo(feeders[1], {'ignoreCore': true}) + creep.travelTo(feeders[1], { ignoreCore: true }) } } else { delete creep.memory.filling @@ -235,7 +235,7 @@ class Factotum extends MetaRole { if (creep.pos.isNearTo(lab)) { creep.withdraw(lab, lab.mineralType) } else { - creep.travelTo(lab, {'ignoreCore': true}) + creep.travelTo(lab, { ignoreCore: true }) } } @@ -324,7 +324,7 @@ class Factotum extends MetaRole { if (creep.pos.isNearTo(structure)) { creep.transfer(structure, RESOURCE_ENERGY) } else { - creep.travelTo(structure, {'ignoreCore': true}) + creep.travelTo(structure, { ignoreCore: true }) } } @@ -370,7 +370,7 @@ class Factotum extends MetaRole { } goHome (creep) { - return creep.travelTo(creep.room.getFactotumHome(), {'ignoreCore': true}) + return creep.travelTo(creep.room.getFactotumHome(), { ignoreCore: true }) } } diff --git a/src/roles/spook.js b/src/roles/spook.js index d044d39..0dfdbf6 100644 --- a/src/roles/spook.js +++ b/src/roles/spook.js @@ -58,7 +58,7 @@ class Spook extends MetaRole { stompConstruction (creep) { // Use cached construction site if (creep.memory.stomp) { - let construction = Game.getObjectById(creep.memory.stomp) + const construction = Game.getObjectById(creep.memory.stomp) if (construction) { creep.travelTo(construction) return true @@ -67,9 +67,11 @@ class Spook extends MetaRole { } } // Find a new site to stomp, excluding any being stood on. - const construction = creep.pos.findClosestByRange(FIND_HOSTILE_CONSTRUCTION_SITES, {filter: function (site) { - return site.pos.getRangeTo(creep) > 0 - }}) + const construction = creep.pos.findClosestByRange(FIND_HOSTILE_CONSTRUCTION_SITES, { + filter: function (site) { + return site.pos.getRangeTo(creep) > 0 + } + }) if (!construction) { return false } diff --git a/test/extends/roomposition/createBoundingBoxForRange.js b/test/extends/roomposition/createBoundingBoxForRange.js index fd27243..ca48d1a 100644 --- a/test/extends/roomposition/createBoundingBoxForRange.js +++ b/test/extends/roomposition/createBoundingBoxForRange.js @@ -1,9 +1,9 @@ 'use strict' -import test from 'ava' +const test = require('ava') -import '../../helpers/screeps-globals' +require('../../helpers/screeps-globals') -import { createBoundingBoxForRange } from '../../../src/extends/roomposition' +const { createBoundingBoxForRange } = require('../../../src/extends/roomposition') const BOUND_MIN = 0 const BOUND_MAX = 49