Skip to content

Commit

Permalink
Merge pull request #77090 from RenechCDDA/unfuck_monster_food
Browse files Browse the repository at this point in the history
Clean up monster eating code, part 1/???
  • Loading branch information
Maleclypse authored Oct 17, 2024
2 parents 1691109 + c780b4f commit 3d61dae
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 102 deletions.
2 changes: 2 additions & 0 deletions data/json/effects.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@
]
},
{
"//": "This effect is automatically applied in C++.",
"type": "effect_type",
"id": "critter_well_fed",
"name": [ "Well Fed" ],
"show_in_info": true,
"desc": [ { "str": "AI tag for when critter has had enough to eat. This is a bug if you have it.", "//~": "NO_I18N" } ]
},
{
"//": "This effect is automatically applied in C++.",
"type": "effect_type",
"id": "critter_underfed",
"name": [ "Underfed" ],
Expand Down
1 change: 1 addition & 0 deletions src/do_turn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ void monmove()
}
critter.try_biosignature();
critter.try_reproduce();
critter.digest_food();
}
while( critter.get_moves() > 0 && !critter.is_dead() && !critter.has_effect( effect_ridden ) ) {
critter.made_footstep = false;
Expand Down
9 changes: 3 additions & 6 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ static const efftype_id effect_cig( "cig" );
static const efftype_id effect_conjunctivitis( "conjunctivitis" );
static const efftype_id effect_contacts( "contacts" );
static const efftype_id effect_corroding( "corroding" );
static const efftype_id effect_critter_well_fed( "critter_well_fed" );
static const efftype_id effect_crushed( "crushed" );
static const efftype_id effect_datura( "datura" );
static const efftype_id effect_dazed( "dazed" );
Expand Down Expand Up @@ -1615,14 +1614,12 @@ std::optional<int> iuse::petfood( Character *p, item *it, const tripoint & )
}

