diff --git a/src/map.cpp b/src/map.cpp index f3a0b6b623ca5..45611bcdaa620 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1890,6 +1890,36 @@ ter_id map::ter( const tripoint_bub_ms &p ) const return ter( p.raw() ); } +int map::get_map_damage( const tripoint_bub_ms &p ) const +{ + if( !inbounds( p ) ) { + return 0; + } + + point_sm_ms l; + const submap *const current_submap = unsafe_get_submap_at( p, l ); + if( current_submap == nullptr ) { + debugmsg( "Called get_map_damage for unloaded submap" ); + return 0; + } + return current_submap->get_map_damage( l ); +} + +void map::set_map_damage( const tripoint_bub_ms &p, int dmg ) +{ + if( !inbounds( p ) ) { + return; + } + + point_sm_ms l; + submap *const current_submap = unsafe_get_submap_at( p, l ); + if( current_submap == nullptr ) { + debugmsg( "Called set_map_damage for unloaded submap" ); + return; + } + return current_submap->set_map_damage( l, dmg ); +} + uint8_t map::get_known_connections( const tripoint &p, const std::bitset &connect_group, const std::map &override ) const @@ -3971,9 +4001,18 @@ void map::bash_ter_furn( const tripoint &p, bash_params ¶ms ) } // Linear interpolation from str_min to str_max const int resistance = smin + ( params.roll * ( smax - smin ) ); - if( params.strength >= resistance ) { + // Semi-persistant map damage. Increment by one for each bash over smin + // Gradually makes hard bashes easier + int damage = get_map_damage( tripoint_bub_ms( p ) ); + add_msg_debug( debugmode::DF_MAP, "Bashing diff. %d to %d, roll %g. Strength is %d + %d vs %d", + smin, smax, params.roll, params.strength, damage, resistance ); + if( params.strength + damage >= resistance ) { + damage = 0; success = true; + } else if( params.strength >= smin ) { + damage += 1; } + set_map_damage( tripoint_bub_ms( p ), damage ); } if( smash_furn ) { diff --git a/src/map.h b/src/map.h index 967c9c88ac44c..c1a746e143417 100644 --- a/src/map.h +++ b/src/map.h @@ -809,6 +809,9 @@ class map return ter( tripoint( p, abs_sub.z() ) ); } + int get_map_damage( const tripoint_bub_ms &p ) const; + void set_map_damage( const tripoint_bub_ms &p, int dmg ); + // Return a bitfield of the adjacent tiles which connect to the given // connect_group. From least-significant bit the order is south, east, // west, north (because that's what cata_tiles expects). diff --git a/src/submap.h b/src/submap.h index d4e6073557d04..96fa0b798bdc3 100644 --- a/src/submap.h +++ b/src/submap.h @@ -123,6 +123,17 @@ class submap ensure_nonuniform(); std::uninitialized_fill_n( &m->frn[0][0], elements, furn ); } + int get_map_damage( const point_sm_ms &p ) const { + auto it = ephemeral_data.find( p ); + if( it != ephemeral_data.end() ) { + return it->second.damage; + } + return 0; + } + + void set_map_damage( const point_sm_ms &p, int dmg ) { + ephemeral_data[p] = { dmg }; + } ter_id get_ter( const point &p ) const { if( is_uniform() ) { @@ -294,7 +305,12 @@ class submap std::map partial_constructions; std::unique_ptr camp; // only allowing one basecamp per submap + struct tile_data { + int damage; + }; + private: + std::map ephemeral_data; std::map computers; std::unique_ptr legacy_computer; std::unique_ptr m;