Lançamento inicial

master
BrunoMine 2016-08-20 15:27:11 -03:00
parent b2d2a085e6
commit 3211f0523c
17 changed files with 1065 additions and 1 deletions

View File

@ -1 +1,9 @@
sociedades
Modpack Colonus
===============
### Sobre
Esse modpack adiciona sociedades em minetest.
Cada sociedade possui uma caracteristica própria.
### Contribuidores:
BrunoMine

1
depends.txt Normal file
View File

@ -0,0 +1 @@

1
modpack.txt Normal file
View File

@ -0,0 +1 @@

165
sunos/LICENSE Normal file
View File

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

43
sunos/README.md Normal file
View File

@ -0,0 +1,43 @@
Sunos v0.7-beta
===============
Por BrunoMine
Esse mod adiciona os povos sunos ao jogo.
Eles aparecem aleatoriamente
# Sobre os Sunos
Os sunos (do esperanto, "sol") são povoados humildes que vivem
em planicies. Não possuem muita habilidade técnica e por isso
só utilizam materiais simples de encontrar
(Madeira, Pedras e etc).
### Licenças
Software LGPL v3
Sunos é um software livre; você pode redistribuí-lo e/ou
modificá-lo dentro dos termos da Licença Pública Geral Menor GNU
como publicada pela Fundação do Software Livre (FSF); na versão 3
da Licença, ou (na sua opinião) qualquer versão.
Este programa é distribuído na esperança de que possa ser útil,
mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO
a qualquer MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a
Licença Pública Geral Menor GNU para maiores detalhes.
Você deve ter recebido uma cópia da Licença Pública
Geral Menor GNU junto com este programa,
se não, veja <http://www.gnu.org/licenses/>.
## Comandos
/sunos <func> | Opera algumas funcionalidades
funcionalidades:
- Salvar uma estrutura: s <nome> <arquivo>
## Estruturas
Todas as estruturas tem largura e comprimento iguais e altura
maxima de 15.

74
sunos/comandos.lua Normal file
View File

@ -0,0 +1,74 @@
--[[
Mod Sunos para Minetest
Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine)
Recebeste uma cópia da GNU Lesser General
Public License junto com esse software,
se não, veja em <http://www.gnu.org/licenses/>.
Comandos
]]
-- Diretorio do Mod
local modpath = minetest.get_modpath("sunos")
-- Comando de serializar estrutura
minetest.register_chatcommand("sunos", {
privs = {server=true},
params = "<funcao> [Salvar estrutura | s <nome> <largura>] ",
description = "Opera algumas funcionalidades",
func = function(name, param)
local m = string.split(param, " ")
local param1, param2, param3 = m[1], m[2], m[3]
if param1 == "s" and tonumber(param3) then
param3 = tonumber(param3)
if param3 == 3 or param3 == 5 or param3 == 7 or param3 == 9 or param3 == 11 then
-- Serializando a estrutura
local player = minetest.get_player_by_name(name)
local pos = player:getpos()
local largura = param3
local altura = 15
-- Criar estrutura
local estrutura = {}
local ix, iy, iz = 1, 1, 1
local x, y, z = pos.x, pos.y, pos.z
local limx, limy, limz = (pos.x+largura-1), (pos.y+altura-1), (pos.z+largura-1)
local i = 0
while (x <= limx) do
while (y <= limy) do
while (z <= limz) do
estrutura[ix.." "..iy.." "..iz] = minetest.get_node({x = x, y = y, z = z})
i = i + 1
z = z + 1
iz = iz + 1
end
z = pos.z
iz = 1
y = y + 1
iy = iy + 1
end
y = pos.y
iy = 1
x = x + 1
ix = ix + 1
end
-- Criar arquivo
local output = io.open(modpath .. "/estruturas/"..param2.."."..largura, "w")
output:write(minetest.serialize(estrutura))
io.close(output)
-- Estrutura serializada com sucesso
minetest.chat_send_all("Serializacao concluida.")
end
else
return false
end
end
})

166
sunos/comum.lua Normal file
View File

