Skip to content

Commit

Permalink
Fix garage door knockback crash (#36671)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpwbrown authored and ZhilkinSerg committed Jan 4, 2020
1 parent 525090e commit 443da66
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5050,18 +5050,19 @@ bool game::forced_door_closing( const tripoint &p, const ter_id &door_type, int
const std::string &door_name = door_type.obj().name();
int kbx = x; // Used when player/monsters are knocked back
int kby = y; // and when moving items out of the way
for( int i = 0; i < 20; i++ ) {
const int x_ = x + rng( -1, +1 );
const int y_ = y + rng( -1, +1 );
if( is_empty( {x_, y_, get_levz()} ) ) {
// invert direction, as game::knockback needs
// the source of the force that knocks back
kbx = -x_ + x + x;
kby = -y_ + y + y;
break;
}
const auto valid_location = [&]( const tripoint & p ) {
return g->is_empty( p );
};
if( const cata::optional<tripoint> pos = random_point( m.points_in_radius( p, 2 ),
valid_location ) ) {
kbx = -pos->x + x + x;
kby = -pos->y + y + y;
}
const tripoint kbp( kbx, kby, p.z );
if( kbp == p ) {
// cant pushback any creatures anywhere, that means the door cant close.
return false;
}
const bool can_see = u.sees( tripoint( x, y, p.z ) );
player *npc_or_player = critter_at<player>( tripoint( x, y, p.z ), false );
if( npc_or_player != nullptr ) {
Expand Down

0 comments on commit 443da66

Please sign in to comment.