From ec47ad16817351b756266b0ccb880693c380c3f8 Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Tue, 9 Mar 2010 13:54:00 +0000 Subject: [PATCH] begin changing map generators to handle subgenerators git-svn-id: http://svn.net-core.org/repos/t-engine4@388 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engine/Map.lua | 27 +++++++ game/engine/generator/map/Roomer.lua | 10 +-- game/engine/generator/map/Static.lua | 28 +++++++- game/modules/tome/class/Game.lua | 5 ++ .../data/maps/zones/tower-amon-sul-last.lua | 71 +++++++++++++++++++ game/modules/tome/data/rooms/maze.lua | 34 +++++++++ .../tome/data/zones/tower-amon-sul/zone.lua | 14 ++-- game/modules/tome/dialogs/IntroDialog.lua | 2 +- 8 files changed, 179 insertions(+), 12 deletions(-) create mode 100644 game/modules/tome/data/maps/zones/tower-amon-sul-last.lua create mode 100644 game/modules/tome/data/rooms/maze.lua diff --git a/game/engine/Map.lua b/game/engine/Map.lua index 814698b0ea..f470e1bc65 100644 --- a/game/engine/Map.lua +++ b/game/engine/Map.lua @@ -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 diff --git a/game/engine/generator/map/Roomer.lua b/game/engine/generator/map/Roomer.lua index 9354e638ac..ff7a0a4c3f 100644 --- a/game/engine/generator/map/Roomer.lua +++ b/game/engine/generator/map/Roomer.lua @@ -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 diff --git a/game/engine/generator/map/Static.lua b/game/engine/generator/map/Static.lua index 9b8b850ef9..8ff364268a 100644 --- a/game/engine/generator/map/Static.lua +++ b/game/engine/generator/map/Static.lua @@ -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 diff --git a/game/modules/tome/class/Game.lua b/game/modules/tome/class/Game.lua index 7fcdaa54fe..dfea6faef0 100644 --- a/game/modules/tome/class/Game.lua +++ b/game/modules/tome/class/Game.lua @@ -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 diff --git a/game/modules/tome/data/maps/zones/tower-amon-sul-last.lua b/game/modules/tome/data/maps/zones/tower-amon-sul-last.lua new file mode 100644 index 0000000000..1bf08c7ce7 --- /dev/null +++ b/game/modules/tome/data/maps/zones/tower-amon-sul-last.lua @@ -0,0 +1,71 @@ +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.......................#]], +[[##################################################]] +} diff --git a/game/modules/tome/data/rooms/maze.lua b/game/modules/tome/data/rooms/maze.lua new file mode 100644 index 0000000000..930a1c2631 --- /dev/null +++ b/game/modules/tome/data/rooms/maze.lua @@ -0,0 +1,34 @@ +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 diff --git a/game/modules/tome/data/zones/tower-amon-sul/zone.lua b/game/modules/tome/data/zones/tower-amon-sul/zone.lua index 7388eb7871..24d8340c59 100644 --- a/game/modules/tome/data/zones/tower-amon-sul/zone.lua +++ b/game/modules/tome/data/zones/tower-amon-sul/zone.lua @@ -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", + }, }, + }, }, } diff --git a/game/modules/tome/dialogs/IntroDialog.lua b/game/modules/tome/dialogs/IntroDialog.lua index a434178662..3257e1fae9 100644 --- a/game/modules/tome/dialogs/IntroDialog.lua +++ b/game/modules/tome/dialogs/IntroDialog.lua @@ -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", -- GitLab