File room-intel.ts
has 652 lines of code (exceeds 250 allowed). Consider refactoring. Open
/* global PathFinder Room RoomPosition
STRUCTURE_KEEPER_LAIR STRUCTURE_CONTROLLER FIND_SOURCES
TERRAIN_MASK_WALL TERRAIN_MASK_SWAMP POWER_BANK_DECAY STRUCTURE_PORTAL
STRUCTURE_POWER_BANK FIND_MY_CONSTRUCTION_SITES STRUCTURE_STORAGE
STRUCTURE_TERMINAL FIND_RUINS STRUCTURE_INVADER_CORE EFFECT_COLLAPSE_TIMER */
RoomIntel
has 41 functions (exceeds 20 allowed). Consider refactoring. Open
export default class RoomIntel {
roomName: string;
memory: RoomIntelMemory;
newStatus: Record<string, boolean>;
Function calculateAdjacentRoomSafety
has 74 lines of code (exceeds 25 allowed). Consider refactoring. Open
calculateAdjacentRoomSafety(options?: {safe?: string[]; unsafe?: string[]}): {directions: Record<string, boolean>; safeRooms: string[]} {
return cache.inHeap('adjacentSafety:' + this.roomName, 100, () => {
if (!this.memory.exits) {
return {
directions: {
Function gatherDepositIntel
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
gatherDepositIntel() {
delete this.memory.deposits;
const room = Game.rooms[this.roomName];
const deposits = room.find(FIND_DEPOSITS);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function gatherTerrainIntel
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
gatherTerrainIntel() {
// Check terrain.
this.memory.terrain = {
exit: 0,
wall: 0,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function handleAdjacentRoom
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
handleAdjacentRoom(roomData: AdjacentRoomEntry, openList: Record<string, AdjacentRoomEntry>, closedList: Record<string, AdjacentRoomEntry>) {
const roomIntel = getRoomIntel(roomData.room);
if (roomIntel.getAge() > 100_000) {
// Room has no intel, declare it as unsafe.
this.newStatus[roomData.origin] = false;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function gatherDepositIntel
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
gatherDepositIntel() {
delete this.memory.deposits;
const room = Game.rooms[this.roomName];
const deposits = room.find(FIND_DEPOSITS);
Function gatherIntel
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
gatherIntel() {
const room = Game.rooms[this.roomName];
if (!room) return;
const intel = this.memory;
Function getCostMatrix
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
getCostMatrix(): CostMatrix {
// @todo For some reason, calling this in console gives a different version of the cost matrix. Verify!
let obstaclePositions: {obstacles: RoomPosition[]; roads: RoomPosition[]};
if (this.memory.costPositions) {
obstaclePositions = {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getCostMatrix
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
getCostMatrix(): CostMatrix {
// @todo For some reason, calling this in console gives a different version of the cost matrix. Verify!
let obstaclePositions: {obstacles: RoomPosition[]; roads: RoomPosition[]};
if (this.memory.costPositions) {
obstaclePositions = {
Function gatherPowerIntel
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
gatherPowerIntel(powerBanks: StructurePowerBank[]) {
delete this.memory.power;
const powerBank: StructurePowerBank = _.first(powerBanks);
if (!powerBank || powerBank.hits === 0 || powerBank.power === 0) return;
Function gatherTerrainIntel
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
gatherTerrainIntel() {
// Check terrain.
this.memory.terrain = {
exit: 0,
wall: 0,
Function gatherAbandonedResourcesIntel
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
gatherAbandonedResourcesIntel(structures: Record<string, Structure[]>, ruins: Ruin[]) {
// Find origin room.
if (!Memory.strategy) return;
if (!Memory.strategy.roomList) return;
const strategyInfo = Memory.strategy.roomList[this.roomName];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function gatherAbandonedResourcesIntel
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
gatherAbandonedResourcesIntel(structures: Record<string, Structure[]>, ruins: Ruin[]) {
// Find origin room.
if (!Memory.strategy) return;
if (!Memory.strategy.roomList) return;
const strategyInfo = Memory.strategy.roomList[this.roomName];
Function gatherIntel
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
gatherIntel() {
const room = Game.rooms[this.roomName];
if (!room) return;
const intel = this.memory;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function gatherPowerIntel
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
gatherPowerIntel(powerBanks: StructurePowerBank[]) {
delete this.memory.power;
const powerBank: StructurePowerBank = _.first(powerBanks);
if (!powerBank || powerBank.hits === 0 || powerBank.power === 0) return;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function isPotentiallyUnsafeRoom
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
isPotentiallyUnsafeRoom(roomName: string): boolean {
if (this.otherUnsafeRooms.includes(roomName)) return true;
if (this.otherSafeRooms.includes(roomName)) return false;
if (Game.rooms[roomName] && Game.rooms[roomName].isMine()) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
if (!structures[STRUCTURE_STORAGE] && !structures[STRUCTURE_TERMINAL] && ruins.length === 0) return;
Avoid too many return
statements within this function. Open
if (_.keys(resources).length === 0) return;
Avoid too many return
statements within this function. Open
if (this.memory.owner) return;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return;
Function gatherControllerIntel
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
gatherControllerIntel(room: Room) {
this.memory.owner = null;
this.memory.rcl = 0;
this.memory.ticksToDowngrade = 0;
this.memory.hasController = typeof room.controller !== 'undefined';
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function gatherPortalIntel
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
gatherPortalIntel(portals: StructurePortal[]) {
delete this.memory.portals;
const targetRooms: string[] = [];
for (const portal of portals || []) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Open
handleMapArea(powerBank.pos.x, powerBank.pos.y, (x, y) => {
if (terrain.get(x, y) !== TERRAIN_MASK_WALL) {
numberFreeTiles++;
}
});
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 57.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
handleMapArea(deposit.pos.x, deposit.pos.y, (x, y) => {
if (terrain.get(x, y) !== TERRAIN_MASK_WALL) {
numberFreeTiles++;
}
});
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 57.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
_.each(Game.rooms[this.roomName].roomPlanner.getLocations('bay_center'), pos => {
if (matrix.get(pos.x, pos.y) <= 20) {
matrix.set(pos.x, pos.y, 20);
}
});
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 56.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!Memory.strategy.power.rooms[this.roomName] || !Memory.strategy.power.rooms[this.roomName].isActive) {
Memory.strategy.power.rooms[this.roomName] = this.memory.power;
// @todo Update info when gathering is active.
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 54.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!Memory.strategy.deposits.rooms[this.roomName] || !Memory.strategy.deposits.rooms[this.roomName].isActive) {
Memory.strategy.deposits.rooms[this.roomName] = {scouted: true};
// @todo Update info when gathering is active.
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 54.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
sources: Array<{
x: number;
y: number;
id: Id<Source>;
free: number;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 46.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
getSourcePositions(): Array<{x: number; y: number; id: Id<Source>; free: number}> {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 46.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76