From 2f8890c3b6fbd8e5d5380afb81590241b98cf5f2 Mon Sep 17 00:00:00 2001 From: davidpwbrown Date: Mon, 1 Apr 2019 01:03:34 +0100 Subject: [PATCH] reset NPCs on player death --- src/game.cpp | 28 +++++++++++++++++++++++++++- src/game.h | 1 + src/npctalk.cpp | 2 +- src/npctalk_funcs.cpp | 1 + 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 4aa1bc37deccb..39d5b985d8bf8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -918,10 +918,11 @@ bool game::cleanup_at_end() for( monster &critter : all_monsters() ) { despawn_monster( critter ); } + // Reset NPC factions and disposition + reset_npc_dispositions(); // Save the factions', missions and set the NPC's overmap coordinates // Npcs are saved in the overmap. save_factions_missions_npcs(); //missions need to be saved as they are global for all saves. - // save artifacts. save_artifacts(); @@ -2683,6 +2684,31 @@ bool game::load_packs( const std::string &msg, const std::vector &packs, return missing.empty(); } +void game::reset_npc_dispositions() +{ + for( auto elem : follower_ids ) { + std::shared_ptr npc_to_get = overmap_buffer.find_npc( elem ); + npc *npc_to_add = npc_to_get.get(); + npc_to_add->chatbin.missions.clear(); + npc_to_add->chatbin.missions_assigned.clear(); + npc_to_add->mission = NPC_MISSION_NULL; + npc_to_add->chatbin.mission_selected = nullptr; + npc_to_add->set_attitude( NPCATT_NULL ); + npc_to_add->op_of_u.anger = 0; + npc_to_add->op_of_u.fear = 0; + npc_to_add->op_of_u.trust = 0; + npc_to_add->op_of_u.value = 0; + npc_to_add->op_of_u.owed = 0; + npc_to_add->set_fac( faction_id( "wasteland_scavengers" ) ); + npc_to_add->add_new_mission( mission::reserve_random( ORIGIN_ANY_NPC, + npc_to_add->global_omt_location(), + npc_to_add->getID() ) ); + + } + follower_ids.clear(); + +} + //Saves all factions and missions and npcs. bool game::save_factions_missions_npcs() { diff --git a/src/game.h b/src/game.h index a50b533c53012..6e536cb389c6b 100644 --- a/src/game.h +++ b/src/game.h @@ -906,6 +906,7 @@ class game //private save functions. // returns false if saving failed for whatever reason bool save_factions_missions_npcs(); + void reset_npc_dispositions(); void serialize_master( std::ostream &fout ); // returns false if saving failed for whatever reason bool save_artifacts(); diff --git a/src/npctalk.cpp b/src/npctalk.cpp index 50c88f579da20..103bc8b4ebb20 100644 --- a/src/npctalk.cpp +++ b/src/npctalk.cpp @@ -2947,7 +2947,7 @@ void load_talk_topic( JsonObject &jo ) std::string npc::pick_talk_topic( const player &u ) { - //form_opinion(u); + form_opinion( u ); ( void )u; if( personality.aggression > 0 ) { if( op_of_u.fear * 2 < personality.bravery && personality.altruism < 0 ) { diff --git a/src/npctalk_funcs.cpp b/src/npctalk_funcs.cpp index 93c1c1421da10..e364ba0ac8a74 100644 --- a/src/npctalk_funcs.cpp +++ b/src/npctalk_funcs.cpp @@ -459,6 +459,7 @@ void talk_function::follow( npc &p ) { g->add_npc_follower( p.getID() ); p.set_attitude( NPCATT_FOLLOW ); + p.set_fac( faction_id( "your_followers" ) ); g->u.cash += p.cash; p.cash = 0; }