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 cancelling goto with ESC #1309

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client/goto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool is_valid_goto_destination(const struct tile *ptile)
/**
Inserts a waypoint at the end of the current goto line.
*/
bool goto_add_waypoint()
void goto_add_waypoint()
{
for (auto &[_, finder] : goto_finders) {
// Patrol always uses a waypoint
Expand All @@ -114,7 +114,6 @@ bool goto_add_waypoint()
finder.push_waypoint(goto_destination);
}
}
return true;
}

/**
Expand All @@ -123,20 +122,21 @@ bool goto_add_waypoint()
*/
bool goto_pop_waypoint()
{
bool popped = false;
for (auto &[_, finder] : goto_finders) {
// Patrol always uses a waypoint
if (hover_state == HOVER_PATROL) {
finder.pop_waypoint();
}

finder.pop_waypoint();
popped |= finder.pop_waypoint();

// Patrol always uses a waypoint
if (hover_state == HOVER_PATROL) {
finder.push_waypoint(goto_destination);
}
}
return true;
return popped;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion client/goto.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void goto_unit_killed(struct unit *punit);
bool goto_is_active();
bool goto_tile_state(const struct tile *ptile, enum goto_tile_state *state,
int *turns, bool *waypoint);
bool goto_add_waypoint();
void goto_add_waypoint();
bool goto_pop_waypoint();

bool is_valid_goto_destination(const struct tile *ptile);
Expand Down
6 changes: 4 additions & 2 deletions common/path_finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,11 @@ void path_finder::push_waypoint(const tile *location)
*
* \see push_waypoint
*/
void path_finder::pop_waypoint()
bool path_finder::pop_waypoint()
{
// Nothing to to.
if (m_d->waypoints.empty()) {
return;
return false;
}

m_d->waypoints.pop_back();
Expand All @@ -668,6 +668,8 @@ void path_finder::pop_waypoint()
m_d->queue.pop();
}
m_d->insert_initial_vertex();

return true;
}
/**
* Notifies the path finder that some unit died or changed state. In many
Expand Down
2 changes: 1 addition & 1 deletion common/path_finder.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class path_finder {
inline path_finder &operator=(path_finder &&other);

void push_waypoint(const tile *location);
void pop_waypoint();
bool pop_waypoint();

void unit_changed(const unit &unit);

Expand Down