Beispiel #1
0
        private void DisableGrid(IMyCubeGrid grid)
        {
            HashSet <long>      disabledBlocks = new HashSet <long>();
            List <IMySlimBlock> blocks         = new List <IMySlimBlock>();

            grid.GetBlocks(blocks);

            foreach (IMySlimBlock block in blocks)
            {
                if (block.FatBlock == null)
                {
                    continue;
                }

                IMyCubeBlock cubeBlock = block.FatBlock;

                if (!(cubeBlock is IMyFunctionalBlock))
                {
                    continue;
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Reactor) ||
                    cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Thrust) ||
                    cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Battery) ||
                    cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SolarPanel) ||
                    cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Gyro) ||
                    cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    continue;
                }

                if (cubeBlock is IMyProductionBlock)
                {
                    IMyProductionBlock productionBlock = (IMyProductionBlock)cubeBlock;

                    if (productionBlock.IsProducing)
                    {
                        continue;
                    }
                }

                if (FunctionalBlockEntity.GetState(cubeBlock))
                {
                    FunctionalBlockEntity.SetState(cubeBlock, false);
                    disabledBlocks.Add(cubeBlock.EntityId);
                    m_enableCount++;
                }
            }

            lock (GridDisabled)
            {
                GridDisabled.Add(grid.EntityId);
                //if (disabledBlocks.Count > 0)
                //{
                Console.WriteLine("Adding");
                GridBlocksDisabled.Add(grid.EntityId, disabledBlocks);
                //}
            }
        }
Beispiel #2
0
        public void EnableGrid(IMyCubeGrid grid)
        {
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            grid.GetBlocks(blocks);

            lock (GridDisabled)
            {
                if (!GridBlocksDisabled.ContainsKey(grid.EntityId))
                {
                    if (GridDisabled.Contains(grid.EntityId))
                    {
                        GridDisabled.Remove(grid.EntityId);
                    }

                    return;
                }
            }

            HashSet <long> disabledBlocks = GridBlocksDisabled[grid.EntityId];

            foreach (IMySlimBlock block in blocks)
            {
                if (block.FatBlock == null)
                {
                    continue;
                }

                IMyCubeBlock cubeBlock = block.FatBlock;

                if (!(cubeBlock is IMyFunctionalBlock))
                {
                    continue;
                }

                if (!disabledBlocks.Contains(cubeBlock.EntityId))
                {
                    continue;
                }

                if (!FunctionalBlockEntity.GetState(cubeBlock))
                {
                    FunctionalBlockEntity.SetState(cubeBlock, true);
                    m_enableCount++;
                }
            }

            lock (GridDisabled)
            {
                if (GridDisabled.Contains(grid.EntityId))
                {
                    GridDisabled.Remove(grid.EntityId);
                }

                GridBlocksDisabled.Remove(grid.EntityId);
            }
        }
