Advertisement
Guest User

Cactus Door

a guest
Mar 22nd, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.07 KB | None | 0 0
  1.  private void MakeWell()
  2.         {
  3.             float widthScale = (Main.maxTilesX / 4200f); //something about floating numbers
  4.             int numberToGenerate = WorldGen.genRand.Next(1, (int)(2f * widthScale));  
  5.             for (int k = 0; k < numberToGenerate; k++)
  6.             {
  7.                 bool success = false;
  8.                 int attempts = 0;
  9.                 while (!success)
  10.                 {
  11.                     attempts++;
  12.                     if (attempts > 1000)
  13.                     {
  14.                         success = true;
  15.                         continue;
  16.                     }
  17.                     int i = WorldGen.genRand.Next(300, Main.maxTilesX - 300);
  18.                     if (i <= Main.maxTilesX / 2 - 50 || i >= Main.maxTilesX / 2 + 50)  
  19.                     {
  20.                         int j = 0;
  21.                         while (!Main.tile[i, j].active() && (double)j < Main.worldSurface)
  22.                         {
  23.                             j++;
  24.                         }
  25.                         if (Main.tile[i, j].type == TileID.Dirt)  //spawn on type of tile
  26.                         {
  27.                             j--;
  28.                             if (j > 150)
  29.                             {
  30.                                 bool placementOK = true;
  31.                                 for (int l = i - 4; l < i + 4; l++)
  32.                                 {
  33.                                     for (int m = j - 6; m < j + 20; m++) //i don't know what this line does
  34.                                     {
  35.                                         if (Main.tile[l, m].active())
  36.                                         {
  37.                                             int type = (int)Main.tile[l, m].type;
  38.                                             if (type == TileID.BlueDungeonBrick || type == TileID.GreenDungeonBrick || type == TileID.PinkDungeonBrick || type == TileID.Cloud || type == TileID.RainCloud)
  39.                                             {
  40.                                                 placementOK = false;
  41.                                             }
  42.                                         }
  43.                                     }
  44.                                 }
  45.                                 if (placementOK)
  46.                                 {
  47.                                     success = PlaceWell(i, j);
  48.                                 }
  49.                             }
  50.                         }
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.  
  56.         int[,] wellshape = new int[,]
  57.         {
  58.             {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
  59.             {1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1 },
  60.             {1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1 },
  61.             {1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1 },
  62.             {1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1 },
  63.             {1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1 },
  64.             {0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1 }, //trying to put a door here
  65.             {0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1 },
  66.             {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
  67.  
  68.         };
  69.  
  70.  
  71.  
  72.         int[,] wellshapeWall = new int[,]
  73.         {
  74.             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  75.             {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 },
  76.             {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 },
  77.             {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 },
  78.             {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 },
  79.             {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 },
  80.             {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 },
  81.             {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 },
  82.             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  83.  
  84.  
  85.         };
  86.  
  87.         int[,] wellshapeWater = new int[,]
  88.         {
  89.             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  90.             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  91.             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  92.             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  93.             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  94.             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  95.             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  96.             {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 },
  97.             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  98.            
  99.         };
  100.  
  101.         public bool PlaceWell(int i, int j)
  102.         {
  103.             if (!WorldGen.SolidTile(i, j + 1))
  104.             {
  105.                 return false;
  106.             }
  107.             if (Main.tile[i, j].active())
  108.             {
  109.                 return false;
  110.             }
  111.             if (j < 150)
  112.             {
  113.                 return false;
  114.             }
  115.            
  116.            
  117.  
  118.                 for (int y = 0; y < wellshape.GetLength(0); y++)
  119.             {
  120.                 for (int x = 0; x < wellshape.GetLength(1); x++)
  121.                 {
  122.                     int k = i - 3 + x;
  123.                     int l = j - 6 + y;
  124.  
  125.                     if (WorldGen.InWorld(k, l, 30))
  126.                         WorldGen.PlaceTile(k + -1, l + 2, 10, true, false, 0, 4); //placing the door
  127.  
  128.                     if (WorldGen.InWorld(k, l, 30))
  129.                     {
  130.                         Tile tile = Framing.GetTileSafely(k, l);
  131.                         switch (wellshape[y, x])                        {
  132.                             case 1:
  133.                                 tile.type = TileID.PearlstoneBrick;  //roof
  134.                                 tile.active(true);
  135.                                 break;
  136.                             case 2:
  137.                                 tile.type = TileID.SilverBrick;  //base edge
  138.                                 tile.active(true);
  139.                                 tile.halfBrick(true);
  140.                                 break;
  141.                             case 3:
  142.                                 tile.type = TileID.CopperBrick;  //left slant
  143.                                 tile.active(true);
  144.                                 tile.slope(2);  //to get the correct slope shader
  145.                                 break;
  146.                             case 4:
  147.                                 tile.type = TileID.MeteoriteBrick;  //right slant
  148.                                 tile.active(true);
  149.                                 tile.slope(1);
  150.                                 break;
  151.                             case 5:
  152.                                 tile.active(false);       //nothing here
  153.                                 break;
  154.                             case 6:
  155.                                 tile.type = TileID.Rope;
  156.                                 tile.active(true);
  157.                                 break;
  158.                        
  159.                                
  160.                         }
  161.                        
  162.                         switch (wellshapeWall[y, x])
  163.                         {
  164.                             case 1:
  165.                                 tile.wall = WallID.SnowBrick;    //wall of well
  166.                                 break;
  167.                         }
  168.                         switch (wellshapeWater[y, x])
  169.                         {
  170.                             case 1:
  171.                                 tile.liquid = 255; //fills with corresponding biome liquid
  172.                                 break;
  173.                         }
  174.                     }
  175.                 }
  176.             }
  177.             return true;
  178.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement