Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1. local b = require 'map_gen.shared.builders'
  2.  
  3. --Create maltese shape
  4. local starting_area = 60
  5. local gradient = 0.05
  6. local tiles_half = (starting_area) * 0.5
  7. local function maltese_cross(x,y)
  8.  
  9.     local abs_x = math.abs(x)
  10.     local abs_y = math.abs(y)
  11.    
  12.     return not (abs_x > (tiles_half+(abs_y*gradient)) and abs_y > (tiles_half+(abs_x*gradient)))
  13. end
  14.  
  15. -- create water crossings and pattern
  16. local water_line =
  17.         b.any {
  18.         b.rectangle(10, 2)
  19.     }  
  20. water_line = b.change_tile(water_line, true, 'water')
  21.  
  22. local waters = b.single_y_pattern(water_line, 3)
  23. local bounds = b.rectangle(10, starting_area+1)
  24. waters = b.choose(bounds, waters, b.empty_shape)
  25. waters = b.translate(waters,34,-1)
  26.  
  27. water_pattern =
  28.     b.any{
  29.     waters,
  30.     b.rotate(waters,degrees(90)),
  31.     b.rotate(waters,degrees(180)),
  32.     b.rotate(waters,degrees(270))
  33.     }
  34.  
  35. -- create the starting area as a concrete square
  36. local starting_square =  b.rectangle(60, 60)
  37. starting_square = b.change_tile(starting_square, true, 'grass-1')
  38.  
  39. -- work on the  ore generation based on the code in hub_spiral.lua
  40.  
  41. -- worm islands
  42. worm_island = b.rectangle(20,300)
  43. worm_island_end = b.circle(10)
  44. worm_island = b.any{
  45.     worm_island_end,
  46.     b.translate(worm_island,0,-150),
  47.     b.translate(worm_island_end,0,-300)
  48. }
  49. worm_island = b.change_tile(worm_island, true, 'grass-1')
  50.  
  51.  
  52. local worm_names = {
  53.     'small-worm-turret',
  54.     'medium-worm-turret',
  55.     'big-worm-turret'
  56. }
  57.  
  58. local max_worm_chance = 1 / 128
  59. local worm_chance_factor = 1 / (192 * 512)
  60.  
  61.  
  62. local function worms(_, _, world)
  63.     local wx, wy = world.x, world.y
  64.     local d = math.sqrt(wx * wx + wy * wy)
  65.  
  66.     local worm_chance = d - 128
  67.  
  68.     if worm_chance > 0 then
  69.         worm_chance = worm_chance * worm_chance_factor
  70.         worm_chance = math.min(worm_chance, max_worm_chance)
  71.  
  72.         if math.random() < worm_chance then
  73.             if d < 256 then
  74.                 return {name = 'small-worm-turret'}
  75.             else
  76.                 local max_lvl
  77.                 local min_lvl
  78.                 if d < 512 then
  79.                     max_lvl = 2
  80.                     min_lvl = 1
  81.                 else
  82.                     max_lvl = 3
  83.                     min_lvl = 2
  84.                 end
  85.                 local lvl = math.random() ^ (512 / d) * max_lvl
  86.                 lvl = math.ceil(lvl)
  87.                 lvl = math.clamp(lvl, min_lvl, 3)
  88.                 return {name = worm_names[lvl]}
  89.             end
  90.         end
  91.     end
  92. end
  93.  
  94. worm_island = b.apply_entities(worm_island, worms)
  95.  
  96. worm_islands = b.any{
  97.     b.rotate(b.translate(worm_island,0,-100),degrees(45)),
  98.     b.rotate(b.translate(worm_island,0,-100),degrees(45+90)),
  99.     b.rotate(b.translate(worm_island,0,-100),degrees(45+180)),
  100.     b.rotate(b.translate(worm_island,0,-100),degrees(45+270))
  101. }
  102.  
  103.  
  104. -- create the start area using the ore, water and concrete squares
  105. local start_area =
  106.     b.any {
  107.     water_pattern,
  108.     starting_square
  109. }
  110.    
  111. maltese_cross = b.change_tile(maltese_cross, true, 'grass-1')
  112.  
  113. local sea = b.change_tile(b.full_shape, true, 'water')
  114. sea = b.fish(sea, 0.00125)
  115.  
  116.  
  117. local map = b.any{worm_islands, start_area, maltese_cross,sea}
  118. return map
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement