Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pathfinding avoiding sharp objects (barbed wire etc) #37964

Merged
merged 4 commits into from
Feb 13, 2020

Conversation

jkraybill
Copy link
Contributor

@jkraybill jkraybill commented Feb 12, 2020

Summary

SUMMARY: Bugfixes "Avoid sharp things in player pathfinding"

Purpose of change

Fixes #37928 by preventing the player from auto-pathing into sharp things (barbed wire fences etc).

Describe the solution

I added a new pathfinding setting, to avoid sharp things, and set it to default true for the player and NPCs and false for monsters.

I made sharp items unpathable if avoid_sharp=true, because there is an issue with route_adjacent in activity_item_handling.cpp. In farming, route_adjacent is called. That method looks up the closest adjacent square to the target "to be planted" square, and if there is a valid path, regardless of cost, it will go to the first valid adjacent square. So I couldn't just give sharp objects a high cost, because path cost isn't taken into account in route_adjacent if the high-cost tile is the destination adjacent tile.

Describe alternatives you've considered

I considered just adding sharp-object-avoidance to the avoid_traps behaviour. This still seems like a reasonable alternative if there is going to never be a situation where pathfinding should avoid either traps or sharp things but not the other.

Testing

I did quite a lot of testing with pathfinding related to farming automation. I did not do a lot of testing related to non-farm-automation pathfinding.

Example of the types of setups I was testing:

image

Additional context

This is my second C++ commit of any significance, I've picked a couple doozies between fuel consumption and pathfinding. I would not be at all surprised if I have made some rookie mistakes and welcome all feedback.

I also expect, but have not confirmed, that this commit will fix some other annoyances with player auto-pathfinding into bushes and barbed wires.

@jkraybill jkraybill changed the title #37928 Support pathfinding avoiding sharp objects (barbed wire etc) Feb 12, 2020
@jkraybill jkraybill changed the title Support pathfinding avoiding sharp objects (barbed wire etc) (WIP) Support pathfinding avoiding sharp objects (barbed wire etc) Feb 12, 2020
@jkraybill
Copy link
Contributor Author

Moving this to WIP because there's now some weird unintended behaviour in manual movement. Working on it.

@jkraybill jkraybill changed the title (WIP) Support pathfinding avoiding sharp objects (barbed wire etc) Support pathfinding avoiding sharp objects (barbed wire etc) Feb 12, 2020
@jkraybill
Copy link
Contributor Author

Removed WIP tag, the test cases I was using are replicable in master with pit traps and auto-travel.

@jkraybill
Copy link
Contributor Author

Did significantly more testing with overmap auto-move. This PR appears to fully resolve the "raspberry bush problem" at the expense of making raspberry bushes and other sharp objects effectively impassable terrain for automove. I think that's a good thing but it's entirely possible I have missed an edge case. This PR makes territory fully bordered by sharp objects un-navigable by auto-move, so if that causes problems I'm not aware of, please let me know.

@curstwist curstwist added [C++] Changes (can be) made in C++. Previously named `Code` Mechanics: Character / Player Character / Player mechanics <Bugfix> This is a fix for a bug (or closes open issue) labels Feb 12, 2020
@ghost
Copy link

ghost commented Feb 12, 2020

Did significantly more testing with overmap auto-move. This PR appears to fully resolve the "raspberry bush problem" at the expense of making raspberry bushes and other sharp objects effectively impassable terrain for automove. I think that's a good thing but it's entirely possible I have missed an edge case. This PR makes territory fully bordered by sharp objects un-navigable by auto-move, so if that causes problems I'm not aware of, please let me know.

I think thats fine, automove shouldnt do anything risky or annoying, the player can do that themselves if they want to.

@jeremyshannon
Copy link
Contributor

jeremyshannon commented Feb 12, 2020

false for monsters.

I feel like that should only be false for unintelligent monsters like zombies or the blob. It's hard to have a pet dog right now when they routinely impale themselves on barbed wire and jagged wreckage because they won't path around it.

@jkraybill
Copy link
Contributor Author

@jeremyshannon thanks for the tip. Opening a separate issue for that, this PR does add a JSON flag to allow that to be specified per monster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Mechanics: Character / Player Character / Player mechanics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto-planting gratuitously paths into dangerous terrain
5 participants