From 1421ea63dd9df061bc777a9ad166f23740701d84 Mon Sep 17 00:00:00 2001 From: Charlie Gardai <32105250+Moltenhead@users.noreply.github.com> Date: Tue, 23 Feb 2021 08:58:57 +0100 Subject: [PATCH] Stand up peek (#47257) --- src/avatar.cpp | 7 +++++++ src/avatar.h | 2 ++ src/game.cpp | 26 +++++++++++++++++++++++--- src/game.h | 9 +++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/avatar.cpp b/src/avatar.cpp index ad261c4b715e6..c3d02b075b953 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -1526,6 +1526,13 @@ void avatar::toggle_crouch_mode() } } +void avatar::activate_crouch_mode() +{ + if( !is_crouching() ) { + set_movement_mode( move_mode_id( "crouch" ) ); + } +} + void avatar::reset_move_mode() { if( !is_walking() ) { diff --git a/src/avatar.h b/src/avatar.h index 1fa81646c7d7e..427aac2176d3c 100644 --- a/src/avatar.h +++ b/src/avatar.h @@ -237,6 +237,8 @@ class avatar : public player void toggle_run_mode(); // Toggles crouching on/off. void toggle_crouch_mode(); + // Activate crouch mode if not in crouch mode. + void activate_crouch_mode(); bool wield( item_location target ); bool wield( item &target ) override; diff --git a/src/game.cpp b/src/game.cpp index 5ace3f5a310c0..90124b343848c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -6121,10 +6121,20 @@ void game::peek( const tripoint &p ) u.moves -= 200; tripoint prev = u.pos(); u.setpos( p ); + const bool is_same_pos = u.pos() == prev; + const bool is_standup_peek = is_same_pos && u.is_crouching(); tripoint center = p; - const look_around_result result = look_around( /*show_window=*/true, center, center, false, false, - true ); - u.setpos( prev ); + + look_around_result result; + const look_around_params looka_params = { true, center, center, false, false, true }; + if( is_standup_peek ) { // Non moving peek from crouch is a standup peek + u.reset_move_mode(); + result = look_around( looka_params ); + u.activate_crouch_mode(); + } else { // Else is normal peek + result = look_around( looka_params ); + u.setpos( prev ); + } if( result.peek_action && *result.peek_action == PA_BLIND_THROW ) { item_location loc; @@ -6132,6 +6142,7 @@ void game::peek( const tripoint &p ) } m.invalidate_map_cache( p.z ); } + //////////////////////////////////////////////////////////////////////////////////////////// cata::optional game::look_debug() { @@ -7042,6 +7053,8 @@ cata::optional game::look_around() return result.position; } +//look_around_result game::look_around( const bool show_window, tripoint ¢er, +// const tripoint &start_point, bool has_first_point, bool select_zone, bool peeking ) look_around_result game::look_around( const bool show_window, tripoint ¢er, const tripoint &start_point, bool has_first_point, bool select_zone, bool peeking ) { @@ -7360,6 +7373,13 @@ look_around_result game::look_around( const bool show_window, tripoint ¢er, return result; } +look_around_result game::look_around( look_around_params looka_params ) +{ + return look_around( looka_params.show_window, looka_params.center, looka_params.start_point, + looka_params.has_first_point, + looka_params.select_zone, looka_params.peeking ); +} + std::vector game::find_nearby_items( int iRadius ) { std::map temp_items; diff --git a/src/game.h b/src/game.h index c7ae2a8a0e4af..ed032374b833f 100644 --- a/src/game.h +++ b/src/game.h @@ -123,6 +123,14 @@ struct look_around_result { cata::optional position; cata::optional peek_action; }; +struct look_around_params { + const bool show_window; + tripoint ¢er; + const tripoint &start_point; + bool has_first_point; + bool select_zone; + bool peeking; +}; struct w_map { int id; @@ -570,6 +578,7 @@ class game cata::optional look_around(); look_around_result look_around( bool show_window, tripoint ¢er, const tripoint &start_point, bool has_first_point, bool select_zone, bool peeking ); + look_around_result look_around( look_around_params ); // Shared method to print "look around" info void pre_print_all_tile_info( const tripoint &lp, const catacurses::window &w_info,