From ae6d2b2d03fe973e03607fa4d54b279424a8c5e1 Mon Sep 17 00:00:00 2001 From: Daniel Brooks Date: Fri, 24 May 2024 12:52:22 +0100 Subject: [PATCH 1/2] edit regen in darkness code for readability and correctness (#70799) * edit regen in darkness code for readability and correctness The boolean > 0 check was inside the call to heal(), so it ended up passing either 1 or 0 rather than the calculated amount of healing. The clear intent of the check, however, is to only print the message if the monster actually needed to be healed. I also gave the calculated amount of healing a name (dHP), so that it is clear to future readers what the calculation is for; see the discussion in #67027 for an example of one of the easy ways to misread the old code. This patch does not change when or by how much the monster regenerates. * fix parenthesis style in monster.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/monster.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/monster.cpp b/src/monster.cpp index 77fc67eb381bf..703298476995c 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -3170,7 +3170,8 @@ void monster::process_effects() if( type->regenerates_in_dark ) { const float light = get_map().ambient_light_at( pos() ); // Magic number 10000 was chosen so that a floodlight prevents regeneration in a range of 20 tiles - if( heal( static_cast( 50.0 * std::exp( - light * light / 10000 ) ) > 0 && one_in( 2 ) ) ) { + const float dHP = 50.0 * std::exp( - light * light / 10000 ); + if( heal( static_cast( dHP ) ) > 0 && one_in( 2 ) ) { add_msg_if_player_sees( *this, m_warning, _( "The %s uses the darkness to regenerate." ), name() ); } } From 120fde47c34c5e21f97fcefa2b85c4246ae546f4 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Fri, 24 May 2024 12:52:52 +0100 Subject: [PATCH 2/2] Merge pull request #72684 from nornagon/no-regenerate-in-sunlight no regenerates_in_dark in sunlight --- src/monster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monster.cpp b/src/monster.cpp index 703298476995c..e65d114f0b443 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -3167,7 +3167,7 @@ void monster::process_effects() add_msg_if_player_sees( *this, m_warning, healing_format_string, name() ); } - if( type->regenerates_in_dark ) { + if( type->regenerates_in_dark && !g->is_in_sunlight( pos() ) ) { const float light = get_map().ambient_light_at( pos() ); // Magic number 10000 was chosen so that a floodlight prevents regeneration in a range of 20 tiles const float dHP = 50.0 * std::exp( - light * light / 10000 );