diff options
Diffstat (limited to '')
-rw-r--r-- | source/MobCensus.cpp | 87 |
1 files changed, 63 insertions, 24 deletions
diff --git a/source/MobCensus.cpp b/source/MobCensus.cpp index 612f25916..67b154404 100644 --- a/source/MobCensus.cpp +++ b/source/MobCensus.cpp @@ -5,7 +5,9 @@ -cMobCensus::tCapMultipliersMap cMobCensus::CapMultiplierInitializerBeforeCx11() + + +cMobCensus::tCapMultipliersMap cMobCensus::CapMultiplierInitializerBeforeCx11(void) { std::map<cMonster::eFamily,int> toReturn; toReturn[cMonster::mfHostile] = 79; @@ -15,7 +17,11 @@ cMobCensus::tCapMultipliersMap cMobCensus::CapMultiplierInitializerBeforeCx11() return toReturn; } -cMobCensus::tMobSpawnRate cMobCensus::MobSpawnRateInitializerBeforeCx11() + + + + +cMobCensus::tMobSpawnRate cMobCensus::MobSpawnRateInitializerBeforeCx11(void) { std::map<cMonster::eFamily,int> toReturn; toReturn[cMonster::mfHostile] = 1; @@ -25,65 +31,98 @@ cMobCensus::tMobSpawnRate cMobCensus::MobSpawnRateInitializerBeforeCx11() return toReturn; } -cMobCensus::tCapMultipliersMap& cMobCensus::m_CapMultipliers() + + + + +cMobCensus::tCapMultipliersMap & cMobCensus::m_CapMultipliers(void) { - static tCapMultipliersMap* value = new tCapMultipliersMap(CapMultiplierInitializerBeforeCx11()); + // TODO: This memory leaks: + static tCapMultipliersMap * value = new tCapMultipliersMap(CapMultiplierInitializerBeforeCx11()); return *value; } -cMobCensus::tMobSpawnRate& cMobCensus::m_SpawnRate() + + + + +cMobCensus::tMobSpawnRate & cMobCensus::m_SpawnRate(void) { + // TODO: This memory leaks: static tMobSpawnRate* value = new tMobSpawnRate(MobSpawnRateInitializerBeforeCx11()); return *value; } -cMobCensus::cMobCensus() -{ -} -void cMobCensus::CollectMob(cMonster& a_Monster, cChunk& a_Chunk, double a_Distance) + + + +void cMobCensus::CollectMob(cMonster & a_Monster, cChunk & a_Chunk, double a_Distance) { m_ProximityCounter.CollectMob(a_Monster,a_Chunk,a_Distance); m_MobFamilyCollecter.CollectMob(a_Monster); } -bool cMobCensus::isCaped(cMonster::eFamily a_MobFamily) + + + + +bool cMobCensus::IsCapped(cMonster::eFamily a_MobFamily) { bool toReturn = true; const int ratio = 319; // this should be 256 as we are only supposed to take account from chunks that are in 17x17 from a player - // but for now, we use all chunks loaded by players. that means 19 x 19 chucks. That's why we use 256 * (19*19) / (17*17) = 319 + // 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 // MG TODO : code the correct count tCapMultipliersMap::const_iterator capMultiplier = m_CapMultipliers().find(a_MobFamily); - if ( + if ( (capMultiplier != m_CapMultipliers().end()) && - (capMultiplier->second * getChunkNb()) / ratio >= m_MobFamilyCollecter.getNumberOfCollectedMobs(a_MobFamily) - ) + ((capMultiplier->second * GetNumChunks()) / ratio >= m_MobFamilyCollecter.GetNumberOfCollectedMobs(a_MobFamily)) + ) { - toReturn = false; + return false; } - return toReturn; + return true; } -void cMobCensus::CollectSpawnableChunk(cChunk& a_Chunk) + + + + +void cMobCensus::CollectSpawnableChunk(cChunk & a_Chunk) { m_EligibleForSpawnChunks.insert(&a_Chunk); } -int cMobCensus::getChunkNb() + + + + +int cMobCensus::GetNumChunks(void) { return m_EligibleForSpawnChunks.size(); } -cMobProximityCounter& cMobCensus::getProximityCounter() + + + + +cMobProximityCounter & cMobCensus::GetProximityCounter(void) { return m_ProximityCounter; } -void cMobCensus::logd() + + + +void cMobCensus::Logd() { - LOGD((std::string("Hostile mobs : %d") + (isCaped(cMonster::mfHostile)?"(capped)":"")).c_str(),m_MobFamilyCollecter.getNumberOfCollectedMobs(cMonster::mfHostile)); - LOGD((std::string("Ambiant mobs : %d") + (isCaped(cMonster::mfAmbient)?"(capped)":"")).c_str(),m_MobFamilyCollecter.getNumberOfCollectedMobs(cMonster::mfAmbient)); - LOGD((std::string("Water mobs : %d") + (isCaped(cMonster::mfWater)? "(capped)":"")).c_str(),m_MobFamilyCollecter.getNumberOfCollectedMobs(cMonster::mfWater)); - LOGD((std::string("Passive mobs : %d") + (isCaped(cMonster::mfPassive)?"(capped)":"")).c_str(),m_MobFamilyCollecter.getNumberOfCollectedMobs(cMonster::mfPassive)); + LOGD("Hostile mobs : %d %s", m_MobFamilyCollecter.GetNumberOfCollectedMobs(cMonster::mfHostile), IsCapped(cMonster::mfHostile) ? "(capped)" : ""); + LOGD("Ambient mobs : %d %s", m_MobFamilyCollecter.GetNumberOfCollectedMobs(cMonster::mfAmbient), IsCapped(cMonster::mfAmbient) ? "(capped)" : ""); + LOGD("Water mobs : %d %s", m_MobFamilyCollecter.GetNumberOfCollectedMobs(cMonster::mfWater), IsCapped(cMonster::mfWater) ? "(capped)" : ""); + LOGD("Passive mobs : %d %s", m_MobFamilyCollecter.GetNumberOfCollectedMobs(cMonster::mfPassive), IsCapped(cMonster::mfPassive) ? "(capped)" : ""); } + + + + |