Skip to content

Commit

Permalink
Merge pull request #34997 from mlangsdorf/npc_follow_close_again
Browse files Browse the repository at this point in the history
npcs: re-enable the follow close command
  • Loading branch information
ZhilkinSerg authored Oct 25, 2019
2 parents 2351bee + 777f4c0 commit 5ad16b6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
4 changes: 2 additions & 2 deletions data/json/npcs/TALK_COMMON_ALLY.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@
{
"truefalsetext": {
"condition": { "npc_rule": "follow_distance_2" },
"true": "<ally_rule_follow_distance_2_true_text>",
"false": "<ally_rule_follow_distance_2_false_text>"
"false": "<ally_rule_follow_distance_2_true_text>",
"true": "<ally_rule_follow_distance_2_false_text>"
},
"topic": "TALK_COMBAT_COMMANDS",
"effect": { "toggle_npc_rule": "follow_distance_2" }
Expand Down
7 changes: 6 additions & 1 deletion src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void npc::assess_danger()
{
float assessment = 0.0f;
float highest_priority = 1.0f;
int def_radius = 6;
int def_radius = rules.has_flag( ally_rule::follow_close ) ? follow_distance() : 6;

// Radius we can attack without moving
const int max_range = std::max( weapon.reach_range( *this ),
Expand Down Expand Up @@ -800,6 +800,11 @@ void npc::move()
}
}

if( action == npc_undecided && is_walking_with() && rules.has_flag( ally_rule::follow_close ) &&
rl_dist( pos(), g->u.pos() ) > follow_distance() ) {
action = npc_follow_player;
}

if( action == npc_undecided && attitude == NPCATT_ACTIVITY ) {
std::vector<tripoint> activity_route = get_auto_move_route();
if( !activity_route.empty() && !has_destination_activity() ) {
Expand Down
36 changes: 21 additions & 15 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,23 +1246,29 @@ void npc_follower_rules::deserialize( JsonIn &jsin )

// This and the following two entries are for legacy save game handling.
// "avoid_combat" was renamed "follow_close" to better reflect behavior.
data.read( "rule_avoid_combat", tmpflag );
if( tmpflag ) {
set_flag( ally_rule::follow_close );
} else {
clear_flag( ally_rule::follow_close );
if( data.has_member( "rule_avoid_combat" ) ) {
data.read( "rule_avoid_combat", tmpflag );
if( tmpflag ) {
set_flag( ally_rule::follow_close );
} else {
clear_flag( ally_rule::follow_close );
}
}
data.read( "override_enable_avoid_combat", tmpflag );
if( tmpflag ) {
enable_override( ally_rule::follow_close );
} else {
disable_override( ally_rule::follow_close );
if( data.has_member( "override_enable_avoid_combat" ) ) {
data.read( "override_enable_avoid_combat", tmpflag );
if( tmpflag ) {
enable_override( ally_rule::follow_close );
} else {
disable_override( ally_rule::follow_close );
}
}
data.read( "override_avoid_combat", tmpflag );
if( tmpflag ) {
set_override( ally_rule::follow_close );
} else {
clear_override( ally_rule::follow_close );
if( data.has_member( "override_avoid_combat" ) ) {
data.read( "override_avoid_combat", tmpflag );
if( tmpflag ) {
set_override( ally_rule::follow_close );
} else {
clear_override( ally_rule::follow_close );
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/npc_talk_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ TEST_CASE( "npc_talk_combat_commands", "[npc_talk]" )
CHECK( d.responses[0].text == "Change your engagement rules..." );
CHECK( d.responses[1].text == "Change your aiming rules..." );
CHECK( d.responses[2].text == "Stick close to me, no matter what." );
CHECK( d.responses[3].text == "<ally_rule_follow_distance_2_true_text>" );
CHECK( d.responses[3].text == "<ally_rule_follow_distance_2_false_text>" );
CHECK( d.responses[4].text == "Don't use ranged weapons anymore." );
CHECK( d.responses[5].text == "Use only silent weapons." );
CHECK( d.responses[6].text == "Don't use grenades anymore." );
Expand Down

0 comments on commit 5ad16b6

Please sign in to comment.