// CXX file for VC AI script
// created by Ando




/*
//_________________________C FILE_________________________
// part of vc1 AI script
// created by Ando
//
#include <inc\sc_global.h>
#include <inc\sc_def.h>



#define P_SIDE			SC_P_SIDE_VC		// SC_P_SIDE_US; SC_P_SIDE_VC; 3 - custom civilian
#define P_GROUP			2					//AI group
#define P_MEMBERID		1					//AI id
//#define P_INIFILENAME	"ini\\players\\vcfighter4.ini"
#define P_NAME_NR		2506	//villager-2510


//____________________________WEAPONS____________________________
#define P_KNIFE			0
#define P_PISTOL		10
//#define P_WEAPON1		2	//random if not defined
#define P_WEAPON2		0
#define P_SLOT1			0


//____________________________AI EXIST IN MODE_______________________________
#define P_EXIST_MODE	7	//		7-COOP,	10-COOP_VC (custom);


//____________________________PATROL______________________________
#define PATROL						0	// 0 - disabled, 1 - normal patrol, 2- follow to player *
	#define PATROL_MOVEMODE			0	//0-walk, 1-aim, 2- run
	#define PATROL_MOVEMODE_2		0	//0-stand,1-crouch,2-LIE	

	#define PATROL_LOOPED			TRUE
	#define PATROL_ORDER			0			//0-forward, 1-backward, 2-forward-backward, 3-random 
	#define PATROL_POINTS			0			//if 0 then detecting automatically max objects with that(PATROL_OBJECTS) name
	#define	PATROL_OBJECTS			"patrol_1#%d"	//waypoint objects (patrol bath waipoint names what must start with end #0( example "patrol_1#0"))

		//_____FOLLOW TO PLAYER___(in peace mode) 
		//only if PATROL = 2
		#define PATROL_FOLLOW_TO			10	//player id (must be same side and same group as current player)
		#define PATROL_STOP_DIST			2	//stop when dist is smaller than
		#define PATROL_FOLLOW_DIST			5	//follow when dist is bigger than
		#define PATROL_TOFAR_DIST			8	//run when too far
		#define VIEW_ROT_FROM_PM			65.0f	// angle in degrees( if 65 then AI will aim 65 degree right from pointman bath)


//_____________________________BEHAVIOUR NEAR OTHER PLAYER_________
#define LOOK_NEAREST_DIST				1.0f	// AI will react when somebody is nearer than that ( AI will stop and look other player)
#define LOOK_NEAREST_TIME				3.0f	// time what AI will look other player near him
#define LOOK_NEAREST_IGNORE				10.0f	// ignore time after looking some player
//_________________________________________________________________
//_________________________________________________________________
//_________________________________________________________________
//__________________________________________________________CREATE CXX


#include <inc\ando\AI\Ando_AI_v2.cxx>

//_________________________END OF C FILE_________________________
*/





//____________________
#define PVANGLE			3.0f
#define PVANGLENEAR		4.0f


//_______________settings of difficulties 
#ifndef D0_SHOOT_PREC
#define	D0_SHOOT_PREC	1.5f
#endif

#ifndef D1_SHOOT_PREC
#define	D1_SHOOT_PREC	1.0f
#endif

#ifndef D2_SHOOT_PREC
#define	D2_SHOOT_PREC	0.3f
#endif

#ifndef D3_SHOOT_PREC
#define	D3_SHOOT_PREC	0.05f
#endif
//________________________________

float			timer = 0.0f;
float			look_timer=0.0;
float			nearest_dist;
float			dist_to_PM;
float			shortest_dist=1000;
float			cur_wp_dist;

int			i_items,j;
int			patrol_obj_count;
int			current_patrol;

dword 		list[32];

dword			gPhase = 0;
dword			cur_pendl_point = -1;
dword			Pendl_Phase=0;

dword			nearest_pl;

c_Vector3			Pl_Pos;
c_Vector3			Target_Pos;
c_Vector3			Last_pos;
c_Vector3			look_dir;
c_Vector3			nearest_head_pos;
c_Vector3			new_look;
c_Vector3			rel_x_pos;
c_Vector3			PM_player_pos;
c_Vector3			player_pos;

s_sphere	sph;

char	txt[32];
s_SC_NOD_transform trans;

s_SC_P_SpecAnims  my_anims;




