Fixed segfault when an NPC completes a pickup after a player has alre… #55319
Annotations
9 warnings
suggester / JSON & C++:
src/npcmove.cpp#L3570
[[JSON & C++ formatters](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/doc/DEVELOPER_TOOLING.md)] reported by reviewdog 🐶
Raw Output:
src/npcmove.cpp:3570:- const tripoint abs_p = get_location().raw() - pos() + p;
src/npcmove.cpp:3571:- const int prev_num_items = ai_cache.searched_tiles.get( abs_p, -1 );
src/npcmove.cpp:3572:- // Prefetch the number of items present so we can bail out if we already checked here.
src/npcmove.cpp:3573:- map_stack m_stack = here.i_at( p );
src/npcmove.cpp:3574:- int num_items = m_stack.size();
src/npcmove.cpp:3575:- const optional_vpart_position vp = here.veh_at( p );
src/npcmove.cpp:3576:- if( vp ) {
src/npcmove.cpp:3577:- if( const std::optional<vpart_reference> vp_cargo = vp.cargo() ) {
src/npcmove.cpp:3578:- num_items += vp_cargo->items().size();
src/npcmove.cpp:3570:+ const tripoint abs_p = get_location().raw() - pos() + p;
src/npcmove.cpp:3571:+ const int prev_num_items = ai_cache.searched_tiles.get( abs_p, -1 );
src/npcmove.cpp:3572:+ // Prefetch the number of items present so we can bail out if we already checked here.
src/npcmove.cpp:3573:+ map_stack m_stack = here.i_at( p );
src/npcmove.cpp:3574:+ int num_items = m_stack.size();
src/npcmove.cpp:3575:+ const optional_vpart_position vp = here.veh_at( p );
src/npcmove.cpp:3576:+ if( vp ) {
src/npcmove.cpp:3577:+ if( const std::optional<vpart_reference> vp_cargo = vp.cargo() ) {
src/npcmove.cpp:3578:+ num_items += vp_cargo->items().size();
src/npcmove.cpp:3579:+ }
|
suggester / JSON & C++:
src/npcmove.cpp#L3580
[[JSON & C++ formatters](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/doc/DEVELOPER_TOOLING.md)] reported by reviewdog 🐶
Raw Output:
src/npcmove.cpp:3580:- }
src/npcmove.cpp:3581:- if( prev_num_items == num_items ) {
src/npcmove.cpp:3582:- continue;
src/npcmove.cpp:3583:- }
src/npcmove.cpp:3584:- auto cache_tile = [this, &abs_p, num_items]() {
src/npcmove.cpp:3585:- if( wanted_item.get_item() == nullptr ) {
src/npcmove.cpp:3586:- ai_cache.searched_tiles.insert( 1000, abs_p, num_items );
src/npcmove.cpp:3581:+ if( prev_num_items == num_items ) {
src/npcmove.cpp:3582:+ continue;
|
suggester / JSON & C++:
src/npcmove.cpp#L3629
[[JSON & C++ formatters](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/doc/DEVELOPER_TOOLING.md)] reported by reviewdog 🐶
Raw Output:
src/npcmove.cpp:3629:- if( wanted_item.get_item() != nullptr ) {
src/npcmove.cpp:3630:- wanted_name = wanted_item->tname();
src/npcmove.cpp:3631:- }
src/npcmove.cpp:3632:-
src/npcmove.cpp:3633:- if( wanted_name.empty() ) {
src/npcmove.cpp:3634:- return;
src/npcmove.cpp:3635:- }
src/npcmove.cpp:3633:+ if( wanted_name.empty() ) {
src/npcmove.cpp:3634:+ return;
src/npcmove.cpp:3635:+ }
|
suggester / JSON & C++:
src/npcmove.cpp#L3652
[[JSON & C++ formatters](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/doc/DEVELOPER_TOOLING.md)] reported by reviewdog 🐶
Raw Output:
src/npcmove.cpp:3652:- if( fetching_item && rl_dist( wanted_item_pos, pos() ) > 1 && is_walking_with() ) {
src/npcmove.cpp:3653:- say( _( "Hold on, I want to pick up that %s." ), wanted_name );
src/npcmove.cpp:3652:+ if( fetching_item && rl_dist( wanted_item_pos, pos() ) > 1 && is_walking_with() ) {
src/npcmove.cpp:3653:+ say( _( "Hold on, I want to pick up that %s." ), wanted_name );
src/npcmove.cpp:3654:+ }
|
suggester / JSON & C++:
src/npcmove.cpp#L3671
[[JSON & C++ formatters](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/doc/DEVELOPER_TOOLING.md)] reported by reviewdog 🐶
Raw Output:
src/npcmove.cpp:3671:- map &here = get_map();
src/npcmove.cpp:3672:- const std::optional<vpart_reference> vp = here.veh_at( wanted_item_pos ).part_with_feature(
src/npcmove.cpp:3673:- VPFLAG_CARGO, false );
src/npcmove.cpp:3674:- const bool has_cargo = vp && !vp->has_feature( "LOCKED" );
src/npcmove.cpp:3675:-
src/npcmove.cpp:3676:- if( ( !here.has_items( wanted_item_pos ) && !has_cargo &&
src/npcmove.cpp:3677:- !here.is_harvestable( wanted_item_pos ) && sees( wanted_item_pos ) ) ||
src/npcmove.cpp:3678:- ( is_player_ally() && g->check_zone( zone_type_NO_NPC_PICKUP, wanted_item_pos ) ) ) {
src/npcmove.cpp:3679:- // Items we wanted no longer exist and we can see it
src/npcmove.cpp:3680:- // Or player who is leading us doesn't want us to pick it up
src/npcmove.cpp:3681:- fetching_item = false;
src/npcmove.cpp:3682:- wanted_item = {};
src/npcmove.cpp:3683:- move_pause();
src/npcmove.cpp:3684:- add_msg_debug( debugmode::DF_NPC, "Canceling pickup - no items or new zone" );
src/npcmove.cpp:3685:- return;
src/npcmove.cpp:3686:- }
src/npcmove.cpp:3670:+ map &here = get_map();
src/npcmove.cpp:3671:+ const std::optional<vpart_reference> vp = here.veh_at( wanted_item_pos ).part_with_feature(
src/npcmove.cpp:3672:+ VPFLAG_CARGO, false );
src/npcmove.cpp:3673:+ const bool has_cargo = vp && !vp->has_feature( "LOCKED" );
|
suggester / JSON & C++:
src/npcmove.cpp#L3708
[[JSON & C++ formatters](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/doc/DEVELOPER_TOOLING.md)] reported by reviewdog 🐶
Raw Output:
src/npcmove.cpp:3708:- const int dist_to_pickup = rl_dist( pos(), wanted_item_pos );
src/npcmove.cpp:3709:- if( dist_to_pickup > 1 && !path.empty() ) {
src/npcmove.cpp:3710:- add_msg_debug( debugmode::DF_NPC, "Moving; [%d, %d, %d] => [%d, %d, %d]",
src/npcmove.cpp:3711:- posx(), posy(), posz(), path[0].x, path[0].y, path[0].z );
src/npcmove.cpp:3712:-
src/npcmove.cpp:3713:- move_to_next();
src/npcmove.cpp:3714:- return;
src/npcmove.cpp:3715:- } else if( dist_to_pickup > 1 && path.empty() ) {
src/npcmove.cpp:3716:- add_msg_debug( debugmode::DF_NPC, "Can't find path" );
src/npcmove.cpp:3717:- // This can happen, always do something
src/npcmove.cpp:3718:- fetching_item = false;
src/npcmove.cpp:3719:- wanted_item = {};
src/npcmove.cpp:3720:- move_pause();
src/npcmove.cpp:3721:- return;
src/npcmove.cpp:3722:- }
src/npcmove.cpp:3687:+ // Check: Is the item owned? Has the situation changed since we last moved? Am 'I' now
src/npcmove.cpp:3688:+ // standing in front of the shopkeeper/player that I am about to steal from?
src/npcmove.cpp:3689:+ if( wanted_item ) {
src/npcmove.cpp:3690:+ if( !::good_for_pickup( *wanted_item, *this, wanted_item_pos ) ) {
src/npcmove.cpp:3691:+ add_msg_debug( debugmode::DF_NPC_ITEMAI,
src/npcmove.cpp:3692:+ "%s canceling pickup - situation changed since they decided to take item", get_name() );
src/npcmove.cpp:3693:+ fetching_item = false;
src/npcmove.cpp:3694:+ wanted_item = {};
src/npcmove.cpp:3695:+ move_pause();
src/npcmove.cpp:3696:+ return;
src/npcmove.cpp:3697:+ }
src/npcmove.cpp:3698:+ }
|
suggester / JSON & C++:
src/npcmove.cpp#L3731
[[JSON & C++ formatters](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/doc/DEVELOPER_TOOLING.md)] reported by reviewdog 🐶
Raw Output:
src/npcmove.cpp:3731:- if( picked_up.empty() ) {
src/npcmove.cpp:3732:- // Last chance: plant harvest
src/npcmove.cpp:3733:- if( here.is_harvestable( wanted_item_pos ) ) {
src/npcmove.cpp:3734:- here.examine( *this, wanted_item_pos );
src/npcmove.cpp:3735:- // Note: we didn't actually pick up anything, just spawned items
src/npcmove.cpp:3736:- // but we want the item picker to find new items
src/npcmove.cpp:3712:+ move_to_next();
src/npcmove.cpp:3713:+ return;
src/npcmove.cpp:3714:+ } else if( dist_to_pickup > 1 && path.empty() ) {
src/npcmove.cpp:3715:+ add_msg_debug( debugmode::DF_NPC, "Can't find path" );
src/npcmove.cpp:3716:+ // This can happen, always do something
|
suggester / JSON & C++:
src/npcmove.cpp#L3741
[[JSON & C++ formatters](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/doc/DEVELOPER_TOOLING.md)] reported by reviewdog 🐶
Raw Output:
src/npcmove.cpp:3741:- }
src/npcmove.cpp:3742:- viewer &player_view = get_player_view();
src/npcmove.cpp:3743:- // Describe the pickup to the player
src/npcmove.cpp:3744:- bool u_see = player_view.sees( *this ) || player_view.sees( wanted_item_pos );
src/npcmove.cpp:3745:- if( u_see ) {
src/npcmove.cpp:3746:- if( picked_up.size() == 1 ) {
src/npcmove.cpp:3747:- add_msg( _( "%1$s picks up a %2$s." ), get_name(), picked_up.front().tname() );
src/npcmove.cpp:3748:- } else if( picked_up.size() == 2 ) {
src/npcmove.cpp:3749:- add_msg( _( "%1$s picks up a %2$s and a %3$s." ), get_name(), picked_up.front().tname(),
src/npcmove.cpp:3750:- picked_up.back().tname() );
src/npcmove.cpp:3751:- } else if( picked_up.size() > 2 ) {
src/npcmove.cpp:3752:- add_msg( _( "%s picks up several items." ), get_name() );
src/npcmove.cpp:3753:- } else {
src/npcmove.cpp:3754:- add_msg( _( "%s looks around nervously, as if searching for something." ), get_name() );
src/npcmove.cpp:3722:+
src/npcmove.cpp:3723:+ // We're adjacent to the item; grab it!
src/npcmove.cpp:3724:+
src/npcmove.cpp:3725:+ auto picked_up = pick_up_item_map( wanted_item_pos );
src/npcmove.cpp:3726:+ if( picked_up.empty() && has_cargo ) {
src/npcmove.cpp:3727:+ picked_up = pick_up_item_vehicle( vp->vehicle(), vp->part_index() );
|
suggester / JSON & C++:
src/npcmove.cpp#L3763
[[JSON & C++ formatters](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/doc/DEVELOPER_TOOLING.md)] reported by reviewdog 🐶
Raw Output:
src/npcmove.cpp:3763:- i_add( it );
src/npcmove.cpp:3764:- mod_moves( -get_speed() );
src/npcmove.cpp:3765:- }
|
Loading