
#include "Fight.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "PublicFun.h"
#include <fstream>

extern int useableskillnum2;
extern  PAINTSTRUCT ps;
extern 	HDC hdc;
extern 	HBITMAP hbmp; 
extern 	HBITMAP hbmp2; 
extern 	BITMAP bmp;
extern 	HDC hdcMem;
extern 	HDC hdcTmp;
extern 	RECT rect;
extern 	HWND hwnd;
extern  char texta[TEXTAMAX][20];
int arrow[MAPMAX][MAPMAX];//移动
int atarr[MAPMAX][MAPMAX];//普通攻击
int skillarr[MAPMAX][MAPMAX];//技能
extern int t_tile[MAPSUM][MAPMAX][MAPMAX];
extern int t_citymapnum[CITYMAX];
extern int t_tilestyle[TILEMAX];

extern int KeyReturn;
extern int KeyEsc;
extern int KeyHome;
extern int KeySpace;
extern int KeyLeft0;
extern int KeyUp0;
extern int KeyRight0;
extern int KeyDown0;

extern int menushow1;
extern int menumove1;
extern int menuspeed1;
extern int color;

extern char t_heroName[HEROMAX][HERONAMEMAXLEN]; 
extern char t_skillName[SKILLMAX][SKILLNAMEMAXLEN];
extern char t_goodName[GOODMAX][GOODNAMEMAXLEN];
extern HFONT t_h;
extern HPEN t_hpen;
extern HBRUSH t_hbrush;

extern char workpath[MAX_PATH];   
extern char absolutepath[MAX_PATH];

int atnowhero=0;
int atnowheroat=0;
int tmpposx=0;
int tmpstarty=0;
int tmpstartx=0;
int tmparrowy=0;
int tmparrowx=0;
int tmpposy=0;
int flagunable=0;
int flagshowsj=0;
int flagshowsw=0;
//int startflag[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int flagshowhurt=0;
int flagshowskillhurt=0;
int ex=0;
int aimat=0;
int hurtmax=0;
int nouse_new_flag1=0;
int new_flag1=0;

int timeTemp = 0;//显示用变量20170205

using namespace std;

void Fight::PubInit(int choice)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	uchoice=choice;
}

void Fight::InitData(int heronumber,int zujiang,int citynumber,int foods)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	//fightmap=new FightMap();
	fightmap.Init(uchoice,citynumber);
	fightmap.citynumfrom=citynumfrom;
	for(int y=0;y<20;y++)
	{
		//fighthero[y]=new FightHero();
		fighthero[y].citynumfrom=citynumfrom;
		fighthero[y].Init(uchoice,citynumber);
		//fighthero[y].SetPosition(y);
	}

	

	//menufight=new Menu();
	menufight.InitMenu(4,5,30,80,4,"Res\\fightesc.sss",1);
	//menushow=new Menu();
	menushow.InitMenu(2,2,290,200,1,"Res\\fightshow.sss",1);
	//menuspeed=new Menu();	 
	menuspeed.InitMenu(2,2,290,200,1,"Res\\fightspeed.sss",1);
	//menumove=new Menu();
	menumove.InitMenu(2,2,290,200,1,"Res\\fightshow.sss",1);
	//menuhero=new Menu();
	menuhero.InitMenu(2,4,400,200,3,"Res\\fightfight.sss",1);
	this->foods=foods;
	weather=1;
	day=1;
	this->foods=foods;
	flagstat=0;
	flagmenu=0;
	flagmenushow=0;
	flagmenumov=0;
	flagmenuspeed=0;
	flagmenuhero=0;
	flaggetfoodamount=0;
	flagarrowmov=0;
	flagarrowat=0;
	flagshowskill=0;//显示技能列表
	flagarrowskill=0;//显示技能范围
	//menushow1=1;//战斗动画
	//menumove1=1;//敌军移动
	//menuspeed1=1;//移动速度

	this->heronumber=heronumber;
	this->citynumber=citynumber;
	this->zujiang=zujiang;
	//InitWujiangData();//给武将属性
	starty=0;
	starty1=0;
	InitSkill();
	InitAffact();
	InitMapStyle();
	
	//headfight=new Head();

}

int Fight::DynamicShow()
{
	fightmap.citynumfrom=citynumfrom;
	for(int hi=0;hi<20;hi++)
	{
		fighthero[hi].citynumfrom=citynumfrom;
		fighthero[hi].warstyle=warstyle;
		fighthero[hi].SetPosition(hi);
	}

	ShowBar();
	fightmap.ShowStart(-2,warstyle);//以敌方主将为中心显示
	
	for(int y=10;y<heronumberto+10;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
			fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
		{
			int yy=fighthero[y].positionx-fightmap.startx;
			int xx=fighthero[y].positiony-fightmap.starty;
			fighthero[y].ShowDirct(xx,yy);//显示敌方武将
		}

	}//显示敌方武将
	Delay(2000);
	fightmap.ShowStart(-1,warstyle);//以自己主将为中心显示
	for(int y=0;y<heronumber;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
			fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
		{
			int yy=fighthero[y].positionx-fightmap.startx;
			int xx=fighthero[y].positiony-fightmap.starty;
			fighthero[y].ShowDirct(xx,yy);//显示己方武将
		}

	}//显示己方武将
	Delay(2000);
	//增加对兵力的检查
	CheckForceBefore();
	if(fighthero[0].bingli==0)
	{
		//我方失败
		new_flag1=1;
	}
	if(fighthero[10].bingli==0)//20150517
	{
		//我方成功
		new_flag1=2;
	}

	ShowWeather();//显示、获取天气并在下方更新
	ShowWeatherBar();
	ShowDay();
	fightmap.Show(0);//自己主将
	/*for(int y=0;y<20;y++)
	{
	fighthero[y].Show();//显示己方武将
	}*/
	for(int er=0;er<heronumber;er++)
	{
		atnowhero=er;
		GetLifeSkillAtDf();
	}
	for(int er=10;er<heronumberto+10;er++)
	{
		atnowhero=er;
		GetLifeSkillAtDf();
	}
	atnowhero=0;

	for(int df=0;df<heronumber;df++)
	{
		OverflowCheck(__FILE__,__LINE__,20,df);
		if(fighthero[df].statue==8)continue;
		int health = (fighthero[df].wuli * 80 / 100 + fighthero[df].zili * 30 / 100 +fighthero[df].degree) * fighthero[df].tili/ 100;
		if(health<0)health=0;
		fighthero[df].health=health;
		int skill = (fighthero[df].zili * 80 / 100 + (PlcExtract(fighthero[df].wuli) >> 1) +fighthero[df].degree) * fighthero[df].tili/ 100;
		if(skill<0)skill=0;	
		fighthero[df].skill=skill;
	}
	for(int df=10;df<heronumberto+10;df++)
	{
		OverflowCheck(__FILE__,__LINE__,20,df);
		if(fighthero[df].statue==8)continue;
		int health = (fighthero[df].wuli * 80 / 100 + fighthero[df].zili * 30 / 100 +fighthero[df].degree) * fighthero[df].tili/ 100;
		if(health<0)health=0;
		fighthero[df].health=health;
		int skill = (fighthero[df].zili * 80 / 100 + (PlcExtract(fighthero[df].wuli) >> 1) +fighthero[df].degree) * fighthero[df].tili/ 100;
		if(skill<0)skill=0;	
		fighthero[df].skill=skill;
	}

	return 0;
}

int Fight::BattlefieldStatusShow(int flagstat)
{
	if(flagstat==1)
	{
		ShowCG(0,"Res\\white.sbp",0,0);
		ShowText(GetStrText("dPowerCmp"),20,60,60);
		ShowText(GetStrText("dDaysInf"),20,130,60);
		ShowText(GetStrText("dReserve0"),80,220,60);
		char str[10];
		sprintf_s(str,"%d",day-1);
		ShowText(str,110+(25-strlen(str)*25/2),130,60);

		MySetShowStyle();
		HPEN hpen=t_hpen;
		HPEN oldhpen=(HPEN)SelectObject(hdcTmp,hpen);

		HBRUSH hbrush = t_hbrush;
		HBRUSH hbrold = (HBRUSH)SelectObject(hdcTmp, hbrush); 




		Rectangle(hdcTmp,115,295,280,455); 
		ShowAllOf();//显示将领分布
		Rectangle(hdcTmp,400,55,795,125); 
		ShowText(GetStrText("dArmyInf"),600,60,60);
		ShowUpName(1);//敌方
		Rectangle(hdcTmp,400,125,795,195); 
		ShowText(GetStrText("dProvInf"),410,130,60);
		if(flaggetfoodamount==0)
		{
			ShowText(GetStrText("dNoView"),550,130,60);
		}
		else
		{
			char str[20];
			sprintf_s(str,"%d",foodsto);
			ShowText(str,550,130,60);
		}
		Rectangle(hdcTmp,400,195,795,520); 
		ShowArmyNumber(1);//显示军队及将领
		SelectObject(hdcTmp,oldhpen);
		DeleteObject(hpen);
		SelectObject(hdcTmp,hbrold);
		DeleteObject(hbrush);
	}
	else if(flagstat==2)
	{
		//显示战场状况,我方
		ShowCG(0,"Res\\white.sbp",0,0);
		ShowText(GetStrText("dPowerCmp"),20,60,60);
		ShowText(GetStrText("dDaysInf"),20,130,60);
		ShowText(GetStrText("dReserve0"),80,220,60);
		char str[10];
		sprintf_s(str,"%d",day-1);
		ShowText(str,110+(25-strlen(str)*25/2),130,60);

		MySetShowStyle();
		HPEN hpen=t_hpen;
		HPEN oldhpen=(HPEN)SelectObject(hdcTmp,hpen);

		HBRUSH hbrush = t_hbrush;
		HBRUSH hbrold = (HBRUSH)SelectObject(hdcTmp, hbrush); 

		Rectangle(hdcTmp,115,295,280,455); 
		ShowAllOf();//显示将领分布
		Rectangle(hdcTmp,400,55,795,125); 
		ShowText(GetStrText("dArmyInf"),600,60,60);
		ShowUpName(0);//我方
		Rectangle(hdcTmp,400,125,795,195); 
		ShowText(GetStrText("dProvInf"),410,130,60);
		char str1[20];
		sprintf_s(str1,"%d",foods);
		ShowText(str1,550,130,60);
		Rectangle(hdcTmp,400,195,795,520); 
		ShowArmyNumber(0);//显示军队及将领
		SelectObject(hdcTmp,oldhpen);
		DeleteObject(hpen);
		SelectObject(hdcTmp,hbrold);
		DeleteObject(hbrush);
	}
	return 0;
}

int Fight::HeroStatusShow(int flagstat)
{
	if(flagstat==3)//我方
	{
		MySetShowStyle();
		HPEN hpen=t_hpen;
		HPEN oldhpen=(HPEN)SelectObject(hdcTmp,hpen);

		HBRUSH hbrush = t_hbrush;
		HBRUSH hbrold = (HBRUSH)SelectObject(hdcTmp, hbrush); 

		MyCreateFont(1.0);
		HFONT	h = t_h;
		HFONT oldh=(HFONT)SelectObject(hdcTmp,h);
		MySetTextColor(FONTA,USEHDCTMP);

		Rectangle(hdcTmp,20,70,780,510); 
		//ShowCG(0,"Res\\white.sbp",0,0);
		ShowText(GetStrTextSpilted("dFgtHlpGen",0,3),40,80,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",1,3),250,80,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",2,4),40,145,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",6,2),370,145,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",7,2),40,210,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",6,3),200,210,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",7,3),40,310,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",8,3),280,310,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",9,3),540,310,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",10,3),120,375,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",11,3),400,375,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",12,3),40,440,60);
		GetLifeSkillAtDf();
		char str[10];
		OverflowCheck(__FILE__,__LINE__,20,atnowhero);
		sprintf_s(str,"%d",fighthero[atnowhero].degree);
		ShowText(str,180,80,60);
		sprintf_s(str,"%d",fighthero[atnowhero].wuli );
		ShowText(str,290,145,60);
		sprintf_s(str,"%d",fighthero[atnowhero].zili);
		ShowText(str,120,210,60);
		sprintf_s(str,"%d",fighthero[atnowhero].experience );
		ShowText(str,410,210,60);
		sprintf_s(str,"%d",fighthero[atnowhero].health );
		ShowText(str,180,310,60);
		//fighthero[atnowhero].skill=0;
		sprintf_s(str,"%d",fighthero[atnowhero].skill);
		ShowText(str,470,310,60);
		//fighthero[atnowhero].at=120;
		int att=fighthero[atnowhero].at;
		if(att<10)
		{
			sprintf_s(str,"%d",att);
			ShowText(str,720,310,60);
		}
		else if(att<100)
		{
			att=att/10;
			sprintf_s(str,"%d",att);
			ShowText(str,720,310,60);
			int atb=fighthero[atnowhero].at-att*10;
			sprintf_s(str,"%d",atb);
			ShowText(str,40,375,60);
		}
		else if(att<1000)
		{
			att=att/100;
			sprintf_s(str,"%d",att);
			ShowText(str,720,310,60);
			int atb=fighthero[atnowhero].at-att*100;
			atb=atb/10;
			sprintf_s(str,"%d",atb);
			ShowText(str,40,375,60);
			int atc=fighthero[atnowhero].at-att*100-atb*10;
			sprintf_s(str,"%d",atc);
			ShowText(str,70,375,60);
		}
		else
		{
			att=att/1000;
			sprintf_s(str,"%d",att);
			ShowText(str,720,310,60);
			int atb=fighthero[atnowhero].at-att*1000;
			atb=atb/100;
			sprintf_s(str,"%d",atb);
			ShowText(str,40,375,60);
			int atc=fighthero[atnowhero].at-att*1000-atb*100;
			atc=atc/10;
			sprintf_s(str,"%d",atc);
			ShowText(str,70,375,60);
			int atd=fighthero[atnowhero].at-att*1000-atb*100-atc*10;
			sprintf_s(str,"%d",atd);
			ShowText(str,100,375,60);
		}
		//fighthero[atnowhero].df=0;
		sprintf_s(str,"%d",fighthero[atnowhero].df);
		ShowText(str,310,375,60);
		sprintf_s(str,"%d",fighthero[atnowhero].bingli);
		ShowText(str,610,375,60);

		ShowText(GetStrTextSpilted("dFgtGenTyp",fighthero[atnowhero].style,1),430,80,60);

		/*switch(fighthero[atnowhero].style)
		{
		case CAVALRY:
		ShowText(GetStrTextSpilted("dFgtGenTyp",0,2),430,80,60);
		break;
		case INFANTRY:
		ShowText(GetStrTextSpilted("dFgtGenTyp",1,2),430,80,60);
		break;
		case ARCHER:
		ShowText(GetStrTextSpilted("dFgtGenTyp",2,2),430,80,60);
		break;
		case SAILOR:
		ShowText(GetStrTextSpilted("dFgtGenTyp",3,2),430,80,60);
		break;
		case GREATHPARM:
		ShowText(GetStrTextSpilted("dFgtGenTyp",4,2),430,80,60);
		break;
		case GREATMPARM:
		ShowText(GetStrTextSpilted("dFgtGenTyp",5,2),430,80,60);
		break;
		}*/
		/*#define	STATE_ZC		0		// 正常 
		#define	STATE_HL		1		//混乱 
		#define	STATE_JZ		2		// 禁咒 
		#define	STATE_DS		3		// 定身 
		#define	STATE_QM		4		// 奇门 
		#define	STATE_DJ		5		// 遁甲 
		#define	STATE_SZ		6		// 石阵 
		#define	STATE_QZ		7		// 潜踪
		#define	STATE_SW		8		// 死亡 */

		switch(fighthero[atnowhero].statue)
		{
		case NORMALSTATUS:
			ShowText(GetStrText("dFgtState0"),220,440,60);
			break;
		case CHAOSSTATUS:
			ShowText(GetStrText("dFgtState1"),220,440,60);
			break;
		case CURSESEALSTATUS:
			ShowText(GetStrText("dFgtState2"),220,440,60);
			break;
		case IMMOBILIZEDSTATUS:
			ShowText(GetStrText("dFgtState3"),220,440,60);
			break;
		case INVISIBLEMAGICSTATUS:
			ShowText(GetStrText("dFgtState4"),220,440,60);
			break;
		case RUNAWAYMAGICSTATUS:
			ShowText(GetStrText("dFgtState5"),220,440,60);
			break;
		case STONEHENGESTATUS:
			ShowText(GetStrText("dFgtState6"),220,440,60);
			break;
		case INVISIBLESTATUS:
			ShowText(GetStrText("dFgtState7"),220,440,60);
			break;

		}

		Rectangle(hdcTmp,520,80,770,300); 
		int ry=fighthero[atnowhero].num;
		switch(uchoice)
		{
		case DZNQ:
			headfight.Init("Res\\Head\\1dznq.sbp",ry);
			break;
		case CCJQ:	
			headfight.Init("Res\\Head\\2ccjq.sbp",ry);
			break;
		case CBZZ:
			headfight.Init("Res\\Head\\3cbzz.sbp",ry);
			break;
		case SGDL:
			headfight.Init("Res\\Head\\4sgdl.sbp",ry);
			break;
		default:
			{
				char name[NORMALSTRLEN];
				sprintf_s(name,"Res\\Head\\period%d.sbp",uchoice+1);
				headfight.Init(name,ry);
			}
			break;
		}
		headfight.Show(590,85);
		char heroname[20];

		sprintf_s(heroname,"%s",t_heroName[ry]);
		//oldh=(HFONT)SelectObject(hdcTmp,h); 
		ShowText(heroname,540+(100-strlen(heroname)*25/2),230,50);
		//TextOut(hdcTmp,540+(100-strlen(heroname)*25/2),230,heroname,strlen(heroname));
		SelectObject(hdcTmp,oldhpen);
		DeleteObject(hpen);
		SelectObject(hdcTmp,oldh);	
		DeleteObject(h);
		SelectObject(hdcTmp,hbrold);
		DeleteObject(hbrush);
		/*char str[10];
		sprintf_s(str,"%d",day-1);
		ShowText(str,95,130,60);
		HPEN hpen=CreatePen(PS_SOLID,5, RGB(0,0,0));
		SelectObject(hdcTmp,hpen);
		Rectangle(hdcTmp,115,295,280,455); 
		ShowAllOf();//显示将领分布
		Rectangle(hdcTmp,400,55,795,125); 
		ShowText("军",600,60,60);
		ShowUpName(0);//我方
		Rectangle(hdcTmp,400,125,795,195); 
		ShowText("粮草:",410,130,60);
		char str1[20];
		sprintf_s(str1,"%d",foods);
		ShowText(str1,550,130,60);
		Rectangle(hdcTmp,400,195,795,520); 
		ShowArmyNumber(0);//显示军队及将领
		DeleteObject(hpen);*/
	}
	else if (flagstat == 5)//敌方
	{
		MySetShowStyle();
		HPEN hpen=t_hpen;
		HPEN oldhpen=(HPEN)SelectObject(hdcTmp,hpen);

		HBRUSH hbrush = t_hbrush;
		HBRUSH hbrold = (HBRUSH)SelectObject(hdcTmp, hbrush); 

		MyCreateFont(1.0);
		HFONT	h = t_h;
		HFONT oldh=(HFONT)SelectObject(hdcTmp,h);
		MySetTextColor(FONTA,USEHDCTMP);

		Rectangle(hdcTmp,20,70,780,510); 
		//ShowCG(0,"Res\\white.sbp",0,0);
		ShowText(GetStrTextSpilted("dFgtHlpGen",0,3),40,80,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",1,3),250,80,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",2,4),40,145,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",6,2),370,145,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",7,2),40,210,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",6,3),200,210,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",7,3),40,310,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",8,3),280,310,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",9,3),540,310,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",10,3),120,375,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",11,3),400,375,60);
		ShowText(GetStrTextSpilted("dFgtHlpGen",12,3),40,440,60);
		int tjk=atnowhero;
		atnowhero=atnowheroat;
		GetLifeSkillAtDf();
		atnowhero=tjk;
		char str[10];
		OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
		sprintf_s(str,"%d",fighthero[atnowheroat].degree);
		ShowText(str,180,80,60);
		sprintf_s(str,"%d",fighthero[atnowheroat].wuli );
		ShowText(str,290,145,60);
		sprintf_s(str,"%d",fighthero[atnowheroat].zili);
		ShowText(str,120,210,60);
		sprintf_s(str,"%d",fighthero[atnowheroat].experience );
		ShowText(str,410,210,60);
		sprintf_s(str,"%d",fighthero[atnowheroat].health );
		ShowText(str,180,310,60);
		//fighthero[atnowhero].skill=0;
		sprintf_s(str,"%d",fighthero[atnowheroat].skill);
		ShowText(str,470,310,60);
		//fighthero[atnowhero].at=120;
		int att=fighthero[atnowheroat].at;
		if(att<10)
		{
			sprintf_s(str,"%d",att);
			ShowText(str,720,310,60);
		}
		else if(att<100)
		{
			att=att/10;
			sprintf_s(str,"%d",att);
			ShowText(str,720,310,60);
			int atb=fighthero[atnowheroat].at-att*10;
			sprintf_s(str,"%d",atb);
			ShowText(str,40,375,60);
		}
		else if(att<1000)
		{
			att=att/100;
			sprintf_s(str,"%d",att);
			ShowText(str,720,310,60);
			int atb=fighthero[atnowheroat].at-att*100;
			atb=atb/10;
			sprintf_s(str,"%d",atb);
			ShowText(str,40,375,60);
			int atc=fighthero[atnowheroat].at-att*100-atb*10;
			sprintf_s(str,"%d",atc);
			ShowText(str,70,375,60);
		}
		else
		{
			att=att/1000;
			sprintf_s(str,"%d",att);
			ShowText(str,720,310,60);
			int atb=fighthero[atnowheroat].at-att*1000;
			atb=atb/100;
			sprintf_s(str,"%d",atb);
			ShowText(str,40,375,60);
			int atc=fighthero[atnowheroat].at-att*1000-atb*100;
			atc=atc/10;
			sprintf_s(str,"%d",atc);
			ShowText(str,70,375,60);
			int atd=fighthero[atnowheroat].at-att*1000-atb*100-atc*10;
			sprintf_s(str,"%d",atd);
			ShowText(str,100,375,60);
		}
		//fighthero[atnowhero].df=0;
		sprintf_s(str,"%d",fighthero[atnowheroat].df);
		ShowText(str,310,375,60);
		sprintf_s(str,"%d",fighthero[atnowheroat].bingli);
		ShowText(str,610,375,60);

		ShowText(GetStrTextSpilted("dFgtGenTyp",fighthero[atnowheroat].style,1),430,80,60);
		/*switch(fighthero[atnowheroat].style)
		{
		case CAVALRY:
		ShowText("骑",430,80,60);
		break;
		case INFANTRY:
		ShowText("步",430,80,60);
		break;
		case ARCHER:
		ShowText("弓",430,80,60);
		break;
		case SAILOR:
		ShowText("水",430,80,60);
		break;
		case GREATHPARM:
		ShowText("极",430,80,60);
		break;
		case GREATMPARM:
		ShowText("玄",430,80,60);
		break;
		}*/


		switch(fighthero[atnowheroat].statue)
		{
		case NORMALSTATUS:
			ShowText(GetStrText("dFgtState0"),220,440,60);
			break;
		case CHAOSSTATUS:
			ShowText(GetStrText("dFgtState1"),220,440,60);
			break;
		case CURSESEALSTATUS:
			ShowText(GetStrText("dFgtState2"),220,440,60);
			break;
		case IMMOBILIZEDSTATUS:
			ShowText(GetStrText("dFgtState3"),220,440,60);
			break;
		case INVISIBLEMAGICSTATUS:
			ShowText(GetStrText("dFgtState4"),220,440,60);
			break;
		case RUNAWAYMAGICSTATUS:
			ShowText(GetStrText("dFgtState5"),220,440,60);
			break;
		case STONEHENGESTATUS:
			ShowText(GetStrText("dFgtState6"),220,440,60);
			break;
		case INVISIBLESTATUS:
			ShowText(GetStrText("dFgtState7"),220,440,60);
			break;

		}

		Rectangle(hdcTmp,520,80,770,300); 
		int ry=fighthero[atnowheroat].num;
		switch(uchoice)
		{
		case DZNQ:
			headfight.Init("Res\\Head\\1dznq.sbp",ry);
			break;
		case CCJQ:	
			headfight.Init("Res\\Head\\2ccjq.sbp",ry);
			break;
		case CBZZ:
			headfight.Init("Res\\Head\\3cbzz.sbp",ry);
			break;
		case SGDL:
			headfight.Init("Res\\Head\\4sgdl.sbp",ry);
			break;
		default:
			{
				char name[NORMALSTRLEN];
				sprintf_s(name,"Res\\Head\\period%d.sbp",uchoice+1);
				headfight.Init(name,ry);
			}
			break;
		}
		headfight.Show(590,85);
		char heroname[20];
		OverflowCheck(__FILE__,__LINE__,HEROMAX,ry);
		sprintf_s(heroname,"%s",t_heroName[ry]);
		//oldh=(HFONT)SelectObject(hdcTmp,h); 
		ShowText(heroname,540+(100-strlen(heroname)*25/2),230,50);
		//TextOut(hdcTmp,540+(100-strlen(heroname)*25/2),230,heroname,strlen(heroname));
		SelectObject(hdcTmp,oldhpen);
		DeleteObject(hpen);
		SelectObject(hdcTmp,oldh);	
		DeleteObject(h);
		SelectObject(hdcTmp,hbrold);
		DeleteObject(hbrush);
	}
	return 0;
}

