MSUTeam / MSU

Modding Standards and Utilities for Battle Brothers
22 stars 4 forks source link

Declutter the 'showCombatDialog' function from 'world_state.nut' to improve hooking from mods #90

Open Darxo opened 2 years ago

Darxo commented 2 years ago

The current 'showCombatDialog' is a 260 line mess of a function if you want to hook into its behaviour.

Specific examples of possible subfunctions:

  1. function getInvolvedParties(_position)

    • it returns an array
    • it would essentially consist of the following vanilla code:

      
      if (parties.len() <= 1)
      {
          this.m.EngageCombatPos = null;
          return;
      }
      
      foreach( party in parties )
      {
          if (!party.isAlive() || party.isPlayerControlled())
          {
              continue;
          }
      
          if (!party.isAttackable() || party.getFaction() == 0 || party.getVisibilityMult() == 0)
          {
              continue;
          }
      
          if (party.isLocation() && party.isLocationType(this.Const.World.LocationType.Unique))
          {
              parties = [party];      // shortcut to the unique location code from the vanilla
              break;
          }
      
          if (party.isInCombat())
          {
              parties = this.World.getAllEntitiesAtPos(_pos, this.Const.World.CombatSettings.CombatPlayerDistance * 2.0);
              break;
          }
      }
  1. function genEntityUIArray(_championArray, _entitiyTypeArray)

    • it returns an array with objects that have Name, Icon and Overlay variables in them
    • it would essentially consist of the following vanilla code

      foreach( c in champions )
      {
          entities.push({
              Name = c.Name,
              Icon = this.Const.EntityIcon[c.ID],
              Overlay = "icons/miniboss.png"
          });
      }
      
      for( local i = 0; i < entityTypes.len(); i = ++i )
      {
          if (entityTypes[i] > 0)
          {
              if (entityTypes[i] == 1)
              {
                  local start = this.isFirstCharacter(this.Const.Strings.EntityName[i], [
                      "A",
                      "E",
                      "I",
                      "O",
                      "U"
                  ]) ? "An " : "A ";
                  entities.push({
                      Name = start + this.removeFromBeginningOfText("The ", this.Const.Strings.EntityName[i]),
                      Icon = this.Const.EntityIcon[i],
                      Overlay = null
                  });
              }
              else
              {
                  local num = this.Const.Strings.EngageEnemyNumbers[this.Math.max(0, this.Math.floor(this.Math.minf(1.0, entityTypes[i] / 14.0) * (this.Const.Strings.EngageEnemyNumbers.len() - 1)))];
                  entities.push({
                      Name = num + " " + this.Const.Strings.EntityNamePlural[i],
                      Icon = this.Const.EntityIcon[i],
                      Overlay = null
                  });
              }
          }
      }
Enduriel commented 2 years ago

If you wanna make a PR @Darxo feel free btw, would make it easier to review the code and make specific suggestions. Also when writing code in issues you can use ```squirrel to make your code highlight properly.

Overall though I quite like this suggestion.

LordMidas commented 2 years ago

For making PR I'd suggest waiting until we release 1.0.0 as we have to merge lots of stuff into main yet which will completely change how MSU is organized.

Enduriel @.***> schrieb am Fr., 8. Apr. 2022, 08:32:

If you wanna make a PR @Darxo https://github.com/Darxo feel free btw, would make it easier to review the code and make specific suggestions. Also when writing code in issues you can use ```squirrel to make your code highlight properly.

Overall though I quite like this suggestion.

— Reply to this email directly, view it on GitHub https://github.com/Battle-Brothers-Legends/mod_MSU/issues/90#issuecomment-1092544085, or unsubscribe https://github.com/notifications/unsubscribe-auth/AND7N4EXNGNPNJ6KJTWMO3TVD7OJ3ANCNFSM5S3K5QGA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

TaroEld commented 2 years ago

At the same time, getLocalCombatProperties of world_state should receive the same treatment.