diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mg_schematic.cpp | 2 | ||||
-rw-r--r-- | src/nodedef.cpp | 39 | ||||
-rw-r--r-- | src/nodedef.h | 22 | ||||
-rw-r--r-- | src/script/lua_api/l_mapgen.cpp | 8 |
4 files changed, 47 insertions, 24 deletions
diff --git a/src/mg_schematic.cpp b/src/mg_schematic.cpp index 299a328c9..0ecbd7083 100644 --- a/src/mg_schematic.cpp +++ b/src/mg_schematic.cpp @@ -248,7 +248,7 @@ bool Schematic::loadSchematicFromFile(const char *filename, nri->nodenames.push_back(name); } - nri->nodename_sizes.push_back(nidmapcount); + nri->nodelistinfo.push_back(NodeListInfo(nidmapcount, CONTENT_AIR)); ndef->pendNodeResolve(nri); size_t nodecount = size.X * size.Y * size.Z; diff --git a/src/nodedef.cpp b/src/nodedef.cpp index bf97ff6d8..f87daa528 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -1308,8 +1308,7 @@ bool CNodeDefManager::getIdFromResolveInfo(NodeResolveInfo *nri, { if (nri->nodenames.empty()) { result = c_fallback; - errorstream << "CNodeDefManager::getIdFromResolveInfo: empty " - "nodenames list" << std::endl; + errorstream << "Resolver empty nodename list" << std::endl; return false; } @@ -1324,8 +1323,8 @@ bool CNodeDefManager::getIdFromResolveInfo(NodeResolveInfo *nri, } if (!success) { - errorstream << "CNodeDefManager::getIdFromResolveInfo: Failed to " - "resolve node name '" << name << "'." << std::endl; + errorstream << "Resolver: Failed to resolve node name '" << name + << "'." << std::endl; c = c_fallback; } @@ -1337,31 +1336,35 @@ bool CNodeDefManager::getIdFromResolveInfo(NodeResolveInfo *nri, bool CNodeDefManager::getIdsFromResolveInfo(NodeResolveInfo *nri, std::vector<content_t> &result) { - if (nri->nodename_sizes.empty()) { - errorstream << "CNodeDefManager::getIdsFromResolveInfo: empty " - "nodename_sizes list" << std::endl; + bool success = true; + + if (nri->nodelistinfo.empty()) { + errorstream << "Resolver: Empty nodelistinfo list" << std::endl; return false; } - size_t nitems = nri->nodename_sizes.front(); - nri->nodename_sizes.pop_front(); + NodeListInfo listinfo = nri->nodelistinfo.front(); + nri->nodelistinfo.pop_front(); - while (nitems--) { + while (listinfo.length--) { if (nri->nodenames.empty()) { - errorstream << "" << std::endl; + errorstream << "Resolver: Empty nodename list" << std::endl; return false; } content_t c; - if (getId(nri->nodenames.front(), c)) { + std::string name = nri->nodenames.front(); + nri->nodenames.pop_front(); + + if (getId(name, c)) { result.push_back(c); - } else { - errorstream << "CNodeDefManager::getIdsFromResolveInfo: empty " - "nodenames list" << std::endl; + } else if (listinfo.all_required) { + errorstream << "Resolver: Failed to resolve node name '" << name + << "'." << std::endl; + result.push_back(listinfo.c_fallback); + success = false; } - - nri->nodenames.pop_front(); } - return true; + return success; } diff --git a/src/nodedef.h b/src/nodedef.h index 0c779ddcc..1be764121 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -285,6 +285,26 @@ struct ContentFeatures class NodeResolver; class INodeDefManager; +struct NodeListInfo { + NodeListInfo(u32 len) + { + length = len; + all_required = false; + c_fallback = CONTENT_IGNORE; + } + + NodeListInfo(u32 len, content_t fallback) + { + length = len; + all_required = true; + c_fallback = fallback; + } + + u32 length; + bool all_required; + content_t c_fallback; +}; + struct NodeResolveInfo { NodeResolveInfo(NodeResolver *nr) { @@ -292,7 +312,7 @@ struct NodeResolveInfo { } std::list<std::string> nodenames; - std::list<size_t> nodename_sizes; + std::list<NodeListInfo> nodelistinfo; NodeResolver *resolver; }; diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index a90c2c6c5..383fbeaef 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -508,7 +508,7 @@ int ModApiMapgen::l_register_decoration(lua_State *L) //// Get node name(s) to place decoration on std::vector<const char *> place_on_names; getstringlistfield(L, index, "place_on", place_on_names); - nri->nodename_sizes.push_back(place_on_names.size()); + nri->nodelistinfo.push_back(NodeListInfo(place_on_names.size())); for (size_t i = 0; i != place_on_names.size(); i++) nri->nodenames.push_back(place_on_names[i]); @@ -585,7 +585,7 @@ bool ModApiMapgen::regDecoSimple(lua_State *L, "defined" << std::endl; return false; } - nri->nodename_sizes.push_back(deco_names.size()); + nri->nodelistinfo.push_back(NodeListInfo(deco_names.size())); for (size_t i = 0; i != deco_names.size(); i++) nri->nodenames.push_back(deco_names[i]); @@ -596,7 +596,7 @@ bool ModApiMapgen::regDecoSimple(lua_State *L, " but num_spawn_by specified" << std::endl; return false; } - nri->nodename_sizes.push_back(spawnby_names.size()); + nri->nodelistinfo.push_back(NodeListInfo(spawnby_names.size())); for (size_t i = 0; i != spawnby_names.size(); i++) nri->nodenames.push_back(spawnby_names[i]); @@ -691,7 +691,7 @@ int ModApiMapgen::l_register_ore(lua_State *L) std::vector<const char *> wherein_names; getstringlistfield(L, index, "wherein", wherein_names); - nri->nodename_sizes.push_back(wherein_names.size()); + nri->nodelistinfo.push_back(NodeListInfo(wherein_names.size())); for (size_t i = 0; i != wherein_names.size(); i++) nri->nodenames.push_back(wherein_names[i]); |