Skip to content

Commit

Permalink
Refactor travel-related overmap keybinds code (CleverRaven#64353)
Browse files Browse the repository at this point in the history
This is a little cleaner

CleverRaven#64174 (comment)
  • Loading branch information
strategineer authored Mar 18, 2023
1 parent d8075bc commit a577338
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/overmap_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1697,14 +1697,11 @@ static std::vector<tripoint_abs_omt> get_overmap_path_to( const tripoint_abs_omt

static int overmap_zoom_level = DEFAULT_TILESET_ZOOM;

static std::string try_travel_to_destination( avatar &player_character, const tripoint_abs_omt curs,
const bool driving )
static bool try_travel_to_destination( avatar &player_character, const tripoint_abs_omt curs,
const bool driving )
{
std::vector<tripoint_abs_omt> path = get_overmap_path_to( curs, driving );
bool same_path_selected = false;
if( path == player_character.omt_path ) {
same_path_selected = true;
}
bool same_path_selected = path == player_character.omt_path;
std::string confirm_msg;
if( !driving && player_character.weight_carried() > player_character.weight_capacity() ) {
confirm_msg = _( "You are overburdened, are you sure you want to travel (it may be painful)?" );
Expand All @@ -1730,9 +1727,9 @@ static std::string try_travel_to_destination( avatar &player_character, const tr
player_character.reset_move_mode();
player_character.assign_activity( ACT_TRAVELLING );
}
return "QUIT";
return true;
}
return nullptr;
return false;
}

static tripoint_abs_omt display( const tripoint_abs_omt &orig,
Expand Down Expand Up @@ -1887,7 +1884,9 @@ static tripoint_abs_omt display( const tripoint_abs_omt &orig,
avatar &player_character = get_avatar();
if( !player_character.omt_path.empty() ) {
const bool driving = player_character.in_vehicle && player_character.controlling_vehicle;
action = try_travel_to_destination( player_character, curs, driving );
if( try_travel_to_destination( player_character, curs, driving ) ) {
action = "QUIT";
}
}
} else if( action == "CENTER_ON_DESTINATION" ) {
avatar &player_character = get_avatar();
Expand All @@ -1907,7 +1906,9 @@ static tripoint_abs_omt display( const tripoint_abs_omt &orig,
player_character.omt_path.swap( path );
}
if( same_path_selected && !player_character.omt_path.empty() ) {
action = try_travel_to_destination( player_character, curs, driving );
if( try_travel_to_destination( player_character, curs, driving ) ) {
action = "QUIT";
}
}
} else if( action == "TOGGLE_BLINKING" ) {
uistate.overmap_blinking = !uistate.overmap_blinking;
Expand Down

0 comments on commit a577338

Please sign in to comment.