/* Minetest Copyright (C) 2010-2015 kwolekr, Ryan Kwolek Copyright (C) 2010-2015 paramat, Matt Gregory 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 "mapgen.h" #include "voxel.h" #include "noise.h" #include "mapblock.h" #include "mapnode.h" #include "map.h" #include "content_sao.h" #include "nodedef.h" #include "voxelalgorithms.h" //#include "profiler.h" // For TimeTaker #include "settings.h" // For g_settings #include "emerge.h" #include "dungeongen.h" #include "cavegen.h" #include "treegen.h" #include "mg_biome.h" #include "mg_ore.h" #include "mg_decoration.h" #include "mapgen_v7.h" FlagDesc flagdesc_mapgen_v7[] = { {"mountains", MGV7_MOUNTAINS}, {"ridges", MGV7_RIDGES}, {NULL, 0} }; /////////////////////////////////////////////////////////////////////////////// MapgenV7::MapgenV7(int mapgenid, MapgenParams *params, EmergeManager *emerge) : Mapgen(mapgenid, params, emerge) { this->m_emerge = emerge; this->bmgr = emerge->biomemgr; //// amount of elements to skip for the next index //// for noise/height/biome maps (not vmanip) this->ystride = csize.X; this->zstride = csize.X * (csize.Y + 2); this->biomemap = new u8[csize.X * csize.Z]; this->heightmap = new s16[csize.X * csize.Z]; this->heatmap = NULL; this->humidmap = NULL; this->ridge_heightmap = new s16[csize.X * csize.Z]; MapgenV7Params *sp = (MapgenV7Params *)params->sparams; this->spflags = sp->spflags; //// Terrain noise noise_terrain_base = new Noise(&sp->np_terrain_base, seed, csize.X, csize.Z); noise_terrain_alt = new Noise(&sp->np_terrain_alt, seed, csize.X, csize.Z); noise_terrain_persist = new Noise(&sp->np_terrain_persist, seed, csize.X, csize.Z); noise_height_select = new Noise(&sp->np_height_select, seed, csize.X, csize.Z); noise_filler_depth = new Noise(&sp->np_filler_depth, seed, csize.X, csize.Z); noise_mount_height = new Noise(&sp->np_mount_height, seed, csize.X, csize.Z); noise_ridge_uwater = new Noise(&sp->np_ridge_uwater, seed, csize.X, csize.Z); //// 3d terrain noise noise_mountain = new Noise(&sp->np_mountain, seed, csize.X, csize.Y + 2, csize.Z); noise_ridge = new Noise(&sp->np_ridge, seed, csize.X, csize.Y + 2, csize.Z); noise_cave1 = new Noise(&sp->np_cave1, seed, csize.X, csize.Y + 2, csize.Z); noise_cave2 = new Noise(&sp->np_cave2, seed, csize.X, csize.Y + 2, csize.Z); //// Biome noise noise_heat = new Noise(¶ms->np_biome_heat, seed, csize.X, csize.Z); noise_humidity = new Noise(¶ms->np_biome_humidity, seed, csize.X, csize.Z); noise_heat_blend = new Noise(¶ms->np_biome_heat_blend, seed, csize.X, csize.Z); noise_humidity_blend = new Noise(¶ms->np_biome_humidity_blend, seed, csize.X, csize.Z); //// Resolve nodes to be used INodeDefManager *ndef = emerge->ndef; c_stone = ndef->getId("mapgen_stone"); c_water_source = ndef->getId("mapgen_water_source"); c_lava_source = ndef->getId("mapgen_lava_source"); c_desert_stone = ndef->getId("mapgen_desert_stone"); c_ice = ndef->getId("mapgen_ice"); c_sandstone = ndef->getId("mapgen_sandstone"); c_cobble = ndef->getId("mapgen_cobble"); c_stair_cobble = ndef->getId("mapgen_stair_cobble"); c_mossycobble = ndef->getId("mapgen_mossycobble"); c_sandstonebrick = ndef->getId("mapgen_sandstonebrick"); c_stair_sandstonebrick = ndef->getId("mapgen_stair_sandstonebrick"); if (c_ice == CONTENT_IGNORE) c_ice = CONTENT_AIR; if (c_mossycobble == CONTENT_IGNORE) c_mossycobble = c_cobble; if (c_stair_cobble == CONTENT_IGNORE) c_stair_cobble = c_cobble; if (c_sandstonebrick == CONTENT_IGNORE) c_sandstonebrick = c_sandstone; if (c_stair_sandstonebrick == CONTENT_IGNORE) c_stair_sandstonebrick = c_sandstone; } MapgenV7::~MapgenV7() { delete noise_terrain_base; delete noise_terrain_persist; delete noise_height_select; delete noise_terrain_alt; delete noise_filler_depth; delete noise_mount_height; delete noise_ridge_uwater; delete noise_mountain; delete noise_ridge; delete noise_cave1; delete noise_cave2; delete noise_heat; delete noise_humidity; delete noise_heat_blend; delete noise_humidity_blend; delete[] ridge_heightmap; delete[] heightmap; delete[] biomemap; } MapgenV7Params::MapgenV7Params() { spflags = MGV7_MOUNTAINS | MGV7_RIDGES; np_terrain_base = NoiseParams(4, 70, v3f(600, 600, 600), 82341, 5, 0.6, 2.0); np_terrain_alt = NoiseParams(4, 25, v3f(600, 600, 600), 5934, 5, 0.6, 2.0); np_terrain_persist = NoiseParams(0.6, 0.1, v3f(2000, 2000, 2000), 539, 3, 0.6, 2.0); np_height_select = NoiseParams(-12, 24, v3f(500, 500, 500), 4213, 6, 0.7, 2.0); np_filler_depth = NoiseParams(0, 1.2, v3f(150, 150, 150), 261, 3, 0.7, 2.0); np_mount_height = NoiseParams(256, 112, v3f(1000, 1000, 1000), 72449, 3, 0.6, 2.0); np_ridge_uwater = NoiseParams(0, 1, v3f(1000, 1000, 1000), 85039, 5, 0.6, 2.0); np_mountain = NoiseParams(-0.6, 1, v3f(250, 350, 250), 5333, 5, 0.63, 2.0); np_ridge = NoiseParams(0, 1, v3f(100, 100, 100), 6467, 4, 0.75, 2.0); np_cave1 = NoiseParams(0, 12, v3f(100, 100, 100), 52534, 4, 0.5, 2.0); np_cave2 = NoiseParams(0, 12, v3f(100, 100, 100), 10325, 4, 0.5, 2.0); } void MapgenV7Params::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7); settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base); settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt); settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist); settings->getNoiseParams("mgv7_np_height_select", np_height_select); settings->getNoiseParams("mgv7_np_filler_depth", np_filler_depth); settings->getNoiseParams("mgv7_np_mount_height", np_mount_height); settings->getNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater); settings->getNoiseParams("mgv7_np_mountain", np_mountain); settings->getNoiseParams("mgv7_np_ridge", np_ridge); settings->getNoiseParams("mgv7_np_cave1", np_cave1); settings->getNoiseParams("mgv7_np_cave2", np_cave2); } void MapgenV7Params::writeParams(Settings *settings) const { settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, U32_MAX); settings->setNoiseParams("mgv7_np_terrain_base", np_terrain_base); settings->setNoiseParams("mgv7_np_terrain_alt", np_terrain_alt); settings->setNoiseParams("mgv7_np_terrain_persist", np_terrain_persist); settings->setNoiseParams("mgv7_np_height_select", np_height_select); settings->setNoiseParams("mgv7_np_filler_depth", np_filler_depth); settings->setNoiseParams("mgv7_np_mount_height", np_mount_height); settings->setNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater); settings->setNoiseParams("mgv7_np_mountain", np_mountain); settings->setNoiseParams("mgv7_np_ridge", np_ridge); settings->setNoiseParams("mgv7_np_cave1", np_cave1); settings->setNoiseParams("mgv7_np_cave2", np_cave2); } /////////////////////////////////////// int MapgenV7::getGroundLevelAtPoint(v2s16 p) { // B/* Minetest-c55 Copyright (C) 2010 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 General Public License as published by the Free Software Foundation; either version 2 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 General Public License for more details. You should have received a copy of the GNU 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. */ #ifndef GUIINVENTORYMENU_HEADER #define GUIINVENTORYMENU_HEADER #include "common_irrlicht.h" #include "inventory.h" #include "utility.h" #include "modalMenu.h" void drawInventoryItem(video::IVideoDriver *driver, gui::IGUIFont *font, InventoryItem *item, core::rect<s32> rect, const core::rect<s32> *clip); class GUIInventoryMenu : public GUIModalMenu { struct ItemSpec { ItemSpec() { i = -1; } ItemSpec(const std::string &a_inventoryname, const std::string &a_listname, s32 a_i) { inventoryname = a_inventoryname; listname = a_listname; i = a_i; } bool isValid() const { return i != -1; } std::string inventoryname; std::string listname; s32 i; }; struct ListDrawSpec { ListDrawSpec() { } ListDrawSpec(const std::string &a_inventoryname, const std::string &a_listname, v2s32 a_pos, v2s32 a_geom) { inventoryname = a_inventoryname; listname = a_listname; pos = a_pos; geom = a_geom; } std::string inventoryname; std::string listname; v2s32 pos; v2s32 geom; }; public: struct DrawSpec { DrawSpec() { } DrawSpec(const std::string &a_type, const std::string &a_name, const std::string &a_subname, v2s32 a_pos, v2s32 a_geom) { type = a_type; name = a_name; subname = a_subname; pos = a_pos; geom = a_geom; } std::string type; std::string name; std::string subname; v2s32 pos; v2s32 geom; }; // See .cpp for format static v2s16 makeDrawSpecArrayFromString( core::array<GUIInventoryMenu::DrawSpec> &draw_spec, const std::string &data, const std::string &current_name); GUIInventoryMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, v2s16 menu_size, InventoryContext *c, InventoryManager *invmgr ); ~GUIInventoryMenu(); void setDrawSpec(core::array<DrawSpec> &init_draw_spec) { m_init_draw_spec = init_draw_spec; } void removeChildren(); /* Remove and re-add (or reposition) stuff */ void regenerateGui(v2u32 screensize); ItemSpec getItemAtPos(v2s32 p) const; void drawList(const ListDrawSpec &s); void drawMenu(); bool OnEvent(const SEvent& event); protected: v2s32 getBasePos() const { return padding + AbsoluteRect.UpperLeftCorner; } v2s16 m_menu_size; v2s32 padding; v2s32 spacing; v2s32 imgsize; InventoryContext *m_c; InventoryManager *m_invmgr; core::array<DrawSpec> m_init_draw_spec; core::array<ListDrawSpec> m_draw_spec; ItemSpec *m_selected_item; }; #endif 16_MAX; for (s16 y = node_max.Y; y >= node_min.Y; y--) { content_t c = vm->m_data[vi].getContent(); // Biome is recalculated each time an upper surface is detected while // working down a column. The selected biome then remains in effect for // all nodes below until the next surface and biome recalculation. // Biome is recalculated: // 1. At the surface of stone below air or water. // 2. At the surface of water below air. // 3. When stone or water is detected but biome has not yet been calculated. if ((c == c_stone && (air_above || water_above || !biome)) || (c == c_water_source && (air_above || !biome))) { biome = bmgr->getBiome(heat_map[index], humidity_map[index], y); depth_top = biome->depth_top; base_filler = MYMAX(depth_top + biome->depth_filler + noise_filler_depth->result[index], 0); depth_water_top = biome->depth_water_top; // Detect stone type for dungeons during every biome calculation. // This is more efficient than detecting per-node and will not // miss any desert stone or sandstone biomes. if (biome->c_stone == c_desert_stone) stone_type = DESERT_STONE; else if (biome->c_stone == c_sandstone) stone_type = SANDSTONE; } if (c == c_stone) { content_t c_below = vm->m_data[vi - em.X].getContent(); // If the node below isn't solid, make this node stone, so that // any top/filler nodes above are structurally supported. // This is done by aborting the cycle of top/filler placement // immediately by forcing nplaced to stone level. if (c_below == CONTENT_AIR || c_below == c_water_source) nplaced = U16_MAX; if (nplaced < depth_top) { vm->m_data[vi] = MapNode(biome->c_top); nplaced++; } else if (nplaced < base_filler) { vm->m_data[vi] = MapNode(biome->c_filler); nplaced++; } else { vm->m_data[vi] = MapNode(biome->c_stone); } air_above = false; water_above = false; } else if (c == c_water_source) { vm->m_data[vi] = MapNode((y > (s32)(water_level - depth_water_top)) ? biome->c_water_top : biome->c_water); nplaced = 0; // Enable top/filler placement for next surface air_above = false; water_above = true; } else if (c == CONTENT_AIR) { nplaced = 0; // Enable top/filler placement for next surface air_above = true; water_above = false; } else { // Possible various nodes overgenerated from neighbouring mapchunks nplaced = U16_MAX; // Disable top/filler placement air_above = false; water_above = false; } vm->m_area.add_y(em, vi, -1); } } return stone_type; } void MapgenV7::dustTopNodes() { if (node_max.Y < water_level) return; v3s16 em = vm->m_area.getExtent(); u32 index = 0; for (s16 z = node_min.Z; z <= node_max.Z; z++) for (s16 x = node_min.X; x <= node_max.X; x++, index++) { Biome *biome = (Biome *)bmgr->getRaw(biomemap[index]); if (biome->c_dust == CONTENT_IGNORE) continue; u32 vi = vm->m_area.index(x, full_node_max.Y, z); content_t c_full_max = vm->m_data[vi].getContent(); s16 y_start; if (c_full_max == CONTENT_AIR) { y_start = full_node_max.Y - 1; } else if (c_full_max == CONTENT_IGNORE) { vi = vm->m_area.index(x, node_max.Y + 1, z); content_t c_max = vm->m_data[vi].getContent(); if (c_max == CONTENT_AIR) y_start = node_max.Y; else continue; } else { continue; } vi = vm->m_area.index(x, y_start, z); for (s16 y = y_start; y >= node_min.Y - 1; y--) { if (vm->m_data[vi].getContent() != CONTENT_AIR) break; vm->m_area.add_y(em, vi, -1); } content_t c = vm->m_data[vi].getContent(); if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE && c != biome->c_dust) { vm->m_area.add_y(em, vi, 1); vm->m_data[vi] = MapNode(biome->c_dust); } } } #if 0 void MapgenV7::addTopNodes() { v3s16 em = vm->m_area.getExtent(); s16 ntopnodes; u32 index = 0; for (s16 z = node_min.Z; z <= node_max.Z; z++) for (s16 x = node_min.X; x <= node_max.X; x++, index++) { Biome *biome = bmgr->biomes[biomemap[index]]; //////////////////// First, add top nodes below the ridge s16 y = ridge_heightmap[index]; // This cutoff is good enough, but not perfect. // It will cut off potentially placed top nodes at chunk boundaries if (y < node_min.Y) continue; if (y > node_max.Y) { y = node_max.Y; // Let's see if we can still go downward anyway u32 vi = vm->m_area.index(x, y, z); content_t c = vm->m_data[vi].getContent(); if (ndef->get(c).walkable) continue; } // N.B. It is necessary to search downward since ridge_heightmap[i] // might not be the actual height, just the lowest part in the chunk // where a ridge had been carved u32 i = vm->m_area.index(x, y, z); for (; y >= node_min.Y; y--) { content_t c = vm->m_data[i].getContent(); if (ndef->get(c).walkable) break; vm->m_area.add_y(em, i, -1); } if (y != node_min.Y - 1 && y >= water_level) { ridge_heightmap[index] = y; //update ridgeheight ntopnodes = biome->top_depth; for (; y <= node_max.Y && ntopnodes; y++) { ntopnodes--; vm->m_data[i] = MapNode(biome->c_top); vm->m_area.add_y(em, i, 1); } // If dirt, grow grass on it. if (y > water_level - 10 && vm->m_data[i].getContent() == CONTENT_AIR) { vm->m_area.add_y(em, i, -1); if (vm->m_data[i].getContent() == c_dirt) vm->m_data[i] = MapNode(c_dirt_with_grass); } } //////////////////// Now, add top nodes on top of the ridge y = heightmap[index]; if (y > node_max.Y) { y = node_max.Y; // Let's see if we can still go downward anyway u32 vi = vm->m_area.index(x, y, z); content_t c = vm->m_data[vi].getContent(); if (ndef->get(c).walkable) continue; } i = vm->m_area.index(x, y, z); for (; y >= node_min.Y; y--) { content_t c = vm->m_data[i].getContent(); if (ndef->get(c).walkable) break; vm->m_area.add_y(em, i, -1); } if (y != node_min.Y - 1) { ntopnodes = biome->top_depth; // Let's see if we've already added it... if (y == ridge_heightmap[index] + ntopnodes - 1) continue; for (; y <= node_max.Y && ntopnodes; y++) { ntopnodes--; vm->m_data[i] = MapNode(biome->c_top); vm->m_area.add_y(em, i, 1); } // If dirt, grow grass on it. if (y > water_level - 10 && vm->m_data[i].getContent() == CONTENT_AIR) { vm->m_area.add_y(em, i, -1); if (vm->m_data[i].getContent() == c_dirt) vm->m_data[i] = MapNode(c_dirt_with_grass); } } } } #endif void MapgenV7::generateCaves(s16 max_stone_y) { if (max_stone_y >= node_min.Y) { u32 index = 0; for (s16 z = node_min.Z; z <= node_max.Z; z++) for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) { u32 i = vm->m_area.index(node_min.X, y, z); for (s16 x = node_min.X; x <= node_max.X; x++, i++, index++) { float d1 = contour(noise_cave1->result[index]); float d2 = contour(noise_cave2->result[index]); if (d1 * d2 > 0.3) { content_t c = vm->m_data[i].getContent(); if (!ndef->get(c).is_ground_content || c == CONTENT_AIR) continue; vm->m_data[i] = MapNode(CONTENT_AIR); } } } } PseudoRandom ps(blockseed + 21343); u32 bruises_count = (ps.range(1, 4) == 1) ? ps.range(1, 2) : 0; for (u32 i = 0; i < bruises_count; i++) { CaveV7 cave(this, &ps); cave.makeCave(node_min, node_max, max_stone_y); } }