Showing with 189 additions and 133 deletions.
  1. +16 −2 doc/lua_api.txt
  2. +21 −16 src/biome.cpp
  3. +2 −2 src/biome.h
  4. +0 −7 src/constants.h
  5. +63 −33 src/content_abm.cpp
  6. +7 −0 src/emerge.cpp
  7. +17 −18 src/environment.cpp
  8. +6 −2 src/environment.h
  9. +3 −3 src/game.cpp
  10. +33 −43 src/map.cpp
  11. +2 −2 src/map.h
  12. +4 −1 src/mapnode.cpp
  13. +4 −1 src/script/cpp_api/s_env.cpp
  14. +3 −2 src/script/lua_api/l_env.cpp
  15. +8 −1 src/script/lua_api/l_env.h
18 changes: 16 additions & 2 deletions doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,18 @@ Known damage and digging time defining groups
speed of a tool if the tool can dig at a faster speed than this
suggests for the hand.

Freezing and melting groups
---------------------------
All values - temperature in celsius, do not forget define freezemelt.
Do not use value=0, groups with =0 ignored
Not recomended hot>melt and cold<freeze - it will cause chain reactions
- freeze: for liquids, transform to something defined in freezemelt
if temperature lower than value
- melt: for non-liquids, transform to liquid defined in freezemelt
if temperature higher than value
- hot: melt nodes around, if their melt lower than value
- cold: freeze liquid nodes around, if their freeze higher than value

Examples of custom groups
--------------------------
Item groups are often used for defining, well, //groups of items//.
Expand Down Expand Up @@ -2006,10 +2018,12 @@ ABM (ActiveBlockModifier) definition (register_abm)
-- In the following two fields, also group:groupname will work.
nodenames = {"default:lava_source"},
neighbors = {"default:water_source", "default:water_flowing"}, -- (any of these)
^ If left out or empty, any neighbor will do
^ If left out or empty, any neighbor will do
neighbors_range = 1,
^ find neighbors in max range from node, do not set big values (>3) - it can eat cpu
interval = 1.0, -- (operation interval)
chance = 1, -- (chance of trigger is 1.0/this)
action = func(pos, node, active_object_count, active_object_count_wider),
action = func(pos, node, active_object_count, active_object_count_wider, neighbor),
}

