////

        private static void ErodeBramblesWithinAreaRadiusRandomly(int tileX, int tileY, int adjacentRadius)
        {
            int minX        = tileX - (adjacentRadius / 2);
            int maxX        = tileX + (adjacentRadius / 2);
            int minY        = tileY - (adjacentRadius / 2);
            int maxY        = tileY + (adjacentRadius / 2);
            int brambleType = ModContent.TileType <CursedBrambleTile>();

            for (int i = minX; i < maxX; i++)
            {
                for (int j = minY; j < maxY; j++)
                {
                    if (!WorldGen.InWorld(i, j))
                    {
                        continue;
                    }

                    Tile tile = Framing.GetTileSafely(i, j);
                    if (!tile.active() || tile.type != brambleType)
                    {
                        continue;
                    }

                    CursedBrambleTile.ErodeBramblesAtRandomly(i, j);
                }
            }
        }
Exemplo n.º 2
0
        ////////////////

        private static double GaugeProspectiveBrambleTile(
            int radius,
            int plrTileX,
            int plrTileY,
            int testTileX,
            int testTileY)
        {
            int diffX = testTileX - plrTileX;
            int diffY = testTileY - plrTileY;

            double dist = Math.Sqrt((diffX * diffX) + (diffY * diffY));

            double radiusFirstDist      = (double)radius * 0.25d;
            double radiusLastDist       = (double)radius - radiusFirstDist;
            double distAfterFirstRadius = dist - radiusFirstDist;

            // distance before the radius's 1/4 mark give diminishing returns
            double weight = dist <= radiusFirstDist
                                ? dist / radiusFirstDist
                                : 0d;

            // distance after the radius's 1/4 mark give diminishing returns
            weight += dist > radiusFirstDist
                                ? Math.Max(1d - (distAfterFirstRadius / radiusLastDist), 0d)
                                : 0d;

            (int solids, int brambles)neighbors = CursedBrambleTile.CountAdjacentBrambles(testTileX, testTileY);

            if (neighbors.solids >= 1)
            {
                if (neighbors.solids <= 3)
                {
                    weight += 0.35d;                     // Edges favored
                }
                else
                {
                    weight -= 0.35d;                            // Unfavor tight spaces
                }
            }

            if (neighbors.brambles >= 1)
            {
                if (neighbors.brambles <= 2)
                {
                    weight += 0.5d;                     // Good for veins and forks
                }
                else
                {
                    weight -= 0.5d;                     // Not too crowded
                }
            }

            return(weight);
        }
Exemplo n.º 3
0
        /// <summary></summary>
        /// <param name="worldPos"></param>
        /// <param name="radius"></param>
        /// <param name="sync"></param>
        public static void CreateNearbyIf(
            Vector2 worldPos,
            int radius,
            Func <int, int, bool> validateAt,
            bool sync)
        {
            int numChecks = radius / 4;

            int tileX = (int)worldPos.X / 16;
            int tileY = (int)worldPos.Y / 16;

            int minX = Math.Max(tileX - radius, 0);
            int maxX = Math.Min(tileX + radius, Main.maxTilesX - 1);
            int minY = Math.Max(tileY - radius, 0);
            int maxY = Math.Min(tileY + radius, Main.maxTilesY - 1);

            (int x, int y, double weight)randPoint = default;

            for (int i = 1; i < numChecks; i++)
            {
                (int x, int y)newPoint = (Main.rand.Next(minX, maxX), Main.rand.Next(minY, maxY));

                if (!CursedBrambleTile.CanPlaceBrambleAt(newPoint.x, newPoint.y))
                {
                    continue;
                }
                if (!(validateAt?.Invoke(newPoint.x, newPoint.y) ?? true))
                {
                    continue;
                }

                double weight = CursedBrambleTile.GaugeProspectiveBrambleTile(
                    radius,
                    tileX,
                    tileY,
                    newPoint.x,
                    newPoint.y
                    );
                if (weight > randPoint.weight)
                {
                    randPoint = (newPoint.x, newPoint.y, weight);
                }
            }

            if (randPoint != default)
            {
                CursedBrambleTile.CreateBrambleAtIf(randPoint.x, randPoint.y, sync);
            }
        }
        /// <summary>
        /// Attempts to remove a random bramble within a given (tile) area.
        /// </summary>
        /// <param name="minTileX"></param>
        /// <param name="minTileY"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="adjacentRadius"></param>
        /// <param name="sync"></param>
        /// <returns>`true` if a bramble was found and removed.</returns>
        public static bool ErodeRandomBrambleWithinArea(
            int minTileX,
            int minTileY,
            int width,
            int height,
            int adjacentRadius,
            bool sync)
        {
            int randTileX = minTileX + TmlLibraries.SafelyGetRand().Next(width);
            int randTileY = minTileY + TmlLibraries.SafelyGetRand().Next(height);

            Tile tile = Framing.GetTileSafely(randTileX, randTileY);

            if (!tile.active() || tile.type != ModContent.TileType <CursedBrambleTile>())
            {
                return(false);
            }

            if (!sync)
            {
                WorldGen.KillTile(
                    i: randTileX,
                    j: randTileY,
                    fail: false,
                    effectOnly: false,
                    noItem: true
                    );
                WorldGen.SquareTileFrame(randTileX, randTileY);
            }
            else
            {
                TileLibraries.KillTile(
                    tileX: randTileX,
                    tileY: randTileY,
                    effectOnly: false,
                    dropsItem: false,
                    forceSyncIfUnchanged: true
                    );
            }

            CursedBrambleTile.ErodeBramblesWithinAreaRadiusRandomly(minTileX, minTileY, adjacentRadius);

            return(true);
        }
        ////////////////

        /// <summary>
        /// Attempts to remove a random bramble within a given (tile) radius of a given tile.
        /// </summary>
        /// <param name="tileX"></param>
        /// <param name="tileY"></param>
        /// <param name="radius"></param>
        /// <param name="adjacentRadius"></param>
        /// <returns>`true` if a bramble was found and removed.</returns>
        public static bool ErodeRandomBrambleWithinRadius(int tileX, int tileY, int radius, int adjacentRadius)
        {
            int randX     = TmlLibraries.SafelyGetRand().Next(radius * 2);
            int randY     = TmlLibraries.SafelyGetRand().Next(radius * 2);
            int randTileX = tileX + (randX - radius);
            int randTileY = tileY + (randY - radius);

            Tile tile = Framing.GetTileSafely(randTileX, randTileY);

            if (!tile.active() || tile.type != ModContent.TileType <CursedBrambleTile>())
            {
                return(false);
            }

            TileLibraries.KillTile(randTileX, randTileY, false, false, true);

            CursedBrambleTile.ErodeBramblesWithinAreaRadiusRandomly(tileX, tileY, adjacentRadius);

            return(true);
        }