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

[1.5] Clean up PlaceUniqueMonster() position logic #7489

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 65 additions & 70 deletions Source/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(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<int>(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++) {
Expand All @@ -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<int>(ActiveMonsterCount);
}
void PlaceUniqueMonst(UniqueMonsterType uniqindex, size_t minionType, int bosspacksize)
{
const auto &uniqueMonsterData = UniqueMonstersData[static_cast<size_t>(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);
}

Expand Down Expand Up @@ -547,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);
}
}

Expand Down Expand Up @@ -3544,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]);

Expand Down
Loading