コード例 #1
0
        private void AttackTarget(MySmallShipBot bot, bool targetVisible)
        {
            Vector3 botToTarget          = m_target.WorldVolume.Center - bot.GetPosition();
            float   distance             = botToTarget.Length() - m_target.WorldVolume.Radius;
            Vector3 botToTargetDirection = botToTarget / distance;
            float   angleToTarget        = (float)Math.Acos(MathHelper.Clamp(Vector3.Dot(bot.WorldMatrix.Forward, botToTargetDirection), -1, 1));

            switch (m_state)
            {
            case StateEnum.CLOSING:
                if (distance > MANEUVERING_RANGE || m_forcedClosingTimer > 0)
                {
                    bot.Move(GetTargetPositionByDamageRatio(bot), m_target.GetPosition(), GetUpPlane(), true);
                    m_closingTimer       += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                    m_forcedClosingTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;

                    if (distance < FIRING_RANGE_MAX)
                    {
                        HandleShooting(bot, distance, angleToTarget, m_targetVisible);
                    }

                    if (m_closingTimer >= CLOSING_FORMATION_TIME)
                    {
                        SwitchToClosingInFormation();
                    }
                }
                else
                {
                    SwitchToAttack(bot);
                }

                break;

            case StateEnum.CLOSING_IN_FORMATION:
                if (distance > MANEUVERING_RANGE || m_forcedClosingTimer > 0)
                {
                    Vector3 formationTarget = MyAttackFormations.Instance.GetFormationPosition(bot, m_target);
                    m_closingTimer       += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                    m_forcedClosingTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;

                    if (distance < FIRING_RANGE_MAX)
                    {
                        bot.Move(formationTarget, m_target.GetPosition(), GetUpPlane(), true);
                        HandleShooting(bot, distance, angleToTarget, m_targetVisible);
                    }
                    else
                    {
                        bot.Move(formationTarget, formationTarget, GetUpPlane(), true);
                    }
                }
                else
                {
                    MyAttackFormations.Instance.RemoveEntity(bot);
                    SwitchToAttack(bot);
                }

                if (distance < FIRING_RANGE_MAX)
                {
                    HandleShooting(bot, distance, angleToTarget, m_targetVisible);
                }
                break;

            case StateEnum.FLYING_AROUND:
                float flyToDistance = Vector3.Distance(bot.GetPosition(), m_flyToTarget);

                if (m_strafe)
                {
                    float rspeed = (1.0f - Math.Abs(MathHelper.Clamp(angleToTarget / MathHelper.Pi, -1, 1))) * 900 + 100;

                    //bot.Move(m_flyToTarget, m_target.GetPosition(), GetUpPlane(), false, customDamping: 0.35f,
                    //    rotationSpeed: rspeed);
                    bot.Move(bot.GetPosition(), GetTargetPositionByDamageRatio(bot), GetUpPlane(), false, customDamping: 0.35f,
                             rotationSpeed: rspeed);
                }
                else
                {
                    float factor = MathHelper.Clamp(flyToDistance / 20, 0.15f, 0.45f);
                    //factor = factor * factor * factor;
                    bot.Move(m_flyToTarget, m_flyToTarget, GetUpPlane(), false, 1, 5, factor, slowRotation: true);
                }

                HandleShooting(bot, distance, angleToTarget, targetVisible);

                if (flyToDistance < 10 || m_flyAroundTimer < 0)
                {
                    if (distance > MANEUVERING_RANGE)
                    {
                        SwitchToClosing();
                    }
                    else
                    {
                        SwitchToAttack(bot);
                    }
                }

                m_flyAroundTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                break;

            case StateEnum.ATTACKING:
                // Handle hologram target, if bot is atacking hologram for 5 seconds he will get it's a hologram
                MySmallShip smallShip = m_target as MySmallShip;
                if (smallShip != null && smallShip.IsHologram)
                {
                    m_hologramTargetTimer += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                    if (m_hologramTargetTimer > 5.0f)
                    {
                        bot.SpoilHologram(smallShip);
                    }
                }

                //bot.Move(bot.GetPosition(), m_target.GetPosition(), GetUpPlane(), false, rotationSpeed: 100);
                bot.Move(bot.GetPosition(), GetTargetPositionByDamageRatio(bot), GetUpPlane(), false, rotationSpeed: 100);

                if (m_attackTimer < 0)
                {
                    if (distance > MANEUVERING_RANGE)
                    {
                        SwitchToClosing();
                    }
                    else
                    {
                        if (!MyFakes.DISABLE_BOT_MANEUVERING)
                        {
                            TrySwitchToAttackSearch(bot);
                        }
                    }
                }
                m_attackTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;

                HandleShooting(bot, distance, angleToTarget, targetVisible);
                break;

            case StateEnum.ATACKING_SEARCHING:
                //bot.Move(bot.GetPosition(), m_target.GetPosition(), GetUpPlane(), false, rotationSpeed: 100);
                bot.Move(bot.GetPosition(), GetTargetPositionByDamageRatio(bot), GetUpPlane(), false, rotationSpeed: 100);

                TrySwitchToFlyAround(bot);

                HandleShooting(bot, distance, angleToTarget, targetVisible);
                break;
            }
        }
