author | Tero Marttila <terom@fixme.fi> |
Fri, 18 Jul 2008 21:28:42 +0300 | |
changeset 11175 | 020c61e39c94 |
parent 11161 | 7d0fac8f14cd |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10429
1b99254f9607
(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:
9302
diff
changeset
|
3 |
/** @file tree_cmd.cpp Handling of tree tiles. */ |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1784
diff
changeset
|
6 |
#include "openttd.h" |
5573
afa6f92a71fd
(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
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3079
diff
changeset
|
8 |
#include "clear_map.h" |
8615
6b91ca653bad
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8612
diff
changeset
|
9 |
#include "tile_cmd.h" |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6574
diff
changeset
|
10 |
#include "landscape.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3079
diff
changeset
|
11 |
#include "tree_map.h" |
8721
b7971ad9bdd9
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8683
diff
changeset
|
12 |
#include "viewport_func.h" |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8604
diff
changeset
|
13 |
#include "command_func.h" |
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8604
diff
changeset
|
14 |
#include "economy_func.h" |
0 | 15 |
#include "town.h" |
2153
91e89aa8c299
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
16 |
#include "variables.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
17 |
#include "genworld.h" |
8345
6caa3fdb972c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
8208
diff
changeset
|
18 |
#include "transparency.h" |
8627
448ebf3a8291
(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:
8615
diff
changeset
|
19 |
#include "functions.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8728
diff
changeset
|
20 |
#include "player_func.h" |
8653
a83f7a536919
(svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents:
8635
diff
changeset
|
21 |
#include "sound_func.h" |
8766
c86cfa3a7580
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8760
diff
changeset
|
22 |
#include "settings_type.h" |
8955 | 23 |
#include "water_map.h" |
24 |
#include "water.h" |
|
10444
3876060cdef7
(svn r12986) -Codechange: move the landscape and transport related types from openttd.h to their own headers.
rubidium
parents:
10429
diff
changeset
|
25 |
#include "landscape_type.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
26 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
27 |
#include "table/strings.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
28 |
#include "table/sprites.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
29 |
#include "table/tree_land.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
30 |
|
8093
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
31 |
/** |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
32 |
* List of tree placer algorithm. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
33 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
34 |
* This enumeration defines all possible tree placer algorithm in the game. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
35 |
*/ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
36 |
enum TreePlacer { |
8093
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
37 |
TP_NONE, ///< No tree placer algorithm |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
38 |
TP_ORIGINAL, ///< The original algorithm |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
39 |
TP_IMPROVED, ///< A 'improved' algorithm |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
40 |
}; |
0 | 41 |
|
8093
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
42 |
/** |
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
43 |
* Tests if a tile can be converted to MP_TREES |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
44 |
* This is true for clear ground without farms or rocks. |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
45 |
* |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
46 |
* @param tile the tile of interest |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
47 |
* @param allow_desert Allow planting trees on CLEAR_DESERT? |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
48 |
* @return true if trees can be built. |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
49 |
*/ |
8955 | 50 |
static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert) |
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
51 |
{ |
8955 | 52 |
switch (GetTileType(tile)) { |
53 |
case MP_WATER: |
|
54 |
return !IsBridgeAbove(tile) && IsCoast(tile) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL)); |
|
55 |
||
56 |
case MP_CLEAR: |
|
57 |
return !IsBridgeAbove(tile) && !IsClearGround(tile, CLEAR_FIELDS) && !IsClearGround(tile, CLEAR_ROCKS) && |
|
58 |
(allow_desert || !IsClearGround(tile, CLEAR_DESERT)); |
|
59 |
||
60 |
default: return false; |
|
61 |
} |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
62 |
} |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
63 |
|
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
64 |
/** |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
65 |
* Creates a tree tile |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
66 |
* Ground type and density is preserved. |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
67 |
* |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
68 |
* @pre the tile must be suitable for trees. |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
69 |
* |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
70 |
* @param tile where to plant the trees. |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
71 |
* @param type The type of the tree |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
72 |
* @param count the number of trees (minus 1) |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
73 |
* @param growth the growth status |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
74 |
*/ |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
75 |
static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, uint growth) |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
76 |
{ |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
77 |
assert(treetype != TREE_INVALID); |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
78 |
assert(CanPlantTreesOnTile(tile, true)); |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
79 |
|
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
80 |
TreeGround ground; |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
81 |
uint density = 3; |
8955 | 82 |
|
83 |
switch (GetTileType(tile)) { |
|
84 |
case MP_WATER: |
|
85 |
ground = TREE_GROUND_SHORE; |
|
86 |
break; |
|
87 |
||
88 |
case MP_CLEAR: |
|
89 |
switch (GetClearGround(tile)) { |
|
90 |
case CLEAR_GRASS: ground = TREE_GROUND_GRASS; density = GetClearDensity(tile); break; |
|
91 |
case CLEAR_ROUGH: ground = TREE_GROUND_ROUGH; break; |
|
92 |
default: ground = TREE_GROUND_SNOW_DESERT; density = GetClearDensity(tile); break; |
|
93 |
} |
|
94 |
break; |
|
95 |
||
96 |
default: NOT_REACHED(); |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
97 |
} |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
98 |
|
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
99 |
MakeTree(tile, treetype, count, growth, ground, density); |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
100 |
} |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
101 |
|
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
102 |
/** |
8093
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
103 |
* Get a random TreeType for the given tile based on a given seed |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
104 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
105 |
* This function returns a random TreeType which can be placed on the given tile. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
106 |
* The seed for randomness must be less or equal 256, use #GB on the value of Random() |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
107 |
* to get such a value. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
108 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
109 |
* @param tile The tile to get a random TreeType from |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
110 |
* @param seed The seed for randomness, must be less or equal 256 |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
111 |
* @return The random tree type |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
112 |
*/ |
2981 | 113 |
static TreeType GetRandomTreeType(TileIndex tile, uint seed) |
0 | 114 |
{ |
10775
7061477bfbcf
(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:
10707
diff
changeset
|
115 |
switch (_settings_game.game_creation.landscape) { |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
116 |
case LT_TEMPERATE: |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
117 |
return (TreeType)(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE); |
0 | 118 |
|
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
119 |
case LT_ARCTIC: |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
120 |
return (TreeType)(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
121 |
|
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
122 |
case LT_TROPIC: |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
123 |
switch (GetTropicZone(tile)) { |
8946
85eff1ad8cda
(svn r12020) -Documentation: Correct description of TropicZone.
frosch
parents:
8944
diff
changeset
|
124 |
case TROPICZONE_NORMAL: return (TreeType)(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
125 |
case TROPICZONE_DESERT: return (TreeType)((seed > 12) ? TREE_INVALID : TREE_CACTUS); |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
126 |
default: return (TreeType)(seed * TREE_COUNT_RAINFOREST / 256 + TREE_RAINFOREST); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
127 |
} |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
128 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
129 |
default: |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
130 |
return (TreeType)(seed * TREE_COUNT_TOYLAND / 256 + TREE_TOYLAND); |
0 | 131 |
} |
132 |
} |
|
133 |
||
8093
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
134 |
/** |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
135 |
* Make a random tree tile of the given tile |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
136 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
137 |
* Create a new tree-tile for the given tile. The second parameter is used for |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
138 |
* randomness like type and number of trees. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
139 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
140 |
* @param tile The tile to make a tree-tile from |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
141 |
* @param r The randomness value from a Random() value |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
142 |
*/ |
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
143 |
static void PlaceTree(TileIndex tile, uint32 r) |
0 | 144 |
{ |
2981 | 145 |
TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8)); |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
146 |
|
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
147 |
if (tree != TREE_INVALID) { |
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
148 |
PlantTreesOnTile(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6)); |
0 | 149 |
|
8955 | 150 |
/* Rerandomize ground, if neither snow nor shore */ |
151 |
TreeGround ground = GetTreeGround(tile); |
|
152 |
if (ground != TREE_GROUND_SNOW_DESERT && ground != TREE_GROUND_SHORE) { |
|
8206
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
153 |
SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3); |
0 | 154 |
} |
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
155 |
|
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
156 |
/* Set the counter to a random start value */ |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
157 |
SetTreeCounter(tile, (TreeGround)GB(r, 24, 4)); |
0 | 158 |
} |
159 |
} |
|
160 |
||
8093
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
161 |
/** |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
162 |
* Place some amount of trees around a given tile. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
163 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
164 |
* This function adds some trees around a given tile. As this function use |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
165 |
* the Random() call it depends on the random how many trees are actually placed |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
166 |
* around the given tile. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
167 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
168 |
* @param tile The center of the trees to add |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
169 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
170 |
static void DoPlaceMoreTrees(TileIndex tile) |
0 | 171 |
{ |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
172 |
uint i; |
0 | 173 |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
174 |
for (i = 0; i < 1000; i++) { |
0 | 175 |
uint32 r = Random(); |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
176 |
int x = GB(r, 0, 5) - 16; |
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
177 |
int y = GB(r, 8, 5) - 16; |
8419
de9999f762d0
(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents:
8372
diff
changeset
|
178 |
uint dist = abs(x) + abs(y); |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
179 |
TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y)); |
0 | 180 |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
181 |
if (dist <= 13 && CanPlantTreesOnTile(cur_tile, true)) { |
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
182 |
PlaceTree(cur_tile, r); |
0 | 183 |
} |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
184 |
} |
0 | 185 |
} |
186 |
||
8093
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
187 |
/** |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
188 |
* Place more trees on the map. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
189 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
190 |
* This function add more trees to the map. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
191 |
*/ |
6573 | 192 |
static void PlaceMoreTrees() |
0 | 193 |
{ |
2243 | 194 |
uint i = ScaleByMapSize(GB(Random(), 0, 5) + 25); |
0 | 195 |
do { |
2051 | 196 |
DoPlaceMoreTrees(RandomTile()); |
0 | 197 |
} while (--i); |
198 |
} |
|
199 |
||
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
200 |
/** |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
201 |
* Place a tree at the same height as an existing tree. |
8093
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
202 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
203 |
* Add a new tree around the given tile which is at the same |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
204 |
* height or at some offset (2 units) of it. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
205 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
206 |
* @param tile The base tile to add a new tree somewhere around |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
207 |
* @param height The height (like the one from the tile) |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
208 |
*/ |
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
209 |
static void PlaceTreeAtSameHeight(TileIndex tile, uint height) |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
210 |
{ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
211 |
uint i; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
212 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
213 |
for (i = 0; i < 1000; i++) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
214 |
uint32 r = Random(); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
215 |
int x = GB(r, 0, 5) - 16; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
216 |
int y = GB(r, 8, 5) - 16; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
217 |
TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y)); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
218 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
219 |
/* Keep in range of the existing tree */ |
8419
de9999f762d0
(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents:
8372
diff
changeset
|
220 |
if (abs(x) + abs(y) > 16) continue; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
221 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
222 |
/* Clear tile, no farm-tiles or rocks */ |
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
223 |
if (!CanPlantTreesOnTile(cur_tile, true)) continue; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
224 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
225 |
/* Not too much height difference */ |
8466
9ce95e16f9f9
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
8463
diff
changeset
|
226 |
if (Delta(GetTileZ(cur_tile), height) > 2) continue; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
227 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
228 |
/* Place one tree and quit */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
229 |
PlaceTree(cur_tile, r); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
230 |
break; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
231 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
232 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
233 |
|
8093
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
234 |
/** |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
235 |
* Place some trees randomly |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
236 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
237 |
* This function just place some trees randomly on the map. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
238 |
*/ |
6573 | 239 |
void PlaceTreesRandomly() |
0 | 240 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
241 |
uint i, j, ht; |
0 | 242 |
|
1202
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
243 |
i = ScaleByMapSize(1000); |
0 | 244 |
do { |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
245 |
uint32 r = Random(); |
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
246 |
TileIndex tile = RandomTileSeed(r); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
247 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
248 |
IncreaseGeneratingWorldProgress(GWP_TREE); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
249 |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
250 |
if (CanPlantTreesOnTile(tile, true)) { |
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
251 |
PlaceTree(tile, r); |
10775
7061477bfbcf
(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:
10707
diff
changeset
|
252 |
if (_settings_game.game_creation.tree_placer != TP_IMPROVED) continue; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
253 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
254 |
/* Place a number of trees based on the tile height. |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
255 |
* This gives a cool effect of multiple trees close together. |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
256 |
* It is almost real life ;) */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
257 |
ht = GetTileZ(tile); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
258 |
/* The higher we get, the more trees we plant */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
259 |
j = GetTileZ(tile) / TILE_HEIGHT * 2; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
260 |
while (j--) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
261 |
/* Above snowline more trees! */ |
10775
7061477bfbcf
(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:
10707
diff
changeset
|
262 |
if (_settings_game.game_creation.landscape == LT_ARCTIC && ht > GetSnowLine()) { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
263 |
PlaceTreeAtSameHeight(tile, ht); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
264 |
PlaceTreeAtSameHeight(tile, ht); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
265 |
}; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
266 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
267 |
PlaceTreeAtSameHeight(tile, ht); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
268 |
} |
0 | 269 |
} |
270 |
} while (--i); |
|
271 |
||
272 |
/* place extra trees at rainforest area */ |
|
10775
7061477bfbcf
(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:
10707
diff
changeset
|
273 |
if (_settings_game.game_creation.landscape == LT_TROPIC) { |
1202
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1093
diff
changeset
|
274 |
i = ScaleByMapSize(15000); |
0 | 275 |
|
276 |
do { |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
277 |
uint32 r = Random(); |
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
278 |
TileIndex tile = RandomTileSeed(r); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
279 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
280 |
IncreaseGeneratingWorldProgress(GWP_TREE); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
281 |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
282 |
if (GetTropicZone(tile) == TROPICZONE_RAINFOREST && CanPlantTreesOnTile(tile, false)) { |
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2957
diff
changeset
|
283 |
PlaceTree(tile, r); |
0 | 284 |
} |
285 |
} while (--i); |
|
286 |
} |
|
287 |
} |
|
288 |
||
8093
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
289 |
/** |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
290 |
* Place new trees. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
291 |
* |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
292 |
* This function takes care of the selected tree placer algorithm and |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
293 |
* place randomly the trees for a new game. |
6f0fa5c9dacc
(svn r11124) -Documentation: of tree_map.h and tree_cmd.cpp. Patch by Progman.
rubidium
parents:
8005
diff
changeset
|
294 |
*/ |
6573 | 295 |
void GenerateTrees() |
0 | 296 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
297 |
uint i, total; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
298 |
|
10775
7061477bfbcf
(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:
10707
diff
changeset
|
299 |
if (_settings_game.game_creation.tree_placer == TP_NONE) return; |
0 | 300 |
|
10775
7061477bfbcf
(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:
10707
diff
changeset
|
301 |
if (_settings_game.game_creation.landscape != LT_TOYLAND) PlaceMoreTrees(); |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
302 |
|
10775
7061477bfbcf
(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:
10707
diff
changeset
|
303 |
switch (_settings_game.game_creation.tree_placer) { |
7061477bfbcf
(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:
10707
diff
changeset
|
304 |
case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 15 : 6; break; |
7061477bfbcf
(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:
10707
diff
changeset
|
305 |
case TP_IMPROVED: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 4 : 2; break; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
306 |
default: NOT_REACHED(); return; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
307 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
308 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
309 |
total = ScaleByMapSize(1000); |
10775
7061477bfbcf
(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:
10707
diff
changeset
|
310 |
if (_settings_game.game_creation.landscape == LT_TROPIC) total += ScaleByMapSize(15000); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
311 |
total *= i; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
312 |
SetGeneratingWorldProgress(GWP_TREE, total); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
313 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4231
diff
changeset
|
314 |
for (; i != 0; i--) { |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
315 |
PlaceTreesRandomly(); |
0 | 316 |
} |
317 |
} |
|
318 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
319 |
/** Plant a tree. |
3491
4c8427796c64
(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
|
320 |
* @param tile start tile of area-drag of tree plantation |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
321 |
* @param flags type of operation |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
322 |
* @param p1 tree type, -1 means random. |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
323 |
* @param p2 end tile of area-drag |
0 | 324 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7179
diff
changeset
|
325 |
CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 326 |
{ |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
327 |
StringID msg = INVALID_STRING_ID; |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8721
diff
changeset
|
328 |
CommandCost cost(EXPENSES_OTHER); |
3491
4c8427796c64
(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
|
329 |
int ex; |
4c8427796c64
(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 ey; |
2118
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
331 |
int sx, sy, x, y; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
332 |
|
2892
390125af7685
(svn r3446) - Fix: incorrect validating of tree-planting command which can allow a buffer-overflow (Tron)
Darkvater
parents:
2654
diff
changeset
|
333 |
if (p2 >= MapSize()) return CMD_ERROR; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1370
diff
changeset
|
334 |
/* Check the tree type. It can be random or some valid value within the current climate */ |
10775
7061477bfbcf
(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:
10707
diff
changeset
|
335 |
if (p1 != (uint)-1 && 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
|
336 |
|
0 | 337 |
// make sure sx,sy are smaller than ex,ey |
3491
4c8427796c64
(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
|
338 |
ex = TileX(tile); |
4c8427796c64
(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 |
ey = TileY(tile); |
2118
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
340 |
sx = TileX(p2); |
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
341 |
sy = TileY(p2); |
6432 | 342 |
if (ex < sx) Swap(ex, sx); |
343 |
if (ey < sy) Swap(ey, sy); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
344 |
|
2118
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
345 |
for (x = sx; x <= ex; x++) { |
c73d32cc0b5e
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
Darkvater
parents:
2088
diff
changeset
|
346 |
for (y = sy; y <= ey; y++) { |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
347 |
TileIndex tile = TileXY(x, y); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
348 |
|
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
349 |
switch (GetTileType(tile)) { |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
350 |
case MP_TREES: |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
351 |
/* no more space for trees? */ |
3003 | 352 |
if (_game_mode != GM_EDITOR && GetTreeCount(tile) == 3) { |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
353 |
msg = STR_2803_TREE_ALREADY_HERE; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
354 |
continue; |
0 | 355 |
} |
356 |
||
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
357 |
if (flags & DC_EXEC) { |
2981 | 358 |
AddTreeCount(tile, 1); |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
359 |
MarkTileDirtyByTile(tile); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
360 |
} |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
361 |
/* 2x as expensive to add more trees to an existing tile */ |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
362 |
cost.AddCost(_price.build_trees * 2); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
363 |
break; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
364 |
|
8005
9f7a95e84682
(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:
7990
diff
changeset
|
365 |
case MP_WATER: |
8955 | 366 |
if (!IsCoast(tile) || IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL))) { |
367 |
msg = STR_3807_CAN_T_BUILD_ON_WATER; |
|
368 |
continue; |
|
369 |
} |
|
370 |
/* FALL THROUGH */ |
|
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
371 |
case MP_CLEAR: |
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
372 |
if (IsBridgeAbove(tile)) { |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
373 |
msg = STR_2804_SITE_UNSUITABLE; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
374 |
continue; |
0 | 375 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
376 |
|
8955 | 377 |
if (IsTileType(tile, MP_CLEAR)) { |
378 |
/* Remove fields or rocks. Note that the ground will get barrened */ |
|
379 |
switch (GetClearGround(tile)) { |
|
380 |
case CLEAR_FIELDS: |
|
381 |
case CLEAR_ROCKS: { |
|
382 |
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
383 |
if (CmdFailed(ret)) return ret; |
|
384 |
cost.AddCost(ret); |
|
385 |
break; |
|
386 |
} |
|
387 |
||
388 |
default: break; |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
389 |
} |
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
390 |
} |
0 | 391 |
|
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
10775
diff
changeset
|
392 |
if (_game_mode != GM_EDITOR && IsValidPlayerID(_current_player)) { |
10775
7061477bfbcf
(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:
10707
diff
changeset
|
393 |
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority); |
8728
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
394 |
if (t != NULL) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM); |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
395 |
} |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
396 |
|
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
397 |
if (flags & DC_EXEC) { |
2981 | 398 |
TreeType treetype; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
399 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
400 |
treetype = (TreeType)p1; |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
401 |
if (treetype == TREE_INVALID) { |
2981 | 402 |
treetype = GetRandomTreeType(tile, GB(Random(), 24, 8)); |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
403 |
if (treetype == TREE_INVALID) treetype = TREE_CACTUS; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
404 |
} |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
405 |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
406 |
/* Plant full grown trees in scenario editor */ |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
407 |
PlantTreesOnTile(tile, treetype, 0, _game_mode == GM_EDITOR ? 3 : 0); |
3003 | 408 |
MarkTileDirtyByTile(tile); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
409 |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
410 |
/* When planting rainforest-trees, set tropiczone to rainforest in editor. */ |
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8419
diff
changeset
|
411 |
if (_game_mode == GM_EDITOR && IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS)) |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
412 |
SetTropicZone(tile, TROPICZONE_RAINFOREST); |
0 | 413 |
} |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
414 |
cost.AddCost(_price.build_trees); |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
415 |
break; |
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
416 |
|
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
417 |
default: |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
418 |
msg = STR_2804_SITE_UNSUITABLE; |
1286
da05e4dc75b5
(svn r1790) Make CmdPlantTree() and related functions more safe and (hopefully) more readable:
tron
parents:
1209
diff
changeset
|
419 |
break; |
0 | 420 |
} |
421 |
} |
|
422 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
423 |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
424 |
if (cost.GetCost() == 0) { |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
425 |
return_cmd_error(msg); |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
426 |
} else { |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
427 |
return cost; |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3144
diff
changeset
|
428 |
} |
0 | 429 |
} |
430 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
431 |
struct TreeListEnt { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
432 |
SpriteID image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
433 |
SpriteID pal; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6923
diff
changeset
|
434 |
byte x, y; |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
435 |
}; |
0 | 436 |
|
437 |
static void DrawTile_Trees(TileInfo *ti) |
|
438 |
{ |
|
2981 | 439 |
switch (GetTreeGround(ti->tile)) { |
8955 | 440 |
case TREE_GROUND_SHORE: DrawShoreTile(ti->tileh); break; |
8206
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
441 |
case TREE_GROUND_GRASS: DrawClearLandTile(ti, GetTreeDensity(ti->tile)); break; |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
442 |
case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
443 |
default: DrawGroundSprite(_tree_sprites_1[GetTreeDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE); break; |
0 | 444 |
} |
445 |
||
2220 | 446 |
DrawClearLandFence(ti); |
0 | 447 |
|
8994
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
448 |
/* Do not draw trees when the invisible trees patch and transparency tree are set */ |
9302
4aa3c4a44b16
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
9112
diff
changeset
|
449 |
if (IsInvisibilitySet(TO_TREES)) return; |
8994
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
450 |
|
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
451 |
uint16 tmp = ti->x; |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
452 |
|
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
453 |
tmp = ROR(tmp, 2); |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
454 |
tmp -= ti->y; |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
455 |
tmp = ROR(tmp, 3); |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
456 |
tmp -= ti->x; |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
457 |
tmp = ROR(tmp, 1); |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
458 |
tmp += ti->y; |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
459 |
|
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
460 |
uint index = GB(tmp, 6, 2) + (GetTreeType(ti->tile) << 2); |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
461 |
|
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
462 |
/* different tree styles above one of the grounds */ |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
463 |
if (GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT && |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
464 |
GetTreeDensity(ti->tile) >= 2 && |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
465 |
IsInsideMM(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) { |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
466 |
index += 164 - (TREE_SUB_ARCTIC << 2); |
0 | 467 |
} |
468 |
||
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
469 |
assert(index < lengthof(_tree_layout_sprite)); |
0 | 470 |
|
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
471 |
const PalSpriteID *s = _tree_layout_sprite[index]; |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
472 |
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
|
473 |
|
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
474 |
/* combine trees into one sprite object */ |
0 | 475 |
StartSpriteCombine(); |
476 |
||
8994
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
477 |
TreeListEnt te[4]; |
0 | 478 |
|
8994
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
479 |
/* put the trees to draw in a list */ |
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
480 |
uint trees = GetTreeCount(ti->tile) + 1; |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
481 |
|
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
482 |
for (uint i = 0; i < trees; i++) { |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
483 |
SpriteID image = s[0].sprite + (i == trees - 1 ? GetTreeGrowth(ti->tile) : 3); |
8994
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
484 |
SpriteID pal = s[0].pal; |
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
485 |
|
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
486 |
te[i].image = image; |
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
487 |
te[i].pal = pal; |
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
488 |
te[i].x = d->x; |
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
489 |
te[i].y = d->y; |
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
490 |
s++; |
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
491 |
d++; |
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
492 |
} |
8994
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
493 |
|
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
494 |
/* draw them in a sorted way */ |
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
495 |
byte z = ti->z + GetSlopeMaxZ(ti->tileh) / 2; |
8994
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
496 |
|
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
497 |
for (; trees > 0; trees--) { |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
498 |
uint min = te[0].x + te[0].y; |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
499 |
uint mi = 0; |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
500 |
|
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
501 |
for (uint i = 1; i < trees; i++) { |
9008 | 502 |
if ((uint)(te[i].x + te[i].y) < min) { |
8994
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
503 |
min = te[i].x + te[i].y; |
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
504 |
mi = i; |
8994
9c43721e9237
(svn r12073) -Codechange: stop drawing trees a bit earlier when they are invisible
smatz
parents:
8955
diff
changeset
|
505 |
} |
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
506 |
} |
0 | 507 |
|
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
508 |
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 | 509 |
|
8995
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
510 |
/* replace the removed one with the last one */ |
08b6c7873511
(svn r12074) -Cleanup: use C++ variable scope and declaration in DrawTile_Trees()
smatz
parents:
8994
diff
changeset
|
511 |
te[mi] = te[trees - 1]; |
0 | 512 |
} |
513 |
||
514 |
EndSpriteCombine(); |
|
515 |
} |
|
516 |
||
517 |
||
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
518 |
static uint GetSlopeZ_Trees(TileIndex tile, uint x, uint y) |
2537 | 519 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
520 |
uint z; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
521 |
Slope tileh = GetTileSlope(tile, &z); |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
522 |
|
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4157
diff
changeset
|
523 |
return z + GetPartialZ(x & 0xF, y & 0xF, tileh); |
0 | 524 |
} |
525 |
||
7831
5dded9b03500
(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:
7829
diff
changeset
|
526 |
static Foundation GetFoundation_Trees(TileIndex tile, Slope tileh) |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2537
diff
changeset
|
527 |
{ |
7831
5dded9b03500
(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:
7829
diff
changeset
|
528 |
return FOUNDATION_NONE; |
39 | 529 |
} |
530 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7179
diff
changeset
|
531 |
static CommandCost ClearTile_Trees(TileIndex tile, byte flags) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
532 |
{ |
2243 | 533 |
uint num; |
0 | 534 |
|
11161
7d0fac8f14cd
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
10775
diff
changeset
|
535 |
if (IsValidPlayerID(_current_player)) { |
10775
7061477bfbcf
(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:
10707
diff
changeset
|
536 |
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority); |
8728
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
537 |
if (t != NULL) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM); |
0 | 538 |
} |
539 |
||
2981 | 540 |
num = GetTreeCount(tile) + 1; |
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8419
diff
changeset
|
541 |
if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4; |
0 | 542 |
|
2243 | 543 |
if (flags & DC_EXEC) DoClearSquare(tile); |
0 | 544 |
|
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8721
diff
changeset
|
545 |
return CommandCost(EXPENSES_CONSTRUCTION, num * _price.remove_trees); |
0 | 546 |
} |
547 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
548 |
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac) |
0 | 549 |
{ |
550 |
/* not used */ |
|
551 |
} |
|
552 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
553 |
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td) |
0 | 554 |
{ |
2981 | 555 |
TreeType tt = GetTreeType(tile); |
556 |
||
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8419
diff
changeset
|
557 |
if (IsInsideMM(tt, TREE_RAINFOREST, TREE_CACTUS)) { |
2981 | 558 |
td->str = STR_280F_RAINFOREST; |
559 |
} else { |
|
8208
ee19a137b686
(svn r11246) -Codechange: beautify some conditions from "if else" into trinary operator
belugas
parents:
8206
diff
changeset
|
560 |
td->str = tt == TREE_CACTUS ? STR_2810_CACTUS_PLANTS : STR_280E_TREES; |
2981 | 561 |
} |
0 | 562 |
|
10662
f455941692a3
(svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents:
10444
diff
changeset
|
563 |
td->owner[0] = GetTileOwner(tile); |
0 | 564 |
} |
565 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
566 |
static void AnimateTile_Trees(TileIndex tile) |
0 | 567 |
{ |
568 |
/* not used */ |
|
569 |
} |
|
570 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
571 |
static void TileLoopTreesDesert(TileIndex tile) |
0 | 572 |
{ |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
573 |
switch (GetTropicZone(tile)) { |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
574 |
case TROPICZONE_DESERT: |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
575 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) { |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
576 |
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3); |
2981 | 577 |
MarkTileDirtyByTile(tile); |
578 |
} |
|
579 |
break; |
|
2243 | 580 |
|
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
581 |
case TROPICZONE_RAINFOREST: { |
2981 | 582 |
static const SoundFx forest_sounds[] = { |
583 |
SND_42_LOON_BIRD, |
|
584 |
SND_43_LION, |
|
585 |
SND_44_MONKEYS, |
|
586 |
SND_48_DISTANT_BIRD |
|
587 |
}; |
|
588 |
uint32 r = Random(); |
|
0 | 589 |
|
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8450
diff
changeset
|
590 |
if (Chance16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile); |
2981 | 591 |
break; |
0 | 592 |
} |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
593 |
|
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
594 |
default: break; |
0 | 595 |
} |
596 |
} |
|
597 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
598 |
static void TileLoopTreesAlps(TileIndex tile) |
0 | 599 |
{ |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6574
diff
changeset
|
600 |
int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT; |
0 | 601 |
|
4157
0c3210247472
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
3977
diff
changeset
|
602 |
if (k < 0) { |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
603 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) return; |
8206
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
604 |
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 3); |
0 | 605 |
} else { |
4157
0c3210247472
(svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents:
3977
diff
changeset
|
606 |
uint density = min((uint)k / TILE_HEIGHT, 3); |
2981 | 607 |
|
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
608 |
if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT || |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
609 |
GetTreeDensity(tile) != density) { |
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
610 |
SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, density); |
2981 | 611 |
} else { |
612 |
if (GetTreeDensity(tile) == 3) { |
|
613 |
uint32 r = Random(); |
|
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8450
diff
changeset
|
614 |
if (Chance16I(1, 200, r)) { |
2981 | 615 |
SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile); |
616 |
} |
|
0 | 617 |
} |
618 |
return; |
|
619 |
} |
|
620 |
} |
|
621 |
MarkTileDirtyByTile(tile); |
|
622 |
} |
|
623 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
624 |
static void TileLoop_Trees(TileIndex tile) |
0 | 625 |
{ |
8955 | 626 |
if (GetTreeGround(tile) == TREE_GROUND_SHORE) { |
627 |
TileLoop_Water(tile); |
|
628 |
} else { |
|
10775
7061477bfbcf
(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:
10707
diff
changeset
|
629 |
switch (_settings_game.game_creation.landscape) { |
8955 | 630 |
case LT_TROPIC: TileLoopTreesDesert(tile); break; |
631 |
case LT_ARCTIC: TileLoopTreesAlps(tile); break; |
|
632 |
} |
|
0 | 633 |
} |
634 |
||
635 |
TileLoopClearHelper(tile); |
|
636 |
||
8206
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
637 |
uint treeCounter = GetTreeCounter(tile); |
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
638 |
|
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
639 |
/* Handle growth of grass at every 8th processings, like it's done for grass */ |
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
640 |
if ((treeCounter & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) { |
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
641 |
uint density = GetTreeDensity(tile); |
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
642 |
if (density < 3) { |
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
643 |
SetTreeGroundDensity(tile, TREE_GROUND_GRASS, density + 1); |
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
644 |
MarkTileDirtyByTile(tile); |
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
645 |
} |
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
646 |
} |
2981 | 647 |
if (GetTreeCounter(tile) < 15) { |
648 |
AddTreeCounter(tile, 1); |
|
649 |
return; |
|
650 |
} |
|
651 |
SetTreeCounter(tile, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
652 |
|
2981 | 653 |
switch (GetTreeGrowth(tile)) { |
654 |
case 3: /* regular sized tree */ |
|
10775
7061477bfbcf
(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:
10707
diff
changeset
|
655 |
if (_settings_game.game_creation.landscape == LT_TROPIC && |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
656 |
GetTreeType(tile) != TREE_CACTUS && |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
657 |
GetTropicZone(tile) == TROPICZONE_DESERT) { |
2981 | 658 |
AddTreeGrowth(tile, 1); |
659 |
} else { |
|
660 |
switch (GB(Random(), 0, 3)) { |
|
661 |
case 0: /* start destructing */ |
|
662 |
AddTreeGrowth(tile, 1); |
|
2955
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
663 |
break; |
27221592ebbc
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
664 |
|
2981 | 665 |
case 1: /* add a tree */ |
666 |
if (GetTreeCount(tile) < 3) { |
|
667 |
AddTreeCount(tile, 1); |
|
668 |
SetTreeGrowth(tile, 0); |
|
669 |
break; |
|
670 |
} |
|
671 |
/* FALL THROUGH */ |
|
0 | 672 |
|
2981 | 673 |
case 2: { /* add a neighbouring tree */ |
674 |
TreeType treetype = GetTreeType(tile); |
|
0 | 675 |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7446
diff
changeset
|
676 |
tile += TileOffsByDir((Direction)(Random() & 7)); |
0 | 677 |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
678 |
/* Cacti don't spread */ |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
679 |
if (!CanPlantTreesOnTile(tile, false)) return; |
2981 | 680 |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
681 |
/* Don't plant trees, if ground was freshly cleared */ |
8955 | 682 |
if (IsTileType(tile, MP_CLEAR) && GetClearGround(tile) == CLEAR_GRASS && GetClearDensity(tile) != 3) return; |
2981 | 683 |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
684 |
PlantTreesOnTile(tile, treetype, 0, 0); |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
685 |
|
2981 | 686 |
break; |
687 |
} |
|
688 |
||
689 |
default: |
|
690 |
return; |
|
691 |
} |
|
0 | 692 |
} |
2981 | 693 |
break; |
694 |
||
695 |
case 6: /* final stage of tree destruction */ |
|
696 |
if (GetTreeCount(tile) > 0) { |
|
697 |
/* more than one tree, delete it */ |
|
698 |
AddTreeCount(tile, -1); |
|
699 |
SetTreeGrowth(tile, 3); |
|
700 |
} else { |
|
701 |
/* just one tree, change type into MP_CLEAR */ |
|
702 |
switch (GetTreeGround(tile)) { |
|
8955 | 703 |
case TREE_GROUND_SHORE: MakeShore(tile); break; |
8206
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
704 |
case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, GetTreeDensity(tile)); break; |
3447 | 705 |
case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break; |
8206
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
706 |
default: // snow or desert |
10775
7061477bfbcf
(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:
10707
diff
changeset
|
707 |
MakeClear(tile, _settings_game.game_creation.landscape == LT_TROPIC ? CLEAR_DESERT : CLEAR_SNOW, GetTreeDensity(tile)); |
8206
573a2d359695
(svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents:
8097
diff
changeset
|
708 |
break; |
2981 | 709 |
} |
0 | 710 |
} |
2981 | 711 |
break; |
712 |
||
713 |
default: |
|
714 |
AddTreeGrowth(tile, 1); |
|
715 |
break; |
|
0 | 716 |
} |
717 |
||
718 |
MarkTileDirtyByTile(tile); |
|
719 |
} |
|
720 |
||
6573 | 721 |
void OnTick_Trees() |
0 | 722 |
{ |
723 |
uint32 r; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
724 |
TileIndex tile; |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3003
diff
changeset
|
725 |
TreeType tree; |
0 | 726 |
|
727 |
/* place a tree at a random rainforest spot */ |
|
10775
7061477bfbcf
(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:
10707
diff
changeset
|
728 |
if (_settings_game.game_creation.landscape == LT_TROPIC && |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3271
diff
changeset
|
729 |
(r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) && |
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
730 |
CanPlantTreesOnTile(tile, false) && |
3441
d1cef7047cd4
(svn r4271) s/\<TR_/TREE_/ resp. s/\<TR_/TREE_GROUND/
tron
parents:
3422
diff
changeset
|
731 |
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) { |
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
732 |
PlantTreesOnTile(tile, tree, 0, 0); |
0 | 733 |
} |
734 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
735 |
/* byte underflow */ |
2088
f290b54c97cb
(svn r2598) Small cleanup, especially get rid of a FindLandscapeHeight(), because it was overkill
tron
parents:
2085
diff
changeset
|
736 |
if (--_trees_tick_ctr != 0) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
160
diff
changeset
|
737 |
|
0 | 738 |
/* place a tree at a random spot */ |
739 |
r = Random(); |
|
740 |
tile = TILE_MASK(r); |
|
8950
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
741 |
if (CanPlantTreesOnTile(tile, false) && (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) { |
78a73e266037
(svn r12024) -Codechange: Reduce code duplication inside tree_cmd.
frosch
parents:
8948
diff
changeset
|
742 |
PlantTreesOnTile(tile, tree, 0, 0); |
0 | 743 |
} |
744 |
} |
|
745 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1902
diff
changeset
|
746 |
static void ClickTile_Trees(TileIndex tile) |
0 | 747 |
{ |
748 |
/* not used */ |
|
749 |
} |
|
750 |
||
9112
ec6800eaa340
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
9092
diff
changeset
|
751 |
static TrackStatus GetTileTrackStatus_Trees(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) |
0 | 752 |
{ |
753 |
return 0; |
|
754 |
} |
|
755 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2243
diff
changeset
|
756 |
static void ChangeTileOwner_Trees(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 757 |
{ |
758 |
/* not used */ |
|
759 |
} |
|
760 |
||
6573 | 761 |
void InitializeTrees() |
0 | 762 |
{ |
763 |
_trees_tick_ctr = 0; |
|
764 |
} |
|
765 |
||
7990
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7831
diff
changeset
|
766 |
static CommandCost TerraformTile_Trees(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new) |
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7831
diff
changeset
|
767 |
{ |
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7831
diff
changeset
|
768 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7831
diff
changeset
|
769 |
} |
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7831
diff
changeset
|
770 |
|
0 | 771 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
772 |
extern const TileTypeProcs _tile_type_trees_procs = { |
4344
5d0e40cd67b9
(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
|
773 |
DrawTile_Trees, /* draw_tile_proc */ |
5d0e40cd67b9
(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 |
GetSlopeZ_Trees, /* get_slope_z_proc */ |
5d0e40cd67b9
(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 |
ClearTile_Trees, /* clear_tile_proc */ |
5d0e40cd67b9
(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 |
GetAcceptedCargo_Trees, /* get_accepted_cargo_proc */ |
5d0e40cd67b9
(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 |
GetTileDesc_Trees, /* get_tile_desc_proc */ |
5d0e40cd67b9
(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 |
GetTileTrackStatus_Trees, /* get_tile_track_status_proc */ |
5d0e40cd67b9
(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 |
ClickTile_Trees, /* click_tile_proc */ |
5d0e40cd67b9
(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 |
AnimateTile_Trees, /* animate_tile_proc */ |
5d0e40cd67b9
(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 |
TileLoop_Trees, /* tile_loop_clear */ |
5d0e40cd67b9
(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 |
ChangeTileOwner_Trees, /* change_tile_owner_clear */ |
5d0e40cd67b9
(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 |
NULL, /* get_produced_cargo_proc */ |
5d0e40cd67b9
(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, /* vehicle_enter_tile_proc */ |
7831
5dded9b03500
(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:
7829
diff
changeset
|
785 |
GetFoundation_Trees, /* get_foundation_proc */ |
7990
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7831
diff
changeset
|
786 |
TerraformTile_Trees, /* terraform_tile_proc */ |
0 | 787 |
}; |