Mirroar/hivemind

View on GitHub
src/creep/combat-manager.ts

Summary

Maintainability
F
5 days
Test Coverage

Function addEnemyRangeScore has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
Open

    private addEnemyRangeScore(creep: Creep, enemyCreeps: Creep[], positions: ScoredPosition[]) {
        const maxRange = this.getMaxAttackRange(creep);
        const isRangedCreep = maxRange > 1;

        // @todo Corner positions are beneficial when we're fleeing, and
Severity: Minor
Found in src/creep/combat-manager.ts - About 1 day to fix

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

File combat-manager.ts has 350 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import hivemind from 'hivemind';
import utilities from 'utilities';
import {getResourcesIn} from 'utils/store';
import {handleMapArea} from 'utils/map';

Severity: Minor
Found in src/creep/combat-manager.ts - About 4 hrs to fix

    CombatManager has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class CombatManager {
        tileCache: Record<number, number>;
        tileCacheTime: number;
    
        hasRangedAttacked: boolean;
    Severity: Minor
    Found in src/creep/combat-manager.ts - About 2 hrs to fix

      Function getNearbyTargets has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          private getNearbyTargets(creep: Creep): AttackTarget[] {
              const availableTargets = [];
              const maxRange = this.getMaxAttackRange(creep);
      
              for (const enemyName in creep.room.enemyCreeps) {
      Severity: Minor
      Found in src/creep/combat-manager.ts - About 2 hrs to fix

      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 healNearbyTargets has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          private healNearbyTargets(creep: Creep) {
              const healParts = creep.getActiveBodyparts(HEAL);
              if (healParts === 0) return;
      
              const targets = creep.pos.findInRange(FIND_CREEPS, 3, {
      Severity: Minor
      Found in src/creep/combat-manager.ts - About 2 hrs to fix

      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 getAllTargetsInRoom has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          private getAllTargetsInRoom(room: Room): AttackTarget[] {
              const allTargets = [];
      
              // Attack harvest / transport creeps, ideally those with energy in them.
              for (const enemyName in room.enemyCreeps) {
      Severity: Minor
      Found in src/creep/combat-manager.ts - About 1 hr to fix

      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 addEnemyRangeScore has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private addEnemyRangeScore(creep: Creep, enemyCreeps: Creep[], positions: ScoredPosition[]) {
              const maxRange = this.getMaxAttackRange(creep);
              const isRangedCreep = maxRange > 1;
      
              // @todo Corner positions are beneficial when we're fleeing, and
      Severity: Minor
      Found in src/creep/combat-manager.ts - About 1 hr to fix

        Function scoreTargets has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private scoreTargets(creep: Creep, targets: AttackTarget[]): Array<{
                weight: number;
                priority: number;
                object: AttackTarget;
            }> {
        Severity: Minor
        Found in src/creep/combat-manager.ts - About 1 hr to fix

          Function generateTileCache has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              private generateTileCache(pos: RoomPosition, encodedPos: string) {
                  if (this.tileCacheTime !== Game.time) {
                      this.tileCache = {};
                      this.tileCacheTime = Game.time;
                  }
          Severity: Minor
          Found in src/creep/combat-manager.ts - About 55 mins to fix

          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 getEnemyMilitaryCreeps has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public getEnemyMilitaryCreeps(room: Room): Creep[] {
                  const creeps = [];
                  for (const userName in room.enemyCreeps) {
                      if (hivemind.relations.isAlly(userName)) continue;
                      for (const enemyCreep of room.enemyCreeps[userName]) {
          Severity: Minor
          Found in src/creep/combat-manager.ts - About 55 mins to fix

          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 addTerrainScore has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              private addTerrainScore(creep: Creep, enemyCreeps: Creep[], positions: ScoredPosition[]) {
                  const isFleeing = _.some(enemyCreeps, c => !this.couldWinFightAgainst(creep, c));
          
                  for (const position of positions) {
                      if (this.isTileSwamp(position.pos)) position.score -= 100;
          Severity: Minor
          Found in src/creep/combat-manager.ts - About 55 mins to fix

          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 performKitingMovement has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public performKitingMovement(creep: Creep, target: AttackTarget) {
                  let targetRange = this.getMaxAttackRange(creep);
                  if (target instanceof Creep) {
                      const isMeleeCreep = target.getActiveBodyparts(ATTACK) > 0;
                      if (!isMeleeCreep) targetRange -= 1;
          Severity: Minor
          Found in src/creep/combat-manager.ts - About 45 mins to fix

          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

                  return false;
          Severity: Major
          Found in src/creep/combat-manager.ts - About 30 mins to fix

            Function couldWinFightAgainst has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public couldWinFightAgainst(creep: Creep, otherCreep: Creep): boolean {
                    if (
                        (
                            creep.getActiveBodyparts(RANGED_ATTACK) > 0 
                            || (creep.getActiveBodyparts(ATTACK) > 0 && otherCreep.getActiveBodyparts(RANGED_ATTACK) === 0)
            Severity: Minor
            Found in src/creep/combat-manager.ts - About 25 mins to fix

            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 3 locations. Consider refactoring.
            Open

                private isTilePlains(pos: RoomPosition): boolean {
                    const encodedPos = pos.roomName + ':' + (pos.x + (50 * pos.y));
                    this.generateTileCache(pos, encodedPos);
            
                    return this.tileCache[encodedPos] === TILE_PLAINS;
            Severity: Major
            Found in src/creep/combat-manager.ts and 2 other locations - About 2 hrs to fix
            src/creep/combat-manager.ts on lines 243..248
            src/creep/combat-manager.ts on lines 250..255

            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 81.

            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

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                private isTileWall(pos: RoomPosition): boolean {
                    const encodedPos = pos.roomName + ':' + (pos.x + (50 * pos.y));
                    this.generateTileCache(pos, encodedPos);
            
                    return this.tileCache[encodedPos] === TILE_WALL;
            Severity: Major
            Found in src/creep/combat-manager.ts and 2 other locations - About 2 hrs to fix
            src/creep/combat-manager.ts on lines 250..255
            src/creep/combat-manager.ts on lines 257..262

            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 81.

            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

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                private isTileSwamp(pos: RoomPosition): boolean {
                    const encodedPos = pos.roomName + ':' + (pos.x + (50 * pos.y));
                    this.generateTileCache(pos, encodedPos);
            
                    return this.tileCache[encodedPos] === TILE_SWAMP;
            Severity: Major
            Found in src/creep/combat-manager.ts and 2 other locations - About 2 hrs to fix
            src/creep/combat-manager.ts on lines 243..248
            src/creep/combat-manager.ts on lines 257..262

            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 81.

            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

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    if (terrain.get(pos.x, pos.y) & TERRAIN_MASK_SWAMP) {
                        if (!_.some(structures, s => s.structureType === STRUCTURE_ROAD)) {
                            this.tileCache[encodedPos] = TILE_SWAMP;
                            return;
                        }
            Severity: Major
            Found in src/creep/combat-manager.ts and 1 other location - About 1 hr to fix
            src/creep/combat-manager.ts on lines 274..279

            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 74.

            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

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    if (terrain.get(pos.x, pos.y) & TERRAIN_MASK_WALL) {
                        if (!_.some(structures, s => s.structureType === STRUCTURE_ROAD)) {
                            this.tileCache[encodedPos] = TILE_WALL;
                            return;
                        }
            Severity: Major
            Found in src/creep/combat-manager.ts and 1 other location - About 1 hr to fix
            src/creep/combat-manager.ts on lines 286..291

            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 74.

            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

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    for (const structure of room.structures) {
                        if (!structure.hits) continue;
                        if ('owner' in structure && hivemind.relations.isAlly(structure.owner?.username)) continue;
                        if (!('owner' in structure) && isMyRoom) continue;
            
            
            Severity: Major
            Found in src/creep/combat-manager.ts and 1 other location - About 1 hr to fix
            src/creep/combat-manager.ts on lines 119..125

            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 74.

            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

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    for (const structure of creep.pos.findInRange(FIND_STRUCTURES, maxRange)) {
                        if (!structure.hits) continue;
                        if ('owner' in structure && hivemind.relations.isAlly(structure.owner?.username)) continue;
                        if (!('owner' in structure) && isMyRoom) continue;
            
            
            Severity: Major
            Found in src/creep/combat-manager.ts and 1 other location - About 1 hr to fix
            src/creep/combat-manager.ts on lines 404..410

            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 74.

            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

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                        if (
                            position.pos.x === 0
                            || position.pos.x === 49
                            || position.pos.y === 0
                            || position.pos.y === 49
            Severity: Major
            Found in src/creep/combat-manager.ts and 1 other location - About 1 hr to fix
            src/creep-manager.ts on lines 111..111

            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 62.

            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

            Further Reading

            There are no issues that match your filters.

            Category
            Status