コード例 #2
0
        private void AttackTarget(MySmallShipBot bot, bool targetVisible)
        {
            Vector3 botToTarget = m_target.WorldVolume.Center - bot.GetPosition();
            float distance = botToTarget.Length() - m_target.WorldVolume.Radius;
            Vector3 botToTargetDirection = botToTarget / distance;
            float angleToTarget = (float)Math.Acos(MathHelper.Clamp(Vector3.Dot(bot.WorldMatrix.Forward, botToTargetDirection), -1, 1));

            switch (m_state)
            {
                case StateEnum.CLOSING:
                    if (distance > MANEUVERING_RANGE || m_forcedClosingTimer > 0)
                    {
                        bot.Move(GetTargetPositionByDamageRatio(bot), m_target.GetPosition(), GetUpPlane(), true);                        
                        m_closingTimer += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                        m_forcedClosingTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;

                        if (distance < FIRING_RANGE_MAX)
                        {
                            HandleShooting(bot, distance, angleToTarget, m_targetVisible);
                        }

                        if (m_closingTimer >= CLOSING_FORMATION_TIME)
                        {
                            SwitchToClosingInFormation();
                        }
                    }
                    else
                    {
                        SwitchToAttack(bot);
                    }

                    break;
                case StateEnum.CLOSING_IN_FORMATION:
                    if (distance > MANEUVERING_RANGE || m_forcedClosingTimer > 0)
                    {
                        Vector3 formationTarget = MyAttackFormations.Instance.GetFormationPosition(bot, m_target);
                        m_closingTimer += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                        m_forcedClosingTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                        
                        if (distance < FIRING_RANGE_MAX)
                        {
                            bot.Move(formationTarget, m_target.GetPosition(), GetUpPlane(), true);
                            HandleShooting(bot, distance, angleToTarget, m_targetVisible);
                        }
                        else
	                    {
                            bot.Move(formationTarget, formationTarget, GetUpPlane(), true);
	                    }
                    }
                    else
                    {
                        MyAttackFormations.Instance.RemoveEntity(bot);
                        SwitchToAttack(bot);
                    }

                    if (distance < FIRING_RANGE_MAX)
                    {
                        HandleShooting(bot, distance, angleToTarget, m_targetVisible);
                    }
                    break;
                case StateEnum.FLYING_AROUND:
                    float flyToDistance = Vector3.Distance(bot.GetPosition(), m_flyToTarget);

                    if (m_strafe)
                    {
                        float rspeed = (1.0f - Math.Abs(MathHelper.Clamp(angleToTarget / MathHelper.Pi, -1, 1))) * 900 + 100;

                        //bot.Move(m_flyToTarget, m_target.GetPosition(), GetUpPlane(), false, customDamping: 0.35f,
                        //    rotationSpeed: rspeed);
                        bot.Move(bot.GetPosition(), GetTargetPositionByDamageRatio(bot), GetUpPlane(), false, customDamping: 0.35f,
                            rotationSpeed: rspeed);
                    }
                    else
                    {
                        float factor = MathHelper.Clamp(flyToDistance / 20, 0.15f, 0.45f);
                        //factor = factor * factor * factor;
                        bot.Move(m_flyToTarget, m_flyToTarget, GetUpPlane(), false, 1, 5, factor, slowRotation: true);
                    }

                    HandleShooting(bot, distance, angleToTarget, targetVisible);

                    if (flyToDistance < 10 || m_flyAroundTimer < 0)
                    {
                        if (distance > MANEUVERING_RANGE)
                        {
                            SwitchToClosing();
                        }
                        else
                        {
                            SwitchToAttack(bot);
                        }
                    }

                    m_flyAroundTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                    break;
                case StateEnum.ATTACKING:
                    // Handle hologram target, if bot is atacking hologram for 5 seconds he will get it's a hologram
                    MySmallShip smallShip = m_target as MySmallShip;
                    if (smallShip != null && smallShip.IsHologram)
                    {
                        m_hologramTargetTimer += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                        if (m_hologramTargetTimer > 5.0f)
                        {
                            bot.SpoilHologram(smallShip);
                        }
                    }

                    //bot.Move(bot.GetPosition(), m_target.GetPosition(), GetUpPlane(), false, rotationSpeed: 100);
                    bot.Move(bot.GetPosition(), GetTargetPositionByDamageRatio(bot), GetUpPlane(), false, rotationSpeed: 100);                    

                    if (m_attackTimer < 0)
                    {
                        if (distance > MANEUVERING_RANGE)
                        {
                            SwitchToClosing();
                        }
                        else
                        {
                            if (!MyFakes.DISABLE_BOT_MANEUVERING)
                            {
                                TrySwitchToAttackSearch(bot);
                            }
                        }
                    }
                    m_attackTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;

                    HandleShooting(bot, distance, angleToTarget, targetVisible);
                    break;
                case StateEnum.ATACKING_SEARCHING:
                    //bot.Move(bot.GetPosition(), m_target.GetPosition(), GetUpPlane(), false, rotationSpeed: 100);
                    bot.Move(bot.GetPosition(), GetTargetPositionByDamageRatio(bot), GetUpPlane(), false, rotationSpeed: 100);

                    TrySwitchToFlyAround(bot);

                    HandleShooting(bot, distance, angleToTarget, targetVisible);
                    break;
            }
        }