From e84897d5bf6ddd7a208d69ea43cf00f080c25b1f Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 10 Sep 2023 14:47:18 +0300 Subject: [PATCH 01/15] Tune tree grow --- src/content_abm_grow_tree.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/content_abm_grow_tree.cpp b/src/content_abm_grow_tree.cpp index b4659e005..02a1c4c83 100644 --- a/src/content_abm_grow_tree.cpp +++ b/src/content_abm_grow_tree.cpp @@ -893,8 +893,9 @@ class GrowLeaves : public ActiveBlockModifier ++i; } - const auto can_decrease = nbh[D_SELF].light < LIGHT_SUN - 1; - if (n_water_level > 1 && can_decrease && + // Slowly evaporate water and kill leaves with water_level==1 + const auto can_decay = have_air && nbh[D_SELF].light < LIGHT_SUN - 1; + if (n_water_level > 1 && can_decay && (!myrand_range(0, 10 * (grow_debug_fast ? 1 : 10)))) { float humidity = map->updateBlockHumidity(env, pos); if (humidity < params.tree_get_water_from_humidity) @@ -908,7 +909,7 @@ class GrowLeaves : public ActiveBlockModifier (grow_debug_fast || !myrand_range(0, params.leaves_to_fruit_chance))) { map->setNode(pos, {c_fruit}); } else if ( - (n_water_level == 1 && can_decrease && + (n_water_level == 1 && can_decay && (!myrand_range(0, 30 * (grow_debug_fast ? 1 : 10)))) || (n_water_level >= 1 && // dont touch old static trees have_air && From 230ac35cab11061b2f5229f5c3b25cd74a7f0671 Mon Sep 17 00:00:00 2001 From: proller Date: Wed, 13 Sep 2023 01:55:19 +0300 Subject: [PATCH 02/15] Update submodules --- games/default | 2 +- src/voxelalgorithms.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/games/default b/games/default index 8c9754d57..c6fd8feac 160000 --- a/games/default +++ b/games/default @@ -1 +1 @@ -Subproject commit 8c9754d578c092b2863b917f11aa803ba8fcc680 +Subproject commit c6fd8feac96fbb2a1fc08600cc44d7146699f353 diff --git a/src/voxelalgorithms.cpp b/src/voxelalgorithms.cpp index 2a0f14054..177eb36cd 100644 --- a/src/voxelalgorithms.cpp +++ b/src/voxelalgorithms.cpp @@ -866,23 +866,23 @@ void is_sunlight_above_block(Map *map, mapblock_v3 pos, light[z][x] = above.getLight(LIGHTBANK_DAY, above_f) == LIGHT_SUN; if (!light[z][x]) { - auto p = source_block->getPosRelative(); + v3pos_t p; bool go = false; if (x == 0) { - p += v3pos_t(x - 1, 0, z); + p = v3pos_t(x - 1, 0, z); go = true; } else if (z == 0) { - p += v3pos_t(x, 0, z - 1); + p = v3pos_t(x, 0, z - 1); go = true; } else if (z == MAP_BLOCKSIZE - 1) { - p += v3pos_t(x, 0, z + 1); + p = v3pos_t(x, 0, z + 1); go = true; } else if (x == MAP_BLOCKSIZE - 1) { - p += v3pos_t(x + 1, 0, z); + p = v3pos_t(x + 1, 0, z); go = true; } if (go) { - const auto n = map->getNode(p); + const auto n = map->getNode(p + source_block->getPosRelative()); if (n.getLight(LIGHTBANK_DAY, ndef->getLightingFlags(n)) == LIGHT_SUN) light[z][x] = true; } From f6750ed614bdb6e6bc4b5146365d55a70884ce0a Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 14 Sep 2023 03:23:37 +0300 Subject: [PATCH 03/15] Tune tree grow --- games/default | 2 +- src/content_abm_grow_tree.cpp | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/games/default b/games/default index c6fd8feac..8fde7836d 160000 --- a/games/default +++ b/games/default @@ -1 +1 @@ -Subproject commit c6fd8feac96fbb2a1fc08600cc44d7146699f353 +Subproject commit 8fde7836d4eb4768cfb83206db996017943f44dd diff --git a/src/content_abm_grow_tree.cpp b/src/content_abm_grow_tree.cpp index 02a1c4c83..926bcb66f 100644 --- a/src/content_abm_grow_tree.cpp +++ b/src/content_abm_grow_tree.cpp @@ -162,7 +162,7 @@ struct GrowParams class GrowTree : public ActiveBlockModifier { - std::unordered_map tree_to_leaves, tree_to_fruit; + std::unordered_map tree_to_leaves; //, tree_to_fruit; std::unordered_map type_params; bool grow_debug_fast = false; @@ -184,9 +184,8 @@ class GrowTree : public ActiveBlockModifier const auto &cf_leaves = ndef->get(id_leaves); type_params.emplace(id_leaves, GrowParams(cf_leaves)); - if (!cf_leaves.liquid_alternative_source.empty()) - tree_to_fruit[id_tree] = - ndef->getId(cf_leaves.liquid_alternative_source); + // if (!cf_leaves.liquid_alternative_source.empty()) + // tree_to_fruit[id_tree] = ndef->getId(cf_leaves.liquid_alternative_source); } } } @@ -220,7 +219,7 @@ class GrowTree : public ActiveBlockModifier int8_t near_soil{0}; int8_t near_liquid{0}; content_t leaves_content{CONTENT_IGNORE}; - content_t fruit_content{CONTENT_IGNORE}; + //content_t fruit_content{CONTENT_IGNORE}; struct Neighbor { @@ -229,7 +228,7 @@ class GrowTree : public ActiveBlockModifier bool is_liquid{false}; bool is_my_leaves{false}; bool is_any_leaves{false}; - bool is_fruit{false}; + //bool is_fruit{false}; bool is_tree{false}; bool is_other_tree{false}; bool is_soil{false}; @@ -275,9 +274,7 @@ class GrowTree : public ActiveBlockModifier leaves_content = tree_to_leaves.contains(nb.content) ? tree_to_leaves.at(nb.content) : CONTENT_IGNORE; - fruit_content = tree_to_fruit.contains(nb.content) - ? tree_to_fruit.at(nb.content) - : CONTENT_IGNORE; + //fruit_content = tree_to_fruit.contains(nb.content) ? tree_to_fruit.at(nb.content) : CONTENT_IGNORE; } //DUMP(is_self, leaves_content); @@ -288,7 +285,7 @@ class GrowTree : public ActiveBlockModifier nb.is_my_leaves = nb.content == leaves_content; nb.is_any_leaves = nb.is_my_leaves || nb.cf->groups.contains("leaves"); - nb.is_fruit = nb.content == fruit_content; + //nb.is_fruit = nb.content == fruit_content; // DUMP(is_self, nb.is_leaves, "=", nb.content, "==", (int)leaves_content); nb.is_liquid = nb.cf->groups.contains("liquid"); near_liquid += nb.is_liquid; @@ -431,8 +428,10 @@ class GrowTree : public ActiveBlockModifier if (!nb.allow_grow_by_rotation) return false; - if (!(nb.is_any_leaves || nb.is_fruit || nb.cf->buildable_to || - nb.is_liquid || nb.is_soil || nb.cf->groups.contains("sand"))) + if (!(nb.is_any_leaves || nb.cf->buildable_to || nb.is_liquid || + nb.is_soil || nb.cf->groups.contains("sand") || + nb.cf->groups.contains("fruit"))) + // || nb.is_fruit return false; if (nb.top) { From c2eb66ed5cb2b6b76faa4d7f237649e891666798 Mon Sep 17 00:00:00 2001 From: proller Date: Fri, 6 Oct 2023 10:33:08 +0200 Subject: [PATCH 04/15] auto fixes --- util/autotest/auto.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/autotest/auto.pl b/util/autotest/auto.pl index 510832e5a..95d0859bf 100755 --- a/util/autotest/auto.pl +++ b/util/autotest/auto.pl @@ -413,7 +413,7 @@ () sy qq{$config->{env} $config->{runner} @_ ./freeminer --run-unittests --logfile $config->{logdir}/autotest.$g->{task_name}.test.log } . options_make([qw(verbose trace)]); }, set_bot => {'----bot' => 1, '----bot_random' => 1}, - run_bot => ['set_bot', 'run_single'], + run_bot => ['set_bot', 'set_client', 'run_single'], run_single_tsan => sub { local $config->{options_display} = 'software' if $config->{tsan_opengl_fix} and !$config->{options_display}; local $config->{cmake_leveldb} //= 0 if $config->{tsan_leveldb_fix}; @@ -488,8 +488,8 @@ () fail => sub { warn 'fail:', join ' ', @_; }, - set_client => [{-no_build_client => 0, -no_build_server => 1,}], - set_server => [{-no_build_client => 1, -no_build_server => 0, -options_add => 'no_exit'}], + set_client => [{'---no_build_client' => 0, '---no_build_server' => 1,}], + set_server => [{'---no_build_client' => 1, '---no_build_server' => 0, -options_add => 'no_exit'}], }; our $tasks = { From 8f5d28add0fcdce377e9daa9f9a94c3130c67270 Mon Sep 17 00:00:00 2001 From: proller Date: Sat, 14 Oct 2023 15:20:35 +0200 Subject: [PATCH 05/15] Tune tree grow --- src/content_abm_grow_tree.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/content_abm_grow_tree.cpp b/src/content_abm_grow_tree.cpp index 926bcb66f..cc954d8cc 100644 --- a/src/content_abm_grow_tree.cpp +++ b/src/content_abm_grow_tree.cpp @@ -614,8 +614,12 @@ top = ceil(avg - 1) const auto float_avg_level = (float)total_level / have_liquid; const auto avg_level = prefer ? floor(float_avg_level + 1) : ceil(float_avg_level - 1); - const auto want_level = - std::min(avg_level, params.tree_water_max); + auto want_level = std::min(avg_level, params.tree_water_max); + + // dont grow down + if (want_level > nbh[D_BOTTOM].water_level) { + want_level = nbh[D_BOTTOM].water_level; + } total_level -= want_level; --have_liquid; From 80d97b81a8c397eed82e2e743ade01b28edee7b9 Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 15 Oct 2023 15:17:37 +0200 Subject: [PATCH 06/15] Fix layers crash --- src/mapgen/mapgen_indev.cpp | 4 ++-- src/mapgen/mapgen_v5.cpp | 2 +- src/mapgen/mapgen_v7.cpp | 4 ++-- util/autotest/auto.pl | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mapgen/mapgen_indev.cpp b/src/mapgen/mapgen_indev.cpp index c563673f4..5e857894c 100644 --- a/src/mapgen/mapgen_indev.cpp +++ b/src/mapgen/mapgen_indev.cpp @@ -165,10 +165,10 @@ MapgenIndev::MapgenIndev(MapgenIndevParams *params, EmergeParams *emerge) floatland_ywater = params->floatland_ywater; - noise_layers = new Noise(&sp->np_layers, seed, csize.X, csize.Y + y_offset * 2, csize.Z); + noise_layers = new Noise(&sp->np_layers, seed, csize.X, csize.Y + y_offset * 2 + 2, csize.Z); layers_init(emerge, sp->paramsj); - noise_cave_indev = new Noise(&sp->np_cave_indev, seed, csize.X, csize.Y + y_offset * 2, csize.Z); + noise_cave_indev = new Noise(&sp->np_cave_indev, seed, csize.X, csize.Y + y_offset * 2 + 2, csize.Z); if (spflags & MGV6_FLOATLANDS) { diff --git a/src/mapgen/mapgen_v5.cpp b/src/mapgen/mapgen_v5.cpp index bc266017b..a229c10fe 100644 --- a/src/mapgen/mapgen_v5.cpp +++ b/src/mapgen/mapgen_v5.cpp @@ -78,7 +78,7 @@ MapgenV5::MapgenV5(MapgenV5Params *params, EmergeParams *emerge) noise_float_islands2 = new Noise(¶ms->np_float_islands2, seed, csize.X, csize.Y + y_offset * 2, csize.Z); noise_float_islands3 = new Noise(¶ms->np_float_islands3, seed, csize.X, csize.Z); - noise_layers = new Noise(¶ms->np_layers, seed, csize.X, csize.Y + y_offset * 2, csize.Z); + noise_layers = new Noise(¶ms->np_layers, seed, csize.X, csize.Y + y_offset * 2 + 2, csize.Z); layers_init(emerge, params->paramsj); //noise_cave_indev = new Noise(&sp->np_cave_indev, seed, csize.X, csize.Y + y_offset * 2, csize.Z); diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp index 3c690c1e4..3fc3de017 100644 --- a/src/mapgen/mapgen_v7.cpp +++ b/src/mapgen/mapgen_v7.cpp @@ -131,9 +131,9 @@ MapgenV7::MapgenV7(MapgenV7Params *params, EmergeParams *emerge) //noise_float_islands2 = new Noise(¶ms->np_float_islands2, seed, csize.X, csize.Y + y_offset * 2, csize.Z); //noise_float_islands3 = new Noise(¶ms->np_float_islands3, seed, csize.X, csize.Z); - noise_layers = new Noise(¶ms->np_layers, seed, csize.X, csize.Y + y_offset * 2, csize.Z); + noise_layers = new Noise(¶ms->np_layers, seed, csize.X, csize.Y + y_offset * 2 + 2, csize.Z); layers_init(emerge, params->paramsj); - noise_cave_indev = new Noise(¶ms->np_cave_indev, seed, csize.X, csize.Y + y_offset * 2, csize.Z); + noise_cave_indev = new Noise(¶ms->np_cave_indev, seed, csize.X, csize.Y + y_offset * 2 + 2, csize.Z); //========== diff --git a/util/autotest/auto.pl b/util/autotest/auto.pl index 95d0859bf..d541c25c4 100755 --- a/util/autotest/auto.pl +++ b/util/autotest/auto.pl @@ -693,6 +693,7 @@ () ++$g->{keep_config}; $config->{runner} = $config->{runner} + . ' ASAN_OPTIONS=abort_on_error=1 ' . $config->{gdb} . q{ -ex 'run' -ex 't a a bt' } . ($config->{gdb_stay} ? '' : q{ -ex 'cont' -ex 'quit' }) From 56254ac7308ed162cdbdc08833778029e738f5c7 Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 15 Oct 2023 15:30:53 +0200 Subject: [PATCH 07/15] fix --- builtin/mainmenu/tab_online.lua | 2 +- src/server.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/mainmenu/tab_online.lua b/builtin/mainmenu/tab_online.lua index 79fda5472..bfb2fbd06 100644 --- a/builtin/mainmenu/tab_online.lua +++ b/builtin/mainmenu/tab_online.lua @@ -312,7 +312,7 @@ local function main_button_handler(tabview, fields, name, tabdata) if gamedata.address and gamedata.port then core.settings:set("address", gamedata.address) core.settings:set("remote_port", gamedata.port) - core.settings:set("remote_proto", gamedata.proto) + core.settings:set("remote_proto", gamedata.proto or "mt") core.start() end return true diff --git a/src/server.cpp b/src/server.cpp index ab7deab25..e425fa039 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -264,7 +264,6 @@ Server::Server( CONNECTION_TIMEOUT, m_bind_addr.isIPv6(), this)), - stat(path_world), m_itemdef(createItemDefManager()), m_nodedef(createNodeDefManager()), m_craftdef(createCraftDefManager()), @@ -272,6 +271,7 @@ Server::Server( m_clients(m_con), m_admin_chat(iface), m_on_shutdown_errmsg(on_shutdown_errmsg), + stat(path_world), m_modchannel_mgr(new ModChannelMgr()) { #if ENABLE_THREADS From 6b3d3c6026866278421cba48122cf2aa9b0a3f45 Mon Sep 17 00:00:00 2001 From: proller Date: Mon, 16 Oct 2023 11:03:33 +0200 Subject: [PATCH 08/15] Tune tree grow --- src/content_abm_grow_tree.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/content_abm_grow_tree.cpp b/src/content_abm_grow_tree.cpp index cc954d8cc..d6a608958 100644 --- a/src/content_abm_grow_tree.cpp +++ b/src/content_abm_grow_tree.cpp @@ -430,6 +430,7 @@ class GrowTree : public ActiveBlockModifier if (!(nb.is_any_leaves || nb.cf->buildable_to || nb.is_liquid || nb.is_soil || nb.cf->groups.contains("sand") || + nb.cf->groups.contains("sapling") || nb.cf->groups.contains("fruit"))) // || nb.is_fruit return false; From 97226f75519c67290f3ddc474a39595c96003d5c Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 19 Oct 2023 01:09:40 +0200 Subject: [PATCH 09/15] Tune tree grow --- games/default | 2 +- src/content_abm_grow_tree.cpp | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/games/default b/games/default index 8fde7836d..b0e628e54 160000 --- a/games/default +++ b/games/default @@ -1 +1 @@ -Subproject commit 8fde7836d4eb4768cfb83206db996017943f44dd +Subproject commit b0e628e542c1a1ea7ac7f48a78693cd4daac3bc2 diff --git a/src/content_abm_grow_tree.cpp b/src/content_abm_grow_tree.cpp index d6a608958..5def20a1f 100644 --- a/src/content_abm_grow_tree.cpp +++ b/src/content_abm_grow_tree.cpp @@ -864,9 +864,22 @@ class GrowLeaves : public ActiveBlockModifier can_grow_leaves(params, n_water_level, nb.top, nb.bottom) && nb.light >= params.leaves_grow_light_min && nb.cf->buildable_to && !nb.is_liquid) { - //if (grow_debug)DUMP("lv->lv ", p.X, p.Y, p.Z, nb.content, c, l, n_water_level,n_water_level_orig, l, ndef->get(nb.content).name); - map->setNode(nb.pos, {nbh[D_SELF].content, nb.node.getParam1(), 2}); - n_water_level -= 2; + uint8_t water_transfer = 0; + // Leaves grow should cost 2 wates, nobody knows why + if (n_water_level > 1) { + ++water_transfer; + --n_water_level; + } + if (n_water_level > 1) { + ++water_transfer; + --n_water_level; + } + if (water_transfer <= 0) { + break; + } + //if (grow_debug)DUMP("lv->lv ", p.X, p.Y, p.Z, nb.content, c, l, n_water_level,n_water_level_orig, water_transfer, ndef->get(nb.content).name); + map->setNode(nb.pos, + {nbh[D_SELF].content, nb.node.getParam1(), water_transfer}); if (!myrand_range(0, 10)) if (const auto block = map->getBlock(getNodeBlockPos(nb.pos)); From 2c80a29aafa951c2929996bc5d05e44a7d442db5 Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 22 Oct 2023 19:59:31 +0200 Subject: [PATCH 10/15] Tune tree grow --- CHANGELOG.md | 5 + games/default | 2 +- src/content_abm_grow_tree.cpp | 257 ++++++++++++++++++++++------------ 3 files changed, 171 insertions(+), 93 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be3403866..a43fe4d90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ Core: fast reliable network protocol, fast multi-threaded server, utf8 chat, bui Changelog ====== +### 5.7.0.0 (?) + * Tree growth + * Weather tuned + + ### 5.6.1.0 (?) * auth_kv removed, use instead in world.mt: auth_backend = leveldbfm diff --git a/games/default b/games/default index b0e628e54..c334440aa 160000 --- a/games/default +++ b/games/default @@ -1 +1 @@ -Subproject commit b0e628e542c1a1ea7ac7f48a78693cd4daac3bc2 +Subproject commit c334440aa48f0c61b3720775dcd6f7973b010a75 diff --git a/src/content_abm_grow_tree.cpp b/src/content_abm_grow_tree.cpp index 5def20a1f..17895f9f5 100644 --- a/src/content_abm_grow_tree.cpp +++ b/src/content_abm_grow_tree.cpp @@ -30,13 +30,14 @@ constexpr auto grow_debug = false; //constexpr auto grow_debug_no_die = false; // Trees use param2 for rotation, level1 is free -inline uint8_t get_tree_water_level(const MapNode &n) +inline uint8_t get_tree_water_level(const MapNode &n, bool use_param2) { - return n.getParam1(); + return use_param2 ? n.getParam2() : n.getParam1(); } -inline void set_tree_water_level(MapNode &n, const uint8_t level) + +inline void set_tree_water_level(MapNode &n, const uint8_t level, bool use_param2) { - n.setParam1(level); + use_param2 ? n.setParam2(level) : n.setParam1(level); } // Leaves use param1 for light, level2 is free @@ -78,6 +79,7 @@ constexpr auto D_BOTTOM = 6; struct GrowParams { + int tree_water_param2 = 0; int tree_water_max = 50; // todo: depend on humidity 10-100 int tree_grow_water_min = 20; int tree_grow_heat_min = 7; @@ -85,6 +87,7 @@ struct GrowParams int tree_grow_light_max = 12; // grow more leaves around before grow tree up int tree_get_water_from_humidity = 70; // rain start int tree_get_water_max_from_humidity = 30; // max level to get from air + int tree_grow_bottom = 1; int tree_grow_chance = 10; int leaves_water_max = 20; // todo: depend on humidity 2-20 int leaves_grow_light_min = 8; @@ -106,6 +109,8 @@ struct GrowParams GrowParams(const ContentFeatures &cf, bool grow_debug_fast = false) { + if (cf.groups.contains("tree_water_param2")) + tree_water_param2 = cf.groups.at("tree_water_param2"); if (cf.groups.contains("tree_water_max")) tree_water_max = cf.groups.at("tree_water_max"); if (cf.groups.contains("tree_grow_water_min")) @@ -116,6 +121,8 @@ struct GrowParams tree_grow_heat_max = cf.groups.at("tree_grow_heat_max"); if (cf.groups.contains("tree_grow_light_max")) tree_grow_light_max = cf.groups.at("tree_grow_light_max"); + if (cf.groups.contains("tree_grow_bottom")) + tree_grow_bottom = cf.groups.at("tree_grow_bottom"); if (cf.groups.contains("tree_grow_chance")) tree_grow_chance = grow_debug_fast ? 0 : cf.groups.at("tree_grow_chance"); if (cf.groups.contains("tree_get_water_from_humidity")) @@ -258,6 +265,8 @@ class GrowTree : public ActiveBlockModifier } nb.content = nb.node.getContent(); + const auto ¶ms = type_params.at(nbh[D_SELF].content); + nb.cf = (ContentFeatures *)&ndef->get(nb.content); nb.light = getLight(ndef, nb.node); nb.top = i == D_TOP; @@ -279,8 +288,9 @@ class GrowTree : public ActiveBlockModifier //DUMP(is_self, leaves_content); if (!is_self) { - if (!nb.top && !nb.bottom && around_all_is_tree && !nb.is_tree) + if (!nb.top && !nb.bottom && around_all_is_tree && !nb.is_tree) { around_all_is_tree = false; + } nb.is_my_leaves = nb.content == leaves_content; nb.is_any_leaves = @@ -291,8 +301,9 @@ class GrowTree : public ActiveBlockModifier near_liquid += nb.is_liquid; ///has_liquids.emplace_back(nb.pos); - if (nb.top && !nb.is_tree) + if (nb.top && !nb.is_tree) { top_is_not_tree = true; + } nb.is_soil = nb.cf->groups.contains("soil"); near_soil += nb.is_soil; @@ -303,8 +314,9 @@ class GrowTree : public ActiveBlockModifier } nb.water_level = nb.is_my_leaves ? get_leaves_water_level(nb.node) - : nb.is_tree ? get_tree_water_level(nb.node) - : 0; + : nb.is_tree ? get_tree_water_level( + nb.node, params.tree_water_param2) + : 0; nb.facedir = nb.node.getFaceDir(ndef); @@ -339,13 +351,14 @@ class GrowTree : public ActiveBlockModifier const auto save = [&]() { if (self_water_level_orig != self_water_level) { - set_tree_water_level(n, self_water_level); + set_tree_water_level(n, self_water_level, params.tree_water_param2); map->setNode(pos, n); } }; const auto decrease = [&](auto &level, int amount = 1) -> auto { - if (level <= amount) + if (level <= amount) { return false; + } level -= amount; return true; }; @@ -356,7 +369,10 @@ class GrowTree : public ActiveBlockModifier float humidity = map->updateBlockHumidity(env, pos); if (humidity >= params.tree_get_water_from_humidity) { if (grow_debug_fast) { - self_water_level = params.tree_get_water_max_from_humidity; + self_water_level = params.tree_get_water_max_from_humidity > + params.tree_water_max + ? params.tree_water_max + : params.tree_get_water_max_from_humidity; } else { // TODO: depend on += ceil( max_from_air * (params.tree_get_water_from_humidity)/(100-humidity)) ++self_water_level; @@ -380,18 +396,22 @@ class GrowTree : public ActiveBlockModifier auto level = nb.node.getLevel(ndef); // TODO: allow get all water if bottom of water != water - if (level <= 1) + if (level <= 1) { return; + } //auto amount = grow_debug_fast ? level - 1 : 1; auto amount = level - 1; - if (self_water_level + amount > params.tree_water_max) + if (self_water_level + amount > params.tree_water_max) { amount = params.tree_water_max - self_water_level; - level -= amount; + } - nb.node.setLevel(ndef, level); + level -= amount; - if (!grow_debug_fast) + if (!grow_debug_fast) { + nb.node.setLevel(ndef, level); map->setNode(nb.pos, nb.node); + } + self_water_level += amount; //set_tree_water_level(n, self_water_level); //map->setNode(p, n); @@ -414,45 +434,57 @@ class GrowTree : public ActiveBlockModifier // DUMP(i, pos.Y, self_water_level, nb.top, nb.water_level, allow_grow_by_light, up_all_leaves, nb.is_my_leaves, nb.is_any_leaves, up_all_leaves, nb.light, params.leaves_die_light_max, nb.allow_grow_by_rotation, nb.is_liquid, nb.cf->name); auto tree_grow = [&]() { - if (content == nb.content) + if (content == nb.content) { return false; + } if (!((!params.tree_grow_heat_min || heat > params.tree_grow_heat_min) && (!params.tree_grow_heat_max || - heat < params.tree_grow_heat_max))) + heat < params.tree_grow_heat_max))) { return false; + } - if (self_water_level < params.tree_grow_water_min) + if (self_water_level < params.tree_grow_water_min) { return false; + } - if (!nb.allow_grow_by_rotation) + if (!nb.allow_grow_by_rotation) { return false; + } if (!(nb.is_any_leaves || nb.cf->buildable_to || nb.is_liquid || nb.is_soil || nb.cf->groups.contains("sand") || nb.cf->groups.contains("sapling") || - nb.cf->groups.contains("fruit"))) + nb.cf->groups.contains("fruit"))) { // || nb.is_fruit return false; + } if (nb.top) { - if (nb.content == CONTENT_AIR && - nb.light > params.leaves_grow_light_min) + if (nb.content == CONTENT_AIR && params.leaves_grow_light_min && + nb.light < params.leaves_grow_light_min) { return false; + } //if (nb.is_any_leaves) return false; - if (!(allow_grow_by_light || up_all_leaves)) + if (!(allow_grow_by_light || up_all_leaves)) { return false; + } } // dont grow too deep in liquid if (nb.bottom) { - if (nb.is_liquid && nb.light <= 0) + if (!params.tree_grow_bottom) { + return false; + } + if (nb.is_liquid && nb.light <= 1) { return false; + } - if (near_tree >= 1) + if (near_tree >= 1) { return false; + } } if (!(grow_debug_fast || activate || @@ -465,47 +497,58 @@ class GrowTree : public ActiveBlockModifier //if (grow_debug) DUMP("tr->tr", i, nb.pos.Y, nb.top, nb.bottom, nb.content, content, self_water_level, self_water_level_orig, nb.light); - map->setNode(nb.pos, {content, 1, nbh[D_SELF].node.getParam2()}); + auto node = + nbh[D_SELF].node; //{content, 1, nbh[D_SELF].node.getParam2()}; + set_tree_water_level(node, 1, params.tree_water_param2); + map->setNode(nb.pos, node); + return true; }; - if (tree_grow()) + if (tree_grow()) { break; + } auto water_pump = [&]() { if (!(((!nb.top || nb.is_other_tree) && !nb.bottom && nb.is_tree && !around_all_is_tree) || - nb.is_my_leaves)) + nb.is_my_leaves)) { return false; + } - if (nb.side && nb.is_tree && self_allow_grow_by_rotation) + if (nb.side && nb.is_tree && self_allow_grow_by_rotation) { // DUMP("skip tr side pump", water_level, nb.is_tree, allow_grow_up_by_rotation), return false; + } // DUMP(nb.node, self_water_level, water_level); //??if (is_tree && dir_allow_grow_up_by_rotation && n_water_level >= params.tree_water_max) continue; if (!(!nb.is_my_leaves || (nb.is_my_leaves && (nb.top || !self_allow_grow_by_rotation || - (!nb.top && top_is_not_tree))))) + (!nb.top && top_is_not_tree))))) { return false; + } - auto water_level = nb.content == leaves_content - ? get_leaves_water_level(nb.node) - : get_tree_water_level(nb.node); + auto water_level = + nb.content == leaves_content + ? get_leaves_water_level(nb.node) + : get_tree_water_level(nb.node, params.tree_water_param2); //DUMP(water_level, nb.is_leaves, allow_grow_up_by_rotation, nb.top, top_is_not_tree); if (water_level >= (nb.is_my_leaves ? params.leaves_water_max - : params.tree_water_max)) + : params.tree_water_max)) { return false; + } if (self_water_level <= water_level + (nb.top ? 2 : 1) /* !!! n_water_level > wl_dir + (top ? -1 :bottom ? 1 : 0) */ - ) + ) { return false; + } if (!decrease(self_water_level)) { // if (grow_debug) DUMP("pumpfail", n_water_level, n_water_level_orig, wl_dir, top, bottom, nb.content, c); @@ -514,13 +557,15 @@ class GrowTree : public ActiveBlockModifier //if (grow_debug)DUMP("tr pump", pos.Y, self_water_level,self_water_level_orig, water_level, nb.top,nb.bottom, nb.content, content); ++water_level; nb.is_my_leaves ? set_leaves_water_level(nb.node, water_level) - : set_tree_water_level(nb.node, water_level); + : set_tree_water_level( + nb.node, water_level, params.tree_water_param2); map->setNode(nb.pos, nb.node); return true; }; - if (water_pump()) + if (water_pump()) { break; + } // Dont grow after top //if ((nb.top && nb.is_my_leaves) || nb.content == content) { @@ -530,24 +575,33 @@ class GrowTree : public ActiveBlockModifier //DUMP(allow_grow_leaves, leaves_c, heat , params.leaves_grow_heat_min, params.leaves_grow_heat_max, n_water_level, light_dir); auto leaves_grow = [&]() { - if (!nb.allow_grow_by_rotation) + if (!nb.allow_grow_by_rotation) { return false; + } if (nbh[D_TOP].content == content) // TODO not top, by grow direction + { return false; - if (leaves_content == CONTENT_IGNORE) + } + if (leaves_content == CONTENT_IGNORE) { return false; + } if (!(heat >= params.leaves_grow_heat_min && - heat <= params.leaves_grow_heat_max)) + heat <= params.leaves_grow_heat_max)) { return false; + } if (!(self_water_level >= (nb.top ? params.leaves_grow_water_min_top - : params.leaves_grow_water_min_side))) + : params.leaves_grow_water_min_side))) { return false; - if (nb.light < params.leaves_grow_light_min) + } + if (nb.light < params.leaves_grow_light_min) { return false; - if (!nb.cf->buildable_to || nb.is_liquid) + } + if (!nb.cf->buildable_to || nb.is_liquid) { return false; - if (!decrease(self_water_level)) + } + if (!decrease(self_water_level)) { return true; + } //if (grow_debug)DUMP("tr->lv", nb.pos, self_water_level, self_water_level_orig,nb.light_dir); map->setNode(nb.pos, {leaves_content, nb.node.param1, 1}); @@ -555,11 +609,13 @@ class GrowTree : public ActiveBlockModifier if (const auto block = map->getBlock(getNodeBlockPos(nb.pos)); block) { block->setLightingComplete(0); } + return true; }; - if (leaves_grow()) + if (leaves_grow()) { break; + } } // up-down distribute of rest @@ -599,6 +655,7 @@ self = round(avg) top = ceil(avg - 1) */ + const auto float_avg_level = (float)total_level / have_liquid; const auto fill_bottom = [&](bool prefer = false) { if (nbh[D_BOTTOM].content == content) { @@ -612,7 +669,7 @@ top = ceil(avg - 1) ? avg_level + (avg_level >= (total_level ? 0 : 1)) : params.tree_water_max; */ - const auto float_avg_level = (float)total_level / have_liquid; + //const auto float_avg_level = (float)total_level / have_liquid; const auto avg_level = prefer ? floor(float_avg_level + 1) : ceil(float_avg_level - 1); auto want_level = std::min(avg_level, params.tree_water_max); @@ -626,7 +683,8 @@ top = ceil(avg - 1) --have_liquid; if (nbh[D_BOTTOM].water_level != want_level) { //if (grow_debug)DUMP("setbot", bottom_level, total_level,avg_level_for_bottom); - set_tree_water_level(n_bottom, want_level); + set_tree_water_level( + n_bottom, want_level, params.tree_water_param2); map->setNode(nbh[D_BOTTOM].pos, n_bottom); } } @@ -644,7 +702,7 @@ top = ceil(avg - 1) ? avg_level + (avg_level >= (total_level ? 0 : 1)) : params.tree_water_max; */ - const auto float_avg_level = (float)total_level / have_liquid; + //const auto float_avg_level = (float)total_level / have_liquid; const auto avg_level = prefer ? floor(float_avg_level + 1) : ceil(float_avg_level - 1); const auto want_level = @@ -655,7 +713,7 @@ top = ceil(avg - 1) if (nbh[D_TOP].water_level != want_level) { //if (grow_debug) DUMP("settop", top_level, total_level, avg_level_for_top,around_all_is_tree); // if (all_is_tree && n_water_level>= params.tree_water_max) DUMP(top_level, total_level, float_avg_level_for_top, avg_level_for_top); - set_tree_water_level(n_top, want_level); + set_tree_water_level(n_top, want_level, params.tree_water_param2); map->setNode(nbh[D_TOP].pos, n_top); } } @@ -681,15 +739,16 @@ S S S S S S S S S SSS SSS SSS SSS SSS //&&((nbh[D_BOTTOM].water_level >= params.tree_get_water_from_humidity / 2) || // params.tree_water_max //(nbh[D_SELF].water_level >= params.tree_get_water_from_humidity / 2)) ) { - //DUMP("prefer top", pos.Y, around_all_is_tree, total_level, nbh[D_BOTTOM].water_level, nbh[D_SELF].water_level,nbh[D_TOP].water_level); + nbh[D_BOTTOM].water_level, nbh[D_SELF].water_level, + nbh[D_TOP].water_level); fill_top(true); fill_bottom(); } else { - //DUMP("prefer bot", pos.Y, around_all_is_tree, total_level); fill_bottom(true); fill_top(); } - // if (grow_debug) DUMP("total res self:", total_level, (int)have_liquid, (int)near_tree, nbh[D_BOTTOM].water_level, nbh[D_SELF].water_level, nbh[D_TOP].water_level); + nbh[D_BOTTOM].water_level, nbh[D_SELF].water_level, + nbh[D_TOP].water_level); self_water_level = total_level; } @@ -706,10 +765,12 @@ class GrowLeaves : public ActiveBlockModifier static bool can_grow_leaves( GrowParams params, int8_t level, bool is_top, bool is_bottom) { - if (is_top) + if (is_top) { return level >= params.leaves_grow_water_min_top; - if (is_bottom) + } + if (is_bottom) { return level >= params.leaves_grow_water_min_bottom; + } return level >= params.leaves_grow_water_min_side; } @@ -724,8 +785,9 @@ class GrowLeaves : public ActiveBlockModifier for (const auto &id : ids) { const auto &cf = ndef->get(id); type_params.emplace(id, GrowParams(cf)); - if (!cf.liquid_alternative_source.empty()) + if (!cf.liquid_alternative_source.empty()) { leaves_to_fruit[id] = ndef->getId(cf.liquid_alternative_source); + } } } virtual const std::vector getTriggerContents() const override @@ -790,41 +852,50 @@ class GrowLeaves : public ActiveBlockModifier have_air = false; goto NEXT; } - - nb.light = getLight(ndef, nb.node); - nb.content = nb.node.getContent(); - nb.is_my_leaves = is_self || nb.content == nbh[D_SELF].content; - nb.cf = (ContentFeatures *)&ndef->get(nb.content); - nb.is_tree = nb.cf->groups.contains("tree"); - nb.is_any_leaves = nb.cf->groups.contains("leaves"); - nb.is_liquid = nb.cf->groups.contains("liquid"); - nb.water_level = nb.is_my_leaves ? get_leaves_water_level(nb.node) - : nb.is_tree ? get_tree_water_level(nb.node) - : 0; - top_is_full_liquid = nb.top && nb.is_liquid && - nb.node.getMaxLevel(ndef) == nb.node.getLevel(ndef); - - if (is_self) { - allow_grow_fruit = leaves_to_fruit.contains(nbh[D_SELF].content); - - c_fruit = allow_grow_fruit ? leaves_to_fruit.at(nbh[D_SELF].content) - : CONTENT_IGNORE; - } else { - if ((nb.content == c_fruit) || - (!nb.top && !nb.bottom && !nb.is_any_leaves)) - allow_grow_fruit = false; - - if (nb.is_tree) // no fruit near tree - allow_grow_fruit = false; - - if (!have_tree_or_soil) - have_tree_or_soil = nb.is_tree || nb.is_any_leaves || - nb.cf->groups.contains("soil") || - nb.is_liquid; - if (!have_air) - have_air = nb.content == CONTENT_AIR; + { + nb.light = getLight(ndef, nb.node); + nb.content = nb.node.getContent(); + const auto params = type_params.at(nbh[D_SELF].content); + nb.is_my_leaves = is_self || nb.content == nbh[D_SELF].content; + nb.cf = (ContentFeatures *)&ndef->get(nb.content); + nb.is_tree = nb.cf->groups.contains("tree"); + nb.is_any_leaves = nb.cf->groups.contains("leaves"); + nb.is_liquid = nb.cf->groups.contains("liquid"); + nb.water_level = nb.is_my_leaves ? get_leaves_water_level(nb.node) + : nb.is_tree ? get_tree_water_level(nb.node, + params.tree_water_param2) + : 0; + top_is_full_liquid = + nb.top && nb.is_liquid && + nb.node.getMaxLevel(ndef) == nb.node.getLevel(ndef); + + if (is_self) { + allow_grow_fruit = leaves_to_fruit.contains(nbh[D_SELF].content); + + c_fruit = allow_grow_fruit + ? leaves_to_fruit.at(nbh[D_SELF].content) + : CONTENT_IGNORE; + } else { + if ((nb.content == c_fruit) || + (!nb.top && !nb.bottom && !nb.is_any_leaves)) { + allow_grow_fruit = false; + } + + if (nb.is_tree) // no fruit near tree + { + allow_grow_fruit = false; + } + + if (!have_tree_or_soil) { + have_tree_or_soil = nb.is_tree || nb.is_any_leaves || + nb.cf->groups.contains("soil") || + nb.is_liquid; + } + if (!have_air) { + have_air = nb.content == CONTENT_AIR; + } + } } - NEXT: ++i; } @@ -846,8 +917,9 @@ class GrowLeaves : public ActiveBlockModifier for (auto &i : grow_order) { auto &nb = nbh[i]; - if (!nb.node) + if (!nb.node) { continue; + } /*todo: shapes: o sphere @@ -915,8 +987,9 @@ class GrowLeaves : public ActiveBlockModifier if (n_water_level > 1 && can_decay && (!myrand_range(0, 10 * (grow_debug_fast ? 1 : 10)))) { float humidity = map->updateBlockHumidity(env, pos); - if (humidity < params.tree_get_water_from_humidity) + if (humidity < params.tree_get_water_from_humidity) { --n_water_level; + } } // DUMP(allow_grow_fruit, n_water_level, leaves_to_fruit_water_min, heat, leaves_to_fruit_heat_min); From f9e5ea59745edfae9ac537e7bf38ee5aa422de29 Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 22 Oct 2023 20:06:51 +0200 Subject: [PATCH 11/15] fix --- src/content_abm_grow_tree.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/content_abm_grow_tree.cpp b/src/content_abm_grow_tree.cpp index 17895f9f5..2d707b393 100644 --- a/src/content_abm_grow_tree.cpp +++ b/src/content_abm_grow_tree.cpp @@ -739,16 +739,13 @@ S S S S S S S S S SSS SSS SSS SSS SSS //&&((nbh[D_BOTTOM].water_level >= params.tree_get_water_from_humidity / 2) || // params.tree_water_max //(nbh[D_SELF].water_level >= params.tree_get_water_from_humidity / 2)) ) { - nbh[D_BOTTOM].water_level, nbh[D_SELF].water_level, - nbh[D_TOP].water_level); fill_top(true); fill_bottom(); } else { fill_bottom(true); fill_top(); } - nbh[D_BOTTOM].water_level, nbh[D_SELF].water_level, - nbh[D_TOP].water_level); + self_water_level = total_level; } From e4ec4e6887fdfeb5434e3b57f10d1cdb8b9b7f23 Mon Sep 17 00:00:00 2001 From: proller Date: Sat, 28 Oct 2023 17:46:58 +0200 Subject: [PATCH 12/15] tree grow: better decay --- src/content_abm_grow_tree.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/content_abm_grow_tree.cpp b/src/content_abm_grow_tree.cpp index 2d707b393..5f0cd2fd9 100644 --- a/src/content_abm_grow_tree.cpp +++ b/src/content_abm_grow_tree.cpp @@ -813,7 +813,7 @@ class GrowLeaves : public ActiveBlockModifier content_t c_fruit{}; bool top_is_full_liquid = false; bool have_tree_or_soil = false; - bool have_air = false; + uint8_t have_not_leaves = 0; bool allow_grow_fruit = false; struct Neighbor @@ -846,7 +846,7 @@ class GrowLeaves : public ActiveBlockModifier if (!nb.node) { have_tree_or_soil = true; // dont remove when map busy allow_grow_fruit = false; - have_air = false; + ++have_not_leaves; goto NEXT; } { @@ -888,8 +888,8 @@ class GrowLeaves : public ActiveBlockModifier nb.cf->groups.contains("soil") || nb.is_liquid; } - if (!have_air) { - have_air = nb.content == CONTENT_AIR; + if (!have_not_leaves && !nb.is_any_leaves) { + ++have_not_leaves; } } } @@ -980,7 +980,7 @@ class GrowLeaves : public ActiveBlockModifier } // Slowly evaporate water and kill leaves with water_level==1 - const auto can_decay = have_air && nbh[D_SELF].light < LIGHT_SUN - 1; + const auto can_decay = !have_not_leaves && nbh[D_SELF].light < LIGHT_SUN - 1; if (n_water_level > 1 && can_decay && (!myrand_range(0, 10 * (grow_debug_fast ? 1 : 10)))) { float humidity = map->updateBlockHumidity(env, pos); @@ -999,7 +999,7 @@ class GrowLeaves : public ActiveBlockModifier (n_water_level == 1 && can_decay && (!myrand_range(0, 30 * (grow_debug_fast ? 1 : 10)))) || (n_water_level >= 1 && // dont touch old static trees - have_air && + !have_not_leaves && ((nbh[D_SELF].light < params.leaves_die_light_max && (nbh[D_SELF].light > 0 || activate || !myrand_range(0, params.leaves_die_chance))) || From 09b8c75ad0090995c2a01e55292a9b57cff5d1f6 Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 5 Nov 2023 14:43:11 +0100 Subject: [PATCH 13/15] Tune groe tree (cacti) --- games/default | 2 +- src/content_abm_grow_tree.cpp | 177 +++++++++++++++++++------------- src/script/common/c_content.cpp | 2 +- 3 files changed, 108 insertions(+), 73 deletions(-) diff --git a/games/default b/games/default index c334440aa..56322b15d 160000 --- a/games/default +++ b/games/default @@ -1 +1 @@ -Subproject commit c334440aa48f0c61b3720775dcd6f7973b010a75 +Subproject commit 56322b15d2648690992c4c8de44b79a35fe40433 diff --git a/src/content_abm_grow_tree.cpp b/src/content_abm_grow_tree.cpp index 5f0cd2fd9..46682f60d 100644 --- a/src/content_abm_grow_tree.cpp +++ b/src/content_abm_grow_tree.cpp @@ -27,6 +27,7 @@ along with Freeminer. If not, see . #include "serverenvironment.h" constexpr auto grow_debug = false; +constexpr auto grow_debug_fast_default = 0; //constexpr auto grow_debug_no_die = false; // Trees use param2 for rotation, level1 is free @@ -89,6 +90,7 @@ struct GrowParams int tree_get_water_max_from_humidity = 30; // max level to get from air int tree_grow_bottom = 1; int tree_grow_chance = 10; + int tree_width_to_height = 1; int leaves_water_max = 20; // todo: depend on humidity 2-20 int leaves_grow_light_min = 8; int leaves_grow_water_min_top = 4; @@ -107,7 +109,7 @@ struct GrowParams int leaves_to_fruit_light_min = 10; int leaves_to_fruit_chance = 10; - GrowParams(const ContentFeatures &cf, bool grow_debug_fast = false) + GrowParams(const ContentFeatures &cf, int16_t grow_debug_fast = 0) { if (cf.groups.contains("tree_water_param2")) tree_water_param2 = cf.groups.at("tree_water_param2"); @@ -124,7 +126,9 @@ struct GrowParams if (cf.groups.contains("tree_grow_bottom")) tree_grow_bottom = cf.groups.at("tree_grow_bottom"); if (cf.groups.contains("tree_grow_chance")) - tree_grow_chance = grow_debug_fast ? 0 : cf.groups.at("tree_grow_chance"); + tree_grow_chance = cf.groups.at("tree_grow_chance"); + if (cf.groups.contains("tree_width_to_height")) + tree_width_to_height = cf.groups.at("tree_width_to_height"); if (cf.groups.contains("tree_get_water_from_humidity")) tree_get_water_from_humidity = cf.groups.at("tree_get_water_from_humidity"); if (cf.groups.contains("tree_get_water_max_from_humidity")) @@ -153,7 +157,7 @@ struct GrowParams if (cf.groups.contains("leaves_die_heat_min")) leaves_die_heat_min = cf.groups.at("leaves_die_heat_min"); if (cf.groups.contains("leaves_die_chance")) - leaves_die_chance = grow_debug_fast ? 0 : cf.groups.at("leaves_die_chance"); + leaves_die_chance = cf.groups.at("leaves_die_chance"); if (cf.groups.contains("leaves_die_from_liquid")) leaves_die_from_liquid = cf.groups.at("leaves_die_from_liquid"); if (cf.groups.contains("leaves_to_fruit_water_min")) @@ -164,6 +168,14 @@ struct GrowParams leaves_to_fruit_light_min = cf.groups.at("leaves_to_fruit_light_min"); if (cf.groups.contains("leaves_to_fruit_chance")) leaves_to_fruit_chance = cf.groups.at("leaves_to_fruit_chance"); + + if (grow_debug_fast) { + tree_grow_chance = leaves_die_chance = 0; + } + if (grow_debug_fast > 1) { + tree_grow_heat_min = tree_grow_heat_max = leaves_grow_heat_min = + leaves_grow_heat_max = 0; + } } }; @@ -172,13 +184,13 @@ class GrowTree : public ActiveBlockModifier std::unordered_map tree_to_leaves; //, tree_to_fruit; std::unordered_map type_params; - bool grow_debug_fast = false; + int16_t grow_debug_fast = grow_debug_fast_default; // bool grow_debug = false; public: GrowTree(ServerEnvironment *env, NodeDefManager *ndef) { // g_settings->getBoolNoEx("grow_debug", grow_debug); - g_settings->getBoolNoEx("grow_debug_fast", grow_debug_fast); + g_settings->getS16NoEx("grow_debug_fast", grow_debug_fast); std::vector ids; ndef->getIds("group:grow_tree", ids); @@ -190,7 +202,7 @@ class GrowTree : public ActiveBlockModifier tree_to_leaves[id_tree] = id_leaves; const auto &cf_leaves = ndef->get(id_leaves); - type_params.emplace(id_leaves, GrowParams(cf_leaves)); + type_params.emplace(id_leaves, GrowParams(cf_leaves, grow_debug_fast)); // if (!cf_leaves.liquid_alternative_source.empty()) // tree_to_fruit[id_tree] = ndef->getId(cf_leaves.liquid_alternative_source); } @@ -364,6 +376,7 @@ class GrowTree : public ActiveBlockModifier }; if (params.tree_get_water_from_humidity && + self_water_level < params.tree_water_max && self_water_level < params.tree_get_water_max_from_humidity - 1 && near_soil && self_allow_grow_by_rotation && !near_liquid) { float humidity = map->updateBlockHumidity(env, pos); @@ -396,26 +409,23 @@ class GrowTree : public ActiveBlockModifier auto level = nb.node.getLevel(ndef); // TODO: allow get all water if bottom of water != water - if (level <= 1) { - return; - } - //auto amount = grow_debug_fast ? level - 1 : 1; - auto amount = level - 1; - if (self_water_level + amount > params.tree_water_max) { - amount = params.tree_water_max - self_water_level; - } + if (level > 1) { + //auto amount = grow_debug_fast ? level - 1 : 1; + auto amount = level - 1; + if (self_water_level + amount > params.tree_water_max) { + amount = params.tree_water_max - self_water_level; + } - level -= amount; + level -= amount; - if (!grow_debug_fast) { - nb.node.setLevel(ndef, level); - map->setNode(nb.pos, nb.node); - } + if (!grow_debug_fast) { + nb.node.setLevel(ndef, level); + map->setNode(nb.pos, nb.node); + } - self_water_level += amount; - //set_tree_water_level(n, self_water_level); - //map->setNode(p, n); - //if (grow_debug) DUMP("absorbwater", self_water_level, level, amount); + self_water_level += amount; + + } } // Light recalc sometimes too rare @@ -438,9 +448,8 @@ class GrowTree : public ActiveBlockModifier return false; } - if (!((!params.tree_grow_heat_min || heat > params.tree_grow_heat_min) && - (!params.tree_grow_heat_max || - heat < params.tree_grow_heat_max))) { + if ((params.tree_grow_heat_min && heat < params.tree_grow_heat_min) || + (params.tree_grow_heat_max && heat > params.tree_grow_heat_max)) { return false; } @@ -489,11 +498,13 @@ class GrowTree : public ActiveBlockModifier if (!(grow_debug_fast || activate || !myrand_range( - 0, params.tree_grow_chance * (nb.bottom ? 3 : 1)))) + 0, params.tree_grow_chance * (nb.bottom ? 3 : 1)))) { return false; + } - if (!decrease(self_water_level)) + if (!decrease(self_water_level)) { return true; + } //if (grow_debug) DUMP("tr->tr", i, nb.pos.Y, nb.top, nb.bottom, nb.content, content, self_water_level, self_water_level_orig, nb.light); @@ -576,6 +587,7 @@ class GrowTree : public ActiveBlockModifier auto leaves_grow = [&]() { if (!nb.allow_grow_by_rotation) { + // if (grow_debug) DUMP(nb.allow_grow_by_rotation, nb.top, nb.bottom, (int)nb.facedir); return false; } if (nbh[D_TOP].content == content) // TODO not top, by grow direction @@ -585,8 +597,9 @@ class GrowTree : public ActiveBlockModifier if (leaves_content == CONTENT_IGNORE) { return false; } - if (!(heat >= params.leaves_grow_heat_min && - heat <= params.leaves_grow_heat_max)) { + if ((params.leaves_grow_heat_min && heat < params.leaves_grow_heat_min) || + (params.leaves_grow_heat_max && + heat > params.leaves_grow_heat_max)) { return false; } if (!(self_water_level >= (nb.top ? params.leaves_grow_water_min_top @@ -623,19 +636,20 @@ class GrowTree : public ActiveBlockModifier if (self_allow_grow_by_rotation) { int16_t total_level = self_water_level; int8_t have_liquid = 1; - auto &n_bottom = nbh[D_BOTTOM].node; + //auto &n_bottom = nbh[D_BOTTOM].node; if (nbh[D_BOTTOM].content == content) { total_level += nbh[D_BOTTOM].water_level; ++have_liquid; //if (grow_debug)DUMP("get bot", nbh[D_BOTTOM].water_level, total_level,(int)have_liquid); } - auto &n_top = nbh[D_TOP].node; + //auto &n_top = nbh[D_TOP].node; if (nbh[D_TOP].content == content) { total_level += nbh[D_TOP].water_level; // wl_top; ++have_liquid; //if (grow_debug)DUMP("get top", nbh[D_TOP].water_level, total_level,(int)have_liquid); } + const auto total_level_orig = total_level; /* tot @@ -657,9 +671,12 @@ top = ceil(avg - 1) */ const auto float_avg_level = (float)total_level / have_liquid; const auto fill_bottom = [&](bool prefer = false) { - if (nbh[D_BOTTOM].content == content) { - - /* + if (nbh[D_BOTTOM].content != content) + return; + if (total_level <= 1) + return; + //const auto float_avg_level = (float)total_level / have_liquid; + /* const auto float_avg_level = (float)total_level / have_liquid; //if (grow_debug)DUMP(avg_level_for_bottom, (int)have_liquid, total_level); const auto avg_level = prefer ? ceil(float_avg_level + 0.1) @@ -669,30 +686,42 @@ top = ceil(avg - 1) ? avg_level + (avg_level >= (total_level ? 0 : 1)) : params.tree_water_max; */ - //const auto float_avg_level = (float)total_level / have_liquid; - const auto avg_level = prefer ? floor(float_avg_level + 1) - : ceil(float_avg_level - 1); - auto want_level = std::min(avg_level, params.tree_water_max); - - // dont grow down - if (want_level > nbh[D_BOTTOM].water_level) { - want_level = nbh[D_BOTTOM].water_level; - } + //const auto float_avg_level = (float)total_level / have_liquid; + auto avg_level = + prefer ? floor(float_avg_level + 1) : ceil(float_avg_level - 1); + if (avg_level < 1) + avg_level = 1; + auto want_level = std::min(avg_level, params.tree_water_max); + + // dont grow down + if (want_level > nbh[D_BOTTOM].water_level) { + want_level = nbh[D_BOTTOM].water_level; + } - total_level -= want_level; - --have_liquid; - if (nbh[D_BOTTOM].water_level != want_level) { - //if (grow_debug)DUMP("setbot", bottom_level, total_level,avg_level_for_bottom); - set_tree_water_level( - n_bottom, want_level, params.tree_water_param2); - map->setNode(nbh[D_BOTTOM].pos, n_bottom); - } + total_level -= want_level; + + --have_liquid; + if (have_liquid == 1 && total_level > params.tree_water_max && + want_level < params.tree_water_max) { + --total_level; + ++want_level; + } + + if (nbh[D_BOTTOM].water_level != want_level) { + //if (grow_debug)DUMP("setbot", bottom_level, total_level,avg_level_for_bottom); + set_tree_water_level( + nbh[D_BOTTOM].node, want_level, params.tree_water_param2); + map->setNode(nbh[D_BOTTOM].pos, nbh[D_BOTTOM].node); } }; const auto fill_top = [&](bool prefer = false) { - if (nbh[D_TOP].content == content) { - /* + if (nbh[D_TOP].content != content) + return; + if (total_level <= 1) + return; + //const auto float_avg_level = (float)total_level / have_liquid; + /* const auto float_avg_level = (float)total_level / have_liquid; //const int16_t avg_level_for_top = const auto avg_level = prefer ? ceil(float_avg_level + 0.1) @@ -702,20 +731,26 @@ top = ceil(avg - 1) ? avg_level + (avg_level >= (total_level ? 0 : 1)) : params.tree_water_max; */ - //const auto float_avg_level = (float)total_level / have_liquid; - const auto avg_level = prefer ? floor(float_avg_level + 1) - : ceil(float_avg_level - 1); - const auto want_level = - std::min(avg_level, params.tree_water_max); - - total_level -= want_level; - --have_liquid; - if (nbh[D_TOP].water_level != want_level) { + auto avg_level = + prefer ? floor(float_avg_level + 1) : ceil(float_avg_level - 1); + if (avg_level < 1) + avg_level = 1; + auto want_level = std::min(avg_level, params.tree_water_max); + + total_level -= want_level; + --have_liquid; + + if (have_liquid == 1 && total_level > params.tree_water_max && + want_level < params.tree_water_max) { + --total_level; + ++want_level; + } + if (nbh[D_TOP].water_level != want_level) { //if (grow_debug) DUMP("settop", top_level, total_level, avg_level_for_top,around_all_is_tree); - // if (all_is_tree && n_water_level>= params.tree_water_max) DUMP(top_level, total_level, float_avg_level_for_top, avg_level_for_top); - set_tree_water_level(n_top, want_level, params.tree_water_param2); - map->setNode(nbh[D_TOP].pos, n_top); - } + // if (all_is_tree && n_water_level>= params.tree_water_max) DUMP(top_level, total_level, float_avg_level_for_top, avg_level_for_top); + set_tree_water_level( + nbh[D_TOP].node, want_level, params.tree_water_param2); + map->setNode(nbh[D_TOP].pos, nbh[D_TOP].node); } }; @@ -735,7 +770,7 @@ S S S S S S S S S SSS SSS SSS SSS SSS */ // Yggdrasil mode - if (near_tree >= 4 + if (near_tree >= 4 && params.tree_width_to_height //&&((nbh[D_BOTTOM].water_level >= params.tree_get_water_from_humidity / 2) || // params.tree_water_max //(nbh[D_SELF].water_level >= params.tree_get_water_from_humidity / 2)) ) { @@ -757,7 +792,7 @@ class GrowLeaves : public ActiveBlockModifier { std::unordered_map leaves_to_fruit; std::unordered_map type_params; - bool grow_debug_fast = false; + int16_t grow_debug_fast = grow_debug_fast_default; static bool can_grow_leaves( GrowParams params, int8_t level, bool is_top, bool is_bottom) @@ -775,13 +810,13 @@ class GrowLeaves : public ActiveBlockModifier GrowLeaves(ServerEnvironment *env, NodeDefManager *ndef) { // g_settings->getBoolNoEx("grow_debug", grow_debug); - g_settings->getBoolNoEx("grow_debug_fast", grow_debug_fast); + g_settings->getS16NoEx("grow_debug_fast", grow_debug_fast); std::vector ids; ndef->getIds("group:grow_leaves", ids); for (const auto &id : ids) { const auto &cf = ndef->get(id); - type_params.emplace(id, GrowParams(cf)); + type_params.emplace(id, GrowParams(cf, grow_debug_fast)); if (!cf.liquid_alternative_source.empty()) { leaves_to_fruit[id] = ndef->getId(cf.liquid_alternative_source); } diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index d6c872e10..9172217d2 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -1703,7 +1703,7 @@ void read_groups(lua_State *L, int index, ItemGroupList &result) std::string name = luaL_checkstring(L, -2); int rating = luaL_checkinteger(L, -1); // zero rating indicates not in the group - if (rating != 0) + //fm: wtf? if (rating != 0) result[name] = rating; // removes value, keeps key for next iteration lua_pop(L, 1); From 5556ca563f7c56a3b87db837450778fd662f1642 Mon Sep 17 00:00:00 2001 From: proller Date: Wed, 15 Nov 2023 20:35:06 +0100 Subject: [PATCH 14/15] Fix buckets stack --- games/default | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/games/default b/games/default index 56322b15d..2d0e810bd 160000 --- a/games/default +++ b/games/default @@ -1 +1 @@ -Subproject commit 56322b15d2648690992c4c8de44b79a35fe40433 +Subproject commit 2d0e810bd24d2e8c83ec4bf50a3c88ef23378f65 From ad3c8d40e2565ac55a597b664938f14fccefd871 Mon Sep 17 00:00:00 2001 From: proller Date: Wed, 15 Nov 2023 20:37:12 +0100 Subject: [PATCH 15/15] Update submodules --- games/default | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/games/default b/games/default index 2d0e810bd..3b92947db 160000 --- a/games/default +++ b/games/default @@ -1 +1 @@ -Subproject commit 2d0e810bd24d2e8c83ec4bf50a3c88ef23378f65 +Subproject commit 3b92947db70cca3bd707d644482e123efc3f6350