diff --git a/src/game.cpp b/src/game.cpp index fe1042ff603ca..8a945f33ccf4f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -9930,6 +9930,74 @@ void game::vertical_move( int movez, bool force ) } } + // Force means we're going down, even if there's no staircase, etc. + bool climbing = false; + int move_cost = 100; + tripoint stairs( u.posx(), u.posy(), u.posz() + movez ); + if( m.has_zlevels() && !force && movez == 1 && !m.has_flag( "GOES_UP", u.pos() ) ) { + // Climbing + if( m.has_floor_or_support( stairs ) ) { + add_msg( m_info, _( "You can't climb here - there's a ceiling above your head." ) ); + return; + } + + const int cost = u.climbing_cost( u.pos(), stairs ); + if( cost == 0 ) { + add_msg( m_info, _( "You can't climb here - you need walls and/or furniture to brace against." ) ); + return; + } + + std::vector pts; + for( const auto &pt : m.points_in_radius( stairs, 1 ) ) { + if( m.passable( pt ) && + m.has_floor_or_support( pt ) ) { + pts.push_back( pt ); + } + } + + if( cost <= 0 || pts.empty() ) { + add_msg( m_info, + _( "You can't climb here - there is no terrain above you that would support your weight." ) ); + return; + } else { + // TODO: Make it an extended action + climbing = true; + move_cost = cost; + + const cata::optional pnt = point_selection_menu( pts ); + if( !pnt ) { + return; + } + stairs = *pnt; + } + } + + if( !force && movez == -1 && !m.has_flag( "GOES_DOWN", u.pos() ) ) { + add_msg( m_info, _( "You can't go down here!" ) ); + return; + } else if( !climbing && !force && movez == 1 && !m.has_flag( "GOES_UP", u.pos() ) ) { + add_msg( m_info, _( "You can't go up here!" ) ); + return; + } + + if( force ) { + // Let go of a grabbed cart. + u.grab( OBJECT_NONE ); + } else if( u.grab_point != tripoint_zero ) { + add_msg( m_info, _( "You can't drag things up and down stairs." ) ); + return; + } + + // Because get_levz takes z-value from the map, it will change when vertical_shift (m.has_zlevels() == true) + // is called or when the map is loaded on new z-level (== false). + // This caches the z-level we start the movement on (current) and the level we're want to end. + const int z_before = get_levz(); + const int z_after = get_levz() + movez; + if( z_after < -OVERMAP_DEPTH || z_after > OVERMAP_HEIGHT ) { + debugmsg( "Tried to move outside allowed range of z-levels" ); + return; + } + if( !u.move_effects( false ) ) { return; } @@ -10000,74 +10068,6 @@ void game::vertical_move( int movez, bool force ) return; } - // Force means we're going down, even if there's no staircase, etc. - bool climbing = false; - int move_cost = 100; - tripoint stairs( u.posx(), u.posy(), u.posz() + movez ); - if( m.has_zlevels() && !force && movez == 1 && !m.has_flag( "GOES_UP", u.pos() ) ) { - // Climbing - if( m.has_floor_or_support( stairs ) ) { - add_msg( m_info, _( "You can't climb here - there's a ceiling above your head" ) ); - return; - } - - const int cost = u.climbing_cost( u.pos(), stairs ); - if( cost == 0 ) { - add_msg( m_info, _( "You can't climb here - you need walls and/or furniture to brace against" ) ); - return; - } - - std::vector pts; - for( const auto &pt : m.points_in_radius( stairs, 1 ) ) { - if( m.passable( pt ) && - m.has_floor_or_support( pt ) ) { - pts.push_back( pt ); - } - } - - if( cost <= 0 || pts.empty() ) { - add_msg( m_info, - _( "You can't climb here - there is no terrain above you that would support your weight" ) ); - return; - } else { - // TODO: Make it an extended action - climbing = true; - move_cost = cost; - - const cata::optional pnt = point_selection_menu( pts ); - if( !pnt ) { - return; - } - stairs = *pnt; - } - } - - if( !force && movez == -1 && !m.has_flag( "GOES_DOWN", u.pos() ) ) { - add_msg( m_info, _( "You can't go down here!" ) ); - return; - } else if( !climbing && !force && movez == 1 && !m.has_flag( "GOES_UP", u.pos() ) ) { - add_msg( m_info, _( "You can't go up here!" ) ); - return; - } - - if( force ) { - // Let go of a grabbed cart. - u.grab( OBJECT_NONE ); - } else if( u.grab_point != tripoint_zero ) { - add_msg( m_info, _( "You can't drag things up and down stairs." ) ); - return; - } - - // Because get_levz takes z-value from the map, it will change when vertical_shift (m.has_zlevels() == true) - // is called or when the map is loaded on new z-level (== false). - // This caches the z-level we start the movement on (current) and the level we're want to end. - const int z_before = get_levz(); - const int z_after = get_levz() + movez; - if( z_after < -OVERMAP_DEPTH || z_after > OVERMAP_HEIGHT ) { - debugmsg( "Tried to move outside allowed range of z-levels" ); - return; - } - // Shift the map up or down std::unique_ptr tmp_map_ptr;