Splutty Posted March 24, 2017 Share Posted March 24, 2017 So I first started noticing this bug when I sold something to a station that wasn't full, but the stock never updated. Running my automated hauler script, I ran into this same issue again, only this time my hauler would just keep hauling stuff to the affected factory. After some digging, I narrowed it down and started putting in some debug messages. So this is what I eventually ended up with: Fri Mar 24 11:26:21 2017| Calc MaxStock: space/3646.1279296875 goodSize/0.5 round/73 Fri Mar 24 11:26:21 2017| Calc MaxStock: space/3646.1279296875 goodSize/0.5 round/73 Fri Mar 24 11:26:21 2017| IncreaseGoods(sold): Solar Power Plant I/Energy Cell/delta 4/current 7292/maxstock 7300 Fri Mar 24 11:26:21 2017| IncreaseGoods(sold) current after added cargo: 7292 Turns out that the max is rounded, and in this case, rounded UP. So there is actually only room for 7292 energy cells, but the MaxStock returns 7300. So it'll keep trying and trying to add 4 at a time, which goes fine everywhere, except at the actual adding part, because that's the point where the storage is full. For my factory, this means that there are *always* 12 ingredients missing. So my hauler keeps hauling and hauling and hauling. The code that's causing this is in tradingmanager.lua if space / goodSize > 100 then -- round to 100 return math.min(25000, round(space / goodSize / 100) * 100) else -- not very much space already, don't round return math.floor(space / goodSize) end This causes edge cases to be rounded up, this triggering the never filled stock problem. I can only imagine this is done so it looks better, since there is no actual reason to do this. How I've 'fixed' this, and still not have it end on a weird number, is to not do it in 100's but in 10's and round DOWN. This also gives a bit more leeway to relatively low cargospace vs relatively high volume goods. So then it looks like this: if space / goodSize > 100 then -- round down to 10's return math.min(25000, math.floor(space / goodSize / 10) * 10) else -- not very much space already, don't round return math.floor(space / goodSize) end This needs to be done both on client and server side, otherwise the client side interface will still show the 7292/7300 constantly (until these goods are used up, and it'll just be 7200/7300, which looks even worse :) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now