p->add_msg_if_player( _( "You feed your %1$s to the %2$s." ), it->tname(), mon->get_name() );
if( mon->has_flag( mon_flag_EATS ) ) {
if( !mon->has_fully_eaten() && mon->has_flag( mon_flag_EATS ) ) {
int kcal = it->get_comestible()->default_nutrition.kcal();
mon->amount_eaten += kcal;
if( mon->amount_eaten >= mon->stomach_size ) {
mon->mod_amount_eaten( kcal );
if( mon->has_fully_eaten() ) {
p->add_msg_if_player( _( "The %1$s seems full now." ), mon->get_name() );
}
} else if( !mon->has_flag( mon_flag_EATS ) ) {
mon->add_effect( effect_critter_well_fed, 24_hours );
}

if( petfood.feed.empty() ) {
Expand Down
36 changes: 18 additions & 18 deletions src/monattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ bool mattack::eat_crop( monster *z )
target = p;
}
if( target ) {
if( z->amount_eaten <= z->stomach_size ) {
if( !z->has_fully_eaten() ) {
add_msg_if_player_sees( *z, _( "The %1s eats the %2s." ), z->name(), here.furnname( p ) );
here.furn_set( *target, furn_str_id( here.furn( *target )->plant->base ) );
here.i_clear( *target );
z->amount_eaten += 350;
z->mod_amount_eaten( 350 );
return true;
}
}
Expand All @@ -337,18 +337,18 @@ bool mattack::eat_crop( monster *z )
!item.has_flag( flag_CATTLE ) ) {
continue;
}
if( z->amount_eaten <= z->stomach_size ) {
if( !z->has_fully_eaten() ) {
//Check for stomach size 0 so as to not break creatures which haven't
//been given a stomach size yet.
int consumed = 1;
if( item.count_by_charges() ) {
int kcal = item.get_comestible()->default_nutrition.kcal();
z->amount_eaten += kcal;
z->mod_amount_eaten( kcal );
add_msg_if_player_sees( *z, _( "The %1s eats the %2s." ), z->name(), item.display_name() );
here.use_charges( p, 1, item.type->get_id(), consumed );
} else {
int kcal = item.get_comestible()->default_nutrition.kcal();
z->amount_eaten += kcal;
z->mod_amount_eaten( kcal );
add_msg_if_player_sees( *z, _( "The %1s gobbles up the %2s." ), z->name(), item.display_name() );
here.use_amount( p, 1, item.type->get_id(), consumed );
}
Expand Down Expand Up @@ -492,16 +492,16 @@ bool mattack::eat_food( monster *z )
continue;
}
//Don't eat own eggs
if( z->type->baby_type.baby_egg != item.type->get_id() && ( z->amount_eaten <= z->stomach_size ) ) {
if( z->type->baby_type.baby_egg != item.type->get_id() && ( !z->has_fully_eaten() ) ) {
int consumed = 1;
if( item.count_by_charges() ) {
int kcal = item.get_comestible()->default_nutrition.kcal();
z->amount_eaten += kcal;
z->mod_amount_eaten( kcal );
add_msg_if_player_sees( *z, _( "The %1s eats the %2s." ), z->name(), item.display_name() );
here.use_charges( p, 1, item.type->get_id(), consumed );
} else {
int kcal = item.get_comestible()->default_nutrition.kcal();
z->amount_eaten += kcal;
z->mod_amount_eaten( kcal );
add_msg_if_player_sees( *z, _( "The %1s gobbles up the %2s." ), z->name(), item.display_name() );
here.use_amount( p, 1, item.type->get_id(), consumed );
}
Expand All @@ -524,14 +524,14 @@ bool mattack::eat_carrion( monster *z )
for( item &item : items ) {
//TODO: Completely eaten corpses should leave bones and other inedibles.
if( item.has_flag( flag_CORPSE ) && item.damage() < item.max_damage() &&
z->amount_eaten < z->stomach_size &&
!z->has_fully_eaten() &&
( item.made_of( material_flesh ) || item.made_of( material_iflesh ) ||
item.made_of( material_hflesh ) || item.made_of( material_veggy ) ) ) {
item.mod_damage( 700 );
if( item.damage() >= item.max_damage() && item.can_revive() ) {
item.set_flag( flag_PULPED );
}
z->amount_eaten += 100;
z->mod_amount_eaten( 100 );
add_msg_if_player_sees( *z, _( "The %1s gnaws on the %2s." ), z->name(), item.display_name() );
return true;
}
Expand All @@ -551,24 +551,24 @@ bool mattack::graze( monster *z )
}
if( here.has_flag( ter_furn_flag::TFLAG_FLOWER, p ) &&
!here.has_flag( ter_furn_flag::TFLAG_GRAZER_INEDIBLE, p ) &&
( z->amount_eaten <= z->stomach_size ) ) {
( !z->has_fully_eaten() ) ) {
here.furn_set( p, furn_str_id::NULL_ID() );
z->amount_eaten += 50;
z->mod_amount_eaten( 50 );
//Calorie amount is based on the "small_plant" dummy item, as with the grazer mutation.
return true;
}
if( here.has_flag( ter_furn_flag::TFLAG_SHRUB, p ) &&
!here.has_flag( ter_furn_flag::TFLAG_GRAZER_INEDIBLE, p ) &&
( z->amount_eaten <= z->stomach_size ) ) {
( !z->has_fully_eaten() ) ) {
add_msg_if_player_sees( *z, _( "The %1s eats the %2s." ), z->name(), here.tername( p ) );
here.ter_set( p, ter_t_dirt );
z->amount_eaten += 174;
z->mod_amount_eaten( 174 );
//Calorie amount is based on the "underbrush" dummy item, as with the grazer mutation.
return true;
}
if( here.has_flag( ter_furn_flag::TFLAG_GRAZABLE, p ) && z->amount_eaten < z->stomach_size ) {
if( here.has_flag( ter_furn_flag::TFLAG_GRAZABLE, p ) && !z->has_fully_eaten() ) {
here.ter_set( p, here.get_ter_transforms_into( p ) );
z->amount_eaten += 70;
z->mod_amount_eaten( 70 );
//Calorie amount is based on the "grass" dummy item, as with the grazer mutation.
return true;
}
Expand All @@ -585,12 +585,12 @@ bool mattack::browse( monster *z )
if( z->friendly && rl_dist( get_player_character().pos_bub(), p ) <= 2 ) {
continue;
}
if( here.has_flag( ter_furn_flag::TFLAG_BROWSABLE, p ) && ( z->amount_eaten <= z->stomach_size ) ) {
if( here.has_flag( ter_furn_flag::TFLAG_BROWSABLE, p ) && ( !z->has_fully_eaten() ) ) {
const harvest_id harvest = here.get_harvest( p );
if( !harvest.is_null() || !harvest->empty() ) {
add_msg_if_player_sees( *z, _( "The %1s eats from the %2s." ), z->name(), here.tername( p ) );
here.ter_set( p, here.get_ter_transforms_into( p ) );
z->amount_eaten += 174;
z->mod_amount_eaten( 174 );
//Calorie amount is based on the "underbrush" dummy item, as with the grazer mutation.
return true;
}
Expand Down
5 changes: 2 additions & 3 deletions src/mondeath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include "value_ptr.h"
#include "viewer.h"

static const efftype_id effect_critter_underfed( "critter_underfed" );
static const efftype_id effect_no_ammo( "no_ammo" );

static const harvest_drop_type_id harvest_drop_bone( "bone" );
Expand Down Expand Up @@ -202,7 +201,7 @@ item_location mdeath::splatter( monster &z )
if( z.has_effect( effect_no_ammo ) ) {
corpse.set_var( "no_ammo", "no_ammo" );
}
if( z.has_effect( effect_critter_underfed ) ) {
if( !z.has_eaten_enough() ) {
corpse.set_flag( STATIC( flag_id( "UNDERFED" ) ) );
}
return here.add_item_ret_loc( z.pos_bub(), corpse );
Expand Down Expand Up @@ -293,7 +292,7 @@ item_location make_mon_corpse( monster &z, int damageLvl )
if( z.has_effect( effect_no_ammo ) ) {
corpse.set_var( "no_ammo", "no_ammo" );
}
if( z.has_effect( effect_critter_underfed ) ) {
if( !z.has_eaten_enough() ) {
corpse.set_flag( STATIC( flag_id( "UNDERFED" ) ) );
}
return get_map().add_item_ret_loc( z.pos_bub(), corpse );
Expand Down
23 changes: 7 additions & 16 deletions src/monexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

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" );
static const efftype_id effect_has_bag( "has_bag" );
static const efftype_id effect_leashed( "leashed" );
Expand Down Expand Up @@ -528,7 +527,7 @@ void milk_source( monster &source_mon )
add_msg( _( "You milk the %s." ), source_mon.get_name() );
} else {
add_msg( _( "The %s has no more milk." ), source_mon.get_name() );
if( !source_mon.has_effect( effect_critter_well_fed ) ) {
if( !source_mon.has_eaten_enough() ) {
add_msg( _( "It might not be getting enough to eat." ) );
}
}
Expand Down Expand Up @@ -645,13 +644,9 @@ bool monexamine::pet_menu( monster &z )
std::string pet_name = z.get_name();

amenu.text = string_format( _( "What to do with your %s?" ), pet_name );
if( z.has_flag( mon_flag_EATS ) && ( z.amount_eaten < ( z.stomach_size / 10 ) ) ) {
amenu.text = string_format( _( "What to do with your %s?\n" "Hunger: Famished" ), pet_name );
} else if( z.has_flag( mon_flag_EATS ) && ( z.amount_eaten > ( z.stomach_size / 10 ) &&
z.amount_eaten < z.stomach_size ) ) {
amenu.text = string_format( _( "What to do with your %s?\n" "Hunger: Hungry" ), pet_name );
} else if( z.has_flag( mon_flag_EATS ) && z.amount_eaten >= z.stomach_size ) {
amenu.text = string_format( _( "What to do with your %s?\n" "Hunger: Full" ), pet_name );
if( z.has_flag( mon_flag_EATS ) ) {
amenu.text = string_format( _( "What to do with your %s?\n" "Fullness: %i%%" ), pet_name,
z.get_stomach_fullness_percent() );
}
amenu.addentry( swap_pos, true, 's', _( "Swap positions" ) );
amenu.addentry( push_monster, true, 'p', _( "Push %s" ), pet_name );
Expand Down Expand Up @@ -978,13 +973,9 @@ bool monexamine::mfriend_menu( monster &z )
const std::string pet_name = z.get_name();

amenu.text = string_format( _( "What to do with your %s?" ), pet_name );
if( z.has_flag( mon_flag_EATS ) && ( z.amount_eaten < ( z.stomach_size / 10 ) ) ) {
amenu.text = string_format( _( "What to do with your %s?\n" "Hunger: Famished" ), pet_name );
} else if( z.has_flag( mon_flag_EATS ) && ( z.amount_eaten > ( z.stomach_size / 10 ) &&
z.amount_eaten < z.stomach_size ) ) {
amenu.text = string_format( _( "What to do with your %s?\n" "Hunger: Hungry" ), pet_name );
} else if( z.has_flag( mon_flag_EATS ) && z.amount_eaten >= z.stomach_size ) {
amenu.text = string_format( _( "What to do with your %s?\n" "Hunger: Full" ), pet_name );
if( z.has_flag( mon_flag_EATS ) ) {
amenu.text = string_format( _( "What to do with your %s?\n" "Fullness: %i%%" ), pet_name,
z.get_stomach_fullness_percent() );
}
amenu.addentry( swap_pos, true, 's', _( "Swap positions" ) );
amenu.addentry( push_monster, true, 'p', _( "Push %s" ), pet_name );
Expand Down
Loading

0 comments on commit 3d61dae

Please sign in to comment.