Ejemplo n.º 1
0
MachThread::MachThread(MachProcess *process, bool is_64_bit,
                       uint64_t unique_thread_id, thread_t mach_port_num)
    : m_process(process), m_unique_id(unique_thread_id),
      m_mach_port_number(mach_port_num), m_seq_id(GetSequenceID()),
      m_state(eStateUnloaded), m_state_mutex(PTHREAD_MUTEX_RECURSIVE),
      m_suspend_count(0), m_stop_exception(),
      m_arch_ap(DNBArchProtocol::Create(this)), m_reg_sets(NULL),
      m_num_reg_sets(0), m_ident_info(), m_proc_threadinfo(),
      m_dispatch_queue_name(), m_is_64_bit(is_64_bit),
      m_pthread_qos_class_decode(nullptr) {
  nub_size_t num_reg_sets = 0;
  m_reg_sets = m_arch_ap->GetRegisterSetInfo(&num_reg_sets);
  m_num_reg_sets = num_reg_sets;

  m_pthread_qos_class_decode =
      (unsigned int (*)(unsigned long, int *, unsigned long *))dlsym(
          RTLD_DEFAULT, "_pthread_qos_class_decode");

  // Get the thread state so we know if a thread is in a state where we can't
  // muck with it and also so we get the suspend count correct in case it was
  // already suspended
  GetBasicInfo();
  DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE,
                   "MachThread::MachThread ( process = %p, tid = 0x%8.8" PRIx64
                   ", seq_id = %u )",
                   reinterpret_cast<void *>(&m_process), m_unique_id, m_seq_id);
}
Ejemplo n.º 2
0
const char *
MachThread::GetBasicInfoAsString () const
{
    static char g_basic_info_string[1024];
    struct thread_basic_info basicInfo;

    if (GetBasicInfo(m_tid, &basicInfo))
    {

//        char run_state_str[32];
//        size_t run_state_str_size = sizeof(run_state_str);
//        switch (basicInfo.run_state)
//        {
//        case TH_STATE_RUNNING:          strncpy(run_state_str, "running", run_state_str_size); break;
//        case TH_STATE_STOPPED:          strncpy(run_state_str, "stopped", run_state_str_size); break;
//        case TH_STATE_WAITING:          strncpy(run_state_str, "waiting", run_state_str_size); break;
//        case TH_STATE_UNINTERRUPTIBLE:  strncpy(run_state_str, "uninterruptible", run_state_str_size); break;
//        case TH_STATE_HALTED:           strncpy(run_state_str, "halted", run_state_str_size); break;
//        default:                        snprintf(run_state_str, run_state_str_size, "%d", basicInfo.run_state); break;    // ???
//        }
        float user = (float)basicInfo.user_time.seconds + (float)basicInfo.user_time.microseconds / 1000000.0f;
        float system = (float)basicInfo.user_time.seconds + (float)basicInfo.user_time.microseconds / 1000000.0f;
        snprintf(g_basic_info_string, sizeof(g_basic_info_string), "Thread 0x%4.4x: user=%f system=%f cpu=%d sleep_time=%d",
            InferiorThreadID(),
            user,
            system,
            basicInfo.cpu_usage,
            basicInfo.sleep_time);

        return g_basic_info_string;
    }
    return NULL;
}
Ejemplo n.º 3
0
MachThread::MachThread (MachProcess *process, thread_t tid) :
    m_process (process),
    m_tid (tid),
    m_seq_id (GetSequenceID()),
    m_state (eStateUnloaded),
    m_state_mutex (PTHREAD_MUTEX_RECURSIVE),
    m_break_id (INVALID_NUB_BREAK_ID),
    m_suspend_count (0),
    m_stop_exception (),
    m_arch_ap (DNBArchProtocol::Create (this)),
    m_reg_sets (NULL),
    m_num_reg_sets (0)
#ifdef THREAD_IDENTIFIER_INFO_COUNT
    , m_ident_info(),
    m_proc_threadinfo(),
    m_dispatch_queue_name()
