Skip to content

Commit

Permalink
Display ETA and distance for destination
Browse files Browse the repository at this point in the history
+don't overrun our iterators
  • Loading branch information
RenechCDDA committed Jun 16, 2024
1 parent 2e80177 commit 65b284d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/do_turn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ bool do_turn()
// consider a stripped down cache just for monsters.
m.build_map_cache( levz, true );
monmove();
if( calendar::once_every( 5_minutes ) ) {
if( calendar::once_every( time_between_npc_OM_moves ) ) {
overmap_npc_move();
}
if( calendar::once_every( 10_seconds ) ) {
Expand Down
4 changes: 4 additions & 0 deletions src/game_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <map>
#include <string>
#include "calendar.h"
#include "units.h"

// Fixed window sizes.
Expand Down Expand Up @@ -145,6 +146,9 @@ constexpr int BIO_CQB_LEVEL = 5;
// Minimum size of a horde to show up on the minimap.
constexpr int HORDE_VISIBILITY_SIZE = 3;

// How often a NPC can move one tile on the overmap
constexpr time_duration time_between_npc_OM_moves = 5_minutes;

/**
* Average annual temperature in Kelvin used for climate, weather and temperature calculation.
* Average New England temperature = 43F/6C rounded to int.
Expand Down
9 changes: 7 additions & 2 deletions src/npctalk_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void talk_function::goto_location( npc &p )
camps.push_back( temp_camp );
}
for( const basecamp *iter : camps ) {
//~ %1$s: camp name, %2$d and %3$d: coordinates
//~ %1$s: camp name, %2$s: coordinates of the camp
selection_menu.addentry( i++, true, MENU_AUTOASSIGN, pgettext( "camp", "%1$s at %2$s" ),
iter->camp_name(), iter->camp_omt_pos().to_string() );
}
Expand Down Expand Up @@ -410,7 +410,12 @@ void talk_function::goto_location( npc &p )
g->follower_path_to_show = &p; // Necessary for overmap display in tiles version...
ui::omap::display_npc_path( p.global_omt_location(), p.omt_path );
g->follower_path_to_show = nullptr;
if( !query_yn( _( "Is this path and destination acceptable?" ) ) ) {
int tiles_to_travel = p.omt_path.size();
time_duration ETA = time_between_npc_OM_moves * tiles_to_travel;
ETA = ETA * rng_float( 0.8, 1.2 ); // Add +-20% variance in our estimate
if( !query_yn(
_( "Estimated time to arrival: %1$s \nTiles to travel: %2$s \nIs this path and destination acceptable?" ),
to_string_approx( ETA ), tiles_to_travel ) ) {
p.goal = npc::no_goal_point;
p.omt_path.clear();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/overmap_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1895,9 +1895,9 @@ static tripoint_abs_omt display( const tripoint_abs_omt &orig,
// We go faster per-tile the more we have to go
cursor_advance_time = std::chrono::milliseconds( 1000 ) / display_path.size();
cursor_advance_time = std::max( cursor_advance_time, std::chrono::milliseconds( 1 ) );
curs = *display_path_iter;
if( now > last_advance + cursor_advance_time ) {
if( display_path_iter != display_path.rend() ) {
curs = *display_path_iter;
last_advance = now;
display_path_iter++;
} else if( now > last_advance + cursor_advance_time * 10 ) {
Expand Down

0 comments on commit 65b284d

Please sign in to comment.