equal
deleted
inserted
replaced
19 #include "town.h" |
19 #include "town.h" |
20 #include "sound.h" |
20 #include "sound.h" |
21 #include "variables.h" |
21 #include "variables.h" |
22 #include "genworld.h" |
22 #include "genworld.h" |
23 |
23 |
|
24 /** |
|
25 * List of tree placer algorithm. |
|
26 * |
|
27 * This enumeration defines all possible tree placer algorithm in the game. |
|
28 */ |
24 enum TreePlacer { |
29 enum TreePlacer { |
25 TP_NONE, |
30 TP_NONE, ///< No tree placer algorithm |
26 TP_ORIGINAL, |
31 TP_ORIGINAL, ///< The original algorithm |
27 TP_IMPROVED, |
32 TP_IMPROVED, ///< A 'improved' algorithm |
28 }; |
33 }; |
29 |
34 |
|
35 /** |
|
36 * Get a random TreeType for the given tile based on a given seed |
|
37 * |
|
38 * This function returns a random TreeType which can be placed on the given tile. |
|
39 * The seed for randomness must be less or equal 256, use #GB on the value of Random() |
|
40 * to get such a value. |
|
41 * |
|
42 * @param tile The tile to get a random TreeType from |
|
43 * @param seed The seed for randomness, must be less or equal 256 |
|
44 * @return The random tree type |
|
45 */ |
30 static TreeType GetRandomTreeType(TileIndex tile, uint seed) |
46 static TreeType GetRandomTreeType(TileIndex tile, uint seed) |
31 { |
47 { |
32 switch (_opt.landscape) { |
48 switch (_opt.landscape) { |
33 case LT_TEMPERATE: |
49 case LT_TEMPERATE: |
34 return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE); |
50 return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE); |
46 default: |
62 default: |
47 return (TreeType)(seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND); |
63 return (TreeType)(seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND); |
48 } |
64 } |
49 } |
65 } |
50 |
66 |
|
67 /** |
|
68 * Make a random tree tile of the given tile |
|
69 * |
|
70 * Create a new tree-tile for the given tile. The second parameter is used for |
|
71 * randomness like type and number of trees. |
|
72 * |
|
73 * @param tile The tile to make a tree-tile from |
|
74 * @param r The randomness value from a Random() value |
|
75 */ |
51 static void PlaceTree(TileIndex tile, uint32 r) |
76 static void PlaceTree(TileIndex tile, uint32 r) |
52 { |
77 { |
53 TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8)); |
78 TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8)); |
54 |
79 |
55 if (tree != TREE_INVALID) { |
80 if (tree != TREE_INVALID) { |
64 SetTreeCounter(tile, (TreeGround)GB(r, 24, 4)); |
89 SetTreeCounter(tile, (TreeGround)GB(r, 24, 4)); |
65 } |
90 } |
66 } |
91 } |
67 } |
92 } |
68 |
93 |
|
94 /** |
|
95 * Place some amount of trees around a given tile. |
|
96 * |
|
97 * This function adds some trees around a given tile. As this function use |
|
98 * the Random() call it depends on the random how many trees are actually placed |
|
99 * around the given tile. |
|
100 * |
|
101 * @param tile The center of the trees to add |
|
102 */ |
69 static void DoPlaceMoreTrees(TileIndex tile) |
103 static void DoPlaceMoreTrees(TileIndex tile) |
70 { |
104 { |
71 uint i; |
105 uint i; |
72 |
106 |
73 for (i = 0; i < 1000; i++) { |
107 for (i = 0; i < 1000; i++) { |
85 PlaceTree(cur_tile, r); |
119 PlaceTree(cur_tile, r); |
86 } |
120 } |
87 } |
121 } |
88 } |
122 } |
89 |
123 |
|
124 /** |
|
125 * Place more trees on the map. |
|
126 * |
|
127 * This function add more trees to the map. |
|
128 */ |
90 static void PlaceMoreTrees() |
129 static void PlaceMoreTrees() |
91 { |
130 { |
92 uint i = ScaleByMapSize(GB(Random(), 0, 5) + 25); |
131 uint i = ScaleByMapSize(GB(Random(), 0, 5) + 25); |
93 do { |
132 do { |
94 DoPlaceMoreTrees(RandomTile()); |
133 DoPlaceMoreTrees(RandomTile()); |
95 } while (--i); |
134 } while (--i); |
96 } |
135 } |
97 |
136 |
98 /** |
137 /** |
99 * Place a tree at the same height as an existing tree. |
138 * Place a tree at the same height as an existing tree. |
100 * This gives cool effects to the map. |
139 * |
|
140 * Add a new tree around the given tile which is at the same |
|
141 * height or at some offset (2 units) of it. |
|
142 * |
|
143 * @param tile The base tile to add a new tree somewhere around |
|
144 * @param height The height (like the one from the tile) |
101 */ |
145 */ |
102 void PlaceTreeAtSameHeight(TileIndex tile, uint height) |
146 void PlaceTreeAtSameHeight(TileIndex tile, uint height) |
103 { |
147 { |
104 uint i; |
148 uint i; |
105 |
149 |
125 PlaceTree(cur_tile, r); |
169 PlaceTree(cur_tile, r); |
126 break; |
170 break; |
127 } |
171 } |
128 } |
172 } |
129 |
173 |
|
174 /** |
|
175 * Place some trees randomly |
|
176 * |
|
177 * This function just place some trees randomly on the map. |
|
178 */ |
130 void PlaceTreesRandomly() |
179 void PlaceTreesRandomly() |
131 { |
180 { |
132 uint i, j, ht; |
181 uint i, j, ht; |
133 |
182 |
134 i = ScaleByMapSize(1000); |
183 i = ScaleByMapSize(1000); |
181 } |
230 } |
182 } while (--i); |
231 } while (--i); |
183 } |
232 } |
184 } |
233 } |
185 |
234 |
|
235 /** |
|
236 * Place new trees. |
|
237 * |
|
238 * This function takes care of the selected tree placer algorithm and |
|
239 * place randomly the trees for a new game. |
|
240 */ |
186 void GenerateTrees() |
241 void GenerateTrees() |
187 { |
242 { |
188 uint i, total; |
243 uint i, total; |
189 |
244 |
190 if (_patches.tree_placer == TP_NONE) return; |
245 if (_patches.tree_placer == TP_NONE) return; |