Skip to content

Commit

Permalink
Merge pull request #77932 from Night-Pryanik/cutting-stealing
Browse files Browse the repository at this point in the history
Query the player on whether he really want to cut other people's stuff
  • Loading branch information
Maleclypse authored Nov 26, 2024
2 parents e2e9dc5 + 6544258 commit 7fb4cac
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 33 deletions.
17 changes: 1 addition & 16 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1832,22 +1832,7 @@ static bool query_consume_ownership( item &target, Character &p )
if( p.get_value( "THIEF_MODE" ) == "THIEF_HONEST" || !choice ) {
return false;
}
std::vector<npc *> witnesses;
for( npc &elem : g->all_npcs() ) {
if( rl_dist( elem.pos(), p.pos() ) < MAX_VIEW_DISTANCE && elem.sees( p.pos_bub() ) ) {
witnesses.push_back( &elem );
}
}
for( npc *elem : witnesses ) {
elem->say( "<witnessed_thievery>", 7 );
}
if( !witnesses.empty() && target.is_owned_by( p, true ) ) {
if( p.add_faction_warning( target.get_owner() ) ) {
for( npc *elem : witnesses ) {
elem->make_angry();
}
}
}
g->on_witness_theft( target );
}
return true;
}
Expand Down
18 changes: 1 addition & 17 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2659,23 +2659,7 @@ bool Character::disassemble( item_location target, bool interactive, bool disass
return false;
} else {
if( obj.get_owner() ) {
std::vector<npc *> witnesses;
for( npc &elem : g->all_npcs() ) {
if( rl_dist( elem.pos_bub(), player_character.pos_bub() ) < MAX_VIEW_DISTANCE &&
elem.get_faction() &&
obj.is_owned_by( elem ) && elem.sees( player_character.pos_bub() ) ) {
elem.say( "<witnessed_thievery>", 7 );
npc *npc_to_add = &elem;
witnesses.push_back( npc_to_add );
}
}
if( !witnesses.empty() ) {
if( player_character.add_faction_warning( obj.get_owner() ) ) {
for( npc *elem : witnesses ) {
elem->make_angry();
}
}
}
g->on_witness_theft( obj );
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,29 @@ void game::load_npcs()
npcs_dirty = false;
}

void game::on_witness_theft( const item &target )
{
Character &p = get_player_character();
std::vector<npc *> witnesses;
for( npc &elem : g->all_npcs() ) {
if( rl_dist( elem.pos(), p.pos() ) < MAX_VIEW_DISTANCE && elem.sees( p.pos_bub() ) &&
target.is_owned_by( elem ) ) {
witnesses.push_back( &elem );
}
}
for( npc *elem : witnesses ) {
elem->say( "<witnessed_thievery>", 7 );
}
if( !witnesses.empty() ) {
if( p.add_faction_warning( target.get_owner() ) ||
target.get_owner() == faction_id( "no_faction" ) ) {
for( npc *elem : witnesses ) {
elem->make_angry();
}
}
}
}

void game::unload_npcs()
{
for( const auto &npc : critter_tracker->active_npc ) {
Expand Down
4 changes: 4 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ class game
npc *find_npc_by_unique_id( const std::string &unique_id );
/** Makes any nearby NPCs on the overmap active. */
void load_npcs();

/** NPCs who saw player interacting with their stuff (disassembling, cutting etc)
* will notify the player that thievery was witnessed and make angry at the player. */
void on_witness_theft( const item &target );
private:
/** Unloads all NPCs.
*
Expand Down
12 changes: 12 additions & 0 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,18 @@ std::optional<int> salvage_actor::use( Character *p, item &cutter, const tripoin
return std::nullopt;
}

const item &to_cut = *item_loc;
if( !to_cut.is_owned_by( *p, true ) ) {
if( !query_yn( _( "Cutting the %s may anger the people who own it, continue?" ),
to_cut.tname() ) ) {
return false;
} else {
if( to_cut.get_owner() ) {
g->on_witness_theft( to_cut );
}
}
}

return salvage_actor::try_to_cut_up( *p, cutter, item_loc );
}

Expand Down

0 comments on commit 7fb4cac

Please sign in to comment.