Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix breaking grab without spending moves by trying to climb up or down #37499

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 68 additions & 68 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<tripoint> 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<tripoint> 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;
}
Expand Down Expand Up @@ -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<tripoint> 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<tripoint> 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<map> tmp_map_ptr;
Expand Down