Beispiel #3
0
        public static void CheckAndEnableTurrets()
        {
            try
            {
                DateTime start = DateTime.Now;

                List <IMyEntity>    turretList = new List <IMyEntity>();
                HashSet <IMyEntity> entities   = new HashSet <IMyEntity>();
                MyAPIGateway.Entities.GetEntities(entities);
                UpdateIdentityCache();
                _turretsEnabled  = 0;
                _turretsDisabled = 0;
                _turretsToggled  = 0;
                foreach (IMyEntity entity in entities)
                {
                    if (!(entity is IMyCubeGrid))
                    {
                        continue;
                    }

                    if (!entity.InScene)
                    {
                        continue;
                    }

                    turretList.AddList(EnableTurretsWithTargets(entity));
                }

                if (turretList.Count > 0)
                {
                    Wrapper.GameAction(() =>
                    {
                        foreach (IMyEntity entity in turretList)
                        {
                            FunctionalBlockEntity.SetState(entity, true);
                        }
                    });
                }

                if (_turretsToggled > 0 || DateTime.Now - start > TimeSpan.FromSeconds(1))
                {
                    Essentials.Log.Info("Enable: {0} turrets enabled.  {1} turrets diabled.  {2} turrets toggled. ({3} ms)", _turretsEnabled, _turretsDisabled, _turretsToggled, (DateTime.Now - start).TotalMilliseconds);
                }
            }
            catch (Exception ex)
            {
                Essentials.Log.Error(ex);
            }
        }
        public static void CheckAndDisableTurrets()
        {
            try
            {
                DateTime            start      = DateTime.Now;
                List <IMyEntity>    turretList = new List <IMyEntity>();
                HashSet <IMyEntity> entities   = new HashSet <IMyEntity>();
                MyAPIGateway.Entities.GetEntities(entities);
                UpdateIdentityCache();
                m_turretsEnabled  = 0;
                m_turretsDisabled = 0;
                m_turretsToggled  = 0;
                foreach (IMyEntity entity in entities)
                {
                    if (!(entity is IMyCubeGrid))
                    {
                        continue;
                    }

                    if (!entity.InScene)
                    {
                        continue;
                    }

                    turretList.AddList(DisableTurretsWithoutTargets(entity));
                }

                if (turretList.Count > 0)
                {
                    Wrapper.GameAction(() =>
                    {
                        foreach (IMyEntity entity in turretList)
                        {
                            FunctionalBlockEntity.SetState(entity, false);
                        }
                    });
                }

                if (m_turretsToggled > 0 || DateTime.Now - start > TimeSpan.FromSeconds(1))
                {
                    Logging.WriteLineAndConsole(string.Format("Disable: {0} turrets enabled.  {1} turrets diabled.  {2} turrets toggled. ({3} ms)", m_turretsEnabled, m_turretsDisabled, m_turretsToggled, (DateTime.Now - start).TotalMilliseconds));
                }
            }
            catch (Exception ex)
            {
                Logging.WriteLineAndConsole(string.Format("CheckAndDisableTurrets(): {0}", ex.ToString()));
            }
        }
Beispiel #5
0
        protected bool RunCubeBlockReflectionTests()
        {
            bool result = true;

            if (!CubeBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeBlockEntity reflection validation failed!");
            }

            if (!TerminalBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("TerminalBlockEntity reflection validation failed!");
            }

            if (!FunctionalBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("FunctionalBlockEntity reflection validation failed!");
            }

            if (!ProductionBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ProductionBlockEntity reflection validation failed!");
            }

            if (!LightEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("LightEntity reflection validation failed!");
            }

            if (!BatteryBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BatteryBlockEntity reflection validation failed!");
            }

            if (!BatteryBlockNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BatteryBlockNetworkManager reflection validation failed!");
            }

            if (!DoorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("DoorEntity reflection validation failed!");
            }

            if (!GravityBaseEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GravityBaseEntity reflection validation failed!");
            }

            if (!GravityGeneratorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GravityGeneratorEntity reflection validation failed!");
            }

            if (!GravitySphereEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GravitySphereEntity reflection validation failed!");
            }

            if (!BeaconEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BeaconEntity reflection validation failed!");
            }

            if (!AntennaEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("AntennaEntity reflection validation failed!");
            }

            if (!ThrustEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ThrustEntity reflection validation failed!");
            }

            if (!ThrustNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ThrustNetworkManager reflection validation failed!");
            }

            if (!GyroEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GyroEntity reflection validation failed!");
            }

            if (!GyroNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GyroNetworkManager reflection validation failed!");
            }

            if (!CockpitEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CockpitEntity reflection validation failed!");
            }

            if (!TurretBaseEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("TurretBaseEntity reflection validation failed!");
            }

            if (!TurretNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("TurretNetworkManager reflection validation failed!");
            }

            if (!LandingGearEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("LandingGearEntity reflection validation failed!");
            }

            if (!LandingGearNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("LandingGearNetworkManager reflection validation failed!");
            }

            if (!ReactorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ReactorEntity reflection validation failed!");
            }

            if (!SolarPanelEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("SolarPanelEntity reflection validation failed!");
            }

            if (!SmallGatlingGunEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("SmallGatlingGunEntity reflection validation failed!");
            }

            if (!MergeBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("MergeBlockEntity reflection validation failed!");
            }

            if (!PistonEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PistonEntity reflection validation failed!");
            }

            if (!PistonNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PistonNetworkManager reflection validation failed!");
            }

            if (!RotorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("RotorEntity reflection validation failed!");
            }

            if (!VirtualMassEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("VirtualMassEntity reflection validation failed!");
            }

            if (!CameraBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CameraBlockEntity reflection validation failed!");
            }

            if (!OreDetectorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("OreDetectorEntity reflection validation failed!");
            }

            if (!ButtonPanelEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ButtonPanelEntity reflection validation failed!");
            }

            if (!ShipControllerEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ShipControllerEntity reflection validation failed!");
            }

            if (!ShipControllerNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ShipControllerNetworkManager reflection validation failed!");
            }

            if (result)
            {
                Console.WriteLine("All block types passed reflection unit tests!");
            }

            return(result);
        }
