Mirroar/hivemind

View on GitHub
src/manager.military.ts

Summary

Maintainability
F
4 days
Test Coverage

Function assertMilitaryCreepPower has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

Room.prototype.assertMilitaryCreepPower = function (this: Room, creep: Creep | PowerCreep) {
    let hostile: boolean;
    let targets: Array<Creep | PowerCreep>;
    let allies: Array<Creep | PowerCreep>;
    if (creep.my) {
Severity: Minor
Found in src/manager.military.ts - About 3 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

File manager.military.ts has 258 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* global Creep Room FIND_CREEPS BOOSTS ATTACK
RANGED_ATTACK HEAL STRUCTURE_TOWER TOWER_POWER_HEAL TOWER_POWER_ATTACK
ATTACK_POWER RANGED_ATTACK_POWER HEAL_POWER RANGED_HEAL_POWER
CARRY CLAIM MOVE TOUGH WORK TOWER_ENERGY_COST */

Severity: Minor
Found in src/manager.military.ts - About 2 hrs to fix

    Function assertMilitaryCreepPower has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Room.prototype.assertMilitaryCreepPower = function (this: Room, creep: Creep | PowerCreep) {
        let hostile: boolean;
        let targets: Array<Creep | PowerCreep>;
        let allies: Array<Creep | PowerCreep>;
        if (creep.my) {
    Severity: Minor
    Found in src/manager.military.ts - About 2 hrs to fix

      Function assertMilitarySituation has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      Room.prototype.assertMilitarySituation = function (this: Room) {
          if (this._sitRepBuilt) return;
      
          this._sitRepBuilt = true;
          this.sitRep = {
      Severity: Minor
      Found in src/manager.military.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 assertMilitarySituation has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Room.prototype.assertMilitarySituation = function (this: Room) {
          if (this._sitRepBuilt) return;
      
          this._sitRepBuilt = true;
          this.sitRep = {
      Severity: Minor
      Found in src/manager.military.ts - About 1 hr to fix

        Function drawMilitarySituation has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Room.prototype.drawMilitarySituation = function (this: Room) {
            const visual = this.visual;
            _.each(this.sitRep.damage, (colData, x: string) => {
                _.each(colData, (data, y: string) => {
                    visual.text(data.toString(), Number(x), Number(y) - 0.1, {
        Severity: Minor
        Found in src/manager.military.ts - About 1 hr to fix

          Function assertMilitaryStructurePower has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          Room.prototype.assertMilitaryStructurePower = function (this: Room, structure: StructureTower) {
              if (structure.store[RESOURCE_ENERGY] < TOWER_ENERGY_COST) return;
              // Don't count our towers if they're almost empty so we don't shoot at targets
              // we can't kill after all.
              if (structure.my && structure.store[RESOURCE_ENERGY] < TOWER_ENERGY_COST * 10) return;
          Severity: Minor
          Found in src/manager.military.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 getTowerTarget has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          Room.prototype.getTowerTarget = function (this: Room) {
              this.assertMilitarySituation();
              let max = null;
              for (const creep of this.militaryObjects.creeps) {
                  if (!creep.militaryPriority) continue;
          Severity: Minor
          Found in src/manager.military.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

          Function addMilitaryAssertion has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          Room.prototype.addMilitaryAssertion = function (this: Room, x: number, y: number, amount: number, type: string): void {
          Severity: Minor
          Found in src/manager.military.ts - About 35 mins to fix

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

                _.each(this.sitRep.healing, (colData, x: string) => {
                    _.each(colData, (data, y: string) => {
                        visual.text(data.toString(), Number(x), (Number(y)) + 0.4, {
                            color: 'green',
                            font: 0.5,
            Severity: Major
            Found in src/manager.military.ts and 3 other locations - About 3 hrs to fix
            src/manager.military.ts on lines 334..341
            src/manager.military.ts on lines 352..359
            src/manager.military.ts on lines 361..368

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

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

                _.each(this.sitRep.myHealing, (colData, x: string) => {
                    _.each(colData, (data, y: string) => {
                        visual.text(data.toString(), Number(x), (Number(y)) + 0.4, {
                            color: 'green',
                            font: 0.5,
            Severity: Major
            Found in src/manager.military.ts and 3 other locations - About 3 hrs to fix
            src/manager.military.ts on lines 334..341
            src/manager.military.ts on lines 343..350
            src/manager.military.ts on lines 352..359

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

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

                _.each(this.sitRep.myDamage, (colData, x: string) => {
                    _.each(colData, (data, y: string) => {
                        visual.text(data.toString(), Number(x), Number(y) - 0.1, {
                            color: 'red',
                            font: 0.5,
            Severity: Major
            Found in src/manager.military.ts and 3 other locations - About 3 hrs to fix
            src/manager.military.ts on lines 334..341
            src/manager.military.ts on lines 343..350
            src/manager.military.ts on lines 361..368

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

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

                _.each(this.sitRep.damage, (colData, x: string) => {
                    _.each(colData, (data, y: string) => {
                        visual.text(data.toString(), Number(x), Number(y) - 0.1, {
                            color: 'red',
                            font: 0.5,
            Severity: Major
            Found in src/manager.military.ts and 3 other locations - About 3 hrs to fix
            src/manager.military.ts on lines 343..350
            src/manager.military.ts on lines 352..359
            src/manager.military.ts on lines 361..368

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

            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 creep of creeps) {
                    if (creep.my) {
                        // @todo Filter out civilian creeps to save on CPU.
                        this.militaryObjects.myCreeps.push(creep);
                    }
            Severity: Major
            Found in src/manager.military.ts and 1 other location - About 3 hrs to fix
            src/manager.military.ts on lines 89..97

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

            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 powerCreep of powerCreeps) {
                    if (powerCreep.my) {
                        // @todo Filter out civilian creeps to save on CPU.
                        this.militaryObjects.myCreeps.push(powerCreep);
                    }
            Severity: Major
            Found in src/manager.military.ts and 1 other location - About 3 hrs to fix
            src/manager.military.ts on lines 78..86

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

            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 target of targets) {
                    const pos = target.pos;
                    const power = structure.getPowerAtRange(structure.pos.getRangeTo(pos));
                    this.addMilitaryAssertion(pos.x, pos.y, power * TOWER_POWER_ATTACK, hostile ? 'damage' : 'myDamage');
                }
            Severity: Major
            Found in src/manager.military.ts and 1 other location - About 1 hr to fix
            src/manager.military.ts on lines 226..230

            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 ally of allies) {
                    const pos = ally.pos;
                    const power = structure.getPowerAtRange(structure.pos.getRangeTo(pos));
                    this.addMilitaryAssertion(pos.x, pos.y, power * TOWER_POWER_HEAL, hostile ? 'healing' : 'myHealing');
                }
            Severity: Major
            Found in src/manager.military.ts and 1 other location - About 1 hr to fix
            src/manager.military.ts on lines 232..236

            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

            There are no issues that match your filters.

            Category
            Status