Changeset - r15009:8390f54dffd4
[Not reviewed]
master
0 3 0
frosch - 15 years ago 2010-04-14 19:57:19
frosch@openttd.org
(svn r19634) -Codechange: Use TREE_INVALID more consistently.
3 files changed with 10 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/tree_cmd.cpp
Show inline comments
 
@@ -333,25 +333,26 @@ 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
 
 */
 
CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	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) {
 
		switch (GetTileType(tile)) {
 
			case MP_TREES:
 
				/* no more space for trees? */
 
@@ -398,15 +399,13 @@ CommandCost CmdPlantTree(TileIndex tile,
 
				if (_game_mode != GM_EDITOR && Company::IsValidID(_current_company)) {
 
					Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
 
					if (t != NULL) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags);
 
				}
 

	
 
				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;
 
					}
 

	
 
					/* Plant full grown trees in scenario editor */
src/tree_gui.cpp
Show inline comments
 
@@ -15,12 +15,13 @@
 
#include "gfx_func.h"
 
#include "tilehighlight_func.h"
 
#include "company_func.h"
 
#include "company_base.h"
 
#include "command_func.h"
 
#include "sound_func.h"
 
#include "tree_map.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
#include "table/tree_land.h"
 

	
 
void PlaceTreesRandomly();
 
@@ -47,13 +48,13 @@ enum BuildTreesWidgets {
 
 * The build trees window.
 
 */
 
class BuildTreesWindow : public Window
 
{
 
	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()
 
	{
 
		this->InitNested(desc, window_number);
 
		ResetObjectToPlace();
 
@@ -102,19 +103,19 @@ public:
 
			case BTW_TYPE_11: case BTW_TYPE_12: case BTW_TYPE_13: case BTW_TYPE_14:
 
			case BTW_TYPE_21: case BTW_TYPE_22: case BTW_TYPE_23: case BTW_TYPE_24:
 
			case BTW_TYPE_31: case BTW_TYPE_32: case BTW_TYPE_33: case BTW_TYPE_34:
 
				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;
 

	
 
			case BTW_MANY_RANDOM: // place trees randomly over the landscape
 
				this->LowerWidget(BTW_MANY_RANDOM);
 
				this->flags4 |= WF_TIMEOUT_BEGIN;
src/tree_map.h
Show inline comments
 
@@ -19,23 +19,21 @@
 
 *
 
 * This enumeration contains a list of the different tree types along
 
 * all landscape types. The values for the enumerations may be used for
 
 * 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
 
};
 

	
 
/**
 
 * Counts the number of treetypes for each landscape.
 
 *
 
 * This list contains the counts of different treetypes for each landscape. This list contains
0 comments (0 inline, 0 general)