Mining code using dragged region instead of actual terrain shape


#1

Summary: If you assign a mining zone on the side of a cliff with one click or one click and drag, that is too tall for the hearthlings to reach and at least 2 blocks deep then the hearthlings can’t reach every block in the first layer and won’t move on to mine blocks in the next layer that they can reach.

Steps to reproduce:

  1. With only one click or click and drag, assign a mining zone on the side of a cliff that is taller than 5 (the hearthling reach) and at least 2 blocks deep.
  2. As they have mined out as much as they can reach on the first layer they will stop.
  3. Use the debug tools to see that only the blocks that they can’t reach in the first layer have the red adjacency blocks.
  4. Do the same thing again but assign the mining zone as two steps. One for the bottom 5 layers and one for the layers above.
  5. Now they can mine out the bottom 5 layers.

Expected Results: How you assign the mining zone shouldn’t matter.

Actual Results: I does. :smile:

Notes:
When mining_zone_component.lua is running _update_destination() to look for blocks to mine it takes _self.sv.region:get() and then in _add_destination_blocks it loops through each_cube() and looks for exposed cubes. From what I can tell though, the cubes don’t follow the shape of the terrain but are the cubes that the user dragged out to assign the mining zone.
This causes problems in _add_side_facing_blocks. It looks for the first slice of blocks on each side and ignores blocks that are further in.
The result is that if the hearthlings can’t reach every block in a slice then they won’t move on to mine blocks in the next slice that they can reach.
There seems to be a similar problem with _add_top_facing_blocks but it should be solved at the same time, unless the fix is done inside _add_side_facing_blocks.
I’m not sure if it should be solved by comparing the zone to the terrain at some good point or if it should be handled some other way for better performance.

Attachments:
In the left image I assigned the mining zone with one click and drag. In the right I did the inner layer as one and the rest as one.

Version Number and Mods in use: Latest version and only the defaults and the debug tools.

System Information:


#2

Thanks for reporting! This is an awesome report, with all the steps and details and screenshots :smiley:

I wonder if it has something to do with AI may stall when ecountering small holes in walls

I think there were some cases where they would stop mining on concave shapes. This might be a fallout from the custom mining tool. I tried to repro, but for the steps 4 and 5 sometimes they weren’t able to finish mining the bottom layer either. :thinking:

Since you can keep adding to a mining zone even when they’re already working on it, it’s likely the code doesn’t take into account that they should create a step to be able to mine the top layers, which is probably very difficult to fix.

The mining code was already modified several times before 1.0 because it always had bad performance when mining in water, and we also split big mining zones into smaller chunks (like the builder does) for performance.


#3

I had a quick look at that one before writing mine but didn’t see the connection. Looking at it again though, yes, it can definitely be the same problem. If the whole region inside the house is assigned with one action then the blocks in the windows will be considered exposed and no other blocks further in that are exposed in that direction will be a destination, unless they are considered exposed in another direction. It fits with @klaus’s comment “will result in the hearthlings digging out the windows, the door and sometimes, sometimes not, a straight line from the door or the blocks directly adjacent to the door, but ignore the rest of the mining job.”

I don’t know how much changed in the background when that was added, but it might just be that it’s easier to get the situations now.

That’s odd… I’ll admit I only tried that exact method once. It was easier to explain than my other test case. Gonna give it a few more tries.

That’s the behaviour I was about to start working on when I found this. :stuck_out_tongue: Spiral stairs inside the mining zone. Not preplanned but as an organic result of the ai’s decisions, block by block. Gonna be tricky but it might actually be silly enough to work. :smile:


#4

@Relyss I tried step 4 and 5 again and at first didn’t get them to finish the bottom layer. However, it seems to work when I make the two layers with different XZ-size, so my theory is that when you add a new block to the mining zone it is compared to the adjacent blocks and if the size and position is right, so that they can be merged into a single block, they are merged and we’re back to the same situation as in step 1-3.