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);
        }
Beispiel #2
0
        public override void ParallelUpdate(List <IMyCubeGrid> gridList, List <BlockTarget> blocks)
        {
            m_entities.Clear();
            try
            {
                MyAPIGateway.Entities.GetEntities(m_entities, x => x is IMyFloatingObject || x is MyInventoryBagEntity || x is IMyCharacter);
            }
            catch
            {
                Logging.Instance.WriteLine("NaniteFloatingTargets.ParallelUpdate: Error getting entities, skipping.");
                return;
            }

            foreach (var item in m_entities.ToList())
            {
                if (item == null)
                {
                    continue;
                }

                if (item is IMyCharacter)
                {
                    var charBuilder = (MyObjectBuilder_Character)item.GetObjectBuilder();
                    if (charBuilder.LootingCounter <= 0f)
                    {
                        continue;
                    }
                }

                if (IsInRange(item.GetPosition(), m_maxDistance) && TransferFromTarget(item, false))
                {
                    PotentialTargetList.Add(item);
                }
            }
        }
        private bool AddPotentialBlock(IMySlimBlock block, bool remote = false, NaniteAreaBeacon beacon = null)
        {
            if (TargetList.Contains(block))
            {
                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);
        }
Beispiel #4
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);
        }
Beispiel #5
0
 private void ProcessProjector(IMyProjector projector)
 {
     foreach (IMySlimBlock block in ProjectorIntegration.IterBuildableBlocks(projector))
     {
         if (!PotentialTargetList.Contains(block))
         {
             PotentialTargetList.Add(block);
         }
     }
 }
        private bool UpdateProjection(MyCubeBlock projector, MyCubeGrid projectedGrid, MyObjectBuilder_ProjectorBase projectorBuilder)
        {
            // god f*****g damnit object builders
            MyCubeGrid cubeGrid = projector.CubeGrid;
            MyObjectBuilder_CubeGrid gridBuilder = (MyObjectBuilder_CubeGrid)projectedGrid.GetObjectBuilder();
            bool found = false;

            foreach (MyObjectBuilder_CubeBlock blockBuilder in gridBuilder.CubeBlocks)
            {
                Vector3  worldPosition = projectedGrid.GridIntegerToWorld(blockBuilder.Min);
                Vector3I realPosition  = cubeGrid.WorldToGridInteger(worldPosition);
                var      realBlock     = (IMySlimBlock)cubeGrid.GetCubeBlock(realPosition);

                MyCubeBlockDefinition blockDefinition;
                MyDefinitionManager.Static.TryGetCubeBlockDefinition(blockBuilder.GetId(), out blockDefinition);
                if (realBlock != null) // && blockDefinition.Id == new MyDefinitionId(realBlock.GetType()))
                {
                    //Logging.Instance.WriteLine(string.Format("Found overlap - {0} {1}", blockBuilder.GetId(), realBlock.GetObjectBuilder().GetId()));
                }
                else
                {
                    //Logging.Instance.WriteLine(string.Format("No block at position: {0}", blockBuilder.GetId()));
                    if (CanBuildBlock(blockBuilder, projectedGrid, projector, cubeGrid, projectorBuilder))
                    {
                        //Logging.Instance.WriteLine(string.Format("No block at position: {0}", blockBuilder.GetId()));
                        var slimBlock = (IMySlimBlock)projectedGrid.GetCubeBlock(blockBuilder.Min);
                        if (slimBlock != null && slimBlock.CubeGrid.GetPosition() != Vector3D.Zero)
                        {
                            //Logging.Instance.WriteLine(string.Format("Adding block: {0}", blockBuilder.GetId()));
                            PotentialTargetList.Add(slimBlock);
                            found = true;
                        }
                    }
                    else
                    {
                        using (m_lock.AcquireExclusiveUsing())
                        {
                            foreach (var item in blockDefinition.Components)
                            {
                                if (!ComponentsRequired.ContainsKey(item.Definition.Id.SubtypeName))
                                {
                                    ComponentsRequired.Add(item.Definition.Id.SubtypeName, item.Count);
                                }
                                else
                                {
                                    ComponentsRequired[item.Definition.Id.SubtypeName] += item.Count;
                                }
                            }
                        }
                    }
                }
            }

            return(found);
        }