@ -0,0 +1,166 @@
--[[
Mod Sunos para Minetest
Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine)
Recebeste uma cópia da GNU Lesser General
Public License junto com esse software,
se não, veja em <http://www.gnu.org/licenses/>.
Métodos comuns
]]
-- Pegar direcao oposta
sunos.pegar_dir_oposta = function(dir)
if dir == "x+" then
return "x-"
end
if dir == "x-" then
return "x+"
end
if dir == "z+" then
return "z-"
end
if dir == "z-" then
return "z+"
end
end
-- Pega ignore apenas se bloco nao foi gerado
sunos.pegar_node = function(pos)
local node = minetest.get_node(pos)
if node.name == "ignore" then
minetest.get_voxel_manip():read_from_map(pos, pos)
node = minetest.get_node(pos)
end
return node
end
-- Encontrar solo
sunos.pegar_solo = function(pos, dist, subir)
if pos == nil then
minetest.log("error", "[Sunos] Tabela pos nula (em sunos.pegar_solo)")
return false
end
if dist == nil then dist = 10 end
if subir == nil then subir = 0 end
local np = {x=pos.x, y=pos.y+subir, z=pos.z}
local y = 0
local r = nil
while y <= dist do
local node = sunos.pegar_node({x=np.x, y=np.y-y, z=np.z})
if node.name == "default:dirt_with_grass" then
r = {x=np.x, y=np.y-y, z=np.z}
break
end
y = y + 1
end
return r
end
-- Mover pos para uma direcao
sunos.ir_dir = function(pos, dir, dist)
if pos == nil then
minetest.log("error", "[Sunos] Tabela pos nula (em sunos.ir_dir)")
return false
end
if dist == nil then dist = 1 end
if dir == "x+" then
return {x=pos.x+dist, y=pos.y, z=pos.z}
elseif dir == "x-" then
return {x=pos.x-dist, y=pos.y, z=pos.z}
elseif dir == "z+" then
return {x=pos.x, y=pos.y, z=pos.z+dist}
elseif dir == "z-" then
return {x=pos.x, y=pos.y, z=pos.z-dist}
else
return pos
end
end
-- Gira uma direcao
sunos.girar_dir = function(dir, lado)
if dir == nil then
minetest.log("error", "[Sunos] String dir nula (em sunos.girar_dir)")
return false
end
if lado ~= "<" and lado ~= ">" then
minetest.log("error", "[Sunos] String lado invalida (em sunos.girar_dir)")
return false
end
if dir == "x+" then
if lado == "<" then
return "z+"
else
return "z-"
end
elseif dir == "x-" then
if lado == "<" then
return "z-"
else
return "z+"
end
elseif dir == "z+" then
if lado == "<" then
return "x-"
else
return "x+"
end
elseif dir == "z-" then
if lado == "<" then
return "x+"
else
return "x-"
end
end
end
-- Pegar uma direcao aleatoriamente
sunos.pegar_dir_aleatoria = function(exeto)
local d = {"x+", "x-", "z+", "z-"}
if table.maxn(exeto) >= 4 then
minetest.log("error", "[Sunos] todas as direcoes foram proibidas (em sunos.pegar_dir_aleatoria)")
return nil
end
if exeto and table.maxn(exeto) > 0 then
for _,dir2 in ipairs(exeto) do
for n,dir in ipairs(d) do
if dir == dir2 then
table.remove(d, n)
end
end
end
end
return d[math.random(1, table.maxn(d))]
end
-- Forçar tentar pegar solo
sunos.f_pegar_solo = function(p, degrau, dist, subir)
if p == nil then
minetest.log("error", "[Sunos] Tabela p nula (em sunos.f_pegar_solo)")
return false
end
if subir == nil then subir = 0 end
local s = sunos.pegar_solo(p, dist, subir)
if s == nil then
s = p
local pp = minetest.find_node_near(p, 2, {"default:cobble"})
if pp then s.y = pp.y end
end
if degrau then
if s.y > p.y then
s.y = p.y + 1
elseif s.y < p.y then
s.y = p.y - 1
end
end
return s
end

1
sunos/depends.txt Normal file
View File

@ -0,0 +1 @@
default

96
sunos/estruturador.lua Normal file
View File

