
#include "UnitList.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

UnitList::UnitList()
{

	numItems = 0;
}
int UnitList::findUnitTpye(string uit)
{
int j= 0;
	int i = 0;
	//maybey i acn make the conver for sring to char* right in here
	string  temps[2]; //arry to hold data
	
	while (uit[i]!= ',')//'`') //stay in untl you fing the ` at the end riged to find first comma we just want the type
	{
		if (uit[i] != ',')//if found , dont add it to the data and move on to next char
		{
			temps[j] += uit[i]; //add char to temp spot
			i++;
		}
		else
		{
			i++;
			j++;
		}

	}

return StringToNumber(temps[0]);
}

bool UnitList::upDateStats(string strings)
{
		
	int j= 0;
	int i = 0;
	//maybey i acn make the conver for sring to char* right in here
	string  temps[12]; //arry to hold data
	
	while (strings[i]!= ',')//'`') //stay in untl you fing the ` at the end riged to find first comma we just want the id
	{
		if (strings[i] != ',')//if found , dont add it to the data and move on to next char
		{
			temps[j] += strings[i]; //add char to temp spot
			i++;
		}
		else
		{
			i++;
			j++;
		}

	}

	///////////////////////////////////////////////////////////////
	for(i=0; i<numItems;i++)
	{
		if( listofUnits[i]->get_UnitObject()->Get_id() == StringToNumber(temps[0]) )//Id
		{

		
textout(screen,font,strings.c_str(),100,350,makecol(255,0,255));

		
listofUnits[i]->get_UnitObject()->get_attributess()->Set_statholder(strings);

textout(screen,font,listofUnits[i]->get_UnitObject()->get_attributess()->Get_statholder().c_str(),100,310,makecol(255,0,255));
	listofUnits[i]->get_UnitObject()->get_attributess()->fromString();

textout(screen,font,"fixed",100,400,makecol(255,0,255));
//Sleep(7877);

		//nd->UnitObject.Set_desty(StringToNumber(temps[2]));//desty
		//nd->UnitObject.Set_inarea(StringToNumber(temps[3])) //inarea
		}

	}
	/////////////////////////////////////////////////////////////
	
return 1;
}


void UnitList::insert(string chs )
{
	int typ = findUnitTpye(chs);


UnitConfig* nd;
		nd = new UnitConfig;




if(typ == 1)
{
	textout(screen,font,chs.c_str(),100,400,makecol(255,0,255));
//Sleep(987700);	 
	//	textout(screen,font,chs.c_str(),100,400,makecol(255,0,255));
//Sleep(7877);

		listofUnits[numItems] = new CharacterConfig();

nd=(CharacterConfig*)listofUnits[numItems]   ;
	
	//nd->get_UnitObject()->Set_unit(chs);
	//nd->get_UnitObject()->fromString();
//if (nd->get_UnitObject()->get_type() == 1)
		//{

		
nd->get_UnitObject()->Set_unit(chs);
	nd->get_UnitObject()->fromString();
	
	
	nd->get_UnitObject()->Set_destx(nd->get_UnitObject()->Get_X());
	nd->get_UnitObject()->Set_desty(nd->get_UnitObject()->Get_Y());
}
else if(typ == 2)
{
textout(screen,font,chs.c_str(),100,400,makecol(255,0,255));
//Sleep(987700);		 
	
//	textout(screen,font,chs.c_str(),100,400,makecol(255,0,255));
//Sleep(7877);
		listofUnits[numItems] = new TriggerConfig();

nd=(TriggerConfig*)listofUnits[numItems]   ;
	
	//nd->get_UnitObject()->Set_unit(chs);
	//nd->get_UnitObject()->fromString();
//if (nd->get_UnitObject()->get_type() == 1)
		//{

		
nd->get_UnitObject()->Set_unit(chs);
	nd->get_UnitObject()->fromString();
	
	
	nd->get_UnitObject()->Set_destx(nd->get_UnitObject()->Get_X());
	nd->get_UnitObject()->Set_desty(nd->get_UnitObject()->Get_Y());

}
//nd->get_UnitObject()->type =typ;
///////////////////////////////////////////////////////////////////
//if (numItems < maxchars)
//	{
		listofUnits[numItems]=nd;
	numItems++;	
//	}
////////////////////////////////////////////////////////////////////

	
//}
}

