Skip to content

Commit

Permalink
Merge pull request #33889 from mlangsdorf/dont_drown
Browse files Browse the repository at this point in the history
monsters: add a check for vehicles before drowning
  • Loading branch information
ZhilkinSerg authored Sep 9, 2019
2 parents 180273d + 0a7c110 commit 288d4b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,23 @@ static float get_stagger_adjust( const tripoint &source, const tripoint &destina
return std::max( 0.01f, initial_dist - new_dist );
}

bool monster::die_if_drowning( const tripoint &at_pos, const int chance )
{
if( g->m.has_flag( "LIQUID", at_pos ) && can_drown() && one_in( chance ) ) {
// if there's a vehicle here with a boardable part, the monster is on it
// and not drowning
if( g->m.veh_at( at_pos ).part_with_feature( "BOARDABLE", false ) ) {
return false;
}
die( nullptr );
if( g->u.sees( at_pos ) ) {
add_msg( _( "The %s drowns!" ), name() );
}
return true;
}
return false;
}

// General movement.
// Currently, priority goes:
// 1) Special Attack
Expand Down Expand Up @@ -639,11 +656,7 @@ void monster::move()

// The monster is in a deep water tile and has a chance to drown
if( g->m.has_flag_ter( TFLAG_DEEP_WATER, pos() ) ) {
if( g->m.has_flag( "LIQUID", pos() ) && can_drown() && one_in( 10 ) ) {
die( nullptr );
if( g->u.sees( pos() ) ) {
add_msg( _( "The %s drowns!" ), name() );
}
if( die_if_drowning( pos(), 10 ) ) {
return;
}
}
Expand Down Expand Up @@ -1723,13 +1736,9 @@ void monster::knock_back_to( const tripoint &to )

// If we're still in the function at this point, we're actually moving a tile!
if( g->m.has_flag_ter( TFLAG_DEEP_WATER, to ) ) {
if( g->m.has_flag( "LIQUID", to ) && can_drown() ) {
die( nullptr );
if( u_see ) {
add_msg( _( "The %s drowns!" ), name() );
}

} else if( has_flag( MF_AQUATIC ) ) { // We swim but we're NOT in water
// die_if_drowning will kill the monster if necessary, but if the deep water
// tile is on a vehicle, we should check for swimmers out of water
if( !die_if_drowning( to ) && has_flag( MF_AQUATIC ) ) {
die( nullptr );
if( u_see ) {
add_msg( _( "The %s flops around and dies!" ), name() );
Expand Down
5 changes: 5 additions & 0 deletions src/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ class monster : public Creature
void footsteps( const tripoint &p ); // noise made by movement
void shove_vehicle( const tripoint &remote_destination,
const tripoint &nearby_destination ); // shove vehicles out of the way
// check if a monster at a position will drown and kill it if necessary
// returns true if the monster dies
// chance is the one_in( chance ) that the monster will drown
bool die_if_drowning( const tripoint &at_pos, int chance = 1 );


tripoint scent_move();
int calc_movecost( const tripoint &f, const tripoint &t ) const;
Expand Down

0 comments on commit 288d4b5

Please sign in to comment.