OpenTTD Source: src/terraform_gui.cpp File Reference

OpenTTD Source 15.0-RC2

Data Structures | Functions | Variables
terraform_gui.cpp File Reference

GUI related to terraforming the map. More...

`#include "stdafx.h"`
`#include "core/backup_type.hpp"`
`#include "clear_map.h"`
`#include "company_func.h"`
`#include "company_base.h"`
`#include "house.h"`
`#include "gui.h"`
`#include "window_gui.h"`
`#include "window_func.h"`
`#include "viewport_func.h"`
`#include "command_func.h"`
`#include "signs_func.h"`
`#include "sound_func.h"`
`#include "base_station_base.h"`
`#include "textbuf_gui.h"`
`#include "genworld.h"`
`#include "tree_map.h"`
`#include "landscape_type.h"`
`#include "tilehighlight_func.h"`
`#include "strings_func.h"`
`#include "newgrf_object.h"`
`#include "object.h"`
`#include "hotkeys.h"`
`#include "engine_base.h"`
`#include "terraform_gui.h"`
`#include "terraform_cmd.h"`
`#include "zoom_func.h"`
`#include "rail_cmd.h"`
`#include "landscape_cmd.h"`
`#include "object_cmd.h"`
`#include "widgets/terraform_widget.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | TerraformToolbarWindow
| Terra form toolbar managing class. More...
struct | ScenarioEditorLandscapeGenerationWindow
| Landscape generation window handler in the scenario editor. More...

## Functions
void | CcTerraform (Commands, const CommandCost &result, Money, TileIndex tile)
static void | GenerateDesertArea (TileIndex end, TileIndex start)
| Scenario editor command that generates desert areas.
static void | GenerateRockyArea (TileIndex end, TileIndex start)
| Scenario editor command that generates rocky areas.
bool | GUIPlaceProcDragXY (ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
| A central place to handle all X_AND_Y dragged GUI functions.
void | PlaceProc_DemolishArea (TileIndex tile)
| Start a drag for demolishing an area.
Window * | ShowTerraformToolbar (Window *link)
| Show the toolbar for terraforming in the game.
static void | CommonRaiseLowerBigLand (TileIndex tile, bool mode)
| Raise/Lower a bigger chunk of land at the same time in the editor.
static void | ResetLandscapeConfirmationCallback (Window *, bool confirmed)
| Callback function for the scenario editor 'reset landscape' confirmation window.
Window * | ShowEditorTerraformToolbar ()
| Show the toolbar for terraforming in the scenario editor.

## Variables
static constexpr std::initializer_list< NWidgetPart > | _nested_terraform_widgets
static WindowDesc | _terraform_desc (WDP_MANUAL, "toolbar_landscape", 0, 0, WC_SCEN_LAND_GEN, WC_NONE, WindowDefaultFlag::Construction, _nested_terraform_widgets, &TerraformToolbarWindow::hotkeys)
static uint8_t | _terraform_size = 1
static const int8_t | _multi_terraform_coords [][2]
static constexpr std::initializer_list< NWidgetPart > | _nested_scen_edit_land_gen_widgets
static WindowDesc | _scen_edit_land_gen_desc (WDP_AUTO, "toolbar_landscape_scen", 0, 0, WC_SCEN_LAND_GEN, WC_NONE, WindowDefaultFlag::Construction, _nested_scen_edit_land_gen_widgets, &ScenarioEditorLandscapeGenerationWindow::hotkeys)

## Detailed Description

GUI related to terraforming the map.

Definition in file terraform_gui.cpp.

## Function Documentation

## ◆ CcTerraform()

void CcTerraform | ( | Commands | cmd,
|  | const CommandCost & | result,
|  | Money | ,
|  | TileIndex | tile
| ) |  |

Definition at line 48 of file terraform_gui.cpp.

## ◆ CommonRaiseLowerBigLand()

static void CommonRaiseLowerBigLand | ( | TileIndex | tile,
|  | bool | mode
| ) |  |
| static

Raise/Lower a bigger chunk of land at the same time in the editor.

When raising get the lowest point, when lowering the highest point, and set all tiles in the selection to that height.

Todo:
  : Incorporate into game itself to allow for ingame raising/lowering of larger chunks at the same time OR remove altogether, as we have 'level land' ?

Parameters

  tile | The top-left tile where the terraforming will start
  mode | true for raising, false for lowering land

Definition at line 393 of file terraform_gui.cpp.

References _settings_client, OrthogonalTileArea::ClampToMap(), SoundSettings::confirm, OrthogonalTileArea::h, MAX_TILE_HEIGHT, SLOPE_N, SND_1F_CONSTRUCTION_OTHER, ClientSettings::sound, TileHeight(), and OrthogonalTileArea::w.

Referenced by ScenarioEditorLandscapeGenerationWindow::OnPlaceObject().

## ◆ GenerateDesertArea()

static void GenerateDesertArea | ( | TileIndex | end,
|  | TileIndex | start
| ) |  |
| static

Scenario editor command that generates desert areas.

Definition at line 59 of file terraform_gui.cpp.

References _ctrl_pressed, _generating_world, InvalidateWindowClassesData(), MarkTileDirtyByTile(), Backup< T >::Restore(), SetTropicZone(), TROPICZONE_DESERT, TROPICZONE_NORMAL, and WC_TOWN_VIEW.

Referenced by GUIPlaceProcDragXY().

## ◆ GenerateRockyArea()

static void GenerateRockyArea | ( | TileIndex | end,
|  | TileIndex | start
| ) |  |
| static

Scenario editor command that generates rocky areas.

Definition at line 76 of file terraform_gui.cpp.

References _settings_client, CLEAR_ROCKS, SoundSettings::confirm, GetTileType(), GetTreeGround(), MakeClear(), MarkTileDirtyByTile(), MP_CLEAR, MP_TREES, SND_1F_CONSTRUCTION_OTHER, ClientSettings::sound, and TREE_GROUND_SHORE.

Referenced by GUIPlaceProcDragXY().

## ◆ GUIPlaceProcDragXY()

bool GUIPlaceProcDragXY | ( | ViewportDragDropSelectionProcess | proc,
|  | TileIndex | start_tile,
|  | TileIndex | end_tile
| ) |  |

A central place to handle all X_AND_Y dragged GUI functions.

Parameters

  proc | Procedure related to the dragging
  start_tile | Begin of the dragging
  end_tile | End of the dragging

Returns
  Returns true if the action was found and handled, and false otherwise. This allows for additional implements that are more local. For example X_Y drag of convertrail which belongs in rail_gui.cpp and not terraform_gui.cpp

Definition at line 112 of file terraform_gui.cpp.

References _ctrl_pressed, _settings_game, GameSettings::construction, DDSP_CREATE_DESERT, DDSP_CREATE_ROCKS, DDSP_DEMOLISH_AREA, DDSP_LEVEL_AREA, DDSP_LOWER_AND_LEVEL_AREA, DDSP_RAISE_AND_LEVEL_AREA, ConstructionSettings::freeform_edges, GenerateDesertArea(), GenerateRockyArea(), LM_LEVEL, LM_LOWER, LM_RAISE, Map::MaxX(), Map::MaxY(), TileDiffXY(), TileX(), and TileY().

Referenced by BuildAirToolbarWindow::OnPlaceMouseUp(), BuildDocksToolbarWindow::OnPlaceMouseUp(), BuildRailToolbarWindow::OnPlaceMouseUp(), BuildRoadToolbarWindow::OnPlaceMouseUp(), TerraformToolbarWindow::OnPlaceMouseUp(), and ScenarioEditorLandscapeGenerationWindow::OnPlaceMouseUp().

## ◆ PlaceProc_DemolishArea()

void PlaceProc_DemolishArea | ( | TileIndex | tile | ) |

Start a drag for demolishing an area.

Parameters

  tile | Position of one corner.

Definition at line 151 of file terraform_gui.cpp.

References DDSP_DEMOLISH_AREA, VPM_X_AND_Y, and VpStartPlaceSizing().

Referenced by BuildAirToolbarWindow::OnPlaceObject(), BuildDocksToolbarWindow::OnPlaceObject(), BuildRailToolbarWindow::OnPlaceObject(), BuildRoadToolbarWindow::OnPlaceObject(), TerraformToolbarWindow::OnPlaceObject(), and ScenarioEditorLandscapeGenerationWindow::OnPlaceObject().

## ◆ ResetLandscapeConfirmationCallback()

static void ResetLandscapeConfirmationCallback | ( | Window * | ,
|  | bool | confirmed
| ) |  |
| static

Callback function for the scenario editor 'reset landscape' confirmation window.

Parameters

  confirmed | boolean value, true when yes was clicked, false otherwise

Definition at line 496 of file terraform_gui.cpp.

References _generating_world, Bankrupt, ChangeOwnershipOfCompanyItems(), Execute, INVALID_OWNER, IsBuoyTile(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_station_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), MarkWholeScreenDirty(), EngineOverrideManager::ResetToCurrentNewGRFConfig(), and Backup< T >::Restore().

Referenced by ScenarioEditorLandscapeGenerationWindow::OnClick().

## ◆ ShowEditorTerraformToolbar()

Window * ShowEditorTerraformToolbar | ( |  | ) |

Show the toolbar for terraforming in the scenario editor.

Returns
  The allocated toolbar if the window was newly opened, else `nullptr`.

Definition at line 742 of file terraform_gui.cpp.

Referenced by ScenarioEditorToolbarWindow::OnHotkey(), and ScenarioEditorLandscapeGenerationWindow::TerraformToolbarEditorGlobalHotkeys().

## ◆ ShowTerraformToolbar()

Window * ShowTerraformToolbar | ( | Window * | link | ) |

Show the toolbar for terraforming in the game.

Parameters

  link | The toolbar we might want to link to.

Returns
  The allocated toolbar if the window was newly opened, else `nullptr`.

Definition at line 364 of file terraform_gui.cpp.

References _current_text_dir, _local_company, CloseWindowById(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), Window::left, Window::SetDirty(), TD_RTL, Window::top, WC_SCEN_LAND_GEN, and Window::width.

Referenced by MenuClickForest(), MainToolbarWindow::OnHotkey(), and TerraformToolbarWindow::TerraformToolbarGlobalHotkeys().

## Variable Documentation

## ◆ _multi_terraform_coords

const int8_t _multi_terraform_coords[][2]
| static

Initial value:
= {
{ 0, -2},
{ 4, 0}, { -4, 0}, { 0, 2},
{ -8, 2}, { -4, 4}, { 0, 6}, { 4, 4}, { 8, 2},
{-12, 0}, { -8, -2}, { -4, -4}, { 0, -6}, { 4, -4}, { 8, -2}, { 12, 0},
{-16, 2}, {-12, 4}, { -8, 6}, { -4, 8}, { 0, 10}, { 4, 8}, { 8, 6}, { 12, 4}, { 16, 2},
{-20, 0}, {-16, -2}, {-12, -4}, { -8, -6}, { -4, -8}, { 0,-10}, { 4, -8}, { 8, -6}, { 12, -4}, { 16, -2}, { 20, 0},
{-24, 2}, {-20, 4}, {-16, 6}, {-12, 8}, { -8, 10}, { -4, 12}, { 0, 14}, { 4, 12}, { 8, 10}, { 12, 8}, { 16, 6}, { 20, 4}, { 24, 2},
{-28, 0}, {-24, -2}, {-20, -4}, {-16, -6}, {-12, -8}, { -8,-10}, { -4,-12}, { 0,-14}, { 4,-12}, { 8,-10}, { 12, -8}, { 16, -6}, { 20, -4}, { 24, -2}, { 28, 0},
}

Definition at line 432 of file terraform_gui.cpp.

## ◆ _nested_scen_edit_land_gen_widgets

constexpr std::initializer_list<NWidgetPart> _nested_scen_edit_land_gen_widgets
| staticconstexpr

Definition at line 443 of file terraform_gui.cpp.

## ◆ _nested_terraform_widgets

constexpr std::initializer_list<NWidgetPart> _nested_terraform_widgets
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_LANDSCAPING_TOOLBAR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_LOWER_LAND), SetToolbarMinimalSize(1),
SetFill(0, 1), SetSpriteTip(SPR_IMG_TERRAFORM_DOWN, STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_RAISE_LAND), SetToolbarMinimalSize(1),
SetFill(0, 1), SetSpriteTip(SPR_IMG_TERRAFORM_UP, STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_LEVEL_LAND), SetToolbarMinimalSize(1),
SetFill(0, 1), SetSpriteTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_LEVEL_LAND_TOOLTIP),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetToolbarSpacerMinimalSize(), EndContainer(),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_DEMOLISH), SetToolbarMinimalSize(1),
SetFill(0, 1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_BUY_LAND), SetToolbarMinimalSize(1),
SetFill(0, 1), SetSpriteTip(SPR_IMG_BUY_LAND, STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND),
NWidget(WWT_PUSHIMGBTN, COLOUR_DARK_GREEN, WID_TT_PLANT_TREES), SetToolbarMinimalSize(1),
SetFill(0, 1), SetSpriteTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES_TOOLTIP),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_PLACE_SIGN), SetToolbarMinimalSize(1),
SetFill(0, 1), SetSpriteTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN_TOOLTIP),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_TT_SHOW_PLACE_OBJECT),
NWidget(WWT_PUSHIMGBTN, COLOUR_DARK_GREEN, WID_TT_PLACE_OBJECT), SetToolbarMinimalSize(1),
SetFill(0, 1), SetSpriteTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT_TOOLTIP),
EndContainer(),
EndContainer(),
}
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
SetSpriteTip
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
Definition widget_type.h:1251
SetToolbarMinimalSize
constexpr NWidgetPart SetToolbarMinimalSize(int width)
Widget part function to setting the minimal size for a toolbar button.
Definition widget_type.h:1175
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
SetToolbarSpacerMinimalSize
constexpr NWidgetPart SetToolbarSpacerMinimalSize()
Widget part function to setting the minimal size for a toolbar spacer.
Definition widget_type.h:1165
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
WID_TT_LEVEL_LAND
@ WID_TT_LEVEL_LAND
Level land button.
Definition terraform_widget.h:19
WID_TT_DEMOLISH
@ WID_TT_DEMOLISH
Demolish aka dynamite button.
Definition terraform_widget.h:20
WID_TT_SHOW_PLACE_OBJECT
@ WID_TT_SHOW_PLACE_OBJECT
Should the place object button be shown?
Definition terraform_widget.h:15
WID_TT_RAISE_LAND
@ WID_TT_RAISE_LAND
Raise land button.
Definition terraform_widget.h:18
WID_TT_PLACE_OBJECT
@ WID_TT_PLACE_OBJECT
Place object button.
Definition terraform_widget.h:24
WID_TT_PLANT_TREES
@ WID_TT_PLANT_TREES
Plant trees button (note: opens separate window, no place-push-button).
Definition terraform_widget.h:22
WID_TT_PLACE_SIGN
@ WID_TT_PLACE_SIGN
Place sign button.
Definition terraform_widget.h:23
WID_TT_BUY_LAND
@ WID_TT_BUY_LAND
Buy land button.
Definition terraform_widget.h:21
WID_TT_LOWER_LAND
@ WID_TT_LOWER_LAND
Lower land button.
Definition terraform_widget.h:17
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition widget_type.h:105
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71

Definition at line 320 of file terraform_gui.cpp.

## ◆ _terraform_size

uint8_t _terraform_size = 1
| static

Definition at line 382 of file terraform_gui.cpp.