Skip to content

Commit

Permalink
SpawnGroup: Make mincount also respond to other randomization types o…
Browse files Browse the repository at this point in the history
…f entry
  • Loading branch information
killerwife committed Nov 8, 2024
1 parent c0611ab commit db15240
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/game/Maps/SpawnGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ uint32 SpawnGroup::GetEligibleEntry(std::map<uint32, uint32>& 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;
}

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
Expand All @@ -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);
}
}
}
Expand All @@ -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;
Expand Down

0 comments on commit db15240

Please sign in to comment.