Skip to content

Commit

Permalink
Merge pull request #29182 from davidpwbrown/npc_reset_disposition
Browse files Browse the repository at this point in the history
Reset follower NPC disposition/faction on player death
  • Loading branch information
ZhilkinSerg authored Apr 1, 2019
2 parents db80b3b + 2f8890c commit 6e81f56
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -2683,6 +2684,31 @@ bool game::load_packs( const std::string &msg, const std::vector<mod_id> &packs,
return missing.empty();
}

void game::reset_npc_dispositions()
{
for( auto elem : follower_ids ) {
std::shared_ptr<npc> 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()
{
Expand Down
1 change: 1 addition & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
1 change: 1 addition & 0 deletions src/npctalk_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 6e81f56

Please sign in to comment.