2013-09-07 16:19:56 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class cChunk;
|
|
|
|
class cEntity;
|
|
|
|
|
|
|
|
|
|
|
|
// This class is used to collect, for each Mob, what is the distance of the closest player
|
|
|
|
// it was first being designed in order to make mobs spawn / despawn / act
|
|
|
|
// as the behaviour and even life of mobs depends on the distance to closest player
|
|
|
|
class cMobProximityCounter
|
|
|
|
{
|
|
|
|
protected :
|
|
|
|
// structs used for later maps (see m_MonsterToDistance and m_DistanceToMonster)
|
|
|
|
struct sDistanceAndChunk
|
|
|
|
{
|
2015-05-09 05:16:56 -04:00
|
|
|
sDistanceAndChunk(double a_Distance, cChunk & a_Chunk) : m_Distance(a_Distance), m_Chunk(&a_Chunk) {}
|
2013-09-07 16:19:56 -04:00
|
|
|
double m_Distance;
|
2015-05-09 05:16:56 -04:00
|
|
|
cChunk * m_Chunk;
|
2013-09-07 16:19:56 -04:00
|
|
|
};
|
|
|
|
struct sMonsterAndChunk
|
|
|
|
{
|
2015-05-09 05:16:56 -04:00
|
|
|
sMonsterAndChunk(cEntity & a_Monster, cChunk & a_Chunk) : m_Monster(a_Monster), m_Chunk(a_Chunk) {}
|
|
|
|
cEntity & m_Monster;
|
|
|
|
cChunk & m_Chunk;
|
2013-09-07 16:19:56 -04:00
|
|
|
};
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
public :
|
2015-05-09 05:16:56 -04:00
|
|
|
typedef std::map<cEntity *, sDistanceAndChunk> tMonsterToDistance;
|
2014-07-19 08:53:41 -04:00
|
|
|
typedef std::multimap<double, sMonsterAndChunk> tDistanceToMonster;
|
2013-09-07 16:19:56 -04:00
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
protected :
|
2013-09-07 16:19:56 -04:00
|
|
|
// this map is filled during collection phase, it will be later transformed into DistanceToMonster
|
|
|
|
tMonsterToDistance m_MonsterToDistance;
|
|
|
|
|
|
|
|
// this map is generated after collection phase, in order to access monster by distance to player
|
|
|
|
tDistanceToMonster m_DistanceToMonster;
|
|
|
|
|
2013-09-08 06:25:07 -04:00
|
|
|
// this are the collected chunks. Used to determinate the number of elligible chunk for spawning.
|
2013-09-07 16:19:56 -04:00
|
|
|
std::set<cChunk*> m_EligibleForSpawnChunks;
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
protected :
|
2013-09-07 16:19:56 -04:00
|
|
|
// transform monsterToDistance map (that was usefull for collecting) into distanceToMonster
|
|
|
|
// that will be usefull for picking up.
|
|
|
|
void convertMaps();
|
|
|
|
|
|
|
|
public :
|
2013-09-08 06:25:07 -04:00
|
|
|
// count a mob on a specified chunk with specified distance to an unkown player
|
2013-09-07 16:19:56 -04:00
|
|
|
// if the distance is shortest than the one collected, this become the new closest
|
2013-09-08 06:25:07 -04:00
|
|
|
// distance and the chunk become the "hosting" chunk (that is the one that will perform the action)
|
2015-05-09 05:16:56 -04:00
|
|
|
void CollectMob(cEntity & a_Monster, cChunk & a_Chunk, double a_Distance);
|
2013-09-07 16:19:56 -04:00
|
|
|
|
|
|
|
// return the mobs that are within the range of distance of the closest player they are
|
|
|
|
// that means that if a mob is 30 m from a player and 150 m from another one. It will be
|
|
|
|
// in the range [0..50] but not in [100..200]
|
2014-07-19 09:23:40 -04:00
|
|
|
struct sIterablePair
|
|
|
|
{
|
2013-09-07 16:19:56 -04:00
|
|
|
tDistanceToMonster::const_iterator m_Begin;
|
|
|
|
tDistanceToMonster::const_iterator m_End;
|
|
|
|
int m_Count;
|
|
|
|
};
|
|
|
|
sIterablePair getMobWithinThosesDistances(double a_DistanceMin, double a_DistanceMax);
|
|
|
|
|
|
|
|
};
|