Skip to content
Snippets Groups Projects
Commit f86e9162 authored by dg's avatar dg
Browse files

TileSet generator now handels doors smartly

git-svn-id: http://svn.net-core.org/repos/t-engine4@557 51575b47-30f0-44d4-a5cc-537603b46e54
parent d8d65d27
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,8 @@ function _M:init(zone, map, level, data)
engine.Generator.init(self, zone, map, level)
self.data = data
self.grid_list = zone.grid_list
self.tiles, self.raw = self:loadTiles(data.tileset)
self.tiles, self.raw = {}, {}
self:loadTiles(data.tileset)
self.matching_tiles = {}
self.block = self.raw.base
......@@ -44,15 +45,17 @@ end
function _M:loadTiles(tileset)
local f, err = loadfile("/data/tilesets/"..tileset..".lua")
if not f and err then error(err) end
local d = {}
setfenv(f, d)
local d = self.raw
setfenv(f, setmetatable(d, {__index=_G}))
local ret, err = f()
if not ret and err then error(err) end
local tiles = {}
local tiles = self.tiles
for idx, ts in ipairs(d.tiles) do
local t = { id=idx, openings={} }
tiles[idx] = t
local t = { id=#tiles+1, openings={}, type=ts.type }
if not ts.no_random then tiles[#tiles+1] = t end
if ts.define_as then tiles[ts.define_as] = t end
for j, line in ipairs(ts) do
local i = 1
for c in line:gmatch(".") do
......@@ -81,12 +84,13 @@ function _M:loadTiles(tileset)
end
end
t.sizew = mx / d.base.w
t.sizeh = my / d.base.h
i = i + 1
end
end
end
return tiles, d
end
function _M:roomAlloc(bx, by, bw, bh, rid)
......@@ -142,13 +146,13 @@ function _M:findMatchingTiles(st, dir)
end
elseif dir == 4 then
for j = 1, self.block.h do
local ret, fo = self:matchTile(st[1][j], dt[#dt][j])
local ret, fo = self:matchTile(st[1][j], dt[self.block.w][j])
fullok = fullok or fo
if not ret then ok = false end
end
elseif dir == 6 then
for j = 1, self.block.h do
local ret, fo = self:matchTile(st[#dt][j], dt[1][j])
local ret, fo = self:matchTile(st[self.block.w][j], dt[1][j])
fullok = fullok or fo
if not ret then ok = false end
end
......@@ -177,14 +181,16 @@ function _M:resolve(c)
end
function _M:buildTile(tile, bx, by, rid)
local bw, bh = 1, 1
local bw, bh = tile.sizew, tile.sizeh
if not self:roomAlloc(bx, by, bw, bh, rid) then return false end
print("building tile", tile.id, #tile, #tile[1])
for i = 1, #tile do
for j = 1, #tile[1] do
self.map(bx * self.block.w + i - 1, by * self.block.h + j - 1, Map.TERRAIN, self.grid_list[self:resolve(tile[i][j])])
if self.map.room_map[bx * self.block.w + i - 1] and self.map.room_map[bx * self.block.w + i - 1][by * self.block.h + j - 1] then
self.map.room_map[bx * self.block.w + i - 1][by * self.block.h + j - 1].symbol = tile[i][j]
end
end
end
local opens = {}
......@@ -201,6 +207,14 @@ function _M:buildTile(tile, bx, by, rid)
return opens
end
function _M:createMap()
for i = 0, self.map.w - 1 do for j = 0, self.map.h - 1 do
local c = self.map.room_map[i][j].symbol
if self.raw.filler then c = self.raw.filler(c, i, j, self.map.room_map, self.data) end
self.map(i, j, Map.TERRAIN, self.grid_list[self:resolve(c)])
end end
end
function _M:generate()
for i = 0, self.map.w - 1 do for j = 0, self.map.h - 1 do
self.map(i, j, Map.TERRAIN, self.grid_list[self:resolve("#")])
......@@ -225,6 +239,9 @@ function _M:generate()
end
end
-- Fill the map with the real entities based on the map.room_map symbols
self:createMap()
-- Always starts at 1, 1
self.map(1, 1, Map.TERRAIN, self.up)
return 1, 1, 1, 1
......
......@@ -33,15 +33,35 @@ matcher = function(t1, t2)
return false
end
-- Remove some silly doors
filler = function(c, x, y, room_map, data)
if c ~= "'" then return c end
local nb = 0
if room_map[x-1] and room_map[x-1][y] and (room_map[x-1][y].symbol == '.' or room_map[x-1][y].symbol == '+' or room_map[x-1][y].symbol == "'") then nb = nb + 1 end
if room_map[x+1] and room_map[x+1][y] and (room_map[x+1][y].symbol == '.' or room_map[x+1][y].symbol == '+' or room_map[x+1][y].symbol == "'") then nb = nb + 1 end
if room_map[x] and room_map[x][y-1] and (room_map[x][y-1].symbol == '.' or room_map[x][y-1].symbol == '+' or room_map[x][y-1].symbol == "'") then nb = nb + 1 end
if room_map[x] and room_map[x][y+1] and (room_map[x][y+1].symbol == '.' or room_map[x][y+1].symbol == '+' or room_map[x][y+1].symbol == "'") then nb = nb + 1 end
if nb == 2 and rng.percent(data.door_chance or 25) then return '+'
elseif nb < 2 then return '#'
else return '.'
end
end
tiles =
{
{type="room",
[[##.##]],
[[#.#.#]],
[[.#.#.]],
[[#.#.#]],
[[##.##]],
[[##'#######]],
[[#........#]],
[['........#]],
[[#........#]],
[[#........#]],
[[#........#]],
[[#........#]],
[[#........']],
[[#........#]],
[[##'#######]],
},
{type="tunnel",
......
......@@ -24,7 +24,7 @@ return {
max_level = 5,
decay = {300, 800},
actor_adjust_level = function(zone, level, e) return zone.base_level + e:getRankLevelAdjust() + level.level-1 + rng.range(-1,2) end,
width = 100, height = 100,
width = 30, height = 30,
all_remembered = true,
all_lited = true,
-- persistant = "zone",
......@@ -44,17 +44,19 @@ return {
},
actor = {
class = "engine.generator.actor.Random",
nb_npc = {20*5, 20*5},
-- nb_npc = {20*5, 20*5},
nb_npc = {0, 0},
-- guardian = "SHADE_OF_ANGMAR", -- The gardian is set in the static map
},
object = {
class = "engine.generator.object.Random",
nb_object = {6*5, 9*5},
filters = { {type="potion" }, {type="potion" }, {type="potion" }, {type="scroll" }, {}, {} }
-- nb_object = {6*5, 9*5},
nb_object = {0, 0},
},
trap = {
class = "engine.generator.trap.Random",
nb_trap = {6*8, 9*8},
-- nb_trap = {6*8, 9*8},
nb_trap = {0, 0},
},
},
levels =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment