Skip to content

Commit

Permalink
Merge pull request #38805 from ZhilkinSerg/z-fix-monster-blocking-stairs
Browse files Browse the repository at this point in the history
Fix check for monster blocking stairs
  • Loading branch information
Rivet-the-Zombie authored Mar 16, 2020
2 parents 5360c07 + 5269cee commit abec138
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10338,7 +10338,6 @@ cata::optional<tripoint> game::find_or_make_stairs( map &mp, const int z_after,
cata::optional<tripoint> stairs;
int best = INT_MAX;
const int movez = z_after - get_levz();
Creature *blocking_creature = nullptr;
const bool going_down_1 = movez == -1;
const bool going_up_1 = movez == 1;
// If there are stairs on the same x and y as we currently are, use those
Expand All @@ -10348,35 +10347,28 @@ cata::optional<tripoint> game::find_or_make_stairs( map &mp, const int z_after,
if( going_up_1 && mp.has_flag( TFLAG_GOES_DOWN, u.pos() + tripoint_above ) ) {
stairs.emplace( u.pos() + tripoint_above );
}
if( stairs ) {
// We found stairs above or below, no need to do anything else
return stairs;
}
// Otherwise, search the map for them
for( const tripoint &dest : m.points_in_rectangle( omtile_align_start, omtile_align_end ) ) {
if( rl_dist( u.pos(), dest ) <= best &&
( ( going_down_1 && mp.has_flag( TFLAG_GOES_UP, dest ) ) ||
( going_up_1 && ( mp.has_flag( TFLAG_GOES_DOWN, dest ) ||
mp.ter( dest ) == t_manhole_cover ) ) ||
( ( movez == 2 || movez == -2 ) && mp.ter( dest ) == t_elevator ) ) ) {
if( mp.has_zlevels() && critter_at( dest ) ) {
blocking_creature = critter_at( dest );
continue;
// We did not find stairs directly above or below, so search the map for them
if( !stairs.has_value() ) {
for( const tripoint &dest : m.points_in_rectangle( omtile_align_start, omtile_align_end ) ) {
if( rl_dist( u.pos(), dest ) <= best &&
( ( going_down_1 && mp.has_flag( TFLAG_GOES_UP, dest ) ) ||
( going_up_1 && ( mp.has_flag( TFLAG_GOES_DOWN, dest ) ||
mp.ter( dest ) == t_manhole_cover ) ) ||
( ( movez == 2 || movez == -2 ) && mp.ter( dest ) == t_elevator ) ) ) {
stairs.emplace( dest );
best = rl_dist( u.pos(), dest );
}
stairs.emplace( dest );
best = rl_dist( u.pos(), dest );
}
}

if( stairs ) {
// Stairs found
if( stairs.has_value() ) {
if( Creature *blocking_creature = critter_at( stairs.value() ) ) {
add_msg( _( "There's a %s in the way!" ), blocking_creature->get_name() );
return cata::nullopt;
}
return stairs;
}

if( blocking_creature ) {
add_msg( _( "There's a %s in the way!" ), blocking_creature->get_name() );
return cata::nullopt;
}
// No stairs found! Try to make some
rope_ladder = false;
stairs.emplace( u.pos() );
Expand Down

0 comments on commit abec138

Please sign in to comment.