src/tree_cmd.cpp
author glx
Thu, 03 Jan 2008 23:50:58 +0000
changeset 8682 c41d89c0ca8f
parent 8653 a83f7a536919
child 8683 1f3141299c8e
permissions -rw-r--r--
(svn r11749) -Fix (r11352): when a bankrupted company is bought, reset vehicle color mapping so the vehicles use the new owner color
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6683
diff changeset
     3
/** @file tree_cmd.cpp */
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6683
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1784
diff changeset
     6
#include "openttd.h"
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
     7
#include "bridge_map.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3079
diff changeset
     8
#include "clear_map.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     9
#include "table/strings.h"
2148
47ba4a1b1c3b (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2118
diff changeset
    10
#include "table/sprites.h"
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
    11
#include "table/tree_land.h"
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8612
diff changeset
    12
#include "tile_cmd.h"
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6574
diff changeset
    13
#include "landscape.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3079
diff changeset
    14
#include "tree_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "viewport.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8604
diff changeset
    16
#include "command_func.h"
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8604
diff changeset
    17
#include "economy_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "town.h"
2153
91e89aa8c299 (svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents: 2148
diff changeset
    19
#include "variables.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    20
#include "genworld.h"
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8208
diff changeset
    21
#include "transparency.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8615
diff changeset
    22
#include "functions.h"
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8615
diff changeset
    23
#include "player.h"
8653
a83f7a536919 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8635
diff changeset
    24
#include "sound_func.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    25
8093
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    26
/**
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    27
 * List of tree placer algorithm.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    28
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    29
 * This enumeration defines all possible tree placer algorithm in the game.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    30
 */
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    31
enum TreePlacer {
8093
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    32
	TP_NONE,     ///< No tree placer algorithm
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    33
	TP_ORIGINAL, ///< The original algorithm
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    34
	TP_IMPROVED, ///< A 'improved' algorithm
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    35
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
8093
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    37
/**
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    38
 * Get a random TreeType for the given tile based on a given seed
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    39
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    40
 * This function returns a random TreeType which can be placed on the given tile.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    41
 * The seed for randomness must be less or equal 256, use #GB on the value of Random()
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    42
 * to get such a value.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    43
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    44
 * @param tile The tile to get a random TreeType from
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    45
 * @param seed The seed for randomness, must be less or equal 256
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    46
 * @return The random tree type
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    47
 */
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
    48
static TreeType GetRandomTreeType(TileIndex tile, uint seed)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
{
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    50
	switch (_opt.landscape) {
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
    51
		case LT_TEMPERATE:
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    52
			return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
    54
		case LT_ARCTIC:
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    55
			return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    56
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
    57
		case LT_TROPIC:
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3271
diff changeset
    58
			switch (GetTropicZone(tile)) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    59
				case TROPICZONE_INVALID: return (TreeType)(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    60
				case TROPICZONE_DESERT:  return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    61
				default:                 return (TreeType)(seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    62
			}
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    63
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    64
		default:
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    65
			return (TreeType)(seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
8093
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    69
/**
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    70
 * Make a random tree tile of the given tile
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    71
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    72
 * Create a new tree-tile for the given tile. The second parameter is used for
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    73
 * randomness like type and number of trees.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    74
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    75
 * @param tile The tile to make a tree-tile from
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    76
 * @param r The randomness value from a Random() value
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    77
 */
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2957
diff changeset
    78
static void PlaceTree(TileIndex tile, uint32 r)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
{
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
    80
	TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8));
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    81
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    82
	if (tree != TREE_INVALID) {
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    83
		MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6683
diff changeset
    85
		/* above snowline? */
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
    86
		if (_opt.landscape == LT_ARCTIC && GetTileZ(tile) > GetSnowLine()) {
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    87
			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    88
			SetTreeCounter(tile, (TreeGround)GB(r, 24, 3));
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    89
		} else {
8206
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
    90
			SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    91
			SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
8093
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    96
/**
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    97
 * Place some amount of trees around a given tile.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    98
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
    99
 * This function adds some trees around a given tile. As this function use
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   100
 * the Random() call it depends on the random how many trees are actually placed
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   101
 * around the given tile.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   102
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   103
 * @param tile The center of the trees to add
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   104
 */
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   105
static void DoPlaceMoreTrees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
{
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   107
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   109
	for (i = 0; i < 1000; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
		uint32 r = Random();
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   111
		int x = GB(r, 0, 5) - 16;
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   112
		int y = GB(r, 8, 5) - 16;
8419
de9999f762d0 (svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents: 8372
diff changeset
   113
		uint dist = abs(x) + abs(y);
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   114
		TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   116
		if (dist <= 13 &&
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   117
				IsTileType(cur_tile, MP_CLEAR) &&
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
   118
				!IsBridgeAbove(cur_tile) &&
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   119
				!IsClearGround(cur_tile, CLEAR_FIELDS) &&
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   120
				!IsClearGround(cur_tile, CLEAR_ROCKS)) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2957
diff changeset
   121
			PlaceTree(cur_tile, r);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
		}
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   123
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
8093
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   126
/**
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   127
 * Place more trees on the map.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   128
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   129
 * This function add more trees to the map.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   130
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6459
diff changeset
   131
static void PlaceMoreTrees()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
{
2243
9a319ce6bd58 (svn r2763) Small cleanup and improve a few comments
tron
parents: 2238
diff changeset
   133
	uint i = ScaleByMapSize(GB(Random(), 0, 5) + 25);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
	do {
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
   135
		DoPlaceMoreTrees(RandomTile());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   139
/**
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   140
 * Place a tree at the same height as an existing tree.
8093
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   141
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   142
 * Add a new tree around the given tile which is at the same
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   143
 * height or at some offset (2 units) of it.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   144
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   145
 * @param tile The base tile to add a new tree somewhere around
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   146
 * @param height The height (like the one from the tile)
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   147
 */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   148
void PlaceTreeAtSameHeight(TileIndex tile, uint height)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   149
{
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   150
	uint i;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   151
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   152
	for (i = 0; i < 1000; i++) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   153
		uint32 r = Random();
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   154
		int x = GB(r, 0, 5) - 16;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   155
		int y = GB(r, 8, 5) - 16;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   156
		TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y));
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   157
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   158
		/* Keep in range of the existing tree */
8419
de9999f762d0 (svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents: 8372
diff changeset
   159
		if (abs(x) + abs(y) > 16) continue;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   160
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   161
		/* Clear tile, no farm-tiles or rocks */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   162
		if (!IsTileType(cur_tile, MP_CLEAR) ||
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   163
				IsClearGround(cur_tile, CLEAR_FIELDS) ||
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   164
				IsClearGround(cur_tile, CLEAR_ROCKS))
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   165
			continue;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   166
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   167
		/* Not too much height difference */
8466
9ce95e16f9f9 (svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents: 8463
diff changeset
   168
		if (Delta(GetTileZ(cur_tile), height) > 2) continue;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   169
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   170
		/* Place one tree and quit */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   171
		PlaceTree(cur_tile, r);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   172
		break;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   173
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   174
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   175
8093
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   176
/**
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   177
 * Place some trees randomly
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   178
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   179
 * This function just place some trees randomly on the map.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   180
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6459
diff changeset
   181
void PlaceTreesRandomly()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
{
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   183
	uint i, j, ht;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
1202
7d8b86bd8ba2 (svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents: 1093
diff changeset
   185
	i = ScaleByMapSize(1000);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	do {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   187
		uint32 r = Random();
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   188
		TileIndex tile = RandomTileSeed(r);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   189
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   190
		IncreaseGeneratingWorldProgress(GWP_TREE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   191
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   192
		if (IsTileType(tile, MP_CLEAR) &&
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
   193
				!IsBridgeAbove(tile) &&
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   194
				!IsClearGround(tile, CLEAR_FIELDS) &&
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   195
				!IsClearGround(tile, CLEAR_ROCKS)) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2957
diff changeset
   196
			PlaceTree(tile, r);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   197
			if (_patches.tree_placer != TP_IMPROVED) continue;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   198
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   199
			/* Place a number of trees based on the tile height.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   200
			 *  This gives a cool effect of multiple trees close together.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   201
			 *  It is almost real life ;) */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   202
			ht = GetTileZ(tile);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   203
			/* The higher we get, the more trees we plant */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   204
			j = GetTileZ(tile) / TILE_HEIGHT * 2;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   205
			while (j--) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   206
				/* Above snowline more trees! */
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   207
				if (_opt.landscape == LT_ARCTIC && ht > GetSnowLine()) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   208
					PlaceTreeAtSameHeight(tile, ht);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   209
					PlaceTreeAtSameHeight(tile, ht);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   210
				};
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   211
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   212
				PlaceTreeAtSameHeight(tile, ht);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   213
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
	/* place extra trees at rainforest area */
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   218
	if (_opt.landscape == LT_TROPIC) {
1202
7d8b86bd8ba2 (svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents: 1093
diff changeset
   219
		i = ScaleByMapSize(15000);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
		do {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   222
			uint32 r = Random();
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   223
			TileIndex tile = RandomTileSeed(r);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   224
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   225
			IncreaseGeneratingWorldProgress(GWP_TREE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   226
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
   227
			if (IsTileType(tile, MP_CLEAR) &&
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
   228
					!IsBridgeAbove(tile) &&
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
   229
					!IsClearGround(tile, CLEAR_FIELDS) &&
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
   230
					GetTropicZone(tile) == TROPICZONE_RAINFOREST) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2957
diff changeset
   231
				PlaceTree(tile, r);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
		} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
8093
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   237
/**
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   238
 * Place new trees.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   239
 *
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   240
 * This function takes care of the selected tree placer algorithm and
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   241
 * place randomly the trees for a new game.
6f0fa5c9dacc (svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents: 8005
diff changeset
   242
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6459
diff changeset
   243
void GenerateTrees()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
{
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   245
	uint i, total;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   246
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   247
	if (_patches.tree_placer == TP_NONE) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   249
	if (_opt.landscape != LT_TOYLAND) PlaceMoreTrees();
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   250
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   251
	switch (_patches.tree_placer) {
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   252
		case TP_ORIGINAL: i = _opt.landscape == LT_ARCTIC ? 15 : 6; break;
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   253
		case TP_IMPROVED: i = _opt.landscape == LT_ARCTIC ?  4 : 2; break;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   254
		default: NOT_REACHED(); return;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   255
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   256
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   257
	total = ScaleByMapSize(1000);
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   258
	if (_opt.landscape == LT_TROPIC) total += ScaleByMapSize(15000);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   259
	total *= i;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   260
	SetGeneratingWorldProgress(GWP_TREE, total);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   261
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   262
	for (; i != 0; i--) {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   263
		PlaceTreesRandomly();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   267
/** Plant a tree.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   268
 * @param tile start tile of area-drag of tree plantation
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6683
diff changeset
   269
 * @param flags type of operation
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   270
 * @param p1 tree type, -1 means random.
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   271
 * @param p2 end tile of area-drag
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7179
diff changeset
   273
CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
{
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3144
diff changeset
   275
	StringID msg = INVALID_STRING_ID;
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7179
diff changeset
   276
	CommandCost cost;
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   277
	int ex;
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   278
	int ey;
2118
c73d32cc0b5e (svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents: 2088
diff changeset
   279
	int sx, sy, x, y;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   280
2892
390125af7685 (svn r3446) - Fix: incorrect validating of tree-planting command which can allow a buffer-overflow (Tron)
Darkvater
parents: 2654
diff changeset
   281
	if (p2 >= MapSize()) return CMD_ERROR;
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   282
	/* Check the tree type. It can be random or some valid value within the current climate */
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   283
	if (p1 != (uint)-1 && p1 - _tree_base_by_landscape[_opt.landscape] >= _tree_count_by_landscape[_opt.landscape]) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   284
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	// make sure sx,sy are smaller than ex,ey
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   288
	ex = TileX(tile);
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   289
	ey = TileY(tile);
2118
c73d32cc0b5e (svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents: 2088
diff changeset
   290
	sx = TileX(p2);
c73d32cc0b5e (svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents: 2088
diff changeset
   291
	sy = TileY(p2);
6432
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 5919
diff changeset
   292
	if (ex < sx) Swap(ex, sx);
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 5919
diff changeset
   293
	if (ey < sy) Swap(ey, sy);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   294
2118
c73d32cc0b5e (svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents: 2088
diff changeset
   295
	for (x = sx; x <= ex; x++) {
c73d32cc0b5e (svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents: 2088
diff changeset
   296
		for (y = sy; y <= ey; y++) {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   297
			TileIndex tile = TileXY(x, y);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   298
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   299
			switch (GetTileType(tile)) {
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   300
				case MP_TREES:
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6683
diff changeset
   301
					/* no more space for trees? */
3003
15a000f2b81d (svn r3583) Fix 2 glitches in r3556
tron
parents: 2981
diff changeset
   302
					if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 3) {
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3144
diff changeset
   303
						msg = STR_2803_TREE_ALREADY_HERE;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   304
						continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   307
					if (flags & DC_EXEC) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   308
						AddTreeCount(tile, 1);
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   309
						MarkTileDirtyByTile(tile);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   310
					}
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6683
diff changeset
   311
					/* 2x as expensive to add more trees to an existing tile */
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   312
					cost.AddCost(_price.build_trees * 2);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   313
					break;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   314
8005
9f7a95e84682 (svn r11024) -Fix [FS#1173]: give a more correct error when building some things on tile 0; "Can't build on water" or "Too close to the edge" instead of "Vehicle in the way". Patch by SmatZ.
rubidium
parents: 7990
diff changeset
   315
				case MP_WATER:
9f7a95e84682 (svn r11024) -Fix [FS#1173]: give a more correct error when building some things on tile 0; "Can't build on water" or "Too close to the edge" instead of "Vehicle in the way". Patch by SmatZ.
rubidium
parents: 7990
diff changeset
   316
					msg = STR_3807_CAN_T_BUILD_ON_WATER;
9f7a95e84682 (svn r11024) -Fix [FS#1173]: give a more correct error when building some things on tile 0; "Can't build on water" or "Too close to the edge" instead of "Vehicle in the way". Patch by SmatZ.
rubidium
parents: 7990
diff changeset
   317
					continue;
9f7a95e84682 (svn r11024) -Fix [FS#1173]: give a more correct error when building some things on tile 0; "Can't build on water" or "Too close to the edge" instead of "Vehicle in the way". Patch by SmatZ.
rubidium
parents: 7990
diff changeset
   318
					break;
9f7a95e84682 (svn r11024) -Fix [FS#1173]: give a more correct error when building some things on tile 0; "Can't build on water" or "Too close to the edge" instead of "Vehicle in the way". Patch by SmatZ.
rubidium
parents: 7990
diff changeset
   319
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   320
				case MP_CLEAR:
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
   321
					if (!IsTileOwner(tile, OWNER_NONE) ||
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
   322
							IsBridgeAbove(tile)) {
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3144
diff changeset
   323
						msg = STR_2804_SITE_UNSUITABLE;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   324
						continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
					}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   326
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   327
					switch (GetClearGround(tile)) {
8473
773b817b64d0 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 8466
diff changeset
   328
						case CLEAR_FIELDS: cost.AddCost(_price.clear_fields); break;
773b817b64d0 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 8466
diff changeset
   329
						case CLEAR_ROCKS:  cost.AddCost(_price.clear_rocks); break;
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   330
						default: break;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   331
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
8682
c41d89c0ca8f (svn r11749) -Fix (r11352): when a bankrupted company is bought, reset vehicle color mapping so the vehicles use the new owner color
glx
parents: 8653
diff changeset
   333
					if (_game_mode != GM_EDITOR && IsValidPlayer(_current_player)) {
c41d89c0ca8f (svn r11749) -Fix (r11352): when a bankrupted company is bought, reset vehicle color mapping so the vehicles use the new owner color
glx
parents: 8653
diff changeset
   334
						Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
c41d89c0ca8f (svn r11749) -Fix (r11352): when a bankrupted company is bought, reset vehicle color mapping so the vehicles use the new owner color
glx
parents: 8653
diff changeset
   335
						if (t != NULL)
c41d89c0ca8f (svn r11749) -Fix (r11352): when a bankrupted company is bought, reset vehicle color mapping so the vehicles use the new owner color
glx
parents: 8653
diff changeset
   336
							ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
c41d89c0ca8f (svn r11749) -Fix (r11352): when a bankrupted company is bought, reset vehicle color mapping so the vehicles use the new owner color
glx
parents: 8653
diff changeset
   337
					}
c41d89c0ca8f (svn r11749) -Fix (r11352): when a bankrupted company is bought, reset vehicle color mapping so the vehicles use the new owner color
glx
parents: 8653
diff changeset
   338
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   339
					if (flags & DC_EXEC) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   340
						TreeType treetype;
3079
d6541c027250 (svn r3668) Add a function to turn a tile into a tree tile
tron
parents: 3076
diff changeset
   341
						uint growth;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   342
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   343
						treetype = (TreeType)p1;
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   344
						if (treetype == TREE_INVALID) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   345
							treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   346
							if (treetype == TREE_INVALID) treetype = TREE_CACTUS;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   347
						}
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   348
3079
d6541c027250 (svn r3668) Add a function to turn a tile into a tree tile
tron
parents: 3076
diff changeset
   349
						growth = _game_mode == GM_EDITOR ? 3 : 0;
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   350
						switch (GetClearGround(tile)) {
8206
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   351
							case CLEAR_ROUGH:  MakeTree(tile, treetype, 0, growth, TREE_GROUND_ROUGH, 3); break;
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   352
							case CLEAR_SNOW:
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   353
							case CLEAR_DESERT: MakeTree(tile, treetype, 0, growth, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break;
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   354
							default:           MakeTree(tile, treetype, 0, growth, TREE_GROUND_GRASS, GetClearDensity(tile)); break;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   355
						}
3003
15a000f2b81d (svn r3583) Fix 2 glitches in r3556
tron
parents: 2981
diff changeset
   356
						MarkTileDirtyByTile(tile);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   357
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8419
diff changeset
   358
						if (_game_mode == GM_EDITOR && IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS))
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3271
diff changeset
   359
							SetTropicZone(tile, TROPICZONE_RAINFOREST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
					}
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   361
					cost.AddCost(_price.build_trees);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   362
					break;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   363
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   364
				default:
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3144
diff changeset
   365
					msg = STR_2804_SITE_UNSUITABLE;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   366
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   370
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   371
	if (cost.GetCost() == 0) {
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3144
diff changeset
   372
		return_cmd_error(msg);
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3144
diff changeset
   373
	} else {
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3144
diff changeset
   374
		return cost;
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3144
diff changeset
   375
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   378
struct TreeListEnt {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   379
	SpriteID image;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   380
	SpriteID pal;
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6923
diff changeset
   381
	byte x, y;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   382
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
static void DrawTile_Trees(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
{
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   386
	const PalSpriteID *s;
2654
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2644
diff changeset
   387
	const TreePos* d;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
	byte z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   390
	switch (GetTreeGround(ti->tile)) {
8206
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   391
		case TREE_GROUND_GRASS: DrawClearLandTile(ti, GetTreeDensity(ti->tile)); break;
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   392
		case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   393
		default: DrawGroundSprite(_tree_sprites_1[GetTreeDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
2220
6c186dad8188 (svn r2738) Small bit fiddling cleanup
tron
parents: 2186
diff changeset
   396
	DrawClearLandFence(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
	z = ti->z;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   399
	if (ti->tileh != SLOPE_FLAT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
		z += 4;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   401
		if (IsSteepSlope(ti->tileh)) z += 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
		uint16 tmp = ti->x;
959
b031d88c76f3 (svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents: 926
diff changeset
   406
		uint index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   408
		tmp = ROR(tmp, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
		tmp -= ti->y;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   410
		tmp = ROR(tmp, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
		tmp -= ti->x;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   412
		tmp = ROR(tmp, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
		tmp += ti->y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   415
		d = _tree_layout_xy[GB(tmp, 4, 2)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   417
		index = GB(tmp, 6, 2) + (GetTreeType(ti->tile) << 2);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   418
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
		/* different tree styles above one of the grounds */
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   420
		if (GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT &&
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   421
				GetTreeDensity(ti->tile) >= 2 &&
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8419
diff changeset
   422
				IsInsideMM(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) {
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   423
			index += 164 - (TREE_SUB_ARCTIC << 2);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   424
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   425
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   426
		assert(index < lengthof(_tree_layout_sprite));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
		s = _tree_layout_sprite[index];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
	StartSpriteCombine();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
8372
b8194a7821ac (svn r11426) -Codechange: Just one boolean inversion instead of two
belugas
parents: 8345
diff changeset
   432
	if (!(IsTransparencySet(TO_TREES) && _patches.invisible_trees)) {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   433
		TreeListEnt te[4];
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   434
		uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
		/* put the trees to draw in a list */
3271
0e796a2b7c9e (svn r3983) Use existing functions to access tree and road info
tron
parents: 3183
diff changeset
   437
		i = GetTreeCount(ti->tile) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
		do {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   439
			SpriteID image = s[0].sprite + (--i == 0 ? GetTreeGrowth(ti->tile) : 3);
7829
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7813
diff changeset
   440
			SpriteID pal = s[0].pal;
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7813
diff changeset
   441
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
			te[i].image = image;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   443
			te[i].pal   = pal;
2654
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2644
diff changeset
   444
			te[i].x = d->x;
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2644
diff changeset
   445
			te[i].y = d->y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
			s++;
2654
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2644
diff changeset
   447
			d++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
		} while (i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
		/* draw them in a sorted way */
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2912
diff changeset
   451
		for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
			byte min = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
			TreeListEnt *tep = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
3271
0e796a2b7c9e (svn r3983) Use existing functions to access tree and road info
tron
parents: 3183
diff changeset
   455
			i = GetTreeCount(ti->tile) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
			do {
2644
6f699b15c531 (svn r3186) Unnecessary casts and truncation
tron
parents: 2639
diff changeset
   457
				if (te[--i].image != 0 && te[i].x + te[i].y < min) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
					min = te[i].x + te[i].y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
					tep = &te[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
			} while (i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   463
			if (tep == NULL) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8208
diff changeset
   465
			AddSortableSpriteToDraw(tep->image, tep->pal, ti->x + tep->x, ti->y + tep->y, 16 - tep->x, 16 - tep->y, 0x30, z, IsTransparencySet(TO_TREES), -tep->x, -tep->y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
			tep->image = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
	EndSpriteCombine();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   474
static uint GetSlopeZ_Trees(TileIndex tile, uint x, uint y)
2537
d9c0df52a466 (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2436
diff changeset
   475
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   476
	uint z;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   477
	Slope tileh = GetTileSlope(tile, &z);
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   478
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   479
	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   482
static Foundation GetFoundation_Trees(TileIndex tile, Slope tileh)
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2537
diff changeset
   483
{
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   484
	return FOUNDATION_NONE;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   485
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   486
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7179
diff changeset
   487
static CommandCost ClearTile_Trees(TileIndex tile, byte flags)
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   488
{
2243
9a319ce6bd58 (svn r2763) Small cleanup and improve a few comments
tron
parents: 2238
diff changeset
   489
	uint num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
8682
c41d89c0ca8f (svn r11749) -Fix (r11352): when a bankrupted company is bought, reset vehicle color mapping so the vehicles use the new owner color
glx
parents: 8653
diff changeset
   491
	if (IsValidPlayer(_current_player)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
		Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   493
		if (t != NULL)
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 988
diff changeset
   494
			ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   497
	num = GetTreeCount(tile) + 1;
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8419
diff changeset
   498
	if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
2243
9a319ce6bd58 (svn r2763) Small cleanup and improve a few comments
tron
parents: 2238
diff changeset
   500
	if (flags & DC_EXEC) DoClearSquare(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   502
	return CommandCost(num * _price.remove_trees);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   505
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   510
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
{
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   512
	TreeType tt = GetTreeType(tile);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   513
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8419
diff changeset
   514
	if (IsInsideMM(tt, TREE_RAINFOREST, TREE_CACTUS)) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   515
		td->str = STR_280F_RAINFOREST;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   516
	} else {
8208
ee19a137b686 (svn r11246) -Codechange: beautify some conditions from "if else" into trinary operator
belugas
parents: 8206
diff changeset
   517
		td->str = tt == TREE_CACTUS ? STR_2810_CACTUS_PLANTS : STR_280E_TREES;
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   518
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   520
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   523
static void AnimateTile_Trees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   528
static void TileLoopTreesDesert(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
{
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3271
diff changeset
   530
	switch (GetTropicZone(tile)) {
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3271
diff changeset
   531
		case TROPICZONE_DESERT:
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   532
			if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) {
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   533
				SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   534
				MarkTileDirtyByTile(tile);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   535
			}
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   536
			break;
2243
9a319ce6bd58 (svn r2763) Small cleanup and improve a few comments
tron
parents: 2238
diff changeset
   537
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3271
diff changeset
   538
		case TROPICZONE_RAINFOREST: {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   539
			static const SoundFx forest_sounds[] = {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   540
				SND_42_LOON_BIRD,
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   541
				SND_43_LION,
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   542
				SND_44_MONKEYS,
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   543
				SND_48_DISTANT_BIRD
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   544
			};
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   545
			uint32 r = Random();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
8463
3920ac0ab803 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 8450
diff changeset
   547
			if (Chance16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   548
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
		}
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3271
diff changeset
   550
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3271
diff changeset
   551
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   555
static void TileLoopTreesAlps(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
{
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6574
diff changeset
   557
	int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
4157
0c3210247472 (svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents: 3977
diff changeset
   559
	if (k < 0) {
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   560
		if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) return;
8206
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   561
		SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
	} else {
4157
0c3210247472 (svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents: 3977
diff changeset
   563
		uint density = min((uint)k / TILE_HEIGHT, 3);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   564
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   565
		if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT ||
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   566
				GetTreeDensity(tile) != density) {
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   567
			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, density);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   568
		} else {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   569
			if (GetTreeDensity(tile) == 3) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   570
				uint32 r = Random();
8463
3920ac0ab803 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 8450
diff changeset
   571
				if (Chance16I(1, 200, r)) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   572
					SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   573
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   581
static void TileLoop_Trees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
{
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   583
	switch (_opt.landscape) {
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   584
		case LT_TROPIC: TileLoopTreesDesert(tile); break;
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   585
		case LT_ARCTIC: TileLoopTreesAlps(tile);   break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
	TileLoopClearHelper(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
8206
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   590
	uint treeCounter = GetTreeCounter(tile);
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   591
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   592
	/* Handle growth of grass at every 8th processings, like it's done for grass */
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   593
	if ((treeCounter & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) {
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   594
		uint density = GetTreeDensity(tile);
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   595
		if (density < 3) {
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   596
			SetTreeGroundDensity(tile, TREE_GROUND_GRASS, density + 1);
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   597
			MarkTileDirtyByTile(tile);
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   598
		}
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   599
	}
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   600
	if (GetTreeCounter(tile) < 15) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   601
		AddTreeCounter(tile, 1);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   602
		return;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   603
	}
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   604
	SetTreeCounter(tile, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   605
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   606
	switch (GetTreeGrowth(tile)) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   607
		case 3: /* regular sized tree */
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   608
			if (_opt.landscape == LT_TROPIC &&
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   609
					GetTreeType(tile) != TREE_CACTUS &&
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3271
diff changeset
   610
					GetTropicZone(tile) == TROPICZONE_DESERT) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   611
				AddTreeGrowth(tile, 1);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   612
			} else {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   613
				switch (GB(Random(), 0, 3)) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   614
					case 0: /* start destructing */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   615
						AddTreeGrowth(tile, 1);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   616
						break;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   617
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   618
					case 1: /* add a tree */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   619
						if (GetTreeCount(tile) < 3) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   620
							AddTreeCount(tile, 1);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   621
							SetTreeGrowth(tile, 0);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   622
							break;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   623
						}
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   624
						/* FALL THROUGH */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   626
					case 2: { /* add a neighbouring tree */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   627
						TreeType treetype = GetTreeType(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
7813
49fbe41f8a04 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 7446
diff changeset
   629
						tile += TileOffsByDir((Direction)(Random() & 7));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
   631
						if (!IsTileType(tile, MP_CLEAR) || IsBridgeAbove(tile)) return;
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   632
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   633
						switch (GetClearGround(tile)) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   634
							case CLEAR_GRASS:
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   635
								if (GetClearDensity(tile) != 3) return;
8206
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   636
								MakeTree(tile, treetype, 0, 0, TREE_GROUND_GRASS, 3);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   637
								break;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   638
8206
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   639
							case CLEAR_ROUGH: MakeTree(tile, treetype, 0, 0, TREE_GROUND_ROUGH, 3); break;
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   640
							case CLEAR_DESERT: return; // Cacti don't spread
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   641
							case CLEAR_SNOW: MakeTree(tile, treetype, 0, 0, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break;
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   642
							default: return;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   643
						}
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   644
						break;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   645
					}
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   646
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   647
					default:
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   648
						return;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   649
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
			}
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   651
			break;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   652
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   653
		case 6: /* final stage of tree destruction */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   654
			if (GetTreeCount(tile) > 0) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   655
				/* more than one tree, delete it */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   656
				AddTreeCount(tile, -1);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   657
				SetTreeGrowth(tile, 3);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   658
			} else {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   659
				/* just one tree, change type into MP_CLEAR */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   660
				switch (GetTreeGround(tile)) {
8206
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   661
					case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, GetTreeDensity(tile)); break;
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   662
					case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break;
8206
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   663
					default: // snow or desert
8208
ee19a137b686 (svn r11246) -Codechange: beautify some conditions from "if else" into trinary operator
belugas
parents: 8206
diff changeset
   664
						MakeClear(tile, _opt.landscape == LT_TROPIC ? CLEAR_DESERT : CLEAR_SNOW, GetTreeDensity(tile));
8206
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   665
						break;
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   666
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
			}
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   668
			break;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   669
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   670
		default:
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   671
			AddTreeGrowth(tile, 1);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   672
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6459
diff changeset
   678
void OnTick_Trees()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	uint32 r;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   681
	TileIndex tile;
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   682
	ClearGround ct;
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 3003
diff changeset
   683
	TreeType tree;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
	/* place a tree at a random rainforest spot */
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   686
	if (_opt.landscape == LT_TROPIC &&
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3271
diff changeset
   687
			(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1005
diff changeset
   688
			IsTileType(tile, MP_CLEAR) &&
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
   689
			!IsBridgeAbove(tile) &&
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   690
			(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH) &&
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   691
			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
8208
ee19a137b686 (svn r11246) -Codechange: beautify some conditions from "if else" into trinary operator
belugas
parents: 8206
diff changeset
   692
		MakeTree(tile, tree, 0, 0, ct == CLEAR_ROUGH ? TREE_GROUND_ROUGH : TREE_GROUND_GRASS, GetClearDensity(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6683
diff changeset
   695
	/* byte underflow */
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   696
	if (--_trees_tick_ctr != 0) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   697
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	/* place a tree at a random spot */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
	r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
	tile = TILE_MASK(r);
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1005
diff changeset
   701
	if (IsTileType(tile, MP_CLEAR) &&
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4850
diff changeset
   702
			!IsBridgeAbove(tile) &&
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   703
			(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH || ct == CLEAR_SNOW) &&
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   704
			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   705
		switch (ct) {
8206
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   706
			case CLEAR_GRASS: MakeTree(tile, tree, 0, 0, TREE_GROUND_GRASS, GetClearDensity(tile)); break;
573a2d359695 (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 8097
diff changeset
   707
			case CLEAR_ROUGH: MakeTree(tile, tree, 0, 0, TREE_GROUND_ROUGH, 3); break;
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   708
			default: MakeTree(tile, tree, 0, 0, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   713
static void ClickTile_Trees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
7179
3e123c2b7c93 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6987
diff changeset
   718
static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode, uint sub_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2243
diff changeset
   723
static void ChangeTileOwner_Trees(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6459
diff changeset
   728
void InitializeTrees()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
	_trees_tick_ctr = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7831
diff changeset
   733
static CommandCost TerraformTile_Trees(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7831
diff changeset
   734
{
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7831
diff changeset
   735
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7831
diff changeset
   736
}
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7831
diff changeset
   737
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   739
extern const TileTypeProcs _tile_type_trees_procs = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   740
	DrawTile_Trees,           /* draw_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   741
	GetSlopeZ_Trees,          /* get_slope_z_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   742
	ClearTile_Trees,          /* clear_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   743
	GetAcceptedCargo_Trees,   /* get_accepted_cargo_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   744
	GetTileDesc_Trees,        /* get_tile_desc_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   745
	GetTileTrackStatus_Trees, /* get_tile_track_status_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   746
	ClickTile_Trees,          /* click_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   747
	AnimateTile_Trees,        /* animate_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   748
	TileLoop_Trees,           /* tile_loop_clear */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   749
	ChangeTileOwner_Trees,    /* change_tile_owner_clear */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   750
	NULL,                     /* get_produced_cargo_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   751
	NULL,                     /* vehicle_enter_tile_proc */
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   752
	GetFoundation_Trees,      /* get_foundation_proc */
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7831
diff changeset
   753
	TerraformTile_Trees,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
};