Skip to content

Commit

Permalink
Allow autoboating (#36221)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpwbrown authored and ZhilkinSerg committed Dec 19, 2019
1 parent 5727c2c commit 33ad641
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
16 changes: 12 additions & 4 deletions src/overmap_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,12 +1429,21 @@ static tripoint display( const tripoint &orig, const draw_data_t &data = draw_da
curs.y = p.y;
}
} else if( action == "CHOOSE_DESTINATION" ) {
bool in_road_vehicle = g->u.in_vehicle && g->u.controlling_vehicle;
const optional_vpart_position vp = g->m.veh_at( g->u.pos() );
bool in_boat = false;
if( vp && in_road_vehicle ) {
vehicle &veh = vp->vehicle();
in_boat = veh.can_float() && veh.is_watercraft() && veh.is_in_water();
if( in_boat ) {
in_road_vehicle = false;
}
}
const tripoint player_omt_pos = g->u.global_omt_location();
if( !g->u.omt_path.empty() && g->u.omt_path.front() == curs ) {
if( query_yn( _( "Travel to this point?" ) ) ) {
// renew the path incase of a leftover dangling path point
g->u.omt_path = overmap_buffer.get_npc_path( player_omt_pos, curs, g->u.in_vehicle &&
g->u.controlling_vehicle );
g->u.omt_path = overmap_buffer.get_npc_path( player_omt_pos, curs, in_road_vehicle, in_boat );
if( g->u.in_vehicle && g->u.controlling_vehicle ) {
vehicle *player_veh = veh_pointer_or_null( g->m.veh_at( g->u.pos() ) );
player_veh->omt_path = g->u.omt_path;
Expand All @@ -1450,8 +1459,7 @@ static tripoint display( const tripoint &orig, const draw_data_t &data = draw_da
if( curs == player_omt_pos ) {
g->u.omt_path.clear();
} else {
g->u.omt_path = overmap_buffer.get_npc_path( player_omt_pos, curs, g->u.in_vehicle &&
g->u.controlling_vehicle );
g->u.omt_path = overmap_buffer.get_npc_path( player_omt_pos, curs, in_road_vehicle, in_boat );
}
} else if( action == "TOGGLE_BLINKING" ) {
uistate.overmap_blinking = !uistate.overmap_blinking;
Expand Down
12 changes: 8 additions & 4 deletions src/overmapbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ bool overmapbuffer::reveal( const tripoint &center, int radius,
}

std::vector<tripoint> overmapbuffer::get_npc_path( const tripoint &src, const tripoint &dest,
bool road_only )
bool road_only, bool do_boat )
{
std::vector<tripoint> path;
static const int RADIUS = 4; // Maximal radius of search (in overmaps)
Expand Down Expand Up @@ -697,8 +697,12 @@ std::vector<tripoint> overmapbuffer::get_npc_path( const tripoint &src, const tr
!is_ot_match( "road_nesw_manhole", oter, ot_match_type::type ) ) ) {
return pf::rejected;
}
if( do_boat && ( !is_river_or_lake( oter ) ||
is_ot_match( "bridge", oter, ot_match_type::type ) ) ) {
return pf::rejected;
}
if( is_ot_match( "empty_rock", oter, ot_match_type::type ) ||
is_ot_match( "open_air", oter, ot_match_type::type ) || oter->is_lake() ) {
is_ot_match( "open_air", oter, ot_match_type::type ) || ( !do_boat && oter->is_lake() ) ) {
return pf::rejected;
} else if( is_ot_match( "forest", oter, ot_match_type::type ) ) {
travel_cost = 10;
Expand All @@ -708,8 +712,8 @@ std::vector<tripoint> overmapbuffer::get_npc_path( const tripoint &src, const tr
is_ot_match( "bridge", oter, ot_match_type::type ) ||
is_ot_match( "road_nesw_manhole", oter, ot_match_type::type ) ) {
travel_cost = 1;
} else if( is_river( oter ) ) {
travel_cost = 20;
} else if( is_river_or_lake( oter ) ) {
travel_cost = do_boat ? 1 : 20;
}
res += travel_cost;
res += manhattan_dist( finish, cur.pos );
Expand Down
2 changes: 1 addition & 1 deletion src/overmapbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class overmapbuffer
bool reveal( const tripoint &center, int radius,
const std::function<bool( const oter_id & )> &filter );
std::vector<tripoint> get_npc_path( const tripoint &src, const tripoint &dest,
bool road_only = false );
bool road_only = false, bool do_boat = false );
bool reveal_route( const tripoint &source, const tripoint &dest, int radius = 0,
bool road_only = false );
/**
Expand Down

0 comments on commit 33ad641

Please sign in to comment.