2013-08-11 04:09:45 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lua_api/l_mapgen.h"
|
|
|
|
#include "lua_api/l_internal.h"
|
|
|
|
#include "lua_api/l_vmanip.h"
|
|
|
|
#include "common/c_converter.h"
|
|
|
|
#include "common/c_content.h"
|
2014-09-06 02:08:51 +02:00
|
|
|
#include "cpp_api/s_security.h"
|
2014-09-12 00:22:05 +02:00
|
|
|
#include "util/serialize.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "server.h"
|
|
|
|
#include "environment.h"
|
|
|
|
#include "emerge.h"
|
2014-11-01 18:16:23 +01:00
|
|
|
#include "mg_biome.h"
|
|
|
|
#include "mg_ore.h"
|
|
|
|
#include "mg_decoration.h"
|
|
|
|
#include "mg_schematic.h"
|
2014-11-30 05:42:02 +01:00
|
|
|
#include "mapgen_v5.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "mapgen_v7.h"
|
2015-04-08 05:04:48 +02:00
|
|
|
#include "filesys.h"
|
2014-11-13 05:01:13 +01:00
|
|
|
#include "settings.h"
|
2014-09-12 00:22:05 +02:00
|
|
|
#include "log.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
|
|
|
|
struct EnumString ModApiMapgen::es_BiomeTerrainType[] =
|
|
|
|
{
|
2016-05-02 08:45:59 +02:00
|
|
|
{BIOMETYPE_NORMAL, "normal"},
|
|
|
|
{BIOMETYPE_LIQUID, "liquid"},
|
|
|
|
{BIOMETYPE_NETHER, "nether"},
|
|
|
|
{BIOMETYPE_AETHER, "aether"},
|
|
|
|
{BIOMETYPE_FLAT, "flat"},
|
2013-08-11 04:09:45 +02:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EnumString ModApiMapgen::es_DecorationType[] =
|
|
|
|
{
|
|
|
|
{DECO_SIMPLE, "simple"},
|
|
|
|
{DECO_SCHEMATIC, "schematic"},
|
|
|
|
{DECO_LSYSTEM, "lsystem"},
|
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EnumString ModApiMapgen::es_MapgenObject[] =
|
|
|
|
{
|
|
|
|
{MGOBJ_VMANIP, "voxelmanip"},
|
|
|
|
{MGOBJ_HEIGHTMAP, "heightmap"},
|
|
|
|
{MGOBJ_BIOMEMAP, "biomemap"},
|
|
|
|
{MGOBJ_HEATMAP, "heatmap"},
|
|
|
|
{MGOBJ_HUMIDMAP, "humiditymap"},
|
2013-12-14 07:52:06 +01:00
|
|
|
{MGOBJ_GENNOTIFY, "gennotify"},
|
2013-08-11 04:09:45 +02:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EnumString ModApiMapgen::es_OreType[] =
|
|
|
|
{
|
2015-04-01 05:27:19 +02:00
|
|
|
{ORE_SCATTER, "scatter"},
|
|
|
|
{ORE_SHEET, "sheet"},
|
2015-09-16 03:28:16 +02:00
|
|
|
{ORE_PUFF, "puff"},
|
2015-04-01 05:27:19 +02:00
|
|
|
{ORE_BLOB, "blob"},
|
|
|
|
{ORE_VEIN, "vein"},
|
2013-08-11 04:09:45 +02:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EnumString ModApiMapgen::es_Rotation[] =
|
|
|
|
{
|
|
|
|
{ROTATE_0, "0"},
|
|
|
|
{ROTATE_90, "90"},
|
|
|
|
{ROTATE_180, "180"},
|
|
|
|
{ROTATE_270, "270"},
|
|
|
|
{ROTATE_RAND, "random"},
|
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
2015-04-12 22:40:50 +02:00
|
|
|
struct EnumString ModApiMapgen::es_SchematicFormatType[] =
|
|
|
|
{
|
|
|
|
{SCHEM_FMT_HANDLE, "handle"},
|
|
|
|
{SCHEM_FMT_MTS, "mts"},
|
|
|
|
{SCHEM_FMT_LUA, "lua"},
|
|
|
|
{0, NULL},
|
|
|
|
};
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
ObjDef *get_objdef(lua_State *L, int index, ObjDefManager *objmgr);
|
|
|
|
|
|
|
|
Biome *get_or_load_biome(lua_State *L, int index,
|
|
|
|
BiomeManager *biomemgr);
|
|
|
|
Biome *read_biome_def(lua_State *L, int index, INodeDefManager *ndef);
|
|
|
|
size_t get_biome_list(lua_State *L, int index,
|
2017-06-04 21:00:04 +02:00
|
|
|
BiomeManager *biomemgr, std::unordered_set<u8> *biome_id_list);
|
2015-04-01 05:27:19 +02:00
|
|
|
|
|
|
|
Schematic *get_or_load_schematic(lua_State *L, int index,
|
2015-05-07 08:34:15 +02:00
|
|
|
SchematicManager *schemmgr, StringMap *replace_names);
|
2015-04-16 10:12:26 +02:00
|
|
|
Schematic *load_schematic(lua_State *L, int index, INodeDefManager *ndef,
|
2015-05-07 08:34:15 +02:00
|
|
|
StringMap *replace_names);
|
2015-04-16 10:12:26 +02:00
|
|
|
Schematic *load_schematic_from_def(lua_State *L, int index,
|
2015-05-07 08:34:15 +02:00
|
|
|
INodeDefManager *ndef, StringMap *replace_names);
|
2015-04-16 10:12:26 +02:00
|
|
|
bool read_schematic_def(lua_State *L, int index,
|
|
|
|
Schematic *schem, std::vector<std::string> *names);
|
|
|
|
|
|
|
|
bool read_deco_simple(lua_State *L, DecoSimple *deco);
|
2015-04-01 05:27:19 +02:00
|
|
|
bool read_deco_schematic(lua_State *L, SchematicManager *schemmgr, DecoSchematic *deco);
|
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
|
2014-12-10 07:49:57 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
ObjDef *get_objdef(lua_State *L, int index, ObjDefManager *objmgr)
|
|
|
|
{
|
|
|
|
if (index < 0)
|
|
|
|
index = lua_gettop(L) + 1 + index;
|
|
|
|
|
|
|
|
// If a number, assume this is a handle to an object def
|
|
|
|
if (lua_isnumber(L, index))
|
|
|
|
return objmgr->get(lua_tointeger(L, index));
|
|
|
|
|
|
|
|
// If a string, assume a name is given instead
|
|
|
|
if (lua_isstring(L, index))
|
|
|
|
return objmgr->getByName(lua_tostring(L, index));
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
Schematic *get_or_load_schematic(lua_State *L, int index,
|
2015-05-07 08:34:15 +02:00
|
|
|
SchematicManager *schemmgr, StringMap *replace_names)
|
2015-03-31 05:40:35 +02:00
|
|
|
{
|
|
|
|
if (index < 0)
|
|
|
|
index = lua_gettop(L) + 1 + index;
|
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
Schematic *schem = (Schematic *)get_objdef(L, index, schemmgr);
|
|
|
|
if (schem)
|
|
|
|
return schem;
|
|
|
|
|
|
|
|
schem = load_schematic(L, index, schemmgr->getNodeDef(),
|
2015-05-07 08:34:15 +02:00
|
|
|
replace_names);
|
2015-04-16 10:12:26 +02:00
|
|
|
if (!schem)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (schemmgr->add(schem) == OBJDEF_INVALID_HANDLE) {
|
|
|
|
delete schem;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return schem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Schematic *load_schematic(lua_State *L, int index, INodeDefManager *ndef,
|
2015-05-07 08:34:15 +02:00
|
|
|
StringMap *replace_names)
|
2015-04-16 10:12:26 +02:00
|
|
|
{
|
|
|
|
if (index < 0)
|
|
|
|
index = lua_gettop(L) + 1 + index;
|
|
|
|
|
|
|
|
Schematic *schem = NULL;
|
2015-03-31 05:40:35 +02:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
if (lua_istable(L, index)) {
|
2015-04-16 10:12:26 +02:00
|
|
|
schem = load_schematic_from_def(L, index, ndef,
|
2015-05-07 08:34:15 +02:00
|
|
|
replace_names);
|
2015-04-01 05:27:19 +02:00
|
|
|
if (!schem) {
|
2015-03-31 05:40:35 +02:00
|
|
|
delete schem;
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-04-01 05:27:19 +02:00
|
|
|
} else if (lua_isnumber(L, index)) {
|
|
|
|
return NULL;
|
|
|
|
} else if (lua_isstring(L, index)) {
|
|
|
|
schem = SchematicManager::create(SCHEMATIC_NORMAL);
|
2015-04-08 05:04:48 +02:00
|
|
|
|
|
|
|
std::string filepath = lua_tostring(L, index);
|
|
|
|
if (!fs::IsPathAbsolute(filepath))
|
|
|
|
filepath = ModApiBase::getCurrentModPath(L) + DIR_DELIM + filepath;
|
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
if (!schem->loadSchematicFromFile(filepath, ndef,
|
2015-05-07 08:34:15 +02:00
|
|
|
replace_names)) {
|
2015-03-31 05:40:35 +02:00
|
|
|
delete schem;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
return schem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-07 08:34:15 +02:00
|
|
|
Schematic *load_schematic_from_def(lua_State *L, int index,
|
|
|
|
INodeDefManager *ndef, StringMap *replace_names)
|
2015-04-01 05:27:19 +02:00
|
|
|
{
|
2015-04-16 10:12:26 +02:00
|
|
|
Schematic *schem = SchematicManager::create(SCHEMATIC_NORMAL);
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
if (!read_schematic_def(L, index, schem, &schem->m_nodenames)) {
|
|
|
|
delete schem;
|
2015-04-01 05:27:19 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
size_t num_nodes = schem->m_nodenames.size();
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
schem->m_nnlistsizes.push_back(num_nodes);
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
if (replace_names) {
|
|
|
|
for (size_t i = 0; i != num_nodes; i++) {
|
|
|
|
StringMap::iterator it = replace_names->find(schem->m_nodenames[i]);
|
|
|
|
if (it != replace_names->end())
|
|
|
|
schem->m_nodenames[i] = it->second;
|
2015-04-01 05:27:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 04:32:35 +02:00
|
|
|
if (ndef)
|
|
|
|
ndef->pendNodeResolve(schem);
|
2015-03-31 05:40:35 +02:00
|
|
|
|
|
|
|
return schem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
bool read_schematic_def(lua_State *L, int index,
|
|
|
|
Schematic *schem, std::vector<std::string> *names)
|
2014-12-10 07:49:57 +01:00
|
|
|
{
|
2015-04-01 05:27:19 +02:00
|
|
|
if (!lua_istable(L, index))
|
2015-04-16 10:12:26 +02:00
|
|
|
return false;
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2014-12-10 07:49:57 +01:00
|
|
|
//// Get schematic size
|
|
|
|
lua_getfield(L, index, "size");
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 size = check_v3s16(L, -1);
|
2014-12-10 07:49:57 +01:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
schem->size = size;
|
|
|
|
|
2014-12-10 07:49:57 +01:00
|
|
|
//// Get schematic data
|
|
|
|
lua_getfield(L, index, "data");
|
|
|
|
luaL_checktype(L, -1, LUA_TTABLE);
|
|
|
|
|
2015-05-09 07:38:20 +02:00
|
|
|
u32 numnodes = size.X * size.Y * size.Z;
|
2015-04-16 10:12:26 +02:00
|
|
|
schem->schemdata = new MapNode[numnodes];
|
2014-12-10 07:49:57 +01:00
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
size_t names_base = names->size();
|
2017-06-04 21:00:04 +02:00
|
|
|
std::unordered_map<std::string, content_t> name_id_map;
|
2015-04-16 10:12:26 +02:00
|
|
|
|
2015-05-09 07:38:20 +02:00
|
|
|
u32 i = 0;
|
|
|
|
for (lua_pushnil(L); lua_next(L, -2); i++, lua_pop(L, 1)) {
|
|
|
|
if (i >= numnodes)
|
2014-12-10 07:49:57 +01:00
|
|
|
continue;
|
|
|
|
|
2015-05-09 07:38:20 +02:00
|
|
|
//// Read name
|
|
|
|
std::string name;
|
|
|
|
if (!getstringfield(L, -1, "name", name))
|
|
|
|
throw LuaError("Schematic data definition with missing name field");
|
2014-12-10 07:49:57 +01:00
|
|
|
|
2015-05-09 07:38:20 +02:00
|
|
|
//// Read param1/prob
|
2014-12-10 07:49:57 +01:00
|
|
|
u8 param1;
|
2015-05-09 07:38:20 +02:00
|
|
|
if (!getintfield(L, -1, "param1", param1) &&
|
|
|
|
!getintfield(L, -1, "prob", param1))
|
|
|
|
param1 = MTSCHEM_PROB_ALWAYS_OLD;
|
2014-12-10 07:49:57 +01:00
|
|
|
|
2015-05-09 07:38:20 +02:00
|
|
|
//// Read param2
|
|
|
|
u8 param2 = getintfield_default(L, -1, "param2", 0);
|
2014-12-10 07:49:57 +01:00
|
|
|
|
2015-05-09 07:38:20 +02:00
|
|
|
//// Find or add new nodename-to-ID mapping
|
2017-06-04 21:00:04 +02:00
|
|
|
std::unordered_map<std::string, content_t>::iterator it = name_id_map.find(name);
|
2015-04-16 10:12:26 +02:00
|
|
|
content_t name_index;
|
|
|
|
if (it != name_id_map.end()) {
|
|
|
|
name_index = it->second;
|
|
|
|
} else {
|
|
|
|
name_index = names->size() - names_base;
|
|
|
|
name_id_map[name] = name_index;
|
|
|
|
names->push_back(name);
|
2015-04-12 22:40:50 +02:00
|
|
|
}
|
2014-12-10 07:49:57 +01:00
|
|
|
|
2015-05-09 07:38:20 +02:00
|
|
|
//// Perform probability/force_place fixup on param1
|
|
|
|
param1 >>= 1;
|
|
|
|
if (getboolfield_default(L, -1, "force_place", false))
|
|
|
|
param1 |= MTSCHEM_FORCE_PLACE;
|
2014-12-10 07:49:57 +01:00
|
|
|
|
2015-05-09 07:38:20 +02:00
|
|
|
//// Actually set the node in the schematic
|
|
|
|
schem->schemdata[i] = MapNode(name_index, param1, param2);
|
2014-12-10 07:49:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i != numnodes) {
|
2015-04-16 10:12:26 +02:00
|
|
|
errorstream << "read_schematic_def: incorrect number of "
|
2014-12-10 07:49:57 +01:00
|
|
|
"nodes provided in raw schematic data (got " << i <<
|
|
|
|
", expected " << numnodes << ")." << std::endl;
|
2015-04-16 10:12:26 +02:00
|
|
|
return false;
|
2014-12-10 07:49:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//// Get Y-slice probability values (if present)
|
2015-04-16 10:12:26 +02:00
|
|
|
schem->slice_probs = new u8[size.Y];
|
2015-05-13 00:04:30 +02:00
|
|
|
for (i = 0; i != (u32) size.Y; i++)
|
2015-04-16 10:12:26 +02:00
|
|
|
schem->slice_probs[i] = MTSCHEM_PROB_ALWAYS;
|
2014-12-10 07:49:57 +01:00
|
|
|
|
|
|
|
lua_getfield(L, index, "yslice_prob");
|
|
|
|
if (lua_istable(L, -1)) {
|
2015-05-09 07:38:20 +02:00
|
|
|
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
|
|
|
u16 ypos;
|
|
|
|
if (!getintfield(L, -1, "ypos", ypos) || (ypos >= size.Y) ||
|
|
|
|
!getintfield(L, -1, "prob", schem->slice_probs[ypos]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
schem->slice_probs[ypos] >>= 1;
|
2014-12-10 07:49:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
return true;
|
2014-12-10 07:49:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
void read_schematic_replacements(lua_State *L, int index, StringMap *replace_names)
|
2014-12-10 07:49:57 +01:00
|
|
|
{
|
|
|
|
if (index < 0)
|
|
|
|
index = lua_gettop(L) + 1 + index;
|
|
|
|
|
2014-09-12 04:25:06 +02:00
|
|
|
lua_pushnil(L);
|
|
|
|
while (lua_next(L, index)) {
|
|
|
|
std::string replace_from;
|
|
|
|
std::string replace_to;
|
2014-10-08 21:28:14 +02:00
|
|
|
|
|
|
|
if (lua_istable(L, -1)) { // Old {{"x", "y"}, ...} format
|
2014-09-12 04:25:06 +02:00
|
|
|
lua_rawgeti(L, -1, 1);
|
2017-05-08 20:43:03 +02:00
|
|
|
if (!lua_isstring(L, -1))
|
|
|
|
throw LuaError("schematics: replace_from field is not a string");
|
2014-09-12 04:25:06 +02:00
|
|
|
replace_from = lua_tostring(L, -1);
|
|
|
|
lua_pop(L, 1);
|
2014-10-08 21:28:14 +02:00
|
|
|
|
2014-09-12 04:25:06 +02:00
|
|
|
lua_rawgeti(L, -1, 2);
|
2017-05-08 20:43:03 +02:00
|
|
|
if (!lua_isstring(L, -1))
|
|
|
|
throw LuaError("schematics: replace_to field is not a string");
|
2014-09-12 04:25:06 +02:00
|
|
|
replace_to = lua_tostring(L, -1);
|
|
|
|
lua_pop(L, 1);
|
2014-10-08 21:28:14 +02:00
|
|
|
} else { // New {x = "y", ...} format
|
2017-05-08 20:43:03 +02:00
|
|
|
if (!lua_isstring(L, -2))
|
|
|
|
throw LuaError("schematics: replace_from field is not a string");
|
2014-09-12 04:25:06 +02:00
|
|
|
replace_from = lua_tostring(L, -2);
|
2017-05-08 20:43:03 +02:00
|
|
|
if (!lua_isstring(L, -1))
|
|
|
|
throw LuaError("schematics: replace_to field is not a string");
|
2014-09-12 04:25:06 +02:00
|
|
|
replace_to = lua_tostring(L, -1);
|
|
|
|
}
|
2014-10-08 21:28:14 +02:00
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
replace_names->insert(std::make_pair(replace_from, replace_to));
|
2014-09-12 04:25:06 +02:00
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
Biome *get_or_load_biome(lua_State *L, int index, BiomeManager *biomemgr)
|
|
|
|
{
|
|
|
|
if (index < 0)
|
|
|
|
index = lua_gettop(L) + 1 + index;
|
|
|
|
|
|
|
|
Biome *biome = (Biome *)get_objdef(L, index, biomemgr);
|
|
|
|
if (biome)
|
|
|
|
return biome;
|
|
|
|
|
|
|
|
biome = read_biome_def(L, index, biomemgr->getNodeDef());
|
|
|
|
if (!biome)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (biomemgr->add(biome) == OBJDEF_INVALID_HANDLE) {
|
|
|
|
delete biome;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return biome;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Biome *read_biome_def(lua_State *L, int index, INodeDefManager *ndef)
|
|
|
|
{
|
|
|
|
if (!lua_istable(L, index))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
BiomeType biometype = (BiomeType)getenumfield(L, index, "type",
|
2016-05-02 08:45:59 +02:00
|
|
|
ModApiMapgen::es_BiomeTerrainType, BIOMETYPE_NORMAL);
|
2015-04-16 10:12:26 +02:00
|
|
|
Biome *b = BiomeManager::create(biometype);
|
|
|
|
|
|
|
|
b->name = getstringfield_default(L, index, "name", "");
|
2015-08-02 02:35:05 +02:00
|
|
|
b->depth_top = getintfield_default(L, index, "depth_top", 0);
|
|
|
|
b->depth_filler = getintfield_default(L, index, "depth_filler", -31000);
|
2015-04-19 04:37:55 +02:00
|
|
|
b->depth_water_top = getintfield_default(L, index, "depth_water_top", 0);
|
2016-06-03 13:58:50 +02:00
|
|
|
b->depth_riverbed = getintfield_default(L, index, "depth_riverbed", 0);
|
2015-04-19 04:37:55 +02:00
|
|
|
b->y_min = getintfield_default(L, index, "y_min", -31000);
|
|
|
|
b->y_max = getintfield_default(L, index, "y_max", 31000);
|
|
|
|
b->heat_point = getfloatfield_default(L, index, "heat_point", 0.f);
|
|
|
|
b->humidity_point = getfloatfield_default(L, index, "humidity_point", 0.f);
|
2015-04-16 10:12:26 +02:00
|
|
|
b->flags = 0; //reserved
|
|
|
|
|
|
|
|
std::vector<std::string> &nn = b->m_nodenames;
|
2015-04-19 04:37:55 +02:00
|
|
|
nn.push_back(getstringfield_default(L, index, "node_top", ""));
|
|
|
|
nn.push_back(getstringfield_default(L, index, "node_filler", ""));
|
|
|
|
nn.push_back(getstringfield_default(L, index, "node_stone", ""));
|
|
|
|
nn.push_back(getstringfield_default(L, index, "node_water_top", ""));
|
|
|
|
nn.push_back(getstringfield_default(L, index, "node_water", ""));
|
|
|
|
nn.push_back(getstringfield_default(L, index, "node_river_water", ""));
|
2016-06-03 13:58:50 +02:00
|
|
|
nn.push_back(getstringfield_default(L, index, "node_riverbed", ""));
|
2015-04-19 04:37:55 +02:00
|
|
|
nn.push_back(getstringfield_default(L, index, "node_dust", ""));
|
2015-05-07 08:34:15 +02:00
|
|
|
ndef->pendNodeResolve(b);
|
2015-04-16 10:12:26 +02:00
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t get_biome_list(lua_State *L, int index,
|
2017-06-04 21:00:04 +02:00
|
|
|
BiomeManager *biomemgr, std::unordered_set<u8> *biome_id_list)
|
2015-04-16 10:12:26 +02:00
|
|
|
{
|
|
|
|
if (index < 0)
|
|
|
|
index = lua_gettop(L) + 1 + index;
|
|
|
|
|
|
|
|
if (lua_isnil(L, index))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bool is_single = true;
|
|
|
|
if (lua_istable(L, index)) {
|
|
|
|
lua_getfield(L, index, "name");
|
|
|
|
is_single = !lua_isnil(L, -1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_single) {
|
|
|
|
Biome *biome = get_or_load_biome(L, index, biomemgr);
|
|
|
|
if (!biome) {
|
2017-03-13 14:34:32 +01:00
|
|
|
infostream << "get_biome_list: failed to get biome '"
|
2015-05-29 02:04:40 +02:00
|
|
|
<< (lua_isstring(L, index) ? lua_tostring(L, index) : "")
|
|
|
|
<< "'." << std::endl;
|
2015-04-16 10:12:26 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
biome_id_list->insert(biome->index);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns number of failed resolutions
|
|
|
|
size_t fail_count = 0;
|
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
for (lua_pushnil(L); lua_next(L, index); lua_pop(L, 1)) {
|
|
|
|
count++;
|
|
|
|
Biome *biome = get_or_load_biome(L, -1, biomemgr);
|
|
|
|
if (!biome) {
|
|
|
|
fail_count++;
|
2017-03-13 14:34:32 +01:00
|
|
|
infostream << "get_biome_list: failed to get biome '"
|
2015-05-29 02:04:40 +02:00
|
|
|
<< (lua_isstring(L, -1) ? lua_tostring(L, -1) : "")
|
|
|
|
<< "'" << std::endl;
|
2015-04-16 10:12:26 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
biome_id_list->insert(biome->index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fail_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-09-29 19:38:08 +02:00
|
|
|
// get_biome_id(biomename)
|
|
|
|
// returns the biome id used in biomemap
|
|
|
|
int ModApiMapgen::l_get_biome_id(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-09-29 19:38:08 +02:00
|
|
|
const char *biome_str = lua_tostring(L, 1);
|
|
|
|
if (!biome_str)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;
|
|
|
|
|
|
|
|
if (!bmgr)
|
|
|
|
return 0;
|
|
|
|
|
2015-10-25 05:45:18 +01:00
|
|
|
Biome *biome = (Biome *)bmgr->getByName(biome_str);
|
2015-09-29 19:38:08 +02:00
|
|
|
|
|
|
|
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
lua_pushinteger(L, biome->index);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-28 03:02:48 +02:00
|
|
|
// get_mapgen_object(objectname)
|
2013-08-11 04:09:45 +02:00
|
|
|
// returns the requested object used during map generation
|
|
|
|
int ModApiMapgen::l_get_mapgen_object(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
const char *mgobjstr = lua_tostring(L, 1);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
int mgobjint;
|
|
|
|
if (!string_to_enum(es_MapgenObject, mgobjint, mgobjstr ? mgobjstr : ""))
|
|
|
|
return 0;
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
enum MapgenObject mgobj = (MapgenObject)mgobjint;
|
|
|
|
|
|
|
|
EmergeManager *emerge = getServer(L)->getEmergeManager();
|
|
|
|
Mapgen *mg = emerge->getCurrentMapgen();
|
|
|
|
if (!mg)
|
2015-10-26 04:12:59 +01:00
|
|
|
throw LuaError("Must only be called in a mapgen thread!");
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
size_t maplen = mg->csize.X * mg->csize.Z;
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
switch (mgobj) {
|
2015-04-01 05:27:19 +02:00
|
|
|
case MGOBJ_VMANIP: {
|
|
|
|
MMVManip *vm = mg->vm;
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
// VoxelManip object
|
|
|
|
LuaVoxelManip *o = new LuaVoxelManip(vm, true);
|
|
|
|
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
|
|
|
|
luaL_getmetatable(L, "VoxelManip");
|
|
|
|
lua_setmetatable(L, -2);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
// emerged min pos
|
|
|
|
push_v3s16(L, vm->m_area.MinEdge);
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
// emerged max pos
|
|
|
|
push_v3s16(L, vm->m_area.MaxEdge);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
case MGOBJ_HEIGHTMAP: {
|
|
|
|
if (!mg->heightmap)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
for (size_t i = 0; i != maplen; i++) {
|
|
|
|
lua_pushinteger(L, mg->heightmap[i]);
|
|
|
|
lua_rawseti(L, -2, i + 1);
|
2014-10-28 05:18:53 +01:00
|
|
|
}
|
2013-12-14 07:52:06 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case MGOBJ_BIOMEMAP: {
|
2016-04-28 09:43:09 +02:00
|
|
|
if (!mg->biomegen)
|
2015-04-01 05:27:19 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
for (size_t i = 0; i != maplen; i++) {
|
2016-04-28 09:43:09 +02:00
|
|
|
lua_pushinteger(L, mg->biomegen->biomemap[i]);
|
2015-04-01 05:27:19 +02:00
|
|
|
lua_rawseti(L, -2, i + 1);
|
2014-10-28 05:18:53 +01:00
|
|
|
}
|
2013-12-14 07:52:06 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2015-06-19 01:17:03 +02:00
|
|
|
case MGOBJ_HEATMAP: {
|
2016-04-28 09:43:09 +02:00
|
|
|
if (!mg->biomegen || mg->biomegen->getType() != BIOMEGEN_ORIGINAL)
|
2015-04-01 05:27:19 +02:00
|
|
|
return 0;
|
|
|
|
|
2016-04-28 09:43:09 +02:00
|
|
|
BiomeGenOriginal *bg = (BiomeGenOriginal *)mg->biomegen;
|
|
|
|
|
2015-06-19 01:17:03 +02:00
|
|
|
lua_newtable(L);
|
|
|
|
for (size_t i = 0; i != maplen; i++) {
|
2016-04-28 09:43:09 +02:00
|
|
|
lua_pushnumber(L, bg->heatmap[i]);
|
2015-06-19 01:17:03 +02:00
|
|
|
lua_rawseti(L, -2, i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-06-19 01:17:03 +02:00
|
|
|
case MGOBJ_HUMIDMAP: {
|
2016-04-28 09:43:09 +02:00
|
|
|
if (!mg->biomegen || mg->biomegen->getType() != BIOMEGEN_ORIGINAL)
|
2015-04-01 05:27:19 +02:00
|
|
|
return 0;
|
|
|
|
|
2016-04-28 09:43:09 +02:00
|
|
|
BiomeGenOriginal *bg = (BiomeGenOriginal *)mg->biomegen;
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
lua_newtable(L);
|
|
|
|
for (size_t i = 0; i != maplen; i++) {
|
2016-04-28 09:43:09 +02:00
|
|
|
lua_pushnumber(L, bg->humidmap[i]);
|
2015-04-01 05:27:19 +02:00
|
|
|
lua_rawseti(L, -2, i + 1);
|
2014-10-28 05:18:53 +01:00
|
|
|
}
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case MGOBJ_GENNOTIFY: {
|
|
|
|
std::map<std::string, std::vector<v3s16> >event_map;
|
|
|
|
std::map<std::string, std::vector<v3s16> >::iterator it;
|
2013-12-14 07:52:06 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
mg->gennotify.getEvents(event_map);
|
2013-12-14 07:52:06 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
lua_newtable(L);
|
|
|
|
for (it = event_map.begin(); it != event_map.end(); ++it) {
|
2014-12-06 10:18:04 +01:00
|
|
|
lua_newtable(L);
|
2013-12-14 07:52:06 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
for (size_t j = 0; j != it->second.size(); j++) {
|
|
|
|
push_v3s16(L, it->second[j]);
|
|
|
|
lua_rawseti(L, -2, j + 1);
|
2013-12-14 07:52:06 +01:00
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
lua_setfield(L, -2, it->first.c_str());
|
2014-10-28 05:18:53 +01:00
|
|
|
}
|
2015-04-01 05:27:19 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-12-14 07:52:06 +01:00
|
|
|
return 0;
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2014-12-29 18:58:55 +01:00
|
|
|
int ModApiMapgen::l_get_mapgen_params(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2016-06-25 00:15:56 +02:00
|
|
|
log_deprecated(L, "get_mapgen_params is deprecated; "
|
|
|
|
"use get_mapgen_setting instead");
|
|
|
|
|
|
|
|
std::string value;
|
|
|
|
|
|
|
|
MapSettingsManager *settingsmgr =
|
|
|
|
getServer(L)->getEmergeManager()->map_settings_mgr;
|
2014-12-29 18:58:55 +01:00
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
|
2016-06-25 00:15:56 +02:00
|
|
|
settingsmgr->getMapSetting("mg_name", &value);
|
|
|
|
lua_pushstring(L, value.c_str());
|
2014-12-29 18:58:55 +01:00
|
|
|
lua_setfield(L, -2, "mgname");
|
|
|
|
|
2016-06-25 00:15:56 +02:00
|
|
|
settingsmgr->getMapSetting("seed", &value);
|
|
|
|
std::istringstream ss(value);
|
|
|
|
u64 seed;
|
|
|
|
ss >> seed;
|
|
|
|
lua_pushinteger(L, seed);
|
2014-12-29 18:58:55 +01:00
|
|
|
lua_setfield(L, -2, "seed");
|
|
|
|
|
2016-06-25 00:15:56 +02:00
|
|
|
settingsmgr->getMapSetting("water_level", &value);
|
|
|
|
lua_pushinteger(L, stoi(value, -32768, 32767));
|
2014-12-29 18:58:55 +01:00
|
|
|
lua_setfield(L, -2, "water_level");
|
|
|
|
|
2016-06-25 00:15:56 +02:00
|
|
|
settingsmgr->getMapSetting("chunksize", &value);
|
|
|
|
lua_pushinteger(L, stoi(value, -32768, 32767));
|
2014-12-29 18:58:55 +01:00
|
|
|
lua_setfield(L, -2, "chunksize");
|
|
|
|
|
2016-06-25 00:15:56 +02:00
|
|
|
settingsmgr->getMapSetting("mg_flags", &value);
|
|
|
|
lua_pushstring(L, value.c_str());
|
2014-12-29 18:58:55 +01:00
|
|
|
lua_setfield(L, -2, "flags");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2014-04-28 03:02:48 +02:00
|
|
|
// set_mapgen_params(params)
|
2013-08-11 04:09:45 +02:00
|
|
|
// set mapgen parameters
|
|
|
|
int ModApiMapgen::l_set_mapgen_params(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2016-06-25 00:15:56 +02:00
|
|
|
log_deprecated(L, "set_mapgen_params is deprecated; "
|
|
|
|
"use set_mapgen_setting instead");
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
if (!lua_istable(L, 1))
|
|
|
|
return 0;
|
|
|
|
|
2016-06-25 00:15:56 +02:00
|
|
|
MapSettingsManager *settingsmgr =
|
|
|
|
getServer(L)->getEmergeManager()->map_settings_mgr;
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
lua_getfield(L, 1, "mgname");
|
2016-06-25 00:15:56 +02:00
|
|
|
if (lua_isstring(L, -1))
|
|
|
|
settingsmgr->setMapSetting("mg_name", lua_tostring(L, -1), true);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
lua_getfield(L, 1, "seed");
|
2014-02-04 04:42:10 +01:00
|
|
|
if (lua_isnumber(L, -1))
|
2016-06-25 00:15:56 +02:00
|
|
|
settingsmgr->setMapSetting("seed", lua_tostring(L, -1), true);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
lua_getfield(L, 1, "water_level");
|
2014-02-04 04:42:10 +01:00
|
|
|
if (lua_isnumber(L, -1))
|
2016-06-25 00:15:56 +02:00
|
|
|
settingsmgr->setMapSetting("water_level", lua_tostring(L, -1), true);
|
2014-02-04 04:42:10 +01:00
|
|
|
|
2015-10-04 23:26:08 +02:00
|
|
|
lua_getfield(L, 1, "chunksize");
|
|
|
|
if (lua_isnumber(L, -1))
|
2016-06-25 00:15:56 +02:00
|
|
|
settingsmgr->setMapSetting("chunksize", lua_tostring(L, -1), true);
|
2015-10-04 23:26:08 +02:00
|
|
|
|
2015-01-04 09:21:42 +01:00
|
|
|
warn_if_field_exists(L, 1, "flagmask",
|
|
|
|
"Deprecated: flags field now includes unset flags.");
|
2016-06-25 00:15:56 +02:00
|
|
|
|
|
|
|
lua_getfield(L, 1, "flags");
|
2015-01-04 09:21:42 +01:00
|
|
|
if (lua_isstring(L, -1))
|
2016-06-25 00:15:56 +02:00
|
|
|
settingsmgr->setMapSetting("mg_flags", lua_tostring(L, -1), true);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get_mapgen_setting(name)
|
|
|
|
int ModApiMapgen::l_get_mapgen_setting(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2016-06-25 00:15:56 +02:00
|
|
|
std::string value;
|
|
|
|
MapSettingsManager *settingsmgr =
|
|
|
|
getServer(L)->getEmergeManager()->map_settings_mgr;
|
|
|
|
|
|
|
|
const char *name = luaL_checkstring(L, 1);
|
|
|
|
if (!settingsmgr->getMapSetting(name, &value))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
lua_pushstring(L, value.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get_mapgen_setting_noiseparams(name)
|
|
|
|
int ModApiMapgen::l_get_mapgen_setting_noiseparams(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
|
|
|
NoiseParams np;
|
|
|
|
MapSettingsManager *settingsmgr =
|
|
|
|
getServer(L)->getEmergeManager()->map_settings_mgr;
|
|
|
|
|
|
|
|
const char *name = luaL_checkstring(L, 1);
|
|
|
|
if (!settingsmgr->getMapSettingNoiseParams(name, &np))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
push_noiseparams(L, &np);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set_mapgen_setting(name, value, override_meta)
|
|
|
|
// set mapgen config values
|
|
|
|
int ModApiMapgen::l_set_mapgen_setting(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
|
|
|
MapSettingsManager *settingsmgr =
|
|
|
|
getServer(L)->getEmergeManager()->map_settings_mgr;
|
|
|
|
|
|
|
|
const char *name = luaL_checkstring(L, 1);
|
|
|
|
const char *value = luaL_checkstring(L, 2);
|
2017-08-20 19:37:29 +02:00
|
|
|
bool override_meta = lua_isboolean(L, 3) && lua_toboolean(L, 3);
|
2016-06-25 00:15:56 +02:00
|
|
|
|
|
|
|
if (!settingsmgr->setMapSetting(name, value, override_meta)) {
|
|
|
|
errorstream << "set_mapgen_setting: cannot set '"
|
|
|
|
<< name << "' after initialization" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// set_mapgen_setting_noiseparams(name, noiseparams, set_default)
|
|
|
|
// set mapgen config values for noise parameters
|
|
|
|
int ModApiMapgen::l_set_mapgen_setting_noiseparams(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
|
|
|
MapSettingsManager *settingsmgr =
|
|
|
|
getServer(L)->getEmergeManager()->map_settings_mgr;
|
|
|
|
|
|
|
|
const char *name = luaL_checkstring(L, 1);
|
|
|
|
|
|
|
|
NoiseParams np;
|
|
|
|
if (!read_noiseparams(L, 2, &np)) {
|
|
|
|
errorstream << "set_mapgen_setting_noiseparams: cannot set '" << name
|
|
|
|
<< "'; invalid noiseparams table" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-20 19:37:29 +02:00
|
|
|
bool override_meta = lua_isboolean(L, 3) && lua_toboolean(L, 3);
|
2016-06-25 00:15:56 +02:00
|
|
|
|
|
|
|
if (!settingsmgr->setMapSettingNoiseParams(name, &np, override_meta)) {
|
|
|
|
errorstream << "set_mapgen_setting_noiseparams: cannot set '"
|
|
|
|
<< name << "' after initialization" << std::endl;
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2014-12-10 05:44:04 +01:00
|
|
|
// set_noiseparams(name, noiseparams, set_default)
|
|
|
|
// set global config values for noise parameters
|
|
|
|
int ModApiMapgen::l_set_noiseparams(lua_State *L)
|
2014-02-16 00:20:15 +01:00
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2014-12-10 05:44:04 +01:00
|
|
|
const char *name = luaL_checkstring(L, 1);
|
2014-02-16 00:20:15 +01:00
|
|
|
|
2014-12-10 05:44:04 +01:00
|
|
|
NoiseParams np;
|
2016-06-25 00:15:56 +02:00
|
|
|
if (!read_noiseparams(L, 2, &np)) {
|
|
|
|
errorstream << "set_noiseparams: cannot set '" << name
|
|
|
|
<< "'; invalid noiseparams table" << std::endl;
|
2014-02-16 00:20:15 +01:00
|
|
|
return 0;
|
2016-06-25 00:15:56 +02:00
|
|
|
}
|
2014-02-16 00:20:15 +01:00
|
|
|
|
2017-08-20 19:37:29 +02:00
|
|
|
bool set_default = !lua_isboolean(L, 3) || lua_toboolean(L, 3);
|
2014-12-10 05:44:04 +01:00
|
|
|
|
|
|
|
g_settings->setNoiseParams(name, np, set_default);
|
2014-02-16 00:20:15 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-05-26 14:10:08 +02:00
|
|
|
// get_noiseparams(name)
|
|
|
|
int ModApiMapgen::l_get_noiseparams(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-05-26 14:10:08 +02:00
|
|
|
std::string name = luaL_checkstring(L, 1);
|
|
|
|
|
|
|
|
NoiseParams np;
|
|
|
|
if (!g_settings->getNoiseParams(name, np))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
push_noiseparams(L, &np);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-06 10:18:04 +01:00
|
|
|
// set_gen_notify(flags, {deco_id_table})
|
2013-12-14 07:52:06 +01:00
|
|
|
int ModApiMapgen::l_set_gen_notify(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2014-03-08 17:34:46 +01:00
|
|
|
u32 flags = 0, flagmask = 0;
|
2014-12-06 10:18:04 +01:00
|
|
|
EmergeManager *emerge = getServer(L)->getEmergeManager();
|
2014-03-08 17:34:46 +01:00
|
|
|
|
|
|
|
if (read_flags(L, 1, flagdesc_gennotify, &flags, &flagmask)) {
|
2014-12-06 10:18:04 +01:00
|
|
|
emerge->gen_notify_on &= ~flagmask;
|
|
|
|
emerge->gen_notify_on |= flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lua_istable(L, 2)) {
|
|
|
|
lua_pushnil(L);
|
|
|
|
while (lua_next(L, 2)) {
|
|
|
|
if (lua_isnumber(L, -1))
|
2015-07-22 10:11:34 +02:00
|
|
|
emerge->gen_notify_on_deco_ids.insert((u32)lua_tonumber(L, -1));
|
2014-12-06 10:18:04 +01:00
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
2013-12-14 07:52:06 +01:00
|
|
|
}
|
2014-03-08 17:34:46 +01:00
|
|
|
|
2013-12-14 07:52:06 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-05-26 14:10:08 +02:00
|
|
|
// get_gen_notify()
|
|
|
|
int ModApiMapgen::l_get_gen_notify(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-05-26 14:10:08 +02:00
|
|
|
EmergeManager *emerge = getServer(L)->getEmergeManager();
|
|
|
|
push_flags_string(L, flagdesc_gennotify, emerge->gen_notify_on,
|
|
|
|
emerge->gen_notify_on);
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
int i = 1;
|
2017-08-20 13:30:50 +02:00
|
|
|
for (u32 gen_notify_on_deco_id : emerge->gen_notify_on_deco_ids) {
|
|
|
|
lua_pushnumber(L, gen_notify_on_deco_id);
|
2015-05-26 14:10:08 +02:00
|
|
|
lua_rawseti(L, -2, i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
// register_biome({lots of stuff})
|
|
|
|
int ModApiMapgen::l_register_biome(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
int index = 1;
|
|
|
|
luaL_checktype(L, index, LUA_TTABLE);
|
|
|
|
|
2014-12-17 09:20:17 +01:00
|
|
|
INodeDefManager *ndef = getServer(L)->getNodeDefManager();
|
|
|
|
BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
Biome *biome = read_biome_def(L, index, ndef);
|
|
|
|
if (!biome)
|
|
|
|
return 0;
|
2014-10-28 05:18:53 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
ObjDefHandle handle = bmgr->add(biome);
|
2015-03-31 05:40:35 +02:00
|
|
|
if (handle == OBJDEF_INVALID_HANDLE) {
|
2015-04-01 05:27:19 +02:00
|
|
|
delete biome;
|
2014-10-28 05:18:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
lua_pushinteger(L, handle);
|
2014-11-13 05:01:13 +01:00
|
|
|
return 1;
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
// register_decoration({lots of stuff})
|
|
|
|
int ModApiMapgen::l_register_decoration(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
int index = 1;
|
|
|
|
luaL_checktype(L, index, LUA_TTABLE);
|
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
INodeDefManager *ndef = getServer(L)->getNodeDefManager();
|
|
|
|
DecorationManager *decomgr = getServer(L)->getEmergeManager()->decomgr;
|
|
|
|
BiomeManager *biomemgr = getServer(L)->getEmergeManager()->biomemgr;
|
2015-03-24 03:10:59 +01:00
|
|
|
SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;
|
2013-08-11 04:09:45 +02:00
|
|
|
|
|
|
|
enum DecorationType decotype = (DecorationType)getenumfield(L, index,
|
2014-10-29 06:54:11 +01:00
|
|
|
"deco_type", es_DecorationType, -1);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
Decoration *deco = decomgr->create(decotype);
|
2013-08-11 04:09:45 +02:00
|
|
|
if (!deco) {
|
|
|
|
errorstream << "register_decoration: decoration placement type "
|
2015-04-01 05:27:19 +02:00
|
|
|
<< decotype << " not implemented" << std::endl;
|
2013-08-11 04:09:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2014-12-06 10:18:04 +01:00
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
deco->name = getstringfield_default(L, index, "name", "");
|
2014-10-08 21:28:14 +02:00
|
|
|
deco->fill_ratio = getfloatfield_default(L, index, "fill_ratio", 0.02);
|
2014-12-30 07:48:20 +01:00
|
|
|
deco->y_min = getintfield_default(L, index, "y_min", -31000);
|
|
|
|
deco->y_max = getintfield_default(L, index, "y_max", 31000);
|
2016-09-12 00:34:43 +02:00
|
|
|
deco->nspawnby = getintfield_default(L, index, "num_spawn_by", -1);
|
2014-10-08 21:28:14 +02:00
|
|
|
deco->sidelen = getintfield_default(L, index, "sidelen", 8);
|
2013-08-11 04:09:45 +02:00
|
|
|
if (deco->sidelen <= 0) {
|
|
|
|
errorstream << "register_decoration: sidelen must be "
|
|
|
|
"greater than 0" << std::endl;
|
|
|
|
delete deco;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2014-10-08 21:28:14 +02:00
|
|
|
//// Get node name(s) to place decoration on
|
2015-04-16 10:12:26 +02:00
|
|
|
size_t nread = getstringlistfield(L, index, "place_on", &deco->m_nodenames);
|
|
|
|
deco->m_nnlistsizes.push_back(nread);
|
2014-10-08 21:28:14 +02:00
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
//// Get decoration flags
|
2014-12-10 06:56:44 +01:00
|
|
|
getflagsfield(L, index, "flags", flagdesc_deco, &deco->flags, NULL);
|
|
|
|
|
2014-10-08 21:28:14 +02:00
|
|
|
//// Get NoiseParams to define how decoration is placed
|
2013-08-11 04:09:45 +02:00
|
|
|
lua_getfield(L, index, "noise_params");
|
2014-12-10 06:56:44 +01:00
|
|
|
if (read_noiseparams(L, -1, &deco->np))
|
|
|
|
deco->flags |= DECO_USE_NOISE;
|
2013-08-11 04:09:45 +02:00
|
|
|
lua_pop(L, 1);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2014-10-08 21:28:14 +02:00
|
|
|
//// Get biomes associated with this decoration (if any)
|
2015-04-01 05:27:19 +02:00
|
|
|
lua_getfield(L, index, "biomes");
|
|
|
|
if (get_biome_list(L, -1, biomemgr, &deco->biomes))
|
2017-03-13 14:34:32 +01:00
|
|
|
infostream << "register_decoration: couldn't get all biomes " << std::endl;
|
2015-04-01 05:27:19 +02:00
|
|
|
lua_pop(L, 1);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2016-09-12 00:34:43 +02:00
|
|
|
//// Get node name(s) to 'spawn by'
|
|
|
|
size_t nnames = getstringlistfield(L, index, "spawn_by", &deco->m_nodenames);
|
|
|
|
deco->m_nnlistsizes.push_back(nnames);
|
|
|
|
if (nnames == 0 && deco->nspawnby != -1) {
|
|
|
|
errorstream << "register_decoration: no spawn_by nodes defined,"
|
|
|
|
" but num_spawn_by specified" << std::endl;
|
|
|
|
}
|
|
|
|
|
2014-10-08 21:28:14 +02:00
|
|
|
//// Handle decoration type-specific parameters
|
2014-10-29 06:54:11 +01:00
|
|
|
bool success = false;
|
2013-08-11 04:09:45 +02:00
|
|
|
switch (decotype) {
|
2015-03-31 05:40:35 +02:00
|
|
|
case DECO_SIMPLE:
|
2015-04-16 10:12:26 +02:00
|
|
|
success = read_deco_simple(L, (DecoSimple *)deco);
|
2015-03-31 05:40:35 +02:00
|
|
|
break;
|
|
|
|
case DECO_SCHEMATIC:
|
2015-04-01 05:27:19 +02:00
|
|
|
success = read_deco_schematic(L, schemmgr, (DecoSchematic *)deco);
|
2015-03-31 05:40:35 +02:00
|
|
|
break;
|
|
|
|
case DECO_LSYSTEM:
|
|
|
|
break;
|
2014-10-29 06:54:11 +01:00
|
|
|
}
|
2014-10-08 21:28:14 +02:00
|
|
|
|
2014-10-29 06:54:11 +01:00
|
|
|
if (!success) {
|
|
|
|
delete deco;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2015-05-07 08:34:15 +02:00
|
|
|
ndef->pendNodeResolve(deco);
|
2015-04-16 10:12:26 +02:00
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
ObjDefHandle handle = decomgr->add(deco);
|
|
|
|
if (handle == OBJDEF_INVALID_HANDLE) {
|
2014-11-13 05:01:13 +01:00
|
|
|
delete deco;
|
|
|
|
return 0;
|
|
|
|
}
|
2014-10-08 21:28:14 +02:00
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
lua_pushinteger(L, handle);
|
2014-11-13 05:01:13 +01:00
|
|
|
return 1;
|
2014-10-29 06:54:11 +01:00
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
bool read_deco_simple(lua_State *L, DecoSimple *deco)
|
2014-10-29 06:54:11 +01:00
|
|
|
{
|
|
|
|
int index = 1;
|
2016-12-07 07:08:16 +01:00
|
|
|
int param2;
|
2014-10-08 21:28:14 +02:00
|
|
|
|
2014-10-29 06:54:11 +01:00
|
|
|
deco->deco_height = getintfield_default(L, index, "height", 1);
|
|
|
|
deco->deco_height_max = getintfield_default(L, index, "height_max", 0);
|
2014-10-08 21:28:14 +02:00
|
|
|
|
2014-10-29 06:54:11 +01:00
|
|
|
if (deco->deco_height <= 0) {
|
|
|
|
errorstream << "register_decoration: simple decoration height"
|
|
|
|
" must be greater than 0" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-08 17:34:46 +01:00
|
|
|
|
2016-09-12 00:34:43 +02:00
|
|
|
size_t nnames = getstringlistfield(L, index, "decoration", &deco->m_nodenames);
|
2015-04-16 10:12:26 +02:00
|
|
|
deco->m_nnlistsizes.push_back(nnames);
|
|
|
|
if (nnames == 0) {
|
2014-10-29 06:54:11 +01:00
|
|
|
errorstream << "register_decoration: no decoration nodes "
|
|
|
|
"defined" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-08 17:34:46 +01:00
|
|
|
|
2016-12-07 07:08:16 +01:00
|
|
|
param2 = getintfield_default(L, index, "param2", 0);
|
|
|
|
if ((param2 < 0) || (param2 > 255)) {
|
2016-12-07 01:39:33 +01:00
|
|
|
errorstream << "register_decoration: param2 out of bounds (0-255)"
|
|
|
|
<< std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-07 07:08:16 +01:00
|
|
|
deco->deco_param2 = (u8)param2;
|
2016-12-07 01:39:33 +01:00
|
|
|
|
2014-10-29 06:54:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
|
|
|
bool read_deco_schematic(lua_State *L, SchematicManager *schemmgr, DecoSchematic *deco)
|
2014-10-29 06:54:11 +01:00
|
|
|
{
|
|
|
|
int index = 1;
|
2014-10-08 21:28:14 +02:00
|
|
|
|
2014-10-29 06:54:11 +01:00
|
|
|
deco->rotation = (Rotation)getenumfield(L, index, "rotation",
|
2015-04-01 05:27:19 +02:00
|
|
|
ModApiMapgen::es_Rotation, ROTATE_0);
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
StringMap replace_names;
|
2014-10-29 06:54:11 +01:00
|
|
|
lua_getfield(L, index, "replacements");
|
|
|
|
if (lua_istable(L, -1))
|
2015-03-31 05:40:35 +02:00
|
|
|
read_schematic_replacements(L, -1, &replace_names);
|
2014-10-29 06:54:11 +01:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
lua_getfield(L, index, "schematic");
|
2015-04-01 05:27:19 +02:00
|
|
|
Schematic *schem = get_or_load_schematic(L, -1, schemmgr, &replace_names);
|
2014-10-30 21:23:48 +01:00
|
|
|
lua_pop(L, 1);
|
2014-10-29 06:54:11 +01:00
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
deco->schematic = schem;
|
2015-03-24 03:10:59 +01:00
|
|
|
return schem != NULL;
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
// register_ore({lots of stuff})
|
|
|
|
int ModApiMapgen::l_register_ore(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
int index = 1;
|
|
|
|
luaL_checktype(L, index, LUA_TTABLE);
|
|
|
|
|
2014-12-17 09:20:17 +01:00
|
|
|
INodeDefManager *ndef = getServer(L)->getNodeDefManager();
|
2015-04-21 02:25:33 +02:00
|
|
|
BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;
|
2014-12-17 09:20:17 +01:00
|
|
|
OreManager *oremgr = getServer(L)->getEmergeManager()->oremgr;
|
2013-08-11 04:09:45 +02:00
|
|
|
|
|
|
|
enum OreType oretype = (OreType)getenumfield(L, index,
|
2015-04-01 05:27:19 +02:00
|
|
|
"ore_type", es_OreType, ORE_SCATTER);
|
2014-11-13 05:01:13 +01:00
|
|
|
Ore *ore = oremgr->create(oretype);
|
2013-08-11 04:09:45 +02:00
|
|
|
if (!ore) {
|
2015-09-16 03:28:16 +02:00
|
|
|
errorstream << "register_ore: ore_type " << oretype << " not implemented\n";
|
2013-08-11 04:09:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
ore->name = getstringfield_default(L, index, "name", "");
|
2013-08-11 04:09:45 +02:00
|
|
|
ore->ore_param2 = (u8)getintfield_default(L, index, "ore_param2", 0);
|
|
|
|
ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1);
|
|
|
|
ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 1);
|
|
|
|
ore->clust_size = getintfield_default(L, index, "clust_size", 0);
|
2014-10-28 05:18:53 +01:00
|
|
|
ore->noise = NULL;
|
2014-03-08 17:34:46 +01:00
|
|
|
ore->flags = 0;
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2015-12-05 14:00:11 +01:00
|
|
|
//// Get noise_threshold
|
|
|
|
warn_if_field_exists(L, index, "noise_threshhold",
|
|
|
|
"Deprecated: new name is \"noise_threshold\".");
|
|
|
|
|
2015-12-07 09:42:39 +01:00
|
|
|
float nthresh;
|
|
|
|
if (!getfloatfield(L, index, "noise_threshold", nthresh) &&
|
|
|
|
!getfloatfield(L, index, "noise_threshhold", nthresh))
|
2015-12-05 14:00:11 +01:00
|
|
|
nthresh = 0;
|
|
|
|
ore->nthresh = nthresh;
|
|
|
|
|
2015-04-21 02:25:33 +02:00
|
|
|
//// Get y_min/y_max
|
2015-01-04 09:21:42 +01:00
|
|
|
warn_if_field_exists(L, index, "height_min",
|
|
|
|
"Deprecated: new name is \"y_min\".");
|
|
|
|
warn_if_field_exists(L, index, "height_max",
|
|
|
|
"Deprecated: new name is \"y_max\".");
|
|
|
|
|
2014-12-30 07:48:20 +01:00
|
|
|
int ymin, ymax;
|
|
|
|
if (!getintfield(L, index, "y_min", ymin) &&
|
|
|
|
!getintfield(L, index, "height_min", ymin))
|
|
|
|
ymin = -31000;
|
|
|
|
if (!getintfield(L, index, "y_max", ymax) &&
|
|
|
|
!getintfield(L, index, "height_max", ymax))
|
|
|
|
ymax = 31000;
|
|
|
|
ore->y_min = ymin;
|
|
|
|
ore->y_max = ymax;
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
if (ore->clust_scarcity <= 0 || ore->clust_num_ores <= 0) {
|
|
|
|
errorstream << "register_ore: clust_scarcity and clust_num_ores"
|
|
|
|
"must be greater than 0" << std::endl;
|
|
|
|
delete ore;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-21 02:25:33 +02:00
|
|
|
//// Get flags
|
2014-10-28 05:18:53 +01:00
|
|
|
getflagsfield(L, index, "flags", flagdesc_ore, &ore->flags, NULL);
|
|
|
|
|
2015-04-21 02:25:33 +02:00
|
|
|
//// Get biomes associated with this decoration (if any)
|
|
|
|
lua_getfield(L, index, "biomes");
|
|
|
|
if (get_biome_list(L, -1, bmgr, &ore->biomes))
|
2017-03-13 14:34:32 +01:00
|
|
|
infostream << "register_ore: couldn't get all biomes " << std::endl;
|
2015-04-21 02:25:33 +02:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
//// Get noise parameters if needed
|
2014-10-28 05:18:53 +01:00
|
|
|
lua_getfield(L, index, "noise_params");
|
2014-12-10 06:37:09 +01:00
|
|
|
if (read_noiseparams(L, -1, &ore->np)) {
|
|
|
|
ore->flags |= OREFLAG_USE_NOISE;
|
|
|
|
} else if (ore->NEEDS_NOISE) {
|
|
|
|
errorstream << "register_ore: specified ore type requires valid "
|
|
|
|
"noise parameters" << std::endl;
|
|
|
|
delete ore;
|
|
|
|
return 0;
|
|
|
|
}
|
2014-10-28 05:18:53 +01:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
2015-09-13 06:09:00 +02:00
|
|
|
//// Get type-specific parameters
|
2015-09-16 03:28:16 +02:00
|
|
|
switch (oretype) {
|
|
|
|
case ORE_SHEET: {
|
|
|
|
OreSheet *oresheet = (OreSheet *)ore;
|
|
|
|
|
|
|
|
oresheet->column_height_min = getintfield_default(L, index,
|
|
|
|
"column_height_min", 1);
|
|
|
|
oresheet->column_height_max = getintfield_default(L, index,
|
|
|
|
"column_height_max", ore->clust_size);
|
|
|
|
oresheet->column_midpoint_factor = getfloatfield_default(L, index,
|
|
|
|
"column_midpoint_factor", 0.5f);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ORE_PUFF: {
|
|
|
|
OrePuff *orepuff = (OrePuff *)ore;
|
|
|
|
|
|
|
|
lua_getfield(L, index, "np_puff_top");
|
|
|
|
read_noiseparams(L, -1, &orepuff->np_puff_top);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
lua_getfield(L, index, "np_puff_bottom");
|
|
|
|
read_noiseparams(L, -1, &orepuff->np_puff_bottom);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ORE_VEIN: {
|
|
|
|
OreVein *orevein = (OreVein *)ore;
|
|
|
|
|
|
|
|
orevein->random_factor = getfloatfield_default(L, index,
|
|
|
|
"random_factor", 1.f);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2014-12-29 03:17:12 +01:00
|
|
|
}
|
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
ObjDefHandle handle = oremgr->add(ore);
|
|
|
|
if (handle == OBJDEF_INVALID_HANDLE) {
|
2014-11-13 05:01:13 +01:00
|
|
|
delete ore;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
ore->m_nodenames.push_back(getstringfield_default(L, index, "ore", ""));
|
2014-12-17 09:20:17 +01:00
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
size_t nnames = getstringlistfield(L, index, "wherein", &ore->m_nodenames);
|
|
|
|
ore->m_nnlistsizes.push_back(nnames);
|
2014-12-17 09:20:17 +01:00
|
|
|
|
2015-05-07 08:34:15 +02:00
|
|
|
ndef->pendNodeResolve(ore);
|
2014-10-28 05:18:53 +01:00
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
lua_pushinteger(L, handle);
|
2014-11-13 05:01:13 +01:00
|
|
|
return 1;
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
// register_schematic({schematic}, replacements={})
|
|
|
|
int ModApiMapgen::l_register_schematic(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;
|
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
StringMap replace_names;
|
2015-03-24 03:10:59 +01:00
|
|
|
if (lua_istable(L, 2))
|
2015-03-31 05:40:35 +02:00
|
|
|
read_schematic_replacements(L, 2, &replace_names);
|
2015-03-24 03:10:59 +01:00
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
Schematic *schem = load_schematic(L, 1, schemmgr->getNodeDef(),
|
2015-05-07 08:34:15 +02:00
|
|
|
&replace_names);
|
2015-03-24 03:10:59 +01:00
|
|
|
if (!schem)
|
|
|
|
return 0;
|
2015-03-31 05:40:35 +02:00
|
|
|
|
|
|
|
ObjDefHandle handle = schemmgr->add(schem);
|
|
|
|
if (handle == OBJDEF_INVALID_HANDLE) {
|
|
|
|
delete schem;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_pushinteger(L, handle);
|
2015-03-24 03:10:59 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
// clear_registered_biomes()
|
|
|
|
int ModApiMapgen::l_clear_registered_biomes(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;
|
|
|
|
bmgr->clear();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
// clear_registered_decorations()
|
|
|
|
int ModApiMapgen::l_clear_registered_decorations(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
DecorationManager *dmgr = getServer(L)->getEmergeManager()->decomgr;
|
|
|
|
dmgr->clear();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
// clear_registered_ores()
|
|
|
|
int ModApiMapgen::l_clear_registered_ores(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
OreManager *omgr = getServer(L)->getEmergeManager()->oremgr;
|
|
|
|
omgr->clear();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
// clear_registered_schematics()
|
|
|
|
int ModApiMapgen::l_clear_registered_schematics(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
SchematicManager *smgr = getServer(L)->getEmergeManager()->schemmgr;
|
|
|
|
smgr->clear();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
// generate_ores(vm, p1, p2, [ore_id])
|
|
|
|
int ModApiMapgen::l_generate_ores(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
EmergeManager *emerge = getServer(L)->getEmergeManager();
|
|
|
|
|
|
|
|
Mapgen mg;
|
2016-06-25 00:15:56 +02:00
|
|
|
mg.seed = emerge->mgparams->seed;
|
2015-03-24 03:10:59 +01:00
|
|
|
mg.vm = LuaVoxelManip::checkobject(L, 1)->vm;
|
|
|
|
mg.ndef = getServer(L)->getNodeDefManager();
|
|
|
|
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 pmin = lua_istable(L, 2) ? check_v3s16(L, 2) :
|
2015-03-22 22:03:19 +01:00
|
|
|
mg.vm->m_area.MinEdge + v3s16(1,1,1) * MAP_BLOCKSIZE;
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 pmax = lua_istable(L, 3) ? check_v3s16(L, 3) :
|
2015-03-22 22:03:19 +01:00
|
|
|
mg.vm->m_area.MaxEdge - v3s16(1,1,1) * MAP_BLOCKSIZE;
|
|
|
|
sortBoxVerticies(pmin, pmax);
|
2015-03-24 03:10:59 +01:00
|
|
|
|
2015-03-22 22:03:19 +01:00
|
|
|
u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed);
|
2015-03-24 03:10:59 +01:00
|
|
|
|
|
|
|
emerge->oremgr->placeAllOres(&mg, blockseed, pmin, pmax);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
// generate_decorations(vm, p1, p2, [deco_id])
|
|
|
|
int ModApiMapgen::l_generate_decorations(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-03-24 03:10:59 +01:00
|
|
|
EmergeManager *emerge = getServer(L)->getEmergeManager();
|
|
|
|
|
|
|
|
Mapgen mg;
|
2016-06-25 00:15:56 +02:00
|
|
|
mg.seed = emerge->mgparams->seed;
|
2015-03-24 03:10:59 +01:00
|
|
|
mg.vm = LuaVoxelManip::checkobject(L, 1)->vm;
|
|
|
|
mg.ndef = getServer(L)->getNodeDefManager();
|
|
|
|
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 pmin = lua_istable(L, 2) ? check_v3s16(L, 2) :
|
2015-03-22 22:03:19 +01:00
|
|
|
mg.vm->m_area.MinEdge + v3s16(1,1,1) * MAP_BLOCKSIZE;
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 pmax = lua_istable(L, 3) ? check_v3s16(L, 3) :
|
2015-03-22 22:03:19 +01:00
|
|
|
mg.vm->m_area.MaxEdge - v3s16(1,1,1) * MAP_BLOCKSIZE;
|
|
|
|
sortBoxVerticies(pmin, pmax);
|
2015-03-24 03:10:59 +01:00
|
|
|
|
2015-03-22 22:03:19 +01:00
|
|
|
u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed);
|
2015-03-24 03:10:59 +01:00
|
|
|
|
|
|
|
emerge->decomgr->placeAllDecos(&mg, blockseed, pmin, pmax);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
// create_schematic(p1, p2, probability_list, filename, y_slice_prob_list)
|
2013-08-11 04:09:45 +02:00
|
|
|
int ModApiMapgen::l_create_schematic(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-05-08 06:05:08 +02:00
|
|
|
INodeDefManager *ndef = getServer(L)->getNodeDefManager();
|
2014-09-06 02:08:51 +02:00
|
|
|
|
|
|
|
const char *filename = luaL_checkstring(L, 4);
|
2016-12-05 20:59:15 +01:00
|
|
|
CHECK_SECURE_PATH(L, filename, true);
|
2014-09-06 02:08:51 +02:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
Map *map = &(getEnv(L)->getMap());
|
2015-05-08 06:05:08 +02:00
|
|
|
Schematic schem;
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 p1 = check_v3s16(L, 1);
|
|
|
|
v3s16 p2 = check_v3s16(L, 2);
|
2013-08-11 04:09:45 +02:00
|
|
|
sortBoxVerticies(p1, p2);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-12-01 07:23:39 +01:00
|
|
|
std::vector<std::pair<v3s16, u8> > prob_list;
|
2013-08-11 04:09:45 +02:00
|
|
|
if (lua_istable(L, 3)) {
|
|
|
|
lua_pushnil(L);
|
|
|
|
while (lua_next(L, 3)) {
|
|
|
|
if (lua_istable(L, -1)) {
|
|
|
|
lua_getfield(L, -1, "pos");
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 pos = check_v3s16(L, -1);
|
2013-08-11 04:09:45 +02:00
|
|
|
lua_pop(L, 1);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-09-17 05:52:42 +02:00
|
|
|
u8 prob = getintfield_default(L, -1, "prob", MTSCHEM_PROB_ALWAYS);
|
2017-08-20 13:30:50 +02:00
|
|
|
prob_list.emplace_back(pos, prob);
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
}
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2013-12-01 07:23:39 +01:00
|
|
|
std::vector<std::pair<s16, u8> > slice_prob_list;
|
|
|
|
if (lua_istable(L, 5)) {
|
|
|
|
lua_pushnil(L);
|
|
|
|
while (lua_next(L, 5)) {
|
|
|
|
if (lua_istable(L, -1)) {
|
|
|
|
s16 ypos = getintfield_default(L, -1, "ypos", 0);
|
|
|
|
u8 prob = getintfield_default(L, -1, "prob", MTSCHEM_PROB_ALWAYS);
|
2017-08-20 13:30:50 +02:00
|
|
|
slice_prob_list.emplace_back(ypos, prob);
|
2013-12-01 07:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
if (!schem.getSchematicFromMap(map, p1, p2)) {
|
2013-08-11 04:09:45 +02:00
|
|
|
errorstream << "create_schematic: failed to get schematic "
|
|
|
|
"from map" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-01 07:23:39 +01:00
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
schem.applyProbabilities(p1, &prob_list, &slice_prob_list);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2015-05-08 06:05:08 +02:00
|
|
|
schem.saveSchematicToFile(filename, ndef);
|
2013-08-11 04:09:45 +02:00
|
|
|
actionstream << "create_schematic: saved schematic file '"
|
2014-11-13 05:01:13 +01:00
|
|
|
<< filename << "'." << std::endl;
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
lua_pushboolean(L, true);
|
2013-08-11 04:09:45 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
// place_schematic(p, schematic, rotation, replacement)
|
|
|
|
int ModApiMapgen::l_place_schematic(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
MAP_LOCK_REQUIRED;
|
|
|
|
|
2016-12-10 19:02:44 +01:00
|
|
|
GET_ENV_PTR;
|
|
|
|
|
|
|
|
ServerMap *map = &(env->getServerMap());
|
2015-03-24 03:10:59 +01:00
|
|
|
SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
//// Read position
|
2015-04-17 07:03:13 +02:00
|
|
|
v3s16 p = check_v3s16(L, 1);
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
//// Read rotation
|
2013-11-17 08:22:24 +01:00
|
|
|
int rot = ROTATE_0;
|
2015-04-12 22:40:50 +02:00
|
|
|
const char *enumstr = lua_tostring(L, 3);
|
|
|
|
if (enumstr)
|
|
|
|
string_to_enum(es_Rotation, rot, std::string(enumstr));
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
//// Read force placement
|
|
|
|
bool force_placement = true;
|
|
|
|
if (lua_isboolean(L, 5))
|
|
|
|
force_placement = lua_toboolean(L, 5);
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
//// Read node replacements
|
2015-03-31 05:40:35 +02:00
|
|
|
StringMap replace_names;
|
2014-10-08 21:28:14 +02:00
|
|
|
if (lua_istable(L, 4))
|
2015-03-31 05:40:35 +02:00
|
|
|
read_schematic_replacements(L, 4, &replace_names);
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2014-11-13 05:01:13 +01:00
|
|
|
//// Read schematic
|
2015-04-01 05:27:19 +02:00
|
|
|
Schematic *schem = get_or_load_schematic(L, 2, schemmgr, &replace_names);
|
2015-03-24 03:10:59 +01:00
|
|
|
if (!schem) {
|
2014-11-13 05:01:13 +01:00
|
|
|
errorstream << "place_schematic: failed to get schematic" << std::endl;
|
|
|
|
return 0;
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
2013-12-08 07:37:41 +01:00
|
|
|
|
2015-11-04 09:33:12 +01:00
|
|
|
schem->placeOnMap(map, p, 0, (Rotation)rot, force_placement);
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2015-03-31 05:40:35 +02:00
|
|
|
lua_pushboolean(L, true);
|
2013-08-11 04:09:45 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-11-04 09:33:12 +01:00
|
|
|
int ModApiMapgen::l_place_schematic_on_vmanip(lua_State *L)
|
|
|
|
{
|
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
|
|
|
SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;
|
|
|
|
|
|
|
|
//// Read VoxelManip object
|
|
|
|
MMVManip *vm = LuaVoxelManip::checkobject(L, 1)->vm;
|
|
|
|
|
|
|
|
//// Read position
|
|
|
|
v3s16 p = check_v3s16(L, 2);
|
|
|
|
|
|
|
|
//// Read rotation
|
|
|
|
int rot = ROTATE_0;
|
|
|
|
const char *enumstr = lua_tostring(L, 4);
|
|
|
|
if (enumstr)
|
|
|
|
string_to_enum(es_Rotation, rot, std::string(enumstr));
|
|
|
|
|
|
|
|
//// Read force placement
|
|
|
|
bool force_placement = true;
|
|
|
|
if (lua_isboolean(L, 6))
|
|
|
|
force_placement = lua_toboolean(L, 6);
|
|
|
|
|
|
|
|
//// Read node replacements
|
|
|
|
StringMap replace_names;
|
|
|
|
if (lua_istable(L, 5))
|
|
|
|
read_schematic_replacements(L, 5, &replace_names);
|
|
|
|
|
|
|
|
//// Read schematic
|
|
|
|
Schematic *schem = get_or_load_schematic(L, 3, schemmgr, &replace_names);
|
|
|
|
if (!schem) {
|
|
|
|
errorstream << "place_schematic: failed to get schematic" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool schematic_did_fit = schem->placeOnVManip(
|
|
|
|
vm, p, 0, (Rotation)rot, force_placement);
|
|
|
|
|
|
|
|
lua_pushboolean(L, schematic_did_fit);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-16 10:12:26 +02:00
|
|
|
// serialize_schematic(schematic, format, options={...})
|
2015-04-12 22:40:50 +02:00
|
|
|
int ModApiMapgen::l_serialize_schematic(lua_State *L)
|
|
|
|
{
|
2015-10-25 05:45:18 +01:00
|
|
|
NO_MAP_LOCK_REQUIRED;
|
|
|
|
|
2015-04-12 22:40:50 +02:00
|
|
|
SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr;
|
2015-04-16 10:12:26 +02:00
|
|
|
|
|
|
|
//// Read options
|
2015-05-07 08:54:30 +02:00
|
|
|
bool use_comments = getboolfield_default(L, 3, "lua_use_comments", false);
|
|
|
|
u32 indent_spaces = getintfield_default(L, 3, "lua_num_indent_spaces", 0);
|
2015-04-12 22:40:50 +02:00
|
|
|
|
2015-05-07 08:34:15 +02:00
|
|
|
//// Get schematic
|
|
|
|
bool was_loaded = false;
|
|
|
|
Schematic *schem = (Schematic *)get_objdef(L, 1, schemmgr);
|
|
|
|
if (!schem) {
|
|
|
|
schem = load_schematic(L, 1, NULL, NULL);
|
|
|
|
was_loaded = true;
|
|
|
|
}
|
2015-04-12 22:40:50 +02:00
|
|
|
if (!schem) {
|
|
|
|
errorstream << "serialize_schematic: failed to get schematic" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//// Read format of definition to save as
|
|
|
|
int schem_format = SCHEM_FMT_MTS;
|
|
|
|
const char *enumstr = lua_tostring(L, 2);
|
|
|
|
if (enumstr)
|
|
|
|
string_to_enum(es_SchematicFormatType, schem_format, std::string(enumstr));
|
|
|
|
|
|
|
|
//// Serialize to binary string
|
|
|
|
std::ostringstream os(std::ios_base::binary);
|
|
|
|
switch (schem_format) {
|
|
|
|
case SCHEM_FMT_MTS:
|
2015-05-07 08:34:15 +02:00
|
|
|
schem->serializeToMts(&os, schem->m_nodenames);
|
2015-04-12 22:40:50 +02:00
|
|
|
break;
|
|
|
|
case SCHEM_FMT_LUA:
|
2015-05-07 08:54:30 +02:00
|
|
|
schem->serializeToLua(&os, schem->m_nodenames,
|
|
|
|
use_comments, indent_spaces);
|
2015-04-12 22:40:50 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-07 08:34:15 +02:00
|
|
|
if (was_loaded)
|
|
|
|
delete schem;
|
|
|
|
|
2015-04-12 22:40:50 +02:00
|
|
|
std::string ser = os.str();
|
|
|
|
lua_pushlstring(L, ser.c_str(), ser.length());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-01 05:27:19 +02:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
void ModApiMapgen::Initialize(lua_State *L, int top)
|
|
|
|
{
|
2015-09-29 19:38:08 +02:00
|
|
|
API_FCT(get_biome_id);
|
2013-08-11 04:09:45 +02:00
|
|
|
API_FCT(get_mapgen_object);
|
|
|
|
|
2014-12-29 18:58:55 +01:00
|
|
|
API_FCT(get_mapgen_params);
|
2013-08-11 04:09:45 +02:00
|
|
|
API_FCT(set_mapgen_params);
|
2016-06-25 00:15:56 +02:00
|
|
|
API_FCT(get_mapgen_setting);
|
|
|
|
API_FCT(set_mapgen_setting);
|
|
|
|
API_FCT(get_mapgen_setting_noiseparams);
|
|
|
|
API_FCT(set_mapgen_setting_noiseparams);
|
2014-12-10 05:44:04 +01:00
|
|
|
API_FCT(set_noiseparams);
|
2015-05-26 14:10:08 +02:00
|
|
|
API_FCT(get_noiseparams);
|
2013-12-14 07:52:06 +01:00
|
|
|
API_FCT(set_gen_notify);
|
2015-05-26 14:10:08 +02:00
|
|
|
API_FCT(get_gen_notify);
|
2013-08-11 04:09:45 +02:00
|
|
|
|
|
|
|
API_FCT(register_biome);
|
|
|
|
API_FCT(register_decoration);
|
|
|
|
API_FCT(register_ore);
|
2015-03-24 03:10:59 +01:00
|
|
|
API_FCT(register_schematic);
|
2014-12-12 20:07:49 +01:00
|
|
|
|
2014-12-07 00:08:08 +01:00
|
|
|
API_FCT(clear_registered_biomes);
|
2014-12-12 20:07:49 +01:00
|
|
|
API_FCT(clear_registered_decorations);
|
|
|
|
API_FCT(clear_registered_ores);
|
2015-03-24 03:10:59 +01:00
|
|
|
API_FCT(clear_registered_schematics);
|
2013-08-11 04:09:45 +02:00
|
|
|
|
2015-01-05 04:37:20 +01:00
|
|
|
API_FCT(generate_ores);
|
|
|
|
API_FCT(generate_decorations);
|
2013-08-11 04:09:45 +02:00
|
|
|
API_FCT(create_schematic);
|
|
|
|
API_FCT(place_schematic);
|
2015-11-04 09:33:12 +01:00
|
|
|
API_FCT(place_schematic_on_vmanip);
|
2015-04-12 22:40:50 +02:00
|
|
|
API_FCT(serialize_schematic);
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|