Advertisement
QuantumWarpCode

MCEdit Citygen Filter V2

Feb 13th, 2016
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 22.19 KB | None | 0 0
  1. # Made by @QuantumWarpCode.
  2. # Feel free to modify and use this filter however you wish.
  3. # If you do, please give credit to Elopus, Elopus001, or @QuantumWarpCode.
  4. # Version : 1
  5.  
  6. # Import Libraries
  7. # PyMC
  8. from pymclevel import alphaMaterials
  9. # Standard Python
  10. import random
  11. from math import ceil, floor
  12.  
  13. # Define Global Variables and MCEdit Related Values
  14.  
  15. displayName = "Procedural City"
  16.  
  17. inputs = [
  18.     (
  19.         ("Tutorial", "title"),
  20.         ("X - Width", "label"),
  21.         ("C is the number of chunks wide.", "label"),
  22.         ("X = 16C + 2", "label"),
  23.         ("Y - Height", "label"),
  24.         ("F is the number of floors high including basements.", "label"),
  25.         ("Y = 4F + 4", "label"),
  26.         ("Z - Length", "label"),
  27.         ("C is the number of chunks long.", "label"),
  28.         ("Z = 16C + 2", "label"),
  29.         ("Example selection box sizes:", "label"),
  30.         ("34W x 34L x 52H", "label"),
  31.         ("130W x 130L x 128H", "label")
  32.     ),
  33.     (
  34.         ("Options", "title"),
  35.         ("Basements", 3),
  36.         ("Minimum Height", 1),
  37.         ("Create Derelict Structures", True),
  38.         ("Create Empty Lots", True),
  39.         ("Experimental", "label"),
  40.         ("Height Randomization currently does nothing.", "label"),
  41.         ("Enable Height Randomization", False),
  42.     ),
  43.     (
  44.         ("Probabilities", "title"),
  45.         ("Higher values denote lower probability.", "label"),
  46.         ("It is based off of 1 divided by this value.", "label"),
  47.         ("Values below 1 will be set to the default", "label"),
  48.         ("Derelict Probability", 10),
  49.         ("Derelict Remove Block increases the probability of removing glass and plants but decreases probability of removing other blocks when its value is higher.", "label"),
  50.         ("Derelict Remove Block Probability", 10),
  51.         ("Lot Probability", 10),
  52.         ("Hedge Probability", 3),
  53.         ("Flower Probability", 2),
  54.         ("Flower Placement Probability", 5)
  55.     ),
  56.     (
  57.         ("Blocks", "title"),
  58.         ("Ground Block", alphaMaterials[1, 0]),
  59.         ("Grass Block", alphaMaterials[2, 0]),
  60.         ("Sidewalk Block", alphaMaterials[43, 0]),
  61.         ("Dirt Block", alphaMaterials[3, 1]),
  62.         ("Torch Block (Up)", alphaMaterials[50, 5]),
  63.         ("Building Wall Block", alphaMaterials[98, 0]),
  64.         ("Building Floor Block", alphaMaterials[5, 5]),
  65.         ("Glass Block", alphaMaterials[102, 0]),
  66.         ("Hedge Block", alphaMaterials[18, 7]),
  67.         ("Lighting Block", alphaMaterials[89, 0])
  68.     )
  69. ]
  70.  
  71. xMod = 0
  72. xLen = 0
  73. xTrueLen = 0
  74. yMod = 0
  75. yLen = 0
  76. yTrueLen = 0
  77. zMod = 0
  78. zLen = 0
  79. zTrueLen = 0
  80.  
  81. chunkHeightMap = []
  82. chunkPopulationMap = []
  83.  
  84. groundHeight = 0
  85. minHeight = 0
  86. maxHeight = 0
  87. maxBasements = 0
  88.  
  89. derelictProbability = 0
  90. derelictRProbability = 0
  91. lotProbability = 0
  92. hedgeProbability = 0
  93. flowerProbability = 0
  94. flowerPlaceProbability = 0
  95.  
  96. groundBlock = alphaMaterials[0, 0]
  97. dirtBlock = alphaMaterials[0, 0]
  98. grassBlock = alphaMaterials[0, 0]
  99. sideWalkBlock = alphaMaterials[0, 0]
  100. buildingWallBlock = alphaMaterials[0, 0]
  101. buildingFloorBlock = alphaMaterials[0, 0]
  102. lightingBlock = alphaMaterials[0, 0]
  103. torchBlock = alphaMaterials[0, 0]
  104. hedgeBlock = alphaMaterials[0, 0]
  105. glassBlock = alphaMaterials[0, 0]
  106.  
  107. createDerelicts = False
  108. createEmptyLots = False
  109. enableHeightMap = False
  110.  
  111. # Utility Functions
  112. # Sets a block with modifiers automatically applied
  113. def setBlock(x, y, z, block, blockdata, level, derelict = False):
  114.     global xMod
  115.     global yMod
  116.     global zMod
  117.    
  118.     if derelict == False:
  119.         level.setBlockAt(x + xMod, y + yMod, z + zMod, block)
  120.         level.setBlockDataAt(x + xMod, y + yMod, z + zMod, blockdata)
  121.     elif derelict == True:
  122.         global glassBlock
  123.         global hedgeBlock
  124.         global torchBlock
  125.         global derelictRProbability
  126.         probability = random.randint(1, derelictRProbability)
  127.         if (block == glassBlock.ID or block == hedgeBlock.ID or block == torchBlock.ID) and probability == 1:
  128.             level.setBlockAt(x + xMod, y + yMod, z + zMod, block)
  129.             level.setBlockDataAt(x + xMod, y + yMod, z + zMod, blockdata)
  130.         elif block != glassBlock.ID and block != hedgeBlock.ID and block != torchBlock.ID:
  131.             if block != 0 and random.randint(1, derelictRProbability) != 1:
  132.                 level.setBlockAt(x + xMod, y + yMod, z + zMod, block)
  133.                 level.setBlockDataAt(x + xMod, y + yMod, z + zMod, blockdata)
  134.             else:
  135.                 if random.randint(1, derelictRProbability) != 1:
  136.                     level.setBlockAt(x + xMod, y + yMod, z + zMod, 0)
  137.                     level.setBlockDataAt(x + xMod, y + yMod, z + zMod, 0)
  138.                 else:
  139.                     level.setBlockAt(x + xMod, y + yMod, z + zMod, 30)
  140.                     level.setBlockDataAt(x + xMod, y + yMod, z + zMod, 0)
  141.         else:
  142.             if random.randint(1, derelictRProbability) != 1:
  143.                 level.setBlockAt(x + xMod, y + yMod, z + zMod, 0)
  144.                 level.setBlockDataAt(x + xMod, y + yMod, z + zMod, 0)
  145.             else:
  146.                 level.setBlockAt(x + xMod, y + yMod, z + zMod, 30)
  147.                 level.setBlockDataAt(x + xMod, y + yMod, z + zMod, 0)
  148.  
  149. # Generates a rectangle
  150. def genRectangle(xStart, xEnd, y, zStart, zEnd, block, blockdata, level, derelict = False):
  151.     for x in range(xStart, xEnd):
  152.         for z in range(zStart, zEnd):
  153.             setBlock(x, y, z, block, blockdata, level, derelict)
  154.  
  155. # Generates a rectangle perimeter
  156. def genHollowRectangle(xStart, xEnd, y, zStart, zEnd, block, blockdata, level, derelict = False):
  157.     for x in range(xStart, xEnd):
  158.         for z in range(zStart, zEnd):
  159.             if x == xStart or x == xEnd - 1 or z == zStart or z == zEnd - 1:
  160.                 setBlock(x, y, z, block, blockdata, level, derelict)
  161.                
  162. # Generates a rectangle with a gooey center
  163. # Block is the outside and block2 is the center
  164. def genFilledRectangle(xStart, xEnd, y, zStart, zEnd, block, blockdata, block2, block2data, level, derelict = False):
  165.     for x in range(xStart, xEnd):
  166.         for z in range(zStart, zEnd):
  167.             if x == xStart or x == xEnd - 1 or z == zStart or z == zEnd - 1:
  168.                 setBlock(x, y, z, block, blockdata, level, derelict)
  169.             else:
  170.                 setBlock(x, y, z, block2, block2data, level, derelict)
  171.  
  172. # Generates a rectangle with different corners
  173. # Block is the insides and block2 is the corners
  174. def genCornerRectangle(xStart, xEnd, y, zStart, zEnd, block, blockdata, block2, block2data, level, derelict = False):
  175.     for x in range(xStart, xEnd):
  176.         for z in range(zStart, zEnd):
  177.             if (x == xStart or x == xEnd - 1) and (z == zStart or z == zEnd - 1):
  178.                 setBlock(x, y, z, block2, block2data, level, derelict)
  179.             else:
  180.                 setBlock(x, y, z, block, blockdata, level, derelict)
  181.                
  182. # Generates blocks in corners
  183. def genCorners(xStart, xEnd, y, zStart, zEnd, block, blockdata, level, derelict = False):
  184.     for x in range(xStart, xEnd):
  185.         for z in range(zStart, zEnd):
  186.             if (x == xStart or x == xEnd - 1) and (z == zStart or z == zEnd - 1):
  187.                 setBlock(x, y, z, block, blockdata, level, derelict)
  188.  
  189. # Generates a rectangle perimeter with different corners
  190. # Block is the edges and block2 is the corners
  191. def genHollowCornerRectangle(xStart, xEnd, y, zStart, zEnd, block, blockdata, block2, block2data, level, derelict = False):
  192.     for x in range(xStart, xEnd):
  193.         for z in range(zStart, zEnd):
  194.             if (x == xStart or x == xEnd - 1) and (z == zStart or z == zEnd - 1):
  195.                 setBlock(x, y, z, block, blockdata, level, derelict)
  196.             elif x == xStart or x == xEnd - 1 or z == zStart or z == zEnd - 1:
  197.                 setBlock(x, y, z, block2, block2data, level, derelict)
  198.                
  199. # Generates a rectangle with a gooey center and different corners
  200. # Block is the edges and block2 is the corners while block3 is the center
  201. def genFilledCornerRectangle(xStart, xEnd, y, zStart, zEnd, block, blockdata, block2, block2data, block3, block3data, level, derelict = False):
  202.     for x in range(xStart, xEnd):
  203.         for z in range(zStart, zEnd):
  204.             if (x == xStart or x == xEnd - 1) and (z == zStart or z == zEnd - 1):
  205.                 setBlock(x, y, z, block, blockdata, level, derelict)
  206.             elif x == xStart or x == xEnd - 1 or z == zStart or z == zEnd - 1:
  207.                 setBlock(x, y, z, block2, block2data, level, derelict)
  208.             else:
  209.                 setBlock(x, y, z, block3, block3data, level, derelict)
  210.  
  211. # Generates a cube
  212. def genCube(xStart, xEnd, yStart, yEnd, zStart, zEnd, block, blockdata, level, derelict = False):
  213.     for x in range(xStart, xEnd):
  214.         for y in range(yStart, yEnd):
  215.             for z in range(zStart, zEnd):
  216.                 setBlock(x, y, z, block, blockdata, level, derelict)
  217.  
  218. # Generates a rectangle of flowers
  219. def genFlowerRectangle(xStart, xEnd, y, zStart, zEnd, level):
  220.     global flowerPlaceProbability
  221.    
  222.     for x in range(xStart, xEnd):
  223.         for z in range(zStart, zEnd):
  224.             if random.randint(1, flowerPlaceProbability) == 1:
  225.                 setBlock(x, y, z, 38, random.randint(0, 8), level)
  226.             else:
  227.                 setBlock(x, y, z, 0, 0, level)
  228.                
  229. # Building Functions
  230. # Builds a skyrscraper in given area
  231. def genSkyscraper(xStart, xEnd, groundHeight, zStart, zEnd, level, derelict = False):
  232.     global yTrueLen
  233.    
  234.     global hedgeProbability
  235.    
  236.     global buildingFloorBlock
  237.     global buildingWallBlock
  238.     global glassBlock
  239.     global grassBlock
  240.     global dirtBlock
  241.     global hedgeBlock
  242.     global torchBlock
  243.    
  244.     global maxBasements
  245.    
  246.     space = random.randint(2, 5)
  247.    
  248.     possibleHeight = yTrueLen - groundHeight
  249.     maxFloors = int (floor((possibleHeight - 2) / 4))
  250.     floors = random.randint(1, maxFloors)
  251.     aboveGroundHeight = (floors * 4) + 1
  252.     basements = random.randint(0, maxBasements)
  253.     basementHeight = basements * 4
  254.     ymodifier = groundHeight - basementHeight
  255.     trueHeight = aboveGroundHeight + basementHeight + 1
  256.     xLength = xEnd - xStart
  257.     zLength = zEnd - zStart
  258.    
  259.     ladderPos = (random.randint(1, 4))
  260.     ladderRot = (random.randint(1, 2))
  261.  
  262.     if ladderPos == 1:
  263.         ladderTowerXPos = xStart + (xLength / 2) - 1
  264.         ladderTowerZPos = zStart + (zLength / 2) - 1
  265.         if ladderRot == 1:
  266.             ladderXPos = ladderTowerXPos + 1
  267.             ladderZPos = ladderTowerZPos
  268.             ladderData = 5
  269.         elif ladderRot == 2:
  270.             ladderXPos = ladderTowerXPos
  271.             ladderZPos = ladderTowerZPos + 1
  272.             ladderData = 3
  273.     elif ladderPos == 2:
  274.         ladderTowerXPos = xStart + (xLength / 2)
  275.         ladderTowerZPos = zStart + (zLength / 2) - 1
  276.         if ladderRot == 1:
  277.             ladderXPos = ladderTowerXPos - 1
  278.             ladderZPos = ladderTowerZPos
  279.             ladderData = 4
  280.         elif ladderRot == 2:
  281.             ladderXPos = ladderTowerXPos
  282.             ladderZPos = ladderTowerZPos + 1
  283.             ladderData = 3
  284.     elif ladderPos == 3:
  285.         ladderTowerXPos = xStart + (xLength / 2) - 1
  286.         ladderTowerZPos = zStart + (zLength / 2)
  287.         if ladderRot == 1:
  288.             ladderXPos = ladderTowerXPos + 1
  289.             ladderZPos = ladderTowerZPos
  290.             ladderData = 5
  291.         elif ladderRot == 2:
  292.             ladderXPos = ladderTowerXPos
  293.             ladderZPos = ladderTowerZPos - 1
  294.             ladderData = 2
  295.     elif ladderPos == 4:
  296.         ladderTowerXPos = xStart + (xLength / 2)
  297.         ladderTowerZPos = zStart + (zLength / 2)
  298.         if ladderRot == 1:
  299.             ladderXPos = ladderTowerXPos - 1
  300.             ladderZPos = ladderTowerZPos
  301.             ladderData = 4
  302.         elif ladderRot == 2:
  303.             ladderXPos = ladderTowerXPos
  304.             ladderZPos = ladderTowerZPos - 1
  305.             ladderData = 2
  306.    
  307.     if derelict == False:
  308.         genRectangle(xStart + 1, xEnd - 1, groundHeight, zStart + 1, zEnd - 1, grassBlock.ID, grassBlock.blockData, level)
  309.         global flowerProbability
  310.         if random.randint(1, flowerProbability) == 1:
  311.             genFlowerRectangle(xStart + 1, xEnd - 1, groundHeight + 1, zStart + 1, zEnd - 1, level)
  312.     else:
  313.         genRectangle(xStart + 1, xEnd - 1, groundHeight, zStart + 1, zEnd - 1, dirtBlock.ID, dirtBlock.blockData, level)
  314.    
  315.     for y in range(0, trueHeight):
  316.         if y + 1 == trueHeight:
  317.             genFilledRectangle(xStart + space, xEnd - space, y + ymodifier, zStart + space, zEnd - space, buildingWallBlock.ID, buildingWallBlock.blockData, 0, 0, level, derelict)
  318.             genRectangle(xStart + space, xEnd - space, y + ymodifier + 1, zStart + space, zEnd - space, 0, 0, level, derelict)
  319.             genCorners(xStart + space + 1, xEnd - space - 1, y + ymodifier, zStart + space + 1, zEnd - space - 1, torchBlock.ID, torchBlock.blockData, level, derelict)
  320.         elif y + 2 == trueHeight:
  321.             genFilledRectangle(xStart + space, xEnd - space, y + ymodifier, zStart + space, zEnd - space, buildingWallBlock.ID, buildingWallBlock.blockData, buildingFloorBlock.ID, buildingFloorBlock.blockData, level, derelict)
  322.             setBlock(ladderXPos, y + ymodifier, ladderZPos, 65, ladderData, level, derelict)
  323.         elif y == 0:
  324.             genFilledRectangle(xStart + space, xEnd - space, y + ymodifier, zStart + space, zEnd - space, buildingWallBlock.ID, buildingWallBlock.blockData, buildingFloorBlock.ID, buildingFloorBlock.blockData, level, derelict)
  325.         elif y % 4 == 0:
  326.             genFilledRectangle(xStart + space, xEnd - space, y + ymodifier, zStart + space, zEnd - space, buildingWallBlock.ID, buildingWallBlock.blockData, buildingFloorBlock.ID, buildingFloorBlock.blockData, level, derelict)
  327.             setBlock(ladderTowerXPos, y + ymodifier, ladderTowerZPos, buildingWallBlock.ID, buildingWallBlock.blockData, level, derelict)
  328.             setBlock(ladderXPos, y + ymodifier, ladderZPos, 65, ladderData, level, derelict)
  329.         elif (y - 1) % 4 == 0 and y < basementHeight:
  330.             genFilledRectangle(xStart + space, xEnd - space, y + ymodifier, zStart + space, zEnd - space, buildingWallBlock.ID, buildingWallBlock.blockData, 0, 0, level, derelict)
  331.             setBlock(ladderTowerXPos, y + ymodifier, ladderTowerZPos, buildingWallBlock.ID, buildingWallBlock.blockData, level, derelict)
  332.             setBlock(ladderXPos, y + ymodifier, ladderZPos, 65, ladderData, level, derelict)
  333.             genCorners(xStart + space + 1, xEnd - space - 1, y + ymodifier, zStart + space + 1, zEnd - space - 1, torchBlock.ID, torchBlock.blockData, level, derelict)
  334.         elif y < basementHeight:
  335.             genFilledRectangle(xStart + space, xEnd - space, y + ymodifier, zStart + space, zEnd - space, buildingWallBlock.ID, buildingWallBlock.blockData, 0, 0, level, derelict)
  336.             setBlock(ladderTowerXPos, y + ymodifier, ladderTowerZPos, buildingWallBlock.ID, buildingWallBlock.blockData, level, derelict)
  337.             setBlock(ladderXPos, y + ymodifier, ladderZPos, 65, ladderData, level, derelict)
  338.         elif (y - 1) % 4 == 0:
  339.             genFilledCornerRectangle(xStart + space, xEnd - space, y + ymodifier, zStart + space, zEnd - space, buildingWallBlock.ID, buildingWallBlock.blockData, glassBlock.ID, glassBlock.blockData, 0, 0, level, derelict)
  340.             setBlock(ladderTowerXPos, y + ymodifier, ladderTowerZPos, buildingWallBlock.ID, buildingWallBlock.blockData, level, derelict)
  341.             setBlock(ladderXPos, y + ymodifier, ladderZPos, 65, ladderData, level, derelict)
  342.             genCorners(xStart + space + 1, xEnd - space - 1, y + ymodifier, zStart + space + 1, zEnd - space - 1, torchBlock.ID, torchBlock.blockData, level, derelict)
  343.         else:
  344.             genFilledCornerRectangle(xStart + space, xEnd - space, y + ymodifier, zStart + space, zEnd - space, buildingWallBlock.ID, buildingWallBlock.blockData, glassBlock.ID, glassBlock.blockData, 0, 0, level, derelict)
  345.             setBlock(ladderTowerXPos, y + ymodifier, ladderTowerZPos, buildingWallBlock.ID, buildingWallBlock.blockData, level, derelict)
  346.             setBlock(ladderXPos, y + ymodifier, ladderZPos, 65, ladderData, level, derelict)
  347.    
  348.     if space == 4:
  349.         hedge = random.randint(1, hedgeProbability)
  350.         if hedge == 1:
  351.             genHollowRectangle(xStart + 2, xEnd - 2, groundHeight + 1, zStart + 2, zEnd - 2, hedgeBlock.ID, hedgeBlock.blockData, level, derelict)
  352.    
  353.     doors = (random.randint(1, 15))
  354.     if doors  == 1 or doors == 5 or doors == 7 or doors == 9 or doors == 11 or doors == 12 or doors == 13 or doors == 15:
  355.         genRectangle(xStart + (xLength / 2) - 1, xStart + (xLength / 2) + 1, groundHeight, zStart + 1, zStart + space, sideWalkBlock.ID, sideWalkBlock.blockData, level, derelict)
  356.         genRectangle(xStart + (xLength / 2) - 1, xStart + (xLength / 2) + 1, groundHeight + 1, zStart + 1, zStart + space + 1, 0, 0, level)
  357.         genRectangle(xStart + (xLength / 2) - 1, xStart + (xLength / 2) + 1, groundHeight + 2, zStart + 1, zStart + space + 1, 0, 0, level)
  358.     if doors == 2 or doors == 5 or doors == 8 or doors == 10 or doors == 11 or doors == 12 or doors == 14 or doors == 15:
  359.         genRectangle(xStart + (xLength / 2) - 1, xStart + (xLength / 2) + 1, groundHeight, zEnd - space, zEnd - 1, sideWalkBlock.ID, sideWalkBlock.blockData, level, derelict)
  360.         genRectangle(xStart + (xLength / 2) - 1, xStart + (xLength / 2) + 1, groundHeight + 1, zEnd - space - 1, zEnd - 1, 0, 0, level)
  361.         genRectangle(xStart + (xLength / 2) - 1, xStart + (xLength / 2) + 1, groundHeight + 2, zEnd - space - 1, zEnd - 1, 0, 0, level)
  362.     if doors == 3 or doors == 6 or doors == 7 or doors == 10 or doors == 11 or doors == 13 or doors == 14 or doors == 15:
  363.         genRectangle(xStart + 1, xStart + space, groundHeight, zStart + (zLength / 2) - 1, zStart + (zLength / 2) + 1, sideWalkBlock.ID, sideWalkBlock.blockData, level, derelict)
  364.         genRectangle(xStart + 1, xStart + space + 1, groundHeight + 1, zStart + (zLength / 2) - 1, zStart + (zLength / 2) + 1, 0, 0, level)
  365.         genRectangle(xStart + 1, xStart + space + 1, groundHeight + 2, zStart + (zLength / 2) - 1, zStart + (zLength / 2) + 1, 0, 0, level)
  366.     if doors == 4 or doors == 6 or doors == 8 or doors == 9 or doors == 12 or doors == 13 or doors == 14 or doors == 15:
  367.         genRectangle(xEnd - space, xEnd - 1, groundHeight, zStart + (zLength / 2) - 1, zStart + (zLength / 2) + 1, sideWalkBlock.ID, sideWalkBlock.blockData, level, derelict)
  368.         genRectangle(xEnd - space - 1, xEnd - 1, groundHeight + 1, zStart + (zLength / 2) - 1, zStart + (zLength / 2) + 1, 0, 0, level)
  369.         genRectangle(xEnd - space - 1, xEnd - 1, groundHeight + 2, zStart + (zLength / 2) - 1, zStart + (zLength / 2) + 1, 0, 0, level)
  370.  
  371. # Creates an empty (or at least sorta empty) lot
  372. def genEmptyLot(xStart, xEnd, groundHeight, zStart, zEnd, level, derelict = False):
  373.     if derelict == False:
  374.         genRectangle(xStart + 1, xEnd - 1, groundHeight, zStart + 1, zEnd - 1, grassBlock.ID, grassBlock.blockData, level)
  375.         global flowerProbability
  376.         if random.randint(1, flowerProbability) == 1:
  377.             genFlowerRectangle(xStart + 1, xEnd - 1, groundHeight + 1, zStart + 1, zEnd - 1, level)
  378.     else:
  379.         genRectangle(xStart + 1, xEnd - 1, groundHeight, zStart + 1, zEnd - 1, dirtBlock.ID, dirtBlock.blockData, level)
  380.    
  381. # Main Function
  382. def perform(level, box, options):
  383.     #Define size in global variables
  384.     global xMod
  385.     xMod = box.minx
  386.     global xLen
  387.     xLen = box.maxx - xMod
  388.     global yMod
  389.     yMod = box.miny
  390.     global yLen
  391.     yLen = box.maxy - yMod
  392.     global zMod
  393.     zMod = box.minz
  394.     global zLen
  395.     zLen = box.maxz - zMod
  396.    
  397.     global maxBasements
  398.     maxBasements = options["Basements"]
  399.     global minHeight
  400.     minHeight = ((options["Minimum Height"] + options["Basements"]) * 4) + 4
  401.     global groundHeight
  402.     groundHeight = options["Basements"] * 4 + 1
  403.    
  404.     # Define options
  405.     global createDerelicts
  406.     createDerelicts = options["Create Derelict Structures"]
  407.     global createEmptyLots
  408.     createEmptyLots = options["Create Empty Lots"]
  409.     global enableHeightMap
  410.     enableHeightMap = options["Enable Height Randomization"]
  411.    
  412.     # Define probabilities
  413.     global derelictProbability
  414.     derelictProbability = options["Derelict Probability"]
  415.     if derelictProbability < 1:
  416.         derelictProbability = 10
  417.     global derelictRProbability
  418.     derelictRProbability = options["Derelict Remove Block Probability"]
  419.     if derelictRProbability < 1:
  420.         derelictRProbability = 10
  421.     global lotProbability
  422.     lotProbability = options["Lot Probability"]
  423.     if lotProbability < 1:
  424.         lotProbability = 10
  425.     global hedgeProbability
  426.     hedgeProbability = options["Hedge Probability"]
  427.     if hedgeProbability < 1:
  428.         hedgeProbability = 3
  429.     global flowerProbability
  430.     flowerProbability = options["Flower Probability"]
  431.     if flowerProbability < 1:
  432.         flowerProbability = 2
  433.     global flowerPlaceProbability
  434.     flowerPlaceProbability = options["Flower Placement Probability"]
  435.     if flowerPlaceProbability < 1:
  436.         flowerPlaceProbability = 5
  437.    
  438.     # Define blocks
  439.     global groundBlock
  440.     groundBlock = options["Ground Block"]
  441.     global grassBlock
  442.     grassBlock = options["Grass Block"]
  443.     global sideWalkBlock
  444.     sideWalkBlock = options["Sidewalk Block"]
  445.     global buildingWallBlock
  446.     buildingWallBlock = options["Building Wall Block"]
  447.     global buildingFloorBlock
  448.     buildingFloorBlock = options["Building Floor Block"]
  449.     global lightingBlock
  450.     lightingBlock = options["Lighting Block"]
  451.     global torchBlock
  452.     torchBlock = options["Torch Block (Up)"]
  453.     global hedgeBlock
  454.     hedgeBlock = options["Hedge Block"]
  455.     global glassBlock
  456.     glassBlock = options["Glass Block"]
  457.     global dirtBlock
  458.     dirtBlock = options["Dirt Block"]
  459.    
  460.     global xTrueLen
  461.     global yTrueLen
  462.     global zTrueLen
  463.     # Enforce Chunk Conformity
  464.     xTrueLen = int (floor((xLen - 2) / 16) * 16) + 2
  465.     # The following if statement forces enough space into the box for one chunk
  466.     if xTrueLen < 18: # Round 0 to 1
  467.         xTrueLen = 18
  468.     yTrueLen = int (floor((yLen - 4) / 4) * 4) + 4
  469.     # The following if statement forces enough space into the box for one chunk
  470.     if yTrueLen < minHeight: # Round all values below minimum height to minimum height
  471.         yTrueLen = minHeight
  472.     zTrueLen = int (floor((zLen - 2) / 16) * 16) + 2
  473.     # The following if statement forces enough space into the box for one chunk
  474.     if zTrueLen < 18: # Round 0 to 1
  475.         zTrueLen = 18
  476.    
  477.     # Creates the ground as a cube of dirt
  478.     genCube(0, xTrueLen, 0, groundHeight, 0, zTrueLen, groundBlock.ID, groundBlock.blockData, level)
  479.     # Creates the outer sidewalk and inner grass
  480.     genHollowRectangle(0, xTrueLen, groundHeight, 0, zTrueLen, sideWalkBlock.ID, sideWalkBlock.blockData, level)
  481.     genHollowRectangle(0, xTrueLen, groundHeight + 1, 0, zTrueLen, 0, 0, level)
  482.     genHollowRectangle(0, xTrueLen, groundHeight + 2, 0, zTrueLen, 0, 0, level)
  483.     genCorners(0, xTrueLen, groundHeight + 1, 0, zTrueLen, torchBlock.ID, torchBlock.blockData, level)
  484.     genCorners(1, xTrueLen - 1, groundHeight + 1, 0, zTrueLen, torchBlock.ID, torchBlock.blockData, level)
  485.     genCorners(0, xTrueLen, groundHeight + 1, 1, zTrueLen - 1, torchBlock.ID, torchBlock.blockData, level)
  486.    
  487.     for x in range(1, xTrueLen - 1):
  488.         for z in range(1, zTrueLen - 1):
  489.             if (x - 1) % 16 == 0 and (z - 1) % 16 == 0:
  490.                 # Creates sidewalk around the chunk
  491.                 genHollowRectangle(x, x + 16, groundHeight, z, z + 16, sideWalkBlock.ID, sideWalkBlock.blockData, level)
  492.                 genHollowRectangle(x, x + 16, groundHeight + 1, z, z + 16, 0, 0, level)
  493.                 genHollowRectangle(x, x + 16, groundHeight + 2, z, z + 16, 0, 0, level)
  494.                 genCorners(x, x + 16, groundHeight + 1, z, z + 16, torchBlock.ID, torchBlock.blockData, level)
  495.                 type = random.randint(1, lotProbability)
  496.                 if type != 1:
  497.                     # Creates a skyscraper
  498.                     if createDerelicts == True and random.randint(1, derelictProbability) == 1:
  499.                         genSkyscraper(x, x + 16, groundHeight, z, z + 16, level, True)
  500.                     else:
  501.                         genSkyscraper(x, x + 16, groundHeight, z, z + 16, level)
  502.                 else:
  503.                     # Creates an empty lot
  504.                     if createDerelicts == True and random.randint(1, derelictProbability) == 1:
  505.                         genEmptyLot(x, x + 16, groundHeight, z, z + 16, level, True)
  506.                     else:
  507.                         genEmptyLot(x, x + 16, groundHeight, z, z + 16, level)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement