From 99eae7e4ae17169aecb1b2d2d4bee747844802cd Mon Sep 17 00:00:00 2001 From: irwiss Date: Sun, 25 Jun 2023 08:19:39 +0300 Subject: [PATCH] Don't access out of lightmap bounds --- src/lightmap.cpp | 5 +++++ src/map.cpp | 10 +++++----- src/map.h | 4 +++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lightmap.cpp b/src/lightmap.cpp index 254eca1206e81..dc4016abdadbc 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -782,6 +782,11 @@ lit_level map::apparent_light_at( const tripoint &p, const visibility_variables } } +bool tinymap::pl_sees( const tripoint &, int ) const +{ + return false; +} + bool map::pl_sees( const tripoint &t, const int max_range ) const { if( !inbounds( t ) ) { diff --git a/src/map.cpp b/src/map.cpp index 9ebcd5bf1b36c..f090e470d2bfb 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1709,7 +1709,7 @@ bool map::furn_set( const tripoint &p, const furn_id &new_furniture, const bool invalidate_max_populated_zlev( p.z ); set_memory_seen_cache_dirty( p ); - if( player_character.sees( p ) ) { + if( pl_sees( p, player_character.sight_max ) ) { player_character.memorize_clear_decoration( getabs( p ), "f_" ); } @@ -2153,7 +2153,7 @@ bool map::ter_set( const tripoint &p, const ter_id &new_terrain, bool avoid_crea set_memory_seen_cache_dirty( p ); avatar &player_character = get_avatar(); - if( player_character.sees( p ) ) { + if( pl_sees( p, player_character.sight_max ) ) { player_character.memorize_clear_decoration( getabs( p ), "t_" ); } @@ -5917,7 +5917,7 @@ void map::partial_con_remove( const tripoint_bub_ms &p ) current_submap->partial_constructions.erase( tripoint_sm_ms( l, p.z() ) ); set_memory_seen_cache_dirty( p.raw() ); avatar &player_character = get_avatar(); - if( player_character.sees( p ) ) { + if( pl_sees( p.raw(), player_character.sight_max ) ) { player_character.memorize_clear_decoration( getabs( p ), "tr_" ); } } @@ -5960,7 +5960,7 @@ void map::trap_set( const tripoint &p, const trap_id &type ) set_memory_seen_cache_dirty( p ); avatar &player_character = get_avatar(); - if( player_character.sees( p ) ) { + if( pl_sees( p, player_character.sight_max ) ) { player_character.memorize_clear_decoration( getabs( p ), "tr_" ); } // If there was already a trap here, remove it. @@ -5997,7 +5997,7 @@ void map::remove_trap( const tripoint &p ) if( g != nullptr && this == &get_map() ) { set_memory_seen_cache_dirty( p ); avatar &player_character = get_avatar(); - if( player_character.sees( p ) ) { + if( pl_sees( p, player_character.sight_max ) ) { player_character.memorize_clear_decoration( getabs( p ), "tr_" ); } player_character.add_known_trap( p, tr_null.obj() ); diff --git a/src/map.h b/src/map.h index f6a43ab31fdea..dc4fefca2ca36 100644 --- a/src/map.h +++ b/src/map.h @@ -1755,7 +1755,7 @@ class map * @param max_range All squares that are further away than this are invisible. * Ignored if smaller than 0. */ - bool pl_sees( const tripoint &t, int max_range ) const; + virtual bool pl_sees( const tripoint &t, int max_range ) const; /** * Uses the map cache to tell if the player could see the given square. * pl_sees implies pl_line_of_sight @@ -2293,6 +2293,8 @@ class tinymap : public map public: tinymap() : map( 2, false ) {} bool inbounds( const tripoint &p ) const override; + // @returns false + bool pl_sees( const tripoint &t, int max_range ) const override; }; class fake_map : public tinymap