Skip to content

Commit

Permalink
Pets follow stairs well (#68255)
Browse files Browse the repository at this point in the history
* Pets use stairs more smoothly

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Remove unused line

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
marimarigi and github-actions[bot] authored Sep 23, 2023
1 parent 456e914 commit 4a89348
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ static const efftype_id effect_downed( "downed" );
static const efftype_id effect_fake_common_cold( "fake_common_cold" );
static const efftype_id effect_fake_flu( "fake_flu" );
static const efftype_id effect_laserlocked( "laserlocked" );
static const efftype_id effect_led_by_leash( "led_by_leash" );
static const efftype_id effect_no_sight( "no_sight" );
static const efftype_id effect_onfire( "onfire" );
static const efftype_id effect_pet( "pet" );
Expand Down Expand Up @@ -11954,8 +11955,8 @@ void game::vertical_move( int movez, bool force, bool peeking )
// TODO: just check if it's going for the avatar's location, it's simpler
Creature *target = critter.attack_target();
if( ( target && target->is_avatar() ) || ( !critter.has_effect( effect_ridden ) &&
critter.has_effect( effect_pet ) && critter.friendly == -1 &&
!critter.has_effect( effect_tied ) ) ) {
( critter.is_pet_follow() || critter.has_effect( effect_led_by_leash ) ) &&
!critter.has_effect( effect_tied ) && critter.sees( u ) ) ) {
monsters_following.push_back( &critter );
}
}
Expand Down
1 change: 1 addition & 0 deletions src/monexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ void start_leading( monster &z )
untie_pet( z );
}
z.add_effect( effect_led_by_leash, 1_turns, true );
z.unset_dest();
add_msg( _( "You take hold of the %s's leash to make it follow you." ), z.get_name() );
}

Expand Down
43 changes: 24 additions & 19 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ static const mon_flag_str_id mon_flag_PATH_AVOID_DANGER_1( "PATH_AVOID_DANGER_1"
static const mon_flag_str_id mon_flag_PATH_AVOID_DANGER_2( "PATH_AVOID_DANGER_2" );
static const mon_flag_str_id mon_flag_PATH_AVOID_FALL( "PATH_AVOID_FALL" );
static const mon_flag_str_id mon_flag_PATH_AVOID_FIRE( "PATH_AVOID_FIRE" );
static const mon_flag_str_id mon_flag_PET_WONT_FOLLOW( "PET_WONT_FOLLOW" );
static const mon_flag_str_id mon_flag_PRIORITIZE_TARGETS( "PRIORITIZE_TARGETS" );
static const mon_flag_str_id mon_flag_PUSH_MON( "PUSH_MON" );
static const mon_flag_str_id mon_flag_PUSH_VEH( "PUSH_VEH" );
Expand Down Expand Up @@ -758,28 +757,24 @@ void monster::plan()
next_stop = patrol_route.at( next_patrol_point );
}
set_dest( next_stop );
} else if( friendly != 0 && has_effect( effect_led_by_leash ) ) {
} else if( friendly != 0 && has_effect( effect_led_by_leash ) &&
get_location().z() == get_dest().z() ) {
// visibility doesn't matter, we're getting pulled by a leash
if( rl_dist( get_location(), player_character.get_location() ) > 1 ) {
set_dest( player_character.get_location() );
} else {
unset_dest();
}
// To use stairs smoothly, if the destination is on a different Z-level, move there first.
set_dest( player_character.get_location() );
if( friendly > 0 && one_in( 3 ) ) {
// Grow restless with no targets
friendly--;
}
} else if( friendly > 0 && one_in( 3 ) ) {
// Grow restless with no targets
friendly--;
} else if( friendly < 0 && sees( player_character ) &&
// Simpleminded animals are too dumb to follow the player.
!has_flag( mon_flag_PET_WONT_FOLLOW ) ) {
if( rl_dist( get_location(), player_character.get_location() ) > 2 ) {
set_dest( player_character.get_location() );
} else {
unset_dest();
}
} else if( is_pet_follow() && sees( player_character ) &&
( get_location().z() == player_character.get_location().z() ||
get_location().z() == get_dest().z() ) ) {
// Simpleminded animals are too dumb to follow the player.
// To use stairs smoothly, if the destination is on a different Z-level, move there first.
set_dest( player_character.get_location() );
}
}

