Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typified lightmap #73568

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
typified lightmap
  • Loading branch information
PatrikLundell committed May 7, 2024
commit ec028a90bee5e4774cda5e61cedd3e5e54f30501
15 changes: 15 additions & 0 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,21 @@ bool avatar::cant_see( const tripoint &p )
return aim_cache[p.x][p.y];
}

bool avatar::cant_see( const tripoint_bub_ms &p )
PatrikLundell marked this conversation as resolved.
Show resolved Hide resolved
{

// calc based on recoil
if( !last_target_pos.has_value() ) {
return false;
}

if( aim_cache_dirty ) {
rebuild_aim_cache();
}

return aim_cache[p.x()][p.y()];
}

void avatar::rebuild_aim_cache()
{
double pi = 2 * acos( 0.0 );
Expand Down
2 changes: 2 additions & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ class avatar : public Character
std::string preferred_aiming_mode;

// checks if the point is blocked based on characters current aiming state
// TODO Remove untyped overload
bool cant_see( const tripoint &p );
bool cant_see( const tripoint_bub_ms &p );

// rebuilds the full aim cache for the character if it is dirty
void rebuild_aim_cache();
Expand Down
2 changes: 1 addition & 1 deletion src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
}

if( g->display_overlay_state( ACTION_DISPLAY_TRANSPARENCY ) ) {
const float tr = here.light_transparency( {x, y, center.z} );
const float tr = here.light_transparency( tripoint_bub_ms{x, y, center.z} );
int intensity = tr <= LIGHT_TRANSPARENCY_SOLID ? 10 : static_cast<int>
( ( tr - LIGHT_TRANSPARENCY_OPEN_AIR ) * 8 );
draw_debug_tile( intensity, string_format( "%.2f", tr ) );
Expand Down
11 changes: 6 additions & 5 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ int Character::sight_range( float light_level ) const
*/

int range = static_cast<int>( -std::log( get_vision_threshold( get_map().ambient_light_at(
pos() ) ) / light_level ) / LIGHT_TRANSPARENCY_OPEN_AIR );
pos_bub() ) ) / light_level ) / LIGHT_TRANSPARENCY_OPEN_AIR );

// Clamp to [1, sight_max].
return clamp( range, 1, sight_max );
Expand Down Expand Up @@ -1349,7 +1349,7 @@ int Character::clairvoyance() const

