Impossible Ancient Oak/Juniper/etc trees generation

There is two bugs that prevent any ancient tree variation from spawning at the world generation, in this function:

function Landscaper:_get_tree_size(tree_type, value)
   local size_determiner = self._tree_size_determiners[tree_type]
   local quantized = size_determiner.quantizer:quantize_down(value)
   local size = size_determiner.size_map[quantized]

   if size == 'large' then
      local rng = self._rng
      if rng:get_int(1, 100) <= size_determiner.ancient_percentage then
         return ancient
      end
   end
   return size
end

First bug is that size_determiner.ancient_percentage is always being -1. This will make the rng never enter the if condition.

The reason why it is always -1 is because in the function Landscaper:_parse_tree_sizes(tree_variants) there is this piece of code in a loop:

     if tree_size == 'ancient' then
        size_determiner.ancient_percentage = threshold.percentage
     else
        size_determiner.ancient_percentage = -1
        table.insert(thresholds, threshold)
        size_map[threshold] = tree_size
     end

Which will always resets the value back to -1, because the ā€˜ancient’ tree size is not the last call. As soon as another type (small, medium or large) is called, the condition falls into the else statement and the value goes back to -1.


The second bug is that even if we hard code a value there (like 50 to have a 50% chance), when the condition is met an error happens cause it is trying to return the non existent variable ancient, while it should return the string ā€œancientā€

4 Likes

I fixed the second bug by changing that return ancient to return ā€œancientā€

And the first bug at function Landscaper:_parse_tree_sizes(tree_variants) by changing the:

         if tree_size == 'ancient' then
            size_determiner.ancient_percentage = threshold.percentage
         else
            size_determiner.ancient_percentage = -1
            table.insert(thresholds, threshold)
            size_map[threshold] = tree_size
         end

To this:

 if not size_determiner.ancient_percentage then
    size_determiner.ancient_percentage = -1
 end

 if tree_size == 'ancient' then
    size_determiner.ancient_percentage = threshold.percentage
 else
    table.insert(thresholds, threshold)
    size_map[threshold] = tree_size
 end
4 Likes

hmm… i’m not sure if this is a ā€œbugā€, as i’m pretty sure awhile back the team said they removed them until the ancient trees had more of a purpose… could be wrong though, paging @sdee

1 Like

From the point of view that the ancient trees looks almost the same (just bulkier) yeah. But if we are trying to add one ourselves to our biomes (or even changing/adding to the default biomes), there is no way to add ancient trees without changing those codes.

I just had that ā€œ100s of years oldā€- tree in my game. Isnt this the tree you’re talking about?

No, that is the big tree, you can simple plant a sapling and that is the biggest size it reaches.

The ancient tree has (should had) a rare chance to appear, in the temperate it should be 10%. But with this bug it can’t even if you bump it to 100%.

Thanks for taking a look @BrunoSupremo!

@8BitCrab is correct; we removed the ancient trees from world generation till we had a better reason for using them (also, because Tom felt they didn’t look quite right yet). But there’s a chance that the fact that the ancient tree isn’t used is causing the code to atrophy.

2 Likes

That’s ok, there is still other ways to have rarer trees using json alone. I just thought that you guys didn’t noticed that the ancient tree feature was not working.

@BrunoSupremo Thanks for finding the bug! I’ve fixed it and cleaned up the code a bit.

Ancient tree percentages are now specified as 0 in the configuration files which is where that should be controlled.

4 Likes

Moved this back to #support:bug-reports, sorry @BrunoSupremo - I interpreted Stephanie wrong.