///and load from file
void UnitList::load(string filename )
{

	ifstream inData;
	inData.open(filename.c_str() );
	string namer ;
	char trash ;
	int num = 0;
	int num2 = 0;
			 
	inData >> num;
	inData >> trash;	

	while( 	numItems < num)
  	{

		UnitConfig* nd;
		nd = new UnitConfig;

		 
		inData >> num2;
		inData >> trash;
		if (num2 == 1)
		{

		listofUnits[numItems] = new CharacterConfig();

nd=(CharacterConfig*)listofUnits[numItems]   ;
		nd->get_UnitObject()->type=1;
//textout(screen,font,"ghfghfghfgh",100,400,makecol(255,255,255));
		inData >> namer;
		nd->get_UnitObject()->Set_name(namer);
//UnitList[numItems]->UnitObject.Set_name(namer);
		//inData >> trash;


		inData >> num2;
		if (num2 == 1)
		{
			nd->get_UnitObject()->Set_race("namakan");
			//UnitList[numItems]->UnitObject.Set_race("namakan");
		}
		inData >> trash;



		inData >> num2;
		if (num2== 1)
		{
			nd->get_UnitObject()->Set_sex(male);
//UnitList[numItems]->UnitObject.Set_sex(male);
		}
		else if(num2== 2)
		{
			nd->get_UnitObject()->Set_sex(female);
//UnitList[numItems]->UnitObject.Set_sex(female);
		}
		inData >> trash;


		inData >> num2;
		nd->get_UnitObject()->Set_X(num2);
//UnitList[numItems]->UnitObject.Set_X(num2);
		inData >> trash;
		//textprintf_centre(screen, font, 40, 200, makecol(255, 255, 255),"FPS:%d", num2);

		inData >> num2;
		nd->get_UnitObject()->Set_Y(num2);
//UnitList[numItems]->UnitObject.Set_Y(num2);
		inData >> trash;

		inData >> num2;
		nd->get_UnitObject()->Set_W(num2);
//UnitList[numItems]->UnitObject.Set_W(num2);
		inData >> trash;

		inData >> num2;
		nd->get_UnitObject()->Set_H(num2);
//UnitList[numItems]->UnitObject.Set_H(num2);
		inData >> trash;

		inData >> num2;
		nd->get_UnitObject()->Set_layer(num2);
//UnitList[numItems]->UnitObject.Set_layer(num2);
		inData >> trash;

		inData >> num2;
		nd->get_UnitObject()->Set_source_X(num2);
//UnitList[numItems]->UnitObject.Set_source_X(num2);
		inData >> trash;

		inData >> num2;
		nd->get_UnitObject()->Set_source_Y(num2);
//UnitList[numItems]->UnitObject.Set_source_Y(num2);
		inData >> trash;

		inData >> num2;
		if (num2== 0)
		{
			nd->get_UnitObject()->Set_collision(false);
//UnitList[numItems]->UnitObject.Set_collision(false);
		}
		else if (num2== 1)
		{
			nd->get_UnitObject()->Set_collision(true);
//UnitList[numItems]->UnitObject.Set_collision(true);
		}
		inData >> trash;


		inData >> num2;
		nd->get_UnitObject()->Set_frame(num2);
//UnitList[numItems]->UnitObject.Set_frame(num2);
		inData >> trash;



		inData >> num2;
		nd->get_UnitObject()->Set_direction(num2);
//UnitList[numItems]->UnitObject.Set_direction(num2);
		inData >> trash;


		inData >> num2;
		nd->get_UnitObject()->Set_sourcebitmap(num2);
//UnitList[numItems]->UnitObject.Set_sourcebitmap(num2);
		inData >> trash;


		inData >> num2;
		if (num2== 1)
		{
//UnitList[numItems]->UnitObject.Set_destbitmap();
			//nd->UnitObject.Set_destbitmap();
		}
		inData >> trash;

		inData >> num2;
		netId ++;
		nd->get_UnitObject()->Set_id(netId);
//UnitList[numItems]->UnitObject.Set_id(netId);
		inData >> trash;
	
		inData >> num2;
		nd->get_UnitObject()->Set_inarea(num2);
//UnitList[numItems]->UnitObject.Set_inarea(num2);
		inData >> trash;
	
		inData >> num2;

//UnitList[numItems]->UnitObject.Set_socketid(num2);
//UnitList[numItems]->UnitObject.Set_destx(UnitList[numItems]->UnitObject.Get_X());
//UnitList[numItems]->UnitObject.Set_desty(UnitList[numItems]->UnitObject.Get_Y());
//UnitList[numItems]->UnitObject.toString();

		nd->get_UnitObject()->Set_socketid(num2);

nd->get_UnitObject()->Set_destx(nd->get_UnitObject()->Get_X());
nd->get_UnitObject()->Set_desty(nd->get_UnitObject()->Get_Y());
nd->get_UnitObject()->toString();

textout(screen,font,nd->get_UnitObject()->Get_unit().c_str(),100,400,makecol(255,255,255));


		listofUnits[numItems]   = nd;
	
		numItems++;
//textout(screen,font,listofUnits[numItems-1]->get_UnitObject()->Get_unit().c_str(),100,450,makecol(255,0,255));

		}
		else if(num2== 2)//load target
		{



listofUnits[numItems] = new TriggerConfig();

nd=(TriggerConfig*)listofUnits[numItems];

	
			//nd.TriggerObject.//load trigger stuff


nd->get_UnitObject()->type=2;



//textout(screen,font,"ghfghfghfgh",100,400,makecol(255,255,255));
		inData >> namer;
		nd->get_UnitObject()->Set_name(namer);
//UnitList[numItems]->UnitObject.Set_name(namer);
		//inData >> trash;


		inData >> num2;
		if (num2 == 1)
		{
			nd->get_UnitObject()->Set_race("namakan");
			//UnitList[numItems]->UnitObject.Set_race("namakan");
		}
		inData >> trash;



		inData >> num2;
		if (num2== 1)
		{
			nd->get_UnitObject()->Set_sex(male);
//UnitList[numItems]->UnitObject.Set_sex(male);
		}
		else if(num2== 2)
		{
			nd->get_UnitObject()->Set_sex(female);
//UnitList[numItems]->UnitObject.Set_sex(female);
		}
		inData >> trash;


		inData >> num2;
		nd->get_UnitObject()->Set_X(num2);
//UnitList[numItems]->UnitObject.Set_X(num2);
		inData >> trash;
		//textprintf_centre(screen, font, 40, 200, makecol(255, 255, 255),"FPS:%d", num2);

		inData >> num2;
		nd->get_UnitObject()->Set_Y(num2);
//UnitList[numItems]->UnitObject.Set_Y(num2);
		inData >> trash;

		inData >> num2;
		nd->get_UnitObject()->Set_W(num2);
//UnitList[numItems]->UnitObject.Set_W(num2);
		inData >> trash;

		inData >> num2;
		nd->get_UnitObject()->Set_H(num2);
//UnitList[numItems]->UnitObject.Set_H(num2);
		inData >> trash;

		inData >> num2;
		nd->get_UnitObject()->Set_layer(num2);
//UnitList[numItems]->UnitObject.Set_layer(num2);
		inData >> trash;

		inData >> num2;
		nd->get_UnitObject()->Set_source_X(num2);
//UnitList[numItems]->UnitObject.Set_source_X(num2);
		inData >> trash;

		inData >> num2;
		nd->get_UnitObject()->Set_source_Y(num2);
//UnitList[numItems]->UnitObject.Set_source_Y(num2);
		inData >> trash;

		inData >> num2;
		if (num2== 0)
		{
			nd->get_UnitObject()->Set_collision(false);
//UnitList[numItems]->UnitObject.Set_collision(false);
		}
		else if (num2== 1)
		{
			nd->get_UnitObject()->Set_collision(true);
//UnitList[numItems]->UnitObject.Set_collision(true);
		}
		inData >> trash;


		inData >> num2;
		nd->get_UnitObject()->Set_frame(num2);
//UnitList[numItems]->UnitObject.Set_frame(num2);
		inData >> trash;



		inData >> num2;
		nd->get_UnitObject()->Set_direction(num2);
//UnitList[numItems]->UnitObject.Set_direction(num2);
		inData >> trash;


		inData >> num2;
		nd->get_UnitObject()->Set_sourcebitmap(num2);
//UnitList[numItems]->UnitObject.Set_sourcebitmap(num2);
		inData >> trash;


		inData >> num2;
		if (num2== 1)
		{
//UnitList[numItems]->UnitObject.Set_destbitmap();
			//nd->UnitObject.Set_destbitmap();
		}
		inData >> trash;

		inData >> num2;
		netId ++;
		nd->get_UnitObject()->Set_id(netId);
//UnitList[numItems]->UnitObject.Set_id(netId);
		inData >> trash;
	
		inData >> num2;
		nd->get_UnitObject()->Set_inarea(num2);
//UnitList[numItems]->UnitObject.Set_inarea(num2);
		inData >> trash;
	
		inData >> num2;

//UnitList[numItems]->UnitObject.Set_socketid(num2);
//UnitList[numItems]->UnitObject.Set_destx(UnitList[numItems]->UnitObject.Get_X());
//UnitList[numItems]->UnitObject.Set_desty(UnitList[numItems]->UnitObject.Get_Y());
//UnitList[numItems]->UnitObject.toString();

		nd->get_UnitObject()->Set_socketid(num2);
inData >> trash;
	
		inData >> num2;
nd->get_UnitObject()->Set_scriptId(num2);

nd->get_UnitObject()->Set_destx(nd->get_UnitObject()->Get_X());
nd->get_UnitObject()->Set_desty(nd->get_UnitObject()->Get_Y());
nd->get_UnitObject()->toString();

textout(screen,font,nd->get_UnitObject()->Get_unit().c_str(),10,450,makecol(255,255,255));
//Sleep(987700);



	listofUnits[numItems]= nd;
			numItems++;

		}
	
	}

//

	inData.close();

	//Sleep(9000);

}






	
/*


///and save to file
void UnitList::save( string filename)
{
	UnitConfig* nd;
//	nd = head;
	
	ofstream outData;
	outData.open(filename.c_str());
	
	outData << numItems;
	outData << ",";
	outData << endl;
	
	//while( nd != NULL ) 
	//{
for(int i=0; i<numItems;i++)
	{
		nd=UnitList[i];
		outData << nd->UnitObject.Get_name();
		outData << endl;
		outData << 1;//nd->UnitObject.Get_race();
		outData << ",";
		outData << 1;//nd->UnitObject.Get_sex();
		outData << ",";
		outData << nd->UnitObject.Get_X();
		outData << ",";
		outData << nd->UnitObject.Get_Y();
		outData << ",";
		outData << nd->UnitObject.Get_W();	
		outData << ",";
		outData << nd->UnitObject.Get_H();
		outData << ",";
		outData << nd->UnitObject.Get_layer();
		outData << ",";
		outData << nd->UnitObject.Get_source_X();
		outData << ",";
		outData << nd->UnitObject.Get_source_Y();	
		outData << ",";
		outData << 0; //nd->UnitObject.Is_in_collision();
		outData << ",";
		outData << nd->UnitObject.Get_frame();
		outData << ",";
		outData << 1 ;//nd->UnitObject.Get_direction()
		outData << ",";
		outData << nd->UnitObject.Get_sourcebitmap();
		outData << ",";
		outData << 2;//nd->UnitObject.Get_destbitmap();
		outData << ",";
		outData << nd->UnitObject.Get_id();
		outData << ",";
		outData << nd->UnitObject.Get_inarea();
		outData << ",";
		outData << nd->UnitObject.Get_socketid();
		outData << endl;
		
	

	}
	
	
	outData.close();
	
}
////
*/

