MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GenerateTrees

Function GenerateTrees

src/tree_cmd.cpp:469–493  ·  view source on GitHub ↗

* Place new trees. * * This function takes care of the selected tree placer algorithm and * place randomly the trees for a new game. */

Source from the content-addressed store, hash-verified

467 * place randomly the trees for a new game.
468 */
469void GenerateTrees()
470{
471 uint i, total;
472
473 if (_settings_game.game_creation.tree_placer == TP_NONE) return;
474
475 switch (_settings_game.game_creation.tree_placer) {
476 case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LandscapeType::Arctic ? 15 : 6; break;
477 case TP_IMPROVED: i = _settings_game.game_creation.landscape == LandscapeType::Arctic ? 4 : 2; break;
478 default: NOT_REACHED();
479 }
480
481 total = Map::ScaleBySize(DEFAULT_TREE_STEPS);
482 if (_settings_game.game_creation.landscape == LandscapeType::Tropic) total += Map::ScaleBySize(DEFAULT_RAINFOREST_TREE_STEPS);
483 total *= i;
484 uint num_groups = (_settings_game.game_creation.landscape != LandscapeType::Toyland) ? Map::ScaleBySize(GB(Random(), 0, 5) + 25) : 0;
485 total += num_groups * DEFAULT_TREE_STEPS;
486 SetGeneratingWorldProgress(GWP_TREE, total);
487
488 if (num_groups != 0) PlaceTreeGroups(num_groups);
489
490 for (; i != 0; i--) {
491 PlaceTreesRandomly();
492 }
493}
494
495/**
496 * Plant a tree.

Callers 1

_GenerateWorldFunction · 0.85

Calls 6

NOT_REACHEDFunction · 0.85
GBFunction · 0.85
PlaceTreeGroupsFunction · 0.85
PlaceTreesRandomlyFunction · 0.85
RandomFunction · 0.50

Tested by

no test coverage detected