int Fight::TerrainStatusShow()
{
	MySetShowStyle();
	HPEN hpen=t_hpen;
	HPEN oldhpen=(HPEN)SelectObject(hdcTmp,hpen);

	HBRUSH hbrush = t_hbrush;
	HBRUSH hbrold = (HBRUSH)SelectObject(hdcTmp, hbrush); 


	Rectangle(hdcTmp,20,70,780,510); 
	int wx=fightmap.arrowy+fightmap.startx ;
	int wy=fightmap.arrowx+fightmap.starty ;
	OverflowCheck(__FILE__,__LINE__,MAPMAX,wx);
	OverflowCheck(__FILE__,__LINE__,MAPMAX,wy);
	switch(fightmap.tilestyle[wx][wy])
	{
	case PLAIN://平地
		ShowText(GetStrTextSpilted("dTerrInf0",0,11),40,80,60);
		ShowText(GetStrTextSpilted("dTerrInf0",1,11),40,160,60);
		break;
	case GRASS://草地
		ShowText(GetStrTextSpilted("dTerrInf1",0,11),40,80,60);
		ShowText(GetStrTextSpilted("dTerrInf1",1,11),40,160,60);
		break;
	case MOUNTAIN://山脉
		ShowText(GetStrTextSpilted("dTerrInf2",0,11),40,80,60);
		ShowText(GetStrTextSpilted("dTerrInf2",1,11),40,160,60);
		ShowText(GetStrTextSpilted("dTerrInf2",2,11),40,240,60);
		break;
	case FOREST://森林
		ShowText(GetStrTextSpilted("dTerrInf3",0,11),40,80,60);
		ShowText(GetStrTextSpilted("dTerrInf3",1,11),40,160,60);
		ShowText(GetStrTextSpilted("dTerrInf3",2,11),40,240,60);
		break;
	case VILLAGE://村庄
		ShowText(GetStrTextSpilted("dTerrInf4",0,11),40,80,60);
		ShowText(GetStrTextSpilted("dTerrInf4",1,11),40,160,60);
		ShowText(GetStrTextSpilted("dTerrInf4",2,11),40,240,60);
		break;
	case CITY://城池
		ShowText(GetStrTextSpilted("dTerrInf5",0,11),40,80,60);
		ShowText(GetStrTextSpilted("dTerrInf5",1,11),40,160,60);
		ShowText(GetStrTextSpilted("dTerrInf5",2,11),40,240,60);
		break;
	case CAMP://营寨
		ShowText(GetStrTextSpilted("dTerrInf6",0,11),40,80,60);
		ShowText(GetStrTextSpilted("dTerrInf6",1,11),40,160,60);
		ShowText(GetStrTextSpilted("dTerrInf6",2,11),40,240,60);
		break;
	case RIVER://河流
		ShowText(GetStrTextSpilted("dTerrInf7",0,11),40,80,60);
		ShowText(GetStrTextSpilted("dTerrInf7",1,11),40,160,60);
		break;
	}
	SelectObject(hdcTmp,oldhpen);
	DeleteObject(hpen);
	SelectObject(hdcTmp,hbrold);
	DeleteObject(hbrush);
	return 0;
}

int Fight::ArrowRangeShow(int type)
{
	if(type == 0)//移动范围
	{
		for(int i=0;i<MAPMAX;i++)
		{
			for(int j=0;j<MAPMAX;j++)
			{
				if(i>=fightmap.startx&&i<(fightmap.startx+5)&&j>=fightmap.starty&&j<(fightmap.starty+10)&&arrow[i][j]==1)
				{
					int yy=i-fightmap.startx;
					int xx=j-fightmap.starty;
					ShowCGAdd(0,"Res\\Fight\\stepcross.sbp","Res\\Fight\\stepcrossmask.sbp",xx*80,yy*80);
				}

				/*if(arrow[i][j]==1&&i<10&&j<5)
				{

				ShowCGAdd(0,"Res\\Fight\\stepcross.sbp","Res\\Fight\\stepcrossmask.sbp",i*80,j*80);
				}*/
			}
		}
	}
	else if(type == 1)//攻击范围
	{
		for(int i=0;i<MAPMAX;i++)
		{
			for(int j=0;j<MAPMAX;j++)
			{
				if(i>=fightmap.startx&&i<(fightmap.startx+5)&&j>=fightmap.starty&&j<(fightmap.starty+10)&&atarr[i][j]==1)
				{
					int yy=i-fightmap.startx;
					int xx=j-fightmap.starty;
					ShowCGAdd(0,"Res\\Fight\\stepat.sbp","Res\\Fight\\stepatmask.sbp",xx*80,yy*80);
				}

			}
		}
	}
	else if(type == 2)//技能范围
	{
		for(int i=0;i<MAPMAX;i++)
		{
			for(int j=0;j<MAPMAX;j++)
			{
				if(i>=fightmap.startx&&i<(fightmap.startx+5)&&j>=fightmap.starty&&j<(fightmap.starty+10)&&skillarr[i][j]==1)
				{
					int yy=i-fightmap.startx;
					int xx=j-fightmap.starty;
					ShowCGAdd(0,"Res\\Fight\\stepat.sbp","Res\\Fight\\stepatmask.sbp",xx*80,yy*80);
				}

			}
		}
	}
	return 0;
}

int Fight::SpyResultShow()
{
	//显示谍报
	flagstat=0;
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	int fact=fighthero[atnowhero].zili+fighthero[atnowhero].degree+25;
	int fact1=fighthero[10].zili+fighthero[10].degree+5;
	int state = rand() % fact;
	if(state > (fact1>> 1))
	{	// 施展计谋失败 
		ShowCGDirect(0,"Res\\Fight\\fight_messagekuang.sbp",100,200);
		ShowTextDirect("谍报    计谋失败！",150,280);
		return 0;
	}
	else
	{
		//显示消息
		flaggetfoodamount=1;
		ShowInformation(WARINTELLIGENCE,0);
		fighthero[atnowhero].experience+=8;
		ShowSkillHurt(0,8);
		if(fighthero[atnowhero].experience>=100)
		{
			//升级
			ShowLevelUp();
			fighthero[atnowhero].experience-=100;
			fighthero[atnowhero].degree++;
			if(fighthero[atnowhero].degree>20)
				fighthero[atnowhero].degree=20;
			int health = (fighthero[atnowhero].wuli * 80 / 100 + fighthero[atnowhero].zili * 30 / 100 +fighthero[atnowhero].degree) * fighthero[atnowhero].tili/ 100;
			if(health<0)health=0;
			fighthero[atnowhero].health=health;
			int skill = (fighthero[atnowhero].zili * 80 / 100 + (PlcExtract(fighthero[atnowhero].wuli) >> 1) +fighthero[atnowhero].degree) * fighthero[atnowhero].tili/ 100;
			if(skill<0)skill=0;	
			fighthero[atnowhero].skill=skill;

		}
	}
	return 0;
}

int Fight::WeatherChangeSkillShow()
{
	//显示天变
	flagstat=0;
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	fighthero[atnowhero].experience+=8;
	ShowSkillHurt(0,8);
	if(fighthero[atnowhero].experience>=100)
	{
		//升级
		ShowLevelUp();
		fighthero[atnowhero].experience-=100;
		fighthero[atnowhero].degree++;
		if(fighthero[atnowhero].degree>20)
			fighthero[atnowhero].degree=20;
		int health = (fighthero[atnowhero].wuli * 80 / 100 + fighthero[atnowhero].zili * 30 / 100 +fighthero[atnowhero].degree) * fighthero[atnowhero].tili/ 100;
		if(health<0)health=0;
		fighthero[atnowhero].health=health;
		int skill = (fighthero[atnowhero].zili * 80 / 100 + (PlcExtract(fighthero[atnowhero].wuli) >> 1) +fighthero[atnowhero].degree) * fighthero[atnowhero].tili/ 100;
		if(skill<0)skill=0;	
		fighthero[atnowhero].skill=skill;

	}
	return 0;
}

int Fight::HeroShow()
{
	for(int y=0;y<heronumber;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].statue==8)continue;
		if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
			fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
		{
			int yy=fighthero[y].positionx-fightmap.startx;
			int xx=fighthero[y].positiony-fightmap.starty;
			fighthero[y].Show(xx,yy);//显示武将
		}

	}
	for(int y=10;y<heronumberto+10;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].statue==8)continue;
		if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
			fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
		{
			int yy=fighthero[y].positionx-fightmap.startx;
			int xx=fighthero[y].positiony-fightmap.starty;
			fighthero[y].Show(xx,yy);//显示武将
		}

	}
	return 0;
}

void Fight::Show(int g)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	if(g==-100)
	{		
		DynamicShow();
		return;
	}
	else
	{		
		//new_flag1=0;//20150920修正删除
		if(flagstat==1)
		{

			//显示战场状况,敌方
			BattlefieldStatusShow(flagstat);

		}
		else if(flagstat==2)
		{
			//显示战场状况,我方
			BattlefieldStatusShow(flagstat);
		}
		else if(flagstat==3)
		{
			HeroStatusShow(flagstat);

		}
		else if(flagstat==5)//显示敌方武将状态
		{
			HeroStatusShow(flagstat);

		}
		else if(flagstat==6)
		{
			TerrainStatusShow();

		}
		else
		{

			fightmap.Show(0);//自己主将

			ShowBar();
			//ShowCG(0,"Res\\menu.sbp",FIGHTMENUX,FIGHTMENUY);
			ShowCG(0,"Res\\back.sbp",FIGHTBACKX,FIGHTBACKY);
			ShowCGAdd(0,"Res\\leftarrow.sbp","Res\\leftarrowmask.sbp",FIGHTLEFTARROWX,FIGHTLEFTARROWY);
			ShowCGAdd(0,"Res\\rightarrow.sbp","Res\\rightarrowmask.sbp",FIGHTRIGHTARROWX,FIGHTRIGHTARROWY);
			ShowCGAdd(0,"Res\\uparrow.sbp","Res\\uparrowmask.sbp",FIGHTUPARROWX,FIGHTUPARROWY);
			ShowCGAdd(0,"Res\\downarrow.sbp","Res\\downarrowmask.sbp",FIGHTDOWNARROWX,FIGHTDOWNARROWY);
			if(flagarrowmov)
			{
				ArrowRangeShow(0);

			}
			if(flagarrowat)
			{
				ArrowRangeShow(1);

			}
			if(flagarrowskill)
			{
				ArrowRangeShow(2);

			}

			HeroShow();

			fightmap.ShowArrow();
			if(flagmenu==1)
			{
				menufight.Show(0);
			}
			if(flagmenushow==1)
			{
				menushow.Show(0);
			}
			if(flagmenuspeed==1)
			{
				menuspeed.Show(0);
			}
			if(flagmenumov==1)
			{
				menumove.Show(0);
			}
			if(flagmenuhero==1)
			{
				menuhero.Show(0);
			}
			if(flagshowskill==1)
			{
				menuhero.tmpfx=1;
				menuhero.Show(0);				
				fighthero[atnowhero].ShowMenuSkill();
				menuhero.tmpfx=0;
			}
			if(flagstat==4)//谍报
			{
				SpyResultShow();

			}
			if(flagstat==14)//天变
			{
				WeatherChangeSkillShow();
			}

			/*if(flagshowhurt)
			{
			ShowHurt(flagshowhurt,ex);
			flagshowhurt=0;
			}
			if(flagshowskillhurt)
			{
			ShowSkillHurt(flagshowskillhurt,ex);
			flagshowskillhurt=0;
			}
			if(flagshowsj)
			{
			Showsj();
			flagshowsj=0;
			}
			if(flagshowsw)
			{
			Showsw();
			flagshowsw=0;
			}*/

		}
	}

}

int Fight::UseSkill(WPARAM KeyCode)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	int retmenu0=fighthero[atnowhero].menuskill.KeyDown(KeyCode);
	if(retmenu0==-1)
	{
		flagshowskill=0;
		menuhero.tmpfx=1;
		menuhero.statb=1;
		menuhero.statbtp=0;
		menuhero.flagd=0;
		menuhero.flagu=0;
		menuhero.Show(0);
		flagmenuhero=1;
		flagunable=0;

	}
	else if(retmenu0==1)
	{		
		if(fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb]==24)//谍报（直接执行）
		{
			OverflowCheck(__FILE__,__LINE__,20,fighthero[atnowhero].menuskill.statb);
			int tmpl=SkillForceOK(fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb]);
			if(tmpl==0)
			{
				flagunable=6;
				flagshowskill=0;
				menuhero.tmpfx=1;
				menuhero.statb=1;
				menuhero.statbtp=0;
				menuhero.flagd=0;
				menuhero.flagu=0;
				menuhero.Show(0);
				flagmenuhero=1;
			}
			else
			{
				flagstat=4;
				flagmenuhero=0;
				Show(0);
				fighthero[atnowhero].active=0;
				flagshowskill=0;
				SubSkillPower(24);


			}
		}
		else if(fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb]==22)//天变（直接执行）
		{
			OverflowCheck(__FILE__,__LINE__,20,fighthero[atnowhero].menuskill.statb);
			int tmpl=SkillForceOK(fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb]);
			if(tmpl==0)
			{
				flagunable=6;
				flagshowskill=0;
				menuhero.tmpfx=1;
				menuhero.statb=1;
				menuhero.statbtp=0;
				menuhero.flagd=0;
				menuhero.flagu=0;
				menuhero.Show(0);
				flagmenuhero=1;
			}
			else
			{
				flagstat=14;
				flagmenuhero=0;
				weather =rand() % 5 + 1;
				Show(0);
				fighthero[atnowhero].active=0;
				flagshowskill=0;
				SubSkillPower(22);
			}			
		}		
		else
		{
			OverflowCheck(__FILE__,__LINE__,20,fighthero[atnowhero].menuskill.statb);
			int tmpo=WeatherOK(fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb]);
			int tmpp=LandOK(fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb],0);
			int tmpl=SkillForceOK(fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb]);
			if(tmpo==1&&tmpp==1&&tmpl==1)
			{
				flagmenuhero=0;
				flagarrowskill=1;//显示攻击范围
				SetAtSkill(fighthero[atnowhero].positionx,fighthero[atnowhero].positiony,atnowhero,fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb]);
				flagshowskill=0;
			}
			else if(tmpo==0)
			{
				flagunable=4;
				flagshowskill=0;
				menuhero.tmpfx=1;
				menuhero.statb=1;
				menuhero.statbtp=0;
				menuhero.flagd=0;
				menuhero.flagu=0;
				menuhero.Show(0);
				flagmenuhero=1;
			}
			else if(tmpp==0)
			{
				flagunable=5;
				flagshowskill=0;
				menuhero.tmpfx=1;
				menuhero.statb=1;
				menuhero.statbtp=0;
				menuhero.flagd=0;
				menuhero.flagu=0;
				menuhero.Show(0);
				flagmenuhero=1;
			}
			else if(tmpl==0)
			{
				flagunable=6;
				flagshowskill=0;
				menuhero.tmpfx=1;
				menuhero.statb=1;
				menuhero.statbtp=0;
				menuhero.flagd=0;
				menuhero.flagu=0;
				menuhero.Show(0);
				flagmenuhero=1;
			}
		}

	}
	return 0;
}

int Fight::SetIfShowFight(WPARAM KeyCode)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int retmenu1=menushow.KeyDown(KeyCode);
	if(retmenu1==-1)
	{
		flagmenushow=0;
	}
	else if(retmenu1==1)
	{
		menushow1=(menushow.statb);
		char str[10];
		memset(str,0,sizeof(str));
		sprintf_s(str,"%d",menushow1);
		WritePrivateProfileString("Startup", "Menushow", str, absolutepath );
		flagmenushow=0;
	}
	return 0;
}

int Fight::SetMoveSpeed(WPARAM KeyCode)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int retmenu2=menuspeed.KeyDown(KeyCode);	
	if(retmenu2==-1)
	{
		flagmenuspeed=0;
	}
	else if(retmenu2==1)
	{
		menuspeed1=(menuspeed.statb);
		char str[10];
		memset(str,0,sizeof(str));
		sprintf_s(str,"%d",menuspeed1);
		WritePrivateProfileString("Startup", "Menuspeed", str, absolutepath );
		flagmenuspeed=0;
	}
	return 0;
}

int Fight::SetIfShowMove(WPARAM KeyCode)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int retmenu3=menumove.KeyDown(KeyCode);	
	if(retmenu3==-1)
	{
		flagmenumov=0;
	}
	else if(retmenu3==1)
	{
		menumove1=(menumove.statb);
		char str[10];
		memset(str,0,sizeof(str));
		sprintf_s(str,"%d",menumove1);
		WritePrivateProfileString("Startup", "Menumove", str, absolutepath );
		flagmenumov=0;
	}
	return 0;
}

int Fight::DelHero(WPARAM KeyCode)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int retmenu4=menuhero.KeyDown(KeyCode);	
	if(retmenu4==-1)
	{
		flagmenuhero=0;
		menuhero.statb=0;
		menuhero.tmpfx=0;
		menuhero.statbtp=0;
		menuhero.flagd=0;
		menuhero.flagu=1;
		OverflowCheck(__FILE__,__LINE__,20,atnowhero);

			fighthero[atnowhero].positionx=tmpposx;
			fighthero[atnowhero].positiony=tmpposy;
			
			// 移动界面

			fightmap.arrowy = tmparrowy;
			fightmap.arrowx = tmparrowx;
			fightmap.startx = tmpstartx;
			fightmap.starty = tmpstarty;

	}
	else if(retmenu4==1)
	{
		switch(menuhero.statb)
		{
		case ATTACK://攻击
			{
				for(int i=0;i<heronumber;i++)
				{
					OverflowCheck(__FILE__,__LINE__,20,i);
					if(fighthero[i].statue==8)continue;
					int yy=fighthero[i].positionx-fightmap.startx;
					int xx=fighthero[i].positiony-fightmap.starty;
					if(fightmap.arrowx==xx&&fightmap.arrowy==yy&&fighthero[i].active==1)
					{
						//显示箭头，移动范围
						SetAt(fighthero[i].positionx,fighthero[i].positiony,i);//显示攻击范围
						flagarrowat=1;//表示攻击武将
						atnowhero=i;
					}

				}


				break;
			}
		case SKILL://计谋
			OverflowCheck(__FILE__,__LINE__,20,atnowhero);
			fighthero[atnowhero].WriteSkilltoFile();
			fighthero[atnowhero].GetMenuSkill();
			fighthero[atnowhero].ShowMenuSkill();
			flagshowskill=1;
			break;
		case STATUS://查看
			flagstat=3;
			return 0;
		case WAIT://待机
			OverflowCheck(__FILE__,__LINE__,20,atnowhero);
			fighthero[atnowhero].active=0;

			break;
		}

		flagmenuhero=0;
		menuhero.statb=0;
		menuhero.tmpfx=0;
		menuhero.statbtp=0;
		menuhero.flagd=0;
		menuhero.flagu=1;
	}
	return 0;
}

int Fight::SysMenu(WPARAM KeyCode)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int retmenu=menufight.KeyDown(KeyCode);
	if(retmenu==-1)
	{
		flagmenu=0;
		menufight.statb=0;
		menufight.tmpfx=0;
		menufight.statbtp=0;
		menufight.flagd=0;
		menufight.flagu=1;
	}
	else if(retmenu==1)
	{
		int ngret=(menufight.statb)+1;
		switch( ngret)
		{
		case 1:
			{	//回合结束
				int rt=AIRun();//ai策略
				if(rt<0)
					return -1;//我方失败
				flaggetfoodamount=0;
				ShowWeather();//显示、获取天气并在下方更新
				ShowWeatherBar();
				int rte=ShowDay();
				if(rte<0)
				{
					return rte;//我方失败
				}
				int retreq=DayEvent();
				if(retreq<0)//每天的事件处理
				{
					return retreq;//我方失败
				}
				flagmenu=0;
				fightmap.Show(0);
				//20150516修正战斗时 如果移动到右方边缘和下方边缘时，下一回合定位时出现的显示异常问题
				if(fighthero[0].positiony > 4 && fighthero[0].positiony < 27 )
				{
					fightmap.starty = fighthero[0].positiony - 4;
				}
				else if(fighthero[0].positiony >= 27)
				{
					fightmap.starty = 22;
				}
				else if(fighthero[0].positiony <= 4)
				{
					fightmap.starty = 0;
				}

				if(fighthero[0].positionx > 2 && fighthero[0].positionx < 29 )
				{
					fightmap.startx = fighthero[0].positionx - 2;
				}
				else if(fighthero[0].positionx >= 29)
				{
					fightmap.startx = 26;
				}
				else if(fighthero[0].positionx <= 2)
				{
					fightmap.startx = 0;
				}


				//fightmap.starty=fighthero[0].positiony>4?(fighthero[0].positiony-4):0;
				//fightmap.startx=fighthero[0].positionx>2?(fighthero[0].positionx-2):0;
				fightmap.arrowx=4;
				fightmap.arrowy=2;
				break;
			}
		case 2:
			//全军撤退
			GameEnd(0);
			return -1;//我方失败
			break;
		case 3:
			//战斗动画
			menushow.Show(0);
			flagmenushow=1;
			break;
		case 4:
			//移动速度
			menuspeed.Show(0);
			flagmenuspeed=1;
			break;
		case 5:
			//敌军移动
			menumove.Show(0);
			flagmenumov=1;
			break;
		}
	}
	return 0;
}

int Fight::HeroStatusDel(WPARAM KeyCode)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	if(KeyCode==KeyUp0||KeyCode==KeyDown0)
	{
		if(flagstat==1&&starty1==0&&heronumberto>5)
		{
			starty1=1;
		}
		else if(flagstat==2&&starty==0&&heronumber>5)
		{
			starty=1;
		}
		else if(flagstat==1&&starty1==1&&heronumberto>5)
		{
			starty1=0;
		}
		else if(flagstat==2&&starty==1&&heronumber>5)
		{
			starty=0;
		}
	}
	else if(KeyCode==KeyLeft0||KeyCode==KeyRight0)
	{
		if(flagstat==1)flagstat=2;
		else if(flagstat==2)flagstat=1;
	}
	else if(KeyCode==KeyEsc)
	{	
		flagstat=0;
	}
	Show(0);
	return 0;
}

