]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/content_abm.cpp
Bump protocol version
[dragonfireclient.git] / src / content_abm.cpp
index cbfdd2e9f8a1aa3b74a4db189286d790bad7765d..6adcbf708ef94c328957654216c2fb6fb3da6526 100644 (file)
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "settings.h"
 #include "mapblock.h" // For getNodeBlockPos
 #include "treegen.h" // For treegen::make_tree
+#include "main.h" // for g_settings
 #include "map.h"
 
 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@@ -50,11 +51,15 @@ class GrowGrassABM : public ActiveBlockModifier
                ServerMap *map = &env->getServerMap();
                
                MapNode n_top = map->getNodeNoEx(p+v3s16(0,1,0));
+               content_t c_snow = ndef->getId("snow");
                if(ndef->get(n_top).light_propagates &&
                                !ndef->get(n_top).isLiquid() &&
                                n_top.getLightBlend(env->getDayNightRatio(), ndef) >= 13)
                {
-                       n.setContent(ndef->getId("mapgen_dirt_with_grass"));
+                       if(c_snow != CONTENT_IGNORE && n_top.getContent() == c_snow)
+                               n.setContent(ndef->getId("dirt_with_snow"));
+                       else
+                               n.setContent(ndef->getId("mapgen_dirt_with_grass"));
                        map->addNodeWithEvent(p, n);
                }
        }
@@ -93,11 +98,18 @@ class RemoveGrassABM : public ActiveBlockModifier
 class MakeTreesFromSaplingsABM : public ActiveBlockModifier
 {
 private:
+       content_t c_junglesapling;
+       
 public:
+       MakeTreesFromSaplingsABM(ServerEnvironment *env, INodeDefManager *nodemgr) {
+               c_junglesapling = nodemgr->getId("junglesapling");
+       }
+
        virtual std::set<std::string> getTriggerContents()
        {
                std::set<std::string> s;
                s.insert("sapling");
+               s.insert("junglesapling");
                return s;
        }
        virtual float getTriggerInterval()
@@ -110,47 +122,130 @@ class MakeTreesFromSaplingsABM : public ActiveBlockModifier
                INodeDefManager *ndef = env->getGameDef()->ndef();
                ServerMap *map = &env->getServerMap();
                
-               actionstream<<"A sapling grows into a tree at "
-                               <<PP(p)<<std::endl;
+               MapNode n_below = map->getNodeNoEx(p - v3s16(0, 1, 0));
+               if (!((ItemGroupList) ndef->get(n_below).groups)["soil"])
+                       return;
+                       
+               bool is_jungle_tree = n.getContent() == c_junglesapling;
+               
+               actionstream <<"A " << (is_jungle_tree ? "jungle " : "")
+                               << "sapling grows into a tree at "
+                               << PP(p) << std::endl;
 
-               core::map<v3s16, MapBlock*> modified_blocks;
+               std::map<v3s16, MapBlock*> modified_blocks;
                v3s16 tree_p = p;
                ManualMapVoxelManipulator vmanip(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;
-               treegen::make_tree(vmanip, tree_p, is_apple_tree, ndef, myrand());
+               
+               if (is_jungle_tree) {
+                       treegen::make_jungletree(vmanip, tree_p, ndef, myrand());
+               } else {
+                       bool is_apple_tree = myrand() % 4 == 0;
+                       treegen::make_tree(vmanip, tree_p, is_apple_tree, ndef, myrand());
+               }
+               
                vmanip.blitBackAll(&modified_blocks);
 
                // update lighting
-               core::map<v3s16, MapBlock*> lighting_modified_blocks;
-               for(core::map<v3s16, MapBlock*>::Iterator
-                       i = modified_blocks.getIterator();
-                       i.atEnd() == false; i++)
-               {
-                       lighting_modified_blocks.insert(i.getNode()->getKey(), i.getNode()->getValue());
-               }
+               std::map<v3s16, MapBlock*> lighting_modified_blocks;
+               lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
                map->updateLighting(lighting_modified_blocks, modified_blocks);
 
                // Send a MEET_OTHER event
                MapEditEvent event;
                event.type = MEET_OTHER;
-               for(core::map<v3s16, MapBlock*>::Iterator
-                       i = modified_blocks.getIterator();
-                       i.atEnd() == false; i++)
+//             event.modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
+               for(std::map<v3s16, MapBlock*>::iterator
+                       i = modified_blocks.begin();
+                       i != modified_blocks.end(); ++i)
                {
-                       v3s16 p = i.getNode()->getKey();
-                       event.modified_blocks.insert(p, true);
+                       event.modified_blocks.insert(i->first);
                }
                map->dispatchEvent(&event);
        }
 };
 
