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

Fix some problems of thievery #1582

Merged
merged 6 commits into from
Jun 21, 2022
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
38 changes: 28 additions & 10 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ static const mtype_id mon_zombie_crawler( "mon_zombie_crawler" );

static const std::string flag_RELOAD_AND_SHOOT( "RELOAD_AND_SHOOT" );

static const std::string has_thievery_witness( "has_thievery_witness" );

aim_activity_actor::aim_activity_actor()
{
initial_view_offset = get_avatar().view_offset;
Expand Down Expand Up @@ -779,14 +781,6 @@ void move_items_activity_actor::do_turn( player_activity &act, Character &who )
// Make a copy to be put in the destination location
item newit = leftovers;

// Handle charges, quantity == 0 means move all
if( quantity != 0 && newit.count_by_charges() ) {
newit.charges = std::min( newit.charges, quantity );
leftovers.charges -= quantity;
} else {
leftovers.charges = 0;
}

// Check that we can pick it up.
if( !newit.made_of( LIQUID ) ) {
// This is for hauling across zlevels, remove when going up and down stairs
Expand All @@ -796,6 +790,13 @@ void move_items_activity_actor::do_turn( player_activity &act, Character &who )
} else {
continue;
}
// Handle charges, quantity == 0 means move all
if( quantity != 0 && newit.count_by_charges() ) {
newit.charges = std::min( newit.charges, quantity );
leftovers.charges -= quantity;
} else {
leftovers.charges = 0;
}
const tripoint src = target.position();
const int distance = src.z == dest.z ? std::max( rl_dist( src, dest ), 1 ) : 1;
who.mod_moves( -pickup::cost_to_move_item( who, newit ) * distance );
Expand Down Expand Up @@ -843,7 +844,7 @@ std::unique_ptr<activity_actor> move_items_activity_actor::deserialize( JsonIn &
return actor.clone();
}

void pickup_activity_actor::do_turn( player_activity &, Character &who )
void pickup_activity_actor::do_turn( player_activity &act, Character &who )
{
// If we don't have target items bail out
if( target_items.empty() ) {
Expand All @@ -865,9 +866,20 @@ void pickup_activity_actor::do_turn( player_activity &, Character &who )
// False indicates that the player canceled pickup when met with some prompt
const bool keep_going = pickup::do_pickup( target_items, autopickup );

// Check thievey witness
npc *witness = nullptr;
if( !act.str_values.empty() && act.str_values[0] == has_thievery_witness ) {
for( npc &guy : g->all_npcs() ) {
if( guy.get_attitude() == NPCATT_RECOVER_GOODS ) {
witness = &guy;
break;
}
}
}

// If there are items left we ran out of moves, so continue the activity
// Otherwise, we are done.
if( !keep_going || target_items.empty() ) {
if( !keep_going || target_items.empty() || witness ) {
who.cancel_activity();

if( who.get_value( "THIEF_MODE_KEEP" ) != "YES" ) {
Expand All @@ -880,6 +892,12 @@ void pickup_activity_actor::do_turn( player_activity &, Character &who )
// TODO: Move this to advanced inventory instead of hacking it in here
cancel_aim_processing();
}

if( witness ) {
witness->talk_to_u();
// Then remove "has_thievery_witness" from the activity
act.str_values.clear();
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2261,13 +2261,21 @@ void activity_on_turn_move_loot( player_activity &act, player &p )
src_veh = &vp->vehicle();
src_part = vp->part_index();
for( auto &it : src_veh->get_items( src_part ) ) {
if( !it.is_owned_by( p, true ) ) {
continue;
}
it.set_owner( p );
items.push_back( std::make_pair( &it, true ) );
}
} else {
src_veh = nullptr;
src_part = -1;
}
for( auto &it : g->m.i_at( src_loc ) ) {
if( !it.is_owned_by( p, true ) ) {
continue;
}
it.set_owner( p );
items.push_back( std::make_pair( &it, false ) );
}

Expand Down
20 changes: 12 additions & 8 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ static const std::string flag_WATER_EXTINGUISH( "WATER_EXTINGUISH" );
static const std::string flag_WET( "WET" );
static const std::string flag_WIND_EXTINGUISH( "WIND_EXTINGUISH" );

static const std::string has_thievery_witness( "has_thievery_witness" );
static const activity_id ACT_PICKUP( "ACT_PICKUP" );

static const matec_id rapid_strike( "RAPID" );

class npc_class;
Expand Down Expand Up @@ -4281,16 +4284,17 @@ void item::handle_pickup_ownership( Character &c )
}
if( !witnesses.empty() ) {
set_old_owner( get_owner() );
bool guard_chosen = false;
for( npc *elem : witnesses ) {
if( elem->myclass == npc_class_id( "NC_BOUNTY_HUNTER" ) ) {
guard_chosen = true;
elem->witness_thievery( &*this );
break;
// Make sure there is only one witness
for( npc &guy : g->all_npcs() ) {
if( guy.get_attitude() == NPCATT_RECOVER_GOODS ) {
guy.set_attitude( NPCATT_NULL );
}
}
if( !guard_chosen ) {
random_entry( witnesses )->witness_thievery( &*this );
random_entry( witnesses )->set_attitude( NPCATT_RECOVER_GOODS );
// Notify the activity that we got a witness
if( c.activity && !c.activity.is_null() && c.activity.id() == ACT_PICKUP ) {
c.activity.str_values.clear();
c.activity.str_values.emplace_back( has_thievery_witness );
}
}
set_owner( c );
Expand Down
3 changes: 0 additions & 3 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,6 @@ class npc : public player
void handle_sound( sounds::sound_t priority, const std::string &description,
int heard_volume, const tripoint &spos );

void witness_thievery( item *it );

/* shift() works much like monster::shift(), and is called when the player moves
* from one submap to an adjacent submap. It updates our position (shifting by
* 12 tiles), as well as our plans.
Expand Down Expand Up @@ -1305,7 +1303,6 @@ class npc : public player
tripoint_abs_omt goal;
tripoint wander_pos = tripoint_min;
int wander_time = 0;
item *known_stolen_item = nullptr; // the item that the NPC wants the player to drop or barter for.
/**
* Location and index of the corpse we'd like to pulp (if any).
*/
Expand Down
20 changes: 1 addition & 19 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,14 +656,6 @@ void npc::regen_ai_cache()
auto i = std::begin( ai_cache.sound_alerts );
while( i != std::end( ai_cache.sound_alerts ) ) {
if( sees( here.getlocal( i->abs_pos ) ) ) {
// if they were responding to a call for guards because of thievery
npc *const sound_source = g->critter_at<npc>( here.getlocal( i->abs_pos ) );
if( sound_source ) {
if( my_fac == sound_source->my_fac && sound_source->known_stolen_item ) {
sound_source->known_stolen_item = nullptr;
set_attitude( NPCATT_RECOVER_GOODS );
}
}
i = ai_cache.sound_alerts.erase( i );
if( ai_cache.sound_alerts.size() == 1 ) {
path.clear();
Expand Down Expand Up @@ -1308,16 +1300,6 @@ void npc::execute_action( npc_action action )
}
}

void npc::witness_thievery( item *it )
{
known_stolen_item = it;
// Shopkeep is behind glass
if( myclass == npc_class_id( "NC_EVAC_SHOPKEEP" ) ) {
return;
}
set_attitude( NPCATT_RECOVER_GOODS );
}

npc_action npc::method_of_fleeing()
{
if( in_vehicle ) {
Expand Down Expand Up @@ -1941,7 +1923,7 @@ npc_action npc::address_needs( float danger )
npc_action npc::address_player()
{
Character &player_character = get_player_character();
if( ( attitude == NPCATT_TALK || attitude == NPCATT_RECOVER_GOODS ) && sees( player_character ) ) {
if( ( attitude == NPCATT_TALK ) && sees( player_character ) ) {
if( player_character.in_sleep_state() ) {
// Leave sleeping characters alone.
return npc_undecided;
Expand Down
6 changes: 0 additions & 6 deletions src/npctalk_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,6 @@ void talk_function::drop_stolen_item( npc &p )
g->m.add_item_or_charges( g->u.pos(), to_drop );
}
}
if( p.known_stolen_item ) {
p.known_stolen_item = nullptr;
}
if( g->u.is_hauling() ) {
g->u.stop_hauling();
}
Expand All @@ -848,9 +845,6 @@ void talk_function::drop_stolen_item( npc &p )

void talk_function::remove_stolen_status( npc &p )
{
if( p.known_stolen_item ) {
p.known_stolen_item = nullptr;
}
p.set_attitude( NPCATT_NULL );
}

Expand Down