Expand Down Expand Up @@ -977,10 +972,20 @@ void monster::move()
}
}

if( ( current_attitude == MATT_IGNORE && patrol_route.empty() ) ||
( ( current_attitude == MATT_FOLLOW ||
( has_flag( mon_flag_KEEP_DISTANCE ) && !( current_attitude == MATT_FLEE ) ) )
&& rl_dist( get_location(), get_dest() ) <= type->tracking_distance ) ) {
if( is_pet_follow() || ( friendly != 0 && has_effect( effect_led_by_leash ) ) ) {
const int dist = rl_dist( get_location(), get_dest() );
if( ( dist <= 1 || ( dist <= 2 && !has_effect( effect_led_by_leash ) &&
sees( player_character ) ) ) &&
( get_dest() == player_character.get_location() &&
get_location().z() == player_character.get_location().z() ) ) {
moves = 0;
stumble();
return;
}
} else if( ( current_attitude == MATT_IGNORE && patrol_route.empty() ) ||
( ( current_attitude == MATT_FOLLOW ||
( has_flag( mon_flag_KEEP_DISTANCE ) && !( current_attitude == MATT_FLEE ) ) )
&& rl_dist( get_location(), get_dest() ) <= type->tracking_distance ) ) {
moves = 0;
stumble();
return;
Expand Down
12 changes: 12 additions & 0 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ static const efftype_id effect_no_sight( "no_sight" );
static const efftype_id effect_onfire( "onfire" );
static const efftype_id effect_pacified( "pacified" );
static const efftype_id effect_paralyzepoison( "paralyzepoison" );
static const efftype_id effect_pet( "pet" );
static const efftype_id effect_photophobia( "photophobia" );
static const efftype_id effect_poison( "poison" );
static const efftype_id effect_ridden( "ridden" );
Expand Down Expand Up @@ -177,6 +178,7 @@ static const mon_flag_str_id mon_flag_NO_BREED( "NO_BREED" );
static const mon_flag_str_id mon_flag_NO_FUNG_DMG( "NO_FUNG_DMG" );
static const mon_flag_str_id mon_flag_PARALYZEVENOM( "PARALYZEVENOM" );
static const mon_flag_str_id mon_flag_PET_MOUNTABLE( "PET_MOUNTABLE" );
static const mon_flag_str_id mon_flag_PET_WONT_FOLLOW( "PET_WONT_FOLLOW" );
static const mon_flag_str_id mon_flag_PHOTOPHOBIC( "PHOTOPHOBIC" );
static const mon_flag_str_id mon_flag_PLASTIC( "PLASTIC" );
static const mon_flag_str_id mon_flag_QUEEN( "QUEEN" );
Expand Down Expand Up @@ -1283,6 +1285,16 @@ bool monster::made_of( phase_id p ) const
return type->phase == p;
}

bool monster::is_pet() const
{
return friendly == -1 && has_effect( effect_pet );
}

bool monster::is_pet_follow() const
{
return is_pet() && !has_flag( mon_flag_PET_WONT_FOLLOW );
}

std::vector<material_id> monster::get_absorb_material() const
{
return type->absorb_material;
Expand Down
2 changes: 2 additions & 0 deletions src/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ class monster : public Creature
bool made_of( phase_id p ) const; // Returns true if its phase is p

bool shearable() const;
bool is_pet() const;
bool is_pet_follow() const;

bool avoid_trap( const tripoint &pos, const trap &tr ) const override;

Expand Down

0 comments on commit 4a89348

Please sign in to comment.