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

Fix several pets AI bugs, add player homeostatic effect on pets #2177

Merged
merged 10 commits into from
Nov 26, 2022
3 changes: 1 addition & 2 deletions data/json/monsters/mammal.json
Original file line number Diff line number Diff line change
Expand Up @@ -1668,15 +1668,14 @@
"material": [ "flesh" ],
"symbol": "H",
"color": "brown",
"morale": 20,
"melee_skill": 6,
"melee_dice": 2,
"melee_dice_sides": 12,
"melee_cut": 0,
"dodge": 2,
"armor_bash": 2,
"anger_triggers": [ "FRIEND_ATTACKED" ],
"fear_triggers": [ "SOUND", "PLAYER_CLOSE" ],
"fear_triggers": [ "PLAYER_CLOSE" ],
"placate_triggers": [ "PLAYER_WEAK" ],
"death_function": [ "NORMAL" ],
"harvest": "mammal_large_leather",
Expand Down
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10598,4 +10598,4 @@ bool has_psy_protection( const Character &c, int partial_chance )
{
return c.has_artifact_with( AEP_PSYSHIELD ) ||
( c.worn_with_flag( "PSYSHIELD_PARTIAL" ) && one_in( partial_chance ) );
}
}
27 changes: 24 additions & 3 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,33 @@ void monster::plan()
} else if( friendly > 0 && one_in( 3 ) ) {
// Grow restless with no targets
friendly--;
} else if( friendly < 0 && sees( g->u ) && !has_flag( MF_PET_WONT_FOLLOW ) ) {
if( rl_dist( pos(), g->u.pos() ) > 2 ) {
set_dest( g->u.pos() );
// if no target, and friendly pet sees the player
} else if( friendly < 0 && sees( g->u ) ) {
// eg dogs
if( !has_flag( MF_PET_WONT_FOLLOW ) ) {
// if too far from the player, go to him
if( rl_dist( pos(), g->u.pos() ) > 2 ) {
set_dest( g->u.pos() );
} else {
unset_dest();
}
// eg cows, horses
} else {
unset_dest();
}
// when the players is close to their pet, it calms them
// it helps them reach an homeostatic state, for moral and anger
const int distance_from_friend = rl_dist( pos(), get_avatar().pos() );
if( distance_from_friend < 12 ) {
if( one_in( distance_from_friend * 3 ) ) {
if( morale != type->morale ) {
morale += ( morale < type->morale ) ? 1 : -1;
}
if( anger != type->agro ) {
anger += ( anger < type->agro ) ? 1 : -1;
}
}
}
}

// being led by a leash override other movements decisions
Expand Down
7 changes: 4 additions & 3 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ monster_attitude monster::attitude( const Character *u ) const
}

if( effective_anger <= 0 ) {
if( get_hp() != get_hp_max() ) {
if( get_hp() <= 0.6 * get_hp_max() ) {
return MATT_FLEE;
} else {
return MATT_IGNORE;
Expand Down Expand Up @@ -2587,8 +2587,8 @@ void monster::process_effects_internal()
}
}

//Monster will regen morale and aggression if it is on max HP
//It regens more morale and aggression if is currently fleeing.
// Monster will regen morale and aggression if it is on max HP
// It regens more morale and aggression if is currently fleeing.
if( type->regen_morale && hp >= type->hp ) {
if( is_fleeing( g->u ) ) {
morale = type->morale;
Expand Down Expand Up @@ -2959,6 +2959,7 @@ void monster::hear_sound( const tripoint &source, const int vol, const int dist
// target_z will require some special check due to soil muffling sounds

int wander_turns = volume * ( goodhearing ? 6 : 1 );

process_trigger( mon_trigger::SOUND, volume );
if( morale >= 0 && anger >= 10 ) {
// TODO: Add a proper check for fleeing attitude
Expand Down