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

more mapscript stuff

parent 4fb23638
No related branches found
No related tags found
1 merge request!509WIP: Orange tooltip edits
Pipeline #
......@@ -60,6 +60,11 @@ function _M:custom(lev, old_lev)
local file = self:getFile(self.data.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
setfenv(f, setmetatable(env or {
self = self,
zone = self.zone,
......@@ -69,6 +74,8 @@ function _M:custom(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",
}, {__index=_G}))
ret = f()
elseif self.data.custom then
......
-- 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 HMap = require "engine.Heightmap"
--- Generate map-like data from a heightmap fractal
-- @classmod engine.tilemaps.Heightmap
module(..., package.seeall, class.inherit(Tilemap))
function _M:init(roughness, start)
self.roughness = roughness or 1.2
self.start = start or {}
for k, e in pairs(start) do start[k] = e * HMap.max end
end
function _M:make(w, h, chars)
self.data_w = w
self.data_h = h
self.data = self:makeData(w, h, ' ')
local hmap = HMap.new(w, h, self.roughness, self.start)
hmap:generate()
for j = 1, h do
for i = 1, w do
local c = util.bound((math.floor(hmap.hmap[i][j] / hmap.max * #chars) + 1), 1, #chars)
self.data[j][i] = chars[c]
end
end
return self
end
-- 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"
--- Generate map-like data from a noise generator
-- @classmod engine.tilemaps.Noise
module(..., package.seeall, class.inherit(Tilemap))
function _M:init(noise_kind, hurst, lacunarity, zoom, octave)
self.noise_kind = noise_kind or "fbm_perlin"
hurst = hurst or 0.5
lacunarity = lacunarity or 2
self.zoom = zoom or 1
self.octave = octave or 6
self.noise = core.noise.new(2, self.hurst, self.lacunarity)
-- self.data_h = #self.data
-- self.data_w = self.data[1] and #self.data[1] or 0
end
function _M:make(w, h, chars)
self.data_w = w
self.data_h = h
self.data = self:makeData(w, h, ' ')
for i = 1, w do for j = 1, h do
local v = math.floor((self.noise[self.noise_kind](self.noise, self.zoom * (i-1) / w, self.zoom * (j-1) / h, self.octave) / 2 + 0.5) * #chars)
-- print("----noise-----", i, j, '=>', v, '=>', chars[v+1])
self.data[j][i] = chars[v+1]
end end
return self
end
-- 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"
--- Generate map-like data from a tmx file
-- @classmod engine.tilemaps.Static
module(..., package.seeall, class.inherit(Tilemap))
function _M:init(file)
self.data = self:tmxLoad(file)
self.data_h = #self.data
self.data_w = self.data[1] and #self.data[1] or 0
end
......@@ -295,6 +295,14 @@ function _M:eliminateByFloodfill(walls)
end
end
function _M:fillGroup(group, char)
-- print("[Tilemap] Filling group of", #group.list, "with", char)
for j = 1, #group.list do
local jn = group.list[j]
self.data[jn.y][jn.x] = char
end
end
function _M:isInGroup(group, x, y)
if not group.reverse then
group.reverse = {}
......@@ -421,7 +429,7 @@ function _M:groupOuterRectangle(group)
-- end
-- end end
return {x1=x1, y1=y1, x2=x2, y2=y2, w=x2 - x1 + 1, h=y2 - y1 + 1}
return self:point(x1, y1), self:point(x2, y2), x2 - x1 + 1, y2 - y1 + 1
end
--- Carve out a simple linear path from coords until a tile is reached
......@@ -461,6 +469,11 @@ end
--- Merge and 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
if type(x) == "table" then
x, y, tm, char_order, empty_char = x.x, x.y, y, tm, char_order
end
x = math.floor(x)
y = math.floor(y)
char_order = table.reverse(char_order or {})
......
......@@ -18,8 +18,6 @@
-- darkgod@te4.org
require "engine.class"
local lom = require "lxp.lom"
local mime = require "mime"
local Tilemap = require "engine.tilemaps.Tilemap"
--- Generate map-like data from samples using the WaveFunctionCollapse algorithm (in C++)
......
......@@ -63,20 +63,34 @@ tm:carveLinearPath('.', doorwaytunnel + doorwaypos, 6, '.')
-- Find rooms
local rooms = tm:findGroupsOf{'r'}
local noroomforest = true
tm:applyOnGroups(rooms, function(w, h, data, room, idx)
print("ROOM", idx, "::" , unpack(tm:groupOuterRectangle(room)))
local p1, p2, rw, rh = tm:groupOuterRectangle(room)
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, rh, {' ', 'T', '=', '=', ';'})
pond:printResult()
tm:merge(p1.x, p1.y, pond)
noroomforest = false
end
-- table.print()
for j = 1, #room.list do
local jn = room.list[j]
-- data[jn.y][jn.x] = tostring(idx)
end
end)
tm:fillAll('.', 'r')
if noroomforest then return self:regenerate() end
-- Complete the map by putting wall in all the remaining blank spaces
tm:fillAll()
-- Elimitate the rest
if tm:eliminateByFloodfill{'#', 'T'} < 400 then return self:regenerate() end
-- if tm:eliminateByFloodfill{'#', 'T'} < 400 then return self:regenerate() end
-- tm:printResult()
-- local noise = Noise.new():make(12, 12, {'T', 'T', '=', '=', '=', ';', ';'})
-- noise:printResult()
return tm
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