Cuberite
A lightweight, fast and extensible game server for Minecraft
MobProximityCounter.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 class cChunk;
5 class cEntity;
6 
7 
8 // This class is used to collect, for each Mob, what is the distance of the closest player
9 // it was first being designed in order to make mobs spawn / despawn / act
10 // as the behaviour and even life of mobs depends on the distance to closest player
12 {
13 protected :
14  // structs used for later maps (see m_MonsterToDistance and m_DistanceToMonster)
16  {
17  sDistanceAndChunk(double a_Distance, cChunk & a_Chunk) : m_Distance(a_Distance), m_Chunk(&a_Chunk) {}
18  double m_Distance;
20  };
22  {
23  sMonsterAndChunk(cEntity & a_Monster, cChunk & a_Chunk) : m_Monster(a_Monster), m_Chunk(a_Chunk) {}
26  };
27 
28 public :
29  typedef std::map<cEntity *, sDistanceAndChunk> tMonsterToDistance;
30  typedef std::multimap<double, sMonsterAndChunk> tDistanceToMonster;
31 
32 protected :
33  // this map is filled during collection phase, it will be later transformed into DistanceToMonster
35 
36  // this map is generated after collection phase, in order to access monster by distance to player
38 
39  // this are the collected chunks. Used to determinate the number of elligible chunk for spawning.
40  std::set<cChunk*> m_EligibleForSpawnChunks;
41 
42 protected :
43  // transform monsterToDistance map (that was usefull for collecting) into distanceToMonster
44  // that will be usefull for picking up.
45  void convertMaps();
46 
47 public :
48  // count a mob on a specified chunk with specified distance to an unkown player
49  // if the distance is shortest than the one collected, this become the new closest
50  // distance and the chunk become the "hosting" chunk (that is the one that will perform the action)
51  void CollectMob(cEntity & a_Monster, cChunk & a_Chunk, double a_Distance);
52 
53  // return the mobs that are within the range of distance of the closest player they are
54  // that means that if a mob is 30 m from a player and 150 m from another one. It will be
55  // in the range [0..50] but not in [100..200]
57  {
58  tDistanceToMonster::const_iterator m_Begin;
59  tDistanceToMonster::const_iterator m_End;
60  int m_Count;
61  };
62  sIterablePair getMobWithinThosesDistances(double a_DistanceMin, double a_DistanceMax);
63 
64 };
Definition: Chunk.h:36
Definition: Entity.h:76
void CollectMob(cEntity &a_Monster, cChunk &a_Chunk, double a_Distance)
std::map< cEntity *, sDistanceAndChunk > tMonsterToDistance
tDistanceToMonster m_DistanceToMonster
sIterablePair getMobWithinThosesDistances(double a_DistanceMin, double a_DistanceMax)
std::set< cChunk * > m_EligibleForSpawnChunks
tMonsterToDistance m_MonsterToDistance
std::multimap< double, sMonsterAndChunk > tDistanceToMonster
sDistanceAndChunk(double a_Distance, cChunk &a_Chunk)
sMonsterAndChunk(cEntity &a_Monster, cChunk &a_Chunk)
tDistanceToMonster::const_iterator m_Begin
tDistanceToMonster::const_iterator m_End