OpenTTD Source: src/tree_gui.cpp File Reference

OpenTTD Source 15.0-beta1

Data Structures | Functions | Variables
tree_gui.cpp File Reference

GUIs for building trees. More...

`#include "stdafx.h"`
`#include "window_gui.h"`
`#include "gfx_func.h"`
`#include "tilehighlight_func.h"`
`#include "company_func.h"`
`#include "company_base.h"`
`#include "command_func.h"`
`#include "core/random_func.hpp"`
`#include "sound_func.h"`
`#include "strings_func.h"`
`#include "zoom_func.h"`
`#include "tree_map.h"`
`#include "tree_cmd.h"`
`#include "widgets/tree_widget.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`
`#include "table/tree_land.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
class | BuildTreesWindow
| The build trees window. More...

## Functions
void | PlaceTreesRandomly ()
| Place some trees randomly.
uint | PlaceTreeGroupAroundTile (TileIndex tile, TreeType treetype, uint radius, uint count, bool set_zone)
| Place some trees in a radius around a tile.
static Dimension | GetMaxTreeSpriteSize ()
| Calculate the maximum size of all tree sprites.
static std::unique_ptr< NWidgetBase > | MakeTreeTypeButtons ()
| Make widgets for the current available tree types.
void | ShowBuildTreesToolbar ()

## Variables
const PalSpriteID | tree_sprites []
| Tree Sprites with their palettes.
static constexpr NWidgetPart | _nested_build_trees_widgets []
static WindowDesc | _build_trees_desc (WDP_AUTO, "build_tree", 0, 0, WC_BUILD_TREES, WC_NONE, WDF_CONSTRUCTION, _nested_build_trees_widgets)

## Detailed Description

GUIs for building trees.

Definition in file tree_gui.cpp.

## Function Documentation

## ◆ GetMaxTreeSpriteSize()

static Dimension GetMaxTreeSpriteSize | ( |  | ) |
| static

Calculate the maximum size of all tree sprites.

Returns
  Dimension of the largest tree sprite

Definition at line 53 of file tree_gui.cpp.

References _settings_game, GameSettings::game_creation, GetSpriteSize(), GameCreationSettings::landscape, lengthof, ScaleGUITrad(), and tree_sprites.

Referenced by BuildTreesWindow::UpdateWidgetSize().

## ◆ MakeTreeTypeButtons()

static std::unique_ptr< NWidgetBase > MakeTreeTypeButtons | ( |  | ) |
| static

Make widgets for the current available tree types.

This does not use a NWID_MATRIX or WWT_MATRIX control as those are more difficult to get producing the correct result than dynamically building the widgets is.

See also
  NWidgetFunctionType

Definition at line 259 of file tree_gui.cpp.

References _settings_game, CeilDiv(), GameSettings::game_creation, GameCreationSettings::landscape, NC_EQUALSIZE, WID_BT_TYPE_BUTTON_FIRST, and WWT_PANEL.

## ◆ PlaceTreeGroupAroundTile()

uint PlaceTreeGroupAroundTile | ( | TileIndex | tile,
|  | TreeType | treetype,
|  | uint | radius,
|  | uint | count,
|  | bool | set_zone
| ) |  |

Place some trees in a radius around a tile.

The trees are placed in an quasi-normal distribution around the indicated tile, meaning that while the radius does define a square, the distribution inside the square will be roughly circular.

Note
  This function the interactive RNG and must only be used in editor and map generation.

Parameters

  tile | Tile to place trees around.
  treetype | Type of trees to place. Must be a valid tree type for the climate.
  radius | Maximum distance (on each axis) from tile to place trees.
  count | Maximum number of trees to place.
  set_zone | Whether to create a rainforest zone when placing rainforest trees.

Returns
  Number of trees actually placed.

Definition at line 307 of file tree_cmd.cpp.

References AddTreeCount(), CanPlantTreesOnTile(), DistanceSquare(), OrthogonalTileArea::Expand(), GetTileType(), GetTreeCount(), Growing1, Grown, INVALID_TILE, IsInsideMM(), IsTileType(), MarkTileDirtyByTile(), MP_TREES, MP_VOID, PlantTreesOnTile(), SetTreeGrowth(), SetTropicZone(), TileAddWrap(), TREE_CACTUS, TREE_COUNT_TOYLAND, TREE_RAINFOREST, TREE_TOYLAND, and TROPICZONE_RAINFOREST.

## ◆ PlaceTreesRandomly()

void PlaceTreesRandomly | ( |  | ) |

Place some trees randomly.

This function just place some trees randomly on the map.

Definition at line 247 of file tree_cmd.cpp.

References _settings_game, CanPlantTreesOnTile(), DEFAULT_RAINFOREST_TREE_STEPS, DEFAULT_TREE_STEPS, EDITOR_TREE_DIV, GameSettings::game_creation, GetSnowLine(), GetTileZ(), GetTropicZone(), GWP_TREE, IncreaseGeneratingWorldProgress(), GameCreationSettings::landscape, PlaceTree(), PlaceTreeAtSameHeight(), RandomTileSeed(), Map::ScaleBySize(), TP_IMPROVED, GameCreationSettings::tree_placer, and TROPICZONE_RAINFOREST.

Referenced by GenerateTrees(), and BuildTreesWindow::OnClick().

## ◆ ShowBuildTreesToolbar()

void ShowBuildTreesToolbar | ( |  | ) |

Definition at line 320 of file tree_gui.cpp.

## Variable Documentation

## ◆ _nested_build_trees_widgets

constexpr NWidgetPart _nested_build_trees_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_PLANT_TREE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
NWidget(NWID_VERTICAL), SetPIP(0, 1, 0), SetPadding(2),
NWidgetFunction(MakeTreeTypeButtons),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BT_TYPE_RANDOM), SetDataTip(STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TOOLTIP),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BT_SE_PANE),
NWidget(NWID_VERTICAL), SetPIP(0, 1, 0),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BT_MODE_NORMAL), SetFill(1, 0), SetDataTip(STR_TREES_MODE_NORMAL_BUTTON, STR_TREES_MODE_NORMAL_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BT_MODE_FOREST_SM), SetFill(1, 0), SetDataTip(STR_TREES_MODE_FOREST_SM_BUTTON, STR_TREES_MODE_FOREST_SM_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BT_MODE_FOREST_LG), SetFill(1, 0), SetDataTip(STR_TREES_MODE_FOREST_LG_BUTTON, STR_TREES_MODE_FOREST_LG_TOOLTIP),
EndContainer(),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BT_MANY_RANDOM), SetDataTip(STR_TREES_RANDOM_TREES_BUTTON, STR_TREES_RANDOM_TREES_TOOLTIP),
EndContainer(),
EndContainer(),
EndContainer(),
EndContainer(),
}
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition widget_type.h:1341
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1181
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1271
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1228
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition widget_type.h:1202
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1191
MakeTreeTypeButtons
static std::unique_ptr< NWidgetBase > MakeTreeTypeButtons()
Make widgets for the current available tree types.
Definition tree_gui.cpp:259
WID_BT_MANY_RANDOM
@ WID_BT_MANY_RANDOM
Button to build many random trees.
Definition tree_widget.h:20
WID_BT_SE_PANE
@ WID_BT_SE_PANE
Selection pane to show/hide scenario editor tools.
Definition tree_widget.h:16
WID_BT_MODE_NORMAL
@ WID_BT_MODE_NORMAL
Select normal/rectangle planting mode.
Definition tree_widget.h:17
WID_BT_MODE_FOREST_SM
@ WID_BT_MODE_FOREST_SM
Select small forest planting mode.
Definition tree_widget.h:18
WID_BT_MODE_FOREST_LG
@ WID_BT_MODE_FOREST_LG
Select large forest planting mode.
Definition tree_widget.h:19
WID_BT_TYPE_RANDOM
@ WID_BT_TYPE_RANDOM
Button to build random type of tree.
Definition tree_widget.h:15
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition widget_type.h:524
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:113
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:55
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:66
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:64
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:61
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:77
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:69
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:80

Definition at line 288 of file tree_gui.cpp.

## ◆ tree_sprites

const PalSpriteID tree_sprites[]

Initial value:
= {
{ 1621, PAL_NONE }, { 1635, PAL_NONE }, { 1656, PAL_NONE }, { 1579, PAL_NONE },
{ 1607, PAL_NONE }, { 1593, PAL_NONE }, { 1614, PAL_NONE }, { 1586, PAL_NONE },
{ 1663, PAL_NONE }, { 1677, PAL_NONE }, { 1691, PAL_NONE }, { 1705, PAL_NONE },
{ 1711, PAL_NONE }, { 1746, PAL_NONE }, { 1753, PAL_NONE }, { 1732, PAL_NONE },
{ 1739, PAL_NONE }, { 1718, PAL_NONE }, { 1725, PAL_NONE }, { 1760, PAL_NONE },
{ 1838, PAL_NONE }, { 1844, PAL_NONE }, { 1866, PAL_NONE }, { 1871, PAL_NONE },
{ 1899, PAL_NONE }, { 1935, PAL_NONE }, { 1928, PAL_NONE }, { 1915, PAL_NONE },
{ 1887, PAL_NONE }, { 1908, PAL_NONE }, { 1824, PAL_NONE }, { 1943, PAL_NONE },
{ 1950, PAL_NONE }, { 1957, PALETTE_TO_GREEN }, { 1964, PALETTE_TO_RED }, { 1971, PAL_NONE },
{ 1978, PAL_NONE }, { 1985, PALETTE_TO_RED, }, { 1992, PALETTE_TO_PALE_GREEN }, { 1999, PALETTE_TO_YELLOW }, { 2006, PALETTE_TO_RED }
}

Tree Sprites with their palettes.

Definition at line 36 of file tree_gui.cpp.

Referenced by BuildTreesWindow::DrawWidget(), and GetMaxTreeSpriteSize().