aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
ModeNameSize
-rw-r--r--CMakeLists.txt1476logplain
-rw-r--r--l_areastore.cpp9064logplain
-rw-r--r--l_areastore.h1764logplain
-rw-r--r--l_auth.cpp5592logplain
-rw-r--r--l_auth.h1497logplain
-rw-r--r--l_base.cpp4680logplain
-rw-r--r--l_base.h2394logplain
-rw-r--r--l_camera.cpp5460logplain
-rw-r--r--l_camera.h1730logplain
-rw-r--r--l_client.cpp9261logplain
-rw-r--r--l_client.h2557logplain
-rw-r--r--l_craft.cpp14300logplain
-rw-r--r--l_craft.h1583logplain
-rw-r--r--l_env.cpp33297logplain
-rw-r--r--l_env.h8323logplain
-rw-r--r--l_http.cpp5677logplain
-rw-r--r--l_http.h1486logplain
-rw-r--r--l_internal.h1870logplain
-rw-r--r--l_inventory.cpp13929logplain
-rw-r--r--l_inventory.h3798logplain
-rw-r--r--l_item.cpp16203logplain
-rw-r--r--l_item.h4438logplain
-rw-r--r--l_itemstackmeta.cpp3925logplain
-rw-r--r--l_itemstackmeta.h2007logplain
-rw-r--r--l_localplayer.cpp10034logplain
-rw-r--r--l_localplayer.h2666logplain
-rw-r--r--l_mainmenu.cpp29339logplain
-rw-r--r--l_mainmenu.h4044logplain
-rw-r--r--l_mapgen.cpp45876logplain
-rw-r--r--l_mapgen.h4594logplain
-rw-r--r--l_metadata.cpp6930logplain
-rw-r--r--l_metadata.h2134logplain
-rw-r--r--l_minimap.cpp5210logplain
-rw-r--r--l_minimap.h1673logplain
-rw-r--r--l_modchannels.cpp3863logplain
-rw-r--r--l_modchannels.h1749logplain
-rw-r--r--l_nodemeta.cpp7263logplain
-rw-r--r--l_nodemeta.h3083logplain
-rw-r--r--l_nodetimer.cpp4426logplain
-rw-r--r--l_nodetimer.h1729logplain
-rw-r--r--l_noise.cpp15750logplain
-rw-r--r--l_noise.h4547logplain
-rw-r--r--l_object.cpp49392logplain
-rw-r--r--l_object.h9617logplain
-rw-r--r--l_particles.cpp8704logplain
-rw-r--r--l_particles.h1084logplain
-rw-r--r--l_particles_local.cpp7224logplain
-rw-r--r--l_particles_local.h1123logplain
-rw-r--r--l_playermeta.cpp3334logplain
-rw-r--r--l_playermeta.h1735logplain
-rw-r--r--l_rollback.cpp3552logplain
-rw-r--r--l_rollback.h1219logplain
-rw-r--r--l_server.cpp13913logplain
-rw-r--r--l_server.h2974logplain
-rw-r--r--l_settings.cpp7522logplain
-rw-r--r--l_settings.h2342logplain
-rw-r--r--l_sound.cpp1434logplain
-rw-r--r--l_sound.h1086logplain
-rw-r--r--l_storage.cpp3977logplain
-rw-r--r--l_storage.h1647logplain
-rw-r--r--l_util.cpp13089logplain
-rw-r--r--l_util.h3026logplain
-rw-r--r--l_vmanip.cpp10987logplain
-rw-r--r--l_vmanip.h2239logplain
span> nmax.X; x++) { content_t c = vm->m_data[i].getContent(); NodeDrawType dtype = ndef->get(c).drawtype; if (dtype == NDT_AIRLIKE || dtype == NDT_LIQUID || c == CONTENT_IGNORE || !ndef->get(c).is_ground_content) vm->m_flags[i] |= VMANIP_FLAG_DUNGEON_PRESERVE; i++; } } } } // Add them for (u32 i = 0; i < dp.num_dungeons; i++) makeDungeon(v3s16(1, 1, 1) * MAP_BLOCKSIZE); // Optionally convert some structure to alternative structure if (dp.c_alt_wall == CONTENT_IGNORE) return; for (s16 z = nmin.Z; z <= nmax.Z; z++) for (s16 y = nmin.Y; y <= nmax.Y; y++) { u32 i = vm->m_area.index(nmin.X, y, z); for (s16 x = nmin.X; x <= nmax.X; x++) { if (vm->m_data[i].getContent() == dp.c_wall) { if (NoisePerlin3D(&dp.np_alt_wall, x, y, z, blockseed) > 0.0f) vm->m_data[i].setContent(dp.c_alt_wall); } i++; } } //printf("== gen dungeons: %dms\n", t.stop()); } void DungeonGen::makeDungeon(v3s16 start_padding) { const v3s16 &areasize = vm->m_area.getExtent(); v3s16 roomsize; v3s16 roomplace; /* Find place for first room. */ bool fits = false; for (u32 i = 0; i < 100 && !fits; i++) { if (dp.large_room_chance >= 1) { roomsize.Z = random.range(dp.room_size_large_min.Z, dp.room_size_large_max.Z); roomsize.Y = random.range(dp.room_size_large_min.Y, dp.room_size_large_max.Y); roomsize.X = random.range(dp.room_size_large_min.X, dp.room_size_large_max.X); } else { roomsize.Z = random.range(dp.room_size_min.Z, dp.room_size_max.Z); roomsize.Y = random.range(dp.room_size_min.Y, dp.room_size_max.Y); roomsize.X = random.range(dp.room_size_min.X, dp.room_size_max.X); } // start_padding is used to disallow starting the generation of // a dungeon in a neighboring generation chunk roomplace = vm->m_area.MinEdge + start_padding; roomplace.Z += random.range(0, areasize.Z - roomsize.Z - start_padding.Z); roomplace.Y += random.range(0, areasize.Y - roomsize.Y - start_padding.Y); roomplace.X += random.range(0, areasize.X - roomsize.X - start_padding.X); /* Check that we're not putting the room to an unknown place, otherwise it might end up floating in the air */ fits = true; for (s16 z = 0; z < roomsize.Z; z++) for (s16 y = 0; y < roomsize.Y; y++) for (s16 x = 0; x < roomsize.X; x++) { v3s16 p = roomplace + v3s16(x, y, z); u32 vi = vm->m_area.index(p); if ((vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) || vm->m_data[vi].getContent() == CONTENT_IGNORE) { fits = false; break; } } } // No place found if (!fits) return; /* Stores the center position of the last room made, so that a new corridor can be started from the last room instead of the new room, if chosen so. */ v3s16 last_room_center = roomplace + v3s16(roomsize.X / 2, 1, roomsize.Z / 2); for (u32 i = 0; i < dp.num_rooms; i++) { // Make a room to the determined place makeRoom(roomsize, roomplace); v3s16 room_center = roomplace + v3s16(roomsize.X / 2, 1, roomsize.Z / 2); if (gennotify) gennotify->addEvent(dp.notifytype, room_center); #ifdef DGEN_USE_TORCHES // Place torch at room center (for testing) vm->m_data[vm->m_area.index(room_center)] = MapNode(c_torch); #endif // Quit if last room if (i + 1 == dp.num_rooms) break; // Determine walker start position bool start_in_last_room = (random.range(0, 2) != 0); v3s16 walker_start_place; if (start_in_last_room) { walker_start_place = last_room_center; } else { walker_start_place = room_center; // Store center of current room as the last one last_room_center = room_center; } // Create walker and find a place for a door v3s16 doorplace; v3s16 doordir; m_pos = walker_start_place; if (!findPlaceForDoor(doorplace, doordir)) return; if (random.range(0, 1) == 0) // Make the door makeDoor(doorplace, doordir); else // Don't actually make a door doorplace -= doordir; // Make a random corridor starting from the door v3s16 corridor_end; v3s16 corridor_end_dir; makeCorridor(doorplace, doordir, corridor_end, corridor_end_dir); // Find a place for a random sized room if (dp.large_room_chance > 1 && random.range(1, dp.large_room_chance) == 1) { // Large room roomsize.Z = random.range(dp.room_size_large_min.Z, dp.room_size_large_max.Z); roomsize.Y = random.range(dp.room_size_large_min.Y, dp.room_size_large_max.Y); roomsize.X = random.range(dp.room_size_large_min.X, dp.room_size_large_max.X); } else { roomsize.Z = random.range(dp.room_size_min.Z, dp.room_size_max.Z); roomsize.Y = random.range(dp.room_size_min.Y, dp.room_size_max.Y); roomsize.X = random.range(dp.room_size_min.X, dp.room_size_max.X); } m_pos = corridor_end; m_dir = corridor_end_dir; if (!findPlaceForRoomDoor(roomsize, doorplace, doordir, roomplace)) return; if (random.range(0, 1) == 0) // Make the door makeDoor(doorplace, doordir); else // Don't actually make a door roomplace -= doordir; } } void DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace) { MapNode n_wall(dp.c_wall); MapNode n_air(CONTENT_AIR); // Make +-X walls for (s16 z = 0; z < roomsize.Z; z++) for (s16 y = 0; y < roomsize.Y; y++) { { v3s16 p = roomplace + v3s16(0, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_wall; } { v3s16 p = roomplace + v3s16(roomsize.X - 1, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_wall; } } // Make +-Z walls for (s16 x = 0; x < roomsize.X; x++) for (s16 y = 0; y < roomsize.Y; y++) { { v3s16 p = roomplace + v3s16(x, y, 0); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_wall; } { v3s16 p = roomplace + v3s16(x, y, roomsize.Z - 1); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_wall; } } // Make +-Y walls (floor and ceiling) for (s16 z = 0; z < roomsize.Z; z++) for (s16 x = 0; x < roomsize.X; x++) { { v3s16 p = roomplace + v3s16(x, 0, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_wall; } { v3s16 p = roomplace + v3s16(x,roomsize. Y - 1, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_wall; } } // Fill with air for (s16 z = 1; z < roomsize.Z - 1; z++) for (s16 y = 1; y < roomsize.Y - 1; y++) for (s16 x = 1; x < roomsize.X - 1; x++) { v3s16 p = roomplace + v3s16(x, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); vm->m_flags[vi] |= VMANIP_FLAG_DUNGEON_UNTOUCHABLE; vm->m_data[vi] = n_air; } } void DungeonGen::makeFill(v3s16 place, v3s16 size, u8 avoid_flags, MapNode n, u8 or_flags) { for (s16 z = 0; z < size.Z; z++) for (s16 y = 0; y < size.Y; y++) for (s16 x = 0; x < size.X; x++) { v3s16 p = place + v3s16(x, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & avoid_flags) continue; vm->m_flags[vi] |= or_flags; vm->m_data[vi] = n; } } void DungeonGen::makeHole(v3s16 place) { makeFill(place, dp.holesize, 0, MapNode(CONTENT_AIR), VMANIP_FLAG_DUNGEON_INSIDE); } void DungeonGen::makeDoor(v3s16 doorplace, v3s16 doordir) { makeHole(doorplace); #ifdef DGEN_USE_TORCHES // Place torch (for testing) vm->m_data[vm->m_area.index(doorplace)] = MapNode(c_torch); #endif } void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, v3s16 &result_place, v3s16 &result_dir) { makeHole(doorplace); v3s16 p0 = doorplace; v3s16 dir = doordir; u32 length = random.range(dp.corridor_len_min, dp.corridor_len_max); u32 partlength = random.range(dp.corridor_len_min, dp.corridor_len_max); u32 partcount = 0; s16 make_stairs = 0; if (random.next() % 2 == 0 && partlength >= 3) make_stairs = random.next() % 2 ? 1 : -1; for (u32 i = 0; i < length; i++) { v3s16 p = p0 + dir; if (partcount != 0) p.Y += make_stairs; // Check segment of minimum size corridor is in voxelmanip if (vm->m_area.contains(p) && vm->m_area.contains(p + v3s16(0, 1, 0))) { if (make_stairs) { makeFill(p + v3s16(-1, -1, -1), dp.holesize + v3s16(2, 3, 2), VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(dp.c_wall), 0); makeFill(p, dp.holesize, VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(CONTENT_AIR), VMANIP_FLAG_DUNGEON_INSIDE); makeFill(p - dir, dp.holesize, VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(CONTENT_AIR), VMANIP_FLAG_DUNGEON_INSIDE); // TODO: fix stairs code so it works 100% // (quite difficult) // exclude stairs from the bottom step // exclude stairs from diagonal steps if (((dir.X ^ dir.Z) & 1) && (((make_stairs == 1) && i != 0) || ((make_stairs == -1) && i != length - 1))) { // rotate face 180 deg if // making stairs backwards int facedir = dir_to_facedir(dir * make_stairs); v3s16 ps = p; u16 stair_width = (dir.Z != 0) ? dp.holesize.X : dp.holesize.Z; // Stair width direction vector v3s16 swv = (dir.Z != 0) ? v3s16(1, 0, 0) : v3s16(0, 0, 1); for (u16 st = 0; st < stair_width; st++) { if (make_stairs == -1) { u32 vi = vm->m_area.index(ps.X - dir.X, ps.Y - 1, ps.Z - dir.Z); if (vm->m_area.contains(ps + v3s16(-dir.X, -1, -dir.Z)) && vm->m_data[vi].getContent() == dp.c_wall) { vm->m_flags[vi] |= VMANIP_FLAG_DUNGEON_UNTOUCHABLE; vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); } } else if (make_stairs == 1) { u32 vi = vm->m_area.index(ps.X, ps.Y - 1, ps.Z); if (vm->m_area.contains(ps + v3s16(0, -1, 0)) && vm->m_data[vi].getContent() == dp.c_wall) { vm->m_flags[vi] |= VMANIP_FLAG_DUNGEON_UNTOUCHABLE; vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); } } ps += swv; } } } else { makeFill(p + v3s16(-1, -1, -1), dp.holesize + v3s16(2, 2, 2), VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(dp.c_wall), 0); makeHole(p); } p0 = p; } else { // Can't go here, turn away dir = turn_xz(dir, random.range(0, 1)); make_stairs = -make_stairs; partcount = 0; partlength = random.range(1, length); continue; } partcount++; if (partcount >= partlength) { partcount = 0; random_turn(random, dir); partlength = random.range(1, length); make_stairs = 0; if (random.next() % 2 == 0 && partlength >= 3) make_stairs = random.next() % 2 ? 1 : -1; } } result_place = p0; result_dir = dir; } bool DungeonGen::findPlaceForDoor(v3s16 &result_place, v3s16 &result_dir) { for (u32 i = 0; i < 100; i++) { v3s16 p = m_pos + m_dir; v3s16 p1 = p + v3s16(0, 1, 0);