/***********************************************************************
*Copyright (c)2012 , 天际边工作室
*All rights reserved.
**
文件名称：	PublicFun.cpp
*摘要：		公用函数，全局函数头文件
**
*修改历史：
*	版本    日期     作者     改动内容和原因
*   ----------------------------------------------------
*	1.0    2012-10-5  wstjb     基本的功能完成
***********************************************************************/

#pragma once

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <Dbghelp.h>
#include "resource.h" 
#pragma comment(lib,"Dbghelp.lib") 

#define MAINLEFTARROWX 0
#define MAINLEFTARROWY 224
#define MAINRIGHTARROWX 640
#define MAINRIGHTARROWY 224
#define MAINUPARROWX 320
#define MAINUPARROWY 0
#define MAINDOWNARROWX 320
#define MAINDOWNARROWY 448
#define MAINMENUX 690
#define MAINMENUY 420

#define FIGHTLEFTARROWX 0
#define FIGHTLEFTARROWY 185
#define FIGHTRIGHTARROWX 760
#define FIGHTRIGHTARROWY 185
#define FIGHTUPARROWX 380
#define FIGHTUPARROWY 0
#define FIGHTDOWNARROWX 380
#define FIGHTDOWNARROWY 370
#define FIGHTMENUX 590
#define FIGHTMENUY 420
#define FIGHTBACKX 690
#define FIGHTBACKY 420

//24指令
#define RECLAIM		1
#define INVESTMENT	2
#define SEARCH		3
#define GOVERN		4
#define TOUR		5
#define SURRENDER	6
#define BEHEAD		7
#define EXILE		8
#define AWARD		9
#define CONFISCATE	10
#define TRADE		11
#define BANQUET		12
#define TRANSPORT	13
#define MOVE		14
#define ALIENATE	15
#define SOLICIT		16
#define INSTIGATION	17
#define ANTI		18
#define CAPITULATE	19
#define SCOUT		20
#define CONSCRIPTION	21
#define ALLOCATION	22
#define PLUNDER		23
#define EXPEDITION	24

#define NEWEMPEROR	25//新君主选择武将
#define DEFENSE		26//被攻打选择武将

//4时期
#define DZNQ 0
#define CCJQ 1
#define CBZZ 2
#define SGDL 3

//tasklist
#define SEARCHTASK		1
#define SURRENDERTASK	2
#define TRANSPORTTASK	3
#define SOLICITTASK		5
#define INSTIGATIONTASK 6
#define CAPITULATETASK	7
#define EXPEDITIONTASK	8
#define PLUNDERTASK		9
#define DEFENCETASK 	18//防守战
#define WARTASK			-8//完成武将选择

//战斗消息显示定义
#define WARINTELLIGENCE		0
#define HEROLEVELUP			1
#define HERODEATH			2
#define ENEMYLEVELUP		3
#define ENEMYDEATH			4

//战斗技能定义
#define FIREATTACK		0
#define LOGROLLING		1
#define ROCKFALL		2
#define FIGHTBRAVELY	3
#define FLYARROW		4
#define ARROWRAIN		5
#define FIREARROW		6
#define TRAMPLE			7
#define CHARGE			8
#define ASSAULT			9
#define FLOODING		10
#define IMPACT			11
#define CURSESEAL		12
#define IMMOBILIZED		13
#define GOSSIP			14
#define REINFORCEMENTS	15
#define LARGEFIRE		16
#define TSUNAMI			17
#define INVISIBLEMAGIC	18
#define LARGEREINFORCEMENTS 19
#define SIEGE			20
#define SUDDENSTRIKE	21
#define WEATHERCHANGE	22
#define STONEHENGE		23
#define SPY				24
//战斗状态定义

#define NORMALSTATUS		0
#define CHAOSSTATUS			1
#define CURSESEALSTATUS		2
#define IMMOBILIZEDSTATUS	3
#define INVISIBLEMAGICSTATUS 4
#define RUNAWAYMAGICSTATUS	5
#define STONEHENGESTATUS	6
#define INVISIBLESTATUS		7

//兵种定义
#define CAVALRY			0
#define INFANTRY		1
#define ARCHER			2
#define SAILOR			3
#define GREATHPARM		4
#define GREATMPARM		5

//地形定义
#define PLAIN			0
#define GRASS			1
#define MOUNTAIN		2
#define FOREST			3
#define VILLAGE			4
#define CITY			5
#define CAMP			6
#define RIVER			7

//战斗定义
#define ATTACK			0
#define SKILL			1
#define STATUS			2
#define WAIT			3