int Fight::KeyDown(WPARAM KeyCode)
{
	wlogfile(1,__FUNCTION__,"开始",KeyCode);
	if(new_flag1==1)
	{
		new_flag1=0;
		GameEnd(0);
		return -1;//我方失败
	}
	if(new_flag1==2)//20150517
	{
		new_flag1=0;
		GameEnd(1);
		return -2;//我方成功
	}
	//if(atnowhero < 0 && atnowhero >= 20)atnowhero = 0;//20170330修正
	if(flagstat==3||flagstat==4||flagstat==5||flagstat==6||flagstat==14)
	{
		flagstat=0;
	}
	else if(flagshowskill==1)
	{
		UseSkill(KeyCode);

	}
	else if(flagmenushow==1)
	{
		SetIfShowFight(KeyCode);


	}
	else if(flagmenuspeed==1)
	{
		SetMoveSpeed(KeyCode);

	}
	else if(flagmenumov==1)
	{
		SetIfShowMove(KeyCode);

	}
	else if(flagmenuhero==1)
	{
		DelHero(KeyCode);

	}
	else if(flagmenu==1)
	{
		return SysMenu(KeyCode);

	}
	else if(flagstat)
	{
		HeroStatusDel(KeyCode);

	}
	else
	{
		if(KeyCode==KeyUp0||KeyCode==KeyDown0||KeyCode==KeyLeft0||KeyCode==KeyRight0)
		{

			flagunable=0;
			fightmap.KeyDown(KeyCode);
		}
		else if(KeyCode==KeyEsc)
		{
			if(flagarrowmov==0&&flagarrowat==0&&flagarrowskill==0)
			{
				menufight.Show(KeyCode);
				flagmenu=1;
			}
			else if(flagarrowat==1)
			{
				flagarrowat=0;
				flagmenuhero=1;
				OverflowCheck(__FILE__,__LINE__,20,atnowhero);
				int yy=fighthero[atnowhero].positionx-fightmap.startx;
				int xx=fighthero[atnowhero].positiony-fightmap.starty;
				fightmap.arrowx=xx;
				fightmap.arrowy=yy;

			}
			else if(flagarrowskill==1)
			{
				flagarrowskill=0;
				flagmenuhero=1;
				menuhero.tmpfx=1;
				menuhero.statb=1;
				menuhero.statbtp=0;
				menuhero.flagu=0;
				menuhero.flagd=0;
				OverflowCheck(__FILE__,__LINE__,20,atnowhero);
				int yy=fighthero[atnowhero].positionx-fightmap.startx;
				int xx=fighthero[atnowhero].positiony-fightmap.starty;
				fightmap.arrowx=xx;
				fightmap.arrowy=yy;

			}
			else
			{
				flagarrowmov=0;
			}
		}
		else if (KeyCode==KeyHome)
		{
			//显示战场状况
			flagstat=1;
		}
		else if (KeyCode==KeySpace)
		{
			flagstat=6;
			for(int i=0;i<heronumber;i++)
			{
				OverflowCheck(__FILE__,__LINE__,20,i);
				if(fighthero[i].statue==8)continue;
				int yy=fighthero[i].positionx-fightmap.startx;
				int xx=fighthero[i].positiony-fightmap.starty;
				if(fightmap.arrowx==xx&&fightmap.arrowy==yy)
				{
					//显示箭头，移动范围
					atnowhero=i;
					flagstat=3;
					Show(0);				
				}	
			}
			for(int i=10;i<heronumberto+10;i++)
			{
				OverflowCheck(__FILE__,__LINE__,20,i);
				if(fighthero[i].statue==8)continue;
				int yy=fighthero[i].positionx-fightmap.startx;
				int xx=fighthero[i].positiony-fightmap.starty;
				if(fightmap.arrowx==xx&&fightmap.arrowy==yy)
				{
					//显示箭头，移动范围
					atnowheroat=i;
					flagstat=5;
					Show(0);				
				}		
			}

		}
		else if (KeyCode==KeyReturn)
		{	
			if(flagarrowat==1)
			{
				int tmpr=CanAt(0);
				if( tmpr==1)//判断是否为目标
				{
					int ret1=FightEvent();
					if(ret1==-10)//进入战斗并显示（FightShow())
					{
						return -1;
					}
					if(ret1==-11)
					{
						return -2;
					}
				}
				else if(tmpr==2)
				{
					flagunable=3;
				}
				else
				{
					flagunable=2;
				}
			}
			else if(flagarrowskill==1)
			{
				OverflowCheck(__FILE__,__LINE__,20,atnowhero);
				OverflowCheck(__FILE__,__LINE__,20,fighthero[atnowhero].menuskill.statb);
				int tmpr;
				if(atnowhero>19)atnowhero = 0;//20171210
				if(fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb]!=15&&fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb]!=19)
				{
					tmpr=CanAt(1);
				}
				else
				{
					tmpr=CanAt(2);
				}
				if( tmpr==1)//判断是否为目标
				{
					flagunable = 0;
					int tmpp=LandOK(fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb],1);//判断目标地形
					if(tmpp==0)
					{
						flagunable=5;
					}
					else if(fighthero[atnowhero].statue==2)//禁咒状态
					{
						flagunable=3;
					}
					else
					{

						int ret=FightEvent();//进入战斗并显示（FightShow())
						if(ret!=-1)
						{
							SubSkillPower(fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb]);//减少技力；
						}
						if(ret==-10)
						{
							return -1;
						}
						if(ret==-11)
						{
							return -2;
						}
					}
				}
				else if(tmpr==2)
				{
					flagunable=3;
				}
				else
				{
					flagunable=2;
				}
			}
			else if(flagarrowmov==0)
			{

				for(int i=0;i<heronumber;i++)
				{
					OverflowCheck(__FILE__,__LINE__,20,i);
					if(fighthero[i].statue==8)continue;
					int yy=fighthero[i].positionx-fightmap.startx;
					int xx=fighthero[i].positiony-fightmap.starty;
					if(fightmap.arrowx==xx&&fightmap.arrowy==yy&&fighthero[i].active==1)
					{
						//显示箭头，移动范围
						atnowhero=i;
						SetArrive(fighthero[i].positionx,fighthero[i].positiony,i);
						flagarrowmov=1;//表示移动武将
						flagunable=0;
						tmparrowx = fightmap.arrowx ;//20170708
						tmparrowy = fightmap.arrowy ;//20170708
						Show(0);

					}

				}

			}
			else
			{
				if(CanArrive()==1)//在箭头范围内
				{
					OverflowCheck(__FILE__,__LINE__,20,atnowhero);
					tmpposx=fighthero[atnowhero].positionx;
					tmpposy=fighthero[atnowhero].positiony;
					fighthero[atnowhero].positionx=fightmap.startx+fightmap.arrowy;
					fighthero[atnowhero].positiony=fightmap.starty+fightmap.arrowx;

					//存储当前位置信息
						tmpstartx = fightmap.startx ;
						tmpstarty = fightmap.starty ;
						
						
						// 移动界面
						int t_arrowy = 2;
						int t_arrowx = 4;
						
						
						fightmap.arrowy = t_arrowy;
						fightmap.arrowx = t_arrowx;
						fightmap.startx = fighthero[atnowhero].positionx - t_arrowy;
						
						fightmap.starty = fighthero[atnowhero].positiony - t_arrowx;
						if(fightmap.startx < 0 )
						{
							fightmap.arrowy = t_arrowy + fightmap.startx;
							fightmap.startx = 0;
						}
						if(fightmap.starty < 0 )
						{
							fightmap.arrowx = t_arrowx + fightmap.starty;
							fightmap.starty = 0;
						}
						if(fightmap.startx >= (MAPMAX - 6) )
						{
							fightmap.arrowy = t_arrowy + (fightmap.startx - (MAPMAX - 6));
							fightmap.startx = (MAPMAX - 6);
						}
						if(fightmap.starty >= (MAPMAX - 10) )
						{
							fightmap.arrowx = t_arrowx + (fightmap.starty - (MAPMAX - 10));
							fightmap.starty = (MAPMAX - 10) ;
						}

					Show(0);
					menuhero.Show(0);
					flagarrowmov=0;
					flagmenuhero=1;
					if(TestWinLose()==-2)return -2;
				}
				else
				{	
					//显示无法到达
					flagunable=1;
				}
			}
		}
		Show(0);
	}
	return 0;

}

void Fight::ShowWeather()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	weather =rand() % 5 + 1;

	switch(weather)
	{
	case SUNNY:
		ShowCGDirect(500,"Res\\Fight\\01fight_qin.sbp",80,90);
		break;
	case CLOUDY:
		ShowCGDirect(500,"Res\\Fight\\02fight_yin.sbp",80,90);
		break;
	case WIND:
		ShowCGDirect(500,"Res\\Fight\\03fight_feng.sbp",80,90);
		break;
	case RAIN:
		ShowCGDirect(500,"Res\\Fight\\04fight_yu.sbp",80,90);
		break;
	case ICE:
		ShowCGDirect(500,"Res\\Fight\\05fight_bin.sbp",80,90);
		break;
	}

}

void Fight::ShowWeatherBar()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	switch(weather)
	{
	case SUNNY:
		ShowCGAdd(0,"Res\\Fight\\fight_weather1.sbp","Res\\Fight\\fight_weather1mask.sbp",225,410);
		break;
	case CLOUDY:
		ShowCGAdd(0,"Res\\Fight\\fight_weather2.sbp","Res\\Fight\\fight_weather2mask.sbp",225,410);
		break;
	case WIND:
		ShowCGAdd(0,"Res\\Fight\\fight_weather3.sbp","Res\\Fight\\fight_weather3mask.sbp",225,410);
		break;
	case RAIN:
		ShowCGAdd(0,"Res\\Fight\\fight_weather4.sbp","Res\\Fight\\fight_weather4mask.sbp",225,410);
		break;
	case ICE:
		ShowCGAdd(0,"Res\\Fight\\fight_weather5.sbp","Res\\Fight\\fight_weather5mask.sbp",225,410);
		break;
	}
}

int Fight::ShowDay()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	wlogfile(1,"Fight::ShowDay","当前战争类型：",warstyle);
	if(day==31&&warstyle==0)
	{
		GameEnd(0);//我方为攻击方

		return -1;
	}
	if(day==31&&warstyle==1)
	{
		GameEnd(1);

		return -2;
	}
	char str[10];
	sprintf_s(str,"%d",day);	
	ShowCGDirect(0,"Res\\Fight\\fight_days.sbp",310,180);

	if(color==1)
	{	
		SetTextColor(hdc,RGB(255, 255, 255));
	}

	ShowTextDirect(str,383+(25-strlen(str)*25/2),253);
	SetTextColor(hdc,RGB(0, 0, 0));
	Delay(1000);

	day++;
	return 0;

}

void Fight::ShowBar()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	ShowCG(0,"Res\\Fight\\fight_statue.sbp",0,400);
	ShowWeatherBar();
	ShowGround();
	char str[20];
	int foods1=0;
	if(foods>999)
	{
		foods1=foods%1000;
	}
	else
	{
		foods1=foods;
	}
	sprintf_s(str,"%d",foods1);
	ShowText(str,60,460,60);

}

void Fight::ShowGround()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	if(flagunable==1)
	{
		ShowText(GetStrText("dFgtCtMove"),390,460,60);
		return;
	}
	else if(flagunable==2)
	{
		ShowText(GetStrText("dFgtNoAim"),390,460,60);
		return;
	}
	else if(flagunable==3)
	{
		ShowText(GetStrText("dFgtErrAim"),390,460,60);
		return;
	}
	else if(flagunable==4)
	{
		ShowText(GetStrText("dFgtWhrErr"),390,460,60);
		return;
	}
	else if(flagunable==5)
	{
		ShowText(GetStrText("dFgtEthErr"),390,460,60);
		return;
	}
	else if(flagunable==6)
	{
		ShowText(GetStrText("dFgtMpErr"),390,460,60);
		return;
	}
	for(int i=0;i<heronumber;i++)
	{
		OverflowCheck(__FILE__,__LINE__,20,i);
		if(fighthero[i].statue==8)continue;
		int yy=fighthero[i].positionx-fightmap.startx;
		int xx=fighthero[i].positiony-fightmap.starty;
		if(xx==fightmap.arrowx&&yy==fightmap.arrowy)
		{
			char str[20];
			OverflowCheck(__FILE__,__LINE__,HEROMAX,fighthero[i].num);
			sprintf_s(str,"%s",t_heroName[fighthero[i].num]);

			ShowText(str,390,460,60);
			return;
		}
	}
	for(int i=10;i<heronumberto+10;i++)
	{
		OverflowCheck(__FILE__,__LINE__,20,i);
		if(fighthero[i].statue==8)continue;
		int yy=fighthero[i].positionx-fightmap.startx;
		int xx=fighthero[i].positiony-fightmap.starty;
		if(xx==fightmap.arrowx&&yy==fightmap.arrowy)
		{
			char str[20];
			sprintf_s(str,"%s",t_heroName[fighthero[i].num]);
			ShowText(str,390,460,60);
			return;
		}
	}
	OverflowCheck(__FILE__,__LINE__,MAPMAX,fightmap.startx+fightmap.arrowy);
	OverflowCheck(__FILE__,__LINE__,MAPMAX,fightmap.arrowx+fightmap.starty);
	switch(fightmap.tile[fightmap.startx+fightmap.arrowy][fightmap.arrowx+fightmap.starty])
	{
	case 1:
		ShowText(GetStrTextSpilted("dFgtTrnInf",1,2),390,460,60);
		break;
	case 2:
		ShowText(GetStrTextSpilted("dFgtTrnInf",0,2),390,460,60);
		break;
	case 3:
		ShowText(GetStrTextSpilted("dFgtTrnInf",5,2),390,460,60);     
		break;
	case 4:
		ShowText(GetStrTextSpilted("dFgtTrnInf",4,2),390,460,60);     
		break;
	case 5:
		ShowText(GetStrTextSpilted("dFgtTrnInf",3,2),390,460,60);     
		break;
	case 6:
	case 7:
	case 8:
	case 9:
	case 10:
	case 11:
	case 12:
	case 13:
	case 14:
	case 15:
		ShowText(GetStrTextSpilted("dFgtTrnInf",2,2),390,460,60);     
		break;
	case 16:
	case 17:
	case 18:
	case 19:
	case 20:
	case 21:
	case 22:
	case 23:
	case 24:
	case 25:
	case 26:
	case 27:
	case 28:
	case 29:
	case 30:
	case 31:
	case 32:
	case 33:
	case 34:
	case 35:
	case 36:
	case 37:
	case 38:
	case 39:
	case 40:
	case 42:
	case 43:
	case 44:
	case 45:
		ShowText(GetStrTextSpilted("dFgtTrnInf",7,2),390,460,60);     
		break;
	case 41:
		ShowText(GetStrTextSpilted("dFgtTrnInf",6,2),390,460,60);     
		break;
	}

}

void Fight::GameEnd(int result)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	MyCreateFont(1.0);
	HFONT	h = t_h;
	HFONT oldh=(HFONT)SelectObject(hdcTmp,h);
	MySetTextColor(FONTB,USEHDCTMP);

	if(color==0)
	{

		HPEN hpen=CreatePen(PS_SOLID,5, RGB(0,0,0));
		HPEN oldhpen=(HPEN)SelectObject(hdcTmp,hpen);
		Rectangle(hdcTmp,80,70,720,510); 
		SelectObject(hdcTmp,oldhpen);
		DeleteObject(hpen);
	}
	else
	{
		ShowCG(0,"Res\\Fight\\fight_msgback.sbp",80,20);
	}

	SelectObject(hdcTmp,oldh);
	DeleteObject(h);	


	if(result==0)
	{
		ShowCG(0,"Res\\Fight\\fight_lose.sbp",220,50);
		TextOut(hdcTmp,230,430,GetStrText("STR_OURS"),strlen(GetStrText("STR_OURS")));
		TextOut(hdcTmp,380,430,GetStrText("STR_LOST"),strlen(GetStrText("STR_LOST")));
		//TextOut(hdcTmp,230,430,"我方  战斗失败",strlen("我方  战斗失败"));
	}
	else
	{
		ShowCG(0,"Res\\Fight\\fight_win.sbp",220,50);
		TextOut(hdcTmp,230,430,GetStrText("STR_OURS"),strlen(GetStrText("STR_OURS")));
		TextOut(hdcTmp,380,430,GetStrText("STR_WON"),strlen(GetStrText("STR_WON")));
		//TextOut(hdcTmp,230,430,"我方  战斗胜利",strlen("我方  战斗胜利"));
	}
	BitBlt(hdc,0,0,800,600,hdcTmp,0,0,SRCCOPY);
	Delay(1000);
}

void Fight::ShowUpName(int x)
{
	wlogfile(1,__FUNCTION__,"开始",0);


	char str[20];
	if(x==0)//我方
	{	
		OverflowCheck(__FILE__,__LINE__,HEROMAX,owner);
		if(owner > HEROMAX) owner -=HEROMAX;//20171210
		sprintf_s(str,"%s",t_heroName[owner]);

	}
	else//敌方
	{
		OverflowCheck(__FILE__,__LINE__,HEROMAX,ownerto);
		if(ownerto > HEROMAX) ownerto -=HEROMAX;//20171210
		sprintf_s(str,"%s",t_heroName[ownerto]);
	}
	ShowText(str,410,60,60);
}

void Fight::ShowArmyNumber(int x)//starty为显示时开始的值
{			
	wlogfile(1,__FUNCTION__,"开始",0);

	char str[10][20];
	char str1[10][20];
	if(x==0&&starty==0)//我方
	{	
		for(int j=0;j<(heronumber>5?5:heronumber);j++)
		{
			OverflowCheck(__FILE__,__LINE__,20,j);
			OverflowCheck(__FILE__,__LINE__,HEROMAX,fighthero[j].num);
			sprintf_s(str[j],"%s",t_heroName[fighthero[j].num]);

			sprintf_s(str1[j],"%d",fighthero[j].bingli);
			ShowText(str[j],410,200+j*60,60);
			ShowText(str1[j],600,200+j*60,60);
		}
	}
	else if(x==0&&starty==1)//我方
	{	
		for(int j=5;j<heronumber;j++)
		{
			OverflowCheck(__FILE__,__LINE__,20,j);
			OverflowCheck(__FILE__,__LINE__,HEROMAX,fighthero[j].num);
			sprintf_s(str[j],"%s",t_heroName[fighthero[j].num]);
			sprintf_s(str1[j],"%d",fighthero[j].bingli);
			ShowText(str[j],410,200+(j-5)*60,60);
			ShowText(str1[j],600,200+(j-5)*60,60);
		}
	}
	else if(x==1&&starty1==0)//敌方
	{
		for(int j=0;j<(heronumberto>5?5:heronumberto);j++)
		{
			OverflowCheck(__FILE__,__LINE__,20,j+10);
			OverflowCheck(__FILE__,__LINE__,HEROMAX,fighthero[j+10].num);
			sprintf_s(str[j],"%s",t_heroName[fighthero[j+10].num]);

			sprintf_s(str1[j],"%d",fighthero[j+10].bingli);
			ShowText(str[j],410,200+j*60,60);
			ShowText(str1[j],600,200+j*60,60);
		}
	}
	else//敌方
	{
		for(int j=5;j<heronumberto;j++)
		{
			OverflowCheck(__FILE__,__LINE__,20,j+10);
			OverflowCheck(__FILE__,__LINE__,HEROMAX,fighthero[j+10].num);
			sprintf_s(str[j],"%s",t_heroName[fighthero[j+10].num]);
			sprintf_s(str1[j],"%d",fighthero[j+10].bingli);
			ShowText(str[j],410,200+(j-5)*60,60);
			ShowText(str1[j],600,200+(j-5)*60,60);
		}
	}
}

void Fight::ShowAllOf()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int tmp[MAPMAX][MAPMAX];
	for(int pa=0;pa<MAPMAX;pa++)
		for(int pb=0;pb<MAPMAX;pb++)
			tmp[pa][pb]=0;

	for(int pp=0;pp<heronumber;pp++)
	{
		OverflowCheck(__FILE__,__LINE__,20,pp);
		OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[pp].positionx);
		OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[pp].positiony);
		if(fighthero[pp].statue==8)continue;
		tmp[fighthero[pp].positionx][fighthero[pp].positiony]=1;
	}
	for(int pp=10;pp<heronumberto+10;pp++)
	{
		OverflowCheck(__FILE__,__LINE__,20,pp);
		OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[pp].positionx);
		OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[pp].positiony);
		if(fighthero[pp].statue==8)continue;
		tmp[fighthero[pp].positionx][fighthero[pp].positiony]=1;
	}
	for(int pa=0;pa<MAPMAX;pa++)
	{
		for(int pb=0;pb<MAPMAX;pb++)
		{
			if(tmp[pa][pb]==1)
			{
				BitBlt(hdcTmp,120+pb*5,300+pa*5,5,5,hdcTmp,120+pb*5,300+pa*5,DSTINVERT);
			}
		}
	}


}

int Fight::CanArrive()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	if(arrow[fightmap.startx+fightmap.arrowy][fightmap.starty+fightmap.arrowx]==1)
	{
		return 1;//可到达
	}
	else
	{
		return 0;
	}
}