//__________________________________________________________

//______________RANDOM WEAPONS_______________
#define	MAX_US_WEAPS	8
dword us_weap[MAX_US_WEAPS] = {1,4,11,12,17,19,21,25};	//maybe more

#define	MAX_VC_WEAPS	10
dword vc_weap[MAX_VC_WEAPS] = {2,6,8,9,14,15,18,23,26,28}; //maybe more




//______________RANDOM INIS_______________
#define	MAX_US_INIS	6
char *us_ini[MAX_US_INIS] = {	
	"ini\\players\\CIDG.ini", 
	"ini\\players\\CIDG2.ini", 
	"ini\\players\\lldb.ini",
	"ini\\players\\lldb2.ini", 
	"ini\\players\\sf1.ini", 	
	"ini\\players\\sf2.ini"	};


#define	MAX_VC_INIS	15
char *vc_ini[MAX_VC_INIS] = {	
	
	"ini\\players\\default_aiviet.ini",
	"ini\\players\\poorvc.ini", 
	"ini\\players\\poorvc2.ini", 
	"ini\\players\\poorvc3.ini",
	"ini\\players\\vcfighter.ini",
	"ini\\players\\vcfighter2.ini", 
	"ini\\players\\vcfighter3.ini", 
	"ini\\players\\vcfighter4.ini",
	"ini\\players\\vcuniform1.ini",
	"ini\\players\\vcuniform2.ini",
	"ini\\players\\vcuniform3.ini",
	"ini\\players\\nvasoldier2.ini",
	"ini\\players\\nvasoldier3.ini",
	"ini\\players\\vcgirlpajama.ini",
	"ini\\players\\nvaofficer.ini"};

//"ini\\players\\poorvc4.ini",		//FA
//"ini\\players\\vcfighter5.ini",	//FA
//"ini\\players\\vcuniform4.ini",	//FA
//"ini\\players\\nvasoldier4.ini",	//FA
//"ini\\players\\nvacolonel.ini"	//FA




//______________________________________________________________






void equipplayer(s_SC_P_CreateEqp *eqp, int *count){
	int					my_class;
	
	#ifdef P_CLASS
		my_class = CLASS
	#else
		my_class = rand()%5;
	#endif
	

	switch(my_class){
	case 0://	_______________soldier_______________
			//_________head gear
			eqp[0].bes = "G\\Equipment\\US\\bes\\EOP_hlmt1US_v03.BES";
			eqp[0].eqp = "G\\Equipment\\US\\eqp\\CUP_SFgncsldr01\\velka_polni\\EOP_hlmt1US_v03.eqp";
			*count=1;
		break;
	case 1://	_______________engineer
		break;
	case 2://	_______________medic
		break;
	case 3://	_______________machinegunner
		break;
	case 4://	_______________radioman
		break;
	case 5://	_______________sniper
		break;
	}
}


dword 		my_PM_player;
			



