Skip to content

Commit

Permalink
Activate trap on force-moved enemies (#2696)
Browse files Browse the repository at this point in the history
* initial

* fix : adds trap checks to game::knockback

* style reformat : game.cpp

* feature : adds trap checks on teleport
  • Loading branch information
MrLostman committed Apr 25, 2023
1 parent 45cfb3f commit c6c984a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10857,6 +10857,9 @@ void Character::knock_back_to( const tripoint &to )

} else { // It's no wall
setpos( to );

map &here = get_map();
here.creature_on_trap( *this );
}
}

Expand Down
21 changes: 20 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4260,6 +4260,8 @@ void game::knockback( std::vector<tripoint> &traj, int stun, int dam_mult,
}
std::size_t force_remaining = traj.size();
if( monster *const targ = critter_at<monster>( tp, true ) ) {
tripoint start_pos = targ->pos();

if( stun > 0 ) {
targ->add_effect( effect_stunned, 1_turns * stun );
add_msg( _( "%s was stunned!" ), targ->name() );
Expand Down Expand Up @@ -4317,8 +4319,14 @@ void game::knockback( std::vector<tripoint> &traj, int stun, int dam_mult,
}
}
tp = traj[i];
if( start_pos != targ->pos() ) {
map &here = get_map();
here.creature_on_trap( *targ );
}
}
} else if( npc *const targ = critter_at<npc>( tp ) ) {
tripoint start_pos = targ->pos();

if( stun > 0 ) {
targ->add_effect( effect_stunned, 1_turns * stun );
add_msg( _( "%s was stunned!" ), targ->name );
Expand Down Expand Up @@ -4383,8 +4391,15 @@ void game::knockback( std::vector<tripoint> &traj, int stun, int dam_mult,
}
targ->setpos( traj[i] );
tp = traj[i];

if( start_pos != targ->pos() ) {
map &here = get_map();
here.creature_on_trap( *targ );
}
}
} else if( u.pos() == tp ) {
tripoint start_pos = u.pos();

if( stun > 0 ) {
u.add_effect( effect_stunned, 1_turns * stun );
add_msg( m_bad, vgettext( "You were stunned for %d turn!",
Expand Down Expand Up @@ -4462,8 +4477,12 @@ void game::knockback( std::vector<tripoint> &traj, int stun, int dam_mult,
} else {
u.setpos( traj[i] );
}

tp = traj[i];

if( start_pos != u.pos() ) {
map &here = get_map();
here.creature_on_trap( u );
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,9 @@ void monster::knock_back_to( const tripoint &to )

} else { // It's no wall
setpos( to );

map &here = get_map();
here.creature_on_trap( *this );
}
check_dead_state();
}
Expand Down
1 change: 1 addition & 0 deletions src/teleport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ bool teleport::teleport( Creature &critter, int min_distance, int max_distance,
g->update_map( *p );
}
critter.remove_effect( effect_grabbed );
here.creature_on_trap( critter );
return true;
}

0 comments on commit c6c984a

Please sign in to comment.