void Fight::SetArrive(int xx,int yy,int x)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	//xx,yy中心位置
	//i武将编号
	OverflowCheck(__FILE__,__LINE__,20,x);
	int type=fighthero[x].style;
	int move = 0;//20170330新增初始化
	switch(type)
	{
	case CAVALRY:
		move=5;
		break;
	case INFANTRY:
		move=4;
		break;
	case ARCHER:
		move=4;
		break;
	case SAILOR:
		move=5;
		break;
	case GREATHPARM:
		move=8;
		break;
	case GREATMPARM:
		move=8;
		break;
	}
	if(move == 0)//20170330修正
	{
		fighthero[x].style = 1;
		move=4;
	}
	move+=fighthero[x].moveup;
	if(move>8)move=8;
	if(fighthero[x].statue==3)move=0;
	int moveleft=move;
	int moveright=move;
	int moveup=move;
	int movedown=move;


	//int to[MAPMAX][MAPMAX];
	//int arrow[39][40];//[31][32]
	//int of[MAPMAX][MAPMAX];
	int of[MAPMAX][MAPMAX];
	int leavedo[MAPMAX][MAPMAX];//剩余行动力；
	for(int i=0;i<MAPMAX;i++)
	{
		for(int j=0;j<MAPMAX;j++)
		{	
			arrow[i][j]=0;
			leavedo[i][j]=0;
			of[i][j]=c_of[i][j];
		}
	}

	//设置敌人所在位置arrow为-1
	if(x<10)
	{
		for(int i=10;i<heronumberto+10;i++)
		{
			OverflowCheck(__FILE__,__LINE__,20,i);
			OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[i].positionx);
			OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[i].positiony);
			if(fighthero[i].statue!=8)
			{
				
				of[fighthero[i].positionx][fighthero[i].positiony]=7;//敌人
			}
		}
	}
	else
	{
		for(int i=0;i<heronumber+10;i++)
		{
			OverflowCheck(__FILE__,__LINE__,20,i);
			OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[i].positionx);
			OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[i].positiony);
			if(fighthero[i].statue!=8)
			{
				of[fighthero[i].positionx][fighthero[i].positiony]=7;//敌人
			}
		}

	}
	
	arrow[xx][yy]=1;
	//消耗行动力


	if(xx>0)
	{
		arrow[xx-1][yy]=1;
	}
	else
	{
		moveup=0;
	}
	if(xx<(MAPMAX-1))
	{
		arrow[xx+1][yy]=1;
	}
	else
	{
		movedown=0;
	}
	if(yy>0)
	{
		arrow[xx][yy-1]=1;
	}
	else
	{
		moveleft=0;
	}
	if(yy<(MAPMAX-1))
	{
		arrow[xx][yy+1]=1;
	}
	else
	{
		moveright=0;
	}
	/*	骑	步	弓	水  极  玄
	草	1	1	1	2   1   1
	平	1	1	1	2   1   1
	山	3	1	1	3   2   1
	林	3	1	1	3   2   1
	村  3   1   1   3   2   1
	城  3   1   1   3   2   1
	营  3   1   1   3   2   1
	水	3	3	3	1   3   3
	敌  8   8   8   8   8   8
	*/
	//int movecaculate[8][6]={{1,1,1,2,1,1},{3,1,1,3,2,1},{3,1,1,3,2,1},{3,3,3,1,2,3},{3,1,1,3,2,1},{3,1,1,3,2,1},{3,1,1,3,2,1},{8,8,8,8,8,8}};
	//int movecaculate[7][4]={8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8};
	int lefttmp=1;
	int righttmp=1;
	int uptmp=1;
	int downtmp=1;


	while(moveleft>1)
	{
		if((yy-lefttmp)<0||(yy-lefttmp)>(MAPMAX-1))break;
		moveleft-=movecaculate[of[xx][yy-lefttmp]][type];			
		arrow[xx][yy-lefttmp]=1;
		leavedo[xx][yy-lefttmp]=moveleft;
		if((yy-lefttmp-1)<0||(yy-lefttmp-1)>(MAPMAX-1))break;
		if(moveleft<movecaculate[of[xx][yy-lefttmp-1]][type])break;
		if((yy-lefttmp)==0)break;
		lefttmp++;
		//if(moveleft<movecaculate[of[xx][yy-lefttmp]][type])break;
	}

	while(moveright>1)
	{
		if((yy+righttmp)<0||(yy+righttmp)>(MAPMAX-1))break;
		moveright-=movecaculate[of[xx][yy+righttmp]][type];		
		arrow[xx][yy+righttmp]=1;	
		leavedo[xx][yy+righttmp]=moveright;
		if((yy+righttmp+1)<0||(yy+righttmp+1)>(MAPMAX-1))break;
		if(moveright<movecaculate[of[xx][yy+righttmp+1]][type])break;
		if((yy+righttmp)==0)break;
		righttmp++;
		//if(moveright<movecaculate[of[xx][yy+righttmp]][type])break;
	}
	while(moveup>1)
	{
		if((xx-uptmp)<0||(xx-uptmp)>(MAPMAX-1))break;//20150531修正32为30
		moveup-=movecaculate[of[xx-uptmp][yy]][type];	
		arrow[xx-uptmp][yy]=1;
		leavedo[xx-uptmp][yy]=moveup;
		if((xx-uptmp-1)<0||(xx-uptmp-1)>(MAPMAX-1))break;//20150531修正32为30
		if(moveup<movecaculate[of[xx-uptmp-1][yy]][type])break;
		if((xx-uptmp)==0)break;
		uptmp++;
		//if(moveup<movecaculate[of[xx-uptmp][yy]][type])break;
	}
	while(movedown>1)
	{
		if((xx+downtmp)<0||(xx+downtmp)>(MAPMAX-1))break;//20150531修正32为30
		movedown-=movecaculate[of[xx+downtmp][yy]][type];	
		arrow[xx+downtmp][yy]=1;
		leavedo[xx+downtmp][yy]=movedown;		
		if((xx+downtmp+1)<0||(xx+downtmp+1)>(MAPMAX-1))break;//20150531修正32为30
		if(movedown<movecaculate[of[xx+downtmp+1][yy]][type])break;
		if((xx+downtmp)==0)break;
		downtmp++;
		//if(movedown<movecaculate[of[xx+downtmp][yy]][type])break;
	}

	for(int gg=xx+1;gg<xx+downtmp+1;gg++)//右下角
	{
		for(int hh=yy+1;hh<yy+righttmp+1;hh++)
		{
			//arrow[gg][hh]=-1;
			//if(arrow[gg-1][hh]==1)
			if(hh<0||gg<0||hh>(MAPMAX-1)||gg>(MAPMAX-1))break;//20170107
			if((leavedo[gg-1][hh]-movecaculate[of[gg][hh]][type])>0)
			{
				arrow[gg][hh]=1;
				leavedo[gg][hh]=leavedo[gg-1][hh]-movecaculate[of[gg][hh]][type];
			}
			if((leavedo[gg][hh-1]-movecaculate[of[gg][hh]][type])>0)
			{
				arrow[gg][hh]=1;
				leavedo[gg][hh]=leavedo[gg][hh-1]-movecaculate[of[gg][hh]][type];
			}
		}
	}
	for(int gg=xx-1;gg>xx-uptmp-1;gg--)//右上角
	{
		for(int hh=yy+1;hh<yy+righttmp+1;hh++)
		{
			if(hh<0||gg<0||hh>(MAPMAX-1)||gg>(MAPMAX-1))break;//20170107
			if((leavedo[gg+1][hh]-movecaculate[of[gg][hh]][type])>0)
			{
				arrow[gg][hh]=1;
				leavedo[gg][hh]=leavedo[gg+1][hh]-movecaculate[of[gg][hh]][type];
			}
			if((leavedo[gg][hh-1]-movecaculate[of[gg][hh]][type])>0)
			{
				arrow[gg][hh]=1;
				leavedo[gg][hh]=leavedo[gg][hh-1]-movecaculate[of[gg][hh]][type];
			}
		}
	}
	for(int gg=xx-1;gg>xx-uptmp-1;gg--)//左上角
	{
		for(int hh=yy-1;hh>yy-lefttmp-1;hh--)
		{
			if(hh<0||gg<0||hh>(MAPMAX-1)||gg>(MAPMAX-1))break;//20170107
			if((leavedo[gg+1][hh]-movecaculate[of[gg][hh]][type])>0)
			{
				arrow[gg][hh]=1;
				leavedo[gg][hh]=leavedo[gg+1][hh]-movecaculate[of[gg][hh]][type];
			}
			if((leavedo[gg][hh+1]-movecaculate[of[gg][hh]][type])>0)
			{
				arrow[gg][hh]=1;
				leavedo[gg][hh]=leavedo[gg][hh+1]-movecaculate[of[gg][hh]][type];
			}
		}
	}
	for(int gg=xx+1;gg<xx+downtmp+1;gg++)//左下角
	{
		for(int hh=yy-1;hh>yy-lefttmp-1;hh--)
		{
			if(hh<0||gg<0||hh>(MAPMAX-1)||gg>(MAPMAX-1))break;//20170107
			if((leavedo[gg-1][hh]-movecaculate[of[gg][hh]][type])>0)
			{
				arrow[gg][hh]=1;
				leavedo[gg][hh]=leavedo[gg-1][hh]-movecaculate[of[gg][hh]][type];
			}
			if((leavedo[gg][hh+1]-movecaculate[of[gg][hh]][type])>0)
			{
				arrow[gg][hh]=1;
				leavedo[gg][hh]=leavedo[gg][hh+1]-movecaculate[of[gg][hh]][type];
			}
		}
	}
	if(x<10)
	{
		for(int gg=0;gg<MAPMAX;gg++)
		{
			for(int hh=0;hh<MAPMAX;hh++)
			{
				for(int kk=0;kk<heronumber;kk++)
				{
					if(fighthero[kk].statue==8)continue;
					if(fighthero[kk].positionx==gg&&fighthero[kk].positiony==hh&&kk!=atnowhero)
						arrow[gg][hh]=0;
				}
				for(int kk=10;kk<heronumberto+10;kk++)
				{
					if(fighthero[kk].statue==8)continue;
					if(fighthero[kk].positionx==gg&&fighthero[kk].positiony==hh&&kk!=atnowhero)
						arrow[gg][hh]=0;
				}
			}
		}
	}
	else
	{
		for(int gg=0;gg<MAPMAX;gg++)
		{
			for(int hh=0;hh<MAPMAX;hh++)
			{
				for(int kk=0;kk<heronumber;kk++)
				{
					if(fighthero[kk].statue==8)continue;
					if(fighthero[kk].positionx==gg&&fighthero[kk].positiony==hh&&kk!=atnowheroat)
						arrow[gg][hh]=0;
				}
				for(int kk=10;kk<heronumberto+10;kk++)
				{
					if(fighthero[kk].statue==8)continue;
					if(fighthero[kk].positionx==gg&&fighthero[kk].positiony==hh&&kk!=atnowheroat)
						arrow[gg][hh]=0;
				}
			}
		}
	}
	/*if(arrow[xx][yy+1]==1&&arrow[xx+1][yy]==1)
	{
	arrow[xx+1][yy+1]=1;
	}*/

	/*while(move>0)
	{
	if(moveleft>0)
	{
	moveleft-=movecaculate[of[xx][yy-lefttmp]][type];	
	arrow[xx][yy-lefttmp]=1;
	if((yy-lefttmp)==0)goto l1;
	lefttmp++;
	if(moveleft<movecaculate[of[xx][yy-lefttmp]][type])goto l1;
	}
	l1:
	if(moveright>0)
	{
	moveright-=movecaculate[of[xx][yy+righttmp]][type];
	arrow[xx][yy+righttmp]=1;
	if((yy+righttmp)==32)goto l2;
	righttmp++;
	if(moveright<movecaculate[of[xx][yy+righttmp]][type])goto l2;
	}
	l2:
	if(moveup>0)
	{
	moveup-=movecaculate[of[xx-uptmp][yy]][type];
	arrow[xx-uptmp][yy]=1;
	if((xx-uptmp)==0)goto l3;
	uptmp++;
	if(moveup<movecaculate[of[xx-uptmp][yy]][type])goto l3;
	}
	l3:
	if(movedown>0)
	{
	movedown-=movecaculate[of[xx+downtmp][yy]][type];
	arrow[xx+downtmp][yy]=1;
	if((xx+downtmp)==31)goto l4;
	downtmp++;
	if(movedown<movecaculate[of[xx+downtmp][yy]][type])goto l4;
	}
	l4:
	if(movedown>0&&moveright>0)
	{
	//movedown-=movecaculate[of[xx+downtmp][yy]][type];
	//arrow[xx+downtmp][yy+righttmp]=1;
	//if((xx+downtmp)==31||(xx+righttmp)==32)goto l4;
	//downtmp++;
	//if(movedown<movecaculate[of[xx+downtmp][yy]][type])goto l4;
	}

	move--;
	}*/


	/*ofstream outfile("Res\\1.txt",ios::out);
	for(i=0;i<31;i++)
	{
	for(int j=0;j<32;j++)
	{
	outfile<<arrow[i][j];
	outfile<<" ";
	}
	outfile<<"\n";
	}

	for(i=0;i<31;i++)
	{
	for(int j=0;j<32;j++)
	{
	outfile<<leavedo[i][j];
	outfile<<" ";
	}
	outfile<<"\n";
	}

	outfile.close();*/

}

int Fight::DayEvent()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	for (int i=0;i<heronumber;i++)
	{
		OverflowCheck(__FILE__,__LINE__,20,i);
		if(fighthero[i].statue==8)continue;
		if(fighthero[i].active==1)//休息恢复skill
		{
			int maxmp = (int)(((int)(fighthero[i].zili ) * 80 / 100 + (PlcExtract(fighthero[i].wuli ) >> 1) 
				+ fighthero[i].degree) * fighthero[i].tili / 100);
			if(fighthero[i].skill < maxmp)
				fighthero[i].skill += 1;
		}

		if(fighthero[i].statue>0)//驱动非正常状态
		{
			ChangeStatue(i);
		}
		if(fighthero[i].statue==6||fighthero[i].statue==1)
		{
			fighthero[i].active=0;
		}
		else
		{
			fighthero[i].active=1;
		}
	}
	for (int i=10;i<heronumberto+10;i++)
	{
		OverflowCheck(__FILE__,__LINE__,20,i);
		if(fighthero[i].statue==8)continue;
		fighthero[i].active=1;
		if(fighthero[i].statue>0)//驱动非正常状态
		{
			ChangeStatue(i);
		}

	}
	foods-=(PlcExtract(allbingli)/3);
	foodsto-=(PlcExtract(allbinglito)/3);
	if(foods<0)
	{
		//我方没有粮食了；
		TimerMessage(GetStrText("dFgtNoProv0"),"",50,280,12,1,1000);
		GameEnd(0);
		return -1;
	}
	if(foodsto<0)
	{
		//敌方没有粮食了；
		TimerMessage(GetStrText("dFgtNoProv1"),"",50,280,12,1,1000);
		GameEnd(1);
		return -2;
	}
	return 0;
}

void Fight::SetAt(int xx,int yy,int x)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	//xx,yy中心位置
	//x武将编号
	int type=fighthero[x].style;
	for(int i=0;i<MAPMAX;i++)
		for(int j=0;j<MAPMAX;j++)		
			atarr[i][j]=0;
	switch(type)//20150517修正的设置可到达点的BUG //20150531 修正x y 范围
	{
	case CAVALRY:
	case SAILOR:
		if(xx>0)atarr[xx-1][yy]=1;
		if(xx<(MAPMAX-1))atarr[xx+1][yy]=1;
		if(yy>0)atarr[xx][yy-1]=1;
		if(yy<(MAPMAX-1))atarr[xx][yy+1]=1;
		break;
	case INFANTRY:
	case GREATHPARM:
	case GREATMPARM://?
		if(xx>0)atarr[xx-1][yy]=1;
		if(xx<(MAPMAX-1))atarr[xx+1][yy]=1;
		if(yy>0)atarr[xx][yy-1]=1;
		if(yy<(MAPMAX-1))atarr[xx][yy+1]=1;
		if(xx>0&&yy>0)atarr[xx-1][yy-1]=1;
		if(xx<(MAPMAX-1)&&yy<(MAPMAX-1))atarr[xx+1][yy+1]=1;
		if(xx>0&&yy<(MAPMAX-1))atarr[xx-1][yy+1]=1;
		if(xx<(MAPMAX-1)&&yy>0)atarr[xx+1][yy-1]=1;	
		break;
	case ARCHER:
		if(xx>1)atarr[xx-2][yy]=1;
		if(xx<(MAPMAX-2))atarr[xx+2][yy]=1;
		if(yy>1)atarr[xx][yy-2]=1;
		if(yy<(MAPMAX-2))atarr[xx][yy+2]=1;
		if(xx>0&&yy>0)atarr[xx-1][yy-1]=1;//20170805
		if(xx<(MAPMAX-1)&&yy<(MAPMAX-1))atarr[xx+1][yy+1]=1;
		if(xx>0&&yy<(MAPMAX-1))atarr[xx-1][yy+1]=1;//20170805
		if(xx<(MAPMAX-1)&&yy>0)atarr[xx+1][yy-1]=1;//20170805
		break;
	}

}

void Fight::GetLifeSkillAtDf()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int at=fighthero[atnowhero].at;
	int df=fighthero[atnowhero].df;
	int tili=fighthero[atnowhero].tili;



	/*double atfact[8][6]={
	1,0.8,0.9,0.4,1.3,0.4,
	1,0.8,0.9,0.4,1.3,0.4,
	0.25,0.8,0.9,0.1,1.3,0.4,
	0.5,0.8,0.9,0.2,1.3,0.4,
	1.0,0.8,0.9,0.4,1.3,0.4,
	1.0,0.8,0.9,0.4,1.3,0.4,
	1.0,0.8,0.9,0.4,1.3,0.4,
	0.125,0.2,0.225,0.8,1.3,0.4};
	double dffact[8][6]={
	0.7,1.2,1,0.55,1.2,0.6,
	0.7,1.2,1,0.55,1.2,0.6,
	0.2275,1.56,1.3,0.17875,1.56,0.78,
	0.4025,1.38,1.15,0.31625,1.38,0.69,
	0.77,1.32,1.1,0.605,1.32,0.66,
	1.05,1.8,1.5,0.825,1.8,0.9,
	0.84,1.44,1.2,0.66,1.44,0.72,
	0.07,0.24,0.3,0.88,0.96,0.48};*/
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[atnowhero].positionx);
	OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[atnowhero].positiony);
	int tile=fightmap.tile[fighthero[atnowhero].positionx][fighthero[atnowhero].positiony];
	int tile1;
	if(tile==1||tile==2)
	{
		tile1=0;
	}
	else if(tile==3)
	{
		tile1=5;
	}
	if(tile==4)
	{
		tile1=4;
	}
	else if(tile==5)
	{
		tile1=3;
	}
	else if(tile>=6&&tile<=15)
	{
		tile1=2;
	}
	else if(tile>=16&&tile<=45&&tile!=41)
	{
		tile1=7;
	}
	else if(tile==41)
	{
		tile1=6;
	}
	else//20161216 //20170115修正else设置全0bug
	{
		tile1=0;
	}

	at=(int)(((double)fighthero[atnowhero].wuli)*((double)(10+fighthero[atnowhero].degree))*atfact[tile1][fighthero[atnowhero].style]);
	df=(int)(((double)fighthero[atnowhero].zili)*((double)(10+fighthero[atnowhero].degree))*dffact[tile1][fighthero[atnowhero].style]);


	fighthero[atnowhero].at=at;
	fighthero[atnowhero].df=df;

}

void Fight::ShowInformation(int x,int tpheroat)//x=0为谍报,1-升级 2-死亡
{
	wlogfile(1,__FUNCTION__,"开始",0);
	char name[NORMALSTRLEN];
	char name1[NORMALSTRLEN];
	char name2[NORMALSTRLEN];
	int herono=0;
	switch(x)
	{
	case WARINTELLIGENCE:
		sprintf_s(name,"%s",GetStrTextSpilted("dReserve1",0,7));
		sprintf_s(name1,"%s",GetStrTextSpilted("dReserve1",1,7));
		sprintf_s(name2,"%s",GetStrTextSpilted("dReserve1",2,7));
		herono=atnowhero;
		break;
	case HEROLEVELUP:
		{	
			int rr=rand()%3;
			if(rr==0)
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtLevUp0",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtLevUp0",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtLevUp0",2,7));
			}
			else if(rr==1)
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtLevUp1",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtLevUp1",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtLevUp1",2,7));
			}
			else
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtLevUp2",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtLevUp2",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtLevUp2",2,7));	
			}
			herono=atnowhero;
			break;
		}
	case HERODEATH:
		{
			int rr=rand()%3;
			if(rr==0)
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtDead0",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtDead0",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtDead0",2,7));
			}
			else if(rr==1)
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtDead1",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtDead1",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtDead1",2,7));
			}
			else
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtDead2",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtDead2",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtDead2",2,7));
			}
			herono=atnowheroat;
			break;
		}
	case ENEMYLEVELUP:
		{	
			int rr=rand()%3;
			if(rr==0)
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtLevUp0",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtLevUp0",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtLevUp0",2,7));
			}
			else if(rr==1)
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtLevUp1",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtLevUp1",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtLevUp1",2,7));
			}
			else
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtLevUp2",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtLevUp2",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtLevUp2",2,7));	
			}
			herono=atnowheroat;
			break;
		}
	case ENEMYDEATH:
		{
			int rr=rand()%3;
			if(rr==0)
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtDead0",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtDead0",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtDead0",2,7));
			}
			else if(rr==1)
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtDead1",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtDead1",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtDead1",2,7));
			}
			else
			{
				sprintf_s(name,"%s",GetStrTextSpilted("dFgtDead2",0,7));
				sprintf_s(name1,"%s",GetStrTextSpilted("dFgtDead2",1,7));
				sprintf_s(name2,"%s",GetStrTextSpilted("dFgtDead2",2,7));
			}
			herono=tpheroat;
			break;
		}

	}
	MyCreateFont(1.0);
	HFONT	h = t_h;
	HFONT oldh=(HFONT)SelectObject(hdcTmp,h);
	MySetTextColor(FONTB,USEHDCTMP);

	if(color==0)
	{
		HPEN hpen=CreatePen(PS_SOLID,5, RGB(0,0,0));
		HPEN oldhpen=(HPEN)SelectObject(hdcTmp,hpen);
		Rectangle(hdcTmp,20,250,780,500); 	
		SelectObject(hdcTmp,oldhpen);
		DeleteObject(hpen);


	}
	else
	{
		ShowCG(0,"Res\\Fight\\fight_imformation.sbp",20,200);


	}

	TextOut(hdcTmp,300,280,name,strlen(name));
	TextOut(hdcTmp,300,350,name1,strlen(name1));
	TextOut(hdcTmp,300,420,name2,strlen(name2));
	SelectObject(hdcTmp,oldh); 
	DeleteObject(h);

	switch(uchoice)
	{
	case DZNQ:
		headfight.Init("Res\\Head\\1dznq.sbp",fighthero[herono].num);
		break;
	case CCJQ:	
		headfight.Init("Res\\Head\\2ccjq.sbp",fighthero[herono].num);
		break;
	case CBZZ:
		headfight.Init("Res\\Head\\3cbzz.sbp",fighthero[herono].num);
		break;
	case SGDL:
		headfight.Init("Res\\Head\\4sgdl.sbp",fighthero[herono].num);
		break;
	default:
		{
				char name[NORMALSTRLEN];
				sprintf_s(name,"Res\\Head\\period%d.sbp",uchoice+1);
				headfight.Init(name,fighthero[herono].num);
		}
		break;
	}
	headfight.Show(100,290);
	char heroname[20];

	sprintf_s(heroname,"%s",t_heroName[fighthero[herono].num]);
	TextOut(hdcTmp,100,430,heroname,strlen(heroname));
	BitBlt(hdc,0,0,800,600,hdcTmp,0,0,SRCCOPY);
	Delay(2000);
	SetTextColor(hdcTmp,RGB(0, 0, 0));
	//Show(0);
}

