diff --git a/src/activity_actor.cpp b/src/activity_actor.cpp index a005dfa2e9c85..b48bfff63e87e 100644 --- a/src/activity_actor.cpp +++ b/src/activity_actor.cpp @@ -90,7 +90,7 @@ std::string enum_to_string( 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() @@ -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 ) ) { @@ -241,10 +241,12 @@ std::unique_ptr 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 @@ -257,10 +259,11 @@ 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(); } } @@ -268,7 +271,7 @@ void aim_activity_actor::restore_view() 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 { @@ -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; @@ -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 ) ); @@ -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 ) ); @@ -1129,8 +1132,9 @@ std::unique_ptr 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(); return; @@ -1139,7 +1143,7 @@ void consume_activity_actor::start( player_activity &act, Character &guy ) } moves = to_moves( 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(); return; @@ -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 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; } } @@ -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" ); diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 033ac1fe16bcb..646187eaa54e5 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -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; @@ -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( "ANDROID_SHORTCUT_ZONE" ) ) { return "DEFAULTMODE____SHORTCUTS"; } @@ -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; @@ -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; } } @@ -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; @@ -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 { @@ -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 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 ); } @@ -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. @@ -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 ); } diff --git a/src/start_location.cpp b/src/start_location.cpp index f4d7060f2c1be..aecd2da4ceccc 100644 --- a/src/start_location.cpp +++ b/src/start_location.cpp @@ -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 ); @@ -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 @@ -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 ); @@ -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 valid; for( const tripoint &p : m.points_on_zlevel() ) { if( !( m.has_flag_ter( "DOOR", p ) || diff --git a/src/wish.cpp b/src/wish.cpp index 1c8691355e6ad..6ffd27f56f673 100644 --- a/src/wish.cpp +++ b/src/wish.cpp @@ -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 ) { diff --git a/tests/active_item_cache_test.cpp b/tests/active_item_cache_test.cpp index 7b518b842b571..dcea4669b4912 100644 --- a/tests/active_item_cache_test.cpp +++ b/tests/active_item_cache_test.cpp @@ -3,7 +3,6 @@ #include "calendar.h" #include "catch/catch.hpp" -#include "game.h" #include "game_constants.h" #include "item.h" #include "map.h" @@ -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(); @@ -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 } ); } } } diff --git a/tests/memorial_test.cpp b/tests/memorial_test.cpp index 105451d3eb82d..0ce5628ed00e9 100644 --- a/tests/memorial_test.cpp +++ b/tests/memorial_test.cpp @@ -58,9 +58,10 @@ TEST_CASE( "memorials" ) event_bus &b = g->events(); - g->u.male = false; - character_id ch = g->u.getID(); - std::string u_name = g->u.name; + avatar &player_character = get_avatar(); + player_character.male = false; + character_id ch = player_character.getID(); + std::string u_name = player_character.name; character_id ch2 = character_id( ch.get_value() + 1 ); mutagen_technique mutagen = mutagen_technique::injected_purifier; mtype_id mon( "mon_zombie_kevlar_2" ); @@ -193,8 +194,8 @@ TEST_CASE( "memorials" ) std::chrono::seconds( 100 ) ); check_memorial( - m, b, u_name + " began their journey into the Cataclysm.", ch, u_name, g->u.male, - g->u.prof->ident(), g->u.custom_profession, "VERSION_STRING" ); + m, b, u_name + " began their journey into the Cataclysm.", ch, u_name, player_character.male, + player_character.prof->ident(), player_character.custom_profession, "VERSION_STRING" ); // Invokes achievement, so send another to clear the log for the test b.send( ch, cbm ); diff --git a/tests/player_helpers.cpp b/tests/player_helpers.cpp index df42e38bedb94..cba5ba4e15b89 100644 --- a/tests/player_helpers.cpp +++ b/tests/player_helpers.cpp @@ -26,7 +26,7 @@ int get_remaining_charges( const std::string &tool_id ) { - const inventory crafting_inv = g->u.crafting_inventory(); + const inventory crafting_inv = get_player_character().crafting_inventory(); std::vector items = crafting_inv.items_with( [tool_id]( const item & i ) { return i.typeId() == itype_id( tool_id ); @@ -40,7 +40,7 @@ int get_remaining_charges( const std::string &tool_id ) bool player_has_item_of_type( const std::string &type ) { - std::vector matching_items = g->u.inv.items_with( + std::vector matching_items = get_player_character().inv.items_with( [&]( const item & i ) { return i.type->get_id() == itype_id( type ); } ); @@ -113,7 +113,7 @@ void clear_character( player &dummy, bool debug_storage ) void clear_avatar() { - clear_character( g->u ); + clear_character( get_avatar() ); } void process_activity( player &dummy ) @@ -129,7 +129,7 @@ void process_activity( player &dummy ) npc &spawn_npc( const point &p, const std::string &npc_class ) { const string_id test_guy( npc_class ); - const character_id model_id = g->m.place_npc( p, test_guy, true ); + const character_id model_id = get_map().place_npc( p, test_guy, true ); g->load_npcs(); npc *guy = g->find_npc( model_id ); diff --git a/tests/vehicle_interact_test.cpp b/tests/vehicle_interact_test.cpp index 4caaaeb294134..93add711f3688 100644 --- a/tests/vehicle_interact_test.cpp +++ b/tests/vehicle_interact_test.cpp @@ -2,10 +2,9 @@ #include #include -#include "avatar.h" #include "calendar.h" #include "catch/catch.hpp" -#include "game.h" +#include "character.h" #include "inventory.h" #include "item.h" #include "map.h" @@ -23,15 +22,16 @@ static void test_repair( const std::vector &tools, bool expect_craftable ) clear_map(); const tripoint test_origin( 60, 60, 0 ); - g->u.setpos( test_origin ); + Character &player_character = get_player_character(); + player_character.setpos( test_origin ); const item backpack( "backpack" ); - g->u.wear( g->u.i_add( backpack ), false ); + player_character.wear_item( backpack ); for( const item &gear : tools ) { - g->u.i_add( gear ); + player_character.i_add( gear ); } const tripoint vehicle_origin = test_origin + tripoint_south_east; - vehicle *veh_ptr = g->m.add_vehicle( vproto_id( "bicycle" ), vehicle_origin, -90, 0, 0 ); + vehicle *veh_ptr = get_map().add_vehicle( vproto_id( "bicycle" ), vehicle_origin, -90, 0, 0 ); REQUIRE( veh_ptr != nullptr ); // Find the frame at the origin. vehicle_part *origin_frame = nullptr; @@ -51,10 +51,11 @@ static void test_repair( const std::vector &tools, bool expect_craftable ) requirement_data reqs = vp.repair_requirements(); // Bust cache on crafting_inventory() - g->u.mod_moves( 1 ); - inventory crafting_inv = g->u.crafting_inventory(); - bool can_repair = vp.repair_requirements().can_make_with_inventory( g->u.crafting_inventory(), - is_crafting_component ); + player_character.mod_moves( 1 ); + inventory crafting_inv = player_character.crafting_inventory(); + bool can_repair = vp.repair_requirements().can_make_with_inventory( + player_character.crafting_inventory(), + is_crafting_component ); CHECK( can_repair == expect_craftable ); }