Treesplosions are annoying as they can completely junglify an embark that was sparsely forested initially. Not only does an excessive tree take a toll on the FPS, they can also block off parts of the embark completely (especially in the caverns).
My suggestion is to implement an algorithm that causes sapling maturation to slow and stop as the tree density increases. I'd try something along these lines:
- When a sapling is due to mature, make a random determination of whether it is a candidate or if it succumbed to background circumstances (being eaten, parasites, ...). I believe this is basically how it works today, but instead of becoming a tree on a successful roll, the sapling would move to the next stage. The maturation threshold should probably be lowered to compensate for losses in the following stage, though.
- Each biome would have its own set of parameters that controlled maximum tree density.
- I'd try to use two factors to control the process: Distance and Density_Acceptance. The Distance would determine how far away other trees would influence the maturation of a sapling, while Density_Acceptance would be an adjustment factor that determines how many trees' worth of neighbors a sapling can tolerate to have any chance to mature (or, rather, when the chance is reduced to zero).
- I'd have a distance drop-off relation to give a higher weight to an adjacent tree than to one further away. You could e.g. give a weight of 1/distance to each tree within the cutoff Distance.
- You could either use an actual distance to a neighbor tree, or just use the larger of the X or Y distance.
- You would have an overall maximum distance of e.g. 20 tiles.
- Each tree within the maximum distance would add a value of 1/distance/Density_Acceptance of the biome that tree resides in, with 0 if that biome's Distance is shorter than the actual distance (this should result in a gradual density gradient in biome border regions).
- If a tile is a non tree supporting tile (air, rock, water, treeless desert, etc) I'd add a value of 1/320/distance (with a 20 tile max X/Y distance that should mean a single tile surrounded by non tree supporting tiles would have a 50% chance of maturing, if I've calculated it correctly). This is intended to provide some negative pressure from non tree supporting areas.
- The sum of all the results out to the maximum distance should then sum up to a chance of (1.0 - Sum) of maturing, which can be negative, i.e. no chance at all.
- I would probably only check the same Z level as that of the sapling, but it would be possible to check upwards/downwards if desired, to cater for trees below or a canopy above, with the associated complications of a potential floor in between. My guess is that taking Z levels into account isn't worth the effort.
A jungle might have a short Distance of e.g. 3, while a sparsely wooded desert might use the maximum Distance. Similarly, a jungle should have a higher tolerance for competition than less densely forested biomes.
I think sapling maturation happens infrequently enough that the extra CPU used to calculate maturation is more than offset by the savings resulting from not having to calculate the growth of as many trees.
Edit: Below I'm trying to summarize what's known/believed about the current tree behavior, including insights gained after the discussion below occurred.
- A bug correction report indicates adventure mode trees (and a lot of other things) are generated from tile related seeds as the tile is prepared for display.
- There is no indication there is currently any difference in the terminal tree density influenced by the biome. All biomes supporting trees will eventually end up equally dense, apart from inherent differences in canopy suppression (more below) and density of vegetation supporting ground tiles (lots of stones and surface clay can reduce the number of tiles available for vegetation).
- The initial tree density of a fortress biome is probably (my guess) generated using exactly the same algorithm as is used for adventure mode, and that one does, obviously, generate a different tree density appropriate for the biome (as per Toady's interpretation), but has no influence whatsoever for the further tree development.
- Saplings appear to spring up randomly in eligible tiles in competition with other vegetation.
- I haven't heard of any investigation that indicates any pruning of sapling type based on an over abundance of that type of the tree already on the map, although there have been speculations about such a mechanism, I find it unlikely to be present.
- I've speculated above and below that saplings have a random risk of dying rather than maturing. As far as I've seen, that is not the case. Instead, saplings die only because of canopy suppression, physical abuse (trampling), and physical obstructions blocking maturation (ceiling lower than two tiles. Note that bridges do not count as ceilings: trees below will mature and sprout though the bridges [0.40.24, unlikely to have changed]).
- It's currently believed saplings below the canopy of another tree will die, thus providing a small uneven zone around the tree where competition is kept at bay. My experiments indicate this suppression acts ONLY on the level directly above the ground, i.e. the canopy acts identically to a floor above. I've got 3 cases where saplings have matured with a canopy above two tiles above the ground. However, any canopy part, including twigs, seem to suppress sapling maturation if at the appropriate elevation.
- Palm trees and the like have very small canopies, young trees have small, usually lopsided, canopies, and cavern trees are just terrible, with many types just sprouting a pole that may, after many years, grow into a hat, leaving ample time for fences to form. I haven't been able to look too closely at palm trees as I haven't embarked in such biomes much, but there is a risk their canopies actually appear only 2 levels above the ground if they look like real world counterparts, in which case they would provide no suppression at all.
Edit 2:
- After observing a multi biome embark, I've seen the tree maturation rate being considerably higher in the forest biomes than in other biomes. This observation does not contradict the observations above, as it means an undisturbed forest will reach the end density faster than sparser biomes, but the end density will still be the same.