Skip to content

Commit

Permalink
Do not move into monsters that we cannot displace
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrox authored and ekaratzas committed Mar 9, 2024
1 parent b81087d commit aa47114
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9156,23 +9156,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

0 comments on commit aa47114

Please sign in to comment.