Exemplo n.º 1
0
        internal void GetItemsInRadius(Vector3 position, float radius, List <MyEnvironmentItems.ItemInfo> output)
        {
            double num = radius * radius;

            foreach (KeyValuePair <int, MyModelInstanceData> pair in this.m_instanceParts)
            {
                MyModelInstanceData data = pair.Value;
                using (data.InstanceBufferLock.AcquireSharedUsing())
                {
                    foreach (KeyValuePair <int, MyInstanceData> pair2 in data.InstanceData)
                    {
                        MyInstanceData data2       = pair2.Value;
                        Matrix         localMatrix = data2.LocalMatrix;
                        if (!localMatrix.EqualsFast(ref Matrix.Zero, 0.0001f))
                        {
                            Vector3D vectord = Vector3.Transform(data2.LocalMatrix.Translation, this.m_sectorMatrix);
                            if ((vectord - position).LengthSquared() < num)
                            {
                                MyEnvironmentItems.ItemInfo item = new MyEnvironmentItems.ItemInfo {
                                    LocalId   = data.InstanceIds[pair2.Key],
                                    SubtypeId = pair.Value.SubtypeId,
                                    Transform = new MyTransformD(vectord)
                                };
                                output.Add(item);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 internal void GetItems(List <MyEnvironmentItems.ItemInfo> output)
 {
     foreach (KeyValuePair <int, MyModelInstanceData> pair in this.m_instanceParts)
     {
         MyModelInstanceData data = pair.Value;
         using (data.InstanceBufferLock.AcquireSharedUsing())
         {
             foreach (KeyValuePair <int, MyInstanceData> pair2 in data.InstanceData)
             {
                 MyInstanceData data2       = pair2.Value;
                 Matrix         localMatrix = data2.LocalMatrix;
                 if (!localMatrix.EqualsFast(ref Matrix.Zero, 0.0001f))
                 {
                     MyEnvironmentItems.ItemInfo item = new MyEnvironmentItems.ItemInfo {
                         LocalId   = data.InstanceIds[pair2.Key],
                         SubtypeId = pair.Value.SubtypeId,
                         Transform = new MyTransformD(Vector3.Transform(localMatrix.Translation, this.m_sectorMatrix))
                     };
                     output.Add(item);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        public virtual bool SetTargetFromMemory(MyBBMemoryTarget memoryTarget)
        {
            if (memoryTarget.TargetType == MyAiTargetEnum.POSITION)
            {
                Debug.Assert(memoryTarget.Position.HasValue, "Position was not set correctly in memory.");
                if (!memoryTarget.Position.HasValue) return false;

                SetTargetPosition(memoryTarget.Position.Value);
                return true;
            }
            else if (memoryTarget.TargetType == MyAiTargetEnum.ENVIRONMENT_ITEM)
            {
                Debug.Assert(memoryTarget.TreeId.HasValue, "Tree id was not set correctly in memory.");
                if (!memoryTarget.TreeId.HasValue) return false;

                var tree = new MyEnvironmentItems.ItemInfo();
                tree.LocalId = memoryTarget.TreeId.Value;
                tree.Transform.Position = memoryTarget.Position.Value;
                SetTargetTree(ref tree, memoryTarget.EntityId.Value);

                return true;
            }
            else if (memoryTarget.TargetType != MyAiTargetEnum.NO_TARGET)
            {
                Debug.Assert(memoryTarget.EntityId.HasValue, "Entity id was not set correctly in memory.");
                if (!memoryTarget.EntityId.HasValue) return false;

                MyEntity entity = null;
                if (MyEntities.TryGetEntityById(memoryTarget.EntityId.Value, out entity))
                {
                    if (memoryTarget.TargetType == MyAiTargetEnum.CUBE
                        || memoryTarget.TargetType == MyAiTargetEnum.COMPOUND_BLOCK)
                    {
                        var cubeGrid = entity as MyCubeGrid;
                        var cubeBlock = cubeGrid.GetCubeBlock(memoryTarget.BlockPosition);
                        Debug.Assert(cubeBlock != null, "Invalid position for a block");

                        if (cubeBlock != null)
                        {
                            if (memoryTarget.TargetType == MyAiTargetEnum.COMPOUND_BLOCK)
                            {
                                var realBlock = (cubeBlock.FatBlock as MyCompoundCubeBlock).GetBlock(memoryTarget.CompoundId.Value);
                                Debug.Assert(realBlock != null, "Block does not exist in the compound block");
                                if (realBlock == null)
                                    return false;
                                cubeBlock = realBlock;
                                m_compoundId = memoryTarget.CompoundId;
                            }
                            SetTargetBlock(cubeBlock);
                        }
                        else
                            return false;
                    }
                    else if (memoryTarget.TargetType == MyAiTargetEnum.ENTITY)
                    {
                        if (memoryTarget.Position.HasValue && entity is MyFracturedPiece)
                            SetMTargetPosition(memoryTarget.Position.Value);
                        else
                            SetMTargetPosition(entity.PositionComp.GetPosition());

                        SetTargetEntity(entity);
                        m_targetEntity = entity;
                    }
                    else if (memoryTarget.TargetType == MyAiTargetEnum.VOXEL)
                    {
                        var voxelMap = entity as MyVoxelMap;
                        Debug.Assert(memoryTarget.Position.HasValue, "Tree id was not set correctly in memory.");
                        if (!memoryTarget.Position.HasValue) return false;

                        Debug.Assert(voxelMap != null, "Voxel map hasn't been set.");
                        if (voxelMap == null) return false;

                        SetTargetVoxel(memoryTarget.Position.Value, voxelMap);
                        m_targetEntity = voxelMap;
                    }
                    else
                    {
                        SetTargetEntity(entity);
                        //SetMTargetPosition(Vector3D.Zero);
                    }
                    return true;
                }
                else
                {
                    UnsetTarget();
                    return false;
                }
            }
            else if (memoryTarget.TargetType == MyAiTargetEnum.NO_TARGET)
            {
                UnsetTarget();
                return true;
            }
            else
            {
                Debug.Assert(false, "Unrecognized type of target!");
                UnsetTarget();
                return false;
            }
        }