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