void Fight::SetAtSkill(int xx,int yy,int x,int y)//y为技能号0-24
{
	wlogfile(1,__FUNCTION__,"开始",0);
	//xx,yy中心位置
	//x武将编号
	int type=y;
	for(int i=0;i<MAPMAX;i++)
		for(int j=0;j<MAPMAX;j++)		
			skillarr[i][j]=0;

	//20150517修正对位置的溢出//20150530修正x=30 y=31
	switch(type)//0-21 23
	{
	case FIREATTACK:
	case CURSESEAL:
	case IMMOBILIZED:
	case GOSSIP:
	case LARGEFIRE:
	case TSUNAMI:
	case INVISIBLEMAGIC:
	case SIEGE:
	case STONEHENGE:
		if(xx>2)skillarr[xx-3][yy]=1;
		if(xx>1&&yy>0)skillarr[xx-2][yy-1]=1;
		if(xx>1)skillarr[xx-2][yy]=1;
		if(xx>1&&yy<(MAPMAX-1))skillarr[xx-2][yy+1]=1;
		if(xx>0&&yy>1)skillarr[xx-1][yy-2]=1;
		if(xx>0&&yy>0)skillarr[xx-1][yy-1]=1;
		if(xx>0)skillarr[xx-1][yy]=1;
		if(xx>0&&yy<(MAPMAX-1))skillarr[xx-1][yy+1]=1;
		if(xx>0&&yy<(MAPMAX-2))skillarr[xx-1][yy+2]=1;
		if(yy>2)skillarr[xx][yy-3]=1;
		if(yy>1)skillarr[xx][yy-2]=1;
		if(yy>0)skillarr[xx][yy-1]=1;
		if(yy<(MAPMAX-1))skillarr[xx][yy+1]=1;
		if(yy<(MAPMAX-2))skillarr[xx][yy+2]=1;
		if(yy<(MAPMAX-3))skillarr[xx][yy+3]=1;
		if(xx<(MAPMAX-1)&&yy>1)skillarr[xx+1][yy-2]=1;
		if(xx<(MAPMAX-1)&&yy>0)skillarr[xx+1][yy-1]=1;
		if(xx<(MAPMAX-1))skillarr[xx+1][yy]=1;
		if(xx<(MAPMAX-1)&&yy<(MAPMAX-1))skillarr[xx+1][yy+1]=1;
		if(xx<(MAPMAX-1)&&yy<(MAPMAX-2))skillarr[xx+1][yy+2]=1;
		if(xx<(MAPMAX-2)&&yy>0)skillarr[xx+2][yy-1]=1;
		if(xx<(MAPMAX-2))skillarr[xx+2][yy]=1;
		if(xx<(MAPMAX-2)&&yy<(MAPMAX-1))skillarr[xx+2][yy+1]=1;
		if(xx<(MAPMAX-3))skillarr[xx+3][yy]=1;
		break;
	case REINFORCEMENTS:
	case LARGEREINFORCEMENTS:
		skillarr[xx][yy]=1;
		if(xx>2)skillarr[xx-3][yy]=1;
		if(xx>1&&yy>0)skillarr[xx-2][yy-1]=1;
		if(xx>1)skillarr[xx-2][yy]=1;
		if(xx>1&&yy<(MAPMAX-1))skillarr[xx-2][yy+1]=1;
		if(xx>0&&yy>1)skillarr[xx-1][yy-2]=1;
		if(xx>0&&yy>0)skillarr[xx-1][yy-1]=1;
		if(xx>0)skillarr[xx-1][yy]=1;
		if(xx>0&&yy<(MAPMAX-1))skillarr[xx-1][yy+1]=1;
		if(xx>0&&yy<(MAPMAX-2))skillarr[xx-1][yy+2]=1;
		if(yy>2)skillarr[xx][yy-3]=1;
		if(yy>1)skillarr[xx][yy-2]=1;
		if(yy>0)skillarr[xx][yy-1]=1;
		if(yy<(MAPMAX-1))skillarr[xx][yy+1]=1;
		if(yy<(MAPMAX-2))skillarr[xx][yy+2]=1;
		if(yy<(MAPMAX-3))skillarr[xx][yy+3]=1;
		if(xx<(MAPMAX-1)&&yy>1)skillarr[xx+1][yy-2]=1;
		if(xx<(MAPMAX-1)&&yy>0)skillarr[xx+1][yy-1]=1;
		if(xx<(MAPMAX-1))skillarr[xx+1][yy]=1;
		if(xx<(MAPMAX-1)&&yy<(MAPMAX-1))skillarr[xx+1][yy+1]=1;
		if(xx<(MAPMAX-1)&&yy<(MAPMAX-2))skillarr[xx+1][yy+2]=1;
		if(xx<(MAPMAX-2)&&yy>0)skillarr[xx+2][yy-1]=1;
		if(xx<(MAPMAX-2))skillarr[xx+2][yy]=1;
		if(xx<(MAPMAX-2)&&yy<(MAPMAX-1))skillarr[xx+2][yy+1]=1;
		if(xx<(MAPMAX-3))skillarr[xx+3][yy]=1;
		break;
	case LOGROLLING:
	case ROCKFALL:
		if(xx>1)skillarr[xx-2][yy]=1;
		if(xx>0&&yy>0)skillarr[xx-1][yy-1]=1;
		if(xx>0)skillarr[xx-1][yy]=1;
		if(xx>0&&yy<(MAPMAX-1))skillarr[xx-1][yy+1]=1;
		if(yy>1)skillarr[xx][yy-2]=1;
		if(yy>0)skillarr[xx][yy-1]=1;
		if(yy<(MAPMAX-1))skillarr[xx][yy+1]=1;
		if(yy<(MAPMAX-2))skillarr[xx][yy+2]=1;
		if(xx<(MAPMAX-1)&&yy>0)skillarr[xx+1][yy-1]=1;
		if(xx<(MAPMAX-1))skillarr[xx+1][yy]=1;
		if(xx<(MAPMAX-1)&&yy<(MAPMAX-1))skillarr[xx+1][yy+1]=1;
		if(xx<(MAPMAX-2))skillarr[xx+2][yy]=1;
		break;
	case FIGHTBRAVELY:
	case FLOODING:
	case IMPACT:
		if(xx>0)skillarr[xx-1][yy]=1;
		if(yy>0)skillarr[xx][yy-1]=1;
		if(yy<(MAPMAX-1))skillarr[xx][yy+1]=1;
		if(xx<(MAPMAX-1))skillarr[xx+1][yy]=1;
		break;
	case FLYARROW:
	case ARROWRAIN:
	case FIREARROW:
	case ASSAULT:
	case SUDDENSTRIKE:
		if(xx>2)skillarr[xx-3][yy]=1;
		if(xx>1&&yy>0)skillarr[xx-2][yy-1]=1;
		if(xx>1&&yy<(MAPMAX-1))skillarr[xx-2][yy+1]=1;
		if(xx>0&&yy>1)skillarr[xx-1][yy-2]=1;
		if(xx>0&&yy<(MAPMAX-2))skillarr[xx-1][yy+2]=1;
		if(yy>2)skillarr[xx][yy-3]=1;//20170806
		if(yy<(MAPMAX-3))skillarr[xx][yy+3]=1;//20170806
		if(xx<(MAPMAX-1)&&yy>1)skillarr[xx+1][yy-2]=1;
		if(xx<(MAPMAX-1)&&yy<(MAPMAX-2))skillarr[xx+1][yy+2]=1;
		if(xx<(MAPMAX-2)&&yy>0)skillarr[xx+2][yy-1]=1;
		if(xx<(MAPMAX-2)&&yy<(MAPMAX-1))skillarr[xx+2][yy+1]=1;
		if(xx<(MAPMAX-3))skillarr[xx+3][yy]=1;
		break;
	case CHARGE:
		if(xx>1)skillarr[xx-2][yy]=1;
		if(xx>0&&yy>0)skillarr[xx-1][yy-1]=1;
		if(xx>0&&yy<(MAPMAX-1))skillarr[xx-1][yy+1]=1;
		if(yy>1)skillarr[xx][yy-2]=1;
		if(yy<(MAPMAX-2))skillarr[xx][yy+2]=1;
		if(xx<(MAPMAX-1)&&yy>0)skillarr[xx+1][yy-1]=1;
		if(xx<(MAPMAX-1)&&yy<(MAPMAX-1))skillarr[xx+1][yy+1]=1;
		if(xx<(MAPMAX-2))skillarr[xx+2][yy]=1;
		break;
	case TRAMPLE:
		if(xx>0)skillarr[xx-1][yy]=1;
		if(xx>0&&yy>0)skillarr[xx-1][yy-1]=1;
		if(xx>0&&yy<(MAPMAX-1))skillarr[xx-1][yy+1]=1;
		if(yy>0)skillarr[xx][yy-1]=1;
		if(yy<(MAPMAX-1))skillarr[xx][yy+1]=1;
		if(xx<(MAPMAX-1)&&yy>0)skillarr[xx+1][yy-1]=1;
		if(xx<(MAPMAX-1)&&yy<(MAPMAX-1))skillarr[xx+1][yy+1]=1;
		if(xx<(MAPMAX-1))skillarr[xx+1][yy]=1;
		break;
	}

}

int Fight::CanAt(int t)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int xx=fightmap.arrowy+fightmap.startx ;
	int yy=fightmap.arrowx+fightmap.starty ;
	if(atarr[xx][yy]==1&&t==0)//普通攻击
	{
		for(int i=10;i<heronumberto+10;i++)
		{
			OverflowCheck(__FILE__,__LINE__,20,i);
			if(fighthero[i].statue==8)continue;
			if(fighthero[i].positionx==xx&&fighthero[i].positiony==yy)
			{
				atnowheroat=i;
				return 1;
			}
		}
		for(int i=0;i<heronumber;i++)
		{
			OverflowCheck(__FILE__,__LINE__,20,i);
			if(fighthero[i].statue==8)continue;
			if(fighthero[i].positionx==xx&&fighthero[i].positiony==yy)
			{
				return 2;
			}
		}
	}
	if(skillarr[xx][yy]==1&&t==1)//技能,除援兵援军
	{
		for(int i=10;i<heronumberto+10;i++)
		{
			OverflowCheck(__FILE__,__LINE__,20,i);
			if(fighthero[i].statue==8)continue;
			if(fighthero[i].positionx==xx&&fighthero[i].positiony==yy)
			{
				atnowheroat=i;
				return 1;
			}
		}
		for(int i=0;i<heronumber;i++)
		{
			OverflowCheck(__FILE__,__LINE__,20,i);
			if(fighthero[i].statue==8)continue;
			if(fighthero[i].positionx==xx&&fighthero[i].positiony==yy)
			{
				return 2;
			}
		}

	}
	if(skillarr[xx][yy]==1&&t==2)//技能,援兵援军
	{
		for(int i=10;i<heronumberto+10;i++)
		{
			OverflowCheck(__FILE__,__LINE__,20,i);
			if(fighthero[i].statue==8)continue;
			if(fighthero[i].positionx==xx&&fighthero[i].positiony==yy)
			{
				return 2;
			}
		}
		for(int i=0;i<heronumber;i++)
		{
			OverflowCheck(__FILE__,__LINE__,20,i);
			if(fighthero[i].statue==8)continue;
			if(fighthero[i].positionx==xx&&fighthero[i].positiony==yy)
			{
				atnowheroat=i;
				return 1;
			}
		}

	}
	return 0;
}
int Fight::WeatherOK(int x)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	switch(x)//0-21 23
	{
	case FIREATTACK:	
	case FIREARROW:
		if(weather==5||weather==4)
			return 0;
		break;

	case LOGROLLING:
	case ROCKFALL:
	case FIGHTBRAVELY:
	case FLYARROW:
	case ARROWRAIN:

	case TRAMPLE:
	case FLOODING:
	case IMPACT:
	case CURSESEAL:
	case IMMOBILIZED:
	case GOSSIP:
	case REINFORCEMENTS:
	case TSUNAMI:
	case INVISIBLEMAGIC:
	case LARGEREINFORCEMENTS:
	case SIEGE:
	case STONEHENGE:
		if(weather==5)
			return 0;
		break;
	case LARGEFIRE:
		if(weather>=3)
			return 0;
		break;

	}
	return 1;
}

int Fight::LandOK(int x,int flag)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	if(flag==0)
	{
		OverflowCheck(__FILE__,__LINE__,20,atnowhero);
		int tx=fighthero[atnowhero].positionx;
		int ty=fighthero[atnowhero].positiony;

		switch(x)//在山地使用 1 2
		{
		case LOGROLLING:	
		case ROCKFALL:
			if(fightmap.tile[tx][ty]>=6&&fightmap.tile[tx][ty]<=15)
				return 1;
			else
				return 0;
		}
	}
	else 
	{
		
		int wx=fightmap.arrowy+fightmap.startx ;
		int wy=fightmap.arrowx+fightmap.starty ;
		OverflowCheck(__FILE__,__LINE__,MAPMAX,wx);
		OverflowCheck(__FILE__,__LINE__,MAPMAX,wy);

		switch(x)//
		{

		case FIGHTBRAVELY:
			if(fightmap.tile[wx][wy]!=3)
				return 0;
		}
	}

	return 1;
}

int Fight::SkillForceOK(int x)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	switch(x)//0-21 23
	{
	case WEATHERCHANGE:
		if(fighthero[atnowhero].skill<10)
			return 0;
		break;
	case FIREATTACK:	
	case FLYARROW:
	case TRAMPLE:
	case FLOODING:
	case CURSESEAL:
	case REINFORCEMENTS:
	case SPY:
		if(fighthero[atnowhero].skill<15)
			return 0;
		break;
	case LOGROLLING:	
	case ARROWRAIN:
	case CHARGE:
	case IMMOBILIZED:
	case GOSSIP:
	case STONEHENGE:
	case INVISIBLEMAGIC:
		if(fighthero[atnowhero].skill<20)
			return 0;
		break;
	case ROCKFALL:	
	case ASSAULT:
	case FIREARROW:	
	case SUDDENSTRIKE:
		if(fighthero[atnowhero].skill<25)
			return 0;
		break;
	case FIGHTBRAVELY:	
	case IMPACT:
	case LARGEFIRE:	
	case TSUNAMI:
	case LARGEREINFORCEMENTS:	
	case SIEGE:
		if(fighthero[atnowhero].skill<30)
			return 0;
		break;

	}
	return 1;
}

void Fight::SubSkillPower(int x)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	switch(x)
	{
	case WEATHERCHANGE:
		fighthero[atnowhero].skill-=10;
		break;
	case FIREATTACK:	
	case FLYARROW:
	case TRAMPLE:
	case FLOODING:
	case CURSESEAL:
	case REINFORCEMENTS:
	case SPY:
		fighthero[atnowhero].skill-=15;
		break;
	case LOGROLLING:	
	case ARROWRAIN:
	case CHARGE:
	case IMMOBILIZED:
	case GOSSIP:
	case STONEHENGE:
	case INVISIBLEMAGIC:
		fighthero[atnowhero].skill-=20;
		break;
	case ROCKFALL:	
	case ASSAULT:
	case SUDDENSTRIKE:
	case FIREARROW:
		fighthero[atnowhero].skill-=25;
		break;
	case FIGHTBRAVELY:	
	case IMPACT:
	case LARGEFIRE:	
	case TSUNAMI:
	case LARGEREINFORCEMENTS:	
	case SIEGE:
		fighthero[atnowhero].skill-=30;
		break;

	}
	return;
}

int Fight::FightEvent()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	if(flagarrowat)
	{
		CountAtkHurt();
		flagarrowat=0;
	}
	else
	{
		//增加成功率计算
		OverflowCheck(__FILE__,__LINE__,20,atnowhero);
		int fact=fighthero[atnowhero].zili+fighthero[atnowhero].degree+25;
		int fact1=fighthero[10].zili+fighthero[10].degree+5;
		int state = rand() % fact;
		if(state > (fact1>> 1))
		{	// 施展计谋失败 
			char str[20];
			int sdf=fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb];
			sprintf_s(str,"%s",t_skillName[sdf]);

			ShowCGDirect(0,"Res\\Fight\\fight_messagekuang.sbp",100,200);
			ShowTextDirectWithColor(str,150,280);
			ShowTextDirectWithColor(GetStrText("dFgtJNFail"),400,280);
			Delay(1000);
			flagarrowskill=0;
		}
		else
		{
			int ret=CountSklHurt();
			if(ret==-1)
			{
				return -1;
			}
			else
			{
				flagarrowskill=0;
			}
		}
	}
	fighthero[atnowhero].active=0;
	if(TestWinLose()==-1)return -10;
	if(TestWinLose()==-2)return -11;
	return 0;
}

void Fight::CountAtkHurt()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	/*const double SubduModu[6][6] = {
	{1.0,1.2,0.8,1.0,0.7,1.3},
	{0.8,1.0,1.2,1.0,0.6,1.2},
	{1.2,0.8,1.0,1.0,1.1,1.2},
	{1.0,1.0,1.0,1.0,1.0,1.0},
	{1.1,1.3,0.9,1.0,1.0,1.5},
	{0.6,0.6,0.6,0.6,0.6,0.6}};*/

	double d_hurt = 0.0;
	int hurt = 0;

	GetLifeSkillAtDf();
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	int at=fighthero[atnowhero].at;
	int savehero=atnowhero;
	atnowhero=atnowheroat;
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	GetLifeSkillAtDf();
	int df=fighthero[atnowhero].df;
	atnowhero=savehero;
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	int bingli=fighthero[atnowhero].bingli;
	// 基本伤害 hurt = (at / df) * arms / 8 
	d_hurt = (double)( at) /  df * (bingli >> 3);
	// 相克加层 hurt *= modu 
	int txp=fighthero[atnowhero].style;
	int typ=fighthero[atnowheroat].style;
	d_hurt *= SubduModu[txp][typ];
	hurt = (int)d_hurt;
	//if(fightmap.tilestyle[fighthero[atnowheroat].positionx][fighthero[atnowheroat].positiony]==7)hurt*=8;
	hurt+=10;
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	fighthero[atnowheroat].bingli-=hurt;
	allbinglito-=hurt;
	//flagshowhurt=hurt;
	if(fighthero[atnowheroat].bingli<0)
	{
		fighthero[atnowheroat].bingli+=hurt;
		allbinglito+=hurt;
		hurt=fighthero[atnowheroat].bingli;
		allbinglito-=hurt;
		fighthero[atnowheroat].bingli-=hurt;
	}
	ex=GetExp(hurt);
	fighthero[atnowhero].experience+=ex;
	ShowHurt(hurt,ex);
	if(fighthero[atnowheroat].bingli<=0)
	{
		//死亡
		ShowDeath();
		fighthero[atnowheroat].statue=8;
		fighthero[atnowheroat].bingli=0;

	}
	if(fighthero[atnowhero].experience>=100)
	{
		//升级
		ShowLevelUp();
		fighthero[atnowhero].experience-=100;
		fighthero[atnowhero].degree++;
		if(fighthero[atnowhero].degree>20)
			fighthero[atnowhero].degree=20;
		int health = (fighthero[atnowhero].wuli * 80 / 100 + fighthero[atnowhero].zili * 30 / 100 +fighthero[atnowhero].degree) * fighthero[atnowhero].tili/ 100;
		if(health<0)health=0;
		fighthero[atnowhero].health=health;
		int skill = (fighthero[atnowhero].zili * 80 / 100 + (PlcExtract(fighthero[atnowhero].wuli) >> 1) +fighthero[atnowhero].degree) * fighthero[atnowhero].tili/ 100;
		if(skill<0)skill=0;	
		fighthero[atnowhero].skill=skill;
		
	}
}

int Fight::CountSklHurt()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int	hurt=GetSkill();
	if(hurt==-3)
	{
		flagunable=3;
		return -1;
	}
	else if(hurt==-5)
	{
		flagunable=5;
		return -1;
	}
	else
	{
		OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
		OverflowCheck(__FILE__,__LINE__,20,atnowhero);
		if(fighthero[atnowheroat].bingli>=hurt)
		{
			fighthero[atnowheroat].bingli-=hurt;
			allbinglito-=hurt;
		}
		else
		{
			hurt=fighthero[atnowheroat].bingli;
			fighthero[atnowheroat].bingli=0;
			allbinglito-=hurt;
		}
		ex=GetExp(hurt);
		//flagshowskillhurt=hurt;

		int compare=fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb];
		if((compare!=6&&compare<=11)||compare==16||compare==17)
		{
			ShowSkillHurt(hurt,ex);
			fighthero[atnowhero].experience+=ex;
		}
		else
		{
			ShowSkillHurt(hurt,8);
			fighthero[atnowhero].experience+=8;
		}
		if(fighthero[atnowheroat].bingli<=0)
		{
			//死亡
			ShowDeath();
			fighthero[atnowheroat].statue=8;
			fighthero[atnowheroat].bingli=0;

		}
		if(fighthero[atnowhero].experience>=100)
		{
			//升级
			ShowLevelUp();
			fighthero[atnowhero].experience-=100;
			fighthero[atnowhero].degree++;
			if(fighthero[atnowhero].degree>20)
				fighthero[atnowhero].degree=20;
			int health = (fighthero[atnowhero].wuli * 80 / 100 + fighthero[atnowhero].zili * 30 / 100 +fighthero[atnowhero].degree) * fighthero[atnowhero].tili/ 100;
			if(health<0)health=0;
			fighthero[atnowhero].health=health;
			int skill = (fighthero[atnowhero].zili * 80 / 100 + (PlcExtract(fighthero[atnowhero].wuli) >> 1) +fighthero[atnowhero].degree) * fighthero[atnowhero].tili/ 100;
			if(skill<0)skill=0;	
			fighthero[atnowhero].skill=skill;

		}
	}
	return 0;

}

void Fight::ShowHurt(int hurt,int exp)//直接显示，不用缓冲
{
	wlogfile(1,__FUNCTION__,"开始",0);
	if(menushow1==0)
	{
		char str[20];
		OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
		int xx=fighthero[atnowheroat].positionx-fightmap.startx;
		int yy=fighthero[atnowheroat].positiony-fightmap.starty;
		//if(tyx<0)tyx=0;
		//if(tyy<0)tyy=0;
		//int xx=fighthero[atnowheroat].positionx-tyx;
		//int yy=fighthero[atnowheroat].positiony-tyy;
		sprintf_s(str,"-%d",hurt);
		ShowTextDirect(str,fightmap.arrowx*80,fightmap.arrowy*80+50 ,50);
		Delay(1000);

		LoadPic("Res\\Fight\\fight_messagekuang.sbp",hbmp);	// 背景图
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, 105, 185, 590,110, hdcMem, 0, 0, SRCCOPY);
		SelectObject(hdcMem, oldhbmp);
		DeleteObject(hbmp);
		ShowTextDirectWithColor(GetStrText("dFgtGetExp"),200,215,50);
		char str1[20];
		sprintf_s(str1,"%d",exp);
		ShowTextDirectWithColor(str1,500,215,50);
		Delay(1000);
		return ;
	}

	int herostyle=fighthero[atnowhero].style;
	int herostyleto=fighthero[atnowheroat].style;
	int i;

	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[atnowheroat].positionx);
	OverflowCheck(__FILE__,__LINE__,MAPMAX,fighthero[atnowheroat].positiony);
	if(fightmap.tilestyle[fighthero[atnowheroat].positionx][fighthero[atnowheroat].positiony]==7)//水中攻击
	{
		for(i=0;i<4;i++)
		{
			LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);

			LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
			oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 120, 150, 215, 205, hdcMem, 0, 1230, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);	
			if(i==1)
			{
				LoadPic("Res\\Fight\\arrow1.sbp",hbmp);	//箭
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	
			}
			if(i==2)
			{
				LoadPic("Res\\Fight\\arrow2.sbp",hbmp);	//箭
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	
			}
			LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
			oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 0, 1290, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);	

			BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
			Delay(50);

		}
	}
	else
	{
		//herostyle=3;

		switch(herostyle)
		{
		case CAVALRY://骑兵
		case GREATHPARM://极兵
			for(i=0;i<7;i++)
			{
				LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);

				LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 120+i*35, 150, 215, 205, hdcMem, 215*i, herostyle*205, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	

				LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/6), 215*herostyleto, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	

				BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
				Delay(50);

			}
			break;
		case INFANTRY://步兵

			for(i=0;i<4;i++)
			{
				LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);

				LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 120+i*70, 150, 215, 205, hdcMem, 215*i, 205, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	

				LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/3), 215*herostyleto, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	

				BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
				Delay(50);

			}
			break;
		case ARCHER://弓兵

			for(i=0;i<4;i++)
			{
				LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);

				LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 120, 150, 215, 205, hdcMem, 215*i, 410, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	
				if(i==1)
				{
					LoadPic("Res\\Fight\\arrow1.sbp",hbmp);	//箭
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);
					DeleteObject(hbmp);	
				}
				if(i==2)
				{
					LoadPic("Res\\Fight\\arrow2.sbp",hbmp);	//箭
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);
					DeleteObject(hbmp);	
				}
				LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/3), 215*herostyleto, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	

				BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
				Delay(50);

			}
			break;
		case SAILOR://水兵
		case GREATMPARM://玄兵
			for(i=0;i<6;i++)
			{
				LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);

				LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 120+i*42, 150, 215, 205, hdcMem, 215*i, herostyle*205, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	

				LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/5), 215*herostyleto, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	

				BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
				Delay(50);

			}
			break;
		}
	}
	//hurt=8888;
	char str[10];
	if(hurt<10)//20150920增加小于10判断
	{
		int hurt0=hurt;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);	
	}
	else if(hurt<100)
	{
		int hurt0=hurt/10;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);
		Delay(100);
		int hurt1=hurt-hurt0*10;
		sprintf_s(str,"%d",hurt1);
		ShowTextDirectWithColor(str,350,200,100);

	}
	else if(hurt<1000)
	{
		int hurt0=hurt/100;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);
		Delay(100);
		int hurt1=hurt-hurt0*100;
		hurt1=hurt1/10;
		sprintf_s(str,"%d",hurt1);
		ShowTextDirectWithColor(str,350,200,100);
		Delay(100);
		int hurt2=hurt-hurt0*100-hurt1*10;
		sprintf_s(str,"%d",hurt2);
		ShowTextDirectWithColor(str,400,200,100);
	}
	else
	{
		int hurt0=hurt/1000;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);
		Delay(100);
		int hurt1=hurt-hurt0*1000;
		hurt1=hurt1/100;
		sprintf_s(str,"%d",hurt1);
		ShowTextDirectWithColor(str,350,200,100);
		Delay(100);
		int hurt2=hurt-hurt0*1000-hurt1*100;
		hurt2=hurt2/10;
		sprintf_s(str,"%d",hurt2);
		ShowTextDirectWithColor(str,400,200,100);
		Delay(100);
		int hurt3=hurt-hurt0*1000-hurt1*100-hurt2*10;
		sprintf_s(str,"%d",hurt3);
		ShowTextDirectWithColor(str,450,200,100);
	}
	Delay(1000);


	LoadPic("Res\\Fight\\fight_messagekuang.sbp",hbmp);	// 背景图
	HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
	BitBlt(hdc, 105, 185, 590,110, hdcMem, 0, 0, SRCCOPY);
	SelectObject(hdcMem, oldhbmp);
	DeleteObject(hbmp);
	ShowTextDirectWithColor(GetStrText("dFgtGetExp"),200,215,50);
	char str1[20];
	sprintf_s(str1,"%d",exp);
	ShowTextDirectWithColor(str1,500,215,50);
	Delay(1000);
}