@ -0,0 +1,96 @@
--[[
Mod Sunos para Minetest
Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine)
Recebeste uma cópia da GNU Lesser General
Public License junto com esse software,
se não, veja em <http://www.gnu.org/licenses/>.
Montagem de estruturas
]]
local modpath = minetest.get_modpath("sunos")
-- Pegar um nome de uma arquivo de estrutura aleatoriamente
local pegar_arquivo = function(largura)
if largura == nil then
minetest.log("error", "[Sunos] Largura nula (em pegar_arquivo)")
return false
end
local estruturas = minetest.get_dir_list(modpath.."/estruturas")
local validos = {}
if estruturas ~= nil then
for _,nome in ipairs(estruturas) do
local n = string.split(nome, ".")
if n[2] and tonumber(n[2]) == tonumber(largura) then
table.insert(validos, n[1])
end
end
else
return nil
end
if validos[1] then
return validos[math.random(1, table.maxn(validos))]
else
return nil
end
end
-- Montar uma estrutura
sunos.montar_estrutura = function(cpos, dist)
if cpos == nil then
minetest.log("error", "[Sunos] Tabela cpos nula (em sunos.montar_estrutura)")
return false
end
-- Coleta de dados
local pos = {x=cpos.x-dist, y=cpos.y, z=cpos.z-dist}
-- Largura
local largura = 2*dist+1
local altura = 15
-- Estrutura
local ESTRUTURA = {}
if pegar_arquivo(largura) == nil then return false end
local input = io.open(modpath .. "/estruturas/"..pegar_arquivo(largura).."."..largura, "r")
if input then
ESTRUTURA = minetest.deserialize(input:read("*l"))
else
return false
end
io.close(input)
-- Criar estrutura
local ix, iy, iz = 1, 1, 1
local x, y, z = pos.x, pos.y, pos.z
local limx, limy, limz = (pos.x+largura-1), (pos.y+altura-1), (pos.z+largura-1)
local i = 0
while (x <= limx) do
while (y <= limy) do
while (z <= limz) do
local node = ESTRUTURA[ix.." "..iy.." "..iz] or {node={name="air"}}
minetest.set_node({x = x, y = y, z = z}, node)
i = i + 1
z = z + 1
iz = iz + 1
end
z = pos.z
iz = 1
y = y + 1
iy = iy + 1
end
y = pos.y
iy = 1
x = x + 1
ix = ix + 1
end
return true
end

1
sunos/estruturas/teste.3 Normal file

File diff suppressed because one or more lines are too long

1
sunos/estruturas/teste.5 Normal file

File diff suppressed because one or more lines are too long

1
sunos/estruturas/teste.7 Normal file

File diff suppressed because one or more lines are too long

1
sunos/estruturas/teste.9 Normal file

File diff suppressed because one or more lines are too long

43
sunos/init.lua Normal file
View File

@ -0,0 +1,43 @@
--[[
Mod Sunos para Minetest
Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine)
Recebeste uma cópia da GNU Lesser General
Public License junto com esse software,
se não, veja em <http://www.gnu.org/licenses/>.
Inicializador de scripts
]]
-- Tabela global
sunos = {}
-- Configurações / Settings
--[[
Quanto maior, mais raro (Minimo é 1).
The larger, more rare (Minimo is 1).
]]
sunos.RARIDADE = 1
-- Notificador de Inicializador
local notificar = function(msg)
if minetest.setting_get("log_mods") then
minetest.debug("[SUNOS]"..msg)
end
end
-- Modpath
local modpath = minetest.get_modpath("sunos")
-- Carregar scripts
notificar("Carregando...")
dofile(modpath.."/comum.lua")
dofile(modpath.."/estruturador.lua")
dofile(modpath.."/vila.lua")
dofile(modpath.."/mapgen.lua")
dofile(modpath.."/nodes.lua")
dofile(modpath.."/comandos.lua")
notificar("[OK]!")

164
sunos/mapgen.lua Normal file
View File

