Пример #1
0
        private static bool intersects(MapSectionRasterTile tile, int tileSize, Vector position, float radius)
        {
            // TODO: Change Maths to Intrinsics on net core 3.0

            // Find the closest point to the circle within the rectangle
            // Calculate the distance between the circle's center and this closest point
            float distanceX = position.X - MathUtil.Clamp(position.X, tile.X - tileSize / 2f, tile.X + tileSize / 2f);
            float distanceY = position.Y - MathUtil.Clamp(position.Y, tile.Y - tileSize / 2f, tile.Y + tileSize / 2f);

            // If the distance is less than the circle's radius, an intersection occurs
            return((distanceX * distanceX) + (distanceY * distanceY) < (radius * radius));
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mapSection"></param>
        /// <param name="tileSize"></param>
        internal MapSectionRaster(MapSection mapSection, int tileSize)
        {
            MapSection = mapSection;
            TileSize   = tileSize;

            //Stopwatch sw = Stopwatch.StartNew();

            //float width = mapSection.Left < 0 ? Math.Abs(mapSection.Left) + mapSection.Right : Math.Abs(mapSection.Left - mapSection.Right);
            //float height = mapSection.Top < 0 ? Math.Abs(mapSection.Top) + mapSection.Bottom : Math.Abs(mapSection.Top - mapSection.Bottom);
            Size = (int)((float)Map.SectionSize / tileSize + 0.5f);

            int startX = (int)(mapSection.Left + 0.5f);
            int startY = (int)(mapSection.Top + 0.5f);

            Tiles = new MapSectionRasterTile[Size * Size];

            #region Connecting tiles code
            //TopConnectingTiles = new MapSectionRasterConnectingTile[Size];
            //RightConnectingTiles = new MapSectionRasterConnectingTile[Size];
            //BottomConnectingTiles = new MapSectionRasterConnectingTile[Size];
            //LeftConnectingTiles = new MapSectionRasterConnectingTile[Size];
            #endregion

            MapUnit[] stillUnits = mapSection.StillUnits;
            for (int i = 0; i < Tiles.Length; i++)
            {
                int xIndex = i % Size, yIndex = i / Size;

                var tile = new MapSectionRasterTile();
                tile.X = startX + tileSize * xIndex + tileSize / 2f;
                tile.Y = startY + tileSize * yIndex + tileSize / 2f;

                for (int unitIndex = 0; unitIndex < stillUnits.Length; unitIndex++)
                {
                    MapUnit mapUnit = stillUnits[unitIndex];

                    if (mapUnit == null)
                    {
                        break;
                    }

                    // TODO: Hier sollte noch eine Überprüfung für spezielle Units rein
                    // die je nachdem einen Bereich als schlecht oder gut definieren
                    // Sonne z.B. die Koronas als gut, Blackholes der Wirkungskreis als schlecht

                    if (mapUnit.IsSolid &&
                        mapUnit.Mobility == Mobility.Still &&
                        intersects(tile, tileSize, mapUnit.PositionInternal, mapUnit.RadiusInternal))
                    {
                        tile.Status = MapSectionRasterTileStatus.Blocked;
                    }
                }

                Tiles[i] = tile;

                #region Connecting tiles code
                //if (xIndex == 0)
                //{
                //    tile.Status |= MapSectionRasterTileStatus.Connecting;
                //    LeftConnectingTiles[yIndex] = new MapSectionRasterConnectingTile(tile);
                //}
                //else if (xIndex == (Size - 1))
                //{
                //    tile.Status |= MapSectionRasterTileStatus.Connecting;
                //    RightConnectingTiles[yIndex] = new MapSectionRasterConnectingTile(tile);
                //}

                //if (yIndex == 0)
                //{
                //    tile.Status |= MapSectionRasterTileStatus.Connecting;
                //    TopConnectingTiles[xIndex] = new MapSectionRasterConnectingTile(tile);
                //}
                //else if (yIndex == (Size - 1))
                //{
                //    tile.Status |= MapSectionRasterTileStatus.Connecting;
                //    BottomConnectingTiles[xIndex] = new MapSectionRasterConnectingTile(tile);
                //}
                #endregion
            }

            //Console.WriteLine("Raster time: " + sw.Elapsed);
        }
 public MapSectionRasterConnectingTile(MapSectionRasterTile from)
 {
     From = from;
 }