From 7538b4c6201675c566c98b21c8ecddb798a14943 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 25 Jun 2011 04:25:14 +0300 Subject: New map generator added (and SQLite, messed up the commits at that time...) (import from temporary git repo) --- src/environment.cpp | 128 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 53 deletions(-) (limited to 'src/environment.cpp') diff --git a/src/environment.cpp b/src/environment.cpp index 8f8628305..9bbba08b0 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -579,6 +579,64 @@ 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 "<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.XgetPosRelative(); + MapNode n = block->getNodeNoEx(p0); + // 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); + } + } + } + } +} + void ServerEnvironment::step(float dtime) { DSTACK(__FUNCTION_NAME); @@ -715,60 +773,8 @@ 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(); - if(m_game_time > stamp && stamp != BLOCK_TIMESTAMP_UNDEFINED) - dtime_s = m_game_time - block->getTimestamp(); - - // Set current time as timestamp (and let it set ChangedFlag) - block->setTimestamp(m_game_time); - - //dstream<<"Block is "<m_node_metadata.step((float)dtime_s); - if(changed) - { - MapEditEvent event; - event.type = MEET_BLOCK_NODE_METADATA_CHANGED; - event.p = p; - 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.XgetPosRelative(); - MapNode n = block->getNodeNoEx(p0); - // 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); - } - } - } - } + activateBlock(block); } } @@ -867,6 +873,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); + } + } + } } } } -- cgit v1.2.3