2011-11-27 23:45:34 +01:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-11-27 23:45:34 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
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
|
2011-11-27 23:45:34 +01:00
|
|
|
(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
|
2012-06-05 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-11-27 23:45:34 +01:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-11-27 23:45:34 +01:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "content_abm.h"
|
|
|
|
|
|
|
|
#include "environment.h"
|
|
|
|
#include "gamedef.h"
|
|
|
|
#include "nodedef.h"
|
|
|
|
#include "content_sao.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "mapblock.h" // For getNodeBlockPos
|
2012-12-29 16:20:09 +01:00
|
|
|
#include "treegen.h" // For treegen::make_tree
|
2013-02-24 15:39:07 +01:00
|
|
|
#include "main.h" // for g_settings
|
2012-07-26 21:06:45 +02:00
|
|
|
#include "map.h"
|
2011-11-27 23:45:34 +01:00
|
|
|
|
|
|
|
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
|
|
|
|
|
|
|
|
class GrowGrassABM : public ActiveBlockModifier
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
virtual std::set<std::string> getTriggerContents()
|
|
|
|
{
|
|
|
|
std::set<std::string> s;
|
2013-01-02 22:03:36 +01:00
|
|
|
s.insert("mapgen_dirt");
|
2011-11-27 23:45:34 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
virtual float getTriggerInterval()
|
2011-11-29 22:22:44 +01:00
|
|
|
{ return 2.0; }
|
2011-11-27 23:45:34 +01:00
|
|
|
virtual u32 getTriggerChance()
|
2011-11-29 22:22:44 +01:00
|
|
|
{ return 200; }
|
2011-11-27 23:45:34 +01:00
|
|
|
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n)
|
|
|
|
{
|
|
|
|
INodeDefManager *ndef = env->getGameDef()->ndef();
|
|
|
|
ServerMap *map = &env->getServerMap();
|
|
|
|
|
|
|
|
MapNode n_top = map->getNodeNoEx(p+v3s16(0,1,0));
|
2013-04-23 19:02:41 +02:00
|
|
|
content_t c_snow = ndef->getId("snow");
|
2011-11-27 23:45:34 +01:00
|
|
|
if(ndef->get(n_top).light_propagates &&
|
|
|
|
!ndef->get(n_top).isLiquid() &&
|
|
|
|
n_top.getLightBlend(env->getDayNightRatio(), ndef) >= 13)
|
|
|
|
{
|
2013-04-23 19:02:41 +02:00
|
|
|
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"));
|
2011-11-27 23:45:34 +01:00
|
|
|
map->addNodeWithEvent(p, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class RemoveGrassABM : public ActiveBlockModifier
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
virtual std::set<std::string> getTriggerContents()
|
|
|
|
{
|
|
|
|
std::set<std::string> s;
|
2013-01-02 22:03:36 +01:00
|
|
|
s.insert("mapgen_dirt_with_grass");
|
2011-11-27 23:45:34 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
virtual float getTriggerInterval()
|
2011-11-29 22:22:44 +01:00
|
|
|
{ return 2.0; }
|
2011-11-27 23:45:34 +01:00
|
|
|
virtual u32 getTriggerChance()
|
2011-11-29 22:22:44 +01:00
|
|
|
{ return 20; }
|
2011-11-27 23:45:34 +01:00
|
|
|
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n)
|
|
|
|
{
|
|
|
|
INodeDefManager *ndef = env->getGameDef()->ndef();
|
|
|
|
ServerMap *map = &env->getServerMap();
|
|
|
|
|
|
|
|
MapNode n_top = map->getNodeNoEx(p+v3s16(0,1,0));
|
2013-01-20 16:21:09 +01:00
|
|
|
if((!ndef->get(n_top).light_propagates &&
|
|
|
|
n_top.getContent() != CONTENT_IGNORE) ||
|
2011-11-27 23:45:34 +01:00
|
|
|
ndef->get(n_top).isLiquid())
|
|
|
|
{
|
2013-01-03 23:32:31 +01:00
|
|
|
n.setContent(ndef->getId("mapgen_dirt"));
|
2011-11-27 23:45:34 +01:00
|
|
|
map->addNodeWithEvent(p, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MakeTreesFromSaplingsABM : public ActiveBlockModifier
|
|
|
|
{
|
|
|
|
private:
|
2013-03-17 00:37:27 +01:00
|
|
|
content_t c_junglesapling;
|
|
|
|
|
2011-11-27 23:45:34 +01:00
|
|
|
public:
|
2013-03-17 00:37:27 +01:00
|
|
|
MakeTreesFromSaplingsABM(ServerEnvironment *env, INodeDefManager *nodemgr) {
|
2013-04-14 09:01:27 +02:00
|
|
|
c_junglesapling = nodemgr->getId("junglesapling");
|
2013-03-17 00:37:27 +01:00
|
|
|
}
|
|
|
|
|
2011-11-27 23:45:34 +01:00
|
|
|
virtual std::set<std::string> getTriggerContents()
|
|
|
|
{
|
|
|
|
std::set<std::string> s;
|
|
|
|
s.insert("sapling");
|
2013-03-16 22:06:11 +01:00
|
|
|
s.insert("junglesapling");
|
2011-11-27 23:45:34 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
virtual float getTriggerInterval()
|
|
|
|
{ return 10.0; }
|
|
|
|
virtual u32 getTriggerChance()
|
|
|
|
{ return 50; }
|
|
|
|
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
|
|
|
|
u32 active_object_count, u32 active_object_count_wider)
|
|
|
|
{
|
|
|
|
INodeDefManager *ndef = env->getGameDef()->ndef();
|
|
|
|
ServerMap *map = &env->getServerMap();
|
|
|
|
|
2013-03-17 00:37:27 +01:00
|
|
|
MapNode n_below = map->getNodeNoEx(p - v3s16(0, 1, 0));
|
2013-04-14 09:01:27 +02:00
|
|
|
if (!((ItemGroupList) ndef->get(n_below).groups)["soil"])
|
2013-03-17 00:37:27 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
bool is_jungle_tree = n.getContent() == c_junglesapling;
|
2013-03-16 22:06:11 +01:00
|
|
|
|
|
|
|
actionstream <<"A " << (is_jungle_tree ? "jungle " : "")
|
|
|
|
<< "sapling grows into a tree at "
|
|
|
|
<< PP(p) << std::endl;
|
2011-11-27 23:45:34 +01:00
|
|
|
|
2012-12-20 18:19:49 +01:00
|
|
|
std::map<v3s16, MapBlock*> modified_blocks;
|
2011-11-27 23:45:34 +01:00
|
|
|
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));
|
2013-03-16 22:06:11 +01:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2011-11-27 23:45:34 +01:00
|
|
|
vmanip.blitBackAll(&modified_blocks);
|
|
|
|
|
|
|
|
// update lighting
|
2012-12-20 18:19:49 +01:00
|
|
|
std::map<v3s16, MapBlock*> lighting_modified_blocks;
|
|
|
|
lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
|
2011-11-27 23:45:34 +01:00
|
|
|
map->updateLighting(lighting_modified_blocks, modified_blocks);
|
|
|
|
|
|
|
|
// Send a MEET_OTHER event
|
|
|
|
MapEditEvent event;
|
|
|
|
event.type = MEET_OTHER;
|
2012-12-20 18:19:49 +01:00
|
|
|
// 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)
|
2011-11-27 23:45:34 +01:00
|
|
|
{
|
2012-12-20 18:19:49 +01:00
|
|
|
event.modified_blocks.insert(i->first);
|
2011-11-27 23:45:34 +01:00
|
|
|
}
|
|
|
|
map->dispatchEvent(&event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-24 15:39:07 +01:00
|
|
|
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();
|
2013-05-31 20:57:59 +02:00
|
|
|
if (map->transforming_liquid_size() > 500)
|
|
|
|
return;
|
|
|
|
map->transforming_liquid_add(p);
|
2013-02-24 15:39:07 +01:00
|
|
|
//if ((*map).m_transforming_liquid.size() < 500) (*map).m_transforming_liquid.push_back(p);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-31 20:57:59 +02:00
|
|
|
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;
|
2013-06-29 23:29:21 +02:00
|
|
|
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
|
|
|
|
)
|
2013-05-31 20:57:59 +02:00
|
|
|
return;
|
|
|
|
map->transforming_liquid_add(p);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-27 23:45:34 +01:00
|
|
|
void add_legacy_abms(ServerEnvironment *env, INodeDefManager *nodedef)
|
|
|
|
{
|
|
|
|
env->addActiveBlockModifier(new GrowGrassABM());
|
|
|
|
env->addActiveBlockModifier(new RemoveGrassABM());
|
2013-03-17 00:37:27 +01:00
|
|
|
env->addActiveBlockModifier(new MakeTreesFromSaplingsABM(env, nodedef));
|
2013-05-31 20:57:59 +02:00
|
|
|
if (g_settings->getBool("liquid_finite")) {
|
2013-02-24 15:39:07 +01:00
|
|
|
env->addActiveBlockModifier(new LiquidFlowABM(env, nodedef));
|
2013-05-31 20:57:59 +02:00
|
|
|
env->addActiveBlockModifier(new LiquidDropABM(env, nodedef));
|
|
|
|
}
|
2011-11-27 23:45:34 +01:00
|
|
|
}
|