From 6890ec3902b2248abe7e28dc3d7f458ac6f85bcf Mon Sep 17 00:00:00 2001 From: obligaron Date: Sat, 18 Jan 2025 10:34:36 +0100 Subject: [PATCH] Decouple reserved golem slots from max players --- Source/monster.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 4a57871c3..792583763 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -80,6 +80,9 @@ constexpr int HellToHitBonus = 120; constexpr int NightmareAcBonus = 50; constexpr int HellAcBonus = 80; +/** @brief Reserved some entries in @Monster for golems. For vanilla compatibility, this must remain 4. */ +constexpr int ReservedMonsterSlotsForGolems = 4; + /** Tracks which missile files are already loaded */ size_t totalmonsters; int monstimgtot; @@ -3518,7 +3521,7 @@ void WeakenNaKrul() void InitGolems() { if (!setlevel) { - for (int i = 0; i < MAX_PLRS; i++) + for (int i = 0; i < ReservedMonsterSlotsForGolems; i++) AddMonster(GolemHoldingCell, Direction::South, 0, false); } } @@ -3588,7 +3591,7 @@ tl::expected SetMapMonsters(const uint16_t *dunData, Point st { RETURN_IF_ERROR(AddMonsterType(MT_GOLEM, PLACE_SPECIAL)); if (setlevel) - for (int i = 0; i < MAX_PLRS; i++) + for (int i = 0; i < ReservedMonsterSlotsForGolems; i++) AddMonster(GolemHoldingCell, Direction::South, 0, false); WorldTileSize size = GetDunSize(dunData); @@ -4012,7 +4015,7 @@ void GolumAi(Monster &golem) void DeleteMonsterList() { - for (int i = 0; i < MAX_PLRS; i++) { + for (int i = 0; i < ReservedMonsterSlotsForGolems; i++) { Monster &golem = Monsters[i]; if (!golem.isInvalid) continue; @@ -4023,7 +4026,7 @@ void DeleteMonsterList() golem.isInvalid = false; } - for (size_t i = MAX_PLRS; i < ActiveMonsterCount;) { + for (size_t i = ReservedMonsterSlotsForGolems; i < ActiveMonsterCount;) { if (Monsters[ActiveMonsters[i]].isInvalid) { if (pcursmonst == static_cast(ActiveMonsters[i])) // Unselect monster if player highlighted it pcursmonst = -1;