From db15240506d2e9fff9e854beaef22034020daa89 Mon Sep 17 00:00:00 2001 From: killerwife Date: Fri, 8 Nov 2024 20:53:02 +0100 Subject: [PATCH] SpawnGroup: Make mincount also respond to other randomization types of entry --- src/game/Maps/SpawnGroup.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/game/Maps/SpawnGroup.cpp b/src/game/Maps/SpawnGroup.cpp index d9fd0ca3f2..1577c58347 100644 --- a/src/game/Maps/SpawnGroup.cpp +++ b/src/game/Maps/SpawnGroup.cpp @@ -113,9 +113,6 @@ uint32 SpawnGroup::GetEligibleEntry(std::map& existingEntries, s auto itr = minEntries.begin(); std::advance(itr, urand(0, minEntries.size() - 1)); uint32 entry = (*itr).first; - --(*itr).second; - if ((*itr).second == 0) - minEntries.erase(itr); return entry; } @@ -269,7 +266,7 @@ void SpawnGroup::Spawn(bool force) ++itr; } - eligibleGuids.resize(m_entry.MaxCount - m_objects.size()); // now we have final count for processing + eligibleGuids.resize(std::min(eligibleGuids.size(), m_entry.MaxCount - m_objects.size())); // now we have final count for processing auto pickCreatureEntry = [&](const SpawnGroupDbGuids* guids) -> uint32 { @@ -299,6 +296,23 @@ void SpawnGroup::Spawn(bool force) return entry; }; + auto eraseEntry = [&](uint32 entry) + { + if (entry) + { + if (validEntries[entry]) + --validEntries[entry]; + + auto itr = minEntries.find(entry); + if (itr != minEntries.end()) + { + (*itr).second -= 1; + if ((*itr).second == 0) + minEntries.erase(itr); + } + } + }; + // pick static and random entry first in dungeons so spawn group logic can decide after if (m_map.IsDungeon() && GetObjectTypeId() == TYPEID_UNIT) { @@ -308,8 +322,7 @@ void SpawnGroup::Spawn(bool force) { uint32 entry = pickCreatureEntry(data); m_chosenEntries[data->DbGuid] = entry; - if (entry && validEntries[entry]) - --validEntries[entry]; + eraseEntry(entry); } } for (auto data : eligibleGuids) @@ -318,8 +331,7 @@ void SpawnGroup::Spawn(bool force) { uint32 entry = pickCreatureEntry(data); m_chosenEntries[data->DbGuid] = entry; - if (entry && validEntries[entry]) - --validEntries[entry]; + eraseEntry(entry); } } } @@ -337,8 +349,7 @@ void SpawnGroup::Spawn(bool force) entry = pickCreatureEntry(*itr); else // GOs always pick random entry entry = pickGoEntry(*itr); - if (entry && validEntries[entry]) - --validEntries[entry]; + eraseEntry(entry); } float x, y;