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

Use stairs above or below when they exist #38244

Merged
merged 1 commit into from
Mar 2, 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
18 changes: 16 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10284,10 +10284,24 @@ cata::optional<tripoint> game::find_or_make_stairs( map &mp, const int z_after,
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
if( going_down_1 && mp.has_flag( TFLAG_GOES_UP, u.pos() + tripoint_below ) ) {
stairs.emplace( u.pos() + tripoint_below );
}
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 &&
( ( movez == -1 && mp.has_flag( "GOES_UP", dest ) ) ||
( movez == 1 && ( mp.has_flag( "GOES_DOWN", dest ) ||
( ( 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 ) ) {
Expand Down