summaryrefslogtreecommitdiff
path: root/tree_cmd.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2006-08-19 10:00:30 +0000
committertruelight <truelight@openttd.org>2006-08-19 10:00:30 +0000
commit10b842bddcbe6cdcf7111736bec985cdc13e528f (patch)
treecd9ad6758b68622254b2545359b5d87f88f7074b /tree_cmd.c
parent83d56d6d798a28169f00a4c67323a407037c0b0a (diff)
downloadopenttd-10b842bddcbe6cdcf7111736bec985cdc13e528f.tar.xz
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin) - Load heightmaps (either BMP or PNG) - Progress dialog while generating worlds (no longer a 'hanging' screen) - New dialogs for NewGame, Create Scenario and Play Heightmap - Easier to configure your landscape - More things to configure (tree-placer, ..) - Speedup of world generation - New console command 'restart': restart the map EXACTLY as it was when you first started it (needs a game made after or with this commit) - New console command 'getseed': get the seed of your map and share it with others (of course only works with generated maps) - Many new, world generation related, things - Many internal cleanups and rewrites Many tnx to those people who helped making this: Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic) Many tnx to those who helped testing: Arnau, Bjarni, and tokai (alfabetic) And to all other people who helped testing and sending comments / bugs Stats: 673 lines changed, 3534 new lines, 79 new strings
Diffstat (limited to 'tree_cmd.c')
-rw-r--r--tree_cmd.c83
1 files changed, 79 insertions, 4 deletions
diff --git a/tree_cmd.c b/tree_cmd.c
index 99b2de384..6366df469 100644
--- a/tree_cmd.c
+++ b/tree_cmd.c
@@ -15,6 +15,13 @@
#include "town.h"
#include "sound.h"
#include "variables.h"
+#include "genworld.h"
+
+enum TreePlacer {
+ TP_NONE,
+ TP_ORIGINAL,
+ TP_IMPROVED,
+};
static TreeType GetRandomTreeType(TileIndex tile, uint seed)
{
@@ -83,18 +90,70 @@ static void PlaceMoreTrees(void)
} while (--i);
}
-void PlaceTreesRandomly(void)
+/**
+ * Place a tree at the same height as an existing tree.
+ * This gives cool effects to the map.
+ */
+void PlaceTreeAtSameHeight(TileIndex tile, uint height)
{
uint i;
+ for (i = 0; i < 1000; i++) {
+ uint32 r = Random();
+ int x = GB(r, 0, 5) - 16;
+ int y = GB(r, 8, 5) - 16;
+ TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y));
+
+ /* Keep in range of the existing tree */
+ if (myabs(x) + myabs(y) > 16) continue;
+
+ /* Clear tile, no farm-tiles or rocks */
+ if (!IsTileType(cur_tile, MP_CLEAR) ||
+ IsClearGround(cur_tile, CLEAR_FIELDS) ||
+ IsClearGround(cur_tile, CLEAR_ROCKS))
+ continue;
+
+ /* Not too much height difference */
+ if (myabs(GetTileZ(cur_tile) - height) > 2) continue;
+
+ /* Place one tree and quit */
+ PlaceTree(cur_tile, r);
+ break;
+ }
+}
+
+void PlaceTreesRandomly(void)
+{
+ uint i, j, ht;
+
i = ScaleByMapSize(1000);
do {
uint32 r = Random();
TileIndex tile = RandomTileSeed(r);
+
+ IncreaseGeneratingWorldProgress(GWP_TREE);
+
if (IsTileType(tile, MP_CLEAR) &&
!IsClearGround(tile, CLEAR_FIELDS) &&
!IsClearGround(tile, CLEAR_ROCKS)) {
PlaceTree(tile, r);
+ if (_patches.tree_placer != TP_IMPROVED) continue;
+
+ /* Place a number of trees based on the tile height.
+ * This gives a cool effect of multiple trees close together.
+ * It is almost real life ;) */
+ ht = GetTileZ(tile);
+ /* The higher we get, the more trees we plant */
+ j = GetTileZ(tile) / TILE_HEIGHT * 2;
+ while (j--) {
+ /* Above snowline more trees! */
+ if (_opt.landscape == LT_HILLY && ht > _opt.snow_line) {
+ PlaceTreeAtSameHeight(tile, ht);
+ PlaceTreeAtSameHeight(tile, ht);
+ };
+
+ PlaceTreeAtSameHeight(tile, ht);
+ }
}
} while (--i);
@@ -105,7 +164,10 @@ void PlaceTreesRandomly(void)
do {
uint32 r = Random();
TileIndex tile = RandomTileSeed(r);
- if (IsTileType(tile, MP_CLEAR) && GetTropicZone(tile) == TROPICZONE_RAINFOREST) {
+
+ IncreaseGeneratingWorldProgress(GWP_TREE);
+
+ if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_FIELDS) && GetTropicZone(tile) == TROPICZONE_RAINFOREST) {
PlaceTree(tile, r);
}
} while (--i);
@@ -114,11 +176,24 @@ void PlaceTreesRandomly(void)
void GenerateTrees(void)
{
- uint i;
+ uint i, total;
+
+ if (_patches.tree_placer == TP_NONE) return;
if (_opt.landscape != LT_CANDY) PlaceMoreTrees();
- for (i = _opt.landscape == LT_HILLY ? 15 : 6; i != 0; i--) {
+ switch (_patches.tree_placer) {
+ case TP_ORIGINAL: i = _opt.landscape == LT_HILLY ? 15 : 6; break;
+ case TP_IMPROVED: i = _opt.landscape == LT_HILLY ? 4 : 2; break;
+ default: NOT_REACHED(); return;
+ }
+
+ total = ScaleByMapSize(1000);
+ if (_opt.landscape == LT_DESERT) total += ScaleByMapSize(15000);
+ total *= i;
+ SetGeneratingWorldProgress(GWP_TREE, total);
+
+ for (; i != 0; i--) {
PlaceTreesRandomly();
}
}