changeset 16131:8ecd5cd5ab5c draft

(svn r20827) -Codechange: Simplify code for placement of tree groups.
author terkhen <terkhen@openttd.org>
date Sat, 18 Sep 2010 20:41:06 +0000
parents 5f7494d7492e
children 71686276641e
files src/tree_cmd.cpp
diffstat 1 files changed, 17 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/tree_cmd.cpp
+++ b/src/tree_cmd.cpp
@@ -179,42 +179,29 @@
 }
 
 /**
- * Place some amount of trees around a given tile.
- *
- * This function adds some trees around a given tile. As this function use
- * the Random() call it depends on the random how many trees are actually placed
- * around the given tile.
+ * Creates a number of tree groups.
+ * The number of trees in each group depends on how many trees are actually placed around the given tile.
  *
- * @param tile The center of the trees to add
+ * @param num_groups Number of tree groups to place.
  */
-static void DoPlaceMoreTrees(TileIndex tile)
+static void PlaceTreeGroups(uint num_groups)
 {
-	uint i;
+	do {
+		TileIndex center_tile = RandomTile();
 
-	for (i = 0; i < DEFAULT_TREE_STEPS; i++) {
-		uint32 r = Random();
-		int x = GB(r, 0, 5) - 16;
-		int y = GB(r, 8, 5) - 16;
-		uint dist = abs(x) + abs(y);
-		TileIndex cur_tile = TileAddWrap(tile, x, y);
+		for (uint i = 0; i < DEFAULT_TREE_STEPS; i++) {
+			uint32 r = Random();
+			int x = GB(r, 0, 5) - 16;
+			int y = GB(r, 8, 5) - 16;
+			uint dist = abs(x) + abs(y);
+			TileIndex cur_tile = TileAddWrap(center_tile, x, y);
 
-		if (cur_tile != INVALID_TILE && dist <= 13 && CanPlantTreesOnTile(cur_tile, true)) {
-			PlaceTree(cur_tile, r);
+			if (cur_tile != INVALID_TILE && dist <= 13 && CanPlantTreesOnTile(cur_tile, true)) {
+				PlaceTree(cur_tile, r);
+			}
 		}
-	}
-}
 
-/**
- * Place more trees on the map.
- *
- * This function add more trees to the map.
- */
-static void PlaceMoreTrees()
-{
-	uint i = ScaleByMapSize(GB(Random(), 0, 5) + 25);
-	do {
-		DoPlaceMoreTrees(RandomTile());
-	} while (--i);
+	} while (--num_groups);
 }
 
 /**
@@ -313,7 +300,7 @@
 
 	if (_settings_game.game_creation.tree_placer == TP_NONE) return;
 
-	if (_settings_game.game_creation.landscape != LT_TOYLAND) PlaceMoreTrees();
+	if (_settings_game.game_creation.landscape != LT_TOYLAND) PlaceTreeGroups(ScaleByMapSize(GB(Random(), 0, 5) + 25));
 
 	switch (_settings_game.game_creation.tree_placer) {
 		case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 15 : 6; break;