Skip to content

Commit

Permalink
use MAX_VIEW_DISTANCE in place of hardcoded values. unmagic air opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
esotericist committed Apr 25, 2024
1 parent 518d99c commit fd5cee2
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ action_id handle_action_menu()

Character &player_character = get_player_character();
// Check if we're in a potential combat situation, if so, sort a few actions to the top.
if( !player_character.get_hostile_creatures( 60 ).empty() ) {
if( !player_character.get_hostile_creatures( MAX_VIEW_DISTANCE ).empty() ) {
// Only prioritize movement options if we're not driving.
if( !player_character.controlling_vehicle ) {
action_weightings[ACTION_CYCLE_MOVE] = 400;
Expand Down
4 changes: 2 additions & 2 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,8 @@ void hacking_activity_actor::finish( player_activity &act, Character &who )
// currently all things that can be hacked have equivalent alarm failure states.
// this may not always be the case with new hackable things.
get_event_bus().send<event_type::triggers_alarm>( who.getID() );
sounds::sound( who.pos(), 60, sounds::sound_t::music, _( "an alarm sound!" ), true, "environment",
"alarm" );
sounds::sound( who.pos(), MAX_VIEW_DISTANCE, sounds::sound_t::music, _( "an alarm sound!" ), true,
"environment", "alarm" );
break;
case hack_result::NOTHING:
who.add_msg_if_player( _( "You fail the hack, but no alarms are triggered." ) );
Expand Down
4 changes: 2 additions & 2 deletions src/basecamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,9 @@ void basecamp::form_storage_zones( map &here, const tripoint_abs_ms &abspos )
}
tripoint src_loc = here.getlocal( bb_pos ) + point_north;
std::vector<tripoint_abs_ms> possible_liquid_dumps;
if( mgr.has_near( zone_type_CAMP_STORAGE, abspos, 60 ) ) {
if( mgr.has_near( zone_type_CAMP_STORAGE, abspos, MAX_VIEW_DISTANCE ) ) {
const std::vector<const zone_data *> zones = mgr.get_near_zones( zone_type_CAMP_STORAGE, abspos,
60 );
MAX_VIEW_DISTANCE );
// Find the nearest unsorted zone to dump objects at
if( !zones.empty() ) {
if( zones != storage_zones ) {
Expand Down
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ int Character::sight_range( float light_level ) const

int Character::unimpaired_range() const
{
return std::min( sight_max, 60 );
return std::min( sight_max, MAX_VIEW_DISTANCE );
}

bool Character::overmap_los( const tripoint_abs_omt &omt, int sight_points ) const
Expand Down
2 changes: 1 addition & 1 deletion src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ plot_options::query_seed_result plot_options::query_seed()
zone_manager &mgr = zone_manager::get_manager();
map &here = get_map();
const std::unordered_set<tripoint_abs_ms> zone_src_set =
mgr.get_near( zone_type_LOOT_SEEDS, here.getglobal( player_character.pos() ), 60 );
mgr.get_near( zone_type_LOOT_SEEDS, here.getglobal( player_character.pos() ), MAX_VIEW_DISTANCE );
for( const tripoint_abs_ms &elem : zone_src_set ) {
tripoint elem_loc = here.getlocal( elem );
for( item &it : here.i_at( elem_loc ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/clzones.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ inline const faction_id your_fac( "your_followers" );
const std::string type_fac_hash_str = "__FAC__";

//Generic activity: maximum search distance for zones, constructions, etc.
constexpr int ACTIVITY_SEARCH_DISTANCE = 60;
constexpr int ACTIVITY_SEARCH_DISTANCE = MAX_VIEW_DISTANCE;

extern const std::vector<zone_type_id> ignorable_zone_types;

Expand Down
6 changes: 3 additions & 3 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5290,8 +5290,8 @@ bool basecamp::validate_sort_points()
zone_manager &mgr = zone_manager::get_manager();
map *here = &get_map();
const tripoint_abs_ms abspos = get_player_character().get_location();
if( !mgr.has_near( zone_type_CAMP_STORAGE, abspos, 60 ) ||
!mgr.has_near( zone_type_CAMP_FOOD, abspos, 60 ) ) {
if( !mgr.has_near( zone_type_CAMP_STORAGE, abspos, MAX_VIEW_DISTANCE ) ||
!mgr.has_near( zone_type_CAMP_FOOD, abspos, MAX_VIEW_DISTANCE ) ) {
if( query_yn( _( "You do not have sufficient sort zones. Do you want to add them?" ) ) ) {
return set_sort_points();
} else {
Expand Down Expand Up @@ -5687,7 +5687,7 @@ bool basecamp::distribute_food()
}
const tripoint_abs_ms &abspos = get_dumping_spot();
const std::unordered_set<tripoint_abs_ms> &z_food =
mgr.get_near( zone_type_CAMP_FOOD, abspos, 60 );
mgr.get_near( zone_type_CAMP_FOOD, abspos, MAX_VIEW_DISTANCE );

double quick_rot = 0.6 + ( has_provides( "pantry" ) ? 0.1 : 0 );
double slow_rot = 0.8 + ( has_provides( "pantry" ) ? 0.05 : 0 );
Expand Down
8 changes: 4 additions & 4 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7023,7 +7023,7 @@ void game::zones_manager()
}

// get zones with distance between player and
// zone center point <= 60 or all zones, if show_all_zones is true
// zone center point <= ACTIVITY_SEARCH_DISTANCE or all zones, if show_all_zones is true
auto get_zones = [&]() {
std::vector<zone_manager::ref_zone_data> zones;
if( show_all_zones ) {
Expand Down Expand Up @@ -7612,7 +7612,7 @@ std::optional<std::vector<tripoint_bub_ms>> game::safe_route_to( Character &who,
};
route_t shortest_route;
std::unordered_set<tripoint> path_avoid;
for( const tripoint_bub_ms &p : points_in_radius( who.pos_bub(), 60 ) ) {
for( const tripoint_bub_ms &p : points_in_radius( who.pos_bub(), MAX_VIEW_DISTANCE ) ) {
if( is_dangerous_tile( p.raw() ) ) {
path_avoid.insert( p.raw() );
}
Expand Down Expand Up @@ -8345,8 +8345,8 @@ void game::list_items_monsters()
{
// Search whole reality bubble because each function internally verifies
// the visibility of the items / monsters in question.
std::vector<Creature *> mons = u.get_visible_creatures( 60 );
const std::vector<map_item_stack> items = find_nearby_items( 60 );
std::vector<Creature *> mons = u.get_visible_creatures( MAX_VIEW_DISTANCE );
const std::vector<map_item_stack> items = find_nearby_items( MAX_VIEW_DISTANCE );

if( mons.empty() && items.empty() ) {
add_msg( m_info, _( "You don't see any items or monsters around you!" ) );
Expand Down
2 changes: 1 addition & 1 deletion src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7052,7 +7052,7 @@ std::optional<int> iuse::radiocaron( Character *p, item *it, const tripoint & )
static void sendRadioSignal( Character &p, const flag_id &signal )
{
map &here = get_map();
for( const tripoint &loc : here.points_in_radius( p.pos(), 60 ) ) {
for( const tripoint &loc : here.points_in_radius( p.pos(), MAX_VIEW_DISTANCE ) ) {
for( item &it : here.i_at( loc ) ) {
if( it.has_flag( flag_RADIO_ACTIVATION ) && it.has_flag( signal ) ) {
sounds::sound( p.pos(), 6, sounds::sound_t::alarm, _( "beep" ), true, "misc", "beep" );
Expand Down
4 changes: 2 additions & 2 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ void castLight( cata::mdarray<Out, point_bub_ms> &output_cache,
{
constexpr quadrant quad = quadrant_from_x_y( -xx - xy, -yx - yy );
float newStart = 0.0f;
float radius = 60.0f - offsetDistance;
float radius = static_cast<float>( MAX_VIEW_DISTANCE ) - offsetDistance;
if( start < end ) {
return;
}
Expand Down Expand Up @@ -1071,7 +1071,7 @@ void map::build_seen_cache( const tripoint &origin, const int target_z, int exte
if( !is_camera ) {
offsetDistance = penalty + rl_dist( origin, mirror_pos );
} else {
offsetDistance = 60 - vpi_mirror.bonus * vp_mirror.hp() / vpi_mirror.durability;
offsetDistance = MAX_VIEW_DISTANCE - vpi_mirror.bonus * vp_mirror.hp() / vpi_mirror.durability;
mocache = &camera_cache;
( *mocache )[mirror_pos.x][mirror_pos.y] = LIGHT_TRANSPARENCY_OPEN_AIR;
}
Expand Down
11 changes: 7 additions & 4 deletions src/lightmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <cmath> // IWYU pragma: keep
#include <ostream>
#include "map_scale_constants.h"

constexpr float LIGHT_SOURCE_LOCAL = 0.1f;
constexpr float LIGHT_SOURCE_BRIGHT = 10.0f;
Expand All @@ -30,10 +31,12 @@ constexpr float LIGHT_AMBIENT_LIT = 10.0f;
* Note: LIGHT_TRANSPARENCY_SOLID=0 is a special case (it indicates completely opaque tile)
* */
constexpr float LIGHT_TRANSPARENCY_SOLID = 0.0f;
// Calculated to run out at 60 squares.
// Cumulative transparency should drop to 0.1 or lower over 60 squares,
// Bright sunlight should drop to LIGHT_AMBIENT_LOW over 60 squares.
constexpr float LIGHT_TRANSPARENCY_OPEN_AIR = 0.038376418216f;

// Expected to run out at the maximum view distance as per MAX_VIEW_DISTANCE
// in map_scale_constants.h.
// Cumulative transparency should drop to 0.1 or lower, and bright sunlight should drop to
// LIGHT_AMBIENT_LOW over the same distance.
constexpr float LIGHT_TRANSPARENCY_OPEN_AIR = 2.3f / MAX_VIEW_DISTANCE;

// indicates starting (full) visibility (for seen_cache)
constexpr float VISIBILITY_FULL = 1.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9601,7 +9601,7 @@ void map::build_map_cache( const int zlev, bool skip_lightmap )
if( inbounds( mon.second ) ) {
int const range = mon.first->type->vision_day;
build_seen_cache( getlocal( mon.second ), mon.second.z(), range, cumulative,
true, std::max( 60 - range, 0 ) );
true, std::max( MAX_VIEW_DISTANCE - range, 0 ) );
cumulative = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,8 @@ class map

protected:
void generate_lightmap( int zlev );
void build_seen_cache( const tripoint &origin, int target_z, int extension_range = 60,
void build_seen_cache( const tripoint &origin, int target_z,
int extension_range = MAX_VIEW_DISTANCE,
bool cumulative = false,
bool camera = false, int penalty = 0 );
void apply_character_light( Character &p );
Expand Down
10 changes: 5 additions & 5 deletions src/monattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4760,8 +4760,8 @@ bool mattack::flesh_tendril( monster *z )
if( one_in( 70 ) ) {
add_msg( _( "The floor trembles underneath your feet." ) );
z->mod_moves( -to_moves<int>( 2_seconds ) );
sounds::sound( z->pos(), 60, sounds::sound_t::alert, _( "a deafening roar!" ), false, "shout",
"roar" );
sounds::sound( z->pos(), MAX_VIEW_DISTANCE, sounds::sound_t::alert, _( "a deafening roar!" ), false,
"shout", "roar" );
}
return false;
}
Expand All @@ -4788,8 +4788,8 @@ bool mattack::flesh_tendril( monster *z )
//it pulls you towards itself and then knocks you away
bool pulled = z->type->special_attacks.at( "ranged_pull" )->call( *z );
if( pulled && one_in( 4 ) ) {
sounds::sound( z->pos(), 60, sounds::sound_t::alarm, _( "a deafening roar!" ), false, "shout",
"roar" );
sounds::sound( z->pos(), MAX_VIEW_DISTANCE, sounds::sound_t::alarm, _( "a deafening roar!" ), false,
"shout", "roar" );
}
return pulled;
}
Expand Down Expand Up @@ -5537,7 +5537,7 @@ bool mattack::doot( monster *z )

bool mattack::speaker( monster *z )
{
sounds::sound( z->pos(), 60, sounds::sound_t::order,
sounds::sound( z->pos(), MAX_VIEW_DISTANCE, sounds::sound_t::order,
SNIPPET.random_from_category( "speaker_warning" ).value_or( translation() ) );
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ tripoint npc::good_escape_direction( bool include_pos )
zone_type_id retreat_zone = zone_type_NPC_RETREAT;
const tripoint_abs_ms abs_pos = get_location();
const zone_manager &mgr = zone_manager::get_manager();
std::optional<tripoint_abs_ms> retreat_target = mgr.get_nearest( retreat_zone, abs_pos, 60,
fac_id );
std::optional<tripoint_abs_ms> retreat_target = mgr.get_nearest( retreat_zone, abs_pos,
MAX_VIEW_DISTANCE, fac_id );
// if there is a retreat zone in range, go there


Expand Down
2 changes: 1 addition & 1 deletion src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,7 @@ static void CheckMessages()

Character &player_character = get_player_character();
// Check if we're in a potential combat situation, if so, sort a few actions to the top.
if( !player_character.get_hostile_creatures( 60 ).empty() ) {
if( !player_character.get_hostile_creatures( MAX_VIEW_DISTANCE ).empty() ) {
// Only prioritize movement options if we're not driving.
if( !player_character.controlling_vehicle ) {
actions.insert( ACTION_CYCLE_MOVE );
Expand Down
10 changes: 6 additions & 4 deletions src/shadowcasting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "list.h"
#include "point.h"

// historically 8 bits is enough for rise and run, as a shadowcasting radius of 60
// readily fits within that space. larger shadowcasting volumes may require larger
// storage units; a radius of 120 definitely will not fit.
struct slope {
slope( int_least8_t rise, int_least8_t run ) {
// Ensure run is always positive for the inequality operators
Expand All @@ -21,8 +24,7 @@ struct slope {
}
}

// We don't need more that 8 bits since the shadowcasting area is not that large,
// currently the radius is 60.
// see above for commentary on types.
int_least8_t rise;
int_least8_t run;
};
Expand Down Expand Up @@ -166,7 +168,7 @@ void cast_horizontal_zlight_segment(
const tripoint &offset, const int offset_distance,
const T numerator )
{
const int radius = 60 - offset_distance;
const int radius = MAX_VIEW_DISTANCE - offset_distance;

constexpr int min_z = -OVERMAP_DEPTH;
constexpr int max_z = OVERMAP_HEIGHT;
Expand Down Expand Up @@ -362,7 +364,7 @@ void cast_vertical_zlight_segment(
const tripoint &offset, const int offset_distance,
const T numerator )
{
const int radius = 60 - offset_distance;
const int radius = MAX_VIEW_DISTANCE - offset_distance;

constexpr int min_z = -OVERMAP_DEPTH;
constexpr int max_z = OVERMAP_HEIGHT;
Expand Down
3 changes: 2 additions & 1 deletion src/timed_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ void timed_event::actualize()

// You could drop the flag, you know.
if( player_character.has_amount( itype_petrified_eye, 1 ) ) {
sounds::sound( player_character.pos(), 60, sounds::sound_t::alert, _( "a tortured scream!" ), false,
sounds::sound( player_character.pos(), MAX_VIEW_DISTANCE, sounds::sound_t::alert,
_( "a tortured scream!" ), false,
"shout",
"scream_tortured" );
if( !player_character.is_deaf() ) {
Expand Down
2 changes: 1 addition & 1 deletion src/trapfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ bool trapfunc::crossbow( const tripoint &p, Creature *c, item * )
bool trapfunc::shotgun( const tripoint &p, Creature *c, item * )
{
map &here = get_map();
sounds::sound( p, 60, sounds::sound_t::combat, _( "Kerblam!" ), false, "fire_gun",
sounds::sound( p, MAX_VIEW_DISTANCE, sounds::sound_t::combat, _( "Kerblam!" ), false, "fire_gun",
here.tr_at( p ) == tr_shotgun_1 ? "shotgun_s" : "shotgun_d" );
int shots = 1;
if( c != nullptr ) {
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ void vehicle::autopilot_patrol()
}
zone_manager &mgr = zone_manager::get_manager();
const auto &zone_src_set =
mgr.get_near( zone_type_VEHICLE_PATROL, global_square_location(), 60 );
mgr.get_near( zone_type_VEHICLE_PATROL, global_square_location(), MAX_VIEW_DISTANCE );
if( zone_src_set.empty() ) {
is_patrolling = false;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ void vehicle::smash_security_system()
void vehicle::autopilot_patrol_check()
{
zone_manager &mgr = zone_manager::get_manager();
if( mgr.has_near( zone_type_VEHICLE_PATROL, global_square_location(), 60 ) ) {
if( mgr.has_near( zone_type_VEHICLE_PATROL, global_square_location(), MAX_VIEW_DISTANCE ) ) {
enable_patrol();
} else {
g->zones_manager();
Expand Down
16 changes: 8 additions & 8 deletions tests/char_sight_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ TEST_CASE( "character_sight_limits", "[character][sight][vision]" )
here.build_map_cache( 0, false );
REQUIRE_FALSE( g->is_in_sunlight( dummy.pos() ) );

THEN( "sight limit is 60 tiles away" ) {
THEN( "sight limit is" << MAX_VIEW_DISTANCE << "tiles away" ) {
dummy.recalc_sight_limits();
CHECK( dummy.unimpaired_range() == 60 );
CHECK( dummy.unimpaired_range() == MAX_VIEW_DISTANCE );
}
}

Expand Down Expand Up @@ -219,10 +219,10 @@ TEST_CASE( "character_sight_limits", "[character][sight][vision]" )
dummy.wear_item( item( "glasses_eye" ) );
REQUIRE( dummy.worn_with_flag( flag_FIX_NEARSIGHT ) );

THEN( "unimpaired sight, with 60 tiles of range" ) {
THEN( "unimpaired sight, with " << MAX_VIEW_DISTANCE << " tiles of range" ) {
dummy.recalc_sight_limits();
CHECK_FALSE( dummy.sight_impaired() );
CHECK( dummy.unimpaired_range() == 60 );
CHECK( dummy.unimpaired_range() == MAX_VIEW_DISTANCE );
}
}
}
Expand Down Expand Up @@ -281,7 +281,7 @@ TEST_CASE( "ursine_vision", "[character][ursine][vision]" )
THEN( "unimpaired sight, with 7 tiles of range" ) {
dummy.recalc_sight_limits();
CHECK_FALSE( dummy.sight_impaired() );
CHECK( dummy.unimpaired_range() == 60 );
CHECK( dummy.unimpaired_range() == MAX_VIEW_DISTANCE );
CHECK( dummy.sight_range( light_here ) == 7 );
}
}
Expand All @@ -295,7 +295,7 @@ TEST_CASE( "ursine_vision", "[character][ursine][vision]" )
THEN( "unimpaired sight, with 8 tiles of range" ) {
dummy.recalc_sight_limits();
CHECK_FALSE( dummy.sight_impaired() );
CHECK( dummy.unimpaired_range() == 60 );
CHECK( dummy.unimpaired_range() == MAX_VIEW_DISTANCE );
CHECK( dummy.sight_range( light_here ) == 8 );
}
}
Expand All @@ -309,7 +309,7 @@ TEST_CASE( "ursine_vision", "[character][ursine][vision]" )
THEN( "unimpaired sight, with 27 tiles of range" ) {
dummy.recalc_sight_limits();
CHECK_FALSE( dummy.sight_impaired() );
CHECK( dummy.unimpaired_range() == 60 );
CHECK( dummy.unimpaired_range() == MAX_VIEW_DISTANCE );
CHECK( dummy.sight_range( light_here ) == 18 );
}
}
Expand All @@ -336,7 +336,7 @@ TEST_CASE( "ursine_vision", "[character][ursine][vision]" )
THEN( "unimpaired sight, with 87 tiles of range" ) {
dummy.recalc_sight_limits();
CHECK_FALSE( dummy.sight_impaired() );
CHECK( dummy.unimpaired_range() == 60 );
CHECK( dummy.unimpaired_range() == MAX_VIEW_DISTANCE );
CHECK( dummy.sight_range( light_here ) == 87 );
}
}
Expand Down

0 comments on commit fd5cee2

Please sign in to comment.