From d9cd0b1cef84a55e585ee422c697bdc4277c8a91 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 a6f1d61c51a30..fa57de9061a01 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 cb5b0f38c45c1..5e161a35df947 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -6136,10 +6136,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; @@ -6147,6 +6157,7 @@ void game::peek( const tripoint &p ) } m.invalidate_map_cache( p.z ); } + //////////////////////////////////////////////////////////////////////////////////////////// cata::optional game::look_debug() { @@ -7057,6 +7068,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 ) { @@ -7375,6 +7388,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 88e59f130d982..247d68f7da31e 100644 --- a/src/game.h +++ b/src/game.h @@ -125,6 +125,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; @@ -572,6 +580,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,