int Fight::GetExp(int hurt)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int	exp,lec;
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	lec =fighthero[atnowhero].degree - fighthero[atnowheroat].degree;		/* 等级差 */
	exp = PlcExtract(hurt) >> 2;
	if(lec < 0)		// 攻击者比被攻击者的等级低 
	{
		exp -= lec;
		if(exp<0)exp=0;
	}
	else
	{
		if(exp > lec)
			exp -= lec;
		else
			exp = 0;
	}
	exp += 2;
	if(fighthero[atnowheroat].bingli<=0)
	{
		if(lec<0)
		{
			exp+=16;
		}
		else
		{
			exp+=8;
		}
	}
	return (exp % 100);
}

int Fight::GetSkill()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	OverflowCheck(__FILE__,__LINE__,20,fighthero[atnowhero].menuskill.statb);
	int hurt=0;
	int compare=fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb];
	int under0;//我方地形
	int under1;//敌方地形
	//weather-1，天气
	int styleto=fighthero[atnowheroat].style;//敌人兵种

	if((compare!=6&&compare<=11)||compare==16||compare==17)
	{

		int tx=fighthero[atnowhero].positionx;
		int ty=fighthero[atnowhero].positiony;
		under0=fightmap.tilestyle[tx][ty];

		int wx=fighthero[atnowheroat].positionx;
		int wy=fighthero[atnowheroat].positiony;
		under1=fightmap.tilestyle[wx][wy];

		hurt=skilltp[compare][2];
		hurt=hurt*skilltp[compare][4+weather]/100;
		hurt=hurt*skilltp[compare][10+under0]/100;
		if(hurt==0)	//我方地形错误
		{
			//地形错误
			return -5;
		}
		hurt=hurt*skilltp[compare][18+under1]/100;
		if(hurt==0)	//敌方地形错误
		{
			//地形错误
			return -5;
		}
		hurt=hurt*skilltp[compare][26+styleto]/100;
		if(hurt==0)	//目标兵种错误	
		{
			//命令无效
			return -3;
		}
		return hurt;
	}
	else if (compare==6)
	{
		//减粮食
		foodsto-=150;

		return 0;

	}
	else if(compare==15)
	{
		//加兵
		fighthero[atnowheroat].bingli +=800;
		return 0;
	}
	else if(compare==19)
	{
		//加兵
		fighthero[atnowheroat].bingli +=1800;
		return 0;
	}
	else if(compare==21)
	{
		//作用伤敌800，并让敌人进入混乱状态4
		int tx=fighthero[atnowhero].positionx;
		int ty=fighthero[atnowhero].positiony;
		under0=fightmap.tilestyle[tx][ty];

		int wx=fighthero[atnowheroat].positionx;
		int wy=fighthero[atnowheroat].positiony;
		under1=fightmap.tilestyle[wx][wy];

		hurt=skilltp[compare][2];
		hurt=hurt*skilltp[compare][4+weather]/100;
		hurt=hurt*skilltp[compare][10+under0]/100;
		if(hurt==0)	//我方地形错误
		{
			//地形错误
			return -5;
		}
		hurt=hurt*skilltp[compare][18+under1]/100;
		if(hurt==0)	//敌方地形错误
		{
			//地形错误
			return -5;
		}
		hurt=hurt*skilltp[compare][26+styleto]/100;
		if(hurt==0)	//目标兵种错误	
		{
			//命令无效
			return -3;
		}
		fighthero[atnowheroat].statue=1;
		return hurt;
	}
	else if(compare==12)
	{
		//状态禁咒
		fighthero[atnowheroat].statue=2;

		return 0;
	}
	else if(compare==13)
	{
		//状态 定身 
		fighthero[atnowheroat].statue=3;
		return 0;
	}
	else if(compare==14)
	{
		//混乱
		fighthero[atnowheroat].statue=1;
		return 0;
	}
	else if(compare==23)
	{
		//石阵
		fighthero[atnowheroat].statue=6;
		return 0;
	}
	else if(compare==18)
	{
		//奇门：等级14、耗技力30、作用使己方将领免受计谋伤害（持续2～4回合）、范围1～3格、冰雹天不能使用。 18 ？
		fighthero[atnowheroat].statue=4;
		return 0;
	}
	else if(compare==20)
	{

		//围攻：等级19、耗技力30、作用未知、范围1～3格。  20
		return -3;
	}
	return 0;
}

void Fight::ShowSkillHurt(int hurt,int exp)//直接显示，不用缓冲
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	OverflowCheck(__FILE__,__LINE__,20,fighthero[atnowhero].menuskill.statb);
	int compare=fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb];
	if(hurt==0&&((compare!=6&&compare<=11)||compare==16||compare==17))goto exo;

	{
		if(menushow1==0)
		{
			char str[20];
			int compare1=fighthero[atnowhero].skillno[fighthero[atnowhero].menuskill.statb];
			LoadPic("Res\\Fight\\fight_messagekuang.sbp",hbmp);	// 背景图
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdc, 105, 55, 590,110, hdcMem, 0, 0, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);
			sprintf_s(str,"%s",t_skillName[compare1]);
			ShowTextDirectWithColor(str,200,85,50);
			ShowTextDirectWithColor(GetStrText("dFgtArmsH"),400,85,50);
			sprintf_s(str,"-%d",hurt);
			ShowTextDirectWithColor(str,fightmap.arrowx*80 ,fightmap.arrowy*80+50 ,50);
			Delay(1000);

			LoadPic("Res\\Fight\\fight_messagekuang.sbp",hbmp);	// 背景图
			oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdc, 105, 185, 590,110, hdcMem, 0, 0, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);
			ShowTextDirectWithColor(GetStrText("dFgtGetExp"),200,215,50);
			char str1[20];
			sprintf_s(str1,"%d",exp);
			ShowTextDirectWithColor(str1,500,215,50);
			Delay(1000);
			return ;
		}

		int herostyle=fighthero[atnowhero].style;
		int herostyleto=fighthero[atnowheroat].style;

		int i;
		switch(compare)
		{
		case FIREATTACK://火攻
		case FIREARROW://火箭
		case LARGEFIRE://烈火
			for(i=0;i<6;i++)
			{
				LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 0, SRCCOPY);
				DeleteObject(hbmp);

				BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
				Delay(200);

			}
			break;
		case LOGROLLING://滚木1
		case ROCKFALL://落石2

			for(i=0;i<6;i++)
			{
				LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 320, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);

				BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
				Delay(100);

			}
			break;
		case FLOODING://水淹
		case TSUNAMI://海啸
			for(i=0;i<6;i++)
			{
				LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 640, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

				BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
				Delay(100);

			}
			break;
		case IMPACT://撞击
			for(i=0;i<6;i++)
			{
				LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 960, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

				BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
				Delay(100);

			}
			break;
		case CURSESEAL://咒封12
		case IMMOBILIZED://定身13
			for(i=0;i<6;i++)
			{
				LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 1280, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

				BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
				Delay(100);

			}
			break;
		case GOSSIP://留言
			for(i=0;i<6;i++)
			{
				LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 1600, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

				BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
				Delay(100);

			}
			break;
		case REINFORCEMENTS://援军
		case LARGEREINFORCEMENTS://援军
			for(i=0;i<6;i++)
			{
				LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 1920, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

				BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
				Delay(100);

			}
			break;
		case STONEHENGE://石阵
			for(i=0;i<6;i++)
			{
				LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 2240, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

				BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
				Delay(100);

			}
			break;
			/*奋战3
			飞矢4 兵力减少
			箭雨5 兵力减少
			践踏7 兵力减少
			冲锋8
			突击9*/
		case FIGHTBRAVELY:
		case FLYARROW:
		case ARROWRAIN:
		case TRAMPLE:
		case CHARGE:
		case ASSAULT:
		case SUDDENSTRIKE:
			{
				int i;
				switch(herostyle)
				{
				case CAVALRY://骑兵
				case GREATHPARM://极兵
					for(i=0;i<7;i++)
					{
						LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
						HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

						LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
						oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 120+i*35, 150, 215, 205, hdcMem, 215*i, herostyle*205, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

						LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
						oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/6), 215*herostyleto, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

						BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
						Delay(50);

					}
					break;
				case INFANTRY://步兵

					for(i=0;i<4;i++)
					{
						LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
						HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

						LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
						oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 120+i*70, 150, 215, 205, hdcMem, 215*i, 205, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

						LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
						oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/3), 215*herostyleto, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

						BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
						Delay(50);

					}
					break;
				case ARCHER://弓兵

					for(i=0;i<4;i++)
					{
						LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
						HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

						LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
						oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 120, 150, 215, 205, hdcMem, 215*i, 410, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	
						if(i==1)
						{
							LoadPic("Res\\Fight\\arrow1.sbp",hbmp);	//箭
							oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
							BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
							SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	
						}
						if(i==2)
						{
							LoadPic("Res\\Fight\\arrow2.sbp",hbmp);	//箭
							oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
							BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
							SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	
						}
						LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
						oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/3), 215*herostyleto, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

						BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
						Delay(50);

					}
					break;
				case SAILOR://水兵
				case GREATMPARM://玄兵
					for(i=0;i<6;i++)
					{
						LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
						HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

						LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
						oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 120+i*42, 150, 215, 205, hdcMem, 215*i, herostyle*205, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

						LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
						oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/5), 215*herostyleto, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

						BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
						Delay(50);

					}
					break;
				}
			}
			break;
			//case 
			/*
			奇门18
			围攻20*/
			//break;
		}

		//hurt=8888;
		if((compare!=6&&compare<=11)||compare==16||compare==17||compare==21)

		{
			ShowTextDirectWithColor(GetStrText("dFgtArmsH"),250,100,60);
			char str[10];
			if(hurt<10)//20150920增加小于10判断
			{
				int hurt0=hurt;
				sprintf_s(str,"%d",hurt0);
				ShowTextDirectWithColor(str,300,200,100);	
			}
			else if(hurt<100)
			{
				int hurt0=hurt/10;
				sprintf_s(str,"%d",hurt0);
				ShowTextDirectWithColor(str,300,200,100);
				Delay(100);
				int hurt1=hurt-hurt0*10;
				sprintf_s(str,"%d",hurt1);
				ShowTextDirectWithColor(str,350,200,100);

			}
			else if(hurt<1000)
			{
				int hurt0=hurt/100;
				sprintf_s(str,"%d",hurt0);
				ShowTextDirectWithColor(str,300,200,100);
				Delay(100);
				int hurt1=hurt-hurt0*100;
				hurt1=hurt1/10;
				sprintf_s(str,"%d",hurt1);
				ShowTextDirectWithColor(str,350,200,100);
				Delay(100);
				int hurt2=hurt-hurt0*100-hurt1*10;
				sprintf_s(str,"%d",hurt2);
				ShowTextDirectWithColor(str,400,200,100);
			}
			else
			{
				int hurt0=hurt/1000;
				sprintf_s(str,"%d",hurt0);
				ShowTextDirectWithColor(str,300,200,100);
				Delay(100);
				int hurt1=hurt-hurt0*1000;
				hurt1=hurt1/100;
				sprintf_s(str,"%d",hurt1);
				ShowTextDirectWithColor(str,350,200,100);
				Delay(100);
				int hurt2=hurt-hurt0*1000-hurt1*100;
				hurt2=hurt2/10;
				sprintf_s(str,"%d",hurt2);
				ShowTextDirectWithColor(str,400,200,100);
				Delay(100);
				int hurt3=hurt-hurt0*1000-hurt1*100-hurt2*10;
				sprintf_s(str,"%d",hurt3);
				ShowTextDirectWithColor(str,450,200,100);
			}
			Delay(1000);
		}
	}

exo:
	LoadPic("Res\\Fight\\fight_messagekuang.sbp",hbmp);	// 背景图
	HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
	BitBlt(hdc, 105, 185, 590,110, hdcMem, 0, 0, SRCCOPY);
	SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);
	ShowTextDirectWithColor(GetStrText("dFgtGetExp"),200,215,50);
	char str1[20];
	sprintf_s(str1,"%d",exp);
	ShowTextDirectWithColor(str1,500,215,50);
	Delay(1000);
}

void Fight::ChangeStatue(int x)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	bool rec = (rand() % 60) < (fighthero[x].zili >> 1);
	int hurt=0;
	switch(fighthero[x].statue)
	{
	case STONEHENGESTATUS:		/* 石阵 */
		hurt = fighthero[x].bingli >> 3;
		fighthero[x].bingli-= hurt;
	case CHAOSSTATUS:		/* 混乱 */
	case CURSESEALSTATUS:		/* 禁咒 */
	case IMMOBILIZEDSTATUS:		/* 定身 */
		if(rec)
		{
			fighthero[x].statue =0;
		}
		break;
	case INVISIBLEMAGICSTATUS:		/* 奇门 */
	case INVISIBLESTATUS:		/* 潜踪 */
		if(!rec)
		{
			fighthero[x].statue =0;		
		}
		break;
	}
	if(hurt)
	{
		//FgtShowSNum('-',i,hurt);//显示减去伤害
		ShowHurt2(x,hurt);
	}

}

void Fight::ShowLevelUp()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	//20150920修正战斗时 如果移动到右方边缘和下方边缘时，下一回合定位时出现的显示异常问题
	if(fighthero[atnowhero].positiony > 4 && fighthero[atnowhero].positiony < 27 )
	{
		fightmap.starty = fighthero[atnowhero].positiony - 4;
	}
	else if(fighthero[atnowhero].positiony >= 27)
	{
		fightmap.starty = 22;
	}
	else if(fighthero[atnowhero].positiony <= 4)
	{
		fightmap.starty = 0;
	}

	if(fighthero[atnowhero].positionx > 2 && fighthero[atnowhero].positionx < 29 )
	{
		fightmap.startx = fighthero[atnowhero].positionx - 2;
	}
	else if(fighthero[atnowhero].positionx >= 29)
	{
		fightmap.startx = 26;
	}
	else if(fighthero[atnowhero].positionx <= 2)
	{
		fightmap.startx = 0;
	}

	ShowBar();
	fightmap.ShowStart(0,warstyle);//以自己主将为中心显示
	for(int y=0;y<heronumber;y++)
	{	
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].statue==8)continue;
		if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
			fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
		{
			int yy=fighthero[y].positionx-fightmap.startx;
			int xx=fighthero[y].positiony-fightmap.starty;
			fighthero[y].ShowDirct(xx,yy);//显示己方武将
		}

	}//显示己方武将
	for(int y=10;y<heronumberto+10;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].statue==8)continue;
		if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
			fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
		{
			int yy=fighthero[y].positionx-fightmap.startx;
			int xx=fighthero[y].positiony-fightmap.starty;
			fighthero[y].ShowDirct(xx,yy);
		}

	}


	for(int i=0;i<5;i++)
	{
		int xx=fighthero[atnowhero].positionx-fightmap.startx;
		int yy=fighthero[atnowhero].positiony-fightmap.starty;
		LoadPic("Res\\Fight\\sjmask.sbp",hbmp);	
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, yy*80, xx*80+50, 80,80, hdcMem, i*80, 0, SRCPAINT);
		SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

		LoadPic("Res\\Fight\\sj.sbp",hbmp);	
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, yy*80, xx*80+50, 80,80, hdcMem, i*80, 0, SRCAND);
		SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

		Delay(300);
	}
	ShowInformation(HEROLEVELUP,0);
	return;
}

void Fight::ShowDeath()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	//20150920修正战斗时 如果移动到右方边缘和下方边缘时，下一回合定位时出现的显示异常问题
	if(fighthero[atnowheroat].positiony > 4 && fighthero[atnowheroat].positiony < 27 )
	{
		fightmap.starty = fighthero[atnowheroat].positiony - 4;
	}
	else if(fighthero[atnowheroat].positiony >= 27)
	{
		fightmap.starty = 22;
	}
	else if(fighthero[atnowheroat].positiony <= 4)
	{
		fightmap.starty = 0;
	}

	if(fighthero[atnowheroat].positionx > 2 && fighthero[atnowheroat].positionx < 29 )
	{
		fightmap.startx = fighthero[atnowheroat].positionx - 2;
	}
	else if(fighthero[atnowheroat].positionx >= 29)
	{
		fightmap.startx = 26;
	}
	else if(fighthero[atnowheroat].positionx <= 2)
	{
		fightmap.startx = 0;
	}

	ShowBar();
	fightmap.ShowStart(0,warstyle);//以自己主将为中心显示
	for(int y=0;y<heronumber;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].statue==8)continue;
		if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
			fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
		{
			int yy=fighthero[y].positionx-fightmap.startx;
			int xx=fighthero[y].positiony-fightmap.starty;
			fighthero[y].ShowDirct(xx,yy);//显示己方武将
		}

	}//显示己方武将
	for(int y=10;y<heronumberto+10;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].statue==8)continue;
		if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
			fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
		{
			int yy=fighthero[y].positionx-fightmap.startx;
			int xx=fighthero[y].positiony-fightmap.starty;
			fighthero[y].ShowDirct(xx,yy);
		}

	}

	for(int i=0;i<5;i++)
	{
		int xx=fighthero[atnowheroat].positionx-fightmap.startx;
		int yy=fighthero[atnowheroat].positiony-fightmap.starty;

		LoadPic("Res\\Fight\\swmask.sbp",hbmp);	
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, yy*80, xx*80+50, 80,80, hdcMem, i*80, 0, SRCPAINT);
		SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

		LoadPic("Res\\Fight\\sw.sbp",hbmp);	
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, yy*80, xx*80+50, 80,80, hdcMem, i*80, 0, SRCAND);
		SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

		Delay(300);


	}
	ShowInformation(HERODEATH,0);
	return;
}

int Fight::TestWinLose()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	if(foods<0)
	{
		//我方没有粮食了；
		TimerMessage(GetStrText("dFgtNoProv0"),"",50,280,12,1,1000);
		GameEnd(0);
		return -1;
	}
	if(foodsto<0)
	{
		//敌方没有粮食了；
		TimerMessage(GetStrText("dFgtNoProv1"),"",50,280,12,1,1000);
		GameEnd(1);
		return -2;
	}
	if(fighthero[0].bingli==0)//我方主将死亡，结束
	{
		GameEnd(0);
		return -1;
	}
	if(fighthero[10].bingli==0&&warstyle==1)//敌方主将死亡，结束
	{
		GameEnd(1);
		return -2;
	}
	//如果为守方则需增加城池被占领后失败。
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	int xx=fighthero[atnowhero].positionx;
	int yy=fighthero[atnowhero].positiony;
	if(fightmap.tilestyle[xx][yy]==5&&warstyle==0)//我方占领敌方城池，攻击战
	{
		GameEnd(1);
		return -2;
	}
	//20150516增加去除第一回合移动武将时出现提示我方战斗失败
	if(atnowheroat==0) 
	{
		return 0;
	}
	xx=fighthero[atnowheroat].positionx;
	yy=fighthero[atnowheroat].positiony;
	if(fightmap.tilestyle[xx][yy]==5&&warstyle==1)//敌方占领我方城池，防御战
	{
		GameEnd(0);
		return -1;
	}
	return 0;
}

int Fight::AIRun()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	for(int i=10;i<heronumberto+10;i++)
	{
		//0:正常1:混乱2"禁咒3:"定身 4"奇门5遁甲"6石阵7:潜踪
		if(fighthero[i].statue==0)
		{
			atnowheroat=i;

			//移动该武将
			AIMoveHero();
			//物理攻击
			int rt1=AIAtEnable();
			int rt2=0;
			if(rt1==0)
			{
				rt2=AISkillEnable();//技能攻击
			}
			if(rt1==0&&rt2==0)
			{
				//仍没目标，休息
				AISleepyHero();
			}
			if(TestWinLose()==-1)return -1;
		}
	}
	return 0;
}

void Fight::AISleepyHero()//休息，加体力
{
	wlogfile(1,__FUNCTION__,"开始",0);
	//fighthero[atnowheroat].tili+=1;
	return;
}

void Fight::AIShowMoveArrange()//显示移动范围
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	int xx=fighthero[atnowheroat].positionx;
	int yy=fighthero[atnowheroat].positiony;

	//根据arrive[]显示范围，需固定中心位置
	int tyx=xx-2;
	int tyy=yy-4;
	if(tyx<0)tyx=0;
	if(tyy<0)tyy=0;
	for(int i=0;i<MAPMAX;i++)		
	{
		for(int j=0;j<MAPMAX;j++)
		{
			if(i>=tyx&&i<(tyx+5)&&j>=tyy&&j<(tyy+10)&&arrow[i][j]==1)
			{
				int yyy=i-tyx;
				int xxx=j-tyy;
				ShowCGAdd(0,"Res\\Fight\\stepcross.sbp","Res\\Fight\\stepcrossmask.sbp",xxx*80,yyy*80);
				BitBlt(hdc, 0, 0, 800, 600, hdcTmp, 0, 0, SRCCOPY);

			}

		}
	}
}