@ -0,0 +1,164 @@
--[[
Mod Sunos para Minetest
Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine)
Recebeste uma cópia da GNU Lesser General
Public License junto com esse software,
se não, veja em <http://www.gnu.org/licenses/>.
Analize de mapgen
]]
-- Pega ignore apenas se bloco nao foi gerado
local function pegar_node(pos)
local node = minetest.get_node(pos)
if node.name == "ignore" then
minetest.get_voxel_manip():read_from_map(pos, pos)
node = minetest.get_node(pos)
end
return node
end
-- Encontrar solo
local function pegar_solo(pos)
local y = 0
local r = nil
while y <= 80 do
local node = pegar_node({x=pos.x, y=pos.y-y, z=pos.z})
if node.name == "default:dirt_with_grass" then
r = {x=pos.x, y=pos.y-y, z=pos.z}
break
end
y = y + 1
end
return r
end
-- Verifica se um ponto existe na malha
local function verificar_ponto(x, z)
if x < 1 or x > 7 or z < 1 or z > 7 then
return false
else
return true
end
end
-- Comparar valor max
local function comparar_max(max, n)
if max == nil then
return n
elseif max < n then
return n
else
return max
end
end
-- Comparar valor min
local function comparar_min(min, n)
if min == nil then
return n
elseif min > n then
return n
else
return min
end
end
-- Montar malha e coletar dados nos pontos
local pegar_malha = function(minp, maxp)
local vetor = {}
-- montando vetor
for x=1, 7 do
vetor[x] = {}
for z=1, 7 do
vetor[x][z] = {}
end
end
-- Pegando dados para cada posicao
for x,_ in ipairs(vetor) do
for z,_ in ipairs(vetor[x]) do
-- Pegar solo
vetor[x][z].p = pegar_solo({x=minp.x+(10*x), y=maxp.y, z=minp.z+(10*z)})
-- Calcular variacao dos pontos adjacentes
local max, min = nil, nil
local div = 0
for xi=-1, 1 do
for zi=-1, 1 do
local xn, zn = x+xi, z+zi
if verificar_ponto(xn, zn) then
if vetor[xn][zn].p then
max = comparar_max(max, vetor[xn][zn].p.y)
min = comparar_min(min, vetor[xn][zn].p.y)
div = div + 1
end
end
end
end
if div >= 5 then
vetor[x][z].var = max - min
else
vetor[x][z].var = nil
end
end
end
return vetor
end
-- Chamada de função para verificar mapa gerado
minetest.register_on_generated(function(minp, maxp, seed)
-- Verificar altura
if minp.y < -70 or minp.y > 120 then return end
-- Pegar malha
local malha = pegar_malha(minp, maxp)
-- Verificar qunatidade de pontos em areas planos
local rel = {nul=0,bom=0,ruim=0}
local min = nil
local pos = nil
local vpos = {}
for x,_ in ipairs(malha) do
for z,_ in ipairs(malha[x]) do
local po = malha[x][z]
if po.var == nil then
rel.nul = rel.nul + 1
elseif po.var <= 3 then
rel.bom = rel.bom + 1
if malha[x][z].p then
table.insert(vpos, malha[x][z].p)
end
else
rel.ruim = rel.ruim + 1
end
if malha[x][z].p then
if malha[x][z].var and min ~= comparar_min(min, malha[x][z].var) then
min = comparar_min(min, malha[x][z].var)
pos = malha[x][z].p
elseif pos == nil then
pos = malha[x][z].p
end
end
end
end
if rel.bom < 10 then return end
if 1 < math.random(1, sunos.RARIDADE) then return end
if pos then
sunos.criar_vila(pos, vpos)
end
end)

25
sunos/nodes.lua Normal file
View File

@ -0,0 +1,25 @@
--[[
Mod Sunos para Minetest
Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine)
Recebeste uma cópia da GNU Lesser General
Public License junto com esse software,
se não, veja em <http://www.gnu.org/licenses/>.
Nodes
]]
minetest.register_node("sunos:teste", {
description = "TESTE SUNOS",
tiles = {"default_stone.png"},
is_ground_content = true,
groups = {cracky=3, stone=1},
drop = 'default:cobble',
legacy_mineral = true,
sounds = default.node_sound_stone_defaults(),
on_use = function(itemstack, player, pointed_thing)
if pointed_thing and pointed_thing.under then
sunos.criar_vila(pointed_thing.under)
end
end,
})

