Whenever I try it doesn’t fill the main tank fast enough.

Tags
Question

4 Comments

  • Log in to leave a comment
  • Profile image

    @sflanker thank you. That worked a lot better!

    3.9 years ago
  • Profile image
    Mod sflanker

    For tanks that are connected via parts with "Fuel Line" enabled fuel is drained from the tank with the highest "Priority" value first (this setting is below Fuel Type in the part properties panel). So if you want to drain your "external" tanks first, leave your "main" tank's priority at 0 and set your "external" tanks' priorities to values larger than zero.

    3.9 years ago
  • Profile image

    @sflanker how would one change the main tank without changing what fuel tank the engines are attached to?

    3.9 years ago
  • Profile image
    Mod sflanker

    What's the behavior you are observing? When firing engines they should pull from all the tanks in the current group (connected directly or via parts with fuel lines) in priority order, so rates should not be an issue. If fuel isn't being drawn from some tanks then they are probably not connected (you need to enable fuel line on the tanks and other parts in between the engine and the tank). If your "main" tank is being emptied first but you want to empty the connected tanks first then you may need to adjust your tank priorities.

    If you specifically want to use a separate fuel tank and transfer fuel in using the part info panel during flight, the you are limited by the fuel transfer rate for the type of fuel, and the number of sources. So increasing the number of "external" tanks should increase the total transfer rate. If you're curious the code looks something like this:

    private void UpdateTransfer(FuelType fuelType, float deltaTime)
    {
      double totalSourceFuel = 0.0;
      double totalDestCapacity = 0.0;
      int destCount = 0;
      int sourceCount = 0;
      foreach (IFuelSource fuelSource in this.FuelSources)
      {
        if (fuelSource.FuelType == fuelType && fuelSource.FuelTransferMode == FuelTransferMode.Drain)
        {
          totalSourceFuel += fuelSource.TotalFuel;
          ++sourceCount;
        }
        else if (fuelSource.FuelType == fuelType && fuelSource.FuelTransferMode == FuelTransferMode.Fill)
        {
          double currentDestCapacity = Mathd.Clamp(fuelSource.TotalCapacity - fuelSource.TotalFuel, 0.0, fuelSource.TotalCapacity);
          totalDestCapacity += currentDestCapacity;
          ++destCount;
        }
      }
      if (destCount <= 0 || sourceCount <= 0)
        return;
      double maxSourceTransferAmount = (double) fuelType.FuelTransferRate * (double) sourceCount * (double) deltaTime;
      double actualTransferAmount = Mathd.Min(totalDestCapacity, totalSourceFuel, maxSourceTransferAmount);
      if (actualTransferAmount > 0.0)
      {
        double amountPerDest = actualTransferAmount / (double) destCount;
        double amountPerSource = actualTransferAmount / (double) sourceCount;
        double transferTally = 0.0;
        foreach (IFuelSource fuelSource in this.FuelSources)
        {
          if (fuelSource.FuelType == fuelType && fuelSource.FuelTransferMode == FuelTransferMode.Fill)
          {
            double amount = fuelSource.TotalCapacity - fuelSource.TotalFuel;
            if (amount > amountPerDest)
              amount = amountPerDest;
            transferTally += fuelSource.AddFuel(amount);
            if (fuelSource is IFuelTransferredHandler transferredHandler)
              transferredHandler.OnFuelTransferred();
          }
        }
        for (int index = 0; index < sourceCount; ++index)
        {
          foreach (IFuelSource fuelSource in this.FuelSources)
          {
            if (fuelSource.FuelType == fuelType && fuelSource.FuelTransferMode == FuelTransferMode.Drain)
            {
              double amount = Mathd.Min(amountPerSource, transferTally);
              transferTally -= fuelSource.RemoveFuel(amount);
              if (fuelSource is IFuelTransferredHandler transferredHandler)
                transferredHandler.OnFuelTransferred();
              if (transferTally <= 0.0)
              {
                index = sourceCount;
                break;
              }
            }
          }
        }
      }
    }
    
    3.9 years ago

1 Upvote

Log in in to upvote this post.