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

Clear up item ownership for dead factions #38334

Merged
merged 3 commits into from Feb 26, 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
20 changes: 16 additions & 4 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ bool item::is_owned_by( const Character &c, bool available_to_take ) const
// owner.is_null() implies faction_id( "no_faction" ) which shouldnt happen, or no owner at all.
// either way, certain situations this means the thing is available to take.
// in other scenarios we actaully really want to check for id == id, even for no_faction
if( owner.is_null() ) {
if( get_owner().is_null() ) {
return available_to_take;
}
if( !c.get_faction() ) {
Expand All @@ -1048,7 +1048,7 @@ bool item::is_owned_by( const Character &c, bool available_to_take ) const

bool item::is_old_owner( const Character &c, bool available_to_take ) const
{
if( old_owner.is_null() ) {
if( get_old_owner().is_null() ) {
return available_to_take;
}
if( !c.get_faction() ) {
Expand All @@ -1060,11 +1060,11 @@ bool item::is_old_owner( const Character &c, bool available_to_take ) const

std::string item::get_owner_name() const
{
if( !g->faction_manager_ptr->get( owner ) ) {
if( !g->faction_manager_ptr->get( get_owner() ) ) {
debugmsg( "item::get_owner_name() item %s has no valid nor null faction id ", tname() );
return "no owner";
}
return g->faction_manager_ptr->get( owner )->name;
return g->faction_manager_ptr->get( get_owner() )->name;
}

void item::set_owner( const Character &c )
Expand All @@ -1078,14 +1078,26 @@ void item::set_owner( const Character &c )

faction_id item::get_owner() const
{
validate_ownership();
return owner;
}

faction_id item::get_old_owner() const
{
validate_ownership();
return old_owner;
}

void item::validate_ownership() const
{
if( !old_owner.is_null() && !g->faction_manager_ptr->get( old_owner, false ) ) {
remove_old_owner();
}
if( !owner.is_null() && !g->faction_manager_ptr->get( owner, false ) ) {
remove_owner();
}
}

static void insert_separation_line( std::vector<iteminfo> &info )
{
if( info.empty() || info.back().sName != "--" ) {
Expand Down
9 changes: 5 additions & 4 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1963,17 +1963,18 @@ class item : public visitable<item>
void set_birthday( const time_point &bday );
void handle_pickup_ownership( Character &c );
int get_gun_ups_drain() const;
void validate_ownership() const;
inline void set_old_owner( const faction_id &temp_owner ) {
old_owner = temp_owner;
}
inline void remove_old_owner() {
inline void remove_old_owner() const {
old_owner = faction_id::NULL_ID();
}
inline void set_owner( const faction_id &new_owner ) {
owner = new_owner;
}
void set_owner( const Character &c );
inline void remove_owner() {
inline void remove_owner() const {
owner = faction_id::NULL_ID();
}
faction_id get_owner() const;
Expand Down Expand Up @@ -2183,9 +2184,9 @@ class item : public visitable<item>
*/
phase_id current_phase = static_cast<phase_id>( 0 );
// The faction that owns this item.
faction_id owner = faction_id::NULL_ID();
mutable faction_id owner = faction_id::NULL_ID();
// The faction that previously owned this item
faction_id old_owner = faction_id::NULL_ID();
mutable faction_id old_owner = faction_id::NULL_ID();
int damage_ = 0;
light_emission light = nolight;

Expand Down