tree_cmd.c
author tron
Sun, 17 Jul 2005 11:09:03 +0000
changeset 2088 f290b54c97cb
parent 2085 ae9e92ffe168
child 2118 c73d32cc0b5e
permissions -rw-r--r--
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1784
diff changeset
     2
#include "openttd.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     3
#include "table/strings.h"
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
     4
#include "table/tree_land.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
     5
#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
     6
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#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
    10
#include "sound.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    12
static int GetRandomTreeType(TileIndex tile, uint seed)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
{
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    14
	switch (_opt.landscape) {
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    15
		case LT_NORMAL:
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    16
			return seed * 12 >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    18
		case LT_HILLY:
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    19
			return (seed >> 5) + 12;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    20
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    21
		case LT_DESERT:
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    22
			switch (GetMapExtraBits(tile)) {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    23
				case 0:  return (seed >> 6) + 28;
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    24
				case 1:  return (seed > 12) ? -1 : 27;
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    25
				default: return (seed * 7 >> 8) + 20;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    26
			}
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    27
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    28
		default:
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
    29
			return (seed * 9 >> 8) + 32;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
    33
static void PlaceTree(TileIndex tile, uint32 r, byte m5_or)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
{
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    35
	int tree = GetRandomTreeType(tile, GB(r, 24, 8));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	byte m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	if (tree >= 0) {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    39
		SetTileType(tile, MP_TREES);
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    40
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    41
		m5 = GB(r, 16, 8);
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    42
		if (GB(m5, 0, 3) == 7) m5--; // there is no growth state 7
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
    44
		_m[tile].m5 = m5 & 0x07;	// growth state;
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
    45
		_m[tile].m5 |=  m5 & 0xC0;	// amount of trees
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
    47
		_m[tile].m3 = tree;		// set type of tree
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
    48
		_m[tile].m4 = 0;		// no hedge
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
		// 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
    51
		if (_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
    52
			_m[tile].m2 = 0xE0;	// set land type to snow
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    53
			_m[tile].m2 |= GB(r, 24, 3); // randomize counter
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    54
		} else {
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    55
			_m[tile].m2 = GB(r, 24, 5); // randomize counter and ground
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
    60
static void DoPlaceMoreTrees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
{
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    62
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    64
	for (i = 0; i < 1000; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
		uint32 r = Random();
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    66
		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
    67
		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
    68
		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
    69
		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
    70
828
bb08003e61b5 (svn r1299) -Fix: [ 1092473 ] In SE, when trees are placed randomly, they are no
truelight
parents: 817
diff changeset
    71
		/* Only on tiles within 13 squares from tile,
874
877069ec457f (svn r1355) -Fix: [1092473] random trees in scenario editor do not overwrite rocks as well
darkvater
parents: 872
diff changeset
    72
		    on clear tiles, and NOT on farm-tiles or rocks */
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
    73
		if (dist <= 13 && IsTileType(cur_tile, MP_CLEAR) &&
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
    74
			 (_m[cur_tile].m5 & 0x1F) != 0x0F && (_m[cur_tile].m5 & 0x1C) != 8) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
			PlaceTree(cur_tile, r, dist <= 6 ? 0xC0 : 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
		}
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    77
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
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
    80
static void PlaceMoreTrees(void)
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
	uint i = ScaleByMapSize((Random() & 0x1F) + 25);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
	do {
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
    84
		DoPlaceMoreTrees(RandomTile());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
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
    88
void PlaceTreesRandomly(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
{
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    90
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
1202
7d8b86bd8ba2 (svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents: 1093
diff changeset
    92
	i = ScaleByMapSize(1000);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	do {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    94
		uint32 r = Random();
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
    95
		TileIndex tile = RandomTileSeed(r);
874
877069ec457f (svn r1355) -Fix: [1092473] random trees in scenario editor do not overwrite rocks as well
darkvater
parents: 872
diff changeset
    96
		/* Only on clear tiles, and NOT on farm-tiles or rocks */
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
    97
		if (IsTileType(tile, MP_CLEAR) && (_m[tile].m5 & 0x1F) != 0x0F && (_m[tile].m5 & 0x1C) != 8) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
			PlaceTree(tile, r, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	/* place extra trees at rainforest area */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
	if (_opt.landscape == LT_DESERT) {
1202
7d8b86bd8ba2 (svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents: 1093
diff changeset
   104
		i = ScaleByMapSize(15000);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
		do {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   107
			uint32 r = Random();
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   108
			TileIndex tile = RandomTileSeed(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
   109
			if (IsTileType(tile, MP_CLEAR) && GetMapExtraBits(tile) == 2) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
				PlaceTree(tile, r, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
		} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
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
   116
void GenerateTrees(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
{
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   118
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   120
	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
   121
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   122
	for (i = _opt.landscape == LT_HILLY ? 15 : 6; i != 0; i--) {
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   123
		PlaceTreesRandomly();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   127
/** Plant a tree.
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   128
 * @param x,y start tile of area-drag of tree plantation
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   129
 * @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
   130
 * @param p2 end tile of area-drag
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
	int32 cost;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   135
	int sx;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   136
	int sy;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   137
	int x;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   138
	int y;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   139
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   140
	if (p2 > MapSize()) return CMD_ERROR;
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   141
	/* 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
   142
	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
   143
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
	// make sure sx,sy are smaller than ex,ey
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 915
diff changeset
   147
	sx = TileX(p2) * 16;
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 915
diff changeset
   148
	sy = TileY(p2) * 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	if (ex < sx) intswap(ex, sx);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	if (ey < sy) intswap(ey, sy);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   151
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	cost = 0; // total cost
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   154
	for (x = sx; x <= ex; x += 16) {
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   155
		for (y = sy; y <= ey; y += 16) {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   156
			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
   157
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   158
			if (!EnsureNoVehicle(tile)) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   160
			switch (GetTileType(tile)) {
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   161
				case MP_TREES:
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   162
					// no more space for trees?
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   163
					if (_game_mode != GM_EDITOR && (_m[tile].m5 & 0xC0) == 0xC0) {
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   164
						_error_message = STR_2803_TREE_ALREADY_HERE;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   165
						continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   168
					if (flags & DC_EXEC) {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   169
						_m[tile].m5 += 0x40;
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   170
						MarkTileDirtyByTile(tile);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   171
					}
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   172
					// 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
   173
					cost += _price.build_trees * 2;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   174
					break;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   175
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   176
				case MP_CLEAR:
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   177
					if (!IsTileOwner(tile, OWNER_NONE)) {
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   178
						_error_message = STR_2804_SITE_UNSUITABLE;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   179
						continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
					}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   181
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   182
					// it's expensive to clear farmland
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   183
					if ((_m[tile].m5 & 0x1F) == 0xF)
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   184
						cost += _price.clear_3;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   185
					else if ((_m[tile].m5 & 0x1C) == 8)
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   186
						cost += _price.clear_2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   188
					if (flags & DC_EXEC) {
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   189
						int treetype;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   190
						int m2;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   191
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   192
						if (_game_mode != GM_EDITOR && _current_player < MAX_PLAYERS) {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   193
							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
   194
							if (t != NULL)
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   195
								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
   196
						}
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   197
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   198
						switch (_m[tile].m5 & 0x1C) {
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   199
							case 0x04:
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   200
								m2 = 16;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   201
								break;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   202
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   203
							case 0x10:
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   204
								m2 = ((_m[tile].m5 & 3) << 6) | 0x20;
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   205
								break;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   206
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   207
							default:
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   208
								m2 = 0;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   209
								break;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   210
						}
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   211
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   212
						treetype = p1;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   213
						if (treetype == -1) {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   214
							treetype = GetRandomTreeType(tile, Random() >> 24);
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   215
							if (treetype == -1) treetype = 27;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   216
						}
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   217
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   218
						ModifyTile(tile,
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   219
							MP_SETTYPE(MP_TREES) |
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   220
							MP_MAP2 | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5,
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   221
							m2, /* map2 */
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   222
							treetype, /* map3lo */
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   223
							_game_mode == GM_EDITOR ? 3 : 0 /* map5 */
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   224
						);
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   225
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   226
						if (_game_mode == GM_EDITOR && IS_BYTE_INSIDE(treetype, 0x14, 0x1B))
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   227
							SetMapExtraBits(tile, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
					}
1286
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   229
					cost += _price.build_trees;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   230
					break;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   231
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   232
				default:
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   233
					_error_message = STR_2804_SITE_UNSUITABLE;
da05e4dc75b5 (svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents: 1209
diff changeset
   234
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   238
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1370
diff changeset
   239
	return (cost == 0) ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
typedef struct TreeListEnt {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
	byte x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
} TreeListEnt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
static void DrawTile_Trees(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
{
817
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 679
diff changeset
   249
	uint16 m2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	const uint32 *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	const byte *d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
	byte z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   254
	m2 = _m[ti->tile].m2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   256
	if ((m2 & 0x30) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
		DrawClearLandTile(ti, 3);
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   258
	} else if ((m2 & 0x30) == 0x20) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
		DrawGroundSprite(_tree_sprites_1[m2 >> 6] + _tileh_to_sprite[ti->tileh]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
		DrawHillyLandTile(ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   264
	DrawClearLandFence(ti, _m[ti->tile].m4 >> 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
	z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	if (ti->tileh != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
		z += 4;
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2051
diff changeset
   269
		if (IsSteepTileh(ti->tileh))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
			z += 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
		uint16 tmp = ti->x;
959
b031d88c76f3 (svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents: 926
diff changeset
   275
		uint index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   277
		tmp = ROR(tmp, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
		tmp -= ti->y;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   279
		tmp = ROR(tmp, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
		tmp -= ti->x;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   281
		tmp = ROR(tmp, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
		tmp += ti->y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   284
		d = _tree_layout_xy[GB(tmp, 4, 2)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   286
		index = GB(tmp, 6, 2) + (_m[ti->tile].m3 << 2);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   287
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
		/* different tree styles above one of the grounds */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
		if ((m2 & 0xB0) == 0xA0 && index >= 48 && index < 80)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
			index += 164 - 48;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   291
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   292
		assert(index < lengthof(_tree_layout_sprite));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
		s = _tree_layout_sprite[index];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	StartSpriteCombine();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   298
	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
   299
		TreeListEnt te[4];
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   300
		uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
		/* put the trees to draw in a list */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
		i = (ti->map5 >> 6) + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
		do {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   305
			uint32 image = s[0] + (--i == 0 ? (ti->map5 & 7) : 3);
497
2d6d31173813 (svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents: 473
diff changeset
   306
			if (_display_opt & DO_TRANS_BUILDINGS)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
				image = (image & 0x3FFF) | 0x3224000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
			te[i].image = image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
			te[i].x = d[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
			te[i].y = d[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
			s++;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   312
			d += 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
		} while (i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
		/* draw them in a sorted way */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
		for(;;) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
			byte min = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
			TreeListEnt *tep = NULL;
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
			i = (ti->map5 >> 6) + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
			do {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   322
				if (te[--i].image != 0 && (byte)(te[i].x + te[i].y) < min) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
					min = te[i].x + te[i].y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
					tep = &te[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
			} while (i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   328
			if (tep == NULL) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
			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
   331
			tep->image = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
	EndSpriteCombine();
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
static uint GetSlopeZ_Trees(TileInfo *ti) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   343
static uint GetSlopeTileh_Trees(TileInfo *ti) {
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   344
	return ti->tileh;
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   345
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   346
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   347
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
   348
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	int num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	if (flags & DC_EXEC && _current_player < MAX_PLAYERS) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
		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
   353
		if (t != NULL)
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 988
diff changeset
   354
			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
   355
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   357
	num = (_m[tile].m5 >> 6) + 1;
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   358
	if ( (byte)(_m[tile].m3-0x14) <= (0x1A-0x14))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
		num <<= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
	if (flags & DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
		DoClearSquare(tile);
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
	return num * _price.remove_trees;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   367
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   372
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
	byte b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
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
   377
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   379
	b = _m[tile].m3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
	(str=STR_2810_CACTUS_PLANTS, b==0x1B) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	(str=STR_280F_RAINFOREST, IS_BYTE_INSIDE(b, 0x14, 0x1A+1)) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
	(str=STR_280E_TREES, true);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   383
	td->str = str;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   386
static void AnimateTile_Trees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 507
diff changeset
   391
static SoundFx _desert_sounds[] = {
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 507
diff changeset
   392
	SND_42_LOON_BIRD,
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 507
diff changeset
   393
	SND_43_LION,
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 507
diff changeset
   394
	SND_44_MONKEYS,
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 507
diff changeset
   395
	SND_48_DISTANT_BIRD
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   398
static void TileLoopTreesDesert(TileIndex tile)
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
	byte b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   402
	b = GetMapExtraBits(tile);
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   403
	if (b == 2) {
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   404
		uint32 r = Random();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   406
		if (CHANCE16I(1,200, r)) SndPlayTileFx(_desert_sounds[GB(r, 16, 2)], tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
	} else if (b == 1) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   408
		if ((_m[tile].m2 & 0x30) != 0x20) {
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   409
			_m[tile].m2 &= 0xF;
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   410
			_m[tile].m2 |= 0xE0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
			MarkTileDirtyByTile(tile);
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   416
static void TileLoopTreesAlps(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
	byte tmp, m2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	int k;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
	/* distance from snow line, in steps of 8 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
	k = GetTileZ(tile) - _opt.snow_line;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   424
	tmp = _m[tile].m5 & 0xF0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
	if (k < -8) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
		/* snow_m2_down */
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   428
		if ((tmp & 0x30) != 0x20) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
		m2 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
	} else if (k == -8) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
		/* snow_m1 */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   432
		m2 = 0x20;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   433
		if (tmp == m2) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
	} else if (k < 8) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
		/* snow_0 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
		m2 = 0x60;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   437
		if (tmp == m2) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
	} else if (k == 8) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
		/* snow_p1 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
		m2 = 0xA0;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   441
		if (tmp == m2) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
		/* snow_p2_up */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
		if (tmp == 0xC0) {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   445
			uint32 r = Random();
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   446
			if (CHANCE16I(1,200,r)) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 507
diff changeset
   447
				SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
			m2 = 0xE0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   455
	_m[tile].m2 &= 0xF;
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   456
	_m[tile].m2 |= m2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
	MarkTileDirtyByTile(tile);
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   460
static void TileLoop_Trees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
{
817
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 679
diff changeset
   462
	byte m5;
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 679
diff changeset
   463
	uint16 m2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 881
diff changeset
   465
	static const TileIndexDiffC _tileloop_trees_dir[] = {
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 881
diff changeset
   466
		{-1, -1},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 881
diff changeset
   467
		{ 0, -1},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 881
diff changeset
   468
		{ 1, -1},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 881
diff changeset
   469
		{-1,  0},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 881
diff changeset
   470
		{ 1,  0},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 881
diff changeset
   471
		{-1,  1},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 881
diff changeset
   472
		{ 0,  1},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 881
diff changeset
   473
		{ 1,  1}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
	if (_opt.landscape == LT_DESERT) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
		TileLoopTreesDesert(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
	} else if (_opt.landscape == LT_HILLY) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
		TileLoopTreesAlps(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
	TileLoopClearHelper(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
	/* increase counter */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
	{
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   486
		uint16 m2 = _m[tile].m2;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   487
		_m[tile].m2 = m2 = (m2 & 0xF0) | ((m2 + 1) & 0xF);
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   488
		if ((m2 & 0xF) != 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   491
	m5 = _m[tile].m5;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   492
	if (GB(m5, 0, 3) == 3) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
		/* regular sized tree */
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   494
		if (_opt.landscape == LT_DESERT && _m[tile].m3 != 0x1B && GetMapExtraBits(tile) == 1) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
			m5++; /* start destructing */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
			switch(Random() & 0x7) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
			case 0: /* start destructing */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
				m5++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
				break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   501
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
			case 1: /* add a tree */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
				if (m5 < 0xC0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
					m5 = (m5 + 0x40) & ~7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
				/* fall through */
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
			case 2: { /* add a neighbouring tree */
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   510
				byte m3 = _m[tile].m3;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   511
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 881
diff changeset
   512
				tile += ToTileIndexDiff(_tileloop_trees_dir[Random() & 7]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   514
				if (!IsTileType(tile, MP_CLEAR)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   516
				if ( (_m[tile].m5 & 0x1C) == 4) {
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   517
					_m[tile].m2 = 0x10;
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   518
				} else if ((_m[tile].m5 & 0x1C) == 16) {
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   519
					_m[tile].m2 = ((_m[tile].m5 & 3) << 6) | 0x20;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
				} else {
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   521
					if ((_m[tile].m5 & 0x1F) != 3) return;
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   522
					_m[tile].m2 = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   525
				_m[tile].m3 = m3;
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   526
				_m[tile].m4 = 0;
1059
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1035
diff changeset
   527
				SetTileType(tile, MP_TREES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
				m5 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
				break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   531
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
			default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
		}
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   537
	} else if (GB(m5, 0, 3) == 6) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
		/* final stage of tree destruction */
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   539
		if (GB(m5, 6, 2) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
			/* more than one tree, delete it? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
			m5 = ((m5 - 6) - 0x40) + 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
			/* just one tree, change type into MP_CLEAR */
1059
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1035
diff changeset
   544
			SetTileType(tile, MP_CLEAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
			m5 = 3;
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   547
			m2 = _m[tile].m2;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   548
			if ((m2 & 0x30) != 0) { // on snow/desert or rough land
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
				m5 = (m2 >> 6) | 0x10;
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   550
				if ((m2 & 0x30) != 0x20) // if not on snow/desert, then on rough land
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
					m5 = 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
			}
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
   553
			SetTileOwner(tile, OWNER_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
		/* in the middle of a transition, change to next */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
		m5++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   560
	_m[tile].m5 = m5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
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
   564
void OnTick_Trees(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
	uint32 r;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   567
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
	byte m;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
	int tree;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
	/* 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
   572
	if (_opt.landscape == LT_DESERT &&
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   573
			(r = Random(), tile = RandomTileSeed(r), GetMapExtraBits(tile) == 2) &&
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
   574
			IsTileType(tile, MP_CLEAR) &&
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   575
			(m = _m[tile].m5 & 0x1C, m <= 4) &&
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   576
			(tree = GetRandomTreeType(tile, r >> 24)) >= 0) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   577
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
		ModifyTile(tile,
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   579
			MP_SETTYPE(MP_TREES) |
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
			MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
			(m == 4 ? 0x10 : 0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
			tree,
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   583
			_m[tile].m4 & ~3,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
			0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
	// byte underflow
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   589
	if (--_trees_tick_ctr != 0) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   590
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
	/* place a tree at a random spot */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
	r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
	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
   594
	if (IsTileType(tile, MP_CLEAR) &&
2088
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   595
			(m = _m[tile].m5 & 0x1C, m == 0 || m == 4 || m == 0x10) &&
f290b54c97cb (svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents: 2085
diff changeset
   596
			(tree = GetRandomTreeType(tile, r >> 24)) >= 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
		int m2;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   598
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
		if (m == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
			m2 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
		} else if (m == 4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
			m2 = 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
		} else {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   604
			m2 = ((_m[tile].m5 & 3) << 6) | 0x20;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
		ModifyTile(tile,
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 160
diff changeset
   608
			MP_SETTYPE(MP_TREES) |
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
			MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
			m2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
			tree,
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   612
			_m[tile].m4 & ~3,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
			0
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   618
static void ClickTile_Trees(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   623
static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1902
diff changeset
   628
static void ChangeTileOwner_Trees(TileIndex tile, byte old_player, byte new_player)
0
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
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
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
   633
void InitializeTrees(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
	_trees_tick_ctr = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
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
const TileTypeProcs _tile_type_trees_procs = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
	DrawTile_Trees,						/* draw_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
	GetSlopeZ_Trees,					/* get_slope_z_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
	ClearTile_Trees,					/* clear_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
	GetAcceptedCargo_Trees,		/* get_accepted_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
	GetTileDesc_Trees,				/* get_tile_desc_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
	GetTileTrackStatus_Trees,	/* get_tile_track_status_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
	ClickTile_Trees,					/* click_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
	AnimateTile_Trees,				/* animate_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
	TileLoop_Trees,						/* tile_loop_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	ChangeTileOwner_Trees,		/* change_tile_owner_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	NULL,											/* get_produced_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
	NULL,											/* vehicle_enter_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
	NULL,											/* vehicle_leave_tile_proc */
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   653
	GetSlopeTileh_Trees,			/* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
};