Skip to content

Commit

Permalink
Merge pull request #78789 from mqrause/map_pocket_lights
Browse files Browse the repository at this point in the history
Items in transparent pockets on the map illuminate surroundings
  • Loading branch information
Maleclypse authored Dec 27, 2024
2 parents 36bb280 + f9eee2b commit a014c17
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
16 changes: 15 additions & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10258,7 +10258,21 @@ bool item::is_funnel_container( units::volume &bigger_than ) const

bool item::is_emissive() const
{
return light.luminance > 0 || type->light_emission > 0;
if( light.luminance > 0 || type->light_emission > 0 ) {
return true;
}

for( const item_pocket *pkt : get_all_contained_pockets() ) {
if( pkt->transparent() ) {
for( const item *it : pkt->all_items_top() ) {
if( it->is_emissive() ) {
return true;
}
}
}
}

return false;
}

bool item::is_deployable() const
Expand Down
33 changes: 23 additions & 10 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,35 @@ std::string four_quadrants::to_string() const
( *this )[quadrant::SW], ( *this )[quadrant::NW] );
}

void map::add_light_from_items( const tripoint_bub_ms &p, const item_stack &items )
void map::add_item_light_recursive( const tripoint_bub_ms &p, const item &it )
{
for( const item &it : items ) {
float ilum = 0.0f; // brightness
units::angle iwidth = 0_degrees; // 0-360 degrees. 0 is a circular light_source
units::angle idir = 0_degrees; // otherwise, it's a light_arc pointed in this direction
if( it.getlight( ilum, iwidth, idir ) ) {
if( iwidth > 0_degrees ) {
apply_light_arc( p, idir, ilum, iwidth );
} else {
add_light_source( p, ilum );
float ilum = 0.0f; // brightness
units::angle iwidth = 0_degrees; // 0-360 degrees. 0 is a circular light_source
units::angle idir = 0_degrees; // otherwise, it's a light_arc pointed in this direction
if( it.getlight( ilum, iwidth, idir ) ) {
if( iwidth > 0_degrees ) {
apply_light_arc( p, idir, ilum, iwidth );
} else {
add_light_source( p, ilum );
}
}

for( const item_pocket *pkt : it.get_all_contained_pockets() ) {
if( pkt->transparent() ) {
for( const item *cont : pkt->all_items_top() ) {
add_item_light_recursive( p, *cont );
}
}
}
}

void map::add_light_from_items( const tripoint_bub_ms &p, const item_stack &items )
{
for( const item &it : items ) {
add_item_light_recursive( p, it );
}
}

// TODO: Consider making this just clear the cache and dynamically fill it in as is_transparent() is called
bool map::build_transparency_cache( const int zlev )
{
Expand Down
1 change: 1 addition & 0 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,7 @@ class map
void apply_light_ray( cata::mdarray<bool, point_bub_ms, MAPSIZE_X, MAPSIZE_Y> &lit,
const tripoint &s, const tripoint &e, float luminance );
void add_light_from_items( const tripoint_bub_ms &p, const item_stack &items );
void add_item_light_recursive( const tripoint_bub_ms &p, const item &it );
std::unique_ptr<vehicle> add_vehicle_to_map( std::unique_ptr<vehicle> veh, bool merge_wrecks );

// Internal methods used to bash just the selected features
Expand Down

0 comments on commit a014c17

Please sign in to comment.