Exemplo n.º 1
0
        public void Update(GameTime time)
        {
            float timeStep = time.ElapsedGameTime.Milliseconds * 0.001f;

            physicsWorld.Step(timeStep);
            // Create a list of entities to be destroyed after level update
            // We don't want to modify the contents of entity list directly during foreach
            List <Entity> destroyEntities = new List <Entity>();

            foreach (Entity entity in this.entities)
            {
                if (!entity.UpdateEntity(time))
                {
                    destroyEntities.Add(entity);
                }
            }

            foreach (Entity entity in destroyEntities)
            {
                DestroyEntity(entity);
            }

            foreach (Entity entity in NewEntities)
            {
                AddEntity(entity, EntityLayer);
            }
            NewEntities.Clear();
        }
Exemplo n.º 2
0
 public void AddNewEntity(LucyEntity entity)
 {
     if (entity != null)
     {
         NewEntities.Add(entity);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// take all of the new entities and merge them into the main entity pool
 /// </summary>
 public void ProcessNewEntities()
 {
     foreach (var newEntity in NewEntities)
     {
         Entities.Add(newEntity);
     }
     NewEntities.Clear();
 }
Exemplo n.º 4
0
 public virtual void RemoveEntity(Entity entity)
 {
     //Unsubscribe from the destroy event
     NewEntities.Remove(entity);
     if (EntityRemoved != null)
     {
         EntityRemoved(entity);
     }
 }
Exemplo n.º 5
0
        public virtual void Update()
        {
            //Replace the old entities
            Entities = NewEntities.ToList();

            foreach (var e in Entities)
            {
                e.Update();
            }
        }
Exemplo n.º 6
0
 public virtual void AddEntity(Entity entity)
 {
     //Subscribe to the destory event
     entity.DestroyEvent += RemoveEntity;
     entity.CreateEvent  += AddEntity;
     NewEntities.Add(entity);
     if (EntityAdded != null)
     {
         EntityAdded(entity);
     }
 }
Exemplo n.º 7
0
    public static IQueryable traeruser(string id)
    {
        using (NewEntities bla = new NewEntities())

        {
            //bla.TBL_CAPITAN
            var oralinq1 = from e in bla.VW_INT_USUARIOS
                           where e.NDOC == int.Parse(id)
                           select e;

            return(oralinq1);
        }
    }
Exemplo n.º 8
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++;
        }
        internal void Scan()
        {
            using (_scanLock.AcquireExclusiveUsing())
            {
                if (!Scanning && Session.Tick - _lastScan > 100)
                {
                    Scanning          = true;
                    _lastScan         = Session.Tick;
                    GridVolume.Radius = MaxTargetingRange;
                    MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref GridVolume, _possibleTargets);
                    foreach (var grid in PrevSubGrids)
                    {
                        RemSubGrids.Add(grid);
                    }

                    PrevSubGrids.Clear();
                    for (int i = 0; i < _possibleTargets.Count; i++)
                    {
                        var ent = _possibleTargets[i];
                        using (ent.Pin())
                        {
                            if (ent is MyVoxelBase || ent.Physics == null || ent is MyFloatingObject ||
                                ent.MarkedForClose || !ent.InScene || ent.IsPreview || ent.Physics.IsPhantom)
                            {
                                continue;
                            }

                            var grid = ent as MyCubeGrid;
                            if (grid != null && MyGrid.IsSameConstructAs(grid))
                            {
                                PrevSubGrids.Add(grid);
                                continue;
                            }

                            Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entInfo;
                            if (!CreateEntInfo(ent, MyOwner, out entInfo))
                            {
                                continue;
                            }

                            switch (entInfo.Relationship)
                            {
                            case MyRelationsBetweenPlayerAndBlock.Owner:
                            case MyRelationsBetweenPlayerAndBlock.FactionShare:
                            case MyRelationsBetweenPlayerAndBlock.Friends:
                                continue;
                            }

                            if (grid != null)
                            {
                                FatMap fatMap;
                                if (!Session.GridToFatMap.TryGetValue(grid, out fatMap) || fatMap.Trash)
                                {
                                    continue;
                                }

                                var allFat   = fatMap.MyCubeBocks;
                                var fatCount = allFat.Count;

                                if (fatCount <= 0 || !grid.IsPowered)
                                {
                                    continue;
                                }

                                if (fatCount <= 20) // possible debris
                                {
                                    var valid = false;
                                    for (int j = 0; j < fatCount; j++)
                                    {
                                        var fat = allFat[j];
                                        if (fat is IMyTerminalBlock && fat.IsWorking)
                                        {
                                            valid = true;
                                            break;
                                        }
                                    }
                                    if (!valid)
                                    {
                                        continue;
                                    }
                                }

                                int    partCount;
                                GridAi targetAi;
                                if (Session.GridTargetingAIs.TryGetValue(grid, out targetAi))
                                {
                                    targetAi.TargetAisTmp.Add(this);
                                    TargetAisTmp.Add(targetAi);
                                    partCount = targetAi.Construct.BlockCount;
                                }
                                else
                                {
                                    partCount = fatMap.MostBlocks;
                                }

                                NewEntities.Add(new DetectInfo(Session, ent, entInfo, partCount, fatCount));
                                ValidGrids.Add(ent);
                            }
                            else
                            {
                                NewEntities.Add(new DetectInfo(Session, ent, entInfo, 1, 0));
                            }
                        }
                    }
                    FinalizeTargetDb();
                    SubGridDetect();
                }
                Scanning = false;
            }
        }
