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

Reset follower NPC disposition/faction on player death #29182

Merged
merged 1 commit into from Apr 1, 2019
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
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