diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index d2f2012e1576b..74201aca03a9a 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -245,7 +245,7 @@ void advanced_inventory::print_items( const advanced_inventory_pane &pane, bool } else if( pane.in_vehicle() ) { maxvolume = s.veh->max_volume( s.vstor ); } else { - maxvolume = g->m.max_volume( s.pos ); + maxvolume = get_map().max_volume( s.pos ); } formatted_head = string_format( "%3.1f %s %s/%s %s", convert_weight( s.weight ), @@ -817,6 +817,7 @@ bool advanced_inventory::move_all_items( bool nested_call ) do_return_entry(); } + map &here = get_map(); if( spane.get_area() == AIM_INVENTORY || spane.get_area() == AIM_WORN ) { drop_locations dropped; // keep a list of favorites separated, only drop non-fav first if they exist @@ -877,7 +878,7 @@ bool advanced_inventory::move_all_items( bool nested_call ) stack_begin = targets.begin(); stack_end = targets.end(); } else { - map_stack targets = g->m.i_at( sarea.pos ); + map_stack targets = here.i_at( sarea.pos ); stack_begin = targets.begin(); stack_end = targets.end(); } @@ -934,7 +935,7 @@ bool advanced_inventory::move_all_items( bool nested_call ) stack_begin = targets.begin(); stack_end = targets.end(); } else { - map_stack targets = g->m.i_at( sarea.pos ); + map_stack targets = here.i_at( sarea.pos ); stack_begin = targets.begin(); stack_end = targets.end(); } @@ -1107,7 +1108,7 @@ void advanced_inventory::change_square( const aim_location changeSquare, } else { // check item stacks in vehicle and map at said square auto sq = squares[changeSquare]; - auto map_stack = g->m.i_at( sq.pos ); + auto map_stack = get_map().i_at( sq.pos ); auto veh_stack = sq.veh->get_items( sq.vstor ); // auto switch to vehicle storage if vehicle items are there, or neither are there if( !veh_stack.empty() || map_stack.empty() ) { @@ -1843,7 +1844,7 @@ void advanced_inventory::draw_minimap() // get the center of the window tripoint pc = {getmaxx( minimap ) / 2, getmaxy( minimap ) / 2, 0}; // draw the 3x3 tiles centered around player - g->m.draw( minimap, g->u.pos() ); + get_map().draw( minimap, g->u.pos() ); for( auto s : sides ) { char sym = get_minimap_sym( s ); if( sym == '\0' ) { diff --git a/src/advanced_inv_area.cpp b/src/advanced_inv_area.cpp index 1f1610781242c..260b35a3e4edb 100644 --- a/src/advanced_inv_area.cpp +++ b/src/advanced_inv_area.cpp @@ -42,7 +42,7 @@ int advanced_inv_area::get_item_count() const } else if( id == AIM_DRAGGED ) { return can_store_in_vehicle() ? veh->get_items( vstor ).size() : 0; } else { - return g->m.i_at( pos ).size(); + return get_map().i_at( pos ).size(); } } @@ -67,6 +67,7 @@ void advanced_inv_area::init() volume = 0_ml; // must update in main function weight = 0_gram; + map &here = get_map(); switch( id ) { case AIM_INVENTORY: case AIM_WORN: @@ -82,7 +83,7 @@ void advanced_inv_area::init() off = g->u.grab_point; // Reset position because offset changed pos = g->u.pos() + off; - if( const cata::optional vp = g->m.veh_at( pos ).part_with_feature( "CARGO", + if( const cata::optional vp = here.veh_at( pos ).part_with_feature( "CARGO", false ) ) { veh = &vp->vehicle(); vstor = vp->part_index(); @@ -124,7 +125,7 @@ void advanced_inv_area::init() case AIM_NORTH: case AIM_NORTHEAST: { const cata::optional vp = - g->m.veh_at( pos ).part_with_feature( "CARGO", false ); + here.veh_at( pos ).part_with_feature( "CARGO", false ); if( vp ) { veh = &vp->vehicle(); vstor = vp->part_index(); @@ -132,15 +133,15 @@ void advanced_inv_area::init() veh = nullptr; vstor = -1; } - canputitemsloc = can_store_in_vehicle() || g->m.can_put_items_ter_furn( pos ); + canputitemsloc = can_store_in_vehicle() || here.can_put_items_ter_furn( pos ); max_size = MAX_ITEM_IN_SQUARE; if( can_store_in_vehicle() ) { std::string part_name = vp->info().name(); desc[1] = vp->get_label().value_or( part_name ); } // get graffiti or terrain name - desc[0] = g->m.has_graffiti_at( pos ) ? - g->m.graffiti_at( pos ) : g->m.name( pos ); + desc[0] = here.has_graffiti_at( pos ) ? + here.graffiti_at( pos ) : here.name( pos ); } default: break; @@ -149,7 +150,7 @@ void advanced_inv_area::init() /* assemble a list of interesting traits of the target square */ // fields? with a special case for fire bool danger_field = false; - const field &tmpfld = g->m.field_at( pos ); + const field &tmpfld = here.field_at( pos ); for( auto &fld : tmpfld ) { const field_entry &cur = fld.second; if( fld.first.obj().has_fire ) { @@ -165,13 +166,13 @@ void advanced_inv_area::init() } // trap? - const trap &tr = g->m.tr_at( pos ); + const trap &tr = here.tr_at( pos ); if( tr.can_see( pos, g->u ) && !tr.is_benign() ) { flags.append( _( " TRAP" ) ); } // water? - if( g->m.has_flag_ter( TFLAG_SHALLOW_WATER, pos ) || g->m.has_flag_ter( TFLAG_DEEP_WATER, pos ) ) { + if( here.has_flag_ter( TFLAG_SHALLOW_WATER, pos ) || here.has_flag_ter( TFLAG_DEEP_WATER, pos ) ) { flags.append( _( " WATER" ) ); } @@ -188,7 +189,7 @@ units::volume advanced_inv_area::free_volume( bool in_vehicle ) const if( id == AIM_INVENTORY || id == AIM_WORN ) { return g->u.free_space(); } - return in_vehicle ? veh->free_volume( vstor ) : g->m.free_volume( pos ); + return in_vehicle ? veh->free_volume( vstor ) : get_map().free_volume( pos ); } bool advanced_inv_area::is_same( const advanced_inv_area &other ) const @@ -281,13 +282,13 @@ item *advanced_inv_area::get_container( bool in_vehicle ) } } } else { - map &m = g->m; + map &here = get_map(); bool is_in_vehicle = veh && ( uistate.adv_inv_container_in_vehicle || ( can_store_in_vehicle() && in_vehicle ) ); const itemstack &stacks = is_in_vehicle ? i_stacked( veh->get_items( vstor ) ) : - i_stacked( m.i_at( pos ) ); + i_stacked( here.i_at( pos ) ); // check index first if( stacks.size() > static_cast( uistate.adv_inv_container_index ) ) { @@ -393,7 +394,7 @@ void advanced_inv_area::set_container_position() // update the absolute position pos = g->u.pos() + off; // update vehicle information - if( const cata::optional vp = g->m.veh_at( pos ).part_with_feature( "CARGO", + if( const cata::optional vp = get_map().veh_at( pos ).part_with_feature( "CARGO", false ) ) { veh = &vp->vehicle(); vstor = vp->part_index(); diff --git a/src/avatar.cpp b/src/avatar.cpp index e38b73552cfa0..ca499dc994a2b 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -281,7 +281,7 @@ const player *avatar::get_book_reader( const item &book, std::vectorm.veh_at( pos() ); + const optional_vpart_position vp = get_map().veh_at( pos() ); if( vp && vp->vehicle().player_in_control( *this ) ) { reasons.emplace_back( _( "It's a bad idea to read while driving!" ) ); return nullptr; diff --git a/src/avatar_action.cpp b/src/avatar_action.cpp index 68cd3ff60b4c2..91739cdb2679b 100644 --- a/src/avatar_action.cpp +++ b/src/avatar_action.cpp @@ -377,7 +377,7 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d ) add_msg( m_info, _( "%s to dive underwater." ), press_x( ACTION_MOVE_DOWN ) ); } - avatar_action::swim( g->m, g->u, dest_loc ); + avatar_action::swim( get_map(), g->u, dest_loc ); } g->on_move_effects(); @@ -882,21 +882,22 @@ void avatar_action::mend( avatar &you, item_location loc ) bool avatar_action::eat_here( avatar &you ) { + map &here = get_map(); if( ( you.has_active_mutation( trait_RUMINANT ) || you.has_active_mutation( trait_GRAZER ) ) && - ( g->m.ter( you.pos() ) == t_underbrush || g->m.ter( you.pos() ) == t_shrub ) ) { + ( here.ter( you.pos() ) == t_underbrush || here.ter( you.pos() ) == t_shrub ) ) { if( you.get_hunger() < 20 ) { - add_msg( _( "You're too full to eat the leaves from the %s." ), g->m.ter( you.pos() )->name() ); + add_msg( _( "You're too full to eat the leaves from the %s." ), here.ter( you.pos() )->name() ); return true; } else { - g->m.ter_set( you.pos(), t_grass ); + here.ter_set( you.pos(), t_grass ); add_msg( _( "You eat the underbrush." ) ); item food( "underbrush", calendar::turn, 1 ); you.assign_activity( player_activity( consume_activity_actor( food, false ) ) ); return true; } } - if( you.has_active_mutation( trait_GRAZER ) && ( g->m.ter( you.pos() ) == t_grass || - g->m.ter( you.pos() ) == t_grass_long || g->m.ter( you.pos() ) == t_grass_tall ) ) { + if( you.has_active_mutation( trait_GRAZER ) && ( here.ter( you.pos() ) == t_grass || + here.ter( you.pos() ) == t_grass_long || here.ter( you.pos() ) == t_grass_tall ) ) { if( you.get_hunger() < 8 ) { add_msg( _( "You're too full to graze." ) ); return true; @@ -904,24 +905,24 @@ bool avatar_action::eat_here( avatar &you ) add_msg( _( "You eat the grass." ) ); item food( item( "grass", calendar::turn, 1 ) ); you.assign_activity( player_activity( consume_activity_actor( food, false ) ) ); - if( g->m.ter( you.pos() ) == t_grass_tall ) { - g->m.ter_set( you.pos(), t_grass_long ); - } else if( g->m.ter( you.pos() ) == t_grass_long ) { - g->m.ter_set( you.pos(), t_grass ); + if( here.ter( you.pos() ) == t_grass_tall ) { + here.ter_set( you.pos(), t_grass_long ); + } else if( here.ter( you.pos() ) == t_grass_long ) { + here.ter_set( you.pos(), t_grass ); } else { - g->m.ter_set( you.pos(), t_dirt ); + here.ter_set( you.pos(), t_dirt ); } return true; } } if( you.has_active_mutation( trait_GRAZER ) ) { - if( g->m.ter( you.pos() ) == t_grass_golf ) { + if( here.ter( you.pos() ) == t_grass_golf ) { add_msg( _( "This grass is too short to graze." ) ); return true; - } else if( g->m.ter( you.pos() ) == t_grass_dead ) { + } else if( here.ter( you.pos() ) == t_grass_dead ) { add_msg( _( "This grass is dead and too mangled for you to graze." ) ); return true; - } else if( g->m.ter( you.pos() ) == t_grass_white ) { + } else if( here.ter( you.pos() ) == t_grass_white ) { add_msg( _( "This grass is tainted with paint and thus inedible." ) ); return true; } @@ -1050,12 +1051,13 @@ void avatar_action::plthrow( avatar &you, item_location loc, static void make_active( item_location loc ) { + map &here = get_map(); switch( loc.where() ) { case item_location::type::map: - g->m.make_active( loc ); + here.make_active( loc ); break; case item_location::type::vehicle: - g->m.veh_at( loc.position() )->vehicle().make_active( loc ); + here.veh_at( loc.position() )->vehicle().make_active( loc ); break; default: break; @@ -1066,7 +1068,7 @@ static void update_lum( item_location loc, bool add ) { switch( loc.where() ) { case item_location::type::map: - g->m.update_lum( loc, add ); + get_map().update_lum( loc, add ); break; default: break; diff --git a/src/ballistics.cpp b/src/ballistics.cpp index 343720428dc45..ea14c5aa3ff26 100644 --- a/src/ballistics.cpp +++ b/src/ballistics.cpp @@ -57,7 +57,7 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack ) } drop_item.visit_items( [&pt]( const item * it ) { - g->m.add_item_or_charges( pt, *it ); + get_map().add_item_or_charges( pt, *it ); return VisitResponse::NEXT; } ); @@ -125,17 +125,18 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack ) do_drop = !dropped_item.process( nullptr, attack.end_point, true ); } + map &here = get_map(); if( do_drop ) { - g->m.add_item_or_charges( attack.end_point, dropped_item ); + here.add_item_or_charges( attack.end_point, dropped_item ); } if( effects.count( "HEAVY_HIT" ) ) { - if( g->m.has_flag( flag_LIQUID, pt ) ) { + if( here.has_flag( flag_LIQUID, pt ) ) { sounds::sound( pt, 10, sounds::sound_t::combat, _( "splash!" ), false, "bullet_hit", "hit_water" ); } else { sounds::sound( pt, 8, sounds::sound_t::combat, _( "thud." ), false, "bullet_hit", "hit_wall" ); } - const trap &tr = g->m.tr_at( pt ); + const trap &tr = here.tr_at( pt ); if( tr.triggered_by_item( dropped_item ) ) { tr.trigger( pt, nullptr, &dropped_item ); } @@ -191,9 +192,10 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri double range = rl_dist( source, target_arg ); Creature *target_critter = g->critter_at( target_arg ); + map &here = get_map(); double target_size = target_critter != nullptr ? target_critter->ranged_target_size() : - g->m.ranged_target_size( target_arg ); + here.ranged_target_size( target_arg ); projectile_attack_aim aim = projectile_attack_roll( dispersion, range, target_size ); // TODO: move to-hit roll back in here @@ -224,7 +226,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri // If we were targetting a tile rather than a monster, don't overshoot // Unless the target was a wall, then we are aiming high enough to overshoot const bool no_overshoot = proj_effects.count( "NO_OVERSHOOT" ) || - ( g->critter_at( target_arg ) == nullptr && g->m.passable( target_arg ) ); + ( g->critter_at( target_arg ) == nullptr && here.passable( target_arg ) ); double extend_to_range = no_overshoot ? range : proj_arg.range; @@ -265,7 +267,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri trajectory = line_to( source, target ); } else { // Go around obstacles a little if we're on target. - trajectory = g->m.find_clear_path( source, target ); + trajectory = here.find_clear_path( source, target ); } add_msg( m_debug, "missed_by_tiles: %.2f; missed_by: %.2f; target (orig/hit): %d,%d,%d/%d,%d,%d", @@ -282,7 +284,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri static emit_id muzzle_smoke( "emit_smaller_smoke_plume" ); if( proj_effects.count( "MUZZLE_SMOKE" ) ) { - g->m.emit_field( trajectory.front(), muzzle_smoke ); + here.emit_field( trajectory.front(), muzzle_smoke ); } if( !no_overshoot && range < extend_to_range ) { @@ -309,8 +311,8 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri prev_point = tp; tp = trajectory[i]; - if( ( tp.z > prev_point.z && g->m.has_floor( tp ) ) || - ( tp.z < prev_point.z && g->m.has_floor( prev_point ) ) ) { + if( ( tp.z > prev_point.z && here.has_floor( tp ) ) || + ( tp.z < prev_point.z && here.has_floor( prev_point ) ) ) { // Currently strictly no shooting through floor // TODO: Bash the floor tp = prev_point; @@ -333,7 +335,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri } if( in_veh != nullptr ) { - const optional_vpart_position other = g->m.veh_at( tp ); + const optional_vpart_position other = here.veh_at( tp ); if( in_veh == veh_pointer_or_null( other ) && other->is_inside() ) { // Turret is on the roof and can't hit anything inside continue; @@ -373,7 +375,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri } if( critter != nullptr && cur_missed_by < 1.0 ) { - if( in_veh != nullptr && veh_pointer_or_null( g->m.veh_at( tp ) ) == in_veh && + if( in_veh != nullptr && veh_pointer_or_null( here.veh_at( tp ) ) == in_veh && critter->is_player() ) { // Turret either was aimed by the player (who is now ducking) and shoots from above // Or was just IFFing, giving lots of warnings and time to get out of the line of fire @@ -387,21 +389,21 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri const size_t bt_len = blood_trail_len( attack.dealt_dam.total_damage() ); if( bt_len > 0 ) { const tripoint &dest = move_along_line( tp, trajectory, bt_len ); - g->m.add_splatter_trail( critter->bloodType(), tp, dest ); + here.add_splatter_trail( critter->bloodType(), tp, dest ); } sfx::do_projectile_hit( *attack.hit_critter ); has_momentum = false; } else { attack.missed_by = aim.missed_by; } - } else if( in_veh != nullptr && veh_pointer_or_null( g->m.veh_at( tp ) ) == in_veh ) { + } else if( in_veh != nullptr && veh_pointer_or_null( here.veh_at( tp ) ) == in_veh ) { // Don't do anything, especially don't call map::shoot as this would damage the vehicle } else { - g->m.shoot( tp, proj, !no_item_damage && tp == target ); + here.shoot( tp, proj, !no_item_damage && tp == target ); has_momentum = proj.impact.total_damage() > 0; } - if( ( !has_momentum || !is_bullet ) && g->m.impassable( tp ) ) { + if( ( !has_momentum || !is_bullet ) && here.impassable( tp ) ) { // Don't let flamethrowers go through walls // TODO: Let them go through bars traj_len = i; @@ -416,7 +418,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri g->draw_bullet( tp, static_cast( traj_len-- ), trajectory, bullet ); } - if( g->m.impassable( tp ) ) { + if( here.impassable( tp ) ) { tp = prev_point; } @@ -437,7 +439,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri Creature *mon_ptr = g->get_creature_if( [&]( const Creature & z ) { // search for creatures in radius 4 around impact site if( rl_dist( z.pos(), tp ) <= 4 && - g->m.sees( z.pos(), tp, -1 ) ) { + here.sees( z.pos(), tp, -1 ) ) { // don't hit targets that have already been hit if( !z.has_effect( effect_bounced ) ) { return true; diff --git a/src/basecamp.cpp b/src/basecamp.cpp index f3600e8d82b77..02031287c8751 100644 --- a/src/basecamp.cpp +++ b/src/basecamp.cpp @@ -608,7 +608,7 @@ void basecamp::form_crafting_inventory( map &target_map ) const tripoint &dump_spot = get_dumping_spot(); const tripoint &origin = target_map.getlocal( dump_spot ); auto &mgr = zone_manager::get_manager(); - if( g->m.check_vehicle_zones( g->get_levz() ) ) { + if( get_map().check_vehicle_zones( g->get_levz() ) ) { mgr.cache_vzones(); } if( mgr.has_near( zone_type_CAMP_STORAGE, dump_spot, 60 ) ) { @@ -668,7 +668,7 @@ void basecamp::form_crafting_inventory() target_map.load( tripoint( omt_pos.x * 2, omt_pos.y * 2, omt_pos.z ), false ); form_crafting_inventory( target_map ); } else { - form_crafting_inventory( g->m ); + form_crafting_inventory( get_map() ); } } @@ -744,7 +744,7 @@ bool basecamp_action_components::choose_components() void basecamp_action_components::consume_components() { - map *target_map = &g->m; + map *target_map = &get_map(); if( base_.by_radio ) { map_ = std::make_unique(); map_->load( omt_to_sm_copy( base_.camp_omt_pos() ), false ); diff --git a/src/bionics.cpp b/src/bionics.cpp index 4df3762ea4c4a..a5947c1dbdebd 100644 --- a/src/bionics.cpp +++ b/src/bionics.cpp @@ -582,6 +582,7 @@ bool Character::activate_bionic( int b, bool eff_only, bool *close_bionics_ui ) }; item tmp_item; + map &here = get_map(); // On activation effects go here if( bio.info().has_flag( flag_BIO_GUN ) ) { add_msg_activate(); @@ -665,11 +666,11 @@ bool Character::activate_bionic( int b, bool eff_only, bool *close_bionics_ui ) //~Sound of a bionic sonic-resonator shaking the area sounds::sound( pos(), 30, sounds::sound_t::combat, _( "VRRRRMP!" ), false, "bionic", static_cast( bio_resonator ) ); - for( const tripoint &bashpoint : g->m.points_in_radius( pos(), 1 ) ) { - g->m.bash( bashpoint, 110 ); + for( const tripoint &bashpoint : here.points_in_radius( pos(), 1 ) ) { + here.bash( bashpoint, 110 ); // Multibash effect, so that doors &c will fall - g->m.bash( bashpoint, 110 ); - g->m.bash( bashpoint, 110 ); + here.bash( bashpoint, 110 ); + here.bash( bashpoint, 110 ); } mod_moves( -100 ); @@ -845,9 +846,9 @@ bool Character::activate_bionic( int b, bool eff_only, bool *close_bionics_ui ) add_msg_if_player( m_info, _( "You can now run faster, assisted by joint servomotors." ) ); } else if( bio.id == bio_lighter ) { const cata::optional pnt = choose_adjacent( _( "Start a fire where?" ) ); - if( pnt && g->m.is_flammable( *pnt ) ) { + if( pnt && here.is_flammable( *pnt ) ) { add_msg_activate(); - g->m.add_field( *pnt, fd_fire, 1 ); + here.add_field( *pnt, fd_fire, 1 ); mod_moves( -100 ); } else { refund_power(); @@ -892,7 +893,7 @@ bool Character::activate_bionic( int b, bool eff_only, bool *close_bionics_ui ) } else if( bio.id == bio_water_extractor ) { bool no_target = true; bool extracted = false; - for( item &it : g->m.i_at( pos() ) ) { + for( item &it : here.i_at( pos() ) ) { static const auto volume_per_water_charge = 500_ml; if( it.is_corpse() ) { const int avail = it.get_var( "remaining_water", it.volume() / volume_per_water_charge ); @@ -927,12 +928,12 @@ bool Character::activate_bionic( int b, bool eff_only, bool *close_bionics_ui ) // Don't "snowball" by affecting some items multiple times std::vector> affected; const units::mass weight_cap = weight_capacity(); - for( const tripoint &p : g->m.points_in_radius( pos(), 10 ) ) { - if( p == pos() || !g->m.has_items( p ) || g->m.has_flag( flag_SEALED, p ) ) { + for( const tripoint &p : here.points_in_radius( pos(), 10 ) ) { + if( p == pos() || !here.has_items( p ) || here.has_flag( flag_SEALED, p ) ) { continue; } - map_stack stack = g->m.i_at( p ); + map_stack stack = here.i_at( p ); for( auto it = stack.begin(); it != stack.end(); it++ ) { if( it->weight() < weight_cap && it->made_of_any( affected_materials ) ) { @@ -953,7 +954,7 @@ bool Character::activate_bionic( int b, bool eff_only, bool *close_bionics_ui ) dealt_projectile_attack dealt = projectile_attack( proj, pr.second, pos(), dispersion_sources{ 0 }, this ); - g->m.add_item_or_charges( dealt.end_point, pr.first ); + here.add_item_or_charges( dealt.end_point, pr.first ); } mod_moves( -100 ); @@ -967,7 +968,7 @@ bool Character::activate_bionic( int b, bool eff_only, bool *close_bionics_ui ) item fake_lockpick = item( itype_pseudo_bio_picklock ); int moves = to_moves( 4_seconds ); assign_activity( lockpick_activity_actor( moves, cata::nullopt, fake_lockpick, - g->m.getabs( *target ) ) ); + here.getabs( *target ) ) ); if( close_bionics_ui ) { *close_bionics_ui = true; } @@ -988,7 +989,7 @@ bool Character::activate_bionic( int b, bool eff_only, bool *close_bionics_ui ) add_msg_activate(); // Calculate local wind power int vehwindspeed = 0; - if( optional_vpart_position vp = g->m.veh_at( pos() ) ) { + if( optional_vpart_position vp = here.veh_at( pos() ) ) { // vehicle velocity in mph vehwindspeed = std::abs( vp->vehicle().velocity / 100 ); } @@ -1285,7 +1286,7 @@ bool Character::burn_fuel( int b, bool start ) return false; } else { if( current_fuel_stock > 0 ) { - + map &here = get_map(); if( is_metabolism_powered ) { const int kcal_consumed = fuel_energy; // 1kcal = 4187 J @@ -1300,7 +1301,7 @@ bool Character::burn_fuel( int b, bool start ) mod_power_level( units::from_kilojoule( fuel_energy ) * intensity * effective_efficiency ); } else if( fuel == fuel_type_wind ) { int vehwindspeed = 0; - const optional_vpart_position vp = g->m.veh_at( pos() ); + const optional_vpart_position vp = here.veh_at( pos() ); if( vp ) { // vehicle velocity in mph vehwindspeed = std::abs( vp->vehicle().velocity / 100 ); @@ -1331,7 +1332,7 @@ bool Character::burn_fuel( int b, bool start ) } heat_emission( b, fuel_energy ); - g->m.emit_field( pos(), bio.info().power_gen_emission ); + here.emit_field( pos(), bio.info().power_gen_emission ); } else { if( is_metabolism_powered ) { @@ -1367,6 +1368,7 @@ void Character::passive_power_gen( int b ) } const float effective_passive_efficiency = get_effective_efficiency( b, passive_fuel_efficiency ); const std::vector &fuel_available = get_fuel_available( bio.id ); + map &here = get_map(); for( const itype_id &fuel : fuel_available ) { const item &tmp_fuel = item( fuel ); @@ -1380,7 +1382,7 @@ void Character::passive_power_gen( int b ) mod_power_level( units::from_kilojoule( fuel_energy ) * modifier * effective_passive_efficiency ); } else if( fuel == fuel_type_wind ) { int vehwindspeed = 0; - const optional_vpart_position vp = g->m.veh_at( pos() ); + const optional_vpart_position vp = here.veh_at( pos() ); if( vp ) { // vehicle velocity in mph vehwindspeed = std::abs( vp->vehicle().velocity / 100 ); @@ -1394,7 +1396,7 @@ void Character::passive_power_gen( int b ) } heat_emission( b, fuel_energy ); - g->m.emit_field( pos(), bio.info().power_gen_emission ); + here.emit_field( pos(), bio.info().power_gen_emission ); } } @@ -1402,6 +1404,7 @@ void Character::passive_power_gen( int b ) itype_id Character::find_remote_fuel( bool look_only ) { itype_id remote_fuel; + map &here = get_map(); const std::vector cables = items_with( []( const item & it ) { return it.active && it.has_flag( flag_CABLE_SPOOL ); @@ -1411,7 +1414,7 @@ itype_id Character::find_remote_fuel( bool look_only ) const cata::optional target = cable->get_cable_target( this, pos() ); if( !target ) { - if( g->m.is_outside( pos() ) && !is_night( calendar::turn ) && + if( here.is_outside( pos() ) && !is_night( calendar::turn ) && cable->get_var( "state" ) == "solar_pack_link" ) { if( !look_only ) { set_value( "sunlight", "1" ); @@ -1438,7 +1441,7 @@ itype_id Character::find_remote_fuel( bool look_only ) } continue; } - const optional_vpart_position vp = g->m.veh_at( *target ); + const optional_vpart_position vp = here.veh_at( *target ); if( !vp ) { continue; } @@ -1459,10 +1462,11 @@ int Character::consume_remote_fuel( int amount ) return it.active && it.has_flag( flag_CABLE_SPOOL ); } ); + map &here = get_map(); for( const item *cable : cables ) { const cata::optional target = cable->get_cable_target( this, pos() ); if( target ) { - const optional_vpart_position vp = g->m.veh_at( *target ); + const optional_vpart_position vp = here.veh_at( *target ); if( !vp ) { continue; } @@ -1505,9 +1509,10 @@ void Character::heat_emission( int b, int fuel_energy ) const int heat_prod = fuel_energy * ( 1.0f - efficiency ); const int heat_level = std::min( heat_prod / 10, 4 ); const emit_id hotness = emit_id( "emit_hot_air" + to_string( heat_level ) + "_cbm" ); + map &here = get_map(); if( hotness.is_valid() ) { const int heat_spread = std::max( heat_prod / 10 - heat_level, 1 ); - g->m.emit_field( pos(), hotness, heat_spread ); + here.emit_field( pos(), hotness, heat_spread ); } for( const std::pair &bp : bio.info().occupied_bodyparts ) { add_effect( effect_heating_bionic, 2_seconds, bp.first->token, false, heat_prod ); @@ -2205,6 +2210,7 @@ bool Character::uninstall_bionic( const bionic_id &b_id, player &installer, bool void Character::perform_uninstall( const bionic_id &bid, int difficulty, int success, const units::energy &power_lvl, int pl_skill ) { + map &here = get_map(); if( success > 0 ) { g->events().send( getID(), bid ); @@ -2225,7 +2231,7 @@ void Character::perform_uninstall( const bionic_id &bid, int difficulty, int suc cbm.set_flag( flag_NO_STERILE ); cbm.set_flag( flag_NO_PACKED ); cbm.faults.emplace( fault_bionic_salvaged ); - g->m.add_item( pos(), cbm ); + here.add_item( pos(), cbm ); } else { g->events().send( getID(), bid ); // for chance_of_success calculation, shift skill down to a float between ~0.4 - 30 @@ -2235,7 +2241,7 @@ void Character::perform_uninstall( const bionic_id &bid, int difficulty, int suc bionics_uninstall_failure( difficulty, success, adjusted_skill ); } - g->m.invalidate_map_cache( g->get_levz() ); + here.invalidate_map_cache( g->get_levz() ); } bool Character::uninstall_bionic( const bionic &target_cbm, monster &installer, player &patient, @@ -2303,7 +2309,7 @@ bool Character::uninstall_bionic( const bionic &target_cbm, monster &installer, cbm.set_flag( flag_NO_STERILE ); cbm.set_flag( flag_NO_PACKED ); cbm.faults.emplace( fault_bionic_salvaged ); - g->m.add_item( patient.pos(), cbm ); + get_map().add_item( patient.pos(), cbm ); } else { bionics_uninstall_failure( installer, patient, difficulty, success, adjusted_skill ); } @@ -2381,9 +2387,10 @@ bool Character::can_install_bionics( const itype &type, Character &installer, bo float Character::env_surgery_bonus( int radius ) const { float bonus = 1.0; - for( const tripoint &cell : g->m.points_in_radius( pos(), radius ) ) { - if( g->m.furn( cell )->surgery_skill_multiplier ) { - bonus = std::max( bonus, *g->m.furn( cell )->surgery_skill_multiplier ); + map &here = get_map(); + for( const tripoint &cell : here.points_in_radius( pos(), radius ) ) { + if( here.furn( cell )->surgery_skill_multiplier ) { + bonus = std::max( bonus, *here.furn( cell )->surgery_skill_multiplier ); } } return bonus; @@ -2476,7 +2483,7 @@ void Character::perform_install( const bionic_id &bid, const bionic_id &upbid, i ( 10.0 ) ); bionics_install_failure( bid, installer_name, difficulty, success, adjusted_skill, patient_pos ); } - g->m.invalidate_map_cache( g->get_levz() ); + get_map().invalidate_map_cache( g->get_levz() ); } void Character::bionics_install_failure( const bionic_id &bid, const std::string &installer, @@ -2579,7 +2586,7 @@ void Character::bionics_install_failure( const bionic_id &bid, const std::string cbm.set_flag( flag_NO_STERILE ); cbm.set_flag( flag_NO_PACKED ); cbm.faults.emplace( fault_bionic_salvaged ); - g->m.add_item( patient_pos, cbm ); + get_map().add_item( patient_pos, cbm ); } } diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index a048eec961a2a..4e57e4ad51afa 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1011,8 +1011,9 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int get_window_tile_counts( width, height, s.x, s.y ); init_light(); - g->m.update_visibility_cache( center.z ); - const visibility_variables &cache = g->m.get_visibility_variables_cache(); + map &here = get_map(); + here.update_visibility_cache( center.z ); + const visibility_variables &cache = here.get_visibility_variables_cache(); const bool iso_mode = tile_iso; @@ -1034,7 +1035,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int const int max_visible_x = ( g->u.posx() % SEEX ) + ( MAPSIZE - 1 ) * SEEX; const int max_visible_y = ( g->u.posy() % SEEY ) + ( MAPSIZE - 1 ) * SEEY; - const auto &ch = g->m.access_cache( center.z ); + const auto &ch = here.access_cache( center.z ); //set up a default tile for the edges outside the render area visibility_type offscreen_type = visibility_type::DARK; @@ -1058,15 +1059,15 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } std::unordered_set collision_checkpoints; std::unordered_set target_points; - for( const wrapped_vehicle &elem : g->m.get_vehicles() ) { + for( const wrapped_vehicle &elem : here.get_vehicles() ) { if( elem.v->get_autodrive_target() != tripoint_zero ) { - target_points.insert( g->m.getlocal( elem.v->get_autodrive_target().xy() ) ); + target_points.insert( here.getlocal( elem.v->get_autodrive_target().xy() ) ); } if( elem.v->collision_check_points.empty() ) { continue; } else { for( const point &pt_elem : elem.v->collision_check_points ) { - collision_checkpoints.insert( g->m.getlocal( pt_elem ) ); + collision_checkpoints.insert( here.getlocal( pt_elem ) ); } } } @@ -1148,7 +1149,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int const auto rad_override = radiation_override.find( pos ); const bool rad_overridden = rad_override != radiation_override.end(); if( rad_overridden || !invisible[0] ) { - const int rad_value = rad_overridden ? rad_override->second : g->m.get_radiation( pos ); + const int rad_value = rad_overridden ? rad_override->second : here.get_radiation( pos ); catacurses::base_color col; if( rad_value > 0 ) { col = catacurses::green; @@ -1217,7 +1218,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } // note: lighting will be constrained in the [1.0, 11.0] range. - float ambient = g->m.ambient_light_at( {x, y, center.z} ); + float ambient = here.ambient_light_at( {x, y, center.z} ); float lighting = std::max( 1.0, LIGHT_AMBIENT_LIT - ambient + 1.0 ); auto tile_pos = player_to_screen( point( x, y ) ); @@ -1234,7 +1235,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } } - if( !invisible[0] && apply_vision_effects( pos, g->m.get_visibility( ll, cache ) ) ) { + if( !invisible[0] && apply_vision_effects( pos, here.get_visibility( ll, cache ) ) ) { const Creature *critter = g->critter_at( pos, true ); if( has_draw_override( pos ) || has_memory_at( pos ) || @@ -1249,7 +1250,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int const tripoint np = pos + neighborhood[i]; invisible[1 + i] = np.y < min_visible_y || np.y > max_visible_y || np.x < min_visible_x || np.x > max_visible_x || - would_apply_vision_effects( g->m.get_visibility( ch.visibility_cache[np.x][np.y], cache ) ); + would_apply_vision_effects( here.get_visibility( ch.visibility_cache[np.x][np.y], cache ) ); } int height_3d = 0; @@ -1336,7 +1337,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } const tripoint p( mem_x, mem_y, center.z ); lit_level lighting = ch.visibility_cache[p.x][p.y]; - if( apply_vision_effects( p, g->m.get_visibility( lighting, cache ) ) ) { + if( apply_vision_effects( p, here.get_visibility( lighting, cache ) ) ) { continue; } int height_3d = 0; @@ -1346,16 +1347,16 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int const tripoint np = p + neighborhood[i]; invisible[1 + i] = np.y < min_visible_y || np.y > max_visible_y || np.x < min_visible_x || np.x > max_visible_x || - would_apply_vision_effects( g->m.get_visibility( ch.visibility_cache[np.x][np.y], cache ) ); + would_apply_vision_effects( here.get_visibility( ch.visibility_cache[np.x][np.y], cache ) ); } //calling draw to memorize everything. //bypass cache check in case we learn something new about the terrain's connections draw_terrain( p, lighting, height_3d, invisible ); - if( g->m.check_seen_cache( p ) ) { + if( here.check_seen_cache( p ) ) { draw_furniture( p, lighting, height_3d, invisible ); draw_trap( p, lighting, height_3d, invisible ); draw_vpart( p, lighting, height_3d, invisible ); - g->m.check_and_set_seen_cache( p ); + here.check_and_set_seen_cache( p ); } } } @@ -1783,13 +1784,14 @@ bool cata_tiles::draw_from_id_string( std::string id, TILE_CATEGORY category, // seed the PRNG to get a reproducible random int // TODO: faster solution here unsigned int seed = 0; + map &here = get_map(); // TODO: determine ways other than category to differentiate more types of sprites switch( category ) { case C_TERRAIN: case C_FIELD: case C_LIGHTING: // stationary map tiles, seed based on map coordinates - seed = g->m.getabs( pos ).x + g->m.getabs( pos ).y * 65536; + seed = here.getabs( pos ).x + here.getabs( pos ).y * 65536; break; case C_VEHICLE_PART: // vehicle parts, seed based on coordinates within the vehicle @@ -1805,7 +1807,7 @@ bool cata_tiles::draw_from_id_string( std::string id, TILE_CATEGORY category, seed = mount.x + mount.y * 65536; } } else { - const optional_vpart_position vp = g->m.veh_at( pos ); + const optional_vpart_position vp = here.veh_at( pos ); if( vp ) { seed = vp->mount().x + vp->mount().y * 65536; } @@ -1826,7 +1828,7 @@ bool cata_tiles::draw_from_id_string( std::string id, TILE_CATEGORY category, if( fid.is_valid() ) { const furn_t &f = fid.obj(); if( !f.is_movable() ) { - seed = g->m.getabs( pos ).x + g->m.getabs( pos ).y * 65536; + seed = here.getabs( pos ).x + here.getabs( pos ).y * 65536; } } } @@ -2106,18 +2108,19 @@ bool cata_tiles::apply_vision_effects( const tripoint &pos, bool cata_tiles::draw_terrain_below( const tripoint &p, const lit_level, int &, const bool ( &invisible )[5] ) { + map &here = get_map(); const auto low_override = draw_below_override.find( p ); const bool low_overridden = low_override != draw_below_override.end(); if( low_overridden ? !low_override->second : ( invisible[0] || - !g->m.need_draw_lower_floor( p ) ) ) { + !here.need_draw_lower_floor( p ) ) ) { return false; } tripoint pbelow = tripoint( p.xy(), p.z - 1 ); SDL_Color tercol = curses_color_to_SDL( c_dark_gray ); - const ter_t &curr_ter = g->m.ter( pbelow ).obj(); - const furn_t &curr_furn = g->m.furn( pbelow ).obj(); + const ter_t &curr_ter = here.ter( pbelow ).obj(); + const furn_t &curr_furn = here.furn( pbelow ).obj(); int part_below; int sizefactor = 2; const vehicle *veh; @@ -2126,7 +2129,7 @@ bool cata_tiles::draw_terrain_below( const tripoint &p, const lit_level, int &, tercol = curses_color_to_SDL( curr_furn.color() ); } else if( curr_furn.movecost < 0 ) { tercol = curses_color_to_SDL( curr_furn.color() ); - } else if( ( veh = g->m.veh_at_internal( pbelow, part_below ) ) != nullptr ) { + } else if( ( veh = here.veh_at_internal( pbelow, part_below ) ) != nullptr ) { const int roof = veh->roof_at_part( part_below ); const auto vpobst = vpart_position( const_cast( *veh ), part_below ).obstacle_at_part(); tercol = curses_color_to_SDL( ( roof >= 0 || @@ -2175,6 +2178,7 @@ bool cata_tiles::draw_terrain_below( const tripoint &p, const lit_level, int &, bool cata_tiles::draw_terrain( const tripoint &p, const lit_level ll, int &height_3d, const bool ( &invisible )[5] ) { + map &here = get_map(); const auto override = terrain_override.find( p ); const bool overridden = override != terrain_override.end(); bool neighborhood_overridden = overridden; @@ -2187,7 +2191,7 @@ bool cata_tiles::draw_terrain( const tripoint &p, const lit_level ll, int &heigh } } // first memorize the actual terrain - const ter_id &t = g->m.ter( p ); + const ter_id &t = here.ter( p ); if( t && !invisible[0] ) { int subtile = 0; int rotation = 0; @@ -2195,14 +2199,14 @@ bool cata_tiles::draw_terrain( const tripoint &p, const lit_level ll, int &heigh if( t.obj().connects( connect_group ) ) { get_connect_values( p, subtile, rotation, connect_group, {} ); // re-memorize previously seen terrain in case new connections have been seen - g->m.set_memory_seen_cache_dirty( p ); + here.set_memory_seen_cache_dirty( p ); } else { get_terrain_orientation( p, rotation, subtile, {}, invisible ); // do something to get other terrain orientation values } const std::string &tname = t.id().str(); - if( g->m.check_seen_cache( p ) ) { - g->u.memorize_tile( g->m.getabs( p ), tname, subtile, rotation ); + if( here.check_seen_cache( p ) ) { + g->u.memorize_tile( here.getabs( p ), tname, subtile, rotation ); } // draw the actual terrain if there's no override if( !neighborhood_overridden ) { @@ -2244,7 +2248,7 @@ bool cata_tiles::draw_terrain( const tripoint &p, const lit_level ll, int &heigh bool cata_tiles::has_memory_at( const tripoint &p ) const { if( g->u.should_show_map_memory() ) { - const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) ); + const memorized_terrain_tile t = g->u.get_memorized_tile( get_map().getabs( p ) ); return !t.tile.empty(); } return false; @@ -2253,7 +2257,7 @@ bool cata_tiles::has_memory_at( const tripoint &p ) const bool cata_tiles::has_terrain_memory_at( const tripoint &p ) const { if( g->u.should_show_map_memory() ) { - const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) ); + const memorized_terrain_tile t = g->u.get_memorized_tile( get_map().getabs( p ) ); if( t.tile.substr( 0, 2 ) == "t_" ) { return true; } @@ -2264,7 +2268,7 @@ bool cata_tiles::has_terrain_memory_at( const tripoint &p ) const bool cata_tiles::has_furniture_memory_at( const tripoint &p ) const { if( g->u.should_show_map_memory() ) { - const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) ); + const memorized_terrain_tile t = g->u.get_memorized_tile( get_map().getabs( p ) ); if( t.tile.substr( 0, 2 ) == "f_" ) { return true; } @@ -2275,7 +2279,7 @@ bool cata_tiles::has_furniture_memory_at( const tripoint &p ) const bool cata_tiles::has_trap_memory_at( const tripoint &p ) const { if( g->u.should_show_map_memory() ) { - const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) ); + const memorized_terrain_tile t = g->u.get_memorized_tile( get_map().getabs( p ) ); if( t.tile.substr( 0, 3 ) == "tr_" ) { return true; } @@ -2286,7 +2290,7 @@ bool cata_tiles::has_trap_memory_at( const tripoint &p ) const bool cata_tiles::has_vpart_memory_at( const tripoint &p ) const { if( g->u.should_show_map_memory() ) { - const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) ); + const memorized_terrain_tile t = g->u.get_memorized_tile( get_map().getabs( p ) ); if( t.tile.substr( 0, 3 ) == "vp_" ) { return true; } @@ -2297,7 +2301,7 @@ bool cata_tiles::has_vpart_memory_at( const tripoint &p ) const memorized_terrain_tile cata_tiles::get_terrain_memory_at( const tripoint &p ) const { if( g->u.should_show_map_memory() ) { - const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) ); + const memorized_terrain_tile t = g->u.get_memorized_tile( get_map().getabs( p ) ); if( t.tile.substr( 0, 2 ) == "t_" ) { return t; } @@ -2308,7 +2312,7 @@ memorized_terrain_tile cata_tiles::get_terrain_memory_at( const tripoint &p ) co memorized_terrain_tile cata_tiles::get_furniture_memory_at( const tripoint &p ) const { if( g->u.should_show_map_memory() ) { - const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) ); + const memorized_terrain_tile t = g->u.get_memorized_tile( get_map().getabs( p ) ); if( t.tile.substr( 0, 2 ) == "f_" ) { return t; } @@ -2319,7 +2323,7 @@ memorized_terrain_tile cata_tiles::get_furniture_memory_at( const tripoint &p ) memorized_terrain_tile cata_tiles::get_trap_memory_at( const tripoint &p ) const { if( g->u.should_show_map_memory() ) { - const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) ); + const memorized_terrain_tile t = g->u.get_memorized_tile( get_map().getabs( p ) ); if( t.tile.substr( 0, 3 ) == "tr_" ) { return t; } @@ -2330,7 +2334,7 @@ memorized_terrain_tile cata_tiles::get_trap_memory_at( const tripoint &p ) const memorized_terrain_tile cata_tiles::get_vpart_memory_at( const tripoint &p ) const { if( g->u.should_show_map_memory() ) { - const memorized_terrain_tile t = g->u.get_memorized_tile( g->m.getabs( p ) ); + const memorized_terrain_tile t = g->u.get_memorized_tile( get_map().getabs( p ) ); if( t.tile.substr( 0, 3 ) == "vp_" ) { return t; } @@ -2352,21 +2356,22 @@ bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &hei } } } + map &here = get_map(); // first memorize the actual furniture - const furn_id &f = g->m.furn( p ); + const furn_id &f = here.furn( p ); if( f && !invisible[0] ) { const int neighborhood[4] = { - static_cast( g->m.furn( p + point_south ) ), - static_cast( g->m.furn( p + point_east ) ), - static_cast( g->m.furn( p + point_west ) ), - static_cast( g->m.furn( p + point_north ) ) + static_cast( here.furn( p + point_south ) ), + static_cast( here.furn( p + point_east ) ), + static_cast( here.furn( p + point_west ) ), + static_cast( here.furn( p + point_north ) ) }; int subtile = 0; int rotation = 0; get_tile_values( f.to_i(), neighborhood, subtile, rotation ); const std::string &fname = f.id().str(); - if( g->m.check_seen_cache( p ) ) { - g->u.memorize_tile( g->m.getabs( p ), fname, subtile, rotation ); + if( here.check_seen_cache( p ) ) { + g->u.memorize_tile( here.getabs( p ), fname, subtile, rotation ); } // draw the actual furniture if there's no override if( !neighborhood_overridden ) { @@ -2383,7 +2388,7 @@ bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &hei const auto furn = [&]( const tripoint & q, const bool invis ) -> furn_id { const auto it = furniture_override.find( q ); return it != furniture_override.end() ? it->second : - ( !overridden || !invis ) ? g->m.furn( q ) : f_null; + ( !overridden || !invis ) ? here.furn( q ) : f_null; }; const int neighborhood[4] = { static_cast( furn( p + point_south, invisible[1] ) ), @@ -2426,21 +2431,22 @@ bool cata_tiles::draw_trap( const tripoint &p, const lit_level ll, int &height_3 } } + map &here = get_map(); // first memorize the actual trap - const trap_id &tr = g->m.tr_at( p ).loadid; + const trap_id &tr = here.tr_at( p ).loadid; if( tr && !invisible[0] && tr.obj().can_see( p, g->u ) ) { const int neighborhood[4] = { - static_cast( g->m.tr_at( p + point_south ).loadid ), - static_cast( g->m.tr_at( p + point_east ).loadid ), - static_cast( g->m.tr_at( p + point_west ).loadid ), - static_cast( g->m.tr_at( p + point_north ).loadid ) + static_cast( here.tr_at( p + point_south ).loadid ), + static_cast( here.tr_at( p + point_east ).loadid ), + static_cast( here.tr_at( p + point_west ).loadid ), + static_cast( here.tr_at( p + point_north ).loadid ) }; int subtile = 0; int rotation = 0; get_tile_values( tr.to_i(), neighborhood, subtile, rotation ); const std::string trname = tr.id().str(); - if( g->m.check_seen_cache( p ) ) { - g->u.memorize_tile( g->m.getabs( p ), trname, subtile, rotation ); + if( here.check_seen_cache( p ) ) { + g->u.memorize_tile( here.getabs( p ), trname, subtile, rotation ); } // draw the actual trap if there's no override if( !neighborhood_overridden ) { @@ -2457,7 +2463,7 @@ bool cata_tiles::draw_trap( const tripoint &p, const lit_level ll, int &height_3 const auto tr_at = [&]( const tripoint & q, const bool invis ) -> trap_id { const auto it = trap_override.find( q ); return it != trap_override.end() ? it->second : - ( !overridden || !invis ) ? g->m.tr_at( q ).loadid : tr_null; + ( !overridden || !invis ) ? here.tr_at( q ).loadid : tr_null; }; const int neighborhood[4] = { static_cast( tr_at( p + point_south, invisible[1] ) ), @@ -2490,7 +2496,7 @@ bool cata_tiles::draw_graffiti( const tripoint &p, const lit_level ll, int &heig { const auto override = graffiti_override.find( p ); const bool overridden = override != graffiti_override.end(); - if( overridden ? !override->second : ( invisible[0] || !g->m.has_graffiti_at( p ) ) ) { + if( overridden ? !override->second : ( invisible[0] || !get_map().has_graffiti_at( p ) ) ) { return false; } const lit_level lit = overridden ? lit_level::LIT : ll; @@ -2502,8 +2508,9 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int { const auto fld_override = field_override.find( p ); const bool fld_overridden = fld_override != field_override.end(); + map &here = get_map(); const field_type_id &fld = fld_overridden ? - fld_override->second : g->m.field_at( p ).displayed_field_type(); + fld_override->second : here.field_at( p ).displayed_field_type(); bool ret_draw_field = false; bool ret_draw_items = false; if( ( fld_overridden || !invisible[0] ) && fld.obj().display_field ) { @@ -2513,7 +2520,7 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int auto field_at = [&]( const tripoint & q, const bool invis ) -> field_type_id { const auto it = field_override.find( q ); return it != field_override.end() ? it->second : - ( !fld_overridden || !invis ) ? g->m.field_at( q ).displayed_field_type() : fd_null; + ( !fld_overridden || !invis ) ? here.field_at( q ).displayed_field_type() : fd_null; }; // for rotation information const int neighborhood[4] = { @@ -2543,8 +2550,8 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int mon_id = std::get<1>( it_override->second ); hilite = std::get<2>( it_override->second ); it_type = item::find_type( it_id ); - } else if( !invisible[0] && g->m.sees_some_items( p, g->u ) ) { - const maptile &tile = g->m.maptile_at( p ); + } else if( !invisible[0] && here.sees_some_items( p, g->u ) ) { + const maptile &tile = here.maptile_at( p ); const item &itm = tile.get_uppermost_item(); const mtype *const mon = itm.get_mtype(); it_id = itm.typeId(); @@ -2577,7 +2584,7 @@ bool cata_tiles::draw_vpart_below( const tripoint &p, const lit_level /*ll*/, in const auto low_override = draw_below_override.find( p ); const bool low_overridden = low_override != draw_below_override.end(); if( low_overridden ? !low_override->second : ( invisible[0] || - !g->m.need_draw_lower_floor( p ) ) ) { + !get_map().need_draw_lower_floor( p ) ) ) { return false; } tripoint pbelow( p.xy(), p.z - 1 ); @@ -2592,8 +2599,9 @@ bool cata_tiles::draw_vpart( const tripoint &p, lit_level ll, int &height_3d, { const auto override = vpart_override.find( p ); const bool overridden = override != vpart_override.end(); + map &here = get_map(); // first memorize the actual vpart - const optional_vpart_position vp = g->m.veh_at( p ); + const optional_vpart_position vp = here.veh_at( p ); if( vp && !invisible[0] ) { const vehicle &veh = vp->vehicle(); const int veh_part = vp->part_index(); @@ -2605,8 +2613,8 @@ bool cata_tiles::draw_vpart( const tripoint &p, lit_level ll, int &height_3d, const int rotation = veh.face.dir(); const std::string vpname = "vp_" + vp_id.str(); if( !veh.forward_velocity() && !veh.player_in_control( g->u ) && - g->m.check_seen_cache( p ) ) { - g->u.memorize_tile( g->m.getabs( p ), vpname, subtile, rotation ); + here.check_seen_cache( p ) ) { + g->u.memorize_tile( here.getabs( p ), vpname, subtile, rotation ); } if( !overridden ) { const cata::optional cargopart = vp.part_with_feature( "CARGO", true ); @@ -2653,7 +2661,7 @@ bool cata_tiles::draw_critter_at_below( const tripoint &p, const lit_level, int const auto low_override = draw_below_override.find( p ); const bool low_overridden = low_override != draw_below_override.end(); if( low_overridden ? !low_override->second : ( invisible[0] || - !g->m.need_draw_lower_floor( p ) ) ) { + !get_map().need_draw_lower_floor( p ) ) ) { return false; } @@ -2824,7 +2832,7 @@ bool cata_tiles::draw_zone_mark( const tripoint &p, lit_level ll, int &height_3d } const zone_manager &mgr = zone_manager::get_manager(); - const tripoint &abs = g->m.getabs( p ); + const tripoint &abs = get_map().getabs( p ); const auto zone = mgr.get_bottom_zone( abs ); if( zone && zone->has_options() ) { @@ -2842,9 +2850,10 @@ bool cata_tiles::draw_zone_mark( const tripoint &p, lit_level ll, int &height_3d bool cata_tiles::draw_zombie_revival_indicators( const tripoint &pos, const lit_level /*ll*/, int &/*height_3d*/, const bool ( &invisible )[5] ) { + map &here = get_map(); if( tileset_ptr->find_tile_type( ZOMBIE_REVIVAL_INDICATOR ) && !invisible[0] && - item_override.find( pos ) == item_override.end() && g->m.could_see_items( pos, g->u ) ) { - for( auto &i : g->m.i_at( pos ) ) { + item_override.find( pos ) == item_override.end() && here.could_see_items( pos, g->u ) ) { + for( auto &i : here.i_at( pos ) ) { if( i.can_revive() ) { return draw_from_id_string( ZOMBIE_REVIVAL_INDICATOR, C_NONE, empty_string, pos, 0, 0, lit_level::LIT, false ); @@ -3363,11 +3372,12 @@ void cata_tiles::init_light() void cata_tiles::get_terrain_orientation( const tripoint &p, int &rota, int &subtile, const std::map &ter_override, const bool ( &invisible )[5] ) { + map &here = get_map(); const bool overridden = ter_override.find( p ) != ter_override.end(); const auto ter = [&]( const tripoint & q, const bool invis ) -> ter_id { const auto override = ter_override.find( q ); return override != ter_override.end() ? override->second : - ( !overridden || !invis ) ? g->m.ter( q ) : t_null; + ( !overridden || !invis ) ? here.ter( q ) : t_null; }; // get terrain at x,y @@ -3477,7 +3487,7 @@ void cata_tiles::get_rotation_and_subtile( const char val, int &rotation, int &s void cata_tiles::get_connect_values( const tripoint &p, int &subtile, int &rotation, const int connect_group, const std::map &ter_override ) { - uint8_t connections = g->m.get_known_connections( p, connect_group, ter_override ); + uint8_t connections = get_map().get_known_connections( p, connect_group, ter_override ); get_rotation_and_subtile( connections, rotation, subtile ); }