1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Decoration: Add support for zero probability, fix breakage from last commit

This commit is contained in:
kwolekr 2013-06-22 20:48:19 -04:00
parent 130464c268
commit 309c5f3641
4 changed files with 35 additions and 15 deletions

View file

@ -542,6 +542,9 @@ void DecoSchematic::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
if (!vm->m_area.contains(vi))
continue;
if (schematic[i].getContent() == CONTENT_IGNORE)
continue;
content_t c = vm->m_data[vi].getContent();
if (c != CONTENT_AIR && c != CONTENT_IGNORE)
continue;
@ -588,6 +591,10 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
for (s16 x = 0; x != size.X; x++, i++, vi++) {
if (!vm->m_area.contains(vi))
continue;
if (schematic[i].getContent() == CONTENT_IGNORE)
continue;
if (schematic[i].param1 && myrand_range(1, 256) > schematic[i].param1)
continue;
@ -746,12 +753,17 @@ bool DecoSchematic::getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2) {
}
void DecoSchematic::applyProbabilities(std::vector<std::pair<v3s16, u8> > *plist, v3s16 p0) {
void DecoSchematic::applyProbabilities(std::vector<std::pair<v3s16, s16> > *plist, v3s16 p0) {
for (size_t i = 0; i != plist->size(); i++) {
v3s16 p = (*plist)[i].first - p0;
int index = p.Z * (size.Y * size.X) + p.Y * size.X + p.X;
if (index < size.Z * size.Y * size.X)
schematic[index].param1 = (*plist)[i].second;
if (index < size.Z * size.Y * size.X) {
s16 prob = (*plist)[i].second;
if (prob != -1)
schematic[index].param1 = prob;
else
schematic[index].setContent(CONTENT_IGNORE);
}
}
}

View file

@ -271,7 +271,7 @@ public:
bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
void placeStructure(Map *map, v3s16 p);
void applyProbabilities(std::vector<std::pair<v3s16, u8> > *plist, v3s16 p0);
void applyProbabilities(std::vector<std::pair<v3s16, s16> > *plist, v3s16 p0);
};
void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,

View file

@ -674,7 +674,7 @@ int ModApiBasic::l_register_ore(lua_State *L)
verbosestream << "register_ore: ore '" << ore->ore_name
<< "' registered" << std::endl;
return 1;
return 0;
}
// register_decoration({lots of stuff})
@ -793,7 +793,7 @@ int ModApiBasic::l_register_decoration(lua_State *L)
verbosestream << "register_decoration: decoration '" << deco->getName()
<< "' registered" << std::endl;
return 1;
return 0;
}
// create_schematic(p1, p2, probability_list, filename)
@ -808,7 +808,7 @@ int ModApiBasic::l_create_schematic(lua_State *L)
v3s16 p2 = read_v3s16(L, 2);
sortBoxVerticies(p1, p2);
std::vector<std::pair<v3s16, u8> > probability_list;
std::vector<std::pair<v3s16, s16> > probability_list;
if (lua_istable(L, 3)) {
lua_pushnil(L);
while (lua_next(L, 3)) {
@ -817,12 +817,12 @@ int ModApiBasic::l_create_schematic(lua_State *L)
v3s16 pos = read_v3s16(L, -1);
lua_pop(L, 1);
int prob = getintfield_default(L, -1, "prob", 0);
if (prob < 0 || prob >= UCHAR_MAX) {
s16 prob = getintfield_default(L, -1, "prob", 0);
if (prob < -1 || prob >= UCHAR_MAX) {
errorstream << "create_schematic: probability value of "
<< prob << " at " << PP(pos) << " out of range" << std::endl;
} else {
probability_list.push_back(std::make_pair(pos, (u8)prob));
probability_list.push_back(std::make_pair(pos, prob));
}
}