#include "ExplosionBlock.hpp"
#include "Game.hpp"

ExplosionBlock::ExplosionBlock(Game* g):
Block(g, true),
explosionRadius(2.5f)
{
}



bool IsEntityInRadius(Entity* ent, Vector3f Position, float Radius)
{
	return (ent->getPosition()-Position).length()<Radius;
}

void ExplosionBlock::onHit()
{
	manager->markToRemove(this);

	//delete blocks in range:
	std::list<Entity*> Res=manager->FindEntities(boost::bind(IsEntityInRadius, _1, position, explosionRadius));
	for(Entity* ent : Res)
	{
		Block* b = dynamic_cast<Block*>(ent);
		if(b && !b->IsDeleted())
		{
			b->onHit();
		}
	}

	game->AddParticleSystem(new SmokeParticle(position+(cm.max-cm.min)/2));
	game->AddParticleSystem(new FireParticle(position+(cm.max-cm.min)/2, Vector3f(1, 1, 0), 3));
	game->AddParticleSystem(new FireParticle(position+(cm.max-cm.min)/2, Vector3f(1, 0, 0), 1.5));
	game->PlaySound("explosion");
}
