//@STATE=嶌惉拞
//@DESCRIPTION ---------------------------------------------------------------
// Effects.cpp: Effects 僋儔僗偺僀儞僾儕儊儞僥乕僔儑儞
//	棜楌丗
// $Log: Effects.cpp,v $
// Revision 1.1  2001/10/28 21:40:35  fujiwara
// DLL偵暘妱
//
// Revision 1.6  2001/07/09 20:30:08  fujiwara
// 椺奜張棟偺慻傒崬傒
//
// Revision 1.5  2001/07/01 21:30:33  fujiwara
// 儊儌儕儕乕僋僠僃僢僋尒捈偟
//
// Revision 1.4  2001/05/13 20:04:23  fujiwara
// 儊儌儕乕儕乕僋偑敪惗偟偨偺偱庢傝彍偔丅
// 帺抏偺僒僂儞僪僥僗僩
//
// Revision 1.3  2001/05/12 08:17:25  fujiwara
// 堦斒曐岇堘斀偑婲偙傞BUG廋惓
//
// Revision 1.2  2001/05/12 00:50:48  fujiwara
// 俠倁俽傪摫擖偟丄儘僌昞帵傪捛壛
//
//@DESCRIPTION_END -----------------------------------------------------------
//@AUTHOR=S.F.
///////////////////////////////////////////////////////////////////////////////

#pragma warning( disable : 4786 )	//STL偺寈崘奜偟
// 儊儌儕乕儕乕僋専弌梡
#include "sfdebug.h"

#include <string>
#include <vector>
#include <memory>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <map>

#include "stdio.h"
#include "math.h"

#include "exception.h"
#include "singleton.h"
#include "system.h"
#include "console.h"
#include "input.h"
#include "sound.h"

#include "Obj.h"
#include "Obj2D.h"
#include "Obj3D.h"
#include "Obj3DL.h"
#include "ObjRectangle.h"
#include "ObjQuadrangle.h"

#include "Background.h"
#include "Scene.h"
#include "main.h"

#include "character.h"
#include "Hit.h"
#include "MyShip.h"
#include "Game.h"
#include "Effects.h"
#include "explosion.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

using namespace sf::application::effect;
using namespace sf::application;


IMPLEMENT_SINGLETON(Effects,Effects)

const Effects::LoaderFuncPtr Effects::mpLoaders[MAX_TYPE] = 
{	&Explosion::load
};

const int Effects::INIT_EFFECTS = 16;

const Effects::CreateFuncPtr Effects::mpFunctions[MAX_TYPE] = 
{	&Explosion::create };

// 僐儞僗僩儔僋僞 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
Effects::Effects()
{
	int i;
	mCount = 0;
	mMax = INIT_EFFECTS;
	
	for(i = 0;i < MAX_EFFECTS;i++){
		mpEffects[i] = NULL;
	}

}// Effects()

// 僨僗僩儔僋僞 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
Effects::~Effects()
{
	int i;
	for(i = 0;i < MAX_EFFECTS;i++)
	{
		if(mpEffects[i]){
			delete mpEffects[i];
			mpEffects[i] = NULL;
		}
	}
}// ~Effects()

// 弶婜壔 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void Effects::initialize(){
	
	int i;
	for(i = 0;i < MAX_EFFECTS;i++)
	{
		if(mpEffects[i]){
			delete mpEffects[i];
			mpEffects[i] = NULL;
		}
	}

	// 價僢僩儅僢僾偺儘乕僪
	for(i = 0;i < MAX_TYPE;i++){
		(*mpLoaders[i])();
	}
	
	mCount = 0;
}// initialize()

// 抏偺堏摦 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void Effects::move(void)
{
	int count = 0;
	for(int i = 0;i < MAX_EFFECTS;i++)
	{
		if(mpEffects[i]){
			mpEffects[i]->move();
		}
	}
}// move()

// 抏傪惗惉偡傞 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
Character * const Effects::create(const TYPE id,const float x,const float y,const float z,sf::application::scene::Game *pGame,sf::application::Character *pCharacter)
{
	if(id >= MAX_TYPE)
		return NULL;

	if(mCount >= mMax)
		return NULL;
	
	for(int i = 0 ; i < MAX_EFFECTS; i++){
		if(mpEffects[i] == NULL){
			mpEffects[i] = (*mpFunctions[id])(x,y,z,pGame,pCharacter,i);
			mCount++;
			return mpEffects[i];
		}
	}
	return NULL;
}// create()

// 摉傝敾掕 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
const bool Effects::hitCheck(Character * const pDest){
	bool return_ = false;

	for(int i = 0;i < MAX_EFFECTS;i++){
		if(mpEffects[i]){
			if(mpEffects[i]->hitCheck(pDest)){
				mpEffects[i]->hit(pDest);
				pDest->hit(mpEffects[i]);
				return_ = true; 
			};
		}
	}
	return return_;
}// hitCheck(Character * const pDest)

const bool Effects::hitCheck(Characters * const pDest){
	bool return_ = false;

	for(int i = 0;i < MAX_EFFECTS;i++){
		if(mpEffects[i]){
			if(pDest->hitCheck(mpEffects[i]))
				return_ = true;
		}
	}

	return return_;
}// hitCheck(Characters * const pDest)