From 65b284dbe56ec22ba342e458f37d2edbe141192b Mon Sep 17 00:00:00 2001 From: RenechCDDA <84619419+RenechCDDA@users.noreply.github.com> Date: Sun, 16 Jun 2024 08:25:32 -0400 Subject: [PATCH] Display ETA and distance for destination +don't overrun our iterators --- src/do_turn.cpp | 2 +- src/game_constants.h | 4 ++++ src/npctalk_funcs.cpp | 9 +++++++-- src/overmap_ui.cpp | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/do_turn.cpp b/src/do_turn.cpp index c30b6b130e279..faabb59d44833 100644 --- a/src/do_turn.cpp +++ b/src/do_turn.cpp @@ -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 ) ) { diff --git a/src/game_constants.h b/src/game_constants.h index 0a4881cccc959..2a82625d81864 100644 --- a/src/game_constants.h +++ b/src/game_constants.h @@ -4,6 +4,7 @@ #include #include +#include "calendar.h" #include "units.h" // Fixed window sizes. @@ -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. diff --git a/src/npctalk_funcs.cpp b/src/npctalk_funcs.cpp index 92428bdaf8cb6..9dd5c9ddac4ce 100644 --- a/src/npctalk_funcs.cpp +++ b/src/npctalk_funcs.cpp @@ -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() ); } @@ -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; diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index 685cc3f042371..bb6cde41ba89b 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -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 ) {