diff options
author | Mattes D <github@xoft.cz> | 2013-10-18 12:41:43 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2013-10-18 12:41:43 +0200 |
commit | 8bba2b02a132d236703835d93ab18e09e0ea7230 (patch) | |
tree | e637945c6eb845e82c4f2790c07c6fd82a1f79ef /source/ChunkMap.cpp | |
parent | APIDump: Renamed output for helper stuff. (diff) | |
parent | Removed reading default values from settings.ini for worlds. (diff) | |
download | cuberite-8bba2b02a132d236703835d93ab18e09e0ea7230.tar cuberite-8bba2b02a132d236703835d93ab18e09e0ea7230.tar.gz cuberite-8bba2b02a132d236703835d93ab18e09e0ea7230.tar.bz2 cuberite-8bba2b02a132d236703835d93ab18e09e0ea7230.tar.lz cuberite-8bba2b02a132d236703835d93ab18e09e0ea7230.tar.xz cuberite-8bba2b02a132d236703835d93ab18e09e0ea7230.tar.zst cuberite-8bba2b02a132d236703835d93ab18e09e0ea7230.zip |
Diffstat (limited to 'source/ChunkMap.cpp')
-rw-r--r-- | source/ChunkMap.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/source/ChunkMap.cpp b/source/ChunkMap.cpp index 3c098fdfe..c3bd5f33d 100644 --- a/source/ChunkMap.cpp +++ b/source/ChunkMap.cpp @@ -12,6 +12,8 @@ #include "BlockArea.h" #include "PluginManager.h" #include "Entities/TNTEntity.h" +#include "MobCensus.h" +#include "MobSpawner.h" #ifndef _WIN32 #include <cstdlib> // abs @@ -2152,6 +2154,32 @@ void cChunkMap::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ) +void cChunkMap::CollectMobCensus(cMobCensus& a_ToFill) +{ + cCSLock Lock(m_CSLayers); + for (cChunkLayerList::iterator itr = m_Layers.begin(); itr != m_Layers.end(); ++itr) + { + (*itr)->CollectMobCensus(a_ToFill); + } // for itr - m_Layers +} + + + + + + +void cChunkMap::SpawnMobs(cMobSpawner& a_MobSpawner) +{ + cCSLock Lock(m_CSLayers); + for (cChunkLayerList::iterator itr = m_Layers.begin(); itr != m_Layers.end(); ++itr) + { + (*itr)->SpawnMobs(a_MobSpawner); + } // for itr - m_Layers +} + + + + void cChunkMap::Tick(float a_Dt) { @@ -2310,6 +2338,38 @@ cChunk * cChunkMap::cChunkLayer::FindChunk(int a_ChunkX, int a_ChunkZ) +void cChunkMap::cChunkLayer::CollectMobCensus(cMobCensus& a_ToFill) +{ + for (int i = 0; i < ARRAYCOUNT(m_Chunks); i++) + { + // We do count every Mobs in the world. But we are assuming that every chunk not loaded by any client + // doesn't affect us. Normally they should not have mobs because every "too far" mobs despawn + // If they have (f.i. when player disconnect) we assume we don't have to make them live or despawn + if ((m_Chunks[i] != NULL) && m_Chunks[i]->IsValid() && m_Chunks[i]->HasAnyClients()) + { + m_Chunks[i]->CollectMobCensus(a_ToFill); + } + } // for i - m_Chunks[] +} + + + + + + +void cChunkMap::cChunkLayer::SpawnMobs(cMobSpawner& a_MobSpawner) +{ + for (int i = 0; i < ARRAYCOUNT(m_Chunks); i++) + { + // We only spawn close to players + if ((m_Chunks[i] != NULL) && m_Chunks[i]->IsValid() && m_Chunks[i]->HasAnyClients()) + { + m_Chunks[i]->SpawnMobs(a_MobSpawner); + } + } // for i - m_Chunks[] +} + + void cChunkMap::cChunkLayer::Tick(float a_Dt) { |