private bool AddPotentialBlock(IMySlimBlock block, bool remote = false, NaniteAreaBeacon beacon = null)
        {
            if (PotentialTargetList.Contains(block))
            {
                return(false);
            }

            if (!remote && block.FatBlock != null && block.FatBlock is IMyTerminalBlock && block.FatBlock.OwnerId != 0 &&
                !MyRelationsBetweenPlayerAndBlockExtensions.IsFriendly(block.FatBlock.GetUserRelationToOwner(m_constructionBlock.ConstructionBlock.OwnerId)))
            {
                return(false);
            }

            if (!block.IsFullIntegrity || block.HasDeformation)
            {
                if (beacon != null)
                {
                    if (!m_areaTargetBlocks.ContainsKey(block))
                    {
                        m_areaTargetBlocks.Add(block, beacon);
                    }
                    else
                    {
                        m_areaTargetBlocks[block] = beacon;
                    }
                }

                PotentialTargetList.Add(block);
                return(true);
            }

            return(false);
        }
示例#2
0
        public override void ParallelUpdate(List <IMyCubeGrid> gridList, List <BlockTarget> gridBlocks)
        {
            List <IMyPlayer> players = new List <IMyPlayer>();

            try
            {
                MyAPIGateway.Players.GetPlayers(players);
            }
            catch
            {
                Logging.Instance.WriteLine("NaniteLifeSupportTargets.ParallelUpdate: Error getting players, skipping");
                return;
            }

            foreach (IMyPlayer item in players)
            {
                var functional = m_constructionBlock.ConstructionBlock as IMyFunctionalBlock;
                MyRelationsBetweenPlayerAndBlock relations = functional.GetUserRelationToOwner(item.IdentityId);
                if (relations != MyRelationsBetweenPlayerAndBlock.Owner && relations != MyRelationsBetweenPlayerAndBlock.FactionShare)
                {
                    continue;
                }

                if (!DoesTargetNeedLifeSupport(item))
                {
                    continue;
                }

                if (PotentialTargetList.Contains(item) || TargetList.Contains(item))
                {
                    continue;
                }

                if (IsInRange(item.GetPosition(), m_maxDistance))
                {
                    PotentialTargetList.Add(item);
                }
            }

            List <IMyGasTank> removalList = new List <IMyGasTank>();

            foreach (IMyGasTank tank in connectedGasTanks)
            {
                if (!GridHelper.IsValidGasConnection(m_constructionBlock.ConstructionCubeBlock, tank))
                {
                    removalList.Add(tank);
                }
            }

            foreach (IMyGasTank tank in removalList)
            {
                connectedGasTanks.Remove(tank);
            }

            CheckTanks(ref m_hasOxygen, ref m_hasHydrogen);
        }
示例#3
0
 private void ProcessProjector(IMyProjector projector)
 {
     foreach (IMySlimBlock block in ProjectorIntegration.IterBuildableBlocks(projector))
     {
         if (!PotentialTargetList.Contains(block))
         {
             PotentialTargetList.Add(block);
         }
     }
 }
