Suggestion: set slot filters to expected item

Adds new train stops forming a highly configurable logistic network.

Moderator: Optera

Post Reply
wvlad
Fast Inserter
Fast Inserter
Posts: 215
Joined: Thu Jul 13, 2017 9:55 pm
Contact:

Suggestion: set slot filters to expected item

Post by wvlad »

Now it's recommended to use filter inserters but why bother if the mod can set wagon filter slots so noone can insert anything wrong?

This way even if a filter inserter stucks with a wrong item in its hand it won't put that item in a wagon like it happened to me. (Yes, I know about the "Locked slots" feature but it seems so overcomplicated to use it).

In control.lua after

Code: Select all

  schedule.records[1] = NewScheduleRecord(depot.entity.backer_name, "inactivity", depot_inactivity)
  schedule.records[2] = NewScheduleRecord(from, "item_count", ">", loadingList)
  schedule.records[3] = NewScheduleRecord(to, "item_count", "=", loadingList, 0)
  selectedTrain.schedule = schedule
add this

Code: Select all

  if selectedTrain.cargo_wagons then
      local loadingListIndex = 0
      local stacksSet = 0

      repeat 
          loadingListIndex = loadingListIndex + 1
      until (#loadingList < loadingListIndex) or (#loadingList[loadingListIndex].type ~= "fluid")

      for n,wagon in pairs(selectedTrain.cargo_wagons) do
        local inventory = wagon.get_inventory(defines.inventory.cargo_wagon)
        if inventory then
          if inventory.supports_filters() then
            for slotIndex=1, #inventory, 1 do
              if #loadingList < loadingListIndex then
                  inventory.setbar(slotIndex-1)
                  break
              else
                  local el = loadingList[loadingListIndex]
                  inventory.set_filter(slotIndex, el.name)
                  stacksSet = stacksSet + 1
                  if (el.stacks - stacksSet <= 0) then
                      repeat 
                          loadingListIndex = loadingListIndex + 1
                      until (#loadingList < loadingListIndex) or (#loadingList[loadingListIndex].type ~= "fluid")
                      stacksSet = 0
                  end
              end
            end
          end
        end
      end
  end

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Suggestion: set slot filters to expected item

Post by Optera »

Not going to happen.
Iterating every slot in every wagon whenever a train is set on a delivery becomes too expensive, especially in huge networks with 100+ 8 wagon trains.

I'll review this idea when the api provides a fast way to set filters for whole trains or at least whole wagons.

Post Reply

Return to “Logistic Train Network”