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

Do not move into monsters that we cannot displace #47717

Merged
merged 1 commit into from
Feb 24, 2021
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
27 changes: 18 additions & 9 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9991,23 +9991,32 @@ point game::place_player( const tripoint &dest_loc )
// TODO: handling for ridden creatures other than players mount.
if( !critter.has_effect( effect_ridden ) ) {
if( u.is_mounted() ) {
std::vector<tripoint> valid;
std::vector<tripoint> maybe_valid;
for( const tripoint &jk : m.points_in_radius( critter.pos(), 1 ) ) {
if( is_empty( jk ) ) {
valid.push_back( jk );
maybe_valid.push_back( jk );
}
}
if( !valid.empty() ) {
critter.move_to( random_entry( valid ) );
add_msg( _( "You push the %s out of the way." ), critter.name() );
} else {
bool moved = false;
while( !maybe_valid.empty() ) {
if( critter.move_to( random_entry_removed( maybe_valid ) ) ) {
add_msg( _( "You push the %s out of the way." ), critter.name() );
moved = true;
}
}
if( !moved ) {
add_msg( _( "There is no room to push the %s out of the way." ), critter.name() );
return u.pos().xy();
}
} else {
critter.move_to( u.pos(), false,
true ); // Force the movement even though the player is there right now.
add_msg( _( "You displace the %s." ), critter.name() );
// Force the movement even though the player is there right now.
const bool moved = critter.move_to( u.pos(), /*force=*/false, /*step_on_critter=*/true );
if( moved ) {
add_msg( _( "You displace the %s." ), critter.name() );
} else {
add_msg( _( "You cannot move the %s out of the way." ), critter.name() );
return u.pos().xy();
}
}
} else if( !u.has_effect( effect_riding ) ) {
add_msg( _( "You cannot move the %s out of the way." ), critter.name() );
Expand Down