void UnitList::setup_collision()
{
	if(debugmode==true)
{
	textout(screen,font,"setup_collision called ",100,320,makecol(6,255,255));
	}
	
	int i,j;
	
	for(  i = 0; i < numItems; i++ )
	{
	 
		for(  j = 0; j < numItems; j++ )
		{
			if(listofUnits[i]->get_UnitObject()->Get_inarea()==listofUnits[j]->get_UnitObject()->Get_inarea())
			{
				if(listofUnits[i]->get_UnitObject()->is_collision(listofUnits[j]->get_UnitObject()) )
				{
					if(listofUnits[i]->get_UnitObject()->Get_id() != listofUnits[j]->get_UnitObject()->Get_id())
					{
						textout(screen,font," collision detected ",400,320,makecol(6,255,255));

						listofUnits[i]->get_UnitObject()->Set_collision(true);
						listofUnits[j]->get_UnitObject()->Set_collision(true);/// this has the sam bug from project 3 setting point useable
						if(listofUnits[i]->get_UnitObject()->type ==2)
						{
							listofUnits[i]->get_UnitObject()->triggered=true;
						//listofUnits[i]->get_UnitObject()->set_onewhotiggeredme(*(listofUnits[j]->get_UnitObject()));

if(listofUnits[i]->get_UnitObject()->scriptId==1)
{
	listofUnits[j]->get_UnitObject()->Set_inarea(1);//rig
	if(computerId==listofUnits[j]->get_UnitObject()->Get_id())
	{
		ch_current_area = 1;//rig
	}
}	
else if(listofUnits[i]->get_UnitObject()->scriptId==2)
{
	listofUnits[j]->get_UnitObject()->Set_inarea(2);//rig
	if(computerId==listofUnits[j]->get_UnitObject()->Get_id())
	{
		ch_current_area = 2;//rig
	}
}
else if(listofUnits[i]->get_UnitObject()->scriptId==3)
{
	listofUnits[j]->get_UnitObject()->Set_inarea(3);//rig
	if(computerId==listofUnits[j]->get_UnitObject()->Get_id())
	{
		ch_current_area = 3;//rig
	}
}

else if(listofUnits[i]->get_UnitObject()->scriptId==4)
{
	listofUnits[j]->get_UnitObject()->Set_inarea(4);//rig
	if(computerId==listofUnits[j]->get_UnitObject()->Get_id())
	{
		ch_current_area = 4;//rig
	}
}


				
//	listofUnits[i]->get_UnitObject()->runScript();
	listofUnits[i]->get_UnitObject()->triggered=false;

						//	listofUnits[i]->get_UnitObject()->set_onewhotiggeredme(NULL);
						}
						break;//list of ele
					}
					else
					{
						listofUnits[i]->get_UnitObject()->Set_collision(false);
			
					}
				}
				else
				{
					listofUnits[i]->get_UnitObject()->Set_collision(false);

				}
			}
		
		}	
	
	}
if(debugmode==true)
{
	textout(screen,font,"setup_collision done ",100,350,makecol(255,6,255));
}
}




