Skip to content

Commit

Permalink
Don't access out of lightmap bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
irwiss committed Jun 25, 2023
1 parent 0bdd97d commit 933f08e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down
10 changes: 5 additions & 5 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_" );
}

Expand Down Expand Up @@ -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_" );
}

Expand Down Expand Up @@ -5913,7 +5913,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_" );
}
}
Expand Down Expand Up @@ -5956,7 +5956,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.
Expand Down Expand Up @@ -5993,7 +5993,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() );
Expand Down
4 changes: 3 additions & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 933f08e

Please sign in to comment.