Item definition (register_node, register_craftitem, register_tool)
Expand Down
37 changes: 21 additions & 16 deletions src/biome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ u8 BiomeDefManager::getBiomeIdByName(const char *name) {
///////////////////////////// Weather


s16 BiomeDefManager::calcBlockHeat(v3s16 p, u64 seed, float timeofday, float totaltime) {
s16 BiomeDefManager::calcBlockHeat(v3s16 p, u64 seed, float timeofday, float totaltime, bool use_weather) {
//variant 1: full random
//f32 heat = NoisePerlin3D(np_heat, p.X, env->getGameTime()/100, p.Z, seed);

Expand All @@ -225,32 +225,37 @@ s16 BiomeDefManager::calcBlockHeat(v3s16 p, u64 seed, float timeofday, float tot
if (np_heat->scale)
heat /= np_heat->scale / scale; // -20..0..+20

f32 seasonv = totaltime;
seasonv /= 86400 * g_settings->getS16("year_days"); // season change speed
seasonv += (f32)p.X / 3000; // you can walk to area with other season
seasonv = sin(seasonv * M_PI);
heat += (range * (heat < 0 ? 2 : 0.5)) * seasonv; // -60..0..30
if (use_weather) {
f32 seasonv = totaltime;
seasonv /= 86400 * g_settings->getS16("year_days"); // season change speed
seasonv += (f32)p.X / 3000; // you can walk to area with other season
seasonv = sin(seasonv * M_PI);
heat += (range * (heat < 0 ? 2 : 0.5)) * seasonv; // -60..0..30

heat += offset; // -40..0..50
// daily change, hotter at sun +4, colder at night -4
heat += 8 * (sin(cycle_shift(timeofday, -0.25) * M_PI) - 0.5); //-44..20..54
}
heat += offset; // -40..20..50
heat += p.Y / -333; // upper=colder, lower=hotter, 3c per 1000

// daily change, hotter at sun +4, colder at night -4
heat += 8 * (sin(cycle_shift(timeofday, -0.25) * M_PI) - 0.5); //-44..20..54

if (p.Y < -(MAP_GENERATION_LIMIT-1000)) heat += 6000 * (1-((float)(p.Y - -MAP_GENERATION_LIMIT)/1000)); //hot core, later via realms, DISABLE BEFORE MERGING

return heat;
}


s16 BiomeDefManager::calcBlockHumidity(v3s16 p, u64 seed, float timeofday, float totaltime) {
s16 BiomeDefManager::calcBlockHumidity(v3s16 p, u64 seed, float timeofday, float totaltime, bool use_weather) {

f32 humidity = NoisePerlin2D(np_humidity, p.X, p.Z, seed);

f32 seasonv = totaltime;
seasonv /= 86400 * 2; // bad weather change speed (2 days)
seasonv += (f32)p.Z / 300;
humidity += 30 * sin(seasonv * M_PI);
if (use_weather) {
f32 seasonv = totaltime;
seasonv /= 86400 * 2; // bad weather change speed (2 days)
seasonv += (f32)p.Z / 300;
humidity += 30 * sin(seasonv * M_PI);
humidity += -12 * (sin(cycle_shift(timeofday, -0.1) * M_PI) - 0.5);
}

humidity += -12 * (sin(cycle_shift(timeofday, -0.1) * M_PI) - 0.5);
humidity = rangelim(humidity, 0, 100);

return humidity;
Expand Down
4 changes: 2 additions & 2 deletions src/biome.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class BiomeDefManager {
void resolveNodeNames(INodeDefManager *ndef);
u8 getBiomeIdByName(const char *name);

s16 calcBlockHeat(v3s16 p, u64 seed, float timeofday, float totaltime);
s16 calcBlockHumidity(v3s16 p, u64 seed, float timeofday, float totaltime);
s16 calcBlockHeat(v3s16 p, u64 seed, float timeofday, float totaltime, bool use_weather = 1);
s16 calcBlockHumidity(v3s16 p, u64 seed, float timeofday, float totaltime, bool use_weather = 1);
};

#endif
7 changes: 0 additions & 7 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,4 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// Maximum hit points of a player
#define PLAYER_MAX_HP 20

/*
Environmental condition constants
*/
#define HEAT_UNDEFINED (-0x7fff-1)
#define HUMIDITY_UNDEFINED (-0x7fff-1)

#endif

96 changes: 63 additions & 33 deletions src/content_abm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class LiquidFlowABM : public ActiveBlockModifier {
{ return 10.0; }
virtual u32 getTriggerChance()
{ return 10; }
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n) {
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
u32 active_object_count, u32 active_object_count_wider, MapNode neighbor) {
ServerMap *map = &env->getServerMap();
if (map->transforming_liquid_size() > 500)
return;
Expand Down Expand Up @@ -80,7 +81,8 @@ class LiquidDropABM : public ActiveBlockModifier {
{ return 20.0; }
virtual u32 getTriggerChance()
{ return 10; }
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n) {
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
u32 active_object_count, u32 active_object_count_wider, MapNode neighbor) {
ServerMap *map = &env->getServerMap();
if (map->transforming_liquid_size() > 500)
return;
Expand All @@ -100,32 +102,35 @@ class LiquidFreeze : public ActiveBlockModifier {
LiquidFreeze(ServerEnvironment *env, INodeDefManager *nodemgr) { }
virtual std::set<std::string> getTriggerContents() {
std::set<std::string> s;
s.insert("group:freezes");
s.insert("group:freeze");
return s;
}
virtual std::set<std::string> getRequiredNeighbors() {
std::set<std::string> s;
s.insert("air");
s.insert("group:melts");
s.insert("group:melt");
return s;
}
virtual float getTriggerInterval()
{ return 10.0; }
virtual u32 getTriggerChance()
{ return 20; }
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n) {
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
u32 active_object_count, u32 active_object_count_wider, MapNode neighbor) {
ServerMap *map = &env->getServerMap();
INodeDefManager *ndef = env->getGameDef()->ndef();

float heat = map->updateBlockHeat(env, p);
//heater = rare
content_t c = map->getNodeNoEx(p - v3s16(0, -1, 0 )).getContent(); // top
//more chance to freeze if air at top
if (heat <= -1 && (heat <= -50 || (myrand_range(-50, heat) <= (c == CONTENT_AIR ? -10 : -40)))) {
int freeze = ((ItemGroupList) ndef->get(n).groups)["freeze"];
if (heat <= freeze-1 && (heat <= freeze-50 ||
(myrand_range(freeze-50, heat) <= (c == CONTENT_AIR ? freeze-10 : freeze-40)))) {
content_t c_self = n.getContent();
// making freeze not annoying, do not freeze random blocks in center of ocean
// todo: any block not water (dont freeze _source near _flowing)
bool allow = heat < -40;
bool allow = heat < freeze-40;
// todo: make for(...)
if (!allow) {
c = map->getNodeNoEx(p - v3s16(0, 1, 0 )).getContent(); // below
Expand Down Expand Up @@ -157,44 +162,46 @@ class LiquidFreeze : public ActiveBlockModifier {
}
};

class LiquidMeltWeather : public ActiveBlockModifier {
class MeltWeather : public ActiveBlockModifier {
public:
LiquidMeltWeather(ServerEnvironment *env, INodeDefManager *nodemgr) { }
MeltWeather(ServerEnvironment *env, INodeDefManager *nodemgr) { }
virtual std::set<std::string> getTriggerContents() {
std::set<std::string> s;
s.insert("group:melts");
s.insert("group:melt");
return s;
}
virtual std::set<std::string> getRequiredNeighbors() {
std::set<std::string> s;
s.insert("air");
s.insert("group:freezes");
s.insert("group:freeze");
return s;
}
virtual float getTriggerInterval()
{ return 10.0; }
virtual u32 getTriggerChance()
{ return 20; }
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n) {
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
u32 active_object_count, u32 active_object_count_wider, MapNode neighbor) {
ServerMap *map = &env->getServerMap();
INodeDefManager *ndef = env->getGameDef()->ndef();

float heat = map->updateBlockHeat(env, p);
content_t c = map->getNodeNoEx(p - v3s16(0, -1, 0 )).getContent(); // top
if (heat >= 1 && (heat >= 40 || ((myrand_range(heat, 40)) >= (c == CONTENT_AIR ? 10 : 20)))) {
int melt = ((ItemGroupList) ndef->get(n).groups)["melt"];
if (heat >= melt+1 && (heat >= melt+40 ||
((myrand_range(heat, melt+40)) >= (c == CONTENT_AIR ? melt+10 : melt+20)))) {
n.freezeMelt(ndef);
map->addNodeWithEvent(p, n);
env->getScriptIface()->node_falling_update(p);
//env->getScriptIface()->node_falling_update(p); //enable after making FAST nodeupdate
}
}
};

class LiquidMeltHot : public ActiveBlockModifier {
class MeltHot : public ActiveBlockModifier {
public:
LiquidMeltHot(ServerEnvironment *env, INodeDefManager *nodemgr) { }
MeltHot(ServerEnvironment *env, INodeDefManager *nodemgr) { }
virtual std::set<std::string> getTriggerContents() {
std::set<std::string> s;
s.insert("group:melts");
s.insert("group:melt");
return s;
}
virtual std::set<std::string> getRequiredNeighbors() {
Expand All @@ -203,45 +210,68 @@ class LiquidMeltHot : public ActiveBlockModifier {
s.insert("group:hot");
return s;
}
virtual u32 getNeighborsRange()
{ return 2; }
virtual float getTriggerInterval()
{ return 2.0; }
{ return 3.0; }
virtual u32 getTriggerChance()
{ return 4; }
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n) {
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
u32 active_object_count, u32 active_object_count_wider, MapNode neighbor) {
ServerMap *map = &env->getServerMap();
INodeDefManager *ndef = env->getGameDef()->ndef();
n.freezeMelt(ndef);
map->addNodeWithEvent(p, n);
env->getScriptIface()->node_falling_update(p);
int hot = ((ItemGroupList) ndef->get(neighbor).groups)["hot"];
int melt = ((ItemGroupList) ndef->get(n).groups)["melt"];
if (hot > melt) {
n.freezeMelt(ndef);
map->addNodeWithEvent(p, n);
env->getScriptIface()->node_falling_update(p);
}
}
};

/* too buggy, later via liquid flow code
class LiquidMeltAround : public LiquidMeltHot {
class LiquidFreezeCold : public ActiveBlockModifier {
public:
LiquidMeltAround(ServerEnvironment *env, INodeDefManager *nodemgr)
: LiquidMeltHot(env, nodemgr) { }
LiquidFreezeCold(ServerEnvironment *env, INodeDefManager *nodemgr) { }
virtual std::set<std::string> getTriggerContents() {
std::set<std::string> s;
s.insert("group:freeze");
return s;
}
virtual std::set<std::string> getRequiredNeighbors() {
std::set<std::string> s;
s.insert("group:melt_around");
s.insert("group:cold");
return s;
}
virtual u32 getNeighborsRange()
{ return 1; }
virtual float getTriggerInterval()
{ return 40.0; }
{ return 3.0; }
virtual u32 getTriggerChance()
{ return 60; }
{ return 4; }
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
u32 active_object_count, u32 active_object_count_wider, MapNode neighbor) {
ServerMap *map = &env->getServerMap();
INodeDefManager *ndef = env->getGameDef()->ndef();
int cold = ((ItemGroupList) ndef->get(neighbor).groups)["cold"];
int freeze = ((ItemGroupList) ndef->get(n).groups)["freeze"];
if (cold < freeze) {
n.freezeMelt(ndef);
map->addNodeWithEvent(p, n);
}
}
};
*/

void add_legacy_abms(ServerEnvironment *env, INodeDefManager *nodedef) {
if (g_settings->getBool("liquid_finite")) {
env->addActiveBlockModifier(new LiquidFlowABM(env, nodedef));
env->addActiveBlockModifier(new LiquidDropABM(env, nodedef));
env->addActiveBlockModifier(new LiquidMeltHot(env, nodedef));
env->addActiveBlockModifier(new MeltHot(env, nodedef));
env->addActiveBlockModifier(new LiquidFreezeCold(env, nodedef));
//env->addActiveBlockModifier(new LiquidMeltAround(env, nodedef));
if (env->m_use_weather) {
env->addActiveBlockModifier(new LiquidFreeze(env, nodedef));
env->addActiveBlockModifier(new LiquidMeltWeather(env, nodedef));
env->addActiveBlockModifier(new MeltWeather(env, nodedef));
}
}
}
7 changes: 7 additions & 0 deletions src/emerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,13 @@ void *EmergeThread::Thread() {
if (block)
modified_blocks[p] = block;

// Update weather data in mapblock
for(std::map<v3s16, MapBlock *>::iterator
i = modified_blocks.begin();
i != modified_blocks.end(); ++i) {
map->updateBlockHeat(m_server->m_env, MAP_BLOCKSIZE*i->first, i->second);
}

// Set the modified blocks unsent for all the clients
for (std::map<u16, RemoteClient*>::iterator
i = m_server->m_clients.begin();
Expand Down
Loading