Beispiel #6
0
        private static List <IMyEntity> DisableTurretsWithoutTargets(IMyEntity entity)
        {
            _scanCache.Clear();

            List <IMyEntity> turretList = new List <IMyEntity>();

            if (!(entity is IMyCubeGrid))
            {
                return(turretList);
            }

            IMyCubeGrid         grid   = (IMyCubeGrid)entity;
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            grid.GetBlocks(blocks);
            //bool disable = false;
            //bool ignore = false;
            foreach (IMySlimBlock block in blocks)
            {
                if (block.FatBlock == null)
                {
                    continue;
                }

                if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_InteriorTurret) ||
                    block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LargeGatlingTurret) ||
                    block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LargeMissileTurret))
                {
                    IMyEntity turret = block.FatBlock;
                    bool      state  = FunctionalBlockEntity.GetState(turret);

                    if (state)
                    {
                        _turretsEnabled++;
                    }
                    else
                    {
                        _turretsDisabled++;
                    }

                    if (state)                    // && !ignore)
                    {
                        //Console.WriteLine("Finding targets on: {0}", entity.DisplayName);
                        // No target, so we're not going to enable anything on this grid
                        //if (!disable && DoesGridHaveTarget(grid, block))
                        if (DoesGridHaveTarget(grid, block))
                        {
                            // We'll ignore state and only collect for statistics
                            //ignore = true;
                            continue;
                        }

//						Console.WriteLine("Disabling");
                        //disable = true;

                        if (PluginSettings.Instance.DynamicTurretAllowExemption)
                        {
                            IMyFunctionalBlock functional = (IMyFunctionalBlock)turret;
                            if (functional.CustomName.ToLower().Contains("[manualcontrol]"))
                            {
                                continue;
                            }
                        }

                        _turretsToggled++;
                        turretList.Add(turret);
                    }
                }
            }

            return(turretList);
        }
