summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2014-01-19 02:44:22 -0500
committerkwolekr <kwolekr@minetest.net>2014-01-19 02:44:45 -0500
commit21c96249fa6e9d4c65b4d897d4b6e2f48371e620 (patch)
treeadfd56da2552cc021425a6d708dcca3239f801f6 /src/script
parent66b24cc9ff7c852e5455cc6c2c024d51c37c0c2a (diff)
downloadminetest-21c96249fa6e9d4c65b4d897d4b6e2f48371e620.tar.gz
minetest-21c96249fa6e9d4c65b4d897d4b6e2f48371e620.tar.bz2
minetest-21c96249fa6e9d4c65b4d897d4b6e2f48371e620.zip
Schematic: Read slice probability table from schematic descriptors
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index c4acb7c32..0d1f7aa03 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -958,6 +958,7 @@ bool read_schematic(lua_State *L, int index, DecoSchematic *dschem, Server *serv
MapNode *schemdata = new MapNode[numnodes];
int i = 0;
+ // Get schematic data
lua_getfield(L, index, "data");
luaL_checktype(L, -1, LUA_TTABLE);
@@ -986,15 +987,34 @@ bool read_schematic(lua_State *L, int index, DecoSchematic *dschem, Server *serv
lua_pop(L, 1);
}
- dschem->size = size;
- dschem->schematic = schemdata;
-
if (i != numnodes) {
errorstream << "read_schematic: incorrect number of "
"nodes provided in raw schematic data (got " << i <<
", expected " << numnodes << ")." << std::endl;
return false;
}
+
+ u8 *sliceprobs = new u8[size.Y];
+ for (i = 0; i != size.Y; i++)
+ sliceprobs[i] = MTSCHEM_PROB_ALWAYS;
+
+ // Get Y-slice probability values (if present)
+ lua_getfield(L, index, "yslice_prob");
+ if (lua_istable(L, -1)) {
+ lua_pushnil(L);
+ while (lua_next(L, -2)) {
+ if (getintfield(L, -1, "ypos", i) && i >= 0 && i < size.Y) {
+ sliceprobs[i] = getintfield_default(L, -1,
+ "prob", MTSCHEM_PROB_ALWAYS);
+ }
+ lua_pop(L, 1);
+ }
+ }
+
+ dschem->size = size;
+ dschem->schematic = schemdata;
+ dschem->slice_probs = sliceprobs;
+
} else if (lua_isstring(L, index)) {
dschem->filename = std::string(lua_tostring(L, index));
} else {