273
sunos/vila.lua Normal file
View File

@ -0,0 +1,273 @@
--[[
Mod Sunos para Minetest
Copyright (C) 2016 BrunoMine (https://github.com/BrunoMine)
Recebeste uma cópia da GNU Lesser General
Public License junto com esse software,
se não, veja em <http://www.gnu.org/licenses/>.
Montagem de vilas
]]
-- Criar assentamento de construcao
local criar_assent = function(pos, dist)
for x=pos.x-dist, pos.x+dist do
for z=pos.z-dist, pos.z+dist do
local y = pos.y + 6
while y > pos.y-5 do
local p = {x=x, y=y, z=z}
if y > pos.y then
minetest.set_node(p, {name="air"})
elseif y == pos.y then
minetest.set_node(p, {name="default:cobble"})
elseif y == pos.y-1 then
minetest.set_node(p, {name="default:dirt"})
else
minetest.set_node(p, {name="default:stone"})
end
y = y - 1
end
end
end
-- Criar faixa de terra ao redor
local y = pos.y + 6
while y > pos.y-5 do
for x=pos.x-dist-1, pos.x+dist+1 do
local p1 = {x=x, y=y, z=pos.z+dist+1}
local p2 = {x=x, y=y, z=pos.z-dist-1}
if y > pos.y then
minetest.set_node(p1, {name="air"})
minetest.set_node(p2, {name="air"})
elseif y == pos.y then
minetest.set_node(p1, {name="default:dirt_with_grass"})
minetest.set_node(p2, {name="default:dirt_with_grass"})
elseif y == pos.y-1 then
minetest.set_node(p1, {name="default:dirt"})
minetest.set_node(p2, {name="default:dirt"})
else
minetest.set_node(p1, {name="default:stone"})
minetest.set_node(p2, {name="default:stone"})
end
end
for z=pos.z-dist-1, pos.z+dist+1 do
local p1 = {x=pos.x+dist+1, y=y, z=z}
local p2 = {x=pos.x-dist-1, y=y, z=z}
if y > pos.y then
minetest.set_node(p1, {name="air"})
minetest.set_node(p2, {name="air"})
elseif y == pos.y then
minetest.set_node(p1, {name="default:dirt_with_grass"})
minetest.set_node(p2, {name="default:dirt_with_grass"})
elseif y == pos.y-1 then
minetest.set_node(p1, {name="default:dirt"})
minetest.set_node(p2, {name="default:dirt"})
else
minetest.set_node(p1, {name="default:stone"})
minetest.set_node(p2, {name="default:stone"})
end
end
y = y - 1
end
end
-- Verificar pos obstruidos (pode verificar largura disponivel de assentamento)
local verif_obs = function(pos, assent)
if pos == nil then
minetest.log("error", "[Sunos] Tabela pos nula (em verif_obs)")
return false
end
if assent and tonumber(assent) then
local a = 0
while a <= assent do
local i = 0
local p = {x=pos.x, y=pos.y, z=pos.z}
-- Quinas
p = {x=pos.x+a, y=pos.y, z=pos.z+a}
if sunos.pegar_solo(p, 4, 2) then i = i + 1 end
p = {x=pos.x+a, y=pos.y, z=pos.z-a}
if sunos.pegar_solo(p, 4, 2) then i = i + 1 end
p = {x=pos.x-a, y=pos.y, z=pos.z+a}
if sunos.pegar_solo(p, 4, 2) then i = i + 1 end
p = {x=pos.x-a, y=pos.y, z=pos.z-a}
if sunos.pegar_solo(p, 4, 2) then i = i + 1 end
-- Lados
p = {x=pos.x+a, y=pos.y, z=pos.z}
if sunos.pegar_solo(p, 4, 2) then i = i + 1 end
p = {x=pos.x-a, y=pos.y, z=pos.z}
if sunos.pegar_solo(p, 4, 2) then i = i + 1 end
p = {x=pos.x, y=pos.y, z=pos.z+a}
if sunos.pegar_solo(p, 4, 2) then i = i + 1 end
p = {x=pos.x, y=pos.y, z=pos.z-a}
if sunos.pegar_solo(p, 4, 2) then i = i + 1 end
if i < 8 then
a = a - 1
break
end
a = a + 1
end
return a
end
-- verifica bloco um bloco
if sunos.pegar_solo(pos, 4, 2) then
return true
else
return false
end
end
sunos.verif_obs = verif_obs
-- Verifica direcoes obstruidas (retorna tabela de disponiveis como segundo valor)
local verif_obs_dir = function(pos, dist)
if pos == nil then
minetest.log("error", "[Sunos] Tabela pos nula (em verif_obs_dir)")
return false
end
if dist == nil then dist = 4 end
local obs = {}
local disp = {}
for _,dir in ipairs({"x+", "x-", "z+", "z-"}) do
if verif_obs(sunos.ir_dir(pos, dir, dist)) == false then
table.insert(obs, dir)
else
table.insert(disp, dir)
end
end
return obs, disp
end
-- Tentar colocar assentamento por perto
local tentar_assentamento = function(pos)
if pos == nil then
minetest.log("error", "[Sunos] Tabela pos nula (em verif_assentamento)")
return false
end
-- Distancia centro-borda do assentamento
local dist_assent = math.random(4, 6)
-- Distancia da rua ao centro do terreno
local dist = dist_assent + 2
-- Pegando lugares obstruidos e disponiveis
local obs, disp = verif_obs_dir(pos, dist)
-- Descarta caso nao encontre possibilidades
if table.maxn(disp) == 0 then return false end
-- Montando metapos de possiveis lugares
local mpos = {}
for n,dir in ipairs(disp) do
local p = sunos.pegar_solo(sunos.ir_dir(pos, dir, dist), 4, 2)
local dist_disp = verif_obs(p, dist_assent)
-- Desconta a dintancia entre obstrucoes (assentamentos, ruas e etc)
dist_disp = dist_disp - 3
-- armazenando
if dist_disp >= 1 then
table.insert(mpos, {p=p, dist=dist_disp})
end
end
-- Pega o metapos
local max = 0
local nmax = nil
for n,dados in ipairs(mpos) do
if dados.dist > max then
max = dados.dist
nmax = n
end
end
if nmax == nil or max == 0 then
return nil
end
criar_assent(mpos[nmax].p, mpos[nmax].dist)
return {pos=mpos[nmax].p, dist=mpos[nmax].dist}
end
-- Montar uma vila
sunos.criar_vila = function(pos, vpos)
if pos == nil then
minetest.log("error", "[Sunos] Tabela pos nula (em sunos.criar_vila)")
return false
end
if vpos == nil then
vpos = {}
end
-- Metanode que guia a montagem
-- Realizar ciclos para montar a vila
local dir = nil
local dir_ant = nil
local assent_rest = math.random(6, 10)
local assentamentos = {}
local ciclo = 0
while ciclo <= 50 and assent_rest > 0 do
-- Verificar lados obstruidos (dir_ant se inclui altomaticamente)
local obs = verif_obs_dir(pos, 4)
-- Verifica se todas as direcoes estao obstruidas
if table.maxn(obs) < 4
and minetest.find_node_near(pos, 6, {"group:leaves", "group:water"}) == nil
then
-- Define nova direcao
dir = sunos.pegar_dir_aleatoria(obs)
-- Move metapos para o novo lugar
pos = sunos.ir_dir(pos, dir, 4)
pos = sunos.f_pegar_solo(pos, false, 5, 10)
-- Prepara direcao anterior para o proximo loop
dir_ant = dir
-- Tenta montar um assentamento antes de finalizar o loop (a cada um certo tanto de ruas)
if assent_rest > 0 then
local assent = tentar_assentamento(pos)
if assent then
table.insert(assentamentos, assent)
assent_rest = assent_rest - 1
end
end
else
if table.maxn(vpos) > 1 then
pos = vpos[1]
table.remove(vpos, 1)
else
break
end
end
ciclo = ciclo + 1
end
-- Montar Estruturas nos assentamentos
if assentamentos then
for _,dados in ipairs(assentamentos) do
sunos.montar_estrutura(dados.pos, dados.dist)
end
end
end