Skip to content

Commit

Permalink
Cleaned up the distribution logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnchyDev committed Oct 21, 2023
1 parent 2f1a90d commit 07a9c17
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/ToSMapMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,14 @@ Creature* ToSMapManager::SpawnNPC(uint32 entry, Map* map, Position* position)

return map->SummonCreature(entry, *position);
}

double ToSMapManager::LinearDistribution(double min, double max, double count, double index)
{
double min = -4;
double max = 4;
double total = abs(min) + abs(max);

double amount = total / count;

return (min + (amount * index) + (amount / 2.0));
}
1 change: 1 addition & 0 deletions src/ToSMapMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ToSMapManager
std::vector<ToSRewardTemplate>* GetRewardTemplates(uint32 rewardId);
std::vector<uint32> GetSubGroups(uint32 groupId);
Creature* SpawnNPC(uint32 entry, Map* map, Position* position);
double LinearDistribution(double min, double max, double count, double index);
public:
std::unordered_map<uint32, ToSWaveTemplate> WaveTemplates;
std::unordered_map<uint32, ToSEnemyGroup> EnemyGroups;
Expand Down
10 changes: 2 additions & 8 deletions src/scripts/ToSInstanceScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,14 @@ void ToSInstanceScript::SpawnNextWave(ToSWaveTemplate* waveTemplate = nullptr)
CleanupCreatures();
ApplyCursesToPlayers();

double min = -4;
double max = 4;
double total = abs(min) + abs(max);

double count = enemies.size();
double amount = total / count;

uint32 i = 0;

for (auto it = enemies.begin(); it != enemies.end(); ++it)
{
auto enemy = (*it);

auto diff = (min + (amount * i) + (amount / 2.0));
auto diff = sToSMapMgr->LinearDistribution(-4, 4, enemies.size(), i);

LOG_INFO("module", "Spawning at {}:{}", diff, combatantPosStart->GetPositionY() + diff);
Position tempPos(combatantPosStart->GetPositionX(), combatantPosStart->GetPositionY() + diff, combatantPosStart->GetPositionZ(), combatantPosStart->GetOrientation());

Expand Down

0 comments on commit 07a9c17

Please sign in to comment.