#include "CBombObject.h"
#include "CObjectManager.h"
#include "CParticleManager.h"
#include "CPlayerObject.h"
#include "CExplosionObject.h"
#include "CGame.h"
#include "CAIBombDangerZone.h"

//----------------------------------------------------------------//
//	Constructor/Deconstructor
//----------------------------------------------------------------//

CBombObject::CBombObject()
{


}

CBombObject::~CBombObject()
{



}

void CBombObject::Init(STRINGC fn, int x, int y, int strength, int ownerID)
{

	this->typ=typBomb;		//IMPORTANT!!!

	m_Animation.Init("./objects/bomb/bomb.txt 2");
	CImage* Img = m_Animation.getCurrentImage();
	
	//You MUST set these to zero before setting the bounding box!!!
	m_Position.x=0;	
	m_Position.y=0;
		

	//setup bounding box.
	//For the player we're going to make it the bottom half of the image	
	SetRect(&m_boundingBox,0,0,Img->getWidth(),Img->getHeight());

	//Ok the bounding box is set. Now whenever we move the player we move the bounding box. And everything takes care of itself.
	//(this is done in the CGameObject's default method of setX and setY)

	setX(x);
	setY(y);

	m_Life=250;

	m_OwnerID		= ownerID;
	m_Strength		= strength;

	//Create an AI danger zone! sCary!

	CAIBombDangerZone* dangerZone = (CAIBombDangerZone*)g_ObjectManager.CreateObject(typAIBombDangerZone);
	dangerZone->init();
	
	dangerZone->setStrength(5);

	dangerZone->setX(x + g_Game.getTileSize()/2);
	dangerZone->setY(y + g_Game.getTileSize()/2);	
}

//----------------------------------------------------------------//
//	Draw/Update
//----------------------------------------------------------------//

void CBombObject::Draw()
{
	CImage* Img = m_Animation.getCurrentImage();
	
	if(Img)
	{			
		g_GraphicSystem.DrawCImage(Img, m_Position.x, m_Position.y);
	}

//	this->drawBoundingBox();
	

}

void CBombObject::Update()
{

	m_Life--;

	m_Animation.Update();

	if(m_Life==0)
	{	
		explode();

	}

	

}

void CBombObject::explode()
{
	//check if our player is still alive (almost always yes)
	//and tell him we are blowing up (so that he can place another bomb)

	CPlayerObject* owner = (CPlayerObject*)g_ObjectManager.GetObjectID(m_OwnerID);
	if(owner)
	{
		owner->modifyCurrentBombs(-1);
	}


	g_ObjectManager.RemoveObjectSafe(this->ID);
	//g_ParticleManager.Create4WayExplosion(getX(), getY(), (m_Strength*g_Game.getTileSize()) + (g_Game.getTileSize()/2) );
		
	CExplosionObject* exp = (CExplosionObject*) g_ObjectManager.CreateObject(typExplosion);
	exp->Init(this->getX() , this->getY(), 0 ,1 , 5);
	exp = (CExplosionObject*) g_ObjectManager.CreateObject(typExplosion);
	exp->Init(this->getX() , this->getY(), 0 ,-1 , 5);

	exp = (CExplosionObject*) g_ObjectManager.CreateObject(typExplosion);
	exp->Init(this->getX() , this->getY(), 1 ,0 , 5);

	exp = (CExplosionObject*) g_ObjectManager.CreateObject(typExplosion);
	exp->Init(this->getX() , this->getY(), -1 ,0 , 5);


}


void CBombObject::Collision(CGameObject* obj)
{

	//Block doesn do much. It should blowup if it gets hit with fire. But we dont have 
	//a proper way of removing an object from the game.

	switch(obj->typ)
	{

	case typPlayer:
	
		
		break;

	case typExplosion:

		//explode();

		

		break;

	default:

		break;

	}	

}

//----------------------------------------------------------------//
//	Notify Owner when bomb is exploding
//----------------------------------------------------------------//

void CBombObject::notifyOwner()
{
	//m_Owner->
}



