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

begin changing map generators to handle subgenerators

git-svn-id: http://svn.net-core.org/repos/t-engine4@388 51575b47-30f0-44d4-a5cc-537603b46e54
parent a60093b5
No related branches found
No related tags found
No related merge requests found
......@@ -470,6 +470,33 @@ function _M:isBound(x, y)
return true
end
--- Import a map into the current one
-- @param map the map to import
-- @param dx coordinate where to import it in the current map
-- @param dy coordinate where to import it in the current map
-- @param sx coordinate where to start importing the map, defaults to 0
-- @param sy coordinate where to start importing the map, defaults to 0
-- @param sw size of the imported map to get, defaults to map size
-- @param sh size of the imported map to get, defaults to map size
function _M:import(map, dx, dy, sx, sy, sw, sh)
sx = sx or 0
sy = sy or 0
sw = sw or map.w
sh = sh or map.h
for i = sx, sx + sw - 1 do for j = sy, sy + sh - 1 do
local x, y = dx + i, dy + j
self.map[x + y * self.w] = map.map[i + j * map.w]
self.remembers(x, y, map.remembers(i, j))
self.seens(x, y, map.seens(i, j))
self.lites(x, y, map.lites(i, j))
self:updateMap(x, y)
end end
self.changed = true
end
--- Adds a zone (temporary) effect
-- @param src the source actor
-- @param x the epicenter coords
......
......@@ -69,10 +69,10 @@ function _M:resolve(c)
end
--- Make up a room
function _M:roomAlloc(room, id)
function _M:roomAlloc(room, id, lev, old_lev)
if type(room) == 'function' then
print("room generator", room, "is making a room")
room = room(self, id)
room = room(self, id, lev, old_lev)
end
print("alloc", room.name)
......@@ -183,7 +183,9 @@ function _M:tunnel(x1, y1, x2, y2, id)
end
print(feat, "try pos", nx, ny, "dir", coord_to_dir[xdir][ydir])
if self.room_map[nx][ny].room then
if self.room_map[nx][ny].special then
print(feat, "refuse special")
elseif self.room_map[nx][ny].room then
tun[#tun+1] = {nx,ny}
x1, y1 = nx, ny
print(feat, "accept room")
......@@ -313,7 +315,7 @@ function _M:generate(lev, old_lev)
local nb_room = self.data.nb_rooms or 10
local rooms = {}
while nb_room > 0 do
local r = self:roomAlloc(self.rooms[rng.range(1, #self.rooms)], #rooms+1)
local r = self:roomAlloc(self.rooms[rng.range(1, #self.rooms)], #rooms+1, lev, old_lev)
if r then rooms[#rooms+1] = r end
nb_room = nb_room - 1
end
......
......@@ -7,6 +7,8 @@ module(..., package.seeall, class.inherit(engine.Generator))
function _M:init(zone, map, grid_list, data)
engine.Generator.init(self, zone, map)
self.grid_list = grid_list
self.subgen = {}
self.data = data
self:loadMap(data.map)
end
......@@ -19,8 +21,11 @@ function _M:loadMap(file)
if not f and err then error(err) end
local g = {
Map = require("engine.Map"),
defineTile = function(char, grid, obj, actor)
t[char] = {grid=grid, obj=obj, actor=actor}
subGenerator = function(g)
self.subgen[#self.subgen+1] = g
end,
defineTile = function(char, grid, obj, actor, trap)
t[char] = {grid=grid, obj=obj, actor=actor, trap=trap}
end,
quickEntity = function(char, e)
local e = Grid.new(e)
......@@ -69,10 +74,27 @@ function _M:resolve(typ, c)
end
end
function _M:generate()
function _M:generate(lev, old_lev)
for i = 1, self.gen_map.w do for j = 1, self.gen_map.h do
self.map(i-1, j-1, Map.TERRAIN, self:resolve("grid", self.gen_map[i][j]))
end end
for i = 1, #self.subgen do
local g = self.subgen[i]
local data = g.data
if type(data) == "string" and data == "pass" then data = self.data end
local map = self.zone.map_class.new(g.w, g.h)
local generator = require(g.generator).new(
self.zone,
map,
self.grid_list,
data
)
generator:generate(lev, old_lev)
self.map:import(map, g.x, g.y)
end
return self.gen_map.startx, self.gen_map.starty, self.gen_map.startx, self.gen_map.starty
end
......@@ -365,6 +365,11 @@ function _M:setupCommands()
-- Activate profiler keybinds
self.key:setupProfiler()
self.key:addCommands{
[{"_d","ctrl"}] = function()
self:changeLevel(5, "tower-amon-sul")
end,
}
self.key:addBinds
{
-- Movements
......
defineTile('.', "FLOOR")
defineTile('#', "WALL")
defineTile('+', "DOOR")
defineTile('s', "FLOOR", nil, "SHADE_OF_ANGMAR")
subGenerator{
x = 0, y = 0, w = 50, h = 43,
generator = "engine.generator.map.Roomer",
data = {
nb_rooms = 10,
edge_entrances = {8,2},
rooms = {"simple", "pilar"},
['.'] = "FLOOR",
['#'] = "WALL",
up = "UP",
door = "DOOR",
},
}
return {
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[..................................................]],
[[#########################+########################]],
[[#................................................#]],
[[#................................................#]],
[[#................................................#]],
[[#................................................#]],
[[#........................s.......................#]],
[[##################################################]]
}
return function(gen, id, lev, old_lev)
local w = rng.range(15, 15)
local h = rng.range(15, 15)
return { name="maze"..w.."x"..h, w=w, h=h, generator = function(self, x, y, is_lit)
local map = engine.Map.new(w, h)
local Maze = require("engine.generator.map.Maze")
local maze = Maze.new(gen.zone, map, gen.grid_list, gen.data)
maze:generate(lev, old_lev)
gen.map:import(map, x, y)
-- Make it a room, and make it special so that we do not tunnel through
for i = x, x + w - 1 do for j = y, y + h - 1 do
gen.room_map[i][j].special = true
gen.room_map[i][j].room = id
end end
-- Mark the outer walls are piercable
for i = x, x + w - 1 do
gen.room_map[i][y].special = false
gen.room_map[i][y].room = nil
gen.room_map[i][y].can_open = true
gen.room_map[i][y+h-1].special = false
gen.room_map[i][y+h-1].room = nil
gen.room_map[i][y+h-1].can_open = true
end
for j = y, y + h - 1 do
gen.room_map[x][j].special = false
gen.room_map[x][j].room = nil
gen.room_map[x][j].can_open = true
gen.room_map[x+w-1][j].special = false
gen.room_map[x+w-1][j].room = nil
gen.room_map[x+w-1][j].can_open = true
end
end}
end
......@@ -4,9 +4,9 @@ return {
level_scheme = "player",
max_level = 5,
width = 50, height = 50,
-- all_remembered = true,
-- all_lited = true,
persistant = true,
all_remembered = true,
all_lited = true,
-- persistant = true,
generator = {
map = {
class = "engine.generator.map.Roomer",
......@@ -23,7 +23,7 @@ return {
class = "engine.generator.actor.Random",
nb_npc = {20, 30},
adjust_level = {-1, 2},
guardian = "SHADE_OF_ANGMAR",
-- guardian = "SHADE_OF_ANGMAR", -- The gardian is set in the static map
},
object = {
class = "engine.generator.object.Random",
......@@ -42,5 +42,11 @@ return {
up = "UP_WILDERNESS",
}, },
},
[5] = {
generator = { map = {
class = "engine.generator.map.Static",
map = "zones/tower-amon-sul-last",
}, },
},
},
}
......@@ -5,7 +5,7 @@ module(..., package.seeall, class.inherit(engine.Dialog))
function _M:init(actor)
self.actor = actor
engine.Dialog.init(self, "Welcome to ToME "..actor.name, 500, 300)
engine.Dialog.init(self, "Welcome to ToME", 500, 300)
self:keyCommands(nil, {
ACCEPT = "EXIT",
......
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