Yeah, nice update. Happy to see those fixes!!
December 2019 Update
Welcome to the King under the Mountain monthly update! A little late (again) though I hope you'll forgive me what with it being the Christmas holidays.
At the end of last month's update I was all set on finally moving on to mod support, or at least initially different translations. After the update, on 19th November, Alpha 2.8 was released which introduced the new Kickstarter-backer-specified resources. This brought a reasonable amount of traffic from players old and new, including highlighting several bugs and other problems, most of which had been around a while but I hadn't been able to recreate myself.
In the end, I spent late November and most of December rewriting the item allocations system. That is, whenever something needs to be crafted, or some furniture constructed, or a settler needs a tool, or basically for any use of an item, the game has to keep track of which items/resources are available and which are free to be used. Up to this point, each item entity had a simple pair of integer counters, one for the quantity of the item and one to say how many of that quantity are currently allocated to be in use somewhere. Say a piece of furniture requires 10 stone blocks to be created. It'll ask for stone blocks to be assigned, and perhaps there are two piles of 6 stone blocks that are available. All of the first and 4 of the second would become "assigned", leaving 2 of 6 stone blocks available in the second pile. Something might then go "wrong" though, the stone blocks could be being carried by a settler just as a cave-in happens overhead crushing the settler and the items, or the player might decide to cancel the construction. This should then de-allocate the items assigned to the construction, setting the allocated amount for both piles back to 0 (specifically, decrementing the first by 6 and the second by 4). In almost all situations this worked fine, but there was a very hard to track down problem where sometimes items were not de-allocated properly, leaving them stuck as allocated forever even though the original use for the allocation had since been cancelled or completed.
The above was a very tricky problem to recreate - I could never quite figure out under what circumstances this happened, and when helpful members of the community sent me save files that included occurences of the issue, it had already happened in the past and I had no information to look at to see what had led to this point, just a number saying a certain quantity of some items was allocated somewhere and I had no idea where.
I ended up biting the bullet and spending a lot of time rewriting this system, so that instead of a simple number, each item allocation is now a small group of data detailing the purpose of the allocation (such as for hauling, being used in inventory, etc.), who requested it, the intended destination and so on. I couldn't otherwise figure out the root cause of the problem so at least changing all the item allocations over to this new system would give me enough information to look deeper into the problem and narrow down where it was coming from.
As is often the case with massive changes to a system, having to touch many parts of the codebase led me to discover and fix some existing issues (hopefully including the one that caused me to do this large piece of work in the first place), and of course, inevitably, introduce new problems :) Still, I think the item allocation overhaul has been a big success and was very much worth doing, just a shame it's delayed the implementation of the modding system for another month or so. It wasn't just item allocations that were rewritten either, the way stockpiles manage and keep track of their contents was also overhauled, having been one of the earliest parts of the codebase and something else that wasn't really fit for purpose any longer.
Additionally, I ended up also changing over how liquid allocations work, as that was also a bit of a hack previously. Until now, units of liquids like water and soup were also stored as integers (whole numbers). A barrel can hold 6 units, a bucket moves 2 units of liquid, and so on. This didn't really work for drinking barrels, as I wanted a single bucket of water (2 units) brought to a barrel to suffice for many settlers to drink from. If the 2-unit bucket of water only supplied enough for 2 drinks, the settlements would spend even longer moving water around than they currently do! The original solution was that instead of removing 1 unit when a settler had a drink from a barrel, there was a random dice roll which determined if a unit of water was removed (I think it was a 15% chance). This way, a bucket of water would last several drinks, it would vary in amounts quite a bit, but overall on average it would balance out. Not a great solution but it did work.
However there was also an assignment problem with water barrels. There would be an issue if dozens of dwarves went to drink from the same barrel with only a small amount of water in (say 1 unit). The first dwarf on the scene might end up emptying the barrel, then all the others would get there, get slightly annoyed the barrel was empty, and have to go in search of another, probably all going in a big horde to the next barrel that would probably get emptied to. To avoid this, each 1 unit of water in a barrel was reserved (allocated) by a dwarf wanting to drink there, and unreserved/deallocated when they finished drinking (if they did not end up randomly using up that unit of water). Much like the item allocations, there was also a bug here that I could never quite track down, where some of these allocations would also get stuck and live forever, resulting in the water barrels eventually becoming unusable as their entire contents were incorrectly allocated (a number of people had encountered this one).
So as well as the item allocation overhaul, I finally did the obvious thing and move liquids to using floating point (decimal) numbers for their quantities and allocations. Now a settler reserves 0.15 units of a barrel, and always removes 0.15 units when drinking. A bucket still brings 2.0 units of water to the barrel so each bucket provides enough for 13 and a bit drinks. There's still a lot of legwork for the dwarves to do to get drinks available in water barrels, but do not fear, water pipes and pumps are coming in the future to automate this!
In the same way that overhauling item allocations seemed to fix the problem I was looking for, I believe the new liquid allocations (which get tracked with more info in the same way as item allocations now do) do not have the problem I was looking to solve anymore. Good news!
Helpful members of the community (especially SirRockstar who's been a fantastic help with detailing problems) have been sending me details and savegames for issues in the current versions so there's also been quite a lot of bugfixing going on. A nice one to finally figure out was that bridges didn't always get constructed (I think it depended which side they were "dragged" from by the player) so that's now sorted, and a major quality of life improvement in that constructions now use the nearest available resources rather than what was effectively any (random) available resources.
Sorry it's been a very plain, media-free update this time around. I said it last time but now I will be going on to the first part of modding with language support so look out for that! There's also some semi-exciting news to share but I'll leave it until next month when I have more details nailed down, so see you then!