1
0

Adding mob census (sorry this is a big commit as work was done before git integration i couldn't split it more)

This commit is contained in:
mgueydan
2013-09-07 22:19:56 +02:00
parent e844612503
commit d2eb58f277
14 changed files with 622 additions and 0 deletions

View File

@@ -30,6 +30,8 @@
#include "PluginManager.h"
#include "Blocks/BlockHandler.h"
#include "Simulator/FluidSimulator.h"
#include "MobCensus.h"
#include <json/json.h>
@@ -429,6 +431,43 @@ void cChunk::Stay(bool a_Stay)
void cChunk::CollectMobCensus(cMobCensus& toFill)
{
toFill.CollectSpawnableChunck(*this);
std::list<const Vector3d*> playerPositions;
cPlayer* currentPlayer;
for (cClientHandleList::iterator itr = m_LoadedByClient.begin(), end = m_LoadedByClient.end(); itr != end; ++itr)
{
currentPlayer = (*itr)->GetPlayer();
playerPositions.push_back(&(currentPlayer->GetPosition()));
}
Vector3d currentPosition;
for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr)
{
//LOGD("Counting entity #%i (%s)", (*itr)->GetUniqueID(), (*itr)->GetClass());
if ((*itr)->IsMob())
{
try
{
cMonster& Monster = (cMonster&)(**itr);
currentPosition = Monster.GetPosition();
for (std::list<const Vector3d*>::const_iterator itr2 = playerPositions.begin(); itr2 != playerPositions.end(); itr2 ++)
{
toFill.CollectMob(Monster,*this,(currentPosition-**itr2).SqrLength());
}
}
catch (std::bad_cast& e)
{
LOGD("Something wrong happend I'm collecting an entity that respond 'true' to IsMob() but are not castable in cMonster - No Action");
}
}
} // for itr - m_Entitites[]
}
void cChunk::Tick(float a_Dt)
{