//天气定义
#define SUNNY		1
#define CLOUDY		2
#define WIND		3
#define RAIN		4
#define ICE			5

//城市状态定义
#define NORMAL		0
#define FAMINE		1
#define DROUGHT		2
#define FLOOD		3
#define RIOT		4

//各时期起始年定义
#define DZNQYEAR 190
#define CCJQYEAR 198
#define CBZZYEAR 208
#define SGDLYEAR 225

//map
#define MAPMAX 32

//hero
#define HEROMAX 300

//city
#define CITYMAX 50

//GOOD
#define GOODMAX 50

//TASKLIST
#define TASKLISTMAX 255

#define TEXTAMAX 255

#define NORMALSTRLEN 50

//武将列表属性定义
#define HEROOFTHISCITY				0 //自己城市武将队列
#define CAPTIVEOFTHISCITYADD		1 //（自己城市武将队列后显示）自己城市俘虏队列
#define HEROANDCAPTIVEOFMYCITY		2 //自己城市武将+俘虏队列
#define HEROOFOTHEREMPEROR			3 //（自己城市武将队列后显示）其他君主其他城市武将队列（不含君主）
#define HEROANDEMPEROROFOTHER		4 //（自己城市武将队列后显示）其他君主队列
#define CAPTIVEOFTHISCITY			5 //自己城市俘虏队列
#define HEROOFMYALLCITY				6 //自己所有武将队列
#define HEROlISTTYPEMAX 7

#define LANDSTYLEMAX 8
#define HEROTYPEMAX 6
#define TILESTYLEMAX 50
#define DIRCTIONMAX 8
#define FIGHTHEROMAX 10
#define DEGREEMAX 20
#define MAPSUM 7 //地图数量上限
#define SPECIALHEROMAX 10//特殊技能武将数量
#define HEROSKILLMAX 20//武将拥有的技能上限
#define STRMAX 1000
#define LINEMAX 80 
#define HERONAMEMAXLEN 10 
#define SKILLMAX 50
#define SKILLNAMEMAXLEN 5 
#define GOODNAMEMAXLEN 10 
#define CITYNAMEMAXLEN 10
#define TILEMAX 50//地图tile片的上限
#define SKILLLEN 32

#define BLACKVERSION 0
#define COLORVERSION 1
#define USEHDC 0
#define USEHDCTMP 1
#define FONTA 0
#define FONTB 1

#define PERIODMAX 8
#define PERIODLINEMAX 2

void ShowCG(int delay,char *name,int ux=0,int uy=0);
void ShowCGAdd(int delay,char *name,char *name1,int x,int y);
void LoadPic(char *name,HBITMAP &hbmp);
int ChangeFile(char filename[]);
void Delay(long time);
void CheckSysMsg();
void ShowText(char *text,int x,int y,int size=50);
void ShowTextDirect(char *text,int x,int y,int size=50);
void ShowTextDirectWithColor(char *text,int x,int y,int size=50);
void Message(char *text,int posx,int posy,int ux,int uy);
int GetFileText(char *filename);
int ChangeRes(char *filename);
void ShowCGDirect(int delay,char *name,int ux=0,int uy=0);
void ShowCGStart(int delay,char *name,int ux=0,int uy=0);
void TimerMessage(char *name,char *text,int posx,int posy,int ux,int uy,int delay);
void TimerMessagePlus(char *text1,char *name,char *text2,int posx,int posy,int ux,int uy,int delay);
void TimerMessageCF(char *name,char *text,int posx,int posy,int ux,int uy,int delay);
void TimerMessageGS(char *name,char *text,char *text1,int posx,int posy,int ux,int uy,int delay);
int PlcExtract(int num);
void wlogfile(int type,char *infun,char *inmsg,int result);
void DeleteLog();
LONG WINAPI TopLevelExceptionFilter(struct _EXCEPTION_POINTERS *pExceptionInfo)  ;
char *replace(char *src, char *sub, char *dst);
int InitStrText();//从文本中读取字符串
char *GetStrText(char *strid);//根据strid获取字符串
char *GetStrTextSpilted(char *strid,int pos,int len);//获取截取后的字符串
int InitSSS(int choice);//初始化武将名字列表
int InitTileInfo();//获取战斗TILE相关信息
//int InitMoveCal();//fight用
void MyCreateFont(double times);
void MySetTextColor(int id,int type);
void MySetShowStyle();
void printStack()  ;
void OverflowCheck(char *file,int line,int max,int cur);
void SetEnableDebug();
void GetLine(char *name,int num,int datab[],int datac[]);
void GetStore(char *name,int dataa[]);
void GetPeriodInfo();//获取时期信息
char *GetVersionInfo();