author | tron |
Tue, 04 Apr 2006 06:25:05 +0000 | |
changeset 3441 | d1cef7047cd4 |
parent 3422 | 12cdb13ddb56 |
child 3447 | d136931464f7 |
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" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3079
diff
changeset
|
5 |
#include "clear_map.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
6 |
#include "table/strings.h" |
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2118
diff
changeset
|
7 |
#include "table/sprites.h" |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
8 |
#include "table/tree_land.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2153
diff
changeset
|
9 |
#include "functions.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
541
diff
changeset
|
10 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1202
diff
changeset
|
11 |
#include "tile.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3079
diff
changeset
|
12 |
#include "tree_map.h" |
0 | 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: |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
23 |
return seed * TREE_COUNT_TEMPERATE / 256 + TREE_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: |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
26 |
return seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
27 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
28 |
case LT_DESERT: |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
29 |
switch (GetTropicZone(tile)) { |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
30 |
case TROPICZONE_INVALID: return seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
31 |
case TROPICZONE_DESERT: return (seed > 12) ? TREE_INVALID : TREE_CACTUS; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
32 |
default: return seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
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: |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
36 |
return seed * TREE_COUNT_TOYLAND / 256 + TREE_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 |
|
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
44 |
if (tree != TREE_INVALID) { |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
45 |
MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_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) { |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
49 |
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3); |
2981 | 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); |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
108 |
if (IsTileType(tile, MP_CLEAR) && GetTropicZone(tile) == TROPICZONE_RAINFOREST) { |
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 |
{ |
|
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
133 |
StringID msg = INVALID_STRING_ID; |
0 | 134 |
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
|
135 |
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
|
136 |
|
2892
390125af7685
(svn r3446) - Fix: incorrect validating of tree-planting command which can allow a buffer-overflow (Tron)
Darkvater
parents:
2654
diff
changeset
|
137 |
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
|
138 |
/* 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
|
139 |
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
|
140 |
|
0 | 141 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
142 |
||
143 |
// 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
|
144 |
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
|
145 |
sy = TileY(p2); |
3422
12cdb13ddb56
(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
|
146 |
ex /= TILE_SIZE; |
12cdb13ddb56
(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
|
147 |
ey /= TILE_SIZE; |
0 | 148 |
if (ex < sx) intswap(ex, sx); |
149 |
if (ey < sy) intswap(ey, sy); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
150 |
|
0 | 151 |
cost = 0; // total cost |
152 |
||
2118
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
157 |
if (!EnsureNoVehicle(tile)) continue; |
0 | 158 |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
159 |
switch (GetTileType(tile)) { |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
160 |
case MP_TREES: |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
161 |
// no more space for trees? |
3003 | 162 |
if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 3) { |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
163 |
msg = STR_2803_TREE_ALREADY_HERE; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
164 |
continue; |
0 | 165 |
} |
166 |
||
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
167 |
if (flags & DC_EXEC) { |
2981 | 168 |
AddTreeCount(tile, 1); |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
169 |
MarkTileDirtyByTile(tile); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
170 |
} |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
171 |
// 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
|
172 |
cost += _price.build_trees * 2; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
173 |
break; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
174 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
175 |
case MP_CLEAR: |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
176 |
if (!IsTileOwner(tile, OWNER_NONE)) { |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
177 |
msg = STR_2804_SITE_UNSUITABLE; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
178 |
continue; |
0 | 179 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
180 |
|
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
} |
0 | 186 |
|
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
187 |
if (flags & DC_EXEC) { |
2981 | 188 |
TreeType treetype; |
3079
d6541c027250
(svn r3668) Add a function to turn a tile into a tree tile
tron
parents:
3076
diff
changeset
|
189 |
uint growth; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
190 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
191 |
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
|
192 |
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
|
193 |
if (t != NULL) |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
194 |
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
|
195 |
} |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
196 |
|
2981 | 197 |
treetype = p1; |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
198 |
if (treetype == TREE_INVALID) { |
2981 | 199 |
treetype = GetRandomTreeType(tile, GB(Random(), 24, 8)); |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
200 |
if (treetype == TREE_INVALID) treetype = TREE_CACTUS; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
201 |
} |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
202 |
|
3079
d6541c027250
(svn r3668) Add a function to turn a tile into a tree tile
tron
parents:
3076
diff
changeset
|
203 |
growth = _game_mode == GM_EDITOR ? 3 : 0; |
2981 | 204 |
switch (GetClearGround(tile)) { |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
205 |
case CL_ROUGH: MakeTree(tile, treetype, 0, growth, TREE_GROUND_ROUGH, 0); break; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
206 |
case CL_SNOW: MakeTree(tile, treetype, 0, growth, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
207 |
default: MakeTree(tile, treetype, 0, growth, TREE_GROUND_GRASS, 0); break; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
208 |
} |
3003 | 209 |
MarkTileDirtyByTile(tile); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
210 |
|
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
211 |
if (_game_mode == GM_EDITOR && IS_INT_INSIDE(treetype, TREE_RAINFOREST, TREE_CACTUS)) |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
212 |
SetTropicZone(tile, TROPICZONE_RAINFOREST); |
0 | 213 |
} |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
214 |
cost += _price.build_trees; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
215 |
break; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
216 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
217 |
default: |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
218 |
msg = STR_2804_SITE_UNSUITABLE; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
219 |
break; |
0 | 220 |
} |
221 |
} |
|
222 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
223 |
|
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
224 |
if (cost == 0) { |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
225 |
return_cmd_error(msg); |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
226 |
} else { |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
227 |
return cost; |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
228 |
} |
0 | 229 |
} |
230 |
||
231 |
typedef struct TreeListEnt { |
|
232 |
uint32 image; |
|
233 |
byte x,y; |
|
234 |
} TreeListEnt; |
|
235 |
||
236 |
static void DrawTile_Trees(TileInfo *ti) |
|
237 |
{ |
|
238 |
const uint32 *s; |
|
2654
df351c3ddd59
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
239 |
const TreePos* d; |
0 | 240 |
byte z; |
241 |
||
2981 | 242 |
switch (GetTreeGround(ti->tile)) { |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
243 |
case TREE_GROUND_GRASS: DrawClearLandTile(ti, 3); break; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
244 |
case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
245 |
default: DrawGroundSprite(_tree_sprites_1[GetTreeDensity(ti->tile)] + _tileh_to_sprite[ti->tileh]); break; |
0 | 246 |
} |
247 |
||
2220 | 248 |
DrawClearLandFence(ti); |
0 | 249 |
|
250 |
z = ti->z; |
|
251 |
if (ti->tileh != 0) { |
|
252 |
z += 4; |
|
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2051
diff
changeset
|
253 |
if (IsSteepTileh(ti->tileh)) |
0 | 254 |
z += 4; |
255 |
} |
|
256 |
||
257 |
{ |
|
258 |
uint16 tmp = ti->x; |
|
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
259 |
uint index; |
0 | 260 |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
261 |
tmp = ROR(tmp, 2); |
0 | 262 |
tmp -= ti->y; |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
263 |
tmp = ROR(tmp, 3); |
0 | 264 |
tmp -= ti->x; |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
265 |
tmp = ROR(tmp, 1); |
0 | 266 |
tmp += ti->y; |
267 |
||
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
268 |
d = _tree_layout_xy[GB(tmp, 4, 2)]; |
0 | 269 |
|
2981 | 270 |
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
|
271 |
|
0 | 272 |
/* different tree styles above one of the grounds */ |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
273 |
if (GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT && |
2981 | 274 |
GetTreeDensity(ti->tile) >= 2 && |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
275 |
IS_INT_INSIDE(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) { |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
276 |
index += 164 - (TREE_SUB_ARCTIC << 2); |
2981 | 277 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
278 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
279 |
assert(index < lengthof(_tree_layout_sprite)); |
0 | 280 |
s = _tree_layout_sprite[index]; |
281 |
} |
|
282 |
||
283 |
StartSpriteCombine(); |
|
284 |
||
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
285 |
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
|
286 |
TreeListEnt te[4]; |
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
287 |
uint i; |
0 | 288 |
|
289 |
/* put the trees to draw in a list */ |
|
3271
0e796a2b7c9e
(svn r3983) Use existing functions to access tree and road info
tron
parents:
3183
diff
changeset
|
290 |
i = GetTreeCount(ti->tile) + 1; |
0 | 291 |
do { |
3271
0e796a2b7c9e
(svn r3983) Use existing functions to access tree and road info
tron
parents:
3183
diff
changeset
|
292 |
uint32 image = s[0] + (--i == 0 ? GetTreeGrowth(ti->tile) : 3); |
2639 | 293 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
0 | 294 |
te[i].image = image; |
2654
df351c3ddd59
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
295 |
te[i].x = d->x; |
df351c3ddd59
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
296 |
te[i].y = d->y; |
0 | 297 |
s++; |
2654
df351c3ddd59
(svn r3196) Use structs instead of magic offsets into arrays
tron
parents:
2644
diff
changeset
|
298 |
d++; |
0 | 299 |
} while (i); |
300 |
||
301 |
/* draw them in a sorted way */ |
|
2952 | 302 |
for (;;) { |
0 | 303 |
byte min = 0xFF; |
304 |
TreeListEnt *tep = NULL; |
|
305 |
||
3271
0e796a2b7c9e
(svn r3983) Use existing functions to access tree and road info
tron
parents:
3183
diff
changeset
|
306 |
i = GetTreeCount(ti->tile) + 1; |
0 | 307 |
do { |
2644 | 308 |
if (te[--i].image != 0 && te[i].x + te[i].y < min) { |
0 | 309 |
min = te[i].x + te[i].y; |
310 |
tep = &te[i]; |
|
311 |
} |
|
312 |
} while (i); |
|
313 |
||
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
314 |
if (tep == NULL) break; |
0 | 315 |
|
316 |
AddSortableSpriteToDraw(tep->image, ti->x + tep->x, ti->y + tep->y, 5, 5, 0x10, z); |
|
317 |
tep->image = 0; |
|
318 |
} |
|
319 |
} |
|
320 |
||
321 |
EndSpriteCombine(); |
|
322 |
} |
|
323 |
||
324 |
||
2537 | 325 |
static uint GetSlopeZ_Trees(const TileInfo* ti) |
326 |
{ |
|
2243 | 327 |
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
0 | 328 |
} |
329 |
||
3418
a592d40a4d04
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3379
diff
changeset
|
330 |
static uint GetSlopeTileh_Trees(TileIndex tile, uint tileh) |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2537
diff
changeset
|
331 |
{ |
3418
a592d40a4d04
(svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents:
3379
diff
changeset
|
332 |
return tileh; |
39 | 333 |
} |
334 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
335 |
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
|
336 |
{ |
2243 | 337 |
uint num; |
0 | 338 |
|
339 |
if (flags & DC_EXEC && _current_player < MAX_PLAYERS) { |
|
340 |
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
|
341 |
if (t != NULL) |
1005 | 342 |
ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM); |
0 | 343 |
} |
344 |
||
2981 | 345 |
num = GetTreeCount(tile) + 1; |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
346 |
if (IS_INT_INSIDE(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4; |
0 | 347 |
|
2243 | 348 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 349 |
|
350 |
return num * _price.remove_trees; |
|
351 |
} |
|
352 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
353 |
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac) |
0 | 354 |
{ |
355 |
/* not used */ |
|
356 |
} |
|
357 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
358 |
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td) |
0 | 359 |
{ |
2981 | 360 |
TreeType tt = GetTreeType(tile); |
361 |
||
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
362 |
if (IS_INT_INSIDE(tt, TREE_RAINFOREST, TREE_CACTUS)) { |
2981 | 363 |
td->str = STR_280F_RAINFOREST; |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
364 |
} else if (tt == TREE_CACTUS) { |
2981 | 365 |
td->str = STR_2810_CACTUS_PLANTS; |
366 |
} else { |
|
367 |
td->str = STR_280E_TREES; |
|
368 |
} |
|
0 | 369 |
|
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
|
370 |
td->owner = GetTileOwner(tile); |
0 | 371 |
} |
372 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
373 |
static void AnimateTile_Trees(TileIndex tile) |
0 | 374 |
{ |
375 |
/* not used */ |
|
376 |
} |
|
377 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
378 |
static void TileLoopTreesDesert(TileIndex tile) |
0 | 379 |
{ |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
380 |
switch (GetTropicZone(tile)) { |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
381 |
case TROPICZONE_DESERT: |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
382 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) { |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
383 |
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3); |
2981 | 384 |
MarkTileDirtyByTile(tile); |
385 |
} |
|
386 |
break; |
|
2243 | 387 |
|
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
388 |
case TROPICZONE_RAINFOREST: { |
2981 | 389 |
static const SoundFx forest_sounds[] = { |
390 |
SND_42_LOON_BIRD, |
|
391 |
SND_43_LION, |
|
392 |
SND_44_MONKEYS, |
|
393 |
SND_48_DISTANT_BIRD |
|
394 |
}; |
|
395 |
uint32 r = Random(); |
|
0 | 396 |
|
2981 | 397 |
if (CHANCE16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile); |
398 |
break; |
|
0 | 399 |
} |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
400 |
|
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
401 |
default: break; |
0 | 402 |
} |
403 |
} |
|
404 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
405 |
static void TileLoopTreesAlps(TileIndex tile) |
0 | 406 |
{ |
2981 | 407 |
int k = GetTileZ(tile) - _opt.snow_line; |
0 | 408 |
|
3422
12cdb13ddb56
(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
|
409 |
if (k < -TILE_HEIGHT) { |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
410 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) return; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
411 |
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 0); |
0 | 412 |
} else { |
3422
12cdb13ddb56
(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
|
413 |
uint density = min((uint)(k + TILE_HEIGHT) / TILE_HEIGHT, 3); |
2981 | 414 |
|
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
415 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT || |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
416 |
GetTreeDensity(tile) != density) { |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
417 |
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, density); |
2981 | 418 |
} else { |
419 |
if (GetTreeDensity(tile) == 3) { |
|
420 |
uint32 r = Random(); |
|
421 |
if (CHANCE16I(1, 200, r)) { |
|
422 |
SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile); |
|
423 |
} |
|
0 | 424 |
} |
425 |
return; |
|
426 |
} |
|
427 |
} |
|
428 |
MarkTileDirtyByTile(tile); |
|
429 |
} |
|
430 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
431 |
static void TileLoop_Trees(TileIndex tile) |
0 | 432 |
{ |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
433 |
static const TileIndexDiffC _tileloop_trees_dir[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
434 |
{-1, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
435 |
{ 0, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
436 |
{ 1, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
437 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
438 |
{ 1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
439 |
{-1, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
440 |
{ 0, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
881
diff
changeset
|
441 |
{ 1, 1} |
0 | 442 |
}; |
443 |
||
2981 | 444 |
switch (_opt.landscape) { |
445 |
case LT_DESERT: TileLoopTreesDesert(tile); break; |
|
446 |
case LT_HILLY: TileLoopTreesAlps(tile); break; |
|
0 | 447 |
} |
448 |
||
449 |
TileLoopClearHelper(tile); |
|
450 |
||
2981 | 451 |
if (GetTreeCounter(tile) < 15) { |
452 |
AddTreeCounter(tile, 1); |
|
453 |
return; |
|
454 |
} |
|
455 |
SetTreeCounter(tile, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
456 |
|
2981 | 457 |
switch (GetTreeGrowth(tile)) { |
458 |
case 3: /* regular sized tree */ |
|
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
459 |
if (_opt.landscape == LT_DESERT && |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
460 |
GetTreeType(tile) != TREE_CACTUS && |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
461 |
GetTropicZone(tile) == TROPICZONE_DESERT) { |
2981 | 462 |
AddTreeGrowth(tile, 1); |
463 |
} else { |
|
464 |
switch (GB(Random(), 0, 3)) { |
|
465 |
case 0: /* start destructing */ |
|
466 |
AddTreeGrowth(tile, 1); |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
467 |
break; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
468 |
|
2981 | 469 |
case 1: /* add a tree */ |
470 |
if (GetTreeCount(tile) < 3) { |
|
471 |
AddTreeCount(tile, 1); |
|
472 |
SetTreeGrowth(tile, 0); |
|
473 |
break; |
|
474 |
} |
|
475 |
/* FALL THROUGH */ |
|
0 | 476 |
|
2981 | 477 |
case 2: { /* add a neighbouring tree */ |
478 |
TreeType treetype = GetTreeType(tile); |
|
0 | 479 |
|
2981 | 480 |
tile += ToTileIndexDiff(_tileloop_trees_dir[Random() & 7]); |
0 | 481 |
|
2981 | 482 |
if (!IsTileType(tile, MP_CLEAR)) return; |
483 |
||
484 |
switch (GetClearGround(tile)) { |
|
485 |
case CL_GRASS: |
|
486 |
if (GetClearDensity(tile) != 3) return; |
|
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
487 |
MakeTree(tile, treetype, 0, 0, TREE_GROUND_GRASS, 0); |
2981 | 488 |
break; |
489 |
||
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
490 |
case CL_ROUGH: MakeTree(tile, treetype, 0, 0, TREE_GROUND_ROUGH, 0); break; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
491 |
case CL_SNOW: MakeTree(tile, treetype, 0, 0, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break; |
2981 | 492 |
default: return; |
493 |
} |
|
494 |
break; |
|
495 |
} |
|
496 |
||
497 |
default: |
|
498 |
return; |
|
499 |
} |
|
0 | 500 |
} |
2981 | 501 |
break; |
502 |
||
503 |
case 6: /* final stage of tree destruction */ |
|
504 |
if (GetTreeCount(tile) > 0) { |
|
505 |
/* more than one tree, delete it */ |
|
506 |
AddTreeCount(tile, -1); |
|
507 |
SetTreeGrowth(tile, 3); |
|
508 |
} else { |
|
509 |
/* just one tree, change type into MP_CLEAR */ |
|
510 |
switch (GetTreeGround(tile)) { |
|
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
511 |
case TREE_GROUND_GRASS: MakeClear(tile, CL_GRASS, 3); break; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
512 |
case TREE_GROUND_ROUGH: MakeClear(tile, CL_ROUGH, 3); break; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
513 |
default: MakeClear(tile, CL_SNOW, GetTreeDensity(tile)); break; |
2981 | 514 |
} |
0 | 515 |
} |
2981 | 516 |
break; |
517 |
||
518 |
default: |
|
519 |
AddTreeGrowth(tile, 1); |
|
520 |
break; |
|
0 | 521 |
} |
522 |
||
523 |
MarkTileDirtyByTile(tile); |
|
524 |
} |
|
525 |
||
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
|
526 |
void OnTick_Trees(void) |
0 | 527 |
{ |
528 |
uint32 r; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
529 |
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
|
530 |
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
|
531 |
TreeType tree; |
0 | 532 |
|
533 |
/* 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
|
534 |
if (_opt.landscape == LT_DESERT && |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
535 |
(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) && |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
536 |
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
|
537 |
(ct = GetClearGround(tile), ct == CL_GRASS || ct == CL_ROUGH) && |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
538 |
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) { |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
539 |
MakeTree(tile, tree, 0, 0, ct == CL_ROUGH ? TREE_GROUND_ROUGH : TREE_GROUND_GRASS, 0); |
0 | 540 |
} |
541 |
||
542 |
// byte underflow |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
543 |
if (--_trees_tick_ctr != 0) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
544 |
|
0 | 545 |
/* place a tree at a random spot */ |
546 |
r = Random(); |
|
547 |
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
|
548 |
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
|
549 |
(ct = GetClearGround(tile), ct == CL_GRASS || ct == CL_ROUGH || ct == CL_SNOW) && |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
550 |
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) { |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
551 |
switch (ct) { |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
552 |
case CL_GRASS: MakeTree(tile, tree, 0, 0, TREE_GROUND_GRASS, 0); break; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
553 |
case CL_ROUGH: MakeTree(tile, tree, 0, 0, TREE_GROUND_ROUGH, 0); break; |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
554 |
default: MakeTree(tile, tree, 0, 0, TREE_GROUND_SNOW_DESERT, GetClearDensity(tile)); break; |
0 | 555 |
} |
556 |
} |
|
557 |
} |
|
558 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
559 |
static void ClickTile_Trees(TileIndex tile) |
0 | 560 |
{ |
561 |
/* not used */ |
|
562 |
} |
|
563 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
564 |
static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode) |
0 | 565 |
{ |
566 |
return 0; |
|
567 |
} |
|
568 |
||
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
|
569 |
static void ChangeTileOwner_Trees(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 570 |
{ |
571 |
/* not used */ |
|
572 |
} |
|
573 |
||
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
|
574 |
void InitializeTrees(void) |
0 | 575 |
{ |
576 |
_trees_tick_ctr = 0; |
|
577 |
} |
|
578 |
||
579 |
||
580 |
const TileTypeProcs _tile_type_trees_procs = { |
|
581 |
DrawTile_Trees, /* draw_tile_proc */ |
|
582 |
GetSlopeZ_Trees, /* get_slope_z_proc */ |
|
583 |
ClearTile_Trees, /* clear_tile_proc */ |
|
584 |
GetAcceptedCargo_Trees, /* get_accepted_cargo_proc */ |
|
585 |
GetTileDesc_Trees, /* get_tile_desc_proc */ |
|
586 |
GetTileTrackStatus_Trees, /* get_tile_track_status_proc */ |
|
587 |
ClickTile_Trees, /* click_tile_proc */ |
|
588 |
AnimateTile_Trees, /* animate_tile_proc */ |
|
589 |
TileLoop_Trees, /* tile_loop_clear */ |
|
590 |
ChangeTileOwner_Trees, /* change_tile_owner_clear */ |
|
591 |
NULL, /* get_produced_cargo_proc */ |
|
592 |
NULL, /* vehicle_enter_tile_proc */ |
|
593 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 594 |
GetSlopeTileh_Trees, /* get_slope_tileh_proc */ |
0 | 595 |
}; |