Skip to content

Commit

Permalink
Show messages when pet is captured or released
Browse files Browse the repository at this point in the history
When using a pet carrier to capture or release a pet, it was not
displaying any kind of success message in the log. Now you will get i.e.

    "You capture the cat in your pet carrier."
    "You release the cat."

Following the example of similar log messages in these functions, I
added one message for successful capture, and one for successful
release.

This commit was going to be a simple two-line addition, but I discovered
that `release_monster` was deleting the name of the contained animal as
part of releaseing it, thus I got an empty string when trying to log it.

The solution, setting a local `contained_name` variable to remember the
animal name, had a nice side-effect of making several other lines a
little cleaner and more readable after slight refactoring, so I am
including that too.
  • Loading branch information
wapcaplet committed Jan 29, 2020
1 parent 0f3aa32 commit a6e9728
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/iuse.cpp
Expand Up @@ -9252,6 +9252,9 @@ int iuse::capture_monster_act( player *p, item *it, bool, const tripoint &pos )
return 0;
}
if( it->has_var( "contained_name" ) ) {
// Remember contained_name for messages after release_monster erases it
const std::string contained_name = it->get_var( "contained_name", "" );

if( it->release_monster( pos ) ) {
// It's been activated somewhere where there isn't a player or monster, good.
return 0;
Expand All @@ -9260,21 +9263,19 @@ int iuse::capture_monster_act( player *p, item *it, bool, const tripoint &pos )
if( it->release_monster( p->pos(), 1 ) ) {
return 0;
}
p->add_msg_if_player( _( "There is no place to put the %s." ),
it->get_var( "contained_name", "" ) );
p->add_msg_if_player( _( "There is no place to put the %s." ), contained_name );
return 0;
} else {
const std::string query = string_format( _( "Place the %s where?" ),
it->get_var( "contained_name", "" ) );
const std::string query = string_format( _( "Place the %s where?" ), contained_name );
const cata::optional<tripoint> pos_ = choose_adjacent( query );
if( !pos_ ) {
return 0;
}
if( it->release_monster( *pos_ ) ) {
p->add_msg_if_player( _( "You release the %s." ), contained_name );
return 0;
}
p->add_msg_if_player( m_info, _( "You cannot place the %s there!" ),
it->get_var( "contained_name", "" ) );
p->add_msg_if_player( m_info, _( "You cannot place the %s there!" ), contained_name );
return 0;
}
} else {
Expand Down Expand Up @@ -9311,6 +9312,8 @@ int iuse::capture_monster_act( player *p, item *it, bool, const tripoint &pos )
// If the monster is friendly, then put it in the item
// without checking if it rolled a success.
if( f.friendly != 0 || one_in( chance ) ) {
p->add_msg_if_player( _( "You capture the %1$s in your %2$s." ),
f.type->nname(), it->tname() );
return it->contain_monster( target );
} else {
p->add_msg_if_player( m_bad, _( "The %1$s avoids your attempts to put it in the %2$s." ),
Expand Down

0 comments on commit a6e9728

Please sign in to comment.