#endif
{
    nub_size_t num_reg_sets = 0;
    m_reg_sets = m_arch_ap->GetRegisterSetInfo (&num_reg_sets);
    m_num_reg_sets = num_reg_sets;

    // Get the thread state so we know if a thread is in a state where we can't
    // muck with it and also so we get the suspend count correct in case it was
    // already suspended
    GetBasicInfo();
    DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::MachThread ( process = %p, tid = 0x%4.4x, seq_id = %u )", &m_process, m_tid, m_seq_id);
}
Ejemplo n.º 4
0
bool
MachThread::SetSuspendCountBeforeResume(bool others_stopped)
{
    DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
    DNBError err;
    if (ThreadIDIsValid(m_tid) == false)
        return false;
        
    size_t times_to_resume;
        
    if (others_stopped)
    {
        if (GetBasicInfo())
        {
            times_to_resume = m_basic_info.suspend_count;
            m_suspend_count = - (times_to_resume - m_suspend_count);
        }
        else
            times_to_resume = 0;
    }
    else
    {
        times_to_resume = m_suspend_count;
        m_suspend_count = 0;
    }

    if (times_to_resume > 0)
    {
        while (times_to_resume > 0)
        {
            err = ::thread_resume (m_tid);
            if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
                err.LogThreaded("::thread_resume (%4.4x)", m_tid);
            if (err.Success())
                --times_to_resume;
            else
            {
                if (GetBasicInfo())
                    times_to_resume = m_basic_info.suspend_count;
                else
                    times_to_resume = 0;
            }
        }
    }
    return true;
}
Ejemplo n.º 5
0
void CWxwidgetsPropertyBase::SaveToXML( TiXmlElement* pParentNode )
{
    TiXmlElement* pVariableElement = new TiXmlElement("VariableNode");
    pVariableElement->SetAttribute("Type", m_type);
    char variableName[MAX_PATH] = {0};
    CStringHelper::GetInstance()->ConvertToCHAR(GetBasicInfo()->m_variableName.c_str(), variableName, MAX_PATH);
    pVariableElement->SetAttribute("Variable", variableName);
    char szValue[102400];
    GetValueAsChar(eVT_CurrentValue, szValue);
    pVariableElement->SetAttribute("SavedValue", szValue);
    pParentNode->LinkEndChild(pVariableElement);
    for (size_t i = 0; i < m_pChildren->size(); ++i)
    {
        (*m_pChildren)[i]->SaveToXML(pVariableElement);
    }
}
Ejemplo n.º 6
0
MachThread::MachThread (MachProcess *process, thread_t thread) :
    m_process (process),
    m_tid (thread),
    m_seq_id (GetSequenceID()),
    m_state (eStateUnloaded),
    m_state_mutex (PTHREAD_MUTEX_RECURSIVE),
    m_breakID (INVALID_NUB_BREAK_ID),
    m_suspendCount (0),
    m_arch_ap (DNBArchProtocol::Create (this)),
    m_reg_sets (m_arch_ap->GetRegisterSetInfo (&n_num_reg_sets))
{
    // Get the thread state so we know if a thread is in a state where we can't
    // muck with it and also so we get the suspend count correct in case it was
    // already suspended
    GetBasicInfo();
    DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::MachThread ( process = %p, tid = 0x%4.4x, seq_id = %u )", &m_process, m_tid, m_seq_id);
}
Ejemplo n.º 7
0
bool MachThread::IsUserReady() {
  if (m_basic_info.run_state == 0)
    GetBasicInfo();

  switch (m_basic_info.run_state) {
  default:
  case TH_STATE_UNINTERRUPTIBLE:
    break;

  case TH_STATE_RUNNING:
  case TH_STATE_STOPPED:
  case TH_STATE_WAITING:
  case TH_STATE_HALTED:
    return true;
  }
  return false;
}
Ejemplo n.º 8
0
bool
MachThread::RestoreSuspendCountAfterStop ()
{
    DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
    DNBError err;
    if (ThreadIDIsValid(m_tid) == false)
        return false;
        
    if (m_suspend_count > 0)
    {
        while (m_suspend_count > 0)
        {
            err = ::thread_resume (m_tid);
            if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
                err.LogThreaded("::thread_resume (%4.4x)", m_tid);
            if (err.Success())
                --m_suspend_count;
            else
            {
                if (GetBasicInfo())
                    m_suspend_count = m_basic_info.suspend_count;
                else
                    m_suspend_count = 0;
                return false; // ??? 
            }
        }
    }
    else if (m_suspend_count < 0)
    {
        while (m_suspend_count < 0)
        {
            err = ::thread_suspend (m_tid);
            if (err.Success())
                ++m_suspend_count;
            if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
            {
                err.LogThreaded("::thread_suspend (%4.4x)", m_tid);
                return false;
            }
        }
    }
    return true;
}
Ejemplo n.º 9
0
bool
MachThread::RestoreSuspendCount()
{
    DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
    DNBError err;
    if (ThreadIDIsValid(m_tid) == false)
        return false;
    if (m_suspendCount > 0)
    {
        while (m_suspendCount > 0)
        {
            err = ::thread_resume (m_tid);
            if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
                err.LogThreaded("::thread_resume (%4.4x)", m_tid);
            if (err.Success())
                --m_suspendCount;
            else
            {
                if (GetBasicInfo())
                    m_suspendCount = m_basicInfo.suspend_count;
                else
                    m_suspendCount = 0;
                return false; // ??? 
            }
        }
    }
    // We don't currently really support resuming a thread that was externally
    // suspended. If/when we do, we will need to make the code below work and
    // m_suspendCount will need to become signed instead of unsigned.
//    else if (m_suspendCount < 0)
//    {
//        while (m_suspendCount < 0)
//        {
//            err = ::thread_suspend (m_tid);
//            if (err.Success())
//                ++m_suspendCount;
//            if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
//                err.LogThreaded("::thread_suspend (%4.4x)", m_tid);
//        }
//    }
    return true;
}
Ejemplo n.º 10
0
LRESULT CMainDlg::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
  if (wParam == kIconTimerID) {
    static int index = 0;
    if (index == 0) {
      HICON hIcon = AtlLoadIconImage(IDI_ICON_WINDOW8, LR_DEFAULTCOLOR,
        ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON));
      SetIcon(hIcon, TRUE);
      HICON hIconSmall = AtlLoadIconImage(IDI_ICON_WINDOW8, LR_DEFAULTCOLOR,
        ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON));
      SetIcon(hIconSmall, FALSE);
      index = 1;
    } else {
      HICON hIcon = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR,
        ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON));
      SetIcon(hIcon, TRUE);
      HICON hIconSmall = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR,
        ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON));
      SetIcon(hIconSmall, FALSE);
      index = 0;
    }    

  } else if (wParam == kTimerID) {
    POINT pt;
    GetCursorPos(&pt);

    // if no movement, do not refresh the ui.
    if (pt.x == point_.x && pt.y == point_.y)
      return 0;

    point_.x = pt.x;
    point_.y = pt.y;

    // Basic Information
    GetBasicInfo();

    // Advanced Information
    GetAdvancedInfo();
  }
  
  return 0;
}
Ejemplo n.º 11
0
///////////////////////////CREATED_BY_ABILITYTAO_AND_CYACM_2009_NOV///////////////////////////////////////////////
CLIENT_EXPORT_API void __stdcall AI()
{

	//截获状态并生成策略
	state=GetBasicInfo();
	stategy=UpdateInfo();

	//抓金色飞贼优先级最高,仅作尝试,小概率事件^_^
	if(iGoldBall.b_visible==true)
	{
		if(iHero_1.b_snatch_goldball)
			if(Tc_SnatchBall(hHero_1,TC_GOLD_BALL))
				return ;
		else if(iHero_2.b_snatch_goldball)
			if(Tc_SnatchBall(hHero_2,TC_GOLD_BALL))
				return;
		
	}
	//////////////////////////////////////////////////////////////////////////


	//这里貌似有问题,领先的时候也进入这个函数,奇怪!
	//if(iGoldBall.b_visible==true&&( ((int)iOwnGameInfo.score_enemy-(int)iOwnGameInfo.score_self)>=GRAB_GOLD_BALL_LIMITATION ) )
	//{
	//	if(iHero_1.b_snatch_goldball)
	//		Tc_SnatchBall(hHero_1,TC_GOLD_BALL);	
	//	if(iHero_2.b_snatch_goldball)
	//		Tc_SnatchBall(hHero_2,TC_GOLD_BALL);
	//	CATCH_GOLD_BALL.run();
	//	return;
	//}
	/*
	TC_Position t_h;
	TC_Position t_b;
	t_h.x=iHeroWithBall.pos.x+64;
	t_h.y=iHeroWithBall.pos.y+64;
	t_b.x=iFreeBall.pos.x+32;
	t_b.y=iFreeBall.pos.y+32;
	if(GetLineDis(&t_h,&t_b)<100)
	{

	int f=1;
	}//用来调试
	*/


	//如果是从左向右攻
	if(iAttackDirection==TC_DIRECTION_RIGHT)
	{
		switch (stategy)
		{
		case FORCE_ATTACK:
			{

				//////////////////////////////////////////////////////////////////////////
				//优先级最低
				Save_Move(hHeroWithBall,GetAttackDirection(&iHeroWithBall));
				Save_Move(hHeroWithoutBall,GetPosToPosDirection(&iHeroWithoutBall.pos,&iHeroWithBall.pos));

				//拿到球后尽可能往前传,节约时间
				if(iHeroWithBall.pos.x<R_CS_LINE-TC_HERO_WIDTH)
				{
					TC_Position target;
					if(iHeroWithBall.pos.x+TC_PASSBALL_DISTANCE<R_FORBIDDEN_LINE)
						target.x=iHeroWithBall.pos.x+TC_PASSBALL_DISTANCE;
					else
						target.x=R_FORBIDDEN_LINE-1;
					target.y=iHeroWithBall.pos.y;
					if(iHeroWithBall.abnormal_type!=TC_SPELLED_BY_MALFOY&&iHeroWithBall.abnormal_type!=TC_SPELLED_BY_FREEBALL)
						Tc_PassBall(hHeroWithBall,target);
				}
				//如果在前场禁区右侧进攻时,形成混战,吹走一个人,局部二打一
				if(iHero_2.b_ghostball==false&&iHero_2.b_can_spell==true&&iHero_2.curr_blue>2000&&GetLineDis(&iHero_1.pos,&iHero_2.pos)<TC_HERO_SPELL_DISTANCE&&iHero_1.pos.x>(R_CS_LINE+128)&&GetLineDis(&iHero_1.pos,&iEnemy_1.pos)<TC_HERO_WIDTH*2&&GetLineDis(&iHero_1.pos,&iEnemy_2.pos)<TC_HERO_WIDTH*2)
				{
					if(GetLineDis(&iHero_1.pos,&iEnemy_1.pos)<=GetLineDis(&iHero_1.pos,&iEnemy_2.pos))
						Tc_Spell(hHero_2,hEnemy_1);
					else
						Tc_Spell(hHero_2,hEnemy_2);
				}

				//在禁区内遭遇吹球或吹人,如果不能交给队友则传到禁区下侧
				if(iHeroWithBall.pos.x>R_CS_LINE&&iEnemy_1.b_is_spelling==true&&(iEnemy_1.type==TC_HERO_GINNY||iEnemy_1.type==TC_HERO_RON||iEnemy_1.type==TC_HERO_MALFOY)&&(iEnemyGate.x-iHeroWithBall.pos.x)>TC_HERO_WIDTH)
				{
					if( (iEnemy_1.type==TC_HERO_GINNY||iEnemy_1.type==TC_HERO_RON||iEnemy_1.type==TC_HERO_MALFOY)&&GetLineDis(&iHeroWithBall.pos,&iHeroWithoutBall.pos)>(TC_HERO_WIDTH-64)  )
					{

						TC_Position t;
						t.x=R_FORBIDDEN_LINE+128+64;
						t.y=640;
						Tc_PassBall(hHeroWithBall,t);
					}


				}
				else if(iHeroWithBall.pos.x>R_CS_LINE&&iEnemy_2.b_is_spelling==true&&(iEnemy_2.type==TC_HERO_GINNY||iEnemy_2.type==TC_HERO_RON||iEnemy_2.type==TC_HERO_MALFOY)&&(iEnemyGate.x-iHeroWithBall.pos.x)>TC_HERO_WIDTH)
				{
					if( (iEnemy_2.type==TC_HERO_GINNY||iEnemy_2.type==TC_HERO_RON||iEnemy_2.type==TC_HERO_MALFOY)&&GetLineDis(&iHeroWithBall.pos,&iHeroWithoutBall.pos)>(TC_HERO_WIDTH-64)  )
					{
						TC_Position t;
						t.x=R_FORBIDDEN_LINE+128+64;
						t.y=640;
						Tc_PassBall(hHeroWithBall,t);
					}
				}
				//如果持球队员被晕了或是被乌龟了,另一个队员夺走球继续进攻
				if( ( ( warn==1&&iHeroBeingSpelled.b_ghostball==true)||(iHeroWithBall.abnormal_type==TC_SPELLED_BY_HERMIONE||iHeroWithBall.abnormal_type==TC_SPELLED_BY_MALFOY||iHeroWithBall.abnormal_type==TC_SPELLED_BY_FREEBALL||iHeroWithBall.abnormal_type==TC_SPELLED_BY_RON) )  &&GetLineDis(&iHeroWithBall.pos,&iHeroWithoutBall.pos)<=(TC_HERO_WIDTH-32))
				{

					if(iHeroWithoutBall.b_snatch_ghostball==true)
					{
						bool test;//调试用1
						test=Tc_SnatchBall(hHeroWithoutBall,TC_GHOST_BALL);
						int a=1;//调试用2
					}
					else
						Save_Move(hHeroWithoutBall,GetPosToPosDirection(&iHeroWithoutBall.pos,&iHeroWithBall.pos));
				}
				break;
			}
		case FORCE_DEFEND:
			{

				//////////////////////////////////////////////////////////////////////////
				//暴抢,双人抢,优先级最低
				Save_Move(hHero_1,GetEnemyDirection(&iHero_1,&iEnemyWithBall));
				TC_Position centre;
				centre.x=CENTREX-TC_HERO_WIDTH/2;//让球员中心与中点重合
				centre.y=CENTREY-TC_HERO_WIDTH/2;//同上
				if(iHero_1.abnormal_type==TC_SPELLED_BY_NONE&&GetLineDis(&iHero_1.pos,&iEnemyWithBall.pos)<TC_HERO_SPELL_DISTANCE&&iEnemyWithBall.pos.x<L_CS_LINE&&(iHero_1.b_can_spell==true||iHero_1.b_is_spelling==true) )
				{
					Save_Move(hHero_2,GetPosToPosDirection(&iHero_2.pos,&centre));
				}

				else
					Save_Move(hHero_2,GetEnemyDirection(&iHero_2,&iEnemyWithBall));

				//如果在中场混战,吹飞一人,二打一
				//if( iEnemy_1.pos.x<CENTREX+TC_HERO_WIDTH && iEnemy_1.pos.x >CENTREX-TC_HERO_WIDTH && iEnemy_2.pos.x<CENTREX+TC_HERO_WIDTH && iEnemy_2.pos.x >CENTREX-TC_HERO_WIDTH&&iHero_1.pos.x<CENTREX+TC_HERO_WIDTH && iHero_1.pos.x >CENTREX-TC_HERO_WIDTH&&iHero_2.pos.x<CENTREX+TC_HERO_WIDTH && iHero_2.pos.x >CENTREX-TC_HERO_WIDTH&&GetLineDis(&iHero_1.pos,&iEnemy_1.pos)<TC_HERO_WIDTH&&GetLineDis(&iHero_1.pos,&iEnemy_2.pos)<TC_HERO_WIDTH&&GetLineDis(&iHero_2.pos,&iEnemy_1.pos)<TC_HERO_WIDTH&&GetLineDis(&iHero_2.pos,&iEnemy_2.pos)<TC_HERO_WIDTH&&iHero_2.curr_blue>2000&&iHero_2.b_can_spell==true)
				//{

				//	if(GetLineDis(&iEnemy_1.pos,&iHero_2.pos)<=GetLineDis(&iEnemy_2.pos,&iHero_2.pos) )
				//	{
				//		Tc_Spell(hHero_2,hHeroWithBall);
				//	}
				//}


				//珍妮施法将球吹回中场

				if(iHero_1.type==TC_HERO_GINNY&&iHero_1.b_can_spell==true&&iEnemyWithBall.pos.x-iOwnGate.x<DANGERDIS&&iHero_2.b_is_spelling==false&&iEnemyWithBall.abnormal_type!=TC_SPELLED_BY_RON)
				{
					Tc_Spell(hHero_1,hEnemyWithBall);
				}

				//如果珍妮不能,RON协助将带球人吹回后场,争取时间,RON的danger值做了微调
				else if(iHero_2.type==TC_HERO_RON&&iHero_2.b_can_spell==true&&iEnemyWithBall.pos.x-iOwnGate.x<(DANGERDIS+10)&&GetLineDis(&iHero_2.pos,&iHeroWithBall.pos)<TC_HERO_SPELL_DISTANCE&&iHero_1.b_is_spelling==false)
				{
					Tc_Spell(hHero_2,hEnemyWithBall);
				}


				if(iHero_1.b_snatch_ghostball==true)
					Tc_SnatchBall(hHero_1,TC_GHOST_BALL);
				else if(iHero_2.b_snatch_ghostball==true)
					Tc_SnatchBall(hHero_2,TC_GHOST_BALL);


				//抓金色飞贼优先级最高,仅作尝试,小概率事件^_^
				if(iGoldBall.b_visible==true)
				{
					if(iHero_1.b_snatch_goldball)
						Tc_SnatchBall(hHero_1,TC_GOLD_BALL);
					else if(iHero_2.b_snatch_goldball)
						Tc_SnatchBall(hHero_2,TC_GOLD_BALL);
				}
				//////////////////////////////////////////////////////////////////////////
				break;


			}
		case FORCE_GRAB_FREE_BALL:
			{
				//////////////////////////////////////////////////////////////////////////

				int grabflag=0;
				if (iHero_1.b_snatch_ghostball == true)
				{
					if(IsBallInPassing(&iGhostBall)==true&&iGhostBall.speed.vx>0)
						Save_Move(hHero_1,GetBallDirection(&iHero_1,&iGhostBall));
					else
					{
						Tc_SnatchBall(hHero_1,TC_GHOST_BALL);
						grabflag=1;
					}

				}
				else
					Save_Move(hHero_1,GetBallDirection(&iHero_1,&iGhostBall));


				//////////////////////////////////////////////////////////////////////////
				if (iHero_2.b_snatch_ghostball == true&&grabflag==0)
				{
					if(IsBallInPassing(&iGhostBall)==true&&iGhostBall.speed.vx>0)
						Save_Move(hHero_2,GetBallDirection(&iHero_2,&iGhostBall));
					else
					{
						Tc_SnatchBall(hHero_2,TC_GHOST_BALL);

					}
				}
				else
					Save_Move(hHero_2,GetBallDirection(&iHero_2,&iGhostBall));

				break;
			}


		}
	}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	else if(iAttackDirection==TC_DIRECTION_LEFT)
	{
		///////////////////////////////////////////////////////
		/*if(iEnemy_1.b_is_spelling==true||iEnemy_2.b_is_spelling==true)
		{
			int res=1;
		}//调试用
		*/
		

		switch (stategy)
		{
		case FORCE_ATTACK:
			{

				//////////////////////////////////////////////////////////////////////////
				//优先级最低
				Save_Move(hHeroWithBall,GetAttackDirection(&iHeroWithBall));
				Save_Move(hHeroWithoutBall,GetPosToPosDirection(&iHeroWithoutBall.pos,&iHeroWithBall.pos));

				//拿到球后尽可能往前传,节约时间
				if(iHeroWithBall.pos.x>L_CS_LINE+TC_HERO_WIDTH)
				{
					TC_Position target;
					if(iHeroWithBall.pos.x+TC_HERO_WIDTH/2-TC_PASSBALL_DISTANCE-30>L_FORBIDDEN_LINE)
						target.x=iHeroWithBall.pos.x+TC_HERO_WIDTH/2-TC_PASSBALL_DISTANCE-30;
					else
						target.x=L_FORBIDDEN_LINE+1;
					target.y=iHeroWithBall.pos.y;
					if(iHeroWithBall.abnormal_type!=TC_SPELLED_BY_MALFOY&&iHeroWithBall.abnormal_type!=TC_SPELLED_BY_FREEBALL)
					{
						bool test;
						test=Tc_PassBall(hHeroWithBall,target);
						int a=1;
					}
				}
				//如果在前场禁区左侧进攻时,形成混战,吹走一个人,局部二打一
				if(iHero_2.b_ghostball==false&&iHero_2.b_can_spell==true&&iHero_2.curr_blue>2000&&GetLineDis(&iHero_1.pos,&iHero_2.pos)<TC_HERO_SPELL_DISTANCE&&iHero_1.pos.x<(L_CS_LINE-128)&&GetLineDis(&iHero_1.pos,&iEnemy_1.pos)<TC_HERO_WIDTH*2&&GetLineDis(&iHero_1.pos,&iEnemy_2.pos)<TC_HERO_WIDTH*2)
				{

					if(GetLineDis(&iHero_1.pos,&iEnemy_1.pos)<=GetLineDis(&iHero_1.pos,&iEnemy_2.pos))
						Tc_Spell(hHero_2,hEnemy_1);
					else
						Tc_Spell(hHero_2,hEnemy_2);

				}

				//在禁区内遭遇吹球或吹人,如果不能交给队友则传到禁区下侧
				if(iHeroWithBall.pos.x<L_CS_LINE+TC_HERO_WIDTH   &&   iEnemy_1.b_is_spelling==true  &&  (iEnemy_1.type==TC_HERO_GINNY||iEnemy_1.type==TC_HERO_RON||iEnemy_1.type==TC_HERO_MALFOY)   &&   (iEnemyGate.x-iHeroWithBall.pos.x)<0)
				{
					if( (iEnemy_1.type==TC_HERO_GINNY||iEnemy_1.type==TC_HERO_RON||iEnemy_1.type==TC_HERO_MALFOY)&&GetLineDis(&iHeroWithBall.pos,&iHeroWithoutBall.pos)>(TC_HERO_WIDTH-64)  )
					{

						TC_Position t;
						t.x=L_FORBIDDEN_LINE-128-64;
						t.y=640;
						Tc_PassBall(hHeroWithBall,t);
					}


				}

				else if(iHeroWithBall.pos.x<L_CS_LINE+TC_HERO_WIDTH&&iEnemy_2.b_is_spelling==true&&(iEnemy_2.type==TC_HERO_GINNY||iEnemy_2.type==TC_HERO_RON||iEnemy_2.type==TC_HERO_MALFOY)&&iEnemyGate.x-iHeroWithBall.pos.x<0)
				{
					if( (iEnemy_2.type==TC_HERO_GINNY||iEnemy_2.type==TC_HERO_RON||iEnemy_2.type==TC_HERO_MALFOY)&&GetLineDis(&iHeroWithBall.pos,&iHeroWithoutBall.pos)>(TC_HERO_WIDTH-64)  )
					{
						TC_Position t;
						t.x=L_FORBIDDEN_LINE-128-64;
						t.y=640;
						Tc_PassBall(hHeroWithBall,t);
					}
				}
				//如果持球队员被晕了或是被乌龟了,另一个队员夺走球继续进攻
				if( ( ( warn==1&&iHeroBeingSpelled.b_ghostball==true)||(iHeroWithBall.abnormal_type==TC_SPELLED_BY_HERMIONE||iHeroWithBall.abnormal_type==TC_SPELLED_BY_MALFOY||iHeroWithBall.abnormal_type==TC_SPELLED_BY_FREEBALL||iHeroWithBall.abnormal_type==TC_SPELLED_BY_RON) ) &&GetLineDis(&iHeroWithBall.pos,&iHeroWithoutBall.pos)<=(TC_HERO_WIDTH-32))
				{

					if(iHeroWithoutBall.b_snatch_ghostball==true)
					{
						Tc_SnatchBall(hHeroWithoutBall,TC_GHOST_BALL);
					}
					else
						Save_Move(hHeroWithoutBall,GetPosToPosDirection(&iHeroWithoutBall.pos,&iHeroWithBall.pos));
				}
				break;
			}
		case FORCE_DEFEND:
			{

				//////////////////////////////////////////////////////////////////////////
				//暴抢,双人抢,优先级最低
				Save_Move(hHero_1,GetEnemyDirection(&iHero_1,&iEnemyWithBall));
				TC_Position centre;
				centre.x=CENTREX-TC_HERO_WIDTH/2;//让球员中心与中点重合
				centre.y=CENTREY-TC_HERO_WIDTH/2;//同上
				if(iHero_1.abnormal_type==TC_SPELLED_BY_NONE&&GetLineDis(&iHero_1.pos,&iEnemyWithBall.pos)<TC_HERO_SPELL_DISTANCE&&iEnemyWithBall.pos.x>R_CS_LINE&&(iHero_1.b_can_spell==true||iHero_1.b_is_spelling==true) )
				{
					Save_Move(hHero_2,GetPosToPosDirection(&iHero_2.pos,&centre));
				}

				else
					Save_Move(hHero_2,GetEnemyDirection(&iHero_2,&iEnemyWithBall));

				//如果在中场混战,吹飞一人,二打一
				//if( iEnemy_1.pos.x<CENTREX+TC_HERO_WIDTH && iEnemy_1.pos.x >CENTREX-TC_HERO_WIDTH && iEnemy_2.pos.x<CENTREX+TC_HERO_WIDTH && iEnemy_2.pos.x >CENTREX-TC_HERO_WIDTH&&iHero_1.pos.x<CENTREX+TC_HERO_WIDTH && iHero_1.pos.x >CENTREX-TC_HERO_WIDTH&&iHero_2.pos.x<CENTREX+TC_HERO_WIDTH && iHero_2.pos.x >CENTREX-TC_HERO_WIDTH&&GetLineDis(&iHero_1.pos,&iEnemy_1.pos)<TC_HERO_WIDTH&&GetLineDis(&iHero_1.pos,&iEnemy_2.pos)<TC_HERO_WIDTH&&GetLineDis(&iHero_2.pos,&iEnemy_1.pos)<TC_HERO_WIDTH&&GetLineDis(&iHero_2.pos,&iEnemy_2.pos)<TC_HERO_WIDTH&&iHero_2.curr_blue>2000&&iHero_2.b_can_spell==true)
				//{

				//	if(GetLineDis(&iEnemy_1.pos,&iHero_2.pos)<=GetLineDis(&iEnemy_2.pos,&iHero_2.pos) )
				//	{
				//		Tc_Spell(hHero_2,hHeroWithBall);
				//	}
				//}


				//珍妮施法将球吹回中场

				if(iHero_1.type==TC_HERO_GINNY&&iHero_1.b_can_spell==true&&abs(iEnemyWithBall.pos.x-iOwnGate.x)<DANGERDIS+TC_HERO_WIDTH&&iHero_2.b_is_spelling==false&&iEnemyWithBall.abnormal_type!=TC_SPELLED_BY_RON)
				{
					Tc_Spell(hHero_1,hEnemyWithBall);
				}

				//如果珍妮不能,RON协助将带球人吹回后场,争取时间,RON的danger值做了微调
				else if(iHero_2.type==TC_HERO_RON&&iHero_2.b_can_spell==true&&abs(iEnemyWithBall.pos.x-iOwnGate.x)<(DANGERDIS+10+TC_HERO_WIDTH)&&GetLineDis(&iHero_2.pos,&iHeroWithBall.pos)<TC_HERO_SPELL_DISTANCE&&iHero_1.b_is_spelling==false)
				{
					Tc_Spell(hHero_2,hEnemyWithBall);
				}


				if(iHero_1.b_snatch_ghostball==true)
					Tc_SnatchBall(hHero_1,TC_GHOST_BALL);
				else if(iHero_2.b_snatch_ghostball==true)
					Tc_SnatchBall(hHero_2,TC_GHOST_BALL);


				//抓金色飞贼优先级最高,仅作尝试,小概率事件^_^
				if(iGoldBall.b_visible==true)
				{
					if(iHero_1.b_snatch_goldball)
						Tc_SnatchBall(hHero_1,TC_GOLD_BALL);
					else if(iHero_2.b_snatch_goldball)
						Tc_SnatchBall(hHero_2,TC_GOLD_BALL);
				}
				//////////////////////////////////////////////////////////////////////////
				break;


			}
		case FORCE_GRAB_FREE_BALL:
			{
				//////////////////////////////////////////////////////////////////////////

				int grabflag=0;
				if (iHero_1.b_snatch_ghostball == true)
				{
					if(IsBallInPassing(&iGhostBall)==true&&iGhostBall.speed.vx<0)
						Save_Move(hHero_1,GetBallDirection(&iHero_1,&iGhostBall));
					else
					{
						Tc_SnatchBall(hHero_1,TC_GHOST_BALL);
						grabflag=1;
					}

				}
				else
					Save_Move(hHero_1,GetBallDirection(&iHero_1,&iGhostBall));


				//////////////////////////////////////////////////////////////////////////
				if (iHero_2.b_snatch_ghostball == true&&grabflag==0)
				{
					if(IsBallInPassing(&iGhostBall)==true&&iGhostBall.speed.vx<0)
						Save_Move(hHero_2,GetBallDirection(&iHero_2,&iGhostBall));
					else
					{
						Tc_SnatchBall(hHero_2,TC_GHOST_BALL);

					}
				}
				else
					Save_Move(hHero_2,GetBallDirection(&iHero_2,&iGhostBall));

				break;
			}
		}

		
	}
}