//@STATE=嶌惉拞
//@DESCRIPTION ---------------------------------------------------------------
// Bullets.cpp: Bullets 僋儔僗偺僀儞僾儕儊儞僥乕僔儑儞
//	棜楌丗
// $Log: EnemyBullets.cpp,v $
// Revision 1.1  2001/10/28 21:40:35  fujiwara
// DLL偵暘妱
//
// Revision 1.5  2001/07/09 20:30:08  fujiwara
// 椺奜張棟偺慻傒崬傒
//
// Revision 1.4  2001/07/01 21:30:33  fujiwara
// 儊儌儕儕乕僋僠僃僢僋尒捈偟
//
// Revision 1.3  2001/07/01 01:03:43  fujiwara
// const 偺尒捈偟
// 攝抲僄僨傿僞偼搑拞宱夁
//
// Revision 1.2  2001/05/13 20:04:23  fujiwara
// 儊儌儕乕儕乕僋偑敪惗偟偨偺偱庢傝彍偔丅
// 帺抏偺僒僂儞僪僥僗僩
//
// Revision 1.1  2001/05/12 21:46:39  fujiwara
// 揋抏僋儔僗怴婯捛壛
//
// Revision 1.4  2001/05/12 08:17:31  fujiwara
// 堦斒曐岇堘斀偑婲偙傞BUG廋惓
//
// Revision 1.3  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 "Enemys.h"
#include "Armys.h"
#include "DispositionControl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include "EnemyBullets.h"
#include "EB01.h"

//////////////////////////////////////////////////////////////////////
// 峔抸/徚柵
//////////////////////////////////////////////////////////////////////


using namespace sf::application::enemy;
using namespace sf::application;

IMPLEMENT_SINGLETON(Bullets,Bullets)

const Bullets::LoaderFuncPtr Bullets::mpLoaders[MAX_BULLET_TYPE]
={	&EB01::load };

const int Bullets::INIT_BULLETS = 16;

const Bullets::CreateFuncPtr Bullets::mpFunctions[MAX_BULLET_TYPE]
 ={	&EB01::create };

const Bullets::UnloadFuncPtr Bullets::mpUnloadFunc[MAX_BULLET_TYPE]
 ={	&EB01::unload };


// 僐儞僗僩儔僋僞 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
Bullets::Bullets()
{
	int i;
	mCount = 0;
	mMax = INIT_BULLETS;
	
	for(i = 0;i < MAX_BULLETS;i++){
		mpBullets[i] = NULL;
	}

}// Bullets()

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

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

	mCount = 0;
}// initialize()

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

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

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

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

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

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

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

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

// 僥僋僗僠儍偺慡奐曻 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void Bullets::unload(void){
	for(int i = 0;i < MAX_BULLET_TYPE;i++)
	{
		(*mpUnloadFunc[i])();
	}
}// unload()

// 僥僋僗僠儍偺儘乕僪 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void Bullets::load(int value){
	// 價僢僩儅僢僾偺儘乕僪
	(*mpLoaders[value])();
}// load()

