www.pudn.com > mycode-08[1].8.24.rar > deathcontend.c


#include "version.h" 
#include  
#include  
#include "util.h" 
#include "char.h" 
#include "char_data.h" 
#include "char_base.h" 
#include "battle.h" 
#include "configfile.h" 
#include "saacproto_cli.h" 
#include "buf.h" 
#include "log.h" 
 
#ifdef _DEATH_CONTEND 
 
#include "deathcontend.h" 
 
PkTeamLists *PkTeamList=NULL; 
 
PKProcedures PKProcedure[MAXJOINTEAM]; 
 
static char chartslist[65536*3]; 
 
static char ABattlelist[65536*2]; 
static char ABLevelup[65536*2]; 
 
static int maxteam = 0; 
 
static int PKListSort[550]; 
 
//正式赛 
ArrangeBattleC *NowABattle[MAXBAHEAD][MAXBAFLOOR][MAXNOWBATTLE]; 
ArrangeBattleC *headABattle[MAXBAHEAD]; 
ArrangeBattleC *InBattle[MAXBATTLEPAGE]; 
 
static int maxfloor=0; 
static int maxbati=0; 
int ABFloor[MAXBAHEAD]; 
 
/* 
struct { 
	int floor; 
	int x; 
	int y; 
	int use; 
}PK_WATCHMAP[MAXJOINTEAM][MAXWATCHMAP]={ 
	{}, 
 
 
}; 
*/ 
struct { 
	int floor; 
	int x; 
	int y; 
	int use; 
}PK_BATTLEMAP[MAXJOINTEAM]={ 
//	{ 8240, 13, 14, 0}, { 8240, 13, 27, 0}, { 8240, 26, 14, 0}, { 8240, 26, 27, 0}, 
 
	{ 8240, 13, 14, 0}, { 8240, 13, 27, 0}, { 8240, 26, 14, 0}, { 8240, 26, 27, 0}, 
	{ 8241, 13, 14, 0}, { 8241, 13, 27, 0}, { 8241, 26, 14, 0}, { 8241, 26, 27, 0}, 
	{ 8242, 13, 14, 0}, { 8242, 13, 27, 0}, { 8242, 26, 14, 0}, { 8242, 26, 27, 0}, 
	{ 8243, 13, 14, 0}, { 8243, 13, 27, 0}, { 8243, 26, 14, 0}, { 8243, 26, 27, 0}, 
	{ 8244, 13, 14, 0}, { 8244, 13, 27, 0}, { 8244, 26, 14, 0}, { 8244, 26, 27, 0}, 
 
	{ 8245, 13, 14, 0}, { 8245, 13, 27, 0}, { 8245, 26, 14, 0}, { 8245, 26, 27, 0}, 
	{ 8246, 13, 14, 0}, { 8246, 13, 27, 0}, { 8246, 26, 14, 0}, { 8246, 26, 27, 0}, 
	{ 8247, 13, 14, 0}, { 8247, 13, 27, 0}, { 8247, 26, 14, 0}, { 8247, 26, 27, 0}, 
	{ 8248, 13, 14, 0}, { 8248, 13, 27, 0}, { 8248, 26, 14, 0}, { 8248, 26, 27, 0}, 
	{ 8249, 13, 14, 0}, { 8249, 13, 27, 0}, { 8249, 26, 14, 0}, { 8249, 26, 27, 0}, 
 
}; 
 
void PKLIST_shoutToAll( char *token, int teamnum, int floor) 
{ 
	int i; 
    int playernum = CHAR_getPlayerMaxNum(); 
 
	LogPkContend( token, "shoutToAll", 0, 0, 0, 1); 
 
    for( i=0 ; i= maxteam ) return; 
	for( k=0;k= maxteam ) return; 
	PkTeamList[ti].use = 0; 
	PkTeamList[ti].teamnum = -1; 
	memset( PkTeamList[ti].teamname, 0, sizeof( PkTeamList[ti].teamname ) ); 
	memset( PkTeamList[ti].pathdir, 0, sizeof( PkTeamList[ti].pathdir) ); 
	memset( PkTeamList[ti].leadercdkey, 0, sizeof( PkTeamList[ti].leadercdkey ) ); 
	PkTeamList[ti].win = 0; 
	PkTeamList[ti].lost = 0; 
	PkTeamList[ti].battleplay = 0; 
	PkTeamList[ti].score = 0; 
	PkTeamList[ti].inside = 1; 
	PkTeamList[ti].read = 1; 
} 
//----------------------------------------------------------- 
 
int PKLIST_InitPkTeamList( int teamnum ) 
{ 
	int i; 
	if( PkTeamList != NULL || teamnum <= 0 ) return -1; 
	maxteam = teamnum; 
	PkTeamList = (PkTeamLists *)calloc( 1, sizeof( struct _tagPkTeamLists) * maxteam ); 
	if( PkTeamList == NULL ){ 
		print( "ANDY err Can't calloc PkTeamList :%d !!\n", 
			sizeof( struct _tagPkTeamLists) * maxteam ); 
		return -1; 
	} 
	print( "PkTeamList calloc size :%d ..\n", 
		sizeof( struct _tagPkTeamLists) * maxteam ); 
 
	for( i=0; i= DEFMAXBATTLENUM ){ 
			CHAR_talkToCli( charaindex, -1, "对战场次已满!", CHAR_COLORYELLOW); 
			return FALSE; 
		} 
		if( PkTeamList[array].BHistory[k].use == 0 ) continue; 
		if( PkTeamList[array].BHistory[k].teamnum == toteamnum ) return FALSE; 
	} 
	return TRUE; 
} 
 
int PKLIST_CHECKPkTeamNew( int teamnum, int charaindex, char *cdkey ) 
{ 
	int k; 
	int array; 
	array = PKLIST_GetPkTeamListArray( teamnum, cdkey); 
	if( array == -1 ){ 
		CHAR_talkToCli( charaindex, -1, "无法取得队伍资料!", CHAR_COLORYELLOW); 
		return -1; 
	} 
	for( k=0; k= DEFMAXBATTLENUM ){ 
		CHAR_talkToCli( charaindex, -1, "对战场次已满!", CHAR_COLORYELLOW); 
		return -1; 
	} 
	return k; 
} 
 
