Skip to content

Commit

Permalink
Merge pull request #51194 from eltank/fix_despawn_monster
Browse files Browse the repository at this point in the history
Fix zombie insta-healing after reviving
  • Loading branch information
kevingranade authored Aug 29, 2021
2 parents 3ad3a2e + 22d023e commit ba0c50d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
25 changes: 14 additions & 11 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4609,22 +4609,24 @@ bool game::revive_corpse( const tripoint &p, item &it )
if( g->new_game ) {
return false;
}
shared_ptr_fast<monster> newmon_ptr = make_shared_fast<monster>
( it.get_mtype()->id );
if( it.has_var( "zombie_form" ) ) { // if the monster can reanimate has a zombie
if( it.has_flag( flag_FIELD_DRESS ) || it.has_flag( flag_FIELD_DRESS_FAILED ) ||
it.has_flag( flag_QUARTERED ) ) {
// Failed reanimation due to corpse being butchered
return false;
}
shared_ptr_fast<monster> newmon_ptr;
if( it.has_var( "zombie_form" ) ) {
// the monster was not a zombie but turns into one when its corpse is revived
newmon_ptr = make_shared_fast<monster>( mtype_id( it.get_var( "zombie_form" ) ) );
} else {
newmon_ptr = make_shared_fast<monster>( it.get_mtype()->id );
}
monster &critter = *newmon_ptr;
critter.init_from_item( it );
if( critter.get_hp() < 1 ) {
// Failed reanimation due to corpse being too burned
return false;
}
if( it.has_flag( flag_FIELD_DRESS ) || it.has_flag( flag_FIELD_DRESS_FAILED ) ||
it.has_flag( flag_QUARTERED ) ) {
// Failed reanimation due to corpse being butchered
return false;
}

critter.no_extra_death_drops = true;
critter.add_effect( effect_downed, 5_turns, true );
Expand Down Expand Up @@ -10984,12 +10986,13 @@ void game::update_overmap_seen()

void game::despawn_monster( monster &critter )
{
critter.on_unload();
// hallucinations aren't stored, they come and go as they like
if( !critter.is_hallucination() ) {
// hallucinations aren't stored, they come and go as they like,
// despawn_monster saves a copy of the monster in the overmap, so
// this must be called after on_unload (which updates state)
overmap_buffer.despawn_monster( critter );
}

critter.on_unload();
remove_zombie( critter );
// simulate it being dead so further processing of it (e.g. in monmove) will yield
critter.set_hp( 0 );
Expand Down
4 changes: 2 additions & 2 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3108,11 +3108,11 @@ void monster::on_load()
float regen = type->regenerates;
if( regen <= 0 ) {
if( has_flag( MF_REVIVES ) ) {
regen = 1.0f / to_turns<int>( 1_hours );
regen = 0.02f * type->hp / to_turns<int>( 1_hours );
} else if( made_of( material_id( "flesh" ) ) || made_of( material_id( "iflesh" ) ) ||
made_of( material_id( "veggy" ) ) ) {
// Most living stuff here
regen = 0.25f / to_turns<int>( 1_hours );
regen = 0.005f * type->hp / to_turns<int>( 1_hours );
}
}
const int heal_amount = roll_remainder( regen * to_turns<int>( dt ) );
Expand Down
8 changes: 2 additions & 6 deletions src/overmapbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,20 +1545,16 @@ void overmapbuffer::spawn_monster( const tripoint_abs_sm &p )

void overmapbuffer::despawn_monster( const monster &critter )
{
// Get absolute coordinates of the monster in map squares, translate to submap position
// TODO: fix point types
tripoint_abs_sm abs_sm( ms_to_sm_copy( get_map().getabs( critter.pos() ) ) );
// Get the overmap coordinates and get the overmap, sm is now local to that overmap
point_abs_om omp;
tripoint_om_sm sm;
std::tie( omp, sm ) = project_remain<coords::om>( abs_sm );
std::tie( omp, sm ) = project_remain<coords::om>( critter.global_sm_location() );
overmap &om = get( omp );
// Store the monster using coordinates local to the overmap

if( critter.is_nemesis() ) {
//if the monster is the 'hunted' trait's nemesis, it becomes an overmap horde
tripoint_abs_omt abs_omt( ms_to_omt_copy( get_map().getabs( critter.pos() ) ) );
om.place_nemesis( abs_omt );
om.place_nemesis( critter.global_omt_location() );
} else {
om.monster_map.insert( std::make_pair( sm, critter ) );
}
Expand Down

0 comments on commit ba0c50d

Please sign in to comment.