Beispiel #7
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);
                            }
                        }
                    }
                }
            }
        }
        public void CancelTarget(IMySlimBlock obj)
        {
            Logging.Instance.WriteLine(string.Format("CANCELLING Deconstruction Target: {0} - {1} (EntityID={2},Position={3})", m_constructionBlock.ConstructionBlock.EntityId, obj.GetType().Name, obj.FatBlock != null ? obj.FatBlock.EntityId : 0, obj.Position));
            if (Sync.IsServer)
            {
                m_constructionBlock.SendCancelTarget(obj, TargetTypes.Deconstruction);
            }

            m_constructionBlock.ParticleManager.CancelTarget(obj);
            m_constructionBlock.ToolManager.Remove(obj);
            Remove(obj);

            using (Lock.AcquireExclusiveUsing())
                PotentialTargetList.Add(obj);
        }
        public override void ParallelUpdate(List <IMyCubeGrid> gridList, List <IMySlimBlock> blocks)
        {
            using (m_lock.AcquireExclusiveUsing())
            {
                PotentialTargetList.Clear();
            }

            m_entities.Clear();
            try
            {
                MyAPIGateway.Entities.GetEntities(m_entities, x => x is IMyFloatingObject || x is MyInventoryBagEntity || x is IMyCharacter);
            }
            catch
            {
                Logging.Instance.WriteLine(string.Format("Error getting entities, skipping"));
                return;
            }

            if (!IsEnabled())
            {
                return;
            }

            foreach (var item in m_entities)
            {
                if (item is IMyCharacter)
                {
                    var charBuilder = (MyObjectBuilder_Character)item.GetObjectBuilder();
                    if (charBuilder.LootingCounter <= 0f)
                    {
                        continue;
                    }
                }

                if (Vector3D.DistanceSquared(m_constructionBlock.ConstructionBlock.GetPosition(), item.GetPosition()) < m_maxDistance * m_maxDistance &&
                    TransferFromTarget(item, false))
                {
                    using (m_lock.AcquireExclusiveUsing())
                        PotentialTargetList.Add(item);
                }
            }
        }
        public override void ParallelUpdate(List <IMyCubeGrid> gridList, List <IMySlimBlock> gridBlocks)
        {
            using (Lock.AcquireExclusiveUsing())
                PotentialTargetList.Clear();

            List <IMyPlayer> players = new List <IMyPlayer>();

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

            if (!IsEnabled())
            {
                return;
            }

            foreach (var 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 (item.Controller == null || item.Controller.ControlledEntity == null || item.Controller.ControlledEntity.Entity == null)
                {
                    continue;
                }

                bool damaged = false;
                foreach (var component in item.Controller.ControlledEntity.Entity.Components)
                {
                    var stat = component as MyCharacterStatComponent;
                    if (stat != null)
                    {
                        if (stat.Health.Value < stat.Health.MaxValue)
                        {
                            damaged = true;
                        }

                        break;
                    }
                }

                if (!damaged)
                {
                    continue;
                }

                if (Vector3D.DistanceSquared(m_constructionBlock.ConstructionBlock.GetPosition(), item.GetPosition()) < m_maxDistance * m_maxDistance)
                {
                    using (m_lock.AcquireExclusiveUsing())
                        PotentialTargetList.Add(item);
                }
            }
        }
        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()));
            }
        }
        public override void ParallelUpdate(List <IMyCubeGrid> NaniteGridGroup, List <BlockTarget> gridBlocks)
        {
            try
            {
                // Add
                foreach (var beaconBlock in NaniteConstructionManager.BeaconList.Where(x => x.Value is NaniteBeaconDeconstruct))
                {
                    IMyCubeBlock item = (IMyCubeBlock)beaconBlock.Value.BeaconBlock;

                    if (item == null ||
                        item.CubeGrid == null ||
                        !((IMyFunctionalBlock)item).Enabled ||
                        !((IMyFunctionalBlock)item).IsFunctional ||
                        NaniteGridGroup.Contains(item.CubeGrid) ||
                        !MyRelationsBetweenPlayerAndBlockExtensions.IsFriendly(item.GetUserRelationToOwner(m_constructionBlock.ConstructionBlock.OwnerId)) ||
                        m_validBeaconedGrids.FirstOrDefault(x => x.GridsProcessed.Contains(item.CubeGrid)) != null ||
                        !IsInRange(item.GetPosition(), m_maxDistance)
                        )
                    {
                        continue;
                    }

                    NaniteDeconstructionGrid deconstruct = new NaniteDeconstructionGrid(item.CubeGrid);

                    CreateGridStack(NaniteGridGroup, deconstruct, (MyCubeGrid)item.CubeGrid, (MyCubeBlock)item);
                    m_validBeaconedGrids.Add(deconstruct);

                    Logging.Instance.WriteLine($"[Deconstruction] Grid {item.CubeGrid.CustomName} queued for deconstruction", 1);

                    foreach (var slimBlock in deconstruct.RemoveList)
                    {
                        if (slimBlock != null)
                        {
                            PotentialTargetList.Add(slimBlock);
                        }
                    }

                    deconstruct.RemoveList.Clear();
                }

                CheckAreaBeacons(NaniteGridGroup);

                if (PotentialTargetList.Count > 0)
                {
                    foreach (IMySlimBlock item in PotentialTargetList.ToList())
                    {
                        if (item == null || item.CubeGrid == null || item.CubeGrid.Closed || item.IsDestroyed || item.IsFullyDismounted ||
                            (item.FatBlock != null && item.FatBlock.Closed) ||
                            EntityHelper.GetDistanceBetweenBlockAndSlimblock((IMyCubeBlock)m_constructionBlock.ConstructionBlock, item) > m_maxDistance)
                        {
                            PotentialTargetList.Remove(item);
                        }
                    }
                }
                else if (TargetList.Count == 0 && PotentialTargetList.Count == 0)
                {
                    m_validBeaconedGrids.Clear();
                }
            }
            catch (Exception e)
            { Logging.Instance.WriteLine($"Exception in NaniteDeconstructionTargets.ParallelUpdate:\n{e}"); }
        }