Exemple #1
0
void CBoidBird::CalcMovementBird(float dt,SBoidContext& bc,bool banking)
{
	// correct heading, can't be too vertical
	// do only some rough linear computation for optimization

	if(m_status == Bird::ON_GROUND)
	{
		if(bc.walkSpeed <= 0)
		{
			m_accel.zero();
			m_speed = 0;
			m_currentAccel.zero();
			Interpolate(m_pos,m_landingPoint, 2.0f,dt);
			return;
		}
		// Avoid obstacles & terrain.
		IPhysicalWorld *physWorld = bc.physics;

		Vec3 vDir0 = m_heading*bc.fBoidRadius*0.5f;
		Vec3 vPos = m_pos;
		vPos.z += bc.fBoidRadius*0.5f;
		Vec3 vDir(0,0,bc.fBoidRadius*1.5f);

		m_floorCollisionInfo.QueueRaycast(m_entity,vPos,vDir);
	}

	// check current raycast result
	if(m_floorCollisionInfo.IsColliding())
	{
		m_heading.z = 0;
	}

	static const float maxZ = sinf(gf_PI/4);
	static const float coeffXY = cosf(gf_PI/4);

	if(m_heading.z > maxZ)
	{
		float l = m_heading.GetLength2D();
		m_heading.x *= coeffXY/l;
		m_heading.y *= coeffXY/l;
		m_heading.z = maxZ;
		m_heading.NormalizeFast();
	}

	CBoidObject::CalcMovement(dt, bc, banking);


	if(m_floorCollisionInfo.IsColliding())
	{
		float minZ = m_floorCollisionInfo.Point().z;
		m_pos.z = minZ +bc.groundOffset ;
	}

	UpdateAnimationSpeed(bc);

}
void CChickenBoid::Update(float dt,SBoidContext &bc)
{
	if(m_physicsControlled)
	{
		UpdatePhysics(dt,bc);

		if(m_bThrown && m_pPhysics)
		{
			pe_status_awake tmp;
			bool bAwake = m_pPhysics->GetStatus(&tmp) != 0;

			if(!bAwake)
			{
				// Falled on ground after being thrown.
				m_bThrown = false;
				m_physicsControlled = false;
			}
		}

		return;
	}

	if(m_dead)
		return;

	m_lastThinkTime += dt;

	if(bc.waterLevel > bc.terrainZ)
		bc.terrainZ = bc.waterLevel;

	if(bc.followPlayer)
	{
		if(m_pos.GetSquaredDistance(bc.playerPos) > MAX_CHICKEN_DISTANCE_FROM_PLAYER*MAX_CHICKEN_DISTANCE_FROM_PLAYER)
		{
			float z = bc.MinHeight + (Boid::Frand()+1)/2.0f*(bc.MaxHeight - bc.MinHeight);
			m_pos = bc.playerPos + Vec3(Boid::Frand()*MAX_CHICKEN_DISTANCE_FROM_PLAYER,Boid::Frand()*MAX_CHICKEN_DISTANCE_FROM_PLAYER,z);
			m_pos.z = bc.engine->GetTerrainElevation(m_pos.x,m_pos.y) + bc.fBoidRadius*0.5f;
			m_speed = bc.MinSpeed;
			m_heading = Vec3(Boid::Frand(),Boid::Frand(),0).GetNormalized();
		}
	}

	Think(dt,bc);

	if(!m_landing)
	{
		// Calc movement with current velocity.
		CalcMovement(dt,bc,true);

		UpdateAnimationSpeed(bc);
		m_accel.Set(0,0,0);
	}
}
Exemple #3
0
int KRLRemoteCharacter::Update(double fTime, double fTimeLast, DWORD dwGameLoop, BOOL bFrame)
{
    int nRetCode = false;
    int nResult = false;
    HRESULT hr = E_FAIL;
    RL_ANIMATION_DOWN nAnimationDown = RL_ANIMATION_DOWN_NONE;
    RL_ADVANCE nAdvance = RL_ADVANCE_FORWARD;

    if (m_RLCharacter.m_RenderData.HasLoadedMDL())
    {
        if (!m_RLCharacter.IsFadeOut() && m_FrameData.m_pCharacter)
        {
            if (bFrame)
            {
                m_FrameData.UpdateRepresentFrameData(
                    m_RLCharacter.m_RenderData.IsVisible(), 
                    m_FrameData.GetCurrentPosition());
            }

            nRetCode = m_FrameData.Interpolate(m_RLCharacter.m_RenderData.IsVisible(), false);
            KGLOG_PROCESS_ERROR(nRetCode);

            nRetCode = UpdatePosition(FALSE);
            KGLOG_PROCESS_ERROR(nRetCode);

            if (bFrame)
            {
				nRetCode = UpdateYaw(&nAdvance);
				KGLOG_PROCESS_ERROR(nRetCode);
            }

            nRetCode = UpdateDirection(TRUE);
            KGLOG_PROCESS_ERROR(nRetCode);

            if (bFrame)
            {
                nRetCode = UpdateSheath();
                KGLOG_PROCESS_ERROR(nRetCode);

	            nAnimationDown = GetRLAnimationDown(
	                m_FrameData.m_Current.nMoveState, 
	                m_FrameData.m_Current.nOTAction,
	                m_FrameData.m_Current.nJumpCount,
	                m_nTurning);

                if (m_RLCharacter.m_bAnimationPaused && nAnimationDown != RL_ANIMATION_DOWN_FREEZE)
                    m_RLCharacter.PauseAnimation(FALSE);

                nRetCode = UpdateAnimationUp();
                KGLOG_PROCESS_ERROR(nRetCode);

                nRetCode = m_RLCharacter.UpdateVehicle(
                    m_FrameData.m_Current.nVehicleTrack, 
                    FALSE);
                KGLOG_PROCESS_ERROR(nRetCode);

                nRetCode = m_RLCharacter.UpdateAnimationDown(nAnimationDown, nAdvance,
                    m_FrameData.m_Current.bSlip,
                    m_FrameData.m_Current.nFightFlag,
                    m_FrameData.m_Current.dwSkillBuffs);
                KGLOG_PROCESS_ERROR(nRetCode);

                UpdateLifeState(FALSE);
                
                UpdateAnimationSpeed(nAnimationDown, nAdvance);
            }
        }

        if (bFrame)
        {
            m_RLCharacter.UpdateFade();

            hr = m_RLCharacter.m_RenderData.Update();
            KGLOG_COM_PROCESS_ERROR(hr);

            if (!IS_PLAYER(m_RLCharacter.GetObjectID()))
            {
                BOOL bSelectable = m_RLCharacter.m_RenderData.IsMDLSelectable();

                if (nAnimationDown == RL_ANIMATION_DOWN_DEATH && bSelectable)
                {
                    nRetCode = m_RLCharacter.SetSelectable(FALSE);
                    KGLOG_PROCESS_ERROR(nRetCode);
                } 
                else if (nAnimationDown != RL_ANIMATION_DOWN_DEATH && 
                    !bSelectable && 
                    m_FrameData.m_pCharacter)
                {
                    nRetCode = m_RLCharacter.ResetSelectable();
                    KGLOG_PROCESS_ERROR(nRetCode);
                }
            }
        }
    }

    nResult = true;
Exit0:
    return nResult;
}
Exemple #4
0
int KRLLocalCharacter::Update(double fTime, double fTimeLast, DWORD dwGameLoop, BOOL bFrame)
{
    int nRetCode = false;
    int nResult = false;
    HRESULT hr = E_FAIL;
    RL_ANIMATION_UP nAnimationUp = RL_ANIMATION_UP_NONE;
    RL_ANIMATION_DOWN nAnimationDown = RL_ANIMATION_DOWN_NONE;
    RL_ADVANCE nAdvance = RL_ADVANCE_FORWARD;

    ASSERT(!m_RLCharacter.IsFadeOut());

    if (m_RLCharacter.m_RenderData.HasLoadedMDL())
    {
        if (bFrame)
        {
            m_RLCharacter.m_FrameData.UpdateRepresentFrameData(TRUE);

            if (m_bSheath != m_RLCharacter.m_FrameData.m_Current.bSheathFlag)
            {
                m_bSheath = m_RLCharacter.m_FrameData.m_Current.bSheathFlag;
                m_RLCharacter.UpdateSheath(m_bSheath);
            }
        }

        nRetCode = m_RLCharacter.m_FrameData.Interpolate(m_RLCharacter.m_RenderData.IsVisible(), false);
        KGLOG_PROCESS_ERROR(nRetCode);

        nRetCode = UpdatePosition();
        KGLOG_PROCESS_ERROR(nRetCode);

        nRetCode = UpdateDirection();
        KGLOG_PROCESS_ERROR(nRetCode);

        nAnimationDown = GetRLAnimationDown(
                             m_RLCharacter.m_FrameData.m_Current.nMoveState,
                             m_RLCharacter.m_FrameData.m_Current.nOTAction,
                             m_RLCharacter.m_FrameData.m_Current.nJumpCount,
                             m_nTurning);

        nAdvance = GetAdvance(nAnimationDown);

        nRetCode = UpdateListener();
        KGLOG_PROCESS_ERROR(nRetCode);

        if (bFrame)
        {
            if (m_RLCharacter.m_bAnimationPaused && nAnimationDown != RL_ANIMATION_DOWN_FREEZE)
                m_RLCharacter.PauseAnimation(FALSE);

            nAnimationUp = GetRLAnimationUp(m_RLCharacter.m_FrameData.m_Current.nOTAction);

            if (nAnimationUp == RL_ANIMATION_UP_NONE && m_nAnimationUp != RL_ANIMATION_UP_NONE ||
                    nAnimationUp != RL_ANIMATION_UP_NONE)
            {
                nRetCode = m_RLCharacter.UpdateAnimationUp(nAnimationUp);
                KGLOG_PROCESS_ERROR(nRetCode);

                m_nAnimationUp = nAnimationUp;
            }

            nRetCode = m_RLCharacter.UpdateVehicle(
                           m_RLCharacter.m_FrameData.m_Current.nVehicleTrack,
                           FALSE);
            KGLOG_PROCESS_ERROR(nRetCode);

            nRetCode = m_RLCharacter.UpdateAnimationDown(nAnimationDown, nAdvance,
                       m_RLCharacter.m_FrameData.m_Current.nFightFlag,
                       m_RLCharacter.m_FrameData.m_Current.dwSkillBuffs);
            KGLOG_PROCESS_ERROR(nRetCode);

            UpdateLifeState();

            UpdateAnimationSpeed(nAnimationDown, nAdvance);

            if (m_dwLockControlFrame > 0)
            {
                --m_dwLockControlFrame;
            }

            hr = m_RLCharacter.m_RenderData.Update();
            KGLOG_COM_PROCESS_ERROR(hr);
        }
    }

    nResult = true;
Exit0:
    return nResult;
}
Exemple #5
0
void CBoidBug::Update( float dt,SBoidContext &bc )
{
	if (bc.behavior == EBUGS_FROG)
	{
		UpdateFrogsBehavior( dt,bc );
		return;
	}

	if (m_onGround)
	{
		if ((Vec3(bc.playerPos.x-m_pos.x,bc.playerPos.y-m_pos.y,0).GetLengthSquared()) < BUGS_SCARE_DISTANCE*BUGS_SCARE_DISTANCE)
		{
			// Sacred by player, fast takeoff.
			m_onGround = false;
			m_heading = (m_pos - bc.playerPos).GetNormalized();
			m_heading.z = 0.3f;
			m_heading = (m_heading).GetNormalized();
			m_speed = 1;
		}
		else if (cry_random(0, 49) == 0)
		{
			// take off.
			m_onGround = false;
			m_heading.z = 0.2f;
			m_heading = (m_heading).GetNormalized();
		}
		return;
	}
	// Keep in range.
	bc.terrainZ = bc.engine->GetTerrainElevation(m_pos.x,m_pos.y);

	float range = bc.MaxAttractDistance;

	Vec3 origin = bc.flockPos;

	if (bc.followPlayer)
	{
		origin = bc.playerPos;
	}
	
	if (bc.followPlayer)
	{
		if (m_pos.x < origin.x - range)
			m_pos.x = origin.x + range;
		if (m_pos.y < origin.y - range)
			m_pos.y = origin.y + range;
		if (m_pos.x > origin.x + range)
			m_pos.x = origin.x - range;
		if (m_pos.y > origin.y + range)
			m_pos.y = origin.y - range;
	}
	else
	{
		if (bc.behavior == EBUGS_BUG || bc.behavior == EBUGS_DRAGONFLY)
		{
			if (m_pos.x < origin.x-range)
				m_accel = (origin - m_pos)*bc.factorAttractToOrigin;
			if (m_pos.y < origin.y-range)
				m_accel = (origin - m_pos)*bc.factorAttractToOrigin;
			if (m_pos.x > origin.x+range)
				m_accel = (origin - m_pos)*bc.factorAttractToOrigin;
			if (m_pos.y > origin.y+range)
				m_accel = (origin - m_pos)*bc.factorAttractToOrigin;
		}
	}

	if (bc.behavior == EBUGS_BUG)
	{
		UpdateBugsBehavior( dt,bc );
	}
	else 	if (bc.behavior == EBUGS_DRAGONFLY)
	{
		UpdateDragonflyBehavior( dt,bc );
	}
	else 	if (bc.behavior == EBUGS_FROG)
	{
		UpdateFrogsBehavior( dt,bc );
	}
	else
	{
		UpdateBugsBehavior( dt,bc );
	}

	bool bBanking = m_object != 0;
	CalcMovement( dt,bc,bBanking );
	
	UpdateAnimationSpeed(bc);

	if (m_pos.z < bc.terrainZ+0.1f)
	{
		// Land.
		m_pos.z = bc.terrainZ+0.1f;
		if (!bc.noLanding && cry_random(0, 9) == 0)
		{
			m_onGround = true;
			m_speed = 0;
			m_accel.Set(0,0,0);
		}
	}

	if (m_pos.z < bc.waterLevel)
		m_pos.z = bc.waterLevel;
}
Exemple #6
0
void CBoidBug::UpdateFrogsBehavior( float dt,SBoidContext &bc )
{
	if (m_onGround)
	{
		if ((cry_random(0, 99) == 1) ||
			((Vec3(bc.playerPos.x-m_pos.x,bc.playerPos.y-m_pos.y,0).GetLengthSquared()) < BUGS_SCARE_DISTANCE*BUGS_SCARE_DISTANCE))
		{
			// Sacred by player or random jump.
			m_onGround = false;
			m_heading = m_pos - bc.playerPos;
			if (m_heading != Vec3(0,0,0))
				m_heading = m_heading.GetNormalized();
			else
				m_heading = Vec3(Boid::Frand(),Boid::Frand(),Boid::Frand()).GetNormalized();
			m_heading.z = 0.2f + (Boid::Frand()+1.0f)*0.5f;
			m_heading += Vec3(Boid::Frand()*0.3f,Boid::Frand()*0.3f,0 );
			if (m_heading != Vec3(0,0,0))
				m_heading = m_heading.GetNormalized();
			else
				m_heading = Vec3(Boid::Frand(),Boid::Frand(),Boid::Frand()).GetNormalized();
			m_speed = bc.MaxSpeed;
		}
	}

	bc.terrainZ = bc.engine->GetTerrainElevation(m_pos.x,m_pos.y);

	float range = bc.MaxAttractDistance;

	Vec3 origin = bc.flockPos;

	if (bc.followPlayer)
	{
		origin = bc.playerPos;
	}

	// Keep in range.
	if (bc.followPlayer)
	{
		if (m_pos.x < origin.x - range)
			m_pos.x = origin.x + range;
		if (m_pos.y < origin.y - range)
			m_pos.y = origin.y + range;
		if (m_pos.x > origin.x + range)
			m_pos.x = origin.x - range;
		if (m_pos.y > origin.y + range)
			m_pos.y = origin.y - range;
	}
	else
	{
		/*
		if (bc.behavior == EBUGS_BUG || bc.behavior == EBUGS_DRAGONFLY)
		{
			if (m_pos.x < origin.x-range)
				m_accel = (origin - m_pos)*bc.factorAttractToOrigin;
			if (m_pos.y < origin.y-range)
				m_accel = (origin - m_pos)*bc.factorAttractToOrigin;
			if (m_pos.x > origin.x+range)
				m_accel = (origin - m_pos)*bc.factorAttractToOrigin;
			if (m_pos.y > origin.y+range)
				m_accel = (origin - m_pos)*bc.factorAttractToOrigin;
		}
		*/
	}
	m_accel.Set( 0,0,-10 );

	bool bBanking = m_object != 0;
	CalcMovement( dt,bc,bBanking );
	
	UpdateAnimationSpeed(bc);

	if (m_pos.z < bc.terrainZ+0.1f)
	{
		// Land.
		m_pos.z = bc.terrainZ+0.1f;
		m_onGround = true;
		m_speed = 0;
	}
}