BOOL PKLIST_LoadPkTeamListDataSub( int ti, char *data) 
{ 
	int oldinside = -1; 
	char buf[512]; 
	if( getStringFromIndexWithDelim( data, "|", 1, buf, sizeof( buf)) == FALSE  ) return FALSE; 
		PkTeamList[ti].teamnum = atoi( buf); 
	if( getStringFromIndexWithDelim( data, "|", 2, buf, sizeof( buf)) == FALSE  ) return FALSE; 
		sprintf( PkTeamList[ti].pathdir, "%s", buf); 
	if( getStringFromIndexWithDelim( data, "|", 3, buf, sizeof( buf)) == FALSE  ) return FALSE; 
		sprintf( PkTeamList[ti].teamname, "%s", buf); 
	if( getStringFromIndexWithDelim( data, "|", 4, buf, sizeof( buf)) == FALSE  ) return FALSE; 
		sprintf( PkTeamList[ti].leadercdkey, "%s", buf); 
	if( getStringFromIndexWithDelim( data, "|", 5, buf, sizeof( buf)) == FALSE  ) return FALSE; 
		PkTeamList[ti].win = atoi( buf); 
	if( getStringFromIndexWithDelim( data, "|", 6, buf, sizeof( buf)) == FALSE  ) return FALSE; 
		PkTeamList[ti].lost = atoi( buf); 
	if( getStringFromIndexWithDelim( data, "|", 7, buf, sizeof( buf)) == FALSE  ) return FALSE; 
		PkTeamList[ti].battleplay = atoi( buf); 
	if( getStringFromIndexWithDelim( data, "|", 8, buf, sizeof( buf)) == FALSE  ) return FALSE; 
		PkTeamList[ti].score = atoi( buf); 
 
	oldinside = PkTeamList[ti].inside; 
	if( getStringFromIndexWithDelim( data, "|", 9, buf, sizeof( buf)) == FALSE  ) return FALSE; 
		PkTeamList[ti].inside = atoi( buf); 
 
	if( PkTeamList[ti].inside == 2 && PkTeamList[ti].inside != oldinside ){//广播 
		char token[256]; 
		int i; 
		int playernum = CHAR_getPlayerMaxNum(); 
		sprintf( token, "%s 队,达成比赛规定积分,积分:%d。", 
			PkTeamList[ti].teamname, PkTeamList[ti].score ); 
 
		for( i=0; i= MAXTEAMMANNUM ) break; 
	} 
	if( count <= 0 ) return FALSE; 
 
	return TRUE; 
} 
 
BOOL PKLIST_LoadPkTeamListDataBHistory( int ti, char *data) 
{ 
	int k=1, count=0; 
	char buf[256], buf1[64]; 
	while( getStringFromIndexWithDelim( data, "|", k, buf, sizeof( buf)) !=FALSE )	{ 
		k++; 
		if( getStringFromIndexWithDelim( buf, ",", 1, buf1, sizeof( buf1)) == FALSE  ) continue; 
		PkTeamList[ti].BHistory[count].teamnum = atoi( buf1); 
		if( getStringFromIndexWithDelim( buf, ",", 2, buf1, sizeof( buf1)) == FALSE  ) continue; 
		PkTeamList[ti].BHistory[count].flg = atoi( buf1); 
 
		PkTeamList[ti].BHistory[count].use = 1; 
		count++; 
		if( count >= MAXBATTLENUM ) break; 
	} 
	return TRUE; 
} 
 
// teamlist.ini 内容 
// teamnum|teamname|leadercdkeky|leadername|cdkey|name|cdkey|name|cdkey|name|cdkey|name 
 
void PKLIST_LoadInitPkTeamListData(void) 
{ 
	FILE *fp = NULL; 
	int count = 0,i; 
	char szReadData[1024],buf[1024],buf1[1024]; 
 
	if((fp = fopen("data//pkdata//teamlist.txt","r")) != NULL){ 
		fclose(fp); 
		return; 
	} 
	if((fp = fopen("data//pkdata//teamlist.ini","r")) == NULL){ 
		print("can't find data/pkdata/teamlist.ini\n"); 
		return; 
	} 
	while(1){ 
		memset(szReadData,0,sizeof(szReadData)); 
		memset(buf,0,sizeof(buf)); 
		if(fgets(szReadData,1024,fp) == NULL) break; 
		if(getStringFromIndexWithDelim(szReadData,"|",1,buf,sizeof(buf)) == FALSE){ 
			print("err get teamindex data:%s\n",szReadData); 
			continue; 
		} 
		PkTeamList[count].teamnum = atoi(buf); 
		sprintf(PkTeamList[count].pathdir,"NOUSE"); 
		if(getStringFromIndexWithDelim(szReadData,"|",2,buf,sizeof(buf)) == FALSE){ 
			print("err get teamindex data:%s\n",szReadData); 
			continue; 
		} 
		sprintf(PkTeamList[count].teamname,"%s",buf); 
		if(getStringFromIndexWithDelim(szReadData,"|",3,buf,sizeof(buf)) == FALSE){ 
			print("err get leadercdkey data:%s\n",szReadData); 
			continue; 
		} 
		sprintf(PkTeamList[count].leadercdkey,"%s",buf); 
		for(i=0;i=maxteam ){ 
			print("err 1 buf:%s\n", buf); 
			continue; 
		} 
		if( getStringFromIndexWithDelim( buf, "_", 2, buf1, sizeof( buf1)) == FALSE  ){ 
			print("err 2 buf:%s\n", buf); 
			continue; 
		} 
		if( PKLIST_LoadPkTeamListDataSub( array, buf1 ) == FALSE ){ 
			print("err 3 buf:%s\n", buf); 
			continue; 
		} 
		if( getStringFromIndexWithDelim( buf, "_", 3, buf1, sizeof( buf1)) == FALSE  ){ 
			print("err 4 buf:%s\n", buf); 
			continue; 
		} 
		if( PKLIST_LoadPkTeamListDataMyTeamMans( array, buf1) == FALSE ){ 
			print("err 5 buf:%s\n", buf); 
			continue; 
		} 
		if( getStringFromIndexWithDelim( buf, "_", 4, buf1, sizeof( buf1)) != FALSE  ){ 
			if( PKLIST_LoadPkTeamListDataBHistory( array, buf1) == FALSE ){ 
				print("err 7 buf:%s\n", buf); 
				continue; 
			} 
		} 
 
		teamcount++; 
	} 
	//andy_log 
	print("\nteamcount:%d \n", teamcount); 
	if( teamcount <= 0 ) return TRUE; 
	return TRUE; 
} 
*/ 
 