void Fight::AIMoveHero()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	int xx=fighthero[atnowheroat].positionx;
	int yy=fighthero[atnowheroat].positiony;
	SetArrive(xx,yy,atnowheroat);

	if(atnowheroat==10&&warstyle==0)//若当前将领是太守，不进行移动
		return;

	// 获取移动的目标点
	int ox = fighthero[atnowheroat].positionx;
	int oy = fighthero[atnowheroat].positiony;
	int ax = fighthero[0].positionx;
	int ay = fighthero[0].positiony;
	int bx=ox;
	int by=oy;
	int pathmin = 255;//路径最短值
	hurtmax = 0;//伤害最大值
	int delta = abs(ox-ax)+abs(oy-ay);
	//ax = ox;
	//ay = oy;
	for(int i=0;i<MAPMAX;i++)
	{
		for(int j=0;j<MAPMAX;j++)
		{	

			// 若电脑为进攻模式，且能进入城池，利马儿执行
			if(fightmap.tilestyle[i][j]==5&&warstyle==1&&arrow[i][j]==1)
			{
				bx = i;
				by = j;

				goto xs;
			}
			else if(arrow[i][j]==1)
			{			
				int mark[10];
				int marknum=0;
				for(int it=0;it<10;it++)
				{
					mark[it]=0;
				}
				// 取伤害最大或距离目标点最近，或有防御加层但有攻击目标的地形优先考虑 
				SetAt(i,j,atnowheroat);


				for(int ii=0;ii<heronumber;ii++)
				{
					OverflowCheck(__FILE__,__LINE__,20,ii);
					int posx=fighthero[ii].positionx;
					int posy=fighthero[ii].positiony;
					if(atarr[posx][posy]==1&&fighthero[ii].statue!=8)
					{
						mark[marknum]=ii;
						marknum++;
					}
				}
				if(marknum==0)
				{
					;
				}
				else//存在目标
				{
					for(int ij=0;ij<marknum;ij++)
					{
						AIGetAtDf(ox,oy,i,j,mark[ij]);
						int hurtret=AICountAtHurtBefore(mark[ij]);//获取最大伤害
						if (hurtret>hurtmax&&arrow[i][j]==1)
						{
							hurtmax=hurtret;
							bx=i;
							by=j;

						}
						else if(hurtret==hurtmax&&arrow[i][j]==1)
						{
							if(fightmap.tilestyle[i][j]>=2&&fightmap.tilestyle[i][j]<=6)
							{
								bx=i;
								by=j;
							}
						}
					}
				}


				// 决定是否更新移动目标点 		
				if(hurtmax==0)
				{	// 没有能造成伤害的情况下，以趋近目标优先移动 
					delta = abs(i-ax)+abs(j-ay);
					if(pathmin > delta)//趋近目标移动 
					{
						bx=i;
						by=j;
						pathmin=delta;
					}
					else if(pathmin == delta)// 有距离相同的点，随机更新 
					{
						int flagnew = rand() % 10;
						if(flagnew)
						{
							bx=i;
							by=j;
						}
					}
					else
					{

					}
				}
			}
		}
	}

xs:

	if(menumove1==0)//不观看敌军移动
	{
		OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
		fighthero[atnowheroat].positionx=bx;
		fighthero[atnowheroat].positiony=by;
		return;
	}

	//显示之前武将的位置，在屏幕中间
	//fighthero[atnowheroat].positionx;
	//ShowBar();
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	int tyx=fighthero[atnowheroat].positionx-2;
	int tyy=fighthero[atnowheroat].positiony-4;

	//20150517修正显示敌方移动出界显示的BUG
	if(tyx<0)tyx = 0;
	if(tyy<0)tyy = 0;
	if(tyx>26)tyx = 26;
	if(tyy>22)tyy = 22;

	fightmap.ShowMove(tyx,tyy);//以敌方主将为中心显示

	AIShowMoveArrange();
	for(int y=0;y<heronumber;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示wo方武将
		}

	}
	for(int y=10;y<heronumberto+10;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示敌方武将
		}

	}//显示敌方武将

	char str[20];
	//显示武将名字
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	OverflowCheck(__FILE__,__LINE__,HEROMAX,fighthero[atnowheroat].num);
	sprintf_s(str,"%s",t_heroName[fighthero[atnowheroat].num]);

	//ShowText("          ",390,460,60);
	ShowCG(0,"Res\\Fight\\fight_statue.sbp",0,400);
	ShowWeatherBar();
	char str1[20];
	int foods1=0;
	if(foods>999)
	{
		foods1=foods%1000;
	}
	else
	{
		foods1=foods;
	}
	sprintf_s(str1,"%d",foods1);
	ShowText(str1,60,460,60);

	ShowText(str,390,460,60);
	//ShowWeatherBar();
	BitBlt(hdc, 0, 0, 800, 600, hdcTmp, 0, 0, SRCCOPY);

	Delay(200+800*menuspeed1);
	//Delay(5000);
	//显示更新后武将位置，在屏幕中间，通过移动背景？直接显示
	fighthero[atnowheroat].positionx=bx;
	fighthero[atnowheroat].positiony=by;


	tyx=fighthero[atnowheroat].positionx-2;
	tyy=fighthero[atnowheroat].positiony-4;
	//20170805修正显示敌方移动出界显示的BUG
	if(tyx<0)tyx = 0;
	if(tyy<0)tyy = 0;
	if(tyx>26)tyx = 26;
	if(tyy>22)tyy = 22;

	fightmap.ShowMove(tyx,tyy);//以敌方主将为中心显示

	for(int y=0;y<heronumber;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示wo方武将
		}

	}
	for(int y=10;y<heronumberto+10;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示敌方武将
		}

	}//显示敌方武将
	ShowText(str,390,460,60);
	BitBlt(hdc, 0, 0, 800, 600, hdcTmp, 0, 0, SRCCOPY);
	Delay(200+800*menuspeed1);		
	//Delay(5000);	

}
int Fight::AIAtEnable()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	// 搜索目标（范围），确定施展对象
	if(AIGetRange(0,0)==0)
		return 0;
	// 产生攻击的命令
	AICountAtHurt();
	return 1;
}
int Fight::AISkillEnable()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	fighthero[atnowheroat].GetMenuSkill();
	int rnd=rand();
	// 智力越高的，施展技能的可能性越高
	if(rnd%150>fighthero[atnowheroat].zili)
		return 0;
	// 兵力剩余越少，施展技能的可能性越高(玄兵除外) 
	if(fighthero[atnowheroat].style!=6)//不是玄兵
	{
		int arms =(fighthero[atnowheroat].wuli +fighthero[atnowheroat].zili) * 10 +fighthero[atnowheroat].degree * 100;
		arms+=arms>>1;
		if(rand()%arms<fighthero[atnowheroat].bingli)
			return 0;
	}
	// 获取要施展的技能
	int id=rand()%useableskillnum2;
	// 自己是否符合施展的条件

	id=fighthero[atnowheroat].skillno[id];

	if(AICanUseSkill(id)==0)//1-可以用
		return 0;
	// 搜索目标（范围），确定施展对象
	if(AIGetRange(1,id)==0)
		return 0;
	//施展
	if(id == 15 || id == 19)
	{
		;
	}
	else
	{	// 施展计谋成功
		AICountSkillHurt(id);
		//显示计谋；
		//Show();
		return 1;
	}
	return 0;
}

int Fight::AIGetRange(int type ,int id)//攻击0还是技能1 技能序号
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	int xx=fighthero[atnowheroat].positionx;
	int yy=fighthero[atnowheroat].positiony;
	int mark[10];
	int marknum;
	if(type==0)
	{
		SetAt(xx,yy,atnowheroat);
		marknum=0;
		for(int i=0;i<10;i++)
		{
			mark[i]=0;
		}
		for(int i=0;i<heronumber;i++)
		{
			OverflowCheck(__FILE__,__LINE__,20,i);
			int posx=fighthero[i].positionx;
			int posy=fighthero[i].positiony;
			if(atarr[posx][posy]==1&&fighthero[i].statue!=8)
			{
				mark[marknum]=i;
				marknum++;
			}
		}
		if(marknum==0)
		{
			return 0;
		}
		else if(marknum==1)//找到唯一可攻击对象
		{
			aimat=mark[marknum-1];
			return 1;
		}
		else//找到多个
		{
			int hurtmax=0;
			aimat=mark[0];
			for(int ii=0;ii<marknum;ii++)
			{
				if(mark[ii]==0&&fighthero[0].statue!=8)//攻击主将
				{
					aimat=mark[ii];
					return 1;
				}
			}
			for(int ii=0;ii<marknum;ii++)
			{
				OverflowCheck(__FILE__,__LINE__,20,mark[ii]);
				OverflowCheck(__FILE__,__LINE__,10,ii);
				int ui=fighthero[mark[ii]].positionx;
				int uj=fighthero[mark[ii]].positiony;
				AIGetAtDf(xx,yy,ui,uj,mark[ii]);
				int hurtcurrent=AICountAtHurtBefore(mark[ii]);//获取最大伤害
				if (hurtcurrent>hurtmax)
				{
					hurtmax=hurtcurrent;
					aimat=mark[ii];
				}
			}
			return 1;
		}
	}
	else
	{
		SetAtSkill(xx,yy,atnowheroat,id);
		marknum=0;
		for(int i=0;i<10;i++)
		{
			mark[i]=0;
		}
		for(int i=0;i<heronumber;i++)
		{
			int posx=fighthero[i].positionx;
			int posy=fighthero[i].positiony;
			if(skillarr[posx][posy]==1&&fighthero[i].statue!=8)
			{
				mark[marknum]=i;
				marknum++;
			}
		}
		if(marknum==0)
		{
			return 0;
		}
		else if(marknum==1)//找到唯一可攻击对象
		{
			
			aimat=mark[marknum];
			return 1;
		}
		else//找到多个
		{
			OverflowCheck(__FILE__,__LINE__,10,marknum);
			hurtmax=0;
			aimat=mark[0];
			for(int ii=0;ii<marknum;ii++)
			{
				if(mark[ii]==0&&fighthero[0].statue!=8)//攻击主将
				{
					aimat=mark[marknum];
					return 1;
				}
			}
			for(int ii=0;ii<marknum;ii++)
			{
				int hurtcurrent=AICountSkillHurtBefore(mark[ii],id);//获取最大伤害
				if (hurtcurrent>hurtmax)
				{
					hurtmax=hurtcurrent;
					aimat=mark[ii];
				}
			}
			return 1;
		}
	}
	return 0;
}

int Fight::AICountAtHurtBefore(int tpheroat)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	/*const double SubduModu[6][6] = {
	{1.0,1.2,0.8,1.0,0.7,1.3},{0.8,1.0,1.2,1.0,0.6,1.2},{1.2,0.8,1.0,1.0,1.1,1.2},
	{1.0,1.0,1.0,1.0,1.0,1.0},{1.1,1.3,0.9,1.0,1.0,1.5},{0.6,0.6,0.6,0.6,0.6,0.6}};*/

	int	hurt;
	int savehero=atnowhero;

	atnowhero=atnowheroat;
	GetLifeSkillAtDf();
	int at=fighthero[atnowhero].at;
	int bingli=fighthero[atnowhero].bingli;

	atnowhero=tpheroat;
	GetLifeSkillAtDf();
	int df=fighthero[atnowhero].df;
	atnowhero=savehero;

	// 基本伤害 hurt = (at / df) * arms / 8 
	hurt = (at / df )* (bingli >> 3);
	// 相克加层 hurt *= modu 
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	OverflowCheck(__FILE__,__LINE__,20,tpheroat);
	int txp=fighthero[atnowheroat].style;
	int typ=fighthero[tpheroat].style;
	hurt = (int)(((double)hurt) * SubduModu[txp][typ]);
	hurt+=10;
	return hurt;
}

int Fight::AICountSkillHurtBefore(int tpheroat,int id)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int hurt=0;
	int compare=id;
	int under0;//我方地形
	int under1;//敌方地形
	//weather-1，天气
	OverflowCheck(__FILE__,__LINE__,20,tpheroat);
	int styleto=fighthero[tpheroat].style;//敌人兵种

	if((compare!=6&&compare<=11)||compare==16||compare==17)
	{
		OverflowCheck(__FILE__,__LINE__,20,tpheroat);
		OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
		int tx=fighthero[atnowheroat].positionx;
		int ty=fighthero[atnowheroat].positiony;
		under0=fightmap.tilestyle[tx][ty];

		int wx=fighthero[tpheroat].positionx;
		int wy=fighthero[tpheroat].positiony;
		under1=fightmap.tilestyle[wx][wy];

		OverflowCheck(__FILE__,__LINE__,SKILLMAX,compare);
		hurt=skilltp[compare][2];
		OverflowCheck(__FILE__,__LINE__,SKILLLEN,4+weather);
		hurt=hurt*skilltp[compare][4+weather]/100;
		OverflowCheck(__FILE__,__LINE__,SKILLLEN,10+under0);
		hurt=hurt*skilltp[compare][10+under0]/100;
		if(hurt==0)	//我方地形错误
		{
			//地形错误
			return -1;
		}
		OverflowCheck(__FILE__,__LINE__,SKILLLEN,18+under1);
		hurt=hurt*skilltp[compare][18+under1]/100;
		if(hurt==0)	//敌方地形错误
		{
			//地形错误
			return -1;
		}
		OverflowCheck(__FILE__,__LINE__,SKILLLEN,26+styleto);
		hurt=hurt*skilltp[compare][26+styleto]/100;
		if(hurt==0)	//目标兵种错误	
		{
			//命令无效
			return -1;
		}
		return hurt;
	}

	return -1;
}

void Fight::AICountAtHurt()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	/*const double SubduModu[6][6] = {
	{1.0,1.2,0.8,1.0,0.7,1.3},{0.8,1.0,1.2,1.0,0.6,1.2},{1.2,0.8,1.0,1.0,1.1,1.2},
	{1.0,1.0,1.0,1.0,1.0,1.0},{1.1,1.3,0.9,1.0,1.0,1.5},{0.6,0.6,0.6,0.6,0.6,0.6}};*/

	double d_hurt = 0.0;
	int hurt = 0;
	int savehero=atnowhero;

	atnowhero=atnowheroat;
	GetLifeSkillAtDf();
	OverflowCheck(__FILE__,__LINE__,20,atnowhero);
	int at=fighthero[atnowhero].at;
	int bingli=fighthero[atnowhero].bingli;

	atnowhero=aimat;
	GetLifeSkillAtDf();
	int df=fighthero[atnowhero].df;
	atnowhero=savehero;


	// 基本伤害 hurt = (at / df) * arms / 8 
	d_hurt = (double)( at) /  df * (bingli >> 3);
	// 相克加层 hurt *= modu 
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	int txp=fighthero[atnowheroat].style;
	OverflowCheck(__FILE__,__LINE__,20,aimat);
	int typ=fighthero[aimat].style;

	
	/* 相克加层 hurt *= modu */
	d_hurt *= SubduModu[txp][typ];
	hurt = (int)d_hurt;
	hurt += 10;
	fighthero[aimat].bingli-=hurt;
	allbingli-=hurt;
	//flagshowhurt=hurt;
	if(fighthero[aimat].bingli<0)
	{
		fighthero[aimat].bingli+=hurt;
		allbingli+=hurt;
		hurt=fighthero[aimat].bingli;
		fighthero[aimat].bingli-=hurt;
		allbingli-=hurt;
	}
	ex=GetExp(hurt);
	fighthero[atnowheroat].experience+=ex;
	AIShowArrowAt(aimat);
	AIShowAtHurt(hurt,ex,aimat);
	if(fighthero[aimat].bingli<=0)
	{
		//死亡
		AIShowDeath(aimat);
		fighthero[aimat].statue=8;
		fighthero[aimat].bingli=0;

	}
	if(fighthero[atnowheroat].experience>=100)
	{
		//升级
		AIShowLevelUp();
		fighthero[atnowheroat].experience-=100;
		fighthero[atnowheroat].degree++;
		if(fighthero[atnowheroat].degree>20)
			fighthero[atnowheroat].degree=20;
		int health = (fighthero[atnowheroat].wuli * 80 / 100 + fighthero[atnowheroat].zili * 30 / 100 +fighthero[atnowheroat].degree) * fighthero[atnowheroat].tili/ 100;
		if(health<0)health=0;
		fighthero[atnowhero].health=health;
		int skill = (fighthero[atnowheroat].zili * 80 / 100 + (PlcExtract(fighthero[atnowheroat].wuli) >> 1) +fighthero[atnowheroat].degree) * fighthero[atnowheroat].tili/ 100;
		if(skill<0)skill=0;	
		fighthero[atnowheroat].skill=skill;

	}
}

int Fight::AICountSkillHurt(int id)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	int	hurt=hurtmax;
	ex=GetExp(hurt);
	OverflowCheck(__FILE__,__LINE__,20,aimat);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	if(fighthero[aimat].bingli>=hurt)
	{
		fighthero[aimat].bingli-=hurt;
		allbingli-=hurt;
	}
	else
	{
		hurt=fighthero[aimat].bingli;
		fighthero[aimat].bingli=0;
		allbingli-=hurt;
	}
	//flagshowskillhurt=hurt;
	fighthero[atnowheroat].experience+=ex;
	AIShowSkillHurt(hurt,ex,id,aimat);
	if(fighthero[aimat].bingli<=0)
	{
		//死亡
		AIShowDeath(aimat);
		fighthero[aimat].statue=8;
		fighthero[aimat].bingli=0;

	}
	if(fighthero[atnowheroat].experience>=100)
	{
		//升级
		AIShowLevelUp();
		fighthero[atnowheroat].experience-=100;
		fighthero[atnowheroat].degree++;
		if(fighthero[atnowheroat].degree>20)
			fighthero[atnowheroat].degree=20;
		int health = (fighthero[atnowheroat].wuli * 80 / 100 + fighthero[atnowheroat].zili * 30 / 100 +fighthero[atnowheroat].degree) * fighthero[atnowheroat].tili/ 100;
		if(health<0)health=0;
		fighthero[atnowhero].health=health;
		int skill = (fighthero[atnowheroat].zili * 80 / 100 + (PlcExtract(fighthero[atnowheroat].wuli) >> 1) +fighthero[atnowheroat].degree) * fighthero[atnowheroat].tili/ 100;
		if(skill<0)skill=0;	
		fighthero[atnowheroat].skill=skill;

	}
	return 0;
}

int Fight::AICanUseSkill(int x)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	if(WeatherOK(x)&&AILandOK(x)&&AISkillOK(x))
		return 1;
	return 0;
}

int Fight::AILandOK(int x)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	int tx=fighthero[atnowheroat].positionx;
	int ty=fighthero[atnowheroat].positiony;
	switch(x)//在山地使用 1 2
	{
	case LOGROLLING:	
	case ROCKFALL:
		if(fightmap.tile[tx][ty]>=6&&fightmap.tile[tx][ty]<=15)
			return 0;
	}

	return 1;
}

int Fight::AISkillOK(int x)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	switch(x)//0-21 23
	{
	case WEATHERCHANGE:
		if(fighthero[atnowheroat].skill<10)
			return 0;
		break;
	case FIREATTACK:	
	case FLYARROW:
	case TRAMPLE:
	case FLOODING:
	case CURSESEAL:
	case REINFORCEMENTS:
	case SPY:
		if(fighthero[atnowheroat].skill<15)
			return 0;
		break;
	case LOGROLLING:	
	case ARROWRAIN:
	case CHARGE:
	case IMMOBILIZED:
	case GOSSIP:
	case STONEHENGE:
	case INVISIBLEMAGIC:
		if(fighthero[atnowheroat].skill<20)
			return 0;
		break;
	case ROCKFALL:	
	case ASSAULT:
	case FIREARROW:	
	case SUDDENSTRIKE:
		if(fighthero[atnowheroat].skill<25)
			return 0;
		break;
	case FIGHTBRAVELY:	
	case IMPACT:
	case LARGEFIRE:	
	case TSUNAMI:
	case LARGEREINFORCEMENTS:	
	case SIEGE:
		if(fighthero[atnowheroat].skill<30)
			return 0;
		break;

	}
	return 1;
}

void Fight::AIShowAtHurt(int hurt,int exp,int tpheroat)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,tpheroat);
	if(hurt==0)return;
	if(menushow1==0)
	{
		char str[20];
		int tyx=fighthero[tpheroat].positionx-2;
		int tyy=fighthero[tpheroat].positiony-4;
		if(tyx<0)tyx=0;
		if(tyy<0)tyy=0;
		int xx=fighthero[tpheroat].positionx-tyx;
		int yy=fighthero[tpheroat].positiony-tyy;
		sprintf_s(str,"-%d",hurt);
		ShowTextDirect(str,4*80 ,2*80+50 ,50);
		Delay(1000);
		return ;
	}

	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	OverflowCheck(__FILE__,__LINE__,20,aimat);

	int herostyle=fighthero[atnowheroat].style;
	int herostyleto=fighthero[aimat].style;
	//herostyle=3;
	int i;
	
	if(fightmap.tilestyle[fighthero[aimat].positionx][fighthero[aimat].positiony]==7)//水中攻击
	{
		for(i=0;i<4;i++)
		{
			LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);

			LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
			oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 120, 150, 215, 205, hdcMem, 0, 1230, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);	
			if(i==1)
			{
				LoadPic("Res\\Fight\\arrow1.sbp",hbmp);	//箭
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	
			}
			if(i==2)
			{
				LoadPic("Res\\Fight\\arrow2.sbp",hbmp);	//箭
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);
				DeleteObject(hbmp);	
			}
			LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
			oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 0, 1290, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);
			DeleteObject(hbmp);	

			BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
			Delay(50);

		}
	}
	else
	{
		switch(herostyle)
		{
		case CAVALRY://骑兵
		case GREATHPARM://极兵
			for(i=0;i<7;i++)
			{
				LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

				LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 120+i*35, 150, 215, 205, hdcMem, 215*i, herostyle*205, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

				LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/6), 215*herostyleto, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

				BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
				Delay(50);

			}
			break;
		case INFANTRY://步兵

			for(i=0;i<4;i++)
			{
				LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

				LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 120+i*70, 150, 215, 205, hdcMem, 215*i, 205, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

				LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/3), 215*herostyleto, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

				BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
				Delay(50);

			}
			break;
		case ARCHER://弓兵

			for(i=0;i<4;i++)
			{
				LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

				LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 120, 150, 215, 205, hdcMem, 215*i, 410, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	
				if(i==1)
				{
					LoadPic("Res\\Fight\\arrow1.sbp",hbmp);	//箭
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	
				}
				if(i==2)
				{
					LoadPic("Res\\Fight\\arrow2.sbp",hbmp);	//箭
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	
				}
				LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/3), 215*herostyleto, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

				BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
				Delay(50);

			}
			break;
		case SAILOR://水兵
		case GREATMPARM://玄兵
			for(i=0;i<6;i++)
			{
				LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
				HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

				LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 120+i*42, 150, 215, 205, hdcMem, 215*i, herostyle*205, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

				LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
				oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
				BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/5), 215*herostyleto, SRCCOPY);
				SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

				BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
				Delay(50);

			}
			break;
		}
	}
	//hurt=8888;
	char str[10];
	if(hurt<10)//20150920增加小于10判断
	{
		int hurt0=hurt;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);	
	}
	else if(hurt<100)
	{
		int hurt0=hurt/10;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);
		Delay(100);
		int hurt1=hurt-hurt0*10;
		sprintf_s(str,"%d",hurt1);
		ShowTextDirectWithColor(str,350,200,100);

	}
	else if(hurt<1000)
	{
		int hurt0=hurt/100;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);
		Delay(100);
		int hurt1=hurt-hurt0*100;
		hurt1=hurt1/10;
		sprintf_s(str,"%d",hurt1);
		ShowTextDirectWithColor(str,350,200,100);
		Delay(100);
		int hurt2=hurt-hurt0*100-hurt1*10;
		sprintf_s(str,"%d",hurt2);
		ShowTextDirectWithColor(str,400,200,100);
	}
	else
	{
		int hurt0=hurt/1000;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);
		Delay(100);
		int hurt1=hurt-hurt0*1000;
		hurt1=hurt1/100;
		sprintf_s(str,"%d",hurt1);
		ShowTextDirectWithColor(str,350,200,100);
		Delay(100);
		int hurt2=hurt-hurt0*1000-hurt1*100;
		hurt2=hurt2/10;
		sprintf_s(str,"%d",hurt2);
		ShowTextDirectWithColor(str,400,200,100);
		Delay(100);
		int hurt3=hurt-hurt0*1000-hurt1*100-hurt2*10;
		sprintf_s(str,"%d",hurt3);
		ShowTextDirectWithColor(str,450,200,100);
	}

	Delay(1000);

}

