Skip to content

Commit

Permalink
Treat bleeding from pets (#75274)
Browse files Browse the repository at this point in the history
* Treat bleeding from pets

-Easy way to treat the bleeding of a pet

-Add message when bleeding stops

* Apply suggestions from code review

Better style

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

* Order efftype_id

Solve error with message:

Error: /home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/monexamine.cpp:58:1: error: string_id declarations should be sorted. [cata-static-string_id-constants,-warnings-as-errors]

/home/runner/work/Cataclysm-DDA/Cataclysm-DDA/src/monexamine.cpp:58:1: note: 'effect_bleed' should be before 'effect_tied'.

* Update src/monexamine.cpp

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

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Roguecop and github-actions[bot] authored Jul 28, 2024
1 parent 0e4fd32 commit 4752f59
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions src/monexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#include "creature.h"
#include "debug.h"
#include "enums.h"
#include "flag.h"
#include "game.h"
#include "game_inventory.h"
#include "item.h"
#include "item_location.h"
#include "itype.h"
#include "iuse.h"
#include "iuse_actor.h"
#include "map.h"
#include "messages.h"
#include "monster.h"
Expand All @@ -39,8 +41,8 @@
#include "ui.h"
#include "units.h"
#include "value_ptr.h"
#include "flag.h"

static const efftype_id effect_bleed( "bleed" );
static const efftype_id effect_controlled( "controlled" );
static const efftype_id effect_critter_well_fed( "critter_well_fed" );
static const efftype_id effect_harnessed( "harnessed" );
Expand All @@ -55,6 +57,7 @@ static const efftype_id effect_ridden( "ridden" );
static const efftype_id effect_sheared( "sheared" );
static const efftype_id effect_tied( "tied" );


static const flag_id json_flag_MECH_BAT( "MECH_BAT" );
static const flag_id json_flag_TACK( "TACK" );
static const flag_id json_flag_TIE_UP( "TIE_UP" );
Expand Down Expand Up @@ -94,6 +97,34 @@ void attach_saddle_to( monster &z )
loc.remove_item();
}

void bandage_animal( monster &z )
{
if( !z.has_effect( effect_bleed ) ) {
return;
}
item_location wieldede_item = get_player_character().get_wielded_item();
if( !wieldede_item ) {
add_msg( _( "I need to have in hand something to stop the bleeding of %s" ), z.name() );
return;
}
const use_function *usage = wieldede_item.get_item()->type->get_use( "heal" );
if( usage == nullptr ) {
add_msg( _( "I'm not going to stop %s bleeding with this %s " ), z.name(),
wieldede_item.get_item()->display_name() );
return;
}
const heal_actor *actor = dynamic_cast<const heal_actor *>( usage->get_actor_ptr() );
if( actor->bleed ) {
z.remove_effect( effect_bleed );
wieldede_item.remove_item();
add_msg( _( "The bleeding of %s stopped" ), z.name() );

} else {
add_msg( _( "I'm not going to stop %s bleeding with this %s " ), z.name(),
wieldede_item.get_item()->display_name() );
}
}

void remove_saddle_from( monster &z )
{
if( !z.has_effect( effect_monster_saddled ) ) {
Expand Down Expand Up @@ -606,7 +637,8 @@ bool monexamine::pet_menu( monster &z )
insert_bat,
check_bat,
attack,
talk_to
talk_to,
stop_bleeding
};

uilist amenu;
Expand Down Expand Up @@ -710,6 +742,9 @@ bool monexamine::pet_menu( monster &z )
if( !z.type->chat_topics.empty() ) {
amenu.addentry( talk_to, true, 'c', _( "Talk to %s" ), pet_name );
}
if( z.has_effect( effect_bleed ) ) {
amenu.addentry( stop_bleeding, true, 'B', _( "Treat bleeding from %s" ), pet_name );
}
if( !z.has_flag( mon_flag_RIDEABLE_MECH ) ) {
if( z.has_flag( mon_flag_PET_MOUNTABLE ) && player_character.can_mount( z ) ) {
amenu.addentry( mount, true, 'r', _( "Mount %s" ), pet_name );
Expand Down Expand Up @@ -845,6 +880,9 @@ bool monexamine::pet_menu( monster &z )
case talk_to:
get_avatar().talk_to( get_talker_for( z ) );
break;
case stop_bleeding:
bandage_animal( z );
break;
default:
break;
}
Expand Down Expand Up @@ -932,7 +970,8 @@ bool monexamine::mfriend_menu( monster &z )
push_monster,
rename,
attack,
talk_to
talk_to,
stop_bleeding
};

uilist amenu;
Expand Down Expand Up @@ -975,6 +1014,9 @@ bool monexamine::mfriend_menu( monster &z )
case talk_to:
get_avatar().talk_to( get_talker_for( z ) );
break;
case stop_bleeding:
bandage_animal( z );
break;
default:
break;
}
Expand Down

0 comments on commit 4752f59

Please sign in to comment.