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

Global reference migration part 15 #41793

Merged
merged 1 commit into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
48 changes: 27 additions & 21 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ std::string enum_to_string<WS>( WS data )

aim_activity_actor::aim_activity_actor()
{
initial_view_offset = g->u.view_offset;
initial_view_offset = get_avatar().view_offset;
}

aim_activity_actor aim_activity_actor::use_wielded()
Expand Down Expand Up @@ -136,7 +136,7 @@ void aim_activity_actor::do_turn( player_activity &act, Character &who )
aborted = true;
return;
}
avatar &you = g->u;
avatar &you = get_avatar();

item *weapon = get_weapon();
if( !weapon || !avatar_action::can_fire_weapon( you, get_map(), *weapon ) ) {
Expand Down Expand Up @@ -241,10 +241,12 @@ std::unique_ptr<activity_actor> aim_activity_actor::deserialize( JsonIn &jsin )
item *aim_activity_actor::get_weapon()
{
switch( weapon_source ) {
case WeaponSource::Wielded:
case WeaponSource::Wielded: {
Character &player_character = get_player_character();
// Check for lost gun (e.g. yanked by zombie technician)
// TODO: check that this is the same gun that was used to start aiming
return g->u.weapon.is_null() ? nullptr : &g->u.weapon;
return player_character.weapon.is_null() ? nullptr : &player_character.weapon;
}
case WeaponSource::Bionic:
case WeaponSource::Mutation:
// TODO: check if the player lost relevant bionic/mutation
Expand All @@ -257,18 +259,19 @@ item *aim_activity_actor::get_weapon()

void aim_activity_actor::restore_view()
{
bool changed_z = g->u.view_offset.z != initial_view_offset.z;
g->u.view_offset = initial_view_offset;
avatar &player_character = get_avatar();
bool changed_z = player_character.view_offset.z != initial_view_offset.z;
player_character.view_offset = initial_view_offset;
if( changed_z ) {
get_map().invalidate_map_cache( g->u.view_offset.z );
get_map().invalidate_map_cache( player_character.view_offset.z );
g->invalidate_main_ui_adaptor();
}
}

bool aim_activity_actor::load_RAS_weapon()
{
// TODO: use activity for fetching ammo and loading weapon
player &you = g->u;
player &you = get_avatar();
item *weapon = get_weapon();
gun_mode gun = weapon->gun_current_mode();
const auto ammo_location_is_valid = [&]() -> bool {
Expand Down Expand Up @@ -313,7 +316,7 @@ bool aim_activity_actor::load_RAS_weapon()
void aim_activity_actor::unload_RAS_weapon()
{
// Unload reload-and-shoot weapons to avoid leaving bows pre-loaded with arrows
avatar &you = g->u;
avatar &you = get_avatar();
item *weapon = get_weapon();
if( !weapon ) {
return;
Expand Down Expand Up @@ -390,7 +393,7 @@ void dig_activity_actor::finish( player_activity &act, Character &who )
calendar::turn ) );
}

const int helpersize = g->u.get_num_crafting_helpers( 3 );
const int helpersize = get_avatar().get_num_crafting_helpers( 3 );
who.mod_stored_nutr( 5 - helpersize );
who.mod_thirst( 5 - helpersize );
who.mod_fatigue( 10 - ( helpersize * 2 ) );
Expand Down Expand Up @@ -460,7 +463,7 @@ void dig_channel_activity_actor::finish( player_activity &act, Character &who )
calendar::turn ) );
}

const int helpersize = g->u.get_num_crafting_helpers( 3 );
const int helpersize = get_avatar().get_num_crafting_helpers( 3 );
who.mod_stored_nutr( 5 - helpersize );
who.mod_thirst( 5 - helpersize );
who.mod_fatigue( 10 - ( helpersize * 2 ) );
Expand Down Expand Up @@ -1129,8 +1132,9 @@ std::unique_ptr<activity_actor> open_gate_activity_actor::deserialize( JsonIn &j
void consume_activity_actor::start( player_activity &act, Character &guy )
{
int moves;
Character &player_character = get_player_character();
if( consume_location ) {
const auto ret = g->u.will_eat( *consume_location, true );
const auto ret = player_character.will_eat( *consume_location, true );
if( !ret.success() ) {
consume_menu_selections = std::vector<int>();
return;
Expand All @@ -1139,7 +1143,7 @@ void consume_activity_actor::start( player_activity &act, Character &guy )
}
moves = to_moves<int>( guy.get_consume_time( *consume_location ) );
} else if( !consume_item.is_null() ) {
const auto ret = g->u.will_eat( consume_item, true );
const auto ret = player_character.will_eat( consume_item, true );
if( !ret.success() ) {
consume_menu_selections = std::vector<int>();
return;
Expand All @@ -1163,22 +1167,23 @@ void consume_activity_actor::finish( player_activity &act, Character & )
// too late; we've already consumed).
act.interruptable = false;

avatar &player_character = get_avatar();
if( consume_location ) {
g->u.consume( consume_location, force );
player_character.consume( consume_location, force );
} else if( !consume_item.is_null() ) {
g->u.consume( consume_item, force );
player_character.consume( consume_item, force );
} else {
debugmsg( "Item location/name to be consumed should not be null." );
}
if( g->u.get_value( "THIEF_MODE_KEEP" ) != "YES" ) {
g->u.set_value( "THIEF_MODE", "THIEF_ASK" );
if( player_character.get_value( "THIEF_MODE_KEEP" ) != "YES" ) {
player_character.set_value( "THIEF_MODE", "THIEF_ASK" );
}
//setting act to null clears these so back them up
std::vector<int> temp_selections = consume_menu_selections;
act.set_to_null();
if( !temp_selections.empty() ) {
g->u.assign_activity( ACT_EAT_MENU );
g->u.activity.values = temp_selections;
player_character.assign_activity( ACT_EAT_MENU );
player_character.activity.values = temp_selections;
}
}

Expand Down Expand Up @@ -1314,11 +1319,12 @@ void workout_activity_actor::start( player_activity &act, Character &who )
act.set_to_null();
return;
}
map &here = get_map();
// free training requires all limbs intact, but specialized workout machines
// train upper or lower parts of body only and may permit workout with
// broken limbs as long as they are not involved by the machine
bool hand_equipment = g->m.has_flag_furn( "WORKOUT_ARMS", location );
bool leg_equipment = g->m.has_flag_furn( "WORKOUT_LEGS", location );
bool hand_equipment = here.has_flag_furn( "WORKOUT_ARMS", location );
bool leg_equipment = here.has_flag_furn( "WORKOUT_LEGS", location );
static const bodypart_id arm_l = bodypart_id( "arm_l" );
static const bodypart_id arm_r = bodypart_id( "arm_r" );
static const bodypart_id leg_l = bodypart_id( "leg_l" );
Expand Down
43 changes: 24 additions & 19 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ void cata_cursesport::curses_drawwindow( const catacurses::window &w )
clear_window_area( w );
tilecontext->draw_minimap(
point( win->pos.x * fontwidth, win->pos.y * fontheight ),
tripoint( g->u.pos().xy(), g->ter_view_p.z ),
tripoint( get_player_character().pos().xy(), g->ter_view_p.z ),
win->width * font->fontwidth, win->height * font->fontheight );
update = true;

Expand Down Expand Up @@ -1854,7 +1854,8 @@ input_context touch_input_context;

std::string get_quick_shortcut_name( const std::string &category )
{
if( category == "DEFAULTMODE" && g->check_zone( zone_type_id( "NO_AUTO_PICKUP" ), g->u.pos() ) &&
if( category == "DEFAULTMODE" &&
g->check_zone( zone_type_id( "NO_AUTO_PICKUP" ), get_player_character().pos() ) &&
get_option<bool>( "ANDROID_SHORTCUT_ZONE" ) ) {
return "DEFAULTMODE____SHORTCUTS";
}
Expand Down Expand Up @@ -2112,10 +2113,11 @@ void remove_stale_inventory_quick_shortcuts()
valid = inv_chars.valid( key );
in_inventory = false;
if( valid ) {
in_inventory = g->u.inv.invlet_to_position( key ) != INT_MIN;
Character &player_character = get_player_character();
in_inventory = player_character.inv.invlet_to_position( key ) != INT_MIN;
if( !in_inventory ) {
// We couldn't find this item in the inventory, let's check worn items
for( const auto &item : g->u.worn ) {
for( const auto &item : player_character.worn ) {
if( item.invlet == key ) {
in_inventory = true;
break;
Expand All @@ -2124,7 +2126,7 @@ void remove_stale_inventory_quick_shortcuts()
}
if( !in_inventory ) {
// We couldn't find it in worn items either, check weapon held
if( g->u.weapon.invlet == key ) {
if( player_character.weapon.invlet == key ) {
in_inventory = true;
}
}
Expand Down Expand Up @@ -2244,11 +2246,13 @@ void draw_quick_shortcuts()
std::string hint_text;
if( show_hint ) {
if( touch_input_context.get_category() == "INVENTORY" && inv_chars.valid( key ) ) {
Character &player_character = get_player_character();
// Special case for inventory items - show the inventory item name as help text
hint_text = g->u.inv.find_item( g->u.inv.invlet_to_position( key ) ).display_name();
hint_text = player_character.inv.find_item( player_character.inv.invlet_to_position(
key ) ).display_name();
if( hint_text == "none" ) {
// We couldn't find this item in the inventory, let's check worn items
for( const auto &item : g->u.worn ) {
for( const auto &item : player_character.worn ) {
if( item.invlet == key ) {
hint_text = item.display_name();
break;
Expand All @@ -2257,8 +2261,8 @@ void draw_quick_shortcuts()
}
if( hint_text == "none" ) {
// We couldn't find it in worn items either, must be weapon held
if( g->u.weapon.invlet == key ) {
hint_text = g->u.weapon.display_name();
if( player_character.weapon.invlet == key ) {
hint_text = player_character.weapon.display_name();
}
}
} else {
Expand Down Expand Up @@ -2627,24 +2631,25 @@ static void CheckMessages()
// Actions to remove - we only want to remove things that we're 100% sure won't be useful to players otherwise
std::set<action_id> actions_remove;

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( !g->u.get_hostile_creatures( 60 ).empty() ) {
if( !player_character.get_hostile_creatures( 60 ).empty() ) {
// Only prioritize movement options if we're not driving.
if( !g->u.controlling_vehicle ) {
if( !player_character.controlling_vehicle ) {
actions.insert( ACTION_CYCLE_MOVE );
}
// Only prioritize fire weapon options if we're wielding a ranged weapon.
if( g->u.weapon.is_gun() || g->u.weapon.has_flag( "REACH_ATTACK" ) ) {
if( player_character.weapon.is_gun() || player_character.weapon.has_flag( "REACH_ATTACK" ) ) {
actions.insert( ACTION_FIRE );
}
}

// If we're already running, make it simple to toggle running to off.
if( g->u.is_running() ) {
if( player_character.is_running() ) {
actions.insert( ACTION_TOGGLE_RUN );
}
// If we're already crouching, make it simple to toggle crouching to off.
if( g->u.is_crouching() ) {
if( player_character.is_crouching() ) {
actions.insert( ACTION_TOGGLE_CROUCH );
}

Expand All @@ -2658,9 +2663,9 @@ static void CheckMessages()
// display that action at the top of the list.
for( int dx = -1; dx <= 1; dx++ ) {
for( int dy = -1; dy <= 1; dy++ ) {
int x = g->u.posx() + dx;
int y = g->u.posy() + dy;
int z = g->u.posz();
int x = player_character.posx() + dx;
int y = player_character.posy() + dy;
int z = player_character.posz();
const tripoint pos( x, y, z );

// Check if we're near a vehicle, if so, vehicle controls should be top.
Expand Down Expand Up @@ -2757,12 +2762,12 @@ static void CheckMessages()
}

// Check if we're significantly hungry or thirsty - if so, add eat
if( g->u.get_hunger() > 100 || g->u.get_thirst() > 40 ) {
if( player_character.get_hunger() > 100 || player_character.get_thirst() > 40 ) {
actions.insert( ACTION_EAT );
}

// Check if we're dead tired - if so, add sleep
if( g->u.get_fatigue() > fatigue_levels::DEAD_TIRED ) {
if( player_character.get_fatigue() > fatigue_levels::DEAD_TIRED ) {
actions.insert( ACTION_SLEEP );
}

Expand Down
16 changes: 9 additions & 7 deletions src/start_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ static void board_up( map &m, const tripoint_range &range )
continue;
}
// If the furniture is movable and the character can move it, use it to barricade
// g->u is workable here as NPCs by definition are not starting the game. (Let's hope.)
// is workable here as NPCs by definition are not starting the game. (Let's hope.)
///\EFFECT_STR determines what furniture might be used as a starting area barricade
if( m.furn( p ).obj().is_movable() && m.furn( p ).obj().move_str_req < g->u.get_str() ) {
if( m.furn( p ).obj().is_movable() &&
m.furn( p ).obj().move_str_req < get_player_character().get_str() ) {
if( m.furn( p ).obj().movecost == 0 ) {
// Obstacles are better, prefer them
furnitures1.push_back( p );
Expand Down Expand Up @@ -288,13 +289,13 @@ static int rate_location( map &m, const tripoint &p, const bool must_be_inside,
void start_location::place_player( player &u ) const
{
// Need the "real" map with it's inside/outside cache and the like.
map &m = g->m;
map &here = get_map();
// Start us off somewhere in the center of the map
u.setx( HALF_MAPSIZE_X );
u.sety( HALF_MAPSIZE_Y );
u.setz( g->get_levz() );
m.invalidate_map_cache( m.get_abs_sub().z );
m.build_map_cache( m.get_abs_sub().z );
here.invalidate_map_cache( here.get_abs_sub().z );
here.build_map_cache( here.get_abs_sub().z );
const bool must_be_inside = flags().count( "ALLOW_OUTSIDE" ) == 0;
///\EFFECT_STR allows player to start behind less-bashable furniture and terrain
// TODO: Allow using items here
Expand All @@ -315,7 +316,7 @@ void start_location::place_player( player &u ) const
int tries = 0;
const auto check_spot = [&]( const tripoint & pt ) {
tries++;
const int rate = rate_location( m, pt, must_be_inside, bash, tries, checked );
const int rate = rate_location( here, pt, must_be_inside, bash, tries, checked );
if( best_rate < rate ) {
best_rate = rate;
u.setpos( pt );
Expand Down Expand Up @@ -355,7 +356,8 @@ void start_location::burn( const tripoint &omtstart, const size_t count, const i
tinymap m;
m.load( player_location, false );
m.build_outside_cache( m.get_abs_sub().z );
const point u( g->u.posx() % HALF_MAPSIZE_X, g->u.posy() % HALF_MAPSIZE_Y );
point player_pos = get_player_character().pos().xy();
const point u( player_pos.x % HALF_MAPSIZE_X, player_pos.y % HALF_MAPSIZE_Y );
std::vector<tripoint> valid;
for( const tripoint &p : m.points_on_zlevel() ) {
if( !( m.has_flag_ter( "DOOR", p ) ||
Expand Down
2 changes: 1 addition & 1 deletion src/wish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void debug_menu::wishitem( player *p, const tripoint &pos )
}
p->invalidate_crafting_inventory();
} else if( pos.x >= 0 && pos.y >= 0 ) {
g->m.add_item_or_charges( pos, granted );
get_map().add_item_or_charges( pos, granted );
wmenu.ret = -1;
}
if( amount > 0 ) {
Expand Down
28 changes: 14 additions & 14 deletions tests/active_item_cache_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "calendar.h"
#include "catch/catch.hpp"
#include "game.h"
#include "game_constants.h"
#include "item.h"
#include "map.h"
Expand All @@ -13,14 +12,15 @@
TEST_CASE( "place_active_item_at_various_coordinates", "[item]" )
{
clear_map();
map &here = get_map();
for( int z = -OVERMAP_DEPTH; z < OVERMAP_HEIGHT; ++z ) {
for( int x = 0; x < MAPSIZE_X; ++x ) {
for( int y = 0; y < MAPSIZE_Y; ++y ) {
g->m.i_clear( { x, y, z } );
here.i_clear( { x, y, z } );
}
}
}
REQUIRE( g->m.get_submaps_with_active_items().empty() );
REQUIRE( here.get_submaps_with_active_items().empty() );
// An arbitrary active item.
item active( "firecracker_act", 0, item::default_charges_tag() );
active.activate();
Expand All @@ -29,20 +29,20 @@ TEST_CASE( "place_active_item_at_various_coordinates", "[item]" )
int z = 0;
for( int x = 0; x < MAPSIZE_X; ++x ) {
for( int y = 0; y < MAPSIZE_Y; ++y ) {
REQUIRE( g->m.i_at( { x, y, z } ).empty() );
REQUIRE( here.i_at( { x, y, z } ).empty() );
CAPTURE( x, y, z );
tripoint abs_loc = g->m.get_abs_sub() + tripoint( x / SEEX, y / SEEY, z );
tripoint abs_loc = here.get_abs_sub() + tripoint( x / SEEX, y / SEEY, z );
CAPTURE( abs_loc.x, abs_loc.y, abs_loc.z );
REQUIRE( g->m.get_submaps_with_active_items().empty() );
REQUIRE( g->m.get_submaps_with_active_items().find( abs_loc ) ==
g->m.get_submaps_with_active_items().end() );
item &item_ref = g->m.add_item( { x, y, z }, active );
REQUIRE( here.get_submaps_with_active_items().empty() );
REQUIRE( here.get_submaps_with_active_items().find( abs_loc ) ==
here.get_submaps_with_active_items().end() );
item &item_ref = here.add_item( { x, y, z }, active );
REQUIRE( item_ref.active );
REQUIRE_FALSE( g->m.get_submaps_with_active_items().empty() );
REQUIRE( g->m.get_submaps_with_active_items().find( abs_loc ) !=
g->m.get_submaps_with_active_items().end() );
REQUIRE_FALSE( g->m.i_at( { x, y, z } ).empty() );
g->m.i_clear( { x, y, z } );
REQUIRE_FALSE( here.get_submaps_with_active_items().empty() );
REQUIRE( here.get_submaps_with_active_items().find( abs_loc ) !=
here.get_submaps_with_active_items().end() );
REQUIRE_FALSE( here.i_at( { x, y, z } ).empty() );
here.i_clear( { x, y, z } );
}
}
}
Loading