void UnitList::traverse2( )
{
	UnitConfig *nd;
	
	
	for( int i = 0; i < numItems; i++ )
	{
		nd = listofUnits[i];
		
	}
	
}

void UnitList::sort()
{
//first we need to sorut by x lesest to greatest
quickSort(listofUnits,0,numItems-1);
}


void UnitList::draw(BITMAP* bmp,int lay,View v )
{


//textout(screen,font,NumberToString(numItems).c_str(),100,400,makecol(255,255,255));


for( int i = 0; i < numItems; i++ )
	{

		listofUnits[i]->get_UnitObject()->do_moveing();
listofUnits[i]->get_UnitObject()->animate();
	if(listofUnits[i]->get_UnitObject()->Get_inarea() == current_area)
	{

		
		if (listofUnits[i]->get_UnitObject()->Get_layer()== lay)
		{	
			if(listofUnits[i]->get_UnitObject()->get_type()==1)
			{
			
			 //listofUnits[i]->get_UnitObject()->do_moveing();
			//listofUnits[i]->get_UnitObject()->animate();
			listofUnits[i]->get_UnitObject()->draw(bmp,v);
			listofUnits[i]->get_UnitObject()->showname(bmp,v);
			listofUnits[i]->get_UnitObject()->showlife(bmp,v);
			listofUnits[i]->get_UnitObject()->talk(bmp,v);
			}
			else if(listofUnits[i]->get_UnitObject()->get_type()==2)
			{
			
			// listofUnits[i]->get_UnitObject()->do_moveing();
			//listofUnits[i]->get_UnitObject()->animate();
			listofUnits[i]->get_UnitObject()->draw(bmp,v);
			listofUnits[i]->get_UnitObject()->showname(bmp,v);
			listofUnits[i]->get_UnitObject()->showlife(bmp,v);
			listofUnits[i]->get_UnitObject()->talk(bmp,v);
			}
		}
	}
		
	}


}

