diff --git a/Source/dead.cpp b/Source/dead.cpp index e245b945b..33518e702 100644 --- a/Source/dead.cpp +++ b/Source/dead.cpp @@ -28,6 +28,19 @@ void InitDeadAnimationFromMonster(Corpse &corpse, const CMonster &mon) corpse.frame = animData.frames - 1; corpse.width = animData.width; } + +void MoveLightToCorpse(Monster &monster) +{ + for (int dx = 0; dx < MAXDUNX; dx++) { + for (int dy = 0; dy < MAXDUNY; dy++) { + if ((dCorpse[dx][dy] & 0x1F) == monster.corpseId) { + ChangeLightXY(monster.lightId, { dx, dy }); + return; + } + } + } + AddUnLight(monster.lightId); +} } // namespace void InitCorpses() @@ -79,18 +92,13 @@ void AddCorpse(Point tilePosition, int8_t dv, Direction ddir) dCorpse[tilePosition.x][tilePosition.y] = (dv & 0x1F) + (static_cast(ddir) << 5); } -void SyncUniqDead() +void MoveLightsToCorpses() { for (size_t i = 0; i < ActiveMonsterCount; i++) { auto &monster = Monsters[ActiveMonsters[i]]; if (!monster.isUnique()) continue; - for (int dx = 0; dx < MAXDUNX; dx++) { - for (int dy = 0; dy < MAXDUNY; dy++) { - if ((dCorpse[dx][dy] & 0x1F) == monster.corpseId) - ChangeLightXY(monster.lightId, { dx, dy }); - } - } + MoveLightToCorpse(monster); } } diff --git a/Source/dead.h b/Source/dead.h index dedefcfb1..ded4699dd 100644 --- a/Source/dead.h +++ b/Source/dead.h @@ -39,6 +39,6 @@ extern int8_t stonendx; void InitCorpses(); void AddCorpse(Point tilePosition, int8_t dv, Direction ddir); -void SyncUniqDead(); +void MoveLightsToCorpses(); } // namespace devilution diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 8b58b2d37..1fd6a9169 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -2590,7 +2590,7 @@ void LoadLevel() for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert) dCorpse[i][j] = file.NextLE(); } - SyncUniqDead(); + MoveLightsToCorpses(); } ActiveMonsterCount = file.NextBE(); diff --git a/Source/monster.cpp b/Source/monster.cpp index 866a21739..3ae9cbd27 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3699,6 +3699,8 @@ void MonsterDeath(Monster &monster, Direction md, bool sendmsg) md = Direction::South; NewMonsterAnim(monster, MonsterGraphic::Death, md, gGameLogicStep < GameLogicStep::ProcessMonsters ? AnimationDistributionFlags::ProcessAnimationPending : AnimationDistributionFlags::None); monster.mode = MonsterMode::Death; + } else if (monster.isUnique()) { + AddUnLight(monster.lightId); } monster.goal = MonsterGoal::None; monster.var1 = 0;