author | rubidium |
Thu, 18 Dec 2008 12:23:08 +0000 | |
changeset 10436 | 8d3a9fbe8f19 |
parent 10363 | 96eb6897bf96 |
child 10438 | 51bff16a04c9 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8806
diff
changeset
|
3 |
/** @file tree_cmd.cpp Handling of tree tiles. */ |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1784
diff
changeset
|
6 |
#include "openttd.h" |
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
4850
diff
changeset
|
7 |
#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
|
8 |
#include "clear_map.h" |
8119
52b48108425a
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8116
diff
changeset
|
9 |
#include "tile_cmd.h" |
6343
76d17f784c13
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6248
diff
changeset
|
10 |
#include "landscape.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3079
diff
changeset
|
11 |
#include "tree_map.h" |
8225
cd84a95b6630
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8187
diff
changeset
|
12 |
#include "viewport_func.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8108
diff
changeset
|
13 |
#include "command_func.h" |
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8108
diff
changeset
|
14 |
#include "economy_func.h" |
0 | 15 |
#include "town.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
|
16 |
#include "variables.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
17 |
#include "genworld.h" |
7849
0a1c0af2c96c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
7712
diff
changeset
|
18 |
#include "transparency.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8119
diff
changeset
|
19 |
#include "functions.h" |
10208
72c00af5c95d
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents:
10207
diff
changeset
|
20 |
#include "company_func.h" |
8157
1505def01945
(svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents:
8139
diff
changeset
|
21 |
#include "sound_func.h" |
8270
e7c342f6b14c
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8264
diff
changeset
|
22 |
#include "settings_type.h" |
8459 | 23 |
#include "water_map.h" |
24 |
#include "water.h" |
|
9126
5648d696456b
(svn r12986) -Codechange: move the landscape and transport related types from openttd.h to their own headers.
rubidium
parents:
9111
diff
changeset
|
25 |
#include "landscape_type.h" |
10208
72c00af5c95d
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents:
10207
diff
changeset
|
26 |
#include "company_base.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
27 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
28 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
29 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
30 |
#include "table/tree_land.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
31 |
|
7597
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
32 |
/** |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
33 |
* List of tree placer algorithm. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
34 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
35 |
* This enumeration defines all possible tree placer algorithm in the game. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
36 |
*/ |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
37 |
enum TreePlacer { |
7597
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
38 |
TP_NONE, ///< No tree placer algorithm |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
39 |
TP_ORIGINAL, ///< The original algorithm |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
40 |
TP_IMPROVED, ///< A 'improved' algorithm |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
41 |
}; |
0 | 42 |
|
7597
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
43 |
/** |
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
44 |
* Tests if a tile can be converted to MP_TREES |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
45 |
* This is true for clear ground without farms or rocks. |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
46 |
* |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
47 |
* @param tile the tile of interest |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
48 |
* @param allow_desert Allow planting trees on CLEAR_DESERT? |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
49 |
* @return true if trees can be built. |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
50 |
*/ |
8459 | 51 |
static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert) |
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
52 |
{ |
8459 | 53 |
switch (GetTileType(tile)) { |
54 |
case MP_WATER: |
|
55 |
return !IsBridgeAbove(tile) && IsCoast(tile) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL)); |
|
56 |
||
57 |
case MP_CLEAR: |
|
58 |
return !IsBridgeAbove(tile) && !IsClearGround(tile, CLEAR_FIELDS) && !IsClearGround(tile, CLEAR_ROCKS) && |
|
59 |
(allow_desert || !IsClearGround(tile, CLEAR_DESERT)); |
|
60 |
||
61 |
default: return false; |
|
62 |
} |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
63 |
} |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
64 |
|
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
65 |
/** |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
66 |
* Creates a tree tile |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
67 |
* Ground type and density is preserved. |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
68 |
* |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
69 |
* @pre the tile must be suitable for trees. |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
70 |
* |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
71 |
* @param tile where to plant the trees. |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
72 |
* @param type The type of the tree |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
73 |
* @param count the number of trees (minus 1) |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
74 |
* @param growth the growth status |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
75 |
*/ |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
76 |
static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, uint growth) |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
77 |
{ |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
78 |
assert(treetype != TREE_INVALID); |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
79 |
assert(CanPlantTreesOnTile(tile, true)); |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
80 |
|
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
81 |
TreeGround ground; |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
82 |
uint density = 3; |
8459 | 83 |
|
84 |
switch (GetTileType(tile)) { |
|
85 |
case MP_WATER: |
|
86 |
ground = TREE_GROUND_SHORE; |
|
87 |
break; |
|
88 |
||
89 |
case MP_CLEAR: |
|
90 |
switch (GetClearGround(tile)) { |
|
91 |
case CLEAR_GRASS: ground = TREE_GROUND_GRASS; density = GetClearDensity(tile); break; |
|
92 |
case CLEAR_ROUGH: ground = TREE_GROUND_ROUGH; break; |
|
93 |
default: ground = TREE_GROUND_SNOW_DESERT; density = GetClearDensity(tile); break; |
|
94 |
} |
|
95 |
break; |
|
96 |
||
97 |
default: NOT_REACHED(); |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
98 |
} |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
99 |
|
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
100 |
MakeTree(tile, treetype, count, growth, ground, density); |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
101 |
} |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
102 |
|
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
103 |
/** |
7597
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
104 |
* Get a random TreeType for the given tile based on a given seed |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
105 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
106 |
* This function returns a random TreeType which can be placed on the given tile. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
107 |
* The seed for randomness must be less or equal 256, use #GB on the value of Random() |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
108 |
* to get such a value. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
109 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
110 |
* @param tile The tile to get a random TreeType from |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
111 |
* @param seed The seed for randomness, must be less or equal 256 |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
112 |
* @return The random tree type |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
113 |
*/ |
2981 | 114 |
static TreeType GetRandomTreeType(TileIndex tile, uint seed) |
0 | 115 |
{ |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
116 |
switch (_settings_game.game_creation.landscape) { |
6357
f0f5e7d1713c
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6343
diff
changeset
|
117 |
case LT_TEMPERATE: |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
118 |
return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE); |
0 | 119 |
|
6357
f0f5e7d1713c
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6343
diff
changeset
|
120 |
case LT_ARCTIC: |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
121 |
return (TreeType)(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
|
122 |
|
6357
f0f5e7d1713c
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6343
diff
changeset
|
123 |
case LT_TROPIC: |
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
|
124 |
switch (GetTropicZone(tile)) { |
8450
73371bb82922
(svn r12020) -Documentation: Correct description of TropicZone.
frosch
parents:
8448
diff
changeset
|
125 |
case TROPICZONE_NORMAL: return (TreeType)(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
126 |
case TROPICZONE_DESERT: return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS); |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
127 |
default: return (TreeType)(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
|
128 |
} |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
129 |
|
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
130 |
default: |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
131 |
return (TreeType)(seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND); |
0 | 132 |
} |
133 |
} |
|
134 |
||
7597
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
135 |
/** |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
136 |
* Make a random tree tile of the given tile |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
137 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
138 |
* Create a new tree-tile for the given tile. The second parameter is used for |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
139 |
* randomness like type and number of trees. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
140 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
141 |
* @param tile The tile to make a tree-tile from |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
142 |
* @param r The randomness value from a Random() value |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
143 |
*/ |
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
144 |
static void PlaceTree(TileIndex tile, uint32 r) |
0 | 145 |
{ |
2981 | 146 |
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
|
147 |
|
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
148 |
if (tree != TREE_INVALID) { |
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
149 |
PlantTreesOnTile(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6)); |
0 | 150 |
|
8459 | 151 |
/* Rerandomize ground, if neither snow nor shore */ |
152 |
TreeGround ground = GetTreeGround(tile); |
|
153 |
if (ground != TREE_GROUND_SNOW_DESERT && ground != TREE_GROUND_SHORE) { |
|
7710
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
154 |
SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3); |
0 | 155 |
} |
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
156 |
|
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
157 |
/* Set the counter to a random start value */ |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
158 |
SetTreeCounter(tile, (TreeGround)GB(r, 24, 4)); |
0 | 159 |
} |
160 |
} |
|
161 |
||
7597
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
162 |
/** |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
163 |
* Place some amount of trees around a given tile. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
164 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
165 |
* This function adds some trees around a given tile. As this function use |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
166 |
* the Random() call it depends on the random how many trees are actually placed |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
167 |
* around the given tile. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
168 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
169 |
* @param tile The center of the trees to add |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
170 |
*/ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
171 |
static void DoPlaceMoreTrees(TileIndex tile) |
0 | 172 |
{ |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
173 |
uint i; |
0 | 174 |
|
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
175 |
for (i = 0; i < 1000; i++) { |
0 | 176 |
uint32 r = Random(); |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
177 |
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
|
178 |
int y = GB(r, 8, 5) - 16; |
7923
91982bd3c549
(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents:
7876
diff
changeset
|
179 |
uint dist = abs(x) + abs(y); |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
180 |
TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y)); |
0 | 181 |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
182 |
if (dist <= 13 && CanPlantTreesOnTile(cur_tile, true)) { |
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
183 |
PlaceTree(cur_tile, r); |
0 | 184 |
} |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
185 |
} |
0 | 186 |
} |
187 |
||
7597
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
188 |
/** |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
189 |
* Place more trees on the map. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
190 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
191 |
* This function add more trees to the map. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
192 |
*/ |
6247 | 193 |
static void PlaceMoreTrees() |
0 | 194 |
{ |
2243 | 195 |
uint i = ScaleByMapSize(GB(Random(), 0, 5) + 25); |
0 | 196 |
do { |
2051 | 197 |
DoPlaceMoreTrees(RandomTile()); |
0 | 198 |
} while (--i); |
199 |
} |
|
200 |
||
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
201 |
/** |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
202 |
* Place a tree at the same height as an existing tree. |
7597
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
203 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
204 |
* Add a new tree around the given tile which is at the same |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
205 |
* height or at some offset (2 units) of it. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
206 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
207 |
* @param tile The base tile to add a new tree somewhere around |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
208 |
* @param height The height (like the one from the tile) |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
209 |
*/ |
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
210 |
static void PlaceTreeAtSameHeight(TileIndex tile, uint height) |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
211 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
212 |
uint i; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
213 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
214 |
for (i = 0; i < 1000; i++) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
215 |
uint32 r = Random(); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
216 |
int x = GB(r, 0, 5) - 16; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
217 |
int y = GB(r, 8, 5) - 16; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
218 |
TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y)); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
219 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
220 |
/* Keep in range of the existing tree */ |
7923
91982bd3c549
(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents:
7876
diff
changeset
|
221 |
if (abs(x) + abs(y) > 16) continue; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
222 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
223 |
/* Clear tile, no farm-tiles or rocks */ |
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
224 |
if (!CanPlantTreesOnTile(cur_tile, true)) continue; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
225 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
226 |
/* Not too much height difference */ |
7970
7d6b9ab57081
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
7967
diff
changeset
|
227 |
if (Delta(GetTileZ(cur_tile), height) > 2) continue; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
228 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
229 |
/* Place one tree and quit */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
230 |
PlaceTree(cur_tile, r); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
231 |
break; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
232 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
233 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
234 |
|
7597
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
235 |
/** |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
236 |
* Place some trees randomly |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
237 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
238 |
* This function just place some trees randomly on the map. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
239 |
*/ |
6247 | 240 |
void PlaceTreesRandomly() |
0 | 241 |
{ |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
242 |
uint i, j, ht; |
0 | 243 |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
244 |
i = ScaleByMapSize(1000); |
0 | 245 |
do { |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
246 |
uint32 r = Random(); |
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
247 |
TileIndex tile = RandomTileSeed(r); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
248 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
249 |
IncreaseGeneratingWorldProgress(GWP_TREE); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
250 |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
251 |
if (CanPlantTreesOnTile(tile, true)) { |
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
252 |
PlaceTree(tile, r); |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
253 |
if (_settings_game.game_creation.tree_placer != TP_IMPROVED) continue; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
254 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
255 |
/* Place a number of trees based on the tile height. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
256 |
* This gives a cool effect of multiple trees close together. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
257 |
* It is almost real life ;) */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
258 |
ht = GetTileZ(tile); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
259 |
/* The higher we get, the more trees we plant */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
260 |
j = GetTileZ(tile) / TILE_HEIGHT * 2; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
261 |
while (j--) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
262 |
/* Above snowline more trees! */ |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
263 |
if (_settings_game.game_creation.landscape == LT_ARCTIC && ht > GetSnowLine()) { |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
264 |
PlaceTreeAtSameHeight(tile, ht); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
265 |
PlaceTreeAtSameHeight(tile, ht); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
266 |
}; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
267 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
268 |
PlaceTreeAtSameHeight(tile, ht); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
269 |
} |
0 | 270 |
} |
271 |
} while (--i); |
|
272 |
||
273 |
/* place extra trees at rainforest area */ |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
274 |
if (_settings_game.game_creation.landscape == LT_TROPIC) { |
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
275 |
i = ScaleByMapSize(15000); |
0 | 276 |
|
277 |
do { |
|
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
278 |
uint32 r = Random(); |
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
279 |
TileIndex tile = RandomTileSeed(r); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
280 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
281 |
IncreaseGeneratingWorldProgress(GWP_TREE); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
282 |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
283 |
if (GetTropicZone(tile) == TROPICZONE_RAINFOREST && CanPlantTreesOnTile(tile, false)) { |
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
284 |
PlaceTree(tile, r); |
0 | 285 |
} |
286 |
} while (--i); |
|
287 |
} |
|
288 |
} |
|
289 |
||
7597
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
290 |
/** |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
291 |
* Place new trees. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
292 |
* |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
293 |
* This function takes care of the selected tree placer algorithm and |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
294 |
* place randomly the trees for a new game. |
e9ad1ed5c4d5
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
7509
diff
changeset
|
295 |
*/ |
6247 | 296 |
void GenerateTrees() |
0 | 297 |
{ |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
298 |
uint i, total; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
299 |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
300 |
if (_settings_game.game_creation.tree_placer == TP_NONE) return; |
0 | 301 |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
302 |
if (_settings_game.game_creation.landscape != LT_TOYLAND) PlaceMoreTrees(); |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
303 |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
304 |
switch (_settings_game.game_creation.tree_placer) { |
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
305 |
case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 15 : 6; break; |
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
306 |
case TP_IMPROVED: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 4 : 2; break; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
307 |
default: NOT_REACHED(); return; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
308 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
309 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
310 |
total = ScaleByMapSize(1000); |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
311 |
if (_settings_game.game_creation.landscape == LT_TROPIC) total += ScaleByMapSize(15000); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
312 |
total *= i; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
313 |
SetGeneratingWorldProgress(GWP_TREE, total); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
314 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
315 |
for (; i != 0; i--) { |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
316 |
PlaceTreesRandomly(); |
0 | 317 |
} |
318 |
} |
|
319 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
320 |
/** 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
|
321 |
* @param tile start tile of area-drag of tree plantation |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
322 |
* @param flags type of operation |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
323 |
* @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
|
324 |
* @param p2 end tile of area-drag |
0 | 325 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6683
diff
changeset
|
326 |
CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 327 |
{ |
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
|
328 |
StringID msg = INVALID_STRING_ID; |
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8225
diff
changeset
|
329 |
CommandCost cost(EXPENSES_OTHER); |
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
|
330 |
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
|
331 |
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
|
332 |
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
|
333 |
|
2892
db216dc91941
(svn r3446) - Fix: incorrect validating of tree-planting command which can allow a buffer-overflow (Tron)
Darkvater
parents:
2654
diff
changeset
|
334 |
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
|
335 |
/* Check the tree type. It can be random or some valid value within the current climate */ |
10236
50afe9dd466e
(svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium
parents:
10208
diff
changeset
|
336 |
if (p1 != UINT_MAX && p1 - _tree_base_by_landscape[_settings_game.game_creation.landscape] >= _tree_count_by_landscape[_settings_game.game_creation.landscape]) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
337 |
|
0 | 338 |
// 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
|
339 |
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
|
340 |
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
|
341 |
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
|
342 |
sy = TileY(p2); |
6106 | 343 |
if (ex < sx) Swap(ex, sx); |
344 |
if (ey < sy) Swap(ey, sy); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
345 |
|
2118
aec8042f000b
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
346 |
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
|
347 |
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
|
348 |
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
|
349 |
|
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
350 |
switch (GetTileType(tile)) { |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
351 |
case MP_TREES: |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
352 |
/* no more space for trees? */ |
10363
96eb6897bf96
(svn r14614) -Codechange [FS#2423]: GetTreeCount() should behave as its name and documentation imply. Remove unused SetTreeCount() (PhilSophus)
smatz
parents:
10236
diff
changeset
|
353 |
if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 4) { |
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
|
354 |
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
|
355 |
continue; |
0 | 356 |
} |
357 |
||
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
358 |
if (flags & DC_EXEC) { |
2981 | 359 |
AddTreeCount(tile, 1); |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
360 |
MarkTileDirtyByTile(tile); |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
361 |
} |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
362 |
/* 2x as expensive to add more trees to an existing tile */ |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
363 |
cost.AddCost(_price.build_trees * 2); |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
364 |
break; |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
365 |
|
7509
23372ed624e8
(svn r11024) -Fix [FS#1173]: give a more correct error when building some things on tile 0; "Can't build on water" or "Too close to the edge" instead of "Vehicle in the way". Patch by SmatZ.
rubidium
parents:
7494
diff
changeset
|
366 |
case MP_WATER: |
8459 | 367 |
if (!IsCoast(tile) || IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL))) { |
368 |
msg = STR_3807_CAN_T_BUILD_ON_WATER; |
|
369 |
continue; |
|
370 |
} |
|
371 |
/* FALL THROUGH */ |
|
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
372 |
case MP_CLEAR: |
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
373 |
if (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
|
374 |
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
|
375 |
continue; |
0 | 376 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
377 |
|
8459 | 378 |
if (IsTileType(tile, MP_CLEAR)) { |
379 |
/* Remove fields or rocks. Note that the ground will get barrened */ |
|
380 |
switch (GetClearGround(tile)) { |
|
381 |
case CLEAR_FIELDS: |
|
382 |
case CLEAR_ROCKS: { |
|
383 |
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
384 |
if (CmdFailed(ret)) return ret; |
|
385 |
cost.AddCost(ret); |
|
386 |
break; |
|
387 |
} |
|
388 |
||
389 |
default: break; |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
390 |
} |
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
|
391 |
} |
0 | 392 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9659
diff
changeset
|
393 |
if (_game_mode != GM_EDITOR && IsValidCompanyID(_current_company)) { |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
394 |
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority); |
8232
a4883a0598db
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8230
diff
changeset
|
395 |
if (t != NULL) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM); |
a4883a0598db
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8230
diff
changeset
|
396 |
} |
a4883a0598db
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8230
diff
changeset
|
397 |
|
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
398 |
if (flags & DC_EXEC) { |
2981 | 399 |
TreeType treetype; |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
400 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
401 |
treetype = (TreeType)p1; |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
402 |
if (treetype == TREE_INVALID) { |
2981 | 403 |
treetype = GetRandomTreeType(tile, GB(Random(), 24, 8)); |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
404 |
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
|
405 |
} |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
406 |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
407 |
/* Plant full grown trees in scenario editor */ |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
408 |
PlantTreesOnTile(tile, treetype, 0, _game_mode == GM_EDITOR ? 3 : 0); |
3003 | 409 |
MarkTileDirtyByTile(tile); |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
410 |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
411 |
/* When planting rainforest-trees, set tropiczone to rainforest in editor. */ |
7954
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7923
diff
changeset
|
412 |
if (_game_mode == GM_EDITOR && IsInsideMM(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
|
413 |
SetTropicZone(tile, TROPICZONE_RAINFOREST); |
0 | 414 |
} |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
415 |
cost.AddCost(_price.build_trees); |
1286
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
416 |
break; |
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
417 |
|
10b9fe28effc
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
418 |
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
|
419 |
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
|
420 |
break; |
0 | 421 |
} |
422 |
} |
|
423 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
424 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
425 |
if (cost.GetCost() == 0) { |
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
|
426 |
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
|
427 |
} 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
|
428 |
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
|
429 |
} |
0 | 430 |
} |
431 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
432 |
struct TreeListEnt { |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
433 |
SpriteID image; |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
434 |
SpriteID pal; |
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6427
diff
changeset
|
435 |
byte x, y; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
436 |
}; |
0 | 437 |
|
438 |
static void DrawTile_Trees(TileInfo *ti) |
|
439 |
{ |
|
2981 | 440 |
switch (GetTreeGround(ti->tile)) { |
8459 | 441 |
case TREE_GROUND_SHORE: DrawShoreTile(ti->tileh); break; |
7710
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
442 |
case TREE_GROUND_GRASS: DrawClearLandTile(ti, GetTreeDensity(ti->tile)); break; |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
443 |
case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break; |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
444 |
default: DrawGroundSprite(_tree_sprites_1[GetTreeDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE); break; |
0 | 445 |
} |
446 |
||
2220 | 447 |
DrawClearLandFence(ti); |
0 | 448 |
|
8498
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
449 |
/* Do not draw trees when the invisible trees patch and transparency tree are set */ |
8806
4fe163e0b52a
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
8616
diff
changeset
|
450 |
if (IsInvisibilitySet(TO_TREES)) return; |
8498
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
451 |
|
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
452 |
uint16 tmp = ti->x; |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
453 |
|
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
454 |
tmp = ROR(tmp, 2); |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
455 |
tmp -= ti->y; |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
456 |
tmp = ROR(tmp, 3); |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
457 |
tmp -= ti->x; |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
458 |
tmp = ROR(tmp, 1); |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
459 |
tmp += ti->y; |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
460 |
|
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
461 |
uint index = GB(tmp, 6, 2) + (GetTreeType(ti->tile) << 2); |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
462 |
|
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
463 |
/* different tree styles above one of the grounds */ |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
464 |
if (GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT && |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
465 |
GetTreeDensity(ti->tile) >= 2 && |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
466 |
IsInsideMM(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) { |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
467 |
index += 164 - (TREE_SUB_ARCTIC << 2); |
0 | 468 |
} |
469 |
||
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
470 |
assert(index < lengthof(_tree_layout_sprite)); |
0 | 471 |
|
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
472 |
const PalSpriteID *s = _tree_layout_sprite[index]; |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
473 |
const TreePos *d = _tree_layout_xy[GB(tmp, 4, 2)]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
474 |
|
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
475 |
/* combine trees into one sprite object */ |
0 | 476 |
StartSpriteCombine(); |
477 |
||
8498
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
478 |
TreeListEnt te[4]; |
0 | 479 |
|
8498
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
480 |
/* put the trees to draw in a list */ |
10363
96eb6897bf96
(svn r14614) -Codechange [FS#2423]: GetTreeCount() should behave as its name and documentation imply. Remove unused SetTreeCount() (PhilSophus)
smatz
parents:
10236
diff
changeset
|
481 |
uint trees = GetTreeCount(ti->tile); |
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
482 |
|
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
483 |
for (uint i = 0; i < trees; i++) { |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
484 |
SpriteID image = s[0].sprite + (i == trees - 1 ? GetTreeGrowth(ti->tile) : 3); |
8498
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
485 |
SpriteID pal = s[0].pal; |
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
486 |
|
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
487 |
te[i].image = image; |
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
488 |
te[i].pal = pal; |
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
489 |
te[i].x = d->x; |
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
490 |
te[i].y = d->y; |
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
491 |
s++; |
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
492 |
d++; |
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
493 |
} |
8498
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
494 |
|
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
495 |
/* draw them in a sorted way */ |
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
496 |
byte z = ti->z + GetSlopeMaxZ(ti->tileh) / 2; |
8498
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
497 |
|
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
498 |
for (; trees > 0; trees--) { |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
499 |
uint min = te[0].x + te[0].y; |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
500 |
uint mi = 0; |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
501 |
|
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
502 |
for (uint i = 1; i < trees; i++) { |
8512 | 503 |
if ((uint)(te[i].x + te[i].y) < min) { |
8498
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
504 |
min = te[i].x + te[i].y; |
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
505 |
mi = i; |
8498
b3dc2f7cf759
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8459
diff
changeset
|
506 |
} |
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
507 |
} |
0 | 508 |
|
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
509 |
AddSortableSpriteToDraw(te[mi].image, te[mi].pal, ti->x + te[mi].x, ti->y + te[mi].y, 16 - te[mi].x, 16 - te[mi].y, 0x30, z, IsTransparencySet(TO_TREES), -te[mi].x, -te[mi].y); |
0 | 510 |
|
8499
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
511 |
/* replace the removed one with the last one */ |
f1b8d734495b
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8498
diff
changeset
|
512 |
te[mi] = te[trees - 1]; |
0 | 513 |
} |
514 |
||
515 |
EndSpriteCombine(); |
|
516 |
} |
|
517 |
||
518 |
||
4231
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
519 |
static uint GetSlopeZ_Trees(TileIndex tile, uint x, uint y) |
2537 | 520 |
{ |
4231
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
521 |
uint z; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
522 |
Slope tileh = GetTileSlope(tile, &z); |
4231
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
523 |
|
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
524 |
return z + GetPartialZ(x & 0xF, y & 0xF, tileh); |
0 | 525 |
} |
526 |
||
7335
141c6b86ec1f
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7333
diff
changeset
|
527 |
static Foundation GetFoundation_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
|
528 |
{ |
7335
141c6b86ec1f
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7333
diff
changeset
|
529 |
return FOUNDATION_NONE; |
39 | 530 |
} |
531 |
||
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6683
diff
changeset
|
532 |
static CommandCost ClearTile_Trees(TileIndex tile, byte flags) |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
533 |
{ |
2243 | 534 |
uint num; |
0 | 535 |
|
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9659
diff
changeset
|
536 |
if (IsValidCompanyID(_current_company)) { |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
537 |
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority); |
8232
a4883a0598db
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8230
diff
changeset
|
538 |
if (t != NULL) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM); |
0 | 539 |
} |
540 |
||
10363
96eb6897bf96
(svn r14614) -Codechange [FS#2423]: GetTreeCount() should behave as its name and documentation imply. Remove unused SetTreeCount() (PhilSophus)
smatz
parents:
10236
diff
changeset
|
541 |
num = GetTreeCount(tile); |
7954
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7923
diff
changeset
|
542 |
if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4; |
0 | 543 |
|
2243 | 544 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 545 |
|
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8225
diff
changeset
|
546 |
return CommandCost(EXPENSES_CONSTRUCTION, num * _price.remove_trees); |
0 | 547 |
} |
548 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
549 |
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac) |
0 | 550 |
{ |
551 |
/* not used */ |
|
552 |
} |
|
553 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
554 |
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td) |
0 | 555 |
{ |
2981 | 556 |
TreeType tt = GetTreeType(tile); |
557 |
||
7954
57b51c69c072
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
7923
diff
changeset
|
558 |
if (IsInsideMM(tt, TREE_RAINFOREST, TREE_CACTUS)) { |
2981 | 559 |
td->str = STR_280F_RAINFOREST; |
560 |
} else { |
|
7712
ceffd344c7a7
(svn r11246) -Codechange: beautify some conditions from "if else" into trinary operator
belugas
parents:
7710
diff
changeset
|
561 |
td->str = tt == TREE_CACTUS ? STR_2810_CACTUS_PLANTS : STR_280E_TREES; |
2981 | 562 |
} |
0 | 563 |
|
9322
cf7dc39f9576
(svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents:
9126
diff
changeset
|
564 |
td->owner[0] = GetTileOwner(tile); |
0 | 565 |
} |
566 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
567 |
static void AnimateTile_Trees(TileIndex tile) |
0 | 568 |
{ |
569 |
/* not used */ |
|
570 |
} |
|
571 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
572 |
static void TileLoopTreesDesert(TileIndex tile) |
0 | 573 |
{ |
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
|
574 |
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
|
575 |
case TROPICZONE_DESERT: |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
576 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) { |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
577 |
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3); |
2981 | 578 |
MarkTileDirtyByTile(tile); |
579 |
} |
|
580 |
break; |
|
2243 | 581 |
|
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
|
582 |
case TROPICZONE_RAINFOREST: { |
2981 | 583 |
static const SoundFx forest_sounds[] = { |
584 |
SND_42_LOON_BIRD, |
|
585 |
SND_43_LION, |
|
586 |
SND_44_MONKEYS, |
|
587 |
SND_48_DISTANT_BIRD |
|
588 |
}; |
|
589 |
uint32 r = Random(); |
|
0 | 590 |
|
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7954
diff
changeset
|
591 |
if (Chance16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile); |
2981 | 592 |
break; |
0 | 593 |
} |
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
|
594 |
|
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
|
595 |
default: break; |
0 | 596 |
} |
597 |
} |
|
598 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
599 |
static void TileLoopTreesAlps(TileIndex tile) |
0 | 600 |
{ |
6343
76d17f784c13
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6248
diff
changeset
|
601 |
int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT; |
0 | 602 |
|
4157
8d0051fdde68
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
3977
diff
changeset
|
603 |
if (k < 0) { |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
604 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) return; |
7710
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
605 |
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 3); |
0 | 606 |
} else { |
4157
8d0051fdde68
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
3977
diff
changeset
|
607 |
uint density = min((uint)k / TILE_HEIGHT, 3); |
2981 | 608 |
|
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
609 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT || |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
610 |
GetTreeDensity(tile) != density) { |
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
611 |
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, density); |
2981 | 612 |
} else { |
613 |
if (GetTreeDensity(tile) == 3) { |
|
614 |
uint32 r = Random(); |
|
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7954
diff
changeset
|
615 |
if (Chance16I(1, 200, r)) { |
2981 | 616 |
SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile); |
617 |
} |
|
0 | 618 |
} |
619 |
return; |
|
620 |
} |
|
621 |
} |
|
622 |
MarkTileDirtyByTile(tile); |
|
623 |
} |
|
624 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
625 |
static void TileLoop_Trees(TileIndex tile) |
0 | 626 |
{ |
8459 | 627 |
if (GetTreeGround(tile) == TREE_GROUND_SHORE) { |
628 |
TileLoop_Water(tile); |
|
629 |
} else { |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
630 |
switch (_settings_game.game_creation.landscape) { |
8459 | 631 |
case LT_TROPIC: TileLoopTreesDesert(tile); break; |
632 |
case LT_ARCTIC: TileLoopTreesAlps(tile); break; |
|
633 |
} |
|
0 | 634 |
} |
635 |
||
636 |
TileLoopClearHelper(tile); |
|
637 |
||
7710
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
638 |
uint treeCounter = GetTreeCounter(tile); |
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
639 |
|
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
640 |
/* Handle growth of grass at every 8th processings, like it's done for grass */ |
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
641 |
if ((treeCounter & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) { |
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
642 |
uint density = GetTreeDensity(tile); |
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
643 |
if (density < 3) { |
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
644 |
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, density + 1); |
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
645 |
MarkTileDirtyByTile(tile); |
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
646 |
} |
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
647 |
} |
2981 | 648 |
if (GetTreeCounter(tile) < 15) { |
649 |
AddTreeCounter(tile, 1); |
|
650 |
return; |
|
651 |
} |
|
652 |
SetTreeCounter(tile, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
653 |
|
2981 | 654 |
switch (GetTreeGrowth(tile)) { |
655 |
case 3: /* regular sized tree */ |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
656 |
if (_settings_game.game_creation.landscape == LT_TROPIC && |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
657 |
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
|
658 |
GetTropicZone(tile) == TROPICZONE_DESERT) { |
2981 | 659 |
AddTreeGrowth(tile, 1); |
660 |
} else { |
|
661 |
switch (GB(Random(), 0, 3)) { |
|
662 |
case 0: /* start destructing */ |
|
663 |
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
|
664 |
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
|
665 |
|
2981 | 666 |
case 1: /* add a tree */ |
10363
96eb6897bf96
(svn r14614) -Codechange [FS#2423]: GetTreeCount() should behave as its name and documentation imply. Remove unused SetTreeCount() (PhilSophus)
smatz
parents:
10236
diff
changeset
|
667 |
if (GetTreeCount(tile) < 4) { |
2981 | 668 |
AddTreeCount(tile, 1); |
669 |
SetTreeGrowth(tile, 0); |
|
670 |
break; |
|
671 |
} |
|
672 |
/* FALL THROUGH */ |
|
0 | 673 |
|
2981 | 674 |
case 2: { /* add a neighbouring tree */ |
675 |
TreeType treetype = GetTreeType(tile); |
|
0 | 676 |
|
7317
e61af9d8a2b3
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
6950
diff
changeset
|
677 |
tile += TileOffsByDir((Direction)(Random() & 7)); |
0 | 678 |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
679 |
/* Cacti don't spread */ |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
680 |
if (!CanPlantTreesOnTile(tile, false)) return; |
2981 | 681 |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
682 |
/* Don't plant trees, if ground was freshly cleared */ |
8459 | 683 |
if (IsTileType(tile, MP_CLEAR) && GetClearGround(tile) == CLEAR_GRASS && GetClearDensity(tile) != 3) return; |
2981 | 684 |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
685 |
PlantTreesOnTile(tile, treetype, 0, 0); |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
686 |
|
2981 | 687 |
break; |
688 |
} |
|
689 |
||
690 |
default: |
|
691 |
return; |
|
692 |
} |
|
0 | 693 |
} |
2981 | 694 |
break; |
695 |
||
696 |
case 6: /* final stage of tree destruction */ |
|
10363
96eb6897bf96
(svn r14614) -Codechange [FS#2423]: GetTreeCount() should behave as its name and documentation imply. Remove unused SetTreeCount() (PhilSophus)
smatz
parents:
10236
diff
changeset
|
697 |
if (GetTreeCount(tile) > 1) { |
2981 | 698 |
/* more than one tree, delete it */ |
699 |
AddTreeCount(tile, -1); |
|
700 |
SetTreeGrowth(tile, 3); |
|
701 |
} else { |
|
702 |
/* just one tree, change type into MP_CLEAR */ |
|
703 |
switch (GetTreeGround(tile)) { |
|
8459 | 704 |
case TREE_GROUND_SHORE: MakeShore(tile); break; |
7710
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
705 |
case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, GetTreeDensity(tile)); break; |
3447 | 706 |
case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break; |
7710
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
707 |
default: // snow or desert |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
708 |
MakeClear(tile, _settings_game.game_creation.landscape == LT_TROPIC ? CLEAR_DESERT : CLEAR_SNOW, GetTreeDensity(tile)); |
7710
777524fbb1fb
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
7601
diff
changeset
|
709 |
break; |
2981 | 710 |
} |
0 | 711 |
} |
2981 | 712 |
break; |
713 |
||
714 |
default: |
|
715 |
AddTreeGrowth(tile, 1); |
|
716 |
break; |
|
0 | 717 |
} |
718 |
||
719 |
MarkTileDirtyByTile(tile); |
|
720 |
} |
|
721 |
||
6247 | 722 |
void OnTick_Trees() |
0 | 723 |
{ |
724 |
uint32 r; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
725 |
TileIndex tile; |
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
|
726 |
TreeType tree; |
0 | 727 |
|
728 |
/* place a tree at a random rainforest spot */ |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
729 |
if (_settings_game.game_creation.landscape == LT_TROPIC && |
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
|
730 |
(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) && |
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
731 |
CanPlantTreesOnTile(tile, false) && |
3441
fead68bcb6a3
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
732 |
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) { |
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
733 |
PlantTreesOnTile(tile, tree, 0, 0); |
0 | 734 |
} |
735 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
736 |
/* byte underflow */ |
2088
d7a97ef74701
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
737 |
if (--_trees_tick_ctr != 0) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
738 |
|
0 | 739 |
/* place a tree at a random spot */ |
740 |
r = Random(); |
|
741 |
tile = TILE_MASK(r); |
|
8454
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
742 |
if (CanPlantTreesOnTile(tile, false) && (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) { |
8d9d0731716c
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8452
diff
changeset
|
743 |
PlantTreesOnTile(tile, tree, 0, 0); |
0 | 744 |
} |
745 |
} |
|
746 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
747 |
static void ClickTile_Trees(TileIndex tile) |
0 | 748 |
{ |
749 |
/* not used */ |
|
750 |
} |
|
751 |
||
8616
fd862a55c47f
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
8596
diff
changeset
|
752 |
static TrackStatus GetTileTrackStatus_Trees(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) |
0 | 753 |
{ |
754 |
return 0; |
|
755 |
} |
|
756 |
||
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9659
diff
changeset
|
757 |
static void ChangeTileOwner_Trees(TileIndex tile, Owner old_owner, Owner new_owner) |
0 | 758 |
{ |
759 |
/* not used */ |
|
760 |
} |
|
761 |
||
6247 | 762 |
void InitializeTrees() |
0 | 763 |
{ |
764 |
_trees_tick_ctr = 0; |
|
765 |
} |
|
766 |
||
7494
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7335
diff
changeset
|
767 |
static CommandCost TerraformTile_Trees(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new) |
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7335
diff
changeset
|
768 |
{ |
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7335
diff
changeset
|
769 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7335
diff
changeset
|
770 |
} |
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7335
diff
changeset
|
771 |
|
0 | 772 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
773 |
extern const TileTypeProcs _tile_type_trees_procs = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
774 |
DrawTile_Trees, /* draw_tile_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
775 |
GetSlopeZ_Trees, /* get_slope_z_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
776 |
ClearTile_Trees, /* clear_tile_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
777 |
GetAcceptedCargo_Trees, /* get_accepted_cargo_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
778 |
GetTileDesc_Trees, /* get_tile_desc_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
779 |
GetTileTrackStatus_Trees, /* get_tile_track_status_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
780 |
ClickTile_Trees, /* click_tile_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
781 |
AnimateTile_Trees, /* animate_tile_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
782 |
TileLoop_Trees, /* tile_loop_clear */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
783 |
ChangeTileOwner_Trees, /* change_tile_owner_clear */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
784 |
NULL, /* get_produced_cargo_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4300
diff
changeset
|
785 |
NULL, /* vehicle_enter_tile_proc */ |
7335
141c6b86ec1f
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7333
diff
changeset
|
786 |
GetFoundation_Trees, /* get_foundation_proc */ |
7494
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7335
diff
changeset
|
787 |
TerraformTile_Trees, /* terraform_tile_proc */ |
0 | 788 |
}; |