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

#5031: Fix accessibility logic for wagons #5053

Merged
merged 25 commits into from
Dec 9, 2024
Merged

Conversation

dhthwy
Copy link
Contributor

@dhthwy dhthwy commented Nov 29, 2024

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.

@dhthwy
Copy link
Contributor Author

dhthwy commented Nov 29, 2024

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 and possibly necessary for the fix.

@dhthwy dhthwy marked this pull request as draft November 29, 2024 23:26
@dhthwy
Copy link
Contributor Author

dhthwy commented Nov 29, 2024

Marked as draft temporarily.

@dhthwy
Copy link
Contributor Author

dhthwy commented Nov 30, 2024

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 and pending some tests on that adv mode save from the original complaint.

@dhthwy dhthwy marked this pull request as ready for review November 30, 2024 20:04
@dhthwy dhthwy changed the title #5031: Handle top ramps when pathfinding to depot #5031: Fix wagon accessibility Nov 30, 2024
@dhthwy dhthwy changed the title #5031: Fix wagon accessibility #5031: Fix accessibility logic for wagons Nov 30, 2024
@myk002
Copy link
Member

myk002 commented Dec 7, 2024

I see some wonkiness with trees and boulders:
image

but notably, it's not all trees and boulders

test save: https://drive.google.com/file/d/1ID5Tu9XteyEwCpeKuFVjf3ygfWiXe6K0/view?usp=sharing

library/modules/Maps.cpp Outdated Show resolved Hide resolved
Copy link
Member

@myk002 myk002 left a 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!


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)) {
Copy link
Member

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?

Copy link
Contributor Author

@dhthwy dhthwy Dec 7, 2024

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.

@dhthwy
Copy link
Contributor Author

dhthwy commented Dec 7, 2024

I see some wonkiness with trees and boulders
but notably, it's not all trees and boulders

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.

@dhthwy
Copy link
Contributor Author

dhthwy commented Dec 8, 2024

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.

@myk002
Copy link
Member

myk002 commented Dec 9, 2024

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

Copy link
Member

@myk002 myk002 left a 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?
Copy link
Member

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

Copy link
Member

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?)

// 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)) {
Copy link
Member

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?

Copy link
Contributor Author

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.

Comment on lines 382 to 383
// When there is no path to the depot entry_tiles will not
// contain any edge tiles.
Copy link
Member

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.

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);
Copy link
Member

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

Comment on lines 300 to 302
default:
//NOTREACHED
break;
Copy link
Member

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


// 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) {
Copy link
Member

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

auto special = tileSpecial(tt);
auto material = tileMaterial(tt);

// Allow murky pool ramps
Copy link
Member

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

@myk002 myk002 merged commit ef3144c into DFHack:develop Dec 9, 2024
14 checks passed
myk002 added a commit that referenced this pull request Dec 9, 2024
@dhthwy dhthwy deleted the wagonpathfix branch December 9, 2024 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

gui/pathable says depot is wagon accessible but it is not
2 participants