Exemple #1
0
        private void FinalizeTargetDb()
        {
            MyPlanetTmp = MyGamePruningStructure.GetClosestPlanet(ScanVolume.Center);
            ObstructionsTmp.Clear();
            StaticsInRangeTmp.Clear();
            for (int i = 0; i < NearByEntitiesTmp; i++)
            {
                var ent = _possibleTargets[i];
                if (Session.ShieldApiLoaded && ent.DefinitionId?.SubtypeId == Session.ShieldHash && ent.Render.Visible)
                {
                    var shieldblock = Session.SApi.MatchEntToShieldFast(ent, false);
                    if (shieldblock != null)
                    {
                        NearByShieldsTmp.Add(new Shields {
                            Id = ent.Hierarchy.ChildId, ShieldEnt = ent, ShieldBlock = (MyCubeBlock)shieldblock
                        });
                    }
                }
                var voxel    = ent as MyVoxelBase;
                var grid     = ent as MyCubeGrid;
                var safeZone = ent as MySafeZone;

                var blockingThings = safeZone != null || ent.Physics != null && grid != null || voxel != null && voxel == voxel.RootVoxel;
                if (!blockingThings || voxel != null && (voxel.RootVoxel is MyPlanet || voxel.PositionComp.LocalVolume.Radius < 15))
                {
                    continue;
                }

                if (voxel != null || safeZone != null || ent.Physics.IsStatic)
                {
                    StaticsInRangeTmp.Add(ent);
                }

                GridMap map;
                if (grid != null && (PrevSubGrids.Contains(grid) || ValidGrids.Contains(ent) || grid.PositionComp.LocalVolume.Radius < 10 || Session.GridToInfoMap.TryGetValue(grid, out map) && map.Trash || grid.BigOwners.Count == 0))
                {
                    continue;
                }

                ObstructionsTmp.Add(ent);
            }


            foreach (var pair in NoTargetLos)
            {
                if (Session.Tick - pair.Value > 120)
                {
                    uint lastLosTick;
                    NoTargetLos.TryRemove(pair.Key, out lastLosTick);
                }
            }

            ValidGrids.Clear();
            _possibleTargets.Clear();
        }
        private void FinalizeTargetDb()
        {
            MyPlanetTmp   = MyGamePruningStructure.GetClosestPlanet(GridVolume.Center);
            ShieldNearTmp = false;
            ObstructionsTmp.Clear();
            StaticsInRangeTmp.Clear();
            for (int i = 0; i < _possibleTargets.Count; i++)
            {
                var ent        = _possibleTargets[i];
                var hasPhysics = ent.Physics != null;
                if (Session.ShieldApiLoaded && hasPhysics && !ent.Physics.Enabled && ent.Physics.IsPhantom && !ent.Render.CastShadows)
                {
                    long testId;
                    long.TryParse(ent.Name, out testId);
                    if (testId != 0)
                    {
                        MyEntity shieldEnt;
                        if (testId == MyGrid.EntityId)
                        {
                            MyShieldTmp = ent;
                        }
                        else if (MyEntities.TryGetEntityById(testId, out shieldEnt))
                        {
                            var shieldGrid = shieldEnt as MyCubeGrid;
                            if (shieldGrid != null && MyGrid.IsSameConstructAs(shieldGrid))
                            {
                                MyShieldTmp = ent;
                            }
                        }
                        else if (!ShieldNearTmp)
                        {
                            ShieldNearTmp = true;
                        }
                    }
                }
                var voxel          = ent as MyVoxelBase;
                var grid           = ent as MyCubeGrid;
                var blockingThings = ent.Physics != null && (voxel != null && voxel.RootVoxel == voxel || grid != null);
                if (!blockingThings)
                {
                    continue;
                }
                if (ent.Physics.IsStatic)
                {
                    if (voxel is MyPlanet)
                    {
                        continue;
                    }

                    StaticsInRangeTmp.Add(ent);
                }

                if (grid != null && (PrevSubGrids.Contains(grid) || ValidGrids.Contains(ent) || grid.PositionComp.LocalVolume.Radius < 6))
                {
                    continue;
                }
                ObstructionsTmp.Add(ent);
            }
            ValidGrids.Clear();
            _possibleTargets.Clear();
        }