author | peter1138 |
Sat, 03 Jun 2006 19:23:14 +0000 | |
changeset 3943 | d3d5f7b3d3d0 |
parent 3933 | 231ae3c419f4 |
child 3977 | 513433ebd092 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1784
diff
changeset
|
4 |
#include "openttd.h" |
3933 | 5 |
#include "bridge_map.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3079
diff
changeset
|
6 |
#include "clear_map.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
7 |
#include "table/strings.h" |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2118
diff
changeset
|
8 |
#include "table/sprites.h" |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
9 |
#include "table/tree_land.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2153
diff
changeset
|
10 |
#include "functions.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
541
diff
changeset
|
11 |
#include "map.h" |
1209
2e00193652b2
(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
|
12 |
#include "tile.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3079
diff
changeset
|
13 |
#include "tree_map.h" |
0 | 14 |
#include "viewport.h" |
15 |
#include "command.h" |
|
16 |
#include "town.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
17 |
#include "sound.h" |
2153
ecfc674410b4
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
18 |
#include "variables.h" |
0 | 19 |
|
2981 | 20 |
static TreeType GetRandomTreeType(TileIndex tile, uint seed) |
0 | 21 |
{ |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
22 |
switch (_opt.landscape) { |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
23 |
case LT_NORMAL: |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
24 |
return seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE; |
0 | 25 |
|
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
26 |
case LT_HILLY: |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
27 |
return seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC; |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
28 |
|
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
29 |
case LT_DESERT: |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
30 |
switch (GetTropicZone(tile)) { |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
31 |
case TROPICZONE_INVALID: return seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL; |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
32 |
case TROPICZONE_DESERT: return (seed > 12) ? TREE_INVALID : TREE_CACTUS; |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
33 |
default: return seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST; |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
34 |
} |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
35 |
|
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
36 |
default: |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
37 |
return seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND; |
0 | 38 |
} |
39 |
} |
|
40 |
||
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
41 |
static void PlaceTree(TileIndex tile, uint32 r) |
0 | 42 |
{ |
2981 | 43 |
TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8)); |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
44 |
|
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
45 |
if (tree != TREE_INVALID) { |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
46 |
MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0); |
0 | 47 |
|
48 |
// above snowline? |
|
1370
c86b2c30fd01
(svn r1874) Fix bug introduced in r1839 which placed snow covered trees below the snow line ([1121680])
tron
parents:
1286
diff
changeset
|
49 |
if (_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) { |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
50 |
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3); |
2981 | 51 |
SetTreeCounter(tile, GB(r, 24, 3)); |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
52 |
} else { |
2981 | 53 |
SetTreeGroundDensity(tile, GB(r, 28, 1), 0); |
54 |
SetTreeCounter(tile, GB(r, 24, 4)); |
|
0 | 55 |
} |
56 |
} |
|
57 |
} |
|
58 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
59 |
static void DoPlaceMoreTrees(TileIndex tile) |
0 | 60 |
{ |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
61 |
uint i; |
0 | 62 |
|
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
63 |
for (i = 0; i < 1000; i++) { |
0 | 64 |
uint32 r = Random(); |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
65 |
int x = GB(r, 0, 5) - 16; |
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
66 |
int y = GB(r, 8, 5) - 16; |
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
67 |
uint dist = myabs(x) + myabs(y); |
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
68 |
TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y)); |
0 | 69 |
|
2955
24de69e236d2
(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 |
if (dist <= 13 && |
24de69e236d2
(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 |
IsTileType(cur_tile, MP_CLEAR) && |
3933 | 72 |
!IsBridgeAbove(cur_tile) && |
3447 | 73 |
!IsClearGround(cur_tile, CLEAR_FIELDS) && |
74 |
!IsClearGround(cur_tile, CLEAR_ROCKS)) { |
|
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
75 |
PlaceTree(cur_tile, r); |
0 | 76 |
} |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
77 |
} |
0 | 78 |
} |
79 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
80 |
static void PlaceMoreTrees(void) |
0 | 81 |
{ |
2243 | 82 |
uint i = ScaleByMapSize(GB(Random(), 0, 5) + 25); |
0 | 83 |
do { |
2051 | 84 |
DoPlaceMoreTrees(RandomTile()); |
0 | 85 |
} while (--i); |
86 |
} |
|
87 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
88 |
void PlaceTreesRandomly(void) |
0 | 89 |
{ |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
90 |
uint i; |
0 | 91 |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
92 |
i = ScaleByMapSize(1000); |
0 | 93 |
do { |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
94 |
uint32 r = Random(); |
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
95 |
TileIndex tile = RandomTileSeed(r); |
2955
24de69e236d2
(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 |
if (IsTileType(tile, MP_CLEAR) && |
3933 | 97 |
!IsBridgeAbove(tile) && |
3447 | 98 |
!IsClearGround(tile, CLEAR_FIELDS) && |
99 |
!IsClearGround(tile, CLEAR_ROCKS)) { |
|
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
100 |
PlaceTree(tile, r); |
0 | 101 |
} |
102 |
} while (--i); |
|
103 |
||
104 |
/* place extra trees at rainforest area */ |
|
105 |
if (_opt.landscape == LT_DESERT) { |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
106 |
i = ScaleByMapSize(15000); |
0 | 107 |
|
108 |
do { |
|
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
109 |
uint32 r = Random(); |
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
110 |
TileIndex tile = RandomTileSeed(r); |
3933 | 111 |
if (IsTileType(tile, MP_CLEAR) && |
112 |
!IsBridgeAbove(tile) && |
|
113 |
GetTropicZone(tile) == TROPICZONE_RAINFOREST) { |
|
2958
ac0a9673b522
(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
4fdc46eaf423
(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
d7a97ef74701
(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
d7a97ef74701
(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(); |
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
125 |
|
d7a97ef74701
(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--) { |
d7a97ef74701
(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
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
131 |
/** Plant a tree. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
132 |
* @param tile start tile of area-drag of tree plantation |
1784
d0698aac0c2e
(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. |
d0698aac0c2e
(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 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
136 |
int32 CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 137 |
{ |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
138 |
StringID msg = INVALID_STRING_ID; |
0 | 139 |
int32 cost; |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
140 |
int ex; |
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
141 |
int ey; |
2118
aec8042f000b
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
142 |
int sx, sy, x, y; |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
143 |
|
2892
db216dc91941
(svn r3446) - Fix: incorrect validating of tree-planting command which can allow a buffer-overflow (Tron)
Darkvater
parents:
2654
diff
changeset
|
144 |
if (p2 >= MapSize()) return CMD_ERROR; |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
145 |
/* Check the tree type. It can be random or some valid value within the current climate */ |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
146 |
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
|
147 |
|
0 | 148 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
149 |
||
150 |
// make sure sx,sy are smaller than ex,ey |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
151 |
ex = TileX(tile); |
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
152 |
ey = TileY(tile); |
2118
aec8042f000b
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
153 |
sx = TileX(p2); |
aec8042f000b
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
154 |
sy = TileY(p2); |
0 | 155 |
if (ex < sx) intswap(ex, sx); |
156 |
if (ey < sy) intswap(ey, sy); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
157 |
|
0 | 158 |
cost = 0; // total cost |
159 |
||
2118
aec8042f000b
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
160 |
for (x = sx; x <= ex; x++) { |
aec8042f000b
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
161 |
for (y = sy; y <= ey; y++) { |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
162 |
TileIndex tile = TileXY(x, y); |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
163 |
|
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
164 |
if (!EnsureNoVehicle(tile)) continue; |
0 | 165 |
|
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
166 |
switch (GetTileType(tile)) { |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
167 |
case MP_TREES: |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
168 |
// no more space for trees? |
3003 | 169 |
if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 3) { |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
170 |
msg = STR_2803_TREE_ALREADY_HERE; |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
171 |
continue; |
0 | 172 |
} |
173 |
||
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
174 |
if (flags & DC_EXEC) { |
2981 | 175 |
AddTreeCount(tile, 1); |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
176 |
MarkTileDirtyByTile(tile); |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
177 |
} |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
178 |
// 2x as expensive to add more trees to an existing tile |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
179 |
cost += _price.build_trees * 2; |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
180 |
break; |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
181 |
|
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
182 |
case MP_CLEAR: |
3933 | 183 |
if (!IsTileOwner(tile, OWNER_NONE) || |
184 |
IsBridgeAbove(tile)) { |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
185 |
msg = STR_2804_SITE_UNSUITABLE; |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
186 |
continue; |
0 | 187 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
188 |
|
2955
24de69e236d2
(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
|
189 |
switch (GetClearGround(tile)) { |
3447 | 190 |
case CLEAR_FIELDS: cost += _price.clear_3; break; |
191 |
case CLEAR_ROCKS: cost += _price.clear_2; break; |
|
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
192 |
default: break; |
24de69e236d2
(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
|
193 |
} |
0 | 194 |
|
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
195 |
if (flags & DC_EXEC) { |
2981 | 196 |
TreeType treetype; |
3079
a26f87fba4c1
(svn r3668) Add a function to turn a tile into a tree tile
tron
parents:
3076
diff
changeset
|
197 |
uint growth; |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
198 |
|
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
199 |
if (_game_mode != GM_EDITOR && _current_player < MAX_PLAYERS) { |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
200 |
Town *t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
201 |
if (t != NULL) |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
202 |
ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM); |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
203 |
} |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
204 |
|
2981 | 205 |
treetype = p1; |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
206 |
if (treetype == TREE_INVALID) { |
2981 | 207 |
treetype = GetRandomTreeType(tile, GB(Random(), 24, 8)); |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
208 |
if (treetype == TREE_INVALID) treetype = TREE_CACTUS; |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
209 |
} |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
210 |
|
3079
a26f87fba4c1
(svn r3668) Add a function to turn a tile into a tree tile
tron
parents:
3076
diff
changeset
|
211 |
growth = _game_mode == GM_EDITOR ? 3 : 0; |
2981 | 212 |
switch (GetClearGround(tile)) { |
3447 | 213 |
case CLEAR_ROUGH: MakeTree(tile, treetype, 0, growth, TREE_GROUND_ROUGH, 0); break; |
214 |
case CLEAR_SNOW: MakeTree(tile, treetype, 0, growth, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break; |
|
215 |
default: MakeTree(tile, treetype, 0, growth, TREE_GROUND_GRASS, 0); break; |
|
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
216 |
} |
3003 | 217 |
MarkTileDirtyByTile(tile); |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
218 |
|
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
219 |
if (_game_mode == GM_EDITOR && IS_INT_INSIDE(treetype, TREE_RAINFOREST, TREE_CACTUS)) |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
220 |
SetTropicZone(tile, TROPICZONE_RAINFOREST); |
0 | 221 |
} |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
222 |
cost += _price.build_trees; |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
223 |
break; |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
224 |
|
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
225 |
default: |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
226 |
msg = STR_2804_SITE_UNSUITABLE; |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
227 |
break; |
0 | 228 |
} |
229 |
} |
|
230 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
231 |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
232 |
if (cost == 0) { |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
233 |
return_cmd_error(msg); |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
234 |
} else { |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
235 |
return cost; |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
236 |
} |
0 | 237 |
} |
238 |
||
239 |
typedef struct TreeListEnt { |
|
240 |
uint32 image; |
|
241 |
byte x,y; |
|
242 |
} TreeListEnt; |
|
243 |
||
244 |
static void DrawTile_Trees(TileInfo *ti) |
|
245 |
{ |
|
246 |
const uint32 *s; |
|
2654
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
247 |
const TreePos* d; |
0 | 248 |
byte z; |
249 |
||
2981 | 250 |
switch (GetTreeGround(ti->tile)) { |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
251 |
case TREE_GROUND_GRASS: DrawClearLandTile(ti, 3); break; |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
252 |
case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break; |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
253 |
default: DrawGroundSprite(_tree_sprites_1[GetTreeDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); break; |
0 | 254 |
} |
255 |
||
2220 | 256 |
DrawClearLandFence(ti); |
0 | 257 |
|
258 |
z = ti->z; |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
259 |
if (ti->tileh != SLOPE_FLAT) { |
0 | 260 |
z += 4; |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
261 |
if (IsSteepSlope(ti->tileh)) z += 4; |
0 | 262 |
} |
263 |
||
264 |
{ |
|
265 |
uint16 tmp = ti->x; |
|
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
266 |
uint index; |
0 | 267 |
|
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
268 |
tmp = ROR(tmp, 2); |
0 | 269 |
tmp -= ti->y; |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
270 |
tmp = ROR(tmp, 3); |
0 | 271 |
tmp -= ti->x; |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
272 |
tmp = ROR(tmp, 1); |
0 | 273 |
tmp += ti->y; |
274 |
||
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
275 |
d = _tree_layout_xy[GB(tmp, 4, 2)]; |
0 | 276 |
|
2981 | 277 |
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
|
278 |
|
0 | 279 |
/* different tree styles above one of the grounds */ |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
280 |
if (GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT && |
2981 | 281 |
GetTreeDensity(ti->tile) >= 2 && |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
282 |
IS_INT_INSIDE(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) { |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
283 |
index += 164 - (TREE_SUB_ARCTIC << 2); |
2981 | 284 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
285 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
286 |
assert(index < lengthof(_tree_layout_sprite)); |
0 | 287 |
s = _tree_layout_sprite[index]; |
288 |
} |
|
289 |
||
290 |
StartSpriteCombine(); |
|
291 |
||
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
292 |
if (!(_display_opt & DO_TRANS_BUILDINGS) || !_patches.invisible_trees) { |
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
293 |
TreeListEnt te[4]; |
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
294 |
uint i; |
0 | 295 |
|
296 |
/* put the trees to draw in a list */ |
|
3271
114243e3465f
(svn r3983) Use existing functions to access tree and road info
tron
parents:
3183
diff
changeset
|
297 |
i = GetTreeCount(ti->tile) + 1; |
0 | 298 |
do { |
3271
114243e3465f
(svn r3983) Use existing functions to access tree and road info
tron
parents:
3183
diff
changeset
|
299 |
uint32 image = s[0] + (--i == 0 ? GetTreeGrowth(ti->tile) : 3); |
2639 | 300 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 301 |
te[i].image = image; |
2654
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
302 |
te[i].x = d->x; |
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
303 |
te[i].y = d->y; |
0 | 304 |
s++; |
2654
1370de8783d3
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
305 |
d++; |
0 | 306 |
} while (i); |
307 |
||
308 |
/* draw them in a sorted way */ |
|
2952 | 309 |
for (;;) { |
0 | 310 |
byte min = 0xFF; |
311 |
TreeListEnt *tep = NULL; |
|
312 |
||
3271
114243e3465f
(svn r3983) Use existing functions to access tree and road info
tron
parents:
3183
diff
changeset
|
313 |
i = GetTreeCount(ti->tile) + 1; |
0 | 314 |
do { |
2644 | 315 |
if (te[--i].image != 0 && te[i].x + te[i].y < min) { |
0 | 316 |
min = te[i].x + te[i].y; |
317 |
tep = &te[i]; |
|
318 |
} |
|
319 |
} while (i); |
|
320 |
||
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
321 |
if (tep == NULL) break; |
0 | 322 |
|
323 |
AddSortableSpriteToDraw(tep->image, ti->x + tep->x, ti->y + tep->y, 5, 5, 0x10, z); |
|
324 |
tep->image = 0; |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
EndSpriteCombine(); |
|
329 |
} |
|
330 |
||
331 |
||
2537 | 332 |
static uint GetSlopeZ_Trees(const TileInfo* ti) |
333 |
{ |
|
2243 | 334 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
0 | 335 |
} |
336 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3491
diff
changeset
|
337 |
static Slope GetSlopeTileh_Trees(TileIndex tile, Slope tileh) |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2537
diff
changeset
|
338 |
{ |
3418
ec9003ebf933
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3379
diff
changeset
|
339 |
return tileh; |
39 | 340 |
} |
341 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
342 |
static int32 ClearTile_Trees(TileIndex tile, byte flags) |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
343 |
{ |
2243 | 344 |
uint num; |
0 | 345 |
|
346 |
if (flags & DC_EXEC && _current_player < MAX_PLAYERS) { |
|
347 |
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
|
348 |
if (t != NULL) |
1005 | 349 |
ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM); |
0 | 350 |
} |
351 |
||
2981 | 352 |
num = GetTreeCount(tile) + 1; |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
353 |
if (IS_INT_INSIDE(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4; |
0 | 354 |
|
2243 | 355 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 356 |
|
357 |
return num * _price.remove_trees; |
|
358 |
} |
|
359 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
360 |
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac) |
0 | 361 |
{ |
362 |
/* not used */ |
|
363 |
} |
|
364 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
365 |
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td) |
0 | 366 |
{ |
2981 | 367 |
TreeType tt = GetTreeType(tile); |
368 |
||
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
369 |
if (IS_INT_INSIDE(tt, TREE_RAINFOREST, TREE_CACTUS)) { |
2981 | 370 |
td->str = STR_280F_RAINFOREST; |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
371 |
} else if (tt == TREE_CACTUS) { |
2981 | 372 |
td->str = STR_2810_CACTUS_PLANTS; |
373 |
} else { |
|
374 |
td->str = STR_280E_TREES; |
|
375 |
} |
|
0 | 376 |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
377 |
td->owner = GetTileOwner(tile); |
0 | 378 |
} |
379 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
380 |
static void AnimateTile_Trees(TileIndex tile) |
0 | 381 |
{ |
382 |
/* not used */ |
|
383 |
} |
|
384 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
385 |
static void TileLoopTreesDesert(TileIndex tile) |
0 | 386 |
{ |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
387 |
switch (GetTropicZone(tile)) { |
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
388 |
case TROPICZONE_DESERT: |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
389 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) { |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
390 |
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3); |
2981 | 391 |
MarkTileDirtyByTile(tile); |
392 |
} |
|
393 |
break; |
|
2243 | 394 |
|
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
395 |
case TROPICZONE_RAINFOREST: { |
2981 | 396 |
static const SoundFx forest_sounds[] = { |
397 |
SND_42_LOON_BIRD, |
|
398 |
SND_43_LION, |
|
399 |
SND_44_MONKEYS, |
|
400 |
SND_48_DISTANT_BIRD |
|
401 |
}; |
|
402 |
uint32 r = Random(); |
|
0 | 403 |
|
2981 | 404 |
if (CHANCE16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile); |
405 |
break; |
|
0 | 406 |
} |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
407 |
|
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
408 |
default: break; |
0 | 409 |
} |
410 |
} |
|
411 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
412 |
static void TileLoopTreesAlps(TileIndex tile) |
0 | 413 |
{ |
2981 | 414 |
int k = GetTileZ(tile) - _opt.snow_line; |
0 | 415 |
|
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
416 |
if (k < -TILE_HEIGHT) { |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
417 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) return; |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
418 |
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 0); |
0 | 419 |
} else { |
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
420 |
uint density = min((uint)(k + TILE_HEIGHT) / TILE_HEIGHT, 3); |
2981 | 421 |
|
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
422 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT || |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
423 |
GetTreeDensity(tile) != density) { |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
424 |
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, density); |
2981 | 425 |
} else { |
426 |
if (GetTreeDensity(tile) == 3) { |
|
427 |
uint32 r = Random(); |
|
428 |
if (CHANCE16I(1, 200, r)) { |
|
429 |
SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile); |
|
430 |
} |
|
0 | 431 |
} |
432 |
return; |
|
433 |
} |
|
434 |
} |
|
435 |
MarkTileDirtyByTile(tile); |
|
436 |
} |
|
437 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
438 |
static void TileLoop_Trees(TileIndex tile) |
0 | 439 |
{ |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
440 |
static const TileIndexDiffC _tileloop_trees_dir[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
441 |
{-1, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
442 |
{ 0, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
443 |
{ 1, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
444 |
{-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
445 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
446 |
{-1, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
447 |
{ 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
448 |
{ 1, 1} |
0 | 449 |
}; |
450 |
||
2981 | 451 |
switch (_opt.landscape) { |
452 |
case LT_DESERT: TileLoopTreesDesert(tile); break; |
|
453 |
case LT_HILLY: TileLoopTreesAlps(tile); break; |
|
0 | 454 |
} |
455 |
||
456 |
TileLoopClearHelper(tile); |
|
457 |
||
2981 | 458 |
if (GetTreeCounter(tile) < 15) { |
459 |
AddTreeCounter(tile, 1); |
|
460 |
return; |
|
461 |
} |
|
462 |
SetTreeCounter(tile, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
463 |
|
2981 | 464 |
switch (GetTreeGrowth(tile)) { |
465 |
case 3: /* regular sized tree */ |
|
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
466 |
if (_opt.landscape == LT_DESERT && |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
467 |
GetTreeType(tile) != TREE_CACTUS && |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
468 |
GetTropicZone(tile) == TROPICZONE_DESERT) { |
2981 | 469 |
AddTreeGrowth(tile, 1); |
470 |
} else { |
|
471 |
switch (GB(Random(), 0, 3)) { |
|
472 |
case 0: /* start destructing */ |
|
473 |
AddTreeGrowth(tile, 1); |
|
2955
24de69e236d2
(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
|
474 |
break; |
24de69e236d2
(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
|
475 |
|
2981 | 476 |
case 1: /* add a tree */ |
477 |
if (GetTreeCount(tile) < 3) { |
|
478 |
AddTreeCount(tile, 1); |
|
479 |
SetTreeGrowth(tile, 0); |
|
480 |
break; |
|
481 |
} |
|
482 |
/* FALL THROUGH */ |
|
0 | 483 |
|
2981 | 484 |
case 2: { /* add a neighbouring tree */ |
485 |
TreeType treetype = GetTreeType(tile); |
|
0 | 486 |
|
2981 | 487 |
tile += ToTileIndexDiff(_tileloop_trees_dir[Random() & 7]); |
0 | 488 |
|
3933 | 489 |
if (!IsTileType(tile, MP_CLEAR) || IsBridgeAbove(tile)) return; |
2981 | 490 |
|
491 |
switch (GetClearGround(tile)) { |
|
3447 | 492 |
case CLEAR_GRASS: |
2981 | 493 |
if (GetClearDensity(tile) != 3) return; |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
494 |
MakeTree(tile, treetype, 0, 0, TREE_GROUND_GRASS, 0); |
2981 | 495 |
break; |
496 |
||
3447 | 497 |
case CLEAR_ROUGH: MakeTree(tile, treetype, 0, 0, TREE_GROUND_ROUGH, 0); break; |
498 |
case CLEAR_SNOW: MakeTree(tile, treetype, 0, 0, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break; |
|
2981 | 499 |
default: return; |
500 |
} |
|
501 |
break; |
|
502 |
} |
|
503 |
||
504 |
default: |
|
505 |
return; |
|
506 |
} |
|
0 | 507 |
} |
2981 | 508 |
break; |
509 |
||
510 |
case 6: /* final stage of tree destruction */ |
|
511 |
if (GetTreeCount(tile) > 0) { |
|
512 |
/* more than one tree, delete it */ |
|
513 |
AddTreeCount(tile, -1); |
|
514 |
SetTreeGrowth(tile, 3); |
|
515 |
} else { |
|
516 |
/* just one tree, change type into MP_CLEAR */ |
|
517 |
switch (GetTreeGround(tile)) { |
|
3447 | 518 |
case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, 3); break; |
519 |
case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break; |
|
520 |
default: MakeClear(tile, CLEAR_SNOW, GetTreeDensity(tile)); break; |
|
2981 | 521 |
} |
3933 | 522 |
ClearBridgeMiddle(tile); |
0 | 523 |
} |
2981 | 524 |
break; |
525 |
||
526 |
default: |
|
527 |
AddTreeGrowth(tile, 1); |
|
528 |
break; |
|
0 | 529 |
} |
530 |
||
531 |
MarkTileDirtyByTile(tile); |
|
532 |
} |
|
533 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
534 |
void OnTick_Trees(void) |
0 | 535 |
{ |
536 |
uint32 r; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
537 |
TileIndex tile; |
2955
24de69e236d2
(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 |
ClearGround ct; |
3017
a75caf4efa2d
(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
|
539 |
TreeType tree; |
0 | 540 |
|
541 |
/* 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
|
542 |
if (_opt.landscape == LT_DESERT && |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
543 |
(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) && |
1035
812f837ee03f
(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
|
544 |
IsTileType(tile, MP_CLEAR) && |
3933 | 545 |
!IsBridgeAbove(tile) && |
3447 | 546 |
(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH) && |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
547 |
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) { |
3447 | 548 |
MakeTree(tile, tree, 0, 0, ct == CLEAR_ROUGH ? TREE_GROUND_ROUGH : TREE_GROUND_GRASS, 0); |
0 | 549 |
} |
550 |
||
551 |
// byte underflow |
|
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
552 |
if (--_trees_tick_ctr != 0) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
553 |
|
0 | 554 |
/* place a tree at a random spot */ |
555 |
r = Random(); |
|
556 |
tile = TILE_MASK(r); |
|
1035
812f837ee03f
(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
|
557 |
if (IsTileType(tile, MP_CLEAR) && |
3933 | 558 |
!IsBridgeAbove(tile) && |
3447 | 559 |
(ct = GetClearGround(tile), ct == CLEAR_GRASS || ct == CLEAR_ROUGH || ct == CLEAR_SNOW) && |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
560 |
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) { |
2955
24de69e236d2
(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
|
561 |
switch (ct) { |
3447 | 562 |
case CLEAR_GRASS: MakeTree(tile, tree, 0, 0, TREE_GROUND_GRASS, 0); break; |
563 |
case CLEAR_ROUGH: MakeTree(tile, tree, 0, 0, TREE_GROUND_ROUGH, 0); break; |
|
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
564 |
default: MakeTree(tile, tree, 0, 0, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break; |
0 | 565 |
} |
566 |
} |
|
567 |
} |
|
568 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
569 |
static void ClickTile_Trees(TileIndex tile) |
0 | 570 |
{ |
571 |
/* not used */ |
|
572 |
} |
|
573 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
574 |
static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode) |
0 | 575 |
{ |
576 |
return 0; |
|
577 |
} |
|
578 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2243
diff
changeset
|
579 |
static void ChangeTileOwner_Trees(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 580 |
{ |
581 |
/* not used */ |
|
582 |
} |
|
583 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
584 |
void InitializeTrees(void) |
0 | 585 |
{ |
586 |
_trees_tick_ctr = 0; |
|
587 |
} |
|
588 |
||
589 |
||
590 |
const TileTypeProcs _tile_type_trees_procs = { |
|
591 |
DrawTile_Trees, /* draw_tile_proc */ |
|
592 |
GetSlopeZ_Trees, /* get_slope_z_proc */ |
|
593 |
ClearTile_Trees, /* clear_tile_proc */ |
|
594 |
GetAcceptedCargo_Trees, /* get_accepted_cargo_proc */ |
|
595 |
GetTileDesc_Trees, /* get_tile_desc_proc */ |
|
596 |
GetTileTrackStatus_Trees, /* get_tile_track_status_proc */ |
|
597 |
ClickTile_Trees, /* click_tile_proc */ |
|
598 |
AnimateTile_Trees, /* animate_tile_proc */ |
|
599 |
TileLoop_Trees, /* tile_loop_clear */ |
|
600 |
ChangeTileOwner_Trees, /* change_tile_owner_clear */ |
|
601 |
NULL, /* get_produced_cargo_proc */ |
|
602 |
NULL, /* vehicle_enter_tile_proc */ |
|
39 | 603 |
GetSlopeTileh_Trees, /* get_slope_tileh_proc */ |
0 | 604 |
}; |