summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/cavegen.cpp266
-rw-r--r--src/cavegen.h68
-rw-r--r--src/emerge.cpp2
-rw-r--r--src/hud.cpp68
-rw-r--r--src/hud.h6
-rw-r--r--src/mapgen_indev.cpp83
-rw-r--r--src/mapgen_indev.h12
-rw-r--r--src/mapgen_v6.cpp268
-rw-r--r--src/mapgen_v6.h17
-rw-r--r--src/mapgen_v7.cpp115
-rw-r--r--src/mapgen_v7.h3
-rw-r--r--src/scriptapi_object.cpp20
-rw-r--r--src/server.cpp32
14 files changed, 563 insertions, 398 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7ddeeb02e..74c5fabb8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -248,6 +248,7 @@ set(common_SRCS
mapgen_singlenode.cpp
treegen.cpp
dungeongen.cpp
+ cavegen.cpp
content_nodemeta.cpp
content_mapnode.cpp
collision.cpp
diff --git a/src/cavegen.cpp b/src/cavegen.cpp
new file mode 100644
index 000000000..bef50c7a7
--- /dev/null
+++ b/src/cavegen.cpp
@@ -0,0 +1,266 @@
+/*
+Minetest
+Copyright (C) 2010-2013 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 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 "util/numeric.h"
+#include "map.h"
+#include "mapgen.h"
+#include "cavegen.h"
+
+
+CaveV6::CaveV6(Mapgen *mg, PseudoRandom *ps, PseudoRandom *ps2,
+ bool is_large_cave, content_t c_water, content_t c_lava) {
+ this->vm = mg->vm;
+ this->water_level = mg->water_level;
+ this->large_cave = is_large_cave;
+ this->ps = ps;
+ this->ps2 = ps2;
+ this->c_water_source = c_water;
+ this->c_lava_source = c_lava;
+
+ min_tunnel_diameter = 2;
+ max_tunnel_diameter = ps->range(2, 6);
+ dswitchint = ps->range(1, 14);
+ flooded = true;
+
+ if (large_cave) {
+ part_max_length_rs = ps->range(2,4);
+ tunnel_routepoints = ps->range(5, ps->range(15,30));
+ min_tunnel_diameter = 5;
+ max_tunnel_diameter = ps->range(7, ps->range(8,24));
+ } else {
+ part_max_length_rs = ps->range(2,9);
+ tunnel_routepoints = ps->range(10, ps->range(15,30));
+ }
+
+ large_cave_is_flat = (ps->range(0,1) == 0);
+}
+
+
+void CaveV6::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height) {
+ node_min = nmin;
+ node_max = nmax;
+ max_stone_y = max_stone_height;
+ main_direction = v3f(0, 0, 0);
+
+ // Allowed route area size in nodes
+ ar = node_max - node_min + v3s16(1, 1, 1);
+ // Area starting point in nodes
+ of = node_min;
+
+ // Allow a bit more
+ //(this should be more than the maximum radius of the tunnel)
+ const s16 max_spread_amount = MAP_BLOCKSIZE;
+ s16 insure = 10;
+ s16 more = max_spread_amount - max_tunnel_diameter / 2 - insure;
+ ar += v3s16(1,0,1) * more * 2;
+ of -= v3s16(1,0,1) * more;
+
+ route_y_min = 0;
+ // Allow half a diameter + 7 over stone surface
+ route_y_max = -of.Y + max_stone_y + max_tunnel_diameter / 2 + 7;
+
+ // Limit maximum to area
+ route_y_max = rangelim(route_y_max, 0, ar.Y - 1);
+
+ if (large_cave) {
+ s16 min = 0;
+ if (node_min.Y < water_level && node_max.Y > water_level) {
+ min = water_level - max_tunnel_diameter/3 - of.Y;
+ route_y_max = water_level + max_tunnel_diameter/3 - of.Y;
+ }
+ route_y_min = ps->range(min, min + max_tunnel_diameter);
+ route_y_min = rangelim(route_y_min, 0, route_y_max);
+ }
+
+ s16 route_start_y_min = route_y_min;
+ s16 route_start_y_max = route_y_max;
+
+ route_start_y_min = rangelim(route_start_y_min, 0, ar.Y-1);
+ route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y-1);
+
+ // Randomize starting position
+ orp = v3f(
+ (float)(ps->next() % ar.X) + 0.5,
+ (float)(ps->range(route_start_y_min, route_start_y_max)) + 0.5,
+ (float)(ps->next() % ar.Z) + 0.5
+ );
+
+ // Generate some tunnel starting from orp
+ for (u16 j = 0; j < tunnel_routepoints; j++)
+ makeTunnel(j % dswitchint == 0);
+}
+
+
+void CaveV6::makeTunnel(bool dirswitch) {
+ if (dirswitch && !large_cave) {
+ main_direction = v3f(
+ ((float)(ps->next() % 20) - (float)10) / 10,
+ ((float)(ps->next() % 20) - (float)10) / 30,
+ ((float)(ps->next() % 20) - (float)10) / 10
+ );
+ main_direction *= (float)ps->range(0, 10) / 10;
+ }
+
+ // Randomize size
+ s16 min_d = min_tunnel_diameter;
+ s16 max_d = max_tunnel_diameter;
+ rs = ps->range(min_d, max_d);
+
+ v3s16 maxlen;
+ if (large_cave) {
+ maxlen = v3s16(
+ rs * part_max_length_rs,
+ rs * part_max_length_rs / 2,
+ rs * part_max_length_rs
+ );
+ } else {
+ maxlen = v3s16(
+ rs * part_max_length_rs,
+ ps->range(1, rs * part_max_length_rs),
+ rs * part_max_length_rs
+ );
+ }
+
+ v3f vec(
+ (float)(ps->next() % (maxlen.X * 1)) - (float)maxlen.X / 2,
+ (float)(ps->next() % (maxlen.Y * 1)) - (float)maxlen.Y / 2,
+ (float)(ps->next() % (maxlen.Z * 1)) - (float)maxlen.Z / 2
+ );
+
+ // Jump downward sometimes
+ if (!large_cave && ps->range(0, 12) == 0) {
+ vec = v3f(
+ (float)(ps->next() % (maxlen.X * 1)) - (float)maxlen.X / 2,
+ (float)(ps->next() % (maxlen.Y * 2)) - (float)maxlen.Y,
+ (float)(ps->next() % (maxlen.Z * 1)) - (float)maxlen.Z / 2
+ );
+ }
+
+ /*if(large_cave){
+ v3f p = orp + vec;
+ s16 h = find_ground_level_clever(vmanip, v2s16(p.X, p.Z), ndef);
+ route_y_min = h - rs/3;
+ route_y_max = h + rs;
+ }*/
+
+ vec += main_direction;
+
+ v3f rp = orp + vec;
+ if (rp.X < 0)
+ rp.X = 0;
+ else if (rp.X >= ar.X)
+ rp.X = ar.X - 1;
+
+ if (rp.Y < route_y_min)
+ rp.Y = route_y_min;
+ else if (rp.Y >= route_y_max)
+ rp.Y = route_y_max - 1;
+
+ if (rp.Z < 0)
+ rp.Z = 0;
+ else if (rp.Z >= ar.Z)
+ rp.Z = ar.Z - 1;
+
+ vec = rp - orp;
+
+ float veclen = vec.getLength();
+ // As odd as it sounds, veclen is *exactly* 0.0 sometimes, causing a FPE
+ if (veclen == 0.0)
+ veclen = 1.0;
+
+ // Every second section is rough
+ bool randomize_xz = (ps2->range(1, 2) == 1);
+
+ // Carve routes
+ for (float f = 0; f < 1.0; f += 1.0 / veclen)
+ carveRoute(vec, f, randomize_xz);
+
+ orp = rp;
+}
+
+
+void CaveV6::carveRoute(v3f vec, float f, bool randomize_xz) {
+ MapNode airnode(CONTENT_AIR);
+ MapNode waternode(c_water_source);
+ MapNode lavanode(c_lava_source);
+
+ v3s16 startp(orp.X, orp.Y, orp.Z);
+ startp += of;
+
+ v3f fp = orp + vec * f;
+ fp.X += 0.1 * ps->range(-10, 10);
+ fp.Z += 0.1 * ps->range(-10, 10);
+ v3s16 cp(fp.X, fp.Y, fp.Z);
+
+ s16 d0 = -rs/2;
+ s16 d1 = d0 + rs;
+ if (randomize_xz) {
+ d0 += ps->range(-1, 1);
+ d1 += ps->range(-1, 1);
+ }
+
+ for (s16 z0 = d0; z0 <= d1; z0++) {
+ s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
+ for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) {
+ s16 maxabsxz = MYMAX(abs(x0), abs(z0));
+ s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1);
+ for (s16 y0 = -si2; y0 <= si2; y0++) {
+ // Make better floors in small caves
+ //if(y0 <= -rs/2 && rs<=7)
+ // continue;
+
+ if (large_cave_is_flat) {
+ // Make large caves not so tall
+ if (rs > 7 && abs(y0) >= rs / 3)
+ continue;
+ }
+
+ v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
+ p += of;
+
+ if (vm->m_area.contains(p) == false)
+ continue;
+
+ u32 i = vm->m_area.index(p);
+
+ if (large_cave) {
+ int full_ymin = node_min.Y - MAP_BLOCKSIZE;
+ int full_ymax = node_max.Y + MAP_BLOCKSIZE;
+
+ if (flooded && full_ymin < water_level && full_ymax > water_level) {
+ vm->m_data[i] = (p.Y <= water_level) ? waternode : airnode;
+ } else if (flooded && full_ymax < water_level) {
+ vm->m_data[i] = (p.Y < startp.Y - 2) ? lavanode : airnode;
+ } else {
+ vm->m_data[i] = airnode;
+ }
+ } else {
+ // Don't replace air or water or lava or ignore
+ content_t c = vm->m_data[i].getContent();
+ if (c == CONTENT_IGNORE || c == CONTENT_AIR ||
+ c == c_water_source || c == c_lava_source)
+ continue;
+
+ vm->m_data[i] = airnode;
+ vm->m_flags[i] |= VMANIP_FLAG_CAVE;
+ }
+ }
+ }
+ }
+}
diff --git a/src/cavegen.h b/src/cavegen.h
new file mode 100644
index 000000000..979226b3e
--- /dev/null
+++ b/src/cavegen.h
@@ -0,0 +1,68 @@
+/*
+Minetest
+Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+
+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.
+*/
+
+#ifndef CAVEGEN_HEADER
+#define CAVEGEN_HEADER
+
+#define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
+
+class CaveV6 {
+public:
+ ManualMapVoxelManipulator *vm;
+
+ s16 min_tunnel_diameter;
+ s16 max_tunnel_diameter;
+ u16 tunnel_routepoints;
+ int dswitchint;
+ int part_max_length_rs;
+
+ bool large_cave;
+ bool large_cave_is_flat;
+ bool flooded;
+
+ s16 max_stone_y;
+ v3s16 node_min;
+ v3s16 node_max;
+
+ v3f orp; //original point
+ v3s16 of;
+ v3s16 ar; // allowed route area
+ s16 rs; // radius size
+ v3f main_direction;
+
+ s16 route_y_min;
+ s16 route_y_max;
+
+ PseudoRandom *ps;
+ PseudoRandom *ps2;
+
+ content_t c_water_source;
+ content_t c_lava_source;
+
+ int water_level;
+
+ CaveV6() {}
+ CaveV6(Mapgen *mg, PseudoRandom *ps, PseudoRandom *ps2, bool large_cave,
+ content_t c_water, content_t c_lava);
+ void makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height);
+ void makeTunnel(bool dirswitch);
+ void carveRoute(v3f vec, float f, bool randomize_xz);
+};
+
+#endif
diff --git a/src/emerge.cpp b/src/emerge.cpp
index 049b3cc12..2d8b01819 100644
--- a/src/emerge.cpp
+++ b/src/emerge.cpp
@@ -50,7 +50,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
EmergeManager::EmergeManager(IGameDef *gamedef) {
//register built-in mapgens
registerMapgen("v6", new MapgenFactoryV6());
- //registerMapgen("v7", new MapgenFactoryV7());
+ registerMapgen("v7", new MapgenFactoryV7());
registerMapgen("indev", new MapgenFactoryIndev());
registerMapgen("singlenode", new MapgenFactorySinglenode());
diff --git a/src/hud.cpp b/src/hud.cpp
index 349c55add..77cf23173 100644
--- a/src/hud.cpp
+++ b/src/hud.cpp
@@ -198,7 +198,7 @@ void Hud::drawLuaElements() {
font->draw(narrow_to_wide(e->text).c_str(), size + pos, color);
break; }
case HUD_ELEM_STATBAR:
- drawStatbar(pos, e->text, e->number);
+ drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number);
break;
case HUD_ELEM_INVENTORY: {
InventoryList *inv = inventory->getList(e->text);
@@ -212,38 +212,55 @@ void Hud::drawLuaElements() {
}
-void Hud::drawStatbar(v2s32 upperleftpos, std::string texture, s32 count) {
+void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count) {
+ const video::SColor color(255, 255, 255, 255);
+ const video::SColor colors[] = {color, color, color, color};
+
video::ITexture *stat_texture =
gamedef->getTextureSource()->getTextureRaw(texture);
if (!stat_texture)
return;
+
+ core::dimension2di srcd(stat_texture->getOriginalSize());
- v2s32 p = upperleftpos;
+ v2s32 p = pos;
+ if (corner & HUD_CORNER_LOWER)
+ p -= srcd.Height;
+
+ v2s32 steppos;
+ switch (drawdir) {
+ case HUD_DIR_RIGHT_LEFT:
+ steppos = v2s32(-1, 0);
+ break;
+ case HUD_DIR_TOP_BOTTOM:
+ steppos = v2s32(0, 1);
+ break;
+ case HUD_DIR_BOTTOM_TOP:
+ steppos = v2s32(0, -1);
+ break;
+ default:
+ steppos = v2s32(1, 0);
+ }
+ steppos.X *= srcd.Width;
+ steppos.Y *= srcd.Height;
+
for (s32 i = 0; i < count / 2; i++)
{
- core::dimension2di srcd(stat_texture->getOriginalSize());
- const video::SColor color(255, 255, 255, 255);
- const video::SColor colors[] = {color, color, color, color};
- core::rect<s32> rect(0, 0, srcd.Width, srcd.Height);
- rect += p;
- driver->draw2DImage(stat_texture, rect,
- core::rect<s32>(core::position2d<s32>(0, 0), srcd),
- NULL, colors, true);
- p += v2s32(srcd.Width, 0);
+ core::rect<s32> srcrect(0, 0, srcd.Width, srcd.Height);
+ core::rect<s32> dstrect(srcrect);
+
+ dstrect += p;
+ driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true);
+ p += steppos;
}
if (count % 2 == 1)
{
- core::dimension2di srcd(stat_texture->getOriginalSize());
- const video::SColor color(255, 255, 255, 255);
- const video::SColor colors[] = {color, color, color, color};
- core::rect<s32> rect(0, 0, srcd.Width / 2, srcd.Height);
- rect += p;
- srcd.Width /= 2;
- driver->draw2DImage(stat_texture, rect,
- core::rect<s32>(core::position2d<s32>(0, 0), srcd),
- NULL, colors, true);
- p += v2s32(srcd.Width * 2, 0);
+ core::rect<s32> srcrect(0, 0, srcd.Width / 2, srcd.Height);
+ core::rect<s32> dstrect(srcrect);
+
+ dstrect += p;
+ driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true);
}
}
@@ -260,14 +277,15 @@ void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) {
v2s32 pos = centerlowerpos - v2s32(width / 2, hotbar_imagesize + padding * 2);
drawItem(pos, hotbar_imagesize, hotbar_itemcount, mainlist, playeritem + 1, 0);
- drawStatbar(pos + v2s32(0, -20), "heart.png", halfheartcount);
+ drawStatbar(pos - v2s32(0, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT,
+ "heart.png", halfheartcount);
}
void Hud::drawCrosshair() {
- driver->draw2DLine(displaycenter - v2s32(10,0),
+ driver->draw2DLine(displaycenter - v2s32(10, 0),
displaycenter + v2s32(10, 0), crosshair_argb);
- driver->draw2DLine(displaycenter - v2s32(0,10),
+ driver->draw2DLine(displaycenter - v2s32(0, 10),
displaycenter + v2s32(0, 10), crosshair_argb);
}
diff --git a/src/hud.h b/src/hud.h
index 7e00a94e3..274a669c4 100644
--- a/src/hud.h
+++ b/src/hud.h
@@ -27,6 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define HUD_DIR_TOP_BOTTOM 2
#define HUD_DIR_BOTTOM_TOP 3
+#define HUD_CORNER_UPPER 0
+#define HUD_CORNER_LOWER 1
+#define HUD_CORNER_CENTER 2
+
class Player;
enum HudElementType {
@@ -102,7 +106,7 @@ public:
void drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount,
InventoryList *mainlist, u16 selectitem, u16 direction);
void drawLuaElements();
- void drawStatbar(v2s32 upperleftpos, std::string texture, s32 count);
+ void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count);
void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem);
void resizeHotbar();
diff --git a/src/mapgen_indev.cpp b/src/mapgen_indev.cpp
index 5c842b6a5..7f0faf16f 100644
--- a/src/mapgen_indev.cpp
+++ b/src/mapgen_indev.cpp
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "constants.h"
#include "map.h"
#include "main.h"
+#include "util/numeric.h"
#include "log.h"
/////////////////// Mapgen Indev perlin noise (default values - not used, from config or defaultsettings)
@@ -154,9 +155,6 @@ void MapgenIndev::calculateNoise() {
z + 0.5 * noiseindev_float_islands3->npindev->spread.Z * farscale(noiseindev_float_islands3->npindev->farspread, x, z));
noiseindev_float_islands3->transformNoiseMapFarScale(x, y, z);
- }
-
- if (!(flags & MG_FLAT)) {
noiseindev_mud->perlinMap2D(
x + 0.5 * noiseindev_mud->npindev->spread.X * farscale(noiseindev_mud->npindev->farspread, x, y, z),
z + 0.5 * noiseindev_mud->npindev->spread.Z * farscale(noiseindev_mud->npindev->farspread, x, y, z));
@@ -256,28 +254,66 @@ float MapgenIndev::getMudAmount(int index) {
return noiseindev_mud->result[index];
}
-void MapgenIndev::defineCave(Cave & cave, PseudoRandom ps, v3s16 node_min, bool large_cave) {
- cave.min_tunnel_diameter = 2;
- cave.max_tunnel_diameter = ps.range(2,6);
- cave.dswitchint = ps.range(1,14);
- cave.flooded = large_cave && ps.range(0,4);
- if(large_cave){
- cave.part_max_length_rs = ps.range(2,4);
- if (node_min.Y < -100 && !ps.range(0, farscale(0.2, node_min.X,node_min.Y,node_min.Z)*30)) { //huge
- cave.flooded = !ps.range(0, 3);
- cave.tunnel_routepoints = ps.range(5, 30);
- cave.min_tunnel_diameter = 30;
- cave.max_tunnel_diameter = ps.range(40, ps.range(80,200));
+void MapgenIndev::generateCaves(int max_stone_y) {
+ float cave_amount = NoisePerlin2D(np_cave, node_min.X, node_min.Y, seed);
+ int volume_nodes = (node_max.X - node_min.X + 1) *
+ (node_max.Y - node_min.Y + 1) * MAP_BLOCKSIZE;
+ cave_amount = MYMAX(0.0, cave_amount);
+ u32 caves_count = cave_amount * volume_nodes / 50000;
+ u32 bruises_count = 1;
+ PseudoRandom ps(blockseed + 21343);
+ PseudoRandom ps2(blockseed + 1032);
+
+ if (ps.range(1, 6) == 1)
+ bruises_count = ps.range(0, ps.range(0, 2));
+
+ if (getBiome(v2s16(node_min.X, node_min.Z)) == BT_DESERT) {
+ caves_count /= 3;
+ bruises_count /= 3;
+ }
+
+ for (u32 i = 0; i < caves_count + bruises_count; i++) {
+ bool large_cave = (i >= caves_count);
+ CaveIndev cave(this, &ps, &ps2, node_min, large_cave,
+ c_water_source, c_lava_source);
+
+ cave.makeCave(node_min, node_max, max_stone_y);
+ }
+}
+
+CaveIndev::CaveIndev(Mapgen *mg, PseudoRandom *ps, PseudoRandom *ps2,
+ v3s16 node_min, bool is_large_cave,
+ content_t c_water, content_t c_lava) {
+ this->vm = mg->vm;
+ this->water_level = mg->water_level;
+ this->large_cave = is_large_cave;
+ this->ps = ps;
+ this->ps2 = ps2;
+ this->c_water_source = c_water;
+ this->c_lava_source = c_lava;
+
+ min_tunnel_diameter = 2;
+ max_tunnel_diameter = ps->range(2,6);
+ dswitchint = ps->range(1,14);
+ flooded = large_cave && ps->range(0,4);
+ if (large_cave) {
+ part_max_length_rs = ps->range(2,4);
+ float scale = farscale(0.2, node_min.X, node_min.Y, node_min.Z);
+ if (node_min.Y < -100 && !ps->range(0, scale * 30)) { //huge
+ flooded = !ps->range(0, 3);
+ tunnel_routepoints = ps->range(5, 30);
+ min_tunnel_diameter = 30;
+ max_tunnel_diameter = ps->range(40, ps->range(80, 200));
} else {
- cave.tunnel_routepoints = ps.range(5, ps.range(15,30));
- cave.min_tunnel_diameter = 5;
- cave.max_tunnel_diameter = ps.range(7, ps.range(8,24));
+ tunnel_routepoints = ps->range(5, ps->range(15,30));
+ min_tunnel_diameter = 5;
+ max_tunnel_diameter = ps->range(7, ps->range(8,24));
}
} else {
- cave.part_max_length_rs = ps.range(2,9);
- cave.tunnel_routepoints = ps.range(10, ps.range(15,30));
+ part_max_length_rs = ps->range(2,9);
+ tunnel_routepoints = ps->range(10, ps->range(15,30));
}
- cave.large_cave_is_flat = (ps.range(0,1) == 0);
+ large_cave_is_flat = (ps->range(0,1) == 0);
}
/*
@@ -365,7 +401,8 @@ void MapgenIndev::generateFloatIslands(int min_y) {
}
}
-void MapgenIndev::generateSomething() {
+void MapgenIndev::generateExperimental() {
int float_islands = g_settings->getS16("mgindev_float_islands");
- if(float_islands) generateFloatIslands(float_islands);
+ if (float_islands)
+ generateFloatIslands(float_islands);
}
diff --git a/src/mapgen_indev.h b/src/mapgen_indev.h
index fdac1ba20..bd6faa21c 100644
--- a/src/mapgen_indev.h
+++ b/src/mapgen_indev.h
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapgen.h"
#include "mapgen_v6.h"
+#include "cavegen.h"
float farscale(float scale, float z);
float farscale(float scale, float x, float z);
@@ -133,8 +134,9 @@ class MapgenIndev : public MapgenV6 {
float baseTerrainLevelFromNoise(v2s16 p);
float baseTerrainLevelFromMap(int index);
float getMudAmount(int index);
- void defineCave(Cave & cave, PseudoRandom ps, v3s16 node_min, bool large_cave);
- void generateSomething();
+ void generateCaves(int max_stone_y);
+ //void defineCave(Cave & cave, PseudoRandom ps, v3s16 node_min, bool large_cave);
+ void generateExperimental();
void generateFloatIslands(int min_y);
};
@@ -149,4 +151,10 @@ struct MapgenFactoryIndev : public MapgenFactoryV6 {
};
};
+class CaveIndev : public CaveV6 {
+public:
+ CaveIndev(Mapgen *mg, PseudoRandom *ps, PseudoRandom *ps2, v3s16 node_min,
+ bool is_large_cave, content_t c_water, content_t c_lava);
+};
+
#endif
diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp
index 2e44d7b4a..352afd2f3 100644
--- a/src/mapgen_v6.cpp
+++ b/src/mapgen_v6.cpp
@@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "main.h" // For g_profiler
#include "emerge.h"
#include "dungeongen.h"
+#include "cavegen.h"
#include "treegen.h"
#include "mapgen_v6.h"
@@ -423,7 +424,7 @@ void MapgenV6::makeChunk(BlockMakeData *data) {
// Generate general ground level to full area
stone_surface_max_y = generateGround();
- generateSomething();
+ generateExperimental();
const s16 max_spread_amount = MAP_BLOCKSIZE;
// Limit dirt flow area by 1 because mud is flown into neighbors.
@@ -927,35 +928,10 @@ void MapgenV6::growGrass() {
}
-void MapgenV6::defineCave(Cave &cave, PseudoRandom ps,
- v3s16 node_min, bool large_cave) {
- cave.min_tunnel_diameter = 2;
- cave.max_tunnel_diameter = ps.range(2,6);
- cave.dswitchint = ps.range(1,14);
- cave.flooded = true; //large_cave && ps.range(0,4);
- if (large_cave){
- cave.part_max_length_rs = ps.range(2,4);
- cave.tunnel_routepoints = ps.range(5, ps.range(15,30));
- cave.min_tunnel_diameter = 5;
- cave.max_tunnel_diameter = ps.range(7, ps.range(8,24));
- } else {
- cave.part_max_length_rs = ps.range(2,9);
- cave.tunnel_routepoints = ps.range(10, ps.range(15,30));
- }
- cave.large_cave_is_flat = (ps.range(0,1) == 0);
-}
-
-
void MapgenV6::generateCaves(int max_stone_y) {
- // 24ms @cs=8
- //TimeTaker timer1("caves");
-
- /*double cave_amount = 6.0 + 6.0 * noise2d_perlin(
- 0.5+(double)node_min.X/250, 0.5+(double)node_min.Y/250,
- data->seed+34329, 3, 0.50);*/
- const s16 max_spread_amount = MAP_BLOCKSIZE;
float cave_amount = NoisePerlin2D(np_cave, node_min.X, node_min.Y, seed);
-
+ int volume_nodes = (node_max.X - node_min.X + 1) *
+ (node_max.Y - node_min.Y + 1) * MAP_BLOCKSIZE;
cave_amount = MYMAX(0.0, cave_amount);
u32 caves_count = cave_amount * volume_nodes / 50000;
u32 bruises_count = 1;
@@ -970,238 +946,10 @@ void MapgenV6::generateCaves(int max_stone_y) {
bruises_count /= 3;
}
- for(u32 jj = 0; jj < caves_count + bruises_count; jj++) {
- /*int avg_height = (int)
- ((base_rock_level_2d(data->seed, v2s16(node_min.X, node_min.Z)) +
- base_rock_level_2d(data->seed, v2s16(node_max.X, node_max.Z))) / 2);
- if ((node_max.Y + node_min.Y) / 2 > avg_height)
- break;*/
-
- bool large_cave = (jj >= caves_count);
-
- Cave cave;
- defineCave(cave, ps, node_min, large_cave);
-
- v3f main_direction(0,0,0);
-
- // Allowed route area size in nodes
- v3s16 ar = central_area_size;
-
- // Area starting point in nodes
- v3s16 of = node_min;
-
- // Allow a bit more
- //(this should be more than the maximum radius of the tunnel)
- s16 insure = 10;
- s16 more = max_spread_amount - cave.max_tunnel_diameter / 2 - insure;
- ar += v3s16(1,0,1) * more * 2;
- of -= v3s16(1,0,1) * more;
-
- s16 route_y_min = 0;
- // Allow half a diameter + 7 over stone surface
- s16 route_y_max = -of.Y + max_stone_y + cave.max_tunnel_diameter/2 + 7;
-
- // Limit maximum to area
- route_y_max = rangelim(route_y_max, 0, ar.Y-1);
-
- if(large_cave)
- {
- s16 min = 0;
- if(node_min.Y < water_level && node_max.Y > water_level)
- {
- min = water_level - cave.max_tunnel_diameter/3 - of.Y;
- route_y_max = water_level + cave.max_tunnel_diameter/3 - of.Y;
- }
- route_y_min = ps.range(min, min + cave.max_tunnel_diameter);
- route_y_min = rangelim(route_y_min, 0, route_y_max);
- }
-
- s16 route_start_y_min = route_y_min;
- s16 route_start_y_max = route_y_max;
-
- route_start_y_min = rangelim(route_start_y_min, 0, ar.Y-1);
- route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y-1);
-
- // Randomize starting position
- v3f orp(
- (float)(ps.next()%ar.X)+0.5,
- (float)(ps.range(route_start_y_min, route_start_y_max))+0.5,
- (float)(ps.next()%ar.Z)+0.5
- );
-
- v3s16 startp(orp.X, orp.Y, orp.Z);
- startp += of;
-
- MapNode airnode(CONTENT_AIR);
- MapNode waternode(c_water_source);
- MapNode lavanode(c_lava_source);
+ for (u32 i = 0; i < caves_count + bruises_count; i++) {
+ bool large_cave = (i >= caves_count);
+ CaveV6 cave(this, &ps, &ps2, large_cave, c_water_source, c_lava_source);
- /*
- Generate some tunnel starting from orp
- */
-
- for(u16 j=0; j<cave.tunnel_routepoints; j++)
- {
- if(j%cave.dswitchint==0 && large_cave == false)
- {
- main_direction = v3f(
- ((float)(ps.next()%20)-(float)10)/10,
- ((float)(ps.next()%20)-(float)10)/30,
- ((float)(ps.next()%20)-(float)10)/10
- );
- main_direction *= (float)ps.range(0, 10)/10;
- }
-
- // Randomize size
- s16 min_d = cave.min_tunnel_diameter;
- s16 max_d = cave.max_tunnel_diameter;
- s16 rs = ps.range(min_d, max_d);
-
- // Every second section is rough
- bool randomize_xz = (ps2.range(1,2) == 1);
-
- v3s16 maxlen;
- if(large_cave)
- {
- maxlen = v3s16(
- rs*cave.part_max_length_rs,
- rs*cave.part_max_length_rs/2,
- rs*cave.part_max_length_rs
- );
- }
- else
- {
- maxlen = v3s16(
- rs*cave.part_max_length_rs,
- ps.range(1, rs*cave.part_max_length_rs),
- rs*cave.part_max_length_rs
- );
- }
-
- v3f vec;
-
- vec = v3f(
- (float)(ps.next()%(maxlen.X*1))-(float)maxlen.X/2,
- (float)(ps.next()%(maxlen.Y*1))-(float)maxlen.Y/2,
- (float)(ps.next()%(maxlen.Z*1))-(float)maxlen.Z/2
- );
-
- // Jump downward sometimes
- if(!large_cave && ps.range(0,12) == 0)
- {
- vec = v3f(
- (float)(ps.next()%(maxlen.X*1))-(float)maxlen.X/2,
- (float)(ps.next()%(maxlen.Y*2))-(float)maxlen.Y*2/2,
- (float)(ps.next()%(maxlen.Z*1))-(float)maxlen.Z/2
- );
- }
-
- /*if(large_cave){
- v3f p = orp + vec;
- s16 h = find_ground_level_clever(vmanip,
- v2s16(p.X, p.Z), ndef);
- route_y_min = h - rs/3;
- route_y_max = h + rs;
- }*/
-
- vec += main_direction;
-
- v3f rp = orp + vec;
- if(rp.X < 0)
- rp.X = 0;
- else if(rp.X >= ar.X)
- rp.X = ar.X-1;
- if(rp.Y < route_y_min)
- rp.Y = route_y_min;
- else if(rp.Y >= route_y_max)
- rp.Y = route_y_max-1;
- if(rp.Z < 0)
- rp.Z = 0;
- else if(rp.Z >= ar.Z)
- rp.Z = ar.Z-1;
- vec = rp - orp;
-
- float veclen = vec.getLength();
- // As odd as it sounds, veclen is *exactly*
- // 0.0 sometimes, causing a FPE
- if (veclen == 0.0)
- veclen = 1.0;
-
- for(float f=0; f<1.0; f+=1.0/veclen)
- {
- v3f fp = orp + vec * f;
- fp.X += 0.1*ps.range(-10,10);
- fp.Z += 0.1*ps.range(-10,10);
- v3s16 cp(fp.X, fp.Y, fp.Z);
-
- s16 d0 = -rs/2;
- s16 d1 = d0 + rs;
- if(randomize_xz){
- d0 += ps.range(-1,1);
- d1 += ps.range(-1,1);
- }
- for(s16 z0=d0; z0<=d1; z0++)
- {
- s16 si = rs/2 - MYMAX(0, abs(z0)-rs/7-1);
- for(s16 x0=-si-ps.range(0,1); x0<=si-1+ps.range(0,1); x0++)
- {
- s16 maxabsxz = MYMAX(abs(x0), abs(z0));
- s16 si2 = rs/2 - MYMAX(0, maxabsxz-rs/7-1);
- for(s16 y0=-si2; y0<=si2; y0++)
- {
- /*// Make better floors in small caves
- if(y0 <= -rs/2 && rs<=7)
- continue;*/
- if (cave.large_cave_is_flat) {
- // Make large caves not so tall
- if (rs > 7 && abs(y0) >= rs/3)
- continue;
- }
-
- s16 z = cp.Z + z0;
- s16 y = cp.Y + y0;
- s16 x = cp.X + x0;
- v3s16 p(x,y,z);
- p += of;
-
- if(vm->m_area.contains(p) == false)
- continue;
-
- u32 i = vm->m_area.index(p);
-
- if(large_cave) {
- if (cave.flooded && full_node_min.Y < water_level &&
- full_node_max.Y > water_level) {
- if (p.Y <= water_level)
- vm->m_data[i] = waternode;
- else
- vm->m_data[i] = airnode;
- } else if (cave.flooded && full_node_max.Y < water_level) {
- if (p.Y < startp.Y - 2)
- vm->m_data[i] = lavanode;
- else
- vm->m_data[i] = airnode;
- } else {
- vm->m_data[i] = airnode;
- }
- } else {
- // Don't replace air or water or lava or ignore
- if (vm->m_data[i].getContent() == CONTENT_IGNORE ||
- vm->m_data[i].getContent() == CONTENT_AIR ||
- vm->m_data[i].getContent() == c_water_source ||
- vm->m_data[i].getContent() == c_lava_source)
- continue;
-
- vm->m_data[i] = airnode;
-
- // Set tunnel flag
- vm->m_flags[i] |= VMANIP_FLAG_CAVE;
- }
- }
- }
- }
- }
- orp = rp;
- }
+ cave.makeCave(node_min, node_max, max_stone_y);
}
}
diff --git a/src/mapgen_v6.h b/src/mapgen_v6.h
index d37e406cb..a0276fb59 100644
--- a/src/mapgen_v6.h
+++ b/src/mapgen_v6.h
@@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapgen.h"
#define AVERAGE_MUD_AMOUNT 4
-#define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
enum BiomeType
{
@@ -43,16 +42,6 @@ extern NoiseParams nparams_v6_def_humidity;
extern NoiseParams nparams_v6_def_trees;
extern NoiseParams nparams_v6_def_apple_trees;
-struct Cave {
- s16 min_tunnel_diameter;
- s16 max_tunnel_diameter;
- int dswitchint;
- u16 tunnel_routepoints;
- int part_max_length_rs;
- bool large_cave_is_flat;
- bool flooded;
-};
-
struct MapgenV6Params : public MapgenParams {
float freq_desert;
float freq_beach;
@@ -166,10 +155,8 @@ public:
void addDirtGravelBlobs();
void growGrass();
void placeTreesAndJungleGrass();
- virtual void defineCave(Cave &cave, PseudoRandom ps,
- v3s16 node_min, bool large_cave);
- void generateCaves(int max_stone_y);
- virtual void generateSomething() {}; //for next mapgen
+ virtual void generateCaves(int max_stone_y);
+ virtual void generateExperimental() {}
};
struct MapgenFactoryV6 : public MapgenFactory {
diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp
index 8aad37f73..efcf78672 100644
--- a/src/mapgen_v7.cpp
+++ b/src/mapgen_v7.cpp
@@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "main.h" // For g_profiler
#include "emerge.h"
#include "dungeongen.h"
+#include "cavegen.h"
#include "treegen.h"
#include "biome.h"
#include "mapgen_v7.h"
@@ -114,7 +115,23 @@ MapgenV7::~MapgenV7() {
int MapgenV7::getGroundLevelAtPoint(v2s16 p) {
- return 20;
+ s16 groundlevel = baseTerrainLevelAtPoint(p.X, p.Y);
+ float heat = NoisePerlin2D(bmgr->np_heat, p.X, p.Y, seed);
+ float humidity = NoisePerlin2D(bmgr->np_humidity, p.X, p.Y, seed);
+ Biome *b = bmgr->getBiome(heat, humidity, groundlevel);
+
+ s16 y = groundlevel;
+ if (y > water_level) {
+ int iters = 1024; // don't even bother iterating more than 1024 times..
+ while (iters--) {
+ float ridgenoise = NoisePerlin3D(noise_ridge->np, p.X, y, p.Y, seed);
+ if (ridgenoise * (float)(y * y) < 15.0)
+ break;
+ y--;
+ }
+ }
+
+ return y + b->top_depth;
}
@@ -142,7 +159,7 @@ void MapgenV7::makeChunk(BlockMakeData *data) {
full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
- //blockseed = emerge->getBlockSeed(full_node_min);
+ blockseed = emerge->getBlockSeed(full_node_min); //////use getBlockSeed2()!
// Make some noise
calculateNoise();
@@ -163,14 +180,13 @@ void MapgenV7::makeChunk(BlockMakeData *data) {
c_dirt_with_grass = ndef->getId("mapgen_dirt_with_grass");
c_sand = ndef->getId("mapgen_sand");
c_water_source = ndef->getId("mapgen_water_source");
+ c_lava_source = ndef->getId("mapgen_lava_source");
generateTerrain();
carveRidges();
- //carveRivers();
+ generateCaves(stone_surface_max_y);
addTopNodes();
- growGrass();
-
//v3s16 central_area_size = node_max - node_min + v3s16(1,1,1);
if (flags & MG_DUNGEONS) {
@@ -189,7 +205,8 @@ void MapgenV7::makeChunk(BlockMakeData *data) {
calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE);
- //setLighting(node_min, node_max, 0xFF);
+ //setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
+ // node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);
this->generating = false;
}
@@ -252,7 +269,7 @@ float MapgenV7::baseTerrainLevelAtPoint(int x, int z) {
}
-float MapgenV7::baseTerrainLevelFromMap(int index) {
+float MapgenV7::baseTerrainLevelFromMap(int index) {
float terrain_mod = noise_terrain_mod->result[index];
float hselect = noise_height_select->result[index];
float terrain_base = noise_terrain_base->result[index];
@@ -395,10 +412,12 @@ 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++) {
- // First, add top nodes below the ridge
+ 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.
@@ -408,7 +427,8 @@ void MapgenV7::addTopNodes() {
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);
- if (vm->m_data[vi].getContent() != CONTENT_AIR)
+ content_t c = vm->m_data[vi].getContent();
+ if (ndef->get(c).walkable)
continue;
}
@@ -417,14 +437,13 @@ void MapgenV7::addTopNodes() {
// where a ridge had been carved
u32 i = vm->m_area.index(x, y, z);
for (; y >= node_min.Y; y--) {
- if (vm->m_data[i].getContent() != CONTENT_AIR)
+ content_t c = vm->m_data[i].getContent();
+ if (ndef->get(c).walkable)
break;
vm->m_area.add_y(em, i, -1);
}
- Biome *biome = bmgr->biomes[biomemap[index]];
-
- if (y != node_min.Y - 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++) {
@@ -432,15 +451,28 @@ void MapgenV7::addTopNodes() {
vm->m_data[i] = MapNode(biome->c_top);
vm->m_area.add_y(em, i, 1);
}
- //heightmap[index] = y;
+ // If dirt, grow grass on it.
+ if (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
+ //////////////////// 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--) {
- if (vm->m_data[i].getContent() != CONTENT_AIR)
+ content_t c = vm->m_data[i].getContent();
+ if (ndef->get(c).walkable)
break;
vm->m_area.add_y(em, i, -1);
}
@@ -456,35 +488,36 @@ void MapgenV7::addTopNodes() {
vm->m_data[i] = MapNode(biome->c_top);
vm->m_area.add_y(em, i, 1);
}
+ // If dirt, grow grass on it.
+ if (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);
+ }
}
}
}
-void MapgenV7::growGrass() {
- for (s16 z = node_min.Z; z <= node_max.Z; z++)
- for (s16 x = node_min.X; x <= node_max.X; x++) {
- // Find the lowest surface to which enough light ends up to make
- // grass grow. Basically just wait until not air and not leaves.
- s16 surface_y = 0;
- {
- v3s16 em = vm->m_area.getExtent();
- u32 i = vm->m_area.index(x, node_max.Y, z);
- s16 y;
- // Go to ground level
- for (y = node_max.Y; y >= node_min.Y; y--) {
- MapNode &n = vm->m_data[i];
- if (ndef->get(n).param_type != CPT_LIGHT ||
- ndef->get(n).liquid_type != LIQUID_NONE)
- break;
- vm->m_area.add_y(em, i, -1);
- }
- surface_y = (y >= node_min.Y) ? y : node_min.Y;
- }
+#include "mapgen_v6.h"
+void MapgenV7::generateCaves(int max_stone_y) {
+ PseudoRandom ps(blockseed + 21343);
+ PseudoRandom ps2(blockseed + 1032);
- u32 i = vm->m_area.index(x, surface_y, z);
- MapNode *n = &vm->m_data[i];
- if (n->getContent() == c_dirt && surface_y >= water_level - 20)
- n->setContent(c_dirt_with_grass);
+ int volume_nodes = (node_max.X - node_min.X + 1) *
+ (node_max.Y - node_min.Y + 1) * MAP_BLOCKSIZE;
+ float cave_amount = NoisePerlin2D(&nparams_v6_def_cave,
+ node_min.X, node_min.Y, seed);
+
+ u32 caves_count = MYMAX(0.0, cave_amount) * volume_nodes / 50000;
+ for (u32 i = 0; i < caves_count; i++) {
+ CaveV6 cave(this, &ps, &ps2, false, c_water_source, c_lava_source);
+ cave.makeCave(node_min, node_max, max_stone_y);
}
+
+ u32 bruises_count = (ps.range(1, 6) == 1) ? ps.range(0, ps.range(0, 2)) : 1;
+ for (u32 i = 0; i < bruises_count; i++) {
+ CaveV6 cave(this, &ps, &ps2, true, c_water_source, c_lava_source);
+ cave.makeCave(node_min, node_max, max_stone_y);
+ }
}
diff --git a/src/mapgen_v7.h b/src/mapgen_v7.h
index 73fa9be03..3391098ea 100644
--- a/src/mapgen_v7.h
+++ b/src/mapgen_v7.h
@@ -109,7 +109,8 @@ public:
void testBiomes();
void addTopNodes();
- void growGrass();
+
+ void generateCaves(int max_stone_y);
};
struct MapgenFactoryV7 : public MapgenFactory {
diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp
index 531bb7a58..9152c9eb3 100644
--- a/src/scriptapi_object.cpp
+++ b/src/scriptapi_object.cpp
@@ -749,7 +749,7 @@ int ObjectRef::l_hud_add(lua_State *L)
elem->text = getstringfield_default(L, 2, "text", "");
elem->number = getintfield_default(L, 2, "number", 0);
elem->item = getintfield_default(L, 2, "item", 0);
- elem->dir = getintfield_default(L, 2, "dir", 0);
+ elem->dir = getintfield_default(L, 2, "direction", 0);
u32 id = get_server(L)->hudAdd(player, elem);
if (id == (u32)-1) {
@@ -788,15 +788,17 @@ int ObjectRef::l_hud_change(lua_State *L)
if (player == NULL)
return 0;
- u32 id = -1;
- if (!lua_isnil(L, 2))
- id = lua_tonumber(L, 2);
-
- HudElementStat stat = (HudElementStat)getenumfield(L, 3, "stat",
- es_HudElementStat, HUD_STAT_NUMBER);
-
+ u32 id = !lua_isnil(L, 2) ? lua_tonumber(L, 2) : -1;
if (id >= player->hud.size())
return 0;
+
+ HudElementStat stat = HUD_STAT_NUMBER;
+ if (!lua_isnil(L, 3)) {
+ int statint;
+ std::string statstr = lua_tostring(L, 3);
+ stat = string_to_enum(es_HudElementStat, statint, statstr) ?
+ (HudElementStat)statint : HUD_STAT_NUMBER;
+ }
void *value = NULL;
HudElement *e = player->hud[id];
@@ -832,7 +834,7 @@ int ObjectRef::l_hud_change(lua_State *L)
e->dir = lua_tonumber(L, 4);
value = &e->dir;
}
-
+
get_server(L)->hudChange(player, id, stat, value);
lua_pushboolean(L, true);
diff --git a/src/server.cpp b/src/server.cpp
index 241826ba2..7fad623c2 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -4951,36 +4951,28 @@ v3f findSpawnPos(ServerMap &map)
{
s32 range = 1 + i;
// We're going to try to throw the player to this position
- v2s16 nodepos2d = v2s16(-range + (myrand()%(range*2)),
- -range + (myrand()%(range*2)));
- //v2s16 sectorpos = getNodeSectorPos(nodepos2d);
- // Get ground height at point (fallbacks to heightmap function)
+ v2s16 nodepos2d = v2s16(
+ -range + (myrand() % (range * 2)),
+ -range + (myrand() % (range * 2)));
+
+ // Get ground height at point
s16 groundheight = map.findGroundLevel(nodepos2d);
- // Don't go underwater
- if(groundheight <= water_level)
- {
- //infostream<<"-> Underwater"<<std::endl;
+ if (groundheight <= water_level) // Don't go underwater
continue;
- }
- // Don't go to high places
- if(groundheight > water_level + 6)
- {
- //infostream<<"-> Underwater"<<std::endl;
+ if (groundheight > water_level + 6) // Don't go to high places
continue;
- }
- nodepos = v3s16(nodepos2d.X, groundheight-2, nodepos2d.Y);
+ nodepos = v3s16(nodepos2d.X, groundheight, nodepos2d.Y);
bool is_good = false;
s32 air_count = 0;
- for(s32 i=0; i<10; i++){
+ for (s32 i = 0; i < 10; i++) {
v3s16 blockpos = getNodeBlockPos(nodepos);
map.emergeBlock(blockpos, true);
- MapNode n = map.getNodeNoEx(nodepos);
- if(n.getContent() == CONTENT_AIR){
+ content_t c = map.getNodeNoEx(nodepos).getContent();
+ if (c == CONTENT_AIR || c == CONTENT_IGNORE) {
air_count++;
- if(air_count >= 2){
+ if (air_count >= 2){
is_good = true;
- nodepos.Y -= 1;
break;
}
}