示例#4
0
        private void ProcessProjector(IMyProjector projector)
        {
            MyCubeGrid grid = (MyCubeGrid)projector.ProjectedGrid;

            foreach (IMySlimBlock block in grid.GetBlocks())
            {
                if (projector.CanBuild(block, false) == BuildCheckResult.OK && !PotentialTargetList.Contains(block))
                {
                    PotentialTargetList.Add(block);
                }
            }
        }
        private void CheckAreaBeacons(List <IMyCubeGrid> NaniteGridGroup)
        {
            foreach (var beaconBlock in NaniteConstructionManager.BeaconList.Where(x => x.Value is NaniteAreaBeacon).ToList())
            {
                IMyCubeBlock cubeBlock = (IMyCubeBlock)beaconBlock.Value.BeaconBlock;

                if (!IsAreaBeaconValid(cubeBlock))
                {
                    continue;
                }

                var item = beaconBlock.Value as NaniteAreaBeacon;
                if (!item.Settings.AllowDeconstruction)
                {
                    continue;
                }

                HashSet <IMyEntity> entities = new HashSet <IMyEntity>();
                MyAPIGateway.Entities.GetEntities(entities);
                foreach (var entity in entities)
                {
                    var grid = entity as IMyCubeGrid;
                    if (grid != null && grid.Physics != null && grid.Physics.AngularVelocity.Length() == 0f &&
                        grid.Physics.LinearVelocity.Length() == 0f && m_validBeaconedGrids.FirstOrDefault(x => x.GridsProcessed.Contains(grid)) == null &&
                        !MyAPIGateway.GridGroups.GetGroup(grid, GridLinkTypeEnum.Physical).Contains(cubeBlock.CubeGrid) &&
                        (grid.GetPosition() - cubeBlock.GetPosition()).LengthSquared() < m_maxDistance * m_maxDistance && item.IsInsideBox(grid.WorldAABB, false))
                    {
                        NaniteDeconstructionGrid deconstruct = new NaniteDeconstructionGrid(grid);
                        m_validBeaconedGrids.Add(deconstruct);
                        CreateGridStack(NaniteGridGroup, deconstruct, (MyCubeGrid)grid, null);

                        if (!m_areaTargetBlocks.ContainsKey(grid))
                        {
                            m_areaTargetBlocks.Add(grid, item);
                        }
                        else
                        {
                            m_areaTargetBlocks[grid] = item;
                        }

                        foreach (var block in deconstruct.RemoveList)
                        {
                            if (!PotentialTargetList.Contains(block))
                            {
                                PotentialTargetList.Add(block);
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        private bool AddPotentialBlock(IMySlimBlock block, bool remote = false, NaniteAreaBeacon beacon = null)
        {
            if (PotentialTargetList.Contains(block))
            {
                return(false);
            }

            if (EntityHelper.GetDistanceBetweenBlockAndSlimblock((IMyCubeBlock)m_constructionBlock.ConstructionBlock, block) > m_maxDistance)
            {
                return(false);
            }

            if (!remote && block.FatBlock != null && block.FatBlock is IMyTerminalBlock && block.FatBlock.OwnerId != 0)
            {
                IMyTerminalBlock terminal = (IMyTerminalBlock)block.FatBlock;
                MyRelationsBetweenPlayerAndBlock relation = terminal.GetUserRelationToOwner(m_constructionBlock.ConstructionBlock.OwnerId);

                if (relation == MyRelationsBetweenPlayerAndBlock.Neutral ||
                    relation == MyRelationsBetweenPlayerAndBlock.Enemies)
                {
                    return(false);
                }
            }
            else if (remote)
            {
                //if (block.CubeGrid.BigOwners.Count < 1)
                //    return false;

                foreach (var item in block.CubeGrid.BigOwners)
                {
                    MyRelationsBetweenPlayerAndBlock relation = m_constructionBlock.ConstructionBlock.GetUserRelationToOwner(item);

                    if (relation == MyRelationsBetweenPlayerAndBlock.Neutral ||
                        relation == MyRelationsBetweenPlayerAndBlock.Enemies)
                    {
                        return(false);
                    }
                }
            }

            if (!block.IsFullIntegrity || block.HasDeformation)
            {
                using (Lock.AcquireExclusiveUsing())
                {
                    if (beacon != null)
                    {
                        if (!m_areaTargetBlocks.ContainsKey(block))
                        {
                            m_areaTargetBlocks.Add(block, beacon);
                        }
                        else
                        {
                            m_areaTargetBlocks[block] = beacon;
                        }
                    }

                    PotentialTargetList.Add(block);
                    return(true);
                }
            }

            return(false);
        }
        private void CheckAreaBeacons()
        {
            foreach (var beaconBlock in NaniteConstructionManager.BeaconList.Where(x => x is NaniteAreaBeacon))
            {
                IMyCubeBlock cubeBlock = (IMyCubeBlock)beaconBlock.BeaconBlock;

                if (!((IMyFunctionalBlock)cubeBlock).Enabled || !((IMyFunctionalBlock)cubeBlock).IsFunctional)
                {
                    continue;
                }

                MyRelationsBetweenPlayerAndBlock relation = cubeBlock.GetUserRelationToOwner(m_constructionBlock.ConstructionBlock.OwnerId);
                if (!(relation == MyRelationsBetweenPlayerAndBlock.Owner || relation == MyRelationsBetweenPlayerAndBlock.FactionShare || (MyAPIGateway.Session.CreativeMode && relation == MyRelationsBetweenPlayerAndBlock.NoOwnership)))
                {
                    continue;
                }

                var item = beaconBlock as NaniteAreaBeacon;
                if (!item.Settings.AllowDeconstruction)
                {
                    continue;
                }

                HashSet <IMyEntity> entities = new HashSet <IMyEntity>();
                MyAPIGateway.Entities.GetEntities(entities);
                foreach (var entity in entities)
                {
                    var grid = entity as IMyCubeGrid;
                    if (grid == null)
                    {
                        continue;
                    }

                    if (grid.Physics == null)
                    {
                        continue;
                    }

                    if (grid.Physics.AngularVelocity.Length() != 0f || grid.Physics.LinearVelocity.Length() != 0f)
                    {
                        continue;
                    }

                    if (m_validBeaconedGrids.FirstOrDefault(x => x.GridsProcessed.Contains(grid)) != null)
                    {
                        continue;
                    }

                    if (GridHelper.GetGridGroup(grid).Contains(cubeBlock.CubeGrid))
                    {
                        continue;
                    }

                    if ((grid.GetPosition() - cubeBlock.GetPosition()).LengthSquared() < m_maxDistance * m_maxDistance)
                    {
                        if (item.IsInsideBox(grid.WorldAABB, false))
                        {
                            NaniteDeconstructionGrid deconstruct = new NaniteDeconstructionGrid(grid);
                            m_validBeaconedGrids.Add(deconstruct);
                            CreateGridStack(deconstruct, (MyCubeGrid)grid, null);
                            if (!m_areaTargetBlocks.ContainsKey(grid))
                            {
                                m_areaTargetBlocks.Add(grid, item);
                            }
                            else
                            {
                                m_areaTargetBlocks[grid] = item;
                            }

                            foreach (var block in deconstruct.RemoveList)
                            {
                                if (!PotentialTargetList.Contains(block))
                                {
                                    PotentialTargetList.Add(block);
                                }
                            }
                        }
                    }
                }
            }
        }
        public override void ParallelUpdate(List <IMyCubeGrid> gridList, List <IMySlimBlock> gridBlocks)
        {
            try
            {
                if (!IsEnabled())
                {
                    PotentialTargetList.Clear();
                    return;
                }

                // Add
                foreach (var beaconBlock in NaniteConstructionManager.BeaconList.Where(x => x is NaniteBeaconDeconstruct && Vector3D.DistanceSquared(m_constructionBlock.ConstructionBlock.GetPosition(), x.BeaconBlock.GetPosition()) < m_maxDistance * m_maxDistance))
                {
                    IMyCubeBlock item = (IMyCubeBlock)beaconBlock.BeaconBlock;

                    if (!((IMyFunctionalBlock)item).Enabled || !((IMyFunctionalBlock)item).IsFunctional)
                    {
                        continue;
                    }

                    if (gridList.Contains(item.CubeGrid))
                    {
                        continue;
                    }

                    MyRelationsBetweenPlayerAndBlock relation = item.GetUserRelationToOwner(m_constructionBlock.ConstructionBlock.OwnerId);
                    if (!(relation == MyRelationsBetweenPlayerAndBlock.Owner || relation == MyRelationsBetweenPlayerAndBlock.FactionShare || (MyAPIGateway.Session.CreativeMode && relation == MyRelationsBetweenPlayerAndBlock.NoOwnership)))
                    {
                        continue;
                    }

                    if (m_validBeaconedGrids.FirstOrDefault(x => x.GridsProcessed.Contains(item.CubeGrid)) != null)
                    {
                        continue;
                    }

                    NaniteDeconstructionGrid deconstruct = new NaniteDeconstructionGrid(item.CubeGrid);
                    m_validBeaconedGrids.Add(deconstruct);
                    CreateGridStack(deconstruct, (MyCubeGrid)item.CubeGrid, (MyCubeBlock)item);

                    using (Lock.AcquireExclusiveUsing())
                    {
                        foreach (var slimBlock in deconstruct.RemoveList)
                        {
                            if (!PotentialTargetList.Contains(slimBlock))
                            {
                                PotentialTargetList.Add(slimBlock);
                            }
                        }
                    }

                    deconstruct.RemoveList.Clear();
                }

                CheckAreaBeacons();

                if (PotentialTargetList.Count > 0)
                {
                    using (Lock.AcquireExclusiveUsing())
                    {
                        foreach (IMySlimBlock item in PotentialTargetList.ToList())
                        {
                            if (item.CubeGrid.Closed || item.IsDestroyed || item.IsFullyDismounted || (item.FatBlock != null && item.FatBlock.Closed))
                            {
                                PotentialTargetList.Remove(item);
                            }

                            if (EntityHelper.GetDistanceBetweenBlockAndSlimblock((IMyCubeBlock)m_constructionBlock.ConstructionBlock, item) > m_maxDistance)
                            {
                                PotentialTargetList.Remove(item);
                            }
                        }

                        //m_potentialTargetList = m_potentialTargetList.OrderBy(x => GetBlockConnections((IMySlimBlock)(x))).ToList();
                    }
                }
                else if (TargetList.Count == 0 && PotentialTargetList.Count == 0)
                {
                    m_validBeaconedGrids.Clear();
                }
            }
            catch (Exception ex)
            {
                Logging.Instance.WriteLine(string.Format("Parallel Erorr: {0}", ex.ToString()));
            }
        }