public MySeeEnemyDesire(MyEntity enemy)
     : base(BotDesireType.SEE_ENEMY)
 {
     System.Diagnostics.Debug.Assert(!enemy.Closed);
     Enemy   = enemy.GetBaseEntity();
     invalid = false;
 }
Beispiel #2
0
        /// <summary>
        /// Starts retreiving items, connection needs to be established within 200 updates of invoking this function.
        /// </summary>
        public void Start()
        {
            Log.DebugLog("shopper started");
            m_navSet.Shopper = null;

            this.m_grid.GetBlocks_Safe(null, slim => {
                MyEntity entity = slim.FatBlock as MyEntity;
                if (entity != null && entity is Sandbox.ModAPI.Ingame.IMyCargoContainer)
                {
                    Log.DebugLog("entity: " + entity.GetBaseEntity().getBestName() + ", inventories: " + entity.InventoryCount);
                    int count = entity.InventoryCount;
                    for (int i = 0; i < count; i++)
                    {
                        m_destInventory.Add(entity.GetInventory(i));
                    }
                }
                return(false);
            });

            if (m_destInventory.Count == 0)
            {
                Log.DebugLog("no dest inventory");
                return;
            }

            m_navSet.Settings_Task_NavWay.NavigatorMover            = this;
            m_navSet.Settings_Task_NavWay.PathfinderCanChangeCourse = false;

            m_nextUpdate = Globals.UpdateCount + 200ul;             // give attached a chance to be registered before FindSourceInventory
        }
        public MyCuriousDesire(MyEntity entity, Vector3 location)
            : base(BotDesireType.CURIOUS)
        {
            if (entity != null)
                EntityID = entity.GetBaseEntity().EntityId;
            Location = location;

            System.Diagnostics.Debug.Assert(entity == null || !entity.Closed);
        }
        public MyCuriousDesire(MyEntity entity, Vector3 location)
            : base(BotDesireType.CURIOUS)
        {
            if (entity != null)
            {
                EntityID = entity.GetBaseEntity().EntityId;
            }
            Location = location;

            System.Diagnostics.Debug.Assert(entity == null || !entity.Closed);
        }
Beispiel #5
0
 public MyKillDesire(MyEntity target)
     : base(BotDesireType.KILL)
 {
     Target = target.GetBaseEntity();
 }
        public void DoWork()
        {
            //  Search for target to attack
            ClosestEnemy  = null;
            ClosestVisual = null;

            float distanceSqr              = m_seeDistance * m_seeDistance;
            float closestEnemyDistanceSqr  = float.PositiveInfinity;
            float closestVisualDistanceSqr = float.PositiveInfinity;

            using (var rbFounded = PoolList <MyRBElement> .Get())
            {
                try
                {
                    MyEntities.EntityCloseLock.AcquireShared();

                    MyDynamicAABBTree prunningStructure = MyPhysics.physicsSystem.GetRigidBodyModule().GetPruningStructure();

                    BoundingBox rbInputElementGetWorldSpaceAABB = new BoundingBox(
                        m_botWorldMatrix.Translation - new Vector3(m_seeDistance),
                        m_botWorldMatrix.Translation + new Vector3(m_seeDistance));
                    prunningStructure.OverlapAllBoundingBox(ref rbInputElementGetWorldSpaceAABB, rbFounded, (uint)MyElementFlag.EF_RB_ELEMENT);

                    //now try find spot
                    foreach (MyRBElement rb in rbFounded)
                    {
                        if (m_bot == null)
                        {
                            return;
                        }

                        var rigidBody = rb.GetRigidBody();
                        if (rigidBody == null)
                        {
                            continue;
                        }

                        MyEntity entity = ((MyPhysicsBody)rigidBody.m_UserData).Entity;
                        if (entity == m_bot || entity == null || entity.AIPriority == -1)
                        {
                            continue;
                        }


                        entity = entity.GetBaseEntity();    // Large weapons

                        // Ignore spoiled holograms
                        if (m_bot.IsSpoiledHologram(entity))
                        {
                            continue;
                        }

                        // Don't attack disabled weapons
                        MyPrefabLargeWeapon largeWeapon = entity as MyPrefabLargeWeapon;
                        MySmallShip         smallShip   = entity as MySmallShip;
                        MyPrefabLargeShip   largeShip   = entity as MyPrefabLargeShip;

                        if (largeWeapon != null && !largeWeapon.IsWorking())
                        {
                            continue;
                        }

                        // Test smallships and largeweapons
                        if (smallShip != null || largeWeapon != null || largeShip != null)
                        {
                            // Is enemy?
                            if (MyFactions.GetFactionsRelation(m_bot, entity) == MyFactionRelationEnum.Enemy && CanSeeTarget(m_bot, entity))
                            {
                                var entityDistanceSqr = Vector3.DistanceSquared(entity.GetPosition(), m_position);

                                if (entityDistanceSqr < distanceSqr &&
                                    (ClosestEnemy == null || entity.AIPriority >= ClosestEnemy.AIPriority) &&
                                    (entityDistanceSqr < closestEnemyDistanceSqr || entity.AIPriority > ClosestEnemy.AIPriority))
                                {
                                    MyLine line   = new MyLine(m_position, entity.GetPosition(), true);
                                    var    result = MyEntities.GetIntersectionWithLine(ref line, m_bot, entity, true, ignoreChilds: true);
                                    if (!result.HasValue)
                                    {
                                        // Visual Detection - ignore visualy detected targets if they are further than any normaly detected target
                                        if (IsVisualyDetected(smallShip))
                                        {
                                            if (entityDistanceSqr < closestVisualDistanceSqr)
                                            {
                                                ClosestVisual            = entity;
                                                closestVisualDistanceSqr = entityDistanceSqr;
                                            }
                                        }
                                        else
                                        {
                                            closestEnemyDistanceSqr = entityDistanceSqr;
                                            ClosestEnemy            = entity;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    MyEntities.EntityCloseLock.ReleaseShared();
                }
            }
        }
 public MyAttackedByEnemyDesire(MyEntity damageSource)
     : base(BotDesireType.ATACKED_BY_ENEMY)
 {
     DamageSource = damageSource.GetBaseEntity();
 }
 public MyAttackedByEnemyDesire(MyEntity damageSource)
     : base(BotDesireType.ATACKED_BY_ENEMY)
 {
     DamageSource = damageSource.GetBaseEntity();
 }
Beispiel #9
0
 public MyKillDesire(MyEntity target)
     : base(BotDesireType.KILL)
 {
     Target = target.GetBaseEntity();
 }