Exemple #1
0
        internal void CompChange(bool add, WeaponComponent comp)
        {
            if (add)
            {
                if (WeaponsIdx.ContainsKey(comp))
                {
                    return;
                }
                WeaponsIdx.Add(comp, Weapons.Count);
                Weapons.Add(comp);
            }
            else
            {
                int idx;
                if (!WeaponsIdx.TryGetValue(comp, out idx))
                {
                    return;
                }

                Weapons.RemoveAtFast(idx);
                if (idx < Weapons.Count)
                {
                    WeaponsIdx[Weapons[idx]] = idx;
                }

                WeaponsIdx.Remove(comp);
            }
        }
Exemple #2
0
        internal void CompChange(bool add, WeaponComponent comp)
        {
            if (add)
            {
                if (WeaponsIdx.ContainsKey(comp))
                {
                    Log.Line($"CompAddFailed:<{comp.MyCube.EntityId}> - comp({comp.MyCube.DebugName}[{comp.MyCube.BlockDefinition.Id.SubtypeName}]) already existed in {MyGrid.DebugName}");
                    return;
                }

                if (comp.HasArmor)
                {
                    for (int i = 0; i < comp.Platform.Weapons.Length; i++)
                    {
                        var w = comp.Platform.Weapons[i];
                        if (w.System.Armor != WeaponDefinition.HardPointDef.HardwareDef.ArmorState.IsWeapon)
                        {
                            Armor.Add(w.Comp.MyCube, w);
                        }
                    }
                    Session.ArmorCubes.Add(comp.MyCube, comp);
                }
                WeaponsIdx.Add(comp, Weapons.Count);
                //Session.IdToCompMap.Add(comp.MyCube.EntityId, comp);
                Weapons.Add(comp);
            }
            else
            {
                int idx;
                if (!WeaponsIdx.TryGetValue(comp, out idx))
                {
                    Log.Line($"CompRemoveFailed: <{comp.MyCube.EntityId}> - {Weapons.Count}[{WeaponsIdx.Count}]({WeaponBase.Count}) - {Weapons.Contains(comp)}[{Weapons.Count}] - {Session.GridTargetingAIs[comp.MyCube.CubeGrid].WeaponBase.ContainsKey(comp.MyCube)} - {Session.GridTargetingAIs[comp.MyCube.CubeGrid].WeaponBase.Count} ");
                    return;
                }

                if (comp.HasArmor)
                {
                    for (int i = 0; i < comp.Platform.Weapons.Length; i++)
                    {
                        var w = comp.Platform.Weapons[i];
                        if (w.System.Armor != WeaponDefinition.HardPointDef.HardwareDef.ArmorState.IsWeapon)
                        {
                            Armor.Remove(w.Comp.MyCube);
                        }
                    }
                    Session.ArmorCubes.Remove(comp.MyCube);
                }

                Weapons.RemoveAtFast(idx);
                if (idx < Weapons.Count)
                {
                    WeaponsIdx[Weapons[idx]] = idx;
                }

                //Session.IdToCompMap.Remove(comp.MyCube.EntityId);
                WeaponsIdx.Remove(comp);
            }
        }
Exemple #3
0
 internal void CleanUp()
 {
     RegisterMyGridEvents(false);
     foreach (var grid in SubGrids)
     {
         if (grid == MyGrid)
         {
             continue;
         }
         RemSubGrids.Add(grid);
     }
     AddSubGrids.Clear();
     SubGridChanges();
     SubGrids.Clear();
     Obstructions.Clear();
     TargetAis.Clear();
     EntitiesInRange.Clear();
     Batteries.Clear();
     Targets.Clear();
     SortedTargets.Clear();
     BlockGroups.Clear();
     Weapons.Clear();
     WeaponsIdx.Clear();
     WeaponBase.Clear();
     AmmoInventories.Clear();
     Inventories.Clear();
     LiveProjectile.Clear();
     DeadProjectiles.Clear();
     ControllingPlayers.Clear();
     SourceCount           = 0;
     BlockCount            = 0;
     MyOwner               = 0;
     PointDefense          = false;
     FadeOut               = false;
     SupressMouseShoot     = false;
     OverPowered           = false;
     UpdatePowerSources    = false;
     AvailablePowerChanged = false;
     PowerIncrease         = false;
     RequestedPowerChanged = false;
     RequestIncrease       = false;
     DbReady               = false;
     Focus.Clean();
     MyShieldTmp        = null;
     MyShield           = null;
     MyPlanetTmp        = null;
     MyPlanet           = null;
     TerminalSystem     = null;
     LastWeaponTerminal = null;
     LastTerminal       = null;
     PowerDistributor   = null;
 }
Exemple #4
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++;
        }