Skip to content

Commit

Permalink
Enhance limb healing functionality (#55069)
Browse files Browse the repository at this point in the history
  • Loading branch information
Venera3 authored Feb 4, 2022
1 parent 3f2ba3d commit c6e58fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/JSON_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ Some armor flags, such as `WATCH` and `ALARMCLOCK` are compatible with other ite
## Bodyparts

- ```ALWAYS_BLOCK``` This nonstandard bodypart is always eligible to block in unarmed combat even if your martial arts don't allow such blocks.
- ```ALWAYS_HEAL``` This bodypart regenerates every regen tick (5 minutes, currently) regardless if the part would have healed normally.
- ```HEAL_OVERRIDE``` This bodypart will always regenerate its `heal_bonus` HP instead of it modifying the base healing step. Without `ALWAYS_HEAL` this still only happens when the part would have healed non-zero amount of damage.
- ```IGNORE_TEMP``` This bodypart is ignored for temperature calculations
- ```LIMB_LOWER``` This bodypart is close to the ground, and as such has a higher chance to be attacked by small monsters - hitsize is tripled for creatures that can't attack upper limbs.
- ```LIMB_UPPER``` This bodypart is high off the ground, and as such can't be attacked by small monsters - unless they have the `FLIES` or have `ATTACK_UPPER` flags`
Expand Down
2 changes: 1 addition & 1 deletion doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ For information about tools with option to export ASCII art in format ready to b
| `temp_mod` | (_optional array_) Intrinsic temperature modifier of the bodypart. The first value (in the same "temperature unit" as mutations' `bodytemp_modifier`) is always applied, the second value is apllied on top when the bodypart isn't overheated.
| `env_protection` | (_optional_) Innate environmental protection of this part. (default: `0`)
| `stat_hp_mods` | (_optional_) Values modifying hp_max of this part following this formula: `hp_max += int_mod*int_max + dex_mod*dex_max + str_mod*str_max + per_mod*per_max + health_mod*get_healthy()` with X_max being the unmodified value of the X stat and get_healthy() being the hidden health stat of the character.
| `heal_bonus` | (_optional_) Innate amount of HP the bodypart heals every healing roll ( 5 minutes, currently ).
| `heal_bonus` | (_optional_) Innate amount of HP the bodypart heals every successful healing roll. See the `ALWAYS_HEAL` and `HEAL_OVERRIDE` flags.
| `mend_rate` | (_optional_) Innate mending rate of the limb, should it get broken. Default `1.0`, used as a multiplier on the healing factor after other factors are calculated.
| `health_limit` | (_optional_) Amount of limb HP necessary for the limb to provide its melee `techniques` and `conditional_flags`. Defaults to 1, meaning broken limbs don't contribute.
| `bionic_slots` | (_optional_) How many bionic slots does this part have.
Expand Down
17 changes: 15 additions & 2 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ static const itype_id itype_rm13_armor_on( "rm13_armor_on" );

static const json_character_flag json_flag_ACID_IMMUNE( "ACID_IMMUNE" );
static const json_character_flag json_flag_ALARMCLOCK( "ALARMCLOCK" );
static const json_character_flag json_flag_ALWAYS_HEAL( "ALWAYS_HEAL" );
static const json_character_flag json_flag_BASH_IMMUNE( "BASH_IMMUNE" );
static const json_character_flag json_flag_BIO_IMMUNE( "BIO_IMMUNE" );
static const json_character_flag json_flag_BLIND( "BLIND" );
Expand All @@ -291,6 +292,7 @@ static const json_character_flag json_flag_ELECTRIC_IMMUNE( "ELECTRIC_IMMUNE" );
static const json_character_flag json_flag_ENHANCED_VISION( "ENHANCED_VISION" );
static const json_character_flag json_flag_EYE_MEMBRANE( "EYE_MEMBRANE" );
static const json_character_flag json_flag_FEATHER_FALL( "FEATHER_FALL" );
static const json_character_flag json_flag_HEAL_OVERRIDE( "HEAL_OVERRIDE" );
static const json_character_flag json_flag_HEATPROOF( "HEATPROOF" );
static const json_character_flag json_flag_HEATSINK( "HEATSINK" );
static const json_character_flag json_flag_HYPEROPIC( "HYPEROPIC" );
Expand Down Expand Up @@ -7526,10 +7528,21 @@ void Character::heal_bp( bodypart_id bp, int dam )

void Character::heal( const bodypart_id &healed, int dam )
{
if( !is_limb_broken( healed ) ) {
int effective_heal = std::min( dam + healed->heal_bonus,
if( !is_limb_broken( healed ) && ( dam != 0 || healed->has_flag( json_flag_ALWAYS_HEAL ) ) ) {
add_msg_debug( debugmode::DF_CHAR_HEALTH, "Base healing of %s = %d", body_part_name( healed ),
dam );
if( healed->has_flag( json_flag_HEAL_OVERRIDE ) ) {
dam = healed->heal_bonus;
add_msg_debug( debugmode::DF_CHAR_HEALTH, "Heal override, new healing %d", dam );
} else {
dam += healed->heal_bonus;
add_msg_debug( debugmode::DF_CHAR_HEALTH, "Healing after bodypart heal bonus %d", dam );
}
int effective_heal = std::min( dam,
get_part_hp_max( healed ) - get_part_hp_cur( healed ) ) ;
mod_part_hp_cur( healed, effective_heal );
add_msg_debug( debugmode::DF_CHAR_HEALTH, "Final healing of %s = %d", body_part_name( healed ),
dam );
get_event_bus().send<event_type::character_heals_damage>( getID(), effective_heal );
}
}
Expand Down

0 comments on commit c6e58fc

Please sign in to comment.