theFox6 / working_villages

A mod for minetest that adds villagers performing work
https://content.minetest.net/packages/theFox/working_villages/
MIT License
13 stars 10 forks source link

woodcutter: remember and don't retry failed targets #38

Closed bengardner closed 1 year ago

bengardner commented 2 years ago

Playing with the woodcutter again.

I've observed the woodcutter repeatedly try to move to cut a log that it cannot access. The move to fails (can't find path), but it keeps selecting the log as the best job. There were no other trees around.

To work around this, it would be nice to remember an unreachable log target and exclude it for a while. This could be done by recording the failed target in a table with the key set to minetest.pos_to_string(pos). The value could be the number of minutes to persist. Every minute a cleanup task could run that removes all expired entries. If that approach were used, the woodcutter would give up after the first failed attempt and do something else for a while.

I've also seen it repeatedly try to plant a sapling in an area that is not allowed. I used the 'areas' mod to protect an area. The woodcutter repeatedly attempted to plant a sapling in the same spot in the protected area. Modifying is_sapling_spot() to check for protection fixed half the issue, but we can't reasonably check above the plant spot. The default.sapling_on_place() function checks above the tree, but we don't know the exact dimensions of the final tree, so we can't check early. We need to detect that the place failed and remember it and not try again.

None of this needs to or should be permanent. I'm thinking a 3 minute memory is enough. It doesn't have to be specific to any one woodcutter, either.

I have a patch that does this. I'll submit it shortly.