Browse Source

Rework PlaceGroup to not use UniqueMonsterPack enum

pull/4977/head
ephphatha 4 years ago committed by Anders Jenbo
parent
commit
ff1e67ae73
  1. 16
      Source/monster.cpp

16
Source/monster.cpp

@ -317,7 +317,7 @@ void PlaceMonster(int i, int mtype, Point position)
InitMonster(Monsters[i], rd, mtype, position); InitMonster(Monsters[i], rd, mtype, position);
} }
void PlaceGroup(int mtype, unsigned num, UniqueMonsterPack uniqueMonsterPack, Monster *leader) void PlaceGroup(int mtype, unsigned num, Monster *leader = nullptr, bool leashed = false)
{ {
unsigned placed = 0; unsigned placed = 0;
@ -331,7 +331,7 @@ void PlaceGroup(int mtype, unsigned num, UniqueMonsterPack uniqueMonsterPack, Mo
int xp; int xp;
int yp; int yp;
if (uniqueMonsterPack != UniqueMonsterPack::None) { if (leader != nullptr) {
int offset = GenerateRnd(8); int offset = GenerateRnd(8);
auto position = leader->position.tile + static_cast<Direction>(offset); auto position = leader->position.tile + static_cast<Direction>(offset);
xp = position.x; xp = position.x;
@ -353,19 +353,19 @@ void PlaceGroup(int mtype, unsigned num, UniqueMonsterPack uniqueMonsterPack, Mo
for (int try2 = 0; j < num && try2 < 100; xp += Displacement(static_cast<Direction>(GenerateRnd(8))).deltaX, yp += Displacement(static_cast<Direction>(GenerateRnd(8))).deltaX) { /// BUGFIX: `yp += Point.y` for (int try2 = 0; j < num && try2 < 100; xp += Displacement(static_cast<Direction>(GenerateRnd(8))).deltaX, yp += Displacement(static_cast<Direction>(GenerateRnd(8))).deltaX) { /// BUGFIX: `yp += Point.y`
if (!CanPlaceMonster({ xp, yp }) if (!CanPlaceMonster({ xp, yp })
|| (dTransVal[xp][yp] != dTransVal[x1][y1]) || (dTransVal[xp][yp] != dTransVal[x1][y1])
|| (uniqueMonsterPack == UniqueMonsterPack::Leashed && (abs(xp - x1) >= 4 || abs(yp - y1) >= 4))) { || (leashed && (abs(xp - x1) >= 4 || abs(yp - y1) >= 4))) {
try2++; try2++;
continue; continue;
} }
PlaceMonster(ActiveMonsterCount, mtype, { xp, yp }); PlaceMonster(ActiveMonsterCount, mtype, { xp, yp });
if (uniqueMonsterPack != UniqueMonsterPack::None) { if (leader != nullptr) {
auto &minion = Monsters[ActiveMonsterCount]; auto &minion = Monsters[ActiveMonsterCount];
minion.maxHitPoints *= 2; minion.maxHitPoints *= 2;
minion.hitPoints = minion.maxHitPoints; minion.hitPoints = minion.maxHitPoints;
minion.intelligence = leader->intelligence; minion.intelligence = leader->intelligence;
if (uniqueMonsterPack == UniqueMonsterPack::Leashed) { if (leashed) {
minion.setLeader(leader); minion.setLeader(leader);
} }
@ -386,7 +386,7 @@ void PlaceGroup(int mtype, unsigned num, UniqueMonsterPack uniqueMonsterPack, Mo
} }
} }
if (uniqueMonsterPack == UniqueMonsterPack::Leashed) { if (leashed) {
leader->packSize = placed; leader->packSize = placed;
} }
} }
@ -3531,7 +3531,7 @@ void PrepareUniqueMonst(Monster &monster, int uniqindex, int miniontype, int bos
} }
if (uniqueMonsterData.monsterPack != UniqueMonsterPack::None) { if (uniqueMonsterData.monsterPack != UniqueMonsterPack::None) {
PlaceGroup(miniontype, bosspacksize, uniqueMonsterData.monsterPack, &monster); PlaceGroup(miniontype, bosspacksize, &monster, uniqueMonsterData.monsterPack == UniqueMonsterPack::Leashed);
} }
if (monster.ai != AI_GARG) { if (monster.ai != AI_GARG) {
@ -3809,7 +3809,7 @@ void InitMonsters()
na = GenerateRnd(2) + 2; na = GenerateRnd(2) + 2;
else else
na = GenerateRnd(3) + 3; na = GenerateRnd(3) + 3;
PlaceGroup(mtype, na, UniqueMonsterPack::None, nullptr); PlaceGroup(mtype, na);
} }
} }
for (int i = 0; i < nt; i++) { for (int i = 0; i < nt; i++) {

Loading…
Cancel
Save