Skip to content

Commit

Permalink
Stand up peek (#47257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moltenhead authored and ZhilkinSerg committed Mar 16, 2021
1 parent dec9476 commit 7219784
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) {
Expand Down
2 changes: 2 additions & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 23 additions & 3 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6136,17 +6136,28 @@ 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;
avatar_action::plthrow( u, loc, p );
}
m.invalidate_map_cache( p.z );
}

////////////////////////////////////////////////////////////////////////////////////////////
cata::optional<tripoint> game::look_debug()
{
Expand Down Expand Up @@ -7057,6 +7068,8 @@ cata::optional<tripoint> game::look_around()
return result.position;
}

//look_around_result game::look_around( const bool show_window, tripoint &center,
// const tripoint &start_point, bool has_first_point, bool select_zone, bool peeking )
look_around_result game::look_around( const bool show_window, tripoint &center,
const tripoint &start_point, bool has_first_point, bool select_zone, bool peeking )
{
Expand Down Expand Up @@ -7375,6 +7388,13 @@ look_around_result game::look_around( const bool show_window, tripoint &center,
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<map_item_stack> game::find_nearby_items( int iRadius )
{
std::map<std::string, map_item_stack> temp_items;
Expand Down
9 changes: 9 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ struct look_around_result {
cata::optional<tripoint> position;
cata::optional<peek_act> peek_action;
};
struct look_around_params {
const bool show_window;
tripoint &center;
const tripoint &start_point;
bool has_first_point;
bool select_zone;
bool peeking;
};

struct w_map {
int id;
Expand Down Expand Up @@ -572,6 +580,7 @@ class game
cata::optional<tripoint> look_around();
look_around_result look_around( bool show_window, tripoint &center,
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,
Expand Down

0 comments on commit 7219784

Please sign in to comment.