Skip to content

Commit

Permalink
Clean up PlaceUniqueMonst()
Browse files Browse the repository at this point in the history
  • Loading branch information
AJenbo committed Oct 8, 2024
1 parent 9788a8f commit 2d9ab68
Showing 1 changed file with 49 additions and 63 deletions.
112 changes: 49 additions & 63 deletions Source/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,101 +333,87 @@ size_t GetMonsterTypeIndex(_monster_id type)
return LevelMonsterTypeCount;
}

void PlaceUniqueMonst(UniqueMonsterType uniqindex, size_t minionType, int bosspacksize)
{
Monster &monster = Monsters[ActiveMonsterCount];
const auto &uniqueMonsterData = UniqueMonstersData[static_cast<size_t>(uniqindex)];

Point position;
bool hasPredefinedPosition = true;
Point GetUniqueMonstPosition(UniqueMonsterType 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:
position = SetPiece.position.megaToWorld() + Displacement { 8, 12 };
break;
return SetPiece.position.megaToWorld() + Displacement { 8, 12 };
case UniqueMonsterType::WarlordOfBlood:
position = SetPiece.position.megaToWorld() + Displacement { 6, 7 };
break;
return SetPiece.position.megaToWorld() + Displacement { 6, 7 };
case UniqueMonsterType::Zhar:
for (int i = 0; i < themeCount; i++) {
if (i == zharlib) {
position = themeLoc[i].room.position.megaToWorld() + Displacement { 4, 4 };
break;
return themeLoc[i].room.position.megaToWorld() + Displacement { 4, 4 };
}
}
break;
case UniqueMonsterType::Lazarus:
if (setlevel) {
position = { 32, 46 };
} else {
position = SetPiece.position.megaToWorld() + Displacement { 3, 6 };
}
break;
return SetPiece.position.megaToWorld() + Displacement { 3, 6 };
case UniqueMonsterType::RedVex:
if (setlevel) {
position = { 40, 45 };
} else {
position = SetPiece.position.megaToWorld() + Displacement { 5, 3 };
}
break;
return SetPiece.position.megaToWorld() + Displacement { 5, 3 };
case UniqueMonsterType::BlackJade:
if (setlevel) {
position = { 38, 49 };
} else {
position = SetPiece.position.megaToWorld() + Displacement { 5, 9 };
}
break;
case UniqueMonsterType::SkeletonKing:
if (setlevel) {
position = { 35, 47 };
}
break;
return SetPiece.position.megaToWorld() + Displacement { 5, 9 };
case UniqueMonsterType::Butcher:
position = SetPiece.position.megaToWorld() + Displacement { 4, 4 };
break;
return SetPiece.position.megaToWorld() + Displacement { 4, 4 };
case UniqueMonsterType::NaKrul:
if (UberRow == 0 || UberCol == 0) {
UberDiabloMonsterIndex = -1;
return;
break;
}
position = { UberRow - 2, UberCol };
UberDiabloMonsterIndex = static_cast<int>(ActiveMonsterCount);
break;
return { UberRow - 2, UberCol };
default:
hasPredefinedPosition = false;
break;
}

if (!hasPredefinedPosition) {
int count = 0;
while (true) {
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++) {
if (InDungeonBounds({ x, y }) && CanPlaceMonster({ x, y })) {
count2++;
}
}
}

if (count2 < 9) {
count++;
if (count < 1000) {
continue;
Point position;
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++) {
if (InDungeonBounds({ x, y }) && CanPlaceMonster({ x, y })) {
count2++;
}
}
}

if (CanPlaceMonster(position)) {
break;
if (count2 < 9) {
count++;
if (count < 1000) {
continue;
}
}
}
} while (!CanPlaceMonster(position));

Check warning on line 403 in Source/monster.cpp

View workflow job for this annotation

GitHub Actions / build

uninitialized local variable 'position' used

return position;
}

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

0 comments on commit 2d9ab68

Please sign in to comment.