[r572x64] Hearthlings Reach and Movement Limitations

edit: new title & the discussion is below
Will showing some different screenshots of things hearthlings can’t mine help?

I hope so! :slight_smile:
Note: I’ve been hacking the game’s LUA to avoid a certain issue with mining - where they end up with a block, some gaps then a block above that; and can’t mine the block above because it’s out of reach unless they stand on the block below, but if they stand on the block below the can’t mine the block above because it’s directly overhead. Because of the order they mine this bug can stall entire mining jobs - they pick a column of blocks they think they can mine, try to do it and find they can’t, and don’t try other columns of blocks so nothing more gets mined.
What I’ve been doing is going into “mods/stonehearth/services/server/mining/mining_service.lua” and changing “MAX_REACH_UP = 3” to “MAX_REACH_UP = 4”. This means they can reach the block above without being directly under it, which prevents the problem. It doesn’t seem to cause any other problems either.
Of course there’s multiple other issues that cause problems mining, including not being able to find a path that exists (often due tricky ladder positioning), failing to bother to find a path (because path finding took too long), miners “locking” columns of blocks they can’t reach and preventing miners that can reach from doing their job, AI issues (e.g. the “hearthlings idle when work to do” problem that effects every part of the game also effects mining), etc.
There’s also inefficiencies that aren’t bugs - like 3 miners will finish everything except for one block, and then you’ll wait patiently for a fourth miner to wander half way across the map just to do that last little block - the miners that are already there can’t “steal” work from the distant miner after the distant miner decided to do it.

Right.
To me it seems directly linked to the pathing where they seem to check if they can reach the block or not and if they mine the block they will have no path, so they don’t and they don’t think about it any further than that. Where what they should do is calculate if X amounts of blocks in this mining order are mined then they will once again have a path and should just continue.
I’ve also talked about is that the reach of the hearthlings should be just as high as the size of a pillar. Scientifically when you study anatomy when you spread your arms out, your arm length is equal to your height. Now I realize hearthlings are like dwarves, or children, and basically have no reach at all. My point is that if you extend your arm above your head its always exactly equal to one cubit, wich happens to be about 1.5 feet or 18 inches for a 6 foot man and is 1/4 or 25% of your height. Now I am a little over 6 feet and if I stretch my arm above my head I can touch the ceiling in my house because its a little less than 8 feet high in pretty much every bedrooom/office/bathroom and its built to a standard of average height. The same should be true of hearthlings, they are 4 blocks tall and should be able to reach and grab stuff at 5 blocks (and barely touch 6th block) - and even as dwarves or children should be able to reach 4 blocks. The problem is they can only reach that 4th block in overly specific situations and its causing an unreasonable amount of problems. This combined with the fact they they can only climb on a single block height and refused to jump down anything above a 2 block height (when this should be about 4x your height+ before you will pretty much guarantee an injury) and you have a being that is completely inept at basic mobility and survival functions and its silly to think that optimizing within the limitations they currently set will be as good as if it were realistic - there is a reason things in reality work the way they do.

I agree.
For full disclosure, I was considering doing a “better mining” mod - that’s why I was poking around in that “mining_service.lua” file originally.
What I did was modify a function that determines which blocks can be reached from a certain position. The current version only considers the 4 columns that are adjacent to the position, but I increased it to 2 columns in any of the 4 directions (N, E, S, W), plus the diagonals (NE, SE, SW, NW), plus the column at the position itself; with varying “column heights” (closer columns taller, further columns shorter). This worked, but is only the first third of what would be needed.
The second third of what I was planning is a group of functions that do the opposite - determines which position/s a heartlhing can be to reach a block. I didn’t modify this (I was planning to), so my changes to the first function didn’t really improve mining.
The last part of what I was planning is a function that chooses a block to mine after the game has determined “reachable blocks” (after the first function). This would’ve needed to be changed so the game does blocks in a nice order (e.g. doesn’t mine further away blocks when closer blocks are in the way). I was investigating this when I had to give up in frustration.
The problem was me - I have difficulty tolerating the code. More specifically, LUA uses “duck typing” which makes it extremely painful just to figure out what data types existing code is using (is it an integer? an array? a structure? an object reference?), and the LUA code uses lots of abstractions which means that to understand it you need to hunt down where the abstractions are (and you’ll have one layer on top of another layer on top of a third layer; and have to find and decipher each of the layers to get a full understanding), and sometimes (usually?) that isn’t possible. For a simple example, there’s a “region” abstraction in there somewhere, and I spent at least an hour attempting to determine what its interface is, what it actually does, what the data types involved are, etc. I still have no idea, and I suspect the lowest layer of it is implemented in C++ so it just “disappears” into an undocumented and undiscoverable black hole.
For what it’s worth; as far as I can understand it, the full “mining” logic goes something like this:

  • Impossible to understand magic voodoo makes a hearthling attempt to do some mining
  • Impossible to understand magic voodoo chooses a region for the hearthling to mine
  • Something somewhere decides if the hearthling should attempt to mine the region from the top or from a side
  • The game selects a block to mine (either one of the highest blocks if mining from the top, or one of the blocks closest to the side if mining from the side)
  • The game determines a location for the hearthling to stand while mining that is adjacent to the selected block, and retries previous step if there is none
  • The game then determines all the columns of blocks that are adjacent to the location (N, E, S, W; with columns of about 4 blocks tall), finds a column that isn’t already “locked” and “locks” a column so that no other hearthling can touch it
  • Something somewhere tries to find a path from wherever the hearthling is to the selected location, and (I assume) gives up when no path can be found because the previous steps didn’t take pathing/accessibility into account.
  • Then (I assume) the hearthling mines the column (or the hearthling gets hungry or couldn’t find a path or something else instead), and the column is “unlocked” again I guess
  • Then (I assume) all of the above gets repeated, until there’s nothing left to mine (or until the game is constantly repeating the steps and failing to mine).
Notes:
  1. It’s very likely that my understanding is at least partially wrong
  2. It’s very inefficient because there’s way too much chance of CPU doing a bunch of work/processing that gets discarded and retried
  3. There’s no attempt at “move hearthling near mining site first, then try to find blocks to mine after hearthling is close”
  4. There’s no “determine order of blocks to be mined, to ensure hearthling/s don’t get stuck”

The mining height didn’t seem to change anything in my current game, but I started a new one and for the most part my hearthlings do not seem to be doing any more derp mining. Thank you.

moved to suggestions
here is hoping the devs listen and change the default hearthling reach and movement limitations to be more reasonable as talked about above