Ejemplo n.º 1
0
        private bool CanTarget(LastSeen seen)
        {
            try
            {
                if (m_mustBeRecent && !seen.isRecent())
                {
                    m_logger.debugLog("no longer recent: " + seen.Entity.getBestName() + ", age: " + (DateTime.UtcNow - seen.LastSeenAt), "CanTarget()");
                    return false;
                }

                // if it is too far from start, cannot target
                if (MaximumRange > 1f && Vector3.DistanceSquared(m_startPosition, seen.GetPosition()) > MaximumRange * MaximumRange)
                {
                    m_logger.debugLog("out of range of start position: " + seen.Entity.getBestName(), "CanTarget()");
                    return false;
                }

                // if it is too fast, cannot target
                float speedTarget = m_navSet.Settings_Current.SpeedTarget - 1f;
                if (seen.GetLinearVelocity().LengthSquared() >= speedTarget * speedTarget)
                {
                    m_logger.debugLog("too fast to target: " + seen.Entity.getBestName(), "CanTarget()");
                    return false;
                }

                return GridCondition == null || GridCondition(seen.Entity as IMyCubeGrid);
            }
            catch (NullReferenceException nre)
            {
                m_logger.alwaysLog("Exception: " + nre, "CanTarget()", Logger.severity.ERROR);

                if (!seen.Entity.Closed)
                    throw nre;
                m_logger.debugLog("Caught exception caused by grid closing, ignoring.", "CanTarget()");
                return false;
            }
        }
Ejemplo n.º 2
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)
                {
                    m_logger.debugLog("out of range of start position: " + seen.Entity.getBestName(), "CanTarget()");
                    if (m_reason < ReasonCannotTarget.Too_Far)
                    {
                        m_reason = ReasonCannotTarget.Too_Far;
                        m_reasonGrid = seen.Entity.EntityId;
                    }
                    return false;
                }

                // if it is too fast, cannot target
                float speedTarget = m_navSet.Settings_Current.SpeedTarget - 1f;
                if (seen.GetLinearVelocity().LengthSquared() >= speedTarget * speedTarget)
                {
                    m_logger.debugLog("too fast to target: " + seen.Entity.getBestName(), "CanTarget()");
                    if (m_reason < ReasonCannotTarget.Too_Fast)
                    {
                        m_reason = ReasonCannotTarget.Too_Fast;
                        m_reasonGrid = seen.Entity.EntityId;
                    }
                    return false;
                }

                if (GridCondition != null && !GridCondition(seen.Entity as IMyCubeGrid))
                {
                    m_logger.debugLog("Failed grid condition: " + seen.Entity.getBestName(), "CanTarget()");
                    if (m_reason < ReasonCannotTarget.Grid_Condition)
                    {
                        m_reason = ReasonCannotTarget.Grid_Condition;
                        m_reasonGrid = seen.Entity.EntityId;
                    }
                    return false;
                }

                return true;
            }
            catch (NullReferenceException nre)
            {
                m_logger.alwaysLog("Exception: " + nre, "CanTarget()", Logger.severity.ERROR);

                if (!seen.Entity.Closed)
                    throw nre;
                m_logger.debugLog("Caught exception caused by grid closing, ignoring.", "CanTarget()");
                return false;
            }
        }