From 2e146614a5748d4d34d81300bde26c5baffadc7f Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Wed, 23 Jan 2019 22:47:23 +0000 Subject: [PATCH 1/2] Fix player lighting walls at night Player- (and npc-) held items were performing their lighting updates before natural light falling upon walls. Furthermore, the natural light on exterior wall tiles was setting the natural light value without regard to the previous value. Consequently, at night player-held items appeared unable to illuminate exterior walls. Fix this by correcting the natural light code. --- src/lightmap.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lightmap.cpp b/src/lightmap.cpp index ac2eadff1dc89..e0b05b54e028e 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -241,11 +241,14 @@ void map::generate_lightmap( const int zlev ) ) && outside_cache[p.x + dir_x[i]][p.y + dir_y[i]] ) { if( light_transparency( p ) > LIGHT_TRANSPARENCY_SOLID ) { - lm[p.x][p.y][quadrant::default_] = natural_light; + update_light_quadrants( + lm[p.x][p.y], natural_light, quadrant::default_ ); apply_directional_light( p, dir_d[i], natural_light ); } else { - lm[p.x][p.y][dir_quadrants[i][0]] = natural_light; - lm[p.x][p.y][dir_quadrants[i][1]] = natural_light; + update_light_quadrants( + lm[p.x][p.y], natural_light, dir_quadrants[i][0] ); + update_light_quadrants( + lm[p.x][p.y], natural_light, dir_quadrants[i][1] ); } } } From be8f6ce862e3149eb9b9e1db70f4232d4714fcbf Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Wed, 23 Jan 2019 22:57:26 +0000 Subject: [PATCH 2/2] Vision test for player lighting at night Regression test for just-fixed lighting bug. --- tests/vision_test.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/tests/vision_test.cpp b/tests/vision_test.cpp index bbca0f0476239..06141819c441b 100644 --- a/tests/vision_test.cpp +++ b/tests/vision_test.cpp @@ -21,6 +21,7 @@ void full_map_test( const std::vector &setup, g->place_player( tripoint( 60, 60, 0 ) ); g->reset_light_level(); + g->u.worn.clear(); // Remove any light-emitting clothing g->u.clear_effects(); clear_map(); @@ -48,9 +49,16 @@ void full_map_test( const std::vector &setup, tripoint origin; for( int y = 0; y < height; ++y ) { for( int x = 0; x < width; ++x ) { - if( setup[y][x] == 'U' || setup[y][x] == 'u' ) { - origin = g->u.pos() - point( x, y ); - break; + switch( setup[y][x] ) { + case 'V': + case 'U': + case 'u': + origin = g->u.pos() - point( x, y ); + if( setup[y][x] == 'V' ) { + item headlamp( "wearable_light_on" ); + g->u.worn.push_back( headlamp ); + } + break; } } } @@ -63,7 +71,7 @@ void full_map_test( const std::vector &setup, REQUIRE( player_offset.x >= 0 ); REQUIRE( player_offset.x < width ); char player_char = setup[player_offset.y][player_offset.x]; - REQUIRE( ( player_char == 'U' || player_char == 'u' ) ); + REQUIRE( ( player_char == 'U' || player_char == 'u' || player_char == 'V' ) ); } for( int y = 0; y < height; ++y ) { @@ -86,6 +94,7 @@ void full_map_test( const std::vector &setup, g->m.ter_set( p, t_floor ); break; case 'U': + case 'V': // Already handled above break; default: @@ -269,6 +278,7 @@ static constexpr int midday = HOURS( 12 ); // '-' - empty, indoors // 'U' - player, outdoors // 'u' - player, indoors +// 'V' - player, with light in inventory // 'L' - light, indoors // '#' - wall // '=' - window frame @@ -395,6 +405,30 @@ TEST_CASE( "vision_wall_obstructs_light", "[shadowcasting][vision]" ) t.test_all(); } +TEST_CASE( "vision_wall_can_be_lit_by_player", "[shadowcasting][vision]" ) +{ + vision_test_case t { + { + " V", + " ", + " ", + "##", + "--", + }, + { + "44", + "44", + "44", + "44", + "66", + }, + midnight, + true + }; + + t.test_all(); +} + TEST_CASE( "vision_see_wall_in_moonlight", "[shadowcasting][vision]" ) { const time_duration till_full_moon = calendar::season_length() / 3;