void PKLIST_InsertTeamNum( int charaindex ) 
{ 
	int i, k; 
	char *cdkey, *name; 
	if( !CHAR_CHECKINDEX( charaindex) ) return; 
	cdkey = CHAR_getChar( charaindex, CHAR_CDKEY); 
	name = CHAR_getChar( charaindex, CHAR_NAME); 
 
	for( i=0; i= (int)time(NULL) ) return; 
			side = (j+1)%2; 
			 
			if( PKProcedure[battlearray].Team[side].use == 0 ) return; 
			if( (tonum = PKProcedure[battlearray].Team[side].teamnum ) < 0 ) return; 
			 
			if( (toarray = PKLIST_GetPkTeamListArrayFromNum( tonum)) == -1 || 
				PKLIST_GetTeamLeaderCdkey( tonum, tocdkey ) == FALSE ){ 
				print("Can't Get Data tonum:%d err !!\n", tonum); 
				return; 
			} 
			break; 
		} 
		//andy_log 
		print("NPC_PKLIST_PlayerLogout_Exit( %d) \n", charaindex); 
		if( (menum=CHAR_getInt( charaindex, CHAR_PKLISTTEAMNUM)) < 0 ) return; 
 
		if( (aB1=ABATTLE_getInBattle( menum))==NULL ) return; 
		if( (aBo=aB1->top) == NULL ) return; 
		if( (aB1=aBo->next[0]) == NULL || (aB2=aBo->next[1]) == NULL ) return; 
 
		if( aB1->teamnum == menum ){ 
			sprintf( token, "%s 队 胜 %s 队。", aB2->teamname, aB1->teamname ); 
			LogPkContend( aB2->teamname , aB1->teamname, 0, 0, 0, 0); 
			ABATTLE_RecordBattle( -1, aB1->teamname, "", aB2->teamname, "胜"); 
			tonum = aB2->teamnum; 
			ABATTLE_EnterBattle( aB2); 
		}else{ 
			sprintf( token, "%s 队 胜 %s 队。", aB1->teamname, aB2->teamname ); 
			LogPkContend( aB1->teamname , aB2->teamname, 0, 0, 0, 0); 
			ABATTLE_RecordBattle( -1, aB1->teamname, "胜", aB2->teamname, ""); 
			tonum = aB1->teamnum; 
			ABATTLE_EnterBattle( aB1); 
		} 
		for( i=0; i= (int)time(NULL) ) return; 
		side = (j+1)%2; 
 
		if( PKProcedure[battlearray].Team[side].use == 0 ) return; 
		if( (tonum = PKProcedure[battlearray].Team[side].teamnum ) < 0 ) return; 
 
		if( (toarray = PKLIST_GetPkTeamListArrayFromNum( tonum)) == -1 || 
			PKLIST_GetTeamLeaderCdkey( tonum, tocdkey ) == FALSE ){ 
			print("Can't Get Data tonum:%d err !!\n", tonum); 
			return; 
		} 
 
		PKLIST_LOCKTeam( menum); 
		PKLIST_LOCKTeam( tonum); 
		//saacproto_PkListUpDate_send( acfd , tocdkey, mecdkey,tonum, menum, 0, 0); 
		PKLIST_UpData(tocdkey,mecdkey,tonum,menum,0,0); 
 
		sprintf( token, "%s 队 胜 %s 队。", 
			PkTeamList[toarray].teamname, PkTeamList[mearray].teamname); 
 
		LogPkContend( PkTeamList[toarray].teamname, PkTeamList[mearray].teamname, 
					CHAR_getInt( charaindex, CHAR_FLOOR), 
					CHAR_getInt( charaindex, CHAR_X), CHAR_getInt( charaindex, CHAR_Y), 0); 
 
		PKLIST_DelPKProcedures( battlearray, 0, PKTYPE_WAIT); 
		PKLIST_DelPKProcedures( battlearray, 1, PKTYPE_WAIT); 
 
		{ //广播胜负 
			int i; 
			int playernum = CHAR_getPlayerMaxNum(); 
			for( i=0; itop == NULL || aB2->top == NULL || 
			aB1->top != aB2->top ) return 0; 
 
		if( winside == 0 ){ 
			sprintf( token, "%s 队 胜 %s 队。", aB1->teamname, aB2->teamname ); 
			LogPkContend( aB1->teamname , aB2->teamname, 0, 0, 0, 0); 
			ABATTLE_RecordBattle( -1, aB1->teamname, "胜", aB2->teamname, ""); 
			ABATTLE_EnterBattle( aB1); 
		}else{ 
			sprintf( token, "%s 队 胜 %s 队。", aB2->teamname, aB1->teamname ); 
			LogPkContend( aB2->teamname , aB1->teamname, 0, 0, 0, 0); 
			ABATTLE_RecordBattle( -1, aB1->teamname, "", aB2->teamname, "胜"); 
			ABATTLE_EnterBattle( aB2); 
		} 
 
		for( i=0; itop ) InBattle[i] = NULL; 
		} 
 
		{ //广播胜负 
			int i; 
			int playernum = CHAR_getPlayerMaxNum(); 
			for( i=0; i=40 ) return; 
	if( side<0 || side >1 ) return; 
 
	PKProcedure[ti].use = 0; 
	PKProcedure[ti].type = type; 
	PKProcedure[ti].Team[side].use = 0; 
	PKProcedure[ti].Team[side].teamnum = -1; 
	PKProcedure[ti].Team[side].fd = -1; 
 
} 
 
BOOL PKLIST_CheckPklistInServerMap( int ti, int side) 
{ 
	if( !CHAR_CHECKINDEX( PKProcedure[ti].Team[side].toindex) || 
		PKLIST_GetPkTeamListArrayFromNum( PKProcedure[ti].Team[side].teamnum ) == -1 || 
		PKProcedure[ti].Team[side].fd != getfdFromCharaIndex( PKProcedure[ti].Team[side].toindex) || 
		CHAR_getInt( PKProcedure[ti].Team[side].toindex, CHAR_FLOOR ) == 8250 ){ 
		return FALSE; 
	} 
	return TRUE; 
} 
 
