From 85f119e1e6cc958a54eaf8468f2a302aa8c60dbe Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Tue, 16 Aug 2011 02:14:49 -0700 Subject: Adding (most) of the sapling functionality. It has yet to work, since MEET_OTHER was not implemented at the time of this commit. Hopefully it will work when merged with celeron's latest. --- src/environment.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/environment.cpp') diff --git a/src/environment.cpp b/src/environment.cpp index 8103b7110..93f1627c5 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "serverobject.h" #include "content_sao.h" +#include "mapgen.h" Environment::Environment(): m_time_of_day(9000) @@ -922,7 +923,34 @@ void ServerEnvironment::step(float dtime) addActiveObject(obj); } } - } + } + /* + Make trees from saplings! + */ + if(n.getContent() == CONTENT_SAPLING) + { + if(myrand()%2 == 0) + { + core::map modified_blocks; + v3s16 tree_p = p; + MapEditEvent event; + event.type = MEET_OTHER; + ManualMapVoxelManipulator vmanip(m_map); + v3s16 tree_blockp = getNodeBlockPos(tree_p); + vmanip.initialEmerge(tree_blockp - v3s16(1,1,1), tree_blockp + v3s16(1,1,1)); + bool is_apple_tree = myrand()%4 == 0; + mapgen::make_tree(vmanip, tree_p, is_apple_tree); + for(core::map::Iterator + i = modified_blocks.getIterator(); + i.atEnd() == false; i++) + { + v3s16 p = i.getNode()->getKey(); + event.modified_blocks.insert(p, true); + } + m_map->dispatchEvent(&event); + } + } + } } } -- cgit v1.2.3 From 319f43e6d2d59b6062b3643b8cb26f4153cbc750 Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Fri, 23 Sep 2011 07:27:57 -0700 Subject: Fixed saplings growing into trees (thanks so much, Kahrl!) Put the random interval back to 1 in 50 chance. It's not as rare as rats, but rarer than grass. --- src/environment.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/environment.cpp') diff --git a/src/environment.cpp b/src/environment.cpp index 93f1627c5..71fceae28 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -929,17 +929,30 @@ void ServerEnvironment::step(float dtime) */ if(n.getContent() == CONTENT_SAPLING) { - if(myrand()%2 == 0) + if(myrand()%50 == 0) { core::map modified_blocks; v3s16 tree_p = p; - MapEditEvent event; - event.type = MEET_OTHER; ManualMapVoxelManipulator vmanip(m_map); v3s16 tree_blockp = getNodeBlockPos(tree_p); vmanip.initialEmerge(tree_blockp - v3s16(1,1,1), tree_blockp + v3s16(1,1,1)); bool is_apple_tree = myrand()%4 == 0; mapgen::make_tree(vmanip, tree_p, is_apple_tree); + vmanip.blitBackAll(&modified_blocks); + + // update lighting + core::map lighting_modified_blocks; + for(core::map::Iterator + i = modified_blocks.getIterator(); + i.atEnd() == false; i++) + { + lighting_modified_blocks.insert(i.getNode()->getKey(), i.getNode()->getValue()); + } + m_map->updateLighting(lighting_modified_blocks, modified_blocks); + + // Send a MEET_OTHER event + MapEditEvent event; + event.type = MEET_OTHER; for(core::map::Iterator i = modified_blocks.getIterator(); i.atEnd() == false; i++) -- cgit v1.2.3