diff --git a/src/creature.cpp b/src/creature.cpp index b6d81911a8ce8..04b52d4d3b80b 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -396,9 +396,9 @@ bool Creature::sees( const tripoint &t, bool is_avatar, int range_mod ) const const int wanted_range = rl_dist( pos(), t ); if( wanted_range <= range_min || ( wanted_range <= range_max && - here.ambient_light_at( t ) > g->natural_light_level( t.z ) ) ) { + here.ambient_light_at( t ) > here.get_cache_ref( t.z ).natural_light_level_cache ) ) { int range = 0; - if( here.ambient_light_at( t ) > g->natural_light_level( t.z ) ) { + if( here.ambient_light_at( t ) > here.get_cache_ref( t.z ).natural_light_level_cache ) { range = MAX_VIEW_DISTANCE; } else { range = range_min; diff --git a/src/level_cache.h b/src/level_cache.h index 8c8ac64744665..85a971a059b83 100644 --- a/src/level_cache.h +++ b/src/level_cache.h @@ -36,6 +36,9 @@ struct level_cache { // This is only valid for the duration of generate_lightmap float light_source_buffer[MAPSIZE_X][MAPSIZE_Y]; + // Cache of natural light level is useful if it needs to be in sync with the light cache. + float natural_light_level_cache; + // if false, means tile is under the roof ("inside"), true means tile is "outside" // "inside" tiles are protected from sun, rain, etc. (see ter_furn_flag::TFLAG_INDOORS flag) bool outside_cache[MAPSIZE_X][MAPSIZE_Y]; diff --git a/src/lightmap.cpp b/src/lightmap.cpp index 066dd720a0c3f..61bb4db2a1484 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -268,6 +268,7 @@ void map::build_sunlight_cache( int pzlev ) for( int zlev = zlev_max; zlev >= zlev_min; zlev-- ) { level_cache &map_cache = get_cache( zlev ); + map_cache.natural_light_level_cache = g->natural_light_level( zlev ); auto &lm = map_cache.lm; // Grab illumination at ground level. const float outside_light_level = g->natural_light_level( 0 );