Example #1
0
INT CArcher::Tracing(CMoveShape* pTarget)
{
	if (0)//EscapeNearEnemy(1)
	{
		SearchEnemy();
		return TRACE_RESULT_TRACE;
	}
	else
	{
		return CMonsterAI::Tracing(pTarget);
	}
}
Example #2
0
 bool PeaceStateScript::PreExecute(BaseType::EntityType *entity)
 {
     if(SearchEnemy(entity) ||
         CheckHangup(entity) ||
         CheckCycleState(entity))
     {
         return true;
     }
     if(CheckRunByRoad(entity))
     {
         return true;
     }
     return false;
 }
Example #3
0
    bool FightStateScript::PreExecute(BaseType::EntityType *entity)
    {
        // search enemy first
	    SearchEnemy(entity);

		// check cycle action
        if(CheckCycleState(entity))
		{
			return true;
		}

        if(CheckTracer(entity))
        {
            return true;
        }

        return false;
    }
Example #4
0
    void SummonPeaceState::Execute(BaseType::EntityType *entity)
    {
		if (entity == NULL)
		{
			LogError(AI_MODULE, "entity is null.");
			return;
		}
        if(SearchEnemy(entity))
        {
            return;
        }

        /// Stand ... Don't move
        MonsterAI *ai = static_cast<MonsterAI*>(entity);
        CMonster  *monster = static_cast<CMonster*>(entity->GetOwner());
		if (monster == NULL)
		{
			LogError(AI_MODULE, "MonsterAI do not have owner.");
		}
        assert(ai && monster);
        ai->Stand(monster->GetStopFrame());
    }
Example #5
0
	void FightStateNormal::Execute(BaseType::EntityType *entity)
	{
		if (entity == NULL)
		{
			LogError(AI_MODULE, "entity is null.");
			return;
		}
		// search enemy first
	    SearchEnemy(entity);

		// check cycle action
        if(CheckCycleState(entity))
		{
			return ;
		}

		// can return peace ?
		MonsterAI *monsterAI = static_cast<MonsterAI*>(entity);
		if(monsterAI->GetFightObj().CheckReturnPeace())
		{
			// return peace
			return ;
		}

		// attack the target
		CMoveShape *target = entity->GetTarget();
		if(target == NULL)
		{
			LogError(AI_MODULE, "attack target is null.");
			// return peace ?
			monsterAI->GetFightObj().LoseTarget();
			entity->Resume(OPER_FAILED_TIME);
			return ;
		}
		Attack(entity, target);
	}
Example #6
0
bool CAutoRadar::EventProcess(const Event &event)
{
    Math::Vector    pos, ePos;
    float       speed, angle, prog, freq, ampl;

    CAuto::EventProcess(event);

    if ( m_engine->GetPause() )  return true;
    if ( event.type != EVENT_FRAME )  return true;
    if ( m_phase == ARAP_WAIT )  return true;

    m_progress += event.rTime*m_speed;
    m_aTime += event.rTime;
    m_timeVirus -= event.rTime;

    if ( m_object->GetVirusMode() )  // contaminated by a virus?
    {
        if ( m_timeVirus <= 0.0f )
        {
            m_timeVirus = 0.1f+Math::Rand()*0.3f;

            angle = m_object->GetAngleY(1);
            angle += (Math::Rand()-0.2f)*0.5f;
            m_object->SetAngleY(1, angle);

            angle = m_object->GetAngleY(2);
            angle += (Math::Rand()-0.8f)*1.0f;
            m_object->SetAngleY(2, angle);

            m_object->SetAngleX(3, (Math::Rand()-0.5f)*0.3f);

            m_totalDetect = static_cast< int >(Math::Rand()*10.0f);
            UpdateInterface();
        }
        return true;
    }

    if ( m_phase == ARAP_SEARCH )
    {
        if ( m_progress < 1.0f )
        {
            speed = Math::Min(10.0f, m_progress*50.0f);
            angle = m_object->GetAngleY(1);
            angle += event.rTime*speed;
            m_object->SetAngleY(1, angle);
        }
        else
        {
            if ( !SearchEnemy(ePos) )
            {
                m_phase    = ARAP_SEARCH;
                m_progress = 10.0f/50.0f;  // full speed immediately
                m_speed    = 1.0f/3.0f;
            }
            else
            {
                pos = m_object->GetPosition(0);
                m_start = m_object->GetAngleY(1);
                m_angle = m_start-Math::NormAngle(m_start)+Math::PI*2.0f;
                m_angle += Math::RotateAngle(pos.x-ePos.x, ePos.z-pos.z);
                m_angle += Math::PI-m_object->GetAngleY(0);

                m_phase    = ARAP_SHOW;
                m_progress = 0.0f;
                m_speed    = 1.0f/(fabs(m_angle-m_start)/10.0f);
            }
        }
    }

    if ( m_phase == ARAP_SHOW )
    {
        if ( m_progress < 1.0f )
        {
            angle = m_start + (m_angle-m_start)*m_progress;
            m_object->SetAngleY(1, angle);
        }
        else
        {
            m_sound->Play(SOUND_RADAR, m_object->GetPosition(0));

            m_phase    = ARAP_SINUS;
            m_progress = 0.0f;
            m_speed    = 1.0f/4.0f;
            m_time     = 0.0f;
        }
    }

    if ( m_phase == ARAP_SINUS )
    {
        if ( m_progress < 1.0f )
        {
            prog = Math::Min(1.0f, m_progress*2.0f);
            freq = 16.0f*(prog+1.0f);
            ampl = 0.2f-prog*0.2f;
            angle = m_angle + sinf(m_time*freq)*ampl;
            m_object->SetAngleY(1, angle);
        }
        else
        {
            m_phase    = ARAP_SEARCH;
            m_progress = 0.0f;
            m_speed    = 1.0f/3.0f;
        }
    }

    angle = -m_aTime*2.0f;
    m_object->SetAngleY(2, angle);

    angle = sinf(m_aTime*4.0f)*0.3f;
    m_object->SetAngleX(3, angle);

    return true;
}