void Fight::AIShowSkillHurt(int hurt,int exp,int id,int tpheroat)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,tpheroat);
	if(hurt==0)return;
	if(menushow1==0)
	{
		char str[20];
		int compare1=id;
		LoadPic("Res\\Fight\\fight_messagekuang.sbp",hbmp);	// 背景图
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, 105, 55, 590,110, hdcMem, 0, 0, SRCCOPY);
		SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);
		sprintf_s(str,"%s",t_skillName[compare1]);

		ShowTextDirect(str,200,85,50);
		ShowTextDirect(GetStrText("dFgtArmsH"),400,85,50);
		sprintf_s(str,"-%d",hurt);
		int tyx=fighthero[tpheroat].positionx-2;
		int tyy=fighthero[tpheroat].positiony-4;
		if(tyx<0)tyx=0;
		if(tyy<0)tyy=0;
		int xx=fighthero[tpheroat].positionx-tyx;
		int yy=fighthero[tpheroat].positiony-tyy;
		ShowTextDirect(str,xx*80 ,yy*80 ,50);//需调整
		Delay(1000);
		return ;
	}

	int herostyle=fighthero[atnowheroat].style;
	int herostyleto=fighthero[aimat].style;
	int compare=id;
	int i;
	switch(compare)
	{
	case FIREATTACK://火攻
	case FIREARROW://火箭
		for(i=0;i<6;i++)
		{
			LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 0, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

			BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
			Delay(200);

		}
		break;
	case LOGROLLING://滚木1
	case ROCKFALL://落石2

		for(i=0;i<6;i++)
		{
			LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 320, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

			BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
			Delay(100);

		}
		break;
	case FLOODING://水淹
	case TSUNAMI://海啸
		for(i=0;i<6;i++)
		{
			LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 640, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

			BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
			Delay(100);

		}
		break;
	case IMPACT://撞击
		for(i=0;i<6;i++)
		{
			LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 960, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

			BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
			Delay(100);

		}
		break;
	case CURSESEAL://咒封12
	case IMMOBILIZED://定身13
		for(i=0;i<6;i++)
		{
			LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 1280, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

			BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
			Delay(100);

		}
		break;
	case GOSSIP://留言
		for(i=0;i<6;i++)
		{
			LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 1600, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

			BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
			Delay(100);

		}
		break;
	case REINFORCEMENTS://援军
	case LARGEREINFORCEMENTS://援军
		for(i=0;i<6;i++)
		{
			LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 1920, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

			BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
			Delay(100);

		}
		break;
	case STONEHENGE://石阵
		for(i=0;i<6;i++)
		{
			LoadPic("Res\\Fight\\fight_skill.sbp",hbmp);
			HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
			BitBlt(hdcTmp, 200, 80, 330,320, hdcMem, (i%2)*330, 2240, SRCCOPY);
			SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

			BitBlt(hdc,200,80, 330,320, hdcTmp, 200, 80, SRCCOPY);
			Delay(100);

		}
		break;
		/*奋战3
		飞矢4 兵力减少
		箭雨5 兵力减少
		践踏7 兵力减少
		冲锋8
		突击9*/
	case FIGHTBRAVELY:
	case FLYARROW:
	case ARROWRAIN:
	case TRAMPLE:
	case CHARGE:
	case ASSAULT:
		{
			int i;
			switch(herostyle)
			{
			case CAVALRY://骑兵
			case GREATHPARM://极兵
				for(i=0;i<7;i++)
				{
					LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
					HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

					LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 120+i*35, 150, 215, 205, hdcMem, 215*i, herostyle*205, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

					LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/6), 215*herostyleto, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

					BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
					Delay(50);

				}
				break;
			case INFANTRY://步兵

				for(i=0;i<4;i++)
				{
					LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
					HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

					LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 120+i*70, 150, 215, 205, hdcMem, 215*i, 205, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

					LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/3), 215*herostyleto, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

					BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
					Delay(50);

				}
				break;
			case ARCHER://弓兵

				for(i=0;i<4;i++)
				{
					LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
					HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

					LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 120, 150, 215, 205, hdcMem, 215*i, 410, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	
					if(i==1)
					{
						LoadPic("Res\\Fight\\arrow1.sbp",hbmp);	//箭
						oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	
					}
					if(i==2)
					{
						LoadPic("Res\\Fight\\arrow2.sbp",hbmp);	//箭
						oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
						BitBlt(hdcTmp, 270+i*70, 150, 45, 25, hdcMem, 0, 0, SRCCOPY);
						SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	
					}
					LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/3), 215*herostyleto, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

					BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
					Delay(50);

				}
				break;
			case SAILOR://水兵
			case GREATMPARM://玄兵
				for(i=0;i<6;i++)
				{
					LoadPic("Res\\Fight\\SpeBack.sbp",hbmp);	// 背景图
					HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 75, 80, 650,320, hdcMem, 0, 0, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

					LoadPic("Res\\Fight\\fight_left.sbp",hbmp);	//攻方
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 120+i*42, 150, 215, 205, hdcMem, 215*i, herostyle*205, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

					LoadPic("Res\\Fight\\fight_right.sbp",hbmp);	//守方
					oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
					BitBlt(hdcTmp, 500, 150, 190, 215, hdcMem, 190*(int)(i/5), 215*herostyleto, SRCCOPY);
					SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);	

					BitBlt(hdc,75,80, 650,320, hdcTmp, 75, 80, SRCCOPY);
					Delay(50);

				}
				break;
			}
		}
		break;
		//case 
		/*
		烈火16
		奇门18
		围攻20
		突袭21*/
		//break;
	}

	//hurt=8888;
	ShowTextDirectWithColor(GetStrText("dFgtArmsH"),250,100,60);
	char str[10];
	if(hurt<10)//20150920增加小于10判断
	{
		int hurt0=hurt;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);	
	}
	else if(hurt<100)
	{
		int hurt0=hurt/10;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);
		Delay(100);
		int hurt1=hurt-hurt0*10;
		sprintf_s(str,"%d",hurt1);
		ShowTextDirectWithColor(str,350,200,100);

	}
	else if(hurt<1000)
	{
		int hurt0=hurt/100;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);
		Delay(100);
		int hurt1=hurt-hurt0*100;
		hurt1=hurt1/10;
		sprintf_s(str,"%d",hurt1);
		ShowTextDirectWithColor(str,350,200,100);
		Delay(100);
		int hurt2=hurt-hurt0*100-hurt1*10;
		sprintf_s(str,"%d",hurt2);
		ShowTextDirectWithColor(str,400,200,100);
	}
	else
	{
		int hurt0=hurt/1000;
		sprintf_s(str,"%d",hurt0);
		ShowTextDirectWithColor(str,300,200,100);
		Delay(100);
		int hurt1=hurt-hurt0*1000;
		hurt1=hurt1/100;
		sprintf_s(str,"%d",hurt1);
		ShowTextDirectWithColor(str,350,200,100);
		Delay(100);
		int hurt2=hurt-hurt0*1000-hurt1*100;
		hurt2=hurt2/10;
		sprintf_s(str,"%d",hurt2);
		ShowTextDirectWithColor(str,400,200,100);
		Delay(100);
		int hurt3=hurt-hurt0*1000-hurt1*100-hurt2*10;
		sprintf_s(str,"%d",hurt3);
		ShowTextDirectWithColor(str,450,200,100);
	}
	Delay(1000);
}

void Fight::AIGetAtDf(int ox,int oy,int xx,int yy,int tpheroat)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	OverflowCheck(__FILE__,__LINE__,20,tpheroat);
	int at=fighthero[atnowheroat].at;
	int df=fighthero[atnowheroat].df;
	int tili=fighthero[atnowheroat].tili;

	int at1=fighthero[tpheroat].at;
	int df1=fighthero[tpheroat].df;
	int tili1=fighthero[tpheroat].tili;



	/*double atfact[8][6]={
	1,0.8,0.9,0.4,1.3,0.4,
	1,0.8,0.9,0.4,1.3,0.4,
	0.25,0.8,0.9,0.1,1.3,0.4,
	0.5,0.8,0.9,0.2,1.3,0.4,
	1.0,0.8,0.9,0.4,1.3,0.4,
	1.0,0.8,0.9,0.4,1.3,0.4,
	1.0,0.8,0.9,0.4,1.3,0.4,
	0.125,0.2,0.225,0.8,1.3,0.4};
	double dffact[8][6]={
	0.7,1.2,1,0.55,1.2,0.6,
	0.7,1.2,1,0.55,1.2,0.6,
	0.2275,1.56,1.3,0.17875,1.56,0.78,
	0.4025,1.38,1.15,0.31625,1.38,0.69,
	0.77,1.32,1.1,0.605,1.32,0.66,
	1.05,1.8,1.5,0.825,1.8,0.9,
	0.84,1.44,1.2,0.66,1.44,0.72,
	0.07,0.24,0.3,0.88,0.96,0.48};*/
	int tile=fightmap.tile[ox][oy];
	int tile1;
	if(tile==1||tile==2)
	{
		tile1=0;
	}
	if(tile==3)
	{
		tile1=5;
	}
	if(tile==4)
	{
		tile1=4;
	}
	if(tile==5)
	{
		tile1=3;
	}
	if(tile>=6&&tile<=15)
	{
		tile1=2;
	}
	if(tile>=16&&tile<=45&&tile!=41)
	{
		tile1=7;
	}
	if(tile==41)
	{
		tile1=6;
	}

	at=(int)(((double)fighthero[atnowheroat].wuli)*((double)(10+fighthero[atnowheroat].degree))*atfact[tile1][fighthero[atnowheroat].style]);
	df=(int)(((double)fighthero[atnowheroat].zili)*((double)(10+fighthero[atnowheroat].degree))*dffact[tile1][fighthero[atnowheroat].style]);


	fighthero[atnowheroat].at=at;
	fighthero[atnowheroat].df=df;

	tile=fightmap.tile[xx][yy];
	tile1;
	if(tile==1||tile==2)
	{
		tile1=0;
	}
	if(tile==3)
	{
		tile1=5;
	}
	if(tile==4)
	{
		tile1=4;
	}
	if(tile==5)
	{
		tile1=3;
	}
	if(tile>=6&&tile<=15)
	{
		tile1=2;
	}
	if(tile>=16&&tile<=45&&tile!=41)
	{
		tile1=7;
	}
	if(tile==41)
	{
		tile1=6;
	}

	at1=(int)(((double)fighthero[tpheroat].wuli)*((double)(10+fighthero[tpheroat].degree))*atfact[tile1][fighthero[tpheroat].style]);
	df1=(int)(((double)fighthero[tpheroat].zili)*((double)(10+fighthero[tpheroat].degree))*dffact[tile1][fighthero[tpheroat].style]);


	fighthero[tpheroat].at=at1;
	fighthero[tpheroat].df=df1;

}

void Fight::AIShowLevelUp()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	ShowBar();
	OverflowCheck(__FILE__,__LINE__,20,atnowheroat);
	int tyx=fighthero[atnowheroat].positionx-2;
	int tyy=fighthero[atnowheroat].positiony-4;
	if(tyx<0)tyx=0;
	if(tyy<0)tyy=0;
	//20150920增加下右溢出判断
	if(tyy>26)tyy = 26;
	if(tyx>28)tyx = 28;

	fightmap.ShowMove(tyx,tyy);
	for(int y=0;y<heronumber;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示wo方武将
		}

	}
	for(int y=10;y<heronumberto+10;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示敌方武将
		}

	}//显示敌方武将
	BitBlt(hdc, 0, 0, 800, 600, hdcTmp, 0, 0, SRCCOPY);

	for(int i=0;i<5;i++)
	{
		int xx=fighthero[atnowheroat].positionx-tyx;
		int yy=fighthero[atnowheroat].positiony-tyy;
		LoadPic("Res\\Fight\\sjmask.sbp",hbmp);	
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, yy*80, xx*80+50, 80,80, hdcMem, i*80, 0, SRCPAINT);
		SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

		LoadPic("Res\\Fight\\sj.sbp",hbmp);	
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, yy*80, xx*80+50, 80,80, hdcMem, i*80, 0, SRCAND);
		SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

		Delay(300);
	}
	ShowInformation(ENEMYLEVELUP,0);
	return;
}


void Fight::AIShowDeath(int tpheroat)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,tpheroat);
	ShowBar();
	int tyx=fighthero[tpheroat].positionx-2;
	int tyy=fighthero[tpheroat].positiony-4;
	if(tyx<0)tyx=0;
	if(tyy<0)tyy=0;
	//20150920增加下右溢出判断
	if(tyy>26)tyy = 26;
	if(tyx>28)tyx = 28;

	fightmap.ShowMove(tyx,tyy);
	for(int y=0;y<heronumber;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示wo方武将
		}

	}
	for(int y=10;y<heronumberto+10;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示敌方武将
		}

	}//显示敌方武将
	BitBlt(hdc, 0, 0, 800, 600, hdcTmp, 0, 0, SRCCOPY);
	for(int i=0;i<5;i++)
	{
		int xx=fighthero[tpheroat].positionx-tyx;
		int yy=fighthero[tpheroat].positiony-tyy;

		LoadPic("Res\\Fight\\swmask.sbp",hbmp);	
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, yy*80, xx*80+50, 80,80, hdcMem, i*80, 0, SRCPAINT);
		SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

		LoadPic("Res\\Fight\\sw.sbp",hbmp);	
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, yy*80, xx*80+50, 80,80, hdcMem, i*80, 0, SRCAND);
		SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);



		Delay(300);

	}
	ShowInformation(ENEMYDEATH,tpheroat);
	return;
}

void Fight::AIShowArrowAt(int tpheroat)
{
	wlogfile(1,__FUNCTION__,"开始",0);
	OverflowCheck(__FILE__,__LINE__,20,tpheroat);
	ShowBar();
	int tyx=fighthero[tpheroat].positionx-2;
	int tyy=fighthero[tpheroat].positiony-4;
	if(tyx<0)tyx=0;
	if(tyy<0)tyy=0;
	fightmap.ShowMove(tyx,tyy);
	for(int y=0;y<heronumber;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示wo方武将
		}

	}
	for(int y=10;y<heronumberto+10;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示敌方武将
		}

	}//显示敌方武将
	BitBlt(hdc, 0, 0, 800, 600, hdcTmp, 0, 0, SRCCOPY);

	for(int i=0;i<5;i++)
	{
		int xx=fighthero[tpheroat].positionx-tyx;
		int yy=fighthero[tpheroat].positiony-tyy;

		LoadPic("Res\\Fight\\atshowmask.sbp",hbmp);	
		HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, yy*80, xx*80+50, 80,80, hdcMem, i*80, 0, SRCPAINT);
		SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);

		LoadPic("Res\\Fight\\atshow.sbp",hbmp);	
		oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
		BitBlt(hdc, yy*80, xx*80+50, 80,80, hdcMem, i*80, 0, SRCAND);
		SelectObject(hdcMem, oldhbmp);DeleteObject(hbmp);
		Delay(200);
	}

}

void Fight::CheckForceBefore()
{
	wlogfile(1,__FUNCTION__,"开始",0);
	for(int yu=0;yu<heronumber;yu++)
	{
		OverflowCheck(__FILE__,__LINE__,20,yu);
		if(fighthero[yu].bingli==0)
		{
			AIShowDeath(yu);
			fighthero[yu].statue=8;
		}
	}
	for(int yu=10;yu<heronumberto+10;yu++)
	{
		OverflowCheck(__FILE__,__LINE__,20,yu);
		if(fighthero[yu].bingli==0)
		{
			AIShowDeath(yu);
			fighthero[yu].statue=8;
		}
	}

}

void Fight::ShowHurt2(int x,int hurt)//武将编号 hurt
{
	wlogfile(1,__FUNCTION__,"开始",0);
	ShowBar();
	int tyx=fighthero[x].positionx-2;
	int tyy=fighthero[x].positiony-4;
	if(tyx<0)tyx=0;
	if(tyy<0)tyy=0;
	fightmap.ShowMove(tyx,tyy);
	for(int y=0;y<heronumber;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示wo方武将
		}

	}
	for(int y=10;y<heronumberto+10;y++)
	{
		OverflowCheck(__FILE__,__LINE__,20,y);
		if(fighthero[y].positionx>=tyx&&fighthero[y].positionx<(tyx+5)&&
			fighthero[y].positiony>=tyy&&fighthero[y].positiony<(tyy+10)&&fighthero[y].statue!=8)
		{
			int yy=fighthero[y].positionx-tyx;
			int xx=fighthero[y].positiony-tyy;
			fighthero[y].Show(xx,yy);//显示敌方武将
		}

	}//显示敌方武将
	BitBlt(hdc, 0, 0, 800, 600, hdcTmp, 0, 0, SRCCOPY);
	//Delay(5000);


	char str[20];
	sprintf_s(str,"-%d",hurt);
	ShowTextDirect(str,4*80,2*80+50 ,50);
	Delay(1000);

	LoadPic("Res\\Fight\\fight_messagekuang.sbp",hbmp);	// 背景图
	HBITMAP oldhbmp=(HBITMAP)SelectObject(hdcMem, hbmp);
	BitBlt(hdc, 105, 185, 590,110, hdcMem, 0, 0, SRCCOPY);
	SelectObject(hdcMem, oldhbmp);
	DeleteObject(hbmp);
	return ;
}

int Fight::DelTimeEvent()
{
	timeTemp ++ ;
	if(timeTemp >= 2)timeTemp = 0;

	if(CheckNoFlag() == 1)return 0;
	fightmap.Show(0);//自己主将

	ShowBar();
	//ShowCG(0,"Res\\menu.sbp",FIGHTMENUX,FIGHTMENUY);
	ShowCG(0,"Res\\back.sbp",FIGHTBACKX,FIGHTBACKY);
	ShowCGAdd(0,"Res\\leftarrow.sbp","Res\\leftarrowmask.sbp",FIGHTLEFTARROWX,FIGHTLEFTARROWY);
	ShowCGAdd(0,"Res\\rightarrow.sbp","Res\\rightarrowmask.sbp",FIGHTRIGHTARROWX,FIGHTRIGHTARROWY);
	ShowCGAdd(0,"Res\\uparrow.sbp","Res\\uparrowmask.sbp",FIGHTUPARROWX,FIGHTUPARROWY);
	ShowCGAdd(0,"Res\\downarrow.sbp","Res\\downarrowmask.sbp",FIGHTDOWNARROWX,FIGHTDOWNARROWY);
	if(flagarrowmov)
	{
		for(int i=0;i<MAPMAX;i++)
		{
			for(int j=0;j<MAPMAX;j++)
			{
				if(i>=fightmap.startx&&i<(fightmap.startx+5)&&j>=fightmap.starty&&j<(fightmap.starty+10)&&arrow[i][j]==1)
				{
					int yy=i-fightmap.startx;
					int xx=j-fightmap.starty;
					ShowCGAdd(0,"Res\\Fight\\stepcross.sbp","Res\\Fight\\stepcrossmask.sbp",xx*80,yy*80);
				}

				/*if(arrow[i][j]==1&&i<10&&j<5)
				{

				ShowCGAdd(0,"Res\\Fight\\stepcross.sbp","Res\\Fight\\stepcrossmask.sbp",i*80,j*80);
				}*/
			}
		}
	}
	if(flagarrowat)
	{
		for(int i=0;i<MAPMAX;i++)
		{
			for(int j=0;j<MAPMAX;j++)
			{
				if(i>=fightmap.startx&&i<(fightmap.startx+5)&&j>=fightmap.starty&&j<(fightmap.starty+10)&&atarr[i][j]==1)
				{
					int yy=i-fightmap.startx;
					int xx=j-fightmap.starty;
					ShowCGAdd(0,"Res\\Fight\\stepat.sbp","Res\\Fight\\stepatmask.sbp",xx*80,yy*80);
				}

			}
		}
	}
	if(flagarrowskill)
	{
		for(int i=0;i<MAPMAX;i++)
		{
			for(int j=0;j<MAPMAX;j++)
			{
				if(i>=fightmap.startx&&i<(fightmap.startx+5)&&j>=fightmap.starty&&j<(fightmap.starty+10)&&skillarr[i][j]==1)
				{
					int yy=i-fightmap.startx;
					int xx=j-fightmap.starty;
					ShowCGAdd(0,"Res\\Fight\\stepat.sbp","Res\\Fight\\stepatmask.sbp",xx*80,yy*80);
				}

			}
		}
	}

	if(timeTemp == 0 )//单数时动态武将图像1
	{
		for(int y=0;y<heronumber;y++)
		{
			if(fighthero[y].statue==8)continue;
			if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
				fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
			{

				int yy=fighthero[y].positionx-fightmap.startx;
				int xx=fighthero[y].positiony-fightmap.starty;
				fighthero[y].Show(xx,yy,0);//显示武将
			}

		}
		for(int y=10;y<heronumberto+10;y++)
		{
			if(fighthero[y].statue==8)continue;
			if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
				fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
			{
				int yy=fighthero[y].positionx-fightmap.startx;
				int xx=fighthero[y].positiony-fightmap.starty;
				fighthero[y].Show(xx,yy,0);//显示武将
			}

		}

	}
	else//双数时动态武将图像2
	{
		for(int y=0;y<heronumber;y++)
		{
			if(fighthero[y].statue==8)continue;
			if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
				fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
			{
				int yy=fighthero[y].positionx-fightmap.startx;
				int xx=fighthero[y].positiony-fightmap.starty;
				fighthero[y].Show(xx,yy,1);//显示武将
			}

		}
		for(int y=10;y<heronumberto+10;y++)
		{
			if(fighthero[y].statue==8)continue;
			if(fighthero[y].positionx>=fightmap.startx&&fighthero[y].positionx<(fightmap.startx+5)&&
				fighthero[y].positiony>=fightmap.starty&&fighthero[y].positiony<(fightmap.starty+10))
			{
				int yy=fighthero[y].positionx-fightmap.startx;
				int xx=fighthero[y].positiony-fightmap.starty;
				fighthero[y].Show(xx,yy,1);//显示武将
			}

		}

	}
	fightmap.ShowArrow();
	BitBlt(hdc,0,0,800,600,hdcTmp,0,0,SRCCOPY);
	InvalidateRect(hwnd,NULL,false);
	return 0;
}

int Fight::CheckNoFlag()
{
	if(flagmenu||flagstat||flaggetfoodamount||flagmenuhero||flagarrowmov||flagarrowat||flagshowskill||flagarrowskill||flagmenushow||flagmenumov||flagmenuspeed)
		return 1;
	return 0;
}

int Fight::InitAffact()
{

	ifstream infile("Res\\Fight\\affact.sdt",ios::in);;
	for(int i=0;i<LANDSTYLEMAX;i++)
	{
		for(int j=0;j<HEROTYPEMAX;j++)
		{
			infile>>atfact[i][j];

		}

	}
	for(int i=0;i<LANDSTYLEMAX;i++)
	{
		for(int j=0;j<HEROTYPEMAX;j++)
		{
			infile>>dffact[i][j];

		}

	}
	for(int i=0;i<LANDSTYLEMAX+1;i++)
	{
		for(int j=0;j<HEROTYPEMAX;j++)
		{
			infile>>movecaculate[i][j];

		}

	}
	for(int i=0;i<HEROTYPEMAX;i++)
	{
		for(int j=0;j<HEROTYPEMAX;j++)
		{
			infile>>SubduModu[i][j];

		}

	}
	infile.close();
	return 0;
}

int Fight::InitMapStyle()
{
	int retch=0;
	if(citynumber>=CITYMAX)retch=0;//20161216
	else
	{
		retch = t_citymapnum[citynumber];
	}

	for(int g=0;g<MAPMAX;g++)
	{
		for(int h=0;h<MAPMAX;h++)
		{			
			c_of[g][h] = t_tilestyle[t_tile[retch][g][h]-1];

		}			
	}

	return 0;
}

int Fight::InitSkill()
{

	ifstream infile("Res\\Fight\\skill.sdt",ios::in);;
	for(int i=0;i<SKILLMAX;i++)
	{
		for(int j=0;j<SKILLLEN;j++)
		{
			infile>>skilltp[i][j];
			if(infile.eof()!=0) break;
		}
		if(infile.eof()!=0) break;
	}
	infile.close();
	return 0;
}