Beispiel #7
0
        protected bool RunReflectionUnitTests()
        {
            bool result = true;

            if (!BaseObject.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BaseObject reflection validation failed!");
            }

            if (!BaseEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BaseEntity reflection validation failed!");
            }

            if (!BaseEntityNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BaseEntityNetworkManager reflection validation failed!");
            }

            if (!CubeGridEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeGridEntity reflection validation failed!");
            }

            if (!CubeGridNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeGridNetworkManager reflection validation failed!");
            }

            if (!CubeBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeBlockEntity reflection validation failed!");
            }

            if (!TerminalBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("TerminalBlockEntity reflection validation failed!");
            }

            if (!FunctionalBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("FunctionalBlockEntity reflection validation failed!");
            }

            if (!SectorObjectManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("SectorObjectManager reflection validation failed!");
            }

            if (!CharacterEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CharacterEntity reflection validation failed!");
            }

            if (!InventoryEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("InventoryEntity reflection validation failed!");
            }

            if (!InventoryItemEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("InventoryItemEntity reflection validation failed!");
            }

            if (!PlayerMap.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PlayerMap reflection validation failed!");
            }

            if (!PlayerManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PlayerManager reflection validation failed!");
            }

            if (!WorldManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("WorldManager reflection validation failed!");
            }

            if (!RadioManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("RadioManager reflection validation failed!");
            }

            if (!RadioManagerNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("RadioManagerNetworkManager reflection validation failed!");
            }

            if (!PowerManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PowerManager reflection validation failed!");
            }

            if (!FactionsManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("FactionsManager reflection validation failed!");
            }

            if (!Faction.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("Faction reflection validation failed!");
            }

            if (!PowerProducer.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PowerProducer reflection validation failed!");
            }

            if (!PowerReceiver.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PowerReceiver reflection validation failed!");
            }

            result &= RunCubeBlockReflectionTests();

            if (result)
            {
                Console.WriteLine("All main types passed reflection unit tests!");
            }

            return(result);
        }
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (words.Length != 1)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            DateTime            start    = DateTime.Now;
            HashSet <IMyEntity> entities = new HashSet <IMyEntity>();

            MyAPIGateway.Entities.GetEntities(entities);
            int count    = 0;
            int enabled  = 0;
            int disabled = 0;
            int keepOn   = 0;

            foreach (IMyEntity entity in entities)
            {
                if (!(entity is IMyCubeGrid))
                {
                    continue;
                }

                if (!entity.InScene)
                {
                    continue;
                }

                IMyCubeGrid grid = (IMyCubeGrid)entity;
                //MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity);
                //if (builder == null)
                //	continue;

                List <IMySlimBlock> blocks = new List <IMySlimBlock>();
                grid.GetBlocks(blocks);
                foreach (IMySlimBlock block in blocks)
                //foreach (MyObjectBuilder_CubeBlock block in builder.CubeBlocks)
                {
                    //if (block is MyObjectBuilder_TurretBase)
                    if (block.FatBlock == null)
                    {
                        continue;
                    }

                    if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_InteriorTurret) ||
                        block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LargeGatlingTurret) ||
                        block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LargeMissileTurret))
                    {
                        //IMyEntity turret = MyAPIGateway.Entities.GetEntityById(block.EntityId);
                        IMyEntity turret = block.FatBlock;
                        bool      state  = FunctionalBlockEntity.GetState(turret);

                        if (words[0].ToLower() == "toggle")
                        {
                            FunctionalBlockEntity.SetState(turret, !state);
                        }

                        count++;

                        if (state)
                        {
                            enabled++;
                        }
                        else
                        {
                            disabled++;
                        }

                        if (words[0].ToLower() == "test" && state)
                        {
                            BoundingSphereD  sphere       = new BoundingSphereD(grid.GetPosition(), 2000);
                            List <IMyEntity> testEntities = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
                            bool             found        = false;
                            foreach (IMyEntity testEntity in testEntities)
                            {
                                if (entity == testEntity)
                                {
                                    continue;
                                }

                                if (testEntity is IMyCubeBlock)
                                {
                                    continue;
                                }

                                if (!(testEntity is IMyControllableEntity))
                                {
                                    //Console.WriteLine("Entity: {0}", testEntity.GetType());
                                    continue;
                                }


                                IMyCubeGrid testGrid = testEntity as IMyCubeGrid;
                                if (testGrid != null)
                                {
                                    foreach (long owner in testGrid.BigOwners)
                                    {
                                        if (block.FatBlock.GetUserRelationToOwner(owner) == MyRelationsBetweenPlayerAndBlock.Enemies ||
                                            block.FatBlock.GetUserRelationToOwner(owner) == MyRelationsBetweenPlayerAndBlock.Neutral)
                                        {
                                            found = true;
                                            keepOn++;
                                            break;
                                        }
                                        else
                                        {
                                            Console.WriteLine("Relation: {0} - {1}", block.FatBlock.GetUserRelationToOwner(owner), testGrid.DisplayName);
                                        }
                                    }

                                    if (found)
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    var builderBase             = testEntity.GetObjectBuilder();
                                    MyObjectBuilder_Character c = builderBase as MyObjectBuilder_Character;
                                    if (c != null)
                                    {
                                        ulong steamId = PlayerMap.Instance.GetSteamId(c.EntityId);
                                        if (steamId < 1)
                                        {
                                            continue;
                                        }

                                        long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(steamId);
                                        if (playerId < 1)
                                        {
                                            continue;
                                        }

                                        if (block.FatBlock.GetUserRelationToOwner(playerId) == MyRelationsBetweenPlayerAndBlock.Enemies ||
                                            block.FatBlock.GetUserRelationToOwner(playerId) == MyRelationsBetweenPlayerAndBlock.Neutral)
                                        {
                                            found = true;
                                            keepOn++;
                                            break;
                                        }

/*
 *                                                                              else
 *                                                                              {
 *                                                                                      Console.WriteLine("Character Relation: {0} - {1}", block.FatBlock.GetUserRelationToOwner(playerId), c.DisplayName);
 *                                                                              }
 */
                                        if (found)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }

                            //break;
                        }
                    }
                }
            }

            Communication.SendPrivateInformation(userId, string.Format("{0} turrets.  {1} on, {2} off.  {3} keepon ({4} ms)", count, enabled, disabled, keepOn, (DateTime.Now - start).TotalMilliseconds));
            return(true);
        }