//@STATE=嶌惉拞
//@DESCRIPTION ---------------------------------------------------------------
// Armys.cpp: Armys 僋儔僗偺僀儞僾儕儊儞僥乕僔儑儞
//	棜楌丗
// $Log: Armys.cpp,v $
// Revision 1.1  2001/10/28 21:40:35  fujiwara
// DLL偵暘妱
//
// Revision 1.4  2001/07/09 20:30:07  fujiwara
// 椺奜張棟偺慻傒崬傒
//
// Revision 1.3  2001/07/01 21:30:33  fujiwara
// 儊儌儕儕乕僋僠僃僢僋尒捈偟
//
// Revision 1.2  2001/07/01 01:03:43  fujiwara
// const 偺尒捈偟
// 攝抲僄僨傿僞偼搑拞宱夁
//
// Revision 1.1  2001/06/03 09:21:26  fujiwara
// 抧忋揋僋儔僗偺捛壛
//
// Revision 1.5  2001/05/13 20:04:23  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偺寈崘奜偟
// 儊儌儕乕儕乕僋専弌梡

// System Includes //

#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"

// Project Includes  //

#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"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include "Armys.h"
#include "DispositionControl.h"
#include "EA01.h"

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


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

IMPLEMENT_SINGLETON(Armys,Armys);
const Armys::LoaderFuncPtr Armys::mpLoaders[MAX_ARMYS_TYPE] = 
{	&EA01::load
};

const int Armys::INIT_ARMYS = 16;

const Armys::CreateFuncPtr Armys::mpFunctions[MAX_ARMYS_TYPE] = 
{	&EA01::create };

const Armys::UnloadFuncPtr Armys::mpUnloadFunc[MAX_ARMYS_TYPE] = 
{	&EA01::unload };

// 僐儞僗僩儔僋僞 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
Armys::Armys()
{
	int i;
	mCount = 0;
	mMax = INIT_ARMYS;
	
	for(i = 0;i < MAX_ARMYS;i++){
		mpArmys[i] = NULL;
	}

}// Armys()

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

// 弶婜壔 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void Armys::initialize(void){
	
	int i;
	for(i = 0;i < MAX_ARMYS;i++)
	{
		if(mpArmys[i]){
			delete mpArmys[i];
			mpArmys[i] = NULL;
		}
	}
	mCount = 0;
}// initialize()

// 抏偺堏摦 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void Armys::move(void)
{
	for(int i = 0;i < MAX_ARMYS;i++)
	{
		if(mpArmys[i]){
			mpArmys[i]->move();
		}
	}
}// move()

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

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

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

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

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

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

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

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

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

void Armys::allBomb(void){
	;
}
