Пример #1
0
        public static int GridWeaponCount(GridEntity grid)
        {
            int result = 0;

            foreach (var gun in grid.Guns)
            {
                if (!gun.ActiveEntity())
                {
                    continue;
                }

                result++;
            }

            foreach (var turret in grid.Turrets)
            {
                if (!turret.ActiveEntity())
                {
                    continue;
                }

                result++;
            }

            return(result);
        }
Пример #2
0
        public static Vector2 GridPowerOutput(GridEntity grid)
        {
            var result = Vector2.Zero;

            if (grid.IsClosed())
            {
                return(result);
            }

            foreach (var block in grid.Power)
            {
                if (block.IsClosed() || !block.Working || !block.Functional)
                {
                    continue;
                }

                var powerBlock = block.Block as IMyPowerProducer;

                if (powerBlock == null)
                {
                    continue;
                }

                result.X += powerBlock.CurrentOutput;
                result.Y += powerBlock.MaxOutput;
            }

            return(result);
        }
Пример #3
0
        public static void NewEntityDetected(IMyEntity entity)
        {
            var cubeGrid = entity as IMyCubeGrid;

            if (cubeGrid != null)
            {
                lock (GridManager.Grids) {
                    var gridEntity = new GridEntity(entity);
                    UnloadEntities += gridEntity.Unload;
                    GridManager.Grids.Add(gridEntity);
                }

                return;
            }

            var planet = entity as MyPlanet;

            if (planet != null)
            {
                var planetEntity = new PlanetEntity(entity);
                UnloadEntities += planetEntity.Unload;
                Planets.Add(planetEntity);
                return;
            }

            var safezone = entity as MySafeZone;

            if (safezone != null)
            {
                var safezoneEntity = new SafeZoneEntity(entity);
                UnloadEntities += safezoneEntity.Unload;
                SafeZones.Add(safezoneEntity);
                return;
            }
        }
Пример #4
0
        public static int GridVisibleMovementScore(GridEntity grid)
        {
            var speed = grid.CurrentSpeed();

            if (speed < 1)
            {
                return(0);
            }

            return((int)(grid.BoundingBoxSize() * speed));
        }
Пример #5
0
        public static double GridBroadcastRange(GridEntity grid, bool onlyAntenna = false)
        {
            double result = 0;

            foreach (var antenna in grid.Antennas)
            {
                if (antenna.IsClosed() || !antenna.Working || !antenna.Functional)
                {
                    continue;
                }

                var antennaBlock = antenna.Block as IMyRadioAntenna;

                if (antennaBlock == null || !antennaBlock.IsBroadcasting)
                {
                    continue;
                }

                if (antennaBlock.Radius > result)
                {
                    result = antennaBlock.Radius;
                }
            }

            if (onlyAntenna)
            {
                return(result);
            }

            foreach (var beacon in grid.Beacons)
            {
                if (beacon.IsClosed() || !beacon.Working || !beacon.Functional)
                {
                    continue;
                }

                var beaconBlock = beacon.Block as IMyBeacon;

                if (beaconBlock == null)
                {
                    continue;
                }

                if (beaconBlock.Radius > result)
                {
                    result = beaconBlock.Radius;
                }
            }

            return(result);
        }
Пример #6
0
        public static float GridTargetValue(GridEntity grid)
        {
            float result = 0;

            if (grid.IsClosed())
            {
                return(result);
            }

            result += GetTargetValueFromBlockList(grid.Antennas, 4, 2);
            result += GetTargetValueFromBlockList(grid.Beacons, 3, 2);
            result += GetTargetValueFromBlockList(grid.Containers, 0.5f, 2, true);
            result += GetTargetValueFromBlockList(grid.Controllers, 0.5f, 2);
            result += GetTargetValueFromBlockList(grid.Gravity, 2, 4, true);
            result += GetTargetValueFromBlockList(grid.Guns, 5, 4, true);
            result += GetTargetValueFromBlockList(grid.JumpDrives, 10, 2);
            result += GetTargetValueFromBlockList(grid.Mechanical, 1, 2);
            result += GetTargetValueFromBlockList(grid.Medical, 10, 2);
            result += GetTargetValueFromBlockList(grid.NanoBots, 15, 2);
            result += GetTargetValueFromBlockList(grid.Production, 2, 2, true);
            result += GetTargetValueFromBlockList(grid.Power, 0.5f, 2, true);
            result += GetTargetValueFromBlockList(grid.Shields, 15, 2);
            result += GetTargetValueFromBlockList(grid.Thrusters, 1, 2);
            result += GetTargetValueFromBlockList(grid.Tools, 2, 2, true);
            result += GetTargetValueFromBlockList(grid.Turrets, 7.5f, 4, true);

            //Factor Power

            //Factor Total Block Count

            //Factor Static/Dynamic

            //Factor Grid Box Size

            //Factor Cube Size

            return(result);
        }
Пример #7
0
        public static bool GridShielded(GridEntity grid)
        {
            if (grid.IsClosed())
            {
                return(false);
            }

            if (EntityShielded(grid.CubeGrid))
            {
                return(true);
            }

            foreach (var shield in grid.Shields)
            {
                if (shield.IsClosed() || !shield.Working || !shield.Functional)
                {
                    continue;
                }

                return(true);
            }

            return(false);
        }
Пример #8
0
        public static bool IsPlayerControlled(GridEntity cubeGrid)
        {
            foreach (var controller in cubeGrid.Controllers)
            {
                if (!controller.ActiveEntity())
                {
                    continue;
                }

                IMyShipController shipController = controller.Block as IMyShipController;

                if (shipController == null)
                {
                    continue;
                }

                if (shipController.CanControlShip && shipController.IsUnderControl)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #9
0
        public static void GetBlocksFromGrid <T>(GridEntity grid, List <IMySlimBlock> blocks) where T : class
        {
            if (grid == null || !grid.ActiveEntity())
            {
                return;
            }

            lock (grid.AllTerminalBlocks) {
                for (int j = grid.AllTerminalBlocks.Count - 1; j >= 0; j--)
                {
                    var block = grid.AllTerminalBlocks[j];

                    if (block == null || !block.ActiveEntity())
                    {
                        continue;
                    }

                    if (block.Block as T != null)
                    {
                        blocks.Add(block.Block.SlimBlock);
                    }
                }
            }
        }
Пример #10
0
 public static bool GridPowered(GridEntity grid)
 {
     return(grid.IsPowered());
 }