Skip to content

Commit

Permalink
Optionally accept precise OMT coordinates in debug "Teleport - to spe…
Browse files Browse the repository at this point in the history
…cific overmap" function (#79343)

* Change teleport_overmap to optionally accept major and minor coordinate pairs rather than single integer coordinates.

* Update src/debug_menu.cpp

* Update src/debug_menu.cpp

* Fix clang-tidy errors.

* Use emplace_back properly without the redundant temporary.

* Whitespace adjustment from the github-actions bot.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: Maleclypse <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 30, 2025
1 parent 1d6506e commit 8762277
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1791,21 +1791,35 @@ static void teleport_overmap( bool specific_coordinates = false )
coord_strings.size() );
return;
}
std::vector<int> coord_ints;
std::vector<std::pair<int, int>> coord_ints;
for( const std::string &coord_string : coord_strings ) {
ret_val<int> parsed_coord = try_parse_integer<int>( coord_string, true );
const std::vector<std::string> coord_parts = string_split( coord_string, '\'' );
if( coord_parts.empty() || coord_parts.size() > 2 ) {
popup( _( "Error interpreting teleport target: "
"expected an integer or two integers separated by \'; got %s" ), coord_string );
return;
}
ret_val<int> parsed_coord = try_parse_integer<int>( coord_parts[0], true );
if( !parsed_coord.success() ) {
popup( _( "Error interpreting teleport target: %s" ), parsed_coord.str() );
return;
}
coord_ints.push_back( parsed_coord.value() );
int major_coord = parsed_coord.value();
int minor_coord = 0;
if( coord_parts.size() >= 2 ) {
ret_val<int> parsed_coord2 = try_parse_integer<int>( coord_parts[1], true );
if( !parsed_coord2.success() ) {
popup( _( "Error interpreting teleport target: %s" ), parsed_coord2.str() );
return;
}
minor_coord = parsed_coord2.value();
}
coord_ints.emplace_back( major_coord, minor_coord );
}
cata_assert( coord_ints.size() >= 2 );
tripoint coord;
coord.x = coord_ints[0];
coord.y = coord_ints[1];
coord.z = coord_ints.size() >= 3 ? coord_ints[2] : 0;
where = tripoint_abs_omt( OMAPX * coord.x, OMAPY * coord.y, coord.z );
where = tripoint_abs_omt( OMAPX * coord_ints[0].first + coord_ints[0].second,
OMAPY * coord_ints[1].first + coord_ints[1].second,
( coord_ints.size() >= 3 ? coord_ints[2].first : 0 ) );
} else {
const std::optional<tripoint_rel_ms> dir_ = choose_direction(
_( "Where is the desired overmap?" ) );
Expand Down

0 comments on commit 8762277

Please sign in to comment.