Skip to content

Commit

Permalink
Merge pull request #27814 from jbytheway/night_light_sources
Browse files Browse the repository at this point in the history
Fix at-night lighting by player
  • Loading branch information
kevingranade authored Jan 24, 2019
2 parents ca7031a + be8f6ce commit 9572152
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] );
}
}
}
Expand Down
42 changes: 38 additions & 4 deletions tests/vision_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void full_map_test( const std::vector<std::string> &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();

Expand Down Expand Up @@ -48,9 +49,16 @@ void full_map_test( const std::vector<std::string> &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;
}
}
}
Expand All @@ -63,7 +71,7 @@ void full_map_test( const std::vector<std::string> &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 ) {
Expand All @@ -86,6 +94,7 @@ void full_map_test( const std::vector<std::string> &setup,
g->m.ter_set( p, t_floor );
break;
case 'U':
case 'V':
// Already handled above
break;
default:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9572152

Please sign in to comment.