Authored by DarkGod
1 parent c016ff56

### plop

Showing with 48 additions and 9 deletions
 ... ... @@ -89,6 +89,9 @@ local point_meta = { 89 89 hashCoord = function(p, tilemap) 90 90 return p.y * tilemap.data_w + p.x 91 91 end, 92 + area = function(p) 93 + return p.y * p.x 94 + end, 92 95 }, 93 96 } 94 97 --- Make a point data, can be added ... ...
 ... ... @@ -18,22 +18,58 @@ 18 18 -- darkgod@te4.org 19 19 20 20 local BSP = require "engine.tilemaps.BSP" 21 +local MST = require "engine.algorithms.MST" 21 22 22 --- rng.seed(2) 23 +-- rng.seed(1) 23 24 24 25 local tm = Tilemap.new(self.mapsize, '=', 1) 25 26 26 -local bsp = BSP.new(10, 10, 8):make(50, 50, '.', '#') 27 +local bsp = BSP.new(4, 4, 10):make(50, 50, '.', '#') 27 28 28 -local rooms = {} 29 -for _, room in ipairs(bsp.rooms) do 30 - rooms[#rooms+1] = room.map 29 +-- Remove a few rooms 30 +for i = 1, #bsp.rooms / 4 do 31 + local room = rng.tableRemove(bsp.rooms) 32 + room.map:carveArea('#', room.map:point(1, 1), room.map.data_size) 31 33 end 32 34 33 -tm:merge(1, 1, bsp) 35 +local mstrun = MST.new() 36 + 37 +-- Generate all possible edges 38 +for i, room1 in ipairs(bsp.rooms) do 39 + local c = room1.map:centerPoint() 40 + for j, room2 in ipairs(bsp.rooms) do if room1 ~= room2 then 41 + local c1, c2 = room1.map:centerPoint(), room2.map:centerPoint() 42 + mstrun:edge(room1, room2, core.fov.distance(c1.x, c1.y, c2.x, c2.y)) 43 + end end 44 +end 45 + 46 +-- Compute! 47 +mstrun:run() 34 48 35 -if not loadMapScript("lib/connect_rooms_multi", {map=tm, rooms=rooms, tunnel_char='.', tunnel_through={'#'}, edges_surplus=0}) then return self:regenerate() end 49 +for _, edge in pairs(mstrun.mst) do 50 + if edge.from.from.x - 1 == edge.to.to.x + 1 then 51 + local min_y, max_y = math.max(edge.from.from.y, edge.to.from.y), math.min(edge.from.to.y, edge.to.to.y) 52 + bsp:put(bsp:point(edge.from.from.x - 1, rng.range(min_y, max_y)), rng.percent(40) and '+' or '.') 53 + elseif edge.from.to.x + 1 == edge.to.from.x - 1 then 54 + local min_y, max_y = math.max(edge.from.from.y, edge.to.from.y), math.min(edge.from.to.y, edge.to.to.y) 55 + bsp:put(bsp:point(edge.from.to.x + 1, rng.range(min_y, max_y)), rng.percent(40) and '+' or '.') 56 + elseif edge.from.from.y - 1 == edge.to.to.y + 1 then 57 + local min_x, max_x = math.max(edge.from.from.x, edge.to.from.x), math.min(edge.from.to.x, edge.to.to.x) 58 + bsp:put(bsp:point(rng.range(min_x, max_x), edge.from.from.y - 1), rng.percent(40) and '+' or '.') 59 + elseif edge.from.to.y + 1 == edge.to.from.y - 1 then 60 + local min_x, max_x = math.max(edge.from.from.x, edge.to.from.x), math.min(edge.from.to.x, edge.to.to.x) 61 + bsp:put(bsp:point(rng.range(min_x, max_x), edge.from.to.y + 1), rng.percent(40) and '+' or '.') 62 + end 63 +end 64 + 65 +bsp:applyOnGroups(bsp:findGroupsOf{'.', '+'}, function(room, idx) 66 + if room.map.data_size:area() < 10 then 67 + room.map:carveArea('#', room.map:point(1, 1), room.map.data_size) 68 + end 69 +end) 70 +-- if bsp:eliminateByFloodfill{'#'} < 10 then return self:regenerate() end 71 + 72 +tm:merge(1, 1, bsp) 36 73 37 --- if tm:eliminateByFloodfill{'T','#'} < 800 then return self:regenerate() end 38 74 39 75 return tm ... ...
 ... ... @@ -25,7 +25,7 @@ return { 25 25 decay = {300, 800}, 26 26 actor_adjust_level = function(zone, level, e) return zone.base_level + e:getRankLevelAdjust() + level.level-1 + rng.range(-1,2) end, 27 27 width = 80, height = 80, 28 - all_remembered = true, 28 + -- all_remembered = true, 29 29 all_lited = true, 30 30 no_level_connectivity = true, 31 31 ... ...