Cuberite
A lightweight, fast and extensible game server for Minecraft
MobCensus.cpp
Go to the documentation of this file.
1 
2 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
3 
4 #include "MobCensus.h"
5 
6 
7 
8 
9 
10 void cMobCensus::CollectMob(cMonster & a_Monster, cChunk & a_Chunk, double a_Distance)
11 {
12  m_ProximityCounter.CollectMob(a_Monster, a_Chunk, a_Distance);
14 }
15 
16 
17 
18 
19 
21 {
22  const int ratio = 319; // This should be 256 as we are only supposed to take account from chunks that are in 17 x 17 from a player
23  // but for now, we use all chunks loaded by players. that means 19 x 19 chunks. That's why we use 256 * (19 * 19) / (17 * 17) = 319
24  // MG TODO : code the correct count
25  const auto MobCap = ((GetCapMultiplier(a_MobFamily) * GetNumChunks()) / ratio);
26  return (MobCap < m_MobFamilyCollecter.GetNumberOfCollectedMobs(a_MobFamily));
27 }
28 
29 
30 
31 
32 
34 {
35  switch (a_MobFamily)
36  {
37  case cMonster::mfHostile: return 79;
38  case cMonster::mfPassive: return 11;
39  case cMonster::mfAmbient: return 16;
40  case cMonster::mfWater: return 5;
42  {
43  break;
44  }
45  }
46  UNREACHABLE("Unsupported mob family");
47 }
48 
49 
50 
51 
52 
54 {
55  m_EligibleForSpawnChunks.insert(&a_Chunk);
56 }
57 
58 
59 
60 
61 
63 {
64  return static_cast<int>(m_EligibleForSpawnChunks.size());
65 }
66 
67 
68 
69 
70 
72 {
73  return m_ProximityCounter;
74 }
75 
76 
77 
78 
79 
81 {
86 }
87 
88 
89 
90 
91 
#define UNREACHABLE(x)
Definition: Globals.h:288
#define LOGD
Definition: LoggerSimple.h:83
Definition: Chunk.h:36
bool IsCapped(cMonster::eFamily a_MobFamily)
Returns true if the family is capped (i.e.
Definition: MobCensus.cpp:20
int GetNumChunks()
Returns the number of chunks that are elligible for spawning (for now, the loaded,...
Definition: MobCensus.cpp:62
cMobProximityCounter & GetProximityCounter(void)
Returns the nested proximity counter.
Definition: MobCensus.cpp:71
static int GetCapMultiplier(cMonster::eFamily a_MobFamily)
Returns the cap multiplier value of the given monster family.
Definition: MobCensus.cpp:33
void CollectSpawnableChunk(cChunk &a_Chunk)
Definition: MobCensus.cpp:53
std::set< cChunk * > m_EligibleForSpawnChunks
Definition: MobCensus.h:48
cMobProximityCounter m_ProximityCounter
Definition: MobCensus.h:45
cMobFamilyCollecter m_MobFamilyCollecter
Definition: MobCensus.h:46
void CollectMob(cMonster &a_Monster, cChunk &a_Chunk, double a_Distance)
Collect a mob - its distance to player, its family ...
Definition: MobCensus.cpp:10
void Logd(void)
log the results of census to server console
Definition: MobCensus.cpp:80
int GetNumberOfCollectedMobs(cMonster::eFamily a_Family)
void CollectMob(cMonster &a_Monster)
void CollectMob(cEntity &a_Monster, cChunk &a_Chunk, double a_Distance)
@ mfNoSpawn
Definition: Monster.h:35
@ mfAmbient
Definition: Monster.h:32
@ mfWater
Definition: Monster.h:33
@ mfPassive
Definition: Monster.h:31
@ mfHostile
Definition: Monster.h:30