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

Pets follow stairs well #68255

Merged
merged 5 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 ) ) ) {
marimarigi marked this conversation as resolved.
Show resolved Hide resolved
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
34 changes: 19 additions & 15 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,28 +758,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() ) {
marimarigi marked this conversation as resolved.
Show resolved Hide resolved
// 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() ) ) {
marimarigi marked this conversation as resolved.
Show resolved Hide resolved
// 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,7 +973,15 @@ void monster::move()
}
}

if( ( current_attitude == MATT_IGNORE && patrol_route.empty() ) ||
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() ) ) {
marimarigi marked this conversation as resolved.
Show resolved Hide resolved
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 ) ) {
marimarigi marked this conversation as resolved.
Show resolved Hide resolved
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