author | tron |
Mon, 13 Feb 2006 21:15:00 +0000 | |
changeset 3017 | 915fae59d5e0 |
parent 3003 | 15a000f2b81d |
child 3076 | 9584f34a83dc |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1784
diff
changeset
|
4 |
#include "openttd.h" |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
5 |
#include "clear.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
6 |
#include "table/strings.h" |
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2118
diff
changeset
|
7 |
#include "table/sprites.h" |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
8 |
#include "table/tree_land.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2153
diff
changeset
|
9 |
#include "functions.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
541
diff
changeset
|
10 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1202
diff
changeset
|
11 |
#include "tile.h" |
2981 | 12 |
#include "tree.h" |
0 | 13 |
#include "viewport.h" |
14 |
#include "command.h" |
|
15 |
#include "town.h" |
|
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
16 |
#include "sound.h" |
2153
91e89aa8c299
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
17 |
#include "variables.h" |
0 | 18 |
|
2981 | 19 |
static TreeType GetRandomTreeType(TileIndex tile, uint seed) |
0 | 20 |
{ |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
21 |
switch (_opt.landscape) { |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
22 |
case LT_NORMAL: |
2981 | 23 |
return seed * TR_COUNT_TEMPERATE / 256 + TR_TEMPERATE; |
0 | 24 |
|
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
25 |
case LT_HILLY: |
2981 | 26 |
return seed * TR_COUNT_SUB_ARCTIC / 256 + TR_SUB_ARCTIC; |
1286
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 |
case LT_DESERT: |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
29 |
switch (GetMapExtraBits(tile)) { |
2981 | 30 |
case 0: return seed * TR_COUNT_SUB_TROPICAL / 256 + TR_SUB_TROPICAL; |
31 |
case 1: return (seed > 12) ? TR_INVALID : TR_CACTUS; |
|
32 |
default: return seed * TR_COUNT_RAINFOREST / 256 + TR_RAINFOREST; |
|
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
33 |
} |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
34 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
35 |
default: |
2981 | 36 |
return seed * TR_COUNT_TOYLAND / 256 + TR_TOYLAND; |
0 | 37 |
} |
38 |
} |
|
39 |
||
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
40 |
static void PlaceTree(TileIndex tile, uint32 r) |
0 | 41 |
{ |
2981 | 42 |
TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8)); |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
43 |
|
2981 | 44 |
if (tree != TR_INVALID) { |
45 |
SetTileType(tile, MP_TREES); |
|
46 |
SetTreeType(tile, tree); |
|
47 |
SetFenceSE(tile, 0); |
|
48 |
SetFenceSW(tile, 0); |
|
49 |
SetTreeCount(tile, GB(r, 22, 2)); |
|
50 |
SetTreeGrowth(tile, min(GB(r, 16, 3), 6)); |
|
0 | 51 |
|
52 |
// 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
|
53 |
if (_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) { |
2981 | 54 |
SetTreeGroundDensity(tile, TR_SNOW_DESERT, 3); |
55 |
SetTreeCounter(tile, GB(r, 24, 3)); |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
56 |
} else { |
2981 | 57 |
SetTreeGroundDensity(tile, GB(r, 28, 1), 0); |
58 |
SetTreeCounter(tile, GB(r, 24, 4)); |
|
0 | 59 |
} |
60 |
} |
|
61 |
} |
|
62 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
63 |
static void DoPlaceMoreTrees(TileIndex tile) |
0 | 64 |
{ |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
65 |
uint i; |
0 | 66 |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
67 |
for (i = 0; i < 1000; i++) { |
0 | 68 |
uint32 r = Random(); |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y)); |
0 | 73 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
74 |
if (dist <= 13 && |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
75 |
IsTileType(cur_tile, MP_CLEAR) && |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
76 |
!IsClearGround(cur_tile, CL_FIELDS) && |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
77 |
!IsClearGround(cur_tile, CL_ROCKS)) { |
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
78 |
PlaceTree(cur_tile, r); |
0 | 79 |
} |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
80 |
} |
0 | 81 |
} |
82 |
||
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
|
83 |
static void PlaceMoreTrees(void) |
0 | 84 |
{ |
2243 | 85 |
uint i = ScaleByMapSize(GB(Random(), 0, 5) + 25); |
0 | 86 |
do { |
2051 | 87 |
DoPlaceMoreTrees(RandomTile()); |
0 | 88 |
} while (--i); |
89 |
} |
|
90 |
||
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
|
91 |
void PlaceTreesRandomly(void) |
0 | 92 |
{ |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
93 |
uint i; |
0 | 94 |
|
1202
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
95 |
i = ScaleByMapSize(1000); |
0 | 96 |
do { |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
97 |
uint32 r = Random(); |
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
98 |
TileIndex tile = RandomTileSeed(r); |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
99 |
if (IsTileType(tile, MP_CLEAR) && |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
100 |
!IsClearGround(tile, CL_FIELDS) && |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
101 |
!IsClearGround(tile, CL_ROCKS)) { |
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
102 |
PlaceTree(tile, r); |
0 | 103 |
} |
104 |
} while (--i); |
|
105 |
||
106 |
/* place extra trees at rainforest area */ |
|
107 |
if (_opt.landscape == LT_DESERT) { |
|
1202
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
108 |
i = ScaleByMapSize(15000); |
0 | 109 |
|
110 |
do { |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
111 |
uint32 r = Random(); |
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
112 |
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
|
113 |
if (IsTileType(tile, MP_CLEAR) && GetMapExtraBits(tile) == 2) { |
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
114 |
PlaceTree(tile, r); |
0 | 115 |
} |
116 |
} while (--i); |
|
117 |
} |
|
118 |
} |
|
119 |
||
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
|
120 |
void GenerateTrees(void) |
0 | 121 |
{ |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
122 |
uint i; |
0 | 123 |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
124 |
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
|
125 |
|
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
126 |
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
|
127 |
PlaceTreesRandomly(); |
0 | 128 |
} |
129 |
} |
|
130 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
131 |
/** Plant a tree. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
132 |
* @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
|
133 |
* @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
|
134 |
* @param p2 end tile of area-drag |
0 | 135 |
*/ |
136 |
int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2) |
|
137 |
{ |
|
138 |
int32 cost; |
|
2118
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
139 |
int sx, sy, x, y; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
140 |
|
2892
390125af7685
(svn r3446) - Fix: incorrect validating of tree-planting command which can allow a buffer-overflow (Tron)
Darkvater
parents:
2654
diff
changeset
|
141 |
if (p2 >= MapSize()) return CMD_ERROR; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
142 |
/* 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
|
143 |
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
|
144 |
|
0 | 145 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
146 |
||
147 |
// make sure sx,sy are smaller than ex,ey |
|
2118
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
148 |
sx = TileX(p2); |
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
149 |
sy = TileY(p2); |
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
150 |
ex /= 16; ey /= 16; |
0 | 151 |
if (ex < sx) intswap(ex, sx); |
152 |
if (ey < sy) intswap(ey, sy); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
153 |
|
0 | 154 |
cost = 0; // total cost |
155 |
||
2118
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
156 |
for (x = sx; x <= ex; x++) { |
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
157 |
for (y = sy; y <= ey; y++) { |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
158 |
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
|
159 |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
160 |
if (!EnsureNoVehicle(tile)) continue; |
0 | 161 |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
162 |
switch (GetTileType(tile)) { |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
163 |
case MP_TREES: |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
164 |
// no more space for trees? |
3003 | 165 |
if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 3) { |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
166 |
_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
|
167 |
continue; |
0 | 168 |
} |
169 |
||
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
170 |
if (flags & DC_EXEC) { |
2981 | 171 |
AddTreeCount(tile, 1); |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
172 |
MarkTileDirtyByTile(tile); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
173 |
} |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
174 |
// 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
|
175 |
cost += _price.build_trees * 2; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
176 |
break; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
177 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
178 |
case MP_CLEAR: |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
179 |
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
|
180 |
_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
|
181 |
continue; |
0 | 182 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
183 |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
184 |
switch (GetClearGround(tile)) { |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
185 |
case CL_FIELDS: cost += _price.clear_3; break; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
186 |
case CL_ROCKS: cost += _price.clear_2; break; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
187 |
default: break; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
188 |
} |
0 | 189 |
|
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
190 |
if (flags & DC_EXEC) { |
2981 | 191 |
TreeType treetype; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
192 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
193 |
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
|
194 |
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
|
195 |
if (t != NULL) |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
196 |
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
|
197 |
} |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
198 |
|
2981 | 199 |
treetype = p1; |
200 |
if (treetype == TR_INVALID) { |
|
201 |
treetype = GetRandomTreeType(tile, GB(Random(), 24, 8)); |
|
202 |
if (treetype == TR_INVALID) treetype = TR_CACTUS; |
|
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
203 |
} |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
204 |
|
2981 | 205 |
switch (GetClearGround(tile)) { |
206 |
case CL_ROUGH: SetTreeGroundDensity(tile, TR_ROUGH, 0); break; |
|
207 |
case CL_SNOW: SetTreeGroundDensity(tile, TR_SNOW_DESERT, GetClearDensity(tile)); break; |
|
208 |
default: SetTreeGroundDensity(tile, TR_GRASS, 0); break; |
|
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
209 |
} |
2981 | 210 |
SetTreeCounter(tile, 0); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
211 |
|
2981 | 212 |
SetTileType(tile, MP_TREES); |
213 |
SetTreeType(tile, treetype); |
|
214 |
SetFenceSE(tile, 0); |
|
215 |
SetFenceSW(tile, 0); |
|
216 |
SetTreeCount(tile, 0); |
|
217 |
SetTreeGrowth(tile, _game_mode == GM_EDITOR ? 3 : 0); |
|
3003 | 218 |
MarkTileDirtyByTile(tile); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
219 |
|
2981 | 220 |
if (_game_mode == GM_EDITOR && IS_INT_INSIDE(treetype, TR_RAINFOREST, TR_CACTUS)) |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
221 |
SetMapExtraBits(tile, 2); |
0 | 222 |
} |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
223 |
cost += _price.build_trees; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
224 |
break; |
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 |
default: |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
227 |
_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
|
228 |
break; |
0 | 229 |
} |
230 |
} |
|
231 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
232 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
233 |
return (cost == 0) ? CMD_ERROR : cost; |
0 | 234 |
} |
235 |
||
236 |
typedef struct TreeListEnt { |
|
237 |
uint32 image; |
|
238 |
byte x,y; |
|
239 |
} TreeListEnt; |
|
240 |
||
241 |
static void DrawTile_Trees(TileInfo *ti) |
|
242 |
{ |
|
243 |
const uint32 *s; |
|
2654
df351c3ddd59
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
244 |
const TreePos* d; |
0 | 245 |
byte z; |
246 |
||
2981 | 247 |
switch (GetTreeGround(ti->tile)) { |
248 |
case TR_GRASS: DrawClearLandTile(ti, 3); break; |
|
249 |
case TR_ROUGH: DrawHillyLandTile(ti); break; |
|
250 |
default: DrawGroundSprite(_tree_sprites_1[GetTreeDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); break; |
|
0 | 251 |
} |
252 |
||
2220 | 253 |
DrawClearLandFence(ti); |
0 | 254 |
|
255 |
z = ti->z; |
|
256 |
if (ti->tileh != 0) { |
|
257 |
z += 4; |
|
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2051
diff
changeset
|
258 |
if (IsSteepTileh(ti->tileh)) |
0 | 259 |
z += 4; |
260 |
} |
|
261 |
||
262 |
{ |
|
263 |
uint16 tmp = ti->x; |
|
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
264 |
uint index; |
0 | 265 |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
266 |
tmp = ROR(tmp, 2); |
0 | 267 |
tmp -= ti->y; |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
268 |
tmp = ROR(tmp, 3); |
0 | 269 |
tmp -= ti->x; |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
270 |
tmp = ROR(tmp, 1); |
0 | 271 |
tmp += ti->y; |
272 |
||
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
273 |
d = _tree_layout_xy[GB(tmp, 4, 2)]; |
0 | 274 |
|
2981 | 275 |
index = GB(tmp, 6, 2) + (GetTreeType(ti->tile) << 2); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
276 |
|
0 | 277 |
/* different tree styles above one of the grounds */ |
2981 | 278 |
if (GetTreeGround(ti->tile) == TR_SNOW_DESERT && |
279 |
GetTreeDensity(ti->tile) >= 2 && |
|
280 |
IS_INT_INSIDE(index, TR_SUB_ARCTIC << 2, TR_RAINFOREST << 2)) { |
|
281 |
index += 164 - (TR_SUB_ARCTIC << 2); |
|
282 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
283 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
284 |
assert(index < lengthof(_tree_layout_sprite)); |
0 | 285 |
s = _tree_layout_sprite[index]; |
286 |
} |
|
287 |
||
288 |
StartSpriteCombine(); |
|
289 |
||
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
290 |
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
|
291 |
TreeListEnt te[4]; |
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
292 |
uint i; |
0 | 293 |
|
294 |
/* put the trees to draw in a list */ |
|
295 |
i = (ti->map5 >> 6) + 1; |
|
296 |
do { |
|
2243 | 297 |
uint32 image = s[0] + (--i == 0 ? GB(ti->map5, 0, 3) : 3); |
2639 | 298 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 299 |
te[i].image = image; |
2654
df351c3ddd59
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
300 |
te[i].x = d->x; |
df351c3ddd59
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
301 |
te[i].y = d->y; |
0 | 302 |
s++; |
2654
df351c3ddd59
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
303 |
d++; |
0 | 304 |
} while (i); |
305 |
||
306 |
/* draw them in a sorted way */ |
|
2952 | 307 |
for (;;) { |
0 | 308 |
byte min = 0xFF; |
309 |
TreeListEnt *tep = NULL; |
|
310 |
||
311 |
i = (ti->map5 >> 6) + 1; |
|
312 |
do { |
|
2644 | 313 |
if (te[--i].image != 0 && te[i].x + te[i].y < min) { |
0 | 314 |
min = te[i].x + te[i].y; |
315 |
tep = &te[i]; |
|
316 |
} |
|
317 |
} while (i); |
|
318 |
||
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
319 |
if (tep == NULL) break; |
0 | 320 |
|
321 |
AddSortableSpriteToDraw(tep->image, ti->x + tep->x, ti->y + tep->y, 5, 5, 0x10, z); |
|
322 |
tep->image = 0; |
|
323 |
} |
|
324 |
} |
|
325 |
||
326 |
EndSpriteCombine(); |
|
327 |
} |
|
328 |
||
329 |
||
2537 | 330 |
static uint GetSlopeZ_Trees(const TileInfo* ti) |
331 |
{ |
|
2243 | 332 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
0 | 333 |
} |
334 |
||
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2537
diff
changeset
|
335 |
static uint GetSlopeTileh_Trees(const TileInfo* ti) |
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2537
diff
changeset
|
336 |
{ |
39 | 337 |
return ti->tileh; |
338 |
} |
|
339 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
340 |
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
|
341 |
{ |
2243 | 342 |
uint num; |
0 | 343 |
|
344 |
if (flags & DC_EXEC && _current_player < MAX_PLAYERS) { |
|
345 |
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
|
346 |
if (t != NULL) |
1005 | 347 |
ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM); |
0 | 348 |
} |
349 |
||
2981 | 350 |
num = GetTreeCount(tile) + 1; |
351 |
if (IS_INT_INSIDE(GetTreeType(tile), TR_RAINFOREST, TR_CACTUS)) num *= 4; |
|
0 | 352 |
|
2243 | 353 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 354 |
|
355 |
return num * _price.remove_trees; |
|
356 |
} |
|
357 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
358 |
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac) |
0 | 359 |
{ |
360 |
/* not used */ |
|
361 |
} |
|
362 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
363 |
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td) |
0 | 364 |
{ |
2981 | 365 |
TreeType tt = GetTreeType(tile); |
366 |
||
367 |
if (IS_INT_INSIDE(tt, TR_RAINFOREST, TR_CACTUS)) { |
|
368 |
td->str = STR_280F_RAINFOREST; |
|
369 |
} else if (tt == TR_CACTUS) { |
|
370 |
td->str = STR_2810_CACTUS_PLANTS; |
|
371 |
} else { |
|
372 |
td->str = STR_280E_TREES; |
|
373 |
} |
|
0 | 374 |
|
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
|
375 |
td->owner = GetTileOwner(tile); |
0 | 376 |
} |
377 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
378 |
static void AnimateTile_Trees(TileIndex tile) |
0 | 379 |
{ |
380 |
/* not used */ |
|
381 |
} |
|
382 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
383 |
static void TileLoopTreesDesert(TileIndex tile) |
0 | 384 |
{ |
2981 | 385 |
switch (GetMapExtraBits(tile)) { |
386 |
case 1: |
|
387 |
if (GetTreeGround(tile) != TR_SNOW_DESERT) { |
|
388 |
SetTreeGroundDensity(tile, TR_SNOW_DESERT, 3); |
|
389 |
MarkTileDirtyByTile(tile); |
|
390 |
} |
|
391 |
break; |
|
2243 | 392 |
|
2981 | 393 |
case 2: { |
394 |
static const SoundFx forest_sounds[] = { |
|
395 |
SND_42_LOON_BIRD, |
|
396 |
SND_43_LION, |
|
397 |
SND_44_MONKEYS, |
|
398 |
SND_48_DISTANT_BIRD |
|
399 |
}; |
|
400 |
uint32 r = Random(); |
|
0 | 401 |
|
2981 | 402 |
if (CHANCE16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile); |
403 |
break; |
|
0 | 404 |
} |
405 |
} |
|
406 |
} |
|
407 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
408 |
static void TileLoopTreesAlps(TileIndex tile) |
0 | 409 |
{ |
2981 | 410 |
int k = GetTileZ(tile) - _opt.snow_line; |
0 | 411 |
|
412 |
if (k < -8) { |
|
2981 | 413 |
if (GetTreeGround(tile) != TR_SNOW_DESERT) return; |
414 |
SetTreeGroundDensity(tile, TR_GRASS, 0); |
|
0 | 415 |
} else { |
2981 | 416 |
uint density = min((uint)(k + 8) / 8, 3); |
417 |
||
418 |
if (GetTreeGround(tile) != TR_SNOW_DESERT || GetTreeDensity(tile) != density) { |
|
419 |
SetTreeGroundDensity(tile, TR_SNOW_DESERT, density); |
|
420 |
} else { |
|
421 |
if (GetTreeDensity(tile) == 3) { |
|
422 |
uint32 r = Random(); |
|
423 |
if (CHANCE16I(1, 200, r)) { |
|
424 |
SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile); |
|
425 |
} |
|
0 | 426 |
} |
427 |
return; |
|
428 |
} |
|
429 |
} |
|
430 |
MarkTileDirtyByTile(tile); |
|
431 |
} |
|
432 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
433 |
static void TileLoop_Trees(TileIndex tile) |
0 | 434 |
{ |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
435 |
static const TileIndexDiffC _tileloop_trees_dir[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
436 |
{-1, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
437 |
{ 0, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
438 |
{ 1, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
439 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
440 |
{ 1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
441 |
{-1, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
442 |
{ 0, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
443 |
{ 1, 1} |
0 | 444 |
}; |
445 |
||
2981 | 446 |
switch (_opt.landscape) { |
447 |
case LT_DESERT: TileLoopTreesDesert(tile); break; |
|
448 |
case LT_HILLY: TileLoopTreesAlps(tile); break; |
|
0 | 449 |
} |
450 |
||
451 |
TileLoopClearHelper(tile); |
|
452 |
||
2981 | 453 |
if (GetTreeCounter(tile) < 15) { |
454 |
AddTreeCounter(tile, 1); |
|
455 |
return; |
|
456 |
} |
|
457 |
SetTreeCounter(tile, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
458 |
|
2981 | 459 |
switch (GetTreeGrowth(tile)) { |
460 |
case 3: /* regular sized tree */ |
|
461 |
if (_opt.landscape == LT_DESERT && GetTreeType(tile) != TR_CACTUS && GetMapExtraBits(tile) == 1) { |
|
462 |
AddTreeGrowth(tile, 1); |
|
463 |
} else { |
|
464 |
switch (GB(Random(), 0, 3)) { |
|
465 |
case 0: /* start destructing */ |
|
466 |
AddTreeGrowth(tile, 1); |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
467 |
break; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
468 |
|
2981 | 469 |
case 1: /* add a tree */ |
470 |
if (GetTreeCount(tile) < 3) { |
|
471 |
AddTreeCount(tile, 1); |
|
472 |
SetTreeGrowth(tile, 0); |
|
473 |
break; |
|
474 |
} |
|
475 |
/* FALL THROUGH */ |
|
0 | 476 |
|
2981 | 477 |
case 2: { /* add a neighbouring tree */ |
478 |
TreeType treetype = GetTreeType(tile); |
|
0 | 479 |
|
2981 | 480 |
tile += ToTileIndexDiff(_tileloop_trees_dir[Random() & 7]); |
0 | 481 |
|
2981 | 482 |
if (!IsTileType(tile, MP_CLEAR)) return; |
483 |
||
484 |
switch (GetClearGround(tile)) { |
|
485 |
case CL_GRASS: |
|
486 |
if (GetClearDensity(tile) != 3) return; |
|
487 |
SetTreeGroundDensity(tile, TR_GRASS, 0); |
|
488 |
break; |
|
489 |
||
490 |
case CL_ROUGH: SetTreeGroundDensity(tile, TR_ROUGH, 0); break; |
|
491 |
case CL_SNOW: SetTreeGroundDensity(tile, TR_SNOW_DESERT, GetClearDensity(tile)); break; |
|
492 |
default: return; |
|
493 |
} |
|
494 |
SetTreeCounter(tile, 0); |
|
495 |
||
496 |
SetTileType(tile, MP_TREES); |
|
497 |
SetTreeType(tile, treetype); |
|
498 |
SetFenceSE(tile, 0); |
|
499 |
SetFenceSW(tile, 0); |
|
500 |
SetTreeCount(tile, 0); |
|
501 |
SetTreeGrowth(tile, 0); |
|
502 |
break; |
|
503 |
} |
|
504 |
||
505 |
default: |
|
506 |
return; |
|
507 |
} |
|
0 | 508 |
} |
2981 | 509 |
break; |
510 |
||
511 |
case 6: /* final stage of tree destruction */ |
|
512 |
if (GetTreeCount(tile) > 0) { |
|
513 |
/* more than one tree, delete it */ |
|
514 |
AddTreeCount(tile, -1); |
|
515 |
SetTreeGrowth(tile, 3); |
|
516 |
} else { |
|
517 |
/* just one tree, change type into MP_CLEAR */ |
|
518 |
SetTileType(tile, MP_CLEAR); |
|
519 |
SetTileOwner(tile, OWNER_NONE); |
|
520 |
switch (GetTreeGround(tile)) { |
|
521 |
case TR_GRASS: SetClearGroundDensity(tile, CL_GRASS, 3); break; |
|
522 |
case TR_ROUGH: SetClearGroundDensity(tile, CL_ROUGH, 3); break; |
|
523 |
default: SetClearGroundDensity(tile, CL_SNOW, GetTreeDensity(tile)); break; |
|
524 |
} |
|
0 | 525 |
} |
2981 | 526 |
break; |
527 |
||
528 |
default: |
|
529 |
AddTreeGrowth(tile, 1); |
|
530 |
break; |
|
0 | 531 |
} |
532 |
||
533 |
MarkTileDirtyByTile(tile); |
|
534 |
} |
|
535 |
||
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
|
536 |
void OnTick_Trees(void) |
0 | 537 |
{ |
538 |
uint32 r; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
539 |
TileIndex tile; |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
540 |
ClearGround ct; |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3003
diff
changeset
|
541 |
TreeType tree; |
0 | 542 |
|
543 |
/* 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
|
544 |
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
|
545 |
(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
|
546 |
IsTileType(tile, MP_CLEAR) && |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
547 |
(ct = GetClearGround(tile), ct == CL_GRASS || ct == CL_ROUGH) && |
2981 | 548 |
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TR_INVALID) { |
549 |
SetTileType(tile, MP_TREES); |
|
550 |
SetTreeGroundDensity(tile, ct == CL_ROUGH ? TR_ROUGH : TR_GRASS, 0); |
|
551 |
SetTreeCounter(tile, 0); |
|
552 |
SetTreeType(tile, tree); |
|
553 |
SetTreeCount(tile, 0); |
|
554 |
SetTreeGrowth(tile, 0); |
|
0 | 555 |
} |
556 |
||
557 |
// byte underflow |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
558 |
if (--_trees_tick_ctr != 0) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
559 |
|
0 | 560 |
/* place a tree at a random spot */ |
561 |
r = Random(); |
|
562 |
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
|
563 |
if (IsTileType(tile, MP_CLEAR) && |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
564 |
(ct = GetClearGround(tile), ct == CL_GRASS || ct == CL_ROUGH || ct == CL_SNOW) && |
2981 | 565 |
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TR_INVALID) { |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
566 |
switch (ct) { |
2981 | 567 |
case CL_GRASS: SetTreeGroundDensity(tile, TR_GRASS, 0); break; |
568 |
case CL_ROUGH: SetTreeGroundDensity(tile, TR_ROUGH, 0); break; |
|
569 |
default: SetTreeGroundDensity(tile, TR_SNOW_DESERT, GetClearDensity(tile)); break; |
|
0 | 570 |
} |
2981 | 571 |
SetTreeCounter(tile, 0); |
572 |
SetTileType(tile, MP_TREES); |
|
573 |
SetTreeType(tile, tree); |
|
574 |
SetTreeCount(tile, 0); |
|
575 |
SetTreeGrowth(tile, 0); |
|
0 | 576 |
} |
577 |
} |
|
578 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
579 |
static void ClickTile_Trees(TileIndex tile) |
0 | 580 |
{ |
581 |
/* not used */ |
|
582 |
} |
|
583 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
584 |
static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode) |
0 | 585 |
{ |
586 |
return 0; |
|
587 |
} |
|
588 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2243
diff
changeset
|
589 |
static void ChangeTileOwner_Trees(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 590 |
{ |
591 |
/* not used */ |
|
592 |
} |
|
593 |
||
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
|
594 |
void InitializeTrees(void) |
0 | 595 |
{ |
596 |
_trees_tick_ctr = 0; |
|
597 |
} |
|
598 |
||
599 |
||
600 |
const TileTypeProcs _tile_type_trees_procs = { |
|
601 |
DrawTile_Trees, /* draw_tile_proc */ |
|
602 |
GetSlopeZ_Trees, /* get_slope_z_proc */ |
|
603 |
ClearTile_Trees, /* clear_tile_proc */ |
|
604 |
GetAcceptedCargo_Trees, /* get_accepted_cargo_proc */ |
|
605 |
GetTileDesc_Trees, /* get_tile_desc_proc */ |
|
606 |
GetTileTrackStatus_Trees, /* get_tile_track_status_proc */ |
|
607 |
ClickTile_Trees, /* click_tile_proc */ |
|
608 |
AnimateTile_Trees, /* animate_tile_proc */ |
|
609 |
TileLoop_Trees, /* tile_loop_clear */ |
|
610 |
ChangeTileOwner_Trees, /* change_tile_owner_clear */ |
|
611 |
NULL, /* get_produced_cargo_proc */ |
|
612 |
NULL, /* vehicle_enter_tile_proc */ |
|
613 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 614 |
GetSlopeTileh_Trees, /* get_slope_tileh_proc */ |
0 | 615 |
}; |