aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorparamat <mat.gregory@virginmedia.com>2016-09-11 23:34:43 +0100
committerparamat <mat.gregory@virginmedia.com>2016-09-14 09:19:54 +0100
commitb88595050f3af5ccac06aac331ead4ebdcb9deb9 (patch)
tree378906d675cd1c87637646f8ea4f084202d514a9 /src/script/lua_api
parentb77cee146b0029d377f1028b942857d062bc1374 (diff)
downloadminetest-b88595050f3af5ccac06aac331ead4ebdcb9deb9.tar.gz
minetest-b88595050f3af5ccac06aac331ead4ebdcb9deb9.tar.bz2
minetest-b88595050f3af5ccac06aac331ead4ebdcb9deb9.zip
Decorations: Generalise 'spawn by' to be used by all decoration types
In lua_api.txt, make clear that 'place on' and 'spawn by' can be lists.
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_mapgen.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index 9f28231eb..a176f4f52 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -902,6 +902,7 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
deco->fill_ratio = getfloatfield_default(L, index, "fill_ratio", 0.02);
deco->y_min = getintfield_default(L, index, "y_min", -31000);
deco->y_max = getintfield_default(L, index, "y_max", 31000);
+ deco->nspawnby = getintfield_default(L, index, "num_spawn_by", -1);
deco->sidelen = getintfield_default(L, index, "sidelen", 8);
if (deco->sidelen <= 0) {
errorstream << "register_decoration: sidelen must be "
@@ -929,6 +930,14 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
errorstream << "register_decoration: couldn't get all biomes " << std::endl;
lua_pop(L, 1);
+ //// 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;
+ }
+
//// Handle decoration type-specific parameters
bool success = false;
switch (decotype) {
@@ -962,12 +971,10 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
bool read_deco_simple(lua_State *L, DecoSimple *deco)
{
- size_t nnames;
int index = 1;
deco->deco_height = getintfield_default(L, index, "height", 1);
deco->deco_height_max = getintfield_default(L, index, "height_max", 0);
- deco->nspawnby = getintfield_default(L, index, "num_spawn_by", -1);
if (deco->deco_height <= 0) {
errorstream << "register_decoration: simple decoration height"
@@ -975,7 +982,7 @@ bool read_deco_simple(lua_State *L, DecoSimple *deco)
return false;
}
- nnames = getstringlistfield(L, index, "decoration", &deco->m_nodenames);
+ size_t nnames = getstringlistfield(L, index, "decoration", &deco->m_nodenames);
deco->m_nnlistsizes.push_back(nnames);
if (nnames == 0) {
errorstream << "register_decoration: no decoration nodes "
@@ -983,14 +990,6 @@ bool read_deco_simple(lua_State *L, DecoSimple *deco)
return false;
}
- 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;
- return false;
- }
-
return true;
}