Skip to content

Commit

Permalink
Merge pull request #75149 from CleverRaven/no-wasting-dodges-on-thing…
Browse files Browse the repository at this point in the history
…s-you-cant-see

Only attempt to dodge relatively slow projectiles
  • Loading branch information
Maleclypse authored Jul 22, 2024
2 parents d09c6c1 + 8adfc09 commit ee4058b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ void Character::consume_dodge_attempts()
}
}

ret_val<void> Character::can_try_doge( bool ignore_dodges_left ) const
ret_val<void> Character::can_try_dodge( bool ignore_dodges_left ) const
{
//If we're asleep or busy we can't dodge
if( in_sleep_state() || has_effect( effect_narcosis ) ||
Expand All @@ -1199,7 +1199,7 @@ ret_val<void> Character::can_try_doge( bool ignore_dodges_left ) const
}
//If stamina is too low we can't dodge
if( get_stamina_dodge_modifier() <= 0.11 ) {
add_msg_debug( debugmode::DF_MELEE, "Stamina too low to doge. Stamina: %d", get_stamina() );
add_msg_debug( debugmode::DF_MELEE, "Stamina too low to dodge. Stamina: %d", get_stamina() );
add_msg_debug( debugmode::DF_MELEE, "Stamina dodge modifier: %f", get_stamina_dodge_modifier() );
return ret_val<void>::make_failure( !is_npc() ? _( "Your stamina is too low to attempt to dodge." )
:
Expand Down Expand Up @@ -1935,7 +1935,7 @@ void Character::mod_part_hp_cur( const bodypart_id &id, int set )

void Character::on_try_dodge()
{
ret_val<void> can_dodge = can_try_doge();
ret_val<void> can_dodge = can_try_dodge();
if( !can_dodge.success() ) {
add_msg( m_bad, can_dodge.c_str() );
return;
Expand All @@ -1955,7 +1955,7 @@ void Character::on_dodge( Creature *source, float difficulty, float training_lev
{
// Make sure we're not practicing dodge in situation where we can't dodge
// We can ignore dodges_left because it was already checked in get_dodge()
if( !can_try_doge( true ).success() ) {
if( !can_try_dodge( true ).success() ) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ class Character : public Creature, public visitable
void set_dodges_left( int dodges );
void mod_dodges_left( int mod );
void consume_dodge_attempts();
ret_val<void> can_try_doge( bool ignore_dodges_left = false ) const;
ret_val<void> can_try_dodge( bool ignore_dodges_left = false ) const;

float get_stamina_dodge_modifier() const;

Expand Down
5 changes: 4 additions & 1 deletion src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,10 @@ void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack
const bool u_see_this = player_view.sees( *this );

const double goodhit = accuracy_projectile_attack( attack );
on_try_dodge(); // There's a doge roll in accuracy_projectile_attack()
// We only trigger a dodge attempt if it's a relatively slow projectile.
if( attack.proj.speed < 20 ) {
on_try_dodge(); // There's a dodge roll in accuracy_projectile_attack()
}

if( goodhit >= 1.0 && !magic ) {
attack.missed_by = 1.0; // Arbitrary value
Expand Down
2 changes: 1 addition & 1 deletion src/melee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ int Character::get_spell_resist() const

float Character::get_dodge() const
{
if( !can_try_doge().success() ) {
if( !can_try_dodge().success() ) {
return 0.0f;
}

Expand Down

0 comments on commit ee4058b

Please sign in to comment.