Skip to content
Snippets Groups Projects
Commit e1959608 authored by DarkGod's avatar DarkGod
Browse files

test map

parent 0d4747fe
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -1176,5 +1176,7 @@ function _M:runPostGeneration(level)
end
end
level.map.room_map = nil -- delete the room map
if not config.settings.cheat then
level.map.room_map = nil -- delete the room map, but keep it for debugging
end
end
......@@ -31,6 +31,9 @@ function _M:init(zone, map, level, data)
self.grid_list = zone.grid_list
self.spots = {}
self.mapsize = {self.map.w, self.map.h, w=self.map.w, h=self.map.h}
self.post_gen = {}
self.rooms_positions = {}
self.rooms_registers = {}
RoomsLoader.init(self, data)
end
......@@ -62,35 +65,26 @@ function _M:custom(lev, old_lev)
local file = self:getFile(mapscript..".lua", "mapscripts")
local f, err = loadfile(file)
if not f and err then error(err) end
package.loaded["engine.tilemaps.Tilemap"] = nil
package.loaded["engine.tilemaps.Static"] = nil
package.loaded["engine.tilemaps.WaveFunctionCollapse"] = nil
package.loaded["engine.tilemaps.Noise"] = nil
package.loaded["engine.tilemaps.Heightmap"] = nil
package.loaded["engine.tilemaps.Maze"] = nil
setfenv(f, setmetatable(env or {
local nenv = {
self = self,
zone = self.zone,
level = self.level,
lev = lev,
old_lev = old_lev,
Tilemap = require "engine.tilemaps.Tilemap",
Static = require "engine.tilemaps.Static",
WaveFunctionCollapse = require "engine.tilemaps.WaveFunctionCollapse",
Noise = require "engine.tilemaps.Noise",
Heightmap = require "engine.tilemaps.Heightmap",
Maze = require "engine.tilemaps.Maze",
}, {__index=_G}))
}
for f in fs.iterate("/engine/tilemaps/", function(f) return f:find("%.lua$") end) do
local n = f:sub(1, -5)
local nf = "engine.tilemaps."..n
package.loaded[nf] = nil
nenv[n] = require(nf)
end
setfenv(f, setmetatable(env or nenv, {__index=_G}))
ret = f()
elseif self.data.custom then
ret = self.data.custom(self, lev, old_lev)
end
if ret then
-- If we got a Tilemap instance (very likely) then ask it for the actual characters map
if ret.isClassName and ret:isClassName("engine.tilemaps.Tilemap") then
ret = ret:getResult(true)
end
return ret
elseif self.force_regen then
return nil
......@@ -101,16 +95,39 @@ end
function _M:generate(lev, old_lev)
print("Generating MapScript")
self.lev, self.old_lev = lev, old_lev
self.force_regen = false
local data = self:custom(lev, old_lev)
if self.force_regen then return self:generate(lev, old_lev) end
for id, room in pairs(self.rooms_registers) do
local pos = self.rooms_positions[id]
self:roomPlace(room, id, pos.x - 1, pos.y - 1)
data:applyArea(pos, pos + data:point(room.w - 1, room.h - 1), function(x, y, symb)
if self.map.room_map[x-1][y-1].can_open then
return symb
else
return "⛝" -- Carve out the interrior and all non openings with a special symbol to mark them as needing to NOT be overridden
end
end)
end
data:printResult()
data = data:getResult(true)
for i = 0, self.map.w - 1 do
for j = 0, self.map.h - 1 do
self.map(i, j, Map.TERRAIN, self:resolve(data[j+1][i+1] or '#'))
if data[j+1][i+1] ~= "⛝" then
self.map(i, j, Map.TERRAIN, self:resolve(data[j+1][i+1] or '#'))
end
end
end
return self:makeStairsSides(lev, old_lev, {4,6},self.spots)
for _, post in pairs(self.post_gen) do
post(self, lev, old_lev)
end
return 1, 1, 1, 1
-- return self:makeStairsSides(lev, old_lev, {4,6}, self.spots)
-- return self:makeStairsInside(lev, old_lev, self.spots)
end
......@@ -124,6 +141,10 @@ function _M:addSpot(x, y, type, subtype, data)
self.spots[#self.spots+1] = data
end
function _M:postGen(fct)
self.post_gen[#self.post_gen+1] = fct
end
--- Create the stairs inside the level
function _M:makeStairsInside(lev, old_lev, spots)
-- Put down stairs
......
-- TE4 - T-Engine 4
-- Copyright (C) 2009 - 2018 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
local Tilemap = require "engine.tilemaps.Tilemap"
local RoomsLoader = require "engine.generator.map.RoomsLoader"
--- Generate map-like data from a heightmap fractal
-- @classmod engine.tilemaps.Heightmap
module(..., package.seeall, class.inherit(Tilemap))
function _M:init(mapscript, rooms_list)
self.mapscript = mapscript
if type(rooms_list) == "string" then rooms_list = {rooms_list} end
self.rooms = {}
for _, file in ipairs(rooms_list) do
table.insert(self.rooms, mapscript:loadRoom(file))
end
self.room_next_id = 1
end
function _M:generateRoom(temp_symbol, account_for_border)
local mapscript = self.mapscript
local roomdef = rng.table(self.rooms)
local id = tostring(self)..":"..self.room_next_id
local room = mapscript:roomGen(roomdef, id, mapscript.lev, mapscript.old_lev)
if not room then
print("Tilemap.Rooms failed to generate room")
return nil
end
self.room_next_id = self.room_next_id + 1
if account_for_border == nil then account_for_border = false end
local tm = Tilemap.new({room.w - (account_for_border and 2 or 0), room.h - (account_for_border and 2 or 0)}, temp_symbol or '⍓')
room.temp_symbol = temp_symbol
mapscript.rooms_registers[id] = room
mapscript.rooms_positions[id] = account_for_border and self:point(0, 0) or self:point(1, 1)
tm.mergedAt = function(self, x, y)
mapscript.rooms_positions[id] = mapscript.rooms_positions[id] + self:point(x - 1, y - 1)
end
print('------------------------------exits')
table.print(room.exits)
print('------------------------------')
return tm
end
......@@ -35,6 +35,10 @@ function _M:init(size, fill_with)
end
end
function _M:getSize()
return self.data_w, self.data_h
end
function _M:makeData(w, h, fill_with)
local data = {}
for y = 1, h do
......@@ -497,15 +501,39 @@ end
function _M:carveLinearPath(char, from, dir, stop_at, dig_only_into)
local x, y = math.floor(from.x), math.floor(from.y)
local dx, dy = util.dirToCoord(dir)
if dig_only_into then dig_only_into = table.reverse(dig_only_into) end
if type(dig_only_into) == "table" then dig_only_into = table.reverse(dig_only_into) end
while x >= 1 and x <= self.data_w and y >= 1 and y <= self.data_h and self.data[y][x] ~= stop_at do
if not dig_only_into or dig_only_into[self.data[y][x]] then
if not dig_only_into or (type(dig_only_into) == "table" and dig_only_into[self.data[y][x]]) or (type(dig_only_into) == "function" and dig_only_into(x, y, self.data[y][x])) then
self.data[y][x] = char
end
x, y = x + dx, y + dy
end
end
--- Carve out a simple rectangle
function _M:carveArea(char, from, to, dig_only_into)
if type(dig_only_into) == "table" then dig_only_into = table.reverse(dig_only_into) end
for x = from.x, to.x do for y = from.y, to.y do
if x >= 1 and x <= self.data_w and y >= 1 and y <= self.data_h then
if not dig_only_into or (type(dig_only_into) == "table" and dig_only_into[self.data[y][x]]) or (type(dig_only_into) == "function" and dig_only_into(x, y, self.data[y][x])) then
self.data[y][x] = char
end
end
end end
end
--- Apply a function over an area
function _M:applyArea(from, to, fct)
for x = from.x, to.x do for y = from.y, to.y do
if x >= 1 and x <= self.data_w and y >= 1 and y <= self.data_h then
local ret = fct(x, y, self.data[y][x])
if ret ~= nil then
self.data[y][x] = ret
end
end
end end
end
--- Get the results
-- @param is_array if true returns a table[][] of characters, if false a table[] of string lines
function _M:getResult(is_array)
......@@ -530,7 +558,7 @@ function _M:printResult()
print("]]-----------")
end
--- Merge and other Tilemap's data
--- Merge an other Tilemap's data
function _M:merge(x, y, tm, char_order, empty_char)
if not self.data or not tm.data then return end
-- if x is a table it's a point data so we shift parameters
......@@ -561,4 +589,9 @@ function _M:merge(x, y, tm, char_order, empty_char)
end
end
end
tm:mergedAt(x, y)
end
--- Does nothing, meant to be superloaded
function _M:mergedAt(x, y)
end
......@@ -19,7 +19,7 @@
return function(gen, id)
local w = rng.table{4,6,8,10}
local h = h
local h = w
local function make_pod(self, x, y, is_lit)
gen:makePod(x + w / 2, y + h / 2, w, id)
end
......
......@@ -69,9 +69,9 @@ tm:applyOnGroups(rooms, function(w, h, data, room, idx)
print("ROOM", idx, "::", rw, rh, "=>", rw * rh)
tm:fillGroup(room, '.')
if noroomforest and rw >= 8 and rh >= 8 then
local pond = Heightmap.new(1.6, {up_left=0, down_left=0, up_right=0, down_right=0, middle=1}):make(rw-2, rh-2, {' ', 'T', '=', '='})
local pond = Heightmap.new(1.6, {up_left=0, down_left=0, up_right=0, down_right=0, middle=1}):make(rw-2, rh-2, {' ', ';', ';', 'T', '=', '='})
pond:printResult()
tm:fillGroup(room, ';')
-- tm:fillGroup(room, ';')
tm:merge(p1.x+1, p1.y+1, pond)
noroomforest = false
end
......@@ -92,20 +92,25 @@ tm:fillAll()
-- Elimitate the rest
if tm:eliminateByFloodfill{'#', 'T'} < 400 then return self:regenerate() end
-- tm:printResult()
print('---==============---')
local noise = Noise.new(nil, 0.5, 2, 3, 6):make(80, 50, {'T', 'T', '=', '=', '=', ';', ';'})
noise:printResult()
print('---==============---')
print('---==============---')
local pond = Heightmap.new(1.9, {up_left=0, down_left=0, up_right=0, down_right=0, middle=1}):make(30, 30, {';', 'T', '=', '=', ';'})
pond:printResult()
print('---==============---')
print('---==============---')
local maze = Maze.new():makeSimple(31, 31, '.', {'#','T'}, true)
maze:printResult()
print('---==============---')
self.data.greater_vaults_list = {"32-chambers"}
local proom = Rooms.new(self, "greater_vault"):generateRoom()
tm:carveArea('#', tm:point(28, 1), tm:point(28+proom.data_w+4, 2+proom.data_h+4))
tm:merge(30, 2, proom)
tm:printResult()
-- print('---==============---')
-- local noise = Noise.new(nil, 0.5, 2, 3, 6):make(80, 50, {'T', 'T', '=', '=', '=', ';', ';'})
-- noise:printResult()
-- print('---==============---')
-- print('---==============---')
-- local pond = Heightmap.new(1.9, {up_left=0, down_left=0, up_right=0, down_right=0, middle=1}):make(30, 30, {';', 'T', '=', '=', ';'})
-- pond:printResult()
-- print('---==============---')
-- print('---==============---')
-- local maze = Maze.new():makeSimple(31, 31, '.', {'#','T'}, true)
-- maze:printResult()
-- print('---==============---')
-- DGDGDGDG: make at least Tilemap handlers for BSP, roomer (single room), roomers and correctly handle up/down stairs
......
-- ToME - Tales of Maj'Eyal
-- Copyright (C) 2009 - 2018 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
-- Merge them all
local tm = Tilemap.new(self.mapsize, '#')
tm:carveArea(';', tm:point(1, 1), tm:point(4, 4))
self.data.greater_vaults_list = {"32-chambers"}
local proom = Rooms.new(self, "greater_vault"):generateRoom()
tm:merge(12, 5, proom)
tm:printResult()
-- print('---==============---')
-- local noise = Noise.new(nil, 0.5, 2, 3, 6):make(80, 50, {'T', 'T', '=', '=', '=', ';', ';'})
-- noise:printResult()
-- print('---==============---')
-- print('---==============---')
-- local pond = Heightmap.new(1.9, {up_left=0, down_left=0, up_right=0, down_right=0, middle=1}):make(30, 30, {';', 'T', '=', '=', ';'})
-- pond:printResult()
-- print('---==============---')
-- print('---==============---')
-- local maze = Maze.new():makeSimple(31, 31, '.', {'#','T'}, true)
-- maze:printResult()
-- print('---==============---')
-- DGDGDGDG: make at least Tilemap handlers for BSP, roomer (single room), roomers and correctly handle up/down stairs
return tm
......@@ -42,7 +42,8 @@ return {
['_'] = "FLOOR", ['O'] = "WALL",
[';'] = "GRASS", ['T'] = "TREE",
['='] = "DEEP_WATER",
mapscript = "!inner_outer",
mapscript = "!testroom",
-- mapscript = "!inner_outer",
--]]
--[[
class = "engine.generator.map.Hexacle",
......
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