Mercurial > hg > openttd
changeset 15019:26df377a8d35 draft
(svn r19634) -Codechange: Use TREE_INVALID more consistently.
author | frosch <frosch@openttd.org> |
---|---|
date | Wed, 14 Apr 2010 19:57:19 +0000 |
parents | 473c5cfc4d3d |
children | a864a5a396ed |
files | src/tree_cmd.cpp src/tree_gui.cpp src/tree_map.h |
diffstat | 3 files changed, 10 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -336,7 +336,7 @@ /** 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 @@ { 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 @@ } 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;
--- a/src/tree_gui.cpp +++ b/src/tree_gui.cpp @@ -18,6 +18,7 @@ #include "company_base.h" #include "command_func.h" #include "sound_func.h" +#include "tree_map.h" #include "table/sprites.h" #include "table/strings.h" @@ -50,7 +51,7 @@ { uint16 base; ///< Base tree number used for drawing the window. uint16 count; ///< Number of different trees available. - uint tree_to_plant; ///< Tree number to plant, \c UINT_MAX for a random tree. + TreeType tree_to_plant; ///< Tree number to plant, \c TREE_INVALID for a random tree. public: BuildTreesWindow(const WindowDesc *desc, WindowNumber window_number) : Window() @@ -105,13 +106,13 @@ if (widget - BTW_TYPE_11 >= this->count) break; if (HandlePlacePushButton(this, widget, SPR_CURSOR_TREE, HT_RECT, NULL)) { - this->tree_to_plant = this->base + widget - BTW_TYPE_11; + this->tree_to_plant = (TreeType)(this->base + widget - BTW_TYPE_11); } break; case BTW_TYPE_RANDOM: // tree of random type. if (HandlePlacePushButton(this, BTW_TYPE_RANDOM, SPR_CURSOR_TREE, HT_RECT, NULL)) { - this->tree_to_plant = UINT_MAX; + this->tree_to_plant = TREE_INVALID; } break;
--- a/src/tree_map.h +++ b/src/tree_map.h @@ -22,17 +22,15 @@ * offsets from the grfs files. These points to the start of * the tree list for a landscape. See the TREE_COUNT_* enumerations * for the amount of different trees for a specific landscape. - * - * @note TREE_INVALID may be 0xFF according to the coding style, not -1 (Progman) */ enum TreeType { - TREE_INVALID = -1, ///< An invalid tree TREE_TEMPERATE = 0x00, ///< temperate tree TREE_SUB_ARCTIC = 0x0C, ///< tree on a sub_arctic landscape TREE_RAINFOREST = 0x14, ///< tree on the 'green part' on a sub-tropical map TREE_CACTUS = 0x1B, ///< a catus for the 'desert part' on a sub-tropical map TREE_SUB_TROPICAL = 0x1C, ///< tree on a sub-tropical map, non-rainforest, non-desert TREE_TOYLAND = 0x20, ///< tree on a toyland map + TREE_INVALID = 0xFF, ///< An invalid tree }; /**