Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(UpdateChance(GrowCactus) && Cactus.Tile.Conditions(Nactive, NotHalfBrick, NoSlope, NoLiquidOnTile))
- {
- if (Cactus.Tile.IsOneOf(Sand, Ebonsand, Pearlsand, Crimsand) && !TileLoader.CanGrowModCactus(Cactus.Tile.type))
- {
- return;
- }
- if (Cactus.Tile.IsOneOf(Sand, Ebonsand, Pearlsand, Crimsand) || TileLoader.CanGrowModCactus(Cactus.Tile.type))
- {
- // If the three tiles above are open.
- if (Cactus.TileAbove.active() || Cactus.TileTLCorner.active() || Cactus.TileTRCorner.active())
- {
- return;
- }
- // This is to store the count of how tall the cactus is
- int CactusHeightCounter = 0;
- int SandCounter = 0;
- // This searches the amount of cacti and sand in the area.
- for (int XIndex = Cactus.Location.X - 6; XIndex <= Cactus.Location.X + 6; XIndex++)
- {
- for (int YIndex = Cactus.Location.Y - 3; YIndex <= Cactus.Location.Y + 1; YIndex++)
- {
- Tile CurrentTile = tile[XIndex, YIndex];
- if (CurrentTile.active())
- {
- if (CurrentTile.type == TileID.Cactus)
- {
- CactusHeightCounter++;
- if (CactusHeightCounter >= MaxCactusHeight)
- {
- return;
- }
- }
- if (CurrentTile.IsOneOf(Sand, Ebonsand, Pearlsand, Crimsand) || TileLoader.CanGrowModCactus(CurrentTile.type))
- {
- SandCounter++;
- }
- }
- }
- }
- if (SandCounter > 10)
- {
- Cactus.TileAbove.active(true);
- Cactus.TileAbove.type = TileID.Cactus;
- if (netMode == 2)
- {
- NetMessage.SendTileSquare(-1, Cactus.Location.X, Cactus.Location.Y - 1, 1, TileChangeType.None);
- }
- SquareTileFrame(Cactus.Location.X, Cactus.Location.Y - 1, true);
- return;
- }
- return;
- }
- else
- {
- if (Cactus.Tile.type != TileID.Cactus)
- {
- return;
- }
- // The purpose of this while loop is to find the base of a cactus if it picked a tile
- // that was not the base of the cactus against the ground.
- // By the end of the loop buffer X and buffer Y will contain coordinates of the basetile of the cactus.
- while (Buffer.Tile.active() && Buffer.Tile.type == TileID.Cactus)
- {
- // Go down one tile
- BufferY++;
- // Until you reach a tile with no cactus.
- if (!Buffer.Tile.active() || Buffer.Tile.type != TileID.Cactus)
- {
- // If cactus tile to the left or corner, move left.
- if (Buffer.TileLeft.active() && Buffer.TileLeft.type == TileID.Cactus &&
- Buffer.TileLLCorner.active() && Buffer.TileLLCorner.Is(TileID.Cactus) &&
- BufferX >= Cactus.Location.X)
- {
- BufferX--;
- }
- // Same concept but move right.
- if (Buffer.TileRight.active() && Buffer.TileRight.type == TileID.Cactus &&
- Buffer.TileTRCorner.active() && Buffer.TileTRCorner.type == 80 &&
- BufferX <= Cactus.Location.X)
- {
- BufferX++;
- }
- }
- // Update struct to contain changed buffers.
- Buffer = new TileAt(BufferX,BufferY);
- }
- // Increments the buffer Y position to the base of the cactus.
- BufferY--;
- // The Y offset of one tile up vs starting tile
- /*was num5 */int YBaseOffset = BufferY - Cactus.Location.Y;
- // Seems to be the X offset from the base tile.
- /*was num6 */int XBaseOffset = Cactus.Location.X - BufferX;
- // buffers are now changed to the top left of an rectangle encompassing the cactus.
- BufferX = Cactus.Location.X - XBaseOffset;
- BufferY = Cactus.Location.Y;
- // Cactii have 11 as the default maximum height.
- /*was num7 */int MaxHeight = MaxCacHeight - YBaseOffset;
- // Used to basically say how many pieces of cacti tile this cactus have.
- int CactusCounter = 0;
- // This counts the total amount of tiles of cacti are around for this cactus.
- for (int XIndex = BufferX - 2; XIndex <= BufferX + 2; XIndex++)
- {
- for (int YIndex = BufferY - MaxHeight; YIndex <= BufferY + YBaseOffset; YIndex++)
- {
- if (tile[XIndex, YIndex].IsActiveAndType(TileID.Cactus))
- {
- CactusCounter++;
- }
- }
- }
- // If this cactus is made up of less than 11 to 13 pieces.
- if (CactusCounter < genRand.Next(11, 13))
- {
- // Reset buffers back to updating tile's location.
- BufferX = Cactus.Location.X;
- BufferY = Cactus.Location.Y;
- Buffer = new TileAt(BufferX, BufferY);
- if (XBaseOffset == 0)
- {
- if (YBaseOffset == 0)
- {
- // This chain of logic basically occurs when the cactus only had a single tile making up its whole body.
- //This cancels control of the method if there is a solid tile blocking the way.
- if (Main.tile[BufferX, BufferY - 1].active())
- {
- return;
- }
- // Set and activate Tile and then send the appropriate networking data if running on a server.
- Buffer.TileAbove.SetTypeAndActivate(TileID.Cactus);
- SquareTileFrame(BufferX, BufferY - 1, true);
- if (netMode == 2)
- {
- NetMessage.SendTileSquare(-1, BufferX, BufferY - 1, 1, TileChangeType.None);
- return;
- }
- return;
- }
- else
- {
- bool flag = false;
- bool flag2 = false;
- if (Buffer.TileAbove.IsActiveAndType(TileID.Cactus))
- {
- if (!Main.tile[BufferX - 1, BufferY].active() && !Main.tile[BufferX - 2, BufferY + 1].active() && !Main.tile[BufferX - 1, BufferY - 1].active() && !Main.tile[BufferX - 1, BufferY + 1].active() && !Main.tile[BufferX - 2, BufferY].active())
- {
- flag = true;
- }
- if (!Main.tile[BufferX + 1, BufferY].active() && !Main.tile[BufferX + 2, BufferY + 1].active() && !Main.tile[BufferX + 1, BufferY - 1].active() && !Main.tile[BufferX + 1, BufferY + 1].active() && !Main.tile[BufferX + 2, BufferY].active())
- {
- flag2 = true;
- }
- }
- int num9 = WorldGen.genRand.Next(3);
- if (num9 == 0 && flag)
- {
- Main.tile[BufferX - 1, BufferY].active(true);
- Main.tile[BufferX - 1, BufferY].type = 80;
- WorldGen.SquareTileFrame(BufferX - 1, BufferY, true);
- if (Main.netMode == 2)
- {
- NetMessage.SendTileSquare(-1, BufferX - 1, BufferY, 1, TileChangeType.None);
- return;
- }
- return;
- }
- else if (num9 == 1 && flag2)
- {
- Main.tile[BufferX + 1, BufferY].active(true);
- Main.tile[BufferX + 1, BufferY].type = 80;
- WorldGen.SquareTileFrame(BufferX + 1, BufferY, true);
- if (Main.netMode == 2)
- {
- NetMessage.SendTileSquare(-1, BufferX + 1, BufferY, 1, TileChangeType.None);
- return;
- }
- return;
- }
- else
- {
- if (num5 >= WorldGen.genRand.Next(2, 8))
- {
- return;
- }
- if (Main.tile[BufferX - 1, BufferY - 1].active())
- {
- ushort arg_6E7_0 = Main.tile[BufferX - 1, BufferY - 1].type;
- }
- if (Main.tile[BufferX + 1, BufferY - 1].active() && Main.tile[BufferX + 1, BufferY - 1].type == 80)
- {
- return;
- }
- if (Main.tile[BufferX, BufferY - 1].active())
- {
- return;
- }
- Main.tile[BufferX, BufferY - 1].active(true);
- Main.tile[BufferX, BufferY - 1].type = 80;
- WorldGen.SquareTileFrame(BufferX, BufferY - 1, true);
- if (Main.netMode == 2)
- {
- NetMessage.SendTileSquare(-1, BufferX, BufferY - 1, 1, TileChangeType.None);
- return;
- }
- return;
- }
- }
- }
- else
- {
- if (Main.tile[BufferX, BufferY - 1].active() || Main.tile[BufferX, BufferY - 2].active() || Main.tile[BufferX + num6, BufferY - 1].active() || !Main.tile[BufferX - num6, BufferY - 1].active() || Main.tile[BufferX - num6, BufferY - 1].type != 80)
- {
- return;
- }
- Main.tile[BufferX, BufferY - 1].active(true);
- Main.tile[BufferX, BufferY - 1].type = 80;
- WorldGen.SquareTileFrame(BufferX, BufferY - 1, true);
- if (Main.netMode == 2)
- {
- NetMessage.SendTileSquare(-1, BufferX, BufferY - 1, 1, TileChangeType.None);
- return;
- }
- return;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement