Skip to content

Commit

Permalink
Display ordered NPC path on map (WIP implementation)
Browse files Browse the repository at this point in the history
  • Loading branch information
RenechCDDA committed May 29, 2024
1 parent de4ec39 commit 33c8311
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/npctalk_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "npctrade.h"
#include "output.h"
#include "overmap.h"
#include "overmap_ui.h"
#include "overmapbuffer.h"
#include "pimpl.h"
#include "player_activity.h"
Expand Down Expand Up @@ -400,6 +401,12 @@ void talk_function::goto_location( npc &p )
add_msg( m_info, _( "That is not a valid destination for %s." ), p.disp_name() );
return;
}
ui::omap::display_npc_path( p.global_omt_location(), p.omt_path );
if( !query_yn( _( "Is this path and destination acceptable?" ) ) ) {
p.goal = npc::no_goal_point;
p.omt_path.clear();
return;
}
p.set_mission( NPC_MISSION_TRAVELLING );
p.chatbin.first_topic = p.chatbin.talk_friend_guard;
p.guard_pos = std::nullopt;
Expand Down
39 changes: 34 additions & 5 deletions src/overmap_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ static bool get_and_assign_los( int &los, avatar &player_character, const tripoi
static void draw_ascii(
const catacurses::window &w, const tripoint_abs_omt &center,
const tripoint_abs_omt &orig, bool blink, bool show_explored, bool /* fast_scroll */,
input_context * /* inp_ctxt */, const draw_data_t &data )
input_context * /* inp_ctxt */, const draw_data_t &data,
std::vector<tripoint_abs_omt> display_path )
{

const int om_map_width = OVERMAP_WINDOW_WIDTH;
Expand Down Expand Up @@ -688,6 +689,11 @@ static void draw_ascii(
npc *npc_to_add = npc_to_get.get();
followers.push_back( npc_to_add );
}
if( !display_path.empty() ) {
for( auto &elem : display_path ) {
npc_path_route.insert( elem );
}
}
// get all traveling NPCs for the debug menu to show pathfinding routes.
if( g->debug_pathfinding ) {
for( auto &elem : overmap_buffer.get_npcs_near_player( 200 ) ) {
Expand Down Expand Up @@ -1253,7 +1259,7 @@ tiles_redraw_info redraw_info;
static void draw(
ui_adaptor &ui, const tripoint_abs_omt &center, const tripoint_abs_omt &orig,
bool blink, bool show_explored, bool fast_scroll,
input_context *inp_ctxt, const draw_data_t &data )
input_context *inp_ctxt, const draw_data_t &data, std::vector<tripoint_abs_omt> display_path )
{
draw_om_sidebar( ui, g->w_omlegend, center, orig, blink, fast_scroll, inp_ctxt, data );
#if defined( TILES )
Expand All @@ -1265,7 +1271,8 @@ static void draw(
return;
}
#endif // TILES
draw_ascii( g->w_overmap, center, orig, blink, show_explored, fast_scroll, inp_ctxt, data );
draw_ascii( g->w_overmap, center, orig, blink, show_explored, fast_scroll, inp_ctxt, data,
display_path );
}

static void create_note( const tripoint_abs_omt &curs )
Expand Down Expand Up @@ -1769,7 +1776,7 @@ static bool try_travel_to_destination( avatar &player_character, const tripoint_
}

static tripoint_abs_omt display( const tripoint_abs_omt &orig,
const draw_data_t &data = draw_data_t() )
const draw_data_t &data = draw_data_t(), std::vector<tripoint_abs_omt> display_path = {} )
{
const int previous_zoom = g->get_zoom();
g->set_zoom( overmap_zoom_level );
Expand Down Expand Up @@ -1857,10 +1864,11 @@ static tripoint_abs_omt display( const tripoint_abs_omt &orig,
int fast_scroll_offset = get_option<int>( "FAST_SCROLL_OFFSET" );
std::optional<tripoint> mouse_pos;
std::chrono::time_point<std::chrono::steady_clock> last_blink = std::chrono::steady_clock::now();
int i = display_path.size() - 1;

ui.on_redraw( [&]( ui_adaptor & ui ) {
draw( ui, curs, orig, uistate.overmap_show_overlays,
show_explored, fast_scroll, &ictxt, data );
show_explored, fast_scroll, &ictxt, data, display_path );
} );

do {
Expand All @@ -1876,6 +1884,21 @@ static tripoint_abs_omt display( const tripoint_abs_omt &orig,
#else
action = ictxt.handle_input( get_option<int>( "BLINK_SPEED" ) );
#endif
if( !display_path.empty() ) {
std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
// This is probably awful? Should use a reverse iterator instead, or something?
curs = display_path.at( i );
if( now > last_blink + std::chrono::milliseconds( 250 ) ) {
if( i > 0 ) {
last_blink = now;
i--;
continue;
} else if( now > last_blink + std::chrono::milliseconds( 2500 ) ) {
action = "QUIT";
break;
}
}
}
if( const std::optional<tripoint> vec = ictxt.get_direction( action ) ) {
int scroll_d = fast_scroll ? fast_scroll_offset : 1;
curs += vec->xy() * scroll_d;
Expand Down Expand Up @@ -2049,6 +2072,12 @@ void ui::omap::display()
overmap_ui::display( get_player_character().global_omt_location(), overmap_ui::draw_data_t() );
}

void ui::omap::display_npc_path( tripoint_abs_omt starting_pos,
std::vector<tripoint_abs_omt> display_path )
{
overmap_ui::display( starting_pos, overmap_ui::draw_data_t(), display_path );
}

void ui::omap::display_hordes()
{
overmap_ui::draw_data_t data;
Expand Down
4 changes: 4 additions & 0 deletions src/overmap_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ namespace omap
* Display overmap centered at the player's position.
*/
void display();
/**
* Display overmap centered at the given NPC's position and visually move across their intended OMT path.
*/
void display_npc_path( tripoint_abs_omt starting_pos, std::vector<tripoint_abs_omt> display_path );
/**
* Display overmap like with @ref display() and display hordes.
*/
Expand Down

0 comments on commit 33c8311

Please sign in to comment.