Jump to content

Station Supply Chains and The Problem with the Sell Goods Order


Lt. Derp

Recommended Posts

I posted this on the Steam discussion but wanted to copy it here.

The basic issue is that when you are setting up complex production chains and have stations in multiple sectors and you only want to use materials produced by your own mines/factories, you have to set up a huge number of freighters once you get past basic production chains. Why? Because when looping orders to set up a supply chain, a "soft error" can occur where a station becomes full of a feedstock and your freighter will wait indefinitely until the # of goods in the freighter cargo hold you first set when issuing the order is achieved. It will send an error notification every 10 mins and otherwise do nothing, even if it has other commands available in the loop.

Below is some of the pertinent code(I am not a coder):

From sellgoods.lua:


-- ## Things that can go wrong: ## --
-- no station buys the goods -> critical error
-- stations buy the goods, but not enough space -> soft error
-- stations buy the goods, but unfitting prices -> soft error
-- other player doesn't have enough money -> soft error

-- Critical Error: notify & block
-- Soft Error: keep trying / wait, after 10 minutes: notify & keep trying


if full and badMargin then
-- soft error
TradeUT.setSoftError("No merchant has room for '%s' or a matching price."%_T, self.data.name)
return
elseif full then
-- soft error
TradeUT.setSoftError("No merchant has room for '%s'."%_T, self.data.name)
return
elseif badMargin then
-- soft error
TradeUT.setSoftError("No merchant accepts '%s' for a matching price."%_T, self.data.name)
return
end
end
end


From tradeutility.lua

function TradeUT.updateErrorHandling(timeStep)
if not self.currentError then return end

local maximum = 10 * 60

self.notificationTimer = (self.notificationTimer or maximum) + timeStep
self.lastError = self.lastError or ""

local newError = self.lastError ~= self.currentError.text

if self.notificationTimer > maximum or newError then
self.notificationTimer = 0
self.lastError = self.currentError.text

if self.currentError.critical or not newError then
-- notify whenever an error has been there for a while
-- or when a critical error happens for the first time
Faction():sendChatMessage(Entity().name, ChatMessageType.Normal, self.currentError.text, unpack(self.currentError.args))
end
end

DockAI.reset()
end

function TradeUT.setSoftError(msg, ...)
self.currentError = {text = msg, critical = false, args = {...}}
end


Like I said, I'm no coder so I could have missed something but it seems like the issue is that a soft error does not take in to account if a ship is in a command loop. Since the scenario where a station becomes full of feed material is likely to occur at times, especially when first setting up large supply chains, it makes sense to have it check if the next order in a loop can be completed without errors. Seems like a third "Very Soft Error" should be made for TradeUT.setSoftError("No merchant has room for '%s'."%_T, self.data.name)" error.

If that can be done, then you could technically have a single giant barge supplying all your stations with self produced materials.

  • Like 1
Link to comment
Share on other sites

For anyone that is interested, I figured out a patch to somewhat fix this(I am not a coder so your mileage may vary):

in sellgoods.lua:

-add "local stationsupplier = false" variable at the top with the other local variables, before the "if onServer() then" line
-two functions need to be edited, Function 1:


function updateServer(timeStep)

...(first part is same,edit the text below from)...

-- Check if we're done yet
local required = getRemainingAmountToFulfill()
if required == 0 then
-- print ("required: " .. required)
terminate()
return
end


CHANGE TO:

-- Check if we're done yet
local required = getRemainingAmountToFulfill()
if required == 0 and stationsupplier == false then
-- print ("required: " .. required)
terminate()
return
elseif required >= 0 and stationsupplier == true then
-- print ("Idle Station Supplier Detected, executing next Order")
terminate()
return
end

(leave the rest)

Function 2:

function updateFindingPartner()

...(first part is same,edit below from)...

elseif full then
-- soft error
TradeUT.setSoftError("No merchant has room for '%s'."%_T, self.data.name)
return

CHANGE TO:

elseif full then
-- soft error
TradeUT.setSoftError("No merchant has room for '%s', assuming station supplier."%_T, self.data.name)
stationsupplier = true
return

(leave the rest)

This could break your game so try it at your own risk(always make a backup of edited files and saves). The idea is to flag any sell order that has a good station to trade with but a full station cargo as a "stationsupplier", which will then complete the sell order as if the cargo of the ship is 0(leaving the remaining cargo in the ship and moving to the next order if there is one). I'm sure their are scenarios where this breaks but I just wanted a quick fix to supply my stations with as few ships as possible.

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...