|
113 | 113 | #include "translation.h"
|
114 | 114 | #include "translations.h"
|
115 | 115 | #include "trap.h"
|
116 |
| -#include "uilist.h" |
117 | 116 | #include "ui_manager.h"
|
| 117 | +#include "uilist.h" |
118 | 118 | #include "uistate.h"
|
119 | 119 | #include "units.h"
|
120 | 120 | #include "value_ptr.h"
|
|
127 | 127 | #include "vpart_range.h"
|
128 | 128 | #include "weather.h"
|
129 | 129 | #include "weather_type.h"
|
| 130 | +#include "wound.h" |
130 | 131 |
|
131 | 132 | class activity_actor;
|
132 | 133 |
|
@@ -2546,6 +2547,8 @@ void Character::process_turn()
|
2546 | 2547 | }
|
2547 | 2548 | }
|
2548 | 2549 |
|
| 2550 | + update_wounds( 1_turns ); |
| 2551 | + |
2549 | 2552 | // We can dodge again! Assuming we can actually move...
|
2550 | 2553 | if( in_sleep_state() ) {
|
2551 | 2554 | blocks_left = 0;
|
@@ -7957,6 +7960,21 @@ void Character::update_cached_mutations()
|
7957 | 7960 | trait_flag_cache.clear();
|
7958 | 7961 | }
|
7959 | 7962 |
|
| 7963 | +void Character::apply_wound( bodypart_id bp, wound_type_id wd ) |
| 7964 | +{ |
| 7965 | + bodypart &body_bp = body.at( bp.id() ); |
| 7966 | + body_bp.add_wound( wd ); |
| 7967 | + morale->on_stat_change( "perceived_pain", get_perceived_pain() ); |
| 7968 | +} |
| 7969 | + |
| 7970 | +void Character::update_wounds( time_duration time_passed ) |
| 7971 | +{ |
| 7972 | + for( auto &bp : body ) { |
| 7973 | + bp.second.update_wounds( time_passed ); |
| 7974 | + } |
| 7975 | + morale->on_stat_change( "perceived_pain", get_perceived_pain() ); |
| 7976 | +} |
| 7977 | + |
7960 | 7978 | void Character::passive_absorb_hit( const bodypart_id &bp, damage_unit &du ) const
|
7961 | 7979 | {
|
7962 | 7980 | // >0 check because some mutations provide negative armor
|
@@ -8377,6 +8395,30 @@ void Character::apply_damage( Creature *source, bodypart_id hurt, int dam,
|
8377 | 8395 | }
|
8378 | 8396 | }
|
8379 | 8397 |
|
| 8398 | +void Character::apply_random_wound( bodypart_id bp, const damage_instance &d ) |
| 8399 | +{ |
| 8400 | + if( x_in_y( 1.0f - get_option<float>( "WOUND_CHANCE" ), 1.0f ) ) { |
| 8401 | + return; |
| 8402 | + } |
| 8403 | + |
| 8404 | + weighted_int_list<wound_type_id> possible_wounds; |
| 8405 | + for( const weighted_object<int, bp_wounds> &wd : bp->potential_wounds ) { |
| 8406 | + for( const damage_unit &du : d.damage_units ) { |
| 8407 | + const bool damage_within_limits = |
| 8408 | + du.amount >= wd.obj.damage_required.first && |
| 8409 | + du.amount <= wd.obj.damage_required.second; |
| 8410 | + const bool damage_type_matches = std::find( wd.obj.damage_type.begin(), wd.obj.damage_type.end(), |
| 8411 | + du.type ) != wd.obj.damage_type.end(); |
| 8412 | + if( damage_within_limits && damage_type_matches ) { |
| 8413 | + possible_wounds.add( wd.obj.id, wd.weight ); |
| 8414 | + } |
| 8415 | + } |
| 8416 | + } |
| 8417 | + if( !possible_wounds.empty() ) { |
| 8418 | + apply_wound( bp, *possible_wounds.pick() ); |
| 8419 | + } |
| 8420 | +} |
| 8421 | + |
8380 | 8422 | dealt_damage_instance Character::deal_damage( Creature *source, bodypart_id bp,
|
8381 | 8423 | const damage_instance &d, const weakpoint_attack &attack, const weakpoint & )
|
8382 | 8424 | {
|
@@ -8493,6 +8535,8 @@ dealt_damage_instance Character::deal_damage( Creature *source, bodypart_id bp,
|
8493 | 8535 | }
|
8494 | 8536 | }
|
8495 | 8537 |
|
| 8538 | + apply_random_wound( bp, d ); |
| 8539 | + |
8496 | 8540 | on_hurt( source );
|
8497 | 8541 | return dealt_dams;
|
8498 | 8542 | }
|
@@ -12798,6 +12842,18 @@ bool Character::immune_to( const bodypart_id &bp, damage_unit dam ) const
|
12798 | 12842 | return dam.amount <= 0;
|
12799 | 12843 | }
|
12800 | 12844 |
|
| 12845 | +int Character::get_pain() const |
| 12846 | +{ |
| 12847 | + int p = 0; |
| 12848 | + for( const std::pair<const bodypart_str_id, bodypart> &bp : get_body() ) { |
| 12849 | + for( const wound &wd : bp.second.get_wounds() ) { |
| 12850 | + p += wd.get_pain(); |
| 12851 | + } |
| 12852 | + } |
| 12853 | + |
| 12854 | + return p + Creature::get_pain(); |
| 12855 | +} |
| 12856 | + |
12801 | 12857 | int Character::mod_pain( int npain )
|
12802 | 12858 | {
|
12803 | 12859 | if( npain > 0 ) {
|
|
0 commit comments