+class LiquidFlowABM : public ActiveBlockModifier
+{
+private:
+       std::set<std::string> contents;
+
+public:
+       LiquidFlowABM(ServerEnvironment *env, INodeDefManager *nodemgr) 
+       {
+               std::set<content_t> liquids;
+               nodemgr->getIds("group:liquid", liquids);
+               for(std::set<content_t>::const_iterator k = liquids.begin(); k != liquids.end(); k++)
+                       contents.insert(nodemgr->get(*k).liquid_alternative_flowing);
+               
+       }
+       virtual std::set<std::string> getTriggerContents()
+       {
+               return contents;
+       }
+       virtual float getTriggerInterval()
+       { return 10.0; }
+       virtual u32 getTriggerChance()
+       { return 10; }
+       virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n)
+       {
+               ServerMap *map = &env->getServerMap();
+               if (map->transforming_liquid_size() > 500)
+                       return;
+               map->transforming_liquid_add(p);
+               //if ((*map).m_transforming_liquid.size() < 500) (*map).m_transforming_liquid.push_back(p);
+       }
+};
+
+class LiquidDropABM : public ActiveBlockModifier
+{
+private:
+       std::set<std::string> contents;
+
+public:
+       LiquidDropABM(ServerEnvironment *env, INodeDefManager *nodemgr) 
+       {
+               std::set<content_t> liquids;
+               nodemgr->getIds("group:liquid", liquids);
+               for(std::set<content_t>::const_iterator k = liquids.begin(); k != liquids.end(); k++)
+                       contents.insert(nodemgr->get(*k).liquid_alternative_source);
+       }
+       virtual std::set<std::string> getTriggerContents()
+       { return contents; }
+       virtual std::set<std::string> getRequiredNeighbors()
+       {
+               std::set<std::string> neighbors;
+               neighbors.insert("mapgen_air");
+               return neighbors; 
+       }
+       virtual float getTriggerInterval()
+       { return 20.0; }
+       virtual u32 getTriggerChance()
+       { return 10; }
+       virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n) 
+       {
+               ServerMap *map = &env->getServerMap();
+               if (map->transforming_liquid_size() > 500)
+                       return;
+               if (       map->getNodeNoEx(p - v3s16(0,  1, 0 )).getContent() != CONTENT_AIR  // below
+                       && map->getNodeNoEx(p - v3s16(1,  0, 0 )).getContent() != CONTENT_AIR  // right
+                       && map->getNodeNoEx(p - v3s16(-1, 0, 0 )).getContent() != CONTENT_AIR  // left
+                       && map->getNodeNoEx(p - v3s16(0,  0, 1 )).getContent() != CONTENT_AIR  // back 
+                       && map->getNodeNoEx(p - v3s16(0,  0, -1)).getContent() != CONTENT_AIR  // front
+               )
+                       return;
+               map->transforming_liquid_add(p);
+       }
+};
+
 void add_legacy_abms(ServerEnvironment *env, INodeDefManager *nodedef)
 {
        env->addActiveBlockModifier(new GrowGrassABM());
        env->addActiveBlockModifier(new RemoveGrassABM());
-       env->addActiveBlockModifier(new MakeTreesFromSaplingsABM());
+       env->addActiveBlockModifier(new MakeTreesFromSaplingsABM(env, nodedef));
+       if (g_settings->getBool("liquid_finite")) {
+               env->addActiveBlockModifier(new LiquidFlowABM(env, nodedef));
+               env->addActiveBlockModifier(new LiquidDropABM(env, nodedef));
+       }
 }
-
-