void SwitchToAttack(MySmallShipBot bot)
        {
            m_state       = StateEnum.ATTACKING;
            m_attackTimer = MyMwcUtils.GetRandomFloat(2, 4);

            MyBotCoordinator.AddAttacker(bot, m_target);
        }
        internal override void Close(MySmallShipBot bot)
        {
            base.Close(bot);

            if (m_state == StateEnum.CLOSING_IN_FORMATION)
            {
                MyAttackFormations.Instance.RemoveEntity(bot);
            }

            MyBotCoordinator.RemoveAttacker(bot);
        }
        void HandleShooting(MySmallShipBot bot, float distance, float angleToTarget, bool targetVisible)
        {
            if (bot.InitTime > 0)
            {
                return;
            }

            if (!MyBotCoordinator.IsAllowedToAttack(bot, m_target))
            {
                return;
            }

            m_smokeBombTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
            m_flashBombTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
            m_hologramTimer  -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;

            // Change weapon - 2sec CD
            if (m_weaponChangeTimer < 2)
            {
                m_weaponChangeTimer = 0;

                var oldWeapon = m_currentWeapon;
                m_currentWeapon = SelectWeapon(distance);

                if (m_currentWeapon != oldWeapon)
                {
                    m_fireState = FireStateEnum.WAIT;
                }
            }

            // Handle weapon shooting
            switch (m_currentWeapon)
            {
            case MyMwcObjectBuilder_FireKeyEnum.Primary:
                ShootAutocannon(bot, targetVisible, distance, angleToTarget);
                break;

            case MyMwcObjectBuilder_FireKeyEnum.Secondary:
                ShootShotgun(bot, targetVisible, distance, angleToTarget);
                break;

            case MyMwcObjectBuilder_FireKeyEnum.Third:
                ShootSniper(bot, targetVisible, distance, angleToTarget);
                break;
            }

            if (MyFakes.ENABLE_BOT_MISSILES_AND_CANNON)
            {
                if (m_canShootFlash &&
                    m_flashBombTimer <= 0 &&
                    targetVisible &&
                    distance > 125 && distance < 250 &&
                    angleToTarget < SHOOT_CONE)
                {
                    m_flashBombTimer = MyMwcUtils.GetRandomFloat(30, 60);
                    bot.Shoot(MyMwcObjectBuilder_FireKeyEnum.FlashBombFront);
                }

                if (m_canShootSmoke &&
                    m_smokeBombTimer <= 0 &&
                    targetVisible &&
                    distance > 150 && distance < 300 &&
                    angleToTarget < SHOOT_CONE)
                {
                    m_smokeBombTimer = MyMwcUtils.GetRandomFloat(30, 60);
                    bot.Shoot(MyMwcObjectBuilder_FireKeyEnum.SmokeBombFront);
                }

                if (m_canShootHologram &&
                    m_hologramTimer <= 0 &&
                    distance > 100 && distance < 500)
                {
                    m_hologramTimer = MyMwcUtils.GetRandomFloat(30, 60);
                    bot.Shoot(MyMwcObjectBuilder_FireKeyEnum.HologramFront);
                }

                // Handle missile and cannon shooting
                if (m_canShootMissile || m_canShootCannon)
                {
                    MyMwcObjectBuilder_FireKeyEnum firekey;
                    if (m_canShootMissile)
                    {
                        firekey = MyMwcObjectBuilder_FireKeyEnum.Fourth;
                    }
                    else
                    {
                        firekey = MyMwcObjectBuilder_FireKeyEnum.Fifth;
                    }

                    int missileFireTime = MyMinerGame.TotalGamePlayTimeInMilliseconds - m_planedMissileTime;
                    if (missileFireTime > 0)
                    {
                        if (missileFireTime > 1500)
                        {
                            // if bot can't shoot in 1.5 sec, wait for next time window
                            PlanNextMissile();
                        }
                        else if (targetVisible &&
                                 distance >= MyFakes.BOT_MISSILE_FIRING_RANGE_MIN &&
                                 distance <= FIRING_RANGE_MAX &&
                                 angleToTarget < SHOOT_CONE)
                        {
                            // Successful shot
                            bot.Shoot(firekey);
                            PlanNextMissile();
                        }
                    }
                }
            }
        }