bool UnitList::isEmpty( )
{
	return( numItems == 0 );
}

int UnitList::GetnumItems( )
{
	return numItems;
}

bool UnitList::IsInList( int d )
{
	//UnitConfig* nd;
	//nd = head;
//	while( nd != NULL )
for( int i = 0; i < numItems; i++ )
	
	{
		if( listofUnits[i]->get_UnitObject()->Get_id() == d )
		{
			return true;
		}
			//nd = nd->GetNext( );
	}
	return false;
}

void UnitList::setdest()
{

	int j= 0;
	int i = 0;
	//maybey i acn make the conver for sring to char* right in here
	string temps[8]; //arry to hold data
	
	while (movestring[i]!= '`') //stay in untl you fing the ` at the end
	{
		if (movestring[i] != ',')//if found , dont add it to the data and move on to next char
		{
			temps[j] += movestring[i]; //add char to temp spot
			i++;
		}
		else
		{
			i++;
			j++;
		}

	}

	UnitConfig* nd;
//	nd = head;
	nd=&CharacterConfig();
	//while( nd != NULL )
	//{
for(  i = 0; i < numItems; i++ )
	{
nd=(CharacterConfig*)listofUnits[i];
		if( nd->get_UnitObject()->Get_id() == StringToNumber(temps[0]) )//Id
		{
		nd->get_UnitObject()->Set_X(StringToNumber(temps[3]));//curent x
		nd->get_UnitObject()->Set_Y(StringToNumber(temps[4]));//curent y
		nd->get_UnitObject()->Set_destx(StringToNumber(temps[1])); //destx
		nd->get_UnitObject()->Set_desty(StringToNumber(temps[2]));//desty
		
		nd->get_UnitObject()->Set_direction(StringToNumber(temps[5]));//curent dirfacing
		nd->get_UnitObject()->Set_frame(StringToNumber(temps[6])); //current frame
		//nd->UnitObject.Set_inarea(StringToNumber(temps[3])) //inarea
		break;//if found stop looking
		}
		//	nd = nd->GetNext( );
			
	}

}

