Skip to content

Commit

Permalink
Merge pull request #41362 from kevingranade/map-ref-mig-two
Browse files Browse the repository at this point in the history
Map reference migration part two
  • Loading branch information
ZhilkinSerg authored Jun 17, 2020
2 parents 28e7c1e + ace8231 commit 43eebbd
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 152 deletions.
11 changes: 6 additions & 5 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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() ) {
Expand Down Expand Up @@ -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' ) {
Expand Down
27 changes: 14 additions & 13 deletions src/advanced_inv_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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:
Expand All @@ -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<vpart_reference> vp = g->m.veh_at( pos ).part_with_feature( "CARGO",
if( const cata::optional<vpart_reference> vp = here.veh_at( pos ).part_with_feature( "CARGO",
false ) ) {
veh = &vp->vehicle();
vstor = vp->part_index();
Expand Down Expand Up @@ -124,23 +125,23 @@ void advanced_inv_area::init()
case AIM_NORTH:
case AIM_NORTHEAST: {
const cata::optional<vpart_reference> 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();
} else {
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;
Expand All @@ -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 ) {
Expand All @@ -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" ) );
}

Expand All @@ -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
Expand Down Expand Up @@ -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<size_t>( uistate.adv_inv_container_index ) ) {
Expand Down Expand Up @@ -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<vpart_reference> vp = g->m.veh_at( pos ).part_with_feature( "CARGO",
if( const cata::optional<vpart_reference> vp = get_map().veh_at( pos ).part_with_feature( "CARGO",
false ) ) {
veh = &vp->vehicle();
vstor = vp->part_index();
Expand Down
2 changes: 1 addition & 1 deletion src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ const player *avatar::get_book_reader( const item &book, std::vector<std::string
}

// Check for conditions that immediately disqualify the player from reading:
const optional_vpart_position vp = g->m.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;
Expand Down
36 changes: 19 additions & 17 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -882,46 +882,47 @@ 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;
} else {
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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 43eebbd

Please sign in to comment.