예제 #1
0
int CScriptBind_Boids::CanPickup(IFunctionHandler *pH, SmartScriptTable flockEntity, SmartScriptTable boidEntity)
{
	CFlock* flock = GetFlock(flockEntity);
	IEntity* pBoidEntity = GetEntity(boidEntity);

	if (flock != NULL && pBoidEntity != NULL)
	{
		CBoidObject* pBoidObject = NULL;

		for (int i = 0; i < flock->GetBoidsCount(); ++i)
		{
			if (flock->GetBoid(i)->GetId() == pBoidEntity->GetId())
			{
				pBoidObject = flock->GetBoid(i);
				break;
			}
		}

		if (pBoidObject != NULL)
		{
			SBoidContext bc;
			flock->GetBoidSettings(bc);

			return pH->EndFunction((pBoidObject->IsDead() && bc.bPickableWhenDead) || (!pBoidObject->IsDead() && bc.bPickableWhenAlive));
		}
	}
	return pH->EndFunction(0);
}
예제 #2
0
파일: Flock.cpp 프로젝트: hybridsix/Code
void CFlock::UpdateAvgBoidPos(float dt)
{
	m_lastUpdatePosTimePassed += dt;
	if(m_lastUpdatePosTimePassed < 0.5f + Boid::Frand()/4.f)
		return;

	m_lastUpdatePosTimePassed = 0;

	m_avgBoidPos.zero();
	int n=0;

	for (Boids::iterator it = m_boids.begin(),itEnd = m_boids.end(); it != itEnd; ++it)
	{
		CBoidObject* pBoid = (*it);
		if(pBoid && !pBoid->IsDead())
		{
			m_avgBoidPos += pBoid->GetPos();
			++n;
		}
	}
	if(n)
		m_avgBoidPos /= float(n);

}