void UnitList::setdieolog()
{

	int j= 0;
	int i = 0;
	//maybey i acn make the conver for sring to char* right in here
	string temps[3]; //arry to hold data
	
	while (talkstring[i]!= '`') //stay in untl you fing the ` at the end
	{
		if (talkstring[i] != ',')//if found , dont add it to the data and move on to next char
		{
			temps[j] += talkstring[i]; //add char to temp spot
			i++;
		}
		else
		{
			i++;
			j++;
		}

	}

if (StringToNumber(temps[0]) == 0)
{
serverdiolog = temps[1];
}
else
{

	UnitConfig* nd;
//	nd = head;
	int index = 0;
//	while( nd != NULL )
	//{
for( i=0; i<numItems;i++)
	{
 nd= listofUnits[i];
		if( nd->get_UnitObject()->Get_id() == StringToNumber(temps[0]) )//Id
		{
		
		nd->get_UnitObject()->Set_dieolog(temps[1]); 
nd->get_UnitObject()->set_mesageLife( 0);

//nd->UnitObject.msgdie = xt +5;
		break; //stop looking when found
		}
		//	nd = nd->GetNext( );
			
	}
}
}

int UnitList::IndexOf( int d )
{
	for( int i = 0; i < numItems; i++ )
	{
		
		if( listofUnits[i]->get_UnitObject()->Get_id() == d )
		{
			//nd = nd->GetNext();
			return i;
		}
	}
	
	return -1;
}



Unit *UnitList::Get_Unit( int d )
{

	//notfoun need log error
	for( int i = 0; i < numItems; i++ )
	{
		
		if( listofUnits[i]->get_UnitObject()->Get_id() == d )
		{
		//nd = nd->GetNext();
			return listofUnits[i]->get_UnitObject();
		}
	}
	return &Unit();
}





