From a5f22931a3daa3759844f1425c720a94764701e3 Mon Sep 17 00:00:00 2001 From: Eric Robinson <68359262+kphoenix137@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:12:35 -0400 Subject: [PATCH 1/2] Clean up PlaceUniqueMonster() position logic --- Source/monster.cpp | 119 ++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 61 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 2608accac60..1650e98806e 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -313,15 +313,58 @@ size_t GetMonsterTypeIndex(_monster_id type) return LevelMonsterTypeCount; } -void PlaceUniqueMonst(UniqueMonsterType uniqindex, size_t minionType, int bosspacksize) +Point GetUniqueMonstPosition(UniqueMonsterType uniqindex) { - auto &monster = Monsters[ActiveMonsterCount]; - const auto &uniqueMonsterData = UniqueMonstersData[static_cast(uniqindex)]; + if (setlevel) { + switch (uniqindex) { + case UniqueMonsterType::Lazarus: + return { 32, 46 }; + case UniqueMonsterType::RedVex: + return { 40, 45 }; + case UniqueMonsterType::BlackJade: + return { 38, 49 }; + case UniqueMonsterType::SkeletonKing: + return { 35, 47 }; + default: + break; + } + } + + switch (uniqindex) { + case UniqueMonsterType::SnotSpill: + return SetPiece.position.megaToWorld() + Displacement { 8, 12 }; + case UniqueMonsterType::WarlordOfBlood: + return SetPiece.position.megaToWorld() + Displacement { 6, 7 }; + case UniqueMonsterType::Zhar: + for (int i = 0; i < themeCount; i++) { + if (i == zharlib) { + return themeLoc[i].room.position.megaToWorld() + Displacement { 4, 4 }; + } + } + break; + case UniqueMonsterType::Lazarus: + return SetPiece.position.megaToWorld() + Displacement { 3, 6 }; + case UniqueMonsterType::RedVex: + return SetPiece.position.megaToWorld() + Displacement { 5, 3 }; + case UniqueMonsterType::BlackJade: + return SetPiece.position.megaToWorld() + Displacement { 5, 9 }; + case UniqueMonsterType::Butcher: + return SetPiece.position.megaToWorld() + Displacement { 4, 4 }; + case UniqueMonsterType::NaKrul: + if (UberRow == 0 || UberCol == 0) { + UberDiabloMonsterIndex = -1; + break; + } + UberDiabloMonsterIndex = static_cast(ActiveMonsterCount); + return { UberRow - 2, UberCol }; + default: + break; + } - int count = 0; Point position; - while (true) { - position = Point { GenerateRnd(80), GenerateRnd(80) } + Displacement { 16, 16 }; + int count = 0; + do { + Point position = Point { GenerateRnd(80), GenerateRnd(80) } + Displacement { 16, 16 }; int count2 = 0; for (int x = position.x - 3; x < position.x + 3; x++) { for (int y = position.y - 3; y < position.y + 3; y++) { @@ -337,66 +380,20 @@ void PlaceUniqueMonst(UniqueMonsterType uniqindex, size_t minionType, int bosspa continue; } } + } while (!CanPlaceMonster(position)); - if (CanPlaceMonster(position)) { - break; - } - } - - if (uniqindex == UniqueMonsterType::SnotSpill) { - position = SetPiece.position.megaToWorld() + Displacement { 8, 12 }; - } - if (uniqindex == UniqueMonsterType::WarlordOfBlood) { - position = SetPiece.position.megaToWorld() + Displacement { 6, 7 }; - } - if (uniqindex == UniqueMonsterType::Zhar) { - for (int i = 0; i < themeCount; i++) { - if (i == zharlib) { - position = themeLoc[i].room.position.megaToWorld() + Displacement { 4, 4 }; - break; - } - } - } - if (setlevel) { - if (uniqindex == UniqueMonsterType::Lazarus) { - position = { 32, 46 }; - } - if (uniqindex == UniqueMonsterType::RedVex) { - position = { 40, 45 }; - } - if (uniqindex == UniqueMonsterType::BlackJade) { - position = { 38, 49 }; - } - if (uniqindex == UniqueMonsterType::SkeletonKing) { - position = { 35, 47 }; - } - } else { - if (uniqindex == UniqueMonsterType::Lazarus) { - position = SetPiece.position.megaToWorld() + Displacement { 3, 6 }; - } - if (uniqindex == UniqueMonsterType::RedVex) { - position = SetPiece.position.megaToWorld() + Displacement { 5, 3 }; - } - if (uniqindex == UniqueMonsterType::BlackJade) { - position = SetPiece.position.megaToWorld() + Displacement { 5, 9 }; - } - } - if (uniqindex == UniqueMonsterType::Butcher) { - position = SetPiece.position.megaToWorld() + Displacement { 4, 4 }; - } + return position; +} - if (uniqindex == UniqueMonsterType::NaKrul) { - if (UberRow == 0 || UberCol == 0) { - UberDiabloMonsterIndex = -1; - return; - } - position = { UberRow - 2, UberCol }; - UberDiabloMonsterIndex = static_cast(ActiveMonsterCount); - } +void PlaceUniqueMonst(UniqueMonsterType uniqindex, size_t minionType, int bosspacksize) +{ + const auto &uniqueMonsterData = UniqueMonstersData[static_cast(uniqindex)]; const size_t typeIndex = GetMonsterTypeIndex(uniqueMonsterData.mtype); + const Point position = GetUniqueMonstPosition(uniqindex); PlaceMonster(ActiveMonsterCount, typeIndex, position); - ActiveMonsterCount++; + Monster &monster = Monsters[ActiveMonsterCount]; + ActiveMonsterCount++; PrepareUniqueMonst(monster, uniqindex, minionType, bosspacksize, uniqueMonsterData); } From f71c7ff56f451e2fde1a1bd3ab240be8d9a35633 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Mon, 7 Oct 2024 23:38:20 -0400 Subject: [PATCH 2/2] Move Lazarus spawn code --- Source/monster.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 1650e98806e..4080b4dff7d 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -544,6 +544,13 @@ void PlaceQuestMonsters() } } else if (setlvlnum == SL_SKELKING) { PlaceUniqueMonst(UniqueMonsterType::SkeletonKing, 0, 0); + } else if (setlvlnum == SL_VILEBETRAYER) { + AddMonsterType(UniqueMonsterType::Lazarus, PLACE_UNIQUE); + AddMonsterType(UniqueMonsterType::RedVex, PLACE_UNIQUE); + AddMonsterType(UniqueMonsterType::BlackJade, PLACE_UNIQUE); + PlaceUniqueMonst(UniqueMonsterType::Lazarus, 0, 0); + PlaceUniqueMonst(UniqueMonsterType::RedVex, 0, 0); + PlaceUniqueMonst(UniqueMonsterType::BlackJade, 0, 0); } } @@ -3541,15 +3548,6 @@ void SetMapMonsters(const uint16_t *dunData, Point startPosition) for (int i = 0; i < MAX_PLRS; i++) AddMonster(GolemHoldingCell, Direction::South, 0, false); - if (setlevel && setlvlnum == SL_VILEBETRAYER) { - AddMonsterType(UniqueMonsterType::Lazarus, PLACE_UNIQUE); - AddMonsterType(UniqueMonsterType::RedVex, PLACE_UNIQUE); - AddMonsterType(UniqueMonsterType::BlackJade, PLACE_UNIQUE); - PlaceUniqueMonst(UniqueMonsterType::Lazarus, 0, 0); - PlaceUniqueMonst(UniqueMonsterType::RedVex, 0, 0); - PlaceUniqueMonst(UniqueMonsterType::BlackJade, 0, 0); - } - int width = SDL_SwapLE16(dunData[0]); int height = SDL_SwapLE16(dunData[1]);