-
Notifications
You must be signed in to change notification settings - Fork 481
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
#5031: Fix accessibility logic for wagons #5053
Conversation
Apparently I may have worked on a separate problem that I saw. After re-reading the issue, if dfhack claims wagon is accessible when it is not, then this doesn't fix that. Back to the start on this one -- though I still think these changes may be wanted |
Marked as draft temporarily. |
…rectly reporting wagon accessibility
The first four commits deal with what I perceive to be an issue with how down ramps are handled. Without those commits, we get X's on the down ramps, but not on the up ramps. The lack of symmetry is odd. However, it probably doesn't belong in this PR - especially the change in Maps. The down ramp appearance change in pathable will, iirc, visually make down ramps appear accessible for wagons. I believe the change in maps was to do the same for 'follow mouse' in gui/pathable. I think I am done with this pending review |
I see some wonkiness with trees and boulders: but notably, it's not all trees and boulders test save: https://drive.google.com/file/d/1ID5Tu9XteyEwCpeKuFVjf3ygfWiXe6K0/view?usp=sharing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget a changelog entry!
plugins/pathable.cpp
Outdated
|
||
if (ctx.wgroup == Maps::getWalkableGroup(pos)) | ||
return true; | ||
|
||
// RAMP_TOP is assigned a walkability group if that commit is accepted | ||
// so this test, I think, would be useless. | ||
if (shape == df::tiletype_shape::RAMP_TOP ) { | ||
df::coord pos_below = pos + df::coord(0, 0, -1); | ||
if (Maps::getWalkableGroup(pos_below)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assuming the Maps module change does not go in quite yet, do we need to add logic here that checks whether the walkability group of pos_below
matches ctx.wgroup
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assumed invariant: adjacent (RAMP_TOP) tiles belong to the same walkability group.
The group returned by Maps::getWalkableGroup(pos) for a RAMP_TOP will only return a non-zero group if an adjacent tile is the same group as a tile below the ramp.
I think this test here
if (ctx.wgroup == Maps::getWalkableGroup(pos))
return true;
is sufficient. But I agree, this change should probably not be done in this PR.
I noticed this on the linked save for this, and mine as well. I haven't figured out the root cause yet -- but it doesn't appear to impact whether the wagon can reach the depot. When this occurs, instead of marking the tree/boulder blocked, it seems to mark the surrounding tiles blocked instead. |
I think that last commit solves it. I didn't see any incorrectly marked tiles after that commit using the save you linked to. However, there's an incorrectly marked boulder on a surface edge tile in my own save that the latest commit doesn't resolve. |
The edge tiles need a separate check (which can be solved in a separate PR). The edge tile map is populated indiscriminately. There should be a wagon pathability check on each tile before it is added to the map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code overally LGTM, just one substantive question and a few nits
@@ -248,12 +332,13 @@ static void check_wagon_tile(FloodCtx & ctx, const df::coord & pos) { | |||
ctx.seen.emplace(pos); | |||
|
|||
if (ctx.entry_tiles.contains(pos)) { | |||
ctx.wagon_path.emplace(pos); | |||
ctx.wagon_path.emplace(pos); // Is this needed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not since the rendering of the edge tile will overwrite the rendering of the wagon path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, keep this in, since we might want to highlight the overlap (by coloring it green?)
plugins/pathable.cpp
Outdated
// Ensure our wagon flood end points lands on an edge tile. | ||
// When there is no path to the depot entry_tiles will not | ||
// contain any edge tiles. | ||
if ((pos.x == 0 || pos.y == 0) && entry_tiles.contains(pos)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we restricting the entry edge match to the top or left of the map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huge oversight. Thanks for pointing that out.
plugins/pathable.cpp
Outdated
// When there is no path to the depot entry_tiles will not | ||
// contain any edge tiles. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this statement is not quite correct. when there is no path to the depot, then the search_edge will never contain any edge tiles. entry_tiles
contains edge tiles regardless of the accessibility of the depot.
plugins/pathable.cpp
Outdated
auto tt = Maps::getTileType(pos); | ||
if (!tt) | ||
return false; | ||
|
||
auto shape = tileShape(*tt); | ||
if (shape == df::tiletype_shape::STAIR_UP || shape == df::tiletype_shape::STAIR_UPDOWN) | ||
return false; | ||
auto& occ = *Maps::getTileOccupancy(pos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while the return value should never ever be NULL if tt
is not NULL, it's still common practice to check it before dereferencing it
plugins/pathable.cpp
Outdated
default: | ||
//NOTREACHED | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove the default case so the compiler complains if another case ever appears
plugins/pathable.cpp
Outdated
|
||
// NOTE: When i.e. tracks, stairs have a bridge over them, the tile will have | ||
// an occupancy of floored. | ||
static bool is_wagon_tile_traversible(df::tiletype& tt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
df::tiletype
is just an int (an enum), so no need to take a reference
plugins/pathable.cpp
Outdated
auto special = tileSpecial(tt); | ||
auto material = tileMaterial(tt); | ||
|
||
// Allow murky pool ramps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe explain why you're calling out murky pools in particular
Fixes #5031
The save for 5031 has down stairs blocking the wagon path. This PR attempts more robust wagon accessibility handling.
Other issues:
There is also an issue with the 'follow mouse' functionality where walkability is being correctly set for top ramps. This causes the UI to erroneously display an 'X' over the ramp tile, incorrectly indicating that the tile (or the z-level below) is inaccessible.
I am unsure about tests for this.
Me, from elsewhere:
"It looks like walkable is computed by df, right? The down ramp itself is not walkable. I suspect we'll have to special case ramps in Maps and have it tie its walkability group to an adjacent tiles group" AND ensure the tile below the ramp also matches the group of its adjacent tile.
Assumed invariant: adjacent tiles belong to the same walkability group.