2013-09-07 16:19:56 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "MobProximityCounter.h"
|
|
|
|
|
|
|
|
#include "Entities/Entity.h"
|
|
|
|
#include "Chunk.h"
|
|
|
|
|
|
|
|
void cMobProximityCounter::CollectMob(cEntity& a_Monster, cChunk& a_Chunk, double a_Distance)
|
|
|
|
{
|
|
|
|
// LOGD("Collecting monster %s, with distance %f",a_Monster->GetClass(),a_Distance);
|
|
|
|
tMonsterToDistance::iterator it = m_MonsterToDistance.find(&a_Monster);
|
|
|
|
if (it == m_MonsterToDistance.end())
|
|
|
|
{
|
2013-09-08 06:25:07 -04:00
|
|
|
sDistanceAndChunk newDistanceAndChunk(a_Distance,a_Chunk);
|
|
|
|
std::pair<tMonsterToDistance::iterator,bool> result = m_MonsterToDistance.insert(tMonsterToDistance::value_type(&a_Monster,newDistanceAndChunk));
|
2013-09-08 06:04:20 -04:00
|
|
|
if (!result.second)
|
|
|
|
{
|
2013-09-08 06:20:19 -04:00
|
|
|
ASSERT(!"A collected Monster was not found inside distance map using find(), but insert() said there already is a key for it");
|
2013-09-08 06:04:20 -04:00
|
|
|
}
|
2013-09-07 16:19:56 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-08 06:04:20 -04:00
|
|
|
if (a_Distance < it->second.m_Distance)
|
|
|
|
{
|
|
|
|
it->second.m_Distance = a_Distance;
|
|
|
|
it->second.m_Chunk = a_Chunk;
|
|
|
|
}
|
2013-09-07 16:19:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
m_EligibleForSpawnChunks.insert(&a_Chunk);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMobProximityCounter::convertMaps()
|
|
|
|
{
|
2014-04-18 15:09:44 -04:00
|
|
|
for(tMonsterToDistance::const_iterator itr = m_MonsterToDistance.begin(); itr != m_MonsterToDistance.end(); ++itr)
|
2013-09-07 16:19:56 -04:00
|
|
|
{
|
|
|
|
m_DistanceToMonster.insert(tDistanceToMonster::value_type(itr->second.m_Distance,sMonsterAndChunk(*itr->first,itr->second.m_Chunk)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cMobProximityCounter::sIterablePair cMobProximityCounter::getMobWithinThosesDistances(double a_DistanceMin, double a_DistanceMax)
|
|
|
|
{
|
|
|
|
sIterablePair toReturn;
|
|
|
|
toReturn.m_Count = 0;
|
|
|
|
toReturn.m_Begin = m_DistanceToMonster.end();
|
|
|
|
toReturn.m_End = m_DistanceToMonster.end();
|
|
|
|
|
|
|
|
a_DistanceMin *= a_DistanceMin;// this is because is use square distance
|
|
|
|
a_DistanceMax *= a_DistanceMax;
|
|
|
|
|
|
|
|
if (m_DistanceToMonster.size() <= 0)
|
|
|
|
{
|
|
|
|
convertMaps();
|
|
|
|
}
|
|
|
|
|
2014-04-18 15:09:44 -04:00
|
|
|
for(tDistanceToMonster::const_iterator itr = m_DistanceToMonster.begin(); itr != m_DistanceToMonster.end(); ++itr)
|
2013-09-07 16:19:56 -04:00
|
|
|
{
|
|
|
|
if (toReturn.m_Begin == m_DistanceToMonster.end())
|
|
|
|
{
|
2014-01-24 14:54:13 -05:00
|
|
|
if ((a_DistanceMin == 1) || (itr->first > a_DistanceMin))
|
2013-09-07 16:19:56 -04:00
|
|
|
{
|
|
|
|
toReturn.m_Begin = itr; // this is the first one with distance > a_DistanceMin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toReturn.m_Begin != m_DistanceToMonster.end())
|
|
|
|
{
|
2014-01-24 14:54:13 -05:00
|
|
|
if ((a_DistanceMax != 1) && (itr->first > a_DistanceMax))
|
2013-09-07 16:19:56 -04:00
|
|
|
{
|
|
|
|
toReturn.m_End = itr; // this is just after the last one with distance < a_DistanceMax
|
|
|
|
// Note : if we are not going through this, it's ok, toReturn.m_End will be end();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
toReturn.m_Count ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|