]> git.lizzy.rs Git - minetest.git/blobdiff - src/environment.cpp
Merge pull request #13 from Bahamada/upstream_merge
[minetest.git] / src / environment.cpp
index 798228802dd27300d7245e70d23bc0b006adb11e..e2c704259888323064063c0bf7a4a78b8e7aeab0 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "filesys.h"
 #include "porting.h"
 #include "collision.h"
+#include "content_mapnode.h"
 
 
 Environment::Environment():
@@ -578,6 +579,66 @@ void spawnRandomObjects(MapBlock *block)
 }
 #endif
 
+void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
+{
+       // Get time difference
+       u32 dtime_s = 0;
+       u32 stamp = block->getTimestamp();
+       if(m_game_time > stamp && stamp != BLOCK_TIMESTAMP_UNDEFINED)
+               dtime_s = m_game_time - block->getTimestamp();
+       dtime_s += additional_dtime;
+
+       // Set current time as timestamp (and let it set ChangedFlag)
+       block->setTimestamp(m_game_time);
+
+       //dstream<<"Block is "<<dtime_s<<" seconds old."<<std::endl;
+
+       // Activate stored objects
+       activateObjects(block);
+
+       // Run node metadata
+       bool changed = block->m_node_metadata.step((float)dtime_s);
+       if(changed)
+       {
+               MapEditEvent event;
+               event.type = MEET_BLOCK_NODE_METADATA_CHANGED;
+               event.p = block->getPos();
+               m_map->dispatchEvent(&event);
+
+               block->setChangedFlag();
+       }
+
+       // TODO: Do something
+       // TODO: Implement usage of ActiveBlockModifier
+
+       // Here's a quick demonstration
+       v3s16 p0;
+       for(p0.X=0; p0.X<MAP_BLOCKSIZE; p0.X++)
+       for(p0.Y=0; p0.Y<MAP_BLOCKSIZE; p0.Y++)
+       for(p0.Z=0; p0.Z<MAP_BLOCKSIZE; p0.Z++)
+       {
+               v3s16 p = p0 + block->getPosRelative();
+               MapNode n = block->getNodeNoEx(p0);
+#if 1
+               // Test something:
+               // Convert all mud under proper day lighting to grass
+               if(n.d == CONTENT_MUD)
+               {
+                       if(dtime_s > 300)
+                       {
+                               MapNode n_top = block->getNodeNoEx(p0+v3s16(0,1,0));
+                               if(content_features(n_top.d).air_equivalent &&
+                                               n_top.getLight(LIGHTBANK_DAY) >= 13)
+                               {
+                                       n.d = CONTENT_GRASS;
+                                       m_map->addNodeWithEvent(p, n);
+                               }
+                       }
+               }
+#endif
+       }
+}
+
 void ServerEnvironment::step(float dtime)
 {
        DSTACK(__FUNCTION_NAME);
@@ -693,8 +754,8 @@ void ServerEnvironment::step(float dtime)
                        MapBlock *block = m_map->getBlockNoCreateNoEx(p);
                        if(block==NULL)
                                continue;
-                       
                        // Set current time as timestamp (and let it set ChangedFlag)
+
                        block->setTimestamp(m_game_time);
                }
 
@@ -714,7 +775,7 @@ void ServerEnvironment::step(float dtime)
                        MapBlock *block = m_map->getBlockNoCreateNoEx(p);
                        if(block==NULL)
                                continue;
-                       
+
                        // Get time difference
                        u32 dtime_s = 0;
                        u32 stamp = block->getTimestamp();
@@ -725,7 +786,7 @@ void ServerEnvironment::step(float dtime)
                        block->setTimestamp(m_game_time);
 
                        //dstream<<"Block is "<<dtime_s<<" seconds old."<<std::endl;
-                       
+
                        // Activate stored objects
                        activateObjects(block);
 
@@ -743,7 +804,7 @@ void ServerEnvironment::step(float dtime)
 
                        // TODO: Do something
                        // TODO: Implement usage of ActiveBlockModifier
-                       
+
                        // Here's a quick demonstration
                        v3s16 p0;
                        for(p0.X=0; p0.X<MAP_BLOCKSIZE; p0.X++)
@@ -767,6 +828,22 @@ void ServerEnvironment::step(float dtime)
                                                }
                                        }
                                }
+                               /*
+                                       Convert grass into mud if under something else than air
+                               */
+                               else if(n.d == CONTENT_GRASS)
+                               {
+                                       //if(myrand()%20 == 0)
+                                       {
+                                               MapNode n_top = block->getNodeNoEx(p0+v3s16(0,1,0));
+                                               if(n_top.d != CONTENT_AIR
+                                                               && n_top.d != CONTENT_IGNORE)
+                                               {
+                                                       n.d = CONTENT_MUD;
+                                                       m_map->addNodeWithEvent(p, n);
+                                               }
+                                       }
+                               }
                        }
                }
        }
@@ -866,6 +943,22 @@ void ServerEnvironment::step(float dtime)
                                                }
                                        }
                                }
+                               /*
+                                       Convert grass into mud if under something else than air
+                               */
+                               else if(n.d == CONTENT_GRASS)
+                               {
+                                       //if(myrand()%20 == 0)
+                                       {
+                                               MapNode n_top = block->getNodeNoEx(p0+v3s16(0,1,0));
+                                               if(n_top.d != CONTENT_AIR
+                                                               && n_top.d != CONTENT_IGNORE)
+                                               {
+                                                       n.d = CONTENT_MUD;
+                                                       m_map->addNodeWithEvent(p, n);
+                                               }
+                                               }
+                                       }
                        }
                }
        }