bool Character::sight_impaired() const
{
const bool in_light = get_map().ambient_light_at( pos() ) > LIGHT_AMBIENT_LIT;
const bool in_light = get_map().ambient_light_at( pos_bub() ) > LIGHT_AMBIENT_LIT;
return ( ( has_effect( effect_boomered ) || has_effect( effect_no_sight ) ||
has_effect( effect_darkness ) ) &&
( !has_trait( trait_PER_SLIME_OK ) ) ) ||
Expand Down Expand Up @@ -2518,7 +2518,7 @@ void Character::recalc_sight_limits()
{
sight_max = 9999;
vision_mode_cache.reset();
const bool in_light = get_map().ambient_light_at( pos() ) > LIGHT_AMBIENT_LIT;
const bool in_light = get_map().ambient_light_at( pos_bub() ) > LIGHT_AMBIENT_LIT;
bool in_shell = has_active_mutation( trait_SHELL2 ) ||
has_active_mutation( trait_SHELL3 );

Expand Down Expand Up @@ -2805,9 +2805,10 @@ float Character::fine_detail_vision_mod( const tripoint &p ) const

// Same calculation as above, but with a result 3 lower.
float ambient_light{};
tripoint const check_p = p == tripoint_min ? pos() : p;
tripoint_bub_ms const check_p = tripoint_bub_ms( p ) == tripoint_bub_ms(
tripoint_min ) ? pos_bub() : tripoint_bub_ms( p );
tripoint const avatar_p = get_avatar().pos();
if( is_avatar() || check_p.z == avatar_p.z ) {
if( is_avatar() || check_p.z() == avatar_p.z ) {
ambient_light = std::max( 1.0f,
LIGHT_AMBIENT_LIT - get_map().ambient_light_at( check_p ) + 1.0f );
} else {
Expand Down
20 changes: 10 additions & 10 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,12 @@ bool Creature::sees( const Creature &critter ) const

bool Creature::sees( const tripoint &t, bool is_avatar, int range_mod ) const
{
if( std::abs( posz() - t.z ) > fov_3d_z_range ) {
return Creature::sees( tripoint_bub_ms( t ), is_avatar, range_mod );
}

bool Creature::sees( const tripoint_bub_ms &t, bool is_avatar, int range_mod ) const
{
if( std::abs( posz() - t.z() ) > fov_3d_z_range ) {
return false;
}

Expand All @@ -501,12 +506,12 @@ bool Creature::sees( const tripoint &t, bool is_avatar, int range_mod ) const
const int range_night = sight_range( 0 );
const int range_max = std::max( range_day, range_night );
const int range_min = std::min( range_cur, range_max );
const int wanted_range = rl_dist( pos(), t );
const int wanted_range = rl_dist( pos_bub(), t );
if( wanted_range <= range_min ||
( wanted_range <= range_max &&
here.ambient_light_at( t ) > here.get_cache_ref( t.z ).natural_light_level_cache ) ) {
here.ambient_light_at( t ) > here.get_cache_ref( t.z() ).natural_light_level_cache ) ) {
int range = 0;
if( here.ambient_light_at( t ) > here.get_cache_ref( t.z ).natural_light_level_cache ) {
if( here.ambient_light_at( t ) > here.get_cache_ref( t.z() ).natural_light_level_cache ) {
range = MAX_VIEW_DISTANCE;
} else {
range = range_min;
Expand All @@ -524,18 +529,13 @@ bool Creature::sees( const tripoint &t, bool is_avatar, int range_mod ) const
return adj_range >= wanted_range &&
here.get_cache_ref( pos().z ).seen_cache[pos().x][pos().y] > LIGHT_TRANSPARENCY_SOLID;
} else {
return here.sees( pos(), t, range );
return here.sees( pos_bub(), t, range );
}
} else {
return false;
}
}

bool Creature::sees( const tripoint_bub_ms &t, bool is_avatar, int range_mod ) const
{
return sees( t.raw(), is_avatar, range_mod );
}

// Helper function to check if potential area of effect of a weapon overlaps vehicle
// Maybe TODO: If this is too slow, precalculate a bounding box and clip the tested area to it
static bool overlaps_vehicle( const std::set<tripoint> &veh_area, const tripoint &pos,
Expand Down
2 changes: 1 addition & 1 deletion src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ void editmap::update_view_with_help( const std::string &txt, const std::string &
map_cache.seen_cache[target.x][target.y],
map_cache.camera_cache[target.x][target.y]
);
map::apparent_light_info al = map::apparent_light_helper( map_cache, target );
map::apparent_light_info al = map::apparent_light_helper( map_cache, tripoint_bub_ms( target ) );
int apparent_light = static_cast<int>(
here.apparent_light_at( target, here.get_visibility_variables_cache() ) );
mvwprintw( w_info, point( 1, off++ ), _( "outside: %d obstructed: %d floor: %d" ),
Expand Down
2 changes: 1 addition & 1 deletion src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ static std::vector<tripoint> shrapnel( const Creature *source, const tripoint &s

castLightAll<fragment_cloud, fragment_cloud, shrapnel_calc, shrapnel_check,
update_fragment_cloud, accumulate_fragment_cloud>
( visited_cache, obstacle_cache, src.xy(), 0, initial_cloud );
( visited_cache, obstacle_cache, point_bub_ms( src.xy() ), 0, initial_cloud );

creature_tracker &creatures = get_creature_tracker();
Creature *mutable_source = source == nullptr ? nullptr : creatures.creature_at( source->pos() );
Expand Down
5 changes: 3 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6636,7 +6636,7 @@ void game::print_terrain_info( const tripoint &lp, const catacurses::window &w_l

// Print light level on the selected tile.
std::pair<std::string, nc_color> ll = get_light_level( std::max( 1.0,
LIGHT_AMBIENT_LIT - m.ambient_light_at( lp ) + 1.0 ) );
LIGHT_AMBIENT_LIT - m.ambient_light_at( tripoint_bub_ms( lp ) ) + 1.0 ) );
mvwprintz( w_look, point( column, ++line ), c_light_gray, _( "Lighting: " ) );
mvwprintz( w_look, point( column + utf8_width( _( "Lighting: " ) ), line ), ll.second, ll.first );

Expand Down Expand Up @@ -10547,7 +10547,8 @@ bool game::walk_move( const tripoint &dest_loc, const bool via_ramp, const bool
}

const int ramp_adjust = via_ramp ? u.posz() : dest_loc.z;
const float dest_light_level = get_map().ambient_light_at( tripoint( dest_loc.xy(), ramp_adjust ) );
const float dest_light_level = get_map().ambient_light_at( tripoint_bub_ms( point_bub_ms(
dest_loc.xy() ), ramp_adjust ) );

// Allow players with nyctophobia to move freely through cloudy and dark tiles
const float nyctophobia_threshold = LIGHT_AMBIENT_LIT - 3.0f;
Expand Down
Loading
Loading