Esempio n. 1
0
        public override void Move()
        {
            //Log.DebugLog("entered");

            if (m_enemy == null)
            {
                m_mover.StopMove();
                return;
            }

            m_mover.Thrust.Update();
            m_approaching = m_mover.SignificantGravity() && !m_navSet.DistanceLessThan(3000f);
            if (m_approaching)
            {
                m_pathfinder.MoveTo(m_enemy);
                return;
            }

            float myAccel = m_mover.Thrust.GetForceInDirection(Base6Directions.GetClosestDirection(m_mover.Thrust.Standard.LocalMatrix.Forward)) * Movement.Mover.AvailableForceRatio / m_controlBlock.Physics.Mass;

            Vector3D enemyPosition = m_enemy.GetPosition();
            Vector3  aimDirection;
            Vector3D contactPoint;

            TargetingBase.FindInterceptVector(m_controlBlock.Pseudo.WorldPosition, m_controlBlock.Physics.LinearVelocity, enemyPosition, m_enemy.GetLinearVelocity(), myAccel, true, out aimDirection, out contactPoint);
            Vector3 aimVelo; Vector3.Multiply(ref aimDirection, myAccel, out aimVelo);

            Vector3 linearVelocity = m_controlBlock.Physics.LinearVelocity;
            Vector3 addToVelocity; Vector3.Add(ref linearVelocity, ref aimVelo, out addToVelocity);

            m_pathfinder.MoveTo(m_enemy, addToVelocity: addToVelocity);
        }
Esempio n. 2
0
        public override void Move()
        {
            Log.DebugLog("entered");

            if (m_enemy == null)
            {
                m_mover.StopMove();
                return;
            }

            Vector3D position     = m_mover.Block.CubeBlock.GetPosition();
            Vector3D flyDirection = position - m_enemy.GetPosition();

            flyDirection.Normalize();

            Destination destination = new Destination(position + flyDirection * 1e6);

            m_pathfinder.MoveTo(destinations: destination);
        }
Esempio n. 3
0
        private bool CanTarget(LastSeen seen)
        {
            try
            {
                // if it is too far from start, cannot target
                if (MaximumRange > 1f && Vector3.DistanceSquared(m_startPosition, seen.GetPosition()) > MaximumRange * MaximumRange)
                {
                    Log.DebugLog("out of range: " + seen.Entity.getBestName());
                    if (m_reason < ReasonCannotTarget.Too_Far)
                    {
                        m_reason   = ReasonCannotTarget.Too_Far;
                        m_bestGrid = seen;
                    }
                    return(false);
                }

                // if it is too fast, cannot target
                float speedTarget = m_navSet.Settings_Task_NavEngage.SpeedTarget - 1f;
                if (seen.GetLinearVelocity().LengthSquared() >= speedTarget * speedTarget)
                {
                    Log.DebugLog("too fast to target: " + seen.Entity.getBestName() + ", speed: " + seen.GetLinearVelocity().Length() + ", my speed: " + m_navSet.Settings_Task_NavEngage.SpeedTarget);
                    if (m_reason < ReasonCannotTarget.Too_Fast)
                    {
                        m_reason   = ReasonCannotTarget.Too_Fast;
                        m_bestGrid = seen;
                    }
                    return(false);
                }

                if (GridCondition != null && !GridCondition(seen.Entity as IMyCubeGrid))
                {
                    Log.DebugLog("Failed grid condition: " + seen.Entity.getBestName());
                    if (m_reason < ReasonCannotTarget.Grid_Condition)
                    {
                        m_reason   = ReasonCannotTarget.Grid_Condition;
                        m_bestGrid = seen;
                    }
                    return(false);
                }

                m_bestGrid = seen;
                return(true);
            }
            catch (NullReferenceException nre)
            {
                Log.AlwaysLog("Exception: " + nre, Logger.severity.ERROR);

                if (!seen.Entity.Closed)
                {
                    throw;
                }
                Log.DebugLog("Caught exception caused by grid closing, ignoring.");
                return(false);
            }
        }
Esempio n. 4
0
        public override void Move()
        {
            if (!m_weaponArmed)
            {
                m_mover.StopMove();
                return;
            }

            if (m_weapon_primary == null || m_weapon_primary.CubeBlock.Closed)
            {
                Log.DebugLog("no primary weapon");
                m_mover.StopMove();
                return;
            }

            if (m_currentTarget == null)
            {
                m_mover.StopMove();
                return;
            }

            if (m_orbiter == null)
            {
                if (m_navSet.DistanceLessThan(m_weaponRange_min * 2f))
                {
                    // we give orbiter a lower distance, so it will calculate orbital speed from that
                    m_orbiter = new Orbiter(m_pathfinder, m_navSet, m_currentTarget.Entity, m_weaponRange_min + FinalAltitude, m_currentTarget.HostileName());
                    // start further out so we can spiral inwards
                    m_finalOrbitAltitude = m_orbiter.Altitude;
                    m_orbiter.Altitude   = m_finalOrbitAltitude + InitialAltitude - FinalAltitude;
                    Log.DebugLog("weapon range: " + m_weaponRange_min + ", final orbit altitude: " + m_finalOrbitAltitude + ", initial orbit altitude: " + m_orbiter.Altitude, Logger.severity.DEBUG);
                }
                else
                {
                    m_mover.Thrust.Update();
                    Vector3 direction = m_mover.SignificantGravity() ?
                                        (Vector3)m_mover.Thrust.WorldGravity / -m_mover.Thrust.GravityStrength :
                                        Vector3.CalculatePerpendicularVector(Vector3.Normalize(m_weapon_primary_pseudo.WorldPosition - m_currentTarget.GetPosition()));
                    Vector3 offset = direction * (m_weaponRange_min + InitialAltitude);

                    m_pathfinder.MoveTo(m_currentTarget, offset);
                    return;
                }
            }

            Target current = m_weapon_primary.CurrentTarget;

            if ((current == null || current.Entity == null) && m_orbiter.Altitude > m_finalOrbitAltitude && m_navSet.DistanceLessThan(m_orbiter.OrbitSpeed * 0.5f))
            {
                Log.DebugLog("weapon range: " + m_weaponRange_min + ", final orbit altitude: " + m_finalOrbitAltitude + ", initial orbit altitude: " + m_orbiter.Altitude +
                             ", dist: " + m_navSet.Settings_Current.Distance + ", orbit speed: " + m_orbiter.OrbitSpeed, Logger.severity.TRACE);
                m_orbiter.Altitude -= 10f;
            }

            m_orbiter.Move();

            ////Log.DebugLog("moving to " + (m_currentTarget.predictPosition() + m_currentOffset), "Move()");
            //m_mover.CalcMove(m_weapon_primary_pseudo, m_currentTarget.GetPosition() + m_currentOffset, m_currentTarget.GetLinearVelocity());
        }