Exemplo n.º 10
0
        internal void Scan()
        {
            MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref ScanVolume, _possibleTargets);
            NearByEntitiesTmp = _possibleTargets.Count;

            foreach (var grid in PrevSubGrids)
            {
                RemSubGrids.Add((MyCubeGrid)grid);
            }

            PrevSubGrids.Clear();
            for (int i = 0; i < NearByEntitiesTmp; i++)
            {
                var ent = _possibleTargets[i];
                using (ent.Pin()) {
                    if (ent is MyVoxelBase || ent.Physics == null || ent is MyFloatingObject || ent.MarkedForClose || !ent.InScene || ent.IsPreview || ent.Physics.IsPhantom)
                    {
                        continue;
                    }

                    var grid = ent as MyCubeGrid;
                    if (grid != null && MyGrid.IsSameConstructAs(grid))
                    {
                        PrevSubGrids.Add(grid);
                        continue;
                    }

                    Sandbox.ModAPI.Ingame.MyDetectedEntityInfo entInfo;
                    if (!CreateEntInfo(ent, AiOwner, out entInfo))
                    {
                        continue;
                    }

                    switch (entInfo.Relationship)
                    {
                    case MyRelationsBetweenPlayerAndBlock.Owner:
                    case MyRelationsBetweenPlayerAndBlock.FactionShare:
                    case MyRelationsBetweenPlayerAndBlock.Friends:
                        continue;
                    }

                    if (grid != null)
                    {
                        GridMap gridMap;
                        if (!Session.GridToInfoMap.TryGetValue(grid, out gridMap) || gridMap.Trash)
                        {
                            continue;
                        }

                        var allFat   = gridMap.MyCubeBocks;
                        var fatCount = allFat.Count;

                        if (fatCount <= 0)
                        {
                            continue;
                        }

                        var loneWarhead = false;
                        if (fatCount <= 20)    // possible debris

                        {
                            var valid = false;
                            for (int j = 0; j < fatCount; j++)
                            {
                                var fat     = allFat[j];
                                var warhead = fat is IMyWarhead;
                                if (warhead || fat is IMyTerminalBlock && fat.IsWorking)
                                {
                                    loneWarhead = warhead && fatCount == 1;
                                    valid       = true;
                                    break;
                                }
                            }
                            if (!valid)
                            {
                                continue;
                            }
                        }
                        int    partCount;
                        GridAi targetAi;
                        if (Session.GridTargetingAIs.TryGetValue(grid, out targetAi))
                        {
                            targetAi.TargetAisTmp.Add(this);
                            TargetAisTmp.Add(targetAi);
                            partCount = targetAi.Construct.BlockCount;
                        }
                        else
                        {
                            partCount = gridMap.MostBlocks;
                        }

                        NewEntities.Add(new DetectInfo(Session, ent, entInfo, partCount, !loneWarhead? fatCount : 2));// bump warhead to 2 fatblocks so its not ignored by targeting
                        ValidGrids.Add(ent);
                    }
                    else
                    {
                        NewEntities.Add(new DetectInfo(Session, ent, entInfo, 1, 0));
                    }
                }
            }
            FinalizeTargetDb();
            SubGridDetect();
        }