Advertisement
Guest User

Untitled

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