BOOL PKLIST_CheckPKSameTeam( int charaindex ) 
{ 
	int teamnum, i, meti; 
	char szMsg[128]; 
 
	if( !CHAR_CHECKINDEX( charaindex) ){ 
		print( "CHAR_CHECKINDEX err !!\n"); 
		return FALSE; 
	} 
 
	if( (teamnum=CHAR_getInt( charaindex, CHAR_PKLISTTEAMNUM)) < 0 ){ 
		print( "CHAR_PKLISTTEAMNUM err !!\n"); 
		return FALSE; 
	} 
	if( (meti=PKLIST_GetPkTeamListArrayFromNum( teamnum )) == -1 ){ 
		print( "GetPkTeamListArray err !!\n"); 
		return FALSE; 
	} 
#ifdef _DEATH_CONTENDAB 
	if( CHAR_getInt( charaindex, CHAR_PKLISTLEADER) != 1 ){ 
		return FALSE; 
	} 
#else 
	if( PkTeamList[meti].battleplay >= DEFMAXBATTLENUM ){ 
		CHAR_talkToCli( charaindex, -1, "对战场数已满!", CHAR_COLORYELLOW); 
		return FALSE; 
	} 
 
	if( CHAR_getInt( charaindex, CHAR_PKLISTLEADER) != 1 ){ 
		CHAR_talkToCli( charaindex, -1, "只有参赛队伍的队长才能加入赛程喔!", CHAR_COLORYELLOW); 
		return FALSE; 
	} 
#endif 
	if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_LEADER ){ 
		return TRUE; 
	} 
 
	for( i=0; i<5; i++){ 
		int pindex = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1+i); 
		if( !CHAR_CHECKINDEX( pindex) ) continue; 
		if( teamnum != CHAR_getInt( pindex, CHAR_PKLISTTEAMNUM) ){ 
			CHAR_talkToCli( charaindex, -1, "你的队里怎会有不同队伍的人呢?", CHAR_COLORYELLOW); 
			return FALSE; 
		} 
	} 
	for( i=0; i<5; i++){ 
		int pindex = CHAR_getWorkInt( charaindex, CHAR_WORKPARTYINDEX1+i); 
		if(!CHAR_CHECKINDEX(pindex)) continue; 
		if(CHAR_getInt(pindex,CHAR_LV) < 120){ 
			sprintf(szMsg,"你的队里 %s 等级 %d 未达比赛标准喔!",CHAR_getChar(pindex,CHAR_NAME),CHAR_getInt(pindex,CHAR_LV)); 
			CHAR_talkToCli(charaindex,-1,szMsg,CHAR_COLORYELLOW); 
			return FALSE; 
		} 
		if(CHAR_getInt(pindex,CHAR_TRANSMIGRATION) < 3){ 
			sprintf(szMsg,"你的队里 %s 转生数 %d 转,未达比赛标准喔!",CHAR_getChar(pindex,CHAR_NAME),CHAR_getInt(pindex,CHAR_TRANSMIGRATION)); 
			CHAR_talkToCli(charaindex,-1,szMsg,CHAR_COLORYELLOW); 
			return FALSE; 
		} 
	} 
	return TRUE; 
} 
 
 
BOOL PKLIST_CheckPKReapetTeam( int menum, int tonum) 
{ 
	int meti, k, toti; 
	if( (meti=PKLIST_GetPkTeamListArrayFromNum( menum )) == -1 ){ 
		return FALSE; 
	} 
	for( k=0; k (int)time(NULL) ){ 
		return FALSE; 
	} 
	return TRUE; 
 
} 
 
void PKLIST_LOCKTeam( int menum) 
{ 
	int meti=-1; 
	if( (meti=PKLIST_GetPkTeamListArrayFromNum( menum )) == -1 ){ 
		return; 
	} 
	PkTeamList[meti].read = (int)time(NULL)+60; 
} 
 
void PKLIST_UNLOCKTeam( int menum) 
{ 
	int meti=-1; 
	if( (meti=PKLIST_GetPkTeamListArrayFromNum( menum )) == -1 ){ 
		return; 
	} 
	PkTeamList[meti].read = 0; 
} 
 
void PKLIST_Sort_PKListSort( void) 
{ 
	int i, j, k, last=-1; 
	char data[65535*3], buf[512]; 
	for( i=0; i=0; k-- ){ 
			if( PkTeamList[i].score <= 0 ) continue; 
			if( PKListSort[k] == -1 ){ 
				last = k; 
				continue; 
			} 
			if(	PkTeamList[i].score > PkTeamList[PKListSort[k]].score ){ 
				last = k; 
				continue; 
			} 
			break; 
		} 
		if( last == -1 ) continue; 
		for( j=548; j>=last; j-- ){ 
			PKListSort[j+1] = PKListSort[j]; 
		} 
		PKListSort[last]=i; 
	} 
	memset(data,0,sizeof(data)); 
	for(i=0;i<550;i++){ 
		if(PKListSort[i] == -1) continue; 
			 
		sprintf(buf, "%s|%d|%d|%d|%d ", 
			PkTeamList[PKListSort[i]].teamname, 
			PkTeamList[PKListSort[i]].win, PkTeamList[PKListSort[i]].lost, 
			PkTeamList[PKListSort[i]].battleplay, PkTeamList[PKListSort[i]].score ); 
		strcat(data,buf); 
	} 
	PKLIST_HandleChartsMess(0,data,2,0); 
} 
 
//正式赛 
 
void ABATTLE_InitABattle( int maxnums ) 
{ 
	int i,j,k; 
	if( maxnums<1 || maxnums >= MAXBAFLOOR) return; 
	memset( ABLevelup, 0, sizeof(ABLevelup)); 
	for( k=0; ktop = NULL; 
		for( j=0; jfl = 0; 
			headABattle[i]->code = j; 
			break; 
		} 
		if( j >= MAXNOWBATTLE ) return; 
		ABATTLE_CreateNet( headABattle[i], i, 0, maxnums); 
	} 
	{ 
		FILE *fp=NULL; 
		int count=0; 
		char buf[256], buf1[256], buf2[256], filename[256]; 
		 
		for( i=0; iteamnum = atoi( buf1); 
				snprintf( NowABattle[i][maxnums][count]->teamname, 
					sizeof( NowABattle[i][maxnums][count]->teamname),"%s", buf2); 
				if( NowABattle[i][maxnums][count]->teamnum >= 0 ) 
					NowABattle[i][maxnums][count]->use = 1; 
 
				//andy_log 
				print("NowABattle[%d][%d][%d].  %x[%d,%d,%s]\n", 
					i, maxnums, count, 
					NowABattle[i][maxnums][count], 
					NowABattle[i][maxnums][count]->use,  
					NowABattle[i][maxnums][count]->teamnum, 
					NowABattle[i][maxnums][count]->teamname ); 
 
				count++; 
			} 
			fclose( fp); 
			//remove( filename); 
		} 
	} 
 
	maxbati = MAXBAHEAD; 
	maxfloor = maxnums; 
} 
 
int ABATTLE_CreateNet( ArrangeBattleC *now, int ti, int fl, int maxfl) 
{ 
	int i,j; 
	ArrangeBattleC *news=NULL; 
	//andy_log 
	print( "CreateNet( %d,%d)\n", ti, fl); 
 
	if( fl != 0 ){ 
		for( j=0; j NowABattle[%d][%d][%d]\n", ti, fl, j); 
			NowABattle[ti][fl][j] = now; 
			now->fl = fl; 
			now->code = j; 
			break; 
		} 
		if( j >= MAXNOWBATTLE ) return 0; 
	} 
	if( fl < maxfl ){ 
		for( i=0; i<2; i++){ 
		 
			news=NULL; 
			if( (news = ArrangeBattleC_getNew()) == NULL ){ 
				//andy_log 
				print("err can't get news NULL\n"); 
				return 0; 
			} 
			now->next[i] = news; 
			news->top = now; 
			if( ABATTLE_CreateNet( news, ti, fl+1, maxfl) == 0 ){ 
				//andy_log 
				print("err net free %x \n", news); 
				free( news ); 
				now->next[i] = NULL; 
				return 0; 
			} 
		} 
	} 
 
	return 1; 
} 
 
void ABATTLE_ShowNet( ArrangeBattleC *now, int fl) 
{ 
	int i; 
	if( now == NULL ) return; 
 
	if( now->fl == fl ){ 
		print(" [%d,%d,%s] %x,top:%x\n", now->use, now->teamnum, now->teamname, now, 
			now->top ); 
	} 
 
	for( i=0; i<2; i++){ 
		if( now->next[i] == NULL )continue; 
		ABATTLE_ShowNet( now->next[i], fl); 
	} 
} 
 
void ABATTLE_ShowBattlefromFl( int ti, int fl) 
{ 
	int j, total=0; 
	if( fl<0 ) return; 
	if( ti<0 || ti >= MAXBAHEAD ) return; 
	print("headABattle:%x\n", headABattle); 
	ABATTLE_ShowNet( headABattle[ti], fl); 
	print("\nNOWBATTLE:\n"); 
	if( fl<0 || fl >= MAXBAFLOOR) return; 
 
 
	for( j=0; juse, NowABattle[ti][fl][j]->teamnum,  
			NowABattle[ti][fl][j]->teamname, NowABattle[ti][fl][j], 
			NowABattle[ti][fl][j]->top ); 
		total++; 
	} 
	print("\ntotal:%d\n", total); 
} 
 
BOOL ABATTLE_InsertBattle( ArrangeBattleC *aB) 
{ 
	ArrangeBattleC *aBo=NULL; 
	int i; 
	if( aB == NULL ) return FALSE; 
	for( i=0; inext[0])==NULL || aBo->use == 0 || aBo->type > 0 ) return FALSE; 
		if( (aBo=aB->next[1])==NULL || aBo->use == 0 || aBo->type > 0 ) return FALSE; 
		InBattle[i] = aB; 
		InBattle[i]->next[0]->type =1; 
		InBattle[i]->next[1]->type =1; 
 
		print("InsertBattle[%d,%s vs %d,%s]\n", 
			InBattle[i]->next[0]->teamnum, InBattle[i]->next[0]->teamname, 
			InBattle[i]->next[1]->teamnum, InBattle[i]->next[1]->teamname ); 
#ifdef _DEATH_CONTENDTEST 
		aB->time = (int)time(NULL)+30;	//战斗时间 
#else 
		aB->time = (int)time(NULL)+(5*60);	//战斗时间 
#endif 
		aB->type = 1; // 战斗旗标 
		return TRUE; 
	} 
	return FALSE; 
} 
 
void ABATTLE_EnterBattle( ArrangeBattleC *aB) 
{ 
	ArrangeBattleC *aBtop=NULL; 
	ArrangeBattleC *aBo=NULL; 
 
	if( (aBtop=aB->top) == NULL ){ 
		//andy_log 
		print("del (aBtop=aB->top) NULL !\n"); 
		return; 
	} 
 
	aBtop->teamnum = aB->teamnum; 
	snprintf( aBtop->teamname, sizeof(aBtop->teamname),"%s", aB->teamname); 
	aBtop->type = 0; 
	aBtop->use = 1; 
 
	if( (aBo=aBtop->next[0]) != NULL ){ 
		aBo->use=0; 
		aBo->teamnum=-1; 
	} 
	if( (aBo=aBtop->next[1]) != NULL ){ 
		aBo->use=0; 
		aBo->teamnum=-1; 
	} 
} 
 
void ABATTLE_EliminateBattlefromFl( ArrangeBattleC *aB) 
{ 
	ArrangeBattleC *aBtop=NULL; 
	if( aB == NULL ) return; 
	aB->use=0; 
	aB->type = 0; 
	aB->teamnum = -1; 
	free( aB); 
} 
 
int ABATTLE_FindBattlefromFl( int ti, int fl) 
{ 
	int i, j, side=0, count=0; 
	ArrangeBattleC *aBo=NULL; 
	ArrangeBattleC *aB1=NULL; 
	ArrangeBattleC *aB2=NULL; 
 
	//andy_log 
	print( "FindBattlefromFl(%d,%d)\n", ti, fl); 
	for( i=0; inext[j]) == NULL || aB1->use == 0 || aB1->type > 0 )continue; 
 
			side = (j+1)%2; 
			aB2=aBo->next[side]; 
 
			if( aB2 == NULL || aB2->use == 0 || aB2->teamnum == -1 ){ //没有对手 
			}else{ 
				if( ABATTLE_InsertBattle( aBo) == FALSE ){ 
					return -1; 
				}else{ 
					char token[256]; 
					int playernum = CHAR_getPlayerMaxNum(); 
					sprintf( token, "%s队 VS %s队 5分钟後决斗。", aB1->teamname, aB2->teamname ); 
					PKLIST_shoutToAll( token, -1, -1); 
					count++; 
					// 把排入赛程的人员传入地图 8250 
					for(i=0;iteamnum || CHAR_getInt(i,CHAR_PKLISTTEAMNUM) == aB2->teamnum) && 
							CHAR_getInt(i,CHAR_FLOOR) != 8250){ 
							printf("send!!\n"); 
							CHAR_warpToSpecificPoint(i,8250,15,15); 
						} 
						else printf("has not send!!(teamnum:%d,floor:%d)\n",CHAR_getInt(i,CHAR_PKLISTTEAMNUM),CHAR_getInt(i,CHAR_FLOOR)); 
					} 
					//if( count >= 2) return count; 
					return count; 
				} 
			} 
		} 
	} 
	return count; 
} 
 
void ABATTLE_CheckBattlefromFl(int charindex, int ti,int battleindex) 
{ 
	int i = ti, count = 0,floor=0; 
	//ABFloor[MAXBAHEAD]; 
	//andy_log 
	print("ABATTLE_CheckBattlefromFl(%d,%d )..\n",ti,battleindex); 
	//for( i=0; iuse == 1 && headABattle[i]->teamnum != -1 ){ 
				char token[256]; 
				sprintf( token, "恭喜 %s 队,取得分组优胜,晋级下一阶段。", headABattle[i]->teamname ); 
				PKLIST_shoutToAll( token, -1, 8250); 
				ABATTLE_RecordBattle( i, headABattle[i]->teamname, "晋级8强", "NULL", ""); 
 
			} 
			if( (fp=fopen( "nbattle.txt", "a+")) != NULL ){ 
				fprintf( fp, "%d %d|%s|\n", 
					i, headABattle[i]->teamnum, headABattle[i]->teamname); 
				fclose( fp); 
			} 
		} 
	} 
 
} 
 
int ABATTLE_CheckBattlefromFl_sub(int charindex, int ti, int fl, int battleindex) 
{ 
	int i = battleindex; 
	char token[256]; 
	ArrangeBattleC *aBo=NULL; 
	ArrangeBattleC *aB1=NULL; 
	ArrangeBattleC *aB2=NULL; 
	 
	//andy_log 
	print("CheckBattlefromFl_sub( %d, %d, %d)\n", ti, fl, battleindex); 
 
	for( i=0; inext[0]; 
		aB2=aBo->next[1]; 
		if( (aB1 == NULL || aB1->use == 0 ) && 
			(aB2 == NULL || aB2->use == 0 ) ){//两队都不成立 
			if( aB1 != NULL ) free( aB1); 
			if( aB2 != NULL ) free( aB2); 
			aBo->next[0] = NULL; 
			aBo->next[1] = NULL; 
			continue; 
		}else if( aB1 == NULL || aB1->use == 0 || aB1->teamnum == -1 ){ //0不成立 
			ABATTLE_EliminateBattlefromFl( aB1); 
			aBo->next[0] = NULL; 
			if( aB2 != NULL && aB2->use != 0 && aB2->type == 0 ){ 
				ABATTLE_EnterBattle( aB2); 
			} 
			return fl; 
		}else if( aB2 == NULL || aB2->use == 0 || aB2->teamnum == -1 ){ //1不成立 
			ABATTLE_EliminateBattlefromFl( aB2); 
			aBo->next[1] = NULL; 
			if( aB1 != NULL && aB1->use != 0 && aB1->type == 0 ){ 
				ABATTLE_EnterBattle( aB1); 
			} 
			return fl; 
		}else{ 
			//andy_log 
			print("两者成立!.%d.%x[%d,%s] %x[%d,%s]\n", i, 
				aB1, aB1->teamnum, aB1->teamname, 
				aB2, aB2->teamnum, aB2->teamname ); 
			return fl; 
		} 
	} 
 
	return (fl-1); 
} 
 
//确认赛程战斗状态 包含时间 
BOOL ABATTLE_CheckInABattle( int ti) 
{ 
	ArrangeBattleC *aB=NULL; 
	ArrangeBattleC *aB1=NULL; 
	ArrangeBattleC *aB2=NULL; 
	int i; 
	int playernum = CHAR_getPlayerMaxNum(); 
	char token[256]; 
 
	if( ti<0 || ti>MAXBATTLEPAGE ) return FALSE; 
	if( (aB=InBattle[ti]) == NULL ) return FALSE; 
 
	aB1=aB->next[0]; 
	aB2=aB->next[1]; 
 
	switch( aB->type){ 
	case 0: 
		break; 
	case 1:	//已排入赛程 5分钟後进场 
		if( aB->time < (int)time(NULL) ){ 
			if( aB1 == NULL || aB1->use == 0 ||  
				aB2 == NULL || aB2->use == 0 ) return FALSE; 
			sprintf( token, "%s队 VS %s队,赛程即将开始,请两队做好准备。", 
				aB1->teamname, aB2->teamname ); 
			//PKLIST_shoutToAll( token, aB1->teamnum, 8250); 
			PKLIST_shoutToAll( token, aB2->teamnum, 8250); 
#ifdef _DEATH_CONTENDTEST 
			aB->time=(int)time(NULL)+30; 
#else 
			aB->time=(int)time(NULL)+(2*60); 
#endif 
			aB->type=2; 
			// 把排入赛程的人员传入地图 8250 
			for(i=0;iteamnum || CHAR_getInt(i,CHAR_PKLISTTEAMNUM) == aB2->teamnum) && 
					CHAR_getInt(i,CHAR_FLOOR) != 8250){ 
					printf("send!!\n"); 
					CHAR_warpToSpecificPoint(i,8250,15,15); 
				} 
				else printf("has not send!!(teamnum:%d,floor:%d)\n",CHAR_getInt(i,CHAR_PKLISTTEAMNUM),CHAR_getInt(i,CHAR_FLOOR)); 
			} 
		} 
		break; 
	case 2:	//已排入赛程 进场3分钟 并判断队长是否存在 并广播 
		{ 
			int playernum = CHAR_getPlayerMaxNum(); 
			for( i=0 ; itoindex) && 
					aB1->teamnum == CHAR_getInt( i, CHAR_PKLISTTEAMNUM) &&  
					CHAR_getInt( i, CHAR_PKLISTLEADER) == 1 && 
					PKLIST_CheckPKSameTeam( i) == TRUE ){ 
 
						int stime = ((aB->time)-(int)time(NULL)); 
						sprintf( token, "请快找齐你的所有队员,并组好队,%d秒後将进行传送。", (stime<0)?0:stime); 
						CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW); 
						aB1->toindex = i; 
						continue; 
 
				} 
				if( aB2!=NULL && !CHAR_CHECKINDEX( aB2->toindex) && 
					aB2->teamnum == CHAR_getInt( i, CHAR_PKLISTTEAMNUM) && 
					CHAR_getInt( i, CHAR_PKLISTLEADER) == 1 && 
					PKLIST_CheckPKSameTeam( i) == TRUE ){ 
						int stime = ((aB->time)-(int)time(NULL)); 
						sprintf( token, "请快找齐你的所有队员,并组好队,%d秒後将进行传送。", (stime<0)?0:stime); 
						CHAR_talkToCli( i, -1, token, CHAR_COLORYELLOW); 
						aB2->toindex = i; 
						continue; 
				} 
			} 
		} 
		// 把排入赛程的人员传入地图 8250 
		for(i=0;iteamnum || CHAR_getInt(i,CHAR_PKLISTTEAMNUM) == aB2->teamnum) && 
				CHAR_getInt(i,CHAR_FLOOR) != 8250) CHAR_warpToSpecificPoint(i,8250,15,15); 
		} 
 
		if( aB->time < (int)time(NULL) ){ 
			char token[256]; 
 
			sprintf( token, "%s队 VS %s队,赛程开始。", aB1->teamname, aB2->teamname ); 
			PKLIST_shoutToAll( token, -1, 8250); 
 
			if( CHAR_CHECKINDEX( aB1->toindex) && CHAR_CHECKINDEX( aB2->toindex) ){ 
				PKLIST_warpOne( aB2->toindex, PK_BATTLEMAP[ti].floor, PK_BATTLEMAP[ti].x+1, PK_BATTLEMAP[ti].y); 
				PKLIST_warpOne( aB1->toindex, PK_BATTLEMAP[ti].floor, PK_BATTLEMAP[ti].x, PK_BATTLEMAP[ti].y); 
#ifdef _DEATH_CONTENDTEST 
				aB->time=(int)time(NULL)+5; 
#else 
				aB->time=(int)time(NULL)+(20); 
#endif 
				aB->type=3; 
				return TRUE; 
			}else if( !CHAR_CHECKINDEX( aB1->toindex) && !CHAR_CHECKINDEX( aB2->toindex) ){ 
				sprintf( token, "%s队(%d),%s队(%d),因队长未在时间内到场,视为弃权。",aB1->teamname,aB1->toindex, 
					aB2->teamname,aB2->toindex); 
				ABATTLE_RecordBattle( ti, aB1->teamname, "未", aB2->teamname, "未"); 
				aB1->use = 0; 
				aB2->use = 0; 
			}else if( !CHAR_CHECKINDEX( aB1->toindex) ) { 
				sprintf( token, "%s队(%d),因队长未在时间内到场,视为弃权。",aB1->teamname,aB1->toindex); 
				aB1->use = 0; 
				ABATTLE_RecordBattle( ti, aB1->teamname, "未", "NULL", ""); 
				ABATTLE_EnterBattle( aB2); 
			}else if( !CHAR_CHECKINDEX( aB2->toindex) ){ 
				sprintf( token, "%s队(%d),因队长未在时间内到场,视为弃权。",aB2->teamname,aB2->toindex); 
				aB2->use = 0; 
				ABATTLE_RecordBattle( ti, aB2->teamname, "未", "NULL", ""); 
				ABATTLE_EnterBattle( aB1); 
			} 
			PKLIST_shoutToAll( token, -1, 8250); 
			InBattle[ti] = NULL; 
			return FALSE; 
		} 
		break; 
	case 3:	//已排入赛程 队伍到齐 5分钟内 强制战斗 
		aB->type=4; 
		aB->time=(int)time(NULL)+(2*60); 
		break; 
	case 4: 
		if( aB->time < (int)time(NULL) ){//强制战斗 
			if( CHAR_getWorkInt( aB1->toindex, CHAR_WORKBATTLEMODE) == BATTLE_CHARMODE_NONE ){ 
				//andy_log 
				print("强制战斗 %s vs %s \n", aB1->teamname, aB2->teamname); 
				BATTLE_CreateVsPlayer( aB1->toindex, aB2->toindex ); 
				aB->type = 5; 
			} 
		} 
		break; 
	} 
 
	return TRUE; 
} 
 
void ABATTLE_MakeInABattleString( void) 
{ 
	ArrangeBattleC *aB=NULL; 
	ArrangeBattleC *aB1=NULL; 
	ArrangeBattleC *aB2=NULL; 
	char buf1[256], buf[256]; 
	int i, fir=1; 
 
	memset( ABattlelist, 0, sizeof(ABattlelist)); 
 
	for( i=0; inext[0]) == NULL || aB1->use == 0 )continue; 
		if( (aB2=aB->next[1]) == NULL || aB2->use == 0 )continue; 
 
		switch( aB->type){ 
		case 0: continue; 
			break; 
		case 1://预定 
			strcpy( buf, "预定"); 
			break; 
		case 2://准备 
			strcpy( buf, "准备"); 
			break; 
		case 3://开始 
		case 4: 
			strcpy( buf, "开始"); 
			break; 
		} 
 
		sprintf( buf1, "%d|%s|%s|%d|%s", 
			i, aB1->teamname, aB2->teamname, aB->time, buf); 
		if( fir != 1 ) strcat( ABattlelist, " "); 
		fir=0; 
		strcat( ABattlelist, buf1); 
	} 
} 
 
BOOL PKLIST_GetABattlelistDataString( int ti, int *tindex, int *stimes, 
									 char *buf1, char *buf2, char *buf3, int flg) 
{ 
	char data[1024], buf[256], buff[256]; 
	switch( flg){ 
	case 3: 
		{ 
			memset( data, 0, sizeof(data)); 
			if( getStringFromIndexWithDelim( ABattlelist, " ", ti, data, sizeof(data)) == FALSE  ) 
				return FALSE; 
			if( getStringFromIndexWithDelim( data, "|", 1, buf, sizeof( buf)) == FALSE ) return FALSE; 
			*tindex=atoi( buf); 
			if( getStringFromIndexWithDelim( data, "|", 2, buf, sizeof( buf))== FALSE) return FALSE; 
			strcpy( buf1, buf); 
			if( getStringFromIndexWithDelim( data, "|", 3, buf, sizeof( buf))== FALSE) return FALSE; 
			strcpy( buf2, buf); 
			if( getStringFromIndexWithDelim( data, "|", 4, buf, sizeof( buf))== FALSE) return FALSE; 
			*stimes = atoi( buf); 
			if( getStringFromIndexWithDelim( data, "|", 5, buf, sizeof( buf))== FALSE ) return FALSE; 
			strcpy( buf3, buf); 
		} 
		break; 
	case 5: 
		{ 
			if( getStringFromIndexWithDelim( ABLevelup, " ", ti, data, sizeof(data)) == FALSE  ) 
				return FALSE; 
			if( getStringFromIndexWithDelim( data, "|", 1, buf, sizeof( buf)) == FALSE ) return FALSE; 
			*tindex=atoi( buf); 
			if( getStringFromIndexWithDelim( data, "|", 2, buff, sizeof( buff)) == FALSE ) return FALSE; 
			if( getStringFromIndexWithDelim( data, "|", 3, buf, sizeof( buf)) == FALSE ) return FALSE; 
			sprintf( buf1, "[%s]%s ", buff, buf); 
			if( getStringFromIndexWithDelim( data, "|", 4, buff, sizeof( buff)) == FALSE ) return FALSE; 
			if( getStringFromIndexWithDelim( data, "|", 5, buf, sizeof( buf)) == FALSE ) return FALSE; 
			sprintf( buf2, "[%s]%s ", buff, buf); 
		} 
		break; 
	} 
	return TRUE; 
} 
 
ArrangeBattleC *ABATTLE_getInBattle( int teamnum) 
{ 
	ArrangeBattleC *aB=NULL; 
	ArrangeBattleC *aBx=NULL; 
	int i; 
 
	for( i=0; inext[0]) != NULL && aBx->use == 1 && aBx->teamnum != -1 ){ 
			if( aBx->teamnum == teamnum ) 
				return aBx; 
		} 
		if( (aBx=aB->next[1]) != NULL && aBx->use == 1 && aBx->teamnum != -1 ){ 
			if( aBx->teamnum == teamnum ) 
				return aBx; 
		} 
	} 
	return NULL; 
} 
 
ArrangeBattleC *ArrangeBattleC_getNew( void) 
{ 
	ArrangeBattleC *MBUF=NULL; 
	MBUF = (ArrangeBattleC *) calloc( 1, sizeof( struct _tagArrangeBattle) ); 
	if( MBUF == NULL ) return NULL; 
 
	MBUF->use = 0; 
	MBUF->fl = -1; 
	MBUF->code = -1; 
	MBUF->teamnum = -1; 
	MBUF->toindex = -1; 
	MBUF->type=0; 
	MBUF->teamname[0]=0; 
	MBUF->next[0] = NULL; 
	MBUF->next[1] = NULL; 
	MBUF->top = NULL; 
 
	return MBUF; 
} 
 
ArrangeBattleC *ArrangeBattleC_getInBattleArray( int ti) 
{ 
	if( ti<0 || ti>MAXBATTLEPAGE ) return NULL; 
	return InBattle[ti]; 
} 
 
void ABATTLE_RecordBattle( int ti, char *buf1, char *tstr1,char *buf2, char *tstr2) 
{//ABLevelup 
	char strlog[512]; 
	FILE *fp=NULL; 
 
	if( (fp=fopen( "battle.rec", "a+") )==NULL )return; 
	sprintf( strlog, "%d|%s|%s|%s|%s", ti, tstr1, buf1, tstr2, buf2); 
	fprintf( fp, "%s\n", strlog); 
	fclose( fp); 
 
	ABATTLE_GetRecordBattle(); 
} 
 
void remove_r( char *s ) 
{ 
    int i; 
    for(i=0;;i++){ 
        if( s[i]=='\r' || s[i]=='\n' )s[i] =0; 
        if( s[i]==0)break; 
    } 
} 
 
void ABATTLE_GetRecordBattle( void) 
{//ABLevelup 
	char data[512]; 
	FILE *fp=NULL; 
	memset( ABLevelup, 0, sizeof(ABLevelup)); 
 
	if( (fp=fopen( "battle.rec", "r") )==NULL )return; 
	while( fgets( data, sizeof(data)-1, fp) ){ 
		if( strlen( data) <= 0 ) continue; 
		remove_r( data); 
		if( strlen( ABLevelup) > 0 ) strcat( ABLevelup, " "); 
		strcat( ABLevelup, data); 
	} 
	fclose( fp); 
} 
 
void PKLIST_UpData(char *mycdkey,char *tocdkey,int menum,int tonum,int winer,int flg) 
{ 
	int k,meti,toti; 
 
	if((meti = PKLIST_GetPkTeamListArray(menum,mycdkey)) == -1){ 
		printf("can't find meteam.teamnum(%d),cdkey(%s)\n",menum,mycdkey); 
		return; 
	} 
	if((toti = PKLIST_GetPkTeamListArray(tonum,tocdkey)) == -1){ 
		printf("can't find toteam.teamnum(%d),cdkey(%s)\n",tonum,tocdkey); 
		return; 
	} 
 
	if(PkTeamList[meti].use != 1){ 
		printf("meteam not in use.teamnum(%d),cdkey(%s)\n",menum,mycdkey); 
		return; 
	} 
	/*for(k=0;k= 90 ){ 
		PkTeamList[ti].inside = 2; //录取 
	}else if( PkTeamList[ti].lost > 50*0.4){// 0.7 = (1-胜率3成)*最高场次 
		PkTeamList[ti].inside = 0; 
	}else { 
		PkTeamList[ti].inside = 1; 
	} 
 
	if( PkTeamList[ti].score < 0 ) PkTeamList[ti].score = 0; 
 
	ret = PKLIST_SetOneBHistory( ti, battleTi, 1, forti, winerflg); 
	//PKLIST_SortTheCharts( ti); 
	return ret; 
} 
 
int PKLIST_GetOneBHistory( int ti ) 
{ 
	int i; 
	if( ti < 0 || ti >= maxteam ){ 
		printf( "GetOneBHistory(ti:%d) err return -1 !!\n", ti); 
		return -1; 
	} 
	for( i=0; i=DEFMAXBATTLENUM ) break; 
		if( PkTeamList[ti].BHistory[i].use == 0 ){ 
			printf("return BHistory[%d] \n", i) ; 
			return i; 
		} 
	} 
 
	printf("BATTLEFULL err !! \n") ; 
	return -1; 
} 
 
int PKLIST_SetOneBHistory( int ti, int hi, int use, int teamnum, int flg ) 
{ 
	if( ti < 0 || ti >= maxteam ) return -1; 
	if( hi < 0 || hi >= MAXBATTLENUM ) return -1; 
	if( PkTeamList[ti].BHistory[hi].use == use ) return -1; 
	 
	PkTeamList[ti].BHistory[hi].teamnum = teamnum; 
	PkTeamList[ti].BHistory[hi].flg = flg; 
	PkTeamList[ti].BHistory[hi].use = use; 
	return 1; 
} 
 
#endif