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

Fix off-by-one in path finding logic #7682

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

StephenCWills
Copy link
Member

@StephenCWills StephenCWills commented Jan 28, 2025

This fixes an issue where items and objects can no longer be interacted with unless the player is on top of them.

In the following conditional statement, the call to GetDistance() always returned zero. The reason is that the logic thought that a path of length 1 exceeds the maximum path length of 1 that was passed in via the second argument.

if (targetPosition != futurePosition && GetDistance(targetPosition, 1) == 0) {
// Don't check the tile we're leaving if the player is walking
continue;
}

This resolves #7681

Source/engine/path.cpp Outdated Show resolved Hide resolved
@Trihedraf
Copy link
Collaborator

That does fix it in game. But now the tests are broken 🫠

@glebm
Copy link
Collaborator

glebm commented Jan 28, 2025

The failing test says:

	// Longest possible path is currently 24 steps meaning tiles 24 units away are reachable
	Point startingPosition { 56, 56 };
	CheckPath(startingPosition, startingPosition + Displacement { 24, 24 }, std::vector<std::string>(24, ""));

	// But trying to navigate 25 units fails
	CheckPath(startingPosition, startingPosition + Displacement { 25, 25 }, {});

However, the longest possible path is actually 25, so I think the test is wrong (or we can reduce the maximum path length for monsters to 24, I think that might be closer to previous behaviour)

Source/engine/path.cpp Outdated Show resolved Hide resolved
@StephenCWills
Copy link
Member Author

I kept the monster path length at 25 because I do not think it particularly matters. Assuming the save format supports path lengths of 25, I think it's reasonable to consider this a bugfix.

I restricted the path tests to 24 so we wouldn't have to change the current test suite. It's still a good test to demonstrate we are appropriately failing when we reach the maximum path length.

@AJenbo AJenbo merged commit 52ce98b into diasurgical:master Jan 28, 2025
23 checks passed
@StephenCWills StephenCWills deleted the max-path-len branch January 28, 2025 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue Report]: #7522 breaks auto selecting dungeon objects on touch controls
4 participants