Esempio n. 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();
        }
Esempio n. 2
0
        internal void CleanUp()
        {
            AiCloseTick = Session.Tick;

            MyGrid.Components.Remove <AiComponent>();

            for (int i = 0; i < MIds.Length; i++)
            {
                MIds[i] = 0;
            }

            if (Session.IsClient)
            {
                Session.SendUpdateRequest(MyGrid.EntityId, PacketType.ClientAiRemove);
            }

            Data.Repo.ControllingPlayers.Clear();
            Data.Repo.ActiveTerminal = 0;

            CleanSortedTargets();
            Construct.Clean();
            Obstructions.Clear();
            ObstructionsTmp.Clear();
            TargetAis.Clear();
            TargetAisTmp.Clear();
            EntitiesInRange.Clear();
            Batteries.Clear();
            Targets.Clear();
            Weapons.Clear();
            WeaponsIdx.Clear();
            WeaponBase.Clear();
            LiveProjectile.Clear();
            DeadProjectiles.Clear();
            NearByShieldsTmp.Clear();
            NearByFriendlyShields.Clear();
            StaticsInRange.Clear();
            StaticsInRangeTmp.Clear();
            TestShields.Clear();
            NewEntities.Clear();
            SubGridsRegistered.Clear();
            SourceCount           = 0;
            BlockCount            = 0;
            AiOwner               = 0;
            ProjectileTicker      = 0;
            NearByEntities        = 0;
            NearByEntitiesTmp     = 0;
            MyProjectiles         = 0;
            AccelChecked          = false;
            PointDefense          = false;
            FadeOut               = false;
            SuppressMouseShoot    = false;
            OverPowered           = false;
            UpdatePowerSources    = false;
            AvailablePowerChanged = false;
            PowerIncrease         = false;
            RequestedPowerChanged = false;
            RequestIncrease       = false;
            DbReady               = false;
            GridInit              = false;
            TouchingWater         = false;
            Data.Clean();

            MyShield         = null;
            MyPlanetTmp      = null;
            MyPlanet         = null;
            TerminalSystem   = null;
            LastTerminal     = null;
            PowerDistributor = null;
            PowerBlock       = null;
            MyGrid           = null;
            PowerDistributor = null;
            Session          = null;
            Closed           = true;
            CanShoot         = true;
            Version++;
        }
        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();
        }