From f093d9415fc2c636b77ff5b241b0fdae4e0fc7f2 Mon Sep 17 00:00:00 2001 From: David Brown Date: Mon, 23 Sep 2019 12:27:13 +0200 Subject: [PATCH] more faction fixes - when telling an NPC to stop being a follower, form new faction properly --- src/faction.cpp | 4 ++-- src/npc.cpp | 5 ----- src/npc.h | 1 - src/npctalk_funcs.cpp | 10 +++++++++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/faction.cpp b/src/faction.cpp index 19606d9f11f7d..13c6e7586576d 100644 --- a/src/faction.cpp +++ b/src/faction.cpp @@ -378,10 +378,10 @@ faction *faction_manager::add_new_faction( const std::string &name_new, const fa fac.name = name_new; fac.id = id_new; factions[fac.id] = fac; + return &factions[fac.id]; } } - faction *ret = get( id_new ); - return ret ? ret : nullptr; + return nullptr; } faction *faction_manager::get( const faction_id &id, const bool complain ) diff --git a/src/npc.cpp b/src/npc.cpp index 89f4fb2a32b60..3099df8a7c704 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -464,11 +464,6 @@ faction *npc::get_faction() const return my_fac; } -void npc::clear_fac() -{ - my_fac = nullptr; - fac_id = string_id( "" ); -} // item id from group "_" or from fallback group // may still be a null item! static item random_item_from( const npc_class_id &type, const std::string &what, diff --git a/src/npc.h b/src/npc.h index 35a019fa49825..d5c3683ef25b2 100644 --- a/src/npc.h +++ b/src/npc.h @@ -744,7 +744,6 @@ class npc : public player void set_fac( const string_id &id ); faction *get_faction() const override; string_id get_fac_id() const; - void clear_fac(); /** * Set @ref submap_coords and @ref pos. * @param mx,my,mz are global submap coordinates. diff --git a/src/npctalk_funcs.cpp b/src/npctalk_funcs.cpp index a2ce02a1b03df..fdba2feb6c645 100644 --- a/src/npctalk_funcs.cpp +++ b/src/npctalk_funcs.cpp @@ -766,7 +766,15 @@ void talk_function::leave( npc &p ) { add_msg( _( "%s leaves." ), p.name ); g->remove_npc_follower( p.getID() ); - p.clear_fac(); + std::string new_fac_id = "solo_"; + new_fac_id += p.name; + // create a new "lone wolf" faction for this one NPC + faction *new_solo_fac = g->faction_manager_ptr->add_new_faction( p.name, + faction_id( new_fac_id ), faction_id( "no_faction" ) ); + p.set_fac( new_solo_fac ? new_solo_fac->id : faction_id( "no_faction" ) ); + if( new_solo_fac ) { + new_solo_fac->known_by_u = true; + } p.set_attitude( NPCATT_NULL ); }