tree_cmd.c
author glx
Mon, 24 Sep 2007 03:08:47 +0000
branch0.5
changeset 5545 f42dc59a45f5
parent 5541 08e4afe5e927
permissions -rw-r--r--
(svn r11153) [0.5] -Fix [FS#1251]: incorrect usage of {G} tag in slovak translation
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
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1784
diff changeset
     4
#include "openttd.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3079
diff changeset
     5
#include "clear_map.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     6
#include "table/strings.h"
2148
47ba4a1b1c3b (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2118
diff changeset
     7
#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
     8
#include "table/tree_land.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2153
diff changeset
     9
#include "functions.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 541
diff changeset
    10
#include "map.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1202
diff changeset
    11
#include "tile.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3079
diff changeset
    12
#include "tree_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "town.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 193
diff changeset
    16
#include "sound.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
    17
#include "variables.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    18
#include "genworld.h"
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    19
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    20
enum TreePlacer {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    21
	TP_NONE,
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    22
	TP_ORIGINAL,
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    23
	TP_IMPROVED,
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    24
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
    26
static TreeType GetRandomTreeType(TileIndex tile, uint seed)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
{
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    28
	switch (_opt.landscape) {
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    29
		case LT_NORMAL:
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    30
			return seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    32
		case LT_HILLY:
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    33
			return 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
    34
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    35
		case LT_DESERT:
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
    36
			switch (GetTropicZone(tile)) {
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    37
				case TROPICZONE_INVALID: return seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL;
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    38
				case TROPICZONE_DESERT:  return (seed > 12) ? TREE_INVALID : TREE_CACTUS;
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    39
				default:                 return 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
    40
			}
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    41
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    42
		default:
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    43
			return seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2957
diff changeset
    47
static void PlaceTree(TileIndex tile, uint32 r)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
{
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
    49
	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
    50
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    51
	if (tree != TREE_INVALID) {
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    52
		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
    53
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
		// above snowline?
1370
5818d387fa69 (svn r1874) Fix bug introduced in r1839 which placed snow covered trees below the snow line ([1121680])
tron
parents: 1286
diff changeset
    55
		if (_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) {
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
    56
			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
    57
			SetTreeCounter(tile, 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
    58
		} else {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
    59
			SetTreeGroundDensity(tile, GB(r, 28, 1), 0);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
    60
			SetTreeCounter(tile, GB(r, 24, 4));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
    65
static void DoPlaceMoreTrees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
{
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    67
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    69
	for (i = 0; i < 1000; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
		uint32 r = Random();
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    71
		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
    72
		int y = GB(r, 8, 5) - 16;
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    73
		uint dist = myabs(x) + myabs(y);
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    74
		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
    75
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
    76
		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
    77
				IsTileType(cur_tile, MP_CLEAR) &&
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
    78
				!IsClearGround(cur_tile, CLEAR_FIELDS) &&
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
    79
				!IsClearGround(cur_tile, CLEAR_ROCKS)) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2957
diff changeset
    80
			PlaceTree(cur_tile, r);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
		}
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    82
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
    85
static void PlaceMoreTrees(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
{
2243
9a319ce6bd58 (svn r2763) Small cleanup and improve a few comments
tron
parents: 2238
diff changeset
    87
	uint i = ScaleByMapSize(GB(Random(), 0, 5) + 25);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
	do {
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
    89
		DoPlaceMoreTrees(RandomTile());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    93
/**
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    94
 * Place a tree at the same height as an existing tree.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    95
 *  This gives cool effects to the map.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    96
 */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    97
void PlaceTreeAtSameHeight(TileIndex tile, uint height)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    98
{
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    99
	uint i;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   100
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   101
	for (i = 0; i < 1000; i++) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   102
		uint32 r = Random();
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   103
		int x = GB(r, 0, 5) - 16;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   104
		int y = GB(r, 8, 5) - 16;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   105
		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
   106
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   107
		/* Keep in range of the existing tree */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   108
		if (myabs(x) + myabs(y) > 16) continue;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   109
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   110
		/* Clear tile, no farm-tiles or rocks */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   111
		if (!IsTileType(cur_tile, MP_CLEAR) ||
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   112
				IsClearGround(cur_tile, CLEAR_FIELDS) ||
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   113
				IsClearGround(cur_tile, CLEAR_ROCKS))
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   114
			continue;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   115
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   116
		/* Not too much height difference */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   117
		if (myabs(GetTileZ(cur_tile) - height) > 2) continue;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   118
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   119
		/* Place one tree and quit */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   120
		PlaceTree(cur_tile, r);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   121
		break;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   122
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   123
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   124
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   125
void PlaceTreesRandomly(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
{
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   127
	uint i, j, ht;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
1202
7d8b86bd8ba2 (svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents: 1093
diff changeset
   129
	i = ScaleByMapSize(1000);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	do {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   131
		uint32 r = Random();
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   132
		TileIndex tile = RandomTileSeed(r);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   133
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   134
		IncreaseGeneratingWorldProgress(GWP_TREE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   135
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
   136
		if (IsTileType(tile, MP_CLEAR) &&
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   137
				!IsClearGround(tile, CLEAR_FIELDS) &&
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   138
				!IsClearGround(tile, CLEAR_ROCKS)) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2957
diff changeset
   139
			PlaceTree(tile, r);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   140
			if (_patches.tree_placer != TP_IMPROVED) continue;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   141
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   142
			/* 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
   143
			 *  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
   144
			 *  It is almost real life ;) */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   145
			ht = GetTileZ(tile);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   146
			/* 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
   147
			j = GetTileZ(tile) / TILE_HEIGHT * 2;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   148
			while (j--) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   149
				/* Above snowline more trees! */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   150
				if (_opt.landscape == LT_HILLY && ht > _opt.snow_line) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   151
					PlaceTreeAtSameHeight(tile, ht);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   152
					PlaceTreeAtSameHeight(tile, ht);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   153
				};
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   154
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   155
				PlaceTreeAtSameHeight(tile, ht);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   156
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	/* place extra trees at rainforest area */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	if (_opt.landscape == LT_DESERT) {
1202
7d8b86bd8ba2 (svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents: 1093
diff changeset
   162
		i = ScaleByMapSize(15000);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
		do {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   165
			uint32 r = Random();
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   166
			TileIndex tile = RandomTileSeed(r);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   167
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   168
			IncreaseGeneratingWorldProgress(GWP_TREE);
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
			if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_FIELDS) && GetTropicZone(tile) == TROPICZONE_RAINFOREST) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2957
diff changeset
   171
				PlaceTree(tile, r);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
		} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   177
void GenerateTrees(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
{
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   179
	uint i, total;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   180
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   181
	if (_patches.tree_placer == TP_NONE) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   183
	if (_opt.landscape != LT_CANDY) PlaceMoreTrees();
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   184
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   185
	switch (_patches.tree_placer) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   186
		case TP_ORIGINAL: i = _opt.landscape == LT_HILLY ? 15 : 6; break;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   187
		case TP_IMPROVED: i = _opt.landscape == LT_HILLY ?  4 : 2; break;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   188
		default: NOT_REACHED(); return;
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
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   191
	total = ScaleByMapSize(1000);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   192
	if (_opt.landscape == LT_DESERT) total += ScaleByMapSize(15000);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   193
	total *= i;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   194
	SetGeneratingWorldProgress(GWP_TREE, total);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   195
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   196
	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
   197
		PlaceTreesRandomly();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   201
/** 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
   202
 * @param tile start tile of area-drag of tree plantation
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   203
 * @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
   204
 * @param p2 end tile of area-drag
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
 */
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
   206
int32 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
   207
{
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
   208
	StringID msg = INVALID_STRING_ID;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
	int32 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
   210
	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
   211
	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
   212
	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
   213
2892
390125af7685 (svn r3446) - Fix: incorrect validating of tree-planting command which can allow a buffer-overflow (Tron)
Darkvater
parents: 2654
diff changeset
   214
	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
   215
	/* 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
   216
	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
   217
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
	// 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
   221
	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
   222
	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
   223
	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
   224
	sy = TileY(p2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	if (ex < sx) intswap(ex, sx);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	if (ey < sy) intswap(ey, sy);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   227
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	cost = 0; // total cost
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
2118
c73d32cc0b5e (svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents: 2088
diff changeset
   230
	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
   231
		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
   232
			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
   233
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   234
			if (!EnsureNoVehicle(tile)) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   236
			switch (GetTileType(tile)) {
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   237
				case MP_TREES:
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   238
					// no more space for trees?
3003
15a000f2b81d (svn r3583) Fix 2 glitches in r3556
tron
parents: 2981
diff changeset
   239
					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
   240
						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
   241
						continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   244
					if (flags & DC_EXEC) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   245
						AddTreeCount(tile, 1);
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   246
						MarkTileDirtyByTile(tile);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   247
					}
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   248
					// 2x as expensive to add more trees to an existing tile
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   249
					cost += _price.build_trees * 2;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   250
					break;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   251
5541
08e4afe5e927 (svn r11073) [0.5] -Backport from trunk (r11039, r11029, r11027, r11024, r11021, r11020, r11018):
rubidium
parents: 4850
diff changeset
   252
				case MP_WATER:
08e4afe5e927 (svn r11073) [0.5] -Backport from trunk (r11039, r11029, r11027, r11024, r11021, r11020, r11018):
rubidium
parents: 4850
diff changeset
   253
					msg = STR_3807_CAN_T_BUILD_ON_WATER;
08e4afe5e927 (svn r11073) [0.5] -Backport from trunk (r11039, r11029, r11027, r11024, r11021, r11020, r11018):
rubidium
parents: 4850
diff changeset
   254
					continue;
08e4afe5e927 (svn r11073) [0.5] -Backport from trunk (r11039, r11029, r11027, r11024, r11021, r11020, r11018):
rubidium
parents: 4850
diff changeset
   255
					break;
08e4afe5e927 (svn r11073) [0.5] -Backport from trunk (r11039, r11029, r11027, r11024, r11021, r11020, r11018):
rubidium
parents: 4850
diff changeset
   256
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   257
				case MP_CLEAR:
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   258
					if (!IsTileOwner(tile, OWNER_NONE)) {
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
   259
						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
   260
						continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
					}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   262
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
   263
					switch (GetClearGround(tile)) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   264
						case CLEAR_FIELDS: cost += _price.clear_3; break;
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   265
						case CLEAR_ROCKS:  cost += _price.clear_2; 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
   266
						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
   267
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   269
					if (flags & DC_EXEC) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   270
						TreeType treetype;
3079
d6541c027250 (svn r3668) Add a function to turn a tile into a tree tile
tron
parents: 3076
diff changeset
   271
						uint growth;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   272
4850
b4e9be22945f (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4559
diff changeset
   273
						if (_game_mode != GM_EDITOR && IsValidPlayer(_current_player)) {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   274
							Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   275
							if (t != NULL)
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   276
								ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   277
						}
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   278
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   279
						treetype = p1;
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   280
						if (treetype == TREE_INVALID) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   281
							treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   282
							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
   283
						}
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   284
3079
d6541c027250 (svn r3668) Add a function to turn a tile into a tree tile
tron
parents: 3076
diff changeset
   285
						growth = _game_mode == GM_EDITOR ? 3 : 0;
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   286
						switch (GetClearGround(tile)) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   287
							case CLEAR_ROUGH: MakeTree(tile, treetype, 0, growth, TREE_GROUND_ROUGH, 0); break;
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   288
							case CLEAR_SNOW:  MakeTree(tile, treetype, 0, growth, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break;
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   289
							default:          MakeTree(tile, treetype, 0, growth, TREE_GROUND_GRASS, 0); break;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   290
						}
3003
15a000f2b81d (svn r3583) Fix 2 glitches in r3556
tron
parents: 2981
diff changeset
   291
						MarkTileDirtyByTile(tile);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   292
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   293
						if (_game_mode == GM_EDITOR && IS_INT_INSIDE(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
   294
							SetTropicZone(tile, TROPICZONE_RAINFOREST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
					}
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   296
					cost += _price.build_trees;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   297
					break;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   298
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   299
				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
   300
					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
   301
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   305
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
   306
	if (cost == 0) {
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
   307
		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
   308
	} 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
   309
		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
   310
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
typedef struct TreeListEnt {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	byte x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
} TreeListEnt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
static void DrawTile_Trees(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
	const uint32 *s;
2654
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2644
diff changeset
   321
	const TreePos* d;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
	byte z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   324
	switch (GetTreeGround(ti->tile)) {
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   325
		case TREE_GROUND_GRASS: DrawClearLandTile(ti, 3); break;
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   326
		case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break;
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   327
		default: DrawGroundSprite(_tree_sprites_1[GetTreeDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
2220
6c186dad8188 (svn r2738) Small bit fiddling cleanup
tron
parents: 2186
diff changeset
   330
	DrawClearLandFence(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
	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
   333
	if (ti->tileh != SLOPE_FLAT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
		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
   335
		if (IsSteepSlope(ti->tileh)) z += 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
		uint16 tmp = ti->x;
959
b031d88c76f3 (svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents: 926
diff changeset
   340
		uint index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   342
		tmp = ROR(tmp, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
		tmp -= ti->y;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   344
		tmp = ROR(tmp, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
		tmp -= ti->x;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   346
		tmp = ROR(tmp, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
		tmp += ti->y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   349
		d = _tree_layout_xy[GB(tmp, 4, 2)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   351
		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
   352
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
		/* 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
   354
		if (GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT &&
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   355
				GetTreeDensity(ti->tile) >= 2 &&
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   356
				IS_INT_INSIDE(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) {
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   357
			index += 164 - (TREE_SUB_ARCTIC << 2);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   358
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   359
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   360
		assert(index < lengthof(_tree_layout_sprite));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
		s = _tree_layout_sprite[index];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
	StartSpriteCombine();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   366
	if (!(_display_opt & DO_TRANS_BUILDINGS) || !_patches.invisible_trees) {
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   367
		TreeListEnt te[4];
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   368
		uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
		/* 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
   371
		i = GetTreeCount(ti->tile) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
		do {
3271
0e796a2b7c9e (svn r3983) Use existing functions to access tree and road info
tron
parents: 3183
diff changeset
   373
			uint32 image = s[0] + (--i == 0 ? GetTreeGrowth(ti->tile) : 3);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   374
			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
			te[i].image = image;
2654
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2644
diff changeset
   376
			te[i].x = d->x;
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2644
diff changeset
   377
			te[i].y = d->y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
			s++;
2654
df351c3ddd59 (svn r3196) Use structs instead of magic offsets into arrays
tron
parents: 2644
diff changeset
   379
			d++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
		} while (i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
		/* draw them in a sorted way */
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2912
diff changeset
   383
		for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
			byte min = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
			TreeListEnt *tep = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
3271
0e796a2b7c9e (svn r3983) Use existing functions to access tree and road info
tron
parents: 3183
diff changeset
   387
			i = GetTreeCount(ti->tile) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
			do {
2644
6f699b15c531 (svn r3186) Unnecessary casts and truncation
tron
parents: 2639
diff changeset
   389
				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
   390
					min = te[i].x + te[i].y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
					tep = &te[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
			} while (i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   395
			if (tep == NULL) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
			AddSortableSpriteToDraw(tep->image, ti->x + tep->x, ti->y + tep->y, 5, 5, 0x10, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
			tep->image = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
	EndSpriteCombine();
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
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   406
static uint GetSlopeZ_Trees(TileIndex tile, uint x, uint y)
2537
d9c0df52a466 (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2436
diff changeset
   407
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   408
	uint z;
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   409
	uint tileh = GetTileSlope(tile, &z);
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   410
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   411
	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   414
static Slope GetSlopeTileh_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
   415
{
3418
a592d40a4d04 (svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents: 3379
diff changeset
   416
	return tileh;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   417
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   418
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   419
static int32 ClearTile_Trees(TileIndex tile, byte flags)
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   420
{
2243
9a319ce6bd58 (svn r2763) Small cleanup and improve a few comments
tron
parents: 2238
diff changeset
   421
	uint num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
4850
b4e9be22945f (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4559
diff changeset
   423
	if ((flags & DC_EXEC) && IsValidPlayer(_current_player)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
		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
   425
		if (t != NULL)
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 988
diff changeset
   426
			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
   427
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   429
	num = GetTreeCount(tile) + 1;
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   430
	if (IS_INT_INSIDE(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
2243
9a319ce6bd58 (svn r2763) Small cleanup and improve a few comments
tron
parents: 2238
diff changeset
   432
	if (flags & DC_EXEC) DoClearSquare(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
	return num * _price.remove_trees;
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   437
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   442
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
{
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   444
	TreeType tt = GetTreeType(tile);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   445
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   446
	if (IS_INT_INSIDE(tt, TREE_RAINFOREST, TREE_CACTUS)) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   447
		td->str = STR_280F_RAINFOREST;
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   448
	} else if (tt == TREE_CACTUS) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   449
		td->str = STR_2810_CACTUS_PLANTS;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   450
	} else {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   451
		td->str = STR_280E_TREES;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   452
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
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
   454
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   457
static void AnimateTile_Trees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
	/* not used */
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   462
static void TileLoopTreesDesert(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
{
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
   464
	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
   465
		case TROPICZONE_DESERT:
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   466
			if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) {
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   467
				SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   468
				MarkTileDirtyByTile(tile);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   469
			}
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   470
			break;
2243
9a319ce6bd58 (svn r2763) Small cleanup and improve a few comments
tron
parents: 2238
diff changeset
   471
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
   472
		case TROPICZONE_RAINFOREST: {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   473
			static const SoundFx forest_sounds[] = {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   474
				SND_42_LOON_BIRD,
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   475
				SND_43_LION,
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   476
				SND_44_MONKEYS,
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   477
				SND_48_DISTANT_BIRD
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   478
			};
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   479
			uint32 r = Random();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   481
			if (CHANCE16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   482
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
		}
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
   484
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
   485
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   489
static void TileLoopTreesAlps(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
{
4157
0c3210247472 (svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents: 3977
diff changeset
   491
	int k = GetTileZ(tile) - _opt.snow_line + TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
4157
0c3210247472 (svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents: 3977
diff changeset
   493
	if (k < 0) {
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   494
		if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) return;
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   495
		SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
	} else {
4157
0c3210247472 (svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents: 3977
diff changeset
   497
		uint density = min((uint)k / TILE_HEIGHT, 3);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   498
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   499
		if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT ||
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   500
				GetTreeDensity(tile) != density) {
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   501
			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, density);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   502
		} else {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   503
			if (GetTreeDensity(tile) == 3) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   504
				uint32 r = Random();
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   505
				if (CHANCE16I(1, 200, r)) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   506
					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
   507
				}
0
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
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   515
static void TileLoop_Trees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
{
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   517
	switch (_opt.landscape) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   518
		case LT_DESERT: TileLoopTreesDesert(tile); break;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   519
		case LT_HILLY:  TileLoopTreesAlps(tile);   break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
	}
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
	TileLoopClearHelper(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   524
	if (GetTreeCounter(tile) < 15) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   525
		AddTreeCounter(tile, 1);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   526
		return;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   527
	}
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   528
	SetTreeCounter(tile, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   529
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   530
	switch (GetTreeGrowth(tile)) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   531
		case 3: /* regular sized tree */
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
   532
			if (_opt.landscape == LT_DESERT &&
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   533
					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
   534
					GetTropicZone(tile) == TROPICZONE_DESERT) {
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   535
				AddTreeGrowth(tile, 1);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   536
			} else {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   537
				switch (GB(Random(), 0, 3)) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   538
					case 0: /* start destructing */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   539
						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
   540
						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
   541
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   542
					case 1: /* add a tree */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   543
						if (GetTreeCount(tile) < 3) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   544
							AddTreeCount(tile, 1);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   545
							SetTreeGrowth(tile, 0);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   546
							break;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   547
						}
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   548
						/* FALL THROUGH */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   550
					case 2: { /* add a neighbouring tree */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   551
						TreeType treetype = GetTreeType(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4344
diff changeset
   553
						tile += TileOffsByDir(Random() & 7);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   555
						if (!IsTileType(tile, MP_CLEAR)) return;
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   556
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   557
						switch (GetClearGround(tile)) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   558
							case CLEAR_GRASS:
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   559
								if (GetClearDensity(tile) != 3) return;
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   560
								MakeTree(tile, treetype, 0, 0, TREE_GROUND_GRASS, 0);
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   561
								break;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   562
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   563
							case CLEAR_ROUGH: MakeTree(tile, treetype, 0, 0, TREE_GROUND_ROUGH, 0); break;
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   564
							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
   565
							default: return;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   566
						}
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   567
						break;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   568
					}
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   569
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   570
					default:
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   571
						return;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   572
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
			}
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   574
			break;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   575
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   576
		case 6: /* final stage of tree destruction */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   577
			if (GetTreeCount(tile) > 0) {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   578
				/* more than one tree, delete it */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   579
				AddTreeCount(tile, -1);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   580
				SetTreeGrowth(tile, 3);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   581
			} else {
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   582
				/* just one tree, change type into MP_CLEAR */
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   583
				switch (GetTreeGround(tile)) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   584
					case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, 3); break;
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   585
					case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break;
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   586
					default: MakeClear(tile, CLEAR_SNOW, GetTreeDensity(tile)); break;
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   587
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
			}
2981
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   589
			break;
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   590
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   591
		default:
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   592
			AddTreeGrowth(tile, 1);
31760b6a88aa (svn r3556) Add accessors for handling tree tiles
tron
parents: 2968
diff changeset
   593
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   599
void OnTick_Trees(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	uint32 r;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   602
	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
   603
	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
   604
	TreeType tree;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
	/* place a tree at a random rainforest spot */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   607
	if (_opt.landscape == LT_DESERT &&
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
   608
			(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
   609
			IsTileType(tile, MP_CLEAR) &&
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   610
			(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
   611
			(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   612
		MakeTree(tile, tree, 0, 0, ct == CLEAR_ROUGH ? TREE_GROUND_ROUGH : TREE_GROUND_GRASS, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
	// byte underflow
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   616
	if (--_trees_tick_ctr != 0) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   617
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
	/* place a tree at a random spot */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
	r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	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
   621
	if (IsTileType(tile, MP_CLEAR) &&
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   622
			(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
   623
			(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
   624
		switch (ct) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   625
			case CLEAR_GRASS: MakeTree(tile, tree, 0, 0, TREE_GROUND_GRASS, 0); break;
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3441
diff changeset
   626
			case CLEAR_ROUGH: MakeTree(tile, tree, 0, 0, TREE_GROUND_ROUGH, 0); break;
3441
d1cef7047cd4 (svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents: 3422
diff changeset
   627
			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
   628
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   632
static void ClickTile_Trees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   637
static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
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
   642
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
   643
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   647
void InitializeTrees(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	_trees_tick_ctr = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
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
   654
	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
   655
	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
   656
	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
   657
	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
   658
	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
   659
	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
   660
	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
   661
	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
   662
	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
   663
	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
   664
	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
   665
	NULL,                     /* vehicle_enter_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
   666
	GetSlopeTileh_Trees,      /* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
};