int UnitList::Find_Unit_id( int d ,int c)
{
	/*
	UnitConfig* nd;
	//nd = head;
	int index = 0;
	
	while( nd != NULL )
	{
		
		if( nd->UnitObject.Get_id() == d )
		{

			if (c == 1)
			{
			nd->UnitObject.Set_corrent_frame(nd->UnitObject.Get_frame2());

			}
			else if(c == 2)
			{
			nd->UnitObject.Set_corrent_frame(nd->UnitObject.Get_frame3());

			}
			else if(c == 3)
			{
			nd->animeObject.Set_corrent_frame(nd->animeObject.Get_frame4());

			}
			else if(c == 4)
			{
			nd->animeObject.Set_corrent_frame(nd->animeObject.Get_frame5());

			}
			else 
			{
			nd->animeObject.Set_corrent_frame(nd->animeObject.Get_frame1());

			}

			return nd->UnitObject.Get_corrent_frame();
			break;
			
		}
	//	nd = nd->GetNext( );
		index++;
	}
*/
	return -1;
}


bool UnitList::Delete(int d)
{

	int i;
	for( i=0; i<numItems;i++)
	{
		if(listofUnits[i]->get_UnitObject()->Get_id()==d)
		{
			swap(listofUnits[i],listofUnits[numItems-1]);
			numItems--;
	
			return true;
		}
	}

	return false;
}


bool UnitList::Deletec(int d)
{

	int i;
	for( i=0; i<numItems;i++)
	{
		if(listofUnits[i]->get_UnitObject()->Get_socketid()==d)
		{
			swap(listofUnits[i],listofUnits[numItems-1]);
			numItems--;
			return true;
		}
	}


return false;
}

string UnitList::listToString(string d)
{
	UnitConfig* nd;
	//	nd = head;
	string list="";
	loding += (numItems * 2) + 1;
	for( int i = 0; i < numItems; i++ )
	{
		nd=(CharacterConfig*)listofUnits[i];
		textout(screen,font,(nd->get_UnitObject()->toString()).c_str(),100,300,makecol(255,255,255));
		//Sleep(10000);
		outboxbuffer += d+"|0|004|"+ (nd->get_UnitObject()->toString()) +'~';
		outboxbuffer += d+"|0|009|"+NumberToString((nd->get_UnitObject()->Get_id())) +','+ (nd->get_UnitObject()->get_attributess()->toString()) +'~';
		list += nd->get_UnitObject()->toString() + '~';
		//nd = nd->GetNext();
	}
//textout(screen,font,outboxbuffer.c_str(),-250,300,makecol(255,255,255));
//
	return list;
}

int UnitList::battle(string bat)
{
	int j= 0;
	int i = 0;
//maybey i acn make the conver for sring to char* right in here
	string temps[2]; //arry to hold data
	
	while (bat[i]!= '`') //stay in untl you fing the ` at the end
	{
		if (bat[i] != ',')//if found , dont add it to the data and move on to next char
		{
			temps[j] += bat[i]; //add char to temp spot
			i++;
		}
		else
		{
			i++;
			j++;
		}

	}



	int attacker_id = StringToNumber(temps[0]); 
	int defender_id = StringToNumber(temps[1]);
	
	bool attacker_found = false, defender_found = false;

	int attacker,defender;

	for(  attacker = 0; attacker < numItems; attacker++ )
	{
		
		if( listofUnits[attacker]->get_UnitObject()->Get_id() == attacker_id )
		{
			
			attacker_found = true;
			break;
		}

	}

	for(  defender= 0; defender < numItems; defender++ )
	{
		
		if( listofUnits[defender]->get_UnitObject()->Get_id() ==defender_id )
		{
		
			defender_found = true;
			break;
		}
	}

		if ((attacker_found == true) && (defender_found == true))
		{
			if(listofUnits[defender]->get_UnitObject()->Is_in_collision()==1 && listofUnits[attacker]->get_UnitObject()->Is_in_collision()==1 )
			{

					listofUnits[attacker]->get_UnitObject()->attack(listofUnits[defender]->get_UnitObject());
			}
			else
			{
				outboxbuffer +=attacker_id +"|0|003|" + NumberToString(computerId) + ",you or your tager is not in collision`~";
			}

		}
		else
		{
		outboxbuffer +=attacker_id +"|0|003|" + NumberToString(computerId) + ",cant find traget`~";
		return -1;
		}


return 0;	
}

UnitList::~UnitList()
{

}
