summaryrefslogtreecommitdiff
path: root/src/tree_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-04-14 19:57:19 +0000
committerfrosch <frosch@openttd.org>2010-04-14 19:57:19 +0000
commitaea22529607303aadd138b75b95382c4b3ed02e3 (patch)
treee6c618956ca8137af08953249c33bef0f0f5d236 /src/tree_cmd.cpp
parenta929ab0c24826e80e01c59fe57b4c6087d59301c (diff)
downloadopenttd-aea22529607303aadd138b75b95382c4b3ed02e3.tar.xz
(svn r19634) -Codechange: Use TREE_INVALID more consistently.
Diffstat (limited to 'src/tree_cmd.cpp')
-rw-r--r--src/tree_cmd.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp
index 3c127e0ae..3a96ddc3a 100644
--- a/src/tree_cmd.cpp
+++ b/src/tree_cmd.cpp
@@ -336,7 +336,7 @@ void GenerateTrees()
/** Plant a tree.
* @param tile start tile of area-drag of tree plantation
* @param flags type of operation
- * @param p1 tree type, -1 means random.
+ * @param p1 tree type, TREE_INVALID means random.
* @param p2 end tile of area-drag
* @param text unused
* @return the cost of this operation or an error
@@ -345,10 +345,11 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
{
StringID msg = INVALID_STRING_ID;
CommandCost cost(EXPENSES_OTHER);
+ const byte tree_to_plant = GB(p1, 0, 8); // We cannot use Extract as min and max are climate specific.
if (p2 >= MapSize()) return CMD_ERROR;
- /* Check the tree type. It can be random or some valid value within the current climate */
- if (p1 != UINT_MAX && p1 - _tree_base_by_landscape[_settings_game.game_creation.landscape] >= _tree_count_by_landscape[_settings_game.game_creation.landscape]) return CMD_ERROR;
+ /* Check the tree type within the current climate */
+ if (tree_to_plant != TREE_INVALID && !IsInsideBS(tree_to_plant, _tree_base_by_landscape[_settings_game.game_creation.landscape], _tree_count_by_landscape[_settings_game.game_creation.landscape])) return CMD_ERROR;
TileArea ta(tile, p2);
TILE_AREA_LOOP(tile, ta) {
@@ -401,9 +402,7 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
}
if (flags & DC_EXEC) {
- TreeType treetype;
-
- treetype = (TreeType)p1;
+ TreeType treetype = (TreeType)tree_to_plant;
if (treetype == TREE_INVALID) {
treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
if (treetype == TREE_INVALID) treetype = TREE_CACTUS;