int ScriptMain(s_SC_P_info *info){
	s_SC_P_Create		pinfo;
	s_SC_P_CreateEqp	eqp[10];
	s_SC_P_AI_props		props;
	s_SC_P_getinfo		plInfo;
	c_Vector3			plPos;
	dword				i, j;
	int					eqpcount;
	int					patrol_back=1;


	info->next_exe_time = 0.5f;
	switch( info->message ){
	case SC_P_MES_TIME:
		timer+=info->elapsed_time;
		if (SC_ggi(GVAR_MP_MISSIONTYPE)==P_EXIST_MODE){	
			switch( gPhase ){
			case 0:
				CLEAR(pinfo);
				pinfo.type =		SC_P_TYPE_AI;
				pinfo.side =		P_SIDE;
				pinfo.group =		P_GROUP;
				pinfo.member_id =	P_MEMBERID;

				#ifdef P_INIFILENAME
					pinfo.inifile =	P_INIFILENAME;
				#else
					if(SC_P_SIDE_VC== 0){//us
						pinfo.inifile =	us_ini[ rand()%MAX_US_INIS ];
					}else{	//vc
						pinfo.inifile =	vc_ini[ rand()%MAX_VC_INIS ];
					}
					
				#endif
				pinfo.name_nr =		P_NAME_NR;
				pinfo.icon_name =	"nhut";
				pinfo.weap_knife =	P_KNIFE;
				pinfo.weap_pistol = P_PISTOL;

				#ifdef P_WEAPON1
					pinfo.weap_main1 =	P_WEAPON1;
				#else
					if(SC_P_SIDE_VC== 0){//us
						pinfo.weap_main1 = us_weap[ rand()%MAX_US_WEAPS ];
					}else{	//vc
						pinfo.weap_main1 = vc_weap[ rand()%MAX_VC_WEAPS ];
					}
					
				#endif
				pinfo.weap_main2 =	P_WEAPON2;
				pinfo.weap_slot1 =	P_SLOT1;
				pinfo.debrief_group=SC_P_DEBRIEFGROUP_VC;//SC_P_DEBRIEFGROUP_CIVIL;
				pinfo.recover_pos = info->pos;	

				
				CLEAR(eqp);


				
				//equipplayer(eqp,&eqpcount); 

				//pinfo.eqps = eqpcount; 
				//pinfo.eqp=eqp;



				if (P_SIDE==3){
					eqpcount=1;
					eqp[0].bes = "G\\ITEMS\\V - PRACOVNI NASTROJE\\IVQ_KOPAC.BES";
					eqp[0].eqp = "G\\EQUIPMENT\\US\\EQP\\IVQ_KOPAC.EQP";

					pinfo.eqps = eqpcount; 
					pinfo.eqp = eqp;  
				}





				info->pl_id = SC_P_Create(&pinfo);
				gPhase = 1;
				break;
			case 1:
				if ( !SC_P_IsReady(info->pl_id) ) 
					return 0;

				Pendl_Phase=0;
				cur_pendl_point = -1;
				if (P_SIDE<=1) SC_P_Ai_EnableShooting(info->pl_id, TRUE);
				else SC_P_Ai_EnableShooting(info->pl_id, FALSE);//disable shooting for civilians

				SC_P_Ai_SetPeaceMode(info->pl_id, SC_P_AI_PEACEMODE_HOLD);

				SC_P_Ai_SetBattleMode(info->pl_id, SC_P_AI_BATTLEMODE_ATTACK);//____________

				SC_P_Ai_SetMode(info->pl_id, SC_P_AI_MODE_BATTLE);//	SC_P_AI_MODE_SCRIPT
				CLEAR(props);
				SC_P_Ai_GetProps(info->pl_id, &props);			
				props.extend_searchway		= FALSE;
				props.shortdistance_fight	= 0.0f;
				props.view_angle			= PVANGLE;
				props.view_angle_near		= PVANGLENEAR;
				props.shoot_imprecision = 0;
				props.shoot_damage_mult = 1.3f;
				props.watchfulness_maxdistance = 1;
				props.reaction_time		= 0.01f;
				props.scout				= 0.1f + frnd(0.1f);
				props.berserk			= 0.1f;
//SC_message("My AI max_vis_distance  %f",props.max_vis_distance);
				props.max_vis_distance = SC_GetVisibility()-2;

				//props.max_vis_distance = 120			// maximum visual distance the AI can see, if not specified, AI uses maximum visual distance specified for the level.
				//props.watchfulness_zerodist = 2		// how good is AI at recognizing the enemy at zero distance.
				//props.watchfulness_maxdistance = 1	// how good is AI at recognizing the enemy at maximum distance.
				//props.boldness = 1					// this is used to determine how bold is the AI when in cover and under fire. 0.5 is very cautious player, 2 is medium, 4 is high. 10 is almost suicidal, the AI will not give a damn if someone is shooting at him.
				//props.coveramount = 0.5				// how far the AI will run for cover compared to the distance to the closest enemy, default is 0.5.
				//props.hear_imprecision = 1			// imprecision of the AI’s hearing. 0 absolute hearing, 1 average, 5 very bad.
				//props.hear_distance_mult = 1			// hear distance multiplier – 0.5 is half, 2 is two times better.
				//props.hear_distance_max = 1000		// maximum hearing distance.

				//props.grenade_min_distance;			// minimal distance to throw grenade at (default: 10.0f)
				//props.grenade_timing_imprecision = 2.5	// this is maximum time (will be randomized) between impact of the grenade and it’s explosion.
				//props.grenade_throw_imprecision = 1	// imprecision of the grenade throwing. 0 perfect, 1 average, 2 quite bad.
				//props.grenade_sure_time = 13.737358	// how long the AI will wait until it’s sure the situation demands a grenade.
				//props.forget_enemy_mult = 1			// how fast will the AI forgot the enemies it has no more contact? 1 is default, 0.5  means two times slower, 2 mean two times faster.
				//disable_peace_crouch = 0;//BOOL		// this disables AI crouching in the peace mode.
				//props.peace_fakeenemy_run = 1;		// this is used to set the movement type under the fake enemy situation.  1 means always run, 0 always walk, 0.5 use run/walk 1:1.
				//props.peace_fakeenemy_phase = 0.5		// same as previous, only for the stand/crouch.
				//props.shoot_while_hidding	 = 0.3		// if enabled the AI will shoot even when moving to the hide out.
				//props.aimtime_max = 0.7				// maximum time for AI to take an aim, default 0.7 seconds
				//props.aimtime_canshoot = 0.1			// minimum time for AI to take an aim, default 0.1 seconds.
				//props.aimtime_rotmult = 0.5			// multiplier of the rotation speed when aiming, default 0.5 seconds.
				//props.wounded_start_perc = 0.5		// value of the current hp/max hp when the AI aiming starts to be worse
				//props.wounded_aimtime_mult_max = 2	// multiplier for the maximum aim time when hit points of the AI is zero.
				//props.wounded_shoot_imprec_plus = 0.5	// multiplier for the maximum aim imprecision when hit points of the AI is zero.
				//props.shoot_imprecision = D0_SHOOT_PREC;	//overload previous (default) setting
				//props.shoot_damage_mult = 0.5f;
				//props.grenade_throw_imprecision = 1.5f + frnd(0.5f);


			//set by difficulty
			switch( SC_ggi(SGI_DIFFICULTY) ){
			case 0:
				props.shoot_imprecision		= D0_SHOOT_PREC;		//overload previous (default) setting
				props.shoot_damage_mult		= 0.5f;
				props.grenade_throw_imprecision = 1.5f + frnd(0.5f);
				break;
			case 1:
				props.shoot_imprecision		= D1_SHOOT_PREC;
				props.shoot_damage_mult		= 1.0f;
				props.grenade_throw_imprecision = 1.0f + frnd(0.5f);
				break;
			case 2:
				props.shoot_imprecision		= D2_SHOOT_PREC;
				props.shoot_damage_mult		= 1.1f;
				props.grenade_throw_imprecision = 0.5f + frnd(0.5f);
				break;
			case 3:
				props.shoot_imprecision		= D3_SHOOT_PREC;
				props.shoot_damage_mult		= 1.2f;
				props.grenade_throw_imprecision = 0.3f + frnd(0.3f);
				break;
			}

				SC_P_Ai_SetProps(info->pl_id,&props);
				SC_P_SetSpeachDist(info->pl_id,20);
			

				current_patrol=PATROL;

				switch( current_patrol ){
				case 0://PATROL disabled
					gPhase = 3;
					break;
				case 1://Normal PATROL
					SC_P_Ai_SetMovePos(info->pl_id, PATROL_MOVEMODE_2); // test
					gPhase = 2; 
					if (PATROL_POINTS==0){
						patrol_obj_count=0;
						for(i= 0; i < 20; i++){//count of objects
							sprintf(txt, PATROL_OBJECTS, i);
							if (SC_NOD_GetNoMessage_Entity(txt))patrol_obj_count++;
						}
					}else{
						patrol_obj_count=PATROL_POINTS;
					}
					break;
				case 2://Follow to player
					SC_P_Ai_SetMovePos(info->pl_id, PATROL_MOVEMODE_2); // test
					gPhase = 2;
					//
					if (PATROL_POINTS==0){
						patrol_obj_count=0;
						for(i= 0; i < 20; i++){//count of objects
							sprintf(txt, PATROL_OBJECTS, i);
							if (SC_NOD_GetNoMessage_Entity(txt))patrol_obj_count++;
						}
					}else{
						patrol_obj_count=PATROL_POINTS;
					}


					break;
				}
				break;
			case 2://__________________________________PATROL__________________________
				if (SC_P_Ai_GetEnemies(info->pl_id) < 1) {//if (SC_P_Ai_GetDanger(info->pl_id) <= 0.001f) {
					if (timer >= 0){//ready
						switch( current_patrol ){
						case 1://Normal PATROL
							switch( Pendl_Phase ){
							case 0://give task
								if (cur_pendl_point== -1){//first start for normal or follower whos PM is dead
									SC_message("1");
									//search closest PATROL point
									SC_P_GetPos(info->pl_id, &Pl_Pos);
									for(i = 0; i < patrol_obj_count; i++){
										SC_message("1  %d",i);
										sprintf(txt, PATROL_OBJECTS, i);
										SC_NOD_GetTransform(SC_NOD_GetNoMessage_Entity(txt),&trans);
										Target_Pos=trans.loc;
										cur_wp_dist = SC_2VectorsDist(&Pl_Pos, &Target_Pos);
										if (cur_wp_dist < shortest_dist){
											shortest_dist=cur_wp_dist;
											cur_pendl_point=i;
										}
									}
								}
								sprintf(txt, PATROL_OBJECTS, cur_pendl_point);
								SC_P_Ai_SetMode(info->pl_id, SC_P_AI_MODE_SCRIPT);
								SC_P_Ai_SetMoveMode(info->pl_id, PATROL_MOVEMODE);
								SC_NOD_GetTransform(SC_NOD_GetNoMessage_Entity(txt),&trans);
								Target_Pos=trans.loc;
								SC_P_Ai_Go(info->pl_id, &Target_Pos);
								info->next_exe_time = 0.5f;//
								Pendl_Phase=1;
								break;
							case 1://going
								Last_pos=Pl_Pos;
								SC_P_GetPos(info->pl_id, &Pl_Pos);

								sph.pos=Pl_Pos;
								sph.rad=LOOK_NEAREST_DIST;
								i_items=32;
								
								SC_GetPls(&sph,list,&i_items);
								
								look_timer+=info->elapsed_time;

								if((i_items>1)&&(look_timer<0)){//is there nearest player near him && look time isnt over
									
									if (list[0]==info->pl_id){
										j=1;
									}
									else{
										j=0;
									}
									SC_P_Ai_Stop(info->pl_id);
									SC_P_GetHeadPos(list[j], &nearest_head_pos);
									SC_P_Ai_LookAt(info->pl_id, &nearest_head_pos);// look at nearest player
									timer=-1;


								}
								else{	// no player near him OR ignore him
									if (look_timer>LOOK_NEAREST_IGNORE){	//ignore is over
										look_timer=0-LOOK_NEAREST_TIME;
									}
									

									if ((Last_pos.x==Pl_Pos.x) &&(Last_pos.y==Pl_Pos.y)){// player not moveing, need to give task again
									Pendl_Phase=0;
									
									}
								}
								if (SC_IsNear3D(&Pl_Pos, &Target_Pos, 1)){//reached to target pos
									timer=-1;//wait more one sec
									Pendl_Phase=2;
								}
								break;
							case 2://do something
								timer=-4;
								look_dir.x    = trans.loc.x+sin(trans.rot.z)*10;    
								look_dir.y    = trans.loc.y+cos(trans.rot.z)*10;
								look_dir.z    = trans.loc.z-sin(trans.rot.x)*10;
								SC_P_Ai_LookAt(info->pl_id, &look_dir);
								SC_P_Ai_SetMovePos(info->pl_id, PATROL_MOVEMODE_2);
								
								Pendl_Phase=3;
								break;
							case 3://loop or finish
								//SC_P_DoAnim(info->pl_id, NULL);
								if(PATROL_LOOPED){
									Pendl_Phase=0;
								}
								else{
									Pendl_Phase=4;
								}
								switch( PATROL_ORDER ){
								case 0://forward
									cur_pendl_point+=1;
									if(cur_pendl_point == patrol_obj_count)	cur_pendl_point =0;
									break;
								case 1://backward
									cur_pendl_point-=1;
									if(cur_pendl_point == -1)cur_pendl_point = patrol_obj_count-1;
									break;
								case 2://forward-backward
									if(cur_pendl_point == 0)	patrol_back=1;
									if (cur_pendl_point == patrol_obj_count-1)	patrol_back=(-1);
									cur_pendl_point+=patrol_back;
									break;
								case 3://random
									cur_pendl_point = rand() % patrol_obj_count ;//random target point 
									break;
								}
								break;
							case 4://finished
								break;
							}
							break;
						case 2://Follow to player
							my_PM_player = SC_P_GetBySideGroupMember(P_SIDE, P_GROUP, PATROL_FOLLOW_TO);
							if (my_PM_player){
								if (SC_P_IsReady(my_PM_player)){
								
									SC_P_Ai_SetMode(info->pl_id, SC_P_AI_MODE_SCRIPT);
									SC_P_Ai_SetMoveMode(info->pl_id, PATROL_MOVEMODE);

									SC_P_GetPos(my_PM_player, &PM_player_pos);
									SC_P_GetPos(info->pl_id, &player_pos);
									dist_to_PM =SC_2VectorsDist(&PM_player_pos, &player_pos);


									
									// look TEST__________________
									rel_x_pos.x = PM_player_pos.x - player_pos.x;
									rel_x_pos.y = PM_player_pos.y - player_pos.y;
									rel_x_pos.z = PM_player_pos.z - player_pos.z;
									new_look.x=player_pos.x +(rel_x_pos.x*cos(VIEW_ROT_FROM_PM*PI/180))+(rel_x_pos.y*sin(VIEW_ROT_FROM_PM*PI/180));
									new_look.y=player_pos.y -(rel_x_pos.x*sin(VIEW_ROT_FROM_PM*PI/180))+(rel_x_pos.y*cos(VIEW_ROT_FROM_PM*PI/180));
									new_look.z=player_pos.z;
									SC_P_Ai_LookAt(info->pl_id, &new_look);// look at nearest player
									SC_P_Ai_ShouldLookAt(info->pl_id, &new_look, 2.0f);
									// END OF look TEST__________________
									if(dist_to_PM > PATROL_FOLLOW_DIST){
										SC_P_Ai_Go(info->pl_id, &PM_player_pos);
										SC_P_Ai_SetMoveMode(info->pl_id,SC_P_AI_MOVEMODE_WALK);
										SC_P_Ai_SetMovePos(info->pl_id, PATROL_MOVEMODE_2); //
										SC_P_Ai_WalkThruAIs(info->pl_id,FALSE);
									}
									if(dist_to_PM > PATROL_TOFAR_DIST){
										SC_P_Ai_Go(info->pl_id, &PM_player_pos);
										SC_P_Ai_SetMoveMode(info->pl_id,SC_P_AI_MOVEMODE_RUN);
										SC_P_Ai_WalkThruAIs(info->pl_id,TRUE);
									}
									if(dist_to_PM < PATROL_STOP_DIST){
										SC_P_Ai_Stop(info->pl_id);
										SC_P_Ai_SetMoveMode(info->pl_id,SC_P_AI_MOVEMODE_AIM);
										SC_P_Ai_SetMovePos(info->pl_id,SC_P_AI_MOVEPOS_CROUCH);
									}



								}else{//pointman is not alive
									SC_P_GetInfo(my_PM_player, &plInfo);
									if (plInfo.cur_hp<=0) {
										current_patrol=1;//patrol type changed from "follow" to normal patrol. because PM is dead
										return 1;
									}
								}
							}
							break;
						}
					}
				}
				else{
					timer=-15;// switch to script mode after 15 sec of last seen enemy
					SC_P_Ai_SetBattleMode(info->pl_id, SC_P_AI_BATTLEMODE_HOLD);//SC_P_AI_BATTLEMODE_HOLD   SC_P_AI_BATTLEMODE_GOTO
					SC_P_Ai_SetMode(info->pl_id, SC_P_AI_MODE_BATTLE);
				}
				
				break;
			case 3://
				info->next_exe_time = 3.0f;
				break;
			case 4://player killed
				info->next_exe_time = 3.0f;
				break;
			}//switch( gPhase )
			break;	//case SC_P_MES_TIME:
		}
		else{
			info->next_exe_time = 3.0f;//
		}
	case SC_P_MES_KILLED:


		//DEAD_EXIT_HELI  // ifdef
		//
		//SC_P_IsInHeli(dword pl_id);
		//SC_P_ExitShip(dword pl_id, c_Vector3 *new_pos);
		gPhase = 4;
		break;

		
	case SC_P_MES_SHOTAROUNDCALLBACK:

		break;
	case SC_P_MES_EVENT:
		switch(info->param1){
		case SCM_MP_REINIT:
			if (gPhase != 1)
				gPhase = 1;
			break;
		}
		break;
	}
	return 1;
}
