static TreeType GetRandomTreeType(TileIndex tile, uint seed)
{
uint8 th = TileHeight(tile);
uint limited_seed = seed / 16;
uint8 no_trees_height = _settings_game.game_creation.no_trees_height - limited_seed;
uint8 evergreen_min_height = _settings_game.game_creation.evergreen_min_height - limited_seed;
switch (_settings_game.game_creation.landscape) {
case LT_ARCTIC:
/* In arctic clamp the heights to snow line */
no_trees_height = max(GetSnowLine(), no_trees_height);
evergreen_min_height = min(GetSnowLine(), evergreen_min_height);
/* Fall through */
case LT_TEMPERATE:
if (th > no_trees_height) {
return TREE_INVALID;
}
if (th < evergreen_min_height) {
return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
}
return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
case LT_TROPIC:
switch (GetTropicZone(tile)) {
case TROPICZONE_NORMAL: return (TreeType)(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL);
case TROPICZONE_DESERT: return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS);
default: return (TreeType)(seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST);
}
default:
return (TreeType)(seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND);
}
}